appwrite-utils-cli 1.7.8 → 1.8.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/CHANGELOG.md +14 -199
- package/README.md +87 -30
- package/dist/adapters/AdapterFactory.js +5 -25
- package/dist/adapters/DatabaseAdapter.d.ts +17 -2
- package/dist/adapters/LegacyAdapter.d.ts +2 -1
- package/dist/adapters/LegacyAdapter.js +212 -16
- package/dist/adapters/TablesDBAdapter.d.ts +2 -12
- package/dist/adapters/TablesDBAdapter.js +261 -57
- package/dist/cli/commands/databaseCommands.js +10 -10
- package/dist/cli/commands/functionCommands.js +17 -8
- package/dist/collections/attributes.js +447 -125
- package/dist/collections/methods.js +197 -186
- package/dist/collections/tableOperations.d.ts +86 -0
- package/dist/collections/tableOperations.js +434 -0
- package/dist/collections/transferOperations.d.ts +3 -2
- package/dist/collections/transferOperations.js +93 -12
- package/dist/config/services/ConfigLoaderService.d.ts +7 -0
- package/dist/config/services/ConfigLoaderService.js +47 -1
- package/dist/config/yamlConfig.d.ts +221 -88
- package/dist/examples/yamlTerminologyExample.d.ts +1 -1
- package/dist/examples/yamlTerminologyExample.js +6 -3
- package/dist/functions/deployments.js +5 -23
- package/dist/functions/fnConfigDiscovery.d.ts +3 -0
- package/dist/functions/fnConfigDiscovery.js +108 -0
- package/dist/functions/methods.js +4 -2
- package/dist/functions/pathResolution.d.ts +37 -0
- package/dist/functions/pathResolution.js +185 -0
- package/dist/functions/templates/count-docs-in-collection/README.md +54 -0
- package/dist/functions/templates/count-docs-in-collection/package.json +25 -0
- package/dist/functions/templates/count-docs-in-collection/src/main.ts +159 -0
- package/dist/functions/templates/count-docs-in-collection/src/request.ts +9 -0
- package/dist/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
- package/dist/functions/templates/hono-typescript/README.md +286 -0
- package/dist/functions/templates/hono-typescript/package.json +26 -0
- package/dist/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/dist/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/dist/functions/templates/hono-typescript/src/app.ts +180 -0
- package/dist/functions/templates/hono-typescript/src/context.ts +103 -0
- package/dist/functions/templates/hono-typescript/src/index.ts +54 -0
- package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/dist/functions/templates/hono-typescript/tsconfig.json +20 -0
- package/dist/functions/templates/typescript-node/README.md +32 -0
- package/dist/functions/templates/typescript-node/package.json +25 -0
- package/dist/functions/templates/typescript-node/src/context.ts +103 -0
- package/dist/functions/templates/typescript-node/src/index.ts +29 -0
- package/dist/functions/templates/typescript-node/tsconfig.json +28 -0
- package/dist/functions/templates/uv/README.md +31 -0
- package/dist/functions/templates/uv/pyproject.toml +30 -0
- package/dist/functions/templates/uv/src/__init__.py +0 -0
- package/dist/functions/templates/uv/src/context.py +125 -0
- package/dist/functions/templates/uv/src/index.py +46 -0
- package/dist/interactiveCLI.js +18 -15
- package/dist/main.js +219 -81
- package/dist/migrations/appwriteToX.d.ts +88 -23
- package/dist/migrations/comprehensiveTransfer.d.ts +2 -0
- package/dist/migrations/comprehensiveTransfer.js +83 -6
- package/dist/migrations/dataLoader.d.ts +227 -69
- package/dist/migrations/dataLoader.js +3 -3
- package/dist/migrations/importController.js +3 -3
- package/dist/migrations/relationships.d.ts +8 -2
- package/dist/migrations/services/ImportOrchestrator.js +3 -3
- package/dist/migrations/transfer.js +159 -37
- package/dist/shared/attributeMapper.d.ts +20 -0
- package/dist/shared/attributeMapper.js +203 -0
- package/dist/shared/selectionDialogs.d.ts +1 -1
- package/dist/shared/selectionDialogs.js +39 -11
- package/dist/storage/schemas.d.ts +354 -92
- package/dist/utils/configDiscovery.js +4 -3
- package/dist/utils/versionDetection.d.ts +0 -4
- package/dist/utils/versionDetection.js +41 -173
- package/dist/utils/yamlConverter.js +89 -16
- package/dist/utils/yamlLoader.d.ts +1 -1
- package/dist/utils/yamlLoader.js +6 -2
- package/dist/utilsController.d.ts +2 -1
- package/dist/utilsController.js +151 -22
- package/package.json +7 -5
- package/scripts/copy-templates.ts +23 -0
- package/src/adapters/AdapterFactory.ts +119 -143
- package/src/adapters/DatabaseAdapter.ts +18 -3
- package/src/adapters/LegacyAdapter.ts +236 -105
- package/src/adapters/TablesDBAdapter.ts +773 -643
- package/src/cli/commands/databaseCommands.ts +19 -19
- package/src/cli/commands/functionCommands.ts +23 -14
- package/src/collections/attributes.ts +2054 -1611
- package/src/collections/methods.ts +208 -293
- package/src/collections/tableOperations.ts +506 -0
- package/src/collections/transferOperations.ts +218 -144
- package/src/config/services/ConfigLoaderService.ts +62 -1
- package/src/examples/yamlTerminologyExample.ts +10 -5
- package/src/functions/deployments.ts +10 -35
- package/src/functions/fnConfigDiscovery.ts +103 -0
- package/src/functions/methods.ts +4 -2
- package/src/functions/pathResolution.ts +227 -0
- package/src/interactiveCLI.ts +25 -20
- package/src/main.ts +557 -202
- package/src/migrations/comprehensiveTransfer.ts +126 -50
- package/src/migrations/dataLoader.ts +3 -3
- package/src/migrations/importController.ts +3 -3
- package/src/migrations/services/ImportOrchestrator.ts +3 -3
- package/src/migrations/transfer.ts +148 -131
- package/src/shared/attributeMapper.ts +229 -0
- package/src/shared/selectionDialogs.ts +65 -32
- package/src/utils/configDiscovery.ts +9 -3
- package/src/utils/versionDetection.ts +74 -228
- package/src/utils/yamlConverter.ts +94 -17
- package/src/utils/yamlLoader.ts +11 -4
- package/src/utilsController.ts +202 -36
- package/dist/utils/schemaStrings.d.ts +0 -14
- package/dist/utils/schemaStrings.js +0 -428
- package/dist/utils/sessionPreservationExample.d.ts +0 -1666
- package/dist/utils/sessionPreservationExample.js +0 -101
|
@@ -1,120 +1,177 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Client,
|
|
3
|
-
Databases,
|
|
4
|
-
ID,
|
|
5
|
-
Query,
|
|
6
|
-
} from "node-appwrite";
|
|
7
|
-
import { tryAwaitWithRetry, delay, calculateExponentialBackoff } from "../utils/helperFunctions.js";
|
|
8
|
-
import { MessageFormatter } from "../shared/messageFormatter.js";
|
|
9
|
-
import { chunk } from "es-toolkit";
|
|
1
|
+
import {
|
|
2
|
+
Client,
|
|
3
|
+
Databases,
|
|
4
|
+
ID,
|
|
5
|
+
Query,
|
|
6
|
+
} from "node-appwrite";
|
|
7
|
+
import { tryAwaitWithRetry, delay, calculateExponentialBackoff } from "../utils/helperFunctions.js";
|
|
8
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
|
9
|
+
import { chunk } from "es-toolkit";
|
|
10
|
+
import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js";
|
|
11
|
+
import { isLegacyDatabases } from "../utils/typeGuards.js";
|
|
12
|
+
import { getAdapter } from "../utils/getClientFromConfig.js";
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Transfers all documents from one collection to another in a different database
|
|
13
16
|
* within the same Appwrite Project
|
|
14
17
|
*/
|
|
15
|
-
export const transferDocumentsBetweenDbsLocalToLocal = async (
|
|
16
|
-
db: Databases,
|
|
17
|
-
fromDbId: string,
|
|
18
|
-
toDbId: string,
|
|
19
|
-
fromCollId: string,
|
|
20
|
-
toCollId: string
|
|
21
|
-
) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
18
|
+
export const transferDocumentsBetweenDbsLocalToLocal = async (
|
|
19
|
+
db: Databases | DatabaseAdapter,
|
|
20
|
+
fromDbId: string,
|
|
21
|
+
toDbId: string,
|
|
22
|
+
fromCollId: string,
|
|
23
|
+
toCollId: string
|
|
24
|
+
) => {
|
|
25
|
+
// Use adapter path when available for bulk operations
|
|
26
|
+
if (!isLegacyDatabases(db)) {
|
|
27
|
+
const adapter = db as DatabaseAdapter;
|
|
28
|
+
|
|
29
|
+
const pageSize = 1000;
|
|
30
|
+
let lastId: string | undefined;
|
|
31
|
+
let totalTransferred = 0;
|
|
32
|
+
|
|
33
|
+
while (true) {
|
|
34
|
+
const queries = [Query.limit(pageSize)];
|
|
35
|
+
if (lastId) queries.push(Query.cursorAfter(lastId));
|
|
36
|
+
|
|
37
|
+
const result = await adapter.listRows({ databaseId: fromDbId, tableId: fromCollId, queries });
|
|
38
|
+
const rows: any[] = (result as any).rows || (result as any).documents || [];
|
|
39
|
+
if (!rows.length) break;
|
|
40
|
+
|
|
41
|
+
// Prepare rows: strip system fields, keep $id and $permissions
|
|
42
|
+
const prepared = rows.map((doc) => {
|
|
43
|
+
const data: any = { ...doc };
|
|
44
|
+
delete data.$databaseId;
|
|
45
|
+
delete data.$collectionId;
|
|
46
|
+
delete data.$createdAt;
|
|
47
|
+
delete data.$updatedAt;
|
|
48
|
+
return data; // keep $id and $permissions for upsert
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Prefer bulk upsert, then bulk create, then individual
|
|
52
|
+
if (typeof (adapter as any).bulkUpsertRows === 'function' && adapter.supportsBulkOperations()) {
|
|
53
|
+
await (adapter as any).bulkUpsertRows({ databaseId: toDbId, tableId: toCollId, rows: prepared });
|
|
54
|
+
} else if (typeof (adapter as any).bulkCreateRows === 'function' && adapter.supportsBulkOperations()) {
|
|
55
|
+
await (adapter as any).bulkCreateRows({ databaseId: toDbId, tableId: toCollId, rows: prepared });
|
|
56
|
+
} else {
|
|
57
|
+
for (const row of prepared) {
|
|
58
|
+
const id = row.$id || ID.unique();
|
|
59
|
+
const permissions = row.$permissions || [];
|
|
60
|
+
const { $id, $permissions, ...data } = row;
|
|
61
|
+
await adapter.createRow({ databaseId: toDbId, tableId: toCollId, id, data, permissions });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
totalTransferred += rows.length;
|
|
66
|
+
if (rows.length < pageSize) break;
|
|
67
|
+
lastId = rows[rows.length - 1].$id;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
MessageFormatter.success(
|
|
71
|
+
`Transferred ${totalTransferred} rows from ${fromDbId}/${fromCollId} to ${toDbId}/${toCollId}`,
|
|
72
|
+
{ prefix: "Transfer" }
|
|
73
|
+
);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Legacy path (Databases) – keep existing behavior
|
|
78
|
+
const legacyDb = db as Databases;
|
|
79
|
+
let fromCollDocs = await tryAwaitWithRetry(async () =>
|
|
80
|
+
legacyDb.listDocuments(fromDbId, fromCollId, [Query.limit(50)])
|
|
81
|
+
);
|
|
82
|
+
let totalDocumentsTransferred = 0;
|
|
83
|
+
|
|
84
|
+
if (fromCollDocs.documents.length === 0) {
|
|
85
|
+
MessageFormatter.info(`No documents found in collection ${fromCollId}`, { prefix: "Transfer" });
|
|
86
|
+
return;
|
|
87
|
+
} else if (fromCollDocs.documents.length < 50) {
|
|
88
|
+
const batchedPromises = fromCollDocs.documents.map((doc) => {
|
|
89
|
+
const toCreateObject: any = {
|
|
90
|
+
...doc,
|
|
91
|
+
};
|
|
92
|
+
delete toCreateObject.$databaseId;
|
|
93
|
+
delete toCreateObject.$collectionId;
|
|
94
|
+
delete toCreateObject.$createdAt;
|
|
95
|
+
delete toCreateObject.$updatedAt;
|
|
96
|
+
delete toCreateObject.$id;
|
|
97
|
+
delete toCreateObject.$permissions;
|
|
98
|
+
return tryAwaitWithRetry(
|
|
99
|
+
async () =>
|
|
100
|
+
await legacyDb.createDocument(
|
|
101
|
+
toDbId,
|
|
102
|
+
toCollId,
|
|
103
|
+
doc.$id,
|
|
104
|
+
toCreateObject,
|
|
105
|
+
doc.$permissions
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
await Promise.all(batchedPromises);
|
|
110
|
+
totalDocumentsTransferred += fromCollDocs.documents.length;
|
|
111
|
+
} else {
|
|
112
|
+
const batchedPromises = fromCollDocs.documents.map((doc) => {
|
|
113
|
+
const toCreateObject: any = {
|
|
114
|
+
...doc,
|
|
115
|
+
};
|
|
116
|
+
delete toCreateObject.$databaseId;
|
|
117
|
+
delete toCreateObject.$collectionId;
|
|
118
|
+
delete toCreateObject.$createdAt;
|
|
119
|
+
delete toCreateObject.$updatedAt;
|
|
120
|
+
delete toCreateObject.$id;
|
|
121
|
+
delete toCreateObject.$permissions;
|
|
122
|
+
return tryAwaitWithRetry(async () =>
|
|
123
|
+
legacyDb.createDocument(
|
|
124
|
+
toDbId,
|
|
125
|
+
toCollId,
|
|
126
|
+
doc.$id,
|
|
127
|
+
toCreateObject,
|
|
128
|
+
doc.$permissions
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
await Promise.all(batchedPromises);
|
|
133
|
+
totalDocumentsTransferred += fromCollDocs.documents.length;
|
|
134
|
+
while (fromCollDocs.documents.length === 50) {
|
|
135
|
+
fromCollDocs = await tryAwaitWithRetry(
|
|
136
|
+
async () =>
|
|
137
|
+
await legacyDb.listDocuments(fromDbId, fromCollId, [
|
|
138
|
+
Query.limit(50),
|
|
139
|
+
Query.cursorAfter(
|
|
140
|
+
fromCollDocs.documents[fromCollDocs.documents.length - 1].$id
|
|
141
|
+
),
|
|
142
|
+
])
|
|
143
|
+
);
|
|
144
|
+
const batchedPromises = fromCollDocs.documents.map((doc) => {
|
|
145
|
+
const toCreateObject: any = {
|
|
146
|
+
...doc,
|
|
147
|
+
};
|
|
148
|
+
delete toCreateObject.$databaseId;
|
|
149
|
+
delete toCreateObject.$collectionId;
|
|
150
|
+
delete toCreateObject.$createdAt;
|
|
151
|
+
delete toCreateObject.$updatedAt;
|
|
152
|
+
delete toCreateObject.$id;
|
|
153
|
+
delete toCreateObject.$permissions;
|
|
154
|
+
return tryAwaitWithRetry(
|
|
155
|
+
async () =>
|
|
156
|
+
await legacyDb.createDocument(
|
|
157
|
+
toDbId,
|
|
158
|
+
toCollId,
|
|
159
|
+
doc.$id,
|
|
160
|
+
toCreateObject,
|
|
161
|
+
doc.$permissions
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
await Promise.all(batchedPromises);
|
|
166
|
+
totalDocumentsTransferred += fromCollDocs.documents.length;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
MessageFormatter.success(
|
|
171
|
+
`Transferred ${totalDocumentsTransferred} documents from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}`,
|
|
172
|
+
{ prefix: "Transfer" }
|
|
173
|
+
);
|
|
174
|
+
};
|
|
118
175
|
|
|
119
176
|
/**
|
|
120
177
|
* Enhanced document transfer with fault tolerance and exponential backoff
|
|
@@ -436,27 +493,24 @@ const transferDocumentBatchWithRetry = async (
|
|
|
436
493
|
return await transferDocumentBatchWithRetryFallback(db, dbId, collectionId, documents, batchSize);
|
|
437
494
|
};
|
|
438
495
|
|
|
439
|
-
export const transferDocumentsBetweenDbsLocalToRemote = async (
|
|
440
|
-
localDb: Databases,
|
|
441
|
-
endpoint: string,
|
|
442
|
-
projectId: string,
|
|
443
|
-
apiKey: string,
|
|
444
|
-
fromDbId: string,
|
|
445
|
-
toDbId: string,
|
|
446
|
-
fromCollId: string,
|
|
447
|
-
toCollId: string
|
|
448
|
-
) => {
|
|
449
|
-
MessageFormatter.info(`Starting enhanced document transfer from ${fromCollId} to ${toCollId}...`, { prefix: "Transfer" });
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
let totalDocumentsProcessed = 0;
|
|
458
|
-
let totalSuccessful = 0;
|
|
459
|
-
let totalFailed = 0;
|
|
496
|
+
export const transferDocumentsBetweenDbsLocalToRemote = async (
|
|
497
|
+
localDb: Databases | DatabaseAdapter,
|
|
498
|
+
endpoint: string,
|
|
499
|
+
projectId: string,
|
|
500
|
+
apiKey: string,
|
|
501
|
+
fromDbId: string,
|
|
502
|
+
toDbId: string,
|
|
503
|
+
fromCollId: string,
|
|
504
|
+
toCollId: string
|
|
505
|
+
) => {
|
|
506
|
+
MessageFormatter.info(`Starting enhanced document transfer from ${fromCollId} to ${toCollId}...`, { prefix: "Transfer" });
|
|
507
|
+
|
|
508
|
+
// Prefer adapter for remote to enable bulk operations
|
|
509
|
+
const { adapter: remoteAdapter, client } = await getAdapter(endpoint, projectId, apiKey, 'auto');
|
|
510
|
+
const remoteDb = new Databases(client); // Legacy fallback for HTTP/individual
|
|
511
|
+
let totalDocumentsProcessed = 0;
|
|
512
|
+
let totalSuccessful = 0;
|
|
513
|
+
let totalFailed = 0;
|
|
460
514
|
|
|
461
515
|
// Fetch documents in larger batches (1000 at a time)
|
|
462
516
|
let hasMoreDocuments = true;
|
|
@@ -468,9 +522,15 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (
|
|
|
468
522
|
queries.push(Query.cursorAfter(lastDocumentId));
|
|
469
523
|
}
|
|
470
524
|
|
|
471
|
-
const fromCollDocs = await tryAwaitWithRetry(async () =>
|
|
472
|
-
localDb
|
|
473
|
-
|
|
525
|
+
const fromCollDocs = await tryAwaitWithRetry(async () => {
|
|
526
|
+
if (isLegacyDatabases(localDb)) {
|
|
527
|
+
return localDb.listDocuments(fromDbId, fromCollId, queries);
|
|
528
|
+
} else {
|
|
529
|
+
const res = await (localDb as DatabaseAdapter).listRows({ databaseId: fromDbId, tableId: fromCollId, queries });
|
|
530
|
+
const rows = (res as any).rows || (res as any).documents || [];
|
|
531
|
+
return { documents: rows } as any;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
474
534
|
|
|
475
535
|
if (fromCollDocs.documents.length === 0) {
|
|
476
536
|
hasMoreDocuments = false;
|
|
@@ -479,13 +539,27 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (
|
|
|
479
539
|
|
|
480
540
|
MessageFormatter.progress(`Fetched ${fromCollDocs.documents.length} documents, processing for transfer...`, { prefix: "Transfer" });
|
|
481
541
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
542
|
+
// Prefer remote adapter bulk upsert if available
|
|
543
|
+
const prepared = fromCollDocs.documents.map((doc: any) => {
|
|
544
|
+
const data: any = { ...doc };
|
|
545
|
+
delete data.$databaseId; delete data.$collectionId; delete data.$createdAt; delete data.$updatedAt;
|
|
546
|
+
return data; // Keep $id and $permissions for upsert
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
let successful = 0; let failed = 0;
|
|
550
|
+
if (typeof (remoteAdapter as any).bulkUpsertRows === 'function' && remoteAdapter.supportsBulkOperations()) {
|
|
551
|
+
try {
|
|
552
|
+
await (remoteAdapter as any).bulkUpsertRows({ databaseId: toDbId, tableId: toCollId, rows: prepared });
|
|
553
|
+
successful = prepared.length;
|
|
554
|
+
} catch (e) {
|
|
555
|
+
MessageFormatter.warning('Remote adapter bulk upsert failed, falling back to HTTP/individual', { prefix: 'Transfer' });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (successful === 0) {
|
|
560
|
+
const res = await transferDocumentBatchWithRetry(remoteDb, client, toDbId, toCollId, fromCollDocs.documents);
|
|
561
|
+
successful = res.successful; failed = res.failed;
|
|
562
|
+
}
|
|
489
563
|
|
|
490
564
|
totalDocumentsProcessed += fromCollDocs.documents.length;
|
|
491
565
|
totalSuccessful += successful;
|
|
@@ -513,4 +587,4 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (
|
|
|
513
587
|
} else {
|
|
514
588
|
MessageFormatter.success(message, { prefix: "Transfer" });
|
|
515
589
|
}
|
|
516
|
-
};
|
|
590
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { resolve as resolvePath, dirname, isAbsolute } from "node:path";
|
|
3
4
|
import yaml from "js-yaml";
|
|
4
5
|
import { register } from "tsx/esm/api";
|
|
5
6
|
import { pathToFileURL } from "node:url";
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
type CollectionDiscoveryResult,
|
|
20
21
|
type TableDiscoveryResult,
|
|
21
22
|
} from "../../utils/configDiscovery.js";
|
|
23
|
+
import { expandTildePath } from "../../functions/pathResolution.js";
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* Options for loading collections or tables
|
|
@@ -51,6 +53,35 @@ export interface CollectionLoadOptions {
|
|
|
51
53
|
* - Validates and normalizes configuration data
|
|
52
54
|
*/
|
|
53
55
|
export class ConfigLoaderService {
|
|
56
|
+
/**
|
|
57
|
+
* Normalizes function dirPath to absolute path
|
|
58
|
+
* @param func Function configuration object
|
|
59
|
+
* @param configDir Directory containing the config file
|
|
60
|
+
* @returns Function with normalized dirPath
|
|
61
|
+
*/
|
|
62
|
+
private normalizeFunctionPath(func: any, configDir: string): any {
|
|
63
|
+
if (!func.dirPath) {
|
|
64
|
+
return func;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Expand tilde first
|
|
68
|
+
const expandedPath = expandTildePath(func.dirPath);
|
|
69
|
+
|
|
70
|
+
// If already absolute, return as-is
|
|
71
|
+
if (isAbsolute(expandedPath)) {
|
|
72
|
+
return {
|
|
73
|
+
...func,
|
|
74
|
+
dirPath: expandedPath
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Resolve relative to config directory
|
|
79
|
+
return {
|
|
80
|
+
...func,
|
|
81
|
+
dirPath: resolvePath(configDir, expandedPath)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
54
85
|
/**
|
|
55
86
|
* Loads configuration from a discovered path, auto-detecting the type
|
|
56
87
|
* @param configPath Path to the configuration file
|
|
@@ -78,6 +109,13 @@ export class ConfigLoaderService {
|
|
|
78
109
|
);
|
|
79
110
|
}
|
|
80
111
|
|
|
112
|
+
const configDir = path.dirname(configPath);
|
|
113
|
+
|
|
114
|
+
// Normalize function paths
|
|
115
|
+
const normalizedFunctions = partialConfig.functions
|
|
116
|
+
? partialConfig.functions.map(func => this.normalizeFunctionPath(func, configDir))
|
|
117
|
+
: [];
|
|
118
|
+
|
|
81
119
|
return {
|
|
82
120
|
appwriteEndpoint: partialConfig.appwriteEndpoint,
|
|
83
121
|
appwriteProject: partialConfig.appwriteProject,
|
|
@@ -105,7 +143,7 @@ export class ConfigLoaderService {
|
|
|
105
143
|
},
|
|
106
144
|
databases: partialConfig.databases || [],
|
|
107
145
|
buckets: partialConfig.buckets || [],
|
|
108
|
-
functions:
|
|
146
|
+
functions: normalizedFunctions,
|
|
109
147
|
collections: partialConfig.collections || [],
|
|
110
148
|
sessionCookie: partialConfig.sessionCookie,
|
|
111
149
|
authMethod: partialConfig.authMethod || "auto",
|
|
@@ -155,6 +193,13 @@ export class ConfigLoaderService {
|
|
|
155
193
|
|
|
156
194
|
// Load collections and tables from their respective directories
|
|
157
195
|
const configDir = path.dirname(yamlPath);
|
|
196
|
+
|
|
197
|
+
// Normalize function paths
|
|
198
|
+
if (config.functions) {
|
|
199
|
+
config.functions = config.functions.map(func =>
|
|
200
|
+
this.normalizeFunctionPath(func, configDir)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
158
203
|
const collectionsDir = path.join(configDir, config.schemaConfig?.collectionsDirectory || "collections");
|
|
159
204
|
const tablesDir = path.join(configDir, config.schemaConfig?.tablesDirectory || "tables");
|
|
160
205
|
|
|
@@ -248,6 +293,14 @@ export class ConfigLoaderService {
|
|
|
248
293
|
throw new Error(`Failed to load TypeScript config from: ${tsPath}`);
|
|
249
294
|
}
|
|
250
295
|
|
|
296
|
+
// Normalize function paths
|
|
297
|
+
const configDir = path.dirname(tsPath);
|
|
298
|
+
if (config.functions) {
|
|
299
|
+
config.functions = config.functions.map(func =>
|
|
300
|
+
this.normalizeFunctionPath(func, configDir)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
251
304
|
MessageFormatter.success(`Loaded TypeScript config from: ${tsPath}`, {
|
|
252
305
|
prefix: "Config",
|
|
253
306
|
});
|
|
@@ -292,6 +345,14 @@ export class ConfigLoaderService {
|
|
|
292
345
|
appwriteConfig.collections = collections;
|
|
293
346
|
}
|
|
294
347
|
|
|
348
|
+
// Normalize function paths
|
|
349
|
+
const configDir = path.dirname(jsonPath);
|
|
350
|
+
if (appwriteConfig.functions) {
|
|
351
|
+
appwriteConfig.functions = appwriteConfig.functions.map(func =>
|
|
352
|
+
this.normalizeFunctionPath(func, configDir)
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
295
356
|
MessageFormatter.success(`Loaded project config from: ${jsonPath}`, {
|
|
296
357
|
prefix: "Config",
|
|
297
358
|
});
|
|
@@ -21,7 +21,10 @@ import {
|
|
|
21
21
|
import { createYamlLoader } from "../utils/yamlLoader.js";
|
|
22
22
|
import { YamlImportIntegration } from "../migrations/yaml/YamlImportIntegration.js";
|
|
23
23
|
import { createImportSchemas } from "../migrations/yaml/generateImportSchemas.js";
|
|
24
|
-
import
|
|
24
|
+
import {
|
|
25
|
+
CollectionCreateSchema,
|
|
26
|
+
type CollectionCreate
|
|
27
|
+
} from "appwrite-utils";
|
|
25
28
|
import fs from "fs";
|
|
26
29
|
import path from "path";
|
|
27
30
|
|
|
@@ -271,7 +274,7 @@ export async function runYamlTerminologyExamples(outputDir: string): Promise<voi
|
|
|
271
274
|
|
|
272
275
|
try {
|
|
273
276
|
// Example collection for demonstrations
|
|
274
|
-
const
|
|
277
|
+
const exampleCollectionInput: CollectionCreate = {
|
|
275
278
|
name: "Product",
|
|
276
279
|
$id: "product",
|
|
277
280
|
enabled: true,
|
|
@@ -286,7 +289,7 @@ export async function runYamlTerminologyExamples(outputDir: string): Promise<voi
|
|
|
286
289
|
},
|
|
287
290
|
{
|
|
288
291
|
key: "price",
|
|
289
|
-
type: "
|
|
292
|
+
type: "double",
|
|
290
293
|
required: true,
|
|
291
294
|
min: 0
|
|
292
295
|
},
|
|
@@ -296,7 +299,8 @@ export async function runYamlTerminologyExamples(outputDir: string): Promise<voi
|
|
|
296
299
|
relationType: "manyToOne",
|
|
297
300
|
relatedCollection: "Categories",
|
|
298
301
|
twoWay: false,
|
|
299
|
-
onDelete: "setNull"
|
|
302
|
+
onDelete: "setNull",
|
|
303
|
+
required: false
|
|
300
304
|
}
|
|
301
305
|
],
|
|
302
306
|
indexes: [
|
|
@@ -308,6 +312,7 @@ export async function runYamlTerminologyExamples(outputDir: string): Promise<voi
|
|
|
308
312
|
],
|
|
309
313
|
importDefs: []
|
|
310
314
|
};
|
|
315
|
+
const exampleCollection = CollectionCreateSchema.parse(exampleCollectionInput);
|
|
311
316
|
|
|
312
317
|
// Run examples
|
|
313
318
|
await generateTemplateExamples(outputDir);
|
|
@@ -338,4 +343,4 @@ export async function runYamlTerminologyExamples(outputDir: string): Promise<voi
|
|
|
338
343
|
}
|
|
339
344
|
}
|
|
340
345
|
|
|
341
|
-
// Note: Functions are already exported above with their declarations
|
|
346
|
+
// Note: Functions are already exported above with their declarations
|
|
@@ -16,30 +16,7 @@ import {
|
|
|
16
16
|
} from "./methods.js";
|
|
17
17
|
import ignore from "ignore";
|
|
18
18
|
import { MessageFormatter } from "../shared/messageFormatter.js";
|
|
19
|
-
|
|
20
|
-
const findFunctionDirectory = (
|
|
21
|
-
basePath: string,
|
|
22
|
-
functionName: string
|
|
23
|
-
): string | undefined => {
|
|
24
|
-
const normalizedName = functionName.toLowerCase().replace(/\s+/g, "-");
|
|
25
|
-
const dirs = fs.readdirSync(basePath, { withFileTypes: true });
|
|
26
|
-
|
|
27
|
-
for (const dir of dirs) {
|
|
28
|
-
if (dir.isDirectory()) {
|
|
29
|
-
const fullPath = join(basePath, dir.name);
|
|
30
|
-
if (dir.name.toLowerCase() === normalizedName) {
|
|
31
|
-
return fullPath;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const nestedResult = findFunctionDirectory(fullPath, functionName);
|
|
35
|
-
if (nestedResult) {
|
|
36
|
-
return nestedResult;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return undefined;
|
|
42
|
-
};
|
|
19
|
+
import { resolveFunctionDirectory, validateFunctionDirectory } from './pathResolution.js';
|
|
43
20
|
|
|
44
21
|
export const deployFunction = async (
|
|
45
22
|
client: Client,
|
|
@@ -183,18 +160,16 @@ export const deployLocalFunction = async (
|
|
|
183
160
|
functionExists = false;
|
|
184
161
|
}
|
|
185
162
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
functionName.toLowerCase().replace(/\s+/g, "-")
|
|
194
|
-
);
|
|
163
|
+
const configDirPath = process.cwd(); // TODO: This should be passed from caller
|
|
164
|
+
const resolvedPath = resolveFunctionDirectory(
|
|
165
|
+
functionName,
|
|
166
|
+
configDirPath,
|
|
167
|
+
functionConfig.dirPath,
|
|
168
|
+
functionPath
|
|
169
|
+
);
|
|
195
170
|
|
|
196
|
-
if (!
|
|
197
|
-
throw new Error(`Function directory
|
|
171
|
+
if (!validateFunctionDirectory(resolvedPath)) {
|
|
172
|
+
throw new Error(`Function directory is invalid or missing required files: ${resolvedPath}`);
|
|
198
173
|
}
|
|
199
174
|
|
|
200
175
|
if (functionConfig.predeployCommands?.length) {
|