appwrite-cli 13.1.0-rc.2 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -2
  3. package/dist/bundle-win-arm64.mjs +378 -221
  4. package/dist/cli.cjs +146341 -0
  5. package/dist/index.js +110592 -10
  6. package/dist/lib/commands/generate.d.ts +3 -0
  7. package/dist/lib/commands/generate.d.ts.map +1 -1
  8. package/dist/lib/commands/generators/base.d.ts.map +1 -1
  9. package/dist/lib/commands/generators/typescript/databases.d.ts +4 -0
  10. package/dist/lib/commands/generators/typescript/databases.d.ts.map +1 -1
  11. package/dist/lib/commands/generic.d.ts.map +1 -1
  12. package/dist/lib/commands/init.d.ts.map +1 -1
  13. package/dist/lib/commands/pull.d.ts.map +1 -1
  14. package/dist/lib/commands/push.d.ts.map +1 -1
  15. package/dist/lib/commands/types.d.ts.map +1 -1
  16. package/dist/lib/constants.d.ts +1 -1
  17. package/dist/lib/constants.d.ts.map +1 -1
  18. package/dist/lib/parser.d.ts.map +1 -1
  19. package/dist/lib/shared/typescript-type-utils.d.ts +6 -18
  20. package/dist/lib/shared/typescript-type-utils.d.ts.map +1 -1
  21. package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -1
  22. package/dist/lib/type-generation/languages/dart.d.ts +2 -1
  23. package/dist/lib/type-generation/languages/dart.d.ts.map +1 -1
  24. package/dist/lib/type-generation/languages/java.d.ts.map +1 -1
  25. package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -1
  26. package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -1
  27. package/dist/lib/type-generation/languages/language.d.ts +15 -15
  28. package/dist/lib/type-generation/languages/language.d.ts.map +1 -1
  29. package/dist/lib/type-generation/languages/php.d.ts.map +1 -1
  30. package/dist/lib/type-generation/languages/swift.d.ts.map +1 -1
  31. package/dist/lib/type-generation/languages/typescript.d.ts +2 -1
  32. package/dist/lib/type-generation/languages/typescript.d.ts.map +1 -1
  33. package/docs/examples/health/get-queue-audits.md +1 -0
  34. package/install.ps1 +2 -2
  35. package/install.sh +1 -1
  36. package/lib/commands/generate.ts +52 -13
  37. package/lib/commands/generators/base.ts +4 -0
  38. package/lib/commands/generators/typescript/databases.ts +116 -27
  39. package/lib/commands/generators/typescript/templates/constants.ts.hbs +1 -1
  40. package/lib/commands/generators/typescript/templates/databases.ts.hbs +110 -37
  41. package/lib/commands/generators/typescript/templates/types.ts.hbs +24 -1
  42. package/lib/commands/generic.ts +38 -4
  43. package/lib/commands/init.ts +28 -41
  44. package/lib/commands/pull.ts +12 -4
  45. package/lib/commands/push.ts +15 -4
  46. package/lib/commands/services/health.ts +11 -0
  47. package/lib/commands/types.ts +8 -2
  48. package/lib/constants.ts +1 -1
  49. package/lib/parser.ts +1 -0
  50. package/lib/shared/typescript-type-utils.ts +16 -55
  51. package/lib/type-generation/languages/csharp.ts +4 -9
  52. package/lib/type-generation/languages/dart.ts +72 -31
  53. package/lib/type-generation/languages/java.ts +5 -9
  54. package/lib/type-generation/languages/javascript.ts +3 -10
  55. package/lib/type-generation/languages/kotlin.ts +5 -9
  56. package/lib/type-generation/languages/language.ts +56 -16
  57. package/lib/type-generation/languages/php.ts +5 -9
  58. package/lib/type-generation/languages/swift.ts +5 -13
  59. package/lib/type-generation/languages/typescript.ts +45 -8
  60. package/package.json +7 -4
  61. package/scoop/appwrite.config.json +3 -3
  62. package/dist/cli.js +0 -147
  63. package/dist/cli.js.map +0 -1
  64. package/dist/index.js.map +0 -1
  65. package/dist/lib/client.js +0 -238
  66. package/dist/lib/client.js.map +0 -1
  67. package/dist/lib/commands/config-validations.js +0 -130
  68. package/dist/lib/commands/config-validations.js.map +0 -1
  69. package/dist/lib/commands/config.js +0 -405
  70. package/dist/lib/commands/config.js.map +0 -1
  71. package/dist/lib/commands/errors.js +0 -72
  72. package/dist/lib/commands/errors.js.map +0 -1
  73. package/dist/lib/commands/generate.js +0 -102
  74. package/dist/lib/commands/generate.js.map +0 -1
  75. package/dist/lib/commands/generators/base.js +0 -27
  76. package/dist/lib/commands/generators/base.js.map +0 -1
  77. package/dist/lib/commands/generators/index.js +0 -55
  78. package/dist/lib/commands/generators/index.js.map +0 -1
  79. package/dist/lib/commands/generators/language-detector.js +0 -127
  80. package/dist/lib/commands/generators/language-detector.js.map +0 -1
  81. package/dist/lib/commands/generators/typescript/databases.js +0 -265
  82. package/dist/lib/commands/generators/typescript/databases.js.map +0 -1
  83. package/dist/lib/commands/generic.js +0 -292
  84. package/dist/lib/commands/generic.js.map +0 -1
  85. package/dist/lib/commands/init.js +0 -527
  86. package/dist/lib/commands/init.js.map +0 -1
  87. package/dist/lib/commands/pull.js +0 -658
  88. package/dist/lib/commands/pull.js.map +0 -1
  89. package/dist/lib/commands/push.js +0 -1855
  90. package/dist/lib/commands/push.js.map +0 -1
  91. package/dist/lib/commands/run.js +0 -289
  92. package/dist/lib/commands/run.js.map +0 -1
  93. package/dist/lib/commands/schema.js +0 -86
  94. package/dist/lib/commands/schema.js.map +0 -1
  95. package/dist/lib/commands/services/account.js +0 -328
  96. package/dist/lib/commands/services/account.js.map +0 -1
  97. package/dist/lib/commands/services/console.js +0 -28
  98. package/dist/lib/commands/services/console.js.map +0 -1
  99. package/dist/lib/commands/services/databases.js +0 -620
  100. package/dist/lib/commands/services/databases.js.map +0 -1
  101. package/dist/lib/commands/services/functions.js +0 -266
  102. package/dist/lib/commands/services/functions.js.map +0 -1
  103. package/dist/lib/commands/services/graphql.js +0 -28
  104. package/dist/lib/commands/services/graphql.js.map +0 -1
  105. package/dist/lib/commands/services/health.js +0 -123
  106. package/dist/lib/commands/services/health.js.map +0 -1
  107. package/dist/lib/commands/services/locale.js +0 -52
  108. package/dist/lib/commands/services/locale.js.map +0 -1
  109. package/dist/lib/commands/services/messaging.js +0 -505
  110. package/dist/lib/commands/services/messaging.js.map +0 -1
  111. package/dist/lib/commands/services/migrations.js +0 -135
  112. package/dist/lib/commands/services/migrations.js.map +0 -1
  113. package/dist/lib/commands/services/project.js +0 -54
  114. package/dist/lib/commands/services/project.js.map +0 -1
  115. package/dist/lib/commands/services/projects.js +0 -421
  116. package/dist/lib/commands/services/projects.js.map +0 -1
  117. package/dist/lib/commands/services/proxy.js +0 -68
  118. package/dist/lib/commands/services/proxy.js.map +0 -1
  119. package/dist/lib/commands/services/sites.js +0 -250
  120. package/dist/lib/commands/services/sites.js.map +0 -1
  121. package/dist/lib/commands/services/storage.js +0 -175
  122. package/dist/lib/commands/services/storage.js.map +0 -1
  123. package/dist/lib/commands/services/tables-db.js +0 -613
  124. package/dist/lib/commands/services/tables-db.js.map +0 -1
  125. package/dist/lib/commands/services/teams.js +0 -123
  126. package/dist/lib/commands/services/teams.js.map +0 -1
  127. package/dist/lib/commands/services/tokens.js +0 -49
  128. package/dist/lib/commands/services/tokens.js.map +0 -1
  129. package/dist/lib/commands/services/users.js +0 -312
  130. package/dist/lib/commands/services/users.js.map +0 -1
  131. package/dist/lib/commands/services/vcs.js +0 -87
  132. package/dist/lib/commands/services/vcs.js.map +0 -1
  133. package/dist/lib/commands/types.js +0 -151
  134. package/dist/lib/commands/types.js.map +0 -1
  135. package/dist/lib/commands/update.js +0 -202
  136. package/dist/lib/commands/update.js.map +0 -1
  137. package/dist/lib/commands/utils/attributes.js +0 -538
  138. package/dist/lib/commands/utils/attributes.js.map +0 -1
  139. package/dist/lib/commands/utils/change-approval.js +0 -129
  140. package/dist/lib/commands/utils/change-approval.js.map +0 -1
  141. package/dist/lib/commands/utils/database-sync.js +0 -136
  142. package/dist/lib/commands/utils/database-sync.js.map +0 -1
  143. package/dist/lib/commands/utils/deployment.js +0 -109
  144. package/dist/lib/commands/utils/deployment.js.map +0 -1
  145. package/dist/lib/commands/utils/error-formatter.js +0 -333
  146. package/dist/lib/commands/utils/error-formatter.js.map +0 -1
  147. package/dist/lib/commands/utils/pools.js +0 -164
  148. package/dist/lib/commands/utils/pools.js.map +0 -1
  149. package/dist/lib/config.js +0 -665
  150. package/dist/lib/config.js.map +0 -1
  151. package/dist/lib/constants.js +0 -19
  152. package/dist/lib/constants.js.map +0 -1
  153. package/dist/lib/emulation/docker.js +0 -237
  154. package/dist/lib/emulation/docker.js.map +0 -1
  155. package/dist/lib/emulation/utils.js +0 -165
  156. package/dist/lib/emulation/utils.js.map +0 -1
  157. package/dist/lib/id.js +0 -27
  158. package/dist/lib/id.js.map +0 -1
  159. package/dist/lib/json.js +0 -25
  160. package/dist/lib/json.js.map +0 -1
  161. package/dist/lib/paginate.js +0 -43
  162. package/dist/lib/paginate.js.map +0 -1
  163. package/dist/lib/parser.js +0 -226
  164. package/dist/lib/parser.js.map +0 -1
  165. package/dist/lib/questions.js +0 -1005
  166. package/dist/lib/questions.js.map +0 -1
  167. package/dist/lib/sdks.js +0 -60
  168. package/dist/lib/sdks.js.map +0 -1
  169. package/dist/lib/services.js +0 -47
  170. package/dist/lib/services.js.map +0 -1
  171. package/dist/lib/shared/typescript-type-utils.js +0 -155
  172. package/dist/lib/shared/typescript-type-utils.js.map +0 -1
  173. package/dist/lib/spinner.js +0 -91
  174. package/dist/lib/spinner.js.map +0 -1
  175. package/dist/lib/type-generation/attribute.js +0 -16
  176. package/dist/lib/type-generation/attribute.js.map +0 -1
  177. package/dist/lib/type-generation/languages/csharp.js +0 -180
  178. package/dist/lib/type-generation/languages/csharp.js.map +0 -1
  179. package/dist/lib/type-generation/languages/dart.js +0 -197
  180. package/dist/lib/type-generation/languages/dart.js.map +0 -1
  181. package/dist/lib/type-generation/languages/java.js +0 -140
  182. package/dist/lib/type-generation/languages/java.js.map +0 -1
  183. package/dist/lib/type-generation/languages/javascript.js +0 -109
  184. package/dist/lib/type-generation/languages/javascript.js.map +0 -1
  185. package/dist/lib/type-generation/languages/kotlin.js +0 -95
  186. package/dist/lib/type-generation/languages/kotlin.js.map +0 -1
  187. package/dist/lib/type-generation/languages/language.js +0 -77
  188. package/dist/lib/type-generation/languages/language.js.map +0 -1
  189. package/dist/lib/type-generation/languages/php.js +0 -116
  190. package/dist/lib/type-generation/languages/php.js.map +0 -1
  191. package/dist/lib/type-generation/languages/swift.js +0 -179
  192. package/dist/lib/type-generation/languages/swift.js.map +0 -1
  193. package/dist/lib/type-generation/languages/typescript.js +0 -63
  194. package/dist/lib/type-generation/languages/typescript.js.map +0 -1
  195. package/dist/lib/types.js +0 -2
  196. package/dist/lib/types.js.map +0 -1
  197. package/dist/lib/utils.js +0 -166
  198. package/dist/lib/utils.js.map +0 -1
  199. package/dist/lib/validations.js +0 -16
  200. package/dist/lib/validations.js.map +0 -1
  201. package/dist/package.json +0 -70
