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/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
- const controller = new UtilsController(process.cwd());
154
- await controller.init();
158
+ let controller: UtilsController | undefined;
155
159
 
156
160
  if (parsedArgv.it) {
157
- const cli = new InteractiveCLI(process.cwd(), controller);
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
@@ -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
+ };