@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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.1.3
4
+
5
+ Fix bigint and float parsing in SDK.
6
+
3
7
  ## 2.1.2
4
8
 
5
9
  * Fix only use `bigint` for min, max and default attributes
package/README.md CHANGED
@@ -33,7 +33,7 @@ import { Client, Account } from "@appwrite.io/console";
33
33
  To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
34
34
 
35
35
  ```html
36
- <script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@2.1.2"></script>
36
+ <script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@2.1.3"></script>
37
37
  ```
38
38
 
39
39
 
package/dist/cjs/sdk.js CHANGED
@@ -1,10 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var JSONbigModule = require('json-bigint');
4
+ var BigNumber = require('bignumber.js');
4
5
 
5
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
7
 
7
8
  var JSONbigModule__default = /*#__PURE__*/_interopDefaultLegacy(JSONbigModule);
9
+ var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
8
10
 
9
11
  /******************************************************************************
10
12
  Copyright (c) Microsoft Corporation.
@@ -90,6 +92,14 @@ Query.equal = (attribute, value) => new Query("equal", attribute, value).toStrin
90
92
  * @returns {string}
91
93
  */
92
94
  Query.notEqual = (attribute, value) => new Query("notEqual", attribute, value).toString();
95
+ /**
96
+ * Filter resources where attribute matches a regular expression pattern.
97
+ *
98
+ * @param {string} attribute The attribute to filter on.
99
+ * @param {string} pattern The regular expression pattern to match.
100
+ * @returns {string}
101
+ */
102
+ Query.regex = (attribute, pattern) => new Query("regex", attribute, pattern).toString();
93
103
  /**
94
104
  * Filter resources where attribute is less than value.
95
105
  *
@@ -136,6 +146,20 @@ Query.isNull = (attribute) => new Query("isNull", attribute).toString();
136
146
  * @returns {string}
137
147
  */
138
148
  Query.isNotNull = (attribute) => new Query("isNotNull", attribute).toString();
149
+ /**
150
+ * Filter resources where the specified attributes exist.
151
+ *
152
+ * @param {string[]} attributes The list of attributes that must exist.
153
+ * @returns {string}
154
+ */
155
+ Query.exists = (attributes) => new Query("exists", undefined, attributes).toString();
156
+ /**
157
+ * Filter resources where the specified attributes do not exist.
158
+ *
159
+ * @param {string[]} attributes The list of attributes that must not exist.
160
+ * @returns {string}
161
+ */
162
+ Query.notExists = (attributes) => new Query("notExists", undefined, attributes).toString();
139
163
  /**
140
164
  * Filter resources where attribute is between start and end (inclusive).
141
165
  *
@@ -333,6 +357,14 @@ Query.or = (queries) => new Query("or", undefined, queries.map((query) => JSONbi
333
357
  * @returns {string}
334
358
  */
335
359
  Query.and = (queries) => new Query("and", undefined, queries.map((query) => JSONbig$1.parse(query))).toString();
360
+ /**
361
+ * Filter array elements where at least one element matches all the specified queries.
362
+ *
363
+ * @param {string} attribute The attribute containing the array to filter on.
364
+ * @param {string[]} queries The list of query strings to match against array elements.
365
+ * @returns {string}
366
+ */
367
+ Query.elemMatch = (attribute, queries) => new Query("elemMatch", attribute, queries.map((query) => JSONbig$1.parse(query))).toString();
336
368
  /**
337
369
  * Filter resources where attribute is at a specific distance from the given coordinates.
338
370
  *
@@ -438,7 +470,47 @@ Query.touches = (attribute, values) => new Query("touches", attribute, [values])
438
470
  */
439
471
  Query.notTouches = (attribute, values) => new Query("notTouches", attribute, [values]).toString();
440
472
 
441
- const JSONbig = JSONbigModule__default["default"]({ useNativeBigInt: true });
473
+ const JSONbigParser = JSONbigModule__default["default"]({ storeAsString: false });
474
+ const JSONbigSerializer = JSONbigModule__default["default"]({ useNativeBigInt: true });
475
+ /**
476
+ * Converts BigNumber objects from json-bigint to native types.
477
+ * - Integer BigNumbers → BigInt (if unsafe) or number (if safe)
478
+ * - Float BigNumbers → number
479
+ * - Strings remain strings (never converted to BigNumber by json-bigint)
480
+ */
481
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
482
+ const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
483
+ function convertBigNumbers(value) {
484
+ if (value === null || value === undefined)
485
+ return value;
486
+ if (Array.isArray(value)) {
487
+ return value.map(convertBigNumbers);
488
+ }
489
+ if (BigNumber__default["default"].isBigNumber(value)) {
490
+ if (value.isInteger()) {
491
+ const str = value.toFixed();
492
+ const bi = BigInt(str);
493
+ if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
494
+ return Number(str);
495
+ }
496
+ return bi;
497
+ }
498
+ // float
499
+ return value.toNumber();
500
+ }
501
+ if (typeof value === 'object') {
502
+ const result = {};
503
+ for (const [k, v] of Object.entries(value)) {
504
+ result[k] = convertBigNumbers(v);
505
+ }
506
+ return result;
507
+ }
508
+ return value;
509
+ }
510
+ const JSONbig = {
511
+ parse: (text) => convertBigNumbers(JSONbigParser.parse(text)),
512
+ stringify: JSONbigSerializer.stringify
513
+ };
442
514
  /**
443
515
  * Exception thrown by the package
444
516
  */
