appwrite-utils-cli 0.0.274 → 0.0.275

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 (77) hide show
  1. package/README.md +4 -39
  2. package/dist/init.d.ts +2 -0
  3. package/dist/init.js +57 -0
  4. package/dist/main.js +62 -100
  5. package/dist/migrations/afterImportActions.d.ts +1 -4
  6. package/dist/migrations/afterImportActions.js +1 -0
  7. package/dist/migrations/appwriteToX.d.ts +46 -46
  8. package/dist/migrations/appwriteToX.js +6 -2
  9. package/dist/migrations/attributes.d.ts +1 -1
  10. package/dist/migrations/attributes.js +97 -71
  11. package/dist/migrations/backup.d.ts +240 -240
  12. package/dist/migrations/backup.js +1 -1
  13. package/dist/migrations/collections.d.ts +1 -1
  14. package/dist/migrations/collections.js +4 -4
  15. package/dist/migrations/converters.d.ts +9 -127
  16. package/dist/migrations/converters.js +1 -504
  17. package/dist/migrations/dataLoader.d.ts +470 -453
  18. package/dist/migrations/dataLoader.js +19 -1
  19. package/dist/migrations/dbHelpers.d.ts +1 -1
  20. package/dist/migrations/dbHelpers.js +3 -0
  21. package/dist/migrations/importController.d.ts +1 -1
  22. package/dist/migrations/importController.js +4 -7
  23. package/dist/migrations/importDataActions.d.ts +4 -6
  24. package/dist/migrations/importDataActions.js +6 -4
  25. package/dist/migrations/indexes.d.ts +1 -1
  26. package/dist/migrations/indexes.js +1 -1
  27. package/dist/migrations/migrationHelper.d.ts +29 -29
  28. package/dist/migrations/migrationHelper.js +1 -1
  29. package/dist/migrations/openapi.d.ts +1 -1
  30. package/dist/migrations/openapi.js +4 -1
  31. package/dist/migrations/queue.d.ts +1 -1
  32. package/dist/migrations/relationships.d.ts +5 -5
  33. package/dist/migrations/relationships.js +3 -0
  34. package/dist/migrations/schemaStrings.d.ts +2 -2
  35. package/dist/migrations/schemaStrings.js +93 -8
  36. package/dist/migrations/setupDatabase.d.ts +1 -1
  37. package/dist/migrations/setupDatabase.js +1 -1
  38. package/dist/migrations/storage.d.ts +1 -1
  39. package/dist/migrations/users.d.ts +1 -1
  40. package/dist/schemas/authUser.d.ts +12 -10
  41. package/dist/types.d.ts +0 -5
  42. package/dist/types.js +0 -2
  43. package/dist/utils/helperFunctions.d.ts +2 -3
  44. package/dist/utils/loadConfigs.d.ts +13 -0
  45. package/dist/utils/loadConfigs.js +47 -0
  46. package/dist/utils/setupFiles.d.ts +1 -0
  47. package/dist/utils/setupFiles.js +98 -223
  48. package/dist/utilsController.d.ts +1 -3
  49. package/dist/utilsController.js +14 -18
  50. package/package.json +9 -2
  51. package/src/init.ts +64 -0
  52. package/src/main.ts +73 -98
  53. package/src/migrations/afterImportActions.ts +1 -5
  54. package/src/migrations/appwriteToX.ts +6 -2
  55. package/src/migrations/attributes.ts +198 -150
  56. package/src/migrations/backup.ts +1 -1
  57. package/src/migrations/collections.ts +5 -11
  58. package/src/migrations/converters.ts +1 -540
  59. package/src/migrations/dataLoader.ts +19 -2
  60. package/src/migrations/dbHelpers.ts +4 -1
  61. package/src/migrations/importController.ts +5 -15
  62. package/src/migrations/importDataActions.ts +10 -14
  63. package/src/migrations/indexes.ts +1 -1
  64. package/src/migrations/migrationHelper.ts +1 -1
  65. package/src/migrations/openapi.ts +4 -1
  66. package/src/migrations/queue.ts +1 -1
  67. package/src/migrations/relationships.ts +4 -1
  68. package/src/migrations/schemaStrings.ts +106 -9
  69. package/src/migrations/setupDatabase.ts +1 -1
  70. package/src/migrations/storage.ts +1 -1
  71. package/src/migrations/users.ts +1 -1
  72. package/src/types.ts +0 -5
  73. package/src/utils/helperFunctions.ts +2 -3
  74. package/src/utils/loadConfigs.ts +55 -0
  75. package/src/utils/setupFiles.ts +114 -225
  76. package/src/utilsController.ts +27 -35
  77. package/src/migrations/schema.ts +0 -748
