appwrite-utils-cli 0.10.86 → 1.0.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 (178) hide show
  1. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
  2. package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
  3. package/.appwrite/collections/Categories.yaml +182 -0
  4. package/.appwrite/collections/ExampleCollection.yaml +36 -0
  5. package/.appwrite/collections/Posts.yaml +227 -0
  6. package/.appwrite/collections/Users.yaml +149 -0
  7. package/.appwrite/config.yaml +109 -0
  8. package/.appwrite/import/README.md +148 -0
  9. package/.appwrite/import/categories-import.yaml +129 -0
  10. package/.appwrite/import/posts-import.yaml +208 -0
  11. package/.appwrite/import/users-import.yaml +130 -0
  12. package/.appwrite/importData/categories.json +194 -0
  13. package/.appwrite/importData/posts.json +270 -0
  14. package/.appwrite/importData/users.json +220 -0
  15. package/.appwrite/schemas/categories.json +128 -0
  16. package/.appwrite/schemas/exampleCollection.json +52 -0
  17. package/.appwrite/schemas/posts.json +173 -0
  18. package/.appwrite/schemas/users.json +125 -0
  19. package/README.md +260 -33
  20. package/dist/collections/attributes.js +3 -2
  21. package/dist/collections/methods.js +56 -38
  22. package/dist/config/yamlConfig.d.ts +501 -0
  23. package/dist/config/yamlConfig.js +452 -0
  24. package/dist/databases/setup.d.ts +6 -0
  25. package/dist/databases/setup.js +119 -0
  26. package/dist/functions/methods.d.ts +1 -1
  27. package/dist/functions/methods.js +5 -2
  28. package/dist/functions/openapi.d.ts +4 -0
  29. package/dist/functions/openapi.js +60 -0
  30. package/dist/interactiveCLI.d.ts +5 -0
  31. package/dist/interactiveCLI.js +194 -49
  32. package/dist/main.js +91 -30
  33. package/dist/migrations/afterImportActions.js +2 -2
  34. package/dist/migrations/appwriteToX.d.ts +10 -0
  35. package/dist/migrations/appwriteToX.js +15 -4
  36. package/dist/migrations/backup.d.ts +16 -16
  37. package/dist/migrations/dataLoader.d.ts +83 -1
  38. package/dist/migrations/dataLoader.js +4 -4
  39. package/dist/migrations/importController.js +25 -18
  40. package/dist/migrations/importDataActions.js +2 -2
  41. package/dist/migrations/logging.d.ts +9 -1
  42. package/dist/migrations/logging.js +41 -22
  43. package/dist/migrations/migrationHelper.d.ts +4 -4
  44. package/dist/migrations/relationships.js +1 -1
  45. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  46. package/dist/migrations/services/DataTransformationService.js +158 -0
  47. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  48. package/dist/migrations/services/FileHandlerService.js +236 -0
  49. package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
  50. package/dist/migrations/services/ImportOrchestrator.js +488 -0
  51. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  52. package/dist/migrations/services/RateLimitManager.js +279 -0
  53. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  54. package/dist/migrations/services/RelationshipResolver.js +332 -0
  55. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  56. package/dist/migrations/services/UserMappingService.js +277 -0
  57. package/dist/migrations/services/ValidationService.d.ts +74 -0
  58. package/dist/migrations/services/ValidationService.js +260 -0
  59. package/dist/migrations/transfer.d.ts +0 -6
  60. package/dist/migrations/transfer.js +16 -132
  61. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
  63. package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
  64. package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
  65. package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
  66. package/dist/migrations/yaml/generateImportSchemas.js +575 -0
  67. package/dist/schemas/authUser.d.ts +9 -9
  68. package/dist/shared/attributeManager.d.ts +17 -0
  69. package/dist/shared/attributeManager.js +273 -0
  70. package/dist/shared/confirmationDialogs.d.ts +75 -0
  71. package/dist/shared/confirmationDialogs.js +236 -0
  72. package/dist/shared/functionManager.d.ts +48 -0
  73. package/dist/shared/functionManager.js +322 -0
  74. package/dist/shared/indexManager.d.ts +24 -0
  75. package/dist/shared/indexManager.js +150 -0
  76. package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
  77. package/dist/shared/jsonSchemaGenerator.js +313 -0
  78. package/dist/shared/logging.d.ts +10 -0
  79. package/dist/shared/logging.js +46 -0
  80. package/dist/shared/messageFormatter.d.ts +37 -0
  81. package/dist/shared/messageFormatter.js +152 -0
  82. package/dist/shared/migrationHelpers.d.ts +173 -0
  83. package/dist/shared/migrationHelpers.js +142 -0
  84. package/dist/shared/operationLogger.d.ts +3 -0
  85. package/dist/shared/operationLogger.js +25 -0
  86. package/dist/shared/operationQueue.d.ts +13 -0
  87. package/dist/shared/operationQueue.js +79 -0
  88. package/dist/shared/progressManager.d.ts +62 -0
  89. package/dist/shared/progressManager.js +215 -0
  90. package/dist/shared/schemaGenerator.d.ts +18 -0
  91. package/dist/shared/schemaGenerator.js +523 -0
  92. package/dist/storage/methods.d.ts +3 -1
  93. package/dist/storage/methods.js +144 -55
  94. package/dist/storage/schemas.d.ts +56 -16
  95. package/dist/types.d.ts +2 -2
  96. package/dist/types.js +1 -1
  97. package/dist/users/methods.d.ts +16 -0
  98. package/dist/users/methods.js +276 -0
  99. package/dist/utils/configMigration.d.ts +1 -0
  100. package/dist/utils/configMigration.js +156 -0
  101. package/dist/utils/dataConverters.d.ts +46 -0
  102. package/dist/utils/dataConverters.js +139 -0
  103. package/dist/utils/loadConfigs.d.ts +15 -4
  104. package/dist/utils/loadConfigs.js +377 -51
  105. package/dist/utils/schemaStrings.js +2 -1
  106. package/dist/utils/setupFiles.d.ts +2 -1
  107. package/dist/utils/setupFiles.js +723 -28
  108. package/dist/utils/validationRules.d.ts +43 -0
  109. package/dist/utils/validationRules.js +42 -0
  110. package/dist/utils/yamlConverter.d.ts +48 -0
  111. package/dist/utils/yamlConverter.js +98 -0
  112. package/dist/utilsController.js +65 -43
  113. package/package.json +19 -15
  114. package/src/collections/attributes.ts +3 -2
  115. package/src/collections/methods.ts +85 -51
  116. package/src/config/yamlConfig.ts +488 -0
  117. package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
  118. package/src/functions/methods.ts +8 -4
  119. package/src/functions/templates/count-docs-in-collection/package.json +25 -0
  120. package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  121. package/src/functions/templates/typescript-node/package.json +24 -0
  122. package/src/functions/templates/typescript-node/tsconfig.json +28 -0
  123. package/src/functions/templates/uv/README.md +31 -0
  124. package/src/functions/templates/uv/pyproject.toml +29 -0
  125. package/src/interactiveCLI.ts +226 -61
  126. package/src/main.ts +111 -37
  127. package/src/migrations/afterImportActions.ts +2 -2
  128. package/src/migrations/appwriteToX.ts +17 -4
  129. package/src/migrations/dataLoader.ts +4 -4
  130. package/src/migrations/importController.ts +30 -22
  131. package/src/migrations/importDataActions.ts +2 -2
  132. package/src/migrations/relationships.ts +1 -1
  133. package/src/migrations/services/DataTransformationService.ts +196 -0
  134. package/src/migrations/services/FileHandlerService.ts +311 -0
  135. package/src/migrations/services/ImportOrchestrator.ts +669 -0
  136. package/src/migrations/services/RateLimitManager.ts +363 -0
  137. package/src/migrations/services/RelationshipResolver.ts +461 -0
  138. package/src/migrations/services/UserMappingService.ts +345 -0
  139. package/src/migrations/services/ValidationService.ts +349 -0
  140. package/src/migrations/transfer.ts +22 -228
  141. package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
  142. package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
  143. package/src/migrations/yaml/generateImportSchemas.ts +589 -0
  144. package/src/shared/attributeManager.ts +429 -0
  145. package/src/shared/confirmationDialogs.ts +327 -0
  146. package/src/shared/functionManager.ts +515 -0
  147. package/src/shared/indexManager.ts +253 -0
  148. package/src/shared/jsonSchemaGenerator.ts +403 -0
  149. package/src/shared/logging.ts +74 -0
  150. package/src/shared/messageFormatter.ts +195 -0
  151. package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
  152. package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
  153. package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
  154. package/src/shared/progressManager.ts +278 -0
  155. package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
  156. package/src/storage/methods.ts +199 -78
  157. package/src/types.ts +2 -2
  158. package/src/{migrations/users.ts → users/methods.ts} +2 -2
  159. package/src/utils/configMigration.ts +212 -0
  160. package/src/utils/loadConfigs.ts +414 -52
  161. package/src/utils/schemaStrings.ts +2 -1
  162. package/src/utils/setupFiles.ts +742 -40
  163. package/src/{migrations → utils}/validationRules.ts +1 -1
  164. package/src/utils/yamlConverter.ts +131 -0
  165. package/src/utilsController.ts +75 -54
  166. package/src/functions/templates/poetry/README.md +0 -30
  167. package/src/functions/templates/poetry/pyproject.toml +0 -16
  168. package/src/migrations/attributes.ts +0 -561
  169. package/src/migrations/backup.ts +0 -205
  170. package/src/migrations/databases.ts +0 -39
  171. package/src/migrations/dbHelpers.ts +0 -92
  172. package/src/migrations/indexes.ts +0 -40
  173. package/src/migrations/logging.ts +0 -29
  174. package/src/migrations/storage.ts +0 -538
  175. /package/src/{migrations → functions}/openapi.ts +0 -0
  176. /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
  177. /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
  178. /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