@@ -488,7 +560,7 @@ class Client {
488
560
  'x-sdk-name': 'Console',
489
561
  'x-sdk-platform': 'console',
490
562
  'x-sdk-language': 'web',
491
- 'x-sdk-version': '2.1.2',
563
+ 'x-sdk-version': '2.1.3',
492
564
  'X-Appwrite-Response-Format': '1.8.0',
493
565
  };
494
566
  this.realtime = {
@@ -790,8 +862,8 @@ class Client {
790
862
  * @deprecated Use the Realtime service instead.
791
863
  * @see Realtime
792
864
  *
793
- * @param {string|string[]} channels
794
- * Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
865
+ * @param {string|string[]|Channel<any>|ActionableChannel|ResolvedChannel|(Channel<any>|ActionableChannel|ResolvedChannel)[]} channels
866
+ * Channel to subscribe - pass a single channel as a string or Channel builder instance, or multiple with an array.
795
867
  *
796
868
  * Possible channels are:
797
869
  * - account
@@ -809,21 +881,40 @@ class Client {
809
881
  * - teams.[ID]
810
882
  * - memberships
811
883
  * - memberships.[ID]
884
+ *
885
+ * You can also use Channel builders:
886
+ * - Channel.database('db').collection('col').document('doc').create()
887
+ * - Channel.bucket('bucket').file('file').update()
888
+ * - Channel.function('func').execution('exec').delete()
889
+ * - Channel.team('team').create()
890
+ * - Channel.membership('membership').update()
812
891
  * @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
813
892
  * @returns {() => void} Unsubscribes from events.
814
893
  */
815
894
  subscribe(channels, callback) {
816
- let channelArray = typeof channels === 'string' ? [channels] : channels;
817
- channelArray.forEach(channel => this.realtime.channels.add(channel));
895
+ const channelArray = Array.isArray(channels) ? channels : [channels];
896
+ // Convert Channel instances to strings
897
+ const channelStrings = channelArray.map(ch => {
898
+ if (typeof ch === 'string') {
899
+ return ch;
900
+ }
901
+ // All Channel instances have toString() method
902
+ if (ch && typeof ch.toString === 'function') {
903
+ return ch.toString();
904
+ }
905
+ // Fallback to generic string conversion
906
+ return String(ch);
907
+ });
908
+ channelStrings.forEach(channel => this.realtime.channels.add(channel));
818
909
  const counter = this.realtime.subscriptionsCounter++;
819
910
  this.realtime.subscriptions.set(counter, {
820
- channels: channelArray,
911
+ channels: channelStrings,
821
912
  callback
822
913
  });
823
914
  this.realtime.connect();
824
915
  return () => {
825
916
  this.realtime.subscriptions.delete(counter);
826
- this.realtime.cleanUp(channelArray);
917
+ this.realtime.cleanUp(channelStrings);
827
918
  this.realtime.connect();
828
919
  };
829
920
  }
@@ -24923,11 +25014,31 @@ class Realtime {
24923
25014
  sleep(ms) {
24924
25015
  return new Promise(resolve => setTimeout(resolve, ms));
24925
25016
  }
25017
+ /**
25018
+ * Convert a channel value to a string
25019
+ *
25020
+ * @private
25021
+ * @param {string | Channel<any> | ActionableChannel | ResolvedChannel} channel - Channel value (string or Channel builder instance)
25022
+ * @returns {string} Channel string representation
25023
+ */
25024
+ channelToString(channel) {
25025
+ if (typeof channel === 'string') {
25026
+ return channel;
25027
+ }
25028
+ // All Channel instances have toString() method
25029
+ if (channel && typeof channel.toString === 'function') {
25030
+ return channel.toString();
25031
+ }
25032
+ return String(channel);
25033
+ }
24926
25034
  subscribe(channelsOrChannel, callback) {
24927
25035
  return __awaiter(this, void 0, void 0, function* () {
24928
- const channels = Array.isArray(channelsOrChannel)
24929
- ? new Set(channelsOrChannel)
24930
- : new Set([channelsOrChannel]);
25036
+ const channelArray = Array.isArray(channelsOrChannel)
25037
+ ? channelsOrChannel
25038
+ : [channelsOrChannel];
25039
+ // Convert all channels to strings
25040
+ const channelStrings = channelArray.map(ch => this.channelToString(ch));
25041
+ const channels = new Set(channelStrings);
24931
25042
  this.subscriptionsCounter++;
24932
25043
  const count = this.subscriptionsCounter;
24933
25044
  for (const channel of channels) {
@@ -25231,6 +25342,96 @@ _a = ID, _ID_hexTimestamp = function _ID_hexTimestamp() {
25231
25342
  return hexTimestamp;
25232
25343
  };
25233
25344
 
25345
+ function normalize(id) {
25346
+ const trimmed = id.trim();
25347
+ return trimmed === "" ? "*" : trimmed;
25348
+ }
25349
+ class Channel {
25350
+ constructor(segments) {
25351
+ this.segments = segments;
25352
+ }
25353
+ next(segment, id = "*") {
25354
+ return new Channel([...this.segments, segment, normalize(id)]);
25355
+ }
25356
+ resolve(action) {
25357
+ return new Channel([...this.segments, action]);
25358
+ }
25359
+ toString() {
25360
+ return this.segments.join(".");
25361
+ }
25362
+ // --- DATABASE ROUTE ---
25363
+ // Only available on Channel<Database>
25364
+ collection(id = "*") {
25365
+ return this.next("collections", id);
25366
+ }
25367
+ // Only available on Channel<Collection>
25368
+ document(id = "*") {
25369
+ return this.next("documents", id);
25370
+ }
25371
+ // --- TABLESDB ROUTE ---
25372
+ table(id = "*") {
25373
+ return this.next("tables", id);
25374
+ }
25375
+ row(id = "*") {
25376
+ return this.next("rows", id);
25377
+ }
25378
+ // --- BUCKET ROUTE ---
25379
+ file(id = "*") {
25380
+ return this.next("files", id);
25381
+ }
25382
+ // --- FUNCTION ROUTE ---
25383
+ execution(id = "*") {
25384
+ return this.next("executions", id);
25385
+ }
25386
+ // --- TERMINAL ACTIONS ---
25387
+ // Restricted to the Actionable union
25388
+ create() {
25389
+ return this.resolve("create");
25390
+ }
25391
+ update() {
25392
+ return this.resolve("update");
25393
+ }
25394
+ delete() {
25395
+ return this.resolve("delete");
25396
+ }
25397
+ // --- ROOT FACTORIES ---
25398
+ static database(id = "*") {
25399
+ return new Channel(["databases", normalize(id)]);
25400
+ }
25401
+ static tablesdb(id = "*") {
25402
+ return new Channel(["tablesdb", normalize(id)]);
25403
+ }
25404
+ static bucket(id = "*") {
25405
+ return new Channel(["buckets", normalize(id)]);
25406
+ }
25407
+ static function(id = "*") {
25408
+ return new Channel(["functions", normalize(id)]);
25409
+ }
25410
+ static team(id = "*") {
25411
+ return new Channel(["teams", normalize(id)]);
25412
+ }
25413
+ static membership(id = "*") {
25414
+ return new Channel(["memberships", normalize(id)]);
25415
+ }
25416
+ static account(userId = "") {
25417
+ const id = normalize(userId);
25418
+ return id === "*" ? "account" : `account.${id}`;
25419
+ }
25420
+ // Global events
25421
+ static get documents() {
25422
+ return "documents";
25423
+ }
25424
+ static get rows() {
25425
+ return "rows";
25426
+ }
25427
+ static get files() {
25428
+ return "files";
25429
+ }
25430
+ static get executions() {
25431
+ return "executions";
25432
+ }
25433
+ }
25434
+
25234
25435
  exports.Condition = void 0;
25235
25436
  (function (Condition) {
25236
25437
  Condition["Equal"] = "equal";
@@ -27059,6 +27260,7 @@ exports.AppwriteException = AppwriteException;
27059
27260
  exports.Assistant = Assistant;
27060
27261
  exports.Avatars = Avatars;
27061
27262
  exports.Backups = Backups;
27263
+ exports.Channel = Channel;
27062
27264
  exports.Client = Client;
27063
27265
  exports.Console = Console;
27064
27266
  exports.Databases = Databases;