appwrite-utils-cli 1.3.5 → 1.4.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 (116) hide show
  1. package/dist/adapters/AdapterFactory.d.ts +87 -0
  2. package/dist/adapters/AdapterFactory.js +217 -0
  3. package/dist/adapters/DatabaseAdapter.d.ts +217 -0
  4. package/dist/adapters/DatabaseAdapter.js +50 -0
  5. package/dist/adapters/LegacyAdapter.d.ts +49 -0
  6. package/dist/adapters/LegacyAdapter.js +382 -0
  7. package/dist/adapters/TablesDBAdapter.d.ts +55 -0
  8. package/dist/adapters/TablesDBAdapter.js +302 -0
  9. package/dist/adapters/index.d.ts +11 -0
  10. package/dist/adapters/index.js +12 -0
  11. package/dist/collections/attributes.js +41 -22
  12. package/dist/collections/methods.d.ts +4 -3
  13. package/dist/collections/methods.js +34 -14
  14. package/dist/config/yamlConfig.d.ts +40 -437
  15. package/dist/config/yamlConfig.js +8 -2
  16. package/dist/databases/setup.js +2 -2
  17. package/dist/main.js +0 -0
  18. package/dist/migrations/appwriteToX.d.ts +26 -37
  19. package/dist/migrations/comprehensiveTransfer.js +4 -4
  20. package/dist/migrations/dataLoader.d.ts +124 -1484
  21. package/dist/migrations/dataLoader.js +2 -1
  22. package/dist/migrations/relationships.d.ts +2 -3
  23. package/dist/migrations/relationships.js +1 -1
  24. package/dist/migrations/services/UserMappingService.js +1 -1
  25. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +24 -279
  26. package/dist/migrations/yaml/YamlImportConfigLoader.js +7 -2
  27. package/dist/schemas/authUser.d.ts +7 -47
  28. package/dist/schemas/authUser.js +1 -1
  29. package/dist/shared/jsonSchemaGenerator.d.ts +0 -2
  30. package/dist/shared/jsonSchemaGenerator.js +4 -17
  31. package/dist/shared/migrationHelpers.d.ts +17 -119
  32. package/dist/shared/operationQueue.js +16 -7
  33. package/dist/shared/schemaGenerator.js +2 -17
  34. package/dist/storage/schemas.d.ts +149 -296
  35. package/dist/users/methods.d.ts +2 -2
  36. package/dist/utils/configMigration.js +0 -1
  37. package/dist/utils/getClientFromConfig.d.ts +26 -0
  38. package/dist/utils/getClientFromConfig.js +37 -0
  39. package/dist/utils/loadConfigs.js +0 -2
  40. package/dist/utils/schemaStrings.js +2 -17
  41. package/dist/utils/setupFiles.js +2 -0
  42. package/dist/utils/versionDetection.d.ts +56 -0
  43. package/dist/utils/versionDetection.js +217 -0
  44. package/dist/utils/yamlConverter.d.ts +0 -1
  45. package/dist/utils/yamlConverter.js +0 -2
  46. package/dist/utilsController.js +2 -0
  47. package/package.json +3 -2
  48. package/src/adapters/AdapterFactory.ts +296 -0
  49. package/src/adapters/DatabaseAdapter.ts +290 -0
  50. package/src/adapters/LegacyAdapter.ts +667 -0
  51. package/src/adapters/TablesDBAdapter.ts +429 -0
  52. package/src/adapters/index.ts +37 -0
  53. package/src/collections/attributes.ts +347 -153
  54. package/src/collections/methods.ts +43 -28
  55. package/src/config/yamlConfig.ts +8 -2
  56. package/src/databases/setup.ts +2 -2
  57. package/src/migrations/afterImportActions.ts +2 -2
  58. package/src/migrations/comprehensiveTransfer.ts +4 -0
  59. package/src/migrations/dataLoader.ts +2 -1
  60. package/src/migrations/relationships.ts +1 -1
  61. package/src/migrations/services/UserMappingService.ts +1 -1
  62. package/src/migrations/yaml/YamlImportConfigLoader.ts +7 -2
  63. package/src/schemas/authUser.ts +1 -1
  64. package/src/shared/jsonSchemaGenerator.ts +4 -19
  65. package/src/shared/operationQueue.ts +20 -13
  66. package/src/shared/schemaGenerator.ts +2 -16
  67. package/src/types/node-appwrite-tablesdb.d.ts +44 -0
  68. package/src/users/methods.ts +2 -2
  69. package/src/utils/configMigration.ts +0 -1
  70. package/src/utils/getClientFromConfig.ts +56 -0
  71. package/src/utils/loadConfigs.ts +0 -2
  72. package/src/utils/schemaStrings.ts +2 -16
  73. package/src/utils/setupFiles.ts +2 -0
  74. package/src/utils/versionDetection.ts +265 -0
  75. package/src/utils/yamlConverter.ts +0 -2
  76. package/src/utilsController.ts +2 -0
  77. package/dist/functions/openapi.d.ts +0 -4
  78. package/dist/functions/openapi.js +0 -60
  79. package/dist/migrations/attributes.d.ts +0 -4
  80. package/dist/migrations/attributes.js +0 -301
  81. package/dist/migrations/backup.d.ts +0 -687
  82. package/dist/migrations/backup.js +0 -175
  83. package/dist/migrations/collections.d.ts +0 -22
  84. package/dist/migrations/collections.js +0 -347
  85. package/dist/migrations/converters.d.ts +0 -46
  86. package/dist/migrations/converters.js +0 -139
  87. package/dist/migrations/databases.d.ts +0 -2
  88. package/dist/migrations/databases.js +0 -28
  89. package/dist/migrations/dbHelpers.d.ts +0 -5
  90. package/dist/migrations/dbHelpers.js +0 -57
  91. package/dist/migrations/helper.d.ts +0 -3
  92. package/dist/migrations/helper.js +0 -21
  93. package/dist/migrations/indexes.d.ts +0 -4
  94. package/dist/migrations/indexes.js +0 -19
  95. package/dist/migrations/logging.d.ts +0 -10
  96. package/dist/migrations/logging.js +0 -46
  97. package/dist/migrations/migrationHelper.d.ts +0 -173
  98. package/dist/migrations/migrationHelper.js +0 -130
  99. package/dist/migrations/openapi.d.ts +0 -4
  100. package/dist/migrations/openapi.js +0 -60
  101. package/dist/migrations/queue.d.ts +0 -13
  102. package/dist/migrations/queue.js +0 -79
  103. package/dist/migrations/schemaStrings.d.ts +0 -14
  104. package/dist/migrations/schemaStrings.js +0 -478
  105. package/dist/migrations/setupDatabase.d.ts +0 -6
  106. package/dist/migrations/setupDatabase.js +0 -115
  107. package/dist/migrations/storage.d.ts +0 -10
  108. package/dist/migrations/storage.js +0 -340
  109. package/dist/migrations/users.d.ts +0 -16
  110. package/dist/migrations/users.js +0 -276
  111. package/dist/migrations/validationRules.d.ts +0 -43
  112. package/dist/migrations/validationRules.js +0 -42
  113. package/dist/shared/attributeManager.d.ts +0 -17
  114. package/dist/shared/attributeManager.js +0 -272
  115. package/src/functions/openapi.ts +0 -83
  116. package/src/shared/attributeManager.ts +0 -428
