@webiny/api-headless-cms-tasks 6.4.9 → 6.4.10-beta.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/DeleteModelTask/DeleteModel.js","sources":["../../../src/features/DeleteModelTask/DeleteModel.ts"],"sourcesContent":["import type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { ListFoldersUseCase } from \"@webiny/api-aco/features/folder/ListFolders/index.js\";\nimport { DeleteFolderUseCase } from \"@webiny/api-aco/features/folder/DeleteFolder/index.js\";\nimport { CmsContext } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { IDeleteModelTaskInput } from \"./types.js\";\nimport type { IDeleteModelTaskOutput } from \"./types.js\";\nimport { createStoreKey } from \"~/helpers/store.js\";\n\ntype IRunParams = TaskDefinition.RunParams<IDeleteModelTaskInput, IDeleteModelTaskOutput>;\n\nexport interface IDeleteModel {\n run(\n params: IRunParams\n ): Promise<TaskDefinition.Result<IDeleteModelTaskInput, IDeleteModelTaskOutput>>;\n}\n\nexport class DeleteModel implements IDeleteModel {\n constructor(private context: CmsContext.Interface) {}\n\n public async run(\n params: IRunParams\n ): Promise<TaskDefinition.Result<IDeleteModelTaskInput, IDeleteModelTaskOutput>> {\n const { input, controller } = params;\n\n const model = await this.getModel(input.modelId);\n\n let hasMoreItems = false;\n let lastDeletedId: string | undefined = input.lastDeletedId;\n do {\n if (controller.runtime.isAborted()) {\n /**\n * If the task was aborted, we need to remove the task tag from the model.\n */\n await this.removeBeingDeleted(model);\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input,\n lastDeletedId\n });\n }\n const where: CmsEntryListWhere = {\n latest: true\n };\n if (lastDeletedId) {\n where.entryId_gte = lastDeletedId;\n }\n const { items, hasMoreItems: metaHasMoreItems } =\n await this.context.cms.storageOperations.entries.list(model, {\n limit: 1000,\n where,\n sort: [\"entryId_ASC\"]\n });\n for (const item of items) {\n try {\n await this.context.cms.deleteEntry(model, item.id, {\n permanently: true,\n force: true\n });\n } catch {\n console.error(\"Failed to delete entry.\", {\n model: model.modelId,\n id: item.id\n });\n return controller.response.error(\n new Error(`Failed to delete entry \"${item.id}\". Cannot continue.`)\n );\n }\n lastDeletedId = item.entryId;\n }\n\n hasMoreItems = metaHasMoreItems;\n } while (hasMoreItems);\n /**\n * Let's do one more check. If there are items, continue the task with 5 seconds delay.\n */\n const { items } = await this.context.cms.storageOperations.entries.list(model, {\n limit: 1,\n where: {\n latest: true\n }\n });\n if (items.length > 0) {\n console.log(\"There are still items to be deleted. Continuing the task.\");\n return controller.response.continue(\n {\n ...input\n },\n {\n seconds: 5\n }\n );\n }\n\n let hasMoreFolders = false;\n\n const listFolders = this.context.container.resolve(ListFoldersUseCase);\n const deleteFolder = this.context.container.resolve(DeleteFolderUseCase);\n\n do {\n const listResult = await listFolders.execute({\n where: {\n type: `cms:${model.modelId}`\n },\n limit: 1000\n });\n\n const { folders, meta } = listResult.value;\n\n for (const item of folders) {\n const result = await deleteFolder.execute(item.id);\n if (result.isFail()) {\n return controller.response.error(result.error);\n }\n }\n\n hasMoreFolders = meta.hasMoreItems;\n } while (hasMoreFolders);\n\n /**\n * When there is no more records to be deleted, let's delete the model, if it's not a plugin.\n */\n await this.removeBeingDeleted(model);\n if (model.isPlugin) {\n return controller.response.done();\n }\n try {\n await this.context.cms.deleteModel(model.modelId);\n } catch (ex) {\n const message = `Failed to delete model \"${model.modelId}\".`;\n console.error(message);\n return controller.response.error(ex);\n }\n\n return controller.response.done();\n }\n\n private async getModel(modelId: string): Promise<CmsModel> {\n const model = await this.context.cms.getModel(modelId);\n if (!model) {\n throw new Error(`Model \"${modelId}\" not found.`);\n }\n return model;\n }\n\n private async removeBeingDeleted(model: Pick<CmsModel, \"modelId\" | \"tenant\">): Promise<void> {\n const key = createStoreKey(model);\n await this.context.db.store.removeValue(key);\n }\n}\n"],"names":["DeleteModel","context","params","input","controller","model","hasMoreItems","lastDeletedId","where","items","metaHasMoreItems","item","console","Error","hasMoreFolders","listFolders","ListFoldersUseCase","deleteFolder","DeleteFolderUseCase","listResult","folders","meta","result","ex","message","modelId","key","createStoreKey"],"mappings":";;;AAkBO,MAAMA;IACT,YAAoBC,OAA6B,CAAE;aAA/BA,OAAO,GAAPA;IAAgC;IAEpD,MAAa,IACTC,MAAkB,EAC2D;QAC7E,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAE9B,MAAMG,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAACF,MAAM,OAAO;QAE/C,IAAIG,eAAe;QACnB,IAAIC,gBAAoCJ,MAAM,aAAa;QAC3D,GAAG;YACC,IAAIC,WAAW,OAAO,CAAC,SAAS,IAAI;gBAIhC,MAAM,IAAI,CAAC,kBAAkB,CAACC;gBAC9B,OAAOD,WAAW,QAAQ,CAAC,OAAO;YACtC;YAAO,IAAIA,WAAW,OAAO,CAAC,gBAAgB,IAC1C,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAAC;gBAChC,GAAGD,KAAK;gBACRI;YACJ;YAEJ,MAAMC,QAA2B;gBAC7B,QAAQ;YACZ;YACA,IAAID,eACAC,MAAM,WAAW,GAAGD;YAExB,MAAM,EAAEE,KAAK,EAAE,cAAcC,gBAAgB,EAAE,GAC3C,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAACL,OAAO;gBACzD,OAAO;gBACPG;gBACA,MAAM;oBAAC;iBAAc;YACzB;YACJ,KAAK,MAAMG,QAAQF,MAAO;gBACtB,IAAI;oBACA,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAACJ,OAAOM,KAAK,EAAE,EAAE;wBAC/C,aAAa;wBACb,OAAO;oBACX;gBACJ,EAAE,OAAM;oBACJC,QAAQ,KAAK,CAAC,2BAA2B;wBACrC,OAAOP,MAAM,OAAO;wBACpB,IAAIM,KAAK,EAAE;oBACf;oBACA,OAAOP,WAAW,QAAQ,CAAC,KAAK,CAC5B,IAAIS,MAAM,CAAC,wBAAwB,EAAEF,KAAK,EAAE,CAAC,mBAAmB,CAAC;gBAEzE;gBACAJ,gBAAgBI,KAAK,OAAO;YAChC;YAEAL,eAAeI;QACnB,QAASJ,aAAc;QAIvB,MAAM,EAAEG,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAACJ,OAAO;YAC3E,OAAO;YACP,OAAO;gBACH,QAAQ;YACZ;QACJ;QACA,IAAII,MAAM,MAAM,GAAG,GAAG;YAClBG,QAAQ,GAAG,CAAC;YACZ,OAAOR,WAAW,QAAQ,CAAC,QAAQ,CAC/B;gBACI,GAAGD,KAAK;YACZ,GACA;gBACI,SAAS;YACb;QAER;QAEA,IAAIW,iBAAiB;QAErB,MAAMC,cAAc,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAACC;QACnD,MAAMC,eAAe,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAACC;QAEpD,GAAG;YACC,MAAMC,aAAa,MAAMJ,YAAY,OAAO,CAAC;gBACzC,OAAO;oBACH,MAAM,CAAC,IAAI,EAAEV,MAAM,OAAO,EAAE;gBAChC;gBACA,OAAO;YACX;YAEA,MAAM,
|
|
1
|
+
{"version":3,"file":"features/DeleteModelTask/DeleteModel.js","sources":["../../../src/features/DeleteModelTask/DeleteModel.ts"],"sourcesContent":["import type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { ListFoldersUseCase } from \"@webiny/api-aco/features/folder/ListFolders/index.js\";\nimport { DeleteFolderUseCase } from \"@webiny/api-aco/features/folder/DeleteFolder/index.js\";\nimport { CmsContext } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { IDeleteModelTaskInput } from \"./types.js\";\nimport type { IDeleteModelTaskOutput } from \"./types.js\";\nimport { createStoreKey } from \"~/helpers/store.js\";\n\ntype IRunParams = TaskDefinition.RunParams<IDeleteModelTaskInput, IDeleteModelTaskOutput>;\n\nexport interface IDeleteModel {\n run(\n params: IRunParams\n ): Promise<TaskDefinition.Result<IDeleteModelTaskInput, IDeleteModelTaskOutput>>;\n}\n\nexport class DeleteModel implements IDeleteModel {\n constructor(private context: CmsContext.Interface) {}\n\n public async run(\n params: IRunParams\n ): Promise<TaskDefinition.Result<IDeleteModelTaskInput, IDeleteModelTaskOutput>> {\n const { input, controller } = params;\n\n const model = await this.getModel(input.modelId);\n\n let hasMoreItems = false;\n let lastDeletedId: string | undefined = input.lastDeletedId;\n do {\n if (controller.runtime.isAborted()) {\n /**\n * If the task was aborted, we need to remove the task tag from the model.\n */\n await this.removeBeingDeleted(model);\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input,\n lastDeletedId\n });\n }\n const where: CmsEntryListWhere = {\n latest: true\n };\n if (lastDeletedId) {\n where.entryId_gte = lastDeletedId;\n }\n const { items, hasMoreItems: metaHasMoreItems } =\n await this.context.cms.storageOperations.entries.list(model, {\n limit: 1000,\n where,\n sort: [\"entryId_ASC\"]\n });\n for (const item of items) {\n try {\n await this.context.cms.deleteEntry(model, item.id, {\n permanently: true,\n force: true\n });\n } catch {\n console.error(\"Failed to delete entry.\", {\n model: model.modelId,\n id: item.id\n });\n return controller.response.error(\n new Error(`Failed to delete entry \"${item.id}\". Cannot continue.`)\n );\n }\n lastDeletedId = item.entryId;\n }\n\n hasMoreItems = metaHasMoreItems;\n } while (hasMoreItems);\n /**\n * Let's do one more check. If there are items, continue the task with 5 seconds delay.\n */\n const { items } = await this.context.cms.storageOperations.entries.list(model, {\n limit: 1,\n where: {\n latest: true\n }\n });\n if (items.length > 0) {\n console.log(\"There are still items to be deleted. Continuing the task.\");\n return controller.response.continue(\n {\n ...input\n },\n {\n seconds: 5\n }\n );\n }\n\n let hasMoreFolders = false;\n\n const listFolders = this.context.container.resolve(ListFoldersUseCase);\n const deleteFolder = this.context.container.resolve(DeleteFolderUseCase);\n\n do {\n const listResult = await listFolders.execute({\n where: {\n type: `cms:${model.modelId}`\n },\n limit: 1000\n });\n\n if (listResult.isFail()) {\n return controller.response.error(listResult.error);\n }\n\n const { folders, meta } = listResult.value;\n\n for (const item of folders) {\n const result = await deleteFolder.execute(item.id);\n if (result.isFail()) {\n return controller.response.error(result.error);\n }\n }\n\n hasMoreFolders = meta.hasMoreItems;\n } while (hasMoreFolders);\n\n /**\n * When there is no more records to be deleted, let's delete the model, if it's not a plugin.\n */\n await this.removeBeingDeleted(model);\n if (model.isPlugin) {\n return controller.response.done();\n }\n try {\n await this.context.cms.deleteModel(model.modelId);\n } catch (ex) {\n const message = `Failed to delete model \"${model.modelId}\".`;\n console.error(message);\n return controller.response.error(ex);\n }\n\n return controller.response.done();\n }\n\n private async getModel(modelId: string): Promise<CmsModel> {\n const model = await this.context.cms.getModel(modelId);\n if (!model) {\n throw new Error(`Model \"${modelId}\" not found.`);\n }\n return model;\n }\n\n private async removeBeingDeleted(model: Pick<CmsModel, \"modelId\" | \"tenant\">): Promise<void> {\n const key = createStoreKey(model);\n await this.context.db.store.removeValue(key);\n }\n}\n"],"names":["DeleteModel","context","params","input","controller","model","hasMoreItems","lastDeletedId","where","items","metaHasMoreItems","item","console","Error","hasMoreFolders","listFolders","ListFoldersUseCase","deleteFolder","DeleteFolderUseCase","listResult","folders","meta","result","ex","message","modelId","key","createStoreKey"],"mappings":";;;AAkBO,MAAMA;IACT,YAAoBC,OAA6B,CAAE;aAA/BA,OAAO,GAAPA;IAAgC;IAEpD,MAAa,I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EAAEnB,MAAM,OAAO,CAAC,EAAE,CAAC;YAC5DO,QAAQ,KAAK,CAACY;YACd,OAAOpB,WAAW,QAAQ,CAAC,KAAK,CAACmB;QACrC;QAEA,OAAOnB,WAAW,QAAQ,CAAC,IAAI;IACnC;IAEA,MAAc,SAASqB,OAAe,EAAqB;QACvD,MAAMpB,QAAQ,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAACoB;QAC9C,IAAI,CAACpB,OACD,MAAM,IAAIQ,MAAM,CAAC,OAAO,EAAEY,QAAQ,YAAY,CAAC;QAEnD,OAAOpB;IACX;IAEA,MAAc,mBAAmBA,KAA2C,EAAiB;QACzF,MAAMqB,MAAMC,eAAetB;QAC3B,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAACqB;IAC5C;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-tasks",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.10-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,26 +17,26 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api": "6.4.
|
|
21
|
-
"@webiny/api-aco": "6.4.
|
|
22
|
-
"@webiny/api-headless-cms": "6.4.
|
|
23
|
-
"@webiny/api-headless-cms-bulk-actions": "6.4.
|
|
24
|
-
"@webiny/background-tasks": "6.4.
|
|
25
|
-
"@webiny/db": "6.4.
|
|
26
|
-
"@webiny/error": "6.4.
|
|
27
|
-
"@webiny/feature": "6.4.
|
|
28
|
-
"@webiny/handler-graphql": "6.4.
|
|
29
|
-
"@webiny/utils": "6.4.
|
|
20
|
+
"@webiny/api": "6.4.10-beta.0",
|
|
21
|
+
"@webiny/api-aco": "6.4.10-beta.0",
|
|
22
|
+
"@webiny/api-headless-cms": "6.4.10-beta.0",
|
|
23
|
+
"@webiny/api-headless-cms-bulk-actions": "6.4.10-beta.0",
|
|
24
|
+
"@webiny/background-tasks": "6.4.10-beta.0",
|
|
25
|
+
"@webiny/db": "6.4.10-beta.0",
|
|
26
|
+
"@webiny/error": "6.4.10-beta.0",
|
|
27
|
+
"@webiny/feature": "6.4.10-beta.0",
|
|
28
|
+
"@webiny/handler-graphql": "6.4.10-beta.0",
|
|
29
|
+
"@webiny/utils": "6.4.10-beta.0",
|
|
30
30
|
"zod": "4.4.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@webiny/api-core": "6.4.
|
|
34
|
-
"@webiny/build-tools": "6.4.
|
|
35
|
-
"@webiny/handler": "6.4.
|
|
36
|
-
"@webiny/handler-aws": "6.4.
|
|
37
|
-
"@webiny/plugins": "6.4.
|
|
38
|
-
"@webiny/project-utils": "6.4.
|
|
39
|
-
"@webiny/wcp": "6.4.
|
|
33
|
+
"@webiny/api-core": "6.4.10-beta.0",
|
|
34
|
+
"@webiny/build-tools": "6.4.10-beta.0",
|
|
35
|
+
"@webiny/handler": "6.4.10-beta.0",
|
|
36
|
+
"@webiny/handler-aws": "6.4.10-beta.0",
|
|
37
|
+
"@webiny/plugins": "6.4.10-beta.0",
|
|
38
|
+
"@webiny/project-utils": "6.4.10-beta.0",
|
|
39
|
+
"@webiny/wcp": "6.4.10-beta.0",
|
|
40
40
|
"typescript": "6.0.3",
|
|
41
41
|
"vitest": "4.1.10"
|
|
42
42
|
},
|