Skip to content

Commit da5a57a

Browse files
authored
Merge pull request #79 from appwrite/dev
feat: .NET SDK update for version 0.22.0
2 parents 59bcf85 + a71b5b6 commit da5a57a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+622
-139
lines changed

Appwrite/Appwrite.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
44
<PackageId>Appwrite</PackageId>
5-
<Version>0.21.2</Version>
5+
<Version>0.22.0</Version>
66
<Authors>Appwrite Team</Authors>
77
<Company>Appwrite Team</Company>
88
<Description>

Appwrite/Client.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public Client(
6969
_headers = new Dictionary<string, string>()
7070
{
7171
{ "content-type", "application/json" },
72-
{ "user-agent" , $"AppwriteDotNetSDK/0.21.2 ({Environment.OSVersion.Platform}; {Environment.OSVersion.VersionString})"},
72+
{ "user-agent" , $"AppwriteDotNetSDK/0.22.0 ({Environment.OSVersion.Platform}; {Environment.OSVersion.VersionString})"},
7373
{ "x-sdk-name", ".NET" },
7474
{ "x-sdk-platform", "server" },
7575
{ "x-sdk-language", "dotnet" },
76-
{ "x-sdk-version", "0.21.2"},
76+
{ "x-sdk-version", "0.22.0"},
7777
{ "X-Appwrite-Response-Format", "1.8.0" }
7878
};
7979

Appwrite/Enums/ExecutionStatus.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public ExecutionStatus(string value)
1515
public static ExecutionStatus Processing => new ExecutionStatus("processing");
1616
public static ExecutionStatus Completed => new ExecutionStatus("completed");
1717
public static ExecutionStatus Failed => new ExecutionStatus("failed");
18+
public static ExecutionStatus Scheduled => new ExecutionStatus("scheduled");
1819
}
1920
}

Appwrite/Enums/Framework.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public Framework(string value)
1919
public static Framework Vue => new Framework("vue");
2020
public static Framework Sveltekit => new Framework("sveltekit");
2121
public static Framework Astro => new Framework("astro");
22+
public static Framework TanstackStart => new Framework("tanstack-start");
2223
public static Framework Remix => new Framework("remix");
2324
public static Framework Lynx => new Framework("lynx");
2425
public static Framework Flutter => new Framework("flutter");