@@ -17,154 +17,52 @@ export declare const ContextObject: z.ZodObject<{
17
17
  finalItem: z.ZodAny;
18
18
  attributeMappings: z.ZodArray<z.ZodObject<{
19
19
  oldKey: z.ZodOptional<z.ZodString>;
20
- oldKeys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
20
+ oldKeys: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
21
  targetKey: z.ZodString;
22
22
  valueToSet: z.ZodOptional<z.ZodAny>;
23
23
  fileData: z.ZodOptional<z.ZodObject<{
24
24
  name: z.ZodString;
25
25
  path: z.ZodString;
26
- }, "strip", z.ZodTypeAny, {
27
- path: string;
28
- name: string;
29
- }, {
30
- path: string;
31
- name: string;
32
- }>>;
33
- converters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
26
+ }, z.core.$strip>>;
27
+ converters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
34
28
  validationActions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
35
29
  action: z.ZodString;
36
- params: z.ZodArray<z.ZodString, "many">;
37
- }, "strip", z.ZodTypeAny, {
38
- params: string[];
39
- action: string;
40
- }, {
41
- params: string[];
42
- action: string;
43
- }>, "many">>>;
30
+ params: z.ZodArray<z.ZodString>;
31
+ }, z.core.$strip>>>>;
44
32
  postImportActions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
45
33
  action: z.ZodString;
