nmtjs 0.15.0-beta.2 → 0.15.0-beta.21
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/dist/cli.d.ts +2 -0
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -0
- package/dist/entrypoints/cli.d.ts +1 -0
- package/dist/entrypoints/cli.js +1 -0
- package/dist/entrypoints/cli.js.map +1 -0
- package/dist/entrypoints/main.d.ts +5 -0
- package/dist/entrypoints/main.js +83 -15
- package/dist/entrypoints/main.js.map +1 -0
- package/dist/entrypoints/thread.d.ts +14 -0
- package/dist/entrypoints/thread.js +130 -24
- package/dist/entrypoints/thread.js.map +1 -0
- package/dist/entrypoints/worker.d.ts +3 -0
- package/dist/entrypoints/worker.js +4 -3
- package/dist/entrypoints/worker.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/{_exports/index.js → index.js} +9 -5
- package/dist/index.js.map +1 -0
- package/dist/resolver.d.ts +2 -0
- package/dist/resolver.js +1 -0
- package/dist/resolver.js.map +1 -0
- package/dist/runtime/application/api/api.d.ts +49 -0
- package/dist/runtime/application/api/api.js +193 -0
- package/dist/runtime/application/api/api.js.map +1 -0
- package/dist/runtime/application/api/constants.d.ts +14 -0
- package/dist/runtime/application/api/constants.js +8 -0
- package/dist/runtime/application/api/constants.js.map +1 -0
- package/dist/runtime/application/api/filters.d.ts +14 -0
- package/dist/runtime/application/api/filters.js +11 -0
- package/dist/runtime/application/api/filters.js.map +1 -0
- package/dist/runtime/application/api/guards.d.ts +13 -0
- package/dist/runtime/application/api/guards.js +8 -0
- package/dist/runtime/application/api/guards.js.map +1 -0
- package/dist/runtime/application/api/index.d.ts +8 -0
- package/dist/runtime/application/api/index.js +9 -0
- package/dist/runtime/application/api/index.js.map +1 -0
- package/dist/runtime/application/api/middlewares.d.ts +14 -0
- package/dist/runtime/application/api/middlewares.js +12 -0
- package/dist/runtime/application/api/middlewares.js.map +1 -0
- package/dist/runtime/application/api/procedure.d.ts +67 -0
- package/dist/runtime/application/api/procedure.js +50 -0
- package/dist/runtime/application/api/procedure.js.map +1 -0
- package/dist/runtime/application/api/router.d.ts +71 -0
- package/dist/runtime/application/api/router.js +51 -0
- package/dist/runtime/application/api/router.js.map +1 -0
- package/dist/runtime/application/api/types.d.ts +32 -0
- package/dist/runtime/application/api/types.js +2 -0
- package/dist/runtime/application/api/types.js.map +1 -0
- package/dist/runtime/application/config.d.ts +26 -0
- package/dist/runtime/application/config.js +21 -0
- package/dist/runtime/application/config.js.map +1 -0
- package/dist/runtime/application/constants.d.ts +2 -0
- package/dist/runtime/application/constants.js +2 -0
- package/dist/runtime/application/constants.js.map +1 -0
- package/dist/runtime/application/hook.d.ts +19 -0
- package/dist/runtime/application/hook.js +11 -0
- package/dist/runtime/application/hook.js.map +1 -0
- package/dist/runtime/application/hooks.d.ts +3 -0
- package/dist/runtime/application/hooks.js +4 -0
- package/dist/runtime/application/hooks.js.map +1 -0
- package/dist/runtime/application/index.d.ts +5 -0
- package/dist/runtime/application/index.js +6 -0
- package/dist/runtime/application/index.js.map +1 -0
- package/dist/runtime/constants.d.ts +8 -0
- package/dist/runtime/constants.js +5 -0
- package/dist/runtime/constants.js.map +1 -0
- package/dist/runtime/core/hooks.d.ts +4 -0
- package/dist/runtime/core/hooks.js +4 -0
- package/dist/runtime/core/hooks.js.map +1 -0
- package/dist/runtime/core/plugin.d.ts +8 -0
- package/dist/runtime/core/plugin.js +4 -0
- package/dist/runtime/core/plugin.js.map +1 -0
- package/dist/runtime/core/runtime.d.ts +27 -0
- package/dist/runtime/core/runtime.js +81 -0
- package/dist/runtime/core/runtime.js.map +1 -0
- package/dist/runtime/enums.d.ts +21 -0
- package/dist/runtime/enums.js +26 -0
- package/dist/runtime/enums.js.map +1 -0
- package/dist/runtime/index.d.ts +21 -0
- package/dist/runtime/index.js +22 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/injectables.d.ts +23 -0
- package/dist/runtime/injectables.js +20 -0
- package/dist/runtime/injectables.js.map +1 -0
- package/dist/runtime/jobs/job.d.ts +132 -0
- package/dist/runtime/jobs/job.js +68 -0
- package/dist/runtime/jobs/job.js.map +1 -0
- package/dist/runtime/jobs/manager.d.ts +113 -0
- package/dist/runtime/jobs/manager.js +210 -0
- package/dist/runtime/jobs/manager.js.map +1 -0
- package/dist/runtime/jobs/router.d.ts +266 -0
- package/dist/runtime/jobs/router.js +432 -0
- package/dist/runtime/jobs/router.js.map +1 -0
- package/dist/runtime/jobs/runner.d.ts +64 -0
- package/dist/runtime/jobs/runner.js +256 -0
- package/dist/runtime/jobs/runner.js.map +1 -0
- package/dist/runtime/jobs/step.d.ts +23 -0
- package/dist/runtime/jobs/step.js +18 -0
- package/dist/runtime/jobs/step.js.map +1 -0
- package/dist/runtime/jobs/ui.d.ts +3 -0
- package/dist/runtime/jobs/ui.js +17 -0
- package/dist/runtime/jobs/ui.js.map +1 -0
- package/dist/runtime/pubsub/manager.d.ts +48 -0
- package/dist/runtime/pubsub/manager.js +119 -0
- package/dist/runtime/pubsub/manager.js.map +1 -0
- package/dist/runtime/pubsub/redis.d.ts +16 -0
- package/dist/runtime/pubsub/redis.js +98 -0
- package/dist/runtime/pubsub/redis.js.map +1 -0
- package/dist/runtime/scheduler/index.d.ts +22 -0
- package/dist/runtime/scheduler/index.js +20 -0
- package/dist/runtime/scheduler/index.js.map +1 -0
- package/dist/runtime/server/applications.d.ts +52 -0
- package/dist/runtime/server/applications.js +133 -0
- package/dist/runtime/server/applications.js.map +1 -0
- package/dist/runtime/server/config.d.ts +121 -0
- package/dist/runtime/server/config.js +33 -0
- package/dist/runtime/server/config.js.map +1 -0
- package/dist/runtime/server/jobs.d.ts +41 -0
- package/dist/runtime/server/jobs.js +181 -0
- package/dist/runtime/server/jobs.js.map +1 -0
- package/dist/runtime/server/pool.d.ts +54 -0
- package/dist/runtime/server/pool.js +194 -0
- package/dist/runtime/server/pool.js.map +1 -0
- package/dist/runtime/server/proxy.d.ts +21 -0
- package/dist/runtime/server/proxy.js +79 -0
- package/dist/runtime/server/proxy.js.map +1 -0
- package/dist/runtime/server/server.d.ts +53 -0
- package/dist/runtime/server/server.js +90 -0
- package/dist/runtime/server/server.js.map +1 -0
- package/dist/runtime/store/index.d.ts +3 -0
- package/dist/runtime/store/index.js +23 -0
- package/dist/runtime/store/index.js.map +1 -0
- package/dist/runtime/types.d.ts +103 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/workers/application.d.ts +47 -0
- package/dist/runtime/workers/application.js +162 -0
- package/dist/runtime/workers/application.js.map +1 -0
- package/dist/runtime/workers/base.d.ts +16 -0
- package/dist/runtime/workers/base.js +46 -0
- package/dist/runtime/workers/base.js.map +1 -0
- package/dist/runtime/workers/cli.d.ts +1 -0
- package/dist/runtime/workers/cli.js +2 -0
- package/dist/runtime/workers/cli.js.map +1 -0
- package/dist/runtime/workers/job.d.ts +20 -0
- package/dist/runtime/workers/job.js +172 -0
- package/dist/runtime/workers/job.js.map +1 -0
- package/dist/typings.d.ts +5 -0
- package/dist/typings.js +4 -3
- package/dist/typings.js.map +1 -0
- package/dist/vite/builder.d.ts +5 -0
- package/dist/vite/builder.js +5 -1
- package/dist/vite/builder.js.map +1 -0
- package/dist/vite/config.d.ts +28 -0
- package/dist/vite/config.js +1 -0
- package/dist/vite/config.js.map +1 -0
- package/dist/vite/plugins.d.ts +2 -0
- package/dist/vite/plugins.js +1 -0
- package/dist/vite/plugins.js.map +1 -0
- package/dist/vite/runners/worker.d.ts +4 -0
- package/dist/vite/runners/worker.js +1 -0
- package/dist/vite/runners/worker.js.map +1 -0
- package/dist/vite/server.d.ts +3 -0
- package/dist/vite/server.js +6 -1
- package/dist/vite/server.js.map +1 -0
- package/dist/vite/servers/main.d.ts +8 -0
- package/dist/vite/servers/main.js +1 -0
- package/dist/vite/servers/main.js.map +1 -0
- package/dist/vite/servers/worker.d.ts +11 -0
- package/dist/vite/servers/worker.js +28 -0
- package/dist/vite/servers/worker.js.map +1 -0
- package/package.json +31 -18
- package/src/cli.ts +144 -0
- package/src/config.ts +64 -0
- package/src/entrypoints/cli.ts +13 -0
- package/src/entrypoints/main.ts +200 -0
- package/src/entrypoints/thread.ts +184 -0
- package/src/entrypoints/worker.ts +48 -0
- package/src/index.ts +82 -0
- package/src/resolver.ts +16 -0
- package/src/runtime/application/api/api.ts +265 -0
- package/src/runtime/application/api/constants.ts +22 -0
- package/src/runtime/application/api/filters.ts +39 -0
- package/src/runtime/application/api/guards.ts +29 -0
- package/src/runtime/application/api/index.ts +8 -0
- package/src/runtime/application/api/middlewares.ts +37 -0
- package/src/runtime/application/api/procedure.ts +229 -0
- package/src/runtime/application/api/router.ts +193 -0
- package/src/runtime/application/api/types.ts +124 -0
- package/src/runtime/application/config.ts +69 -0
- package/src/runtime/application/constants.ts +4 -0
- package/src/runtime/application/hook.ts +51 -0
- package/src/runtime/application/hooks.ts +3 -0
- package/src/runtime/application/index.ts +5 -0
- package/src/runtime/constants.ts +13 -0
- package/src/runtime/core/hooks.ts +5 -0
- package/src/runtime/core/plugin.ts +13 -0
- package/src/runtime/core/runtime.ts +109 -0
- package/src/runtime/enums.ts +24 -0
- package/src/runtime/index.ts +21 -0
- package/src/runtime/injectables.ts +61 -0
- package/src/runtime/jobs/job.ts +370 -0
- package/src/runtime/jobs/manager.ts +348 -0
- package/src/runtime/jobs/router.ts +896 -0
- package/src/runtime/jobs/runner.ts +320 -0
- package/src/runtime/jobs/step.ts +66 -0
- package/src/runtime/jobs/ui.ts +21 -0
- package/src/runtime/pubsub/manager.ts +211 -0
- package/src/runtime/pubsub/redis.ts +108 -0
- package/src/runtime/scheduler/index.ts +39 -0
- package/src/runtime/server/applications.ts +210 -0
- package/src/runtime/server/config.ts +158 -0
- package/src/runtime/server/jobs.ts +250 -0
- package/src/runtime/server/pool.ts +260 -0
- package/src/runtime/server/proxy.ts +118 -0
- package/src/runtime/server/server.ts +155 -0
- package/src/runtime/store/index.ts +30 -0
- package/src/runtime/types.ts +93 -0
- package/src/runtime/workers/application.ts +209 -0
- package/src/runtime/workers/base.ts +68 -0
- package/src/runtime/workers/cli.ts +0 -0
- package/src/runtime/workers/job.ts +153 -0
- package/src/typings.ts +30 -0
- package/src/vite/builder.ts +122 -0
- package/src/vite/config.ts +45 -0
- package/src/vite/plugins.ts +26 -0
- package/src/vite/runners/worker.ts +57 -0
- package/src/vite/server.ts +39 -0
- package/src/vite/servers/main.ts +34 -0
- package/src/vite/servers/worker.ts +143 -0
- package/dist/_exports/application.js +0 -1
- package/dist/_exports/common.js +0 -1
- package/dist/_exports/contract.js +0 -2
- package/dist/_exports/core.js +0 -1
- package/dist/_exports/gateway.js +0 -1
- package/dist/_exports/http-transport/bun.js +0 -1
- package/dist/_exports/http-transport/deno.js +0 -1
- package/dist/_exports/http-transport/node.js +0 -1
- package/dist/_exports/http-transport.js +0 -1
- package/dist/_exports/json-format.js +0 -1
- package/dist/_exports/protocol/client.js +0 -1
- package/dist/_exports/protocol/server.js +0 -1
- package/dist/_exports/protocol.js +0 -1
- package/dist/_exports/runtime/types.js +0 -1
- package/dist/_exports/runtime.js +0 -1
- package/dist/_exports/type.js +0 -2
- package/dist/_exports/ws-transport/bun.js +0 -1
- package/dist/_exports/ws-transport/deno.js +0 -1
- package/dist/_exports/ws-transport/node.js +0 -1
- package/dist/_exports/ws-transport.js +0 -1
- package/dist/command.js +0 -30
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { MaybePromise, TSError } from '@nmtjs/common';
|
|
2
|
+
import type { Dependencies, DependencyContext } from '@nmtjs/core';
|
|
3
|
+
import type { t } from '@nmtjs/type';
|
|
4
|
+
import type { AnyObjectLikeType, ObjectType } from '@nmtjs/type/object';
|
|
5
|
+
import type { JobWorkerPool } from '../enums.ts';
|
|
6
|
+
import type { AnyJobStep, JobStep } from './step.ts';
|
|
7
|
+
import { kJobKey } from '../constants.ts';
|
|
8
|
+
type DefaultObjectType = ObjectType<{}>;
|
|
9
|
+
type DefaultResultType = Record<string, any>;
|
|
10
|
+
export type AnyJobOptions = JobOptions<string, any, any, any, any, any>;
|
|
11
|
+
export interface AnyJob {
|
|
12
|
+
_: {
|
|
13
|
+
data: any;
|
|
14
|
+
result: any;
|
|
15
|
+
input: any;
|
|
16
|
+
output: any;
|
|
17
|
+
progress: any;
|
|
18
|
+
};
|
|
19
|
+
[kJobKey]: true;
|
|
20
|
+
options: AnyJobOptions;
|
|
21
|
+
steps: readonly AnyJobStep[];
|
|
22
|
+
conditions: Map<number, JobCondition<any, any, any, any>>;
|
|
23
|
+
name: string;
|
|
24
|
+
dependencies: Dependencies;
|
|
25
|
+
input: AnyObjectLikeType;
|
|
26
|
+
output: AnyObjectLikeType;
|
|
27
|
+
progress: AnyObjectLikeType;
|
|
28
|
+
afterEachHandler?: JobAfterEachHandler<any, any, any, any, any>;
|
|
29
|
+
beforeEachHandler?: JobBeforeEachHandler<any, any, any, any, any>;
|
|
30
|
+
onErrorHandler?: JobOnErrorHandler<any, any, any, any, any>;
|
|
31
|
+
returnHandler?: JobReturnHandler<any, any, any, any, any, any>;
|
|
32
|
+
}
|
|
33
|
+
export type JobBackoffOptions = {
|
|
34
|
+
type: 'fixed' | 'exponential';
|
|
35
|
+
delay: number;
|
|
36
|
+
jitter?: number;
|
|
37
|
+
};
|
|
38
|
+
export type JobCondition<Deps extends Dependencies = {}, Result extends DefaultResultType = {}, Data = any, Input extends AnyObjectLikeType = AnyObjectLikeType, Progress extends AnyObjectLikeType = AnyObjectLikeType> = (params: {
|
|
39
|
+
context: DependencyContext<Deps>;
|
|
40
|
+
data: Data;
|
|
41
|
+
input: t.infer.decode.output<Input>;
|
|
42
|
+
result: Result;
|
|
43
|
+
progress: t.infer.decode.output<Progress>;
|
|
44
|
+
}) => MaybePromise<boolean>;
|
|
45
|
+
export type JobReturnHandler<Deps extends Dependencies, Result extends DefaultResultType, Input extends AnyObjectLikeType, Output extends AnyObjectLikeType, Data, Progress extends AnyObjectLikeType = AnyObjectLikeType> = (params: {
|
|
46
|
+
context: DependencyContext<Deps>;
|
|
47
|
+
data: Data;
|
|
48
|
+
input: t.infer.decode.output<Input>;
|
|
49
|
+
result: Result;
|
|
50
|
+
progress: t.infer.decode.output<Progress>;
|
|
51
|
+
}) => MaybePromise<t.infer.encode.input<Output>>;
|
|
52
|
+
export type JobDataHandler<Deps extends Dependencies, Input extends AnyObjectLikeType, Data, Progress extends AnyObjectLikeType = AnyObjectLikeType> = (ctx: DependencyContext<Deps>, input: t.infer.decode.output<Input>, progress: t.infer.decode.output<Progress>) => MaybePromise<Data>;
|
|
53
|
+
export type JobAfterEachHandler<Deps extends Dependencies, Result extends DefaultResultType, Input extends AnyObjectLikeType, Data, Progress extends AnyObjectLikeType = AnyObjectLikeType> = (params: {
|
|
54
|
+
context: DependencyContext<Deps>;
|
|
55
|
+
data: Data;
|
|
56
|
+
input: t.infer.decode.output<Input>;
|
|
57
|
+
result: Result;
|
|
58
|
+
progress: t.infer.decode.output<Progress>;
|
|
59
|
+
step: AnyJobStep;
|
|
60
|
+
stepIndex: number;
|
|
61
|
+
}) => MaybePromise<void>;
|
|
62
|
+
export type JobBeforeEachHandler<Deps extends Dependencies, Result extends DefaultResultType, Input extends AnyObjectLikeType, Data, Progress extends AnyObjectLikeType = AnyObjectLikeType> = (params: {
|
|
63
|
+
context: DependencyContext<Deps>;
|
|
64
|
+
data: Data;
|
|
65
|
+
input: t.infer.decode.output<Input>;
|
|
66
|
+
result: Result;
|
|
67
|
+
progress: t.infer.decode.output<Progress>;
|
|
68
|
+
step: AnyJobStep;
|
|
69
|
+
stepIndex: number;
|
|
70
|
+
}) => MaybePromise<void>;
|
|
71
|
+
export type JobOnErrorHandler<Deps extends Dependencies, Result extends DefaultResultType, Input extends AnyObjectLikeType, Data, Progress extends AnyObjectLikeType = AnyObjectLikeType> = (params: {
|
|
72
|
+
context: DependencyContext<Deps>;
|
|
73
|
+
data: Data;
|
|
74
|
+
input: t.infer.decode.output<Input>;
|
|
75
|
+
result: Result;
|
|
76
|
+
progress: t.infer.decode.output<Progress>;
|
|
77
|
+
step: AnyJobStep;
|
|
78
|
+
stepIndex: number;
|
|
79
|
+
error: unknown;
|
|
80
|
+
}) => MaybePromise<boolean | void>;
|
|
81
|
+
export interface JobOptions<Name extends string = string, Input extends AnyObjectLikeType = AnyObjectLikeType, Output extends AnyObjectLikeType = AnyObjectLikeType, Progress extends AnyObjectLikeType = DefaultObjectType, Deps extends Dependencies = {}, Data = any> {
|
|
82
|
+
name: Name;
|
|
83
|
+
pool: JobWorkerPool;
|
|
84
|
+
input: Input;
|
|
85
|
+
output: Output;
|
|
86
|
+
progress?: Progress;
|
|
87
|
+
concurrency?: number;
|
|
88
|
+
timeout?: number;
|
|
89
|
+
dependencies?: Deps;
|
|
90
|
+
data?: JobDataHandler<Deps, Input, Data, Progress>;
|
|
91
|
+
attempts?: number;
|
|
92
|
+
backoff?: JobBackoffOptions;
|
|
93
|
+
oneoff?: boolean;
|
|
94
|
+
}
|
|
95
|
+
export declare class Job<in out Name extends string = string, in out Deps extends Dependencies = {}, in out Data = any, in out Input extends AnyObjectLikeType = DefaultObjectType, in out Output extends AnyObjectLikeType = DefaultObjectType, in out Progress extends AnyObjectLikeType = DefaultObjectType, out Steps extends [...AnyJobStep[]] = [], in out Result extends DefaultResultType = {}, out Return extends boolean = false> implements AnyJob {
|
|
96
|
+
options: JobOptions<Name, Input, Output, Progress, Deps, Data>;
|
|
97
|
+
stack?: string | undefined;
|
|
98
|
+
_: {
|
|
99
|
+
data: Data;
|
|
100
|
+
result: Result & t.infer.decode.output<Input>;
|
|
101
|
+
input: t.infer.decode.output<Input>;
|
|
102
|
+
output: t.infer.decode.output<Output>;
|
|
103
|
+
progress: t.infer.decode.output<Progress>;
|
|
104
|
+
};
|
|
105
|
+
[kJobKey]: true;
|
|
106
|
+
steps: Steps;
|
|
107
|
+
conditions: Map<number, JobCondition<any, any, any, any, any>>;
|
|
108
|
+
returnHandler?: JobReturnHandler<Deps, this['_']['result'], Input, Output, Data, Progress>;
|
|
109
|
+
afterEachHandler?: JobAfterEachHandler<Deps, this['_']['result'], Input, Data, Progress>;
|
|
110
|
+
beforeEachHandler?: JobBeforeEachHandler<Deps, this['_']['result'], Input, Data, Progress>;
|
|
111
|
+
onErrorHandler?: JobOnErrorHandler<Deps, this['_']['result'], Input, Data, Progress>;
|
|
112
|
+
constructor(options: JobOptions<Name, Input, Output, Progress, Deps, Data>, stack?: string | undefined);
|
|
113
|
+
get name(): Name;
|
|
114
|
+
get dependencies(): Deps;
|
|
115
|
+
get input(): Input;
|
|
116
|
+
get output(): Output;
|
|
117
|
+
get progress(): Progress;
|
|
118
|
+
step<StepInput extends AnyObjectLikeType, StepOutput extends AnyObjectLikeType, StepDeps extends Dependencies, StepResult, Condition extends JobCondition<Deps, Result, this['_']['data'], Input> | undefined>(...[step, condition]: Return extends false ? [
|
|
119
|
+
step: JobStep<StepInput, StepOutput, StepDeps, this['_']['result'] extends t.infer.decode.output<StepInput> ? t.infer.decode.output<StepOutput> : TSError<'Accumulated job result does not satisfy current step input:', this['_']['result']>, this['_']['data']>,
|
|
120
|
+
condition?: Condition
|
|
121
|
+
] : [TSError<'Job has already has return statement'>]): Job<Name, Deps, Data, Input, Output, Progress, [...Steps, JobStep<StepInput, StepOutput, StepDeps, StepResult, any>], Result & (undefined extends Condition ? t.infer.decode.output<StepOutput extends undefined ? DefaultObjectType : StepOutput> : Partial<t.infer.decode.output<StepOutput extends undefined ? DefaultObjectType : StepOutput>>)>;
|
|
122
|
+
return(...[handler]: Return extends false ? Result extends t.infer.encode.input<Output> ? [
|
|
123
|
+
JobReturnHandler<Deps, this['_']['result'], Input, Output, Data, Progress>?
|
|
124
|
+
] : [
|
|
125
|
+
JobReturnHandler<Deps, this['_']['result'], Input, Output, Data, Progress>
|
|
126
|
+
] : [TSError<'Job already has a return statement'>]): Job<Name, Deps, Data, Input, Output, Progress, Steps, Result, true>;
|
|
127
|
+
afterEach(handler: Return extends true ? JobAfterEachHandler<Deps, this['_']['result'], Input, Data, Progress> : TSError<'Job must have a return statement to use afterEach'>): this;
|
|
128
|
+
beforeEach(handler: Return extends true ? JobBeforeEachHandler<Deps, this['_']['result'], Input, Data, Progress> : TSError<'Job must have a return statement to use beforeEach'>): this;
|
|
129
|
+
onError(handler: Return extends true ? JobOnErrorHandler<Deps, this['_']['result'], Input, Data, Progress> : TSError<'Job must have a return statement to use onError'>): this;
|
|
130
|
+
}
|
|
131
|
+
export declare function createJob<Name extends string, Input extends AnyObjectLikeType, Output extends AnyObjectLikeType, Deps extends Dependencies = {}, Data = any, Progress extends AnyObjectLikeType = DefaultObjectType>(options: JobOptions<Name, Input, Output, Progress, Deps, Data>): Job<Name, Deps, Data, Input, Output, Progress, [], {}, false>;
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { tryCaptureStackTrace } from '@nmtjs/common';
|
|
2
|
+
import { kJobKey } from "../constants.js";
|
|
3
|
+
import { isJobStep } from "./step.js";
|
|
4
|
+
export class Job {
|
|
5
|
+
options;
|
|
6
|
+
stack;
|
|
7
|
+
_;
|
|
8
|
+
[kJobKey] = true;
|
|
9
|
+
steps = [];
|
|
10
|
+
conditions = new Map();
|
|
11
|
+
returnHandler;
|
|
12
|
+
afterEachHandler;
|
|
13
|
+
beforeEachHandler;
|
|
14
|
+
onErrorHandler;
|
|
15
|
+
constructor(options, stack) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.stack = stack;
|
|
18
|
+
}
|
|
19
|
+
get name() {
|
|
20
|
+
return this.options.name;
|
|
21
|
+
}
|
|
22
|
+
get dependencies() {
|
|
23
|
+
return this.options.dependencies ?? {};
|
|
24
|
+
}
|
|
25
|
+
get input() {
|
|
26
|
+
return this.options.input;
|
|
27
|
+
}
|
|
28
|
+
get output() {
|
|
29
|
+
return this.options.output;
|
|
30
|
+
}
|
|
31
|
+
get progress() {
|
|
32
|
+
return this.options.progress;
|
|
33
|
+
}
|
|
34
|
+
step(...[step, condition]) {
|
|
35
|
+
if (!isJobStep(step))
|
|
36
|
+
throw new Error('Invalid job step object');
|
|
37
|
+
const length = this.steps.push(step);
|
|
38
|
+
if (condition)
|
|
39
|
+
this.conditions.set(length - 1, condition);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
return(...[handler]) {
|
|
43
|
+
if (typeof handler === 'function') {
|
|
44
|
+
this.returnHandler = handler;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.returnHandler = (result) => result;
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
afterEach(handler) {
|
|
52
|
+
this.afterEachHandler = handler;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
beforeEach(handler) {
|
|
56
|
+
this.beforeEachHandler = handler;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
onError(handler) {
|
|
60
|
+
this.onErrorHandler = handler;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function createJob(options) {
|
|
65
|
+
const stack = tryCaptureStackTrace();
|
|
66
|
+
return new Job({ dependencies: {}, ...options }, stack);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.js","sourceRoot":"","sources":["../../../src/runtime/jobs/job.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAIpD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAkJrC,MAAM,OAAO,GAAG;IAqDL;IACA;IA1CT,CAAC,CAMC;IACF,CAAC,OAAO,CAAC,GAAG,IAAa,CAAA;IACzB,KAAK,GAAU,EAAsB,CAAA;IACrC,UAAU,GAAuD,IAAI,GA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CAAC;IAED,SAAS,CACP,OAEgE;QAEhE,IAAI,CAAC,gBAAgB,GAAG,OAAc,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,UAAU,CACR,OAEiE;QAEjE,IAAI,CAAC,iBAAiB,GAAG,OAAc,CAAA;QACvC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CACL,OAE8D;QAE9D,IAAI,CAAC,cAAc,GAAG,OAAc,CAAA;QACpC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAOvB,OAA8D;IAC9D,MAAM,KAAK,GAAG,oBAAoB,EAAE,CAAA;IACpC,OAAO,IAAI,GAAG,CACZ,EAAE,YAAY,EAAE,EAAU,EAAE,GAAG,OAAO,EAAE,EACxC,KAAK,CACN,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { Job, JobState, JobType, QueueEventsListener } from 'bullmq';
|
|
2
|
+
import { Queue, QueueEvents, QueueEventsProducer } from 'bullmq';
|
|
3
|
+
import type { ServerStoreConfig } from '../server/config.ts';
|
|
4
|
+
import type { Store } from '../types.ts';
|
|
5
|
+
import type { AnyJob, JobBackoffOptions } from './job.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Get the dedicated BullMQ queue name for a job
|
|
8
|
+
*/
|
|
9
|
+
export declare function getJobQueueName(job: AnyJob): string;
|
|
10
|
+
type QueueJobResultOptions<T extends AnyJob = AnyJob> = {
|
|
11
|
+
job: T;
|
|
12
|
+
bullJob: Job<T['_']['input'], T['_']['output'], T['options']['name']>;
|
|
13
|
+
events: QueueEvents;
|
|
14
|
+
};
|
|
15
|
+
type QueueJobAddOptions = {
|
|
16
|
+
jobId?: string;
|
|
17
|
+
priority?: number;
|
|
18
|
+
forceMissingWorkers?: boolean;
|
|
19
|
+
attempts?: number;
|
|
20
|
+
backoff?: JobBackoffOptions;
|
|
21
|
+
oneoff?: boolean;
|
|
22
|
+
delay?: number;
|
|
23
|
+
};
|
|
24
|
+
export declare class QueueJobResult<T extends AnyJob = AnyJob> {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(options: QueueJobResultOptions<T>);
|
|
27
|
+
get id(): string | undefined;
|
|
28
|
+
get name(): string;
|
|
29
|
+
waitResult(): Promise<T["_"]["output"]>;
|
|
30
|
+
}
|
|
31
|
+
export type JobItem<T extends AnyJob = AnyJob> = Pick<Job<T['_']['input'], T['_']['output'], T['options']['name']>, 'queueName' | 'priority' | 'progress' | 'name' | 'data' | 'returnvalue' | 'attemptsMade' | 'processedOn' | 'finishedOn' | 'failedReason' | 'stacktrace'> & {
|
|
32
|
+
id: string;
|
|
33
|
+
status: JobState | 'unknown';
|
|
34
|
+
};
|
|
35
|
+
export type JobStepInfo = {
|
|
36
|
+
label?: string;
|
|
37
|
+
conditional: boolean;
|
|
38
|
+
};
|
|
39
|
+
export type JobInfo = {
|
|
40
|
+
name: string;
|
|
41
|
+
steps: JobStepInfo[];
|
|
42
|
+
};
|
|
43
|
+
export interface JobManagerInstance {
|
|
44
|
+
list<T extends AnyJob>(job: T, options?: {
|
|
45
|
+
page?: number;
|
|
46
|
+
limit?: number;
|
|
47
|
+
state?: JobState[];
|
|
48
|
+
}): Promise<{
|
|
49
|
+
items: JobItem<T>[];
|
|
50
|
+
page: number;
|
|
51
|
+
limit: number;
|
|
52
|
+
pages: number;
|
|
53
|
+
total: number;
|
|
54
|
+
}>;
|
|
55
|
+
get<T extends AnyJob>(job: T, id: string): Promise<JobItem<T> | null>;
|
|
56
|
+
getInfo(job: AnyJob): JobInfo;
|
|
57
|
+
add<T extends AnyJob>(job: T, data: T['_']['input'], options?: QueueJobAddOptions): Promise<QueueJobResult<T>>;
|
|
58
|
+
retry(job: AnyJob, id: string, options?: {
|
|
59
|
+
clearState?: boolean;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
remove(job: AnyJob, id: string): Promise<void>;
|
|
62
|
+
cancel(job: AnyJob, id: string): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export type CustomJobsEvents = QueueEventsListener & {
|
|
65
|
+
[K in `cancel:${string}`]: (args: {}, id: string) => void;
|
|
66
|
+
};
|
|
67
|
+
type JobQueueEntry = {
|
|
68
|
+
queue: Queue;
|
|
69
|
+
events: QueueEvents;
|
|
70
|
+
custom: QueueEventsProducer;
|
|
71
|
+
};
|
|
72
|
+
export declare class JobManager {
|
|
73
|
+
protected storeConfig: ServerStoreConfig;
|
|
74
|
+
protected jobs: AnyJob[];
|
|
75
|
+
protected store: Store;
|
|
76
|
+
/**
|
|
77
|
+
* Per-job dedicated queues. Each job has its own queue for granular control.
|
|
78
|
+
*/
|
|
79
|
+
protected jobQueues: Map<string, JobQueueEntry>;
|
|
80
|
+
constructor(storeConfig: ServerStoreConfig, jobs: AnyJob[]);
|
|
81
|
+
get publicInstance(): JobManagerInstance;
|
|
82
|
+
initialize(): Promise<void>;
|
|
83
|
+
terminate(): Promise<void>;
|
|
84
|
+
protected getJobQueue(job: AnyJob): JobQueueEntry;
|
|
85
|
+
getInfo(job: AnyJob): JobInfo;
|
|
86
|
+
list<T extends AnyJob>(job: T, { limit, page, state, }: {
|
|
87
|
+
page?: number;
|
|
88
|
+
limit?: number;
|
|
89
|
+
state?: JobType[];
|
|
90
|
+
}): Promise<never[] | {
|
|
91
|
+
items: (Pick<Job<any, any, string>, "name" | "data" | "progress" | "queueName" | "priority" | "returnvalue" | "attemptsMade" | "processedOn" | "finishedOn" | "failedReason" | "stacktrace"> & {
|
|
92
|
+
id: string;
|
|
93
|
+
status: JobState | "unknown";
|
|
94
|
+
})[];
|
|
95
|
+
page: number;
|
|
96
|
+
limit: number;
|
|
97
|
+
pages: number;
|
|
98
|
+
total: number;
|
|
99
|
+
}>;
|
|
100
|
+
get<T extends AnyJob>(job: T, id: string): Promise<JobItem<AnyJob> | null>;
|
|
101
|
+
add<T extends AnyJob>(job: T, data: T['_']['input'], { forceMissingWorkers, jobId, priority, attempts, backoff, oneoff, delay, }?: QueueJobAddOptions): Promise<QueueJobResult<T>>;
|
|
102
|
+
retry(job: AnyJob, id: string, options?: {
|
|
103
|
+
clearState?: boolean;
|
|
104
|
+
}): Promise<void>;
|
|
105
|
+
remove(job: AnyJob, id: string): Promise<void>;
|
|
106
|
+
cancel(job: AnyJob, id: string): Promise<void>;
|
|
107
|
+
cancellationSignal(job: AnyJob, id: string): AbortSignal & {
|
|
108
|
+
[Symbol.dispose]: () => void;
|
|
109
|
+
};
|
|
110
|
+
getQueue(job: AnyJob): JobQueueEntry;
|
|
111
|
+
protected _mapJob(bullJob: Job): Promise<JobItem>;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { pick } from '@nmtjs/core';
|
|
4
|
+
import { Queue, QueueEvents, QueueEventsProducer, UnrecoverableError, } from 'bullmq';
|
|
5
|
+
import { createStoreClient } from "../store/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Get the dedicated BullMQ queue name for a job
|
|
8
|
+
*/
|
|
9
|
+
export function getJobQueueName(job) {
|
|
10
|
+
return `job.${job.options.name}`;
|
|
11
|
+
}
|
|
12
|
+
export class QueueJobResult {
|
|
13
|
+
#options;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.#options = options;
|
|
16
|
+
}
|
|
17
|
+
get id() {
|
|
18
|
+
return this.#options.bullJob.id;
|
|
19
|
+
}
|
|
20
|
+
get name() {
|
|
21
|
+
return this.#options.job.options.name;
|
|
22
|
+
}
|
|
23
|
+
async waitResult() {
|
|
24
|
+
return await this.#options.bullJob.waitUntilFinished(this.#options.events);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class JobManager {
|
|
28
|
+
storeConfig;
|
|
29
|
+
jobs;
|
|
30
|
+
store;
|
|
31
|
+
/**
|
|
32
|
+
* Per-job dedicated queues. Each job has its own queue for granular control.
|
|
33
|
+
*/
|
|
34
|
+
jobQueues = new Map();
|
|
35
|
+
constructor(storeConfig, jobs) {
|
|
36
|
+
this.storeConfig = storeConfig;
|
|
37
|
+
this.jobs = jobs;
|
|
38
|
+
}
|
|
39
|
+
get publicInstance() {
|
|
40
|
+
return {
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
list: this.list.bind(this),
|
|
43
|
+
add: this.add.bind(this),
|
|
44
|
+
get: this.get.bind(this),
|
|
45
|
+
getInfo: this.getInfo.bind(this),
|
|
46
|
+
retry: this.retry.bind(this),
|
|
47
|
+
remove: this.remove.bind(this),
|
|
48
|
+
cancel: this.cancel.bind(this),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async initialize() {
|
|
52
|
+
this.store = await createStoreClient(this.storeConfig);
|
|
53
|
+
await this.store.connect();
|
|
54
|
+
// Create a dedicated queue for each job
|
|
55
|
+
for (const job of this.jobs) {
|
|
56
|
+
const queueName = getJobQueueName(job);
|
|
57
|
+
const entry = {
|
|
58
|
+
queue: new Queue(queueName, { connection: this.store }),
|
|
59
|
+
events: new QueueEvents(queueName, {
|
|
60
|
+
connection: this.store,
|
|
61
|
+
autorun: true,
|
|
62
|
+
}),
|
|
63
|
+
custom: new QueueEventsProducer(queueName, {
|
|
64
|
+
connection: this.store,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
this.jobQueues.set(job.options.name, entry);
|
|
68
|
+
}
|
|
69
|
+
// Wait for all queues to be ready
|
|
70
|
+
await Promise.all(Array.from(this.jobQueues.values()).flatMap((entry) => [
|
|
71
|
+
entry.queue.waitUntilReady(),
|
|
72
|
+
entry.events.waitUntilReady(),
|
|
73
|
+
entry.custom.waitUntilReady(),
|
|
74
|
+
]));
|
|
75
|
+
}
|
|
76
|
+
async terminate() {
|
|
77
|
+
await Promise.allSettled(Array.from(this.jobQueues.values()).flatMap((entry) => [
|
|
78
|
+
entry.queue.close(),
|
|
79
|
+
entry.events.close(),
|
|
80
|
+
entry.custom.close(),
|
|
81
|
+
]));
|
|
82
|
+
this.store.disconnect(false);
|
|
83
|
+
}
|
|
84
|
+
getJobQueue(job) {
|
|
85
|
+
const entry = this.jobQueues.get(job.options.name);
|
|
86
|
+
if (!entry) {
|
|
87
|
+
throw new Error(`Job queue for [${job.options.name}] not found`);
|
|
88
|
+
}
|
|
89
|
+
return entry;
|
|
90
|
+
}
|
|
91
|
+
getInfo(job) {
|
|
92
|
+
return {
|
|
93
|
+
name: job.options.name,
|
|
94
|
+
steps: job.steps.map((step, index) => ({
|
|
95
|
+
label: step.label,
|
|
96
|
+
conditional: job.conditions.has(index),
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async list(job, { limit = 20, page = 1, state = [], }) {
|
|
101
|
+
const { queue } = this.getJobQueue(job);
|
|
102
|
+
const jobsCount = await queue.getJobCountByTypes(...state);
|
|
103
|
+
const totalPages = Math.ceil(jobsCount / limit);
|
|
104
|
+
if (page > totalPages)
|
|
105
|
+
return [];
|
|
106
|
+
const jobs = await queue.getJobs(state, (page - 1) * limit, page * limit - 1);
|
|
107
|
+
const items = await Promise.all(jobs.map((job) => this._mapJob(job)));
|
|
108
|
+
return { items, page, limit, pages: totalPages, total: jobsCount };
|
|
109
|
+
}
|
|
110
|
+
async get(job, id) {
|
|
111
|
+
const { queue } = this.getJobQueue(job);
|
|
112
|
+
const bullJob = await queue.getJob(id);
|
|
113
|
+
if (!bullJob)
|
|
114
|
+
return null;
|
|
115
|
+
return await this._mapJob(bullJob);
|
|
116
|
+
}
|
|
117
|
+
async add(job, data, { forceMissingWorkers = false, jobId = randomUUID(), priority, attempts = job.options.attempts, backoff = job.options.backoff, oneoff = job.options.oneoff ?? true, delay, } = {}) {
|
|
118
|
+
const { queue, events } = this.getJobQueue(job);
|
|
119
|
+
if (!forceMissingWorkers) {
|
|
120
|
+
if ((await queue.getWorkersCount()) === 0) {
|
|
121
|
+
throw new Error(`No workers available for [${getJobQueueName(job)}] queue`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const bullJob = await queue.add(job.options.name, data, {
|
|
125
|
+
attempts,
|
|
126
|
+
backoff,
|
|
127
|
+
jobId,
|
|
128
|
+
priority,
|
|
129
|
+
delay,
|
|
130
|
+
removeOnComplete: oneoff,
|
|
131
|
+
removeOnFail: oneoff,
|
|
132
|
+
});
|
|
133
|
+
return new QueueJobResult({ job, bullJob, events });
|
|
134
|
+
}
|
|
135
|
+
async retry(job, id, options) {
|
|
136
|
+
const { queue } = this.getJobQueue(job);
|
|
137
|
+
const bullJob = await queue.getJob(id);
|
|
138
|
+
if (!bullJob)
|
|
139
|
+
throw new Error(`Job with id [${id}] not found`);
|
|
140
|
+
const state = await bullJob.getState();
|
|
141
|
+
// For completed jobs, clear state by default so it reruns from scratch
|
|
142
|
+
// For failed jobs, keep state by default so it resumes from checkpoint
|
|
143
|
+
const shouldClearState = options?.clearState ?? state === 'completed';
|
|
144
|
+
if (shouldClearState) {
|
|
145
|
+
await bullJob.updateProgress({});
|
|
146
|
+
}
|
|
147
|
+
await bullJob.retry();
|
|
148
|
+
}
|
|
149
|
+
async remove(job, id) {
|
|
150
|
+
const { queue } = this.getJobQueue(job);
|
|
151
|
+
const bullJob = await queue.getJob(id);
|
|
152
|
+
if (!bullJob)
|
|
153
|
+
throw new Error(`Job with id [${id}] not found`);
|
|
154
|
+
await bullJob.remove();
|
|
155
|
+
}
|
|
156
|
+
async cancel(job, id) {
|
|
157
|
+
const { custom, queue } = this.getJobQueue(job);
|
|
158
|
+
const bullJob = await queue.getJob(id);
|
|
159
|
+
if (!bullJob)
|
|
160
|
+
throw new Error(`Job with id [${id}] not found`);
|
|
161
|
+
if (bullJob.finishedOn)
|
|
162
|
+
return;
|
|
163
|
+
if ((await bullJob.getState()) === 'waiting') {
|
|
164
|
+
return await bullJob.remove();
|
|
165
|
+
}
|
|
166
|
+
if ((await bullJob.getState()) === 'active') {
|
|
167
|
+
await custom.publishEvent({ eventName: `cancel:${id}` });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
cancellationSignal(job, id) {
|
|
171
|
+
const { events } = this.getJobQueue(job);
|
|
172
|
+
const controller = new AbortController();
|
|
173
|
+
const handler = () => {
|
|
174
|
+
controller.abort(new UnrecoverableError('Job cancelled'));
|
|
175
|
+
};
|
|
176
|
+
events.on(`cancel:${id}`, handler);
|
|
177
|
+
const signal = controller.signal;
|
|
178
|
+
return Object.assign(signal, {
|
|
179
|
+
[Symbol.dispose]: () => {
|
|
180
|
+
events.off(`cancel:${id}`, handler);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
getQueue(job) {
|
|
185
|
+
return this.getJobQueue(job);
|
|
186
|
+
}
|
|
187
|
+
async _mapJob(bullJob) {
|
|
188
|
+
const status = await bullJob.getState();
|
|
189
|
+
const id = bullJob.id;
|
|
190
|
+
assert(typeof id === 'string', 'Expected job id to be a string');
|
|
191
|
+
return {
|
|
192
|
+
...pick(bullJob, {
|
|
193
|
+
queueName: true,
|
|
194
|
+
priority: true,
|
|
195
|
+
progress: true,
|
|
196
|
+
name: true,
|
|
197
|
+
data: true,
|
|
198
|
+
returnvalue: true,
|
|
199
|
+
attemptsMade: true,
|
|
200
|
+
processedOn: true,
|
|
201
|
+
finishedOn: true,
|
|
202
|
+
failedReason: true,
|
|
203
|
+
stacktrace: true,
|
|
204
|
+
}),
|
|
205
|
+
id,
|
|
206
|
+
status,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/runtime/jobs/manager.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AASxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EACL,KAAK,EACL,WAAW,EACX,mBAAmB,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