@@ -1,205 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- attributeSchema,
4
- type Attribute,
5
- parseAttribute,
6
- CollectionCreateSchema,
7
- } from "appwrite-utils";
8
-
9
- export const BackupSchema = z.object({
10
- $id: z.string(),
11
- $createdAt: z.string(),
12
- $updatedAt: z.string(),
13
- database: z.string(),
14
- collections: z.array(z.string()),
15
- documents: z
16
- .array(
17
- z.object({
18
- collectionId: z.string(),
19
- data: z.string(),
20
- })
21
- )
22
- .default([]),
23
- });
24
-
25
- export type Backup = z.infer<typeof BackupSchema>;
26
-
27
- export const BackupCreateSchema = BackupSchema.omit({
28
- $id: true,
29
- $createdAt: true,
30
- $updatedAt: true,
31
- });
32
-
33
- export type BackupCreate = z.infer<typeof BackupCreateSchema>;
34
-
35
- export const BatchSchema = z.object({
36
- $id: z.string(),
37
- $createdAt: z.string(),
38
- $updatedAt: z.string(),
39
- data: z.string().describe("The serialized data for this batch"),
40
- processed: z
41
- .boolean()
42
- .default(false)
43
- .describe("Whether the batch has been processed"),
44
- });
45
-
46
- export type Batch = z.infer<typeof BatchSchema>;
47
-
48
- export const BatchCreateSchema = BatchSchema.omit({
49
- $id: true,
50
- $createdAt: true,
51
- $updatedAt: true,
52
- });
53
-
54
- export type BatchCreate = z.infer<typeof BatchCreateSchema>;
55
-
56
- export const OperationSchema = z.object({
57
- $id: z.string(),
58
- $createdAt: z.string(),
59
- $updatedAt: z.string(),
60
- operationType: z.string(),
61
- collectionId: z.string(),
62
- data: z.any(),
63
- batches: z.array(z.string()).default([]).optional(),
64
- progress: z.number(),
65
- total: z.number(),
66
- error: z.string(),
67
- status: z
68
- .enum([
69
- "pending",
70
- "ready",
71
- "in_progress",
72
- "completed",
73
- "error",
74
- "cancelled",
75
- ])
76
- .default("pending"),
77
- });
78
-
79
- export type Operation = z.infer<typeof OperationSchema>;
80
-
81
- export const OperationCreateSchema = OperationSchema.omit({
82
- $id: true,
83
- $createdAt: true,
84
- $updatedAt: true,
85
- });
86
-
87
- export type OperationCreate = z.infer<typeof OperationCreateSchema>;
88
-
89
- export const getMigrationCollectionSchemas = () => {
90
- const currentOperationsAttributes: Attribute[] = [
91
- parseAttribute({
92
- key: "operationType",
93
- type: "string",
94
- error: "Invalid Operation Type",
95
- size: 50,
96
- required: true,
97
- array: false,
98
- xdefault: null,
99
- }),
100
- attributeSchema.parse({
101
- key: "collectionId",
102
- type: "string",
103
- error: "Invalid Collection Id",
104
- size: 50,
105
- array: false,
106
- xdefault: null,
107
- }),
108
- attributeSchema.parse({
109
- key: "batches",
110
- type: "string",
111
- error: "Invalid Batches",
112
- size: 1073741824,
113
- array: true,
114
- }),
115
- attributeSchema.parse({
116
- key: "data",
117
- type: "string",
118
- error: "Invalid Data",
119
- size: 1073741824,
120
- }),
121
- attributeSchema.parse({
122
- key: "progress",
123
- type: "integer",
124
- error: "Invalid Progress",
125
- required: true,
126
- array: false,
127
- }),
128
- attributeSchema.parse({
129
- key: "total",
130
- type: "integer",
131
- error: "Invalid Total",
132
- required: true,
133
- array: false,
134
- }),
135
- attributeSchema.parse({
136
- key: "error",
137
- type: "string",
138
- error: "Operation Error",
139
- required: false,
140
- array: false,
141
- }),
142
- attributeSchema.parse({
143
- key: "status",
144
- type: "enum",
145
- elements: [
146
- "pending",
147
- "ready",
148
- "in_progress",
149
- "completed",
150
- "error",
151
- "cancelled",
152
- ],
153
- error: "Invalid Status",
154
- array: false,
155
- xdefault: "pending",
156
- }),
157
- ];
158
-
159
- const currentOperationsConfig = CollectionCreateSchema.parse({
160
- name: "CurrentOperations",
161
- enabled: true,
162
- documentSecurity: false,
163
- attributes: [],
164
- indexes: [],
165
- });
166
-
167
- const batchesAttributes: Attribute[] = [
168
- attributeSchema.parse({
169
- key: "data",
170
- type: "string",
171
- size: 1073741824,
172
- error: "Invalid Data",
173
- required: true,
174
- array: false,
175
- }),
176
- attributeSchema.parse({
177
- key: "processed",
178
- type: "boolean",
179
- error: "Invalid Processed",
180
- required: true,
181
- array: false,
182
- xdefault: false,
183
- }),
184
- ];
185
-
186
- const batchesConfig = CollectionCreateSchema.parse({
187
- name: "Batches",
188
- enabled: true,
189
- documentSecurity: false,
190
- attributes: [],
191
- indexes: [],
192
- });
193
-
194
- const toReturn = {
195
- CurrentOperations: {
196
- collection: currentOperationsConfig,
197
- attributes: currentOperationsAttributes,
198
- },
199
- Batches: {
200
- collection: batchesConfig,
201
- attributes: batchesAttributes,
202
- },
203
- };
204
- return toReturn;
205
- };
@@ -1,39 +0,0 @@
1
- import {
2
- Client,
3
- Databases,
4
- IndexType,
5
- Query,
6
- type Models,
7
- } from "node-appwrite";
8
- import {
9
- getAppwriteClient,
10
- tryAwaitWithRetry,
11
- } from "../utils/helperFunctions.js";
12
-
13
- export const fetchAllDatabases = async (
14
- database: Databases
15
- ): Promise<Models.Database[]> => {
16
- const databases = await tryAwaitWithRetry(
17
- async () => await database.list([Query.limit(25)])
18
- );
19
- if (!databases) return [];
20
- const allDatabases = databases.databases;
21
- if (allDatabases.length === 0) return [];
22
- let lastDatabaseId = allDatabases[allDatabases.length - 1].$id;
23
- if (databases.databases.length < 25) {
24
- return allDatabases;
25
- } else {
26
- while (lastDatabaseId) {
27
- const databases = await database.list([
28
- Query.limit(25),
29
- Query.cursorAfter(lastDatabaseId),
30
- ]);
31
- allDatabases.push(...databases.databases);
32
- if (databases.databases.length < 25) {
33
- break;
34
- }
35
- lastDatabaseId = databases.databases[databases.databases.length - 1].$id;
36
- }
37
- }
38
- return allDatabases;
39
- };
@@ -1,92 +0,0 @@
1
- import type {
2
- AppwriteConfig,
3
- Attribute,
4
- RelationshipAttribute,
5
- } from "appwrite-utils";
6
-
7
- // Helper function to categorize collections based on relationship sides
8
- export const categorizeCollectionByRelationshipSide = (
9
- attributes: Attribute[]
10
- ): "parent" | "mixed" | "child" => {
11
- let hasParent = false;
12
- let hasChild = false;
13
-
14
- for (const attr of attributes) {
15
- if (attr.type === "relationship") {
16
- if (attr.side === "parent") {
17
- hasParent = true;
18
- } else if (attr.side === "child") {
19
- hasChild = true;
20
- }
21
- }
22
- }
23
-
24
- if (hasParent && hasChild) return "mixed";
25
- if (hasParent) return "parent";
26
- return "child";
27
- };
28
-
29
- // Helper function to get all dependencies of a collection
30
- export const getDependencies = (attributes: Attribute[]): string[] => {
31
- return attributes
32
- .filter(
33
- (attr) =>
34
- attr.type === "relationship" && attr.relatedCollection !== undefined
35
- )
36
- .map((attr) => (attr as RelationshipAttribute).relatedCollection);
37
- };
38
-
39
- // Function to sort collections based on dependencies and relationship sides
40
- export const sortCollections = (
41
- configCollections: AppwriteConfig["collections"]
42
- ): AppwriteConfig["collections"] => {
43
- if (!configCollections) {
44
- return [];
45
- }
46
- // Categorize collections based on their relationship sides
47
- const parentCollections = configCollections.filter(
48
- ({ attributes }) =>
49
- categorizeCollectionByRelationshipSide(attributes) === "parent"
50
- );
51
- const mixedCollections = configCollections.filter(
52
- ({ attributes }) =>
53
- categorizeCollectionByRelationshipSide(attributes) === "mixed"
54
- );
55
- const childCollections = configCollections.filter(
56
- ({ attributes }) =>
57
- categorizeCollectionByRelationshipSide(attributes) === "child"
58
- );
59
-
60
- // Sort mixedCollections to ensure parents are processed before children within the mixed category
61
- // This might involve more sophisticated logic if you need to order mixed collections based on specific parent-child relationships
62
- mixedCollections.sort((a, b) => {
63
- // Example sorting logic for mixed collections; adjust based on your specific needs
64
- const aDependencies = getDependencies(a.attributes).length;
65
- const bDependencies = getDependencies(b.attributes).length;
66
- return aDependencies - bDependencies;
67
- });
68
-
69
- // Combine them back into a single array with the desired order
70
- // Children first because they have no dependencies and parents will create the relationship if it's twoWay
71
- return [...childCollections, ...parentCollections, ...mixedCollections];
72
- };
73
-
74
- // Function to sort attributes within a collection based on relationship sides
75
- export const sortAttributesByRelationshipSide = (
76
- attributes: Attribute[]
77
- ): Attribute[] => {
78
- // Separate attributes into parent and child based on their relationship side
79
- const parentAttributes = attributes.filter(
80
- (attr) => attr.type === "relationship" && attr.side === "parent"
81
- );
82
- const childAttributes = attributes.filter(
83
- (attr) => attr.type === "relationship" && attr.side === "child"
84
- );
85
- const otherAttributes = attributes.filter(
86
- (attr) => attr.type !== "relationship"
87
- );
88
-
89
- // Combine them back into a single array with child attributes first, then other attributes, and parent attributes last
90
- // as parent attributes will create the relationship with the child if needed
91
- return [...childAttributes, ...otherAttributes, ...parentAttributes];
92
- };
@@ -1,40 +0,0 @@
1
- import { indexSchema, type Index } from "appwrite-utils";
2
- import { Databases, IndexType, Query, type Models } from "node-appwrite";
3
- import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
4
- // import {}
5
-
6
- export const createOrUpdateIndex = async (
7
- dbId: string,
8
- db: Databases,
9
- collectionId: string,
10
- index: Index
11
- ) => {
12
- const existingIndex = await db.listIndexes(dbId, collectionId, [
13
- Query.equal("key", index.key),
14
- ]);
15
- if (existingIndex.total > 0) {
16
- await db.deleteIndex(dbId, collectionId, existingIndex.indexes[0].key);
17
- }
18
- const newIndex = await db.createIndex(
19
- dbId,
20
- collectionId,
21
- index.key,
22
- index.type as IndexType,
23
- index.attributes,
24
- index.orders
25
- );
26
- return newIndex;
27
- };
28
-
29
- export const createOrUpdateIndexes = async (
30
- dbId: string,
31
- db: Databases,
32
- collectionId: string,
33
- indexes: Index[]
34
- ) => {
35
- for (const index of indexes) {
36
- await tryAwaitWithRetry(
37
- async () => await createOrUpdateIndex(dbId, db, collectionId, index)
38
- );
39
- }
40
- };
@@ -1,29 +0,0 @@
1
- import winston from "winston";
2
- import fs from "fs";
3
- import path from "path";
4
-
5
- // Ensure the logs directory exists
6
- const logDir = path.join(process.cwd(), "zlogs");
7
- if (!fs.existsSync(logDir)) {
8
- fs.mkdirSync(logDir);
9
- }
10
-
11
- export const logger = winston.createLogger({
12
- level: "debug",
13
- format: winston.format.json({ space: 2 }),
14
- defaultMeta: { service: "appwrite-utils-cli" },
15
- transports: [
16
- new winston.transports.File({
17
- filename: path.join(logDir, "error.log"),
18
- level: "error",
19
- }),
20
- new winston.transports.File({
21
- filename: path.join(logDir, "warn.log"),
22
- level: "warn",
23
- }),
24
- new winston.transports.File({
25
- filename: path.join(logDir, "info.log"),
26
- level: "info",
27
- }),
28
- ],
29
- });