@appwrite.io/console 2.1.2 → 2.1.3
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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/dist/cjs/sdk.js +213 -11
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +212 -12
- package/dist/esm/sdk.js.map +1 -1
- package/dist/iife/sdk.js +246 -64
- package/package.json +3 -2
- package/src/channel.ts +134 -0
- package/src/client.ts +79 -9
- package/src/index.ts +1 -0
- package/src/query.ts +42 -0
- package/src/services/realtime.ts +35 -12
- package/types/channel.d.ts +71 -0
- package/types/client.d.ts +11 -3
- package/types/index.d.ts +1 -0
- package/types/query.d.ts +30 -0
- package/types/services/realtime.d.ts +17 -8
package/dist/iife/sdk.js
CHANGED
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
(function (globalObject) {
|
|
45
45
|
|
|
46
46
|
/*
|
|
47
|
-
* bignumber.js v9.
|
|
47
|
+
* bignumber.js v9.0.0
|
|
48
48
|
* A JavaScript library for arbitrary-precision arithmetic.
|
|
49
49
|
* https://github.com/MikeMcl/bignumber.js
|
|
50
|
-
* Copyright (c)
|
|
50
|
+
* Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
51
51
|
* MIT Licensed.
|
|
52
52
|
*
|
|
53
53
|
* BigNumber.prototype methods | BigNumber methods
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
|
|
188
188
|
// The maximum number of significant digits of the result of the exponentiatedBy operation.
|
|
189
189
|
// If POW_PRECISION is 0, there will be unlimited significant digits.
|
|
190
|
-
POW_PRECISION = 0,
|
|
190
|
+
POW_PRECISION = 0, // 0 to MAX
|
|
191
191
|
|
|
192
192
|
// The format specification used by the BigNumber.prototype.toFormat method.
|
|
193
193
|
FORMAT = {
|
|
@@ -197,15 +197,14 @@
|
|
|
197
197
|
groupSeparator: ',',
|
|
198
198
|
decimalSeparator: '.',
|
|
199
199
|
fractionGroupSize: 0,
|
|
200
|
-
fractionGroupSeparator: '\xA0',
|
|
200
|
+
fractionGroupSeparator: '\xA0', // non-breaking space
|
|
201
201
|
suffix: ''
|
|
202
202
|
},
|
|
203
203
|
|
|
204
204
|
// The alphabet used for base conversion. It must be at least 2 characters long, with no '+',
|
|
205
205
|
// '-', '.', whitespace, or repeated character.
|
|
206
206
|
// '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
|
|
207
|
-
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz'
|
|
208
|
-
alphabetHasNormalDecimalDigits = true;
|
|
207
|
+
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
209
208
|
|
|
210
209
|
|
|
211
210
|
//------------------------------------------------------------------------------------------
|
|
@@ -295,7 +294,7 @@
|
|
|
295
294
|
|
|
296
295
|
// Allow exponential notation to be used with base 10 argument, while
|
|
297
296
|
// also rounding to DECIMAL_PLACES as with other bases.
|
|
298
|
-
if (b == 10
|
|
297
|
+
if (b == 10) {
|
|
299
298
|
x = new BigNumber(v);
|
|
300
299
|
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
301
300
|
}
|
|
@@ -584,10 +583,9 @@
|
|
|
584
583
|
if (obj.hasOwnProperty(p = 'ALPHABET')) {
|
|
585
584
|
v = obj[p];
|
|
586
585
|
|
|
587
|
-
// Disallow if
|
|
586
|
+
// Disallow if only one character,
|
|
588
587
|
// or if it contains '+', '-', '.', whitespace, or a repeated character.
|
|
589
|
-
if (typeof v == 'string' &&
|
|
590
|
-
alphabetHasNormalDecimalDigits = v.slice(0, 10) == '0123456789';
|
|
588
|
+
if (typeof v == 'string' && !/^.$|[+-.\s]|(.).*\1/.test(v)) {
|
|
591
589
|
ALPHABET = v;
|
|
592
590
|
} else {
|
|
593
591
|
throw Error
|
|
@@ -679,7 +677,7 @@
|
|
|
679
677
|
* arguments {number|string|BigNumber}
|
|
680
678
|
*/
|
|
681
679
|
BigNumber.maximum = BigNumber.max = function () {
|
|
682
|
-
return maxOrMin(arguments,
|
|
680
|
+
return maxOrMin(arguments, P.lt);
|
|
683
681
|
};
|
|
684
682
|
|
|
685
683
|
|
|
@@ -689,7 +687,7 @@
|
|
|
689
687
|
* arguments {number|string|BigNumber}
|
|
690
688
|
*/
|
|
691
689
|
BigNumber.minimum = BigNumber.min = function () {
|
|
692
|
-
return maxOrMin(arguments,
|
|
690
|
+
return maxOrMin(arguments, P.gt);
|
|
693
691
|
};
|
|
694
692
|
|
|
695
693
|
|
|
@@ -948,7 +946,7 @@
|
|
|
948
946
|
|
|
949
947
|
// xc now represents str converted to baseOut.
|
|
950
948
|
|
|
951
|
-
//
|
|
949
|
+
// THe index of the rounding digit.
|
|
952
950
|
d = e + dp + 1;
|
|
953
951
|
|
|
954
952
|
// The rounding digit: the digit to the right of the digit that may be rounded up.
|
|
@@ -1312,7 +1310,7 @@
|
|
|
1312
1310
|
|
|
1313
1311
|
// Fixed-point notation.
|
|
1314
1312
|
} else {
|
|
1315
|
-
i -= ne
|
|
1313
|
+
i -= ne;
|
|
1316
1314
|
str = toFixedPoint(str, e, '0');
|
|
1317
1315
|
|
|
1318
1316
|
// Append zeros?
|
|
@@ -1333,20 +1331,24 @@
|
|
|
1333
1331
|
|
|
1334
1332
|
|
|
1335
1333
|
// Handle BigNumber.max and BigNumber.min.
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
var k, y,
|
|
1334
|
+
function maxOrMin(args, method) {
|
|
1335
|
+
var n,
|
|
1339
1336
|
i = 1,
|
|
1340
|
-
|
|
1337
|
+
m = new BigNumber(args[0]);
|
|
1341
1338
|
|
|
1342
1339
|
for (; i < args.length; i++) {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1340
|
+
n = new BigNumber(args[i]);
|
|
1341
|
+
|
|
1342
|
+
// If any number is NaN, return NaN.
|
|
1343
|
+
if (!n.s) {
|
|
1344
|
+
m = n;
|
|
1345
|
+
break;
|
|
1346
|
+
} else if (method.call(m, n)) {
|
|
1347
|
+
m = n;
|
|
1346
1348
|
}
|
|
1347
1349
|
}
|
|
1348
1350
|
|
|
1349
|
-
return
|
|
1351
|
+
return m;
|
|
1350
1352
|
}
|
|
1351
1353
|
|
|
1352
1354
|
|
|
@@ -1465,7 +1467,7 @@
|
|
|
1465
1467
|
n = xc[ni = 0];
|
|
1466
1468
|
|
|
1467
1469
|
// Get the rounding digit at index j of n.
|
|
1468
|
-
rd =
|
|
1470
|
+
rd = n / pows10[d - j - 1] % 10 | 0;
|
|
1469
1471
|
} else {
|
|
1470
1472
|
ni = mathceil((i + 1) / LOG_BASE);
|
|
1471
1473
|
|
|
@@ -1496,7 +1498,7 @@
|
|
|
1496
1498
|
j = i - LOG_BASE + d;
|
|
1497
1499
|
|
|
1498
1500
|
// Get the rounding digit at index j of n.
|
|
1499
|
-
rd = j < 0 ? 0 :
|
|
1501
|
+
rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
|
|
1500
1502
|
}
|
|
1501
1503
|
}
|
|
1502
1504
|
|
|
@@ -1744,7 +1746,7 @@
|
|
|
1744
1746
|
|
|
1745
1747
|
// The sign of the result of pow when x is negative depends on the evenness of n.
|
|
1746
1748
|
// If +n overflows to ±Infinity, the evenness of n would be not be known.
|
|
1747
|
-
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ?
|
|
1749
|
+
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));
|
|
1748
1750
|
return m ? y.mod(m) : y;
|
|
1749
1751
|
}
|
|
1750
1752
|
|
|
@@ -2045,12 +2047,7 @@
|
|
|
2045
2047
|
}
|
|
2046
2048
|
|
|
2047
2049
|
// x < y? Point xc to the array of the bigger number.
|
|
2048
|
-
if (xLTy)
|
|
2049
|
-
t = xc;
|
|
2050
|
-
xc = yc;
|
|
2051
|
-
yc = t;
|
|
2052
|
-
y.s = -y.s;
|
|
2053
|
-
}
|
|
2050
|
+
if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;
|
|
2054
2051
|
|
|
2055
2052
|
b = (j = yc.length) - (i = xc.length);
|
|
2056
2053
|
|
|
@@ -2204,14 +2201,7 @@
|
|
|
2204
2201
|
ycL = yc.length;
|
|
2205
2202
|
|
|
2206
2203
|
// Ensure xc points to longer array and xcL to its length.
|
|
2207
|
-
if (xcL < ycL)
|
|
2208
|
-
zc = xc;
|
|
2209
|
-
xc = yc;
|
|
2210
|
-
yc = zc;
|
|
2211
|
-
i = xcL;
|
|
2212
|
-
xcL = ycL;
|
|
2213
|
-
ycL = i;
|
|
2214
|
-
}
|
|
2204
|
+
if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
|
|
2215
2205
|
|
|
2216
2206
|
// Initialise the result array with zeros.
|
|
2217
2207
|
for (i = xcL + ycL, zc = []; i--; zc.push(0));
|
|
@@ -2332,12 +2322,7 @@
|
|
|
2332
2322
|
b = yc.length;
|
|
2333
2323
|
|
|
2334
2324
|
// Point xc to the longer array, and b to the shorter length.
|
|
2335
|
-
if (a - b < 0)
|
|
2336
|
-
t = yc;
|
|
2337
|
-
yc = xc;
|
|
2338
|
-
xc = t;
|
|
2339
|
-
b = a;
|
|
2340
|
-
}
|
|
2325
|
+
if (a - b < 0) t = yc, yc = xc, xc = t, b = a;
|
|
2341
2326
|
|
|
2342
2327
|
// Only start adding at yc.length - 1 as the further digits of xc can be ignored.
|
|
2343
2328
|
for (a = 0; b;) {
|
|
@@ -2453,7 +2438,7 @@
|
|
|
2453
2438
|
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
2454
2439
|
|
|
2455
2440
|
if (s == 1 / 0) {
|
|
2456
|
-
n = '
|
|
2441
|
+
n = '1e' + e;
|
|
2457
2442
|
} else {
|
|
2458
2443
|
n = s.toExponential();
|
|
2459
2444
|
n = n.slice(0, n.indexOf('e') + 1) + e;
|
|
@@ -2623,12 +2608,7 @@
|
|
|
2623
2608
|
intDigits = isNeg ? intPart.slice(1) : intPart,
|
|
2624
2609
|
len = intDigits.length;
|
|
2625
2610
|
|
|
2626
|
-
if (g2)
|
|
2627
|
-
i = g1;
|
|
2628
|
-
g1 = g2;
|
|
2629
|
-
g2 = i;
|
|
2630
|
-
len -= i;
|
|
2631
|
-
}
|
|
2611
|
+
if (g2) i = g1, g1 = g2, g2 = i, len -= i;
|
|
2632
2612
|
|
|
2633
2613
|
if (g1 > 0 && len > 0) {
|
|
2634
2614
|
i = len % g1 || g1;
|
|
@@ -2780,7 +2760,7 @@
|
|
|
2780
2760
|
str = e <= TO_EXP_NEG || e >= TO_EXP_POS
|
|
2781
2761
|
? toExponential(coeffToString(n.c), e)
|
|
2782
2762
|
: toFixedPoint(coeffToString(n.c), e, '0');
|
|
2783
|
-
} else if (b === 10
|
|
2763
|
+
} else if (b === 10) {
|
|
2784
2764
|
n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
2785
2765
|
str = toFixedPoint(coeffToString(n.c), n.e, '0');
|
|
2786
2766
|
} else {
|
|
@@ -2960,6 +2940,8 @@
|
|
|
2960
2940
|
})(commonjsGlobal);
|
|
2961
2941
|
} (bignumber));
|
|
2962
2942
|
|
|
2943
|
+
var BigNumber$1 = bignumber.exports;
|
|
2944
|
+
|
|
2963
2945
|
(function (module) {
|
|
2964
2946
|
var BigNumber = bignumber.exports;
|
|
2965
2947
|
|
|
@@ -3848,6 +3830,14 @@
|
|
|
3848
3830
|
* @returns {string}
|
|
3849
3831
|
*/
|
|
3850
3832
|
Query.notEqual = (attribute, value) => new Query("notEqual", attribute, value).toString();
|
|
3833
|
+
/**
|
|
3834
|
+
* Filter resources where attribute matches a regular expression pattern.
|
|
3835
|
+
*
|
|
3836
|
+
* @param {string} attribute The attribute to filter on.
|
|
3837
|
+
* @param {string} pattern The regular expression pattern to match.
|
|
3838
|
+
* @returns {string}
|
|
3839
|
+
*/
|
|
3840
|
+
Query.regex = (attribute, pattern) => new Query("regex", attribute, pattern).toString();
|
|
3851
3841
|
/**
|
|
3852
3842
|
* Filter resources where attribute is less than value.
|
|
3853
3843
|
*
|
|
@@ -3894,6 +3884,20 @@
|
|
|
3894
3884
|
* @returns {string}
|
|
3895
3885
|
*/
|
|
3896
3886
|
Query.isNotNull = (attribute) => new Query("isNotNull", attribute).toString();
|
|
3887
|
+
/**
|
|
3888
|
+
* Filter resources where the specified attributes exist.
|
|
3889
|
+
*
|
|
3890
|
+
* @param {string[]} attributes The list of attributes that must exist.
|
|
3891
|
+
* @returns {string}
|
|
3892
|
+
*/
|
|
3893
|
+
Query.exists = (attributes) => new Query("exists", undefined, attributes).toString();
|
|
3894
|
+
/**
|
|
3895
|
+
* Filter resources where the specified attributes do not exist.
|
|
3896
|
+
*
|
|
3897
|
+
* @param {string[]} attributes The list of attributes that must not exist.
|
|
3898
|
+
* @returns {string}
|
|
3899
|
+
*/
|
|
3900
|
+
Query.notExists = (attributes) => new Query("notExists", undefined, attributes).toString();
|
|
3897
3901
|
/**
|
|
3898
3902
|
* Filter resources where attribute is between start and end (inclusive).
|
|
3899
3903
|
*
|
|
@@ -4091,6 +4095,14 @@
|
|
|
4091
4095
|
* @returns {string}
|
|
4092
4096
|
*/
|
|
4093
4097
|
Query.and = (queries) => new Query("and", undefined, queries.map((query) => JSONbig$1.parse(query))).toString();
|
|
4098
|
+
/**
|
|
4099
|
+
* Filter array elements where at least one element matches all the specified queries.
|
|
4100
|
+
*
|
|
4101
|
+
* @param {string} attribute The attribute containing the array to filter on.
|
|
4102
|
+
* @param {string[]} queries The list of query strings to match against array elements.
|
|
4103
|
+
* @returns {string}
|
|
4104
|
+
*/
|
|
4105
|
+
Query.elemMatch = (attribute, queries) => new Query("elemMatch", attribute, queries.map((query) => JSONbig$1.parse(query))).toString();
|
|
4094
4106
|
/**
|
|
4095
4107
|
* Filter resources where attribute is at a specific distance from the given coordinates.
|
|
4096
4108
|
*
|
|
@@ -4196,7 +4208,47 @@
|
|
|
4196
4208
|
*/
|
|
4197
4209
|
Query.notTouches = (attribute, values) => new Query("notTouches", attribute, [values]).toString();
|
|
4198
4210
|
|
|
4199
|
-
const
|
|
4211
|
+
const JSONbigParser = jsonBigint.exports({ storeAsString: false });
|
|
4212
|
+
const JSONbigSerializer = jsonBigint.exports({ useNativeBigInt: true });
|
|
4213
|
+
/**
|
|
4214
|
+
* Converts BigNumber objects from json-bigint to native types.
|
|
4215
|
+
* - Integer BigNumbers → BigInt (if unsafe) or number (if safe)
|
|
4216
|
+
* - Float BigNumbers → number
|
|
4217
|
+
* - Strings remain strings (never converted to BigNumber by json-bigint)
|
|
4218
|
+
*/
|
|
4219
|
+
const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
|
|
4220
|
+
const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
|
|
4221
|
+
function convertBigNumbers(value) {
|
|
4222
|
+
if (value === null || value === undefined)
|
|
4223
|
+
return value;
|
|
4224
|
+
if (Array.isArray(value)) {
|
|
4225
|
+
return value.map(convertBigNumbers);
|
|
4226
|
+
}
|
|
4227
|
+
if (BigNumber$1.isBigNumber(value)) {
|
|
4228
|
+
if (value.isInteger()) {
|
|
4229
|
+
const str = value.toFixed();
|
|
4230
|
+
const bi = BigInt(str);
|
|
4231
|
+
if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
|
|
4232
|
+
return Number(str);
|
|
4233
|
+
}
|
|
4234
|
+
return bi;
|
|
4235
|
+
}
|
|
4236
|
+
// float
|
|
4237
|
+
return value.toNumber();
|
|
4238
|
+
}
|
|
4239
|
+
if (typeof value === 'object') {
|
|
4240
|
+
const result = {};
|
|
4241
|
+
for (const [k, v] of Object.entries(value)) {
|
|
4242
|
+
result[k] = convertBigNumbers(v);
|
|
4243
|
+
}
|
|
4244
|
+
return result;
|
|
4245
|
+
}
|
|
4246
|
+
return value;
|
|
4247
|
+
}
|
|
4248
|
+
const JSONbig = {
|
|
4249
|
+
parse: (text) => convertBigNumbers(JSONbigParser.parse(text)),
|
|
4250
|
+
stringify: JSONbigSerializer.stringify
|
|
4251
|
+
};
|
|
4200
4252
|
/**
|
|
4201
4253
|
* Exception thrown by the package
|
|
4202
4254
|
*/
|
|
@@ -4246,7 +4298,7 @@
|
|
|
4246
4298
|
'x-sdk-name': 'Console',
|
|
4247
4299
|
'x-sdk-platform': 'console',
|
|
4248
4300
|
'x-sdk-language': 'web',
|
|
4249
|
-
'x-sdk-version': '2.1.
|
|
4301
|
+
'x-sdk-version': '2.1.3',
|
|
4250
4302
|
'X-Appwrite-Response-Format': '1.8.0',
|
|
4251
4303
|
};
|
|
4252
4304
|
this.realtime = {
|
|
@@ -4548,8 +4600,8 @@
|
|
|
4548
4600
|
* @deprecated Use the Realtime service instead.
|
|
4549
4601
|
* @see Realtime
|
|
4550
4602
|
*
|
|
4551
|
-
* @param {string|string[]} channels
|
|
4552
|
-
* Channel to subscribe - pass a single channel as a string or multiple with an array
|
|
4603
|
+
* @param {string|string[]|Channel<any>|ActionableChannel|ResolvedChannel|(Channel<any>|ActionableChannel|ResolvedChannel)[]} channels
|
|
4604
|
+
* Channel to subscribe - pass a single channel as a string or Channel builder instance, or multiple with an array.
|
|
4553
4605
|
*
|
|
4554
4606
|
* Possible channels are:
|
|
4555
4607
|
* - account
|
|
@@ -4567,21 +4619,40 @@
|
|
|
4567
4619
|
* - teams.[ID]
|
|
4568
4620
|
* - memberships
|
|
4569
4621
|
* - memberships.[ID]
|
|
4622
|
+
*
|
|
4623
|
+
* You can also use Channel builders:
|
|
4624
|
+
* - Channel.database('db').collection('col').document('doc').create()
|
|
4625
|
+
* - Channel.bucket('bucket').file('file').update()
|
|
4626
|
+
* - Channel.function('func').execution('exec').delete()
|
|
4627
|
+
* - Channel.team('team').create()
|
|
4628
|
+
* - Channel.membership('membership').update()
|
|
4570
4629
|
* @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
|
|
4571
4630
|
* @returns {() => void} Unsubscribes from events.
|
|
4572
4631
|
*/
|
|
4573
4632
|
subscribe(channels, callback) {
|
|
4574
|
-
|
|
4575
|
-
|
|
4633
|
+
const channelArray = Array.isArray(channels) ? channels : [channels];
|
|
4634
|
+
// Convert Channel instances to strings
|
|
4635
|
+
const channelStrings = channelArray.map(ch => {
|
|
4636
|
+
if (typeof ch === 'string') {
|
|
4637
|
+
return ch;
|
|
4638
|
+
}
|
|
4639
|
+
// All Channel instances have toString() method
|
|
4640
|
+
if (ch && typeof ch.toString === 'function') {
|
|
4641
|
+
return ch.toString();
|
|
4642
|
+
}
|
|
4643
|
+
// Fallback to generic string conversion
|
|
4644
|
+
return String(ch);
|
|
4645
|
+
});
|
|
4646
|
+
channelStrings.forEach(channel => this.realtime.channels.add(channel));
|
|
4576
4647
|
const counter = this.realtime.subscriptionsCounter++;
|
|
4577
4648
|
this.realtime.subscriptions.set(counter, {
|
|
4578
|
-
channels:
|
|
4649
|
+
channels: channelStrings,
|
|
4579
4650
|
callback
|
|
4580
4651
|
});
|
|
4581
4652
|
this.realtime.connect();
|
|
4582
4653
|
return () => {
|
|
4583
4654
|
this.realtime.subscriptions.delete(counter);
|
|
4584
|
-
this.realtime.cleanUp(
|
|
4655
|
+
this.realtime.cleanUp(channelStrings);
|
|
4585
4656
|
this.realtime.connect();
|
|
4586
4657
|
};
|
|
4587
4658
|
}
|
|
@@ -28681,11 +28752,31 @@
|
|
|
28681
28752
|
sleep(ms) {
|
|
28682
28753
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
28683
28754
|
}
|
|
28755
|
+
/**
|
|
28756
|
+
* Convert a channel value to a string
|
|
28757
|
+
*
|
|
28758
|
+
* @private
|
|
28759
|
+
* @param {string | Channel<any> | ActionableChannel | ResolvedChannel} channel - Channel value (string or Channel builder instance)
|
|
28760
|
+
* @returns {string} Channel string representation
|
|
28761
|
+
*/
|
|
28762
|
+
channelToString(channel) {
|
|
28763
|
+
if (typeof channel === 'string') {
|
|
28764
|
+
return channel;
|
|
28765
|
+
}
|
|
28766
|
+
// All Channel instances have toString() method
|
|
28767
|
+
if (channel && typeof channel.toString === 'function') {
|
|
28768
|
+
return channel.toString();
|
|
28769
|
+
}
|
|
28770
|
+
return String(channel);
|
|
28771
|
+
}
|
|
28684
28772
|
subscribe(channelsOrChannel, callback) {
|
|
28685
28773
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28686
|
-
const
|
|
28687
|
-
?
|
|
28688
|
-
:
|
|
28774
|
+
const channelArray = Array.isArray(channelsOrChannel)
|
|
28775
|
+
? channelsOrChannel
|
|
28776
|
+
: [channelsOrChannel];
|
|
28777
|
+
// Convert all channels to strings
|
|
28778
|
+
const channelStrings = channelArray.map(ch => this.channelToString(ch));
|
|
28779
|
+
const channels = new Set(channelStrings);
|
|
28689
28780
|
this.subscriptionsCounter++;
|
|
28690
28781
|
const count = this.subscriptionsCounter;
|
|
28691
28782
|
for (const channel of channels) {
|
|
@@ -28989,6 +29080,96 @@
|
|
|
28989
29080
|
return hexTimestamp;
|
|
28990
29081
|
};
|
|
28991
29082
|
|
|
29083
|
+
function normalize(id) {
|
|
29084
|
+
const trimmed = id.trim();
|
|
29085
|
+
return trimmed === "" ? "*" : trimmed;
|
|
29086
|
+
}
|
|
29087
|
+
class Channel {
|
|
29088
|
+
constructor(segments) {
|
|
29089
|
+
this.segments = segments;
|
|
29090
|
+
}
|
|
29091
|
+
next(segment, id = "*") {
|
|
29092
|
+
return new Channel([...this.segments, segment, normalize(id)]);
|
|
29093
|
+
}
|
|
29094
|
+
resolve(action) {
|
|
29095
|
+
return new Channel([...this.segments, action]);
|
|
29096
|
+
}
|
|
29097
|
+
toString() {
|
|
29098
|
+
return this.segments.join(".");
|
|
29099
|
+
}
|
|
29100
|
+
// --- DATABASE ROUTE ---
|
|
29101
|
+
// Only available on Channel<Database>
|
|
29102
|
+
collection(id = "*") {
|
|
29103
|
+
return this.next("collections", id);
|
|
29104
|
+
}
|
|
29105
|
+
// Only available on Channel<Collection>
|
|
29106
|
+
document(id = "*") {
|
|
29107
|
+
return this.next("documents", id);
|
|
29108
|
+
}
|
|
29109
|
+
// --- TABLESDB ROUTE ---
|
|
29110
|
+
table(id = "*") {
|
|
29111
|
+
return this.next("tables", id);
|
|
29112
|
+
}
|
|
29113
|
+
row(id = "*") {
|
|
29114
|
+
return this.next("rows", id);
|
|
29115
|
+
}
|
|
29116
|
+
// --- BUCKET ROUTE ---
|
|
29117
|
+
file(id = "*") {
|
|
29118
|
+
return this.next("files", id);
|
|
29119
|
+
}
|
|
29120
|
+
// --- FUNCTION ROUTE ---
|
|
29121
|
+
execution(id = "*") {
|
|
29122
|
+
return this.next("executions", id);
|
|
29123
|
+
}
|
|
29124
|
+
// --- TERMINAL ACTIONS ---
|
|
29125
|
+
// Restricted to the Actionable union
|
|
29126
|
+
create() {
|
|
29127
|
+
return this.resolve("create");
|
|
29128
|
+
}
|
|
29129
|
+
update() {
|
|
29130
|
+
return this.resolve("update");
|
|
29131
|
+
}
|
|
29132
|
+
delete() {
|
|
29133
|
+
return this.resolve("delete");
|
|
29134
|
+
}
|
|
29135
|
+
// --- ROOT FACTORIES ---
|
|
29136
|
+
static database(id = "*") {
|
|
29137
|
+
return new Channel(["databases", normalize(id)]);
|
|
29138
|
+
}
|
|
29139
|
+
static tablesdb(id = "*") {
|
|
29140
|
+
return new Channel(["tablesdb", normalize(id)]);
|
|
29141
|
+
}
|
|
29142
|
+
static bucket(id = "*") {
|
|
29143
|
+
return new Channel(["buckets", normalize(id)]);
|
|
29144
|
+
}
|
|
29145
|
+
static function(id = "*") {
|
|
29146
|
+
return new Channel(["functions", normalize(id)]);
|
|
29147
|
+
}
|
|
29148
|
+
static team(id = "*") {
|
|
29149
|
+
return new Channel(["teams", normalize(id)]);
|
|
29150
|
+
}
|
|
29151
|
+
static membership(id = "*") {
|
|
29152
|
+
return new Channel(["memberships", normalize(id)]);
|
|
29153
|
+
}
|
|
29154
|
+
static account(userId = "") {
|
|
29155
|
+
const id = normalize(userId);
|
|
29156
|
+
return id === "*" ? "account" : `account.${id}`;
|
|
29157
|
+
}
|
|
29158
|
+
// Global events
|
|
29159
|
+
static get documents() {
|
|
29160
|
+
return "documents";
|
|
29161
|
+
}
|
|
29162
|
+
static get rows() {
|
|
29163
|
+
return "rows";
|
|
29164
|
+
}
|
|
29165
|
+
static get files() {
|
|
29166
|
+
return "files";
|
|
29167
|
+
}
|
|
29168
|
+
static get executions() {
|
|
29169
|
+
return "executions";
|
|
29170
|
+
}
|
|
29171
|
+
}
|
|
29172
|
+
|
|
28992
29173
|
exports.Condition = void 0;
|
|
28993
29174
|
(function (Condition) {
|
|
28994
29175
|
Condition["Equal"] = "equal";
|
|
@@ -30817,6 +30998,7 @@
|
|
|
30817
30998
|
exports.Assistant = Assistant;
|
|
30818
30999
|
exports.Avatars = Avatars;
|
|
30819
31000
|
exports.Backups = Backups;
|
|
31001
|
+
exports.Channel = Channel;
|
|
30820
31002
|
exports.Client = Client;
|
|
30821
31003
|
exports.Console = Console;
|
|
30822
31004
|
exports.Databases = Databases;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@appwrite.io/console",
|
|
3
3
|
"homepage": "https://appwrite.io/support",
|
|
4
4
|
"description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
|
|
5
|
-
"version": "2.1.
|
|
5
|
+
"version": "2.1.3",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "dist/cjs/sdk.js",
|
|
8
8
|
"exports": {
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"build:libs": "rollup -c"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"json-bigint": "1.0.0"
|
|
28
|
+
"json-bigint": "1.0.0",
|
|
29
|
+
"bignumber.js": "9.0.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@rollup/plugin-commonjs": "22.0.0",
|
package/src/channel.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
interface Root {}
|
|
2
|
+
interface Database { _db: any }
|
|
3
|
+
interface Collection { _coll: any }
|
|
4
|
+
interface Document { _doc: any }
|
|
5
|
+
interface TablesDB { _tdb: any }
|
|
6
|
+
interface Table { _tbl: any }
|
|
7
|
+
interface Row { _row: any }
|
|
8
|
+
interface Bucket { _bkt: any }
|
|
9
|
+
interface File { _file: any }
|
|
10
|
+
interface Func { _fn: any }
|
|
11
|
+
interface Execution { _exec: any }
|
|
12
|
+
interface Team { _team: any }
|
|
13
|
+
interface Membership { _mem: any }
|
|
14
|
+
interface Resolved { _res: any }
|
|
15
|
+
|
|
16
|
+
type Actionable = Document | Row | File | Execution | Team | Membership;
|
|
17
|
+
|
|
18
|
+
function normalize(id: string): string {
|
|
19
|
+
const trimmed = id.trim();
|
|
20
|
+
return trimmed === "" ? "*" : trimmed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Channel<T> {
|
|
24
|
+
declare _type: T;
|
|
25
|
+
|
|
26
|
+
private constructor(private readonly segments: string[]) {}
|
|
27
|
+
|
|
28
|
+
private next<N>(segment: string, id: string = "*"): Channel<N> {
|
|
29
|
+
return new Channel<N>([...this.segments, segment, normalize(id)]) as any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private resolve(action: string): Channel<Resolved> {
|
|
33
|
+
return new Channel<Resolved>([...this.segments, action]) as any;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toString(): string {
|
|
37
|
+
return this.segments.join(".");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- DATABASE ROUTE ---
|
|
41
|
+
// Only available on Channel<Database>
|
|
42
|
+
collection(this: Channel<Database>, id: string = "*"): Channel<Collection> {
|
|
43
|
+
return this.next<Collection>("collections", id);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Only available on Channel<Collection>
|
|
47
|
+
document(this: Channel<Collection>, id: string = "*"): Channel<Document> {
|
|
48
|
+
return this.next<Document>("documents", id);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --- TABLESDB ROUTE ---
|
|
52
|
+
table(this: Channel<TablesDB>, id: string = "*"): Channel<Table> {
|
|
53
|
+
return this.next<Table>("tables", id);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
row(this: Channel<Table>, id: string = "*"): Channel<Row> {
|
|
57
|
+
return this.next<Row>("rows", id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- BUCKET ROUTE ---
|
|
61
|
+
file(this: Channel<Bucket>, id: string = "*"): Channel<File> {
|
|
62
|
+
return this.next<File>("files", id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- FUNCTION ROUTE ---
|
|
66
|
+
execution(this: Channel<Func>, id: string = "*"): Channel<Execution> {
|
|
67
|
+
return this.next<Execution>("executions", id);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// --- TERMINAL ACTIONS ---
|
|
71
|
+
// Restricted to the Actionable union
|
|
72
|
+
create(this: Channel<Actionable>): Channel<Resolved> {
|
|
73
|
+
return this.resolve("create");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
update(this: Channel<Actionable>): Channel<Resolved> {
|
|
77
|
+
return this.resolve("update");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
delete(this: Channel<Actionable>): Channel<Resolved> {
|
|
81
|
+
return this.resolve("delete");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --- ROOT FACTORIES ---
|
|
85
|
+
static database(id: string = "*") {
|
|
86
|
+
return new Channel<Database>(["databases", normalize(id)]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static tablesdb(id: string = "*") {
|
|
90
|
+
return new Channel<TablesDB>(["tablesdb", normalize(id)]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static bucket(id: string = "*") {
|
|
94
|
+
return new Channel<Bucket>(["buckets", normalize(id)]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static function(id: string = "*") {
|
|
98
|
+
return new Channel<Func>(["functions", normalize(id)]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static team(id: string = "*") {
|
|
102
|
+
return new Channel<Team>(["teams", normalize(id)]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static membership(id: string = "*") {
|
|
106
|
+
return new Channel<Membership>(["memberships", normalize(id)]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static account(userId: string = ""): string {
|
|
110
|
+
const id = normalize(userId);
|
|
111
|
+
return id === "*" ? "account" : `account.${id}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Global events
|
|
115
|
+
static get documents(): string {
|
|
116
|
+
return "documents";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static get rows(): string {
|
|
120
|
+
return "rows";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static get files(): string {
|
|
124
|
+
return "files";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static get executions(): string {
|
|
128
|
+
return "executions";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Export types for backward compatibility with realtime
|
|
133
|
+
export type ActionableChannel = Channel<Document> | Channel<Row> | Channel<File> | Channel<Execution> | Channel<Team> | Channel<Membership>;
|
|
134
|
+
export type ResolvedChannel = Channel<Resolved>;
|