@@ -1,748 +0,0 @@
1
- import { ID, IndexType, Permission } from "node-appwrite";
2
- import { z } from "zod";
3
-
4
- const stringAttributeSchema = z.object({
5
- key: z.string().describe("The key of the attribute"),
6
- type: z
7
- .literal("string")
8
- .describe("The type of the attribute")
9
- .default("string"),
10
- error: z
11
- .string()
12
- .describe("The error message if the attribute is invalid")
13
- .default("Invalid String Attribute Schema"),
14
- required: z
15
- .boolean()
16
- .describe("Whether the attribute is required or not")
17
- .default(false),
18
- array: z
19
- .boolean()
20
- .optional()
21
- .default(false)
22
- .describe("Whether the attribute is an array or not"),
23
- size: z
24
- .number()
25
- .describe("The max length or size of the attribute")
26
- .optional()
27
- .default(50),
28
- xdefault: z.string().nullish().describe("The default value of the attribute"),
29
- encrypted: z
30
- .boolean()
31
- .optional()
32
- .describe("Whether the attribute is encrypted or not"),
33
- format: z.string().nullish().describe("The format of the attribute"),
34
- description: z
35
- .string()
36
- .or(z.record(z.string()))
37
- .nullish()
38
- .describe(
39
- "The description of the attribute, also used for OpenApi Generation"
40
- ),
41
- });
42
-
43
- type StringAttribute = z.infer<typeof stringAttributeSchema>;
44
-
45
- const integerAttributeSchema = z.object({
46
- key: z.string().describe("The key of the attribute"),
47
- type: z
48
- .literal("integer")
49
- .describe("The type of the attribute")
50
- .default("integer"),
51
- error: z
52
- .string()
53
- .describe("The error message if the attribute is invalid")
54
- .default("Invalid Integer Attribute Schema"),
55
- required: z
56
- .boolean()
57
- .describe("Whether the attribute is required or not")
58
- .default(false),
59
- array: z
60
- .boolean()
61
- .optional()
62
- .default(false)
63
- .describe("Whether the attribute is an array or not"),
64
- min: z
65
- .number()
66
- .int()
67
- .optional()
68
- .describe("The minimum value of the attribute"),
69
- max: z
70
- .number()
71
- .int()
72
- .optional()
73
- .describe("The maximum value of the attribute"),
74
- xdefault: z
75
- .number()
76
- .int()
77
- .nullish()
78
- .describe("The default value of the attribute"),
79
- description: z
80
- .string()
81
- .or(z.record(z.string()))
82
- .nullish()
83
- .describe(
84
- "The description of the attribute, also used for OpenApi Generation"
85
- ),
86
- });
87
-
88
- type IntegerAttribute = z.infer<typeof integerAttributeSchema>;
89
-
90
- const floatAttributeSchema = z.object({
91
- key: z.string().describe("The key of the attribute"),
92
- type: z
93
- .literal("float")
94
- .describe("The type of the attribute")
95
- .default("float"),
96
- error: z
97
- .string()
98
- .describe("The error message if the attribute is invalid")
99
- .default("Invalid Float Attribute Schema"),
100
- required: z
101
- .boolean()
102
- .describe("Whether the attribute is required or not")
103
- .default(false),
104
- array: z
105
- .boolean()
106
- .optional()
107
- .default(false)
108
- .describe("Whether the attribute is an array or not"),
109
- min: z.number().optional().describe("The minimum value of the attribute"),
110
- max: z.number().optional().describe("The maximum value of the attribute"),
111
- xdefault: z.number().nullish().describe("The default value of the attribute"),
112
- description: z
113
- .string()
114
- .or(z.record(z.string()))
115
- .nullish()
116
- .describe(
117
- "The description of the attribute, also used for OpenApi Generation"
118
- ),
119
- });
120
-
121
- type FloatAttribute = z.infer<typeof floatAttributeSchema>;
122
-
123
- const booleanAttributeSchema = z.object({
124
- key: z.string().describe("The key of the attribute"),
125
- type: z
126
- .literal("boolean")
127
- .describe("The type of the attribute")
128
- .default("boolean"),
129
- error: z
130
- .string()
131
- .describe("The error message if the attribute is invalid")
132
- .default("Invalid Boolean Attribute Schema"),
133
- required: z
134
- .boolean()
135
- .describe("Whether the attribute is required or not")
136
- .default(false),
137
- array: z
138
- .boolean()
139
- .optional()
140
- .default(false)
141
- .describe("Whether the attribute is an array or not"),
142
- xdefault: z
143
- .boolean()
144
- .nullish()
145
- .describe("The default value of the attribute"),
146
- description: z
147
- .string()
148
- .or(z.record(z.string()))
149
- .nullish()
150
- .describe(
151
- "The description of the attribute, also used for OpenApi Generation"
152
- ),
153
- });
154
-
155
- type BooleanAttribute = z.infer<typeof booleanAttributeSchema>;
156
-
157
- const datetimeAttributeSchema = z.object({
158
- key: z.string().describe("The key of the attribute"),
159
- type: z
160
- .literal("datetime")
161
- .describe("The type of the attribute")
162
- .default("datetime"),
163
- error: z
164
- .string()
165
- .describe("The error message if the attribute is invalid")
166
- .default("Invalid Datetime Attribute Schema"),
167
- required: z
168
- .boolean()
169
- .describe("Whether the attribute is required or not")
170
- .default(false),
171
- array: z
172
- .boolean()
173
- .optional()
174
- .default(false)
175
- .describe("Whether the attribute is an array or not"),
176
- xdefault: z.string().nullish().describe("The default value of the attribute"),
177
- description: z
178
- .string()
179
- .or(z.record(z.string()))
180
- .nullish()
181
- .describe(
182
- "The description of the attribute, also used for OpenApi Generation"
183
- ),
184
- });
185
-
186
- type DatetimeAttribute = z.infer<typeof datetimeAttributeSchema>;
187
-
188
- const emailAttributeSchema = z.object({
189
- key: z.string().describe("The key of the attribute"),
190
- type: z
191
- .literal("email")
192
- .describe("The type of the attribute")
193
- .default("email"),
194
- error: z
195
- .string()
196
- .describe("The error message if the attribute is invalid")
197
- .default("Invalid Email Attribute Schema"),
198
- required: z
199
- .boolean()
200
- .describe("Whether the attribute is required or not")
201
- .default(false),
202
- array: z
203
- .boolean()
204
- .optional()
205
- .default(false)
206
- .describe("Whether the attribute is an array or not"),
207
- xdefault: z.string().nullish().describe("The default value of the attribute"),
208
- description: z
209
- .string()
210
- .or(z.record(z.string()))
211
- .nullish()
212
- .describe(
213
- "The description of the attribute, also used for OpenApi Generation"
214
- ),
215
- });
216
-
217
- type EmailAttribute = z.infer<typeof emailAttributeSchema>;
218
-
219
- const ipAttributeSchema = z.object({
220
- key: z.string().describe("The key of the attribute"),
221
- type: z.literal("ip").describe("The type of the attribute"),
222
- error: z
223
- .string()
224
- .describe("The error message if the attribute is invalid")
225
- .default("Invalid IP Attribute Schema"),
226
- required: z
227
- .boolean()
228
- .describe("Whether the attribute is required or not")
229
- .default(false),
230
- array: z
231
- .boolean()
232
- .optional()
233
- .default(false)
234
- .describe("Whether the attribute is an array or not"),
235
- xdefault: z.string().nullish().describe("The default value of the attribute"),
236
- description: z
237
- .string()
238
- .or(z.record(z.string()))
239
- .nullish()
240
- .describe(
241
- "The description of the attribute, also used for OpenApi Generation"
242
- ),
243
- });
244
-
245
- type IpAttribute = z.infer<typeof ipAttributeSchema>;
246
-
247
- const urlAttributeSchema = z.object({
248
- key: z.string().describe("The key of the attribute"),
249
- type: z.literal("url").describe("The type of the attribute").default("url"),
250
- error: z
251
- .string()
252
- .describe("The error message if the attribute is invalid")
253
- .default("Invalid URL Attribute Schema"),
254
- required: z
255
- .boolean()
256
- .describe("Whether the attribute is required or not")
257
- .default(false),
258
- array: z
259
- .boolean()
260
- .optional()
261
- .default(false)
262
- .describe("Whether the attribute is an array or not"),
263
- xdefault: z.string().nullish().describe("The default value of the attribute"),
264
- description: z
265
- .string()
266
- .or(z.record(z.string()))
267
- .nullish()
268
- .describe(
269
- "The description of the attribute, also used for OpenApi Generation"
270
- ),
271
- });
272
-
273
- type UrlAttribute = z.infer<typeof urlAttributeSchema>;
274
-
275
- const enumAttributeSchema = z.object({
276
- key: z.string().describe("The key of the attribute"),
277
- type: z.literal("enum").describe("The type of the attribute").default("enum"),
278
- error: z
279
- .string()
280
- .describe("The error message if the attribute is invalid")
281
- .default("Invalid Enum Attribute Schema"),
282
- required: z
283
- .boolean()
284
- .describe("Whether the attribute is required or not")
285
- .default(false),
286
- array: z
287
- .boolean()
288
- .optional()
289
- .default(false)
290
- .describe("Whether the attribute is an array or not"),
291
- elements: z
292
- .array(z.string())
293
- .describe("The elements of the enum attribute")
294
- .default([]),
295
- xdefault: z.string().nullish().describe("The default value of the attribute"),
296
- description: z
297
- .string()
298
- .or(z.record(z.string()))
299
- .nullish()
300
- .describe(
301
- "The description of the attribute, also used for OpenApi Generation"
302
- ),
303
- });
304
-
305
- type EnumAttribute = z.infer<typeof enumAttributeSchema>;
306
-
307
- const relationshipAttributeSchema = z.object({
308
- key: z.string().describe("The key of the attribute"),
309
- type: z
310
- .literal("relationship")
311
- .describe("The type of the attribute")
312
- .default("relationship"),
313
- error: z
314
- .string()
315
- .describe("The error message if the attribute is invalid")
316
- .default("Invalid Relationship Attribute Schema"),
317
- required: z
318
- .boolean()
319
- .describe("Whether the attribute is required or not")
320
- .default(false),
321
- array: z
322
- .boolean()
323
- .optional()
324
- .describe("Whether the attribute is an array or not"),
325
- relatedCollection: z
326
- .string()
327
- .describe("The collection ID of the related collection"),
328
- relationType: z
329
- .enum(["oneToMany", "manyToOne", "oneToOne", "manyToMany"])
330
- .describe("The relation type of the relationship attribute"),
331
- twoWay: z.boolean().describe("Whether the relationship is two way or not"),
332
- twoWayKey: z
333
- .string()
334
- .describe("The ID of the foreign key in the other collection"),
335
- onDelete: z
336
- .enum(["setNull", "cascade", "restrict"])
337
- .describe("The action to take when the related document is deleted")
338
- .default("setNull"),
339
- side: z.enum(["parent", "child"]).describe("The side of the relationship"),
340
- importMapping: z
341
- .object({
342
- originalIdField: z
343
- .string()
344
- .describe(
345
- "The field in the import data representing the original ID to match"
346
- ),
347
- targetField: z
348
- .string()
349
- .optional()
350
- .describe(
351
- "The field in the target collection that matches the original ID. Optional, defaults to the same as originalIdField if not provided"
352
- ),
353
- })
354
- .optional()
355
- .describe(
356
- "Configuration for mapping and resolving relationships during data import"
357
- ),
358
- description: z
359
- .string()
360
- .or(z.record(z.string()))
361
- .nullish()
362
- .describe(
363
- "The description of the attribute, also used for OpenApi Generation"
364
- ),
365
- });
366
-
367
- export type RelationshipAttribute = z.infer<typeof relationshipAttributeSchema>;
368
-
369
- export const createRelationshipAttributes = (
370
- relatedCollection: string,
371
- relationType: "oneToMany" | "manyToOne" | "oneToOne" | "manyToMany",
372
- twoWay: boolean,
373
- twoWayKey: string,
374
- onDelete: "setNull" | "cascade" | "restrict",
375
- side: "parent" | "child"
376
- ) => {
377
- return relationshipAttributeSchema.parse({
378
- relatedCollection,
379
- relationType,
380
- twoWay,
381
- twoWayKey,
382
- onDelete,
383
- side,
384
- });
385
- };
386
-
387
- export const attributeSchema = z.discriminatedUnion("type", [
388
- stringAttributeSchema,
389
- integerAttributeSchema,
390
- floatAttributeSchema,
391
- booleanAttributeSchema,
392
- datetimeAttributeSchema,
393
- emailAttributeSchema,
394
- ipAttributeSchema,
395
- urlAttributeSchema,
396
- enumAttributeSchema,
397
- relationshipAttributeSchema,
398
- ]);
399
-
400
- export const parseAttribute = (
401
- attribute:
402
- | StringAttribute
403
- | IntegerAttribute
404
- | FloatAttribute
405
- | BooleanAttribute
406
- | DatetimeAttribute
407
- | EmailAttribute
408
- | IpAttribute
409
- | UrlAttribute
410
- | EnumAttribute
411
- | RelationshipAttribute
412
- ) => {
413
- if (
414
- attribute.type === "string" &&
415
- attribute.format &&
416
- attribute.format.length > 0
417
- ) {
418
- console.log(
419
- `Parsing attribute ${attribute.key} with format ${
420
- attribute.format
421
- }, setting type to ${attribute.format.toLowerCase()}`
422
- );
423
- // @ts-expect-error
424
- attribute.type = attribute.format.toLowerCase();
425
- delete attribute.format;
426
- }
427
- if (attribute.type === "string") {
428
- return stringAttributeSchema.parse(attribute);
429
- } else if (attribute.type === "integer") {
430
- return integerAttributeSchema.parse(attribute);
431
- } else if (attribute.type === "float") {
432
- return floatAttributeSchema.parse(attribute);
433
- } else if (attribute.type === "boolean") {
434
- return booleanAttributeSchema.parse(attribute);
435
- } else if (attribute.type === "datetime") {
436
- return datetimeAttributeSchema.parse(attribute);
437
- } else if (attribute.type === "email") {
438
- return emailAttributeSchema.parse(attribute);
439
- } else if (attribute.type === "ip") {
440
- return ipAttributeSchema.parse(attribute);
441
- } else if (attribute.type === "url") {
442
- return urlAttributeSchema.parse(attribute);
443
- } else if (attribute.type === "enum") {
444
- return enumAttributeSchema.parse(attribute);
445
- } else if (attribute.type === "relationship") {
446
- return relationshipAttributeSchema.parse(attribute);
447
- } else {
448
- throw new Error("Invalid attribute type");
449
- }
450
- };
451
-
452
- export type Attribute = z.infer<typeof attributeSchema>;
453
-
454
- export const indexSchema = z.object({
455
- key: z.string(),
456
- type: z
457
- .enum([IndexType.Key, IndexType.Unique, IndexType.Fulltext])
458
- .optional()
459
- .default(IndexType.Key),
460
- status: z.string().optional(),
461
- error: z.string().optional(),
462
- attributes: z.array(z.string()),
463
- orders: z.array(z.string()).optional(),
464
- });
465
-
466
- export const indexesSchema = z.array(indexSchema);
467
-
468
- export type Index = z.infer<typeof indexSchema>;
469
-
470
- export const AttributeMappingsSchema = z.array(
471
- z.object({
472
- oldKey: z
473
- .string()
474
- .optional()
475
- .describe("The key of the attribute in the old document"),
476
- oldKeys: z
477
- .array(z.string())
478
- .optional()
479
- .describe(
480
- "The keys of the attribute in the old document, if there are more than one"
481
- ),
482
- targetKey: z
483
- .string()
484
- .describe("The key of the attribute in the new document"),
485
- fileData: z
486
- .object({
487
- name: z
488
- .string()
489
- .describe("The name of the file, can use template strings"),
490
- path: z
491
- .string()
492
- .describe("The path of the file, relative to the appwrite folder"),
493
- })
494
- .optional()
495
- .describe(
496
- "The file data to use for the import, if defined it will upload and replace with ID"
497
- ),
498
- converters: z
499
- .array(z.string())
500
- .describe("The converters to use for the import")
501
- .default([]),
502
- validationActions: z
503
- .array(
504
- z.object({
505
- action: z.string(),
506
- params: z.array(z.string().startsWith("{").endsWith("}")),
507
- })
508
- )
509
- .describe(
510
- "The after import actions and parameter placeholders (they'll be replaced with the actual data) to use for the import"
511
- )
512
- .default([]),
513
- postImportActions: z
514
- .array(
515
- z.object({
516
- action: z.string(),
517
- params: z.array(z.string().or(z.record(z.string(), z.any()))),
518
- })
519
- )
520
- .describe(
521
- "The after import actions and parameter placeholders (they'll be replaced with the actual data) to use for the import"
522
- )
523
- .default([]),
524
- })
525
- );
526
-
527
- export const idMappingSchema = z.array(
528
- z.object({
529
- sourceField: z
530
- .string()
531
- .describe(
532
- "The key of the data in the import data to match in the current data"
533
- ),
534
- fieldToSet: z
535
- .string()
536
- .optional()
537
- .describe(
538
- "The field to set in the target collection, if different from sourceField"
539
- ),
540
- targetField: z
541
- .string()
542
- .describe(
543
- "The field in the target collection to match with sourceField that will then be updated"
544
- ),
545
- targetCollection: z.string().describe("The collection to search"),
546
- })
547
- );
548
-
549
- export const importDefSchema = z
550
- .object({
551
- type: z
552
- .enum(["create", "update"])
553
- .default("create")
554
- .optional()
555
- .describe(
556
- "The type of import action, if update you should set an object for the originalIdField and targetField"
557
- ),
558
- filePath: z.string().describe("The file path of the data to import"),
559
- basePath: z
560
- .string()
561
- .optional()
562
- .describe(
563
- "The base path of the import e.g. if you have JSON, and the array is in the RECORDS object, then this would be RECORDS, if nothing then leave it gone"
564
- ),
565
- primaryKeyField: z
566
- .string()
567
- .default("id")
568
- .describe(
569
- "The field in the import data representing the primary key for this import data (if any)"
570
- ),
571
- idMappings: idMappingSchema
572
- .optional()
573
- .describe("The id mappings for the attribute to map ID's to"),
574
- updateMapping: z
575
- .object({
576
- originalIdField: z
577
- .string()
578
- .describe(
579
- "The field in the import data representing the original ID to match"
580
- ),
581
- targetField: z
582
- .string()
583
- .describe(
584
- "The field in the target collection that matches the original ID. Optional, defaults to the same as originalIdField if not provided"
585
- ),
586
- })
587
- .optional()
588
- .describe(
589
- "Configuration for mapping and resolving the update during data import"
590
- ),
591
- attributeMappings: AttributeMappingsSchema.describe(
592
- "The attribute mappings to use for the import"
593
- ),
594
- })
595
- .describe("An individual import definition for the database");
596
-
597
- export const importDefSchemas = z
598
- .array(importDefSchema)
599
- .default([])
600
- .describe("The import definitions for the database");
601
-
602
- export const permissionSchema = z
603
- .object({
604
- permission: z.string(),
605
- target: z.string(),
606
- })
607
- .or(
608
- z.string().transform((val) => {
609
- const trimmedVal = val.trim();
610
- // Adjusted regex to match double quotes
611
- const match = trimmedVal.match(/^(\w+)\("([^"]+)"\)$/);
612
- if (!match) {
613
- throw new Error(`Invalid permission format: ${trimmedVal}`);
614
- }
615
- return {
616
- permission: match[1],
617
- target: match[2],
618
- };
619
- })
620
- );
621
-
622
- export const permissionsSchema = z.array(permissionSchema).optional();
623
-
624
- export const attributesSchema = z.array(attributeSchema).default([]);
625
-
626
- export const collectionSchema = z.object({
627
- name: z.string().describe("The name of the collection"),
628
- $id: z
629
- .string()
630
- .optional()
631
- .default(ID.unique())
632
- .describe("The ID of the collection, auto generated if not provided"),
633
- enabled: z
634
- .boolean()
635
- .default(true)
636
- .describe("Whether the collection is enabled or not"),
637
- documentSecurity: z
638
- .boolean()
639
- .default(false)
640
- .describe("Whether document security is enabled or not"),
641
- description: z
642
- .string()
643
- .optional()
644
- .describe(
645
- "The description of the collection, if any, used to generate OpenAPI documentation"
646
- ),
647
- $createdAt: z.string(),
648
- $updatedAt: z.string(),
649
- $permissions: z
650
- .array(
651
- z.object({
652
- permission: z.string(),
653
- target: z.string(),
654
- })
655
- )
656
- .default([])
657
- .describe("The permissions of the collection"),
658
- attributes: z
659
- .array(attributeSchema)
660
- .default([])
661
- .describe("The attributes of the collection"),
662
- indexes: z
663
- .array(indexSchema)
664
- .default([])
665
- .describe("The indexes of the collection"),
666
- importDefs: importDefSchemas,
667
- databaseId: z
668
- .string()
669
- .optional()
670
- .describe("The ID of the database the collection belongs to"),
671
- });
672
-
673
- export const CollectionCreateSchema = collectionSchema.omit({
674
- $createdAt: true,
675
- $updatedAt: true,
676
- });
677
-
678
- export type Collection = z.infer<typeof collectionSchema>;
679
- export type CollectionCreate = z.infer<typeof CollectionCreateSchema>;
680
-
681
- export const AppwriteConfigSchema = z.object({
682
- appwriteEndpoint: z.string().default("https://cloud.appwrite.io/v1"),
683
- appwriteProject: z.string(),
684
- appwriteKey: z.string(),
685
- appwriteClient: z.any().or(z.null()).default(null),
686
- enableDevDatabase: z
687
- .boolean()
688
- .default(true)
689
- .describe("Enable development database alongside production database"),
690
- enableBackups: z.boolean().default(true).describe("Enable backups"),
691
- backupInterval: z
692
- .number()
693
- .default(3600)
694
- .describe("Backup interval in seconds"),
695
- backupRetention: z.number().default(30).describe("Backup retention in days"),
696
- enableBackupCleanup: z
697
- .boolean()
698
- .default(true)
699
- .describe("Enable backup cleanup"),
700
- enableMockData: z.boolean().default(false).describe("Enable mock data"),
701
- enableWipeOtherDatabases: z
702
- .boolean()
703
- .default(true)
704
- .describe("Enable wiping other databases"),
705
- documentBucketId: z
706
- .string()
707
- .default("documents")
708
- .describe("Documents bucket id for imported documents"),
709
- usersCollectionName: z
710
- .string()
711
- .default("Members")
712
- .describe(
713
- "Users collection name for any overflowing data associated with users, will try to match one of the collections by name"
714
- ),
715
- databases: z
716
- .array(
717
- z.object({
718
- $id: z.string(),
719
- name: z.string(),
720
- })
721
- )
722
- .default([
723
- { $id: "dev", name: "Development" },
724
- { $id: "main", name: "Main" },
725
- { $id: "staging", name: "Staging" },
726
- { $id: "migrations", name: "Migrations" },
727
- ])
728
- .describe("Databases to create, $id is the id of the database"),
729
- collections: z
730
- .array(CollectionCreateSchema)
731
- .optional()
732
- .default([])
733
- .describe(
734
- "Collections to create, $id is the id of the collection, it'll always check by collection name and $id for existing before creating another"
735
- ),
736
- });
737
-
738
- export type AppwriteConfig = z.infer<typeof AppwriteConfigSchema>;
739
- export type ConfigCollections = AppwriteConfig["collections"];
740
- export type ConfigCollection = ConfigCollections[number];
741
- export type ConfigDatabases = AppwriteConfig["databases"];
742
- export type ConfigDatabase = ConfigDatabases[number];
743
- export type ImportDefs = z.infer<typeof importDefSchemas>;
744
- export type ImportDef = z.infer<typeof importDefSchema>;
745
- export type IdMappings = z.infer<typeof idMappingSchema>;
746
- export type IdMapping = IdMappings[number];
747
- export type AttributeMappings = z.infer<typeof AttributeMappingsSchema>;
748
- export type AttributeMapping = AttributeMappings[number];