appwrite-cli 12.0.1 → 13.0.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 (283) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +2 -2
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +145 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/client.d.ts +89 -0
  8. package/dist/lib/client.d.ts.map +1 -0
  9. package/dist/lib/client.js +227 -0
  10. package/dist/lib/client.js.map +1 -0
  11. package/dist/lib/commands/account.d.ts +379 -0
  12. package/dist/lib/commands/account.d.ts.map +1 -0
  13. package/dist/lib/commands/account.js +1228 -0
  14. package/dist/lib/commands/account.js.map +1 -0
  15. package/dist/lib/commands/console.d.ts +20 -0
  16. package/dist/lib/commands/console.d.ts.map +1 -0
  17. package/dist/lib/commands/console.js +78 -0
  18. package/dist/lib/commands/console.js.map +1 -0
  19. package/dist/lib/commands/databases.d.ts +732 -0
  20. package/dist/lib/commands/databases.d.ts.map +1 -0
  21. package/dist/lib/commands/databases.js +2196 -0
  22. package/dist/lib/commands/databases.js.map +1 -0
  23. package/dist/lib/commands/functions.d.ts +310 -0
  24. package/dist/lib/commands/functions.d.ts.map +1 -0
  25. package/dist/lib/commands/functions.js +1100 -0
  26. package/dist/lib/commands/functions.js.map +1 -0
  27. package/dist/lib/commands/generic.d.ts +17 -0
  28. package/dist/lib/commands/generic.d.ts.map +1 -0
  29. package/dist/lib/commands/generic.js +279 -0
  30. package/dist/lib/commands/generic.js.map +1 -0
  31. package/dist/lib/commands/graphql.d.ts +19 -0
  32. package/dist/lib/commands/graphql.d.ts.map +1 -0
  33. package/dist/lib/commands/graphql.js +77 -0
  34. package/dist/lib/commands/graphql.js.map +1 -0
  35. package/dist/lib/commands/health.d.ts +153 -0
  36. package/dist/lib/commands/health.d.ts.map +1 -0
  37. package/dist/lib/commands/health.js +464 -0
  38. package/dist/lib/commands/health.js.map +1 -0
  39. package/dist/lib/commands/init.d.ts +3 -0
  40. package/dist/lib/commands/init.d.ts.map +1 -0
  41. package/dist/lib/commands/init.js +518 -0
  42. package/dist/lib/commands/init.js.map +1 -0
  43. package/dist/lib/commands/locale.d.ts +53 -0
  44. package/dist/lib/commands/locale.d.ts.map +1 -0
  45. package/dist/lib/commands/locale.js +165 -0
  46. package/dist/lib/commands/locale.js.map +1 -0
  47. package/dist/lib/commands/messaging.d.ts +588 -0
  48. package/dist/lib/commands/messaging.d.ts.map +1 -0
  49. package/dist/lib/commands/messaging.js +2042 -0
  50. package/dist/lib/commands/messaging.js.map +1 -0
  51. package/dist/lib/commands/migrations.d.ts +150 -0
  52. package/dist/lib/commands/migrations.d.ts.map +1 -0
  53. package/dist/lib/commands/migrations.js +524 -0
  54. package/dist/lib/commands/migrations.js.map +1 -0
  55. package/dist/lib/commands/organizations.d.ts +11 -0
  56. package/dist/lib/commands/organizations.d.ts.map +1 -0
  57. package/dist/lib/commands/organizations.js +31 -0
  58. package/dist/lib/commands/organizations.js.map +1 -0
  59. package/dist/lib/commands/project.d.ts +53 -0
  60. package/dist/lib/commands/project.d.ts.map +1 -0
  61. package/dist/lib/commands/project.js +176 -0
  62. package/dist/lib/commands/project.js.map +1 -0
  63. package/dist/lib/commands/projects.d.ts +516 -0
  64. package/dist/lib/commands/projects.d.ts.map +1 -0
  65. package/dist/lib/commands/projects.js +1590 -0
  66. package/dist/lib/commands/projects.js.map +1 -0
  67. package/dist/lib/commands/proxy.d.ts +71 -0
  68. package/dist/lib/commands/proxy.d.ts.map +1 -0
  69. package/dist/lib/commands/proxy.js +240 -0
  70. package/dist/lib/commands/proxy.js.map +1 -0
  71. package/dist/lib/commands/pull.d.ts +8 -0
  72. package/dist/lib/commands/pull.d.ts.map +1 -0
  73. package/dist/lib/commands/pull.js +455 -0
  74. package/dist/lib/commands/pull.js.map +1 -0
  75. package/dist/lib/commands/push.d.ts +4 -0
  76. package/dist/lib/commands/push.d.ts.map +1 -0
  77. package/dist/lib/commands/push.js +2154 -0
  78. package/dist/lib/commands/push.js.map +1 -0
  79. package/dist/lib/commands/run.d.ts +3 -0
  80. package/dist/lib/commands/run.d.ts.map +1 -0
  81. package/dist/lib/commands/run.js +287 -0
  82. package/dist/lib/commands/run.js.map +1 -0
  83. package/dist/lib/commands/sites.d.ts +296 -0
  84. package/dist/lib/commands/sites.d.ts.map +1 -0
  85. package/dist/lib/commands/sites.js +1046 -0
  86. package/dist/lib/commands/sites.js.map +1 -0
  87. package/dist/lib/commands/storage.d.ts +170 -0
  88. package/dist/lib/commands/storage.d.ts.map +1 -0
  89. package/dist/lib/commands/storage.js +651 -0
  90. package/dist/lib/commands/storage.js.map +1 -0
  91. package/dist/lib/commands/tables-db.d.ts +728 -0
  92. package/dist/lib/commands/tables-db.d.ts.map +1 -0
  93. package/dist/lib/commands/tables-db.js +2198 -0
  94. package/dist/lib/commands/tables-db.js.map +1 -0
  95. package/dist/lib/commands/teams.d.ts +129 -0
  96. package/dist/lib/commands/teams.d.ts.map +1 -0
  97. package/dist/lib/commands/teams.js +403 -0
  98. package/dist/lib/commands/teams.js.map +1 -0
  99. package/dist/lib/commands/tokens.d.ts +48 -0
  100. package/dist/lib/commands/tokens.d.ts.map +1 -0
  101. package/dist/lib/commands/tokens.js +156 -0
  102. package/dist/lib/commands/tokens.js.map +1 -0
  103. package/dist/lib/commands/types.d.ts +3 -0
  104. package/dist/lib/commands/types.d.ts.map +1 -0
  105. package/dist/lib/commands/types.js +155 -0
  106. package/dist/lib/commands/types.js.map +1 -0
  107. package/dist/lib/commands/update.d.ts +3 -0
  108. package/dist/lib/commands/update.d.ts.map +1 -0
  109. package/dist/lib/commands/update.js +202 -0
  110. package/dist/lib/commands/update.js.map +1 -0
  111. package/dist/lib/commands/users.d.ts +382 -0
  112. package/dist/lib/commands/users.d.ts.map +1 -0
  113. package/dist/lib/commands/users.js +1195 -0
  114. package/dist/lib/commands/users.js.map +1 -0
  115. package/dist/lib/commands/vcs.d.ts +92 -0
  116. package/dist/lib/commands/vcs.d.ts.map +1 -0
  117. package/dist/lib/commands/vcs.js +276 -0
  118. package/dist/lib/commands/vcs.js.map +1 -0
  119. package/dist/lib/config.d.ts +118 -0
  120. package/dist/lib/config.d.ts.map +1 -0
  121. package/{lib → dist/lib}/config.js +204 -325
  122. package/dist/lib/config.js.map +1 -0
  123. package/dist/lib/emulation/docker.d.ts +15 -0
  124. package/dist/lib/emulation/docker.d.ts.map +1 -0
  125. package/dist/lib/emulation/docker.js +220 -0
  126. package/dist/lib/emulation/docker.js.map +1 -0
  127. package/dist/lib/emulation/utils.d.ts +29 -0
  128. package/dist/lib/emulation/utils.d.ts.map +1 -0
  129. package/dist/lib/emulation/utils.js +168 -0
  130. package/dist/lib/emulation/utils.js.map +1 -0
  131. package/dist/lib/exception.d.ts +8 -0
  132. package/dist/lib/exception.d.ts.map +1 -0
  133. package/dist/lib/exception.js +16 -0
  134. package/dist/lib/exception.js.map +1 -0
  135. package/dist/lib/id.d.ts +7 -0
  136. package/dist/lib/id.d.ts.map +1 -0
  137. package/dist/lib/id.js +32 -0
  138. package/dist/lib/id.js.map +1 -0
  139. package/dist/lib/paginate.d.ts +10 -0
  140. package/dist/lib/paginate.d.ts.map +1 -0
  141. package/{lib → dist/lib}/paginate.js +9 -15
  142. package/dist/lib/paginate.js.map +1 -0
  143. package/dist/lib/parser.d.ts +18 -0
  144. package/dist/lib/parser.d.ts.map +1 -0
  145. package/dist/lib/parser.js +237 -0
  146. package/dist/lib/parser.js.map +1 -0
  147. package/dist/lib/questions.d.ts +59 -0
  148. package/dist/lib/questions.d.ts.map +1 -0
  149. package/dist/lib/questions.js +995 -0
  150. package/dist/lib/questions.js.map +1 -0
  151. package/dist/lib/sdks.d.ts +4 -0
  152. package/dist/lib/sdks.d.ts.map +1 -0
  153. package/dist/lib/sdks.js +51 -0
  154. package/dist/lib/sdks.js.map +1 -0
  155. package/dist/lib/spinner.d.ts +28 -0
  156. package/dist/lib/spinner.d.ts.map +1 -0
  157. package/{lib → dist/lib}/spinner.js +34 -45
  158. package/dist/lib/spinner.js.map +1 -0
  159. package/dist/lib/type-generation/attribute.d.ts +17 -0
  160. package/dist/lib/type-generation/attribute.d.ts.map +1 -0
  161. package/dist/lib/type-generation/attribute.js +19 -0
  162. package/dist/lib/type-generation/attribute.js.map +1 -0
  163. package/dist/lib/type-generation/languages/csharp.d.ts +7 -0
  164. package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -0
  165. package/dist/lib/type-generation/languages/csharp.js +180 -0
  166. package/dist/lib/type-generation/languages/csharp.js.map +1 -0
  167. package/dist/lib/type-generation/languages/dart.d.ts +8 -0
  168. package/dist/lib/type-generation/languages/dart.d.ts.map +1 -0
  169. package/dist/lib/type-generation/languages/dart.js +197 -0
  170. package/dist/lib/type-generation/languages/dart.js.map +1 -0
  171. package/dist/lib/type-generation/languages/java.d.ts +7 -0
  172. package/dist/lib/type-generation/languages/java.d.ts.map +1 -0
  173. package/dist/lib/type-generation/languages/java.js +140 -0
  174. package/dist/lib/type-generation/languages/java.js.map +1 -0
  175. package/dist/lib/type-generation/languages/javascript.d.ts +9 -0
  176. package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -0
  177. package/dist/lib/type-generation/languages/javascript.js +108 -0
  178. package/dist/lib/type-generation/languages/javascript.js.map +1 -0
  179. package/dist/lib/type-generation/languages/kotlin.d.ts +7 -0
  180. package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -0
  181. package/dist/lib/type-generation/languages/kotlin.js +95 -0
  182. package/dist/lib/type-generation/languages/kotlin.js.map +1 -0
  183. package/dist/lib/type-generation/languages/language.d.ts +43 -0
  184. package/dist/lib/type-generation/languages/language.d.ts.map +1 -0
  185. package/dist/lib/type-generation/languages/language.js +82 -0
  186. package/dist/lib/type-generation/languages/language.js.map +1 -0
  187. package/dist/lib/type-generation/languages/php.d.ts +7 -0
  188. package/dist/lib/type-generation/languages/php.d.ts.map +1 -0
  189. package/dist/lib/type-generation/languages/php.js +116 -0
  190. package/dist/lib/type-generation/languages/php.js.map +1 -0
  191. package/dist/lib/type-generation/languages/swift.d.ts +7 -0
  192. package/dist/lib/type-generation/languages/swift.d.ts.map +1 -0
  193. package/dist/lib/type-generation/languages/swift.js +179 -0
  194. package/dist/lib/type-generation/languages/swift.js.map +1 -0
  195. package/dist/lib/type-generation/languages/typescript.d.ts +9 -0
  196. package/dist/lib/type-generation/languages/typescript.d.ts.map +1 -0
  197. package/dist/lib/type-generation/languages/typescript.js +112 -0
  198. package/dist/lib/type-generation/languages/typescript.js.map +1 -0
  199. package/dist/lib/types.d.ts +133 -0
  200. package/dist/lib/types.d.ts.map +1 -0
  201. package/dist/lib/types.js +3 -0
  202. package/dist/lib/types.js.map +1 -0
  203. package/dist/lib/utils.d.ts +15 -0
  204. package/dist/lib/utils.d.ts.map +1 -0
  205. package/{lib → dist/lib}/utils.js +74 -120
  206. package/dist/lib/utils.js.map +1 -0
  207. package/dist/lib/validations.d.ts +2 -0
  208. package/dist/lib/validations.d.ts.map +1 -0
  209. package/dist/lib/validations.js +20 -0
  210. package/dist/lib/validations.js.map +1 -0
  211. package/docs/examples/databases/upsert-document.md +1 -2
  212. package/index.ts +152 -0
  213. package/install.ps1 +2 -5
  214. package/install.sh +1 -2
  215. package/lib/client.ts +259 -0
  216. package/lib/commands/{account.js → account.ts} +408 -662
  217. package/lib/commands/console.ts +112 -0
  218. package/lib/commands/{databases.js → databases.ts} +818 -1136
  219. package/lib/commands/{functions.js → functions.ts} +381 -526
  220. package/lib/commands/{generic.js → generic.ts} +47 -39
  221. package/lib/commands/graphql.ts +110 -0
  222. package/lib/commands/{health.js → health.ts} +168 -284
  223. package/lib/commands/{init.js → init.ts} +68 -66
  224. package/lib/commands/{locale.js → locale.ts} +75 -121
  225. package/lib/commands/{messaging.js → messaging.ts} +699 -937
  226. package/lib/commands/{migrations.js → migrations.ts} +182 -258
  227. package/lib/commands/organizations.ts +46 -0
  228. package/lib/commands/{project.js → project.ts} +75 -111
  229. package/lib/commands/{projects.js → projects.ts} +587 -843
  230. package/lib/commands/{proxy.js → proxy.ts} +94 -140
  231. package/lib/commands/{pull.js → pull.ts} +54 -44
  232. package/lib/commands/{push.js → push.ts} +235 -191
  233. package/lib/commands/{run.js → run.ts} +61 -55
  234. package/lib/commands/{sites.js → sites.ts} +364 -504
  235. package/lib/commands/{storage.js → storage.ts} +216 -292
  236. package/lib/commands/{tables-db.js → tables-db.ts} +817 -1126
  237. package/lib/commands/{teams.js → teams.ts} +162 -236
  238. package/lib/commands/{tokens.js → tokens.ts} +70 -99
  239. package/lib/commands/{types.js → types.ts} +37 -35
  240. package/lib/commands/{update.js → update.ts} +25 -27
  241. package/lib/commands/{users.js → users.ts} +426 -644
  242. package/lib/commands/{vcs.js → vcs.ts} +118 -174
  243. package/lib/config.ts +854 -0
  244. package/lib/emulation/{docker.js → docker.ts} +39 -38
  245. package/lib/emulation/utils.ts +193 -0
  246. package/lib/exception.ts +20 -0
  247. package/lib/{id.js → id.ts} +5 -5
  248. package/lib/paginate.ts +63 -0
  249. package/lib/parser.ts +238 -0
  250. package/lib/{questions.js → questions.ts} +148 -156
  251. package/lib/sdks.ts +55 -0
  252. package/lib/spinner.ts +118 -0
  253. package/lib/type-generation/attribute.ts +17 -0
  254. package/lib/type-generation/languages/{csharp.js → csharp.ts} +59 -57
  255. package/lib/type-generation/languages/{dart.js → dart.ts} +91 -89
  256. package/lib/type-generation/languages/{java.js → java.ts} +58 -56
  257. package/lib/type-generation/languages/javascript.ts +111 -0
  258. package/lib/type-generation/languages/kotlin.ts +96 -0
  259. package/lib/type-generation/languages/language.ts +119 -0
  260. package/lib/type-generation/languages/{php.js → php.ts} +55 -53
  261. package/lib/type-generation/languages/{swift.js → swift.ts} +59 -57
  262. package/lib/type-generation/languages/typescript.ts +116 -0
  263. package/lib/types.ts +150 -0
  264. package/lib/utils.ts +322 -0
  265. package/lib/validations.ts +17 -0
  266. package/package.json +21 -12
  267. package/scoop/appwrite.config.json +3 -3
  268. package/tsconfig.json +30 -0
  269. package/index.js +0 -147
  270. package/lib/client.js +0 -254
  271. package/lib/commands/console.js +0 -127
  272. package/lib/commands/graphql.js +0 -126
  273. package/lib/commands/organizations.js +0 -48
  274. package/lib/emulation/utils.js +0 -186
  275. package/lib/exception.js +0 -9
  276. package/lib/parser.js +0 -250
  277. package/lib/sdks.js +0 -60
  278. package/lib/type-generation/attribute.js +0 -19
  279. package/lib/type-generation/languages/javascript.js +0 -111
  280. package/lib/type-generation/languages/kotlin.js +0 -94
  281. package/lib/type-generation/languages/language.js +0 -125
  282. package/lib/type-generation/languages/typescript.js +0 -116
  283. package/lib/validations.js +0 -17
