@decaf-ts/core 0.20.0 → 0.21.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/lib/cjs/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/auth/constants.d.ts +5 -0
- package/lib/types/auth/decorators.d.ts +5 -0
- package/lib/types/auth/index.d.ts +2 -0
- package/lib/types/fs/FilesystemAdapter.d.ts +70 -0
- package/lib/types/fs/FsDispatch.d.ts +7 -0
- package/lib/types/fs/helpers.d.ts +17 -0
- package/lib/types/fs/index.d.ts +4 -0
- package/lib/types/fs/indexStore.d.ts +28 -0
- package/lib/types/fs/locks/FilesystemLock.d.ts +13 -0
- package/lib/types/fs/locks/FilesystemMultiLock.d.ts +8 -0
- package/lib/types/fs/types.d.ts +40 -0
- package/lib/types/identity/decorators.d.ts +72 -0
- package/lib/types/identity/index.d.ts +6 -0
- package/lib/types/index.d.cts +1 -1
- package/lib/types/index.d.mts +1 -1
- package/lib/types/index.d.ts +34 -0
- package/lib/types/interfaces/ContextuallyLogged.d.ts +8 -0
- package/lib/types/interfaces/ErrorParser.d.ts +16 -0
- package/lib/types/interfaces/Executor.d.ts +16 -0
- package/lib/types/interfaces/Observable.d.ts +33 -0
- package/lib/types/interfaces/Observer.d.ts +15 -0
- package/lib/types/interfaces/Paginatable.d.ts +20 -0
- package/lib/types/interfaces/Queriable.d.ts +47 -0
- package/lib/types/interfaces/RawExecutor.d.ts +28 -0
- package/lib/types/interfaces/SequenceOptions.d.ts +79 -0
- package/lib/types/interfaces/index.d.ts +12 -0
- package/lib/types/migrations/Migration.d.ts +19 -0
- package/lib/types/migrations/MigrationService.d.ts +63 -0
- package/lib/types/migrations/MigrationTaskBuilder.d.ts +10 -0
- package/lib/types/migrations/MigrationTasks.d.ts +9 -0
- package/lib/types/migrations/MigrationVersioning.d.ts +7 -0
- package/lib/types/migrations/SemverMigrationVersioning.d.ts +10 -0
- package/lib/types/migrations/StandardMigrationVersioning.d.ts +12 -0
- package/lib/types/migrations/constants.d.ts +2 -0
- package/lib/types/migrations/decorators.d.ts +12 -0
- package/lib/types/migrations/index.d.ts +15 -0
- package/lib/types/migrations/types.d.ts +46 -0
- package/lib/types/model/BaseModel.d.ts +37 -0
- package/lib/types/model/SequenceModel.d.ts +32 -0
- package/lib/types/model/construction.d.ts +455 -0
- package/lib/types/model/decorators.d.ts +237 -0
- package/lib/types/model/index.d.ts +11 -0
- package/lib/types/model/indexing.d.ts +20 -0
- package/lib/types/model/types.d.ts +60 -0
- package/lib/types/overrides/Metadata.d.ts +22 -0
- package/lib/types/overrides/Model.d.ts +94 -0
- package/lib/types/overrides/ModelBuilder.d.ts +31 -0
- package/lib/types/overrides/index.d.ts +11 -0
- package/lib/types/overrides/injectables.d.ts +10 -0
- package/lib/types/overrides/overrides.d.ts +1 -0
- package/lib/types/persistence/Adapter.d.ts +469 -0
- package/lib/types/persistence/Context.d.ts +16 -0
- package/lib/types/persistence/ContextLock.d.ts +18 -0
- package/lib/types/persistence/Dispatch.d.ts +128 -0
- package/lib/types/persistence/ObserverHandler.d.ts +111 -0
- package/lib/types/persistence/Sequence.d.ts +126 -0
- package/lib/types/persistence/constants.d.ts +74 -0
- package/lib/types/persistence/decorators.d.ts +28 -0
- package/lib/types/persistence/errors.d.ts +33 -0
- package/lib/types/persistence/event-filters.d.ts +20 -0
- package/lib/types/persistence/generators.d.ts +14 -0
- package/lib/types/persistence/index.d.ts +18 -0
- package/lib/types/persistence/transactions.d.ts +4 -0
- package/lib/types/persistence/types.d.ts +86 -0
- package/lib/types/query/Condition.d.ts +131 -0
- package/lib/types/query/MethodQueryBuilder.d.ts +185 -0
- package/lib/types/query/Paginator.d.ts +105 -0
- package/lib/types/query/Statement.d.ts +136 -0
- package/lib/types/query/constants.d.ts +69 -0
- package/lib/types/query/decorators.d.ts +8 -0
- package/lib/types/query/errors.d.ts +21 -0
- package/lib/types/query/index.d.ts +16 -0
- package/lib/types/query/options.d.ts +393 -0
- package/lib/types/query/selectors.d.ts +39 -0
- package/lib/types/query/types.d.ts +158 -0
- package/lib/types/query/utils.d.ts +40 -0
- package/lib/types/ram/RamAdapter.d.ts +341 -0
- package/lib/types/ram/RamPaginator.d.ts +54 -0
- package/lib/types/ram/RamStatement.d.ts +92 -0
- package/lib/types/ram/constants.d.ts +8 -0
- package/lib/types/ram/handlers.d.ts +24 -0
- package/lib/types/ram/index.d.ts +12 -0
- package/lib/types/ram/types.d.ts +50 -0
- package/lib/types/repository/Repository.d.ts +501 -0
- package/lib/types/repository/constants.d.ts +36 -0
- package/lib/types/repository/decorators.d.ts +30 -0
- package/lib/types/repository/errors.d.ts +19 -0
- package/lib/types/repository/index.d.ts +12 -0
- package/lib/types/repository/injectables.d.ts +95 -0
- package/lib/types/repository/types.d.ts +28 -0
- package/lib/types/repository/utils.d.ts +36 -0
- package/lib/types/services/ModelService.d.ts +45 -0
- package/lib/types/services/PersistenceService.d.ts +17 -0
- package/lib/types/services/index.d.ts +8 -0
- package/lib/types/services/services.d.ts +96 -0
- package/lib/types/tasks/CleanUpTask.d.ts +15 -0
- package/lib/types/tasks/TaskContext.d.ts +30 -0
- package/lib/types/tasks/TaskEngine.d.ts +97 -0
- package/lib/types/tasks/TaskErrors.d.ts +65 -0
- package/lib/types/tasks/TaskEventBus.d.ts +17 -0
- package/lib/types/tasks/TaskEventService.d.ts +7 -0
- package/lib/types/tasks/TaskHandler.d.ts +12 -0
- package/lib/types/tasks/TaskHandlerRegistry.d.ts +8 -0
- package/lib/types/tasks/TaskService.d.ts +65 -0
- package/lib/types/tasks/TaskStateChangeError.d.ts +11 -0
- package/lib/types/tasks/TaskTracker.d.ts +47 -0
- package/lib/types/tasks/builder.d.ts +72 -0
- package/lib/types/tasks/constants.d.ts +31 -0
- package/lib/types/tasks/decorators.d.ts +4 -0
- package/lib/types/tasks/index.d.ts +23 -0
- package/lib/types/tasks/logging.d.ts +31 -0
- package/lib/types/tasks/models/TaskBackoffModel.d.ts +9 -0
- package/lib/types/tasks/models/TaskErrorModel.d.ts +8 -0
- package/lib/types/tasks/models/TaskEventModel.d.ts +11 -0
- package/lib/types/tasks/models/TaskIOSerializer.d.ts +33 -0
- package/lib/types/tasks/models/TaskLogEntryModel.d.ts +10 -0
- package/lib/types/tasks/models/TaskModel.d.ts +43 -0
- package/lib/types/tasks/models/TaskStepResultModel.d.ts +9 -0
- package/lib/types/tasks/models/TaskStepSpecModel.d.ts +9 -0
- package/lib/types/tasks/models/index.d.ts +8 -0
- package/lib/types/tasks/types.d.ts +71 -0
- package/lib/types/tasks/utils.d.ts +5 -0
- package/lib/types/utils/ContextualLoggedClass.d.ts +37 -0
- package/lib/types/utils/decorators.d.ts +27 -0
- package/lib/types/utils/errors.d.ts +56 -0
- package/lib/types/utils/index.d.ts +11 -0
- package/lib/types/utils/throttling.d.ts +9 -0
- package/lib/types/utils/types.d.ts +23 -0
- package/lib/types/utils/utils.d.ts +22 -0
- package/lib/types/workers/TaskEngine.d.ts +40 -0
- package/lib/types/workers/WorkThreadEnvironment.d.ts +35 -0
- package/lib/types/workers/index.d.ts +5 -0
- package/lib/types/workers/messages.d.ts +69 -0
- package/lib/types/workers/types.d.ts +41 -0
- package/lib/types/workers/workerThread.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Exports for the utils module.
|
|
3
|
+
* @summary This file exports all the necessary components for the utils functionality, including the ContextualLoggedClass, decorators, errors, and more.
|
|
4
|
+
* @module core/utils
|
|
5
|
+
*/
|
|
6
|
+
export * from "./ContextualLoggedClass";
|
|
7
|
+
export * from "./decorators";
|
|
8
|
+
export * from "./errors";
|
|
9
|
+
export * from "./utils";
|
|
10
|
+
export * from "./throttling";
|
|
11
|
+
export * from "./types";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type BseThrottlingConfig = {
|
|
2
|
+
delayMs?: number;
|
|
3
|
+
};
|
|
4
|
+
export type ThrottlingConfig = ({
|
|
5
|
+
count: number;
|
|
6
|
+
} | {
|
|
7
|
+
bufferSize: number;
|
|
8
|
+
}) & BseThrottlingConfig;
|
|
9
|
+
export declare function throttle(cfg?: ThrottlingConfig | ((...args: any[]) => ThrottlingConfig), argIndex?: number | number[]): (target: object, propertyKey?: any, descriptor?: any) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type HttpVerbs = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
+
export type DecafApiProperty = {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
type?: any;
|
|
7
|
+
};
|
|
8
|
+
export type DecafModelRoute = {
|
|
9
|
+
path: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
apiProperties: DecafApiProperty[];
|
|
12
|
+
getPK: (...args: Array<string | number>) => string;
|
|
13
|
+
};
|
|
14
|
+
export type DecafParamProps = {
|
|
15
|
+
raw: Record<string, string | number>;
|
|
16
|
+
keysInOrder: Array<string>;
|
|
17
|
+
valuesInOrder: Array<string | number>;
|
|
18
|
+
};
|
|
19
|
+
export interface DecafRouteDecOptions {
|
|
20
|
+
path: string;
|
|
21
|
+
httpMethod: HttpVerbs;
|
|
22
|
+
handler: PropertyDescriptor;
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BlockOperationKind, CrudOperations } from "@decaf-ts/db-decorators";
|
|
2
|
+
import type { ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
export declare function injectableServiceKey(name: string | symbol | Constructor): string;
|
|
5
|
+
export declare function promiseSequence<T>(tasks: (() => Promise<T>)[], continueOnError?: false): Promise<T[]>;
|
|
6
|
+
export declare function promiseSequence<T>(tasks: (() => Promise<T>)[], continueOnError: true): Promise<PromiseSettledResult<T>[]>;
|
|
7
|
+
export declare function isOperationBlocked(ModelConstructor: ModelConstructor<any>, op: CrudOperations): boolean;
|
|
8
|
+
export declare function isOperationBlocked(ModelConstructor: ModelConstructor<any>, kind: BlockOperationKind, value: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* @description Normalizes imports to handle both CommonJS and ESModule formats.
|
|
11
|
+
* @summary Utility function to handle module import differences between formats.
|
|
12
|
+
*
|
|
13
|
+
* @template T - Type of the imported module.
|
|
14
|
+
* @param {Promise<T>} importPromise - Promise returned by dynamic import.
|
|
15
|
+
* @return {Promise<T>} Normalized module.
|
|
16
|
+
*
|
|
17
|
+
* @function normalizeImport
|
|
18
|
+
*
|
|
19
|
+
* @memberOf module:core
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizeImport<T>(importPromise: Promise<T>): Promise<T>;
|
|
22
|
+
export declare function prefixMethod(obj: any, after: (...args: any[]) => any, prefix: (...args: any[]) => any, afterName?: string): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Adapter } from "../persistence/Adapter";
|
|
2
|
+
import { ContextOf } from "../persistence/types";
|
|
3
|
+
import { MaybeContextualArg } from "../utils/ContextualLoggedClass";
|
|
4
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
+
import { TaskModel } from "../tasks/models/TaskModel";
|
|
6
|
+
import { TaskContext, TaskEngine as TE } from "../tasks";
|
|
7
|
+
import { TaskEngineConfig, TaskWorkerThread, WorkerJobState, WorkThreadPoolConfig } from "./types";
|
|
8
|
+
export declare class TaskEngine<A extends Adapter<any, any, any, any>> extends TE<A, TaskEngineConfig<A>> {
|
|
9
|
+
protected workerPoolConfig?: WorkThreadPoolConfig;
|
|
10
|
+
protected workerThreads: TaskWorkerThread[];
|
|
11
|
+
protected workerJobQueue: WorkerJobState[];
|
|
12
|
+
protected workerJobs: Map<string, WorkerJobState>;
|
|
13
|
+
protected workerCounter: number;
|
|
14
|
+
protected workerThreadCapacity: number;
|
|
15
|
+
protected get Context(): Constructor<ContextOf<A>>;
|
|
16
|
+
constructor(config: TaskEngineConfig<A>);
|
|
17
|
+
private normalizeWorkerPoolConfig;
|
|
18
|
+
private hasWorkerPool;
|
|
19
|
+
private getWorkerCount;
|
|
20
|
+
private getWorkerExecutionSlots;
|
|
21
|
+
private canDispatchToWorkers;
|
|
22
|
+
private getExecutionConcurrency;
|
|
23
|
+
private computeWorkerModules;
|
|
24
|
+
start(...args: MaybeContextualArg<any>): Promise<void>;
|
|
25
|
+
stop(...args: MaybeContextualArg<any>): Promise<void>;
|
|
26
|
+
protected spawnWorkers(): Promise<void>;
|
|
27
|
+
protected createWorker(): Promise<void> | undefined;
|
|
28
|
+
private shutdownWorkers;
|
|
29
|
+
private handleWorkerError;
|
|
30
|
+
private handleWorkerExit;
|
|
31
|
+
private handleWorkerMessage;
|
|
32
|
+
private applyWorkerCache;
|
|
33
|
+
private processWorkerQueue;
|
|
34
|
+
private assignWorker;
|
|
35
|
+
private enqueueWorkerJob;
|
|
36
|
+
protected runHandlerInline(classification: string, input: any, ctx: TaskContext): Promise<any>;
|
|
37
|
+
private dispatchToWorker;
|
|
38
|
+
private invokeHandler;
|
|
39
|
+
protected executeClaimed(task: TaskModel): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TaskEngineAutoShutdownConfig } from "../tasks/types";
|
|
2
|
+
type WorkerMode = "node" | "browser";
|
|
3
|
+
export interface WorkThreadPersistenceConfig {
|
|
4
|
+
adapterModule: string;
|
|
5
|
+
adapterClass?: string;
|
|
6
|
+
adapterArgs?: any[];
|
|
7
|
+
flavour?: string;
|
|
8
|
+
alias?: string;
|
|
9
|
+
modules?: WorkThreadModulesConfig;
|
|
10
|
+
}
|
|
11
|
+
export interface WorkThreadTaskEngineConfig {
|
|
12
|
+
concurrency: number;
|
|
13
|
+
leaseMs: number;
|
|
14
|
+
pollMsIdle: number;
|
|
15
|
+
pollMsBusy: number;
|
|
16
|
+
logTailMax: number;
|
|
17
|
+
streamBufferSize: number;
|
|
18
|
+
maxLoggingBuffer: number;
|
|
19
|
+
loggingBufferTruncation: number;
|
|
20
|
+
gracefulShutdownMsTimeout: number;
|
|
21
|
+
autoShutdown?: TaskEngineAutoShutdownConfig;
|
|
22
|
+
}
|
|
23
|
+
export interface WorkThreadModulesConfig {
|
|
24
|
+
imports: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface WorkThreadEnvironmentShape {
|
|
27
|
+
workerId: string;
|
|
28
|
+
mode: WorkerMode;
|
|
29
|
+
persistence: WorkThreadPersistenceConfig;
|
|
30
|
+
taskEngine: WorkThreadTaskEngineConfig;
|
|
31
|
+
modules: WorkThreadModulesConfig;
|
|
32
|
+
}
|
|
33
|
+
export declare const DefaultWorkThreadEnvironment: WorkThreadEnvironmentShape;
|
|
34
|
+
export declare const WorkThreadEnvironment: any;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { LogLevel } from "@decaf-ts/logging";
|
|
2
|
+
import { TaskStateChangeRequest } from "../tasks/TaskStateChangeError";
|
|
3
|
+
export type WorkerLogEntry = [LogLevel, string] | [LogLevel, string, any];
|
|
4
|
+
export interface WorkerJobPayload {
|
|
5
|
+
jobId: string;
|
|
6
|
+
taskId: string;
|
|
7
|
+
classification: string;
|
|
8
|
+
input: any;
|
|
9
|
+
attempt: number;
|
|
10
|
+
resultCache?: Record<string, any>;
|
|
11
|
+
streamBufferSize: number;
|
|
12
|
+
maxLoggingBuffer: number;
|
|
13
|
+
loggingBufferTruncation: number;
|
|
14
|
+
}
|
|
15
|
+
export type WorkerToMainMessage = {
|
|
16
|
+
type: "ready";
|
|
17
|
+
workerId: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "log";
|
|
20
|
+
workerId: string;
|
|
21
|
+
jobId: string;
|
|
22
|
+
entries: WorkerLogEntry[];
|
|
23
|
+
} | {
|
|
24
|
+
type: "progress";
|
|
25
|
+
workerId: string;
|
|
26
|
+
jobId: string;
|
|
27
|
+
payload: any;
|
|
28
|
+
} | {
|
|
29
|
+
type: "heartbeat";
|
|
30
|
+
workerId: string;
|
|
31
|
+
jobId: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "result";
|
|
34
|
+
workerId: string;
|
|
35
|
+
jobId: string;
|
|
36
|
+
status: "success";
|
|
37
|
+
output: any;
|
|
38
|
+
cache?: Record<string, any>;
|
|
39
|
+
} | {
|
|
40
|
+
type: "result";
|
|
41
|
+
workerId: string;
|
|
42
|
+
jobId: string;
|
|
43
|
+
status: "error";
|
|
44
|
+
error: {
|
|
45
|
+
name?: string;
|
|
46
|
+
message: string;
|
|
47
|
+
stack?: string;
|
|
48
|
+
};
|
|
49
|
+
cache?: Record<string, any>;
|
|
50
|
+
} | {
|
|
51
|
+
type: "result";
|
|
52
|
+
workerId: string;
|
|
53
|
+
jobId: string;
|
|
54
|
+
status: "state-change";
|
|
55
|
+
request: TaskStateChangeRequest;
|
|
56
|
+
cache?: Record<string, any>;
|
|
57
|
+
} | {
|
|
58
|
+
type: "error";
|
|
59
|
+
workerId: string;
|
|
60
|
+
error: string;
|
|
61
|
+
stack?: string;
|
|
62
|
+
};
|
|
63
|
+
export type MainToWorkerMessage = {
|
|
64
|
+
type: "control";
|
|
65
|
+
command: "stop" | "shutdown";
|
|
66
|
+
} | {
|
|
67
|
+
type: "execute";
|
|
68
|
+
job: WorkerJobPayload;
|
|
69
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Worker } from "worker_threads";
|
|
2
|
+
import { TaskContext, TaskModel, TaskEngineConfig as TEC, TaskServiceConfig as TSC } from "../tasks/index";
|
|
3
|
+
export type TaskWorkerThread = {
|
|
4
|
+
id: string;
|
|
5
|
+
worker: Worker;
|
|
6
|
+
ready: boolean;
|
|
7
|
+
activeJobs: number;
|
|
8
|
+
capacity: number;
|
|
9
|
+
readyPromise?: Promise<void>;
|
|
10
|
+
resolveReady?: () => void;
|
|
11
|
+
rejectReady?: (error: Error) => void;
|
|
12
|
+
};
|
|
13
|
+
export type WorkerJobState = {
|
|
14
|
+
id: string;
|
|
15
|
+
classification: string;
|
|
16
|
+
input: any;
|
|
17
|
+
task: TaskModel;
|
|
18
|
+
ctx: TaskContext;
|
|
19
|
+
resolve: (value: any) => void;
|
|
20
|
+
reject: (error: any) => void;
|
|
21
|
+
worker?: TaskWorkerThread;
|
|
22
|
+
};
|
|
23
|
+
import { WorkThreadModulesConfig, WorkThreadPersistenceConfig } from "./WorkThreadEnvironment";
|
|
24
|
+
import { Adapter } from "../persistence/index";
|
|
25
|
+
export type WorkerAdapterDescriptor = WorkThreadPersistenceConfig;
|
|
26
|
+
export type WorkThreadPoolConfig = {
|
|
27
|
+
size?: number;
|
|
28
|
+
mode?: "node" | "browser";
|
|
29
|
+
entry: string;
|
|
30
|
+
modules?: WorkThreadModulesConfig;
|
|
31
|
+
};
|
|
32
|
+
export type TaskEngineConfig<A extends Adapter<any, any, any, any>> = TEC<A> & {
|
|
33
|
+
workerAdapter?: WorkerAdapterDescriptor;
|
|
34
|
+
workerPool?: WorkThreadPoolConfig;
|
|
35
|
+
workerConcurrency?: number;
|
|
36
|
+
};
|
|
37
|
+
export type TaskServiceConfig<A extends Adapter<any, any, any, any>> = TSC<A> & {
|
|
38
|
+
workerAdapter?: WorkerAdapterDescriptor;
|
|
39
|
+
workerPool?: WorkThreadPoolConfig;
|
|
40
|
+
workerConcurrency?: number;
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../overrides";
|