appwrite-cli 13.0.0 → 13.1.0-rc.1

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 (105) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +3 -3
  3. package/cli.ts +2 -0
  4. package/dist/bundle.cjs +52800 -50718
  5. package/dist/cli.js +2 -0
  6. package/dist/cli.js.map +1 -1
  7. package/dist/lib/client.d.ts.map +1 -1
  8. package/dist/lib/client.js +3 -4
  9. package/dist/lib/client.js.map +1 -1
  10. package/dist/lib/commands/config-validations.d.ts +53 -0
  11. package/dist/lib/commands/config-validations.d.ts.map +1 -0
  12. package/dist/lib/commands/config-validations.js +130 -0
  13. package/dist/lib/commands/config-validations.js.map +1 -0
  14. package/dist/lib/commands/config.d.ts +241 -236
  15. package/dist/lib/commands/config.d.ts.map +1 -1
  16. package/dist/lib/commands/config.js +85 -105
  17. package/dist/lib/commands/config.js.map +1 -1
  18. package/dist/lib/commands/generate.d.ts +7 -0
  19. package/dist/lib/commands/generate.d.ts.map +1 -0
  20. package/dist/lib/commands/generate.js +92 -0
  21. package/dist/lib/commands/generate.js.map +1 -0
  22. package/dist/lib/commands/generators/base.d.ts +58 -0
  23. package/dist/lib/commands/generators/base.d.ts.map +1 -0
  24. package/dist/lib/commands/generators/base.js +27 -0
  25. package/dist/lib/commands/generators/base.js.map +1 -0
  26. package/dist/lib/commands/generators/index.d.ts +26 -0
  27. package/dist/lib/commands/generators/index.d.ts.map +1 -0
  28. package/dist/lib/commands/generators/index.js +55 -0
  29. package/dist/lib/commands/generators/index.js.map +1 -0
  30. package/dist/lib/commands/generators/language-detector.d.ts +42 -0
  31. package/dist/lib/commands/generators/language-detector.d.ts.map +1 -0
  32. package/dist/lib/commands/generators/language-detector.js +127 -0
  33. package/dist/lib/commands/generators/language-detector.js.map +1 -0
  34. package/dist/lib/commands/generators/typescript/databases.d.ts +36 -0
  35. package/dist/lib/commands/generators/typescript/databases.d.ts.map +1 -0
  36. package/dist/lib/commands/generators/typescript/databases.js +489 -0
  37. package/dist/lib/commands/generators/typescript/databases.js.map +1 -0
  38. package/dist/lib/commands/pull.d.ts.map +1 -1
  39. package/dist/lib/commands/pull.js +15 -9
  40. package/dist/lib/commands/pull.js.map +1 -1
  41. package/dist/lib/commands/push.d.ts +6 -3
  42. package/dist/lib/commands/push.d.ts.map +1 -1
  43. package/dist/lib/commands/push.js +64 -41
  44. package/dist/lib/commands/push.js.map +1 -1
  45. package/dist/lib/commands/schema.d.ts +2 -2
  46. package/dist/lib/commands/schema.d.ts.map +1 -1
  47. package/dist/lib/commands/schema.js +2 -2
  48. package/dist/lib/commands/schema.js.map +1 -1
  49. package/dist/lib/commands/services/projects.js +7 -1
  50. package/dist/lib/commands/services/projects.js.map +1 -1
  51. package/dist/lib/commands/services/storage.js +2 -2
  52. package/dist/lib/commands/services/storage.js.map +1 -1
  53. package/dist/lib/commands/utils/attributes.d.ts +10 -2
  54. package/dist/lib/commands/utils/attributes.d.ts.map +1 -1
  55. package/dist/lib/commands/utils/attributes.js +35 -16
  56. package/dist/lib/commands/utils/attributes.js.map +1 -1
  57. package/dist/lib/commands/utils/pools.d.ts +0 -3
  58. package/dist/lib/commands/utils/pools.d.ts.map +1 -1
  59. package/dist/lib/commands/utils/pools.js +0 -34
  60. package/dist/lib/commands/utils/pools.js.map +1 -1
  61. package/dist/lib/config.d.ts.map +1 -1
  62. package/dist/lib/config.js +37 -141
  63. package/dist/lib/config.js.map +1 -1
  64. package/dist/lib/constants.d.ts +1 -1
  65. package/dist/lib/constants.d.ts.map +1 -1
  66. package/dist/lib/constants.js +1 -1
  67. package/dist/lib/constants.js.map +1 -1
  68. package/dist/lib/json.d.ts +8 -0
  69. package/dist/lib/json.d.ts.map +1 -0
  70. package/dist/lib/json.js +25 -0
  71. package/dist/lib/json.js.map +1 -0
  72. package/dist/lib/utils.d.ts +13 -1
  73. package/dist/lib/utils.d.ts.map +1 -1
  74. package/dist/lib/utils.js +45 -177
  75. package/dist/lib/utils.js.map +1 -1
  76. package/dist/package.json +3 -2
  77. package/docs/examples/projects/update-labels.md +3 -0
  78. package/install.ps1 +2 -2
  79. package/install.sh +1 -1
  80. package/lib/client.ts +3 -5
  81. package/lib/commands/config-validations.ts +199 -0
  82. package/lib/commands/config.ts +93 -120
  83. package/lib/commands/generate.ts +142 -0
  84. package/lib/commands/generators/base.ts +91 -0
  85. package/lib/commands/generators/index.ts +87 -0
  86. package/lib/commands/generators/language-detector.ts +163 -0
  87. package/lib/commands/generators/typescript/databases.ts +590 -0
  88. package/lib/commands/pull.ts +30 -9
  89. package/lib/commands/push.ts +105 -62
  90. package/lib/commands/schema.ts +3 -3
  91. package/lib/commands/services/projects.ts +13 -1
  92. package/lib/commands/services/storage.ts +2 -2
  93. package/lib/commands/utils/attributes.ts +49 -18
  94. package/lib/commands/utils/pools.ts +0 -67
  95. package/lib/config.ts +52 -142
  96. package/lib/constants.ts +1 -1
  97. package/lib/json.ts +28 -0
  98. package/lib/utils.ts +46 -221
  99. package/package.json +3 -2
  100. package/scoop/appwrite.config.json +3 -3
  101. package/dist/lib/commands/db.d.ts +0 -34
  102. package/dist/lib/commands/db.d.ts.map +0 -1
  103. package/dist/lib/commands/db.js +0 -247
  104. package/dist/lib/commands/db.js.map +0 -1
  105. package/lib/commands/db.ts +0 -324
