appwrite-utils-cli 0.9.2 → 0.9.3
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 +2 -1
- package/dist/interactiveCLI.d.ts +3 -2
- package/dist/interactiveCLI.js +18 -13
- package/dist/main.js +18 -3
- package/dist/setupCommands.d.ts +1 -0
- package/dist/setupCommands.js +1 -0
- package/dist/utils/schemaStrings.js +37 -37
- package/dist/utils/setupFiles.d.ts +1 -1
- package/dist/utils/setupFiles.js +2 -2
- package/package.json +53 -53
- package/src/collections/attributes.ts +483 -483
- package/src/collections/indexes.ts +53 -53
- package/src/collections/methods.ts +331 -331
- package/src/interactiveCLI.ts +771 -767
- package/src/main.ts +20 -3
- package/src/migrations/helper.ts +40 -40
- package/src/migrations/transfer.ts +608 -608
- package/src/setupCommands.ts +0 -0
- package/src/storage/methods.ts +371 -371
- package/src/storage/schemas.ts +205 -205
- package/src/utils/getClientFromConfig.ts +17 -17
- package/src/utils/retryFailedPromises.ts +27 -27
- package/src/utils/schemaStrings.ts +473 -473
- package/src/utils/setupFiles.ts +5 -2
package/src/main.ts
CHANGED
@@ -33,6 +33,7 @@ interface CliOptions {
|
|
33
33
|
remoteEndpoint?: string;
|
34
34
|
remoteProjectId?: string;
|
35
35
|
remoteApiKey?: string;
|
36
|
+
setup?: boolean;
|
36
37
|
}
|
37
38
|
|
38
39
|
type ParsedArgv = ArgumentsCamelCase<CliOptions>;
|
@@ -145,18 +146,34 @@ const argv = yargs(hideBin(process.argv))
|
|
145
146
|
type: "string",
|
146
147
|
description: "Set the remote Appwrite API key for transfers",
|
147
148
|
})
|
149
|
+
.option("setup", {
|
150
|
+
type: "boolean",
|
151
|
+
description: "Setup the project with example data",
|
152
|
+
})
|
148
153
|
.help()
|
149
154
|
.parse();
|
150
155
|
|
151
156
|
async function main() {
|
152
157
|
const parsedArgv = (await argv) as ParsedArgv;
|
153
|
-
|
154
|
-
await controller.init();
|
158
|
+
let controller: UtilsController | undefined;
|
155
159
|
|
156
160
|
if (parsedArgv.it) {
|
157
|
-
|
161
|
+
try {
|
162
|
+
controller = new UtilsController(process.cwd());
|
163
|
+
await controller.init();
|
164
|
+
} catch (error: any) {
|
165
|
+
// If it fails, that means there's no config, more than likely
|
166
|
+
console.log(
|
167
|
+
"No config found, you probably need to create the setup files"
|
168
|
+
);
|
169
|
+
}
|
170
|
+
const cli = new InteractiveCLI(process.cwd());
|
158
171
|
await cli.run();
|
159
172
|
} else {
|
173
|
+
if (!controller) {
|
174
|
+
controller = new UtilsController(process.cwd());
|
175
|
+
await controller.init();
|
176
|
+
}
|
160
177
|
// Handle non-interactive mode with the new options
|
161
178
|
const options: SetupOptions = {
|
162
179
|
databases: parsedArgv.dbIds
|
package/src/migrations/helper.ts
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
import type { Databases, Models } from "node-appwrite";
|
2
|
-
import type { OperationCreate } from "../storage/schemas.js";
|
3
|
-
import { tryAwaitWithRetry } from "appwrite-utils";
|
4
|
-
import { ulid } from "ulidx";
|
5
|
-
|
6
|
-
export const logOperation = async (
|
7
|
-
db: Databases,
|
8
|
-
dbId: string,
|
9
|
-
operationDetails: OperationCreate,
|
10
|
-
operationId?: string
|
11
|
-
): Promise<Models.Document> => {
|
12
|
-
try {
|
13
|
-
let operation;
|
14
|
-
if (operationId) {
|
15
|
-
// Update existing operation log
|
16
|
-
operation = await tryAwaitWithRetry(
|
17
|
-
async () =>
|
18
|
-
await db.updateDocument(
|
19
|
-
"migrations",
|
20
|
-
"currentOperations",
|
21
|
-
operationId,
|
22
|
-
operationDetails
|
23
|
-
)
|
24
|
-
);
|
25
|
-
} else {
|
26
|
-
// Create new operation log
|
27
|
-
operation = await db.createDocument(
|
28
|
-
"migrations",
|
29
|
-
"currentOperations",
|
30
|
-
ulid(),
|
31
|
-
operationDetails
|
32
|
-
);
|
33
|
-
}
|
34
|
-
console.log(`Operation logged: ${operation.$id}`);
|
35
|
-
return operation;
|
36
|
-
} catch (error) {
|
37
|
-
console.error(`Error logging operation: ${error}`);
|
38
|
-
throw error;
|
39
|
-
}
|
40
|
-
};
|
1
|
+
import type { Databases, Models } from "node-appwrite";
|
2
|
+
import type { OperationCreate } from "../storage/schemas.js";
|
3
|
+
import { tryAwaitWithRetry } from "appwrite-utils";
|
4
|
+
import { ulid } from "ulidx";
|
5
|
+
|
6
|
+
export const logOperation = async (
|
7
|
+
db: Databases,
|
8
|
+
dbId: string,
|
9
|
+
operationDetails: OperationCreate,
|
10
|
+
operationId?: string
|
11
|
+
): Promise<Models.Document> => {
|
12
|
+
try {
|
13
|
+
let operation;
|
14
|
+
if (operationId) {
|
15
|
+
// Update existing operation log
|
16
|
+
operation = await tryAwaitWithRetry(
|
17
|
+
async () =>
|
18
|
+
await db.updateDocument(
|
19
|
+
"migrations",
|
20
|
+
"currentOperations",
|
21
|
+
operationId,
|
22
|
+
operationDetails
|
23
|
+
)
|
24
|
+
);
|
25
|
+
} else {
|
26
|
+
// Create new operation log
|
27
|
+
operation = await db.createDocument(
|
28
|
+
"migrations",
|
29
|
+
"currentOperations",
|
30
|
+
ulid(),
|
31
|
+
operationDetails
|
32
|
+
);
|
33
|
+
}
|
34
|
+
console.log(`Operation logged: ${operation.$id}`);
|
35
|
+
return operation;
|
36
|
+
} catch (error) {
|
37
|
+
console.error(`Error logging operation: ${error}`);
|
38
|
+
throw error;
|
39
|
+
}
|
40
|
+
};
|