@appwrite.io/console 2.1.2 → 2.2.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/sdk.js +2099 -520
  4. package/dist/cjs/sdk.js.map +1 -1
  5. package/dist/esm/sdk.js +2098 -521
  6. package/dist/esm/sdk.js.map +1 -1
  7. package/dist/iife/sdk.js +2003 -444
  8. package/docs/examples/account/create-key.md +15 -0
  9. package/docs/examples/account/delete-key.md +13 -0
  10. package/docs/examples/account/get-key.md +13 -0
  11. package/docs/examples/account/list-keys.md +13 -0
  12. package/docs/examples/account/update-key.md +16 -0
  13. package/docs/examples/avatars/get-screenshot.md +5 -5
  14. package/docs/examples/backups/create-archive.md +2 -2
  15. package/docs/examples/backups/create-policy.md +2 -2
  16. package/docs/examples/backups/create-restoration.md +2 -2
  17. package/docs/examples/console/{get-regions.md → list-regions.md} +1 -3
  18. package/docs/examples/databases/create-index.md +2 -2
  19. package/docs/examples/databases/create-longtext-attribute.md +18 -0
  20. package/docs/examples/databases/create-mediumtext-attribute.md +18 -0
  21. package/docs/examples/databases/create-text-attribute.md +18 -0
  22. package/docs/examples/databases/create-varchar-attribute.md +19 -0
  23. package/docs/examples/databases/update-collection.md +1 -1
  24. package/docs/examples/databases/update-longtext-attribute.md +18 -0
  25. package/docs/examples/databases/update-mediumtext-attribute.md +18 -0
  26. package/docs/examples/databases/update-text-attribute.md +18 -0
  27. package/docs/examples/databases/update-varchar-attribute.md +19 -0
  28. package/docs/examples/databases/update.md +1 -1
  29. package/docs/examples/functions/create.md +2 -2
  30. package/docs/examples/functions/list-templates.md +3 -3
  31. package/docs/examples/functions/update.md +2 -2
  32. package/docs/examples/migrations/create-appwrite-migration.md +2 -2
  33. package/docs/examples/migrations/create-firebase-migration.md +2 -2
  34. package/docs/examples/migrations/create-n-host-migration.md +2 -2
  35. package/docs/examples/migrations/create-supabase-migration.md +2 -2
  36. package/docs/examples/migrations/get-appwrite-report.md +2 -2
  37. package/docs/examples/migrations/get-firebase-report.md +2 -2
  38. package/docs/examples/migrations/get-n-host-report.md +2 -2
  39. package/docs/examples/migrations/get-supabase-report.md +2 -2
  40. package/docs/examples/organizations/create-key.md +16 -0
  41. package/docs/examples/organizations/create.md +2 -2
  42. package/docs/examples/organizations/delete-key.md +14 -0
  43. package/docs/examples/organizations/estimation-create-organization.md +2 -2
  44. package/docs/examples/organizations/estimation-update-plan.md +2 -2
  45. package/docs/examples/organizations/get-key.md +14 -0
  46. package/docs/examples/organizations/list-keys.md +14 -0
  47. package/docs/examples/organizations/list-regions.md +13 -0
  48. package/docs/examples/organizations/update-key.md +17 -0
  49. package/docs/examples/organizations/update-plan.md +2 -2
  50. package/docs/examples/projects/create-jwt.md +2 -2
  51. package/docs/examples/projects/create-key.md +2 -2
  52. package/docs/examples/projects/update-key.md +2 -2
  53. package/docs/examples/sites/list-templates.md +3 -3
  54. package/docs/examples/tablesdb/create-index.md +2 -2
  55. package/docs/examples/tablesdb/create-longtext-column.md +18 -0
  56. package/docs/examples/tablesdb/create-mediumtext-column.md +18 -0
  57. package/docs/examples/tablesdb/create-text-column.md +18 -0
  58. package/docs/examples/tablesdb/create-varchar-column.md +19 -0
  59. package/docs/examples/tablesdb/update-longtext-column.md +18 -0
  60. package/docs/examples/tablesdb/update-mediumtext-column.md +18 -0
  61. package/docs/examples/tablesdb/update-table.md +1 -1
  62. package/docs/examples/tablesdb/update-text-column.md +18 -0
  63. package/docs/examples/tablesdb/update-varchar-column.md +19 -0
  64. package/docs/examples/tablesdb/update.md +1 -1
  65. package/docs/examples/teams/create-membership.md +2 -2
  66. package/docs/examples/teams/update-membership.md +2 -2
  67. package/package.json +3 -2
  68. package/src/channel.ts +138 -0
  69. package/src/client.ts +54 -9
  70. package/src/enums/browser-permission.ts +22 -0
  71. package/src/enums/deployment-status.ts +1 -0
  72. package/src/enums/frameworks.ts +17 -0
  73. package/src/enums/order-by.ts +4 -0
  74. package/src/enums/resources.ts +13 -0
  75. package/src/enums/roles.ts +7 -0
  76. package/src/enums/runtimes.ts +66 -0
  77. package/src/enums/scopes.ts +65 -0
  78. package/src/enums/services.ts +5 -0
  79. package/src/enums/use-cases.ts +11 -0
  80. package/src/index.ts +10 -1
  81. package/src/models.ts +349 -1
  82. package/src/query.ts +42 -0
  83. package/src/services/account.ts +364 -56
  84. package/src/services/assistant.ts +1 -1
  85. package/src/services/avatars.ts +17 -16
  86. package/src/services/backups.ts +37 -36
  87. package/src/services/console.ts +11 -42
  88. package/src/services/databases.ts +1060 -280
  89. package/src/services/domains.ts +44 -44
  90. package/src/services/functions.ts +60 -57
  91. package/src/services/graphql.ts +2 -2
  92. package/src/services/health.ts +22 -20
  93. package/src/services/messaging.ts +56 -56
  94. package/src/services/migrations.ts +79 -78
  95. package/src/services/organizations.ts +466 -70
  96. package/src/services/project.ts +5 -5
  97. package/src/services/projects.ts +86 -85
  98. package/src/services/proxy.ts +8 -8
  99. package/src/services/realtime.ts +35 -12
  100. package/src/services/sites.ts +42 -40
  101. package/src/services/storage.ts +16 -16
  102. package/src/services/tables-db.ts +1050 -268
  103. package/src/services/teams.ts +31 -30
  104. package/src/services/tokens.ts +5 -5
  105. package/src/services/users.ts +49 -49
  106. package/src/services/vcs.ts +10 -10
  107. package/types/channel.d.ts +72 -0
  108. package/types/client.d.ts +11 -3
  109. package/types/enums/browser-permission.d.ts +22 -0
  110. package/types/enums/deployment-status.d.ts +1 -0
  111. package/types/enums/frameworks.d.ts +17 -0
  112. package/types/enums/order-by.d.ts +4 -0
  113. package/types/enums/resources.d.ts +13 -0
  114. package/types/enums/roles.d.ts +7 -0
  115. package/types/enums/runtimes.d.ts +66 -0
  116. package/types/enums/scopes.d.ts +65 -0
  117. package/types/enums/services.d.ts +5 -0
  118. package/types/enums/use-cases.d.ts +11 -0
  119. package/types/index.d.ts +10 -1
  120. package/types/models.d.ts +341 -1
  121. package/types/query.d.ts +30 -0
  122. package/types/services/account.d.ts +111 -0
  123. package/types/services/avatars.d.ts +5 -4
  124. package/types/services/backups.d.ts +13 -12
  125. package/types/services/console.d.ts +1 -13
  126. package/types/services/databases.d.ts +303 -8
  127. package/types/services/functions.d.ts +18 -15
  128. package/types/services/health.d.ts +2 -0
  129. package/types/services/migrations.d.ts +33 -32
  130. package/types/services/organizations.d.ts +161 -17
  131. package/types/services/projects.d.ts +13 -12
  132. package/types/services/realtime.d.ts +17 -8
  133. package/types/services/sites.d.ts +9 -7
  134. package/types/services/tables-db.d.ts +305 -8
  135. package/types/services/teams.d.ts +9 -8
  136. package/src/enums/billing-plan.ts +0 -17
  137. package/types/enums/billing-plan.d.ts +0 -17
