node-appwrite 20.1.0 → 20.3.0
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/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +2 -2
- package/dist/client.mjs.map +1 -1
- package/dist/enums/execution-status.d.mts +2 -1
- package/dist/enums/execution-status.d.ts +2 -1
- package/dist/enums/execution-status.js +1 -0
- package/dist/enums/execution-status.js.map +1 -1
- package/dist/enums/execution-status.mjs +1 -0
- package/dist/enums/execution-status.mjs.map +1 -1
- package/dist/enums/framework.d.mts +1 -0
- package/dist/enums/framework.d.ts +1 -0
- package/dist/enums/framework.js +1 -0
- package/dist/enums/framework.js.map +1 -1
- package/dist/enums/framework.mjs +1 -0
- package/dist/enums/framework.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/models.d.mts +43 -1
- package/dist/models.d.ts +43 -1
- package/dist/operator.d.mts +181 -0
- package/dist/operator.d.ts +181 -0
- package/dist/operator.js +268 -0
- package/dist/operator.js.map +1 -0
- package/dist/operator.mjs +266 -0
- package/dist/operator.mjs.map +1 -0
- package/dist/query.js +6 -6
- package/dist/query.js.map +1 -1
- package/dist/query.mjs +6 -6
- package/dist/query.mjs.map +1 -1
- package/dist/services/account.d.mts +8 -2
- package/dist/services/account.d.ts +8 -2
- package/dist/services/account.js +14 -4
- package/dist/services/account.js.map +1 -1
- package/dist/services/account.mjs +14 -4
- package/dist/services/account.mjs.map +1 -1
- package/dist/services/databases.d.mts +192 -18
- package/dist/services/databases.d.ts +192 -18
- package/dist/services/databases.js +268 -16
- package/dist/services/databases.js.map +1 -1
- package/dist/services/databases.mjs +268 -16
- package/dist/services/databases.mjs.map +1 -1
- package/dist/services/functions.d.mts +12 -3
- package/dist/services/functions.d.ts +12 -3
- package/dist/services/functions.js +18 -3
- package/dist/services/functions.js.map +1 -1
- package/dist/services/functions.mjs +18 -3
- package/dist/services/functions.mjs.map +1 -1
- package/dist/services/messaging.d.mts +116 -9
- package/dist/services/messaging.d.ts +116 -9
- package/dist/services/messaging.js +182 -9
- package/dist/services/messaging.js.map +1 -1
- package/dist/services/messaging.mjs +182 -9
- package/dist/services/messaging.mjs.map +1 -1
- package/dist/services/sites.d.mts +12 -3
- package/dist/services/sites.d.ts +12 -3
- package/dist/services/sites.js +18 -3
- package/dist/services/sites.js.map +1 -1
- package/dist/services/sites.mjs +18 -3
- package/dist/services/sites.mjs.map +1 -1
- package/dist/services/storage.d.mts +8 -2
- package/dist/services/storage.d.ts +8 -2
- package/dist/services/storage.js +12 -2
- package/dist/services/storage.js.map +1 -1
- package/dist/services/storage.mjs +12 -2
- package/dist/services/storage.mjs.map +1 -1
- package/dist/services/tables-db.d.mts +190 -16
- package/dist/services/tables-db.d.ts +190 -16
- package/dist/services/tables-db.js +268 -16
- package/dist/services/tables-db.js.map +1 -1
- package/dist/services/tables-db.mjs +268 -16
- package/dist/services/tables-db.mjs.map +1 -1
- package/dist/services/teams.d.mts +8 -2
- package/dist/services/teams.d.ts +8 -2
- package/dist/services/teams.js +12 -2
- package/dist/services/teams.js.map +1 -1
- package/dist/services/teams.mjs +12 -2
- package/dist/services/teams.mjs.map +1 -1
- package/dist/services/tokens.d.mts +4 -1
- package/dist/services/tokens.d.ts +4 -1
- package/dist/services/tokens.js +6 -1
- package/dist/services/tokens.js.map +1 -1
- package/dist/services/tokens.mjs +6 -1
- package/dist/services/tokens.mjs.map +1 -1
- package/dist/services/users.d.mts +24 -6
- package/dist/services/users.d.ts +24 -6
- package/dist/services/users.js +37 -7
- package/dist/services/users.js.map +1 -1
- package/dist/services/users.mjs +37 -7
- package/dist/services/users.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
type OperatorValuesSingle = string | number | boolean;
|
|
2
|
+
type OperatorValuesList = string[] | number[] | boolean[] | any[];
|
|
3
|
+
type OperatorValues = OperatorValuesSingle | OperatorValuesList;
|
|
4
|
+
declare enum Condition {
|
|
5
|
+
Equal = "equal",
|
|
6
|
+
NotEqual = "notEqual",
|
|
7
|
+
GreaterThan = "greaterThan",
|
|
8
|
+
GreaterThanEqual = "greaterThanEqual",
|
|
9
|
+
LessThan = "lessThan",
|
|
10
|
+
LessThanEqual = "lessThanEqual",
|
|
11
|
+
Contains = "contains",
|
|
12
|
+
IsNull = "isNull",
|
|
13
|
+
IsNotNull = "isNotNull"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Helper class to generate operator strings for atomic operations.
|
|
17
|
+
*/
|
|
18
|
+
declare class Operator {
|
|
19
|
+
method: string;
|
|
20
|
+
values: OperatorValuesList | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor for Operator class.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} method
|
|
25
|
+
* @param {OperatorValues} values
|
|
26
|
+
*/
|
|
27
|
+
constructor(method: string, values?: OperatorValues);
|
|
28
|
+
/**
|
|
29
|
+
* Convert the operator object to a JSON string.
|
|
30
|
+
*
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
toString(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Increment a numeric attribute by a specified value.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} value
|
|
38
|
+
* @param {number} max
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
static increment: (value?: number, max?: number) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Decrement a numeric attribute by a specified value.
|
|
44
|
+
*
|
|
45
|
+
* @param {number} value
|
|
46
|
+
* @param {number} min
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
static decrement: (value?: number, min?: number) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Multiply a numeric attribute by a specified factor.
|
|
52
|
+
*
|
|
53
|
+
* @param {number} factor
|
|
54
|
+
* @param {number} max
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
static multiply: (factor: number, max?: number) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Divide a numeric attribute by a specified divisor.
|
|
60
|
+
*
|
|
61
|
+
* @param {number} divisor
|
|
62
|
+
* @param {number} min
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
static divide: (divisor: number, min?: number) => string;
|
|
66
|
+
/**
|
|
67
|
+
* Apply modulo operation on a numeric attribute.
|
|
68
|
+
*
|
|
69
|
+
* @param {number} divisor
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
static modulo: (divisor: number) => string;
|
|
73
|
+
/**
|
|
74
|
+
* Raise a numeric attribute to a specified power.
|
|
75
|
+
*
|
|
76
|
+
* @param {number} exponent
|
|
77
|
+
* @param {number} max
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
static power: (exponent: number, max?: number) => string;
|
|
81
|
+
/**
|
|
82
|
+
* Append values to an array attribute.
|
|
83
|
+
*
|
|
84
|
+
* @param {any[]} values
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
static arrayAppend: (values: any[]) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Prepend values to an array attribute.
|
|
90
|
+
*
|
|
91
|
+
* @param {any[]} values
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
static arrayPrepend: (values: any[]) => string;
|
|
95
|
+
/**
|
|
96
|
+
* Insert a value at a specific index in an array attribute.
|
|
97
|
+
*
|
|
98
|
+
* @param {number} index
|
|
99
|
+
* @param {any} value
|
|
100
|
+
* @returns {string}
|
|
101
|
+
*/
|
|
102
|
+
static arrayInsert: (index: number, value: any) => string;
|
|
103
|
+
/**
|
|
104
|
+
* Remove a value from an array attribute.
|
|
105
|
+
*
|
|
106
|
+
* @param {any} value
|
|
107
|
+
* @returns {string}
|
|
108
|
+
*/
|
|
109
|
+
static arrayRemove: (value: any) => string;
|
|
110
|
+
/**
|
|
111
|
+
* Remove duplicate values from an array attribute.
|
|
112
|
+
*
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
static arrayUnique: () => string;
|
|
116
|
+
/**
|
|
117
|
+
* Keep only values that exist in both the current array and the provided array.
|
|
118
|
+
*
|
|
119
|
+
* @param {any[]} values
|
|
120
|
+
* @returns {string}
|
|
121
|
+
*/
|
|
122
|
+
static arrayIntersect: (values: any[]) => string;
|
|
123
|
+
/**
|
|
124
|
+
* Remove values from the array that exist in the provided array.
|
|
125
|
+
*
|
|
126
|
+
* @param {any[]} values
|
|
127
|
+
* @returns {string}
|
|
128
|
+
*/
|
|
129
|
+
static arrayDiff: (values: any[]) => string;
|
|
130
|
+
/**
|
|
131
|
+
* Filter array values based on a condition.
|
|
132
|
+
*
|
|
133
|
+
* @param {Condition} condition
|
|
134
|
+
* @param {any} value
|
|
135
|
+
* @returns {string}
|
|
136
|
+
*/
|
|
137
|
+
static arrayFilter: (condition: Condition, value?: any) => string;
|
|
138
|
+
/**
|
|
139
|
+
* Concatenate a value to a string or array attribute.
|
|
140
|
+
*
|
|
141
|
+
* @param {any} value
|
|
142
|
+
* @returns {string}
|
|
143
|
+
*/
|
|
144
|
+
static stringConcat: (value: any) => string;
|
|
145
|
+
/**
|
|
146
|
+
* Replace occurrences of a search string with a replacement string.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} search
|
|
149
|
+
* @param {string} replace
|
|
150
|
+
* @returns {string}
|
|
151
|
+
*/
|
|
152
|
+
static stringReplace: (search: string, replace: string) => string;
|
|
153
|
+
/**
|
|
154
|
+
* Toggle a boolean attribute.
|
|
155
|
+
*
|
|
156
|
+
* @returns {string}
|
|
157
|
+
*/
|
|
158
|
+
static toggle: () => string;
|
|
159
|
+
/**
|
|
160
|
+
* Add days to a date attribute.
|
|
161
|
+
*
|
|
162
|
+
* @param {number} days
|
|
163
|
+
* @returns {string}
|
|
164
|
+
*/
|
|
165
|
+
static dateAddDays: (days: number) => string;
|
|
166
|
+
/**
|
|
167
|
+
* Subtract days from a date attribute.
|
|
168
|
+
*
|
|
169
|
+
* @param {number} days
|
|
170
|
+
* @returns {string}
|
|
171
|
+
*/
|
|
172
|
+
static dateSubDays: (days: number) => string;
|
|
173
|
+
/**
|
|
174
|
+
* Set a date attribute to the current date and time.
|
|
175
|
+
*
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
178
|
+
static dateSetNow: () => string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export { Condition, Operator, OperatorValues, OperatorValuesList };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
type OperatorValuesSingle = string | number | boolean;
|
|
2
|
+
type OperatorValuesList = string[] | number[] | boolean[] | any[];
|
|
3
|
+
type OperatorValues = OperatorValuesSingle | OperatorValuesList;
|
|
4
|
+
declare enum Condition {
|
|
5
|
+
Equal = "equal",
|
|
6
|
+
NotEqual = "notEqual",
|
|
7
|
+
GreaterThan = "greaterThan",
|
|
8
|
+
GreaterThanEqual = "greaterThanEqual",
|
|
9
|
+
LessThan = "lessThan",
|
|
10
|
+
LessThanEqual = "lessThanEqual",
|
|
11
|
+
Contains = "contains",
|
|
12
|
+
IsNull = "isNull",
|
|
13
|
+
IsNotNull = "isNotNull"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Helper class to generate operator strings for atomic operations.
|
|
17
|
+
*/
|
|
18
|
+
declare class Operator {
|
|
19
|
+
method: string;
|
|
20
|
+
values: OperatorValuesList | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor for Operator class.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} method
|
|
25
|
+
* @param {OperatorValues} values
|
|
26
|
+
*/
|
|
27
|
+
constructor(method: string, values?: OperatorValues);
|
|
28
|
+
/**
|
|
29
|
+
* Convert the operator object to a JSON string.
|
|
30
|
+
*
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
toString(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Increment a numeric attribute by a specified value.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} value
|
|
38
|
+
* @param {number} max
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
static increment: (value?: number, max?: number) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Decrement a numeric attribute by a specified value.
|
|
44
|
+
*
|
|
45
|
+
* @param {number} value
|
|
46
|
+
* @param {number} min
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
static decrement: (value?: number, min?: number) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Multiply a numeric attribute by a specified factor.
|
|
52
|
+
*
|
|
53
|
+
* @param {number} factor
|
|
54
|
+
* @param {number} max
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
static multiply: (factor: number, max?: number) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Divide a numeric attribute by a specified divisor.
|
|
60
|
+
*
|
|
61
|
+
* @param {number} divisor
|
|
62
|
+
* @param {number} min
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
static divide: (divisor: number, min?: number) => string;
|
|
66
|
+
/**
|
|
67
|
+
* Apply modulo operation on a numeric attribute.
|
|
68
|
+
*
|
|
69
|
+
* @param {number} divisor
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
static modulo: (divisor: number) => string;
|
|
73
|
+
/**
|
|
74
|
+
* Raise a numeric attribute to a specified power.
|
|
75
|
+
*
|
|
76
|
+
* @param {number} exponent
|
|
77
|
+
* @param {number} max
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
static power: (exponent: number, max?: number) => string;
|
|
81
|
+
/**
|
|
82
|
+
* Append values to an array attribute.
|
|
83
|
+
*
|
|
84
|
+
* @param {any[]} values
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
static arrayAppend: (values: any[]) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Prepend values to an array attribute.
|
|
90
|
+
*
|
|
91
|
+
* @param {any[]} values
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
static arrayPrepend: (values: any[]) => string;
|
|
95
|
+
/**
|
|
96
|
+
* Insert a value at a specific index in an array attribute.
|
|
97
|
+
*
|
|
98
|
+
* @param {number} index
|
|
99
|
+
* @param {any} value
|
|
100
|
+
* @returns {string}
|
|
101
|
+
*/
|
|
102
|
+
static arrayInsert: (index: number, value: any) => string;
|
|
103
|
+
/**
|
|
104
|
+
* Remove a value from an array attribute.
|
|
105
|
+
*
|
|
106
|
+
* @param {any} value
|
|
107
|
+
* @returns {string}
|
|
108
|
+
*/
|
|
109
|
+
static arrayRemove: (value: any) => string;
|
|
110
|
+
/**
|
|
111
|
+
* Remove duplicate values from an array attribute.
|
|
112
|
+
*
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
static arrayUnique: () => string;
|
|
116
|
+
/**
|
|
117
|
+
* Keep only values that exist in both the current array and the provided array.
|
|
118
|
+
*
|
|
119
|
+
* @param {any[]} values
|
|
120
|
+
* @returns {string}
|
|
121
|
+
*/
|
|
122
|
+
static arrayIntersect: (values: any[]) => string;
|
|
123
|
+
/**
|
|
124
|
+
* Remove values from the array that exist in the provided array.
|
|
125
|
+
*
|
|
126
|
+
* @param {any[]} values
|
|
127
|
+
* @returns {string}
|
|
128
|
+
*/
|
|
129
|
+
static arrayDiff: (values: any[]) => string;
|
|
130
|
+
/**
|
|
131
|
+
* Filter array values based on a condition.
|
|
132
|
+
*
|
|
133
|
+
* @param {Condition} condition
|
|
134
|
+
* @param {any} value
|
|
135
|
+
* @returns {string}
|
|
136
|
+
*/
|
|
137
|
+
static arrayFilter: (condition: Condition, value?: any) => string;
|
|
138
|
+
/**
|
|
139
|
+
* Concatenate a value to a string or array attribute.
|
|
140
|
+
*
|
|
141
|
+
* @param {any} value
|
|
142
|
+
* @returns {string}
|
|
143
|
+
*/
|
|
144
|
+
static stringConcat: (value: any) => string;
|
|
145
|
+
/**
|
|
146
|
+
* Replace occurrences of a search string with a replacement string.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} search
|
|
149
|
+
* @param {string} replace
|
|
150
|
+
* @returns {string}
|
|
151
|
+
*/
|
|
152
|
+
static stringReplace: (search: string, replace: string) => string;
|
|
153
|
+
/**
|
|
154
|
+
* Toggle a boolean attribute.
|
|
155
|
+
*
|
|
156
|
+
* @returns {string}
|
|
157
|
+
*/
|
|
158
|
+
static toggle: () => string;
|
|
159
|
+
/**
|
|
160
|
+
* Add days to a date attribute.
|
|
161
|
+
*
|
|
162
|
+
* @param {number} days
|
|
163
|
+
* @returns {string}
|
|
164
|
+
*/
|
|
165
|
+
static dateAddDays: (days: number) => string;
|
|
166
|
+
/**
|
|
167
|
+
* Subtract days from a date attribute.
|
|
168
|
+
*
|
|
169
|
+
* @param {number} days
|
|
170
|
+
* @returns {string}
|
|
171
|
+
*/
|
|
172
|
+
static dateSubDays: (days: number) => string;
|
|
173
|
+
/**
|
|
174
|
+
* Set a date attribute to the current date and time.
|
|
175
|
+
*
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
178
|
+
static dateSetNow: () => string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export { Condition, Operator, OperatorValues, OperatorValuesList };
|
package/dist/operator.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Condition = /* @__PURE__ */ ((Condition2) => {
|
|
4
|
+
Condition2["Equal"] = "equal";
|
|
5
|
+
Condition2["NotEqual"] = "notEqual";
|
|
6
|
+
Condition2["GreaterThan"] = "greaterThan";
|
|
7
|
+
Condition2["GreaterThanEqual"] = "greaterThanEqual";
|
|
8
|
+
Condition2["LessThan"] = "lessThan";
|
|
9
|
+
Condition2["LessThanEqual"] = "lessThanEqual";
|
|
10
|
+
Condition2["Contains"] = "contains";
|
|
11
|
+
Condition2["IsNull"] = "isNull";
|
|
12
|
+
Condition2["IsNotNull"] = "isNotNull";
|
|
13
|
+
return Condition2;
|
|
14
|
+
})(Condition || {});
|
|
15
|
+
const _Operator = class _Operator {
|
|
16
|
+
/**
|
|
17
|
+
* Constructor for Operator class.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} method
|
|
20
|
+
* @param {OperatorValues} values
|
|
21
|
+
*/
|
|
22
|
+
constructor(method, values) {
|
|
23
|
+
this.method = method;
|
|
24
|
+
if (values !== void 0) {
|
|
25
|
+
if (Array.isArray(values)) {
|
|
26
|
+
this.values = values;
|
|
27
|
+
} else {
|
|
28
|
+
this.values = [values];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convert the operator object to a JSON string.
|
|
34
|
+
*
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
toString() {
|
|
38
|
+
return JSON.stringify({
|
|
39
|
+
method: this.method,
|
|
40
|
+
values: this.values
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Increment a numeric attribute by a specified value.
|
|
46
|
+
*
|
|
47
|
+
* @param {number} value
|
|
48
|
+
* @param {number} max
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
_Operator.increment = (value = 1, max) => {
|
|
52
|
+
if (isNaN(value) || !isFinite(value)) {
|
|
53
|
+
throw new Error("Value cannot be NaN or Infinity");
|
|
54
|
+
}
|
|
55
|
+
if (max !== void 0 && (isNaN(max) || !isFinite(max))) {
|
|
56
|
+
throw new Error("Max cannot be NaN or Infinity");
|
|
57
|
+
}
|
|
58
|
+
const values = [value];
|
|
59
|
+
if (max !== void 0) {
|
|
60
|
+
values.push(max);
|
|
61
|
+
}
|
|
62
|
+
return new _Operator("increment", values).toString();
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Decrement a numeric attribute by a specified value.
|
|
66
|
+
*
|
|
67
|
+
* @param {number} value
|
|
68
|
+
* @param {number} min
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
_Operator.decrement = (value = 1, min) => {
|
|
72
|
+
if (isNaN(value) || !isFinite(value)) {
|
|
73
|
+
throw new Error("Value cannot be NaN or Infinity");
|
|
74
|
+
}
|
|
75
|
+
if (min !== void 0 && (isNaN(min) || !isFinite(min))) {
|
|
76
|
+
throw new Error("Min cannot be NaN or Infinity");
|
|
77
|
+
}
|
|
78
|
+
const values = [value];
|
|
79
|
+
if (min !== void 0) {
|
|
80
|
+
values.push(min);
|
|
81
|
+
}
|
|
82
|
+
return new _Operator("decrement", values).toString();
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Multiply a numeric attribute by a specified factor.
|
|
86
|
+
*
|
|
87
|
+
* @param {number} factor
|
|
88
|
+
* @param {number} max
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
_Operator.multiply = (factor, max) => {
|
|
92
|
+
if (isNaN(factor) || !isFinite(factor)) {
|
|
93
|
+
throw new Error("Factor cannot be NaN or Infinity");
|
|
94
|
+
}
|
|
95
|
+
if (max !== void 0 && (isNaN(max) || !isFinite(max))) {
|
|
96
|
+
throw new Error("Max cannot be NaN or Infinity");
|
|
97
|
+
}
|
|
98
|
+
const values = [factor];
|
|
99
|
+
if (max !== void 0) {
|
|
100
|
+
values.push(max);
|
|
101
|
+
}
|
|
102
|
+
return new _Operator("multiply", values).toString();
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Divide a numeric attribute by a specified divisor.
|
|
106
|
+
*
|
|
107
|
+
* @param {number} divisor
|
|
108
|
+
* @param {number} min
|
|
109
|
+
* @returns {string}
|
|
110
|
+
*/
|
|
111
|
+
_Operator.divide = (divisor, min) => {
|
|
112
|
+
if (isNaN(divisor) || !isFinite(divisor)) {
|
|
113
|
+
throw new Error("Divisor cannot be NaN or Infinity");
|
|
114
|
+
}
|
|
115
|
+
if (min !== void 0 && (isNaN(min) || !isFinite(min))) {
|
|
116
|
+
throw new Error("Min cannot be NaN or Infinity");
|
|
117
|
+
}
|
|
118
|
+
if (divisor === 0) {
|
|
119
|
+
throw new Error("Divisor cannot be zero");
|
|
120
|
+
}
|
|
121
|
+
const values = [divisor];
|
|
122
|
+
if (min !== void 0) {
|
|
123
|
+
values.push(min);
|
|
124
|
+
}
|
|
125
|
+
return new _Operator("divide", values).toString();
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Apply modulo operation on a numeric attribute.
|
|
129
|
+
*
|
|
130
|
+
* @param {number} divisor
|
|
131
|
+
* @returns {string}
|
|
132
|
+
*/
|
|
133
|
+
_Operator.modulo = (divisor) => {
|
|
134
|
+
if (isNaN(divisor) || !isFinite(divisor)) {
|
|
135
|
+
throw new Error("Divisor cannot be NaN or Infinity");
|
|
136
|
+
}
|
|
137
|
+
if (divisor === 0) {
|
|
138
|
+
throw new Error("Divisor cannot be zero");
|
|
139
|
+
}
|
|
140
|
+
return new _Operator("modulo", [divisor]).toString();
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Raise a numeric attribute to a specified power.
|
|
144
|
+
*
|
|
145
|
+
* @param {number} exponent
|
|
146
|
+
* @param {number} max
|
|
147
|
+
* @returns {string}
|
|
148
|
+
*/
|
|
149
|
+
_Operator.power = (exponent, max) => {
|
|
150
|
+
if (isNaN(exponent) || !isFinite(exponent)) {
|
|
151
|
+
throw new Error("Exponent cannot be NaN or Infinity");
|
|
152
|
+
}
|
|
153
|
+
if (max !== void 0 && (isNaN(max) || !isFinite(max))) {
|
|
154
|
+
throw new Error("Max cannot be NaN or Infinity");
|
|
155
|
+
}
|
|
156
|
+
const values = [exponent];
|
|
157
|
+
if (max !== void 0) {
|
|
158
|
+
values.push(max);
|
|
159
|
+
}
|
|
160
|
+
return new _Operator("power", values).toString();
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Append values to an array attribute.
|
|
164
|
+
*
|
|
165
|
+
* @param {any[]} values
|
|
166
|
+
* @returns {string}
|
|
167
|
+
*/
|
|
168
|
+
_Operator.arrayAppend = (values) => new _Operator("arrayAppend", values).toString();
|
|
169
|
+
/**
|
|
170
|
+
* Prepend values to an array attribute.
|
|
171
|
+
*
|
|
172
|
+
* @param {any[]} values
|
|
173
|
+
* @returns {string}
|
|
174
|
+
*/
|
|
175
|
+
_Operator.arrayPrepend = (values) => new _Operator("arrayPrepend", values).toString();
|
|
176
|
+
/**
|
|
177
|
+
* Insert a value at a specific index in an array attribute.
|
|
178
|
+
*
|
|
179
|
+
* @param {number} index
|
|
180
|
+
* @param {any} value
|
|
181
|
+
* @returns {string}
|
|
182
|
+
*/
|
|
183
|
+
_Operator.arrayInsert = (index, value) => new _Operator("arrayInsert", [index, value]).toString();
|
|
184
|
+
/**
|
|
185
|
+
* Remove a value from an array attribute.
|
|
186
|
+
*
|
|
187
|
+
* @param {any} value
|
|
188
|
+
* @returns {string}
|
|
189
|
+
*/
|
|
190
|
+
_Operator.arrayRemove = (value) => new _Operator("arrayRemove", [value]).toString();
|
|
191
|
+
/**
|
|
192
|
+
* Remove duplicate values from an array attribute.
|
|
193
|
+
*
|
|
194
|
+
* @returns {string}
|
|
195
|
+
*/
|
|
196
|
+
_Operator.arrayUnique = () => new _Operator("arrayUnique", []).toString();
|
|
197
|
+
/**
|
|
198
|
+
* Keep only values that exist in both the current array and the provided array.
|
|
199
|
+
*
|
|
200
|
+
* @param {any[]} values
|
|
201
|
+
* @returns {string}
|
|
202
|
+
*/
|
|
203
|
+
_Operator.arrayIntersect = (values) => new _Operator("arrayIntersect", values).toString();
|
|
204
|
+
/**
|
|
205
|
+
* Remove values from the array that exist in the provided array.
|
|
206
|
+
*
|
|
207
|
+
* @param {any[]} values
|
|
208
|
+
* @returns {string}
|
|
209
|
+
*/
|
|
210
|
+
_Operator.arrayDiff = (values) => new _Operator("arrayDiff", values).toString();
|
|
211
|
+
/**
|
|
212
|
+
* Filter array values based on a condition.
|
|
213
|
+
*
|
|
214
|
+
* @param {Condition} condition
|
|
215
|
+
* @param {any} value
|
|
216
|
+
* @returns {string}
|
|
217
|
+
*/
|
|
218
|
+
_Operator.arrayFilter = (condition, value) => {
|
|
219
|
+
const values = [condition, value === void 0 ? null : value];
|
|
220
|
+
return new _Operator("arrayFilter", values).toString();
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Concatenate a value to a string or array attribute.
|
|
224
|
+
*
|
|
225
|
+
* @param {any} value
|
|
226
|
+
* @returns {string}
|
|
227
|
+
*/
|
|
228
|
+
_Operator.stringConcat = (value) => new _Operator("stringConcat", [value]).toString();
|
|
229
|
+
/**
|
|
230
|
+
* Replace occurrences of a search string with a replacement string.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} search
|
|
233
|
+
* @param {string} replace
|
|
234
|
+
* @returns {string}
|
|
235
|
+
*/
|
|
236
|
+
_Operator.stringReplace = (search, replace) => new _Operator("stringReplace", [search, replace]).toString();
|
|
237
|
+
/**
|
|
238
|
+
* Toggle a boolean attribute.
|
|
239
|
+
*
|
|
240
|
+
* @returns {string}
|
|
241
|
+
*/
|
|
242
|
+
_Operator.toggle = () => new _Operator("toggle", []).toString();
|
|
243
|
+
/**
|
|
244
|
+
* Add days to a date attribute.
|
|
245
|
+
*
|
|
246
|
+
* @param {number} days
|
|
247
|
+
* @returns {string}
|
|
248
|
+
*/
|
|
249
|
+
_Operator.dateAddDays = (days) => new _Operator("dateAddDays", [days]).toString();
|
|
250
|
+
/**
|
|
251
|
+
* Subtract days from a date attribute.
|
|
252
|
+
*
|
|
253
|
+
* @param {number} days
|
|
254
|
+
* @returns {string}
|
|
255
|
+
*/
|
|
256
|
+
_Operator.dateSubDays = (days) => new _Operator("dateSubDays", [days]).toString();
|
|
257
|
+
/**
|
|
258
|
+
* Set a date attribute to the current date and time.
|
|
259
|
+
*
|
|
260
|
+
* @returns {string}
|
|
261
|
+
*/
|
|
262
|
+
_Operator.dateSetNow = () => new _Operator("dateSetNow", []).toString();
|
|
263
|
+
let Operator = _Operator;
|
|
264
|
+
|
|
265
|
+
exports.Condition = Condition;
|
|
266
|
+
exports.Operator = Operator;
|
|
267
|
+
//# sourceMappingURL=out.js.map
|
|
268
|
+
//# sourceMappingURL=operator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/operator.ts"],"names":["Condition"],"mappings":"AAIO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,eAAY;AATF,SAAAA;AAAA,GAAA;AAeL,MAAM,YAAN,MAAM,UAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUpB,YACE,QACA,QACA;AACA,SAAK,SAAS;AAEd,QAAI,WAAW,QAAW;AACxB,UAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,aAAK,SAAS;AAAA,MAChB,OAAO;AACL,aAAK,SAAS,CAAC,MAAM;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAmB;AACjB,WAAO,KAAK,UAAU;AAAA,MACpB,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AA6PF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAhSa,UA4CJ,YAAY,CAAC,QAAgB,GAAG,QAAyB;AAC9D,MAAI,MAAM,KAAK,KAAK,CAAC,SAAS,KAAK,GAAG;AACpC,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,MAAI,QAAQ,WAAc,MAAM,GAAG,KAAK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C,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AArQ3B,UA6QJ,cAAc,CAAC,SACpB,IAAI,UAAS,eAAe,CAAC,IAAI,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA9QpC,UAsRJ,cAAc,CAAC,SACpB,IAAI,UAAS,eAAe,CAAC,IAAI,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAvRpC,UA8RJ,aAAa,MAClB,IAAI,UAAS,cAAc,CAAC,CAAC,EAAE,SAAS;AA/RrC,IAAM,WAAN","sourcesContent":["type OperatorValuesSingle = string | number | boolean;\nexport type OperatorValuesList = string[] | number[] | boolean[] | any[];\nexport type OperatorValues = OperatorValuesSingle | OperatorValuesList;\n\nexport enum Condition {\n Equal = \"equal\",\n NotEqual = \"notEqual\",\n GreaterThan = \"greaterThan\",\n GreaterThanEqual = \"greaterThanEqual\",\n LessThan = \"lessThan\",\n LessThanEqual = \"lessThanEqual\",\n Contains = \"contains\",\n IsNull = \"isNull\",\n IsNotNull = \"isNotNull\",\n}\n\n/**\n * Helper class to generate operator strings for atomic operations.\n */\nexport class Operator {\n method: string;\n values: OperatorValuesList | undefined;\n\n /**\n * Constructor for Operator class.\n *\n * @param {string} method\n * @param {OperatorValues} values\n */\n constructor(\n method: string,\n values?: OperatorValues\n ) {\n this.method = method;\n\n if (values !== undefined) {\n if (Array.isArray(values)) {\n this.values = values;\n } else {\n this.values = [values] as OperatorValuesList;\n }\n }\n }\n\n /**\n * Convert the operator object to a JSON string.\n *\n * @returns {string}\n */\n toString(): string {\n return JSON.stringify({\n method: this.method,\n values: this.values,\n });\n }\n\n /**\n * Increment a numeric attribute by a specified value.\n *\n * @param {number} value\n * @param {number} max\n * @returns {string}\n */\n static increment = (value: number = 1, max?: number): string => {\n if (isNaN(value) || !isFinite(value)) {\n throw new Error(\"Value cannot be NaN or Infinity\");\n }\n if (max !== undefined && (isNaN(max) || !isFinite(max))) {\n throw new Error(\"Max cannot be NaN or Infinity\");\n }\n const values: any[] = [value];\n if (max !== undefined) {\n values.push(max);\n }\n return new Operator(\"increment\", values).toString();\n };\n\n /**\n * Decrement a numeric attribute by a specified value.\n *\n * @param {number} value\n * @param {number} min\n * @returns {string}\n */\n static decrement = (value: number = 1, min?: number): string => {\n if (isNaN(value) || !isFinite(value)) {\n throw new Error(\"Value cannot be NaN or Infinity\");\n }\n if (min !== undefined && (isNaN(min) || !isFinite(min))) {\n throw new Error(\"Min cannot be NaN or Infinity\");\n }\n const values: any[] = [value];\n if (min !== undefined) {\n values.push(min);\n }\n return new Operator(\"decrement\", values).toString();\n };\n\n /**\n * Multiply a numeric attribute by a specified factor.\n *\n * @param {number} factor\n * @param {number} max\n * @returns {string}\n */\n static multiply = (factor: number, max?: number): string => {\n if (isNaN(factor) || !isFinite(factor)) {\n throw new Error(\"Factor cannot be NaN or Infinity\");\n }\n if (max !== undefined && (isNaN(max) || !isFinite(max))) {\n throw new Error(\"Max cannot be NaN or Infinity\");\n }\n const values: any[] = [factor];\n if (max !== undefined) {\n values.push(max);\n }\n return new Operator(\"multiply\", values).toString();\n };\n\n /**\n * Divide a numeric attribute by a specified divisor.\n *\n * @param {number} divisor\n * @param {number} min\n * @returns {string}\n */\n static divide = (divisor: number, min?: number): string => {\n if (isNaN(divisor) || !isFinite(divisor)) {\n throw new Error(\"Divisor cannot be NaN or Infinity\");\n }\n if (min !== undefined && (isNaN(min) || !isFinite(min))) {\n throw new Error(\"Min cannot be NaN or Infinity\");\n }\n if (divisor === 0) {\n throw new Error(\"Divisor cannot be zero\");\n }\n const values: any[] = [divisor];\n if (min !== undefined) {\n values.push(min);\n }\n return new Operator(\"divide\", values).toString();\n };\n\n /**\n * Apply modulo operation on a numeric attribute.\n *\n * @param {number} divisor\n * @returns {string}\n */\n static modulo = (divisor: number): string => {\n if (isNaN(divisor) || !isFinite(divisor)) {\n throw new Error(\"Divisor cannot be NaN or Infinity\");\n }\n if (divisor === 0) {\n throw new Error(\"Divisor cannot be zero\");\n }\n return new Operator(\"modulo\", [divisor]).toString();\n };\n\n /**\n * Raise a numeric attribute to a specified power.\n *\n * @param {number} exponent\n * @param {number} max\n * @returns {string}\n */\n static power = (exponent: number, max?: number): string => {\n if (isNaN(exponent) || !isFinite(exponent)) {\n throw new Error(\"Exponent cannot be NaN or Infinity\");\n }\n if (max !== undefined && (isNaN(max) || !isFinite(max))) {\n throw new Error(\"Max cannot be NaN or Infinity\");\n }\n const values: any[] = [exponent];\n if (max !== undefined) {\n values.push(max);\n }\n return new Operator(\"power\", values).toString();\n };\n\n /**\n * Append values to an array attribute.\n *\n * @param {any[]} values\n * @returns {string}\n */\n static arrayAppend = (values: any[]): string =>\n new Operator(\"arrayAppend\", values).toString();\n\n /**\n * Prepend values to an array attribute.\n *\n * @param {any[]} values\n * @returns {string}\n */\n static arrayPrepend = (values: any[]): string =>\n new Operator(\"arrayPrepend\", values).toString();\n\n /**\n * Insert a value at a specific index in an array attribute.\n *\n * @param {number} index\n * @param {any} value\n * @returns {string}\n */\n static arrayInsert = (index: number, value: any): string =>\n new Operator(\"arrayInsert\", [index, value]).toString();\n\n /**\n * Remove a value from an array attribute.\n *\n * @param {any} value\n * @returns {string}\n */\n static arrayRemove = (value: any): string =>\n new Operator(\"arrayRemove\", [value]).toString();\n\n /**\n * Remove duplicate values from an array attribute.\n *\n * @returns {string}\n */\n static arrayUnique = (): string =>\n new Operator(\"arrayUnique\", []).toString();\n\n /**\n * Keep only values that exist in both the current array and the provided array.\n *\n * @param {any[]} values\n * @returns {string}\n */\n static arrayIntersect = (values: any[]): string =>\n new Operator(\"arrayIntersect\", values).toString();\n\n /**\n * Remove values from the array that exist in the provided array.\n *\n * @param {any[]} values\n * @returns {string}\n */\n static arrayDiff = (values: any[]): string =>\n new Operator(\"arrayDiff\", values).toString();\n\n /**\n * Filter array values based on a condition.\n *\n * @param {Condition} condition\n * @param {any} value\n * @returns {string}\n */\n static arrayFilter = (condition: Condition, value?: any): string => {\n const values: any[] = [condition as string, value === undefined ? null : value];\n return new Operator(\"arrayFilter\", values).toString();\n };\n\n /**\n * Concatenate a value to a string or array attribute.\n *\n * @param {any} value\n * @returns {string}\n */\n static stringConcat = (value: any): string =>\n new Operator(\"stringConcat\", [value]).toString();\n\n /**\n * Replace occurrences of a search string with a replacement string.\n *\n * @param {string} search\n * @param {string} replace\n * @returns {string}\n */\n static stringReplace = (search: string, replace: string): string =>\n new Operator(\"stringReplace\", [search, replace]).toString();\n\n /**\n * Toggle a boolean attribute.\n *\n * @returns {string}\n */\n static toggle = (): string =>\n new Operator(\"toggle\", []).toString();\n\n /**\n * Add days to a date attribute.\n *\n * @param {number} days\n * @returns {string}\n */\n static dateAddDays = (days: number): string =>\n new Operator(\"dateAddDays\", [days]).toString();\n\n /**\n * Subtract days from a date attribute.\n *\n * @param {number} days\n * @returns {string}\n */\n static dateSubDays = (days: number): string =>\n new Operator(\"dateSubDays\", [days]).toString();\n\n /**\n * Set a date attribute to the current date and time.\n *\n * @returns {string}\n */\n static dateSetNow = (): string =>\n new Operator(\"dateSetNow\", []).toString();\n}\n"]}
|