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
@@ -1,16 +1,24 @@
1
- const tar = require("tar");
2
- const ignore = require("ignore");
3
- const net = require('net');
4
- const chalk = require('chalk');
5
- const childProcess = require('child_process');
6
- const { localConfig } = require("../config");
7
- const path = require('path');
8
- const fs = require('fs');
9
- const { log, error, success, hint } = require("../parser");
10
- const { openRuntimesVersion, systemTools, Queue } = require("./utils");
11
- const { getAllFiles } = require("../utils");
12
-
13
- async function dockerStop(id) {
1
+ import ignore = require('ignore');
2
+ import net = require('net');
3
+ import chalk from 'chalk';
4
+ import childProcess = require('child_process');
5
+ import { localConfig } from '../config';
6
+ import path = require('path');
7
+ import fs = require('fs');
8
+ import { log, error, success } from '../parser';
9
+ import { openRuntimesVersion, systemTools, Queue } from './utils';
10
+ import { getAllFiles } from '../utils';
11
+
12
+ interface FunctionConfig {
13
+ $id: string;
14
+ runtime: string;
15
+ path: string;
16
+ entrypoint: string;
17
+ commands: string;
18
+ ignore?: string;
19
+ }
20
+
21
+ export async function dockerStop(id: string): Promise<void> {
14
22
  const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], {
15
23
  stdio: 'pipe',
16
24
  env: {
@@ -19,10 +27,10 @@ async function dockerStop(id) {
19
27
  }
20
28
  });
21
29
 
22
- await new Promise((res) => { stopProcess.on('close', res) });
30
+ await new Promise<void>((res) => { stopProcess.on('close', res) });
23
31
  }
24
32
 
25
- async function dockerPull(func) {
33
+ export async function dockerPull(func: FunctionConfig): Promise<void> {
26
34
  const runtimeChunks = func.runtime.split("-");
27
35
  const runtimeVersion = runtimeChunks.pop();
28
36
  const runtimeName = runtimeChunks.join("-");
@@ -38,10 +46,10 @@ async function dockerPull(func) {
38
46
  }
39
47
  });
40
48
 
41
- await new Promise((res) => { pullProcess.on('close', res) });
49
+ await new Promise<void>((res) => { pullProcess.on('close', res) });
42
50
  }
43
51
 
