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.
- package/README.md +162 -96
- package/dist/collections/attributes.d.ts +4 -0
- package/dist/collections/attributes.js +224 -0
- package/dist/collections/indexes.d.ts +4 -0
- package/dist/collections/indexes.js +27 -0
- package/dist/collections/methods.d.ts +16 -0
- package/dist/collections/methods.js +216 -0
- package/dist/databases/methods.d.ts +6 -0
- package/dist/databases/methods.js +33 -0
- package/dist/interactiveCLI.d.ts +19 -0
- package/dist/interactiveCLI.js +555 -0
- package/dist/main.js +224 -62
- package/dist/migrations/afterImportActions.js +37 -40
- package/dist/migrations/appwriteToX.d.ts +26 -25
- package/dist/migrations/appwriteToX.js +42 -6
- package/dist/migrations/attributes.js +21 -20
- package/dist/migrations/backup.d.ts +93 -87
- package/dist/migrations/collections.d.ts +6 -0
- package/dist/migrations/collections.js +149 -20
- package/dist/migrations/converters.d.ts +2 -18
- package/dist/migrations/converters.js +13 -2
- package/dist/migrations/dataLoader.d.ts +276 -161
- package/dist/migrations/dataLoader.js +535 -292
- package/dist/migrations/databases.js +8 -2
- package/dist/migrations/helper.d.ts +3 -0
- package/dist/migrations/helper.js +21 -0
- package/dist/migrations/importController.d.ts +5 -2
- package/dist/migrations/importController.js +125 -88
- package/dist/migrations/importDataActions.d.ts +9 -1
- package/dist/migrations/importDataActions.js +15 -3
- package/dist/migrations/indexes.js +3 -2
- package/dist/migrations/logging.js +20 -8
- package/dist/migrations/migrationHelper.d.ts +9 -4
- package/dist/migrations/migrationHelper.js +6 -5
- package/dist/migrations/openapi.d.ts +1 -1
- package/dist/migrations/openapi.js +33 -18
- package/dist/migrations/queue.js +3 -2
- package/dist/migrations/relationships.d.ts +2 -2
- package/dist/migrations/schemaStrings.js +53 -41
- package/dist/migrations/setupDatabase.d.ts +2 -4
- package/dist/migrations/setupDatabase.js +24 -105
- package/dist/migrations/storage.d.ts +3 -1
- package/dist/migrations/storage.js +110 -16
- package/dist/migrations/transfer.d.ts +30 -0
- package/dist/migrations/transfer.js +337 -0
- package/dist/migrations/users.d.ts +2 -1
- package/dist/migrations/users.js +78 -43
- package/dist/schemas/authUser.d.ts +2 -2
- package/dist/storage/methods.d.ts +15 -0
- package/dist/storage/methods.js +207 -0
- package/dist/storage/schemas.d.ts +687 -0
- package/dist/storage/schemas.js +175 -0
- package/dist/utils/getClientFromConfig.d.ts +4 -0
- package/dist/utils/getClientFromConfig.js +16 -0
- package/dist/utils/helperFunctions.d.ts +11 -1
- package/dist/utils/helperFunctions.js +38 -0
- package/dist/utils/retryFailedPromises.d.ts +2 -0
- package/dist/utils/retryFailedPromises.js +21 -0
- package/dist/utils/schemaStrings.d.ts +13 -0
- package/dist/utils/schemaStrings.js +403 -0
- package/dist/utils/setupFiles.js +110 -61
- package/dist/utilsController.d.ts +40 -22
- package/dist/utilsController.js +164 -84
- package/package.json +13 -15
- package/src/collections/attributes.ts +483 -0
- package/src/collections/indexes.ts +53 -0
- package/src/collections/methods.ts +331 -0
- package/src/databases/methods.ts +47 -0
- package/src/init.ts +64 -64
- package/src/interactiveCLI.ts +767 -0
- package/src/main.ts +289 -83
- package/src/migrations/afterImportActions.ts +553 -490
- package/src/migrations/appwriteToX.ts +237 -174
- package/src/migrations/attributes.ts +483 -422
- package/src/migrations/backup.ts +205 -205
- package/src/migrations/collections.ts +545 -300
- package/src/migrations/converters.ts +161 -150
- package/src/migrations/dataLoader.ts +1615 -1304
- package/src/migrations/databases.ts +44 -25
- package/src/migrations/dbHelpers.ts +92 -92
- package/src/migrations/helper.ts +40 -0
- package/src/migrations/importController.ts +448 -384
- package/src/migrations/importDataActions.ts +315 -307
- package/src/migrations/indexes.ts +40 -37
- package/src/migrations/logging.ts +29 -16
- package/src/migrations/migrationHelper.ts +207 -201
- package/src/migrations/openapi.ts +83 -70
- package/src/migrations/queue.ts +118 -119
- package/src/migrations/relationships.ts +324 -324
- package/src/migrations/schemaStrings.ts +472 -460
- package/src/migrations/setupDatabase.ts +118 -219
- package/src/migrations/storage.ts +538 -358
- package/src/migrations/transfer.ts +608 -0
- package/src/migrations/users.ts +362 -285
- package/src/migrations/validationRules.ts +63 -63
- package/src/schemas/authUser.ts +23 -23
- package/src/setup.ts +8 -8
- package/src/storage/methods.ts +371 -0
- package/src/storage/schemas.ts +205 -0
- package/src/types.ts +9 -9
- package/src/utils/getClientFromConfig.ts +17 -0
- package/src/utils/helperFunctions.ts +181 -127
- package/src/utils/index.ts +2 -2
- package/src/utils/loadConfigs.ts +59 -59
- package/src/utils/retryFailedPromises.ts +27 -0
- package/src/utils/schemaStrings.ts +473 -0
- package/src/utils/setupFiles.ts +228 -182
- package/src/utilsController.ts +325 -194
- package/tsconfig.json +37 -37
package/src/utils/setupFiles.ts
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
documentBucketId: "documents",
|
19
|
-
usersCollectionName: "Members",
|
20
|
-
databases: [
|
21
|
-
{
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
]
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
{ permission: '
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
],
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
const
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
if
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
);
|
180
|
-
|
181
|
-
|
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
|
+
};
|