@@ -0,0 +1,13 @@
1
+ import { Client, Organizations } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const organizations = new Organizations(client);
8
+
9
+ const result = await organizations.listRegions({
10
+ organizationId: '<ORGANIZATION_ID>'
11
+ });
12
+
13
+ console.log(result);
@@ -0,0 +1,17 @@
1
+ import { Client, Organizations, Scopes } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const organizations = new Organizations(client);
8
+
9
+ const result = await organizations.updateKey({
10
+ organizationId: '<ORGANIZATION_ID>',
11
+ keyId: '<KEY_ID>',
12
+ name: '<NAME>',
13
+ scopes: [Scopes.PlatformsRead],
14
+ expire: '' // optional
15
+ });
16
+
17
+ console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, Organizations, BillingPlan } from "@appwrite.io/console";
1
+ import { Client, Organizations } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -8,7 +8,7 @@ const organizations = new Organizations(client);
8
8
 
9
9
  const result = await organizations.updatePlan({
10
10
  organizationId: '<ORGANIZATION_ID>',
11
- billingPlan: BillingPlan.Tier0,
11
+ billingPlan: 'tier-0',
12
12
  paymentMethodId: '<PAYMENT_METHOD_ID>', // optional
13
13
  billingAddressId: '<BILLING_ADDRESS_ID>', // optional
14
14
  invites: [], // optional
@@ -1,4 +1,4 @@
1
- import { Client, Projects } from "@appwrite.io/console";
1
+ import { Client, Projects, Scopes } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -8,7 +8,7 @@ const projects = new Projects(client);
8
8
 
9
9
  const result = await projects.createJWT({
10
10
  projectId: '<PROJECT_ID>',
11
- scopes: [],
11
+ scopes: [Scopes.SessionsWrite],
12
12
  duration: 0 // optional
13
13
  });
14
14
 
@@ -1,4 +1,4 @@
1
- import { Client, Projects } from "@appwrite.io/console";
1
+ import { Client, Projects, Scopes } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -9,7 +9,7 @@ const projects = new Projects(client);
9
9
  const result = await projects.createKey({
10
10
  projectId: '<PROJECT_ID>',
11
11
  name: '<NAME>',
12
- scopes: [],
12
+ scopes: [Scopes.SessionsWrite],
13
13
  expire: '' // optional
14
14
  });
15
15
 
@@ -1,4 +1,4 @@
1
- import { Client, Projects } from "@appwrite.io/console";
1
+ import { Client, Projects, Scopes } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -10,7 +10,7 @@ const result = await projects.updateKey({
10
10
  projectId: '<PROJECT_ID>',
11
11
  keyId: '<KEY_ID>',
12
12
  name: '<NAME>',
13
- scopes: [],
13
+ scopes: [Scopes.SessionsWrite],
14
14
  expire: '' // optional
15
15
  });
16
16
 
@@ -1,4 +1,4 @@
1
- import { Client, Sites } from "@appwrite.io/console";
1
+ import { Client, Sites, Frameworks, UseCases } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -7,8 +7,8 @@ const client = new Client()
7
7
  const sites = new Sites(client);
8
8
 
9
9
  const result = await sites.listTemplates({
10
- frameworks: [], // optional
11
- useCases: [], // optional
10
+ frameworks: [Frameworks.Analog], // optional
11
+ useCases: [UseCases.Portfolio], // optional
12
12
  limit: 1, // optional
13
13
  offset: 0 // optional
14
14
  });
@@ -1,4 +1,4 @@
1
- import { Client, TablesDB, IndexType } from "@appwrite.io/console";
1
+ import { Client, TablesDB, IndexType, OrderBy } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -12,7 +12,7 @@ const result = await tablesDB.createIndex({
12
12
  key: '',
13
13
  type: IndexType.Key,
14
14
  columns: [],
15
- orders: [], // optional
15
+ orders: [OrderBy.Asc], // optional
16
16
  lengths: [] // optional
17
17
  });
18
18
 
@@ -0,0 +1,18 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.createLongtextColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>', // optional
15
+ array: false // optional
16
+ });
17
+
18
+ console.log(result);
@@ -0,0 +1,18 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.createMediumtextColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>', // optional
15
+ array: false // optional
16
+ });
17
+
18
+ console.log(result);
@@ -0,0 +1,18 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.createTextColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>', // optional
15
+ array: false // optional
16
+ });
17
+
18
+ console.log(result);
@@ -0,0 +1,19 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.createVarcharColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ size: 1,
14
+ required: false,
15
+ default: '<DEFAULT>', // optional
16
+ array: false // optional
17
+ });
18
+
19
+ console.log(result);
@@ -0,0 +1,18 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.updateLongtextColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>',
15
+ newKey: '' // optional
16
+ });
17
+
18
+ console.log(result);
@@ -0,0 +1,18 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.updateMediumtextColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>',
15
+ newKey: '' // optional
16
+ });
17
+
18
+ console.log(result);
@@ -9,7 +9,7 @@ const tablesDB = new TablesDB(client);
9
9
  const result = await tablesDB.updateTable({
10
10
  databaseId: '<DATABASE_ID>',
11
11
  tableId: '<TABLE_ID>',
12
- name: '<NAME>',
12
+ name: '<NAME>', // optional
13
13
  permissions: [Permission.read(Role.any())], // optional
14
14
  rowSecurity: false, // optional
15
15
  enabled: false // optional
@@ -0,0 +1,18 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.updateTextColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>',
15
+ newKey: '' // optional
16
+ });
17
+
18
+ console.log(result);
@@ -0,0 +1,19 @@
1
+ import { Client, TablesDB } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const tablesDB = new TablesDB(client);
8
+
9
+ const result = await tablesDB.updateVarcharColumn({
10
+ databaseId: '<DATABASE_ID>',
11
+ tableId: '<TABLE_ID>',
12
+ key: '',
13
+ required: false,
14
+ default: '<DEFAULT>',
15
+ size: 1, // optional
16
+ newKey: '' // optional
17
+ });
18
+
19
+ console.log(result);
@@ -8,7 +8,7 @@ const tablesDB = new TablesDB(client);
8
8
 
