@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/esm/sdk.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import JSONbigModule from 'json-bigint';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
2
3
|
|
|
3
4
|
/******************************************************************************
|
|
4
5
|
Copyright (c) Microsoft Corporation.
|
|
@@ -84,6 +85,14 @@ Query.equal = (attribute, value) => new Query("equal", attribute, value).toStrin
|
|
|
84
85
|
* @returns {string}
|
|
85
86
|
*/
|
|
86
87
|
Query.notEqual = (attribute, value) => new Query("notEqual", attribute, value).toString();
|
|
88
|
+
/**
|
|
89
|
+
* Filter resources where attribute matches a regular expression pattern.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} attribute The attribute to filter on.
|
|
92
|
+
* @param {string} pattern The regular expression pattern to match.
|
|
93
|
+
* @returns {string}
|
|
94
|
+
*/
|
|
95
|
+
Query.regex = (attribute, pattern) => new Query("regex", attribute, pattern).toString();
|
|
87
96
|
/**
|
|
88
97
|
* Filter resources where attribute is less than value.
|
|
89
98
|
*
|
|
@@ -130,6 +139,20 @@ Query.isNull = (attribute) => new Query("isNull", attribute).toString();
|
|
|
130
139
|
* @returns {string}
|
|
131
140
|
*/
|
|
132
141
|
Query.isNotNull = (attribute) => new Query("isNotNull", attribute).toString();
|
|
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
|
+
Query.exists = (attributes) => new Query("exists", undefined, attributes).toString();
|
|
149
|
+
/**
|
|
150
|
+
* Filter resources where the specified attributes do not exist.
|
|
151
|
+
*
|
|
152
|
+
* @param {string[]} attributes The list of attributes that must not exist.
|
|
153
|
+
* @returns {string}
|
|
154
|
+
*/
|
|
155
|
+
Query.notExists = (attributes) => new Query("notExists", undefined, attributes).toString();
|
|
133
156
|
/**
|
|
134
157
|
* Filter resources where attribute is between start and end (inclusive).
|
|
135
158
|
*
|
|
@@ -327,6 +350,14 @@ Query.or = (queries) => new Query("or", undefined, queries.map((query) => JSONbi
|
|
|
327
350
|
* @returns {string}
|
|
328
351
|
*/
|
|
329
352
|
Query.and = (queries) => new Query("and", undefined, queries.map((query) => JSONbig$1.parse(query))).toString();
|
|
353
|
+
/**
|
|
354
|
+
* Filter array elements where at least one element matches all the specified queries.
|
|
355
|
+
*
|
|
356
|
+
* @param {string} attribute The attribute containing the array to filter on.
|
|
357
|
+
* @param {string[]} queries The list of query strings to match against array elements.
|
|
358
|
+
* @returns {string}
|
|
359
|
+
*/
|
|
360
|
+
Query.elemMatch = (attribute, queries) => new Query("elemMatch", attribute, queries.map((query) => JSONbig$1.parse(query))).toString();
|
|
330
361
|
/**
|
|
331
362
|
* Filter resources where attribute is at a specific distance from the given coordinates.
|
|
332
363
|
*
|
|
@@ -432,7 +463,47 @@ Query.touches = (attribute, values) => new Query("touches", attribute, [values])
|
|
|
432
463
|
*/
|
|
433
464
|
Query.notTouches = (attribute, values) => new Query("notTouches", attribute, [values]).toString();
|
|
434
465
|
|
|
435
|
-
const
|
|
466
|
+
const JSONbigParser = JSONbigModule({ storeAsString: false });
|
|
467
|
+
const JSONbigSerializer = JSONbigModule({ useNativeBigInt: true });
|
|
468
|
+
/**
|
|
469
|
+
* Converts BigNumber objects from json-bigint to native types.
|
|
470
|
+
* - Integer BigNumbers → BigInt (if unsafe) or number (if safe)
|
|
471
|
+
* - Float BigNumbers → number
|
|
472
|
+
* - Strings remain strings (never converted to BigNumber by json-bigint)
|
|
473
|
+
*/
|
|
474
|
+
const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
|
|
475
|
+
const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
|
|
476
|
+
function convertBigNumbers(value) {
|
|
477
|
+
if (value === null || value === undefined)
|
|
478
|
+
return value;
|
|
479
|
+
if (Array.isArray(value)) {
|
|
480
|
+
return value.map(convertBigNumbers);
|
|
481
|
+
}
|
|
482
|
+
if (BigNumber.isBigNumber(value)) {
|
|
483
|
+
if (value.isInteger()) {
|
|
484
|
+
const str = value.toFixed();
|
|
485
|
+
const bi = BigInt(str);
|
|
486
|
+
if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
|
|
487
|
+
return Number(str);
|
|
488
|
+
}
|
|
489
|
+
return bi;
|
|
490
|
+
}
|
|
491
|
+
// float
|
|
492
|
+
return value.toNumber();
|
|
493
|
+
}
|
|
494
|
+
if (typeof value === 'object') {
|
|
495
|
+
const result = {};
|
|
496
|
+
for (const [k, v] of Object.entries(value)) {
|
|
497
|
+
result[k] = convertBigNumbers(v);
|
|
498
|
+
}
|
|
499
|
+
return result;
|
|
500
|
+
}
|
|
501
|
+
return value;
|
|
502
|
+
}
|
|
503
|
+
const JSONbig = {
|
|
504
|
+
parse: (text) => convertBigNumbers(JSONbigParser.parse(text)),
|
|
505
|
+
stringify: JSONbigSerializer.stringify
|
|
506
|
+
};
|
|
436
507
|
/**
|
|
437
508
|
* Exception thrown by the package
|
|
438
509
|
*/
|
|
@@ -482,7 +553,7 @@ class Client {
|
|
|
482
553
|
'x-sdk-name': 'Console',
|
|
483
554
|
'x-sdk-platform': 'console',
|
|
484
555
|
'x-sdk-language': 'web',
|
|
485
|
-
'x-sdk-version': '2.1.
|
|
556
|
+
'x-sdk-version': '2.1.3',
|
|
486
557
|
'X-Appwrite-Response-Format': '1.8.0',
|
|
487
558
|
};
|
|
488
559
|
this.realtime = {
|
|
@@ -784,8 +855,8 @@ class Client {
|
|
|
784
855
|
* @deprecated Use the Realtime service instead.
|
|
785
856
|
* @see Realtime
|
|
786
857
|
*
|
|
787
|
-
* @param {string|string[]} channels
|
|
788
|
-
* Channel to subscribe - pass a single channel as a string or multiple with an array
|
|
858
|
+
* @param {string|string[]|Channel<any>|ActionableChannel|ResolvedChannel|(Channel<any>|ActionableChannel|ResolvedChannel)[]} channels
|
|
859
|
+
* Channel to subscribe - pass a single channel as a string or Channel builder instance, or multiple with an array.
|
|
789
860
|
*
|
|
790
861
|
* Possible channels are:
|
|
791
862
|
* - account
|
|
@@ -803,21 +874,40 @@ class Client {
|
|
|
803
874
|
* - teams.[ID]
|
|
804
875
|
* - memberships
|
|
805
876
|
* - memberships.[ID]
|
|
877
|
+
*
|
|
878
|
+
* You can also use Channel builders:
|
|
879
|
+
* - Channel.database('db').collection('col').document('doc').create()
|
|
880
|
+
* - Channel.bucket('bucket').file('file').update()
|
|
881
|
+
* - Channel.function('func').execution('exec').delete()
|
|
882
|
+
* - Channel.team('team').create()
|
|
883
|
+
* - Channel.membership('membership').update()
|
|
806
884
|
* @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
|
|
807
885
|
* @returns {() => void} Unsubscribes from events.
|
|
808
886
|
*/
|
|
809
887
|
subscribe(channels, callback) {
|
|
810
|
-
|
|
811
|
-
|
|
888
|
+
const channelArray = Array.isArray(channels) ? channels : [channels];
|
|
889
|
+
// Convert Channel instances to strings
|
|
890
|
+
const channelStrings = channelArray.map(ch => {
|
|
891
|
+
if (typeof ch === 'string') {
|
|
892
|
+
return ch;
|
|
893
|
+
}
|
|
894
|
+
// All Channel instances have toString() method
|
|
895
|
+
if (ch && typeof ch.toString === 'function') {
|
|
896
|
+
return ch.toString();
|
|
897
|
+
}
|
|
898
|
+
// Fallback to generic string conversion
|
|
899
|
+
return String(ch);
|
|
900
|
+
});
|
|
901
|
+
channelStrings.forEach(channel => this.realtime.channels.add(channel));
|
|
812
902
|
const counter = this.realtime.subscriptionsCounter++;
|
|
813
903
|
this.realtime.subscriptions.set(counter, {
|
|
814
|
-
channels:
|
|
904
|
+
channels: channelStrings,
|
|
815
905
|
callback
|
|
816
906
|
});
|
|
817
907
|
this.realtime.connect();
|
|
818
908
|
return () => {
|
|
819
909
|
this.realtime.subscriptions.delete(counter);
|
|
820
|
-
this.realtime.cleanUp(
|
|
910
|
+
this.realtime.cleanUp(channelStrings);
|
|
821
911
|
this.realtime.connect();
|
|
822
912
|
};
|
|
823
913
|
}
|
|
@@ -24917,11 +25007,31 @@ class Realtime {
|
|
|
24917
25007
|
sleep(ms) {
|
|
24918
25008
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
24919
25009
|
}
|
|
25010
|
+
/**
|
|
25011
|
+
* Convert a channel value to a string
|
|
25012
|
+
*
|
|
25013
|
+
* @private
|
|
25014
|
+
* @param {string | Channel<any> | ActionableChannel | ResolvedChannel} channel - Channel value (string or Channel builder instance)
|
|
25015
|
+
* @returns {string} Channel string representation
|
|
25016
|
+
*/
|
|
25017
|
+
channelToString(channel) {
|
|
25018
|
+
if (typeof channel === 'string') {
|
|
25019
|
+
return channel;
|
|
25020
|
+
}
|
|
25021
|
+
// All Channel instances have toString() method
|
|
25022
|
+
if (channel && typeof channel.toString === 'function') {
|
|
25023
|
+
return channel.toString();
|
|
25024
|
+
}
|
|
25025
|
+
return String(channel);
|
|
25026
|
+
}
|
|
24920
25027
|
subscribe(channelsOrChannel, callback) {
|
|
24921
25028
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24922
|
-
const
|
|
24923
|
-
?
|
|
24924
|
-
:
|
|
25029
|
+
const channelArray = Array.isArray(channelsOrChannel)
|
|
25030
|
+
? channelsOrChannel
|
|
25031
|
+
: [channelsOrChannel];
|
|
25032
|
+
// Convert all channels to strings
|
|
25033
|
+
const channelStrings = channelArray.map(ch => this.channelToString(ch));
|
|
25034
|
+
const channels = new Set(channelStrings);
|
|
24925
25035
|
this.subscriptionsCounter++;
|
|
24926
25036
|
const count = this.subscriptionsCounter;
|
|
24927
25037
|
for (const channel of channels) {
|
|
@@ -25225,6 +25335,96 @@ _a = ID, _ID_hexTimestamp = function _ID_hexTimestamp() {
|
|
|
25225
25335
|
return hexTimestamp;
|
|
25226
25336
|
};
|
|
25227
25337
|
|
|
25338
|
+
function normalize(id) {
|
|
25339
|
+
const trimmed = id.trim();
|
|
25340
|
+
return trimmed === "" ? "*" : trimmed;
|
|
25341
|
+
}
|
|
25342
|
+
class Channel {
|
|
25343
|
+
constructor(segments) {
|
|
25344
|
+
this.segments = segments;
|
|
25345
|
+
}
|
|
25346
|
+
next(segment, id = "*") {
|
|
25347
|
+
return new Channel([...this.segments, segment, normalize(id)]);
|
|
25348
|
+
}
|
|
25349
|
+
resolve(action) {
|
|
25350
|
+
return new Channel([...this.segments, action]);
|
|
25351
|
+
}
|
|
25352
|
+
toString() {
|
|
25353
|
+
return this.segments.join(".");
|
|
25354
|
+
}
|
|
25355
|
+
// --- DATABASE ROUTE ---
|
|
25356
|
+
// Only available on Channel<Database>
|
|
25357
|
+
collection(id = "*") {
|
|
25358
|
+
return this.next("collections", id);
|
|
25359
|
+
}
|
|
25360
|
+
// Only available on Channel<Collection>
|
|
25361
|
+
document(id = "*") {
|
|
25362
|
+
return this.next("documents", id);
|
|
25363
|
+
}
|
|
25364
|
+
// --- TABLESDB ROUTE ---
|
|
25365
|
+
table(id = "*") {
|
|
25366
|
+
return this.next("tables", id);
|
|
25367
|
+
}
|
|
25368
|
+
row(id = "*") {
|
|
25369
|
+
return this.next("rows", id);
|
|
25370
|
+
}
|
|
25371
|
+
// --- BUCKET ROUTE ---
|
|
25372
|
+
file(id = "*") {
|
|
25373
|
+
return this.next("files", id);
|
|
25374
|
+
}
|
|
25375
|
+
// --- FUNCTION ROUTE ---
|
|
25376
|
+
execution(id = "*") {
|
|
25377
|
+
return this.next("executions", id);
|
|
25378
|
+
}
|
|
25379
|
+
// --- TERMINAL ACTIONS ---
|
|
25380
|
+
// Restricted to the Actionable union
|
|
25381
|
+
create() {
|
|
25382
|
+
return this.resolve("create");
|
|
25383
|
+
}
|
|
25384
|
+
update() {
|
|
25385
|
+
return this.resolve("update");
|
|
25386
|
+
}
|
|
25387
|
+
delete() {
|
|
25388
|
+
return this.resolve("delete");
|
|
25389
|
+
}
|
|
25390
|
+
// --- ROOT FACTORIES ---
|
|
25391
|
+
static database(id = "*") {
|
|
25392
|
+
return new Channel(["databases", normalize(id)]);
|
|
25393
|
+
}
|
|
25394
|
+
static tablesdb(id = "*") {
|
|
25395
|
+
return new Channel(["tablesdb", normalize(id)]);
|
|
25396
|
+
}
|
|
25397
|
+
static bucket(id = "*") {
|
|
25398
|
+
return new Channel(["buckets", normalize(id)]);
|
|
25399
|
+
}
|
|
25400
|
+
static function(id = "*") {
|
|
25401
|
+
return new Channel(["functions", normalize(id)]);
|
|
25402
|
+
}
|
|
25403
|
+
static team(id = "*") {
|
|
25404
|
+
return new Channel(["teams", normalize(id)]);
|
|
25405
|
+
}
|
|
25406
|
+
static membership(id = "*") {
|
|
25407
|
+
return new Channel(["memberships", normalize(id)]);
|
|
25408
|
+
}
|
|
25409
|
+
static account(userId = "") {
|
|
25410
|
+
const id = normalize(userId);
|
|
25411
|
+
return id === "*" ? "account" : `account.${id}`;
|
|
25412
|
+
}
|
|
25413
|
+
// Global events
|
|
25414
|
+
static get documents() {
|
|
25415
|
+
return "documents";
|
|
25416
|
+
}
|
|
25417
|
+
static get rows() {
|
|
25418
|
+
return "rows";
|
|
25419
|
+
}
|
|
25420
|
+
static get files() {
|
|
25421
|
+
return "files";
|
|
25422
|
+
}
|
|
25423
|
+
static get executions() {
|
|
25424
|
+
return "executions";
|
|
25425
|
+
}
|
|
25426
|
+
}
|
|
25427
|
+
|
|
25228
25428
|
var Condition;
|
|
25229
25429
|
(function (Condition) {
|
|
25230
25430
|
Condition["Equal"] = "equal";
|
|
@@ -27048,5 +27248,5 @@ var BillingPlanGroup;
|
|
|
27048
27248
|
BillingPlanGroup["Scale"] = "scale";
|
|
27049
27249
|
})(BillingPlanGroup || (BillingPlanGroup = {}));
|
|
27050
27250
|
|
|
27051
|
-
export { Account, Adapter, Api, ApiService, AppwriteException, Assistant, AttributeStatus, AuthMethod, AuthenticationFactor, AuthenticatorType, Avatars, Backups, BillingPlan, BillingPlanGroup, Browser, BuildRuntime, Client, ColumnStatus, Compression, Condition, Console, ConsoleResourceType, CreditCard, DatabaseType, Databases, DeploymentDownloadType, DeploymentStatus, Domains, EmailTemplateLocale, EmailTemplateType, ExecutionMethod, ExecutionStatus, ExecutionTrigger, FilterType, Flag, Framework, Functions, Graphql, Health, HealthAntivirusStatus, HealthCheckStatus, ID, ImageFormat, ImageGravity, IndexStatus, IndexType, Locale, MessagePriority, MessageStatus, Messaging, MessagingProviderType, Migrations, Name, OAuthProvider, Operator, Organizations, PasswordHash, Permission, Platform, PlatformType, Project, ProjectUsageRange, Projects, Proxy, ProxyResourceType, ProxyRuleDeploymentResourceType, ProxyRuleStatus, Query, Realtime, Region, RelationMutate, RelationshipType, Role, Runtime, SMTPSecure, Sites, SmsTemplateLocale, SmsTemplateType, SmtpEncryption, Status, StatusCode, Storage, TablesDB, Teams, TemplateReferenceType, Theme, Timezone, Tokens, UsageRange, Users, VCSDetectionType, VCSReferenceType, Vcs };
|
|
27251
|
+
export { Account, Adapter, Api, ApiService, AppwriteException, Assistant, AttributeStatus, AuthMethod, AuthenticationFactor, AuthenticatorType, Avatars, Backups, BillingPlan, BillingPlanGroup, Browser, BuildRuntime, Channel, Client, ColumnStatus, Compression, Condition, Console, ConsoleResourceType, CreditCard, DatabaseType, Databases, DeploymentDownloadType, DeploymentStatus, Domains, EmailTemplateLocale, EmailTemplateType, ExecutionMethod, ExecutionStatus, ExecutionTrigger, FilterType, Flag, Framework, Functions, Graphql, Health, HealthAntivirusStatus, HealthCheckStatus, ID, ImageFormat, ImageGravity, IndexStatus, IndexType, Locale, MessagePriority, MessageStatus, Messaging, MessagingProviderType, Migrations, Name, OAuthProvider, Operator, Organizations, PasswordHash, Permission, Platform, PlatformType, Project, ProjectUsageRange, Projects, Proxy, ProxyResourceType, ProxyRuleDeploymentResourceType, ProxyRuleStatus, Query, Realtime, Region, RelationMutate, RelationshipType, Role, Runtime, SMTPSecure, Sites, SmsTemplateLocale, SmsTemplateType, SmtpEncryption, Status, StatusCode, Storage, TablesDB, Teams, TemplateReferenceType, Theme, Timezone, Tokens, UsageRange, Users, VCSDetectionType, VCSReferenceType, Vcs };
|
|
27052
27252
|
//# sourceMappingURL=sdk.js.map
|