44
- async function dockerBuild(func, variables) {
52
+ export async function dockerBuild(func: FunctionConfig, variables: Record<string, string>): Promise<void> {
45
53
  const runtimeChunks = func.runtime.split("-");
46
54
  const runtimeVersion = runtimeChunks.pop();
47
55
  const runtimeName = runtimeChunks.join("-");
@@ -51,7 +59,7 @@ async function dockerBuild(func, variables) {
51
59
 
52
60
  const id = func.$id;
53
61
 
54
- const ignorer = ignore();
62
+ const ignorer = ignore.default();
55
63
  ignorer.add('.appwrite');
56
64
  if (func.ignore) {
57
65
  ignorer.add(func.ignore);
@@ -76,7 +84,7 @@ async function dockerBuild(func, variables) {
76
84
  fs.copyFileSync(sourcePath, filePath);
77
85
  }
78
86
 
79
- const params = [ 'run' ];
87
+ const params: string[] = [ 'run' ];
80
88
  params.push('--name', id);
81
89
  params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`);
82
90
  params.push('-e', 'OPEN_RUNTIMES_ENV=development');
@@ -91,7 +99,7 @@ async function dockerBuild(func, variables) {
91
99
 
92
100
  const buildProcess = childProcess.spawn('docker', params, {
93
101
  stdio: 'pipe',
94
- pwd: functionDir,
102
+ cwd: functionDir,
95
103
  env: {
96
104
  ...process.env,
97
105
  DOCKER_CLI_HINTS: 'false'
@@ -117,7 +125,7 @@ async function dockerBuild(func, variables) {
117
125
  }
118
126
  }, 100);
119
127
 
120
- await new Promise((res) => { buildProcess.on('close', res) });
128
+ await new Promise<void>((res) => { buildProcess.on('close', res) });
121
129
 
122
130
  clearInterval(killInterval);
123
131
  if(!Queue.isEmpty()) {
@@ -132,14 +140,14 @@ async function dockerBuild(func, variables) {
132
140
 
133
141
  const copyProcess = childProcess.spawn('docker', ['cp', `${id}:/mnt/code/code.tar.gz`, copyPath], {
134
142
  stdio: 'pipe',
135
- pwd: functionDir,
143
+ cwd: functionDir,
136
144
  env: {
137
145
  ...process.env,
138
146
  DOCKER_CLI_HINTS: 'false'
139
147
  }
140
148
  });
141
149
 
142
- await new Promise((res) => { copyProcess.on('close', res) });
150
+ await new Promise<void>((res) => { copyProcess.on('close', res) });
143
151
 
144
152
  await dockerStop(id);
145
153
 
@@ -151,7 +159,7 @@ async function dockerBuild(func, variables) {
151
159
  fs.rmSync(tmpBuildPath, { recursive: true, force: true });
152
160
  }
153
161
 
154
- async function dockerStart(func, variables, port) {
162
+ export async function dockerStart(func: FunctionConfig, variables: Record<string, string>, port: number): Promise<void> {
155
163
  // Pack function files
156
164
  const functionDir = path.join(localConfig.getDirname(), func.path);
157
165
 
@@ -164,7 +172,7 @@ async function dockerStart(func, variables, port) {
164
172
 
165
173
  const id = func.$id;
166
174
 
167
- const params = [ 'run' ];
175
+ const params: string[] = [ 'run' ];
168
176
  params.push('--rm');
169
177
  params.push('--name', id);
170
178
  params.push('-p', `${port}:3000`);
@@ -182,7 +190,7 @@ async function dockerStart(func, variables, port) {
182
190
 
183
191
  const startProcess = childProcess.spawn('docker', params, {
184
192
  stdio: 'pipe',
185
- pwd: functionDir,
193
+ cwd: functionDir,
186
194
  env: {
187
195
  ...process.env,
188
196
  DOCKER_CLI_HINTS: 'false'
@@ -199,15 +207,15 @@ async function dockerStart(func, variables, port) {
199
207
 
200
208
  try {
201
209
  await waitUntilPortOpen(port);
202
- } catch(err) {
203
- error("Failed to start function with error: " + err.message ? err.message : err.toString());
210
+ } catch(err: any) {
211
+ error("Failed to start function with error: " + (err.message ? err.message : err.toString()));
204
212
  return;
205
213
  }
206
214
 
207
215
  success(`Visit http://localhost:${port}/ to execute your function.`);
208
216
  }
209
217
 
210
- async function dockerCleanup(functionId) {
218
+ export async function dockerCleanup(functionId: string): Promise<void> {
211
219
  await dockerStop(functionId);
212
220
 
213
221
  const func = localConfig.getFunction(functionId);
@@ -222,7 +230,7 @@ async function dockerCleanup(functionId) {
222
230
  }
223
231
  }
224
232
 
225
- function waitUntilPortOpen(port, iteration = 0) {
233
+ function waitUntilPortOpen(port: number, iteration: number = 0): Promise<void> {
226
234
  return new Promise((resolve, reject) => {
227
235
  const client = new net.Socket();
228
236
 
@@ -246,7 +254,7 @@ function waitUntilPortOpen(port, iteration = 0) {
246
254
  if(iteration > 100) {
247
255
  reject(err);
248
256
  } else {
249
- await new Promise((res) => setTimeout(res, 100));
257
+ await new Promise<void>((res) => setTimeout(res, 100));
250
258
  waitUntilPortOpen(port, iteration + 1).then(resolve).catch(reject);
251
259
  }
252
260
  });
@@ -255,10 +263,3 @@ function waitUntilPortOpen(port, iteration = 0) {
255
263
  });
256
264
  }
257
265
 
258
- module.exports = {
259
- dockerPull,
260
- dockerBuild,
261
- dockerStart,
262
- dockerCleanup,
263
- dockerStop,
264
- }
@@ -0,0 +1,193 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { projectsCreateJWT } from '../commands/projects';
3
+ import { localConfig } from '../config';
4
+ import { usersGet, usersCreateJWT } from '../commands/users';
5
+ import { log } from '../parser';
6
+
7
+ export const openRuntimesVersion = 'v4';
8
+
9
+ export const runtimeNames: Record<string, string> = {
10
+ node: 'Node.js',
11
+ php: 'PHP',
12
+ ruby: 'Ruby',
13
+ python: 'Python',
14
+ 'python-ml': 'Python (ML)',
15
+ deno: 'Deno',
16
+ dart: 'Dart',
17
+ dotnet: '.NET',
18
+ java: 'Java',
19
+ swift: 'Swift',
20
+ kotlin: 'Kotlin',
21
+ bun: 'Bun',
22
+ go: 'Go',
23
+ };
24
+
25
+ interface SystemTool {
26
+ isCompiled: boolean;
27
+ startCommand: string;
28
+ dependencyFiles: string[];
29
+ }
30
+
31
+ export const systemTools: Record<string, SystemTool> = {
32
+ node: {
33
+ isCompiled: false,
34
+ startCommand: 'sh helpers/server.sh',
35
+ dependencyFiles: ['package.json', 'package-lock.json'],
36
+ },
37
+ php: {
38
+ isCompiled: false,
39
+ startCommand: 'sh helpers/server.sh',
40
+ dependencyFiles: ['composer.json', 'composer.lock'],
41
+ },
42
+ ruby: {
43
+ isCompiled: false,
44
+ startCommand: 'sh helpers/server.sh',
45
+ dependencyFiles: ['Gemfile', 'Gemfile.lock'],
46
+ },
47
+ python: {
48
+ isCompiled: false,
49
+ startCommand: 'sh helpers/server.sh',
50
+ dependencyFiles: ['requirements.txt', 'requirements.lock'],
51
+ },
52
+ 'python-ml': {
53
+ isCompiled: false,
54
+ startCommand: 'sh helpers/server.sh',
55
+ dependencyFiles: ['requirements.txt', 'requirements.lock'],
56
+ },
57
+ deno: {
58
+ isCompiled: false,
59
+ startCommand: 'sh helpers/server.sh',
60
+ dependencyFiles: [],
61
+ },
62
+ dart: {
63
+ isCompiled: true,
64
+ startCommand: 'sh helpers/server.sh',
65
+ dependencyFiles: [],
66
+ },
67
+ dotnet: {
68
+ isCompiled: true,
69
+ startCommand: 'sh helpers/server.sh',
70
+ dependencyFiles: [],
71
+ },
72
+ java: {
73
+ isCompiled: true,
74
+ startCommand: 'sh helpers/server.sh',
75
+ dependencyFiles: [],
76
+ },
77
+ swift: {
78
+ isCompiled: true,
79
+ startCommand: 'sh helpers/server.sh',
80
+ dependencyFiles: [],
81
+ },
82
+ kotlin: {
83
+ isCompiled: true,
84
+ startCommand: 'sh helpers/server.sh',
85
+ dependencyFiles: [],
86
+ },
87
+ bun: {
88
+ isCompiled: false,
89
+ startCommand: 'sh helpers/server.sh',
90
+ dependencyFiles: ['package.json', 'package-lock.json', 'bun.lockb'],
91
+ },
92
+ go: {
93
+ isCompiled: true,
94
+ startCommand: 'sh helpers/server.sh',
95
+ dependencyFiles: [],
96
+ },
97
+ };
98
+
99
+ export const JwtManager = {
100
+ userJwt: null as string | null,
101
+ functionJwt: null as string | null,
102
+
103
+ timerWarn: null as NodeJS.Timeout | null,
104
+ timerError: null as NodeJS.Timeout | null,
105
+
106
+ async setup(userId: string | null = null, projectScopes: string[] = []): Promise<void> {
107
+ if (this.timerWarn) {
108
+ clearTimeout(this.timerWarn);
109
+ }
110
+
111
+ if (this.timerError) {
112
+ clearTimeout(this.timerError);
113
+ }
114
+
115
+ this.timerWarn = setTimeout(() => {
116
+ log('Warning: Authorized JWT will expire in 5 minutes. Please stop and re-run the command to refresh tokens for 1 hour.');
117
+ }, 1000 * 60 * 55); // 55 mins
118
+
119
+ this.timerError = setTimeout(() => {
120
+ log('Warning: Authorized JWT just expired. Please stop and re-run the command to obtain new tokens with 1 hour validity.');
121
+ log('Some Appwrite API communication is not authorized now.');
122
+ }, 1000 * 60 * 60); // 60 mins
123
+
124
+ if (userId) {
125
+ await usersGet({
126
+ userId,
127
+ parseOutput: false,
128
+ });
129
+ const userResponse: any = await usersCreateJWT({
130
+ userId,
131
+ duration: 60 * 60,
132
+ parseOutput: false,
133
+ });
134
+ this.userJwt = userResponse.jwt;
135
+ }
136
+
137
+ const functionResponse: any = await projectsCreateJWT({
138
+ projectId: localConfig.getProject().projectId!,
139
+ scopes: projectScopes,
140
+ duration: 60 * 60,
141
+ parseOutput: false,
142
+ });
143
+ this.functionJwt = functionResponse.jwt;
144
+ },
145
+ };
146
+
147
+ interface QueueReloadEvent {
148
+ files: string[];
149
+ }
150
+
151
+ export const Queue = {
152
+ files: [] as string[],
153
+ locked: false,
154
+ events: new EventEmitter(),
155
+ debounce: null as NodeJS.Timeout | null,
156
+
157
+ push(file: string): void {
158
+ if (!this.files.includes(file)) {
159
+ this.files.push(file);
160
+ }
161
+
162
+ if (!this.locked) {
163
+ this._trigger();
164
+ }
165
+ },
166
+
167
+ lock(): void {
168
+ this.files = [];
169
+ this.locked = true;
170
+ },
171
+
172
+ isEmpty(): boolean {
173
+ return this.files.length === 0;
174
+ },
175
+
176
+ unlock(): void {
177
+ this.locked = false;
178
+ if (this.files.length > 0) {
179
+ this._trigger();
180
+ }
181
+ },
182
+
183
+ _trigger(): void {
184
+ if (this.debounce) {
185
+ return;
186
+ }
187
+
188
+ this.debounce = setTimeout(() => {
189
+ this.events.emit('reload', { files: this.files } as QueueReloadEvent);
190
+ this.debounce = null;
191
+ }, 300);
192
+ },
193
+ };
@@ -0,0 +1,20 @@
1
+ class AppwriteException extends Error {
2
+ public code?: number;
3
+ public type?: string;
4
+ public response?: string;
5
+
6
+ constructor(message: string, code?: number, type?: string, response?: string) {
7
+ super(message);
8
+ this.name = 'AppwriteException';
9
+ this.code = code;
10
+ this.type = type;
11
+ this.response = response;
12
+
13
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
14
+ if (Error.captureStackTrace) {
15
+ Error.captureStackTrace(this, AppwriteException);
16
+ }
17
+ }
18
+ }
19
+
20
+ export = AppwriteException;
@@ -1,7 +1,7 @@
1
1
  class ID {
2
2
  // Generate an hex ID based on timestamp
3
3
  // Recreated from https://www.php.net/manual/en/function.uniqid.php
4
- static #hexTimestamp() {
4
+ static #hexTimestamp(): string {
5
5
  const now = new Date();
6
6
  const sec = Math.floor(now.getTime() / 1000);
7
7
  const msec = now.getMilliseconds();
@@ -11,11 +11,11 @@ class ID {
11
11
  return hexTimestamp;
12
12
  }
13
13
 
14
- static custom(id) {
15
- return id
14
+ static custom(id: string): string {
15
+ return id;
16
16
  }
17
17
 
18
- static unique(padding = 7) {
18
+ static unique(padding: number = 7): string {
19
19
  // Generate a unique ID with padding to have a longer ID
20
20
  const baseId = ID.#hexTimestamp();
21
21
  let randomPadding = '';
@@ -27,4 +27,4 @@ class ID {
27
27
  }
28
28
  }
29
29
 
30
- module.exports = ID;
30
+ export = ID;
@@ -0,0 +1,63 @@
1
+ interface PaginateArgs {
2
+ [key: string]: any;
3
+ }
4
+
5
+ interface PaginateResponse<T = any> {
6
+ [key: string]: T;
7
+ total: number;
8
+ }
9
+
10
+ export const paginate = async <T = any>(
11
+ action: (args: PaginateArgs) => Promise<any>,
12
+ args: PaginateArgs = {},
13
+ limit: number = 100,
14
+ wrapper: string = '',
15
+ queries: string[] = []
16
+ ): Promise<T[] | PaginateResponse<T[]>> => {
17
+ let pageNumber = 0;
18
+ let results: T[] = [];
19
+ let total = 0;
20
+
21
+ while (true) {
22
+ const offset = pageNumber * limit;
23
+
24
+ // Merge the limit and offset into the args
25
+ const response = await action({
26
+ ...args,
27
+ queries: [
28
+ ...queries,
29
+ JSON.stringify({ method: 'limit', values: [limit] }),
30
+ JSON.stringify({ method: 'offset', values: [offset] }),
31
+ ],
32
+ });
33
+
34
+ if (wrapper === '') {
35
+ if (response.length === 0) {
36
+ break;
37
+ }
38
+ results = results.concat(response);
39
+ } else {
40
+ if (response[wrapper].length === 0) {
41
+ break;
42
+ }
43
+ results = results.concat(response[wrapper]);
44
+ }
45
+
46
+ total = response.total;
47
+
48
+ if (results.length >= total) {
49
+ break;
50
+ }
51
+
52
+ pageNumber++;
53
+ }
54
+
55
+ if (wrapper === '') {
56
+ return results;
57
+ }
58
+
59
+ return {
60
+ [wrapper]: results,
61
+ total,
62
+ } as PaginateResponse<T[]>;
63
+ };