9
9
  const result = await tablesDB.update({
10
10
  databaseId: '<DATABASE_ID>',
11
- name: '<NAME>',
11
+ name: '<NAME>', // optional
12
12
  enabled: false // optional
13
13
  });
14
14
 
@@ -1,4 +1,4 @@
1
- import { Client, Teams } from "@appwrite.io/console";
1
+ import { Client, Teams, Roles } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -8,7 +8,7 @@ const teams = new Teams(client);
8
8
 
9
9
  const result = await teams.createMembership({
10
10
  teamId: '<TEAM_ID>',
11
- roles: [],
11
+ roles: [Roles.Developer],
12
12
  email: 'email@example.com', // optional
13
13
  userId: '<USER_ID>', // optional
14
14
  phone: '+12065550100', // optional
@@ -1,4 +1,4 @@
1
- import { Client, Teams } from "@appwrite.io/console";
1
+ import { Client, Teams, Roles } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -9,7 +9,7 @@ const teams = new Teams(client);
9
9
  const result = await teams.updateMembership({
10
10
  teamId: '<TEAM_ID>',
11
11
  membershipId: '<MEMBERSHIP_ID>',
12
- roles: []
12
+ roles: [Roles.Developer]
13
13
  });
14
14
 
15
15
  console.log(result);
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.2",
5
+ "version": "2.2.0",
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,138 @@
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 documents(): string {
116
+ return "documents";
117
+ }
118
+
119
+ static rows(): string {
120
+ return "rows";
121
+ }
122
+
123
+ static files(): string {
124
+ return "files";
125
+ }
126
+
127
+ static executions(): string {
128
+ return "executions";
129
+ }
130
+
131
+ static teams(): string {
132
+ return "teams";
133
+ }
134
+ }
135
+
136
+ // Export types for backward compatibility with realtime
137
+ export type ActionableChannel = Channel<Document> | Channel<Row> | Channel<File> | Channel<Execution> | Channel<Team> | Channel<Membership>;
138
+ export type ResolvedChannel = Channel<Resolved>;
package/src/client.ts CHANGED
@@ -1,6 +1,32 @@
1
1
  import { Models } from './models';
2
+ import { Channel, ActionableChannel, ResolvedChannel } from './channel';
2
3
  import JSONbigModule from 'json-bigint';
3
- const JSONbig = JSONbigModule({ useNativeBigInt: true });
4
+ import BigNumber from 'bignumber.js';
5
+ const JSONbigParser = JSONbigModule({ storeAsString: false });
6
+ const JSONbigSerializer = JSONbigModule({ useNativeBigInt: true });
7
+
8
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
9
+ const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
10
+
11
+ function reviver(_key: string, value: any): any {
12
+ if (BigNumber.isBigNumber(value)) {
13
+ if (value.isInteger()) {
14
+ const str = value.toFixed();
15
+ const bi = BigInt(str);
16
+ if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
17
+ return Number(str);
18
+ }
19
+ return bi;
20
+ }
21
+ return value.toNumber();
22
+ }
23
+ return value;
24
+ }
25
+
26
+ const JSONbig = {
27
+ parse: (text: string) => JSONbigParser.parse(text, reviver),
28
+ stringify: JSONbigSerializer.stringify
29
+ };
4
30
 
