appwrite-utils-cli 0.0.286 → 0.9.2

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 (109) hide show
  1. package/README.md +162 -96
  2. package/dist/collections/attributes.d.ts +4 -0
  3. package/dist/collections/attributes.js +224 -0
  4. package/dist/collections/indexes.d.ts +4 -0
  5. package/dist/collections/indexes.js +27 -0
  6. package/dist/collections/methods.d.ts +16 -0
  7. package/dist/collections/methods.js +216 -0
  8. package/dist/databases/methods.d.ts +6 -0
  9. package/dist/databases/methods.js +33 -0
  10. package/dist/interactiveCLI.d.ts +19 -0
  11. package/dist/interactiveCLI.js +555 -0
  12. package/dist/main.js +224 -62
  13. package/dist/migrations/afterImportActions.js +37 -40
  14. package/dist/migrations/appwriteToX.d.ts +26 -25
  15. package/dist/migrations/appwriteToX.js +42 -6
  16. package/dist/migrations/attributes.js +21 -20
  17. package/dist/migrations/backup.d.ts +93 -87
  18. package/dist/migrations/collections.d.ts +6 -0
  19. package/dist/migrations/collections.js +149 -20
  20. package/dist/migrations/converters.d.ts +2 -18
  21. package/dist/migrations/converters.js +13 -2
  22. package/dist/migrations/dataLoader.d.ts +276 -161
  23. package/dist/migrations/dataLoader.js +535 -292
  24. package/dist/migrations/databases.js +8 -2
  25. package/dist/migrations/helper.d.ts +3 -0
  26. package/dist/migrations/helper.js +21 -0
  27. package/dist/migrations/importController.d.ts +5 -2
  28. package/dist/migrations/importController.js +125 -88
  29. package/dist/migrations/importDataActions.d.ts +9 -1
  30. package/dist/migrations/importDataActions.js +15 -3
  31. package/dist/migrations/indexes.js +3 -2
  32. package/dist/migrations/logging.js +20 -8
  33. package/dist/migrations/migrationHelper.d.ts +9 -4
  34. package/dist/migrations/migrationHelper.js +6 -5
  35. package/dist/migrations/openapi.d.ts +1 -1
  36. package/dist/migrations/openapi.js +33 -18
  37. package/dist/migrations/queue.js +3 -2
  38. package/dist/migrations/relationships.d.ts +2 -2
  39. package/dist/migrations/schemaStrings.js +53 -41
  40. package/dist/migrations/setupDatabase.d.ts +2 -4
  41. package/dist/migrations/setupDatabase.js +24 -105
  42. package/dist/migrations/storage.d.ts +3 -1
  43. package/dist/migrations/storage.js +110 -16
  44. package/dist/migrations/transfer.d.ts +30 -0
  45. package/dist/migrations/transfer.js +337 -0
  46. package/dist/migrations/users.d.ts +2 -1
  47. package/dist/migrations/users.js +78 -43
  48. package/dist/schemas/authUser.d.ts +2 -2
  49. package/dist/storage/methods.d.ts +15 -0
  50. package/dist/storage/methods.js +207 -0
  51. package/dist/storage/schemas.d.ts +687 -0
  52. package/dist/storage/schemas.js +175 -0
  53. package/dist/utils/getClientFromConfig.d.ts +4 -0
  54. package/dist/utils/getClientFromConfig.js +16 -0
  55. package/dist/utils/helperFunctions.d.ts +11 -1
  56. package/dist/utils/helperFunctions.js +38 -0
  57. package/dist/utils/retryFailedPromises.d.ts +2 -0
  58. package/dist/utils/retryFailedPromises.js +21 -0
  59. package/dist/utils/schemaStrings.d.ts +13 -0
  60. package/dist/utils/schemaStrings.js +403 -0
  61. package/dist/utils/setupFiles.js +110 -61
  62. package/dist/utilsController.d.ts +40 -22
  63. package/dist/utilsController.js +164 -84
  64. package/package.json +13 -15
  65. package/src/collections/attributes.ts +483 -0
  66. package/src/collections/indexes.ts +53 -0
  67. package/src/collections/methods.ts +331 -0
  68. package/src/databases/methods.ts +47 -0
  69. package/src/init.ts +64 -64
  70. package/src/interactiveCLI.ts +767 -0
  71. package/src/main.ts +289 -83
  72. package/src/migrations/afterImportActions.ts +553 -490
  73. package/src/migrations/appwriteToX.ts +237 -174
  74. package/src/migrations/attributes.ts +483 -422
  75. package/src/migrations/backup.ts +205 -205
  76. package/src/migrations/collections.ts +545 -300
  77. package/src/migrations/converters.ts +161 -150
  78. package/src/migrations/dataLoader.ts +1615 -1304
  79. package/src/migrations/databases.ts +44 -25
  80. package/src/migrations/dbHelpers.ts +92 -92
  81. package/src/migrations/helper.ts +40 -0
  82. package/src/migrations/importController.ts +448 -384
  83. package/src/migrations/importDataActions.ts +315 -307
  84. package/src/migrations/indexes.ts +40 -37
  85. package/src/migrations/logging.ts +29 -16
  86. package/src/migrations/migrationHelper.ts +207 -201
  87. package/src/migrations/openapi.ts +83 -70
  88. package/src/migrations/queue.ts +118 -119
  89. package/src/migrations/relationships.ts +324 -324
  90. package/src/migrations/schemaStrings.ts +472 -460
  91. package/src/migrations/setupDatabase.ts +118 -219
  92. package/src/migrations/storage.ts +538 -358
  93. package/src/migrations/transfer.ts +608 -0
  94. package/src/migrations/users.ts +362 -285
  95. package/src/migrations/validationRules.ts +63 -63
  96. package/src/schemas/authUser.ts +23 -23
  97. package/src/setup.ts +8 -8
  98. package/src/storage/methods.ts +371 -0
  99. package/src/storage/schemas.ts +205 -0
  100. package/src/types.ts +9 -9
  101. package/src/utils/getClientFromConfig.ts +17 -0
  102. package/src/utils/helperFunctions.ts +181 -127
  103. package/src/utils/index.ts +2 -2
  104. package/src/utils/loadConfigs.ts +59 -59
  105. package/src/utils/retryFailedPromises.ts +27 -0
  106. package/src/utils/schemaStrings.ts +473 -0
  107. package/src/utils/setupFiles.ts +228 -182
  108. package/src/utilsController.ts +325 -194
  109. package/tsconfig.json +37 -37
