@rockster/core 0.0.4 → 0.1.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.
- package/access/access.module.js +3 -7
- package/access/access.module.js.map +1 -1
- package/access/constants.d.ts +2 -0
- package/access/constants.js +6 -0
- package/access/constants.js.map +1 -0
- package/access/controllers/controllers.d.ts +2 -1
- package/access/controllers/controllers.js +3 -1
- package/access/controllers/controllers.js.map +1 -1
- package/access/controllers/scope-access-profile.controller.d.ts +17 -0
- package/access/controllers/scope-access-profile.controller.js +111 -0
- package/access/controllers/scope-access-profile.controller.js.map +1 -0
- package/access/controllers/scope-group-user.controller.d.ts +11 -4
- package/access/controllers/scope-group-user.controller.js +57 -9
- package/access/controllers/scope-group-user.controller.js.map +1 -1
- package/access/controllers/scope-group.controller.d.ts +8 -5
- package/access/controllers/scope-group.controller.js +66 -12
- package/access/controllers/scope-group.controller.js.map +1 -1
- package/access/controllers/scope-owner.controller.d.ts +3 -2
- package/access/controllers/scope-owner.controller.js +18 -4
- package/access/controllers/scope-owner.controller.js.map +1 -1
- package/access/controllers/scope-user.controller.d.ts +2 -2
- package/access/controllers/scope-user.controller.js +19 -5
- package/access/controllers/scope-user.controller.js.map +1 -1
- package/access/decorators/context-params.decorator.d.ts +2 -0
- package/access/decorators/context-params.decorator.js +13 -0
- package/access/decorators/context-params.decorator.js.map +1 -0
- package/access/decorators/index.d.ts +2 -0
- package/access/decorators/index.js +19 -0
- package/access/decorators/index.js.map +1 -0
- package/access/decorators/scope-context-id-resolver.decorator.d.ts +10 -0
- package/access/decorators/scope-context-id-resolver.decorator.js +22 -0
- package/access/decorators/scope-context-id-resolver.decorator.js.map +1 -0
- package/access/entities/entities.d.ts +3 -1
- package/access/entities/entities.js +4 -0
- package/access/entities/entities.js.map +1 -1
- package/access/entities/index.d.ts +2 -0
- package/access/entities/index.js +2 -0
- package/access/entities/index.js.map +1 -1
- package/access/entities/scope-access-profile-key.d.ts +6 -0
- package/access/entities/scope-access-profile-key.js +40 -0
- package/access/entities/scope-access-profile-key.js.map +1 -0
- package/access/entities/scope-access-profile.d.ts +6 -0
- package/access/entities/scope-access-profile.js +37 -0
- package/access/entities/scope-access-profile.js.map +1 -0
- package/access/entities/scope-group.d.ts +3 -0
- package/access/entities/scope-group.js +16 -0
- package/access/entities/scope-group.js.map +1 -1
- package/access/functions/assert-context-admin-access.d.ts +15 -0
- package/access/functions/assert-context-admin-access.js +62 -0
- package/access/functions/assert-context-admin-access.js.map +1 -0
- package/access/functions/assert-master-or-owner.d.ts +9 -0
- package/access/functions/assert-master-or-owner.js +40 -0
- package/access/functions/assert-master-or-owner.js.map +1 -0
- package/access/functions/assert-scope-action-access.d.ts +32 -0
- package/access/functions/assert-scope-action-access.js +189 -0
- package/access/functions/assert-scope-action-access.js.map +1 -0
- package/access/functions/build-scope-resolver-initial-data.d.ts +4 -0
- package/access/functions/build-scope-resolver-initial-data.js +17 -0
- package/access/functions/build-scope-resolver-initial-data.js.map +1 -0
- package/access/functions/describe-action-scope.d.ts +9 -0
- package/access/functions/describe-action-scope.js +27 -0
- package/access/functions/describe-action-scope.js.map +1 -0
- package/access/functions/index.d.ts +5 -0
- package/access/functions/index.js +5 -0
- package/access/functions/index.js.map +1 -1
- package/access/functions/init-scope-service-executors.d.ts +3 -0
- package/access/functions/init-scope-service-executors.js +38 -0
- package/access/functions/init-scope-service-executors.js.map +1 -0
- package/access/functions/normalize-scope-keys.d.ts +4 -0
- package/access/functions/normalize-scope-keys.js +17 -0
- package/access/functions/normalize-scope-keys.js.map +1 -0
- package/access/functions/register-scope.d.ts +16 -5
- package/access/functions/register-scope.js +57 -45
- package/access/functions/register-scope.js.map +1 -1
- package/access/functions/resolve-scope-context-id.d.ts +9 -0
- package/access/functions/resolve-scope-context-id.js +71 -0
- package/access/functions/resolve-scope-context-id.js.map +1 -0
- package/access/functions/warn-if-public.d.ts +12 -0
- package/access/functions/warn-if-public.js +20 -0
- package/access/functions/warn-if-public.js.map +1 -0
- package/access/index.d.ts +2 -0
- package/access/index.js +2 -0
- package/access/index.js.map +1 -1
- package/access/interfaces/index.d.ts +1 -0
- package/access/interfaces/index.js +1 -0
- package/access/interfaces/index.js.map +1 -1
- package/access/interfaces/resolve-scope-context-id.d.ts +21 -0
- package/access/interfaces/resolve-scope-context-id.js +3 -0
- package/access/interfaces/resolve-scope-context-id.js.map +1 -0
- package/access/interfaces/scope-service-registry.d.ts +16 -1
- package/access/interfaces/scope-service.d.ts +6 -7
- package/access/models/scope-access-profile-keys-update.d.ts +5 -0
- package/access/models/scope-access-profile-keys-update.js +27 -0
- package/access/models/scope-access-profile-keys-update.js.map +1 -0
- package/access/models/scope-group-apply-access-profile.d.ts +6 -0
- package/access/models/scope-group-apply-access-profile.js +32 -0
- package/access/models/scope-group-apply-access-profile.js.map +1 -0
- package/access/models/scope-user-mapped.d.ts +1 -0
- package/access/models/scope-user-mapped.js +6 -0
- package/access/models/scope-user-mapped.js.map +1 -1
- package/access/models/scope-user.js +4 -2
- package/access/models/scope-user.js.map +1 -1
- package/access/queries/scope-access-profile.query.d.ts +1 -0
- package/access/queries/scope-access-profile.query.js +10 -0
- package/access/queries/scope-access-profile.query.js.map +1 -0
- package/access/queries/scope-group.query.js +9 -2
- package/access/queries/scope-group.query.js.map +1 -1
- package/access/services/index.d.ts +1 -0
- package/access/services/index.js +1 -0
- package/access/services/index.js.map +1 -1
- package/access/services/scope-access-profile.service.d.ts +13 -0
- package/access/services/scope-access-profile.service.js +75 -0
- package/access/services/scope-access-profile.service.js.map +1 -0
- package/access/services/scope-access.service.js +4 -2
- package/access/services/scope-access.service.js.map +1 -1
- package/access/services/scope-group-user.service.js +2 -2
- package/access/services/scope-group-user.service.js.map +1 -1
- package/access/services/scope-group.service.d.ts +10 -0
- package/access/services/scope-group.service.js +38 -1
- package/access/services/scope-group.service.js.map +1 -1
- package/access/services/scope-owner.service.d.ts +3 -0
- package/access/services/scope-owner.service.js +26 -1
- package/access/services/scope-owner.service.js.map +1 -1
- package/command/services/post-action-builder.js +19 -17
- package/command/services/post-action-builder.js.map +1 -1
- package/command/services/remove-action-builder.js +30 -22
- package/command/services/remove-action-builder.js.map +1 -1
- package/controllers/interfaces/controller-property.d.ts +7 -1
- package/controllers/services/default-action-builder.js +12 -30
- package/controllers/services/default-action-builder.js.map +1 -1
- package/controllers/services/restful-action-builder.js +25 -1
- package/controllers/services/restful-action-builder.js.map +1 -1
- package/core/contexts/request-context.d.ts +5 -0
- package/core/contexts/request-context.js +6 -0
- package/core/contexts/request-context.js.map +1 -0
- package/core/core.controller.js +6 -1
- package/core/core.controller.js.map +1 -1
- package/core/interfaces/action-docs.d.ts +15 -0
- package/core/interfaces/request-context.d.ts +5 -0
- package/core/services/request-router.js +2 -1
- package/core/services/request-router.js.map +1 -1
- package/database/database.controller.d.ts +1 -3
- package/database/database.controller.js +1 -5
- package/database/database.controller.js.map +1 -1
- package/database/decorators/protect-entity.decorator.d.ts +1 -0
- package/database/decorators/protect-entity.decorator.js +2 -3
- package/database/decorators/protect-entity.decorator.js.map +1 -1
- package/database/decorators/protected-entity.decorator.d.ts +1 -0
- package/database/decorators/protected-entity.decorator.js +2 -16
- package/database/decorators/protected-entity.decorator.js.map +1 -1
- package/database/functions/inject-repository-handle.js +4 -3
- package/database/functions/inject-repository-handle.js.map +1 -1
- package/database/interfaces/entity-object.d.ts +0 -6
- package/database/interfaces/index.d.ts +0 -1
- package/database/interfaces/index.js +0 -1
- package/database/interfaces/index.js.map +1 -1
- package/database/interfaces/repository.d.ts +8 -8
- package/docs/docs.module.js +3 -1
- package/docs/docs.module.js.map +1 -1
- package/docs/migrations/1747584000000-CreateDocsTables.d.ts +5 -0
- package/docs/migrations/1747584000000-CreateDocsTables.js +90 -0
- package/docs/migrations/1747584000000-CreateDocsTables.js.map +1 -0
- package/docs/migrations/migrations.d.ts +2 -0
- package/docs/migrations/migrations.js +8 -0
- package/docs/migrations/migrations.js.map +1 -0
- package/global.d.ts +2 -0
- package/global.js +1 -0
- package/global.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/jobs/jobs.controller.d.ts +2 -0
- package/jobs/jobs.controller.js +20 -16
- package/jobs/jobs.controller.js.map +1 -1
- package/package.json +70 -70
- package/query/functions/add-join.js +2 -13
- package/query/functions/add-join.js.map +1 -1
- package/query/functions/create-query-builder.js +0 -10
- package/query/functions/create-query-builder.js.map +1 -1
- package/query/functions/execute-query.js +34 -0
- package/query/functions/execute-query.js.map +1 -1
- package/query/functions/load-properties.js +73 -5
- package/query/functions/load-properties.js.map +1 -1
- package/query/services/query-action-builder.js +12 -18
- package/query/services/query-action-builder.js.map +1 -1
- package/remote-logs/dtos/index.d.ts +2 -0
- package/remote-logs/dtos/index.js +19 -0
- package/remote-logs/dtos/index.js.map +1 -0
- package/remote-logs/dtos/remote-log-hooks.dto.d.ts +72 -0
- package/remote-logs/dtos/remote-log-hooks.dto.js +280 -0
- package/remote-logs/dtos/remote-log-hooks.dto.js.map +1 -0
- package/remote-logs/dtos/remote-log-search.dto.d.ts +34 -0
- package/remote-logs/dtos/remote-log-search.dto.js +146 -0
- package/remote-logs/dtos/remote-log-search.dto.js.map +1 -0
- package/remote-logs/environment.d.ts +4 -0
- package/remote-logs/environment.js +5 -0
- package/remote-logs/environment.js.map +1 -0
- package/remote-logs/index.d.ts +3 -0
- package/remote-logs/index.js +20 -0
- package/remote-logs/index.js.map +1 -0
- package/remote-logs/interfaces/index.d.ts +1 -0
- package/remote-logs/interfaces/index.js +18 -0
- package/remote-logs/interfaces/index.js.map +1 -0
- package/remote-logs/interfaces/remote-logs-module-options.d.ts +8 -0
- package/remote-logs/interfaces/remote-logs-module-options.js +3 -0
- package/remote-logs/interfaces/remote-logs-module-options.js.map +1 -0
- package/remote-logs/remote-logs-hooks.controller.d.ts +60 -0
- package/remote-logs/remote-logs-hooks.controller.js +331 -0
- package/remote-logs/remote-logs-hooks.controller.js.map +1 -0
- package/remote-logs/remote-logs.controller.d.ts +8 -0
- package/remote-logs/remote-logs.controller.js +41 -0
- package/remote-logs/remote-logs.controller.js.map +1 -0
- package/remote-logs/remote-logs.module.d.ts +12 -0
- package/remote-logs/remote-logs.module.js +107 -0
- package/remote-logs/remote-logs.module.js.map +1 -0
- package/remote-logs/services/opensearch.service.d.ts +13 -0
- package/remote-logs/services/opensearch.service.js +167 -0
- package/remote-logs/services/opensearch.service.js.map +1 -0
- package/security/auth.controller.js +4 -4
- package/security/auth.controller.js.map +1 -1
- package/security/functions/add-protected.d.ts +2 -2
- package/security/functions/add-protected.js +8 -5
- package/security/functions/add-protected.js.map +1 -1
- package/security/functions/create-authentication-interceptor.d.ts +44 -0
- package/security/functions/create-authentication-interceptor.js +114 -0
- package/security/functions/create-authentication-interceptor.js.map +1 -0
- package/security/functions/find-auth-context.d.ts +1 -2
- package/security/functions/find-auth-context.js +6 -11
- package/security/functions/find-auth-context.js.map +1 -1
- package/security/index.d.ts +1 -0
- package/security/index.js +1 -0
- package/security/index.js.map +1 -1
- package/security/interfaces/authorization-schema.d.ts +3 -1
- package/security/services/authorization.service.d.ts +5 -3
- package/security/services/authorization.service.js +56 -37
- package/security/services/authorization.service.js.map +1 -1
- package/storage/services/routes.service.js +1 -1
- package/storage/services/routes.service.js.map +1 -1
- package/tasks/constants.d.ts +3 -0
- package/tasks/constants.js +2 -1
- package/tasks/constants.js.map +1 -1
- package/tasks/controllers/task.controller.d.ts +3 -2
- package/tasks/controllers/task.controller.js +11 -40
- package/tasks/controllers/task.controller.js.map +1 -1
- package/tasks/decorators/index.d.ts +1 -0
- package/tasks/decorators/index.js +1 -0
- package/tasks/decorators/index.js.map +1 -1
- package/tasks/decorators/task-payload.decorator.d.ts +1 -0
- package/tasks/decorators/task-payload.decorator.js +12 -0
- package/tasks/decorators/task-payload.decorator.js.map +1 -0
- package/tasks/decorators/task.decorator.js +3 -0
- package/tasks/decorators/task.decorator.js.map +1 -1
- package/tasks/functions/compile-all-task-post-hooks.d.ts +1 -0
- package/tasks/functions/compile-all-task-post-hooks.js +27 -0
- package/tasks/functions/compile-all-task-post-hooks.js.map +1 -0
- package/tasks/functions/compile-task-hook-handle.d.ts +6 -0
- package/tasks/functions/compile-task-hook-handle.js +67 -0
- package/tasks/functions/compile-task-hook-handle.js.map +1 -0
- package/tasks/functions/create-task-hook.d.ts +9 -0
- package/tasks/functions/create-task-hook.js +13 -0
- package/tasks/functions/create-task-hook.js.map +1 -0
- package/tasks/functions/create-task-message-post.js +2 -0
- package/tasks/functions/create-task-message-post.js.map +1 -1
- package/tasks/functions/register-task-post-hook-interceptors.d.ts +3 -0
- package/tasks/functions/register-task-post-hook-interceptors.js +86 -0
- package/tasks/functions/register-task-post-hook-interceptors.js.map +1 -0
- package/tasks/functions/run-task-post-hooks.d.ts +11 -0
- package/tasks/functions/run-task-post-hooks.js +18 -0
- package/tasks/functions/run-task-post-hooks.js.map +1 -0
- package/tasks/functions/task-message-operations.d.ts +18 -0
- package/tasks/functions/task-message-operations.js +100 -0
- package/tasks/functions/task-message-operations.js.map +1 -0
- package/tasks/functions/validate-task-payload.d.ts +2 -0
- package/tasks/functions/validate-task-payload.js +19 -0
- package/tasks/functions/validate-task-payload.js.map +1 -0
- package/tasks/hook-constants.d.ts +2 -0
- package/tasks/hook-constants.js +6 -0
- package/tasks/hook-constants.js.map +1 -0
- package/tasks/index.d.ts +3 -0
- package/tasks/index.js +3 -0
- package/tasks/index.js.map +1 -1
- package/tasks/interfaces/compiled-task-post-hooks.d.ts +17 -0
- package/tasks/interfaces/compiled-task-post-hooks.js +3 -0
- package/tasks/interfaces/compiled-task-post-hooks.js.map +1 -0
- package/tasks/interfaces/index.d.ts +3 -0
- package/tasks/interfaces/index.js +3 -0
- package/tasks/interfaces/index.js.map +1 -1
- package/tasks/interfaces/task-hook.d.ts +16 -0
- package/tasks/interfaces/task-hook.js +8 -0
- package/tasks/interfaces/task-hook.js.map +1 -0
- package/tasks/interfaces/task-object.d.ts +4 -0
- package/tasks/interfaces/task-post-hook.d.ts +2 -0
- package/{database/interfaces/protector.js → tasks/interfaces/task-post-hook.js} +1 -1
- package/tasks/interfaces/task-post-hook.js.map +1 -0
- package/tasks/interfaces/task-settings.d.ts +5 -0
- package/tasks/services/task-runner.service.d.ts +24 -3
- package/tasks/services/task-runner.service.js +66 -28
- package/tasks/services/task-runner.service.js.map +1 -1
- package/database/functions/use-protector.d.ts +0 -2
- package/database/functions/use-protector.js +0 -11
- package/database/functions/use-protector.js.map +0 -1
- package/database/interfaces/protector.d.ts +0 -51
- package/database/interfaces/protector.js.map +0 -1
- package/database/services/protect-builder.d.ts +0 -60
- package/database/services/protect-builder.js +0 -524
- package/database/services/protect-builder.js.map +0 -1
- package/security/functions/add-protect.d.ts +0 -2
- package/security/functions/add-protect.js +0 -11
- package/security/functions/add-protect.js.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryTaskMessages = queryTaskMessages;
|
|
4
|
+
exports.createTaskMessage = createTaskMessage;
|
|
5
|
+
exports.retryTaskMessage = retryTaskMessage;
|
|
6
|
+
const common_1 = require("@rockster/common");
|
|
7
|
+
const tasks_1 = require("@rockster/common/tasks");
|
|
8
|
+
const execute_post_1 = require("../../command/functions/execute-post");
|
|
9
|
+
const use_repository_1 = require("../../database/functions/use-repository");
|
|
10
|
+
const execute_query_1 = require("../../query/functions/execute-query");
|
|
11
|
+
const generate_entity_id_1 = require("./generate-entity-id");
|
|
12
|
+
const request_context_1 = require("../../core/contexts/request-context");
|
|
13
|
+
const task_hook_1 = require("../interfaces/task-hook");
|
|
14
|
+
const run_task_post_hooks_1 = require("./run-task-post-hooks");
|
|
15
|
+
const validate_task_payload_1 = require("./validate-task-payload");
|
|
16
|
+
function isTaskObjectNote(task) {
|
|
17
|
+
return typeof task === "object" && task != null && "objectKey" in task;
|
|
18
|
+
}
|
|
19
|
+
function resolveTaskObject(task) {
|
|
20
|
+
if (isTaskObjectNote(task)) {
|
|
21
|
+
return task;
|
|
22
|
+
}
|
|
23
|
+
return core.storage.findObject(task);
|
|
24
|
+
}
|
|
25
|
+
const createEmptyRequestContext = () => ({
|
|
26
|
+
response: {},
|
|
27
|
+
request: {},
|
|
28
|
+
pendings: [],
|
|
29
|
+
callbacks: {
|
|
30
|
+
success: [],
|
|
31
|
+
error: [],
|
|
32
|
+
},
|
|
33
|
+
onSuccess: async () => { },
|
|
34
|
+
onError: async () => { },
|
|
35
|
+
});
|
|
36
|
+
function resolveRequestContext(options) {
|
|
37
|
+
return options?.requestContext
|
|
38
|
+
?? request_context_1.requestContextStore.getStore()
|
|
39
|
+
?? createEmptyRequestContext();
|
|
40
|
+
}
|
|
41
|
+
/** Same semantics as {@link TaskController.query}. */
|
|
42
|
+
async function queryTaskMessages(content) {
|
|
43
|
+
return (0, execute_query_1.executeQuery)({ content });
|
|
44
|
+
}
|
|
45
|
+
async function createTaskMessage(task, payload, options) {
|
|
46
|
+
const object = resolveTaskObject(task);
|
|
47
|
+
const skipPhases = new Set(options?.skipPhases ?? []);
|
|
48
|
+
const requestContext = resolveRequestContext(options);
|
|
49
|
+
const Payload = object.payload();
|
|
50
|
+
if (!skipPhases.has(task_hook_1.taskHookPhase.beforeValidation)) {
|
|
51
|
+
await (0, run_task_post_hooks_1.runTaskPostHooks)(object, task_hook_1.taskHookPhase.beforeValidation, {
|
|
52
|
+
payload,
|
|
53
|
+
requestContext,
|
|
54
|
+
});
|
|
55
|
+
await (0, validate_task_payload_1.validateTaskPayload)(Payload, payload);
|
|
56
|
+
}
|
|
57
|
+
const data = {
|
|
58
|
+
id: (0, generate_entity_id_1.generateEntityId)(),
|
|
59
|
+
partitionId: object.nextPartitionId(),
|
|
60
|
+
payload,
|
|
61
|
+
createdAt: new Date(),
|
|
62
|
+
lastModifiedAt: new Date(),
|
|
63
|
+
};
|
|
64
|
+
if (!skipPhases.has(task_hook_1.taskHookPhase.beforeExecute)) {
|
|
65
|
+
await (0, run_task_post_hooks_1.runTaskPostHooks)(object, task_hook_1.taskHookPhase.beforeExecute, {
|
|
66
|
+
payload,
|
|
67
|
+
requestContext,
|
|
68
|
+
message: data,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return (0, execute_post_1.executePost)({
|
|
72
|
+
type: "create",
|
|
73
|
+
target: object.MessageModel,
|
|
74
|
+
idProperty: "id",
|
|
75
|
+
data,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Same semantics as {@link TaskController.retry}. */
|
|
79
|
+
async function retryTaskMessage(object, message) {
|
|
80
|
+
const repository = (0, use_repository_1.useRepository)(object.MessageModel);
|
|
81
|
+
const stored = await repository.findOneBy({
|
|
82
|
+
id: message.id,
|
|
83
|
+
});
|
|
84
|
+
if (!stored || stored.status !== tasks_1.TaskMessageStatus.failed) {
|
|
85
|
+
throw new common_1.BadRequestError({
|
|
86
|
+
message: `Reprocessing unavailable for this task`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const data = {
|
|
90
|
+
payload: message.payload,
|
|
91
|
+
lastModifiedAt: new Date(),
|
|
92
|
+
status: tasks_1.TaskMessageStatus.pending,
|
|
93
|
+
};
|
|
94
|
+
await repository.update({
|
|
95
|
+
id: message.id,
|
|
96
|
+
partitionId: stored.partitionId,
|
|
97
|
+
}, data);
|
|
98
|
+
return { ...stored, ...data };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=task-message-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-message-operations.js","sourceRoot":"./","sources":["tasks/functions/task-message-operations.ts"],"names":[],"mappings":";;AAwDA,8CAEC;AAaD,8CAwCC;AAGD,4CA8BC;AA/ID,6CAAiE;AACjE,kDAAyE;AACzE,uEAAmE;AACnE,4EAAwE;AACxE,uEAAmE;AAEnE,6DAAwD;AAGxD,yEAA0E;AAC1E,uDAAuE;AACvE,+DAAyD;AACzD,mEAA8D;AAE9D,SAAS,gBAAgB,CACtB,IAA4C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,CAAC;IAED,MAAM,IAAI,GAAG;QACV,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,cAAc,EAAE,IAAI,IAAI,EAAE;QAC1B,MAAM,EAAE,yBAAiB,CAAC,OAAO;KACnC,CAAC;IAEF,MAAM,UAAU,CAAC,MAAM,CACpB;QACG,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,WAAW,EAAE,MAAM,CAAC,WAAW;KACjC,EACD,IAAI,CACN,CAAC;IAEF,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTaskPayload = void 0;
|
|
4
|
+
const class_pipe_1 = require("@rockster/class-pipe");
|
|
5
|
+
const global_1 = require("../../global");
|
|
6
|
+
const validateTaskPayload = async (Payload, payload) => {
|
|
7
|
+
const sanitized = {};
|
|
8
|
+
const errors = await (0, class_pipe_1.validate)(Payload, payload, sanitized, {
|
|
9
|
+
groups: [global_1.actionGroups.create],
|
|
10
|
+
});
|
|
11
|
+
if (errors) {
|
|
12
|
+
throw errors;
|
|
13
|
+
}
|
|
14
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
15
|
+
Object.assign(payload, sanitized);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.validateTaskPayload = validateTaskPayload;
|
|
19
|
+
//# sourceMappingURL=validate-task-payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-task-payload.js","sourceRoot":"./","sources":["tasks/functions/validate-task-payload.ts"],"names":[],"mappings":";;;AACA,qDAAgD;AAChD,yCAA4C;AAErC,MAAM,mBAAmB,GAAG,KAAK,EACrC,OAAqB,EACrB,OAAgB,EACF,EAAE;IAChB,MAAM,SAAS,GAAG,EAA6B,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAQ,EAC1B,OAAO,EACP,OAAO,EACP,SAAS,EACT;QACG,MAAM,EAAE,CAAC,qBAAY,CAAC,MAAM,CAAC;KAC/B,CACH,CAAC;IAEF,IAAI,MAAM,EAAE,CAAC;QACV,MAAM,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACrE,MAAM,CAAC,MAAM,CAAC,OAAiB,EAAE,SAAS,CAAC,CAAC;IAC/C,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,mBAAmB,uBAqB9B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TASK_MESSAGE_KEY = exports.TASK_PAYLOAD_KEY = void 0;
|
|
4
|
+
exports.TASK_PAYLOAD_KEY = 'TASK_PAYLOAD';
|
|
5
|
+
exports.TASK_MESSAGE_KEY = 'TASK_MESSAGE';
|
|
6
|
+
//# sourceMappingURL=hook-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-constants.js","sourceRoot":"./","sources":["tasks/hook-constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,gBAAgB,GAAG,cAAc,CAAC"}
|
package/tasks/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from './interfaces';
|
|
2
2
|
export * from './decorators';
|
|
3
|
+
export * from './hook-constants';
|
|
4
|
+
export * from './functions/create-task-hook';
|
|
3
5
|
export * from './functions/throw-task-error';
|
|
6
|
+
export * from './functions/task-message-operations';
|
|
4
7
|
export * from './tasks.module';
|
|
5
8
|
export * from './models';
|
package/tasks/index.js
CHANGED
|
@@ -16,7 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./interfaces"), exports);
|
|
18
18
|
__exportStar(require("./decorators"), exports);
|
|
19
|
+
__exportStar(require("./hook-constants"), exports);
|
|
20
|
+
__exportStar(require("./functions/create-task-hook"), exports);
|
|
19
21
|
__exportStar(require("./functions/throw-task-error"), exports);
|
|
22
|
+
__exportStar(require("./functions/task-message-operations"), exports);
|
|
20
23
|
__exportStar(require("./tasks.module"), exports);
|
|
21
24
|
__exportStar(require("./models"), exports);
|
|
22
25
|
//# sourceMappingURL=index.js.map
|
package/tasks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"./","sources":["tasks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,+DAA6C;AAC7C,iDAA+B;AAC/B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./","sources":["tasks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,mDAAiC;AACjC,+DAA6C;AAC7C,+DAA6C;AAC7C,sEAAoD;AACpD,iDAA+B;AAC/B,2CAAyB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Dictionary } from "@rockster/common";
|
|
2
|
+
import { IRequestContext } from "../../core/interfaces/request-context";
|
|
3
|
+
import { ITaskMessage } from "@rockster/common/tasks";
|
|
4
|
+
export type TaskPostHookInitialData = Dictionary<unknown> & {
|
|
5
|
+
payload: unknown;
|
|
6
|
+
requestContext?: IRequestContext;
|
|
7
|
+
message?: Partial<ITaskMessage>;
|
|
8
|
+
};
|
|
9
|
+
export type TaskPostHookHandle = {
|
|
10
|
+
(initialData: TaskPostHookInitialData): Promise<void>;
|
|
11
|
+
interceptorName: string;
|
|
12
|
+
phase: string;
|
|
13
|
+
};
|
|
14
|
+
export type CompiledTaskPostHooks = {
|
|
15
|
+
beforeValidation: TaskPostHookHandle[];
|
|
16
|
+
beforeExecute: TaskPostHookHandle[];
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiled-task-post-hooks.js","sourceRoot":"./","sources":["tasks/interfaces/compiled-task-post-hooks.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from './task-naming';
|
|
2
2
|
export * from './task-object';
|
|
3
|
+
export * from './task-hook';
|
|
4
|
+
export * from './task-post-hook';
|
|
5
|
+
export * from './compiled-task-post-hooks';
|
|
3
6
|
export * from './task-post-intercept';
|
|
4
7
|
export * from './task-runner';
|
|
5
8
|
export * from './task-search-intercept';
|
|
@@ -16,6 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./task-naming"), exports);
|
|
18
18
|
__exportStar(require("./task-object"), exports);
|
|
19
|
+
__exportStar(require("./task-hook"), exports);
|
|
20
|
+
__exportStar(require("./task-post-hook"), exports);
|
|
21
|
+
__exportStar(require("./compiled-task-post-hooks"), exports);
|
|
19
22
|
__exportStar(require("./task-post-intercept"), exports);
|
|
20
23
|
__exportStar(require("./task-runner"), exports);
|
|
21
24
|
__exportStar(require("./task-search-intercept"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"./","sources":["tasks/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,wDAAsC;AACtC,gDAA8B;AAC9B,0DAAwC;AACxC,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./","sources":["tasks/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,8CAA4B;AAC5B,mDAAiC;AACjC,6DAA2C;AAC3C,wDAAsC;AACtC,gDAA8B;AAC9B,0DAAwC;AACxC,kDAAgC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Instantiable } from "@rockster/common";
|
|
2
|
+
export declare const taskHookPhase: {
|
|
3
|
+
readonly beforeValidation: "taskHook.beforeValidation";
|
|
4
|
+
readonly beforeExecute: "taskHook.beforeExecute";
|
|
5
|
+
};
|
|
6
|
+
export type TaskHookPhase = typeof taskHookPhase[keyof typeof taskHookPhase];
|
|
7
|
+
export type TaskHookDef = {
|
|
8
|
+
name: string;
|
|
9
|
+
phase: TaskHookPhase;
|
|
10
|
+
executor: Instantiable;
|
|
11
|
+
};
|
|
12
|
+
export type TaskHook = TaskHookDef & {
|
|
13
|
+
instance?: {
|
|
14
|
+
intercept(...args: unknown[]): Promise<unknown>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taskHookPhase = void 0;
|
|
4
|
+
exports.taskHookPhase = {
|
|
5
|
+
beforeValidation: 'taskHook.beforeValidation',
|
|
6
|
+
beforeExecute: 'taskHook.beforeExecute',
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=task-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-hook.js","sourceRoot":"./","sources":["tasks/interfaces/task-hook.ts"],"names":[],"mappings":";;;AAEa,QAAA,aAAa,GAAG;IAC1B,gBAAgB,EAAE,2BAA2B;IAC7C,aAAa,EAAE,wBAAwB;CAChC,CAAC"}
|
|
@@ -4,6 +4,8 @@ import { IObject } from "../../core";
|
|
|
4
4
|
import { ITaskSettings } from "./task-settings";
|
|
5
5
|
import { PgTableWithColumns } from "drizzle-orm/pg-core";
|
|
6
6
|
import { ITaskNaming } from "./task-naming";
|
|
7
|
+
import { CompiledTaskPostHooks } from "./compiled-task-post-hooks";
|
|
8
|
+
import { TaskPostHook } from "./task-post-hook";
|
|
7
9
|
import { TaskPostIntercept } from "./task-post-intercept";
|
|
8
10
|
export interface ITaskObject extends IObject {
|
|
9
11
|
type: ObjectType.task;
|
|
@@ -16,4 +18,6 @@ export interface ITaskObject extends IObject {
|
|
|
16
18
|
naming: ITaskNaming;
|
|
17
19
|
nextPartitionId: () => number;
|
|
18
20
|
postInterceptors?: TaskPostIntercept[];
|
|
21
|
+
postHooks?: TaskPostHook[];
|
|
22
|
+
compiledPostHooks?: CompiledTaskPostHooks;
|
|
19
23
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-post-hook.js","sourceRoot":"./","sources":["tasks/interfaces/task-post-hook.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GetTypeCallback } from "@rockster/common";
|
|
2
|
+
import { TaskPostHook } from "./task-post-hook";
|
|
2
3
|
import { TaskPostIntercept } from "./task-post-intercept";
|
|
3
4
|
export interface ITaskSettings<T> {
|
|
4
5
|
/**Executor for any message */
|
|
@@ -13,5 +14,9 @@ export interface ITaskSettings<T> {
|
|
|
13
14
|
retentionDays?: number;
|
|
14
15
|
/**limit: 100. Indicates how many messages the runner will recieve to proccess*/
|
|
15
16
|
messagesLimit?: number;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use `postHooks` instead.
|
|
19
|
+
*/
|
|
16
20
|
postInterceptors?: TaskPostIntercept[];
|
|
21
|
+
postHooks?: TaskPostHook[];
|
|
17
22
|
}
|
|
@@ -9,15 +9,36 @@ type TaskRunner = {
|
|
|
9
9
|
runner: ITaskRunner<any>;
|
|
10
10
|
repository: Repository<ITaskMessage>;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Worker-side task dispatcher: claims pending rows with `SKIP LOCKED`, runs runners concurrently
|
|
14
|
+
* up to {@link TaskRunnerService.maxConcurrentTaskMessages}, without blocking the poll interval on
|
|
15
|
+
* long-running `onRun` handlers.
|
|
16
|
+
*/
|
|
12
17
|
export declare class TaskRunnerService {
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Max concurrent task **messages** being executed at once (per worker thread / process).
|
|
20
|
+
* Tune here if workloads need more / less parallelism.
|
|
21
|
+
*/
|
|
22
|
+
static readonly maxConcurrentTaskMessages = 50;
|
|
23
|
+
/** @deprecated Reserved for future graceful shutdown hooks; not read by the runner today. */
|
|
14
24
|
private static done;
|
|
15
25
|
tasks: TaskRunner[];
|
|
26
|
+
/** Messages currently in `onRun` or DB update after run (best-effort counter). */
|
|
27
|
+
private inFlightCount;
|
|
28
|
+
/** Serializes {@link fillPool} so two ticks cannot claim overlapping capacity. */
|
|
29
|
+
private drainChain;
|
|
16
30
|
activeTimer(): void;
|
|
17
31
|
constructor();
|
|
32
|
+
/** How many task messages are executing right now (0 … {@link maxConcurrentTaskMessages}). */
|
|
33
|
+
getConcurrentInFlight(): number;
|
|
18
34
|
startRunner(object: ObjectNote<ITaskObject>): Promise<void>;
|
|
19
|
-
protected
|
|
20
|
-
|
|
35
|
+
protected scheduleFillPool(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Claims pending messages up to remaining global capacity and **starts** them without awaiting
|
|
38
|
+
* completion (each execution decrements {@link inFlightCount} in `finally`).
|
|
39
|
+
*/
|
|
40
|
+
protected fillPool(): Promise<void>;
|
|
41
|
+
protected executeTaskMessage(task: TaskRunner, message: TaskMessage<any>): Promise<void>;
|
|
21
42
|
protected mapMessage(row: any): TaskMessage<any>;
|
|
22
43
|
}
|
|
23
44
|
export {};
|
|
@@ -15,13 +15,28 @@ const get_pending_task_script_1 = require("../functions/get-pending-task-script"
|
|
|
15
15
|
const use_repository_1 = require("../../database/functions/use-repository");
|
|
16
16
|
const tasks_1 = require("@rockster/common/tasks");
|
|
17
17
|
const class_injector_1 = require("@rockster/class-injector");
|
|
18
|
+
/**
|
|
19
|
+
* Worker-side task dispatcher: claims pending rows with `SKIP LOCKED`, runs runners concurrently
|
|
20
|
+
* up to {@link TaskRunnerService.maxConcurrentTaskMessages}, without blocking the poll interval on
|
|
21
|
+
* long-running `onRun` handlers.
|
|
22
|
+
*/
|
|
18
23
|
let TaskRunnerService = TaskRunnerService_1 = class TaskRunnerService {
|
|
19
24
|
activeTimer() {
|
|
20
25
|
TaskRunnerService_1.done = true;
|
|
21
26
|
}
|
|
22
27
|
constructor() {
|
|
23
28
|
this.tasks = [];
|
|
24
|
-
|
|
29
|
+
/** Messages currently in `onRun` or DB update after run (best-effort counter). */
|
|
30
|
+
this.inFlightCount = 0;
|
|
31
|
+
/** Serializes {@link fillPool} so two ticks cannot claim overlapping capacity. */
|
|
32
|
+
this.drainChain = Promise.resolve();
|
|
33
|
+
setInterval(() => {
|
|
34
|
+
this.scheduleFillPool();
|
|
35
|
+
}, 500);
|
|
36
|
+
}
|
|
37
|
+
/** How many task messages are executing right now (0 … {@link maxConcurrentTaskMessages}). */
|
|
38
|
+
getConcurrentInFlight() {
|
|
39
|
+
return this.inFlightCount;
|
|
25
40
|
}
|
|
26
41
|
async startRunner(object) {
|
|
27
42
|
const runner = await (0, class_injector_1.createInstance)(object.objectClass);
|
|
@@ -29,51 +44,69 @@ let TaskRunnerService = TaskRunnerService_1 = class TaskRunnerService {
|
|
|
29
44
|
this.tasks.push({
|
|
30
45
|
object: object,
|
|
31
46
|
runner: runner,
|
|
32
|
-
repository: repository
|
|
47
|
+
repository: repository,
|
|
33
48
|
});
|
|
34
49
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
scheduleFillPool() {
|
|
51
|
+
this.drainChain = this.drainChain
|
|
52
|
+
.then(() => this.fillPool())
|
|
53
|
+
.catch(() => {
|
|
54
|
+
// Swallow: next interval will retry; avoid breaking the chain.
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Claims pending messages up to remaining global capacity and **starts** them without awaiting
|
|
59
|
+
* completion (each execution decrements {@link inFlightCount} in `finally`).
|
|
60
|
+
*/
|
|
61
|
+
async fillPool() {
|
|
62
|
+
const max = TaskRunnerService_1.maxConcurrentTaskMessages;
|
|
63
|
+
for (const task of this.tasks) {
|
|
64
|
+
while (this.inFlightCount < max) {
|
|
65
|
+
const room = max - this.inFlightCount;
|
|
66
|
+
const query = (0, get_pending_task_script_1.getPendingTaskScript)(task.object.naming, core.workerId, room);
|
|
67
|
+
const rows = (await task.repository.query(query))[0];
|
|
68
|
+
const rawMessages = Array.isArray(rows) ? rows : [];
|
|
69
|
+
if (rawMessages.length === 0) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
for (const row of rawMessages) {
|
|
73
|
+
const message = this.mapMessage(row);
|
|
74
|
+
this.inFlightCount++;
|
|
75
|
+
void this.executeTaskMessage(task, message).finally(() => {
|
|
76
|
+
this.inFlightCount--;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
44
79
|
}
|
|
45
|
-
TaskRunnerService_1.running = false;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
TaskRunnerService_1.running = false;
|
|
49
80
|
}
|
|
50
81
|
}
|
|
51
|
-
async
|
|
82
|
+
async executeTaskMessage(task, message) {
|
|
52
83
|
const stopwatch = getTimer();
|
|
53
84
|
try {
|
|
54
85
|
stopwatch.start();
|
|
55
|
-
await task
|
|
56
|
-
|
|
57
|
-
.onRun({
|
|
58
|
-
message: message
|
|
86
|
+
await task.runner.onRun({
|
|
87
|
+
message: message,
|
|
59
88
|
});
|
|
60
89
|
await task.repository.update({
|
|
61
90
|
id: message.id,
|
|
62
|
-
partitionId: message.partitionId
|
|
91
|
+
partitionId: message.partitionId,
|
|
63
92
|
}, {
|
|
64
93
|
status: tasks_1.TaskMessageStatus.completed,
|
|
65
94
|
lastModifiedAt: new Date(),
|
|
66
95
|
runtimeMs: stopwatch.stop(),
|
|
67
|
-
payload: message.payload
|
|
96
|
+
payload: message.payload,
|
|
68
97
|
});
|
|
69
98
|
}
|
|
70
99
|
catch (error) {
|
|
71
100
|
const taskError = error;
|
|
72
|
-
|
|
73
|
-
|
|
101
|
+
const { message: errorDetail } = getErrorInfos(error);
|
|
102
|
+
taskError.infos = errorDetail;
|
|
103
|
+
if (errorDetail?.trim()) {
|
|
104
|
+
taskError.message = errorDetail.trim().split("\n")[0].trim();
|
|
105
|
+
}
|
|
106
|
+
const isExpose = error.constructor.name !== "Error";
|
|
74
107
|
await task.repository.update({
|
|
75
108
|
id: message.id,
|
|
76
|
-
partitionId: message.partitionId
|
|
109
|
+
partitionId: message.partitionId,
|
|
77
110
|
}, {
|
|
78
111
|
status: tasks_1.TaskMessageStatus.failed,
|
|
79
112
|
lastModifiedAt: new Date(),
|
|
@@ -81,7 +114,7 @@ let TaskRunnerService = TaskRunnerService_1 = class TaskRunnerService {
|
|
|
81
114
|
runtimeMs: stopwatch.stop(),
|
|
82
115
|
internalError: taskError,
|
|
83
116
|
error: isExpose ? taskError : null,
|
|
84
|
-
payload: message.payload
|
|
117
|
+
payload: message.payload,
|
|
85
118
|
});
|
|
86
119
|
}
|
|
87
120
|
}
|
|
@@ -96,12 +129,17 @@ let TaskRunnerService = TaskRunnerService_1 = class TaskRunnerService {
|
|
|
96
129
|
error: row.error,
|
|
97
130
|
internalError: row.internal_error,
|
|
98
131
|
payload: row.payload,
|
|
99
|
-
runtimeMs: row.runtime_ms
|
|
132
|
+
runtimeMs: row.runtime_ms,
|
|
100
133
|
};
|
|
101
134
|
}
|
|
102
135
|
};
|
|
103
136
|
exports.TaskRunnerService = TaskRunnerService;
|
|
104
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Max concurrent task **messages** being executed at once (per worker thread / process).
|
|
139
|
+
* Tune here if workloads need more / less parallelism.
|
|
140
|
+
*/
|
|
141
|
+
TaskRunnerService.maxConcurrentTaskMessages = 50;
|
|
142
|
+
/** @deprecated Reserved for future graceful shutdown hooks; not read by the runner today. */
|
|
105
143
|
TaskRunnerService.done = false;
|
|
106
144
|
exports.TaskRunnerService = TaskRunnerService = TaskRunnerService_1 = __decorate([
|
|
107
145
|
(0, class_injector_1.Injectable)(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-runner.service.js","sourceRoot":"./","sources":["tasks/services/task-runner.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,kFAA4E;AAE5E,4EAAwE;AACxE,kDAIgC;AAChC,6DAGkC;
|
|
1
|
+
{"version":3,"file":"task-runner.service.js","sourceRoot":"./","sources":["tasks/services/task-runner.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,kFAA4E;AAE5E,4EAAwE;AACxE,kDAIgC;AAChC,6DAGkC;AASlC;;;;GAIG;AAEI,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAkB3B,WAAW;QACR,mBAAiB,CAAC,IAAI,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;QAZA,UAAK,GAAG,EAAkB,CAAC;QAE3B,kFAAkF;QAC1E,kBAAa,GAAG,CAAC,CAAC;QAE1B,kFAAkF;QAC1E,eAAU,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;QAOnD,WAAW,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC3B,CAAC,EAAE,GAAG,CAAC,CAAC;IACX,CAAC;IAED,8FAA8F;IAC9F,qBAAqB;QAClB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,MAA+B;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAc,EAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACtD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACb,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,UAAU;SACxB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iB,CAAC,MAAM;gBAChC,cAAc,EAAE,IAAI,IAAI,EAAE;gBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,CAAC;gBAC9B,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE;gBAC3B,aAAa,EAAE,SAAS;gBACxB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;gBAClC,OAAO,EAAE,OAAO,CAAC,OAAO;aAC1B,CACH,CAAC;QACL,CAAC;IACJ,CAAC;IAES,UAAU,CAAC,GAAG;QACrB,OAAO;YACJ,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,WAAW,EAAE,GAAG,CAAC,YAAY;YAC7B,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,SAAS,EAAE,GAAG,CAAC,UAAU;YACzB,cAAc,EAAE,GAAG,CAAC,gBAAgB;YACpC,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,aAAa,EAAE,GAAG,CAAC,cAAc;YACjC,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,SAAS,EAAE,GAAG,CAAC,UAAU;SAC3B,CAAC;IACL,CAAC;;AA/IS,8CAAiB;AAC3B;;;GAGG;AACoB,2CAAyB,GAAG,EAAE,AAAL,CAAM;AAEtD,6FAA6F;AAC9E,sBAAI,GAAG,KAAK,AAAR,CAAS;4BARlB,iBAAiB;IAD7B,IAAA,2BAAU,GAAE;;GACA,iBAAiB,CAgJ7B"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useProtector = void 0;
|
|
4
|
-
const useProtector = (target) => {
|
|
5
|
-
const object = core
|
|
6
|
-
.storage
|
|
7
|
-
.findObject(target);
|
|
8
|
-
return object?.protector;
|
|
9
|
-
};
|
|
10
|
-
exports.useProtector = useProtector;
|
|
11
|
-
//# sourceMappingURL=use-protector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-protector.js","sourceRoot":"./","sources":["database/functions/use-protector.ts"],"names":[],"mappings":";;;AAIO,MAAM,YAAY,GAAG,CAAC,MAAoB,EAAE,EAAE;IAClD,MAAM,MAAM,GAAG,IAAI;SACf,OAAO;SACP,UAAU,CAAC,MAAM,CACO,CAAC;IAC7B,OAAO,MAAM,EAAE,SAAS,CAAC;AAC5B,CAAC,CAAA;AANY,QAAA,YAAY,gBAMxB"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Dictionary, Instantiable } from "@rockster/common";
|
|
2
|
-
import { EntityManager, SelectQueryBuilder } from "typeorm";
|
|
3
|
-
export type IsAuthorizedHandle = {
|
|
4
|
-
(args: {
|
|
5
|
-
userId: string;
|
|
6
|
-
keys: string[];
|
|
7
|
-
contextId?: string;
|
|
8
|
-
entityManager?: EntityManager;
|
|
9
|
-
context?: string;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
export type GetUserPermissionsHandle = {
|
|
13
|
-
(args: {
|
|
14
|
-
userId: string;
|
|
15
|
-
targetUserId: string;
|
|
16
|
-
contextId: string;
|
|
17
|
-
entityManager?: EntityManager;
|
|
18
|
-
context: string;
|
|
19
|
-
}): Promise<string[]>;
|
|
20
|
-
};
|
|
21
|
-
export type SetUserPermissionsHandle = {
|
|
22
|
-
(args: {
|
|
23
|
-
userId: string;
|
|
24
|
-
targetUserId: string;
|
|
25
|
-
contextId: string;
|
|
26
|
-
entityManager?: EntityManager;
|
|
27
|
-
context: string;
|
|
28
|
-
accessKeys: string[];
|
|
29
|
-
}): Promise<void>;
|
|
30
|
-
};
|
|
31
|
-
export type Protector = {
|
|
32
|
-
target: Instantiable;
|
|
33
|
-
rootCondition?: (args: {
|
|
34
|
-
rootAlias: string;
|
|
35
|
-
queryBuilder: SelectQueryBuilder<any>;
|
|
36
|
-
userId: string;
|
|
37
|
-
contextParams: Dictionary<any>;
|
|
38
|
-
}) => SelectQueryBuilder<any>;
|
|
39
|
-
relationCondition?: (args: {
|
|
40
|
-
userId: string;
|
|
41
|
-
contextParams: Dictionary<any>;
|
|
42
|
-
alias: string;
|
|
43
|
-
rootPath: Instantiable;
|
|
44
|
-
}) => string;
|
|
45
|
-
canRemove?: (userId: string, entityId: string, entityManager?: EntityManager) => Promise<void>;
|
|
46
|
-
canModify?: <Entity>(userId: string, value: Entity, entityManager?: EntityManager) => Promise<void>;
|
|
47
|
-
canCreate?: <Entity>(userId: string, value: Entity, entityManager?: EntityManager) => Promise<void>;
|
|
48
|
-
isAuthorized?: IsAuthorizedHandle;
|
|
49
|
-
getUserPermissions?: GetUserPermissionsHandle;
|
|
50
|
-
setUserPermissions?: SetUserPermissionsHandle;
|
|
51
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protector.js","sourceRoot":"./","sources":["database/interfaces/protector.ts"],"names":[],"mappings":""}
|