5
31
  /**
6
32
  * Payload type representing a key-value pair with string keys and any values.
@@ -334,7 +360,7 @@ class Client {
334
360
  'x-sdk-name': 'Console',
335
361
  'x-sdk-platform': 'console',
336
362
  'x-sdk-language': 'web',
337
- 'x-sdk-version': '2.1.2',
363
+ 'x-sdk-version': '2.2.0',
338
364
  'X-Appwrite-Response-Format': '1.8.0',
339
365
  };
340
366
 
@@ -654,8 +680,8 @@ class Client {
654
680
  * @deprecated Use the Realtime service instead.
655
681
  * @see Realtime
656
682
  *
657
- * @param {string|string[]} channels
658
- * Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
683
+ * @param {string|string[]|Channel<any>|ActionableChannel|ResolvedChannel|(Channel<any>|ActionableChannel|ResolvedChannel)[]} channels
684
+ * Channel to subscribe - pass a single channel as a string or Channel builder instance, or multiple with an array.
659
685
  *
660
686
  * Possible channels are:
661
687
  * - account
@@ -673,16 +699,35 @@ class Client {
673
699
  * - teams.[ID]
674
700
  * - memberships
675
701
  * - memberships.[ID]
702
+ *
703
+ * You can also use Channel builders:
704
+ * - Channel.database('db').collection('col').document('doc').create()
705
+ * - Channel.bucket('bucket').file('file').update()
706
+ * - Channel.function('func').execution('exec').delete()
707
+ * - Channel.team('team').create()
708
+ * - Channel.membership('membership').update()
676
709
  * @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
677
710
  * @returns {() => void} Unsubscribes from events.
678
711
  */