package/lib/config.ts CHANGED
@@ -2,8 +2,8 @@ import os from "os";
2
2
  import fs from "fs";
3
3
  import _path from "path";
4
4
  import process from "process";
5
- import JSONbig from "json-bigint";
6
5
  import type { Models } from "@appwrite.io/console";
6
+ import type { z } from "zod";
7
7
  import type {
8
8
  BucketType,
9
9
  CollectionType,
@@ -15,6 +15,20 @@ import type {
15
15
  TeamType,
16
16
  TopicType,
17
17
  } from "./commands/config.js";
18
+ import {
19
+ SiteSchema,
20
+ FunctionSchema,
21
+ DatabaseSchema,
22
+ CollectionSchema,
23
+ AttributeSchema,
24
+ IndexSchema,
25
+ TableSchema,
26
+ ColumnSchema,
27
+ IndexTableSchema,
28
+ TopicSchema,
29
+ TeamSchema,
30
+ BucketSchema,
31
+ } from "./commands/config.js";
18
32
  import type {
19
33
  SessionData,
20
34
  ConfigData,
@@ -22,142 +36,38 @@ import type {
22
36
  GlobalConfigData,
23
37
  } from "./types.js";
24
38
  import { createSettingsObject } from "./utils.js";
25
- import { SDK_TITLE_LOWER } from "./constants.js";
26
-
27
- const JSONBigInt = JSONbig({ useNativeBigInt: true });
39
+ import { EXECUTABLE_NAME } from "./constants.js";
40
+ import { JSONBig } from "./json.js";
41
+
42
+ /**
43
+ * Extract keys from a Zod object schema.
44
+ * Handles both plain ZodObject and ZodEffects (schemas with refinements).
45
+ */
46
+ function getSchemaKeys(schema: z.ZodTypeAny): Set<string> {
47
+ // For ZodEffects (created by .refine(), .superRefine(), .transform())
48
+ if ("def" in schema && "schema" in (schema.def as any)) {
49
+ return getSchemaKeys((schema.def as any).schema);
50
+ }
51
+ // For ZodObject
52
+ if ("shape" in schema) {
53
+ return new Set(Object.keys((schema as any).shape));
54
+ }
55
+ return new Set();
56
+ }
28
57
 
29
58
  const KeysVars = new Set(["key", "value"]);
30
- const KeysSite = new Set([
31
- "path",
32
- "$id",
33
- "name",
34
- "enabled",
35
- "logging",
36
- "timeout",
37
- "framework",
38
- "buildRuntime",
39
- "adapter",
40
- "installCommand",
41
- "buildCommand",
42
- "outputDirectory",
43
- "fallbackFile",
44
- "specification",
45
- "vars",
46
- ]);
47
- const KeysFunction = new Set([
48
- "path",
49
- "$id",
50
- "execute",
51
- "name",
52
- "enabled",
53
- "logging",
54
- "runtime",
55
- "specification",
56
- "scopes",
57
- "events",
58
- "schedule",
59
- "timeout",
60
- "entrypoint",
61
- "commands",
62
- "vars",
63
- ]);
64
- const KeysDatabase = new Set(["$id", "name", "enabled"]);
65
- const KeysCollection = new Set([
66
- "$id",
67
- "$permissions",
68
- "databaseId",
69
- "name",
70
- "enabled",
71
- "documentSecurity",
72
- "attributes",
73
- "indexes",
74
- ]);
75
- const KeysTable = new Set([
76
- "$id",
77
- "$permissions",
78
- "databaseId",
79
- "name",
80
- "enabled",
81
- "rowSecurity",
82
- "columns",
83
- "indexes",
84
- ]);
85
- const KeysStorage = new Set([
86
- "$id",
87
- "$permissions",
88
- "fileSecurity",
89
- "name",
90
- "enabled",
91
- "maximumFileSize",
92
- "allowedFileExtensions",
93
- "compression",
94
- "encryption",
95
- "antivirus",
96
- ]);
97
- const KeysTopics = new Set(["$id", "name", "subscribe"]);
98
- const KeysTeams = new Set(["$id", "name"]);
99
- const KeysAttributes = new Set([
100
- "key",
101
- "type",
102
- "required",
103
- "array",
104
- "size",
105
- "default",
106
- // integer and float
107
- "min",
108
- "max",
109
- // email, enum, URL, IP, and datetime
110
- "format",
111
- // enum
112
- "elements",
113
- // relationship
114
- "relatedCollection",
115
- "relationType",
116
- "twoWay",
117
- "twoWayKey",
118
- "onDelete",
119
- "side",
120
- // Indexes
121
- "attributes",
122
- "orders",
123
- // Strings
124
- "encrypt",
125
- ]);
126
- const KeysColumns = new Set([
127
- "key",
128
- "type",
129
- "required",
130
- "array",
131
- "size",
132
- "default",
133
- // integer and float
134
- "min",
135
- "max",
136
- // email, enum, URL, IP, and datetime
137
- "format",
138
- // enum
139
- "elements",
140
- // relationship
141
- "relatedTable",
142
- "relationType",
143
- "twoWay",
144
- "twoWayKey",
145
- "onDelete",
146
- "side",
147
- // Indexes
148
- "columns",
149
- "orders",
150
- // Strings
151
- "encrypt",
152
- ]);
153
- const KeyIndexes = new Set(["key", "type", "status", "attributes", "orders"]);
154
- const KeyIndexesColumns = new Set([
155
- "key",
156
- "type",
157
- "status",
158
- "columns",
159
- "orders",
160
- ]);
59
+ const KeysSite = getSchemaKeys(SiteSchema);
60
+ const KeysFunction = getSchemaKeys(FunctionSchema);
61
+ const KeysDatabase = getSchemaKeys(DatabaseSchema);
62
+ const KeysCollection = getSchemaKeys(CollectionSchema);
63
+ const KeysTable = getSchemaKeys(TableSchema);
64
+ const KeysStorage = getSchemaKeys(BucketSchema);
65
+ const KeysTopics = getSchemaKeys(TopicSchema);
66
+ const KeysTeams = getSchemaKeys(TeamSchema);
67
+ const KeysAttributes = getSchemaKeys(AttributeSchema);
68
+ const KeysColumns = getSchemaKeys(ColumnSchema);
69
+ const KeyIndexes = getSchemaKeys(IndexSchema);
70
+ const KeyIndexesColumns = getSchemaKeys(IndexTableSchema);
161
71
 
162
72
  const CONFIG_KEY_ORDER = [
163
73
  "projectId",
@@ -235,7 +145,7 @@ class Config<T extends ConfigData = ConfigData> {
235
145
  read(): void {
236
146
  try {
237
147
  const file = fs.readFileSync(this.path).toString();
238
- this.data = JSONBigInt.parse(file);
148
+ this.data = JSONBig.parse(file);
239
149
  } catch (e) {
240
150
  this.data = {} as T;
241
151
  }
@@ -246,7 +156,7 @@ class Config<T extends ConfigData = ConfigData> {
246
156
  if (!fs.existsSync(dir)) {
247
157
  fs.mkdirSync(dir, { recursive: true });
248
158
  }
249
- fs.writeFileSync(this.path, JSONBigInt.stringify(this.data, null, 4), {
159
+ fs.writeFileSync(this.path, JSONBig.stringify(this.data, null, 4), {
250
160
  mode: 0o600,
251
161
  });
252
162
  }
@@ -285,7 +195,7 @@ class Config<T extends ConfigData = ConfigData> {
285
195
  }
286
196
 
287
197
  toString(): string {
288
- return JSONBigInt.stringify(this.data, null, 4);
198
+ return JSONBig.stringify(this.data, null, 4);
289
199
  }
290
200
 
291
201
  protected _getDBEntities(entityType: string): Entity[] {
@@ -342,8 +252,8 @@ class Config<T extends ConfigData = ConfigData> {
342
252
  }
343
253
 
344
254
  class Local extends Config<ConfigType> {
345
- static CONFIG_FILE_PATH = `${SDK_TITLE_LOWER}.config.json`;
346
- static CONFIG_FILE_PATH_LEGACY = `${SDK_TITLE_LOWER}.json`;
255
+ static CONFIG_FILE_PATH = `${EXECUTABLE_NAME}.config.json`;
256
+ static CONFIG_FILE_PATH_LEGACY = `${EXECUTABLE_NAME}.json`;
347
257
  configDirectoryPath = "";
348
258
 
349
259
  constructor(
@@ -367,7 +277,7 @@ class Local extends Config<ConfigType> {
367
277
  fs.mkdirSync(dir, { recursive: true });
368
278
  }
369
279
  const orderedData = orderConfigKeys(this.data);
370
- fs.writeFileSync(this.path, JSONBigInt.stringify(orderedData, null, 4), {
280
+ fs.writeFileSync(this.path, JSONBig.stringify(orderedData, null, 4), {
371
281
  mode: 0o600,
372
282
  });
373
283
  }
@@ -774,7 +684,7 @@ class Local extends Config<ConfigType> {
774
684
  }
775
685
 
776
686
  class Global extends Config<GlobalConfigData> {
777
- static CONFIG_FILE_PATH = `.${SDK_TITLE_LOWER}/prefs.json`;
687
+ static CONFIG_FILE_PATH = `.${EXECUTABLE_NAME}/prefs.json`;
778
688
 
779
689
  static PREFERENCE_CURRENT = "current" as const;
780
690
  static PREFERENCE_ENDPOINT = "endpoint" as const;
package/lib/constants.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // SDK
2
2
  export const SDK_TITLE = 'Appwrite';
3
3
  export const SDK_TITLE_LOWER = 'appwrite';
4
- export const SDK_VERSION = '13.0.0';
4
+ export const SDK_VERSION = '13.1.0-rc.1';
5
5
  export const SDK_NAME = 'Command Line';
6
6
  export const SDK_PLATFORM = 'console';
7
7
  export const SDK_LANGUAGE = 'cli';
package/lib/json.ts ADDED
@@ -0,0 +1,28 @@
1
+ import JSONbigModule from "json-bigint";
2
+ import { BigNumber } from "bignumber.js";
3
+
4
+ const JSONbigParser = JSONbigModule({ storeAsString: false });
5
+ const JSONbigSerializer = JSONbigModule({ useNativeBigInt: true });
6
+
7
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
8
+ const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
9
+
10
+ function reviver(_key: string, value: any): any {
11
+ if (BigNumber.isBigNumber(value)) {
12
+ if (value.isInteger()) {
13
+ const str = value.toFixed();
14
+ const bi = BigInt(str);
15
+ if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
16
+ return Number(str);
17
+ }
18
+ return bi;
19
+ }
20
+ return value.toNumber();
21
+ }
22
+ return value;
23
+ }
24
+
25
+ export const JSONBig = {
26
+ parse: (text: string) => JSONbigParser.parse(text, reviver),
27
+ stringify: JSONbigSerializer.stringify,
28
+ };
package/lib/utils.ts CHANGED
@@ -5,6 +5,7 @@ import childProcess from "child_process";
5
5
  import chalk from "chalk";
6
6
  import { fetch } from "undici";
7
7
  import type { Models } from "@appwrite.io/console";
8
+ import { z } from "zod";
8
9
  import { localConfig, globalConfig } from "./config.js";
9
10
  import type { SettingsType } from "./commands/config.js";
10
11
  import { NPM_REGISTRY_URL, DEFAULT_ENDPOINT } from "./constants.js";
@@ -154,240 +155,64 @@ export const checkDeployConditions = (localConfig: any): void => {
154
155
  }
155
156
  };
156
157
 
157
- export function showConsoleLink(
158
- serviceName: string,
159
- action: string,
160
- ...ids: string[]
161
- ): void {
162
- const projectId = localConfig.getProject().projectId;
163
-
164
- const url = new URL(globalConfig.getEndpoint().replace("/v1", "/console"));
165
- url.pathname += `/project-${projectId}`;
166
- action = action.toLowerCase();
167
-
168
- switch (serviceName) {
169
- case "account":
170
- url.pathname = url.pathname.replace(`/project-${projectId}`, "");
171
- url.pathname += getAccountPath(action);
172
- break;
173
- case "databases":
174
- url.pathname += getDatabasePath(action, ids);
175
- break;
176
- case "functions":
177
- url.pathname += getFunctionsPath(action, ids);
178
- break;
179
- case "messaging":
180
- url.pathname += getMessagingPath(action, ids);
181
- break;
182
- case "projects":
183
- url.pathname = url.pathname.replace(`/project-${projectId}`, "");
184
- url.pathname += getProjectsPath(action, ids);
185
- break;
186
- case "storage":
187
- url.pathname += getBucketsPath(action, ids);
188
- break;
189
- case "teams":
190
- url.pathname += getTeamsPath(action, ids);
191
- break;
192
- case "organizations":
193
- url.pathname += getOrganizationsPath(action, ids);
194
- break;
195
- case "users":
196
- url.pathname += getUsersPath(action, ids);
197
- break;
198
- default:
199
- return;
200
- }
201
-
202
- console.log(
203
- `${chalk.green.bold("✓ Success:")} ${chalk.green(url.toString())}`,
204
- );
205
- }
206
-
207
- function getAccountPath(action: string): string {
208
- let path = "/account";
209
-
210
- if (action === "listsessions") {
211
- path += "/sessions";
212
- }
213
-
214
- return path;
215
- }
216
-
217
- function getDatabasePath(action: string, ids: string[]): string {
218
- let path = "/databases";
219
-
220
- if (
221
- [
222
- "get",
223
- "listcollections",
224
- "getcollection",
225
- "listattributes",
226
- "listdocuments",
227
- "getdocument",
228
- "listindexes",
229
- "getdatabaseusage",
230
- ].includes(action)
231
- ) {
232
- path += `/database-${ids[0]}`;
233
- }
234
-
235
- if (action === "getdatabaseusage") {
236
- path += `/usage`;
237
- }
238
-
239
- if (
240
- [
241
- "getcollection",
242
- "listattributes",
243
- "listdocuments",
244
- "getdocument",
245
- "listindexes",
246
- ].includes(action)
247
- ) {
248
- path += `/collection-${ids[1]}`;
249
- }
250
-
251
- if (action === "listattributes") {
252
- path += "/attributes";
253
- }
254
- if (action === "listindexes") {
255
- path += "/indexes";
256
- }
257
- if (action === "getdocument") {
258
- path += `/document-${ids[2]}`;
259
- }
260
-
261
- return path;
262
- }
263
-
264
- function getFunctionsPath(action: string, ids: string[]): string {
265
- let path = "/functions";
266
-
267
- if (action !== "list") {
268
- path += `/function-${ids[0]}`;
269
- }
270
-
271
- if (action === "getdeployment") {
272
- path += `/deployment-${ids[1]}`;
273
- }
274
-
275
- if (action === "getexecution" || action === "listexecution") {
276
- path += `/executions`;
277
- }
278
- if (action === "getfunctionusage") {
279
- path += `/usage`;
280
- }
281
-
282
- return path;
283
- }
284
-
285
- function getMessagingPath(action: string, ids: string[]): string {
286
- let path = "/messaging";
287
-
288
- if (["getmessage", "listmessagelogs"].includes(action)) {
289
- path += `/message-${ids[0]}`;
290
- }
291
-
292
- if (["listproviders", "getprovider"].includes(action)) {
293
- path += `/providers`;
294
- }
295
-
296
- if (action === "getprovider") {
297
- path += `/provider-${ids[0]}`;
298
- }
299
-
300
- if (["listtopics", "gettopic"].includes(action)) {
301
- path += `/topics`;
302
- }
303
-
304
- if (action === "gettopic") {
305
- path += `/topic-${ids[0]}`;
306
- }
307
-
308
- return path;
309
- }
310
-
311
- function getProjectsPath(action: string, ids: string[]): string {
312
- let path = "";
313
-
314
- if (action !== "list") {
315
- path += `/project-${ids[0]}`;
316
- }
317
-
318
- if (["listkeys", "getkey"].includes(action)) {
319
- path += "/overview/keys";
320
- }
321
-
322
- if (["listplatforms", "getplatform"].includes(action)) {
323
- path += "/overview/platforms";
324
- }
325
-
326
- if (["listwebhooks", "getwebhook"].includes(action)) {
327
- path += "/settings/webhooks";
328
- }
329
-
330
- if (["getplatform", "getkey", "getwebhook"].includes(action)) {
331
- path += `/${ids[1]}`;
332
- }
333
-
334
- return path;
158
+ export function isCloud(): boolean {
159
+ const endpoint = globalConfig.getEndpoint() || DEFAULT_ENDPOINT;
160
+ const hostname = new URL(endpoint).hostname;
161
+ return hostname.endsWith("appwrite.io");
335
162
  }
336
163
 
337
- function getBucketsPath(action: string, ids: string[]): string {
338
- let path = "/storage";
339
-
340
- if (action !== "listbuckets") {
341
- path += `/bucket-${ids[0]}`;
342
- }
343
-
344
- if (action === "getbucketusage") {
345
- path += `/usage`;
346
- }
347
-
348
- if (action === "getfile") {
349
- path += `/file-${ids[1]}`;
164
+ /**
165
+ * Filters an object to only include fields defined in a Zod object schema.
166
+ * Uses the schema's shape to determine allowed keys.
167
+ *
168
+ * @param data - The data to filter
169
+ * @param schema - A Zod object schema with a shape property
170
+ * @returns The filtered data with only schema-defined fields
171
+ */
172
+ export function filterBySchema<T extends z.ZodObject<z.ZodRawShape>>(
173
+ data: Record<string, unknown>,
174
+ schema: T,
175
+ ): z.infer<T> {
176
+ const allowedKeys = Object.keys(schema.shape);
177
+ const result: Record<string, unknown> = {};
178
+
179
+ for (const key of allowedKeys) {
180
+ if (key in data) {
181
+ result[key] = data[key];
182
+ }
350
183
  }
351
184
 
352
- return path;
185
+ return result as z.infer<T>;
353
186
  }
354
187
 
355
- function getTeamsPath(action: string, ids: string[]): string {
356
- let path = "/auth/teams";
357
-
358
- if (action !== "list") {
359
- path += `/team-${ids[0]}`;
360
- }
361
-
362
- return path;
188
+ export function toPascalCase(str: string): string {
189
+ return str
190
+ .replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
191
+ .replace(/^(.)/, (char) => char.toUpperCase());
363
192
  }
364
193
 
365
- function getOrganizationsPath(action: string, ids: string[]): string {
366
- let path = `/organization-${ids[0]}`;
367
-
368
- if (action === "list") {
369
- path = "/account/organizations";
370
- }
371
-
372
- return path;
194
+ export function toUpperSnakeCase(str: string): string {
195
+ return str
196
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
197
+ .replace(/[-\s]+/g, "_")
198
+ .toUpperCase();
373
199
  }
374
200
 
375
- function getUsersPath(action: string, ids: string[]): string {
376
- let path = "/auth";
201
+ export function sanitizeEnumKey(key: string): string {
202
+ let sanitized = toUpperSnakeCase(key)
203
+ .replace(/[^A-Z0-9_]/gi, "_") // Replace non-alphanumeric with underscores
204
+ .replace(/_+/g, "_") // Collapse consecutive underscores
205
+ .replace(/^_+|_+$/g, ""); // Trim leading/trailing underscores
377
206
 
378
- if (action !== "list") {
379
- path += `/user-${ids[0]}`;
207
+ // Prefix with underscore if starts with a digit
208
+ if (/^[0-9]/.test(sanitized)) {
209
+ sanitized = "_" + sanitized;
380
210
  }
381
211
 
382
- if (action === "listsessions") {
383
- path += "sessions";
212
+ // Fallback if empty after sanitization
213
+ if (!sanitized) {
214
+ sanitized = "_VALUE";
384
215
  }
385
216
 
386
- return path;
387
- }
388
-
389
- export function isCloud(): boolean {
390
- const endpoint = globalConfig.getEndpoint() || DEFAULT_ENDPOINT;
391
- const hostname = new URL(endpoint).hostname;
392
- return hostname.endsWith("appwrite.io");
217
+ return sanitized;
393
218
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "homepage": "https://appwrite.io/support",
5
5
  "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",
6
- "version": "13.0.0",
6
+ "version": "13.1.0-rc.1",
7
7
  "license": "BSD-3-Clause",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
@@ -28,7 +28,8 @@
28
28
  "windows-arm64": "bun run build && esbuild dist/cli.js --bundle --platform=node --format=cjs --outfile=dist/bundle.cjs --external:@appwrite.io/console --external:fsevents && pkg dist/bundle.cjs -t node18-win-arm64 -o build/appwrite-cli-win-arm64.exe"
29
29
  },
30
30
  "dependencies": {
31
- "@appwrite.io/console": "^2.1.0",
31
+ "@appwrite.io/console": "^2.1.3",
32
+ "bignumber.js": "^9.0.0",
32
33
  "chalk": "4.1.2",
33
34
  "chokidar": "^3.6.0",
34
35
  "cli-progress": "^3.12.0",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
3
- "version": "13.0.0",
3
+ "version": "13.1.0-rc.1",
4
4
  "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.",
5
5
  "homepage": "https://github.com/appwrite/sdk-for-cli",
6
6
  "license": "BSD-3-Clause",
7
7
  "architecture": {
8
8
  "64bit": {
9
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.0.0/appwrite-cli-win-x64.exe",
9
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.1.0-rc.1/appwrite-cli-win-x64.exe",
10
10
  "bin": [
11
11
  [
12
12
  "appwrite-cli-win-x64.exe",
@@ -15,7 +15,7 @@
15
15
  ]
16
16
  },
17
17
  "arm64": {
18
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.0.0/appwrite-cli-win-arm64.exe",
18
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.1.0-rc.1/appwrite-cli-win-arm64.exe",
19
19
  "bin": [
20
20
  [
21
21
  "appwrite-cli-win-arm64.exe",
@@ -1,34 +0,0 @@
1
- import { ConfigType } from "./config.js";
2
- export interface GenerateOptions {
3
- strict?: boolean;
4
- }
5
- export interface GenerateResult {
6
- dbContent: string;
7
- typesContent: string;
8
- }
9
- export declare class Db {
10
- private getType;
11
- private toPascalCase;
12
- private toCamelCase;
13
- private toUpperSnakeCase;
14
- private generateCollectionType;
15
- private generateEnums;
16
- private generateTypesFile;
17
- private getAppwriteDependency;
18
- private generateDbFile;
19
- /**
20
- * Generates TypeScript code for Appwrite database collections and types based on the provided configuration.
21
- *
22
- * This method returns generated content as strings:
23
- * 1. A types string containing TypeScript interfaces for each collection.
24
- * 2. A database client string with helper methods for CRUD operations on each collection.
25
- *
26
- * @param config - The Appwrite project configuration, including collections and project details.
27
- * @param options - Optional settings for code generation:
28
- * - strict: Whether to use strict naming conventions for collections (default: false).
29
- * @returns A Promise that resolves with an object containing dbContent and typesContent strings.
30
- * @throws If the configuration is missing a projectId or contains no collections.
31
- */
32
- generate(config: ConfigType, options?: GenerateOptions): Promise<GenerateResult>;
33
- }
34
- //# sourceMappingURL=db.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../../lib/commands/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAK1D,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,EAAE;IACb,OAAO,CAAC,OAAO;IA0Df,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,iBAAiB;IA6BzB,OAAO,CAAC,qBAAqB;IAyB7B,OAAO,CAAC,cAAc;IAqFtB;;;;;;;;;;;;OAYG;IACU,QAAQ,CACnB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC;CA4B3B"}