@@ -1,665 +0,0 @@
1
- import os from "os";
2
- import fs from "fs";
3
- import _path from "path";
4
- import process from "process";
5
- import { SiteSchema, FunctionSchema, DatabaseSchema, CollectionSchema, AttributeSchema, IndexSchema, TableSchema, ColumnSchema, IndexTableSchema, TopicSchema, TeamSchema, BucketSchema, } from "./commands/config.js";
6
- import { createSettingsObject } from "./utils.js";
7
- import { EXECUTABLE_NAME } from "./constants.js";
8
- import { JSONBig } from "./json.js";
9
- /**
10
- * Extract keys from a Zod object schema.
11
- * Handles both plain ZodObject and ZodEffects (schemas with refinements).
12
- */
13
- function getSchemaKeys(schema) {
14
- // For ZodEffects (created by .refine(), .superRefine(), .transform())
15
- if ("def" in schema && "schema" in schema.def) {
16
- return getSchemaKeys(schema.def.schema);
17
- }
18
- // For ZodObject
19
- if ("shape" in schema) {
20
- return new Set(Object.keys(schema.shape));
21
- }
22
- return new Set();
23
- }
24
- const KeysVars = new Set(["key", "value"]);
25
- const KeysSite = getSchemaKeys(SiteSchema);
26
- const KeysFunction = getSchemaKeys(FunctionSchema);
27
- const KeysDatabase = getSchemaKeys(DatabaseSchema);
28
- const KeysCollection = getSchemaKeys(CollectionSchema);
29
- const KeysTable = getSchemaKeys(TableSchema);
30
- const KeysStorage = getSchemaKeys(BucketSchema);
31
- const KeysTopics = getSchemaKeys(TopicSchema);
32
- const KeysTeams = getSchemaKeys(TeamSchema);
33
- const KeysAttributes = getSchemaKeys(AttributeSchema);
34
- const KeysColumns = getSchemaKeys(ColumnSchema);
35
- const KeyIndexes = getSchemaKeys(IndexSchema);
36
- const KeyIndexesColumns = getSchemaKeys(IndexTableSchema);
37
- const CONFIG_KEY_ORDER = [
38
- "projectId",
39
- "projectName",
40
- "endpoint",
41
- "settings",
42
- "functions",
43
- "sites",
44
- "databases",
45
- "collections",
46
- "tablesDB",
47
- "tables",
48
- "buckets",
49
- "teams",
50
- "topics",
51
- "messages",
52
- ];
53
- function orderConfigKeys(data) {
54
- const ordered = {};
55
- for (const key of CONFIG_KEY_ORDER) {
56
- if (key in data) {
57
- ordered[key] = data[key];
58
- }
59
- }
60
- for (const key of Object.keys(data)) {
61
- if (!(key in ordered)) {
62
- ordered[key] = data[key];
63
- }
64
- }
65
- return ordered;
66
- }
67
- function whitelistKeys(value, keys, nestedKeys = {}) {
68
- if (Array.isArray(value)) {
69
- const newValue = [];
70
- for (const item of value) {
71
- newValue.push(whitelistKeys(item, keys, nestedKeys));
72
- }
73
- return newValue;
74
- }
75
- const newValue = {};
76
- Object.keys(value).forEach((key) => {
77
- if (keys.has(key)) {
78
- if (nestedKeys[key]) {
79
- newValue[key] = whitelistKeys(value[key], nestedKeys[key]);
80
- }
81
- else {
82
- newValue[key] = value[key];
83
- }
84
- }
85
- });
86
- return newValue;
87
- }
88
- class Config {
89
- path;
90
- data;
91
- constructor(path) {
92
- this.path = path;
93
- this.data = {};
94
- this.read();
95
- }
96
- read() {
97
- try {
98
- const file = fs.readFileSync(this.path).toString();
99
- this.data = JSONBig.parse(file);
100
- }
101
- catch (e) {
102
- this.data = {};
103
- }
104
- }
105
- write() {
106
- const dir = _path.dirname(this.path);
107
- if (!fs.existsSync(dir)) {
108
- fs.mkdirSync(dir, { recursive: true });
109
- }
110
- fs.writeFileSync(this.path, JSONBig.stringify(this.data, null, 4), {
111
- mode: 0o600,
112
- });
113
- }
114
- get(key) {
115
- return this.data[key];
116
- }
117
- set(key, value) {
118
- this.data[key] = value;
119
- this.write();
120
- }
121
- delete(key) {
122
- delete this.data[key];
123
- this.write();
124
- }
125
- clear() {
126
- this.data = {};
127
- this.write();
128
- }
129
- has(key) {
130
- return this.data[key] !== undefined;
131
- }
132
- keys() {
133
- return Object.keys(this.data);
134
- }
135
- values() {
136
- return Object.values(this.data);
137
- }
138
- toString() {
139
- return JSONBig.stringify(this.data, null, 4);
140
- }
141
- _getDBEntities(entityType) {
142
- if (!this.has(entityType)) {
143
- return [];
144
- }
145
- return this.get(entityType);
146
- }
147
- _getDBEntity(entityType, $id) {
148
- if (!this.has(entityType)) {
149
- return {};
150
- }
151
- const entities = this.get(entityType);
152
- for (let i = 0; i < entities.length; i++) {
153
- if (entities[i]["$id"] == $id) {
154
- return entities[i];
155
- }
156
- }
157
- return {};
158
- }
159
- _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
160
- props = whitelistKeys(props, keysSet, nestedKeys);
161
- if (!this.has(entityType)) {
162
- this.set(entityType, []);
163
- }
164
- const entities = this.get(entityType);
165
- for (let i = 0; i < entities.length; i++) {
166
- if (entities[i]["$id"] == props["$id"]) {
167
- entities[i] = props;
168
- this.set(entityType, entities);
169
- return;
170
- }
171
- }
172
- entities.push(props);
173
- this.set(entityType, entities);
174
- }
175
- }
176
- class Local extends Config {
177
- static CONFIG_FILE_PATH = `${EXECUTABLE_NAME}.config.json`;
178
- static CONFIG_FILE_PATH_LEGACY = `${EXECUTABLE_NAME}.json`;
179
- configDirectoryPath = "";
180
- constructor(path = Local.CONFIG_FILE_PATH, legacyPath = Local.CONFIG_FILE_PATH_LEGACY) {
181
- let absolutePath = Local.findConfigFile(path) || Local.findConfigFile(legacyPath);
182
- if (!absolutePath) {
183
- absolutePath = `${process.cwd()}/${path}`;
184
- }
185
- super(absolutePath);
186
- this.configDirectoryPath = _path.dirname(absolutePath);
187
- }
188
- write() {
189
- const dir = _path.dirname(this.path);
190
- if (!fs.existsSync(dir)) {
191
- fs.mkdirSync(dir, { recursive: true });
192
- }
193
- const orderedData = orderConfigKeys(this.data);
194
- fs.writeFileSync(this.path, JSONBig.stringify(orderedData, null, 4), {
195
- mode: 0o600,
196
- });
197
- }
198
- static findConfigFile(filename) {
199
- let currentPath = process.cwd();
200
- while (true) {
201
- const filePath = `${currentPath}/${filename}`;
202
- if (fs.existsSync(filePath)) {
203
- return filePath;
204
- }
205
- const parentDirectory = _path.dirname(currentPath);
206
- if (parentDirectory === currentPath) {
207
- break;
208
- }
209
- currentPath = parentDirectory;
210
- }
211
- return null;
212
- }
213
- getDirname() {
214
- return _path.dirname(this.path);
215
- }
216
- getEndpoint() {
217
- return this.get("endpoint") || "";
218
- }
219
- setEndpoint(endpoint) {
220
- this.set("endpoint", endpoint);
221
- }
222
- getSites() {
223
- if (!this.has("sites")) {
224
- return [];
225
- }
226
- return this.get("sites") ?? [];
227
- }
228
- getSite($id) {
229
- if (!this.has("sites")) {
230
- return {};
231
- }
232
- const sites = this.get("sites") ?? [];
233
- for (let i = 0; i < sites.length; i++) {
234
- if (sites[i]["$id"] == $id) {
235
- return sites[i];
236
- }
237
- }
238
- return {};
239
- }
240
- addSite(props) {
241
- props = whitelistKeys(props, KeysSite, {
242
- vars: KeysVars,
243
- });
244
- if (!this.has("sites")) {
245
- this.set("sites", []);
246
- }
247
- const sites = this.get("sites") ?? [];
248
- for (let i = 0; i < sites.length; i++) {
249
- if (sites[i]["$id"] == props["$id"]) {
250
- sites[i] = {
251
- ...sites[i],
252
- ...props,
253
- };
254
- this.set("sites", sites);
255
- return;
256
- }
257
- }
258
- sites.push(props);
259
- this.set("sites", sites);
260
- }
261
- getFunctions() {
262
- if (!this.has("functions")) {
263
- return [];
264
- }
265
- return this.get("functions") ?? [];
266
- }
267
- getFunction($id) {
268
- if (!this.has("functions")) {
269
- return {};
270
- }
271
- const functions = this.get("functions") ?? [];
272
- for (let i = 0; i < functions.length; i++) {
273
- if (functions[i]["$id"] == $id) {
274
- return functions[i];
275
- }
276
- }
277
- return {};
278
- }
279
- addFunction(props) {
280
- props = whitelistKeys(props, KeysFunction, {
281
- vars: KeysVars,
282
- });
283
- if (!this.has("functions")) {
284
- this.set("functions", []);
285
- }
286
- const functions = this.get("functions") ?? [];
287
- for (let i = 0; i < functions.length; i++) {
288
- if (functions[i]["$id"] == props["$id"]) {
289
- functions[i] = {
290
- ...functions[i],
291
- ...props,
292
- };
293
- this.set("functions", functions);
294
- return;
295
- }
296
- }
297
- functions.push(props);
298
- this.set("functions", functions);
299
- }
300
- getCollections() {
301
- if (!this.has("collections")) {
302
- return [];
303
- }
304
- return this.get("collections") ?? [];
305
- }
306
- getCollection($id) {
307
- if (!this.has("collections")) {
308
- return {};
309
- }
310
- const collections = this.get("collections") ?? [];
311
- for (let i = 0; i < collections.length; i++) {
312
- if (collections[i]["$id"] == $id) {
313
- return collections[i];
314
- }
315
- }
316
- return {};
317
- }
318
- addCollection(props) {
319
- props = whitelistKeys(props, KeysCollection, {
320
- attributes: KeysAttributes,
321
- indexes: KeyIndexes,
322
- });
323
- if (!this.has("collections")) {
324
- this.set("collections", []);
325
- }
326
- const collections = this.get("collections") ?? [];
327
- for (let i = 0; i < collections.length; i++) {
328
- if (collections[i]["$id"] == props["$id"] &&
329
- collections[i]["databaseId"] == props["databaseId"]) {
330
- collections[i] = props;
331
- this.set("collections", collections);
332
- return;
333
- }
334
- }
335
- collections.push(props);
336
- this.set("collections", collections);
337
- }
338
- getTables() {
339
- if (!this.has("tables")) {
340
- return [];
341
- }
342
- return this.get("tables") ?? [];
343
- }
344
- getTable($id) {
345
- if (!this.has("tables")) {
346
- return {};
347
- }
348
- const tables = this.get("tables") ?? [];
349
- for (let i = 0; i < tables.length; i++) {
350
- if (tables[i]["$id"] == $id) {
351
- return tables[i];
352
- }
353
- }
354
- return {};
355
- }
356
- addTable(props) {
357
- props = whitelistKeys(props, KeysTable, {
358
- columns: KeysColumns,
359
- indexes: KeyIndexesColumns,
360
- });
361
- if (!this.has("tables")) {
362
- this.set("tables", []);
363
- }
364
- const tables = this.get("tables") ?? [];
365
- for (let i = 0; i < tables.length; i++) {
366
- if (tables[i]["$id"] == props["$id"] &&
367
- tables[i]["databaseId"] == props["databaseId"]) {
368
- tables[i] = props;
369
- this.set("tables", tables);
370
- return;
371
- }
372
- }
373
- tables.push(props);
374
- this.set("tables", tables);
375
- }
376
- getBuckets() {
377
- if (!this.has("buckets")) {
378
- return [];
379
- }
380
- return this.get("buckets") ?? [];
381
- }
382
- getBucket($id) {
383
- if (!this.has("buckets")) {
384
- return {};
385
- }
386
- const buckets = this.get("buckets") ?? [];
387
- for (let i = 0; i < buckets.length; i++) {
388
- if (buckets[i]["$id"] == $id) {
389
- return buckets[i];
390
- }
391
- }
392
- return {};
393
- }
394
- addBucket(props) {
395
- props = whitelistKeys(props, KeysStorage);
396
- if (!this.has("buckets")) {
397
- this.set("buckets", []);
398
- }
399
- const buckets = this.get("buckets") ?? [];
400
- for (let i = 0; i < buckets.length; i++) {
401
- if (buckets[i]["$id"] == props["$id"]) {
402
- buckets[i] = props;
403
- this.set("buckets", buckets);
404
- return;
405
- }
406
- }
407
- buckets.push(props);
408
- this.set("buckets", buckets);
409
- }
410
- getMessagingTopics() {
411
- if (!this.has("topics")) {
412
- return [];
413
- }
414
- return this.get("topics") ?? [];
415
- }
416
- getMessagingTopic($id) {
417
- if (!this.has("topics")) {
418
- return {};
419
- }
420
- const topics = this.get("topics") ?? [];
421
- for (let i = 0; i < topics.length; i++) {
422
- if (topics[i]["$id"] == $id) {
423
- return topics[i];
424
- }
425
- }
426
- return {};
427
- }
428
- addMessagingTopic(props) {
429
- props = whitelistKeys(props, KeysTopics);
430
- if (!this.has("topics")) {
431
- this.set("topics", []);
432
- }
433
- const topics = this.get("topics") ?? [];
434
- for (let i = 0; i < topics.length; i++) {
435
- if (topics[i]["$id"] === props["$id"]) {
436
- topics[i] = props;
437
- this.set("topics", topics);
438
- return;
439
- }
440
- }
441
- topics.push(props);
442
- this.set("topics", topics);
443
- }
444
- getTablesDBs() {
445
- return this._getDBEntities("tablesDB");
446
- }
447
- getTablesDB($id) {
448
- return this._getDBEntity("tablesDB", $id);
449
- }
450
- addTablesDB(props) {
451
- this._addDBEntity("tablesDB", props, KeysDatabase);
452
- }
453
- getDatabases() {
454
- return this._getDBEntities("databases");
455
- }
456
- getDatabase($id) {
457
- return this._getDBEntity("databases", $id);
458
- }
459
- addDatabase(props) {
460
- this._addDBEntity("databases", props, KeysDatabase);
461
- }
462
- getTeams() {
463
- if (!this.has("teams")) {
464
- return [];
465
- }
466
- return this.get("teams") ?? [];
467
- }
468
- getTeam($id) {
469
- if (!this.has("teams")) {
470
- return {};
471
- }
472
- const teams = this.get("teams") ?? [];
473
- for (let i = 0; i < teams.length; i++) {
474
- if (teams[i]["$id"] == $id) {
475
- return teams[i];
476
- }
477
- }
478
- return {};
479
- }
480
- addTeam(props) {
481
- props = whitelistKeys(props, KeysTeams);
482
- if (!this.has("teams")) {
483
- this.set("teams", []);
484
- }
485
- const teams = this.get("teams") ?? [];
486
- for (let i = 0; i < teams.length; i++) {
487
- if (teams[i]["$id"] == props["$id"]) {
488
- teams[i] = props;
489
- this.set("teams", teams);
490
- return;
491
- }
492
- }
493
- teams.push(props);
494
- this.set("teams", teams);
495
- }
496
- getProject() {
497
- if (!this.has("projectId")) {
498
- return {};
499
- }
500
- return {
501
- projectId: this.get("projectId"),
502
- projectName: this.get("projectName"),
503
- projectSettings: this.get("settings"),
504
- };
505
- }
506
- setProject(projectId, projectName = "", project) {
507
- this.set("projectId", projectId);
508
- if (projectName !== "") {
509
- this.set("projectName", projectName);
510
- }
511
- if (project === undefined) {
512
- return;
513
- }
514
- this.set("settings", createSettingsObject(project));
515
- }
516
- }
517
- class Global extends Config {
518
- static CONFIG_FILE_PATH = `.${EXECUTABLE_NAME}/prefs.json`;
519
- static PREFERENCE_CURRENT = "current";
520
- static PREFERENCE_ENDPOINT = "endpoint";
521
- static PREFERENCE_EMAIL = "email";
522
- static PREFERENCE_SELF_SIGNED = "selfSigned";
523
- static PREFERENCE_COOKIE = "cookie";
524
- static PREFERENCE_PROJECT = "project";
525
- static PREFERENCE_KEY = "key";
526
- static PREFERENCE_LOCALE = "locale";
527
- static PREFERENCE_MODE = "mode";
528
- static IGNORE_ATTRIBUTES = [
529
- Global.PREFERENCE_CURRENT,
530
- Global.PREFERENCE_SELF_SIGNED,
531
- Global.PREFERENCE_ENDPOINT,
532
- Global.PREFERENCE_COOKIE,
533
- Global.PREFERENCE_PROJECT,
534
- Global.PREFERENCE_KEY,
535
- Global.PREFERENCE_LOCALE,
536
- Global.PREFERENCE_MODE,
537
- ];
538
- static MODE_ADMIN = "admin";
539
- static MODE_DEFAULT = "default";
540
- static PROJECT_CONSOLE = "console";
541
- constructor(path = Global.CONFIG_FILE_PATH) {
542
- const homeDir = os.homedir();
543
- super(`${homeDir}/${path}`);
544
- }
545
- getCurrentSession() {
546
- if (!this.has(Global.PREFERENCE_CURRENT)) {
547
- return "";
548
- }
549
- return this.get(Global.PREFERENCE_CURRENT);
550
- }
551
- setCurrentSession(session) {
552
- if (session !== undefined) {
553
- this.set(Global.PREFERENCE_CURRENT, session);
554
- }
555
- }
556
- getSessionIds() {
557
- return Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key));
558
- }
559
- getSessions() {
560
- const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key));
561
- const current = this.getCurrentSession();
562
- const sessionMap = new Map();
563
- sessions.forEach((sessionId) => {
564
- const sessionData = this.data[sessionId];
565
- const email = sessionData[Global.PREFERENCE_EMAIL];
566
- const endpoint = sessionData[Global.PREFERENCE_ENDPOINT];
567
- const key = `${email}|${endpoint}`;
568
- if (sessionId === current || !sessionMap.has(key)) {
569
- sessionMap.set(key, {
570
- id: sessionId,
571
- endpoint: sessionData[Global.PREFERENCE_ENDPOINT],
572
- email: sessionData[Global.PREFERENCE_EMAIL],
573
- });
574
- }
575
- });
576
- return Array.from(sessionMap.values());
577
- }
578
- addSession(session, data) {
579
- this.set(session, data);
580
- }
581
- removeSession(session) {
582
- this.delete(session);
583
- }
584
- getEmail() {
585
- if (!this.hasFrom(Global.PREFERENCE_EMAIL)) {
586
- return "";
587
- }
588
- return this.getFrom(Global.PREFERENCE_EMAIL);
589
- }
590
- setEmail(email) {
591
- this.setTo(Global.PREFERENCE_EMAIL, email);
592
- }
593
- getEndpoint() {
594
- if (!this.hasFrom(Global.PREFERENCE_ENDPOINT)) {
595
- return "";
596
- }
597
- return this.getFrom(Global.PREFERENCE_ENDPOINT);
598
- }
599
- setEndpoint(endpoint) {
600
- this.setTo(Global.PREFERENCE_ENDPOINT, endpoint);
601
- }
602
- getSelfSigned() {
603
- if (!this.hasFrom(Global.PREFERENCE_SELF_SIGNED)) {
604
- return false;
605
- }
606
- return this.getFrom(Global.PREFERENCE_SELF_SIGNED);
607
- }
608
- setSelfSigned(selfSigned) {
609
- this.setTo(Global.PREFERENCE_SELF_SIGNED, selfSigned);
610
- }
611
- getCookie() {
612
- if (!this.hasFrom(Global.PREFERENCE_COOKIE)) {
613
- return "";
614
- }
615
- return this.getFrom(Global.PREFERENCE_COOKIE);
616
- }
617
- setCookie(cookie) {
618
- this.setTo(Global.PREFERENCE_COOKIE, cookie);
619
- }
620
- getProject() {
621
- if (!this.hasFrom(Global.PREFERENCE_PROJECT)) {
622
- return "";
623
- }
624
- return this.getFrom(Global.PREFERENCE_PROJECT);
625
- }
626
- setProject(project) {
627
- this.setTo(Global.PREFERENCE_PROJECT, project);
628
- }
629
- getKey() {
630
- if (!this.hasFrom(Global.PREFERENCE_KEY)) {
631
- return "";
632
- }
633
- return this.getFrom(Global.PREFERENCE_KEY);
634
- }
635
- setKey(key) {
636
- this.setTo(Global.PREFERENCE_KEY, key);
637
- }
638
- hasFrom(key) {
639
- const current = this.getCurrentSession();
640
- if (current) {
641
- const config = this.get(current) ?? {};
642
- return config[key] !== undefined;
643
- }
644
- return false;
645
- }
646
- getFrom(key) {
647
- const current = this.getCurrentSession();
648
- if (current) {
649
- const config = this.get(current) ?? {};
650
- return config[key];
651
- }
652
- }
653
- setTo(key, value) {
654
- const current = this.getCurrentSession();
655
- if (current) {
656
- const config = this.get(current);
657
- config[key] = value;
658
- this.write();
659
- }
660
- }
661
- }
662
- export const localConfig = new Local();
663
- export const globalConfig = new Global();
664
- export { KeysAttributes, KeysSite, KeysFunction, KeysTopics, KeysStorage, KeysTeams, KeysCollection, KeysTable, whitelistKeys, };
665
- //# sourceMappingURL=config.js.map