Skip to content

Commit 6287998

Browse files
committed
Inline convert queries to JSON to avoid changing method parameter types
1 parent e99e74d commit 6287998

File tree

15 files changed

+411
-433
lines changed

15 files changed

+411
-433
lines changed

src/SDK/Language/Deno.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ public function getTypeName(array $parameter, array $spec = []): string
140140
if (!empty($parameter['enumValues'])) {
141141
return \ucfirst($parameter['name']);
142142
}
143-
if (!empty($parameter['name']) && $parameter['name'] === 'queries') {
144-
return 'Query[]';
145-
}
146143
return match ($parameter['type']) {
147144
self::TYPE_INTEGER => 'number',
148145
self::TYPE_STRING => 'string',

src/SDK/Language/JS.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ public function getTypeName(array $parameter, array $spec = []): string
131131
if (!empty($parameter['enumValues'])) {
132132
return \ucfirst($parameter['name']);
133133
}
134-
if (!empty($parameter['name']) && $parameter['name'] === 'queries') {
135-
return 'Query[]';
136-
}
137134
switch ($parameter['type']) {
138135
case self::TYPE_INTEGER:
139136
case self::TYPE_NUMBER:

src/SDK/Language/Node.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public function getTypeName(array $parameter, array $spec = []): string
2525
if (!empty($parameter['enumValues'])) {
2626
return \ucfirst($parameter['name']);
2727
}
28-
if (!empty($parameter['name']) && $parameter['name'] === 'queries') {
29-
return 'Query[]';
30-
}
3128
return match ($parameter['type']) {
3229
self::TYPE_INTEGER,
3330
self::TYPE_NUMBER => 'number',

src/SDK/Language/Web.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ public function getTypeName(array $parameter, array $method = []): string
185185
if (!empty($parameter['enumValues'])) {
186186
return \ucfirst($parameter['name']);
187187
}
188-
if (!empty($parameter['name']) && $parameter['name'] === 'queries') {
189-
return 'Query[]';
190-
}
191188
switch ($parameter['type']) {
192189
case self::TYPE_INTEGER:
193190
case self::TYPE_NUMBER:

templates/android/library/src/main/java/io/appwrite/Query.kt.twig

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,58 @@
11
package {{ sdk.namespace | caseDot }}
22

3-
import com.google.gson.Gson
3+
import {{ sdk.namespace | caseDot }}.extensions.toJson
44

55
class Query(
66
val method: String,
77
val attribute: String? = null,
88
val values: List<Any>? = null,
99
) {
10-
override fun toString() = gson.toJson(this)
10+
override fun toString() = this.toJson()
1111

1212
companion object {
13-
private val gson = Gson()
13+
fun equal(attribute: String, value: Any) = Query("equal", attribute, parseValue(value)).toJson()
1414

15-
fun equal(attribute: String, value: Any) = Query("equal", attribute, parseValue(value))
15+
fun notEqual(attribute: String, value: Any) = Query("notEqual", attribute, parseValue(value)).toJson()
1616

17-
fun notEqual(attribute: String, value: Any) = Query("notEqual", attribute, listOf(value))
17+
fun lessThan(attribute: String, value: Any) = Query("lessThan", attribute, parseValue(value)).toJson()
1818

19-
fun lessThan(attribute: String, value: Any) = Query("lessThan", attribute, listOf(value))
19+
fun lessThanEqual(attribute: String, value: Any) = Query("lessThanEqual", attribute, parseValue(value)).toJson()
2020

21-
fun lessThanEqual(attribute: String, value: Any) = Query("lessThanEqual", attribute, listOf(value))
21+
fun greaterThan(attribute: String, value: Any) = Query("greaterThan", attribute, parseValue(value)).toJson()
2222

23-
fun greaterThan(attribute: String, value: Any) = Query("greaterThan", attribute, listOf(value))
23+
fun greaterThanEqual(attribute: String, value: Any) = Query("greaterThanEqual", attribute, parseValue(value)).toJson()
2424

25-
fun greaterThanEqual(attribute: String, value: Any) = Query("greaterThanEqual", attribute, listOf(value))
25+
fun search(attribute: String, value: String) = Query("search", attribute, listOf(value)).toJson()
2626

27-
fun search(attribute: String, value: String) = Query("search", attribute, listOf(value))
27+
fun isNull(attribute: String) = Query("isNull", attribute).toJson()
2828

29-
fun isNull(attribute: String) = Query("isNull", attribute)
29+
fun isNotNull(attribute: String) = Query("isNotNull", attribute).toJson()
3030

31-
fun isNotNull(attribute: String) = Query("isNotNull", attribute)
31+
fun between(attribute: String, start: Any, end: Any) = Query("between", attribute, listOf(start, end)).toJson()
3232

33-
fun between(attribute: String, start: Any, end: Any) = Query("between", attribute, listOf(start, end))
33+
fun startsWith(attribute: String, value: String) = Query("startsWith", attribute, listOf(value)).toJson()
3434

35-
fun startsWith(attribute: String, value: String) = Query("startsWith", attribute, listOf(value))
35+
fun endsWith(attribute: String, value: String) = Query("endsWith", attribute, listOf(value)).toJson()
3636

37-
fun endsWith(attribute: String, value: String) = Query("endsWith", attribute, listOf(value))
37+
fun select(attributes: List<String>) = Query("select", null, attributes).toJson()
3838

39-
fun select(attributes: List<String>) = Query("select", null, attributes)
39+
fun orderAsc(attribute: String) = Query("orderAsc", attribute).toJson()
4040

41-
fun orderAsc(attribute: String) = Query("orderAsc", attribute)
41+
fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson()
4242

43-
fun orderDesc(attribute: String) = Query("orderDesc", attribute)
43+
fun cursorBefore(documentId: String) = Query("cursorBefore", null, listOf(documentId)).toJson()
4444

45-
fun cursorBefore(documentId: String) = Query("cursorBefore", null, listOf(documentId))
45+
fun cursorAfter(documentId: String) = Query("cursorAfter", null, listOf(documentId)).toJson()
4646

47-
fun cursorAfter(documentId: String) = Query("cursorAfter", null, listOf(documentId))
47+
fun limit(limit: Int) = Query("limit", null, listOf(limit)).toJson()
4848

49-
fun limit(limit: Int) = Query("limit", null, listOf(limit))
49+
fun offset(offset: Int) = Query("offset", null, listOf(offset)).toJson()
5050

51-
fun offset(offset: Int) = Query("offset", null, listOf(offset))
51+
fun contains(attribute: String, value: Any) = Query("contains", attribute, parseValue(value)).toJson()
5252

53-
fun contains(attribute: String, value: Any) = Query("contains", attribute, parseValue(value))
53+
fun or(queries: List<Query>) = Query("or", null, queries).toJson()
5454

55-
fun or(queries: List<Query>) = Query("or", null, queries)
56-
57-
fun and(queries: List<Query>) = Query("and", null, queries)
55+
fun and(queries: List<Query>) = Query("and", null, queries).toJson()
5856

5957
private fun parseValue(value: Any): List<Any> {
6058
return when (value) {

templates/dart/lib/query.dart.twig

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,89 +33,89 @@ class Query {
3333
/// [value] can be a single value or a list. If a list is used
3434
/// the query will return resources where [attribute] is equal
3535
/// to any of the values in the list.
36-
static Query equal(String attribute, dynamic value) =>
37-
Query._('equal', attribute, value);
36+
static string equal(String attribute, dynamic value) =>
37+
Query._('equal', attribute, value).toJson();
3838

3939
/// Filter resources where [attribute] is not equal to [value].
40-
static Query notEqual(String attribute, dynamic value) =>
41-
Query._('notEqual', attribute, [value]);
40+
static string notEqual(String attribute, dynamic value) =>
41+
Query._('notEqual', attribute, [value]).toJson();
4242

4343
/// Filter resources where [attribute] is less than [value].
44-
static Query lessThan(String attribute, dynamic value) =>
45-
Query._('lessThan', attribute, value);
44+
static string lessThan(String attribute, dynamic value) =>
45+
Query._('lessThan', attribute, value).toJson();
4646

4747
/// Filter resources where [attribute] is less than or equal to [value].
48-
static Query lessThanEqual(String attribute, dynamic value) =>
49-
Query._('lessThanEqual', attribute, value);
48+
static string lessThanEqual(String attribute, dynamic value) =>
49+
Query._('lessThanEqual', attribute, value).toJson();
5050

5151
/// Filter resources where [attribute] is greater than [value].
52-
static Query greaterThan(String attribute, dynamic value) =>
53-
Query._('greaterThan', attribute, value);
52+
static string greaterThan(String attribute, dynamic value) =>
53+
Query._('greaterThan', attribute, value).toJson();
5454

5555
/// Filter resources where [attribute] is greater than or equal to [value].
56-
static Query greaterThanEqual(String attribute, dynamic value) =>
57-
Query._('greaterThanEqual', attribute, value);
56+
static string greaterThanEqual(String attribute, dynamic value) =>
57+
Query._('greaterThanEqual', attribute, value).toJson();
5858

5959
/// Filter resources where by searching [attribute] for [value].
60-
static Query search(String attribute, String value) =>
61-
Query._('search', attribute, value);
60+
static string search(String attribute, String value) =>
61+
Query._('search', attribute, value).toJson();
6262

6363
/// Filter resources where [attribute] is null.
64-
static Query isNull(String attribute) => Query._('isNull', attribute);
64+
static string isNull(String attribute) => Query._('isNull', attribute).toJson();
6565

6666
/// Filter resources where [attribute] is not null.
67-
static Query isNotNull(String attribute) => Query._('isNotNull', attribute);
67+
static string isNotNull(String attribute) => Query._('isNotNull', attribute).toJson();
6868

6969
/// Filter resources where [attribute] is between [start] and [end] (inclusive).
70-
static Query between(String attribute, dynamic start, dynamic end) =>
71-
Query._('between', attribute, [start, end]);
70+
static string between(String attribute, dynamic start, dynamic end) =>
71+
Query._('between', attribute, [start, end]).toJson();
7272

7373
/// Filter resources where [attribute] starts with [value].
74-
static Query startsWith(String attribute, String value) =>
75-
Query._('startsWith', attribute, value);
74+
static string startsWith(String attribute, String value) =>
75+
Query._('startsWith', attribute, value).toJson();
7676

7777
/// Filter resources where [attribute] ends with [value].
78-
static Query endsWith(String attribute, String value) =>
79-
Query._('endsWith', attribute, value);
78+
static string endsWith(String attribute, String value) =>
79+
Query._('endsWith', attribute, value).toJson();
8080

8181
/// Filter resouorces where [attribute] contains [value]
8282
/// [value] can be a single value or a list.
83-
static Query contains(String attribute, dynamic value) =>
84-
Query._('contains', attribute, value);
83+
static string contains(String attribute, dynamic value) =>
84+
Query._('contains', attribute, value).toJson();
8585

86-
static Query or(List<Query> queries) => Query._('or', null, queries);
86+
static string or(List<Query> queries) => Query._('or', null, queries).toJson();
8787

88-
static Query and(List<Query> queries) => Query._('and', null, queries);
88+
static string and(List<Query> queries) => Query._('and', null, queries).toJson();
8989

9090
/// Specify which attributes should be returned by the API call.
91-
static Query select(List<String> attributes) =>
92-
Query._('select', null, attributes);
91+
static string select(List<String> attributes) =>
92+
Query._('select', null, attributes).toJson();
9393

9494
/// Sort results by [attribute] ascending.
95-
static Query orderAsc(String attribute) => Query._('orderAsc', attribute);
95+
static string orderAsc(String attribute) => Query._('orderAsc', attribute).toJson();
9696

9797
/// Sort results by [attribute] descending.
98-
static Query orderDesc(String attribute) => Query._('orderDesc', attribute);
98+
static string orderDesc(String attribute) => Query._('orderDesc', attribute).toJson();
9999

100100
/// Return results before [id].
101101
///
102102
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)
103103
/// docs for more information.
104-
static Query cursorBefore(String id) => Query._('cursorBefore', null, id);
104+
static string cursorBefore(String id) => Query._('cursorBefore', null, id).toJson();
105105

106106
/// Return results after [id].
107107
///
108108
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)
109109
/// docs for more information.
110-
static Query cursorAfter(String id) => Query._('cursorAfter', null, id);
110+
static string cursorAfter(String id) => Query._('cursorAfter', null, id).toJson();
111111

112112
/// Return only [limit] results.
113-
static Query limit(int limit) => Query._('limit', null, limit);
113+
static string limit(int limit) => Query._('limit', null, limit).toJson();
114114

115115
/// Return results from [offset].
116116
///
117117
/// Refer to the [Offset Pagination]({{sdk.url}}/docs/pagination#offset-pagination)
118118
/// docs for more information.
119-
static Query offset(int offset) => Query._('offset', null, offset);
119+
static string offset(int offset) => Query._('offset', null, offset).toJson();
120120

121121
}

templates/deno/src/query.ts.twig

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,80 +33,80 @@ export class Query {
3333
});
3434
}
3535

36-
static equal = (attribute: string, value: QueryTypes): Query =>
37-
new Query("equal", attribute, value);
36+
static equal = (attribute: string, value: QueryTypes): string =>
37+
new Query("equal", attribute, value).toString();
3838

39-
static notEqual = (attribute: string, value: QueryTypes): Query =>
40-
new Query("notEqual", attribute, value);
39+
static notEqual = (attribute: string, value: QueryTypes): string =>
40+
new Query("notEqual", attribute, value).toString();
4141

42-
static lessThan = (attribute: string, value: QueryTypes): Query =>
43-
new Query("lessThan", attribute, value);
42+
static lessThan = (attribute: string, value: QueryTypes): string =>
43+
new Query("lessThan", attribute, value).toString();
4444

45-
static lessThanEqual = (attribute: string, value: QueryTypes): Query =>
46-
new Query("lessThanEqual", attribute, value);
45+
static lessThanEqual = (attribute: string, value: QueryTypes): string =>
46+
new Query("lessThanEqual", attribute, value).toString();
4747

48-
static greaterThan = (attribute: string, value: QueryTypes): Query =>
49-
new Query("greaterThan", attribute, value);
48+
static greaterThan = (attribute: string, value: QueryTypes): string =>
49+
new Query("greaterThan", attribute, value).toString();
5050

51-
static greaterThanEqual = (attribute: string, value: QueryTypes): Query =>
52-
new Query("greaterThanEqual", attribute, value);
51+
static greaterThanEqual = (attribute: string, value: QueryTypes): string =>
52+
new Query("greaterThanEqual", attribute, value).toString();
5353

54-
static isNull = (attribute: string): Query => new Query("isNull", attribute);
54+
static isNull = (attribute: string): string => new Query("isNull", attribute);
5555

56-
static isNotNull = (attribute: string): Query =>
57-
new Query("isNotNull", attribute);
56+
static isNotNull = (attribute: string): string =>
57+
new Query("isNotNull", attribute).toString();
5858

5959
static between = (
6060
attribute: string,
6161
start: string | number,
6262
end: string | number
63-
) => new Query("between", attribute, [start, end] as QueryTypesList);
63+
) => new Query("between", attribute, [start, end] as QueryTypesList).toString();
6464

65-
static startsWith = (attribute: string, value: string): Query =>
66-
new Query("startsWith", attribute, value);
65+
static startsWith = (attribute: string, value: string): string =>
66+
new Query("startsWith", attribute, value).toString();
6767

68-
static endsWith = (attribute: string, value: string): Query =>
69-
new Query("endsWith", attribute, value);
68+
static endsWith = (attribute: string, value: string): string =>
69+
new Query("endsWith", attribute, value).toString();
7070

71-
static select = (attributes: string[]): Query =>
72-
new Query("select", undefined, attributes);
71+
static select = (attributes: string[]): string =>
72+
new Query("select", undefined, attributes).toString();
7373

74-
static search = (attribute: string, value: string): Query =>
75-
new Query("search", attribute, value);
74+
static search = (attribute: string, value: string): string =>
75+
new Query("search", attribute, value).toString();
7676

77-
static orderDesc = (attribute: string): Query =>
78-
new Query("orderDesc", attribute);
77+
static orderDesc = (attribute: string): string =>
78+
new Query("orderDesc", attribute).toString();
7979

80-
static orderAsc = (attribute: string): Query =>
81-
new Query("orderAsc", attribute);
80+
static orderAsc = (attribute: string): string =>
81+
new Query("orderAsc", attribute).toString();
8282

83-
static cursorAfter = (documentId: string): Query =>
84-
new Query("cursorAfter", undefined, documentId);
83+
static cursorAfter = (documentId: string): string =>
84+
new Query("cursorAfter", undefined, documentId).toString();
8585

86-
static cursorBefore = (documentId: string): Query =>
87-
new Query("cursorBefore", undefined, documentId);
86+
static cursorBefore = (documentId: string): string =>
87+
new Query("cursorBefore", undefined, documentId).toString();
8888

89-
static limit = (limit: number): Query => new Query("limit", undefined, limit);
89+
static limit = (limit: number): string => new Query("limit", undefined, limit).toString();
9090

91-
static offset = (offset: number): Query =>
92-
new Query("offset", undefined, offset);
91+
static offset = (offset: number): string =>
92+
new Query("offset", undefined, offset).toString();
9393

94-
static contains = (attribute: string, value: string | string[]): Query =>
95-
new Query("contains", attribute, value);
94+
static contains = (attribute: string, value: string | string[]): string =>
95+
new Query("contains", attribute, value).toString();
9696

9797
static or = (...queries: Query[]) => {
9898
return new Query(
9999
"or",
100100
undefined,
101101
queries
102-
);
102+
).toString();
103103
};
104104

105105
static and = (...queries: Query[]) => {
106106
return new Query(
107107
"and",
108108
undefined,
109109
queries
110-
);
110+
).toString();
111111
};
112112
}

0 commit comments

Comments
 (0)