@webiny/api-headless-cms-tasks 6.0.0-alpha.0 → 6.0.0-alpha.2
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/index.d.ts +1 -1
- package/package.json +20 -20
- package/tasks/deleteModel/DeleteModelRunner.d.ts +3 -3
- package/tasks/deleteModel/DeleteModelRunner.js.map +1 -1
- package/tasks/deleteModel/graphql/attachLifecycleEvents.d.ts +1 -1
- package/tasks/deleteModel/graphql/attachLifecycleEvents.js.map +1 -1
- package/tasks/deleteModel/helpers/store.d.ts +2 -2
- package/tasks/deleteModel/helpers/store.js.map +1 -1
- package/tasks/deleteModel/index.d.ts +2 -2
- package/tasks/deleteModel/index.js.map +1 -1
- package/tasks/deleteModel/types.d.ts +2 -2
- package/tasks/deleteModel/types.js.map +1 -1
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createDeleteModelTask } from "./tasks/deleteModel";
|
|
2
2
|
export { createDeleteModelTask };
|
|
3
|
-
export declare const createHcmsTasks: () => (
|
|
3
|
+
export declare const createHcmsTasks: () => ((import("@webiny/api").ContextPlugin<import("./types").HcmsTasksContext> | import("@webiny/tasks").TaskDefinitionPlugin<import("./types").HcmsTasksContext, import("./tasks/deleteModel/types").IDeleteModelTaskInput, import("./tasks/deleteModel/types").IDeleteModelTaskOutput>)[] | ((import("@webiny/handler-aws").EventBridgeEventHandler<"WebinyEmptyTrashBin", Record<string, any>, any> | import("@webiny/handler").HandlerOnRequestPlugin<import("@webiny/handler/types").Context>)[] | import("@webiny/api").ContextPlugin<import("@webiny/api-headless-cms-bulk-actions/types").HcmsBulkActionsContext>)[] | (import("@webiny/api").ContextPlugin<import("@webiny/api-headless-cms-bulk-actions/types").HcmsBulkActionsContext> | (import("@webiny/tasks").TaskDefinitionPlugin<import("@webiny/api-headless-cms-bulk-actions/types").HcmsBulkActionsContext, import("@webiny/api-headless-cms-bulk-actions/types").IBulkActionOperationByModelInput, import("@webiny/api-headless-cms-bulk-actions/types").IBulkActionOperationByModelOutput> | import("@webiny/tasks").TaskDefinitionPlugin<import("@webiny/api-headless-cms-bulk-actions/types").HcmsBulkActionsContext, import("@webiny/api-headless-cms-bulk-actions/types").IBulkActionOperationInput, import("@webiny/api-headless-cms-bulk-actions/types").IBulkActionOperationOutput>)[])[][] | import("@webiny/tasks").TaskDefinitionPlugin<import("@webiny/api-headless-cms-bulk-actions/types").HcmsBulkActionsContext, import("@webiny/api-headless-cms-bulk-actions/types").IEmptyTrashBinsInput, import("@webiny/tasks").ITaskResponseDoneResultOutput> | import("@webiny/plugins/types").Plugin[])[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-tasks",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Background tasks for Webiny Headless CMS",
|
|
6
6
|
"keywords": [
|
|
@@ -13,27 +13,27 @@
|
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/api": "6.0.0-alpha.
|
|
17
|
-
"@webiny/api-aco": "6.0.0-alpha.
|
|
18
|
-
"@webiny/api-headless-cms": "6.0.0-alpha.
|
|
19
|
-
"@webiny/api-headless-cms-bulk-actions": "6.0.0-alpha.
|
|
20
|
-
"@webiny/api-headless-cms-import-export": "6.0.0-alpha.
|
|
21
|
-
"@webiny/db": "6.0.0-alpha.
|
|
22
|
-
"@webiny/error": "6.0.0-alpha.
|
|
23
|
-
"@webiny/handler-graphql": "6.0.0-alpha.
|
|
24
|
-
"@webiny/tasks": "6.0.0-alpha.
|
|
25
|
-
"@webiny/utils": "6.0.0-alpha.
|
|
16
|
+
"@webiny/api": "6.0.0-alpha.2",
|
|
17
|
+
"@webiny/api-aco": "6.0.0-alpha.2",
|
|
18
|
+
"@webiny/api-headless-cms": "6.0.0-alpha.2",
|
|
19
|
+
"@webiny/api-headless-cms-bulk-actions": "6.0.0-alpha.2",
|
|
20
|
+
"@webiny/api-headless-cms-import-export": "6.0.0-alpha.2",
|
|
21
|
+
"@webiny/db": "6.0.0-alpha.2",
|
|
22
|
+
"@webiny/error": "6.0.0-alpha.2",
|
|
23
|
+
"@webiny/handler-graphql": "6.0.0-alpha.2",
|
|
24
|
+
"@webiny/tasks": "6.0.0-alpha.2",
|
|
25
|
+
"@webiny/utils": "6.0.0-alpha.2",
|
|
26
26
|
"zod": "3.23.8"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@webiny/api-i18n": "6.0.0-alpha.
|
|
30
|
-
"@webiny/api-security": "6.0.0-alpha.
|
|
31
|
-
"@webiny/api-tenancy": "6.0.0-alpha.
|
|
32
|
-
"@webiny/api-wcp": "6.0.0-alpha.
|
|
33
|
-
"@webiny/handler": "6.0.0-alpha.
|
|
34
|
-
"@webiny/handler-aws": "6.0.0-alpha.
|
|
35
|
-
"@webiny/plugins": "6.0.0-alpha.
|
|
36
|
-
"@webiny/project-utils": "6.0.0-alpha.
|
|
29
|
+
"@webiny/api-i18n": "6.0.0-alpha.2",
|
|
30
|
+
"@webiny/api-security": "6.0.0-alpha.2",
|
|
31
|
+
"@webiny/api-tenancy": "6.0.0-alpha.2",
|
|
32
|
+
"@webiny/api-wcp": "6.0.0-alpha.2",
|
|
33
|
+
"@webiny/handler": "6.0.0-alpha.2",
|
|
34
|
+
"@webiny/handler-aws": "6.0.0-alpha.2",
|
|
35
|
+
"@webiny/plugins": "6.0.0-alpha.2",
|
|
36
|
+
"@webiny/project-utils": "6.0.0-alpha.2",
|
|
37
37
|
"typescript": "5.3.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"access": "public",
|
|
45
45
|
"directory": "dist"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "7c9e8fbfd62a57ece5f880dbad6c864636b0355e"
|
|
48
48
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ITaskResponse, ITaskResponseResult, ITaskRunParams } from "@webiny/tasks";
|
|
2
|
-
import { HcmsTasksContext } from "../../types";
|
|
3
|
-
import { IDeleteModelTaskInput, IDeleteModelTaskOutput } from "./types";
|
|
1
|
+
import type { ITaskResponse, ITaskResponseResult, ITaskRunParams } from "@webiny/tasks";
|
|
2
|
+
import type { HcmsTasksContext } from "../../types";
|
|
3
|
+
import type { IDeleteModelTaskInput, IDeleteModelTaskOutput } from "./types";
|
|
4
4
|
export interface IDeleteModelRunnerParams<C extends HcmsTasksContext, I extends IDeleteModelTaskInput, O extends IDeleteModelTaskOutput> {
|
|
5
5
|
taskId: string;
|
|
6
6
|
context: C;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_store","require","DeleteModelRunner","constructor","params","taskId","context","response","execute","input","isCloseToTimeout","isAborted","model","getModel","modelId","hasMoreItems","lastDeletedId","removeBeingDeleted","aborted","continue","where","latest","entryId_gte","items","metaHasMoreItems","cms","storageOperations","entries","list","limit","sort","item","deleteEntry","id","permanently","force","ex","console","error","Error","entryId","length","log","seconds","hasMoreFolders","meta","aco","folder","type","delete","isPlugin","done","deleteModel","message","key","createStoreKey","db","store","removeValue","exports","createDeleteModelRunner"],"sources":["DeleteModelRunner.ts"],"sourcesContent":["import { ITaskResponse, ITaskResponseResult, ITaskRunParams } from \"@webiny/tasks\";\nimport { HcmsTasksContext } from \"~/types\";\nimport { IDeleteModelTaskInput, IDeleteModelTaskOutput } from \"./types\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createStoreKey } from \"~/tasks/deleteModel/helpers/store\";\n\nexport interface IDeleteModelRunnerParams<\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n> {\n taskId: string;\n context: C;\n response: ITaskResponse<I, O>;\n}\n\nexport type IExecuteParams<\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n> = Omit<ITaskRunParams<C, I, O>, \"context\" | \"response\" | \"store\" | \"timer\" | \"trigger\">;\n\nexport class DeleteModelRunner<\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n> {\n private readonly taskId: string;\n private readonly context: C;\n private readonly response: ITaskResponse<I, O>;\n\n public constructor(params: IDeleteModelRunnerParams<C, I, O>) {\n this.taskId = params.taskId;\n this.context = params.context;\n this.response = params.response;\n }\n\n public async execute(params: IExecuteParams<C, I, O>): Promise<ITaskResponseResult<I, O>> {\n const { input, isCloseToTimeout, isAborted } = 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 (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 this.response.aborted();\n } else if (isCloseToTimeout()) {\n return this.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 (ex) {\n console.error(\"Failed to delete entry.\", {\n model: model.modelId,\n id: item.id\n });\n return this.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 this.response.continue(\n {\n ...input\n },\n {\n seconds: 5\n }\n );\n }\n\n let hasMoreFolders = false;\n do {\n const [items, meta] = await this.context.aco.folder.list({\n where: {\n type: `cms:${model.modelId}`\n },\n limit: 1000\n });\n for (const item of items) {\n try {\n await this.context.aco.folder.delete(item.id);\n } catch (ex) {\n console.error(`Failed to delete folder \"${item.id}\".`, ex);\n return this.response.error(ex);\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 this.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 this.response.error(ex);\n }\n\n return this.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(\n model: Pick<CmsModel, \"modelId\" | \"tenant\" | \"locale\">\n ): Promise<void> {\n const key = createStoreKey(model);\n await this.context.db.store.removeValue(key);\n }\n}\n\nexport const createDeleteModelRunner = <\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n>(\n params: IDeleteModelRunnerParams<C, I, O>\n) => {\n return new DeleteModelRunner<C, I, O>(params);\n};\n"],"mappings":";;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AAkBO,MAAMC,iBAAiB,CAI5B;EAKSC,WAAWA,CAACC,MAAyC,EAAE;IAC1D,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC3B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,QAAQ,GAAGH,MAAM,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,CAACN,OAAO,CAACkD,EAAE,CAACC,KAAK,CAACC,WAAW,CAACJ,GAAG,CAAC;EAChD;AACJ;AAACK,OAAA,CAAAzD,iBAAA,GAAAA,iBAAA;AAEM,MAAM0D,uBAAuB,GAKhCxD,MAAyC,IACxC;EACD,OAAO,IAAIF,iBAAiB,CAAUE,MAAM,CAAC;AACjD,CAAC;AAACuD,OAAA,CAAAC,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_store","require","DeleteModelRunner","constructor","params","taskId","context","response","execute","input","isCloseToTimeout","isAborted","model","getModel","modelId","hasMoreItems","lastDeletedId","removeBeingDeleted","aborted","continue","where","latest","entryId_gte","items","metaHasMoreItems","cms","storageOperations","entries","list","limit","sort","item","deleteEntry","id","permanently","force","ex","console","error","Error","entryId","length","log","seconds","hasMoreFolders","meta","aco","folder","type","delete","isPlugin","done","deleteModel","message","key","createStoreKey","db","store","removeValue","exports","createDeleteModelRunner"],"sources":["DeleteModelRunner.ts"],"sourcesContent":["import type { ITaskResponse, ITaskResponseResult, ITaskRunParams } from \"@webiny/tasks\";\nimport type { HcmsTasksContext } from \"~/types\";\nimport type { IDeleteModelTaskInput, IDeleteModelTaskOutput } from \"./types\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createStoreKey } from \"~/tasks/deleteModel/helpers/store\";\n\nexport interface IDeleteModelRunnerParams<\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n> {\n taskId: string;\n context: C;\n response: ITaskResponse<I, O>;\n}\n\nexport type IExecuteParams<\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n> = Omit<ITaskRunParams<C, I, O>, \"context\" | \"response\" | \"store\" | \"timer\" | \"trigger\">;\n\nexport class DeleteModelRunner<\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n> {\n private readonly taskId: string;\n private readonly context: C;\n private readonly response: ITaskResponse<I, O>;\n\n public constructor(params: IDeleteModelRunnerParams<C, I, O>) {\n this.taskId = params.taskId;\n this.context = params.context;\n this.response = params.response;\n }\n\n public async execute(params: IExecuteParams<C, I, O>): Promise<ITaskResponseResult<I, O>> {\n const { input, isCloseToTimeout, isAborted } = 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 (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 this.response.aborted();\n } else if (isCloseToTimeout()) {\n return this.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 (ex) {\n console.error(\"Failed to delete entry.\", {\n model: model.modelId,\n id: item.id\n });\n return this.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 this.response.continue(\n {\n ...input\n },\n {\n seconds: 5\n }\n );\n }\n\n let hasMoreFolders = false;\n do {\n const [items, meta] = await this.context.aco.folder.list({\n where: {\n type: `cms:${model.modelId}`\n },\n limit: 1000\n });\n for (const item of items) {\n try {\n await this.context.aco.folder.delete(item.id);\n } catch (ex) {\n console.error(`Failed to delete folder \"${item.id}\".`, ex);\n return this.response.error(ex);\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 this.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 this.response.error(ex);\n }\n\n return this.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(\n model: Pick<CmsModel, \"modelId\" | \"tenant\" | \"locale\">\n ): Promise<void> {\n const key = createStoreKey(model);\n await this.context.db.store.removeValue(key);\n }\n}\n\nexport const createDeleteModelRunner = <\n C extends HcmsTasksContext,\n I extends IDeleteModelTaskInput,\n O extends IDeleteModelTaskOutput\n>(\n params: IDeleteModelRunnerParams<C, I, O>\n) => {\n return new DeleteModelRunner<C, I, O>(params);\n};\n"],"mappings":";;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AAkBO,MAAMC,iBAAiB,CAI5B;EAKSC,WAAWA,CAACC,MAAyC,EAAE;IAC1D,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC3B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,QAAQ,GAAGH,MAAM,CAACG,QAAQ;EACnC;EAEA,MAAaC,OAAOA,CAACJ,MAA+B,EAAsC;IACtF,MAAM;MAAEK,KAAK;MAAEC,gBAAgB;MAAEC;IAAU,CAAC,GAAGP,MAAM;IAErD,MAAMQ,KAAK,GAAG,MAAM,IAAI,CAACC,QAAQ,CAACJ,KAAK,CAACK,OAAO,CAAC;IAEhD,IAAIC,YAAY,GAAG,KAAK;IACxB,IAAIC,aAAiC,GAAGP,KAAK,CAACO,aA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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_error","require","attachLifecycleEvents","context","blockActionOnEvent","params","model","isBeingDeleted","cms","isModelBeingDeleted","modelId","WebinyError","name","onEntryBeforeCreate","subscribe","onEntryRevisionBeforeCreate","onEntryBeforeUpdate","onEntryBeforeUnpublish","onEntryBeforePublish","onEntryBeforeRepublish","onEntryBeforeRestoreFromBin","onEntryBeforeMove","onModelBeforeUpdate","onModelBeforeCreateFrom","exports"],"sources":["attachLifecycleEvents.ts"],"sourcesContent":["import { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { WebinyError } from \"@webiny/error\";\nimport { HcmsTasksContext } from \"~/types\";\n\nexport interface IAttachLifecycleEventsParams {\n context: HcmsTasksContext;\n}\n\ninterface ICbParams {\n model: Pick<CmsModel, \"modelId\" | \"name\">;\n}\n\nexport const attachLifecycleEvents = ({ context }: IAttachLifecycleEventsParams): void => {\n const blockActionOnEvent = async (params: ICbParams): Promise<void> => {\n const { model } = params;\n const isBeingDeleted = await context.cms.isModelBeingDeleted(model.modelId);\n if (!isBeingDeleted) {\n return;\n }\n\n throw new WebinyError(\n `Model \"${model.name}\" is being deleted and you cannot create, update or delete any entries of this model.`\n );\n };\n /**\n * Entry actions.\n */\n context.cms.onEntryBeforeCreate.subscribe(blockActionOnEvent);\n\n context.cms.onEntryRevisionBeforeCreate.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeUpdate.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeUnpublish.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforePublish.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeRepublish.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeRestoreFromBin.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeMove.subscribe(blockActionOnEvent);\n /**\n * Model actions.\n */\n context.cms.onModelBeforeUpdate.subscribe(blockActionOnEvent);\n\n context.cms.onModelBeforeCreateFrom.subscribe(blockActionOnEvent);\n};\n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","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_error","require","attachLifecycleEvents","context","blockActionOnEvent","params","model","isBeingDeleted","cms","isModelBeingDeleted","modelId","WebinyError","name","onEntryBeforeCreate","subscribe","onEntryRevisionBeforeCreate","onEntryBeforeUpdate","onEntryBeforeUnpublish","onEntryBeforePublish","onEntryBeforeRepublish","onEntryBeforeRestoreFromBin","onEntryBeforeMove","onModelBeforeUpdate","onModelBeforeCreateFrom","exports"],"sources":["attachLifecycleEvents.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { HcmsTasksContext } from \"~/types\";\n\nexport interface IAttachLifecycleEventsParams {\n context: HcmsTasksContext;\n}\n\ninterface ICbParams {\n model: Pick<CmsModel, \"modelId\" | \"name\">;\n}\n\nexport const attachLifecycleEvents = ({ context }: IAttachLifecycleEventsParams): void => {\n const blockActionOnEvent = async (params: ICbParams): Promise<void> => {\n const { model } = params;\n const isBeingDeleted = await context.cms.isModelBeingDeleted(model.modelId);\n if (!isBeingDeleted) {\n return;\n }\n\n throw new WebinyError(\n `Model \"${model.name}\" is being deleted and you cannot create, update or delete any entries of this model.`\n );\n };\n /**\n * Entry actions.\n */\n context.cms.onEntryBeforeCreate.subscribe(blockActionOnEvent);\n\n context.cms.onEntryRevisionBeforeCreate.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeUpdate.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeUnpublish.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforePublish.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeRepublish.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeRestoreFromBin.subscribe(blockActionOnEvent);\n\n context.cms.onEntryBeforeMove.subscribe(blockActionOnEvent);\n /**\n * Model actions.\n */\n context.cms.onModelBeforeUpdate.subscribe(blockActionOnEvent);\n\n context.cms.onModelBeforeCreateFrom.subscribe(blockActionOnEvent);\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BAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IStoreValue } from "../types";
|
|
2
|
-
import { StorageKey } from "@webiny/db/types";
|
|
1
|
+
import type { IStoreValue } from "../types";
|
|
2
|
+
import type { StorageKey } from "@webiny/db/types";
|
|
3
3
|
export interface ICreateStoreKeyParams {
|
|
4
4
|
modelId: string;
|
|
5
5
|
tenant: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createStoreNamespace","params","tenant","locale","exports","createStoreKey","modelId","createStoreValue","task","identity"],"sources":["store.ts"],"sourcesContent":["import { IStoreValue } from \"~/tasks/deleteModel/types\";\nimport { StorageKey } from \"@webiny/db/types\";\n\nexport interface ICreateStoreKeyParams {\n modelId: string;\n tenant: string;\n locale: string;\n}\n\nexport const createStoreNamespace = (params: Pick<ICreateStoreKeyParams, \"tenant\" | \"locale\">) => {\n return `deletingCmsModel#T#${params.tenant}#L#${params.locale}#`;\n};\n\nexport const createStoreKey = (params: ICreateStoreKeyParams): StorageKey => {\n return `${createStoreNamespace(params)}${params.modelId}`;\n};\n\nexport const createStoreValue = (params: IStoreValue): IStoreValue => {\n return {\n modelId: params.modelId,\n task: params.task,\n identity: params.identity,\n tenant: params.tenant,\n locale: params.locale\n };\n};\n"],"mappings":";;;;;;AASO,MAAMA,oBAAoB,GAAIC,MAAwD,IAAK;EAC9F,OAAO,sBAAsBA,MAAM,CAACC,MAAM,MAAMD,MAAM,CAACE,MAAM,GAAG;AACpE,CAAC;AAACC,OAAA,CAAAJ,oBAAA,GAAAA,oBAAA;AAEK,MAAMK,cAAc,GAAIJ,MAA6B,IAAiB;EACzE,OAAO,GAAGD,oBAAoB,CAACC,MAAM,CAAC,GAAGA,MAAM,CAACK,OAAO,EAAE;AAC7D,CAAC;AAACF,OAAA,CAAAC,cAAA,GAAAA,cAAA;AAEK,MAAME,gBAAgB,GAAIN,MAAmB,IAAkB;EAClE,OAAO;IACHK,OAAO,EAAEL,MAAM,CAACK,OAAO;IACvBE,IAAI,EAAEP,MAAM,CAACO,IAAI;IACjBC,QAAQ,EAAER,MAAM,CAACQ,QAAQ;IACzBP,MAAM,EAAED,MAAM,CAACC,MAAM;IACrBC,MAAM,EAAEF,MAAM,CAACE;EACnB,CAAC;AACL,CAAC;AAACC,OAAA,CAAAG,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createStoreNamespace","params","tenant","locale","exports","createStoreKey","modelId","createStoreValue","task","identity"],"sources":["store.ts"],"sourcesContent":["import type { IStoreValue } from \"~/tasks/deleteModel/types\";\nimport type { StorageKey } from \"@webiny/db/types\";\n\nexport interface ICreateStoreKeyParams {\n modelId: string;\n tenant: string;\n locale: string;\n}\n\nexport const createStoreNamespace = (params: Pick<ICreateStoreKeyParams, \"tenant\" | \"locale\">) => {\n return `deletingCmsModel#T#${params.tenant}#L#${params.locale}#`;\n};\n\nexport const createStoreKey = (params: ICreateStoreKeyParams): StorageKey => {\n return `${createStoreNamespace(params)}${params.modelId}`;\n};\n\nexport const createStoreValue = (params: IStoreValue): IStoreValue => {\n return {\n modelId: params.modelId,\n task: params.task,\n identity: params.identity,\n tenant: params.tenant,\n locale: params.locale\n };\n};\n"],"mappings":";;;;;;AASO,MAAMA,oBAAoB,GAAIC,MAAwD,IAAK;EAC9F,OAAO,sBAAsBA,MAAM,CAACC,MAAM,MAAMD,MAAM,CAACE,MAAM,GAAG;AACpE,CAAC;AAACC,OAAA,CAAAJ,oBAAA,GAAAA,oBAAA;AAEK,MAAMK,cAAc,GAAIJ,MAA6B,IAAiB;EACzE,OAAO,GAAGD,oBAAoB,CAACC,MAAM,CAAC,GAAGA,MAAM,CAACK,OAAO,EAAE;AAC7D,CAAC;AAACF,OAAA,CAAAC,cAAA,GAAAA,cAAA;AAEK,MAAME,gBAAgB,GAAIN,MAAmB,IAAkB;EAClE,OAAO;IACHK,OAAO,EAAEL,MAAM,CAACK,OAAO;IACvBE,IAAI,EAAEP,MAAM,CAACO,IAAI;IACjBC,QAAQ,EAAER,MAAM,CAACQ,QAAQ;IACzBP,MAAM,EAAED,MAAM,CAACC,MAAM;IACrBC,MAAM,EAAEF,MAAM,CAACE;EACnB,CAAC;AACL,CAAC;AAACC,OAAA,CAAAG,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HcmsTasksContext } from "../../types";
|
|
2
|
-
import { IDeleteModelTaskInput, IDeleteModelTaskOutput } from "./types";
|
|
1
|
+
import type { HcmsTasksContext } from "../../types";
|
|
2
|
+
import type { IDeleteModelTaskInput, IDeleteModelTaskOutput } from "./types";
|
|
3
3
|
export declare const createDeleteModelTask: () => (import("@webiny/api").ContextPlugin<HcmsTasksContext> | import("@webiny/tasks").TaskDefinitionPlugin<HcmsTasksContext, IDeleteModelTaskInput, IDeleteModelTaskOutput>)[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_tasks","require","_DeleteModelRunner","_constants","_graphql","_crud","createDefinition","createTaskDefinition","id","DELETE_MODEL_TASK","disableDatabaseLogs","title","maxIterations","isPrivate","run","params","deleteModelRunner","createDeleteModelRunner","taskId","store","getTask","context","response","execute","input","isCloseToTimeout","isAborted","ex","error","createInputValidation","validator","modelId","string","lastDeletedId","optional","createDeleteModelTask","createDeleteModelCrud","createDeleteModelGraphQl","exports"],"sources":["index.ts"],"sourcesContent":["import { createTaskDefinition } from \"@webiny/tasks\";\nimport { HcmsTasksContext } from \"~/types\";\nimport { IDeleteModelTaskInput, IDeleteModelTaskOutput } from \"./types\";\nimport { createDeleteModelRunner } from \"./DeleteModelRunner\";\nimport { DELETE_MODEL_TASK } from \"./constants\";\nimport { createDeleteModelGraphQl } from \"./graphql\";\nimport { createDeleteModelCrud } from \"./graphql/crud\";\n\nconst createDefinition = () => {\n return createTaskDefinition<HcmsTasksContext, IDeleteModelTaskInput, IDeleteModelTaskOutput>({\n id: DELETE_MODEL_TASK,\n disableDatabaseLogs: true,\n title: \"Delete model and all of the entries\",\n maxIterations: 50,\n isPrivate: true,\n async run(params) {\n try {\n const deleteModelRunner = createDeleteModelRunner({\n taskId: params.store.getTask().id,\n context: params.context,\n response: params.response\n });\n return await deleteModelRunner.execute({\n input: params.input,\n isCloseToTimeout: params.isCloseToTimeout,\n isAborted: params.isAborted\n });\n } catch (ex) {\n return params.response.error(ex);\n }\n },\n createInputValidation: ({ validator }) => {\n return {\n modelId: validator.string(),\n lastDeletedId: validator.string().optional()\n };\n }\n });\n};\n\nexport const createDeleteModelTask = () => {\n return [createDefinition(), createDeleteModelCrud(), createDeleteModelGraphQl()];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,MAAMK,gBAAgB,GAAGA,CAAA,KAAM;EAC3B,OAAO,IAAAC,2BAAoB,EAAkE;IACzFC,EAAE,EAAEC,4BAAiB;IACrBC,mBAAmB,EAAE,IAAI;IACzBC,KAAK,EAAE,qCAAqC;IAC5CC,aAAa,EAAE,EAAE;IACjBC,SAAS,EAAE,IAAI;IACf,MAAMC,GAAGA,CAACC,MAAM,EAAE;MACd,IAAI;QACA,MAAMC,iBAAiB,GAAG,IAAAC,0CAAuB,EAAC;UAC9CC,MAAM,EAAEH,MAAM,CAACI,KAAK,CAACC,OAAO,CAAC,CAAC,CAACZ,EAAE;UACjCa,OAAO,EAAEN,MAAM,CAACM,OAAO;UACvBC,QAAQ,EAAEP,MAAM,CAACO;QACrB,CAAC,CAAC;QACF,OAAO,MAAMN,iBAAiB,CAACO,OAAO,CAAC;UACnCC,KAAK,EAAET,MAAM,CAACS,KAAK;UACnBC,gBAAgB,EAAEV,MAAM,CAACU,gBAAgB;UACzCC,SAAS,EAAEX,MAAM,CAACW;QACtB,CAAC,CAAC;MACN,CAAC,CAAC,OAAOC,EAAE,EAAE;QACT,OAAOZ,MAAM,CAACO,QAAQ,CAACM,KAAK,CAACD,EAAE,CAAC;MACpC;IACJ,CAAC;IACDE,qBAAqB,EAAEA,CAAC;MAAEC;IAAU,CAAC,KAAK;MACtC,OAAO;QACHC,OAAO,EAAED,SAAS,CAACE,MAAM,CAAC,CAAC;QAC3BC,aAAa,EAAEH,SAAS,CAACE,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC;MAC/C,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAEM,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,OAAO,CAAC7B,gBAAgB,CAAC,CAAC,EAAE,IAAA8B,2BAAqB,EAAC,CAAC,EAAE,IAAAC,iCAAwB,EAAC,CAAC,CAAC;AACpF,CAAC;AAACC,OAAA,CAAAH,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_tasks","require","_DeleteModelRunner","_constants","_graphql","_crud","createDefinition","createTaskDefinition","id","DELETE_MODEL_TASK","disableDatabaseLogs","title","maxIterations","isPrivate","run","params","deleteModelRunner","createDeleteModelRunner","taskId","store","getTask","context","response","execute","input","isCloseToTimeout","isAborted","ex","error","createInputValidation","validator","modelId","string","lastDeletedId","optional","createDeleteModelTask","createDeleteModelCrud","createDeleteModelGraphQl","exports"],"sources":["index.ts"],"sourcesContent":["import { createTaskDefinition } from \"@webiny/tasks\";\nimport type { HcmsTasksContext } from \"~/types\";\nimport type { IDeleteModelTaskInput, IDeleteModelTaskOutput } from \"./types\";\nimport { createDeleteModelRunner } from \"./DeleteModelRunner\";\nimport { DELETE_MODEL_TASK } from \"./constants\";\nimport { createDeleteModelGraphQl } from \"./graphql\";\nimport { createDeleteModelCrud } from \"./graphql/crud\";\n\nconst createDefinition = () => {\n return createTaskDefinition<HcmsTasksContext, IDeleteModelTaskInput, IDeleteModelTaskOutput>({\n id: DELETE_MODEL_TASK,\n disableDatabaseLogs: true,\n title: \"Delete model and all of the entries\",\n maxIterations: 50,\n isPrivate: true,\n async run(params) {\n try {\n const deleteModelRunner = createDeleteModelRunner({\n taskId: params.store.getTask().id,\n context: params.context,\n response: params.response\n });\n return await deleteModelRunner.execute({\n input: params.input,\n isCloseToTimeout: params.isCloseToTimeout,\n isAborted: params.isAborted\n });\n } catch (ex) {\n return params.response.error(ex);\n }\n },\n createInputValidation: ({ validator }) => {\n return {\n modelId: validator.string(),\n lastDeletedId: validator.string().optional()\n };\n }\n });\n};\n\nexport const createDeleteModelTask = () => {\n return [createDefinition(), createDeleteModelCrud(), createDeleteModelGraphQl()];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,MAAMK,gBAAgB,GAAGA,CAAA,KAAM;EAC3B,OAAO,IAAAC,2BAAoB,EAAkE;IACzFC,EAAE,EAAEC,4BAAiB;IACrBC,mBAAmB,EAAE,IAAI;IACzBC,KAAK,EAAE,qCAAqC;IAC5CC,aAAa,EAAE,EAAE;IACjBC,SAAS,EAAE,IAAI;IACf,MAAMC,GAAGA,CAACC,MAAM,EAAE;MACd,IAAI;QACA,MAAMC,iBAAiB,GAAG,IAAAC,0CAAuB,EAAC;UAC9CC,MAAM,EAAEH,MAAM,CAACI,KAAK,CAACC,OAAO,CAAC,CAAC,CAACZ,EAAE;UACjCa,OAAO,EAAEN,MAAM,CAACM,OAAO;UACvBC,QAAQ,EAAEP,MAAM,CAACO;QACrB,CAAC,CAAC;QACF,OAAO,MAAMN,iBAAiB,CAACO,OAAO,CAAC;UACnCC,KAAK,EAAET,MAAM,CAACS,KAAK;UACnBC,gBAAgB,EAAEV,MAAM,CAACU,gBAAgB;UACzCC,SAAS,EAAEX,MAAM,CAACW;QACtB,CAAC,CAAC;MACN,CAAC,CAAC,OAAOC,EAAE,EAAE;QACT,OAAOZ,MAAM,CAACO,QAAQ,CAACM,KAAK,CAACD,EAAE,CAAC;MACpC;IACJ,CAAC;IACDE,qBAAqB,EAAEA,CAAC;MAAEC;IAAU,CAAC,KAAK;MACtC,OAAO;QACHC,OAAO,EAAED,SAAS,CAACE,MAAM,CAAC,CAAC;QAC3BC,aAAa,EAAEH,SAAS,CAACE,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC;MAC/C,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAEM,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,OAAO,CAAC7B,gBAAgB,CAAC,CAAC,EAAE,IAAA8B,2BAAqB,EAAC,CAAC,EAAE,IAAAC,iCAAwB,EAAC,CAAC,CAAC;AACpF,CAAC;AAACC,OAAA,CAAAH,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CmsIdentity } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { ITaskResponseDoneResultOutput } from "@webiny/tasks";
|
|
1
|
+
import type { CmsIdentity } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import type { ITaskResponseDoneResultOutput } from "@webiny/tasks";
|
|
3
3
|
import type { ListValuesResult } from "@webiny/db";
|
|
4
4
|
import type { GenericRecord } from "@webiny/api/types";
|
|
5
5
|
export interface IDeleteModelTaskInput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DeleteCmsModelTaskStatus","exports"],"sources":["types.ts"],"sourcesContent":["import { CmsIdentity } from \"@webiny/api-headless-cms/types\";\nimport { ITaskResponseDoneResultOutput } from \"@webiny/tasks\";\nimport type { ListValuesResult } from \"@webiny/db\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport interface IDeleteModelTaskInput {\n modelId: string;\n lastDeletedId?: string;\n}\n\nexport interface IDeleteModelTaskOutput extends ITaskResponseDoneResultOutput {\n total?: number;\n deleted?: number;\n}\n\nexport enum DeleteCmsModelTaskStatus {\n RUNNING = \"running\",\n DONE = \"done\",\n ERROR = \"error\",\n CANCELED = \"canceled\"\n}\n\nexport interface IDeleteCmsModelTask {\n id: string;\n status: DeleteCmsModelTaskStatus;\n total: number;\n deleted: number;\n message?: string;\n}\n\nexport interface IStoreValue {\n modelId: string;\n tenant: string;\n locale: string;\n identity: CmsIdentity;\n task: string;\n}\n\nexport type ListStoreKeysResult = Promise<ListValuesResult<GenericRecord<string, IStoreValue>>>;\n"],"mappings":";;;;;;IAeYA,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,0BAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAA,OAAxBA,wBAAwB;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["DeleteCmsModelTaskStatus","exports"],"sources":["types.ts"],"sourcesContent":["import type { CmsIdentity } from \"@webiny/api-headless-cms/types\";\nimport type { ITaskResponseDoneResultOutput } from \"@webiny/tasks\";\nimport type { ListValuesResult } from \"@webiny/db\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport interface IDeleteModelTaskInput {\n modelId: string;\n lastDeletedId?: string;\n}\n\nexport interface IDeleteModelTaskOutput extends ITaskResponseDoneResultOutput {\n total?: number;\n deleted?: number;\n}\n\nexport enum DeleteCmsModelTaskStatus {\n RUNNING = \"running\",\n DONE = \"done\",\n ERROR = \"error\",\n CANCELED = \"canceled\"\n}\n\nexport interface IDeleteCmsModelTask {\n id: string;\n status: DeleteCmsModelTaskStatus;\n total: number;\n deleted: number;\n message?: string;\n}\n\nexport interface IStoreValue {\n modelId: string;\n tenant: string;\n locale: string;\n identity: CmsIdentity;\n task: string;\n}\n\nexport type ListStoreKeysResult = Promise<ListValuesResult<GenericRecord<string, IStoreValue>>>;\n"],"mappings":";;;;;;IAeYA,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,0BAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAxBA,wBAAwB;EAAA,OAAxBA,wBAAwB;AAAA","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HcmsBulkActionsContext } from "@webiny/api-headless-cms-bulk-actions/types";
|
|
2
2
|
import type { AcoContext } from "@webiny/api-aco/types";
|
|
3
3
|
import type { HeadlessCms } from "@webiny/api-headless-cms/types";
|
|
4
|
-
import { IDeleteCmsModelTask, IStoreValue } from "./tasks/deleteModel/types";
|
|
4
|
+
import type { IDeleteCmsModelTask, IStoreValue } from "./tasks/deleteModel/types";
|
|
5
5
|
export interface HeadlessCmsFullyDeleteModel {
|
|
6
6
|
fullyDeleteModel: (modelId: string) => Promise<IDeleteCmsModelTask>;
|
|
7
7
|
cancelFullyDeleteModel: (modelId: string) => Promise<IDeleteCmsModelTask>;
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"@webiny/api-headless-cms-bulk-actions/types\";\nimport type { AcoContext } from \"@webiny/api-aco/types\";\nimport type { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { IDeleteCmsModelTask, IStoreValue } from \"~/tasks/deleteModel/types\";\n\nexport interface HeadlessCmsFullyDeleteModel {\n fullyDeleteModel: (modelId: string) => Promise<IDeleteCmsModelTask>;\n cancelFullyDeleteModel: (modelId: string) => Promise<IDeleteCmsModelTask>;\n getDeleteModelProgress: (modelId: string) => Promise<IDeleteCmsModelTask>;\n isModelBeingDeleted: (modelId: string) => Promise<boolean>;\n listModelsBeingDeleted: () => Promise<IStoreValue[]>;\n}\n\nexport interface HcmsTasksContext extends HcmsBulkActionsContext, AcoContext {\n cms: HeadlessCms & HeadlessCmsFullyDeleteModel;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"@webiny/api-headless-cms-bulk-actions/types\";\nimport type { AcoContext } from \"@webiny/api-aco/types\";\nimport type { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport type { IDeleteCmsModelTask, IStoreValue } from \"~/tasks/deleteModel/types\";\n\nexport interface HeadlessCmsFullyDeleteModel {\n fullyDeleteModel: (modelId: string) => Promise<IDeleteCmsModelTask>;\n cancelFullyDeleteModel: (modelId: string) => Promise<IDeleteCmsModelTask>;\n getDeleteModelProgress: (modelId: string) => Promise<IDeleteCmsModelTask>;\n isModelBeingDeleted: (modelId: string) => Promise<boolean>;\n listModelsBeingDeleted: () => Promise<IStoreValue[]>;\n}\n\nexport interface HcmsTasksContext extends HcmsBulkActionsContext, AcoContext {\n cms: HeadlessCms & HeadlessCmsFullyDeleteModel;\n}\n"],"mappings":"","ignoreList":[]}
|