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/storage/schemas.ts
CHANGED
@@ -1,205 +1,205 @@
|
|
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
|
+
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,17 +1,17 @@
|
|
1
|
-
import { type AppwriteConfig } from "appwrite-utils";
|
2
|
-
import { Client } from "node-appwrite";
|
3
|
-
export const getClientFromConfig = (config: AppwriteConfig) => {
|
4
|
-
let appwriteClient: Client | undefined;
|
5
|
-
if (!config.appwriteClient) {
|
6
|
-
appwriteClient = new Client()
|
7
|
-
.setEndpoint(config.appwriteEndpoint)
|
8
|
-
.setProject(config.appwriteProject)
|
9
|
-
.setKey(config.appwriteKey);
|
10
|
-
config.appwriteClient = appwriteClient;
|
11
|
-
}
|
12
|
-
return appwriteClient;
|
13
|
-
};
|
14
|
-
|
15
|
-
export const getClient = (endpoint: string, project: string, key: string) => {
|
16
|
-
return new Client().setEndpoint(endpoint).setProject(project).setKey(key);
|
17
|
-
};
|
1
|
+
import { type AppwriteConfig } from "appwrite-utils";
|
2
|
+
import { Client } from "node-appwrite";
|
3
|
+
export const getClientFromConfig = (config: AppwriteConfig) => {
|
4
|
+
let appwriteClient: Client | undefined;
|
5
|
+
if (!config.appwriteClient) {
|
6
|
+
appwriteClient = new Client()
|
7
|
+
.setEndpoint(config.appwriteEndpoint)
|
8
|
+
.setProject(config.appwriteProject)
|
9
|
+
.setKey(config.appwriteKey);
|
10
|
+
config.appwriteClient = appwriteClient;
|
11
|
+
}
|
12
|
+
return appwriteClient;
|
13
|
+
};
|
14
|
+
|
15
|
+
export const getClient = (endpoint: string, project: string, key: string) => {
|
16
|
+
return new Client().setEndpoint(endpoint).setProject(project).setKey(key);
|
17
|
+
};
|
@@ -1,27 +1,27 @@
|
|
1
|
-
import type { Models } from "node-appwrite";
|
2
|
-
|
3
|
-
export const retryFailedPromises = async (
|
4
|
-
batch: Promise<Models.Document>[],
|
5
|
-
maxRetries = 3
|
6
|
-
): Promise<PromiseSettledResult<Models.Document>[]> => {
|
7
|
-
const results = await Promise.allSettled(batch);
|
8
|
-
const toRetry: Promise<any>[] = [];
|
9
|
-
|
10
|
-
results.forEach((result, index) => {
|
11
|
-
if (result.status === "rejected") {
|
12
|
-
console.error("Promise rejected with reason:", result.reason);
|
13
|
-
if (maxRetries > 0) {
|
14
|
-
toRetry.push(batch[index]);
|
15
|
-
}
|
16
|
-
}
|
17
|
-
});
|
18
|
-
|
19
|
-
if (toRetry.length > 0) {
|
20
|
-
console.log(`Retrying ${toRetry.length} promises`);
|
21
|
-
return retryFailedPromises(toRetry, maxRetries - 1);
|
22
|
-
} else {
|
23
|
-
return results
|
24
|
-
.filter((result) => result.status === "fulfilled")
|
25
|
-
.map((result) => result);
|
26
|
-
}
|
27
|
-
};
|
1
|
+
import type { Models } from "node-appwrite";
|
2
|
+
|
3
|
+
export const retryFailedPromises = async (
|
4
|
+
batch: Promise<Models.Document>[],
|
5
|
+
maxRetries = 3
|
6
|
+
): Promise<PromiseSettledResult<Models.Document>[]> => {
|
7
|
+
const results = await Promise.allSettled(batch);
|
8
|
+
const toRetry: Promise<any>[] = [];
|
9
|
+
|
10
|
+
results.forEach((result, index) => {
|
11
|
+
if (result.status === "rejected") {
|
12
|
+
console.error("Promise rejected with reason:", result.reason);
|
13
|
+
if (maxRetries > 0) {
|
14
|
+
toRetry.push(batch[index]);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
if (toRetry.length > 0) {
|
20
|
+
console.log(`Retrying ${toRetry.length} promises`);
|
21
|
+
return retryFailedPromises(toRetry, maxRetries - 1);
|
22
|
+
} else {
|
23
|
+
return results
|
24
|
+
.filter((result) => result.status === "fulfilled")
|
25
|
+
.map((result) => result);
|
26
|
+
}
|
27
|
+
};
|