@sanity/functions 1.6.5 → 1.6.8
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/invoke.js +1 -1
- package/dist/invoke.js.map +1 -1
- package/dist/types.d.ts +106 -118
- package/package.json +1 -1
- package/src/invoke.ts +1 -1
- package/src/types.ts +102 -121
package/dist/invoke.js
CHANGED
|
@@ -128,7 +128,7 @@ export async function invoke(name, payload, options) {
|
|
|
128
128
|
if (!outgoingPayload?.context?.invoke) {
|
|
129
129
|
throw new Error(`No local invoke handler configured for function: ${name}`);
|
|
130
130
|
}
|
|
131
|
-
return await outgoingPayload.context.invoke(name, outgoingPayload, options);
|
|
131
|
+
return await outgoingPayload.context.invoke(name, outgoingPayload.event?.data ?? {}, options);
|
|
132
132
|
}
|
|
133
133
|
const aws = await getAwsLite();
|
|
134
134
|
if (!aws)
|
package/dist/invoke.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoke.js","sourceRoot":"","sources":["../src/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAClC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAC,GAAG,EAAC,MAAM,cAAc,CAAA;AAIhC,IAAI,UAAsD,CAAA;AAE1D,MAAM,aAAa,GAAG,aAAa,CAAA;AACnC,gBAAgB;AAChB,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAA;AAErC;;;GAGG;AACH,SAAS,UAAU;IACjB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,CAAC,KAAK,IAAI,EAAE;YACvB,MAAM,EAAC,OAAO,EAAE,OAAO,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAA;YAC3D,OAAO,OAAO,CAAC;gBACb,OAAO,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,kBAAkB,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I,KAAK,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAA;IACjE,CAAC;IAED,OAAM;AACR,CAAC;AAED,gBAAgB;AAChB,SAAS,gBAAgB,CAAC,OAAe,EAAE,IAAa;IACtD,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC1D,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Callback provided by Sanity CLI when doing local development
|
|
2
|
+
* Callback provided by Sanity CLI when doing local development.
|
|
3
|
+
*
|
|
4
|
+
* The CLI receives the event data alone: it delivers it to the target function as
|
|
5
|
+
* `event.data` and derives the target's context from the calling function's own context.
|
|
3
6
|
*/
|
|
4
|
-
export type InvokeCallback = <T = unknown>(name: string, payload
|
|
7
|
+
export type InvokeCallback = <T = unknown>(name: string, payload?: Record<string, unknown>, options?: InvokeOptions) => Promise<T>;
|
|
5
8
|
/**
|
|
6
9
|
* Options provided to invoke
|
|
7
10
|
*/
|
|
@@ -234,42 +237,41 @@ export type FunctionResourceEnvelope = {
|
|
|
234
237
|
[P in Exclude<FunctionResourceKey, K>]?: FunctionResource;
|
|
235
238
|
};
|
|
236
239
|
}[FunctionResourceKey];
|
|
240
|
+
/**
|
|
241
|
+
* Durable alias of FunctionsContext
|
|
242
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
243
|
+
* @hidden
|
|
244
|
+
*/
|
|
245
|
+
export type DurableContext = FunctionContext;
|
|
237
246
|
/**
|
|
238
247
|
* Logger interface for durables.
|
|
239
248
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
240
249
|
* @hidden
|
|
241
250
|
*/
|
|
242
251
|
export interface DurableLogger {
|
|
243
|
-
debug(
|
|
244
|
-
info(
|
|
245
|
-
warn(
|
|
246
|
-
error(
|
|
247
|
-
log(
|
|
252
|
+
debug(...params: unknown[]): void;
|
|
253
|
+
info(...params: unknown[]): void;
|
|
254
|
+
warn(...params: unknown[]): void;
|
|
255
|
+
error(...params: unknown[]): void;
|
|
256
|
+
log(...params: unknown[]): void;
|
|
248
257
|
}
|
|
249
258
|
/**
|
|
250
|
-
* // @todo: follow-up to better define separated context
|
|
251
259
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
252
260
|
* @hidden
|
|
253
261
|
*/
|
|
254
|
-
export interface
|
|
262
|
+
export interface DurableStepCallbackContext {
|
|
255
263
|
logger: DurableLogger;
|
|
256
264
|
}
|
|
257
265
|
/**
|
|
258
|
-
*
|
|
266
|
+
* Arguments passed to callbacks that execute a durable attempt.
|
|
267
|
+
* step.run & step.waitForCondition
|
|
259
268
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
260
269
|
* @hidden
|
|
261
270
|
*/
|
|
262
|
-
export
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*/
|
|
267
|
-
attempt?: number;
|
|
268
|
-
/**
|
|
269
|
-
* Unique ID for a durable execution
|
|
270
|
-
*/
|
|
271
|
-
runId?: string;
|
|
272
|
-
};
|
|
271
|
+
export interface DurableStepAttemptContext extends DurableStepCallbackContext {
|
|
272
|
+
/** Current attempt number, starting at 1. */
|
|
273
|
+
attempt: number;
|
|
274
|
+
}
|
|
273
275
|
/**
|
|
274
276
|
* The signature of the duration object passed to the `wait` method of a durable function.
|
|
275
277
|
* It can be specified in days, hours, minutes, or seconds.
|
|
@@ -296,36 +298,67 @@ export type DurableDuration = {
|
|
|
296
298
|
* @hidden
|
|
297
299
|
*/
|
|
298
300
|
export type DurableWaitForConditionDecision = {
|
|
299
|
-
|
|
301
|
+
shouldRetry: true;
|
|
300
302
|
delay: DurableDuration;
|
|
301
303
|
} | {
|
|
302
|
-
|
|
304
|
+
shouldRetry: false;
|
|
303
305
|
};
|
|
304
306
|
/**
|
|
305
307
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
306
308
|
* @hidden
|
|
307
309
|
*/
|
|
308
|
-
export
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
export type DurableStepHandler<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn;
|
|
311
|
+
/**
|
|
312
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
313
|
+
* @hidden
|
|
314
|
+
*/
|
|
315
|
+
export type DurableStepRunHandler<T = unknown> = DurableStepHandler<[context: DurableStepAttemptContext], T | Promise<T>>;
|
|
316
|
+
/**
|
|
317
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
318
|
+
* @hidden
|
|
319
|
+
*/
|
|
320
|
+
export type DurableStepWaitForCallbackHandler = DurableStepHandler<[callbackId: string, context: DurableStepCallbackContext], Promise<void>>;
|
|
321
|
+
/**
|
|
322
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
323
|
+
* @hidden
|
|
324
|
+
*/
|
|
325
|
+
export type DurableWaitForConditionPoller<T = unknown> = DurableStepHandler<[state: T, context: DurableStepAttemptContext], Promise<T>>;
|
|
326
|
+
/**
|
|
327
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
328
|
+
* @hidden
|
|
329
|
+
*/
|
|
330
|
+
export type DurableWaitForConditionNext<T = unknown> = DurableStepHandler<[
|
|
331
|
+
state: T,
|
|
332
|
+
context: Pick<DurableStepAttemptContext, 'attempt'>
|
|
333
|
+
], DurableWaitForConditionDecision>;
|
|
312
334
|
/**
|
|
313
335
|
* The interface defining the operations available to a durable function.
|
|
314
336
|
* These operations are steps that delegate to other functions, and wait for external callbacks.
|
|
315
337
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
316
338
|
* @hidden
|
|
317
339
|
*/
|
|
318
|
-
export
|
|
340
|
+
export type DurableOperations = {
|
|
319
341
|
/**
|
|
320
342
|
* Runs a named step. Its result is recorded, so if the workflow re-runs the step
|
|
321
343
|
* is not executed again. Failures are retried on their own.
|
|
322
344
|
* similar to ctx.step()
|
|
323
345
|
* @remarks cannot be nested inside another step
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* step.run({
|
|
349
|
+
* name: 'run-step',
|
|
350
|
+
* handler: async ({logger}) => {
|
|
351
|
+
* logger.log('Running step')
|
|
352
|
+
* }})
|
|
353
|
+
* ```
|
|
324
354
|
* @param name - Step name
|
|
325
|
-
* @param
|
|
355
|
+
* @param handler - function being executed
|
|
326
356
|
* @returns The value returned by the executed function
|
|
327
357
|
*/
|
|
328
|
-
run<T>(name
|
|
358
|
+
run<T>({ name, handler }: {
|
|
359
|
+
name?: string;
|
|
360
|
+
handler: DurableStepRunHandler<T>;
|
|
361
|
+
}): Promise<T>;
|
|
329
362
|
/**
|
|
330
363
|
* Calls another function and awaits its result.
|
|
331
364
|
* similar to ctx.invoke()
|
|
@@ -334,16 +367,22 @@ export interface DurableOperations {
|
|
|
334
367
|
* @param input - Data passed to the called function
|
|
335
368
|
* @returns The value returned by the called function
|
|
336
369
|
*/
|
|
337
|
-
delegate<T>(name
|
|
370
|
+
delegate<T>({ name, input }: {
|
|
371
|
+
name?: string;
|
|
372
|
+
input?: unknown;
|
|
373
|
+
}): Promise<T>;
|
|
338
374
|
/**
|
|
339
375
|
* Waits for an external callback
|
|
340
376
|
* similar to ctx.waitForCallback()
|
|
341
377
|
* @remarks cannot be nested inside another step
|
|
342
378
|
* @param name - Step name
|
|
343
|
-
* @param
|
|
379
|
+
* @param handler - Receives the generated callbackId and returns a delivered promise
|
|
344
380
|
* @returns The value returned by the executed function
|
|
345
381
|
*/
|
|
346
|
-
waitForCallback<T>(name
|
|
382
|
+
waitForCallback<T>({ name, handler }: {
|
|
383
|
+
name?: string;
|
|
384
|
+
handler: DurableStepWaitForCallbackHandler;
|
|
385
|
+
}): Promise<T>;
|
|
347
386
|
/**
|
|
348
387
|
* Waits for a specified duration
|
|
349
388
|
* similar to ctx.wait()
|
|
@@ -351,63 +390,49 @@ export interface DurableOperations {
|
|
|
351
390
|
* @example
|
|
352
391
|
* Wait for 30 seconds
|
|
353
392
|
* ```ts
|
|
354
|
-
* await step.wait('wait30Sec', { seconds: 30 });
|
|
393
|
+
* await step.wait({name: 'wait30Sec', duration: { seconds: 30 }});
|
|
355
394
|
* ```
|
|
356
395
|
* Wait for 2 days and 3 hours
|
|
357
396
|
* ```ts
|
|
358
|
-
* await step.wait('waitALongTime', { days: 2, hours: 3 });
|
|
397
|
+
* await step.wait({name: 'waitALongTime', duration: { days: 2, hours: 3 }});
|
|
359
398
|
* ```
|
|
360
399
|
* @param name - Step name
|
|
361
400
|
* @param duration - Amount of time the function will wait before continuing.
|
|
362
401
|
* Duration is an object with properties of `seconds`, `minutes`, `hours`, or `days`. Must be at least {seconds: 1}
|
|
363
402
|
* @returns Resolves after the duration
|
|
364
403
|
*/
|
|
365
|
-
wait(name
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* @remarks cannot be nested inside another step
|
|
370
|
-
* @example
|
|
371
|
-
* Wait for 30 seconds
|
|
372
|
-
* ```ts
|
|
373
|
-
* await step.wait({ seconds: 30 });
|
|
374
|
-
* ```
|
|
375
|
-
* @param duration - Amount of time the function will wait before continuing.
|
|
376
|
-
* Duration is an object with properties of `seconds`, `minutes`, `hours`, or `days`. Must be at least {seconds: 1}
|
|
377
|
-
* @returns Resolves after the duration
|
|
378
|
-
*/
|
|
379
|
-
wait(duration: DurableDuration): Promise<void>;
|
|
404
|
+
wait({ name, duration }: {
|
|
405
|
+
name?: string;
|
|
406
|
+
duration: DurableDuration;
|
|
407
|
+
}): Promise<void>;
|
|
380
408
|
/**
|
|
381
409
|
* Waits for a specified condition to be met
|
|
382
410
|
* similar to ctx.waitForCondition()
|
|
383
411
|
* @remarks cannot be nested inside another step
|
|
384
412
|
* @example
|
|
385
413
|
* ```ts
|
|
386
|
-
* await step.waitForCondition(
|
|
387
|
-
*
|
|
388
|
-
* async (state, {logger}) => {
|
|
389
|
-
* logger.log('Checking for article')
|
|
390
|
-
*
|
|
391
|
-
* const client = createClient({
|
|
392
|
-
* apiVersion: '2026-08-05',
|
|
393
|
-
* ...context.clientOptions,
|
|
394
|
-
* })
|
|
395
|
-
* const article = await client.fetch<Article | null>(
|
|
396
|
-
* '*[_type == "article"][0]',
|
|
397
|
-
* )
|
|
398
|
-
* return {...state, article}
|
|
399
|
-
* },
|
|
400
|
-
* {
|
|
414
|
+
* await step.waitForCondition({{
|
|
415
|
+
* name: 'waitForCondition',
|
|
401
416
|
* initial: {
|
|
402
|
-
* article: null
|
|
417
|
+
* article: null,
|
|
403
418
|
* },
|
|
404
|
-
*
|
|
405
|
-
*
|
|
419
|
+
* poller: async (state, {attempt}) => {
|
|
420
|
+
* const client = createClient({
|
|
421
|
+
* apiVersion: '2026-08-05',
|
|
422
|
+
* ...context.clientOptions,
|
|
423
|
+
* })
|
|
424
|
+
* const article = await client.fetch<Article | null>(
|
|
425
|
+
* '*[_type == "article"][0]',
|
|
426
|
+
* )
|
|
427
|
+
* return {...state, article}
|
|
428
|
+
* }
|
|
429
|
+
* next: (state, {attempt}) => {
|
|
430
|
+
* if (state.article) return {shouldResume: false}
|
|
406
431
|
*
|
|
407
432
|
* return {
|
|
408
|
-
*
|
|
433
|
+
* shouldResume: true,
|
|
409
434
|
* delay: {
|
|
410
|
-
* seconds: Math.min(
|
|
435
|
+
* seconds: Math.min(attempt * 2, 60),
|
|
411
436
|
* },
|
|
412
437
|
* }
|
|
413
438
|
* },
|
|
@@ -415,57 +440,20 @@ export interface DurableOperations {
|
|
|
415
440
|
* )
|
|
416
441
|
* ```
|
|
417
442
|
* @param name - Step name
|
|
418
|
-
* @param
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* @param options - Configuration options for the condition
|
|
422
|
-
* @returns The value returned by the executed function
|
|
423
|
-
*/
|
|
424
|
-
waitForCondition<T>(name: string, fn: (state: T, args: BaseDurableOperationArgs) => Promise<T>, options: DurableWaitForConditionOptions<T>): Promise<T>;
|
|
425
|
-
/**
|
|
426
|
-
* Waits for a specified condition to be met
|
|
427
|
-
* similar to ctx.waitForCondition()
|
|
428
|
-
* @remarks cannot be nested inside another step
|
|
429
|
-
* @example
|
|
430
|
-
* ```ts
|
|
431
|
-
* await step.waitForCondition(
|
|
432
|
-
* async (state, {logger}) => {
|
|
433
|
-
* logger.log('Checking for article')
|
|
434
|
-
*
|
|
435
|
-
* const client = createClient({
|
|
436
|
-
* apiVersion: '2026-08-05',
|
|
437
|
-
* ...context.clientOptions,
|
|
438
|
-
* })
|
|
439
|
-
* const article = await client.fetch<Article | null>(
|
|
440
|
-
* '*[_type == "article"][0]',
|
|
441
|
-
* )
|
|
442
|
-
* return {...state, article}
|
|
443
|
-
* },
|
|
444
|
-
* {
|
|
445
|
-
* initial: {
|
|
446
|
-
* article: null as Article | null,
|
|
447
|
-
* },
|
|
448
|
-
* next: (state, context) => {
|
|
449
|
-
* if (state.article) return {shouldContinue: false}
|
|
450
|
-
*
|
|
451
|
-
* return {
|
|
452
|
-
* shouldContinue: true,
|
|
453
|
-
* delay: {
|
|
454
|
-
* seconds: Math.min((context.attempt ?? 1) * 2, 60),
|
|
455
|
-
* },
|
|
456
|
-
* }
|
|
457
|
-
* },
|
|
458
|
-
* },
|
|
459
|
-
* )
|
|
460
|
-
* ```
|
|
461
|
-
* @param fn - Called on each attempt with the current state and durable context.
|
|
443
|
+
* @param initial - Initial state passed to the first poller call.
|
|
444
|
+
* @param poller - Called on each attempt with the current state and condition context.
|
|
445
|
+
* @param next - A function that determines whether the condition has been met or another check should be run.
|
|
462
446
|
* Returns a promise resolving to the updated state,
|
|
463
|
-
* which is passed to next to determine whether the condition has been met or another check should be
|
|
464
|
-
* @param options - Configuration options for the condition
|
|
447
|
+
* which is passed to next to determine whether the condition has been met or another check should be run.
|
|
465
448
|
* @returns The value returned by the executed function
|
|
466
449
|
*/
|
|
467
|
-
waitForCondition<T>(
|
|
468
|
-
|
|
450
|
+
waitForCondition<T>({ name, initial, next, poller, }: {
|
|
451
|
+
name?: string;
|
|
452
|
+
initial: T;
|
|
453
|
+
poller: DurableWaitForConditionPoller<T>;
|
|
454
|
+
next: DurableWaitForConditionNext<T>;
|
|
455
|
+
}): Promise<T>;
|
|
456
|
+
};
|
|
469
457
|
/**
|
|
470
458
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
471
459
|
* @hidden
|
package/package.json
CHANGED
package/src/invoke.ts
CHANGED
|
@@ -151,7 +151,7 @@ export async function invoke<T = unknown>(name: string, payload: FunctionPayload
|
|
|
151
151
|
if (!outgoingPayload?.context?.invoke) {
|
|
152
152
|
throw new Error(`No local invoke handler configured for function: ${name}`)
|
|
153
153
|
}
|
|
154
|
-
return await outgoingPayload.context.invoke(name, outgoingPayload, options)
|
|
154
|
+
return await outgoingPayload.context.invoke(name, outgoingPayload.event?.data ?? {}, options)
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
const aws = await getAwsLite()
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Callback provided by Sanity CLI when doing local development
|
|
2
|
+
* Callback provided by Sanity CLI when doing local development.
|
|
3
|
+
*
|
|
4
|
+
* The CLI receives the event data alone: it delivers it to the target function as
|
|
5
|
+
* `event.data` and derives the target's context from the calling function's own context.
|
|
3
6
|
*/
|
|
4
|
-
export type InvokeCallback = <T = unknown>(name: string, payload
|
|
7
|
+
export type InvokeCallback = <T = unknown>(name: string, payload?: Record<string, unknown>, options?: InvokeOptions) => Promise<T>
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Options provided to invoke
|
|
@@ -245,43 +248,43 @@ export type FunctionResourceEnvelope = {
|
|
|
245
248
|
[K in FunctionResourceKey]-?: {[P in K]: FunctionResource} & {[P in Exclude<FunctionResourceKey, K>]?: FunctionResource}
|
|
246
249
|
}[FunctionResourceKey]
|
|
247
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Durable alias of FunctionsContext
|
|
253
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
254
|
+
* @hidden
|
|
255
|
+
*/
|
|
256
|
+
export type DurableContext = FunctionContext
|
|
257
|
+
|
|
248
258
|
/**
|
|
249
259
|
* Logger interface for durables.
|
|
250
260
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
251
261
|
* @hidden
|
|
252
262
|
*/
|
|
253
263
|
export interface DurableLogger {
|
|
254
|
-
debug(
|
|
255
|
-
info(
|
|
256
|
-
warn(
|
|
257
|
-
error(
|
|
258
|
-
log(
|
|
264
|
+
debug(...params: unknown[]): void
|
|
265
|
+
info(...params: unknown[]): void
|
|
266
|
+
warn(...params: unknown[]): void
|
|
267
|
+
error(...params: unknown[]): void
|
|
268
|
+
log(...params: unknown[]): void
|
|
259
269
|
}
|
|
260
270
|
|
|
261
271
|
/**
|
|
262
|
-
* // @todo: follow-up to better define separated context
|
|
263
272
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
264
273
|
* @hidden
|
|
265
274
|
*/
|
|
266
|
-
export interface
|
|
275
|
+
export interface DurableStepCallbackContext {
|
|
267
276
|
logger: DurableLogger
|
|
268
277
|
}
|
|
269
278
|
|
|
270
279
|
/**
|
|
271
|
-
*
|
|
280
|
+
* Arguments passed to callbacks that execute a durable attempt.
|
|
281
|
+
* step.run & step.waitForCondition
|
|
272
282
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
273
283
|
* @hidden
|
|
274
284
|
*/
|
|
275
|
-
export
|
|
276
|
-
/**
|
|
277
|
-
|
|
278
|
-
* Only available in methods that expose the attempt like `waitForCondition`
|
|
279
|
-
*/
|
|
280
|
-
attempt?: number
|
|
281
|
-
/**
|
|
282
|
-
* Unique ID for a durable execution
|
|
283
|
-
*/
|
|
284
|
-
runId?: string
|
|
285
|
+
export interface DurableStepAttemptContext extends DurableStepCallbackContext {
|
|
286
|
+
/** Current attempt number, starting at 1. */
|
|
287
|
+
attempt: number
|
|
285
288
|
}
|
|
286
289
|
|
|
287
290
|
/**
|
|
@@ -300,16 +303,40 @@ export type DurableDuration =
|
|
|
300
303
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
301
304
|
* @hidden
|
|
302
305
|
*/
|
|
303
|
-
export type DurableWaitForConditionDecision = {
|
|
306
|
+
export type DurableWaitForConditionDecision = {shouldRetry: true; delay: DurableDuration} | {shouldRetry: false}
|
|
304
307
|
|
|
305
308
|
/**
|
|
306
309
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
307
310
|
* @hidden
|
|
308
311
|
*/
|
|
309
|
-
export
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
312
|
+
export type DurableStepHandler<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
316
|
+
* @hidden
|
|
317
|
+
*/
|
|
318
|
+
export type DurableStepRunHandler<T = unknown> = DurableStepHandler<[context: DurableStepAttemptContext], T | Promise<T>>
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
322
|
+
* @hidden
|
|
323
|
+
*/
|
|
324
|
+
export type DurableStepWaitForCallbackHandler = DurableStepHandler<[callbackId: string, context: DurableStepCallbackContext], Promise<void>>
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
328
|
+
* @hidden
|
|
329
|
+
*/
|
|
330
|
+
export type DurableWaitForConditionPoller<T = unknown> = DurableStepHandler<[state: T, context: DurableStepAttemptContext], Promise<T>>
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
334
|
+
* @hidden
|
|
335
|
+
*/
|
|
336
|
+
export type DurableWaitForConditionNext<T = unknown> = DurableStepHandler<
|
|
337
|
+
[state: T, context: Pick<DurableStepAttemptContext, 'attempt'>],
|
|
338
|
+
DurableWaitForConditionDecision
|
|
339
|
+
>
|
|
313
340
|
|
|
314
341
|
/**
|
|
315
342
|
* The interface defining the operations available to a durable function.
|
|
@@ -317,17 +344,26 @@ export interface DurableWaitForConditionOptions<T> {
|
|
|
317
344
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
318
345
|
* @hidden
|
|
319
346
|
*/
|
|
320
|
-
export
|
|
347
|
+
export type DurableOperations = {
|
|
321
348
|
/**
|
|
322
349
|
* Runs a named step. Its result is recorded, so if the workflow re-runs the step
|
|
323
350
|
* is not executed again. Failures are retried on their own.
|
|
324
351
|
* similar to ctx.step()
|
|
325
352
|
* @remarks cannot be nested inside another step
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* step.run({
|
|
356
|
+
* name: 'run-step',
|
|
357
|
+
* handler: async ({logger}) => {
|
|
358
|
+
* logger.log('Running step')
|
|
359
|
+
* }})
|
|
360
|
+
* ```
|
|
326
361
|
* @param name - Step name
|
|
327
|
-
* @param
|
|
362
|
+
* @param handler - function being executed
|
|
328
363
|
* @returns The value returned by the executed function
|
|
329
364
|
*/
|
|
330
|
-
run<T>(name
|
|
365
|
+
run<T>({name, handler}: {name?: string; handler: DurableStepRunHandler<T>}): Promise<T>
|
|
366
|
+
|
|
331
367
|
/**
|
|
332
368
|
* Calls another function and awaits its result.
|
|
333
369
|
* similar to ctx.invoke()
|
|
@@ -336,17 +372,17 @@ export interface DurableOperations {
|
|
|
336
372
|
* @param input - Data passed to the called function
|
|
337
373
|
* @returns The value returned by the called function
|
|
338
374
|
*/
|
|
339
|
-
delegate<T>(name: string
|
|
375
|
+
delegate<T>({name, input}: {name?: string; input?: unknown}): Promise<T>
|
|
340
376
|
|
|
341
377
|
/**
|
|
342
378
|
* Waits for an external callback
|
|
343
379
|
* similar to ctx.waitForCallback()
|
|
344
380
|
* @remarks cannot be nested inside another step
|
|
345
381
|
* @param name - Step name
|
|
346
|
-
* @param
|
|
382
|
+
* @param handler - Receives the generated callbackId and returns a delivered promise
|
|
347
383
|
* @returns The value returned by the executed function
|
|
348
384
|
*/
|
|
349
|
-
waitForCallback<T>(name
|
|
385
|
+
waitForCallback<T>({name, handler}: {name?: string; handler: DurableStepWaitForCallbackHandler}): Promise<T>
|
|
350
386
|
|
|
351
387
|
/**
|
|
352
388
|
* Waits for a specified duration
|
|
@@ -355,33 +391,18 @@ export interface DurableOperations {
|
|
|
355
391
|
* @example
|
|
356
392
|
* Wait for 30 seconds
|
|
357
393
|
* ```ts
|
|
358
|
-
* await step.wait('wait30Sec', { seconds: 30 });
|
|
394
|
+
* await step.wait({name: 'wait30Sec', duration: { seconds: 30 }});
|
|
359
395
|
* ```
|
|
360
396
|
* Wait for 2 days and 3 hours
|
|
361
397
|
* ```ts
|
|
362
|
-
* await step.wait('waitALongTime', { days: 2, hours: 3 });
|
|
398
|
+
* await step.wait({name: 'waitALongTime', duration: { days: 2, hours: 3 }});
|
|
363
399
|
* ```
|
|
364
400
|
* @param name - Step name
|
|
365
401
|
* @param duration - Amount of time the function will wait before continuing.
|
|
366
402
|
* Duration is an object with properties of `seconds`, `minutes`, `hours`, or `days`. Must be at least {seconds: 1}
|
|
367
403
|
* @returns Resolves after the duration
|
|
368
404
|
*/
|
|
369
|
-
wait(name: string
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Waits for a specified duration
|
|
373
|
-
* similar to ctx.wait()
|
|
374
|
-
* @remarks cannot be nested inside another step
|
|
375
|
-
* @example
|
|
376
|
-
* Wait for 30 seconds
|
|
377
|
-
* ```ts
|
|
378
|
-
* await step.wait({ seconds: 30 });
|
|
379
|
-
* ```
|
|
380
|
-
* @param duration - Amount of time the function will wait before continuing.
|
|
381
|
-
* Duration is an object with properties of `seconds`, `minutes`, `hours`, or `days`. Must be at least {seconds: 1}
|
|
382
|
-
* @returns Resolves after the duration
|
|
383
|
-
*/
|
|
384
|
-
wait(duration: DurableDuration): Promise<void>
|
|
405
|
+
wait({name, duration}: {name?: string; duration: DurableDuration}): Promise<void>
|
|
385
406
|
|
|
386
407
|
/**
|
|
387
408
|
* Waits for a specified condition to be met
|
|
@@ -389,31 +410,28 @@ export interface DurableOperations {
|
|
|
389
410
|
* @remarks cannot be nested inside another step
|
|
390
411
|
* @example
|
|
391
412
|
* ```ts
|
|
392
|
-
* await step.waitForCondition(
|
|
393
|
-
*
|
|
394
|
-
* async (state, {logger}) => {
|
|
395
|
-
* logger.log('Checking for article')
|
|
396
|
-
*
|
|
397
|
-
* const client = createClient({
|
|
398
|
-
* apiVersion: '2026-08-05',
|
|
399
|
-
* ...context.clientOptions,
|
|
400
|
-
* })
|
|
401
|
-
* const article = await client.fetch<Article | null>(
|
|
402
|
-
* '*[_type == "article"][0]',
|
|
403
|
-
* )
|
|
404
|
-
* return {...state, article}
|
|
405
|
-
* },
|
|
406
|
-
* {
|
|
413
|
+
* await step.waitForCondition({{
|
|
414
|
+
* name: 'waitForCondition',
|
|
407
415
|
* initial: {
|
|
408
|
-
* article: null
|
|
416
|
+
* article: null,
|
|
409
417
|
* },
|
|
410
|
-
*
|
|
411
|
-
*
|
|
418
|
+
* poller: async (state, {attempt}) => {
|
|
419
|
+
* const client = createClient({
|
|
420
|
+
* apiVersion: '2026-08-05',
|
|
421
|
+
* ...context.clientOptions,
|
|
422
|
+
* })
|
|
423
|
+
* const article = await client.fetch<Article | null>(
|
|
424
|
+
* '*[_type == "article"][0]',
|
|
425
|
+
* )
|
|
426
|
+
* return {...state, article}
|
|
427
|
+
* }
|
|
428
|
+
* next: (state, {attempt}) => {
|
|
429
|
+
* if (state.article) return {shouldResume: false}
|
|
412
430
|
*
|
|
413
431
|
* return {
|
|
414
|
-
*
|
|
432
|
+
* shouldResume: true,
|
|
415
433
|
* delay: {
|
|
416
|
-
* seconds: Math.min(
|
|
434
|
+
* seconds: Math.min(attempt * 2, 60),
|
|
417
435
|
* },
|
|
418
436
|
* }
|
|
419
437
|
* },
|
|
@@ -421,61 +439,24 @@ export interface DurableOperations {
|
|
|
421
439
|
* )
|
|
422
440
|
* ```
|
|
423
441
|
* @param name - Step name
|
|
424
|
-
* @param
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
* @param options - Configuration options for the condition
|
|
428
|
-
* @returns The value returned by the executed function
|
|
429
|
-
*/
|
|
430
|
-
waitForCondition<T>(
|
|
431
|
-
name: string,
|
|
432
|
-
fn: (state: T, args: BaseDurableOperationArgs) => Promise<T>,
|
|
433
|
-
options: DurableWaitForConditionOptions<T>,
|
|
434
|
-
): Promise<T>
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Waits for a specified condition to be met
|
|
438
|
-
* similar to ctx.waitForCondition()
|
|
439
|
-
* @remarks cannot be nested inside another step
|
|
440
|
-
* @example
|
|
441
|
-
* ```ts
|
|
442
|
-
* await step.waitForCondition(
|
|
443
|
-
* async (state, {logger}) => {
|
|
444
|
-
* logger.log('Checking for article')
|
|
445
|
-
*
|
|
446
|
-
* const client = createClient({
|
|
447
|
-
* apiVersion: '2026-08-05',
|
|
448
|
-
* ...context.clientOptions,
|
|
449
|
-
* })
|
|
450
|
-
* const article = await client.fetch<Article | null>(
|
|
451
|
-
* '*[_type == "article"][0]',
|
|
452
|
-
* )
|
|
453
|
-
* return {...state, article}
|
|
454
|
-
* },
|
|
455
|
-
* {
|
|
456
|
-
* initial: {
|
|
457
|
-
* article: null as Article | null,
|
|
458
|
-
* },
|
|
459
|
-
* next: (state, context) => {
|
|
460
|
-
* if (state.article) return {shouldContinue: false}
|
|
461
|
-
*
|
|
462
|
-
* return {
|
|
463
|
-
* shouldContinue: true,
|
|
464
|
-
* delay: {
|
|
465
|
-
* seconds: Math.min((context.attempt ?? 1) * 2, 60),
|
|
466
|
-
* },
|
|
467
|
-
* }
|
|
468
|
-
* },
|
|
469
|
-
* },
|
|
470
|
-
* )
|
|
471
|
-
* ```
|
|
472
|
-
* @param fn - Called on each attempt with the current state and durable context.
|
|
442
|
+
* @param initial - Initial state passed to the first poller call.
|
|
443
|
+
* @param poller - Called on each attempt with the current state and condition context.
|
|
444
|
+
* @param next - A function that determines whether the condition has been met or another check should be run.
|
|
473
445
|
* Returns a promise resolving to the updated state,
|
|
474
|
-
* which is passed to next to determine whether the condition has been met or another check should be
|
|
475
|
-
* @param options - Configuration options for the condition
|
|
446
|
+
* which is passed to next to determine whether the condition has been met or another check should be run.
|
|
476
447
|
* @returns The value returned by the executed function
|
|
477
448
|
*/
|
|
478
|
-
waitForCondition<T>(
|
|
449
|
+
waitForCondition<T>({
|
|
450
|
+
name,
|
|
451
|
+
initial,
|
|
452
|
+
next,
|
|
453
|
+
poller,
|
|
454
|
+
}: {
|
|
455
|
+
name?: string
|
|
456
|
+
initial: T
|
|
457
|
+
poller: DurableWaitForConditionPoller<T>
|
|
458
|
+
next: DurableWaitForConditionNext<T>
|
|
459
|
+
}): Promise<T>
|
|
479
460
|
}
|
|
480
461
|
|
|
481
462
|
/**
|