@webiny/api-headless-cms-bulk-actions 6.0.0-alpha.5 → 6.0.0-rc.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/README.md +10 -14
- package/abstractions/IUseCase.js +1 -5
- package/abstractions/index.d.ts +1 -3
- package/abstractions/index.js +1 -38
- package/abstractions/index.js.map +1 -1
- package/domain/BulkActionName.d.ts +3 -0
- package/domain/BulkActionName.js +20 -0
- package/domain/BulkActionName.js.map +1 -0
- package/features/BulkActionContext/abstractions.d.ts +5 -0
- package/features/BulkActionContext/abstractions.js +6 -0
- package/features/BulkActionContext/abstractions.js.map +1 -0
- package/features/BulkActionContext/index.d.ts +1 -0
- package/features/BulkActionContext/index.js +3 -0
- package/features/BulkActionContext/index.js.map +1 -0
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.d.ts +15 -0
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js +29 -0
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js.map +1 -0
- package/features/DeleteEntriesBulkAction/feature.d.ts +1 -0
- package/features/DeleteEntriesBulkAction/feature.js +10 -0
- package/features/DeleteEntriesBulkAction/feature.js.map +1 -0
- package/features/EntriesBulkAction/abstractions.d.ts +38 -0
- package/features/EntriesBulkAction/abstractions.js +5 -0
- package/features/EntriesBulkAction/abstractions.js.map +1 -0
- package/features/EntriesBulkAction/createBulkActionTasks.d.ts +2 -0
- package/features/EntriesBulkAction/createBulkActionTasks.js +147 -0
- package/features/EntriesBulkAction/createBulkActionTasks.js.map +1 -0
- package/{useCases/internals/ChildTaskCleanup → features/EntriesBulkAction/internals}/ChildTasksCleanup.d.ts +1 -1
- package/{useCases/internals/ChildTaskCleanup → features/EntriesBulkAction/internals}/ChildTasksCleanup.js +3 -10
- package/features/EntriesBulkAction/internals/ChildTasksCleanup.js.map +1 -0
- package/features/EntriesBulkAction/internals/CreateTasksByModel.d.ts +16 -0
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js +107 -0
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js.map +1 -0
- package/features/EntriesBulkAction/internals/ProcessTask.d.ts +16 -0
- package/features/EntriesBulkAction/internals/ProcessTask.js +76 -0
- package/features/EntriesBulkAction/internals/ProcessTask.js.map +1 -0
- package/{useCases/internals/ProcessTask/Result.d.ts → features/EntriesBulkAction/internals/ProcessTaskResult.d.ts} +1 -1
- package/{useCases/internals/ProcessTask/Result.js → features/EntriesBulkAction/internals/ProcessTaskResult.js} +2 -9
- package/features/EntriesBulkAction/internals/ProcessTaskResult.js.map +1 -0
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.d.ts +13 -0
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js +56 -0
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js.map +1 -0
- package/{useCases/internals/CreateTasksByModel → features/EntriesBulkAction/internals}/TaskCache.d.ts +4 -4
- package/{useCases/internals/CreateTasksByModel → features/EntriesBulkAction/internals}/TaskCache.js +1 -8
- package/features/EntriesBulkAction/internals/TaskCache.js.map +1 -0
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.d.ts +15 -0
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js +30 -0
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js.map +1 -0
- package/features/MoveToFolderBulkAction/feature.d.ts +1 -0
- package/features/MoveToFolderBulkAction/feature.js +10 -0
- package/features/MoveToFolderBulkAction/feature.js.map +1 -0
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.d.ts +15 -0
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js +29 -0
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js.map +1 -0
- package/features/MoveToTrashBulkAction/feature.d.ts +1 -0
- package/features/MoveToTrashBulkAction/feature.js +10 -0
- package/features/MoveToTrashBulkAction/feature.js.map +1 -0
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.d.ts +15 -0
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js +37 -0
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js.map +1 -0
- package/features/PublishEntriesBulkAction/feature.d.ts +1 -0
- package/features/PublishEntriesBulkAction/feature.js +10 -0
- package/features/PublishEntriesBulkAction/feature.js.map +1 -0
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.d.ts +15 -0
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js +27 -0
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js.map +1 -0
- package/features/RestoreEntriesBulkAction/feature.d.ts +1 -0
- package/features/RestoreEntriesBulkAction/feature.js +10 -0
- package/features/RestoreEntriesBulkAction/feature.js.map +1 -0
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.d.ts +15 -0
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js +27 -0
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js.map +1 -0
- package/features/UnpublishEntriesBulkAction/feature.d.ts +1 -0
- package/features/UnpublishEntriesBulkAction/feature.js +10 -0
- package/features/UnpublishEntriesBulkAction/feature.js.map +1 -0
- package/graphql/createBulkActionGraphQL.d.ts +3 -0
- package/graphql/createBulkActionGraphQL.js +64 -0
- package/graphql/createBulkActionGraphQL.js.map +1 -0
- package/graphql/createDefaultGraphQL.d.ts +3 -0
- package/{plugins → graphql}/createDefaultGraphQL.js +10 -18
- package/graphql/createDefaultGraphQL.js.map +1 -0
- package/handlers/eventBridgeEventHandler.js +3 -10
- package/handlers/eventBridgeEventHandler.js.map +1 -1
- package/handlers/index.d.ts +1 -1
- package/handlers/index.js +4 -11
- package/handlers/index.js.map +1 -1
- package/handlers/setupEventsTenant.js +3 -10
- package/handlers/setupEventsTenant.js.map +1 -1
- package/index.d.ts +8 -6
- package/index.js +46 -69
- package/index.js.map +1 -1
- package/package.json +19 -23
- package/tasks/EmptyTrashBinTaskDefinition.d.ts +26 -0
- package/tasks/EmptyTrashBinTaskDefinition.js +124 -0
- package/tasks/EmptyTrashBinTaskDefinition.js.map +1 -0
- package/tasks/createEmptyTrashBinsTask.d.ts +1 -2
- package/tasks/createEmptyTrashBinsTask.js +5 -114
- package/tasks/createEmptyTrashBinsTask.js.map +1 -1
- package/tasks/index.d.ts +1 -2
- package/tasks/index.js +1 -27
- package/tasks/index.js.map +1 -1
- package/types.d.ts +12 -12
- package/types.js +4 -7
- package/types.js.map +1 -1
- package/abstractions/IListEntries.d.ts +0 -7
- package/abstractions/IListEntries.js +0 -7
- package/abstractions/IListEntries.js.map +0 -1
- package/abstractions/IProcessEntry.d.ts +0 -4
- package/abstractions/IProcessEntry.js +0 -7
- package/abstractions/IProcessEntry.js.map +0 -1
- package/plugins/createBulkAction.d.ts +0 -10
- package/plugins/createBulkAction.js +0 -36
- package/plugins/createBulkAction.js.map +0 -1
- package/plugins/createBulkActionGraphQL.d.ts +0 -7
- package/plugins/createBulkActionGraphQL.js +0 -72
- package/plugins/createBulkActionGraphQL.js.map +0 -1
- package/plugins/createBulkActionTasks.d.ts +0 -9
- package/plugins/createBulkActionTasks.js +0 -135
- package/plugins/createBulkActionTasks.js.map +0 -1
- package/plugins/createDefaultGraphQL.d.ts +0 -3
- package/plugins/createDefaultGraphQL.js.map +0 -1
- package/plugins/index.d.ts +0 -2
- package/plugins/index.js +0 -29
- package/plugins/index.js.map +0 -1
- package/tasks/createBulkActionEntriesTasks.d.ts +0 -1
- package/tasks/createBulkActionEntriesTasks.js +0 -38
- package/tasks/createBulkActionEntriesTasks.js.map +0 -1
- package/useCases/DeleteEntry.d.ts +0 -10
- package/useCases/DeleteEntry.js +0 -26
- package/useCases/DeleteEntry.js.map +0 -1
- package/useCases/ListDeletedEntries.d.ts +0 -13
- package/useCases/ListDeletedEntries.js +0 -28
- package/useCases/ListDeletedEntries.js.map +0 -1
- package/useCases/ListLatestEntries.d.ts +0 -13
- package/useCases/ListLatestEntries.js +0 -28
- package/useCases/ListLatestEntries.js.map +0 -1
- package/useCases/ListNotPublishedEntries.d.ts +0 -13
- package/useCases/ListNotPublishedEntries.js +0 -34
- package/useCases/ListNotPublishedEntries.js.map +0 -1
- package/useCases/ListPublishedEntries.d.ts +0 -13
- package/useCases/ListPublishedEntries.js +0 -28
- package/useCases/ListPublishedEntries.js.map +0 -1
- package/useCases/MoveEntryToFolder.d.ts +0 -13
- package/useCases/MoveEntryToFolder.js +0 -23
- package/useCases/MoveEntryToFolder.js.map +0 -1
- package/useCases/MoveEntryToTrash.d.ts +0 -10
- package/useCases/MoveEntryToTrash.js +0 -26
- package/useCases/MoveEntryToTrash.js.map +0 -1
- package/useCases/PublishEntry.d.ts +0 -10
- package/useCases/PublishEntry.js +0 -20
- package/useCases/PublishEntry.js.map +0 -1
- package/useCases/RestoreEntryFromTrash.d.ts +0 -10
- package/useCases/RestoreEntryFromTrash.js +0 -24
- package/useCases/RestoreEntryFromTrash.js.map +0 -1
- package/useCases/UnpublishEntry.d.ts +0 -10
- package/useCases/UnpublishEntry.js +0 -20
- package/useCases/UnpublishEntry.js.map +0 -1
- package/useCases/index.d.ts +0 -10
- package/useCases/index.js +0 -117
- package/useCases/index.js.map +0 -1
- package/useCases/internals/ChildTaskCleanup/ChildTasksCleanup.js.map +0 -1
- package/useCases/internals/ChildTaskCleanup/index.d.ts +0 -1
- package/useCases/internals/ChildTaskCleanup/index.js +0 -18
- package/useCases/internals/ChildTaskCleanup/index.js.map +0 -1
- package/useCases/internals/CreateTasksByModel/CreateTasksByModel.d.ts +0 -13
- package/useCases/internals/CreateTasksByModel/CreateTasksByModel.js +0 -111
- package/useCases/internals/CreateTasksByModel/CreateTasksByModel.js.map +0 -1
- package/useCases/internals/CreateTasksByModel/TaskCache.js.map +0 -1
- package/useCases/internals/CreateTasksByModel/index.d.ts +0 -1
- package/useCases/internals/CreateTasksByModel/index.js +0 -18
- package/useCases/internals/CreateTasksByModel/index.js.map +0 -1
- package/useCases/internals/ProcessTask/ProcessTask.d.ts +0 -14
- package/useCases/internals/ProcessTask/ProcessTask.js +0 -81
- package/useCases/internals/ProcessTask/ProcessTask.js.map +0 -1
- package/useCases/internals/ProcessTask/Result.js.map +0 -1
- package/useCases/internals/ProcessTask/index.d.ts +0 -1
- package/useCases/internals/ProcessTask/index.js +0 -18
- package/useCases/internals/ProcessTask/index.js.map +0 -1
- package/useCases/internals/ProcessTasksByModel/ProcessTasksByModel.d.ts +0 -11
- package/useCases/internals/ProcessTasksByModel/ProcessTasksByModel.js +0 -67
- package/useCases/internals/ProcessTasksByModel/ProcessTasksByModel.js.map +0 -1
- package/useCases/internals/ProcessTasksByModel/index.d.ts +0 -1
- package/useCases/internals/ProcessTasksByModel/index.js +0 -18
- package/useCases/internals/ProcessTasksByModel/index.js.map +0 -1
- package/useCases/internals/index.d.ts +0 -4
- package/useCases/internals/index.js +0 -51
- package/useCases/internals/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-bulk-actions",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"description": "Webiny Headless CMS bulk actions",
|
|
6
7
|
"keywords": [
|
|
@@ -13,33 +14,28 @@
|
|
|
13
14
|
},
|
|
14
15
|
"license": "MIT",
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@webiny/api-headless-cms": "6.0.0-
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/handler
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
17
|
+
"@webiny/api-headless-cms": "6.0.0-rc.1",
|
|
18
|
+
"@webiny/feature": "6.0.0-rc.1",
|
|
19
|
+
"@webiny/handler": "6.0.0-rc.1",
|
|
20
|
+
"@webiny/handler-aws": "6.0.0-rc.1",
|
|
21
|
+
"@webiny/tasks": "6.0.0-rc.1",
|
|
22
|
+
"@webiny/utils": "6.0.0-rc.1"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
23
|
-
"@webiny/api": "6.0.0-
|
|
24
|
-
"@webiny/api-
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/
|
|
29
|
-
"@webiny/
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"graphql": "15.9.0",
|
|
34
|
-
"typescript": "5.3.3"
|
|
35
|
-
},
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build": "node ../cli/bin.js run build",
|
|
38
|
-
"watch": "node ../cli/bin.js run watch"
|
|
25
|
+
"@webiny/api": "6.0.0-rc.1",
|
|
26
|
+
"@webiny/api-core": "6.0.0-rc.1",
|
|
27
|
+
"@webiny/build-tools": "6.0.0-rc.1",
|
|
28
|
+
"@webiny/handler-graphql": "6.0.0-rc.1",
|
|
29
|
+
"@webiny/plugins": "6.0.0-rc.1",
|
|
30
|
+
"@webiny/project-utils": "6.0.0-rc.1",
|
|
31
|
+
"@webiny/wcp": "6.0.0-rc.1",
|
|
32
|
+
"graphql": "16.12.0",
|
|
33
|
+
"typescript": "5.9.3",
|
|
34
|
+
"vitest": "4.0.18"
|
|
39
35
|
},
|
|
40
36
|
"publishConfig": {
|
|
41
37
|
"access": "public",
|
|
42
38
|
"directory": "dist"
|
|
43
39
|
},
|
|
44
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "36d702721ff9ed39fb21d6f5fe7922a2a8716e63"
|
|
45
41
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from "../types.js";
|
|
2
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
|
+
import { ListTenantsUseCase } from "@webiny/api-core/features/tenancy/ListTenants/index.js";
|
|
4
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
5
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
6
|
+
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
7
|
+
import { ListDeletedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
8
|
+
declare class EmptyTrashBinTask implements TaskDefinition.Interface<IEmptyTrashBinsInput, IEmptyTrashBinsOutput> {
|
|
9
|
+
private tenantContext;
|
|
10
|
+
private listTenants;
|
|
11
|
+
private listModels;
|
|
12
|
+
private listDeletedEntries;
|
|
13
|
+
private deleteEntry;
|
|
14
|
+
readonly isPrivate = true;
|
|
15
|
+
readonly id = "hcmsEntriesEmptyTrashBins";
|
|
16
|
+
readonly title = "Headless CMS - Empty all trash bins";
|
|
17
|
+
readonly description = "Delete all entries in the trash bin for each model in the system.";
|
|
18
|
+
readonly maxIterations = 120;
|
|
19
|
+
readonly databaseLogs = false;
|
|
20
|
+
constructor(tenantContext: TenantContext.Interface, listTenants: ListTenantsUseCase.Interface, listModels: ListModelsUseCase.Interface, listDeletedEntries: ListDeletedEntriesUseCase.Interface, deleteEntry: DeleteEntryUseCase.Interface);
|
|
21
|
+
run(params: TaskDefinition.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>>;
|
|
22
|
+
}
|
|
23
|
+
export declare const EmptyTrashBinTaskDefinition: typeof EmptyTrashBinTask & {
|
|
24
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskDefinition<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
|
+
import { ListTenantsUseCase } from "@webiny/api-core/features/tenancy/ListTenants/index.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
|
+
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
|
+
import { ListDeletedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
7
|
+
const calculateDateTimeString = () => {
|
|
8
|
+
// Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,
|
|
9
|
+
// or default to 90 days if not set or set to 0.
|
|
10
|
+
const retentionPeriodFromEnv = process.env["WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS"];
|
|
11
|
+
const retentionPeriod = retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0 ? Number(retentionPeriodFromEnv) : 90;
|
|
12
|
+
|
|
13
|
+
// Calculate the date-time by subtracting the retention period (in days) from the current date.
|
|
14
|
+
const currentDate = new Date();
|
|
15
|
+
currentDate.setDate(currentDate.getDate() - retentionPeriod);
|
|
16
|
+
|
|
17
|
+
// Return the calculated date-time string in ISO 8601 format.
|
|
18
|
+
return currentDate.toISOString();
|
|
19
|
+
};
|
|
20
|
+
class EmptyTrashBinTask {
|
|
21
|
+
isPrivate = true;
|
|
22
|
+
id = "hcmsEntriesEmptyTrashBins";
|
|
23
|
+
title = "Headless CMS - Empty all trash bins";
|
|
24
|
+
description = "Delete all entries in the trash bin for each model in the system.";
|
|
25
|
+
maxIterations = 120;
|
|
26
|
+
databaseLogs = false;
|
|
27
|
+
constructor(tenantContext, listTenants, listModels, listDeletedEntries, deleteEntry) {
|
|
28
|
+
this.tenantContext = tenantContext;
|
|
29
|
+
this.listTenants = listTenants;
|
|
30
|
+
this.listModels = listModels;
|
|
31
|
+
this.listDeletedEntries = listDeletedEntries;
|
|
32
|
+
this.deleteEntry = deleteEntry;
|
|
33
|
+
}
|
|
34
|
+
async run(params) {
|
|
35
|
+
const {
|
|
36
|
+
input,
|
|
37
|
+
controller
|
|
38
|
+
} = params;
|
|
39
|
+
|
|
40
|
+
// Abort the task if needed.
|
|
41
|
+
if (controller.runtime.isAborted()) {
|
|
42
|
+
return controller.response.aborted();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Fetch all tenants, excluding those already processed.
|
|
46
|
+
const tenantsResult = await this.listTenants.execute();
|
|
47
|
+
const baseTenants = tenantsResult.value;
|
|
48
|
+
const executedTenantIds = input.executedTenantIds || [];
|
|
49
|
+
const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));
|
|
50
|
+
let shouldTaskContinue = false;
|
|
51
|
+
|
|
52
|
+
// Iterate over each tenant.
|
|
53
|
+
await this.tenantContext.withEachTenant(tenants, async tenant => {
|
|
54
|
+
if (controller.runtime.isCloseToTimeout()) {
|
|
55
|
+
shouldTaskContinue = true;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (controller.runtime.isCloseToTimeout()) {
|
|
59
|
+
shouldTaskContinue = true;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// List all non-private models.
|
|
64
|
+
const modelsResult = await this.listModels.execute({
|
|
65
|
+
includePrivate: false
|
|
66
|
+
});
|
|
67
|
+
const models = modelsResult.value;
|
|
68
|
+
|
|
69
|
+
// Process each model to delete trashed entries.
|
|
70
|
+
for (const model of models) {
|
|
71
|
+
// Query parameters for fetching deleted entries older than a minute ago.
|
|
72
|
+
const listEntriesParams = {
|
|
73
|
+
where: {
|
|
74
|
+
deletedOn_lt: calculateDateTimeString()
|
|
75
|
+
},
|
|
76
|
+
limit: 50
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Continue deleting entries while there are entries left to delete.
|
|
80
|
+
while (true) {
|
|
81
|
+
const listResult = await this.listDeletedEntries.execute(model, listEntriesParams);
|
|
82
|
+
const {
|
|
83
|
+
entries,
|
|
84
|
+
meta
|
|
85
|
+
} = listResult.value;
|
|
86
|
+
if (meta.totalCount === 0) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (controller.runtime.isCloseToTimeout()) {
|
|
90
|
+
shouldTaskContinue = true;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
if (controller.runtime.isCloseToTimeout()) {
|
|
95
|
+
shouldTaskContinue = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
// Delete each entry individually.
|
|
99
|
+
await this.deleteEntry.execute(model, entry.id, {
|
|
100
|
+
permanently: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// If the task isn't continuing, add the tenant to the executed list.
|
|
107
|
+
if (!shouldTaskContinue) {
|
|
108
|
+
executedTenantIds.push(tenant.id);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Continue the task or mark it as done based on the `shouldContinue` flag.
|
|
113
|
+
return shouldTaskContinue ? controller.response.continue({
|
|
114
|
+
...input,
|
|
115
|
+
executedTenantIds
|
|
116
|
+
}) : controller.response.done("Task done: emptied the trash bin for all registered models.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export const EmptyTrashBinTaskDefinition = TaskDefinition.createImplementation({
|
|
120
|
+
implementation: EmptyTrashBinTask,
|
|
121
|
+
dependencies: [TenantContext, ListTenantsUseCase, ListModelsUseCase, ListDeletedEntriesUseCase, DeleteEntryUseCase]
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=EmptyTrashBinTaskDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TaskDefinition","ListTenantsUseCase","TenantContext","ListModelsUseCase","DeleteEntryUseCase","ListDeletedEntriesUseCase","calculateDateTimeString","retentionPeriodFromEnv","process","env","retentionPeriod","Number","currentDate","Date","setDate","getDate","toISOString","EmptyTrashBinTask","isPrivate","id","title","description","maxIterations","databaseLogs","constructor","tenantContext","listTenants","listModels","listDeletedEntries","deleteEntry","run","params","input","controller","runtime","isAborted","response","aborted","tenantsResult","execute","baseTenants","value","executedTenantIds","tenants","filter","tenant","includes","shouldTaskContinue","withEachTenant","isCloseToTimeout","modelsResult","includePrivate","models","model","listEntriesParams","where","deletedOn_lt","limit","listResult","entries","meta","totalCount","entry","permanently","push","continue","done","EmptyTrashBinTaskDefinition","createImplementation","implementation","dependencies"],"sources":["EmptyTrashBinTaskDefinition.ts"],"sourcesContent":["import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from \"~/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListTenantsUseCase } from \"@webiny/api-core/features/tenancy/ListTenants/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\n\nconst calculateDateTimeString = () => {\n // Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,\n // or default to 90 days if not set or set to 0.\n const retentionPeriodFromEnv = process.env[\"WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS\"];\n const retentionPeriod =\n retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0\n ? Number(retentionPeriodFromEnv)\n : 90;\n\n // Calculate the date-time by subtracting the retention period (in days) from the current date.\n const currentDate = new Date();\n currentDate.setDate(currentDate.getDate() - retentionPeriod);\n\n // Return the calculated date-time string in ISO 8601 format.\n return currentDate.toISOString();\n};\n\nclass EmptyTrashBinTask\n implements TaskDefinition.Interface<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>\n{\n public readonly isPrivate = true;\n public readonly id = \"hcmsEntriesEmptyTrashBins\";\n public readonly title = \"Headless CMS - Empty all trash bins\";\n public readonly description =\n \"Delete all entries in the trash bin for each model in the system.\";\n public readonly maxIterations = 120;\n public readonly databaseLogs = false;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private listTenants: ListTenantsUseCase.Interface,\n private listModels: ListModelsUseCase.Interface,\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async run(\n params: TaskDefinition.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>\n ): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>> {\n const { input, controller } = params;\n\n // Abort the task if needed.\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n // Fetch all tenants, excluding those already processed.\n const tenantsResult = await this.listTenants.execute();\n const baseTenants = tenantsResult.value;\n const executedTenantIds = input.executedTenantIds || [];\n const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));\n\n let shouldTaskContinue = false;\n\n // Iterate over each tenant.\n await this.tenantContext.withEachTenant(tenants, async tenant => {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n return;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n return;\n }\n\n // List all non-private models.\n const modelsResult = await this.listModels.execute({ includePrivate: false });\n const models = modelsResult.value;\n\n // Process each model to delete trashed entries.\n for (const model of models) {\n // Query parameters for fetching deleted entries older than a minute ago.\n const listEntriesParams = {\n where: {\n deletedOn_lt: calculateDateTimeString()\n },\n limit: 50\n };\n\n // Continue deleting entries while there are entries left to delete.\n while (true) {\n const listResult = await this.listDeletedEntries.execute(\n model,\n listEntriesParams\n );\n const { entries, meta } = listResult.value;\n\n if (meta.totalCount === 0) {\n break;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n for (const entry of entries) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n // Delete each entry individually.\n await this.deleteEntry.execute(model, entry.id, { permanently: true });\n }\n }\n }\n\n // If the task isn't continuing, add the tenant to the executed list.\n if (!shouldTaskContinue) {\n executedTenantIds.push(tenant.id);\n }\n });\n\n // Continue the task or mark it as done based on the `shouldContinue` flag.\n return shouldTaskContinue\n ? controller.response.continue({ ...input, executedTenantIds })\n : controller.response.done(\n \"Task done: emptied the trash bin for all registered models.\"\n );\n }\n}\n\nexport const EmptyTrashBinTaskDefinition = TaskDefinition.createImplementation({\n implementation: EmptyTrashBinTask,\n dependencies: [\n TenantContext,\n ListTenantsUseCase,\n ListModelsUseCase,\n ListDeletedEntriesUseCase,\n DeleteEntryUseCase\n ]\n});\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const createEmptyTrashBinsTask: () => import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, IEmptyTrashBinsInput, import("@webiny/tasks").ITaskResponseDoneResultOutput>;
|
|
1
|
+
export declare const createEmptyTrashBinsTask: () => import("@webiny/api").ContextPlugin<import("@webiny/api/types.js").Context>;
|
|
@@ -1,118 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.createEmptyTrashBinsTask = void 0;
|
|
7
|
-
var _tasks = require("@webiny/tasks");
|
|
8
|
-
var _useCases = require("../useCases");
|
|
9
|
-
const calculateDateTimeString = () => {
|
|
10
|
-
// Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,
|
|
11
|
-
// or default to 90 days if not set or set to 0.
|
|
12
|
-
const retentionPeriodFromEnv = process.env["WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS"];
|
|
13
|
-
const retentionPeriod = retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0 ? Number(retentionPeriodFromEnv) : 90;
|
|
14
|
-
|
|
15
|
-
// Calculate the date-time by subtracting the retention period (in days) from the current date.
|
|
16
|
-
const currentDate = new Date();
|
|
17
|
-
currentDate.setDate(currentDate.getDate() - retentionPeriod);
|
|
18
|
-
|
|
19
|
-
// Return the calculated date-time string in ISO 8601 format.
|
|
20
|
-
return currentDate.toISOString();
|
|
21
|
-
};
|
|
22
|
-
const createEmptyTrashBinsTask = () => {
|
|
23
|
-
return (0, _tasks.createTaskDefinition)({
|
|
24
|
-
isPrivate: true,
|
|
25
|
-
id: "hcmsEntriesEmptyTrashBins",
|
|
26
|
-
title: "Headless CMS - Empty all trash bins",
|
|
27
|
-
description: "Delete all entries in the trash bin for each model in the system.",
|
|
28
|
-
maxIterations: 120,
|
|
29
|
-
disableDatabaseLogs: true,
|
|
30
|
-
run: async params => {
|
|
31
|
-
const {
|
|
32
|
-
response,
|
|
33
|
-
isAborted,
|
|
34
|
-
context,
|
|
35
|
-
input,
|
|
36
|
-
isCloseToTimeout
|
|
37
|
-
} = params;
|
|
38
|
-
|
|
39
|
-
// Abort the task if needed.
|
|
40
|
-
if (isAborted()) {
|
|
41
|
-
return response.aborted();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Fetch all tenants, excluding those already processed.
|
|
45
|
-
const baseTenants = await context.tenancy.listTenants();
|
|
46
|
-
const executedTenantIds = input.executedTenantIds || [];
|
|
47
|
-
const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));
|
|
48
|
-
let shouldContinue = false; // Flag to check if task should continue.
|
|
49
|
-
|
|
50
|
-
// Iterate over each tenant.
|
|
51
|
-
await context.tenancy.withEachTenant(tenants, async tenant => {
|
|
52
|
-
if (isCloseToTimeout()) {
|
|
53
|
-
shouldContinue = true;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Reloading locales for the current tenant to ensure the correct data is available before proceeding.
|
|
58
|
-
await context.i18n.reloadLocales();
|
|
59
|
-
|
|
60
|
-
// Fetch all locales for the tenant.
|
|
61
|
-
const locales = context.i18n.getLocales();
|
|
62
|
-
await context.i18n.withEachLocale(locales, async () => {
|
|
63
|
-
if (isCloseToTimeout()) {
|
|
64
|
-
shouldContinue = true;
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// List all non-private models for the current locale.
|
|
69
|
-
const models = await context.security.withoutAuthorization(async () => (await context.cms.listModels()).filter(m => !m.isPrivate));
|
|
70
|
-
|
|
71
|
-
// Process each model to delete trashed entries.
|
|
72
|
-
for (const model of models) {
|
|
73
|
-
const list = (0, _useCases.createListDeletedEntries)(context); // List trashed entries.
|
|
74
|
-
const mutation = (0, _useCases.createDeleteEntry)(context); // Mutation to delete entries.
|
|
75
|
-
|
|
76
|
-
// Query parameters for fetching deleted entries older than a minute ago.
|
|
77
|
-
const listEntriesParams = {
|
|
78
|
-
where: {
|
|
79
|
-
deletedOn_lt: calculateDateTimeString()
|
|
80
|
-
},
|
|
81
|
-
limit: 50
|
|
82
|
-
};
|
|
83
|
-
let result;
|
|
84
|
-
// Continue deleting entries while there are entries left to delete.
|
|
85
|
-
while ((result = await list.execute(model.modelId, listEntriesParams)) && result.meta.totalCount > 0) {
|
|
86
|
-
if (isCloseToTimeout()) {
|
|
87
|
-
shouldContinue = true;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
for (const entry of result.entries) {
|
|
91
|
-
if (isCloseToTimeout()) {
|
|
92
|
-
shouldContinue = true;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
// Delete each entry individually.
|
|
96
|
-
await mutation.execute(model, entry.id);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// If the task isn't continuing, add the tenant to the executed list.
|
|
103
|
-
if (!shouldContinue) {
|
|
104
|
-
executedTenantIds.push(tenant.id);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Continue the task or mark it as done based on the `shouldContinue` flag.
|
|
109
|
-
return shouldContinue ? response.continue({
|
|
110
|
-
...input,
|
|
111
|
-
executedTenantIds
|
|
112
|
-
}) : response.done("Task done: emptied the trash bin for all registered models.");
|
|
113
|
-
}
|
|
1
|
+
import { createContextPlugin } from "@webiny/api";
|
|
2
|
+
import { EmptyTrashBinTaskDefinition } from "./EmptyTrashBinTaskDefinition.js";
|
|
3
|
+
export const createEmptyTrashBinsTask = () => {
|
|
4
|
+
return createContextPlugin(context => {
|
|
5
|
+
context.container.register(EmptyTrashBinTaskDefinition);
|
|
114
6
|
});
|
|
115
7
|
};
|
|
116
|
-
exports.createEmptyTrashBinsTask = createEmptyTrashBinsTask;
|
|
117
8
|
|
|
118
9
|
//# sourceMappingURL=createEmptyTrashBinsTask.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createContextPlugin","EmptyTrashBinTaskDefinition","createEmptyTrashBinsTask","context","container","register"],"sources":["createEmptyTrashBinsTask.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { EmptyTrashBinTaskDefinition } from \"./EmptyTrashBinTaskDefinition.js\";\n\nexport const createEmptyTrashBinsTask = () => {\n return createContextPlugin(context => {\n context.container.register(EmptyTrashBinTaskDefinition);\n });\n};\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,aAAa;AACjD,SAASC,2BAA2B;AAEpC,OAAO,MAAMC,wBAAwB,GAAGA,CAAA,KAAM;EAC1C,OAAOF,mBAAmB,CAACG,OAAO,IAAI;IAClCA,OAAO,CAACC,SAAS,CAACC,QAAQ,CAACJ,2BAA2B,CAAC;EAC3D,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
package/tasks/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./createEmptyTrashBinsTask";
|
|
1
|
+
export * from "./createEmptyTrashBinsTask.js";
|
package/tasks/index.js
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _createBulkActionEntriesTasks = require("./createBulkActionEntriesTasks");
|
|
7
|
-
Object.keys(_createBulkActionEntriesTasks).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _createBulkActionEntriesTasks[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _createBulkActionEntriesTasks[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _createEmptyTrashBinsTask = require("./createEmptyTrashBinsTask");
|
|
18
|
-
Object.keys(_createEmptyTrashBinsTask).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _createEmptyTrashBinsTask[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _createEmptyTrashBinsTask[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
1
|
+
export * from "./createEmptyTrashBinsTask.js";
|
|
28
2
|
|
|
29
3
|
//# sourceMappingURL=index.js.map
|
package/tasks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./createEmptyTrashBinsTask.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CmsContext } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import type { Context as BaseContext } from "@webiny/handler/types";
|
|
3
|
-
import type { Context as TasksContext,
|
|
4
|
-
import
|
|
1
|
+
import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { Context as BaseContext } from "@webiny/handler/types.js";
|
|
3
|
+
import type { Context as TasksContext, ITaskIdentity } from "@webiny/tasks/types.js";
|
|
4
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
5
5
|
export interface HcmsBulkActionsContext extends BaseContext, CmsContext, TasksContext {
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
@@ -11,15 +11,15 @@ export interface IBulkActionOperationInput {
|
|
|
11
11
|
modelId: string;
|
|
12
12
|
ids: string[];
|
|
13
13
|
data?: Record<string, any>;
|
|
14
|
-
identity:
|
|
14
|
+
identity: ITaskIdentity;
|
|
15
15
|
done?: string[];
|
|
16
16
|
failed?: string[];
|
|
17
17
|
}
|
|
18
|
-
export interface IBulkActionOperationOutput
|
|
18
|
+
export interface IBulkActionOperationOutput {
|
|
19
19
|
done: string[];
|
|
20
20
|
failed: string[];
|
|
21
21
|
}
|
|
22
|
-
export type IBulkActionOperationTaskParams =
|
|
22
|
+
export type IBulkActionOperationTaskParams = TaskDefinition.RunParams<IBulkActionOperationInput, IBulkActionOperationOutput>;
|
|
23
23
|
/**
|
|
24
24
|
* Bulk Action Operation By Model
|
|
25
25
|
*/
|
|
@@ -31,23 +31,23 @@ export declare enum BulkActionOperationByModelAction {
|
|
|
31
31
|
}
|
|
32
32
|
export interface IBulkActionOperationByModelInput {
|
|
33
33
|
modelId: string;
|
|
34
|
-
identity?:
|
|
34
|
+
identity?: ITaskIdentity;
|
|
35
35
|
where?: Record<string, any>;
|
|
36
36
|
search?: string;
|
|
37
37
|
after?: string | null;
|
|
38
38
|
data?: Record<string, any>;
|
|
39
39
|
action?: BulkActionOperationByModelAction;
|
|
40
40
|
}
|
|
41
|
-
export interface IBulkActionOperationByModelOutput
|
|
41
|
+
export interface IBulkActionOperationByModelOutput {
|
|
42
42
|
done: string[];
|
|
43
43
|
failed: string[];
|
|
44
44
|
}
|
|
45
|
-
export type IBulkActionOperationByModelTaskParams =
|
|
45
|
+
export type IBulkActionOperationByModelTaskParams = TaskDefinition.RunParams<IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput>;
|
|
46
46
|
/**
|
|
47
47
|
* Empty Trash Bin
|
|
48
48
|
*/
|
|
49
49
|
export interface IEmptyTrashBinsInput {
|
|
50
50
|
executedTenantIds?: string[] | null;
|
|
51
51
|
}
|
|
52
|
-
export type IEmptyTrashBinsOutput =
|
|
53
|
-
export type IEmptyTrashBinsTaskParams =
|
|
52
|
+
export type IEmptyTrashBinsOutput = TaskDefinition.ResultDone;
|
|
53
|
+
export type IEmptyTrashBinsTaskParams = TaskDefinition.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>;
|
package/types.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BulkActionOperationByModelAction = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* Bulk Action Operation
|
|
9
3
|
*/
|
|
4
|
+
|
|
10
5
|
/**
|
|
11
6
|
* Bulk Action Operation By Model
|
|
12
7
|
*/
|
|
13
|
-
|
|
8
|
+
|
|
9
|
+
export let BulkActionOperationByModelAction = /*#__PURE__*/function (BulkActionOperationByModelAction) {
|
|
14
10
|
BulkActionOperationByModelAction["CREATE_SUBTASKS"] = "CREATE_SUBTASKS";
|
|
15
11
|
BulkActionOperationByModelAction["CHECK_MORE_SUBTASKS"] = "CHECK_MORE_SUBTASKS";
|
|
16
12
|
BulkActionOperationByModelAction["PROCESS_SUBTASKS"] = "PROCESS_SUBTASKS";
|
|
17
13
|
BulkActionOperationByModelAction["END_TASK"] = "END_TASK";
|
|
18
14
|
return BulkActionOperationByModelAction;
|
|
19
15
|
}({});
|
|
16
|
+
|
|
20
17
|
/**
|
|
21
18
|
* Empty Trash Bin
|
|
22
19
|
*/
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BulkActionOperationByModelAction"
|
|
1
|
+
{"version":3,"names":["BulkActionOperationByModelAction"],"sources":["types.ts"],"sourcesContent":["import type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Context as BaseContext } from \"@webiny/handler/types.js\";\nimport type { Context as TasksContext, ITaskIdentity } from \"@webiny/tasks/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface HcmsBulkActionsContext extends BaseContext, CmsContext, TasksContext {}\n\n/**\n * Bulk Action Operation\n */\n\nexport interface IBulkActionOperationInput {\n modelId: string;\n ids: string[];\n data?: Record<string, any>;\n identity: ITaskIdentity;\n done?: string[];\n failed?: string[];\n}\n\nexport interface IBulkActionOperationOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n>;\n\n/**\n * Bulk Action Operation By Model\n */\n\nexport enum BulkActionOperationByModelAction {\n CREATE_SUBTASKS = \"CREATE_SUBTASKS\",\n CHECK_MORE_SUBTASKS = \"CHECK_MORE_SUBTASKS\",\n PROCESS_SUBTASKS = \"PROCESS_SUBTASKS\",\n END_TASK = \"END_TASK\"\n}\n\nexport interface IBulkActionOperationByModelInput {\n modelId: string;\n identity?: ITaskIdentity;\n where?: Record<string, any>;\n search?: string;\n after?: string | null;\n data?: Record<string, any>;\n action?: BulkActionOperationByModelAction;\n}\n\nexport interface IBulkActionOperationByModelOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationByModelTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n>;\n\n/**\n * Empty Trash Bin\n */\n\nexport interface IEmptyTrashBinsInput {\n executedTenantIds?: string[] | null;\n}\n\nexport type IEmptyTrashBinsOutput = TaskDefinition.ResultDone;\n\nexport type IEmptyTrashBinsTaskParams = TaskDefinition.RunParams<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n>;\n"],"mappings":"AAOA;AACA;AACA;;AAqBA;AACA;AACA;;AAEA,WAAYA,gCAAgC,0BAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAA,OAAhCA,gCAAgC;AAAA;;AA2B5C;AACA;AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IListEntries.ts"],"sourcesContent":["import type { CmsEntry, CmsEntryListParams, CmsEntryMeta } from \"@webiny/api-headless-cms/types\";\n\nexport interface IListEntries {\n execute: (\n modelId: string,\n params: CmsEntryListParams\n ) => Promise<{ entries: CmsEntry[]; meta: CmsEntryMeta }>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IProcessEntry.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types\";\n\nexport interface IProcessEntry {\n execute: (model: CmsModel, id: string, data?: any) => Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { IListEntries, IProcessEntry } from "../abstractions";
|
|
2
|
-
import type { HcmsBulkActionsContext } from "../types";
|
|
3
|
-
export interface CreateBulkActionConfig {
|
|
4
|
-
name: string;
|
|
5
|
-
dataLoader: (context: HcmsBulkActionsContext) => IListEntries;
|
|
6
|
-
dataProcessor: (context: HcmsBulkActionsContext) => IProcessEntry;
|
|
7
|
-
modelIds?: string[];
|
|
8
|
-
batchSize?: number;
|
|
9
|
-
}
|
|
10
|
-
export declare const createBulkAction: (config: CreateBulkActionConfig) => (import("@webiny/api").ContextPlugin<HcmsBulkActionsContext> | (import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, import("../types").IBulkActionOperationByModelInput, import("../types").IBulkActionOperationByModelOutput> | import("@webiny/tasks").TaskDefinitionPlugin<HcmsBulkActionsContext, import("../types").IBulkActionOperationInput, import("../types").IBulkActionOperationOutput>)[])[];
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createBulkAction = void 0;
|
|
7
|
-
var _createBulkActionGraphQL = require("./createBulkActionGraphQL");
|
|
8
|
-
var _createBulkActionTasks = require("./createBulkActionTasks");
|
|
9
|
-
function toPascalCase(str) {
|
|
10
|
-
// Step 1: Remove non-alphanumeric characters and replace them with spaces
|
|
11
|
-
str = str.replace(/[^a-zA-Z0-9]+/g, " ");
|
|
12
|
-
|
|
13
|
-
// Step 2: Split the string into words
|
|
14
|
-
const words = str.split(" ");
|
|
15
|
-
|
|
16
|
-
// Step 3: Capitalize the first letter of each word
|
|
17
|
-
const capitalizedWords = words.map(word => word.charAt(0).toUpperCase() + word.slice(1));
|
|
18
|
-
|
|
19
|
-
// Step 4: Join all the capitalized words together
|
|
20
|
-
return capitalizedWords.join("");
|
|
21
|
-
}
|
|
22
|
-
const createBulkAction = config => {
|
|
23
|
-
const name = toPascalCase(config.name);
|
|
24
|
-
return [(0, _createBulkActionTasks.createBulkActionTasks)({
|
|
25
|
-
name,
|
|
26
|
-
dataLoader: config.dataLoader,
|
|
27
|
-
dataProcessor: config.dataProcessor,
|
|
28
|
-
batchSize: config.batchSize
|
|
29
|
-
}), (0, _createBulkActionGraphQL.createBulkActionGraphQL)({
|
|
30
|
-
name,
|
|
31
|
-
modelIds: config.modelIds
|
|
32
|
-
})];
|
|
33
|
-
};
|
|
34
|
-
exports.createBulkAction = createBulkAction;
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=createBulkAction.js.map
|