46
- params: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>, "many">;
47
- }, "strip", z.ZodTypeAny, {
48
- params: (string | Record<string, any>)[];
49
- action: string;
50
- }, {
51
- params: (string | Record<string, any>)[];
52
- action: string;
53
- }>, "many">>>;
54
- }, "strip", z.ZodTypeAny, {
55
- targetKey: string;
56
- oldKey?: string | undefined;
57
- oldKeys?: string[] | undefined;
58
- valueToSet?: any;
59
- fileData?: {
60
- path: string;
61
- name: string;
62
- } | undefined;
63
- converters?: string[] | undefined;
64
- validationActions?: {
65
- params: string[];
66
- action: string;
67
- }[] | undefined;
68
- postImportActions?: {
69
- params: (string | Record<string, any>)[];
70
- action: string;
71
- }[] | undefined;
72
- }, {
73
- targetKey: string;
74
- oldKey?: string | undefined;
75
- oldKeys?: string[] | undefined;
76
- valueToSet?: any;
77
- fileData?: {
78
- path: string;
79
- name: string;
80
- } | undefined;
81
- converters?: string[] | undefined;
82
- validationActions?: {
83
- params: string[];
84
- action: string;
85
- }[] | undefined;
86
- postImportActions?: {
87
- params: (string | Record<string, any>)[];
88
- action: string;
89
- }[] | undefined;
90
- }>, "many">;
34
+ params: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
35
+ }, z.core.$strip>>>>;
36
+ }, z.core.$strip>>;
91
37
  context: z.ZodAny;
92
- }, "strip", z.ZodTypeAny, {
93
- collectionId: string;
94
- attributeMappings: {
95
- targetKey: string;
96
- oldKey?: string | undefined;
97
- oldKeys?: string[] | undefined;
98
- valueToSet?: any;
99
- fileData?: {
100
- path: string;
101
- name: string;
102
- } | undefined;
103
- converters?: string[] | undefined;
104
- validationActions?: {
105
- params: string[];
106
- action: string;
107
- }[] | undefined;
108
- postImportActions?: {
109
- params: (string | Record<string, any>)[];
110
- action: string;
111
- }[] | undefined;
112
- }[];
113
- dbId: string;
114
- context?: any;
115
- finalItem?: any;
116
- }, {
117
- collectionId: string;
118
- attributeMappings: {
119
- targetKey: string;
120
- oldKey?: string | undefined;
121
- oldKeys?: string[] | undefined;
122
- valueToSet?: any;
123
- fileData?: {
124
- path: string;
125
- name: string;
126
- } | undefined;
127
- converters?: string[] | undefined;
128
- validationActions?: {
129
- params: string[];
130
- action: string;
131
- }[] | undefined;
132
- postImportActions?: {
133
- params: (string | Record<string, any>)[];
134
- action: string;
135
- }[] | undefined;
136
- }[];
137
- dbId: string;
138
- context?: any;
139
- finalItem?: any;
140
- }>;
38
+ }, z.core.$strip>;
141
39
  export type ContextObject = z.infer<typeof ContextObject>;
142
40
  export declare const createOrFindAfterImportOperation: (database: Databases, collectionId: string, context: ContextObject, useMigrations?: boolean) => Promise<void>;
143
41
  export declare const addBatch: (database: Databases, data: string) => Promise<string>;
144
42
  export declare const getAfterImportOperations: (database: Databases, collectionId: string, useMigrations?: boolean) => Promise<{
145
- status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
146
- error: string;
147
43
  $id: string;
148
44
  $createdAt: string;
149
45
  $updatedAt: string;
150
- collectionId: string;
151
46
  operationType: string;
47
+ collectionId: string;
48
+ data: any;
152
49
  progress: number;
153
50
  total: number;
154
- data?: any;
51
+ error: string;
52
+ status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
155
53
  batches?: string[] | undefined;
156
54
  }[]>;
157
55
  export declare const findOrCreateOperation: (database: Databases, collectionId: string, operationType: string, additionalQueries?: string[]) => Promise<{
158
- status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
159
- error: string;
160
56
  $id: string;
161
57
  $createdAt: string;
162
58
  $updatedAt: string;
163
- collectionId: string;
164
59
  operationType: string;
60
+ collectionId: string;
61
+ data: any;
165
62
  progress: number;
166
63
  total: number;
167
- data?: any;
64
+ error: string;
65
+ status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
168
66
  batches?: string[] | undefined;
169
67
  }>;
170
68
  export declare const updateOperation: (database: Databases, operationId: string, updateFields: any, useMigrations?: boolean) => Promise<void>;
@@ -1,7 +1,8 @@
1
1
  import { Query } from "node-appwrite";
