appwrite-utils-cli 0.10.85 → 1.0.1
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/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
- package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
- package/.appwrite/collections/Categories.yaml +182 -0
- package/.appwrite/collections/ExampleCollection.yaml +36 -0
- package/.appwrite/collections/Posts.yaml +227 -0
- package/.appwrite/collections/Users.yaml +149 -0
- package/.appwrite/config.yaml +109 -0
- package/.appwrite/import/README.md +148 -0
- package/.appwrite/import/categories-import.yaml +129 -0
- package/.appwrite/import/posts-import.yaml +208 -0
- package/.appwrite/import/users-import.yaml +130 -0
- package/.appwrite/importData/categories.json +194 -0
- package/.appwrite/importData/posts.json +270 -0
- package/.appwrite/importData/users.json +220 -0
- package/.appwrite/schemas/categories.json +128 -0
- package/.appwrite/schemas/exampleCollection.json +52 -0
- package/.appwrite/schemas/posts.json +173 -0
- package/.appwrite/schemas/users.json +125 -0
- package/README.md +261 -33
- package/dist/collections/attributes.js +3 -2
- package/dist/collections/methods.js +56 -38
- package/dist/config/yamlConfig.d.ts +501 -0
- package/dist/config/yamlConfig.js +452 -0
- package/dist/databases/setup.d.ts +6 -0
- package/dist/databases/setup.js +119 -0
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -2
- package/dist/functions/openapi.d.ts +4 -0
- package/dist/functions/openapi.js +60 -0
- package/dist/interactiveCLI.d.ts +5 -0
- package/dist/interactiveCLI.js +196 -52
- package/dist/main.js +91 -30
- package/dist/migrations/afterImportActions.js +2 -2
- package/dist/migrations/appwriteToX.d.ts +10 -0
- package/dist/migrations/appwriteToX.js +15 -4
- package/dist/migrations/backup.d.ts +16 -16
- package/dist/migrations/dataLoader.d.ts +83 -1
- package/dist/migrations/dataLoader.js +4 -4
- package/dist/migrations/importController.js +25 -18
- package/dist/migrations/importDataActions.js +2 -2
- package/dist/migrations/logging.d.ts +9 -1
- package/dist/migrations/logging.js +41 -22
- package/dist/migrations/migrationHelper.d.ts +4 -4
- package/dist/migrations/relationships.js +1 -1
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
- package/dist/migrations/services/ImportOrchestrator.js +488 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +0 -6
- package/dist/migrations/transfer.js +16 -132
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
- package/dist/migrations/yaml/generateImportSchemas.js +575 -0
- package/dist/schemas/authUser.d.ts +9 -9
- package/dist/shared/attributeManager.d.ts +17 -0
- package/dist/shared/attributeManager.js +273 -0
- package/dist/shared/confirmationDialogs.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/functionManager.d.ts +48 -0
- package/dist/shared/functionManager.js +322 -0
- package/dist/shared/indexManager.d.ts +24 -0
- package/dist/shared/indexManager.js +150 -0
- package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
- package/dist/shared/jsonSchemaGenerator.js +313 -0
- package/dist/shared/logging.d.ts +10 -0
- package/dist/shared/logging.js +46 -0
- package/dist/shared/messageFormatter.d.ts +37 -0
- package/dist/shared/messageFormatter.js +152 -0
- package/dist/shared/migrationHelpers.d.ts +173 -0
- package/dist/shared/migrationHelpers.js +142 -0
- package/dist/shared/operationLogger.d.ts +3 -0
- package/dist/shared/operationLogger.js +25 -0
- package/dist/shared/operationQueue.d.ts +13 -0
- package/dist/shared/operationQueue.js +79 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/schemaGenerator.d.ts +18 -0
- package/dist/shared/schemaGenerator.js +523 -0
- package/dist/storage/methods.d.ts +3 -1
- package/dist/storage/methods.js +144 -55
- package/dist/storage/schemas.d.ts +56 -16
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +276 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +156 -0
- package/dist/utils/dataConverters.d.ts +46 -0
- package/dist/utils/dataConverters.js +139 -0
- package/dist/utils/loadConfigs.d.ts +15 -4
- package/dist/utils/loadConfigs.js +377 -51
- package/dist/utils/schemaStrings.js +2 -1
- package/dist/utils/setupFiles.d.ts +2 -1
- package/dist/utils/setupFiles.js +723 -28
- package/dist/utils/validationRules.d.ts +43 -0
- package/dist/utils/validationRules.js +42 -0
- package/dist/utils/yamlConverter.d.ts +48 -0
- package/dist/utils/yamlConverter.js +98 -0
- package/dist/utilsController.js +65 -43
- package/package.json +19 -15
- package/src/collections/attributes.ts +3 -2
- package/src/collections/methods.ts +85 -51
- package/src/config/yamlConfig.ts +488 -0
- package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
- package/src/functions/methods.ts +8 -4
- package/src/functions/templates/count-docs-in-collection/package.json +25 -0
- package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
- package/src/functions/templates/typescript-node/package.json +24 -0
- package/src/functions/templates/typescript-node/tsconfig.json +28 -0
- package/src/functions/templates/uv/README.md +31 -0
- package/src/functions/templates/uv/pyproject.toml +29 -0
- package/src/interactiveCLI.ts +230 -63
- package/src/main.ts +111 -37
- package/src/migrations/afterImportActions.ts +2 -2
- package/src/migrations/appwriteToX.ts +17 -4
- package/src/migrations/dataLoader.ts +4 -4
- package/src/migrations/importController.ts +30 -22
- package/src/migrations/importDataActions.ts +2 -2
- package/src/migrations/relationships.ts +1 -1
- package/src/migrations/services/DataTransformationService.ts +196 -0
- package/src/migrations/services/FileHandlerService.ts +311 -0
- package/src/migrations/services/ImportOrchestrator.ts +669 -0
- package/src/migrations/services/RateLimitManager.ts +363 -0
- package/src/migrations/services/RelationshipResolver.ts +461 -0
- package/src/migrations/services/UserMappingService.ts +345 -0
- package/src/migrations/services/ValidationService.ts +349 -0
- package/src/migrations/transfer.ts +22 -228
- package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
- package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
- package/src/migrations/yaml/generateImportSchemas.ts +589 -0
- package/src/shared/attributeManager.ts +429 -0
- package/src/shared/confirmationDialogs.ts +327 -0
- package/src/shared/functionManager.ts +515 -0
- package/src/shared/indexManager.ts +253 -0
- package/src/shared/jsonSchemaGenerator.ts +403 -0
- package/src/shared/logging.ts +74 -0
- package/src/shared/messageFormatter.ts +195 -0
- package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
- package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
- package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
- package/src/shared/progressManager.ts +278 -0
- package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
- package/src/storage/methods.ts +199 -78
- package/src/types.ts +2 -2
- package/src/{migrations/users.ts → users/methods.ts} +2 -2
- package/src/utils/configMigration.ts +212 -0
- package/src/utils/loadConfigs.ts +414 -52
- package/src/utils/schemaStrings.ts +2 -1
- package/src/utils/setupFiles.ts +742 -40
- package/src/{migrations → utils}/validationRules.ts +1 -1
- package/src/utils/yamlConverter.ts +131 -0
- package/src/utilsController.ts +75 -54
- package/src/functions/templates/poetry/README.md +0 -30
- package/src/functions/templates/poetry/pyproject.toml +0 -16
- package/src/migrations/attributes.ts +0 -561
- package/src/migrations/backup.ts +0 -205
- package/src/migrations/databases.ts +0 -39
- package/src/migrations/dbHelpers.ts +0 -92
- package/src/migrations/indexes.ts +0 -40
- package/src/migrations/logging.ts +0 -29
- package/src/migrations/storage.ts +0 -538
- /package/src/{migrations → functions}/openapi.ts +0 -0
- /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
- /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
- /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
package/src/migrations/backup.ts
DELETED
@@ -1,205 +0,0 @@
|
|
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,39 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Client,
|
3
|
-
Databases,
|
4
|
-
IndexType,
|
5
|
-
Query,
|
6
|
-
type Models,
|
7
|
-
} from "node-appwrite";
|
8
|
-
import {
|
9
|
-
getAppwriteClient,
|
10
|
-
tryAwaitWithRetry,
|
11
|
-
} from "../utils/helperFunctions.js";
|
12
|
-
|
13
|
-
export const fetchAllDatabases = async (
|
14
|
-
database: Databases
|
15
|
-
): Promise<Models.Database[]> => {
|
16
|
-
const databases = await tryAwaitWithRetry(
|
17
|
-
async () => await database.list([Query.limit(25)])
|
18
|
-
);
|
19
|
-
if (!databases) return [];
|
20
|
-
const allDatabases = databases.databases;
|
21
|
-
if (allDatabases.length === 0) return [];
|
22
|
-
let lastDatabaseId = allDatabases[allDatabases.length - 1].$id;
|
23
|
-
if (databases.databases.length < 25) {
|
24
|
-
return allDatabases;
|
25
|
-
} else {
|
26
|
-
while (lastDatabaseId) {
|
27
|
-
const databases = await database.list([
|
28
|
-
Query.limit(25),
|
29
|
-
Query.cursorAfter(lastDatabaseId),
|
30
|
-
]);
|
31
|
-
allDatabases.push(...databases.databases);
|
32
|
-
if (databases.databases.length < 25) {
|
33
|
-
break;
|
34
|
-
}
|
35
|
-
lastDatabaseId = databases.databases[databases.databases.length - 1].$id;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
return allDatabases;
|
39
|
-
};
|
@@ -1,92 +0,0 @@
|
|
1
|
-
import type {
|
2
|
-
AppwriteConfig,
|
3
|
-
Attribute,
|
4
|
-
RelationshipAttribute,
|
5
|
-
} from "appwrite-utils";
|
6
|
-
|
7
|
-
// Helper function to categorize collections based on relationship sides
|
8
|
-
export const categorizeCollectionByRelationshipSide = (
|
9
|
-
attributes: Attribute[]
|
10
|
-
): "parent" | "mixed" | "child" => {
|
11
|
-
let hasParent = false;
|
12
|
-
let hasChild = false;
|
13
|
-
|
14
|
-
for (const attr of attributes) {
|
15
|
-
if (attr.type === "relationship") {
|
16
|
-
if (attr.side === "parent") {
|
17
|
-
hasParent = true;
|
18
|
-
} else if (attr.side === "child") {
|
19
|
-
hasChild = true;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
if (hasParent && hasChild) return "mixed";
|
25
|
-
if (hasParent) return "parent";
|
26
|
-
return "child";
|
27
|
-
};
|
28
|
-
|
29
|
-
// Helper function to get all dependencies of a collection
|
30
|
-
export const getDependencies = (attributes: Attribute[]): string[] => {
|
31
|
-
return attributes
|
32
|
-
.filter(
|
33
|
-
(attr) =>
|
34
|
-
attr.type === "relationship" && attr.relatedCollection !== undefined
|
35
|
-
)
|
36
|
-
.map((attr) => (attr as RelationshipAttribute).relatedCollection);
|
37
|
-
};
|
38
|
-
|
39
|
-
// Function to sort collections based on dependencies and relationship sides
|
40
|
-
export const sortCollections = (
|
41
|
-
configCollections: AppwriteConfig["collections"]
|
42
|
-
): AppwriteConfig["collections"] => {
|
43
|
-
if (!configCollections) {
|
44
|
-
return [];
|
45
|
-
}
|
46
|
-
// Categorize collections based on their relationship sides
|
47
|
-
const parentCollections = configCollections.filter(
|
48
|
-
({ attributes }) =>
|
49
|
-
categorizeCollectionByRelationshipSide(attributes) === "parent"
|
50
|
-
);
|
51
|
-
const mixedCollections = configCollections.filter(
|
52
|
-
({ attributes }) =>
|
53
|
-
categorizeCollectionByRelationshipSide(attributes) === "mixed"
|
54
|
-
);
|
55
|
-
const childCollections = configCollections.filter(
|
56
|
-
({ attributes }) =>
|
57
|
-
categorizeCollectionByRelationshipSide(attributes) === "child"
|
58
|
-
);
|
59
|
-
|
60
|
-
// Sort mixedCollections to ensure parents are processed before children within the mixed category
|
61
|
-
// This might involve more sophisticated logic if you need to order mixed collections based on specific parent-child relationships
|
62
|
-
mixedCollections.sort((a, b) => {
|
63
|
-
// Example sorting logic for mixed collections; adjust based on your specific needs
|
64
|
-
const aDependencies = getDependencies(a.attributes).length;
|
65
|
-
const bDependencies = getDependencies(b.attributes).length;
|
66
|
-
return aDependencies - bDependencies;
|
67
|
-
});
|
68
|
-
|
69
|
-
// Combine them back into a single array with the desired order
|
70
|
-
// Children first because they have no dependencies and parents will create the relationship if it's twoWay
|
71
|
-
return [...childCollections, ...parentCollections, ...mixedCollections];
|
72
|
-
};
|
73
|
-
|
74
|
-
// Function to sort attributes within a collection based on relationship sides
|
75
|
-
export const sortAttributesByRelationshipSide = (
|
76
|
-
attributes: Attribute[]
|
77
|
-
): Attribute[] => {
|
78
|
-
// Separate attributes into parent and child based on their relationship side
|
79
|
-
const parentAttributes = attributes.filter(
|
80
|
-
(attr) => attr.type === "relationship" && attr.side === "parent"
|
81
|
-
);
|
82
|
-
const childAttributes = attributes.filter(
|
83
|
-
(attr) => attr.type === "relationship" && attr.side === "child"
|
84
|
-
);
|
85
|
-
const otherAttributes = attributes.filter(
|
86
|
-
(attr) => attr.type !== "relationship"
|
87
|
-
);
|
88
|
-
|
89
|
-
// Combine them back into a single array with child attributes first, then other attributes, and parent attributes last
|
90
|
-
// as parent attributes will create the relationship with the child if needed
|
91
|
-
return [...childAttributes, ...otherAttributes, ...parentAttributes];
|
92
|
-
};
|
@@ -1,40 +0,0 @@
|
|
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
|
-
// import {}
|
5
|
-
|
6
|
-
export const createOrUpdateIndex = async (
|
7
|
-
dbId: string,
|
8
|
-
db: Databases,
|
9
|
-
collectionId: string,
|
10
|
-
index: Index
|
11
|
-
) => {
|
12
|
-
const existingIndex = await db.listIndexes(dbId, collectionId, [
|
13
|
-
Query.equal("key", index.key),
|
14
|
-
]);
|
15
|
-
if (existingIndex.total > 0) {
|
16
|
-
await db.deleteIndex(dbId, collectionId, existingIndex.indexes[0].key);
|
17
|
-
}
|
18
|
-
const newIndex = await db.createIndex(
|
19
|
-
dbId,
|
20
|
-
collectionId,
|
21
|
-
index.key,
|
22
|
-
index.type as IndexType,
|
23
|
-
index.attributes,
|
24
|
-
index.orders
|
25
|
-
);
|
26
|
-
return newIndex;
|
27
|
-
};
|
28
|
-
|
29
|
-
export const createOrUpdateIndexes = async (
|
30
|
-
dbId: string,
|
31
|
-
db: Databases,
|
32
|
-
collectionId: string,
|
33
|
-
indexes: Index[]
|
34
|
-
) => {
|
35
|
-
for (const index of indexes) {
|
36
|
-
await tryAwaitWithRetry(
|
37
|
-
async () => await createOrUpdateIndex(dbId, db, collectionId, index)
|
38
|
-
);
|
39
|
-
}
|
40
|
-
};
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import winston from "winston";
|
2
|
-
import fs from "fs";
|
3
|
-
import path from "path";
|
4
|
-
|
5
|
-
// Ensure the logs directory exists
|
6
|
-
const logDir = path.join(process.cwd(), "zlogs");
|
7
|
-
if (!fs.existsSync(logDir)) {
|
8
|
-
fs.mkdirSync(logDir);
|
9
|
-
}
|
10
|
-
|
11
|
-
export const logger = winston.createLogger({
|
12
|
-
level: "debug",
|
13
|
-
format: winston.format.json({ space: 2 }),
|
14
|
-
defaultMeta: { service: "appwrite-utils-cli" },
|
15
|
-
transports: [
|
16
|
-
new winston.transports.File({
|
17
|
-
filename: path.join(logDir, "error.log"),
|
18
|
-
level: "error",
|
19
|
-
}),
|
20
|
-
new winston.transports.File({
|
21
|
-
filename: path.join(logDir, "warn.log"),
|
22
|
-
level: "warn",
|
23
|
-
}),
|
24
|
-
new winston.transports.File({
|
25
|
-
filename: path.join(logDir, "info.log"),
|
26
|
-
level: "info",
|
27
|
-
}),
|
28
|
-
],
|
29
|
-
});
|