@revenexx/sdk 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +148 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/sdk.js +16340 -0
- package/dist/cjs/sdk.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/sdk.js +16250 -0
- package/dist/esm/sdk.js.map +1 -0
- package/dist/iife/sdk.js +20101 -0
- package/package.json +56 -0
- package/src/channel.ts +158 -0
- package/src/client.ts +950 -0
- package/src/enums/adapter.ts +4 -0
- package/src/enums/attribute-boolean-status.ts +7 -0
- package/src/enums/attribute-datetime-status.ts +7 -0
- package/src/enums/attribute-email-status.ts +7 -0
- package/src/enums/attribute-enum-status.ts +7 -0
- package/src/enums/attribute-float-status.ts +7 -0
- package/src/enums/attribute-integer-status.ts +7 -0
- package/src/enums/attribute-ip-status.ts +7 -0
- package/src/enums/attribute-line-status.ts +7 -0
- package/src/enums/attribute-longtext-status.ts +7 -0
- package/src/enums/attribute-mediumtext-status.ts +7 -0
- package/src/enums/attribute-point-status.ts +7 -0
- package/src/enums/attribute-polygon-status.ts +7 -0
- package/src/enums/attribute-relationship-status.ts +7 -0
- package/src/enums/attribute-string-status.ts +7 -0
- package/src/enums/attribute-text-status.ts +7 -0
- package/src/enums/attribute-url-status.ts +7 -0
- package/src/enums/attribute-varchar-status.ts +7 -0
- package/src/enums/build-runtime.ts +73 -0
- package/src/enums/code.ts +16 -0
- package/src/enums/collection.ts +4 -0
- package/src/enums/column-boolean-status.ts +7 -0
- package/src/enums/column-datetime-status.ts +7 -0
- package/src/enums/column-email-status.ts +7 -0
- package/src/enums/column-enum-status.ts +7 -0
- package/src/enums/column-float-status.ts +7 -0
- package/src/enums/column-integer-status.ts +7 -0
- package/src/enums/column-ip-status.ts +7 -0
- package/src/enums/column-line-status.ts +7 -0
- package/src/enums/column-longtext-status.ts +7 -0
- package/src/enums/column-mediumtext-status.ts +7 -0
- package/src/enums/column-point-status.ts +7 -0
- package/src/enums/column-polygon-status.ts +7 -0
- package/src/enums/column-relationship-status.ts +7 -0
- package/src/enums/column-string-status.ts +7 -0
- package/src/enums/column-text-status.ts +7 -0
- package/src/enums/column-url-status.ts +7 -0
- package/src/enums/column-varchar-status.ts +7 -0
- package/src/enums/compression.ts +5 -0
- package/src/enums/database-type.ts +4 -0
- package/src/enums/deployment-status.ts +8 -0
- package/src/enums/execution-status.ts +7 -0
- package/src/enums/execution-trigger.ts +5 -0
- package/src/enums/framework.ts +17 -0
- package/src/enums/gravity.ts +11 -0
- package/src/enums/health-antivirus-status.ts +5 -0
- package/src/enums/health-status-status.ts +4 -0
- package/src/enums/index-status.ts +7 -0
- package/src/enums/message-status.ts +7 -0
- package/src/enums/method.ts +9 -0
- package/src/enums/output.ts +9 -0
- package/src/enums/permissions.ts +22 -0
- package/src/enums/priority.ts +4 -0
- package/src/enums/range.ts +5 -0
- package/src/enums/runtime.ts +73 -0
- package/src/enums/runtimes.ts +73 -0
- package/src/enums/scopes.ts +57 -0
- package/src/enums/theme.ts +4 -0
- package/src/enums/timezone.ts +421 -0
- package/src/enums/type.ts +5 -0
- package/src/enums/use-cases.ts +9 -0
- package/src/id.ts +47 -0
- package/src/index.ts +92 -0
- package/src/models.ts +6013 -0
- package/src/operator.ts +308 -0
- package/src/permission.ts +57 -0
- package/src/query.ts +576 -0
- package/src/role.ts +100 -0
- package/src/service.ts +30 -0
- package/src/services/apps.ts +2473 -0
- package/src/services/avatars.ts +744 -0
- package/src/services/carts.ts +1057 -0
- package/src/services/channels.ts +227 -0
- package/src/services/customers.ts +729 -0
- package/src/services/greetings.ts +294 -0
- package/src/services/locale.ts +198 -0
- package/src/services/markets.ts +796 -0
- package/src/services/messaging.ts +3463 -0
- package/src/services/products.ts +3100 -0
- package/src/services/realtime.ts +537 -0
- package/src/services/search.ts +346 -0
- package/src/services/sites.ts +1847 -0
- package/src/services/storage.ts +1076 -0
- package/src/services/tokens.ts +314 -0
- package/types/channel.d.ts +74 -0
- package/types/client.d.ts +211 -0
- package/types/enums/adapter.d.ts +4 -0
- package/types/enums/attribute-boolean-status.d.ts +7 -0
- package/types/enums/attribute-datetime-status.d.ts +7 -0
- package/types/enums/attribute-email-status.d.ts +7 -0
- package/types/enums/attribute-enum-status.d.ts +7 -0
- package/types/enums/attribute-float-status.d.ts +7 -0
- package/types/enums/attribute-integer-status.d.ts +7 -0
- package/types/enums/attribute-ip-status.d.ts +7 -0
- package/types/enums/attribute-line-status.d.ts +7 -0
- package/types/enums/attribute-longtext-status.d.ts +7 -0
- package/types/enums/attribute-mediumtext-status.d.ts +7 -0
- package/types/enums/attribute-point-status.d.ts +7 -0
- package/types/enums/attribute-polygon-status.d.ts +7 -0
- package/types/enums/attribute-relationship-status.d.ts +7 -0
- package/types/enums/attribute-string-status.d.ts +7 -0
- package/types/enums/attribute-text-status.d.ts +7 -0
- package/types/enums/attribute-url-status.d.ts +7 -0
- package/types/enums/attribute-varchar-status.d.ts +7 -0
- package/types/enums/build-runtime.d.ts +73 -0
- package/types/enums/code.d.ts +16 -0
- package/types/enums/collection.d.ts +4 -0
- package/types/enums/column-boolean-status.d.ts +7 -0
- package/types/enums/column-datetime-status.d.ts +7 -0
- package/types/enums/column-email-status.d.ts +7 -0
- package/types/enums/column-enum-status.d.ts +7 -0
- package/types/enums/column-float-status.d.ts +7 -0
- package/types/enums/column-integer-status.d.ts +7 -0
- package/types/enums/column-ip-status.d.ts +7 -0
- package/types/enums/column-line-status.d.ts +7 -0
- package/types/enums/column-longtext-status.d.ts +7 -0
- package/types/enums/column-mediumtext-status.d.ts +7 -0
- package/types/enums/column-point-status.d.ts +7 -0
- package/types/enums/column-polygon-status.d.ts +7 -0
- package/types/enums/column-relationship-status.d.ts +7 -0
- package/types/enums/column-string-status.d.ts +7 -0
- package/types/enums/column-text-status.d.ts +7 -0
- package/types/enums/column-url-status.d.ts +7 -0
- package/types/enums/column-varchar-status.d.ts +7 -0
- package/types/enums/compression.d.ts +5 -0
- package/types/enums/database-type.d.ts +4 -0
- package/types/enums/deployment-status.d.ts +8 -0
- package/types/enums/execution-status.d.ts +7 -0
- package/types/enums/execution-trigger.d.ts +5 -0
- package/types/enums/framework.d.ts +17 -0
- package/types/enums/gravity.d.ts +11 -0
- package/types/enums/health-antivirus-status.d.ts +5 -0
- package/types/enums/health-status-status.d.ts +4 -0
- package/types/enums/index-status.d.ts +7 -0
- package/types/enums/message-status.d.ts +7 -0
- package/types/enums/method.d.ts +9 -0
- package/types/enums/output.d.ts +9 -0
- package/types/enums/permissions.d.ts +22 -0
- package/types/enums/priority.d.ts +4 -0
- package/types/enums/range.d.ts +5 -0
- package/types/enums/runtime.d.ts +73 -0
- package/types/enums/runtimes.d.ts +73 -0
- package/types/enums/scopes.d.ts +57 -0
- package/types/enums/theme.d.ts +4 -0
- package/types/enums/timezone.d.ts +421 -0
- package/types/enums/type.d.ts +5 -0
- package/types/enums/use-cases.d.ts +9 -0
- package/types/id.d.ts +20 -0
- package/types/index.d.ts +92 -0
- package/types/models.d.ts +5830 -0
- package/types/operator.d.ts +180 -0
- package/types/permission.d.ts +43 -0
- package/types/query.d.ts +442 -0
- package/types/role.d.ts +70 -0
- package/types/service.d.ts +11 -0
- package/types/services/apps.d.ts +932 -0
- package/types/services/avatars.d.ts +318 -0
- package/types/services/carts.d.ts +352 -0
- package/types/services/channels.d.ts +75 -0
- package/types/services/customers.d.ts +231 -0
- package/types/services/greetings.d.ts +101 -0
- package/types/services/locale.d.ts +64 -0
- package/types/services/markets.d.ts +274 -0
- package/types/services/messaging.d.ts +1324 -0
- package/types/services/products.d.ts +1014 -0
- package/types/services/realtime.d.ts +134 -0
- package/types/services/search.d.ts +131 -0
- package/types/services/sites.d.ts +689 -0
- package/types/services/storage.d.ts +421 -0
- package/types/services/tokens.d.ts +119 -0
package/src/query.ts
ADDED
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import JSONbigModule from 'json-bigint';
|
|
2
|
+
const JSONbig = JSONbigModule({ useNativeBigInt: true });
|
|
3
|
+
|
|
4
|
+
type QueryTypesSingle = string | number | bigint | boolean;
|
|
5
|
+
export type QueryTypesList = string[] | number[] | bigint[] | boolean[] | Query[] | any[];
|
|
6
|
+
export type QueryTypes = QueryTypesSingle | QueryTypesList;
|
|
7
|
+
type AttributesTypes = string | string[];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Helper class to generate query strings.
|
|
11
|
+
*/
|
|
12
|
+
export class Query {
|
|
13
|
+
method: string;
|
|
14
|
+
attribute: AttributesTypes | undefined;
|
|
15
|
+
values: QueryTypesList | undefined;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constructor for Query class.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} method
|
|
21
|
+
* @param {AttributesTypes} attribute
|
|
22
|
+
* @param {QueryTypes} values
|
|
23
|
+
*/
|
|
24
|
+
constructor(
|
|
25
|
+
method: string,
|
|
26
|
+
attribute?: AttributesTypes,
|
|
27
|
+
values?: QueryTypes
|
|
28
|
+
) {
|
|
29
|
+
this.method = method;
|
|
30
|
+
this.attribute = attribute;
|
|
31
|
+
|
|
32
|
+
if (values !== undefined) {
|
|
33
|
+
if (Array.isArray(values)) {
|
|
34
|
+
this.values = values;
|
|
35
|
+
} else {
|
|
36
|
+
this.values = [values] as QueryTypesList;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Convert the query object to a JSON string.
|
|
43
|
+
*
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
toString(): string {
|
|
47
|
+
return JSONbig.stringify({
|
|
48
|
+
method: this.method,
|
|
49
|
+
attribute: this.attribute,
|
|
50
|
+
values: this.values,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Filter resources where attribute is equal to value.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} attribute
|
|
58
|
+
* @param {QueryTypes} value
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
static equal = (attribute: string, value: QueryTypes): string =>
|
|
62
|
+
new Query("equal", attribute, value).toString();
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Filter resources where attribute is not equal to value.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} attribute
|
|
68
|
+
* @param {QueryTypes} value
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
static notEqual = (attribute: string, value: QueryTypes): string =>
|
|
72
|
+
new Query("notEqual", attribute, value).toString();
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Filter resources where attribute matches a regular expression pattern.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} attribute The attribute to filter on.
|
|
78
|
+
* @param {string} pattern The regular expression pattern to match.
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
static regex = (attribute: string, pattern: string): string =>
|
|
82
|
+
new Query("regex", attribute, pattern).toString();
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Filter resources where attribute is less than value.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} attribute
|
|
88
|
+
* @param {QueryTypes} value
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
static lessThan = (attribute: string, value: QueryTypes): string =>
|
|
92
|
+
new Query("lessThan", attribute, value).toString();
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Filter resources where attribute is less than or equal to value.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} attribute
|
|
98
|
+
* @param {QueryTypes} value
|
|
99
|
+
* @returns {string}
|
|
100
|
+
*/
|
|
101
|
+
static lessThanEqual = (attribute: string, value: QueryTypes): string =>
|
|
102
|
+
new Query("lessThanEqual", attribute, value).toString();
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Filter resources where attribute is greater than value.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} attribute
|
|
108
|
+
* @param {QueryTypes} value
|
|
109
|
+
* @returns {string}
|
|
110
|
+
*/
|
|
111
|
+
static greaterThan = (attribute: string, value: QueryTypes): string =>
|
|
112
|
+
new Query("greaterThan", attribute, value).toString();
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Filter resources where attribute is greater than or equal to value.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} attribute
|
|
118
|
+
* @param {QueryTypes} value
|
|
119
|
+
* @returns {string}
|
|
120
|
+
*/
|
|
121
|
+
static greaterThanEqual = (attribute: string, value: QueryTypes): string =>
|
|
122
|
+
new Query("greaterThanEqual", attribute, value).toString();
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Filter resources where attribute is null.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} attribute
|
|
128
|
+
* @returns {string}
|
|
129
|
+
*/
|
|
130
|
+
static isNull = (attribute: string): string =>
|
|
131
|
+
new Query("isNull", attribute).toString();
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Filter resources where attribute is not null.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} attribute
|
|
137
|
+
* @returns {string}
|
|
138
|
+
*/
|
|
139
|
+
static isNotNull = (attribute: string): string =>
|
|
140
|
+
new Query("isNotNull", attribute).toString();
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Filter resources where the specified attributes exist.
|
|
144
|
+
*
|
|
145
|
+
* @param {string[]} attributes The list of attributes that must exist.
|
|
146
|
+
* @returns {string}
|
|
147
|
+
*/
|
|
148
|
+
static exists = (attributes: string[]): string =>
|
|
149
|
+
new Query("exists", undefined, attributes).toString();
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Filter resources where the specified attributes do not exist.
|
|
153
|
+
*
|
|
154
|
+
* @param {string[]} attributes The list of attributes that must not exist.
|
|
155
|
+
* @returns {string}
|
|
156
|
+
*/
|
|
157
|
+
static notExists = (attributes: string[]): string =>
|
|
158
|
+
new Query("notExists", undefined, attributes).toString();
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Filter resources where attribute is between start and end (inclusive).
|
|
162
|
+
*
|
|
163
|
+
* @param {string} attribute
|
|
164
|
+
* @param {string | number | bigint} start
|
|
165
|
+
* @param {string | number | bigint} end
|
|
166
|
+
* @returns {string}
|
|
167
|
+
*/
|
|
168
|
+
static between = (attribute: string, start: string | number | bigint, end: string | number | bigint): string =>
|
|
169
|
+
new Query("between", attribute, [start, end] as QueryTypesList).toString();
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Filter resources where attribute starts with value.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} attribute
|
|
175
|
+
* @param {string} value
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
178
|
+
static startsWith = (attribute: string, value: string): string =>
|
|
179
|
+
new Query("startsWith", attribute, value).toString();
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Filter resources where attribute ends with value.
|
|
183
|
+
*
|
|
184
|
+
* @param {string} attribute
|
|
185
|
+
* @param {string} value
|
|
186
|
+
* @returns {string}
|
|
187
|
+
*/
|
|
188
|
+
static endsWith = (attribute: string, value: string): string =>
|
|
189
|
+
new Query("endsWith", attribute, value).toString();
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Specify which attributes should be returned by the API call.
|
|
193
|
+
*
|
|
194
|
+
* @param {string[]} attributes
|
|
195
|
+
* @returns {string}
|
|
196
|
+
*/
|
|
197
|
+
static select = (attributes: string[]): string =>
|
|
198
|
+
new Query("select", undefined, attributes).toString();
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Filter resources by searching attribute for value.
|
|
202
|
+
* A fulltext index on attribute is required for this query to work.
|
|
203
|
+
*
|
|
204
|
+
* @param {string} attribute
|
|
205
|
+
* @param {string} value
|
|
206
|
+
* @returns {string}
|
|
207
|
+
*/
|
|
208
|
+
static search = (attribute: string, value: string): string =>
|
|
209
|
+
new Query("search", attribute, value).toString();
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Sort results by attribute descending.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} attribute
|
|
215
|
+
* @returns {string}
|
|
216
|
+
*/
|
|
217
|
+
static orderDesc = (attribute: string): string =>
|
|
218
|
+
new Query("orderDesc", attribute).toString();
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Sort results by attribute ascending.
|
|
222
|
+
*
|
|
223
|
+
* @param {string} attribute
|
|
224
|
+
* @returns {string}
|
|
225
|
+
*/
|
|
226
|
+
static orderAsc = (attribute: string): string =>
|
|
227
|
+
new Query("orderAsc", attribute).toString();
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Sort results randomly.
|
|
231
|
+
*
|
|
232
|
+
* @returns {string}
|
|
233
|
+
*/
|
|
234
|
+
static orderRandom = (): string =>
|
|
235
|
+
new Query("orderRandom").toString();
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Return results after documentId.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} documentId
|
|
241
|
+
* @returns {string}
|
|
242
|
+
*/
|
|
243
|
+
static cursorAfter = (documentId: string): string =>
|
|
244
|
+
new Query("cursorAfter", undefined, documentId).toString();
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Return results before documentId.
|
|
248
|
+
*
|
|
249
|
+
* @param {string} documentId
|
|
250
|
+
* @returns {string}
|
|
251
|
+
*/
|
|
252
|
+
static cursorBefore = (documentId: string): string =>
|
|
253
|
+
new Query("cursorBefore", undefined, documentId).toString();
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Return only limit results.
|
|
257
|
+
*
|
|
258
|
+
* @param {number} limit
|
|
259
|
+
* @returns {string}
|
|
260
|
+
*/
|
|
261
|
+
static limit = (limit: number): string =>
|
|
262
|
+
new Query("limit", undefined, limit).toString();
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Filter resources by skipping the first offset results.
|
|
266
|
+
*
|
|
267
|
+
* @param {number} offset
|
|
268
|
+
* @returns {string}
|
|
269
|
+
*/
|
|
270
|
+
static offset = (offset: number): string =>
|
|
271
|
+
new Query("offset", undefined, offset).toString();
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Filter resources where attribute contains the specified value.
|
|
275
|
+
* For string attributes, checks if the string contains the substring.
|
|
276
|
+
*
|
|
277
|
+
* Note: For array attributes, use {@link containsAny} or {@link containsAll} instead.
|
|
278
|
+
* @param {string} attribute
|
|
279
|
+
* @param {string | string[]} value
|
|
280
|
+
* @returns {string}
|
|
281
|
+
*/
|
|
282
|
+
static contains = (attribute: string, value: string | any[]): string =>
|
|
283
|
+
new Query("contains", attribute, value).toString();
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Filter resources where attribute contains ANY of the specified values.
|
|
287
|
+
* For array and relationship attributes, matches documents where the attribute
|
|
288
|
+
* contains at least one of the given values.
|
|
289
|
+
*
|
|
290
|
+
* @param {string} attribute
|
|
291
|
+
* @param {any[]} value
|
|
292
|
+
* @returns {string}
|
|
293
|
+
*/
|
|
294
|
+
static containsAny = (attribute: string, value: any[]): string =>
|
|
295
|
+
new Query("containsAny", attribute, value).toString();
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Filter resources where attribute contains ALL of the specified values.
|
|
299
|
+
* For array and relationship attributes, matches documents where the attribute
|
|
300
|
+
* contains every one of the given values.
|
|
301
|
+
*
|
|
302
|
+
* @param {string} attribute
|
|
303
|
+
* @param {any[]} value
|
|
304
|
+
* @returns {string}
|
|
305
|
+
*/
|
|
306
|
+
static containsAll = (attribute: string, value: any[]): string =>
|
|
307
|
+
new Query("containsAll", attribute, value).toString();
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Filter resources where attribute does not contain the specified value.
|
|
311
|
+
*
|
|
312
|
+
* @param {string} attribute
|
|
313
|
+
* @param {string | any[]} value
|
|
314
|
+
* @returns {string}
|
|
315
|
+
*/
|
|
316
|
+
static notContains = (attribute: string, value: string | any[]): string =>
|
|
317
|
+
new Query("notContains", attribute, value).toString();
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Filter resources by searching attribute for value (inverse of search).
|
|
321
|
+
* A fulltext index on attribute is required for this query to work.
|
|
322
|
+
*
|
|
323
|
+
* @param {string} attribute
|
|
324
|
+
* @param {string} value
|
|
325
|
+
* @returns {string}
|
|
326
|
+
*/
|
|
327
|
+
static notSearch = (attribute: string, value: string): string =>
|
|
328
|
+
new Query("notSearch", attribute, value).toString();
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Filter resources where attribute is not between start and end (exclusive).
|
|
332
|
+
*
|
|
333
|
+
* @param {string} attribute
|
|
334
|
+
* @param {string | number | bigint} start
|
|
335
|
+
* @param {string | number | bigint} end
|
|
336
|
+
* @returns {string}
|
|
337
|
+
*/
|
|
338
|
+
static notBetween = (attribute: string, start: string | number | bigint, end: string | number | bigint): string =>
|
|
339
|
+
new Query("notBetween", attribute, [start, end] as QueryTypesList).toString();
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Filter resources where attribute does not start with value.
|
|
343
|
+
*
|
|
344
|
+
* @param {string} attribute
|
|
345
|
+
* @param {string} value
|
|
346
|
+
* @returns {string}
|
|
347
|
+
*/
|
|
348
|
+
static notStartsWith = (attribute: string, value: string): string =>
|
|
349
|
+
new Query("notStartsWith", attribute, value).toString();
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Filter resources where attribute does not end with value.
|
|
353
|
+
*
|
|
354
|
+
* @param {string} attribute
|
|
355
|
+
* @param {string} value
|
|
356
|
+
* @returns {string}
|
|
357
|
+
*/
|
|
358
|
+
static notEndsWith = (attribute: string, value: string): string =>
|
|
359
|
+
new Query("notEndsWith", attribute, value).toString();
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Filter resources where document was created before date.
|
|
363
|
+
*
|
|
364
|
+
* @param {string} value
|
|
365
|
+
* @returns {string}
|
|
366
|
+
*/
|
|
367
|
+
static createdBefore = (value: string): string =>
|
|
368
|
+
Query.lessThan("$createdAt", value);
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Filter resources where document was created after date.
|
|
372
|
+
*
|
|
373
|
+
* @param {string} value
|
|
374
|
+
* @returns {string}
|
|
375
|
+
*/
|
|
376
|
+
static createdAfter = (value: string): string =>
|
|
377
|
+
Query.greaterThan("$createdAt", value);
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Filter resources where document was created between dates.
|
|
381
|
+
*
|
|
382
|
+
* @param {string} start
|
|
383
|
+
* @param {string} end
|
|
384
|
+
* @returns {string}
|
|
385
|
+
*/
|
|
386
|
+
static createdBetween = (start: string, end: string): string =>
|
|
387
|
+
Query.between("$createdAt", start, end);
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Filter resources where document was updated before date.
|
|
391
|
+
*
|
|
392
|
+
* @param {string} value
|
|
393
|
+
* @returns {string}
|
|
394
|
+
*/
|
|
395
|
+
static updatedBefore = (value: string): string =>
|
|
396
|
+
Query.lessThan("$updatedAt", value);
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Filter resources where document was updated after date.
|
|
400
|
+
*
|
|
401
|
+
* @param {string} value
|
|
402
|
+
* @returns {string}
|
|
403
|
+
*/
|
|
404
|
+
static updatedAfter = (value: string): string =>
|
|
405
|
+
Query.greaterThan("$updatedAt", value);
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Filter resources where document was updated between dates.
|
|
409
|
+
*
|
|
410
|
+
* @param {string} start
|
|
411
|
+
* @param {string} end
|
|
412
|
+
* @returns {string}
|
|
413
|
+
*/
|
|
414
|
+
static updatedBetween = (start: string, end: string): string =>
|
|
415
|
+
Query.between("$updatedAt", start, end);
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Combine multiple queries using logical OR operator.
|
|
419
|
+
*
|
|
420
|
+
* @param {string[]} queries
|
|
421
|
+
* @returns {string}
|
|
422
|
+
*/
|
|
423
|
+
static or = (queries: string[]) =>
|
|
424
|
+
new Query("or", undefined, queries.map((query) => JSONbig.parse(query))).toString();
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Combine multiple queries using logical AND operator.
|
|
428
|
+
*
|
|
429
|
+
* @param {string[]} queries
|
|
430
|
+
* @returns {string}
|
|
431
|
+
*/
|
|
432
|
+
static and = (queries: string[]) =>
|
|
433
|
+
new Query("and", undefined, queries.map((query) => JSONbig.parse(query))).toString();
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Filter array elements where at least one element matches all the specified queries.
|
|
437
|
+
*
|
|
438
|
+
* @param {string} attribute The attribute containing the array to filter on.
|
|
439
|
+
* @param {string[]} queries The list of query strings to match against array elements.
|
|
440
|
+
* @returns {string}
|
|
441
|
+
*/
|
|
442
|
+
static elemMatch = (attribute: string, queries: string[]): string =>
|
|
443
|
+
new Query(
|
|
444
|
+
"elemMatch",
|
|
445
|
+
attribute,
|
|
446
|
+
queries.map((query) => JSONbig.parse(query))
|
|
447
|
+
).toString();
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Filter resources where attribute is at a specific distance from the given coordinates.
|
|
451
|
+
*
|
|
452
|
+
* @param {string} attribute
|
|
453
|
+
* @param {any[]} values
|
|
454
|
+
* @param {number} distance
|
|
455
|
+
* @param {boolean} meters
|
|
456
|
+
* @returns {string}
|
|
457
|
+
*/
|
|
458
|
+
static distanceEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
|
|
459
|
+
new Query("distanceEqual", attribute, [[values, distance, meters]] as QueryTypesList).toString();
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Filter resources where attribute is not at a specific distance from the given coordinates.
|
|
463
|
+
*
|
|
464
|
+
* @param {string} attribute
|
|
465
|
+
* @param {any[]} values
|
|
466
|
+
* @param {number} distance
|
|
467
|
+
* @param {boolean} meters
|
|
468
|
+
* @returns {string}
|
|
469
|
+
*/
|
|
470
|
+
static distanceNotEqual = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
|
|
471
|
+
new Query("distanceNotEqual", attribute, [[values, distance, meters]] as QueryTypesList).toString();
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
|
|
475
|
+
*
|
|
476
|
+
* @param {string} attribute
|
|
477
|
+
* @param {any[]} values
|
|
478
|
+
* @param {number} distance
|
|
479
|
+
* @param {boolean} meters
|
|
480
|
+
* @returns {string}
|
|
481
|
+
*/
|
|
482
|
+
static distanceGreaterThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
|
|
483
|
+
new Query("distanceGreaterThan", attribute, [[values, distance, meters]] as QueryTypesList).toString();
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
|
|
487
|
+
*
|
|
488
|
+
* @param {string} attribute
|
|
489
|
+
* @param {any[]} values
|
|
490
|
+
* @param {number} distance
|
|
491
|
+
* @param {boolean} meters
|
|
492
|
+
* @returns {string}
|
|
493
|
+
*/
|
|
494
|
+
static distanceLessThan = (attribute: string, values: any[], distance: number, meters: boolean = true): string =>
|
|
495
|
+
new Query("distanceLessThan", attribute, [[values, distance, meters]] as QueryTypesList).toString();
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Filter resources where attribute intersects with the given geometry.
|
|
499
|
+
*
|
|
500
|
+
* @param {string} attribute
|
|
501
|
+
* @param {any[]} values
|
|
502
|
+
* @returns {string}
|
|
503
|
+
*/
|
|
504
|
+
static intersects = (attribute: string, values: any[]): string =>
|
|
505
|
+
new Query("intersects", attribute, [values]).toString();
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Filter resources where attribute does not intersect with the given geometry.
|
|
509
|
+
*
|
|
510
|
+
* @param {string} attribute
|
|
511
|
+
* @param {any[]} values
|
|
512
|
+
* @returns {string}
|
|
513
|
+
*/
|
|
514
|
+
static notIntersects = (attribute: string, values: any[]): string =>
|
|
515
|
+
new Query("notIntersects", attribute, [values]).toString();
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Filter resources where attribute crosses the given geometry.
|
|
519
|
+
*
|
|
520
|
+
* @param {string} attribute
|
|
521
|
+
* @param {any[]} values
|
|
522
|
+
* @returns {string}
|
|
523
|
+
*/
|
|
524
|
+
static crosses = (attribute: string, values: any[]): string =>
|
|
525
|
+
new Query("crosses", attribute, [values]).toString();
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Filter resources where attribute does not cross the given geometry.
|
|
529
|
+
*
|
|
530
|
+
* @param {string} attribute
|
|
531
|
+
* @param {any[]} values
|
|
532
|
+
* @returns {string}
|
|
533
|
+
*/
|
|
534
|
+
static notCrosses = (attribute: string, values: any[]): string =>
|
|
535
|
+
new Query("notCrosses", attribute, [values]).toString();
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Filter resources where attribute overlaps with the given geometry.
|
|
539
|
+
*
|
|
540
|
+
* @param {string} attribute
|
|
541
|
+
* @param {any[]} values
|
|
542
|
+
* @returns {string}
|
|
543
|
+
*/
|
|
544
|
+
static overlaps = (attribute: string, values: any[]): string =>
|
|
545
|
+
new Query("overlaps", attribute, [values]).toString();
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Filter resources where attribute does not overlap with the given geometry.
|
|
549
|
+
*
|
|
550
|
+
* @param {string} attribute
|
|
551
|
+
* @param {any[]} values
|
|
552
|
+
* @returns {string}
|
|
553
|
+
*/
|
|
554
|
+
static notOverlaps = (attribute: string, values: any[]): string =>
|
|
555
|
+
new Query("notOverlaps", attribute, [values]).toString();
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Filter resources where attribute touches the given geometry.
|
|
559
|
+
*
|
|
560
|
+
* @param {string} attribute
|
|
561
|
+
* @param {any[]} values
|
|
562
|
+
* @returns {string}
|
|
563
|
+
*/
|
|
564
|
+
static touches = (attribute: string, values: any[]): string =>
|
|
565
|
+
new Query("touches", attribute, [values]).toString();
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Filter resources where attribute does not touch the given geometry.
|
|
569
|
+
*
|
|
570
|
+
* @param {string} attribute
|
|
571
|
+
* @param {any[]} values
|
|
572
|
+
* @returns {string}
|
|
573
|
+
*/
|
|
574
|
+
static notTouches = (attribute: string, values: any[]): string =>
|
|
575
|
+
new Query("notTouches", attribute, [values]).toString();
|
|
576
|
+
}
|
package/src/role.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class to generate role strings for `Permission`.
|
|
3
|
+
*/
|
|
4
|
+
export class Role {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Grants access to anyone.
|
|
8
|
+
*
|
|
9
|
+
* This includes authenticated and unauthenticated users.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
public static any(): string {
|
|
14
|
+
return 'any'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Grants access to a specific user by user ID.
|
|
19
|
+
*
|
|
20
|
+
* You can optionally pass verified or unverified for
|
|
21
|
+
* `status` to target specific types of users.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} id
|
|
24
|
+
* @param {string} status
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
public static user(id: string, status: string = ''): string {
|
|
28
|
+
if (status === '') {
|
|
29
|
+
return `user:${id}`
|
|
30
|
+
}
|
|
31
|
+
return `user:${id}/${status}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Grants access to any authenticated or anonymous user.
|
|
36
|
+
*
|
|
37
|
+
* You can optionally pass verified or unverified for
|
|
38
|
+
* `status` to target specific types of users.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} status
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
public static users(status: string = ''): string {
|
|
44
|
+
if (status === '') {
|
|
45
|
+
return 'users'
|
|
46
|
+
}
|
|
47
|
+
return `users/${status}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Grants access to any guest user without a session.
|
|
52
|
+
*
|
|
53
|
+
* Authenticated users don't have access to this role.
|
|
54
|
+
*
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
public static guests(): string {
|
|
58
|
+
return 'guests'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Grants access to a team by team ID.
|
|
63
|
+
*
|
|
64
|
+
* You can optionally pass a role for `role` to target
|
|
65
|
+
* team members with the specified role.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} id
|
|
68
|
+
* @param {string} role
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
public static team(id: string, role: string = ''): string {
|
|
72
|
+
if (role === '') {
|
|
73
|
+
return `team:${id}`
|
|
74
|
+
}
|
|
75
|
+
return `team:${id}/${role}`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Grants access to a specific member of a team.
|
|
80
|
+
*
|
|
81
|
+
* When the member is removed from the team, they will
|
|
82
|
+
* no longer have access.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} id
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
public static member(id: string): string {
|
|
88
|
+
return `member:${id}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Grants access to a user with the specified label.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} name
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
public static label(name: string): string {
|
|
98
|
+
return `label:${name}`
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/service.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Client } from './client';
|
|
2
|
+
import type { Payload } from './client';
|
|
3
|
+
|
|
4
|
+
export class Service {
|
|
5
|
+
/**
|
|
6
|
+
* The size for chunked uploads in bytes.
|
|
7
|
+
*/
|
|
8
|
+
static CHUNK_SIZE = 5*1024*1024; // 5MB
|
|
9
|
+
|
|
10
|
+
client: Client;
|
|
11
|
+
|
|
12
|
+
constructor(client: Client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static flatten(data: Payload, prefix = ''): Payload {
|
|
17
|
+
let output: Payload = {};
|
|
18
|
+
|
|
19
|
+
for (const [key, value] of Object.entries(data)) {
|
|
20
|
+
let finalKey = prefix ? prefix + '[' + key +']' : key;
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
output = { ...output, ...Service.flatten(value, finalKey) };
|
|
23
|
+
} else {
|
|
24
|
+
output[finalKey] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return output;
|
|
29
|
+
}
|
|
30
|
+
}
|