@@ -1,182 +1,228 @@
1
- import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
- import path from "node:path";
3
- import type { AppwriteConfig } from "appwrite-utils";
4
- import { findAppwriteConfig } from "./loadConfigs.js";
5
-
6
- // Example base configuration using types from appwrite-utils
7
- const baseConfig: AppwriteConfig = {
8
- appwriteEndpoint: "https://cloud.appwrite.io/v1",
9
- appwriteProject: "YOUR_PROJECT_ID",
10
- appwriteKey: "YOUR_API_KEY",
11
- enableDevDatabase: true,
12
- enableBackups: true,
13
- backupInterval: 3600,
14
- backupRetention: 30,
15
- enableBackupCleanup: true,
16
- enableMockData: false,
17
- enableWipeOtherDatabases: true,
18
- documentBucketId: "documents",
19
- usersCollectionName: "Members",
20
- databases: [
21
- { $id: "main", name: "Main" },
22
- { $id: "staging", name: "Staging" },
23
- { $id: "dev", name: "Development" },
24
- ],
25
- };
26
-
27
- const collectionsConfig: { name: string; content: string }[] = [
28
- {
29
- name: "ExampleCollection",
30
- content: `import { CollectionCreate } from "appwrite-utils";
31
-
32
- const ExampleCollection: Partial<CollectionCreate> = {
33
- name: 'ExampleCollection',
34
- $permissions: [
35
- { permission: 'read', target: 'any' },
36
- { permission: 'create', target: 'users' },
37
- { permission: 'update', target: 'users' },
38
- { permission: 'delete', target: 'users' }
39
- ],
40
- attributes: [
41
- { key: 'alterEgoName', type: 'string', size: 255, required: false },
42
- // Add more attributes here
43
- ],
44
- indexes: [
45
- { key: 'alterEgoName_search', type: 'fulltext', attributes: ['alterEgoName'] }
46
- ],
47
- importDefs: [
48
- // Define import definitions here
49
- ]
50
- };
51
-
52
- export default ExampleCollection;`,
53
- },
54
- // Add more collections here
55
- ];
56
-
57
- // Define our YAML files
58
- // Define our YAML files
59
- const configFileExample = `d`;
60
-
61
- export const customDefinitionsFile = `import type { ConverterFunctions, ValidationRules, AfterImportActions } from "appwrite-utils";
62
-
63
- export const customConverterFunctions: ConverterFunctions = {
64
- // Add your custom converter functions here
65
- }
66
- export const customValidationRules: ValidationRules = {
67
- // Add your custom validation rules here
68
- }
69
- export const customAfterImportActions: AfterImportActions = {
70
- // Add your custom after import actions here
71
- }`;
72
-
73
- export const createEmptyCollection = (collectionName: string) => {
74
- const emptyCollection = `import type { CollectionCreate } from "appwrite-utils";
75
-
76
- const ${collectionName}: Partial<CollectionCreate> = {
77
- name: '${collectionName}',
78
- $permissions: [
79
- { permission: 'read', target: 'any' },
80
- { permission: 'create', target: 'users' },
81
- { permission: 'update', target: 'users' },
82
- { permission: 'delete', target: 'users' }
83
- ],
84
- attributes: [
85
- // Add more attributes here
86
- ],
87
- indexes: [
88
- // Add more indexes here
89
- ],
90
- };
91
-
92
- export default ${collectionName};`;
93
-
94
- const appwriteConfigPath = findAppwriteConfig(process.cwd());
95
- if (!appwriteConfigPath) {
96
- console.error("Failed to find appwriteConfig.ts");
97
- return;
98
- }
99
-
100
- const collectionsFolder = path.join(
101
- path.dirname(appwriteConfigPath),
102
- "collections"
103
- );
104
- const collectionFilePath = path.join(
105
- collectionsFolder,
106
- `${collectionName}.ts`
107
- );
108
- writeFileSync(collectionFilePath, emptyCollection);
109
- };
110
-
111
- export const setupDirsFiles = async (example: boolean = false) => {
112
- const basePath = process.cwd();
113
- const srcPath = path.join(basePath);
114
-
115
- // Check if src directory exists in the current working directory
116
- if (!existsSync(srcPath)) {
117
- console.error("No 'src' directory found in the current working directory.");
118
- return;
119
- }
120
-
121
- const appwriteFolder = path.join(srcPath, "appwrite");
122
- const appwriteConfigFile = path.join(appwriteFolder, "appwriteConfig.ts");
123
- const appwriteCustomDefsFile = path.join(
124
- appwriteFolder,
125
- "customDefinitions.ts"
126
- );
127
- // const appwriteMigrationsFolder = path.join(appwriteFolder, "migrations");
128
- const appwriteSchemaFolder = path.join(appwriteFolder, "schemas");
129
- const appwriteDataFolder = path.join(appwriteFolder, "importData");
130
- const appwriteHiddenFolder = path.join(appwriteFolder, ".appwrite");
131
- const collectionsFolder = path.join(appwriteFolder, "collections");
132
-
133
- // Directory creation and file writing logic remains the same
134
- if (!existsSync(appwriteFolder)) {
135
- mkdirSync(appwriteFolder, { recursive: true });
136
- }
137
-
138
- if (!existsSync(collectionsFolder)) {
139
- mkdirSync(collectionsFolder, { recursive: true });
140
- }
141
-
142
- if (!existsSync(appwriteConfigFile)) {
143
- if (example) {
144
- writeFileSync(appwriteConfigFile, configFileExample);
145
- } else {
146
- const baseConfigContent = `import { type AppwriteConfig } from "appwrite-utils";
147
-
148
- const appwriteConfig: AppwriteConfig = ${JSON.stringify(baseConfig, null, 2)};
149
-
150
- export default appwriteConfig;
151
- `;
152
- writeFileSync(appwriteConfigFile, baseConfigContent);
153
- }
154
- }
155
-
156
- // Create TypeScript files for each collection
157
- collectionsConfig.forEach((collection) => {
158
- const collectionFilePath = path.join(
159
- collectionsFolder,
160
- `${collection.name}.ts`
161
- );
162
- writeFileSync(collectionFilePath, collection.content);
163
- });
164
-
165
- if (!existsSync(appwriteSchemaFolder)) {
166
- mkdirSync(appwriteSchemaFolder, { recursive: true });
167
- }
168
-
169
- if (!existsSync(appwriteDataFolder)) {
170
- mkdirSync(appwriteDataFolder, { recursive: true });
171
- }
172
-
173
- if (!existsSync(appwriteHiddenFolder)) {
174
- mkdirSync(appwriteHiddenFolder, { recursive: true });
175
- }
176
- const schemaFilePath = path.join(
177
- appwriteHiddenFolder,
178
- "appwriteUtilsConfigSchema.json"
179
- );
180
-
181
- console.log("Created config and setup files/directories successfully.");
182
- };
1
+ import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import type { AppwriteConfig } from "appwrite-utils";
4
+ import { findAppwriteConfig } from "./loadConfigs.js";
5
+ import { ID } from "node-appwrite";
6
+ import { ulid } from "ulidx";
7
+
8
+ // Example base configuration using types from appwrite-utils
9
+ const baseConfig: AppwriteConfig = {
10
+ appwriteEndpoint: "https://cloud.appwrite.io/v1",
11
+ appwriteProject: "YOUR_PROJECT_ID",
12
+ appwriteKey: "YOUR_API_KEY",
13
+ enableBackups: true,
14
+ backupInterval: 3600,
15
+ backupRetention: 30,
16
+ enableBackupCleanup: true,
17
+ enableMockData: false,
18
+ documentBucketId: "documents",
19
+ usersCollectionName: "Members",
20
+ databases: [
21
+ {
22
+ $id: "main",
23
+ name: "Main",
24
+ bucket: {
25
+ $id: "main_bucket",
26
+ name: "Main Bucket",
27
+ enabled: true,
28
+ maximumFileSize: 30000000,
29
+ allowedFileExtensions: [],
30
+ encryption: true,
31
+ antivirus: true,
32
+ },
33
+ },
34
+ {
35
+ $id: "staging",
36
+ name: "Staging",
37
+ bucket: {
38
+ $id: "staging_bucket",
39
+ name: "Staging Bucket",
40
+ enabled: true,
41
+ maximumFileSize: 30000000,
42
+ allowedFileExtensions: [],
43
+ encryption: true,
44
+ antivirus: true,
45
+ },
46
+ },
47
+ {
48
+ $id: "dev",
49
+ name: "Development",
50
+ bucket: {
51
+ $id: "dev_bucket",
52
+ name: "Development Bucket",
53
+ enabled: true,
54
+ maximumFileSize: 30000000,
55
+ allowedFileExtensions: [],
56
+ encryption: true,
57
+ antivirus: true,
58
+ },
59
+ },
60
+ ],
61
+ buckets: [
62
+ {
63
+ $id: "global_bucket",
64
+ name: "Global Bucket",
65
+ enabled: true,
66
+ maximumFileSize: 30000000,
67
+ allowedFileExtensions: [],
68
+ encryption: true,
69
+ antivirus: true,
70
+ },
71
+ ],
72
+ };
73
+
74
+ const collectionsConfig: { name: string; content: string }[] = [
75
+ {
76
+ name: "ExampleCollection",
77
+ content: `import { CollectionCreate } from "appwrite-utils";
78
+
79
+ const ExampleCollection: Partial<CollectionCreate> = {
80
+ name: 'ExampleCollection',
81
+ $permissions: [
82
+ { permission: 'read', target: 'any' },
83
+ { permission: 'create', target: 'users' },
84
+ { permission: 'update', target: 'users' },
85
+ { permission: 'delete', target: 'users' }
86
+ ],
87
+ attributes: [
88
+ { key: 'alterEgoName', type: 'string', size: 255, required: false },
89
+ // Add more attributes here
90
+ ],
91
+ indexes: [
92
+ { key: 'alterEgoName_search', type: 'fulltext', attributes: ['alterEgoName'] }
93
+ ],
94
+ importDefs: [
95
+ // Define import definitions here
96
+ ]
97
+ };
98
+
99
+ export default ExampleCollection;`,
100
+ },
101
+ // Add more collections here
102
+ ];
103
+
104
+ // Define our YAML files
105
+ // Define our YAML files
106
+ const configFileExample = `d`;
107
+
108
+ export const customDefinitionsFile = `import type { ConverterFunctions, ValidationRules, AfterImportActions } from "appwrite-utils";
109
+
110
+ export const customConverterFunctions: ConverterFunctions = {
111
+ // Add your custom converter functions here
112
+ }
113
+ export const customValidationRules: ValidationRules = {
114
+ // Add your custom validation rules here
115
+ }
116
+ export const customAfterImportActions: AfterImportActions = {
117
+ // Add your custom after import actions here
118
+ }`;
119
+
120
+ export const createEmptyCollection = (collectionName: string) => {
121
+ const emptyCollection = `import type { CollectionCreate } from "appwrite-utils";
122
+
123
+ const ${collectionName}: Partial<CollectionCreate> = {
124
+ $id: '${ulid()}',
125
+ documentSecurity: false,
126
+ enabled: true,
127
+ name: '${collectionName}',
128
+ $permissions: [
129
+ { permission: 'read', target: 'any' },
130
+ { permission: 'create', target: 'users' },
131
+ { permission: 'update', target: 'users' },
132
+ { permission: 'delete', target: 'users' }
133
+ ],
134
+ attributes: [
135
+ // Add more attributes here
136
+ ],
137
+ indexes: [
138
+ // Add more indexes here
139
+ ],
140
+ };
141
+
142
+ export default ${collectionName};`;
143
+
144
+ const appwriteConfigPath = findAppwriteConfig(process.cwd());
145
+ if (!appwriteConfigPath) {
146
+ console.error("Failed to find appwriteConfig.ts");
147
+ return;
148
+ }
149
+
150
+ const collectionsFolder = path.join(
151
+ path.dirname(appwriteConfigPath),
152
+ "collections"
153
+ );
154
+ const collectionFilePath = path.join(
155
+ collectionsFolder,
156
+ `${collectionName}.ts`
157
+ );
158
+ writeFileSync(collectionFilePath, emptyCollection);
159
+ };
160
+
161
+ export const setupDirsFiles = async (example: boolean = false) => {
162
+ const basePath = process.cwd();
163
+ const srcPath = path.join(basePath);
164
+
165
+ // Check if src directory exists in the current working directory
166
+ if (!existsSync(srcPath)) {
167
+ console.error("No 'src' directory found in the current working directory.");
168
+ return;
169
+ }
170
+
171
+ const appwriteFolder = path.join(srcPath, "appwrite");
172
+ const appwriteConfigFile = path.join(appwriteFolder, "appwriteConfig.ts");
173
+ const appwriteCustomDefsFile = path.join(
174
+ appwriteFolder,
175
+ "customDefinitions.ts"
176
+ );
177
+ // const appwriteMigrationsFolder = path.join(appwriteFolder, "migrations");
178
+ const appwriteSchemaFolder = path.join(appwriteFolder, "schemas");
179
+ const appwriteDataFolder = path.join(appwriteFolder, "importData");
180
+ const appwriteHiddenFolder = path.join(appwriteFolder, ".appwrite");
181
+ const collectionsFolder = path.join(appwriteFolder, "collections");
182
+
183
+ // Directory creation and file writing logic remains the same
184
+ if (!existsSync(appwriteFolder)) {
185
+ mkdirSync(appwriteFolder, { recursive: true });
186
+ }
187
+
188
+ if (!existsSync(collectionsFolder)) {
189
+ mkdirSync(collectionsFolder, { recursive: true });
190
+ }
191
+
192
+ if (!existsSync(appwriteConfigFile)) {
193
+ if (example) {
194
+ writeFileSync(appwriteConfigFile, configFileExample);
195
+ } else {
196
+ const baseConfigContent = `import { type AppwriteConfig } from "appwrite-utils";
197
+
198
+ const appwriteConfig: AppwriteConfig = ${JSON.stringify(baseConfig, null, 2)};
199
+
200
+ export default appwriteConfig;
201
+ `;
202
+ writeFileSync(appwriteConfigFile, baseConfigContent);
203
+ }
204
+ }
205
+
206
+ // Create TypeScript files for each collection
207
+ collectionsConfig.forEach((collection) => {
208
+ const collectionFilePath = path.join(
209
+ collectionsFolder,
210
+ `${collection.name}.ts`
211
+ );
212
+ writeFileSync(collectionFilePath, collection.content);
213
+ });
214
+
215
+ if (!existsSync(appwriteSchemaFolder)) {
216
+ mkdirSync(appwriteSchemaFolder, { recursive: true });
217
+ }
218
+
219
+ if (!existsSync(appwriteDataFolder)) {
220
+ mkdirSync(appwriteDataFolder, { recursive: true });
221
+ }
222
+
223
+ if (!existsSync(appwriteHiddenFolder)) {
224
+ mkdirSync(appwriteHiddenFolder, { recursive: true });
225
+ }
226
+
227
+ console.log("Created config and setup files/directories successfully.");
228
+ };