@tstdl/base 0.93.87 → 0.93.90
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/ai/genkit/helpers.d.ts +3 -1
- package/ai/genkit/helpers.js +3 -3
- package/api/server/gateway.d.ts +3 -0
- package/api/server/gateway.js +15 -4
- package/api/server/middlewares/catch-error.middleware.js +2 -4
- package/api/server/middlewares/cors.middleware.js +2 -3
- package/api/server/middlewares/csrf.middleware.d.ts +41 -0
- package/api/server/middlewares/csrf.middleware.js +108 -0
- package/api/server/middlewares/index.d.ts +1 -0
- package/api/server/middlewares/index.js +1 -0
- package/api/server/module.d.ts +8 -2
- package/api/server/module.js +14 -8
- package/api/server/tests/csrf.middleware.test.js +91 -0
- package/audit/drizzle/{0000_bored_stick.sql → 0000_lumpy_thunderball.sql} +3 -3
- package/audit/drizzle/meta/0000_snapshot.json +4 -4
- package/audit/drizzle/meta/_journal.json +2 -9
- package/audit/module.d.ts +4 -1
- package/audit/module.js +3 -2
- package/audit/schemas.d.ts +1 -1
- package/audit/types.d.ts +1 -1
- package/audit/types.js +1 -1
- package/authentication/client/authentication.service.d.ts +14 -1
- package/authentication/client/authentication.service.js +82 -23
- package/authentication/client/http-client.middleware.d.ts +6 -0
- package/authentication/client/http-client.middleware.js +36 -0
- package/authentication/client/module.js +8 -2
- package/authentication/models/service-account.model.d.ts +2 -2
- package/authentication/models/service-account.model.js +10 -5
- package/authentication/models/subject.model.d.ts +20 -5
- package/authentication/models/subject.model.js +34 -29
- package/authentication/models/system-account.model.d.ts +3 -2
- package/authentication/models/system-account.model.js +11 -5
- package/authentication/models/user.model.d.ts +2 -11
- package/authentication/models/user.model.js +5 -16
- package/authentication/server/authentication-api-request-token.provider.d.ts +0 -2
- package/authentication/server/authentication-api-request-token.provider.js +3 -11
- package/authentication/server/authentication.api-controller.d.ts +1 -2
- package/authentication/server/authentication.api-controller.js +8 -9
- package/authentication/server/authentication.audit.d.ts +3 -2
- package/authentication/server/authentication.service.d.ts +27 -1
- package/authentication/server/authentication.service.js +67 -18
- package/authentication/server/drizzle/{0000_normal_paper_doll.sql → 0000_soft_tag.sql} +25 -32
- package/authentication/server/drizzle/meta/0000_snapshot.json +180 -205
- package/authentication/server/drizzle/meta/_journal.json +2 -2
- package/authentication/server/helper.js +9 -2
- package/authentication/server/module.d.ts +4 -1
- package/authentication/server/module.js +9 -5
- package/authentication/server/schemas.d.ts +2 -1
- package/authentication/server/schemas.js +2 -2
- package/authentication/server/subject.service.d.ts +17 -11
- package/authentication/server/subject.service.js +86 -84
- package/authentication/tests/authentication-ancillary.service.test.d.ts +1 -0
- package/authentication/tests/authentication-ancillary.service.test.js +13 -0
- package/authentication/tests/authentication-secret-requirements.validator.test.d.ts +1 -0
- package/authentication/tests/authentication-secret-requirements.validator.test.js +29 -0
- package/authentication/tests/authentication.api-controller.test.d.ts +1 -0
- package/authentication/tests/authentication.api-controller.test.js +88 -0
- package/authentication/tests/authentication.api-request-token.provider.test.d.ts +1 -0
- package/authentication/tests/authentication.api-request-token.provider.test.js +48 -0
- package/authentication/tests/authentication.client-middleware.test.d.ts +1 -0
- package/authentication/tests/authentication.client-middleware.test.js +23 -0
- package/authentication/tests/authentication.client-service.test.d.ts +1 -0
- package/authentication/tests/authentication.client-service.test.js +70 -0
- package/authentication/tests/authentication.service.test.d.ts +1 -0
- package/authentication/tests/authentication.service.test.js +186 -0
- package/authentication/tests/authentication.test-ancillary-service.d.ts +9 -0
- package/authentication/tests/authentication.test-ancillary-service.js +27 -0
- package/authentication/tests/helper.test.d.ts +1 -0
- package/authentication/tests/helper.test.js +107 -0
- package/authentication/tests/secret-requirements.error.test.d.ts +1 -0
- package/authentication/tests/secret-requirements.error.test.js +14 -0
- package/authentication/tests/subject.service.test.d.ts +1 -0
- package/authentication/tests/subject.service.test.js +140 -0
- package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +1 -1
- package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
- package/circuit-breaker/postgres/module.d.ts +7 -1
- package/circuit-breaker/postgres/module.js +8 -6
- package/circuit-breaker/tests/circuit-breaker.test.js +2 -22
- package/document-management/api/document-management.api.js +2 -6
- package/document-management/server/services/document-validation.service.js +6 -5
- package/document-management/server/services/document-workflow.service.js +5 -5
- package/document-management/service-models/document-folders.view-model.d.ts +5 -2
- package/document-management/service-models/document-folders.view-model.js +42 -9
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
- package/examples/document-management/main.js +4 -4
- package/http/client/adapters/undici.adapter.d.ts +7 -5
- package/http/client/adapters/undici.adapter.js +13 -10
- package/http/client/module.d.ts +3 -1
- package/http/client/module.js +8 -9
- package/http/server/http-server.d.ts +2 -0
- package/http/server/node/module.d.ts +6 -2
- package/http/server/node/module.js +6 -4
- package/http/server/node/node-http-server.d.ts +2 -0
- package/http/server/node/node-http-server.js +7 -0
- package/http/types.d.ts +1 -1
- package/key-value-store/postgres/module.d.ts +7 -1
- package/key-value-store/postgres/module.js +7 -3
- package/lock/postgres/lock.js +0 -1
- package/lock/postgres/module.d.ts +7 -1
- package/lock/postgres/module.js +9 -5
- package/logger/formatter.d.ts +2 -0
- package/logger/formatters/json.js +2 -2
- package/logger/formatters/pretty-print.js +8 -10
- package/logger/logger.d.ts +1 -1
- package/logger/logger.js +15 -12
- package/message-bus/local/module.d.ts +5 -2
- package/message-bus/local/module.js +5 -4
- package/module/module.d.ts +2 -1
- package/module/module.js +3 -0
- package/module/modules/web-server.module.d.ts +11 -6
- package/module/modules/web-server.module.js +15 -10
- package/orm/decorators.d.ts +24 -1
- package/orm/decorators.js +40 -4
- package/orm/query/base.d.ts +17 -17
- package/orm/query/base.js +1 -1
- package/orm/repository.types.d.ts +45 -1
- package/orm/schemas/tsvector.js +1 -1
- package/orm/server/drizzle/schema-converter.d.ts +3 -1
- package/orm/server/drizzle/schema-converter.js +120 -14
- package/orm/server/index.d.ts +1 -0
- package/orm/server/index.js +1 -0
- package/orm/server/module.d.ts +4 -2
- package/orm/server/module.js +6 -5
- package/orm/server/query-converter.d.ts +6 -3
- package/orm/server/query-converter.js +32 -20
- package/orm/server/repository-config.d.ts +8 -0
- package/orm/server/repository-config.js +8 -0
- package/orm/server/repository.d.ts +117 -43
- package/orm/server/repository.js +757 -253
- package/orm/server/transaction.d.ts +4 -2
- package/orm/server/transaction.js +14 -5
- package/orm/server/transactional.d.ts +6 -2
- package/orm/server/transactional.js +39 -9
- package/orm/server/types.d.ts +2 -0
- package/orm/sqls/case-when.d.ts +3 -3
- package/orm/sqls/case-when.js +2 -2
- package/orm/sqls/sqls.d.ts +31 -5
- package/orm/sqls/sqls.js +69 -6
- package/orm/tests/data-types.test.d.ts +1 -0
- package/orm/tests/data-types.test.js +39 -0
- package/orm/tests/decorators.test.d.ts +1 -0
- package/orm/tests/decorators.test.js +77 -0
- package/orm/tests/encryption.test.d.ts +1 -0
- package/orm/tests/encryption.test.js +34 -0
- package/orm/tests/query-complex.test.d.ts +1 -0
- package/orm/tests/query-complex.test.js +203 -0
- package/orm/tests/query-converter-complex.test.d.ts +1 -0
- package/orm/tests/query-converter-complex.test.js +126 -0
- package/orm/tests/query-converter.test.d.ts +1 -0
- package/orm/tests/query-converter.test.js +123 -0
- package/orm/tests/repository-advanced.test.d.ts +1 -0
- package/orm/tests/repository-advanced.test.js +232 -0
- package/orm/tests/repository-attributes.test.d.ts +1 -0
- package/orm/tests/repository-attributes.test.js +99 -0
- package/orm/tests/repository-comprehensive.test.d.ts +1 -0
- package/orm/tests/repository-comprehensive.test.js +187 -0
- package/orm/tests/repository-coverage.test.d.ts +1 -0
- package/orm/tests/repository-coverage.test.js +303 -0
- package/orm/tests/repository-cti-complex.test.d.ts +1 -0
- package/orm/tests/repository-cti-complex.test.js +170 -0
- package/orm/tests/repository-cti-embedded.test.d.ts +1 -0
- package/orm/tests/repository-cti-embedded.test.js +188 -0
- package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
- package/orm/tests/repository-cti-extensive.test.js +308 -0
- package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
- package/orm/tests/repository-cti-mapping.test.js +121 -0
- package/orm/tests/repository-cti-search.test.d.ts +1 -0
- package/orm/tests/repository-cti-search.test.js +152 -0
- package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-cti-soft-delete.test.js +115 -0
- package/orm/tests/repository-cti-transactions.test.d.ts +1 -0
- package/orm/tests/repository-cti-transactions.test.js +126 -0
- package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
- package/orm/tests/repository-cti-upsert-many.test.js +127 -0
- package/orm/tests/repository-cti.test.d.ts +1 -0
- package/orm/tests/repository-cti.test.js +456 -0
- package/orm/tests/repository-edge-cases.test.d.ts +1 -0
- package/orm/tests/repository-edge-cases.test.js +216 -0
- package/orm/tests/repository-expiration.test.d.ts +1 -0
- package/orm/tests/repository-expiration.test.js +153 -0
- package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
- package/orm/tests/repository-extra-coverage.test.js +546 -0
- package/orm/tests/repository-mapping.test.d.ts +1 -0
- package/orm/tests/repository-mapping.test.js +71 -0
- package/orm/tests/repository-regression.test.d.ts +1 -0
- package/orm/tests/repository-regression.test.js +330 -0
- package/orm/tests/repository-search-coverage.test.d.ts +1 -0
- package/orm/tests/repository-search-coverage.test.js +129 -0
- package/orm/tests/repository-search.test.d.ts +1 -0
- package/orm/tests/repository-search.test.js +116 -0
- package/orm/tests/repository-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-soft-delete.test.js +143 -0
- package/orm/tests/repository-transactions-nested.test.d.ts +1 -0
- package/orm/tests/repository-transactions-nested.test.js +202 -0
- package/orm/tests/repository-types.test.d.ts +1 -0
- package/orm/tests/repository-types.test.js +218 -0
- package/orm/tests/schema-converter.test.d.ts +1 -0
- package/orm/tests/schema-converter.test.js +81 -0
- package/orm/tests/schema-generation.test.d.ts +1 -0
- package/orm/tests/schema-generation.test.js +127 -0
- package/orm/tests/sql-helpers.test.d.ts +1 -0
- package/orm/tests/sql-helpers.test.js +67 -0
- package/orm/tests/transaction-safety.test.d.ts +1 -0
- package/orm/tests/transaction-safety.test.js +81 -0
- package/orm/tests/transactional.test.d.ts +1 -0
- package/orm/tests/transactional.test.js +224 -0
- package/orm/tests/utils.test.d.ts +1 -0
- package/orm/tests/utils.test.js +70 -0
- package/orm/utils.d.ts +7 -0
- package/orm/utils.js +26 -6
- package/package.json +12 -7
- package/pool/pool.js +1 -1
- package/rate-limit/index.d.ts +2 -0
- package/rate-limit/index.js +2 -0
- package/rate-limit/postgres/drizzle/0000_watery_rage.sql +7 -0
- package/{queue → rate-limit}/postgres/drizzle/meta/0000_snapshot.json +14 -39
- package/rate-limit/postgres/drizzle/meta/_journal.json +13 -0
- package/{queue → rate-limit}/postgres/drizzle.config.js +1 -1
- package/rate-limit/postgres/index.d.ts +4 -0
- package/rate-limit/postgres/index.js +4 -0
- package/rate-limit/postgres/module.d.ts +12 -0
- package/rate-limit/postgres/module.js +28 -0
- package/rate-limit/postgres/postgres-rate-limiter.d.ts +9 -0
- package/rate-limit/postgres/postgres-rate-limiter.js +56 -0
- package/rate-limit/postgres/rate-limit.model.d.ts +8 -0
- package/rate-limit/postgres/rate-limit.model.js +35 -0
- package/rate-limit/postgres/rate-limiter.provider.d.ts +6 -0
- package/rate-limit/postgres/rate-limiter.provider.js +21 -0
- package/rate-limit/postgres/schemas.d.ts +3 -0
- package/rate-limit/postgres/schemas.js +4 -0
- package/rate-limit/provider.d.ts +9 -0
- package/rate-limit/provider.js +2 -0
- package/rate-limit/rate-limiter.d.ts +35 -0
- package/rate-limit/rate-limiter.js +3 -0
- package/rate-limit/tests/postgres-rate-limiter.test.d.ts +1 -0
- package/rate-limit/tests/postgres-rate-limiter.test.js +92 -0
- package/signals/implementation/configure.d.ts +3 -0
- package/signals/implementation/configure.js +3 -0
- package/sse/data-stream-source.d.ts +1 -1
- package/sse/data-stream-source.js +6 -6
- package/task-queue/enqueue-batch.d.ts +17 -0
- package/task-queue/enqueue-batch.js +24 -0
- package/{queue → task-queue}/index.d.ts +1 -1
- package/{queue → task-queue}/index.js +1 -1
- package/task-queue/postgres/drizzle/0000_thin_black_panther.sql +74 -0
- package/task-queue/postgres/drizzle/meta/0000_snapshot.json +592 -0
- package/task-queue/postgres/drizzle/meta/_journal.json +13 -0
- package/task-queue/postgres/drizzle.config.d.ts +2 -0
- package/task-queue/postgres/drizzle.config.js +11 -0
- package/task-queue/postgres/index.d.ts +4 -0
- package/task-queue/postgres/index.js +4 -0
- package/task-queue/postgres/module.d.ts +12 -0
- package/task-queue/postgres/module.js +28 -0
- package/task-queue/postgres/schemas.d.ts +16 -0
- package/task-queue/postgres/schemas.js +8 -0
- package/task-queue/postgres/task-queue.d.ts +83 -0
- package/task-queue/postgres/task-queue.js +1054 -0
- package/task-queue/postgres/task-queue.provider.d.ts +7 -0
- package/{queue/postgres/queue.provider.js → task-queue/postgres/task-queue.provider.js} +8 -8
- package/task-queue/postgres/task.model.d.ts +39 -0
- package/task-queue/postgres/task.model.js +178 -0
- package/{queue → task-queue}/provider.d.ts +3 -3
- package/task-queue/provider.js +2 -0
- package/{queue → task-queue}/task-context.d.ts +7 -7
- package/{queue → task-queue}/task-context.js +8 -8
- package/{queue/queue.d.ts → task-queue/task-queue.d.ts} +128 -59
- package/task-queue/task-queue.js +200 -0
- package/task-queue/tests/complex.test.d.ts +1 -0
- package/task-queue/tests/complex.test.js +299 -0
- package/task-queue/tests/dependencies.test.d.ts +1 -0
- package/task-queue/tests/dependencies.test.js +174 -0
- package/task-queue/tests/queue.test.d.ts +1 -0
- package/task-queue/tests/queue.test.js +334 -0
- package/task-queue/tests/worker.test.d.ts +1 -0
- package/task-queue/tests/worker.test.js +163 -0
- package/test1.js +1 -1
- package/test4.js +2 -2
- package/unit-test/index.d.ts +1 -0
- package/unit-test/index.js +1 -0
- package/unit-test/integration-setup.d.ts +55 -0
- package/unit-test/integration-setup.js +182 -0
- package/utils/patterns.d.ts +3 -0
- package/utils/patterns.js +6 -1
- package/audit/drizzle/0001_previous_network.sql +0 -2
- package/audit/drizzle/meta/0001_snapshot.json +0 -195
- package/queue/enqueue-batch.d.ts +0 -17
- package/queue/enqueue-batch.js +0 -18
- package/queue/postgres/drizzle/0000_zippy_moondragon.sql +0 -11
- package/queue/postgres/drizzle/0001_certain_wild_pack.sql +0 -2
- package/queue/postgres/drizzle/0002_dear_meggan.sql +0 -2
- package/queue/postgres/drizzle/0003_tricky_venom.sql +0 -30
- package/queue/postgres/drizzle/meta/0001_snapshot.json +0 -103
- package/queue/postgres/drizzle/meta/0002_snapshot.json +0 -90
- package/queue/postgres/drizzle/meta/0003_snapshot.json +0 -288
- package/queue/postgres/drizzle/meta/_journal.json +0 -34
- package/queue/postgres/index.d.ts +0 -4
- package/queue/postgres/index.js +0 -4
- package/queue/postgres/module.d.ts +0 -9
- package/queue/postgres/module.js +0 -29
- package/queue/postgres/queue.d.ts +0 -60
- package/queue/postgres/queue.js +0 -681
- package/queue/postgres/queue.provider.d.ts +0 -7
- package/queue/postgres/schemas.d.ts +0 -14
- package/queue/postgres/schemas.js +0 -6
- package/queue/postgres/task.model.d.ts +0 -24
- package/queue/postgres/task.model.js +0 -115
- package/queue/provider.js +0 -2
- package/queue/queue.js +0 -131
- package/queue/tests/queue.test.js +0 -623
- package/test3.d.ts +0 -1
- package/test3.js +0 -47
- /package/{queue/tests/queue.test.d.ts → api/server/tests/csrf.middleware.test.d.ts} +0 -0
- /package/circuit-breaker/postgres/drizzle/{0000_hard_shocker.sql → 0000_cooing_korath.sql} +0 -0
- /package/{queue → rate-limit}/postgres/drizzle.config.d.ts +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TaskQueueProvider, type QueueConfig } from '../../task-queue/index.js';
|
|
2
|
+
import type { ObjectLiteral } from '../../types/index.js';
|
|
3
|
+
import { PostgresQueue } from './task-queue.js';
|
|
4
|
+
export declare class PostgresTaskQueueProvider extends TaskQueueProvider {
|
|
5
|
+
#private;
|
|
6
|
+
get<Data extends ObjectLiteral, State extends ObjectLiteral, Result extends ObjectLiteral>(namespace: string, config?: QueueConfig): PostgresQueue<Data, State, Result>;
|
|
7
|
+
}
|
|
@@ -7,15 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Singleton } from '../../injector/decorators.js';
|
|
8
8
|
import { inject } from '../../injector/inject.js';
|
|
9
9
|
import { Injector } from '../../injector/injector.js';
|
|
10
|
-
import {
|
|
11
|
-
import { PostgresQueue } from './queue.js';
|
|
12
|
-
let
|
|
10
|
+
import { TaskQueueProvider } from '../../task-queue/index.js';
|
|
11
|
+
import { PostgresQueue } from './task-queue.js';
|
|
12
|
+
let PostgresTaskQueueProvider = class PostgresTaskQueueProvider extends TaskQueueProvider {
|
|
13
13
|
#injector = inject(Injector);
|
|
14
|
-
get(
|
|
15
|
-
return this.#injector.resolve((PostgresQueue), { ...config,
|
|
14
|
+
get(namespace, config) {
|
|
15
|
+
return this.#injector.resolve((PostgresQueue), { ...config, namespace });
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
PostgresTaskQueueProvider = __decorate([
|
|
19
19
|
Singleton()
|
|
20
|
-
],
|
|
21
|
-
export {
|
|
20
|
+
], PostgresTaskQueueProvider);
|
|
21
|
+
export { PostgresTaskQueueProvider };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseEntity, type Json, type Timestamp } from '../../orm/index.js';
|
|
2
|
+
import type { ObjectLiteral, TypedOmit } from '../../types/types.js';
|
|
3
|
+
import { DependencyJoinMode, type Task, TaskState } from '../task-queue.js';
|
|
4
|
+
export declare abstract class PostgresTaskBase<Data extends ObjectLiteral = ObjectLiteral, State extends ObjectLiteral = ObjectLiteral, Result extends ObjectLiteral = ObjectLiteral> extends BaseEntity implements TypedOmit<Task<Data, State, Result>, 'parentId'> {
|
|
5
|
+
namespace: string;
|
|
6
|
+
type: string;
|
|
7
|
+
status: TaskState;
|
|
8
|
+
idempotencyKey: string | null;
|
|
9
|
+
traceId: string | null;
|
|
10
|
+
tags: string[];
|
|
11
|
+
completeAfterTags: string[];
|
|
12
|
+
scheduleAfterTags: string[];
|
|
13
|
+
failFast: boolean;
|
|
14
|
+
dependencyJoinMode: DependencyJoinMode;
|
|
15
|
+
dependencyTriggerStates: TaskState[];
|
|
16
|
+
priority: number;
|
|
17
|
+
token: string | null;
|
|
18
|
+
creationTimestamp: Timestamp;
|
|
19
|
+
priorityAgeTimestamp: Timestamp;
|
|
20
|
+
scheduleTimestamp: Timestamp;
|
|
21
|
+
startTimestamp: Timestamp | null;
|
|
22
|
+
timeToLive: Timestamp | null;
|
|
23
|
+
visibilityDeadline: Timestamp | null;
|
|
24
|
+
completeTimestamp: Timestamp | null;
|
|
25
|
+
tries: number;
|
|
26
|
+
progress: number;
|
|
27
|
+
data: Json<Data> | null;
|
|
28
|
+
state: Json<State> | null;
|
|
29
|
+
result: Json<Result> | null;
|
|
30
|
+
error: Json<ObjectLiteral> | null;
|
|
31
|
+
}
|
|
32
|
+
export declare class PostgresTask<Data extends ObjectLiteral = ObjectLiteral, State extends ObjectLiteral = ObjectLiteral, Result extends ObjectLiteral = ObjectLiteral> extends PostgresTaskBase<Data, State, Result> implements Task<Data, State, Result> {
|
|
33
|
+
static readonly entityName = "Task";
|
|
34
|
+
parentId: string | null;
|
|
35
|
+
}
|
|
36
|
+
export declare class PostgresTaskArchive<Data extends ObjectLiteral = ObjectLiteral, State extends ObjectLiteral = ObjectLiteral, Result extends ObjectLiteral = ObjectLiteral> extends PostgresTaskBase<Data, State, Result> implements PostgresTask<Data, State, Result> {
|
|
37
|
+
static readonly entityName = "TaskArchive";
|
|
38
|
+
parentId: string | null;
|
|
39
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { BaseEntity, Index, JsonProperty, Reference, Table, TimestampProperty, Unique, UuidProperty } from '../../orm/index.js';
|
|
11
|
+
import { Array as ArrayProperty, BooleanProperty, Enumeration, Integer, NumberProperty, StringProperty } from '../../schema/index.js';
|
|
12
|
+
import { DependencyJoinMode, TaskState } from '../task-queue.js';
|
|
13
|
+
export class PostgresTaskBase extends BaseEntity {
|
|
14
|
+
namespace;
|
|
15
|
+
type;
|
|
16
|
+
status;
|
|
17
|
+
idempotencyKey;
|
|
18
|
+
traceId;
|
|
19
|
+
tags;
|
|
20
|
+
completeAfterTags;
|
|
21
|
+
scheduleAfterTags;
|
|
22
|
+
failFast;
|
|
23
|
+
dependencyJoinMode;
|
|
24
|
+
dependencyTriggerStates;
|
|
25
|
+
priority;
|
|
26
|
+
token;
|
|
27
|
+
creationTimestamp;
|
|
28
|
+
priorityAgeTimestamp;
|
|
29
|
+
scheduleTimestamp;
|
|
30
|
+
startTimestamp;
|
|
31
|
+
timeToLive;
|
|
32
|
+
visibilityDeadline;
|
|
33
|
+
completeTimestamp;
|
|
34
|
+
tries;
|
|
35
|
+
progress;
|
|
36
|
+
data;
|
|
37
|
+
state;
|
|
38
|
+
result;
|
|
39
|
+
error;
|
|
40
|
+
}
|
|
41
|
+
__decorate([
|
|
42
|
+
StringProperty(),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], PostgresTaskBase.prototype, "namespace", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
StringProperty(),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], PostgresTaskBase.prototype, "type", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
Enumeration(TaskState),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], PostgresTaskBase.prototype, "status", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
StringProperty({ nullable: true }),
|
|
55
|
+
__metadata("design:type", Object)
|
|
56
|
+
], PostgresTaskBase.prototype, "idempotencyKey", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
StringProperty({ nullable: true }),
|
|
59
|
+
__metadata("design:type", Object)
|
|
60
|
+
], PostgresTaskBase.prototype, "traceId", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
ArrayProperty(String),
|
|
63
|
+
__metadata("design:type", Array)
|
|
64
|
+
], PostgresTaskBase.prototype, "tags", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
ArrayProperty(String),
|
|
67
|
+
__metadata("design:type", Array)
|
|
68
|
+
], PostgresTaskBase.prototype, "completeAfterTags", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
ArrayProperty(String),
|
|
71
|
+
__metadata("design:type", Array)
|
|
72
|
+
], PostgresTaskBase.prototype, "scheduleAfterTags", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
BooleanProperty(),
|
|
75
|
+
__metadata("design:type", Boolean)
|
|
76
|
+
], PostgresTaskBase.prototype, "failFast", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
Enumeration(DependencyJoinMode),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], PostgresTaskBase.prototype, "dependencyJoinMode", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
Enumeration(TaskState, { array: true }),
|
|
83
|
+
__metadata("design:type", Array)
|
|
84
|
+
], PostgresTaskBase.prototype, "dependencyTriggerStates", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
Integer(),
|
|
87
|
+
__metadata("design:type", Number)
|
|
88
|
+
], PostgresTaskBase.prototype, "priority", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
UuidProperty({ nullable: true }),
|
|
91
|
+
__metadata("design:type", Object)
|
|
92
|
+
], PostgresTaskBase.prototype, "token", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
TimestampProperty(),
|
|
95
|
+
__metadata("design:type", Number)
|
|
96
|
+
], PostgresTaskBase.prototype, "creationTimestamp", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
TimestampProperty(),
|
|
99
|
+
__metadata("design:type", Number)
|
|
100
|
+
], PostgresTaskBase.prototype, "priorityAgeTimestamp", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
TimestampProperty(),
|
|
103
|
+
__metadata("design:type", Number)
|
|
104
|
+
], PostgresTaskBase.prototype, "scheduleTimestamp", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
TimestampProperty({ nullable: true }),
|
|
107
|
+
__metadata("design:type", Object)
|
|
108
|
+
], PostgresTaskBase.prototype, "startTimestamp", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
TimestampProperty({ nullable: true }),
|
|
111
|
+
__metadata("design:type", Object)
|
|
112
|
+
], PostgresTaskBase.prototype, "timeToLive", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
TimestampProperty({ nullable: true }),
|
|
115
|
+
__metadata("design:type", Object)
|
|
116
|
+
], PostgresTaskBase.prototype, "visibilityDeadline", void 0);
|
|
117
|
+
__decorate([
|
|
118
|
+
TimestampProperty({ nullable: true }),
|
|
119
|
+
__metadata("design:type", Object)
|
|
120
|
+
], PostgresTaskBase.prototype, "completeTimestamp", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
Integer(),
|
|
123
|
+
__metadata("design:type", Number)
|
|
124
|
+
], PostgresTaskBase.prototype, "tries", void 0);
|
|
125
|
+
__decorate([
|
|
126
|
+
NumberProperty(),
|
|
127
|
+
__metadata("design:type", Number)
|
|
128
|
+
], PostgresTaskBase.prototype, "progress", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
JsonProperty({ nullable: true }),
|
|
131
|
+
__metadata("design:type", Object)
|
|
132
|
+
], PostgresTaskBase.prototype, "data", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
JsonProperty({ nullable: true }),
|
|
135
|
+
__metadata("design:type", Object)
|
|
136
|
+
], PostgresTaskBase.prototype, "state", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
JsonProperty({ nullable: true }),
|
|
139
|
+
__metadata("design:type", Object)
|
|
140
|
+
], PostgresTaskBase.prototype, "result", void 0);
|
|
141
|
+
__decorate([
|
|
142
|
+
JsonProperty({ nullable: true }),
|
|
143
|
+
__metadata("design:type", Object)
|
|
144
|
+
], PostgresTaskBase.prototype, "error", void 0);
|
|
145
|
+
let PostgresTask = class PostgresTask extends PostgresTaskBase {
|
|
146
|
+
static entityName = 'Task';
|
|
147
|
+
parentId;
|
|
148
|
+
};
|
|
149
|
+
__decorate([
|
|
150
|
+
Reference(() => PostgresTask),
|
|
151
|
+
UuidProperty({ nullable: true }),
|
|
152
|
+
__metadata("design:type", Object)
|
|
153
|
+
], PostgresTask.prototype, "parentId", void 0);
|
|
154
|
+
PostgresTask = __decorate([
|
|
155
|
+
Table('task', { schema: 'task_queue' }),
|
|
156
|
+
Unique(['namespace', 'idempotencyKey']),
|
|
157
|
+
Index(['namespace', 'status', 'scheduleTimestamp', 'priority']),
|
|
158
|
+
Index(['tags'], { using: 'gin' }),
|
|
159
|
+
Index(['completeAfterTags'], { using: 'gin' }),
|
|
160
|
+
Index(['scheduleAfterTags'], { using: 'gin' }),
|
|
161
|
+
Index(['status', 'completeTimestamp']),
|
|
162
|
+
Index(['status', 'visibilityDeadline']),
|
|
163
|
+
Index(['parentId'])
|
|
164
|
+
], PostgresTask);
|
|
165
|
+
export { PostgresTask };
|
|
166
|
+
let PostgresTaskArchive = class PostgresTaskArchive extends PostgresTaskBase {
|
|
167
|
+
static entityName = 'TaskArchive';
|
|
168
|
+
parentId;
|
|
169
|
+
};
|
|
170
|
+
__decorate([
|
|
171
|
+
UuidProperty({ nullable: true }),
|
|
172
|
+
__metadata("design:type", Object)
|
|
173
|
+
], PostgresTaskArchive.prototype, "parentId", void 0);
|
|
174
|
+
PostgresTaskArchive = __decorate([
|
|
175
|
+
Table('task_archive', { schema: 'task_queue' }),
|
|
176
|
+
Index(['namespace', 'completeTimestamp'])
|
|
177
|
+
], PostgresTaskArchive);
|
|
178
|
+
export { PostgresTaskArchive };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ObjectLiteral } from '../types/index.js';
|
|
2
|
-
import type {
|
|
3
|
-
export declare abstract class
|
|
4
|
-
abstract get<Data extends ObjectLiteral, State extends ObjectLiteral, Result extends ObjectLiteral>(key: string, config?: QueueConfig):
|
|
2
|
+
import type { TaskQueue, QueueConfig } from './task-queue.js';
|
|
3
|
+
export declare abstract class TaskQueueProvider {
|
|
4
|
+
abstract get<Data extends ObjectLiteral, State extends ObjectLiteral, Result extends ObjectLiteral>(key: string, config?: QueueConfig): TaskQueue<Data, State, Result>;
|
|
5
5
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { CancellationSignal, CancellationToken } from '../cancellation/index.js';
|
|
2
2
|
import type { Logger } from '../logger/index.js';
|
|
3
3
|
import type { Transaction } from '../orm/server/index.js';
|
|
4
|
-
import { type EnqueueManyItem, type EnqueueOptions,
|
|
4
|
+
import { type EnqueueManyItem, type EnqueueOptions, TaskQueue, type Task } from './task-queue.js';
|
|
5
5
|
export declare class TaskContext<Data, State = unknown, Result = unknown> {
|
|
6
6
|
#private;
|
|
7
|
-
constructor(queue:
|
|
7
|
+
constructor(queue: TaskQueue<Data, State, Result>, task: Task<Data, State, Result>, signal: CancellationToken, logger: Logger);
|
|
8
8
|
get id(): string;
|
|
9
9
|
get data(): Data;
|
|
10
10
|
get attempt(): number;
|
|
11
11
|
get triesLeft(): number;
|
|
12
12
|
get signal(): CancellationSignal;
|
|
13
13
|
get logger(): Logger;
|
|
14
|
-
|
|
14
|
+
complete(result?: Result, transaction?: Transaction): Promise<void>;
|
|
15
15
|
checkpoint(options: {
|
|
16
16
|
progress?: number;
|
|
17
17
|
state?: State;
|
|
18
18
|
}): Promise<void>;
|
|
19
|
-
spawn(data: Data, options?: Omit<EnqueueOptions, 'parentId'>): Promise<Task<Data, State, Result>>;
|
|
20
|
-
spawn<D, S, R>(queue:
|
|
19
|
+
spawn(type: string, data: Data, options?: Omit<EnqueueOptions, 'parentId'>): Promise<Task<Data, State, Result>>;
|
|
20
|
+
spawn<D, S, R>(queue: TaskQueue<D, S, R>, type: string, data: D, options?: Omit<EnqueueOptions, 'parentId'>): Promise<Task<D, S, R>>;
|
|
21
21
|
spawnMany(items: EnqueueManyItem<Data>[]): Promise<Task<Data, State, Result>[]>;
|
|
22
|
-
spawnMany<D = Data, S = any, R = any>(queue:
|
|
22
|
+
spawnMany<D = Data, S = any, R = any>(queue: TaskQueue<D, S, R>, items: EnqueueManyItem<D>[]): Promise<Task<D, S, R>[]>;
|
|
23
23
|
/** Stop execution and reschedule the task for later without incrementing tries if possible */
|
|
24
24
|
reschedule(timestamp: number): Promise<void>;
|
|
25
25
|
reschedule(options: {
|
|
@@ -29,7 +29,7 @@ export declare class TaskContext<Data, State = unknown, Result = unknown> {
|
|
|
29
29
|
}
|
|
30
30
|
export declare class BatchTaskContext<Data, State, Result> {
|
|
31
31
|
#private;
|
|
32
|
-
constructor(queue:
|
|
32
|
+
constructor(queue: TaskQueue<Data, State, Result>, tasks: Task<Data, State, Result>[], signal: CancellationToken, logger: Logger);
|
|
33
33
|
get tasks(): Task<Data, State, Result>[];
|
|
34
34
|
get signal(): CancellationSignal;
|
|
35
35
|
get logger(): Logger;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { currentTimestamp } from '../utils/date-time.js';
|
|
2
2
|
import { isInstanceOf, isNumber, isUndefined } from '../utils/type-guards.js';
|
|
3
|
-
import {
|
|
3
|
+
import { TaskQueue } from './task-queue.js';
|
|
4
4
|
export class TaskContext {
|
|
5
5
|
#queue;
|
|
6
6
|
#logger;
|
|
@@ -30,8 +30,8 @@ export class TaskContext {
|
|
|
30
30
|
get logger() {
|
|
31
31
|
return this.#logger;
|
|
32
32
|
}
|
|
33
|
-
async
|
|
34
|
-
await this.#queue.
|
|
33
|
+
async complete(result, transaction) {
|
|
34
|
+
await this.#queue.complete(this.#task, result, transaction);
|
|
35
35
|
}
|
|
36
36
|
async checkpoint(options) {
|
|
37
37
|
const updatedTask = await this.#queue.touch(this.#task, options);
|
|
@@ -43,14 +43,14 @@ export class TaskContext {
|
|
|
43
43
|
this.#task = updatedTask;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
async spawn(
|
|
47
|
-
if (isInstanceOf(
|
|
48
|
-
return await
|
|
46
|
+
async spawn(queueOrType, typeOrData, dataOrOptionsOrNothing, optionsOrNothing) {
|
|
47
|
+
if (isInstanceOf(queueOrType, TaskQueue)) {
|
|
48
|
+
return await queueOrType.enqueue(typeOrData, dataOrOptionsOrNothing, { ...optionsOrNothing, parentId: this.#task.id });
|
|
49
49
|
}
|
|
50
|
-
return await this.#queue.enqueue(
|
|
50
|
+
return await this.#queue.enqueue(queueOrType, typeOrData, { ...dataOrOptionsOrNothing, parentId: this.#task.id });
|
|
51
51
|
}
|
|
52
52
|
async spawnMany(queueOrItems, itemsOrNothing) {
|
|
53
|
-
const isForOtherQueue = isInstanceOf(queueOrItems,
|
|
53
|
+
const isForOtherQueue = isInstanceOf(queueOrItems, TaskQueue);
|
|
54
54
|
const items = (isForOtherQueue ? itemsOrNothing : queueOrItems).map((item) => ({ ...item, parentId: this.#task.id }));
|
|
55
55
|
if (isForOtherQueue) {
|
|
56
56
|
return await queueOrItems.enqueueMany(items, { returnTasks: true });
|
|
@@ -1,26 +1,45 @@
|
|
|
1
1
|
import type { CancellationSignal } from '../cancellation/token.js';
|
|
2
2
|
import { type EnumType } from '../enumeration/enumeration.js';
|
|
3
3
|
import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
|
|
4
|
-
import
|
|
4
|
+
import { Logger } from '../logger/logger.js';
|
|
5
5
|
import type { Transaction } from '../orm/server/transaction.js';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
6
|
+
import { Transactional } from '../orm/server/transactional.js';
|
|
7
|
+
import type { OneOrMany, UndefinableJson } from '../types/types.js';
|
|
8
|
+
import { TaskQueueEnqueueBatch } from './enqueue-batch.js';
|
|
8
9
|
import { BatchTaskContext, type TaskContext } from './task-context.js';
|
|
10
|
+
type TaskResultPayload<Result> = {
|
|
11
|
+
action: 'complete';
|
|
12
|
+
result: Result | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
action: 'fail';
|
|
15
|
+
error: any;
|
|
16
|
+
fatal: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
action: 'reschedule';
|
|
19
|
+
timestamp: number;
|
|
20
|
+
};
|
|
21
|
+
export declare class TaskResult<Result = unknown> {
|
|
22
|
+
readonly payload: TaskResultPayload<Result>;
|
|
23
|
+
private constructor();
|
|
24
|
+
static Complete<Result>(result?: Result): TaskResult<Result>;
|
|
25
|
+
static Fail(error: any, fatal?: boolean): TaskResult;
|
|
26
|
+
static RescheduleTo(timestamp: number): TaskResult;
|
|
27
|
+
static RescheduleBy(milliseconds: number): TaskResult;
|
|
28
|
+
}
|
|
9
29
|
export interface ProcessWorker<Data, State, Result> {
|
|
10
30
|
/**
|
|
11
31
|
* A worker function that processes a single task.
|
|
12
32
|
* @param context The task context providing data, logger, and orchestration helpers.
|
|
13
33
|
*/
|
|
14
|
-
(context: TaskContext<Data, State, Result>):
|
|
34
|
+
(context: TaskContext<Data, State, Result>): TaskResult<Result> | Promise<TaskResult<Result>>;
|
|
15
35
|
}
|
|
16
36
|
export interface ProcessBatchWorker<Data, State, Result> {
|
|
17
37
|
/**
|
|
18
38
|
* A worker function that processes a batch of tasks.
|
|
19
39
|
* @param context The batch context providing tasks and helpers.
|
|
20
40
|
*/
|
|
21
|
-
(context: BatchTaskContext<Data, State, Result>):
|
|
41
|
+
(context: BatchTaskContext<Data, State, Result>): TaskResult<Result>[] | Promise<TaskResult<Result>[]>;
|
|
22
42
|
}
|
|
23
|
-
export type TaskTag = string | null;
|
|
24
43
|
export declare const TaskState: {
|
|
25
44
|
/**
|
|
26
45
|
* The task is waiting to be processed.
|
|
@@ -48,21 +67,35 @@ export declare const TaskState: {
|
|
|
48
67
|
readonly Dead: "dead";
|
|
49
68
|
};
|
|
50
69
|
export type TaskState = EnumType<typeof TaskState>;
|
|
70
|
+
export declare const DependencyJoinMode: {
|
|
71
|
+
readonly And: "and";
|
|
72
|
+
readonly Or: "or";
|
|
73
|
+
};
|
|
74
|
+
export type DependencyJoinMode = EnumType<typeof DependencyJoinMode>;
|
|
51
75
|
export type Task<Data = unknown, State = unknown, Result = unknown> = {
|
|
52
76
|
id: string;
|
|
53
|
-
|
|
77
|
+
namespace: string;
|
|
78
|
+
type: string;
|
|
54
79
|
status: TaskState;
|
|
55
|
-
|
|
80
|
+
token: string | null;
|
|
56
81
|
/**
|
|
57
82
|
* The lower the number, the higher the priority.
|
|
58
83
|
* @default 1000
|
|
59
84
|
*/
|
|
60
85
|
priority: number;
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
idempotencyKey: string | null;
|
|
87
|
+
traceId: string | null;
|
|
88
|
+
tags: string[];
|
|
89
|
+
completeAfterTags: string[];
|
|
90
|
+
scheduleAfterTags: string[];
|
|
91
|
+
failFast: boolean;
|
|
92
|
+
dependencyJoinMode: DependencyJoinMode;
|
|
93
|
+
dependencyTriggerStates: TaskState[];
|
|
94
|
+
data: Data | null;
|
|
63
95
|
parentId: string | null;
|
|
64
96
|
tries: number;
|
|
65
|
-
|
|
97
|
+
creationTimestamp: number;
|
|
98
|
+
priorityAgeTimestamp: number;
|
|
66
99
|
scheduleTimestamp: number;
|
|
67
100
|
/**
|
|
68
101
|
* Timestamp when the task most recently switched to Running state.
|
|
@@ -73,8 +106,11 @@ export type Task<Data = unknown, State = unknown, Result = unknown> = {
|
|
|
73
106
|
* Timestamp after which the task is considered expired if it hasn't started Running.
|
|
74
107
|
* If null, the task never expires in the queue.
|
|
75
108
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
109
|
+
timeToLive: number | null;
|
|
110
|
+
/**
|
|
111
|
+
* Token expiration (Soft Timeout).
|
|
112
|
+
*/
|
|
113
|
+
visibilityDeadline: number | null;
|
|
78
114
|
completeTimestamp: number | null;
|
|
79
115
|
/** A number between 0 and 1 indicating the progress of the task. */
|
|
80
116
|
progress: number;
|
|
@@ -84,46 +120,47 @@ export type Task<Data = unknown, State = unknown, Result = unknown> = {
|
|
|
84
120
|
error: UndefinableJson | null;
|
|
85
121
|
};
|
|
86
122
|
export declare const defaultTaskPriority = 1000;
|
|
87
|
-
export declare const UniqueTagStrategy: {
|
|
88
|
-
readonly KeepOld: 0;
|
|
89
|
-
readonly TakeNew: 1;
|
|
90
|
-
};
|
|
91
|
-
export type UniqueTagStrategy = EnumType<typeof UniqueTagStrategy>;
|
|
92
123
|
export type EnqueueOptions = {
|
|
93
|
-
tag?: TaskTag;
|
|
94
124
|
priority?: number;
|
|
95
125
|
parentId?: string;
|
|
126
|
+
idempotencyKey?: string;
|
|
127
|
+
replace?: boolean;
|
|
128
|
+
tags?: string[];
|
|
129
|
+
completeAfterTags?: string[];
|
|
130
|
+
scheduleAfterTags?: string[];
|
|
131
|
+
failFast?: boolean;
|
|
132
|
+
dependencyJoinMode?: DependencyJoinMode;
|
|
133
|
+
dependencyTriggerStates?: TaskState[];
|
|
96
134
|
scheduleTimestamp?: number;
|
|
97
|
-
|
|
135
|
+
timeToLive?: number;
|
|
98
136
|
transaction?: Transaction;
|
|
99
137
|
};
|
|
100
|
-
export type EnqueueOneOptions = EnqueueOptions
|
|
101
|
-
uniqueTag?: UniqueTagStrategy;
|
|
102
|
-
};
|
|
138
|
+
export type EnqueueOneOptions = EnqueueOptions;
|
|
103
139
|
export type EnqueueManyItem<T> = EnqueueOptions & {
|
|
140
|
+
type: string;
|
|
104
141
|
data: T;
|
|
105
142
|
};
|
|
106
143
|
export type EnqueueManyOptions = {
|
|
107
|
-
|
|
144
|
+
replace?: boolean;
|
|
108
145
|
returnTasks?: boolean;
|
|
109
146
|
transaction?: Transaction;
|
|
110
147
|
};
|
|
111
148
|
export type QueueConfig = {
|
|
112
149
|
/**
|
|
113
|
-
* Duration
|
|
150
|
+
* Duration (ms) before a worker token is considered lost.
|
|
151
|
+
* Corresponds to $$VisibilityTimeout$$
|
|
114
152
|
*/
|
|
115
|
-
|
|
153
|
+
visibilityTimeout?: number;
|
|
116
154
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
155
|
+
* Hard limit for Running state (ms).
|
|
156
|
+
* Corresponds to $$MaxExecutionTime$$
|
|
119
157
|
* **WARN:** CancellationSignal must still be observed by the worker!
|
|
120
|
-
* Default: 15 minutes
|
|
121
158
|
*/
|
|
122
|
-
|
|
123
|
-
/** Maximum number of attempts
|
|
159
|
+
maxExecutionTime?: number;
|
|
160
|
+
/** Maximum number of attempts allowed. Default 3 */
|
|
124
161
|
maxTries?: number;
|
|
125
|
-
/**
|
|
126
|
-
|
|
162
|
+
/** Duration to retain terminal tasks before archival. Default: 30 days */
|
|
163
|
+
retention?: number;
|
|
127
164
|
/** Maximum number of running tasks across all workers (`null` = unlimited) */
|
|
128
165
|
globalConcurrency?: number | null;
|
|
129
166
|
/** Number of consecutive failures before tripping the circuit breaker */
|
|
@@ -136,17 +173,35 @@ export type QueueConfig = {
|
|
|
136
173
|
retryDelayMaximum?: number;
|
|
137
174
|
/** Base for exponential backoff (delay = min * (base ^ tries)). Default: 2 */
|
|
138
175
|
retryDelayGrowth?: number;
|
|
176
|
+
/** Milliseconds to retain archived tasks. Default: 30 days */
|
|
177
|
+
archiveRetention?: number;
|
|
178
|
+
/** Age at which a task's priority is promoted (ms). Default: 1 minute */
|
|
179
|
+
priorityAgingInterval?: number;
|
|
180
|
+
/** Amount to decrement priority on each aging interval. Default: 10 */
|
|
181
|
+
priorityAgingStep?: number;
|
|
182
|
+
/** Default duration for timeToLive (ms). Default: 1 day */
|
|
183
|
+
defaultTimeToLive?: number;
|
|
184
|
+
/** Token bucket size for rate limiting. Default: 100 */
|
|
185
|
+
rateLimit?: number;
|
|
186
|
+
/** Token bucket interval ms for rate limiting. Default: 1000 */
|
|
187
|
+
rateInterval?: number;
|
|
188
|
+
/** Time to retain idempotency keys (ms). Default: 1 hour */
|
|
189
|
+
idempotencyWindow?: number;
|
|
139
190
|
};
|
|
140
|
-
export type
|
|
141
|
-
|
|
191
|
+
export type TaskQueueArgument = string | (QueueConfig & {
|
|
192
|
+
namespace: string;
|
|
142
193
|
});
|
|
143
194
|
export declare const defaultQueueConfig: Required<QueueConfig>;
|
|
144
|
-
export declare abstract class
|
|
145
|
-
readonly [resolveArgumentType]:
|
|
146
|
-
|
|
195
|
+
export declare abstract class TaskQueue<Data, State = unknown, Result = unknown> extends Transactional implements Resolvable<TaskQueueArgument> {
|
|
196
|
+
readonly [resolveArgumentType]: TaskQueueArgument;
|
|
197
|
+
protected readonly config: QueueConfig & {
|
|
198
|
+
namespace: string;
|
|
199
|
+
};
|
|
200
|
+
protected readonly logger: Logger;
|
|
201
|
+
abstract readonly visibilityTimeout: number;
|
|
147
202
|
abstract readonly maxTries: number;
|
|
148
|
-
batch():
|
|
149
|
-
abstract enqueue(data: Data, options?: EnqueueOneOptions): Promise<Task<Data, State, Result>>;
|
|
203
|
+
batch(): TaskQueueEnqueueBatch<Data, State, Result>;
|
|
204
|
+
abstract enqueue(type: string, data: Data, options?: EnqueueOneOptions): Promise<Task<Data, State, Result>>;
|
|
150
205
|
abstract enqueueMany(items: EnqueueManyItem<Data>[], options?: EnqueueManyOptions & {
|
|
151
206
|
returnTasks?: false;
|
|
152
207
|
}): Promise<void>;
|
|
@@ -155,27 +210,27 @@ export declare abstract class Queue<Data, State = unknown, Result = unknown> imp
|
|
|
155
210
|
}): Promise<Task<Data, State, Result>[]>;
|
|
156
211
|
abstract enqueueMany(items: EnqueueManyItem<Data>[], options?: EnqueueManyOptions): Promise<Task<Data, State, Result>[] | undefined>;
|
|
157
212
|
abstract has(id: string): Promise<boolean>;
|
|
158
|
-
abstract
|
|
159
|
-
abstract
|
|
160
|
-
abstract
|
|
161
|
-
abstract countByTag(tag: TaskTag): Promise<number>;
|
|
213
|
+
abstract getTask(id: string): Promise<Task<Data, State, Result> | undefined>;
|
|
214
|
+
abstract getManyByTags(tags: OneOrMany<string>): Promise<Task<Data, State, Result>[]>;
|
|
215
|
+
abstract countByTags(tags: OneOrMany<string>): Promise<number>;
|
|
162
216
|
abstract getTree(rootId: string | string[]): Promise<Task<unknown, unknown, unknown>[]>;
|
|
163
217
|
abstract cancel(id: string): Promise<void>;
|
|
164
218
|
abstract cancelMany(ids: string[]): Promise<void>;
|
|
165
|
-
abstract
|
|
166
|
-
abstract cancelManyByTag(tags: TaskTag[]): Promise<void>;
|
|
219
|
+
abstract cancelManyByTags(tags: OneOrMany<string>): Promise<void>;
|
|
167
220
|
/** Clears all tasks from the queue. Use with caution! */
|
|
168
221
|
abstract clear(): Promise<void>;
|
|
169
222
|
abstract dequeue(): Promise<Task<Data, State, Result> | undefined>;
|
|
170
|
-
abstract dequeueMany(count: number
|
|
223
|
+
abstract dequeueMany(count: number, options?: {
|
|
224
|
+
forceDequeue?: boolean;
|
|
225
|
+
types?: string[];
|
|
226
|
+
}): Promise<Task<Data, State, Result>[]>;
|
|
171
227
|
/**
|
|
172
228
|
* Reschedules a task to run at a specific time.
|
|
173
229
|
* NOTE: If the task is currently running, its retry count is decremented (refunded) so this attempt doesn't count against maxTries.
|
|
174
230
|
*/
|
|
175
231
|
abstract reschedule(id: string, timestamp: number, transaction?: Transaction): Promise<void>;
|
|
176
232
|
abstract rescheduleMany(ids: string[], timestamp: number, transaction?: Transaction): Promise<void>;
|
|
177
|
-
abstract
|
|
178
|
-
abstract rescheduleManyByTag(tags: TaskTag[], timestamp: number, transaction?: Transaction): Promise<void>;
|
|
233
|
+
abstract rescheduleManyByTags(tags: OneOrMany<string>, timestamp: number, transaction?: Transaction): Promise<void>;
|
|
179
234
|
/**
|
|
180
235
|
* Updates task progress, state and lock.
|
|
181
236
|
* Returns the updated task if successful, `undefined` if task is lost/cancelled/timed out.
|
|
@@ -190,23 +245,37 @@ export declare abstract class Queue<Data, State = unknown, Result = unknown> imp
|
|
|
190
245
|
* Returns the IDs of the successfully updated tasks.
|
|
191
246
|
*/
|
|
192
247
|
abstract touchMany(tasks: Task[], progresses?: number[], states?: State[], transaction?: Transaction): Promise<string[]>;
|
|
193
|
-
abstract
|
|
194
|
-
abstract
|
|
248
|
+
abstract complete<R>(task: Task<any, any, R>, result?: R, transaction?: Transaction): Promise<void>;
|
|
249
|
+
abstract completeMany<R>(tasks: Task<any, any, R>[], results?: R[], transaction?: Transaction): Promise<void>;
|
|
195
250
|
abstract fail(task: Task, error: any, fatal?: boolean, transaction?: Transaction): Promise<void>;
|
|
196
251
|
abstract failMany(tasks: Task[], error: any, transaction?: Transaction): Promise<void>;
|
|
197
|
-
abstract
|
|
198
|
-
abstract restart(id: string,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
252
|
+
abstract maintenance(): Promise<void>;
|
|
253
|
+
abstract restart(id: string, options?: {
|
|
254
|
+
resetState?: boolean;
|
|
255
|
+
transaction?: Transaction;
|
|
256
|
+
}): Promise<void>;
|
|
257
|
+
abstract getConsumer(cancellationSignal: CancellationSignal, options?: {
|
|
258
|
+
forceDequeue?: boolean;
|
|
259
|
+
types?: string[];
|
|
260
|
+
}): AsyncIterableIterator<Task<Data, State, Result>>;
|
|
261
|
+
abstract getBatchConsumer(size: number, cancellationSignal: CancellationSignal, options?: {
|
|
262
|
+
forceDequeue?: boolean;
|
|
263
|
+
types?: string[];
|
|
264
|
+
}): AsyncIterableIterator<Task<Data, State, Result>[]>;
|
|
265
|
+
process({ concurrency, cancellationSignal, types, forceDequeue }: {
|
|
202
266
|
concurrency?: number;
|
|
203
267
|
cancellationSignal: CancellationSignal;
|
|
204
|
-
|
|
205
|
-
|
|
268
|
+
types?: string[];
|
|
269
|
+
forceDequeue?: boolean;
|
|
270
|
+
}, handler: ProcessWorker<Data, State, Result>): void;
|
|
271
|
+
processBatch({ batchSize, concurrency, cancellationSignal, types, forceDequeue }: {
|
|
206
272
|
batchSize?: number;
|
|
207
273
|
concurrency?: number;
|
|
208
274
|
cancellationSignal: CancellationSignal;
|
|
209
|
-
|
|
275
|
+
types?: string[];
|
|
276
|
+
forceDequeue?: boolean;
|
|
277
|
+
}, handler: ProcessBatchWorker<Data, State, Result>): void;
|
|
210
278
|
private processWorker;
|
|
211
279
|
private processBatchWorker;
|
|
212
280
|
}
|
|
281
|
+
export {};
|