@dudousxd/nestjs-durable 0.65.0 → 0.67.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/dist/index.cjs +42 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -13
- package/dist/index.d.ts +42 -13
- package/dist/index.js +42 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -166,6 +166,21 @@ type DtoClass = new (...args: any[]) => object;
|
|
|
166
166
|
* constructor is a DTO. A zod schema older than 3.24 (no `~standard`) still works through its `parse`.
|
|
167
167
|
*/
|
|
168
168
|
type IoSchema = StandardSchemaV1 | DtoClass | z.ZodType;
|
|
169
|
+
/**
|
|
170
|
+
* The value a schema parses to, which is what `run(ctx, input)`, `validateInput` and the `singleton`
|
|
171
|
+
* / `concurrency` keys receive: a Standard Schema's output type (`z.output` for zod), a DTO class's
|
|
172
|
+
* instance, `unknown` without a schema. Use it to type `run`'s input from the same schema:
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* const Input = z.object({ companyId: z.string() });
|
|
176
|
+
*
|
|
177
|
+
* @Workflow({ name: 'sync', input: Input, singleton: { key: (input) => input.companyId } })
|
|
178
|
+
* class SyncWorkflow {
|
|
179
|
+
* async run(ctx: WorkflowCtx, input: InferWorkflowInput<typeof Input>) {}
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
type InferWorkflowInput<S> = [S] extends [undefined] ? unknown : [S] extends [StandardSchemaV1] ? StandardSchemaV1.InferOutput<S> : [S] extends [z.ZodType] ? z.output<S> : [S] extends [DtoClass] ? InstanceType<S> : unknown;
|
|
169
184
|
|
|
170
185
|
declare const WORKFLOW_METADATA: unique symbol;
|
|
171
186
|
interface WorkflowMeta {
|
|
@@ -208,7 +223,14 @@ interface WorkflowMeta {
|
|
|
208
223
|
* `WorkflowOptions`. */
|
|
209
224
|
requires?: string[] | undefined;
|
|
210
225
|
}
|
|
211
|
-
|
|
226
|
+
/**
|
|
227
|
+
* `@Workflow` options. `S` is the `input` schema's type, inferred from the option: the `singleton`
|
|
228
|
+
* and `concurrency` keys and `validateInput` then take the schema's parsed type (see
|
|
229
|
+
* {@link InferWorkflowInput}); without an `input` schema they take `unknown`, as they always did.
|
|
230
|
+
* Written without a type argument (`const opts: WorkflowOptions = …`, an interface extending it),
|
|
231
|
+
* it accepts any `input` schema and the callbacks take `unknown`, as before.
|
|
232
|
+
*/
|
|
233
|
+
interface WorkflowOptions<S extends IoSchema | undefined = IoSchema | undefined> {
|
|
212
234
|
name: string;
|
|
213
235
|
version?: string;
|
|
214
236
|
/**
|
|
@@ -238,18 +260,20 @@ interface WorkflowOptions {
|
|
|
238
260
|
* Serialize runs of this workflow that share a key — a durable FIFO mutex. e.g.
|
|
239
261
|
* `singleton: { key: (input) => `base:${input.baseId}` }` runs at most one pipeline per base at a
|
|
240
262
|
* time; same-key runs queue (suspended) and admit in creation order as slots free. `limit` (default
|
|
241
|
-
* 1) raises the concurrency.
|
|
263
|
+
* 1) raises the concurrency. With an `input` schema, `key` receives the parsed input (typed from
|
|
264
|
+
* the schema, the same value `run` gets); without one, the input as sent (`unknown`).
|
|
242
265
|
*/
|
|
243
|
-
singleton?: SingletonConfig
|
|
266
|
+
singleton?: SingletonConfig<InferWorkflowInput<S>>;
|
|
244
267
|
/**
|
|
245
268
|
* A start-time concurrency QUOTA: at most `limit` runs sharing a key in flight, and a start over it
|
|
246
269
|
* is REJECTED (`ConcurrencyLimitError`, nothing created) rather than queued. e.g.
|
|
247
270
|
* `concurrency: { key: (input) => `tenant:${input.tenantId}`, limit: 8 }` caps what one tenant can
|
|
248
271
|
* have executing at once. The key is shared across workflows; `limit` may be a (async) function of
|
|
249
272
|
* the key for per-plan limits; `countStatuses` narrows what occupies a slot (default: every
|
|
250
|
-
* non-terminal status). Use `singleton` instead when excess runs should wait their turn.
|
|
273
|
+
* non-terminal status). Use `singleton` instead when excess runs should wait their turn. With an
|
|
274
|
+
* `input` schema, `key` receives the parsed input, typed from the schema, like `singleton`'s.
|
|
251
275
|
*/
|
|
252
|
-
concurrency?: ConcurrencyConfig
|
|
276
|
+
concurrency?: ConcurrencyConfig<InferWorkflowInput<S>>;
|
|
253
277
|
/**
|
|
254
278
|
* Max wall-clock lifetime for a run of this workflow (e.g. `'2h'`, `'7 days'`, or ms), counted from
|
|
255
279
|
* the run's creation. A run that outlives it is moved to `cancelled` (`execution_timeout`) by the
|
|
@@ -280,9 +304,10 @@ interface WorkflowOptions {
|
|
|
280
304
|
* workflow — bump `version`. A stored input that no longer parses fails the run with
|
|
281
305
|
* `code: 'invalid_input'`.
|
|
282
306
|
*
|
|
283
|
-
* `@Workflow({ name: 'checkout', input: CheckoutInput })` or `input: z.object({ … })`.
|
|
307
|
+
* `@Workflow({ name: 'checkout', input: CheckoutInput })` or `input: z.object({ … })`. Type `run`'s
|
|
308
|
+
* input from the same schema with `InferWorkflowInput<typeof CheckoutInput>`.
|
|
284
309
|
*/
|
|
285
|
-
input?:
|
|
310
|
+
input?: S;
|
|
286
311
|
/**
|
|
287
312
|
* The run's output schema (same forms as {@link input}). The value `run()` returns is parsed before
|
|
288
313
|
* the run completes, and the parsed value is what the run stores as its output. A mismatch fails the
|
|
@@ -292,9 +317,9 @@ interface WorkflowOptions {
|
|
|
292
317
|
/**
|
|
293
318
|
* A custom check at `start` (throw to reject) for a rule a schema can't express — a cross-field
|
|
294
319
|
* invariant, an async lookup. It runs after `input` parses and receives the parsed value (the input
|
|
295
|
-
* as sent when there is no `input` schema).
|
|
320
|
+
* as sent when there is no `input` schema), typed from the schema.
|
|
296
321
|
*/
|
|
297
|
-
validateInput?: (input:
|
|
322
|
+
validateInput?: (input: InferWorkflowInput<S>) => void | Promise<void>;
|
|
298
323
|
/**
|
|
299
324
|
* Validate this workflow's {@link WorkflowCtx.upsertSearchAttributes} writes against a **Standard
|
|
300
325
|
* Schema** (https://standardschema.dev — zod 3.24+, valibot, arktype, …). `ctx.upsertSearchAttributes`
|
|
@@ -349,7 +374,7 @@ interface WorkflowOptions {
|
|
|
349
374
|
* Marks a provider class as a durable workflow. Its `run(ctx, input)` method becomes the
|
|
350
375
|
* workflow function the engine executes and replays.
|
|
351
376
|
*/
|
|
352
|
-
declare function Workflow(options: WorkflowOptions): ClassDecorator;
|
|
377
|
+
declare function Workflow<S extends IoSchema | undefined = undefined>(options: WorkflowOptions<S>): ClassDecorator;
|
|
353
378
|
declare function getWorkflowMeta(target: Function): WorkflowMeta | undefined;
|
|
354
379
|
declare const DURABLE_STEP_METADATA: unique symbol;
|
|
355
380
|
interface DurableStepMeta {
|
|
@@ -1225,7 +1250,11 @@ declare class DurableModule {
|
|
|
1225
1250
|
* alone) cannot evaluate. Declared by `ThinWorkflowRegistrar` for every `@Workflow` it discovers.
|
|
1226
1251
|
*/
|
|
1227
1252
|
interface TenantWorkflowStartPolicy {
|
|
1228
|
-
/** `@Workflow({ input
|
|
1253
|
+
/** `@Workflow({ input })`: parses the input once (throwing rejects the start before anything is
|
|
1254
|
+
* published); `validateInput` and the singleton and concurrency keys read the parsed value. */
|
|
1255
|
+
parseInput?: ((input: unknown) => unknown) | undefined;
|
|
1256
|
+
/** `@Workflow({ validateInput })`: rejects the start (throws) before anything is published. It
|
|
1257
|
+
* receives the value `parseInput` returned, or the input as sent without one. */
|
|
1229
1258
|
validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
|
|
1230
1259
|
/** `@Workflow({ singleton })`: its key is evaluated here and carried on the start-run. */
|
|
1231
1260
|
singleton?: SingletonConfig | undefined;
|
|
@@ -1296,7 +1325,7 @@ declare class DurableStartClient {
|
|
|
1296
1325
|
declareWorkflow(workflow: string, policy: TenantWorkflowStartPolicy): void;
|
|
1297
1326
|
/**
|
|
1298
1327
|
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
1299
|
-
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
1328
|
+
* evaluates the singleton key and the default quota against the parsed input. A per-start `concurrency` wins over the
|
|
1300
1329
|
* workflow's.
|
|
1301
1330
|
*/
|
|
1302
1331
|
private applyPolicy;
|
|
@@ -2185,4 +2214,4 @@ declare class WorkflowService {
|
|
|
2185
2214
|
republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
|
|
2186
2215
|
}
|
|
2187
2216
|
|
|
2188
|
-
export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type ResolvedTenantAuth, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_AUTH, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, tenantScheduleAnnouncement, thinWorkerProviders, unavailableRunGateway };
|
|
2217
|
+
export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type InferWorkflowInput, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type ResolvedTenantAuth, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_AUTH, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, tenantScheduleAnnouncement, thinWorkerProviders, unavailableRunGateway };
|
package/dist/index.d.ts
CHANGED
|
@@ -166,6 +166,21 @@ type DtoClass = new (...args: any[]) => object;
|
|
|
166
166
|
* constructor is a DTO. A zod schema older than 3.24 (no `~standard`) still works through its `parse`.
|
|
167
167
|
*/
|
|
168
168
|
type IoSchema = StandardSchemaV1 | DtoClass | z.ZodType;
|
|
169
|
+
/**
|
|
170
|
+
* The value a schema parses to, which is what `run(ctx, input)`, `validateInput` and the `singleton`
|
|
171
|
+
* / `concurrency` keys receive: a Standard Schema's output type (`z.output` for zod), a DTO class's
|
|
172
|
+
* instance, `unknown` without a schema. Use it to type `run`'s input from the same schema:
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* const Input = z.object({ companyId: z.string() });
|
|
176
|
+
*
|
|
177
|
+
* @Workflow({ name: 'sync', input: Input, singleton: { key: (input) => input.companyId } })
|
|
178
|
+
* class SyncWorkflow {
|
|
179
|
+
* async run(ctx: WorkflowCtx, input: InferWorkflowInput<typeof Input>) {}
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
type InferWorkflowInput<S> = [S] extends [undefined] ? unknown : [S] extends [StandardSchemaV1] ? StandardSchemaV1.InferOutput<S> : [S] extends [z.ZodType] ? z.output<S> : [S] extends [DtoClass] ? InstanceType<S> : unknown;
|
|
169
184
|
|
|
170
185
|
declare const WORKFLOW_METADATA: unique symbol;
|
|
171
186
|
interface WorkflowMeta {
|
|
@@ -208,7 +223,14 @@ interface WorkflowMeta {
|
|
|
208
223
|
* `WorkflowOptions`. */
|
|
209
224
|
requires?: string[] | undefined;
|
|
210
225
|
}
|
|
211
|
-
|
|
226
|
+
/**
|
|
227
|
+
* `@Workflow` options. `S` is the `input` schema's type, inferred from the option: the `singleton`
|
|
228
|
+
* and `concurrency` keys and `validateInput` then take the schema's parsed type (see
|
|
229
|
+
* {@link InferWorkflowInput}); without an `input` schema they take `unknown`, as they always did.
|
|
230
|
+
* Written without a type argument (`const opts: WorkflowOptions = …`, an interface extending it),
|
|
231
|
+
* it accepts any `input` schema and the callbacks take `unknown`, as before.
|
|
232
|
+
*/
|
|
233
|
+
interface WorkflowOptions<S extends IoSchema | undefined = IoSchema | undefined> {
|
|
212
234
|
name: string;
|
|
213
235
|
version?: string;
|
|
214
236
|
/**
|
|
@@ -238,18 +260,20 @@ interface WorkflowOptions {
|
|
|
238
260
|
* Serialize runs of this workflow that share a key — a durable FIFO mutex. e.g.
|
|
239
261
|
* `singleton: { key: (input) => `base:${input.baseId}` }` runs at most one pipeline per base at a
|
|
240
262
|
* time; same-key runs queue (suspended) and admit in creation order as slots free. `limit` (default
|
|
241
|
-
* 1) raises the concurrency.
|
|
263
|
+
* 1) raises the concurrency. With an `input` schema, `key` receives the parsed input (typed from
|
|
264
|
+
* the schema, the same value `run` gets); without one, the input as sent (`unknown`).
|
|
242
265
|
*/
|
|
243
|
-
singleton?: SingletonConfig
|
|
266
|
+
singleton?: SingletonConfig<InferWorkflowInput<S>>;
|
|
244
267
|
/**
|
|
245
268
|
* A start-time concurrency QUOTA: at most `limit` runs sharing a key in flight, and a start over it
|
|
246
269
|
* is REJECTED (`ConcurrencyLimitError`, nothing created) rather than queued. e.g.
|
|
247
270
|
* `concurrency: { key: (input) => `tenant:${input.tenantId}`, limit: 8 }` caps what one tenant can
|
|
248
271
|
* have executing at once. The key is shared across workflows; `limit` may be a (async) function of
|
|
249
272
|
* the key for per-plan limits; `countStatuses` narrows what occupies a slot (default: every
|
|
250
|
-
* non-terminal status). Use `singleton` instead when excess runs should wait their turn.
|
|
273
|
+
* non-terminal status). Use `singleton` instead when excess runs should wait their turn. With an
|
|
274
|
+
* `input` schema, `key` receives the parsed input, typed from the schema, like `singleton`'s.
|
|
251
275
|
*/
|
|
252
|
-
concurrency?: ConcurrencyConfig
|
|
276
|
+
concurrency?: ConcurrencyConfig<InferWorkflowInput<S>>;
|
|
253
277
|
/**
|
|
254
278
|
* Max wall-clock lifetime for a run of this workflow (e.g. `'2h'`, `'7 days'`, or ms), counted from
|
|
255
279
|
* the run's creation. A run that outlives it is moved to `cancelled` (`execution_timeout`) by the
|
|
@@ -280,9 +304,10 @@ interface WorkflowOptions {
|
|
|
280
304
|
* workflow — bump `version`. A stored input that no longer parses fails the run with
|
|
281
305
|
* `code: 'invalid_input'`.
|
|
282
306
|
*
|
|
283
|
-
* `@Workflow({ name: 'checkout', input: CheckoutInput })` or `input: z.object({ … })`.
|
|
307
|
+
* `@Workflow({ name: 'checkout', input: CheckoutInput })` or `input: z.object({ … })`. Type `run`'s
|
|
308
|
+
* input from the same schema with `InferWorkflowInput<typeof CheckoutInput>`.
|
|
284
309
|
*/
|
|
285
|
-
input?:
|
|
310
|
+
input?: S;
|
|
286
311
|
/**
|
|
287
312
|
* The run's output schema (same forms as {@link input}). The value `run()` returns is parsed before
|
|
288
313
|
* the run completes, and the parsed value is what the run stores as its output. A mismatch fails the
|
|
@@ -292,9 +317,9 @@ interface WorkflowOptions {
|
|
|
292
317
|
/**
|
|
293
318
|
* A custom check at `start` (throw to reject) for a rule a schema can't express — a cross-field
|
|
294
319
|
* invariant, an async lookup. It runs after `input` parses and receives the parsed value (the input
|
|
295
|
-
* as sent when there is no `input` schema).
|
|
320
|
+
* as sent when there is no `input` schema), typed from the schema.
|
|
296
321
|
*/
|
|
297
|
-
validateInput?: (input:
|
|
322
|
+
validateInput?: (input: InferWorkflowInput<S>) => void | Promise<void>;
|
|
298
323
|
/**
|
|
299
324
|
* Validate this workflow's {@link WorkflowCtx.upsertSearchAttributes} writes against a **Standard
|
|
300
325
|
* Schema** (https://standardschema.dev — zod 3.24+, valibot, arktype, …). `ctx.upsertSearchAttributes`
|
|
@@ -349,7 +374,7 @@ interface WorkflowOptions {
|
|
|
349
374
|
* Marks a provider class as a durable workflow. Its `run(ctx, input)` method becomes the
|
|
350
375
|
* workflow function the engine executes and replays.
|
|
351
376
|
*/
|
|
352
|
-
declare function Workflow(options: WorkflowOptions): ClassDecorator;
|
|
377
|
+
declare function Workflow<S extends IoSchema | undefined = undefined>(options: WorkflowOptions<S>): ClassDecorator;
|
|
353
378
|
declare function getWorkflowMeta(target: Function): WorkflowMeta | undefined;
|
|
354
379
|
declare const DURABLE_STEP_METADATA: unique symbol;
|
|
355
380
|
interface DurableStepMeta {
|
|
@@ -1225,7 +1250,11 @@ declare class DurableModule {
|
|
|
1225
1250
|
* alone) cannot evaluate. Declared by `ThinWorkflowRegistrar` for every `@Workflow` it discovers.
|
|
1226
1251
|
*/
|
|
1227
1252
|
interface TenantWorkflowStartPolicy {
|
|
1228
|
-
/** `@Workflow({ input
|
|
1253
|
+
/** `@Workflow({ input })`: parses the input once (throwing rejects the start before anything is
|
|
1254
|
+
* published); `validateInput` and the singleton and concurrency keys read the parsed value. */
|
|
1255
|
+
parseInput?: ((input: unknown) => unknown) | undefined;
|
|
1256
|
+
/** `@Workflow({ validateInput })`: rejects the start (throws) before anything is published. It
|
|
1257
|
+
* receives the value `parseInput` returned, or the input as sent without one. */
|
|
1229
1258
|
validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
|
|
1230
1259
|
/** `@Workflow({ singleton })`: its key is evaluated here and carried on the start-run. */
|
|
1231
1260
|
singleton?: SingletonConfig | undefined;
|
|
@@ -1296,7 +1325,7 @@ declare class DurableStartClient {
|
|
|
1296
1325
|
declareWorkflow(workflow: string, policy: TenantWorkflowStartPolicy): void;
|
|
1297
1326
|
/**
|
|
1298
1327
|
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
1299
|
-
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
1328
|
+
* evaluates the singleton key and the default quota against the parsed input. A per-start `concurrency` wins over the
|
|
1300
1329
|
* workflow's.
|
|
1301
1330
|
*/
|
|
1302
1331
|
private applyPolicy;
|
|
@@ -2185,4 +2214,4 @@ declare class WorkflowService {
|
|
|
2185
2214
|
republishLifecycle(target: RepublishLifecycleTarget): Promise<RepublishLifecycleResult>;
|
|
2186
2215
|
}
|
|
2187
2216
|
|
|
2188
|
-
export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type ResolvedTenantAuth, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_AUTH, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, tenantScheduleAnnouncement, thinWorkerProviders, unavailableRunGateway };
|
|
2217
|
+
export { BAD_RUN_REQUEST, CONTEXT_ACCESSOR, type ContextAccessor, type ContextStore, type ContractClass, type ControlPlaneDurableOptions, DEAD_LETTER_METADATA, DURABLE_STEP_METADATA, DURABLE_WORKER_RUNNERS, DURABLE_WORKER_RUNTIME, DeadLetter, type DtoClass, DurableModule, type DurableModuleAsyncOptions, type DurableModuleOptions, type DurableModuleSharedOptions, type DurableRetentionOptions, DurableStartClient, type DurableStepInterceptor, type DurableStepMeta, type DurableTopologyName, ENTITY_METADATA, ENTITY_ON_METADATA, Entity, EntityService, type ErrorClassWithCode, FederatedAppGateway, type FederatedAppGatewayOptions, IN_APP_RUN_REDIS_WORKER, IN_APP_WORKER_BINDING, IN_APP_WORKER_RUNNERS, IN_APP_WORKER_RUNTIME, type InAppWorkerBinding, InAppWorkerBootstrap, type InferWorkflowInput, type IoSchema, type LazyContract, ON_ERROR_METADATA, ON_EVENT_BATCH_METADATA, ON_EVENT_METADATA, On, OnDurableEvent, OnError, type OnErrorMethod, OnWorkflowCompleted, OnWorkflowFailed, type OnWorkflowFailedOptions, type OnWorkflowSettledOptions, ProxyRunGateway, RUN_GATEWAY, RUN_REDIS_WORKER, type ResolvedTenantAuth, RunGatewayError, type RunGatewayErrorCode, type RunLookupStore, type RunRedisWorkerFn, RunRequestResponder, type RunRequestResponderOptions, type RunRequestTransport, STEP_INTERCEPTOR_METADATA, type StandaloneDurableOptions, Step, StepInterceptor, type StepOptions, StoreRunGateway, type SubscriberBatch, type SubscriberDebounce, type SubscriberDecorator, TENANT_AUTH, TENANT_REPUBLISH_MAX_LIMIT, type TenantCredentialsContract, type TenantDurableOptions, TenantEventRepublisher, type TenantFilter, type TenantLevel, type TenantRef, type TenantTokenOption, type TenantVerifierContract, type TenantVerifierInput, type TenantVerifierOption, ThinStepRegistrar, ThinWorkerBootstrap, ThinWorkflowRegistrar, UNSUPPORTED_RUN_REQUEST, type UserRef, WORKFLOW_METADATA, Workflow, type WorkflowAttributesOf, type WorkflowMeta, type WorkflowOptions, WorkflowService, attributesOf, entityConfigFor, eventBatchOf, federatedAppGateway, getDurableStepMeta, getEntityMeta, getOnEvents, getWorkflowMeta, inAppWorkerProviders, isDeadLetterHandler, isDrivingOperator, isOperatorRole, isStepInterceptor, onErrorCodesOf, tenantScheduleAnnouncement, thinWorkerProviders, unavailableRunGateway };
|
package/dist/index.js
CHANGED
|
@@ -127,6 +127,8 @@ function Workflow(options) {
|
|
|
127
127
|
deadLetterWorkflow: options.deadLetterWorkflow,
|
|
128
128
|
onError: options.onError,
|
|
129
129
|
tags: options.tags,
|
|
130
|
+
// The typed callbacks are stored erased: the engine calls them with the parsed input, which is
|
|
131
|
+
// exactly the type `S` gave them (see `workflowIo`).
|
|
130
132
|
singleton: options.singleton,
|
|
131
133
|
concurrency: options.concurrency,
|
|
132
134
|
executionTimeout: options.executionTimeout,
|
|
@@ -721,7 +723,7 @@ var DurableStartClient = class {
|
|
|
721
723
|
}
|
|
722
724
|
/**
|
|
723
725
|
* The start-run fields a declared policy adds for `input`: it validates the input (throwing), and
|
|
724
|
-
* evaluates the singleton key and the default quota. A per-start `concurrency` wins over the
|
|
726
|
+
* evaluates the singleton key and the default quota against the parsed input. A per-start `concurrency` wins over the
|
|
725
727
|
* workflow's.
|
|
726
728
|
*/
|
|
727
729
|
async applyPolicy(workflow, input, opts) {
|
|
@@ -729,10 +731,11 @@ var DurableStartClient = class {
|
|
|
729
731
|
if (!policy) return opts?.concurrency !== void 0 ? {
|
|
730
732
|
concurrency: opts.concurrency
|
|
731
733
|
} : {};
|
|
732
|
-
await policy.
|
|
733
|
-
|
|
734
|
+
const keyInput = policy.parseInput ? await policy.parseInput(input) : input;
|
|
735
|
+
await policy.validateInput?.(keyInput);
|
|
736
|
+
const concurrency = await resolveConcurrency(opts?.concurrency, policy.concurrency, keyInput);
|
|
734
737
|
const singleton = policy.singleton ? {
|
|
735
|
-
key: policy.singleton.key(
|
|
738
|
+
key: policy.singleton.key(keyInput),
|
|
736
739
|
...policy.singleton.limit !== void 0 ? {
|
|
737
740
|
limit: policy.singleton.limit
|
|
738
741
|
} : {},
|
|
@@ -1167,10 +1170,8 @@ function workflowIo(meta) {
|
|
|
1167
1170
|
const parseOutput = meta.output && schemaParser(meta.output, "output", `workflow "${meta.name}" output`);
|
|
1168
1171
|
const validateInput = meta.validateInput;
|
|
1169
1172
|
return {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
await validateInput?.(parsed);
|
|
1173
|
-
} : void 0,
|
|
1173
|
+
parseInput: parseInput || void 0,
|
|
1174
|
+
validateParsed: validateInput,
|
|
1174
1175
|
wrap: /* @__PURE__ */ __name((body) => !parseInput && !parseOutput ? body : async (ctx, input) => {
|
|
1175
1176
|
const output = await body(ctx, parseInput ? await parseInput(input) : input);
|
|
1176
1177
|
return parseOutput ? parseOutput(output) : output;
|
|
@@ -1345,8 +1346,10 @@ var ThinWorkflowRegistrar = class {
|
|
|
1345
1346
|
}
|
|
1346
1347
|
const declare = starter.declareWorkflow;
|
|
1347
1348
|
if (typeof declare === "function") {
|
|
1349
|
+
const io = workflowIo(meta);
|
|
1348
1350
|
const policy = {
|
|
1349
|
-
validateInput:
|
|
1351
|
+
validateInput: io.validateParsed,
|
|
1352
|
+
parseInput: io.parseInput,
|
|
1350
1353
|
singleton: meta.singleton,
|
|
1351
1354
|
concurrency: meta.concurrency,
|
|
1352
1355
|
onEvent: getOnEvents(meta, instance.constructor),
|
|
@@ -1516,12 +1519,21 @@ async function tenantScheduleAnnouncement(options, tenantToken) {
|
|
|
1516
1519
|
return {
|
|
1517
1520
|
schedules: {
|
|
1518
1521
|
tenant,
|
|
1519
|
-
items: (options.schedules ?? []).map(announcedSchedule)
|
|
1522
|
+
items: await Promise.all((options.schedules ?? []).map(announcedSchedule))
|
|
1520
1523
|
}
|
|
1521
1524
|
};
|
|
1522
1525
|
}
|
|
1523
1526
|
__name(tenantScheduleAnnouncement, "tenantScheduleAnnouncement");
|
|
1524
|
-
function
|
|
1527
|
+
async function scheduleKeyInput(parseInput, input) {
|
|
1528
|
+
if (!parseInput) return input;
|
|
1529
|
+
try {
|
|
1530
|
+
return await parseInput(input);
|
|
1531
|
+
} catch {
|
|
1532
|
+
return input;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
__name(scheduleKeyInput, "scheduleKeyInput");
|
|
1536
|
+
async function announcedSchedule(s) {
|
|
1525
1537
|
const item = {
|
|
1526
1538
|
key: s.key,
|
|
1527
1539
|
workflow: workflowName3(s.workflow)
|
|
@@ -1533,10 +1545,12 @@ function announcedSchedule(s) {
|
|
|
1533
1545
|
if (s.paused === true) item.paused = true;
|
|
1534
1546
|
if (s.overlap !== void 0) item.overlap = s.overlap;
|
|
1535
1547
|
if (s.jitter !== void 0 && s.jitter > 0) item.jitterMs = s.jitter;
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1548
|
+
const meta = typeof s.workflow === "function" ? getWorkflowMeta(s.workflow) : void 0;
|
|
1549
|
+
const singleton = meta?.singleton;
|
|
1550
|
+
if (meta && singleton) {
|
|
1551
|
+
const parseInput = workflowIo(meta).parseInput;
|
|
1538
1552
|
item.singleton = {
|
|
1539
|
-
key: singleton.key(s.input),
|
|
1553
|
+
key: singleton.key(await scheduleKeyInput(parseInput, s.input)),
|
|
1540
1554
|
...singleton.limit !== void 0 ? {
|
|
1541
1555
|
limit: singleton.limit
|
|
1542
1556
|
} : {},
|
|
@@ -1564,7 +1578,12 @@ function thinWorkerProviders() {
|
|
|
1564
1578
|
// optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
|
|
1565
1579
|
// reach this branch at all.
|
|
1566
1580
|
useFactory: /* @__PURE__ */ __name((options) => isPureThinWorker(options) ? createWorkerRuntime({
|
|
1567
|
-
workflowGroup: options.partition ?? ""
|
|
1581
|
+
workflowGroup: options.partition ?? "",
|
|
1582
|
+
// The worker unwinds a failed turn's `localStep` undos itself, so it takes the
|
|
1583
|
+
// module's `compensationRetries` as the engine does.
|
|
1584
|
+
...options.compensationRetries !== void 0 ? {
|
|
1585
|
+
compensationRetries: options.compensationRetries
|
|
1586
|
+
} : {}
|
|
1568
1587
|
}) : null, "useFactory"),
|
|
1569
1588
|
inject: [
|
|
1570
1589
|
DURABLE_OPTIONS_CANONICAL
|
|
@@ -1865,7 +1884,12 @@ function inAppWorkerProviders() {
|
|
|
1865
1884
|
// optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
|
|
1866
1885
|
// reach this branch at all.
|
|
1867
1886
|
useFactory: /* @__PURE__ */ __name((options) => isCoLocatedWorker(options) ? createWorkerRuntime({
|
|
1868
|
-
workflowGroup: options.partition ?? ""
|
|
1887
|
+
workflowGroup: options.partition ?? "",
|
|
1888
|
+
// The worker unwinds a failed turn's `localStep` undos itself, so it takes the
|
|
1889
|
+
// module's `compensationRetries` as the engine does.
|
|
1890
|
+
...options.compensationRetries !== void 0 ? {
|
|
1891
|
+
compensationRetries: options.compensationRetries
|
|
1892
|
+
} : {}
|
|
1869
1893
|
}) : null, "useFactory"),
|
|
1870
1894
|
inject: [
|
|
1871
1895
|
DURABLE_OPTIONS_CANONICAL3
|
|
@@ -4051,7 +4075,8 @@ var WorkflowRegistrar = class {
|
|
|
4051
4075
|
concurrency: meta.concurrency,
|
|
4052
4076
|
executionTimeout: meta.executionTimeout,
|
|
4053
4077
|
requires: meta.requires,
|
|
4054
|
-
validateInput: io.
|
|
4078
|
+
validateInput: io.validateParsed,
|
|
4079
|
+
parseInput: io.parseInput,
|
|
4055
4080
|
searchAttributesSchema: meta.searchAttributes,
|
|
4056
4081
|
onEvent: getOnEvents(meta, workflowCtor),
|
|
4057
4082
|
eventBatch,
|