appwrite-utils-cli 0.0.15 → 0.0.16
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.
|
@@ -233,19 +233,29 @@ export class ImportController {
|
|
|
233
233
|
async handleCreate(context, finalItem, updateDefs, id) {
|
|
234
234
|
const existing = await documentExists(this.database, context.dbId, context.collId, finalItem);
|
|
235
235
|
if (!existing) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
updateDefs
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
try {
|
|
237
|
+
const createdDoc = await this.database.createDocument(context.dbId, context.collId, id || ID.unique(), finalItem);
|
|
238
|
+
context.docId = createdDoc.$id;
|
|
239
|
+
context.createdDoc = createdDoc;
|
|
240
|
+
context = { ...context, ...createdDoc };
|
|
241
|
+
// Populate document cache for updates
|
|
242
|
+
if (updateDefs) {
|
|
243
|
+
updateDefs.forEach((def) => {
|
|
244
|
+
if (def.updateMapping) {
|
|
245
|
+
this.documentCache.set(`${finalItem[def.updateMapping.targetField]}`, context);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return context;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
logger.error(`An error occurred during creation -- ${context}, id: ${id}, ${finalItem}}`);
|
|
253
|
+
if (error.type === "document_already_exists") {
|
|
254
|
+
logger.warn(`Document already exists, retrying creation. -- ${context}, id: ${id}, ${finalItem}}`);
|
|
255
|
+
await this.handleCreate(context, finalItem, updateDefs, ID.unique());
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
247
258
|
}
|
|
248
|
-
return context;
|
|
249
259
|
}
|
|
250
260
|
else {
|
|
251
261
|
console.log("Document already exists, skipping creation.");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appwrite-utils-cli",
|
|
3
3
|
"description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.16",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -393,28 +393,41 @@ export class ImportController {
|
|
|
393
393
|
finalItem
|
|
394
394
|
);
|
|
395
395
|
if (!existing) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
396
|
+
try {
|
|
397
|
+
const createdDoc = await this.database.createDocument(
|
|
398
|
+
context.dbId,
|
|
399
|
+
context.collId,
|
|
400
|
+
id || ID.unique(),
|
|
401
|
+
finalItem
|
|
402
|
+
);
|
|
403
|
+
context.docId = createdDoc.$id;
|
|
404
|
+
context.createdDoc = createdDoc;
|
|
405
|
+
context = { ...context, ...createdDoc };
|
|
405
406
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
407
|
+
// Populate document cache for updates
|
|
408
|
+
if (updateDefs) {
|
|
409
|
+
updateDefs.forEach((def) => {
|
|
410
|
+
if (def.updateMapping) {
|
|
411
|
+
this.documentCache.set(
|
|
412
|
+
`${finalItem[def.updateMapping.targetField]}`,
|
|
413
|
+
context
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return context;
|
|
419
|
+
} catch (error: any) {
|
|
420
|
+
logger.error(
|
|
421
|
+
`An error occurred during creation -- ${context}, id: ${id}, ${finalItem}}`
|
|
422
|
+
);
|
|
423
|
+
if (error.type === "document_already_exists") {
|
|
424
|
+
logger.warn(
|
|
425
|
+
`Document already exists, retrying creation. -- ${context}, id: ${id}, ${finalItem}}`
|
|
426
|
+
);
|
|
427
|
+
await this.handleCreate(context, finalItem, updateDefs, ID.unique());
|
|
428
|
+
}
|
|
429
|
+
return;
|
|
416
430
|
}
|
|
417
|
-
return context;
|
|
418
431
|
} else {
|
|
419
432
|
console.log("Document already exists, skipping creation.");
|
|
420
433
|
return existing;
|