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
@@ -1,53 +1,53 @@
|
|
1
|
-
import { indexSchema, type Index } from "appwrite-utils";
|
2
|
-
import { Databases, IndexType, Query, type Models } from "node-appwrite";
|
3
|
-
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
4
|
-
|
5
|
-
export const createOrUpdateIndex = async (
|
6
|
-
dbId: string,
|
7
|
-
db: Databases,
|
8
|
-
collectionId: string,
|
9
|
-
index: Index
|
10
|
-
) => {
|
11
|
-
const existingIndex = await db.listIndexes(dbId, collectionId, [
|
12
|
-
Query.equal("key", index.key),
|
13
|
-
]);
|
14
|
-
let createIndex = false;
|
15
|
-
let newIndex: Models.Index | null = null;
|
16
|
-
if (
|
17
|
-
existingIndex.total > 0 &&
|
18
|
-
existingIndex.indexes.some(
|
19
|
-
(index) =>
|
20
|
-
(index.key === index.key &&
|
21
|
-
index.type === index.type &&
|
22
|
-
index.attributes === index.attributes) ||
|
23
|
-
JSON.stringify(index) === JSON.stringify(index)
|
24
|
-
)
|
25
|
-
) {
|
26
|
-
await db.deleteIndex(dbId, collectionId, existingIndex.indexes[0].key);
|
27
|
-
createIndex = true;
|
28
|
-
}
|
29
|
-
if (createIndex) {
|
30
|
-
newIndex = await db.createIndex(
|
31
|
-
dbId,
|
32
|
-
collectionId,
|
33
|
-
index.key,
|
34
|
-
index.type as IndexType,
|
35
|
-
index.attributes,
|
36
|
-
index.orders
|
37
|
-
);
|
38
|
-
}
|
39
|
-
return newIndex;
|
40
|
-
};
|
41
|
-
|
42
|
-
export const createOrUpdateIndexes = async (
|
43
|
-
dbId: string,
|
44
|
-
db: Databases,
|
45
|
-
collectionId: string,
|
46
|
-
indexes: Index[]
|
47
|
-
) => {
|
48
|
-
for (const index of indexes) {
|
49
|
-
await tryAwaitWithRetry(
|
50
|
-
async () => await createOrUpdateIndex(dbId, db, collectionId, index)
|
51
|
-
);
|
52
|
-
}
|
53
|
-
};
|
1
|
+
import { indexSchema, type Index } from "appwrite-utils";
|
2
|
+
import { Databases, IndexType, Query, type Models } from "node-appwrite";
|
3
|
+
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
4
|
+
|
5
|
+
export const createOrUpdateIndex = async (
|
6
|
+
dbId: string,
|
7
|
+
db: Databases,
|
8
|
+
collectionId: string,
|
9
|
+
index: Index
|
10
|
+
) => {
|
11
|
+
const existingIndex = await db.listIndexes(dbId, collectionId, [
|
12
|
+
Query.equal("key", index.key),
|
13
|
+
]);
|
14
|
+
let createIndex = false;
|
15
|
+
let newIndex: Models.Index | null = null;
|
16
|
+
if (
|
17
|
+
existingIndex.total > 0 &&
|
18
|
+
existingIndex.indexes.some(
|
19
|
+
(index) =>
|
20
|
+
(index.key === index.key &&
|
21
|
+
index.type === index.type &&
|
22
|
+
index.attributes === index.attributes) ||
|
23
|
+
JSON.stringify(index) === JSON.stringify(index)
|
24
|
+
)
|
25
|
+
) {
|
26
|
+
await db.deleteIndex(dbId, collectionId, existingIndex.indexes[0].key);
|
27
|
+
createIndex = true;
|
28
|
+
}
|
29
|
+
if (createIndex) {
|
30
|
+
newIndex = await db.createIndex(
|
31
|
+
dbId,
|
32
|
+
collectionId,
|
33
|
+
index.key,
|
34
|
+
index.type as IndexType,
|
35
|
+
index.attributes,
|
36
|
+
index.orders
|
37
|
+
);
|
38
|
+
}
|
39
|
+
return newIndex;
|
40
|
+
};
|
41
|
+
|
42
|
+
export const createOrUpdateIndexes = async (
|
43
|
+
dbId: string,
|
44
|
+
db: Databases,
|
45
|
+
collectionId: string,
|
46
|
+
indexes: Index[]
|
47
|
+
) => {
|
48
|
+
for (const index of indexes) {
|
49
|
+
await tryAwaitWithRetry(
|
50
|
+
async () => await createOrUpdateIndex(dbId, db, collectionId, index)
|
51
|
+
);
|
52
|
+
}
|
53
|
+
};
|