@@ -0,0 +1,116 @@
1
+ import fs = require('fs');
2
+ import path = require('path');
3
+ import { AttributeType } from '../attribute';
4
+ import { LanguageMeta, Attribute, Collection } from './language';
5
+
6
+ export class TypeScript extends LanguageMeta {
7
+ getType(attribute: Attribute, collections?: Collection[], collectionName?: string): string {
8
+ let type = '';
9
+ switch (attribute.type) {
10
+ case AttributeType.STRING:
11
+ case AttributeType.EMAIL:
12
+ case AttributeType.DATETIME:
13
+ case AttributeType.IP:
14
+ case AttributeType.URL:
15
+ type = 'string';
16
+ if (attribute.format === AttributeType.ENUM) {
17
+ type = LanguageMeta.toPascalCase(collectionName!) + LanguageMeta.toPascalCase(attribute.key);
18
+ }
19
+ break;
20
+ case AttributeType.INTEGER:
21
+ type = 'number';
22
+ break;
23
+ case AttributeType.FLOAT:
24
+ type = 'number';
25
+ break;
26
+ case AttributeType.BOOLEAN:
27
+ type = 'boolean';
28
+ break;
29
+ case AttributeType.RELATIONSHIP:
30
+ const relatedCollection = collections?.find((c) => c.$id === attribute.relatedCollection);
31
+ if (!relatedCollection) {
32
+ throw new Error(`Related collection with ID '${attribute.relatedCollection}' not found.`);
33
+ }
34
+ type = LanguageMeta.toPascalCase(relatedCollection.name);
35
+ if (
36
+ (attribute.relationType === 'oneToMany' && attribute.side === 'parent') ||
37
+ (attribute.relationType === 'manyToOne' && attribute.side === 'child') ||
38
+ attribute.relationType === 'manyToMany'
39
+ ) {
40
+ type = `${type}[]`;
41
+ }
42
+ break;
43
+ case AttributeType.POINT:
44
+ type = 'Array<number>';
45
+ break;
46
+ case AttributeType.LINESTRING:
47
+ type = 'Array<Array<number>>';
48
+ break;
49
+ case AttributeType.POLYGON:
50
+ type = 'Array<Array<Array<number>>>';
51
+ break;
52
+ default:
53
+ throw new Error(`Unknown attribute type: ${attribute.type}`);
54
+ }
55
+ if (attribute.array) {
56
+ type += '[]';
57
+ }
58
+ if (!attribute.required && attribute.default === null) {
59
+ type += ' | null';
60
+ }
61
+ return type;
62
+ }
63
+
64
+ isSingleFile(): boolean {
65
+ return true;
66
+ }
67
+
68
+ private _getAppwriteDependency(): string {
69
+ if (fs.existsSync(path.resolve(process.cwd(), 'package.json'))) {
70
+ const packageJsonRaw = fs.readFileSync(path.resolve(process.cwd(), 'package.json'));
71
+ const packageJson = JSON.parse(packageJsonRaw.toString('utf-8'));
72
+ return packageJson.dependencies && packageJson.dependencies['node-appwrite'] ? 'node-appwrite' : 'appwrite';
73
+ }
74
+
75
+ if (fs.existsSync(path.resolve(process.cwd(), 'deno.json'))) {
76
+ return 'https://deno.land/x/appwrite/mod.ts';
77
+ }
78
+
79
+ return 'appwrite';
80
+ }
81
+
82
+ getTemplate(): string {
83
+ return `import type { Models } from '${this._getAppwriteDependency()}';
84
+
85
+ // This file is auto-generated by the Appwrite CLI.
86
+ // You can regenerate it by running \`appwrite ${process.argv.slice(2).join(' ')}\`.
87
+
88
+ <% for (const collection of collections) { -%>
89
+ <% for (const attribute of collection.attributes) { -%>
90
+ <% if (attribute.format === 'enum') { -%>
91
+ export enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
92
+ <% const entries = Object.entries(attribute.elements); -%>
93
+ <% for (let i = 0; i < entries.length; i++) { -%>
94
+ <%- toUpperSnakeCase(entries[i][1]) %> = "<%- entries[i][1] %>"<% if (i !== entries.length - 1) { %>,<% } %>
95
+ <% } -%>
96
+ }
97
+
98
+ <% } -%>
99
+ <% } -%>
100
+ <% } -%>
101
+ <% for (const [index, collection] of Object.entries(collections)) { -%>
102
+ export type <%- toPascalCase(collection.name) %> = Models.Row & {
103
+ <% for (const attribute of collection.attributes) { -%>
104
+ <% const propertyName = strict ? toCamelCase(attribute.key) : attribute.key; -%>
105
+ <% const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propertyName); -%>
106
+ <% if (isValidIdentifier) { %><%- propertyName %><% } else { %>"<%- propertyName %>"<% } %>: <%- getType(attribute, collections, collection.name) %>;
107
+ <% } -%>
108
+ }<% if (index < collections.length - 1) { %>
109
+ <% } %>
110
+ <% } -%>`;
111
+ }
112
+
113
+ getFileName(_: Collection | undefined): string {
114
+ return 'appwrite.d.ts';
115
+ }
116
+ }
package/lib/types.ts ADDED
@@ -0,0 +1,150 @@
1
+ export interface CliConfig {
2
+ verbose: boolean;
3
+ json: boolean;
4
+ force: boolean;
5
+ all: boolean;
6
+ ids: string[];
7
+ report: boolean;
8
+ reportData: Record<string, unknown>;
9
+ }
10
+
11
+ export interface Headers {
12
+ [key: string]: string;
13
+ }
14
+
15
+ export interface RequestParams {
16
+ [key: string]: unknown;
17
+ }
18
+
19
+ export interface FileUpload {
20
+ type: 'file';
21
+ file: Buffer | ReadableStream;
22
+ filename: string;
23
+ }
24
+
25
+ export type ResponseType = 'json' | 'arraybuffer';
26
+
27
+ export interface ConfigData {
28
+ [key: string]: unknown;
29
+ }
30
+
31
+ export interface SessionData {
32
+ endpoint: string;
33
+ email?: string;
34
+ phone?: string;
35
+ cookie?: string;
36
+ }
37
+
38
+ export interface GlobalConfigData {
39
+ sessions: {
40
+ [key: string]: SessionData;
41
+ };
42
+ current: string;
43
+ cookie?: string;
44
+ }
45
+
46
+ export interface ProjectConfigData {
47
+ projectId?: string;
48
+ projectName?: string;
49
+ functions?: FunctionConfig[];
50
+ collections?: CollectionConfig[];
51
+ databases?: DatabaseConfig[];
52
+ buckets?: BucketConfig[];
53
+ teams?: TeamConfig[];
54
+ topics?: TopicConfig[];
55
+ }
56
+
57
+ export interface FunctionConfig {
58
+ $id: string;
59
+ name: string;
60
+ runtime: string;
61
+ path: string;
62
+ entrypoint: string;
63
+ execute?: string[];
64
+ enabled?: boolean;
65
+ logging?: boolean;
66
+ events?: string[];
67
+ schedule?: string;
68
+ timeout?: number;
69
+ vars?: Record<string, string>;
70
+ commands?: string;
71
+ scopes?: string[];
72
+ specification?: string;
73
+ }
74
+
75
+ export interface CollectionConfig {
76
+ $id: string;
77
+ $permissions?: string[];
78
+ databaseId: string;
79
+ name: string;
80
+ enabled?: boolean;
81
+ documentSecurity?: boolean;
82
+ attributes?: AttributeConfig[];
83
+ indexes?: IndexConfig[];
84
+ }
85
+
86
+ export interface AttributeConfig {
87
+ key: string;
88
+ type: string;
89
+ required?: boolean;
90
+ array?: boolean;
91
+ size?: number;
92
+ default?: unknown;
93
+ min?: number;
94
+ max?: number;
95
+ format?: string;
96
+ elements?: string[];
97
+ relatedCollection?: string;
98
+ relationType?: string;
99
+ twoWay?: boolean;
100
+ twoWayKey?: string;
101
+ onDelete?: string;
102
+ side?: string;
103
+ encrypt?: boolean;
104
+ }
105
+
106
+ export interface IndexConfig {
107
+ key: string;
108
+ type: string;
109
+ status?: string;
110
+ attributes?: string[];
111
+ orders?: string[];
112
+ }
113
+
114
+ export interface DatabaseConfig {
115
+ $id: string;
116
+ name: string;
117
+ enabled?: boolean;
118
+ }
119
+
120
+ export interface BucketConfig {
121
+ $id: string;
122
+ $permissions?: string[];
123
+ name: string;
124
+ enabled?: boolean;
125
+ fileSecurity?: boolean;
126
+ maximumFileSize?: number;
127
+ allowedFileExtensions?: string[];
128
+ compression?: string;
129
+ encryption?: boolean;
130
+ antivirus?: boolean;
131
+ }
132
+
133
+ export interface TeamConfig {
134
+ $id: string;
135
+ name: string;
136
+ }
137
+
138
+ export interface TopicConfig {
139
+ $id: string;
140
+ name: string;
141
+ subscribe?: string[];
142
+ }
143
+
144
+ export interface CommandDescription {
145
+ [key: string]: string;
146
+ }
147
+
148
+ export interface ParsedData {
149
+ [key: string]: unknown;
150
+ }
package/lib/utils.ts ADDED
@@ -0,0 +1,322 @@
1
+ import fs = require('fs');
2
+ import path = require('path');
3
+ import net = require('net');
4
+ import childProcess = require('child_process');
5
+ import chalk = require('chalk');
6
+ import { fetch } from 'undici';
7
+ import { localConfig, globalConfig } from './config';
8
+
9
+ /**
10
+ * Get the latest version from npm registry
11
+ */
12
+ export async function getLatestVersion(): Promise<string> {
13
+ try {
14
+ const response = await fetch('https://registry.npmjs.org/appwrite-cli/latest');
15
+ if (!response.ok) {
16
+ throw new Error(`HTTP ${response.status}`);
17
+ }
18
+ const data = await response.json() as { version: string };
19
+ return data.version;
20
+ } catch (e) {
21
+ throw new Error(`Failed to fetch latest version: ${(e as Error).message}`);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Compare versions using semantic versioning
27
+ */
28
+ export function compareVersions(current: string, latest: string): number {
29
+ const currentParts = current.split('.').map(Number);
30
+ const latestParts = latest.split('.').map(Number);
31
+
32
+ for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
33
+ const currentPart = currentParts[i] || 0;
34
+ const latestPart = latestParts[i] || 0;
35
+
36
+ if (latestPart > currentPart) return 1; // Latest is newer
37
+ if (latestPart < currentPart) return -1; // Current is newer
38
+ }
39
+
40
+ return 0; // Same version
41
+ }
42
+
43
+ export function getAllFiles(folder: string): string[] {
44
+ const files: string[] = [];
45
+ for (const pathDir of fs.readdirSync(folder)) {
46
+ const pathAbsolute = path.join(folder, pathDir);
47
+ let stats: fs.Stats;
48
+ try {
49
+ stats = fs.statSync(pathAbsolute);
50
+ } catch (error) {
51
+ continue;
52
+ }
53
+ if (stats.isDirectory()) {
54
+ files.push(...getAllFiles(pathAbsolute));
55
+ } else {
56
+ files.push(pathAbsolute);
57
+ }
58
+ }
59
+ return files;
60
+ }
61
+
62
+ export async function isPortTaken(port: number): Promise<boolean> {
63
+ const taken = await new Promise<boolean>((res, rej) => {
64
+ const tester = net
65
+ .createServer()
66
+ .once('error', function (err: NodeJS.ErrnoException) {
67
+ if (err.code != 'EADDRINUSE') return rej(err);
68
+ res(true);
69
+ })
70
+ .once('listening', function () {
71
+ tester
72
+ .once('close', function () {
73
+ res(false);
74
+ })
75
+ .close();
76
+ })
77
+ .listen(port);
78
+ });
79
+
80
+ return taken;
81
+ }
82
+
83
+ export function systemHasCommand(command: string): boolean {
84
+ const isUsingWindows = process.platform == 'win32';
85
+
86
+ try {
87
+ if (isUsingWindows) {
88
+ childProcess.execSync('where ' + command, { stdio: 'pipe' });
89
+ } else {
90
+ childProcess.execSync(`[[ $(${command} --version) ]] || { exit 1; } && echo "OK"`, {
91
+ stdio: 'pipe',
92
+ shell: '/bin/bash',
93
+ });
94
+ }
95
+ } catch (error) {
96
+ console.log(error);
97
+ return false;
98
+ }
99
+
100
+ return true;
101
+ }
102
+
103
+ export const checkDeployConditions = (localConfig: any): void => {
104
+ if (Object.keys(localConfig.data).length === 0) {
105
+ throw new Error(
106
+ "No appwrite.config.json file found in the current directory. Please run this command again in the folder containing your appwrite.config.json file, or run 'appwrite init project' to link current directory to an Appwrite project."
107
+ );
108
+ }
109
+ };
110
+
111
+ export function showConsoleLink(serviceName: string, action: string, ...ids: string[]): void {
112
+ const projectId = localConfig.getProject().projectId;
113
+
114
+ const url = new URL(globalConfig.getEndpoint().replace('/v1', '/console'));
115
+ url.pathname += `/project-${projectId}`;
116
+ action = action.toLowerCase();
117
+
118
+ switch (serviceName) {
119
+ case 'account':
120
+ url.pathname = url.pathname.replace(`/project-${projectId}`, '');
121
+ url.pathname += getAccountPath(action);
122
+ break;
123
+ case 'databases':
124
+ url.pathname += getDatabasePath(action, ids);
125
+ break;
126
+ case 'functions':
127
+ url.pathname += getFunctionsPath(action, ids);
128
+ break;
129
+ case 'messaging':
130
+ url.pathname += getMessagingPath(action, ids);
131
+ break;
132
+ case 'projects':
133
+ url.pathname = url.pathname.replace(`/project-${projectId}`, '');
134
+ url.pathname += getProjectsPath(action, ids);
135
+ break;
136
+ case 'storage':
137
+ url.pathname += getBucketsPath(action, ids);
138
+ break;
139
+ case 'teams':
140
+ url.pathname += getTeamsPath(action, ids);
141
+ break;
142
+ case 'organizations':
143
+ url.pathname += getOrganizationsPath(action, ids);
144
+ break;
145
+ case 'users':
146
+ url.pathname += getUsersPath(action, ids);
147
+ break;
148
+ default:
149
+ return;
150
+ }
151
+
152
+ console.log(`${chalk.green.bold('✓ Success:')} ${chalk.green(url.toString())}`);
153
+ }
154
+
155
+ function getAccountPath(action: string): string {
156
+ let path = '/account';
157
+
158
+ if (action === 'listsessions') {
159
+ path += '/sessions';
160
+ }
161
+
162
+ return path;
163
+ }
164
+
165
+ function getDatabasePath(action: string, ids: string[]): string {
166
+ let path = '/databases';
167
+
168
+ if (['get', 'listcollections', 'getcollection', 'listattributes', 'listdocuments', 'getdocument', 'listindexes', 'getdatabaseusage'].includes(action)) {
169
+ path += `/database-${ids[0]}`;
170
+ }
171
+
172
+ if (action === 'getdatabaseusage') {
173
+ path += `/usage`;
174
+ }
175
+
176
+ if (['getcollection', 'listattributes', 'listdocuments', 'getdocument', 'listindexes'].includes(action)) {
177
+ path += `/collection-${ids[1]}`;
178
+ }
179
+
180
+ if (action === 'listattributes') {
181
+ path += '/attributes';
182
+ }
183
+ if (action === 'listindexes') {
184
+ path += '/indexes';
185
+ }
186
+ if (action === 'getdocument') {
187
+ path += `/document-${ids[2]}`;
188
+ }
189
+
190
+ return path;
191
+ }
192
+
193
+ function getFunctionsPath(action: string, ids: string[]): string {
194
+ let path = '/functions';
195
+
196
+ if (action !== 'list') {
197
+ path += `/function-${ids[0]}`;
198
+ }
199
+
200
+ if (action === 'getdeployment') {
201
+ path += `/deployment-${ids[1]}`;
202
+ }
203
+
204
+ if (action === 'getexecution' || action === 'listexecution') {
205
+ path += `/executions`;
206
+ }
207
+ if (action === 'getfunctionusage') {
208
+ path += `/usage`;
209
+ }
210
+
211
+ return path;
212
+ }
213
+
214
+ function getMessagingPath(action: string, ids: string[]): string {
215
+ let path = '/messaging';
216
+
217
+ if (['getmessage', 'listmessagelogs'].includes(action)) {
218
+ path += `/message-${ids[0]}`;
219
+ }
220
+
221
+ if (['listproviders', 'getprovider'].includes(action)) {
222
+ path += `/providers`;
223
+ }
224
+
225
+ if (action === 'getprovider') {
226
+ path += `/provider-${ids[0]}`;
227
+ }
228
+
229
+ if (['listtopics', 'gettopic'].includes(action)) {
230
+ path += `/topics`;
231
+ }
232
+
233
+ if (action === 'gettopic') {
234
+ path += `/topic-${ids[0]}`;
235
+ }
236
+
237
+ return path;
238
+ }
239
+
240
+ function getProjectsPath(action: string, ids: string[]): string {
241
+ let path = '';
242
+
243
+ if (action !== 'list') {
244
+ path += `/project-${ids[0]}`;
245
+ }
246
+
247
+ if (['listkeys', 'getkey'].includes(action)) {
248
+ path += '/overview/keys';
249
+ }
250
+
251
+ if (['listplatforms', 'getplatform'].includes(action)) {
252
+ path += '/overview/platforms';
253
+ }
254
+
255
+ if (['listwebhooks', 'getwebhook'].includes(action)) {
256
+ path += '/settings/webhooks';
257
+ }
258
+
259
+ if (['getplatform', 'getkey', 'getwebhook'].includes(action)) {
260
+ path += `/${ids[1]}`;
261
+ }
262
+
263
+ return path;
264
+ }
265
+
266
+ function getBucketsPath(action: string, ids: string[]): string {
267
+ let path = '/storage';
268
+
269
+ if (action !== 'listbuckets') {
270
+ path += `/bucket-${ids[0]}`;
271
+ }
272
+
273
+ if (action === 'getbucketusage') {
274
+ path += `/usage`;
275
+ }
276
+
277
+ if (action === 'getfile') {
278
+ path += `/file-${ids[1]}`;
279
+ }
280
+
281
+ return path;
282
+ }
283
+
284
+ function getTeamsPath(action: string, ids: string[]): string {
285
+ let path = '/auth/teams';
286
+
287
+ if (action !== 'list') {
288
+ path += `/team-${ids[0]}`;
289
+ }
290
+
291
+ return path;
292
+ }
293
+
294
+ function getOrganizationsPath(action: string, ids: string[]): string {
295
+ let path = `/organization-${ids[0]}`;
296
+
297
+ if (action === 'list') {
298
+ path = '/account/organizations';
299
+ }
300
+
301
+ return path;
302
+ }
303
+
304
+ function getUsersPath(action: string, ids: string[]): string {
305
+ let path = '/auth';
306
+
307
+ if (action !== 'list') {
308
+ path += `/user-${ids[0]}`;
309
+ }
310
+
311
+ if (action === 'listsessions') {
312
+ path += 'sessions';
313
+ }
314
+
315
+ return path;
316
+ }
317
+
318
+ export function isCloud(): boolean {
319
+ const endpoint = globalConfig.getEndpoint() || 'https://cloud.appwrite.io/v1';
320
+ const hostname = new URL(endpoint).hostname;
321
+ return hostname.endsWith('appwrite.io');
322
+ }
@@ -0,0 +1,17 @@
1
+ export const validateRequired = (resource: string, value: any): string | true => {
2
+ if (Array.isArray(value)) {
3
+ if (value.length <= 0) {
4
+ return `Please select at least one ${resource}`;
5
+ }
6
+ } else {
7
+ if (
8
+ value === undefined ||
9
+ value === null ||
10
+ (typeof value === 'string' && value.trim() === '')
11
+ ) {
12
+ return `${resource} is required`;
13
+ }
14
+ }
15
+
16
+ return true;
17
+ };
package/package.json CHANGED
@@ -2,24 +2,27 @@
2
2
  "name": "appwrite-cli",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5
- "version": "12.0.1",
5
+ "version": "13.0.0-rc.1",
6
6
  "license": "BSD-3-Clause",
7
- "main": "index.js",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
8
9
  "bin": {
9
- "appwrite": "index.js"
10
+ "appwrite": "dist/index.js"
10
11
  },
11
12
  "repository": {
12
13
  "type": "git",
13
14
  "url": "https://github.com/appwrite/sdk-for-cli"
14
15
  },
15
16
  "scripts": {
17
+ "build": "tsc || true",
18
+ "prepublishOnly": "npm run build",
16
19
  "test": "echo \"Error: no test specified\" && exit 1",
17
- "linux-x64": "pkg -t node18-linux-x64 -o build/appwrite-cli-linux-x64 package.json",
18
- "linux-arm64": "pkg -t node18-linux-arm64 -o build/appwrite-cli-linux-arm64 package.json",
19
- "mac-x64": "pkg -t node18-macos-x64 -o build/appwrite-cli-darwin-x64 package.json",
20
- "mac-arm64": "pkg -t node18-macos-arm64 -o build/appwrite-cli-darwin-arm64 package.json",
21
- "windows-x64": "pkg -t node18-win-x64 -o build/appwrite-cli-win-x64.exe package.json",
22
- "windows-arm64": "pkg -t node18-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
20
+ "linux-x64": "npm run build && pkg -t node18-linux-x64 -o build/appwrite-cli-linux-x64 package.json",
21
+ "linux-arm64": "npm run build && pkg -t node18-linux-arm64 -o build/appwrite-cli-linux-arm64 package.json",
22
+ "mac-x64": "npm run build && pkg -t node18-macos-x64 -o build/appwrite-cli-darwin-x64 package.json",
23
+ "mac-arm64": "npm run build && pkg -t node18-macos-arm64 -o build/appwrite-cli-darwin-arm64 package.json",
24
+ "windows-x64": "npm run build && pkg -t node18-win-x64 -o build/appwrite-cli-win-x64.exe package.json",
25
+ "windows-arm64": "npm run build && pkg -t node18-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
23
26
  },
24
27
  "dependencies": {
25
28
  "undici": "^5.28.2",
@@ -39,12 +42,18 @@
39
42
  "dotenv": "^16.4.5"
40
43
  },
41
44
  "devDependencies": {
42
- "@yao-pkg/pkg": "^6.9.0"
45
+ "@yao-pkg/pkg": "^6.9.0",
46
+ "@types/node": "^18.19.0",
47
+ "@types/inquirer": "^8.2.10",
48
+ "@types/cli-progress": "^3.11.5",
49
+ "@types/tar": "^6.1.11",
50
+ "@types/json-bigint": "^1.0.4",
51
+ "typescript": "^5.3.3"
43
52
  },
44
53
  "pkg": {
45
54
  "scripts": [
46
- "index.js",
47
- "lib/**/*.js"
55
+ "dist/index.js",
56
+ "dist/lib/**/*.js"
48
57
  ]
49
58
  }
50
59
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
3
- "version": "12.0.1",
3
+ "version": "13.0.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/12.0.1/appwrite-cli-win-x64.exe",
9
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.0.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/12.0.1/appwrite-cli-win-arm64.exe",
18
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.0.0-rc.1/appwrite-cli-win-arm64.exe",
19
19
  "bin": [
20
20
  [
21
21
  "appwrite-cli-win-arm64.exe",