Appwrite/Operator.cs

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Runtime.Serialization;
5+
using System.Text.Json;
6+
using System.Text.Json.Serialization;
7+
8+
namespace Appwrite
9+
{
10+
public enum Condition
11+
{
12+
[EnumMember(Value = "equal")]
13+
Equal,
14+
[EnumMember(Value = "notEqual")]
15+
NotEqual,
16+
[EnumMember(Value = "greaterThan")]
17+
GreaterThan,
18+
[EnumMember(Value = "greaterThanEqual")]
19+
GreaterThanEqual,
20+
[EnumMember(Value = "lessThan")]
21+
LessThan,
22+
[EnumMember(Value = "lessThanEqual")]
23+
LessThanEqual,
24+
[EnumMember(Value = "contains")]
25+
Contains,
26+
[EnumMember(Value = "isNull")]
27+
IsNull,
28+
[EnumMember(Value = "isNotNull")]
29+
IsNotNull
30+
}
31+
32+
public static class ConditionExtensions
33+
{
34+
public static string ToValue(this Condition condition)
35+
{
36+
return condition switch
37+
{
38+
Condition.Equal => "equal",
39+
Condition.NotEqual => "notEqual",
40+
Condition.GreaterThan => "greaterThan",
41+
Condition.GreaterThanEqual => "greaterThanEqual",
42+
Condition.LessThan => "lessThan",
43+
Condition.LessThanEqual => "lessThanEqual",
44+
Condition.Contains => "contains",
45+
Condition.IsNull => "isNull",
46+
Condition.IsNotNull => "isNotNull",
47+
_ => throw new ArgumentOutOfRangeException(nameof(condition), condition, null)
48+
};
49+
}
50+
}
51+
52+
public class Operator
53+
{
54+
[JsonPropertyName("method")]
55+
public string Method { get; set; } = string.Empty;
56+
57+
[JsonPropertyName("values")]
58+
public List<object>? Values { get; set; }
59+
60+
public Operator()
61+
{
62+
}
63+
64+
public Operator(string method, object? values)
65+
{
66+
this.Method = method;
67+
68+
if (values is IList valuesList)
69+
{
70+
this.Values = new List<object>();
71+
foreach (var value in valuesList)
72+
{
73+
this.Values.Add(value);
74+
}
75+
}
76+
else if (values != null)
77+
{
78+
this.Values = new List<object> { values };
79+
}
80+
}
81+
82+
override public string ToString()
83+
{
84+
return JsonSerializer.Serialize(this, Client.SerializerOptions);
85+
}
86+
87+
public static string Increment(double value = 1, double? max = null)
88+
{
89+
if (Double.IsNaN(value) || Double.IsInfinity(value))
90+
{
91+
throw new ArgumentException("Value cannot be NaN or Infinity", nameof(value));
92+
}
93+
if (max.HasValue && (Double.IsNaN(max.Value) || Double.IsInfinity(max.Value)))
94+
{
95+
throw new ArgumentException("Max cannot be NaN or Infinity", nameof(max));
96+
}
97+
var values = new List<object> { value };
98+
if (max.HasValue)
99+
{
100+
values.Add(max.Value);
101+
}
102+
return new Operator("increment", values).ToString();
103+
}
104+
105+
public static string Decrement(double value = 1, double? min = null)
106+
{
107+
if (Double.IsNaN(value) || Double.IsInfinity(value))
108+
{
109+
throw new ArgumentException("Value cannot be NaN or Infinity", nameof(value));
110+
}
111+
if (min.HasValue && (Double.IsNaN(min.Value) || Double.IsInfinity(min.Value)))
112+
{
113+
throw new ArgumentException("Min cannot be NaN or Infinity", nameof(min));
114+
}
115+
var values = new List<object> { value };
116+
if (min.HasValue)
117+
{
118+
values.Add(min.Value);
119+
}
120+
return new Operator("decrement", values).ToString();
121+
}
122+
123+
public static string Multiply(double factor, double? max = null)
124+
{
125+
if (Double.IsNaN(factor) || Double.IsInfinity(factor))
126+
{
127+
throw new ArgumentException("Factor cannot be NaN or Infinity", nameof(factor));
128+
}
129+
if (max.HasValue && (Double.IsNaN(max.Value) || Double.IsInfinity(max.Value)))
130+
{
131+
throw new ArgumentException("Max cannot be NaN or Infinity", nameof(max));
132+
}
133+
var values = new List<object> { factor };
134+
if (max.HasValue)
135+
{
136+
values.Add(max.Value);
137+
}
138+
return new Operator("multiply", values).ToString();
139+
}
140+
141+
public static string Divide(double divisor, double? min = null)
142+
{
143+
if (Double.IsNaN(divisor) || Double.IsInfinity(divisor))
144+
{
145+
throw new ArgumentException("Divisor cannot be NaN or Infinity", nameof(divisor));
146+
}
147+
if (min.HasValue && (Double.IsNaN(min.Value) || Double.IsInfinity(min.Value)))
148+
{
149+
throw new ArgumentException("Min cannot be NaN or Infinity", nameof(min));
150+
}
151+
if (divisor == 0)
152+
{
153+
throw new ArgumentException("Divisor cannot be zero", nameof(divisor));
154+
}
155+
var values = new List<object> { divisor };
156+
if (min.HasValue)
157+
{
158+
values.Add(min.Value);
159+
}
160+
return new Operator("divide", values).ToString();
161+
}
162+
163+
public static string Modulo(double divisor)
164+
{
165+
if (Double.IsNaN(divisor) || Double.IsInfinity(divisor))
166+
{
167+
throw new ArgumentException("Divisor cannot be NaN or Infinity", nameof(divisor));
168+
}
169+
if (divisor == 0)
170+
{
171+
throw new ArgumentException("Divisor cannot be zero", nameof(divisor));
172+
}
173+
return new Operator("modulo", new List<object> { divisor }).ToString();
174+
}
175+
176+
public static string Power(double exponent, double? max = null)
177+
{
178+
if (Double.IsNaN(exponent) || Double.IsInfinity(exponent))
179+
{
180+
throw new ArgumentException("Exponent cannot be NaN or Infinity", nameof(exponent));
181+
}
182+
if (max.HasValue && (Double.IsNaN(max.Value) || Double.IsInfinity(max.Value)))
183+
{
184+
throw new ArgumentException("Max cannot be NaN or Infinity", nameof(max));
185+
}
186+
var values = new List<object> { exponent };
187+
if (max.HasValue)
188+
{
189+
values.Add(max.Value);
190+
}
191+
return new Operator("power", values).ToString();
192+
}
193+
194+
public static string ArrayAppend(List<object> values)
195+
{
196+
if (values == null)
197+
{
198+
throw new ArgumentNullException(nameof(values));
199+
}
200+
return new Operator("arrayAppend", values).ToString();
201+
}
202+
203+
public static string ArrayPrepend(List<object> values)
204+
{
205+
if (values == null)
206+
{
207+
throw new ArgumentNullException(nameof(values));
208+
}
209+
return new Operator("arrayPrepend", values).ToString();
210+
}
211+
212+
public static string ArrayInsert(int index, object value)
213+
{
214+
return new Operator("arrayInsert", new List<object> { index, value }).ToString();
215+
}
216+
217+
public static string ArrayRemove(object value)
218+
{
219+
return new Operator("arrayRemove", new List<object> { value }).ToString();
220+
}
221+
222+
public static string ArrayUnique()
223+
{
224+
return new Operator("arrayUnique", new List<object>()).ToString();
225+
}
226+
227+
public static string ArrayIntersect(List<object> values)
228+
{
229+
if (values == null)
230+
{
231+
throw new ArgumentNullException(nameof(values));
232+
}
233+
return new Operator("arrayIntersect", values).ToString();
234+
}
235+
236+
public static string ArrayDiff(List<object> values)
237+
{
238+
if (values == null)
239+
{
240+
throw new ArgumentNullException(nameof(values));
241+
}
242+
return new Operator("arrayDiff", values).ToString();
243+
}
244+
245+
public static string ArrayFilter(Condition condition, object? value = null)
246+
{
247+
var values = new List<object?> { condition.ToValue(), value };
248+
return new Operator("arrayFilter", values).ToString();
249+
}
250+
251+
public static string StringConcat(object value)
252+
{
253+
return new Operator("stringConcat", new List<object> { value }).ToString();
254+
}
255+
256+
public static string StringReplace(string search, string replace)
257+
{
258+
return new Operator("stringReplace", new List<object> { search, replace }).ToString();
259+
}
260+
261+
public static string Toggle()
262+
{
263+
return new Operator("toggle", new List<object>()).ToString();
264+
}
265+
266+
public static string DateAddDays(int days)
267+
{
268+
return new Operator("dateAddDays", new List<object> { days }).ToString();
269+
}
270+
271+
public static string DateSubDays(int days)
272+
{
273+
return new Operator("dateSubDays", new List<object> { days }).ToString();
274+
}
275+
276+
public static string DateSetNow()
277+
{
278+
return new Operator("dateSetNow", new List<object>()).ToString();
279+
}
280+
}
281+
}