2
- import { createOrUpdateAttribute } from "../collections/attributes.js";
2
+ import { createOrUpdateAttributeWithStatusCheck } from "../collections/attributes.js";
3
3
  import { fetchAndCacheCollectionByName } from "../collections/methods.js";
4
4
  import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
5
+ import chalk from "chalk";
5
6
  export const queuedOperations = [];
6
7
  export const nameToIdMapping = new Map();
7
8
  export const enqueueOperation = (operation) => {
@@ -55,14 +56,22 @@ export const processQueue = async (db, dbId) => {
55
56
  }
56
57
  // Process the operation if the collection is found
57
58
  if (collectionFound && operation.attribute) {
58
- console.log(`\tProcessing attribute: ${operation.attribute.key} for collection ID: ${collectionFound.$id}`);
59
- await createOrUpdateAttribute(db, dbId, collectionFound, operation.attribute);
60
- queuedOperations.splice(i, 1);
61
- i--; // Adjust index since we're modifying the array
62
- progress = true;
59
+ console.log(chalk.cyan(`\t📋 Queue processing relationship attribute: ${operation.attribute.key} for collection: ${collectionFound.name}`));
60
+ const success = await createOrUpdateAttributeWithStatusCheck(db, dbId, collectionFound, operation.attribute);
61
+ if (success) {
62
+ console.log(chalk.green(`\t✅ Successfully processed queued attribute: ${operation.attribute.key}`));
63
+ queuedOperations.splice(i, 1);
64
+ i--; // Adjust index since we're modifying the array
65
+ progress = true;
66
+ }
67
+ else {
68
+ console.log(chalk.red(`\t❌ Failed to process queued attribute: ${operation.attribute.key}, removing from queue`));
69
+ queuedOperations.splice(i, 1);
70
+ i--; // Adjust index since we're modifying the array
71
+ }
63
72
  }
64
73
  else {
65
- console.error(`\tCollection not found for operation, removing from queue: ${JSON.stringify(operation)}`);
74
+ console.log(chalk.yellow(`\t⚠️ Collection not found for queued operation, removing from queue: ${operation.attribute?.key || 'unknown'}`));
66
75
  queuedOperations.splice(i, 1);
67
76
  i--; // Adjust index since we're modifying the array
68
77
  }
@@ -332,11 +332,6 @@ export default appwriteConfig;
332
332
  createSchemaString = (name, attributes) => {
333
333
  const pascalName = toPascalCase(name);
334
334
  let imports = `import { z } from "zod";\n`;
335
- const hasDescription = attributes.some((attr) => attr.description);
336
- if (hasDescription) {
337
- imports += `import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";\n`;
338
- imports += `extendZodWithOpenApi(z);\n`;
339
- }
340
335
  // Use the relationshipMap to find related collections
341
336
  const relationshipDetails = this.relationshipMap.get(name) || [];
342
337
  const relatedCollections = relationshipDetails
@@ -461,7 +456,7 @@ export default appwriteConfig;
461
456
  baseSchemaCode = "z.number().int()";
462
457
  if (finalAttribute.min !== undefined) {
463
458
  if (BigInt(finalAttribute.min) === BigInt(-9223372036854776000)) {
464
- delete finalAttribute.min;
459
+ finalAttribute.min = undefined;
465
460
  }
466
461
  else {
467
462
  baseSchemaCode += `.min(${finalAttribute.min}, "Minimum value of ${finalAttribute.min} not met")`;
@@ -469,7 +464,7 @@ export default appwriteConfig;
469
464
  }
470
465
  if (finalAttribute.max !== undefined) {
471
466
  if (BigInt(finalAttribute.max) === BigInt(9223372036854776000)) {
472
- delete finalAttribute.max;
467
+ finalAttribute.max = undefined;
473
468
  }
474
469
  else {
475
470
  baseSchemaCode += `.max(${finalAttribute.max}, "Maximum value of ${finalAttribute.max} exceeded")`;
@@ -566,16 +561,6 @@ export default appwriteConfig;
566
561
  if (attribute.array && !attribute.required) {
567
562
  baseSchemaCode += ".nullish()";
568
563
  }
569
- if (attribute.description) {
570
- if (typeof attribute.description === "string") {
571
- baseSchemaCode += `.openapi({ description: "${attribute.description}" })`;
572
- }
573
- else {
574
- baseSchemaCode += `.openapi(${Object.entries(attribute.description)
575
- .map(([key, value]) => `"${key}": ${value}`)
576
- .join(", ")})`;
577
- }
578
- }
579
564
  return baseSchemaCode;
580
565
  };
581
566
  }