679
- subscribe<T extends unknown>(channels: string | string[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
680
- let channelArray = typeof channels === 'string' ? [channels] : channels;
681
- channelArray.forEach(channel => this.realtime.channels.add(channel));
712
+ subscribe<T extends unknown>(channels: string | string[] | Channel<any> | ActionableChannel | ResolvedChannel | (Channel<any> | ActionableChannel | ResolvedChannel)[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
713
+ const channelArray = Array.isArray(channels) ? channels : [channels];
714
+ // Convert Channel instances to strings
715
+ const channelStrings = channelArray.map(ch => {
716
+ if (typeof ch === 'string') {
717
+ return ch;
718
+ }
719
+ // All Channel instances have toString() method
720
+ if (ch && typeof (ch as Channel<any>).toString === 'function') {
721
+ return (ch as Channel<any>).toString();
722
+ }
723
+ // Fallback to generic string conversion
724
+ return String(ch);
725
+ });
726
+ channelStrings.forEach(channel => this.realtime.channels.add(channel));
682
727
 
683
728
  const counter = this.realtime.subscriptionsCounter++;
684
729
  this.realtime.subscriptions.set(counter, {
685
- channels: channelArray,
730
+ channels: channelStrings,
686
731
  callback
687
732
  });
688
733
 
@@ -690,7 +735,7 @@ class Client {
690
735
 
691
736
  return () => {
692
737
  this.realtime.subscriptions.delete(counter);
693
- this.realtime.cleanUp(channelArray);
738
+ this.realtime.cleanUp(channelStrings);
694
739
  this.realtime.connect();
695
740
  }
696
741
  }
@@ -0,0 +1,22 @@
1
+ export enum BrowserPermission {
2
+ Geolocation = 'geolocation',
3
+ Camera = 'camera',
4
+ Microphone = 'microphone',
5
+ Notifications = 'notifications',
6
+ Midi = 'midi',
7
+ Push = 'push',
8
+ Clipboardread = 'clipboard-read',
9
+ Clipboardwrite = 'clipboard-write',
10
+ Paymenthandler = 'payment-handler',
11
+ Usb = 'usb',
12
+ Bluetooth = 'bluetooth',
13
+ Accelerometer = 'accelerometer',
14
+ Gyroscope = 'gyroscope',
15
+ Magnetometer = 'magnetometer',
16
+ Ambientlightsensor = 'ambient-light-sensor',
17
+ Backgroundsync = 'background-sync',
18
+ Persistentstorage = 'persistent-storage',
19
+ Screenwakelock = 'screen-wake-lock',
20
+ Webshare = 'web-share',
21
+ Xrspatialtracking = 'xr-spatial-tracking',
22
+ }
@@ -3,5 +3,6 @@ export enum DeploymentStatus {
3
3
  Processing = 'processing',
4
4
  Building = 'building',
5
5
  Ready = 'ready',
6
+ Canceled = 'canceled',
6
7
  Failed = 'failed',
7
8
  }
@@ -0,0 +1,17 @@
1
+ export enum Frameworks {
2
+ Analog = 'analog',
3
+ Angular = 'angular',
4
+ Nextjs = 'nextjs',
5
+ React = 'react',
6
+ Nuxt = 'nuxt',
7
+ Vue = 'vue',
8
+ Sveltekit = 'sveltekit',
9
+ Astro = 'astro',
10
+ Tanstackstart = 'tanstack-start',
11
+ Remix = 'remix',
12
+ Lynx = 'lynx',
13
+ Flutter = 'flutter',
14
+ Reactnative = 'react-native',
15
+ Vite = 'vite',
16
+ Other = 'other',
17
+ }
@@ -0,0 +1,4 @@
1
+ export enum OrderBy {
2
+ Asc = 'asc',
3
+ Desc = 'desc',
4
+ }
@@ -0,0 +1,13 @@
1
+ export enum Resources {
2
+ User = 'user',
3
+ Database = 'database',
4
+ Table = 'table',
5
+ Column = 'column',
6
+ Index = 'index',
7
+ Row = 'row',
8
+ Document = 'document',
9
+ Attribute = 'attribute',
10
+ Collection = 'collection',
11
+ Bucket = 'bucket',
12
+ File = 'file',
13
+ }