Appwrite/Query.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,27 @@ public static string NotEndsWith(string attribute, string value) {
183183
}
184184

185185
public static string CreatedBefore(string value) {
186-
return new Query("createdBefore", null, value).ToString();
186+
return LessThan("$createdAt", value);
187187
}
188188

189189
public static string CreatedAfter(string value) {
190-
return new Query("createdAfter", null, value).ToString();
190+
return GreaterThan("$createdAt", value);
191191
}
192192

193193
public static string CreatedBetween(string start, string end) {
194-
return new Query("createdBetween", null, new List<string> { start, end }).ToString();
194+
return Between("$createdAt", start, end);
195195
}
196196

197197
public static string UpdatedBefore(string value) {
198-
return new Query("updatedBefore", null, value).ToString();
198+
return LessThan("$updatedAt", value);
199199
}
200200

201201
public static string UpdatedAfter(string value) {
202-
return new Query("updatedAfter", null, value).ToString();
202+
return GreaterThan("$updatedAt", value);
203203
}
204204

205205
public static string UpdatedBetween(string start, string end) {
206-
return new Query("updatedBetween", null, new List<string> { start, end }).ToString();
206+
return Between("$updatedAt", start, end);
207207
}
208208

209209
public static string Or(List<string> queries) {

Appwrite/Services/Account.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ static Models.User Convert(Dictionary<string, object> it) =>
126126
/// Get the list of identities for the currently logged in user.
127127
/// </para>
128128
/// </summary>
129-
public Task<Models.IdentityList> ListIdentities(List<string>? queries = null)
129+
public Task<Models.IdentityList> ListIdentities(List<string>? queries = null, bool? total = null)
130130
{
131131
var apiPath = "/account/identities";
132132

133133
var apiParameters = new Dictionary<string, object?>()
134134
{
135-
{ "queries", queries }
135+
{ "queries", queries },
136+
{ "total", total }
136137
};
137138

138139
var apiHeaders = new Dictionary<string, string>()
@@ -219,13 +220,14 @@ static Models.JWT Convert(Dictionary<string, object> it) =>
219220
/// user. Each log returns user IP address, location and date and time of log.
220221
/// </para>
221222
/// </summary>
222-
public Task<Models.LogList> ListLogs(List<string>? queries = null)
223+
public Task<Models.LogList> ListLogs(List<string>? queries = null, bool? total = null)
223224
{
224225
var apiPath = "/account/logs";
225226

226227
var apiParameters = new Dictionary<string, object?>()
227228
{
228-
{ "queries", queries }
229+
{ "queries", queries },
230+
{ "total", total }
229231
};
230232

231233
var apiHeaders = new Dictionary<string, string>()

0 commit comments

Comments
 (0)