@sanity/functions 1.6.1 → 1.6.3
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/{definers.d.ts → src/definers.d.ts} +15 -2
- package/dist/{definers.js → src/definers.js} +17 -2
- package/dist/src/definers.js.map +1 -0
- package/dist/src/durables.js.map +1 -0
- package/dist/src/index.js.map +1 -0
- package/dist/{invoke.d.ts → src/invoke.d.ts} +0 -2
- package/dist/{invoke.js → src/invoke.js} +16 -6
- package/dist/src/invoke.js.map +1 -0
- package/dist/{types.d.ts → src/types.d.ts} +43 -39
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/definers.ts +21 -3
- package/src/invoke.ts +17 -8
- package/src/types.ts +44 -39
- package/dist/definers.js.map +0 -1
- package/dist/durables.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/invoke.js.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{durables.d.ts → src/durables.d.ts} +0 -0
- /package/dist/{durables.js → src/durables.js} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentEventHandler,
|
|
1
|
+
import type { DocumentEventHandler, PubSubEventHandler, ScheduledEventHandler, SyncTagInvalidateEventHandler } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Defines a "document event" function handler.
|
|
4
4
|
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
@@ -23,11 +23,24 @@ export declare function scheduledEventHandler(handler: ScheduledEventHandler): S
|
|
|
23
23
|
* @returns The handler function, unmodified.
|
|
24
24
|
*/
|
|
25
25
|
export declare function syncTagInvalidateEventHandler(handler: SyncTagInvalidateEventHandler): SyncTagInvalidateEventHandler;
|
|
26
|
+
/**
|
|
27
|
+
* Defines a "pubsub event" function handler.
|
|
28
|
+
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
29
|
+
*
|
|
30
|
+
* The handler's return type is inferred, so a pubsub function can resolve to a value that
|
|
31
|
+
* callers receive from `invoke(name, payload, {sync: true})`.
|
|
32
|
+
*
|
|
33
|
+
* @param handler - The event handler function to use.
|
|
34
|
+
* @returns The handler function, unmodified.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pubSubEventHandler<IData = any, IResult = void>(handler: PubSubEventHandler<IData, IResult>): PubSubEventHandler<IData, IResult>;
|
|
26
37
|
/**
|
|
27
38
|
* Defines a "generic" function handler.
|
|
28
39
|
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
29
40
|
*
|
|
41
|
+
* @deprecated Renamed to {@link pubSubEventHandler}. This alias will be removed in the next
|
|
42
|
+
* major version.
|
|
30
43
|
* @param handler - The event handler function to use.
|
|
31
44
|
* @returns The handler function, unmodified.
|
|
32
45
|
*/
|
|
33
|
-
export declare function eventHandler<IData = any>(handler:
|
|
46
|
+
export declare function eventHandler<IData = any, IResult = void>(handler: PubSubEventHandler<IData, IResult>): PubSubEventHandler<IData, IResult>;
|
|
@@ -35,15 +35,30 @@ export function syncTagInvalidateEventHandler(handler) {
|
|
|
35
35
|
return handler;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Defines a "
|
|
38
|
+
* Defines a "pubsub event" function handler.
|
|
39
39
|
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
40
40
|
*
|
|
41
|
+
* The handler's return type is inferred, so a pubsub function can resolve to a value that
|
|
42
|
+
* callers receive from `invoke(name, payload, {sync: true})`.
|
|
43
|
+
*
|
|
41
44
|
* @param handler - The event handler function to use.
|
|
42
45
|
* @returns The handler function, unmodified.
|
|
43
46
|
*/
|
|
44
|
-
export function
|
|
47
|
+
export function pubSubEventHandler(handler) {
|
|
45
48
|
if (typeof handler !== 'function')
|
|
46
49
|
throw new TypeError('`handler` must be a function');
|
|
47
50
|
return handler;
|
|
48
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Defines a "generic" function handler.
|
|
54
|
+
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
55
|
+
*
|
|
56
|
+
* @deprecated Renamed to {@link pubSubEventHandler}. This alias will be removed in the next
|
|
57
|
+
* major version.
|
|
58
|
+
* @param handler - The event handler function to use.
|
|
59
|
+
* @returns The handler function, unmodified.
|
|
60
|
+
*/
|
|
61
|
+
export function eventHandler(handler) {
|
|
62
|
+
return pubSubEventHandler(handler);
|
|
63
|
+
}
|
|
49
64
|
//# sourceMappingURL=definers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definers.js","sourceRoot":"","sources":["../../src/definers.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAc,OAAoC;IACpF,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA8B;IAClE,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAsC;IAClF,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAA2C;IAE3C,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAA8B,OAA2C;I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MAAM,CAAC,OAAyB,EAAE,EAAC,MAAM,EAAC,CAAC,CAAA;AAC3D,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAC,aAAa,EAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
|
@@ -26,8 +26,6 @@ export declare function buildLineageToken(name: string, lineage: string | undefi
|
|
|
26
26
|
* event source and nothing is returned. Pass `{sync: true}` to invoke the function and
|
|
27
27
|
* wait for its return value.
|
|
28
28
|
*
|
|
29
|
-
* @alpha Experimental / preview function not ready for use
|
|
30
|
-
* @hidden
|
|
31
29
|
* @param name - Name of the function to invoke
|
|
32
30
|
* @param payload - The `{event, context}` envelope to deliver
|
|
33
31
|
* @param options - Set `sync: true` to wait for and return the function's result
|
|
@@ -109,6 +109,20 @@ export async function invoke(name, payload, options) {
|
|
|
109
109
|
const stringPayload = JSON.stringify(outgoingPayload);
|
|
110
110
|
// Check to make sure payload is not over the max we can handle
|
|
111
111
|
checkPayloadSize(stringPayload, sync);
|
|
112
|
+
// Make sure we can invoke this function type
|
|
113
|
+
const contextResource = payload?.context?.resources?.(name);
|
|
114
|
+
const functionType = contextResource?.type;
|
|
115
|
+
if (sync === true) {
|
|
116
|
+
if (functionType === undefined) {
|
|
117
|
+
throw new Error(`Function ${name} cannot be invoked synchronously.`);
|
|
118
|
+
}
|
|
119
|
+
if (functionType !== 'sanity.function.pubsub') {
|
|
120
|
+
throw new Error(`Function ${name} of type ${functionType} cannot be invoked synchronously.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (functionType !== 'sanity.function.pubsub' && functionType !== 'sanity.function.queue') {
|
|
124
|
+
throw new Error(`No invokeable resource for function: ${name}`);
|
|
125
|
+
}
|
|
112
126
|
// Local invoke path for Sanity CLI
|
|
113
127
|
if (outgoingPayload?.context?.local) {
|
|
114
128
|
if (!outgoingPayload?.context?.invoke) {
|
|
@@ -121,15 +135,11 @@ export async function invoke(name, payload, options) {
|
|
|
121
135
|
throw new Error(`Unable to invoke function: ${name}`);
|
|
122
136
|
// Look up the function details
|
|
123
137
|
const resource = await getResource(name, aws);
|
|
124
|
-
const contextResource = payload?.context?.resources?.(name);
|
|
125
138
|
// Synchronous invocation
|
|
126
139
|
if (sync === true) {
|
|
127
140
|
if (!resource.function || !contextResource) {
|
|
128
141
|
throw new Error(`Function ${name} cannot be invoked synchronously.`);
|
|
129
142
|
}
|
|
130
|
-
if (contextResource.type !== 'sanity.function.pubsub') {
|
|
131
|
-
throw new Error(`Function ${name} of type ${contextResource.type} cannot be invoked synchronously.`);
|
|
132
|
-
}
|
|
133
143
|
const { Payload, FunctionError } = await aws.Lambda.Invoke({
|
|
134
144
|
FunctionName: resource.function.physicalResourceId,
|
|
135
145
|
Payload: outgoingPayload,
|
|
@@ -143,13 +153,13 @@ export async function invoke(name, payload, options) {
|
|
|
143
153
|
return Payload;
|
|
144
154
|
}
|
|
145
155
|
// Async invocation by type
|
|
146
|
-
if (resource.topic &&
|
|
156
|
+
if (resource.topic && functionType === 'sanity.function.pubsub') {
|
|
147
157
|
await aws.SNS.Publish({
|
|
148
158
|
TopicArn: resource.topic.physicalResourceId,
|
|
149
159
|
Message: stringPayload,
|
|
150
160
|
});
|
|
151
161
|
}
|
|
152
|
-
else if (resource.queue &&
|
|
162
|
+
else if (resource.queue && functionType === 'sanity.function.queue') {
|
|
153
163
|
await aws.SQS.SendMessage({
|
|
154
164
|
MessageBody: stringPayload,
|
|
155
165
|
QueueUrl: resource.queue.physicalResourceId,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke.js","sourceRoot":"","sources":["../../src/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,E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K,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"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Callback provided by Sanity CLI when doing local development
|
|
3
|
-
* @alpha
|
|
4
|
-
* @hidden
|
|
5
3
|
*/
|
|
6
4
|
export type InvokeCallback = <T = unknown>(name: string, payload: FunctionPayload, options?: InvokeOptions) => Promise<T>;
|
|
7
5
|
/**
|
|
8
6
|
* Options provided to invoke
|
|
9
|
-
* @alpha
|
|
10
|
-
* @hidden
|
|
11
7
|
*/
|
|
12
8
|
export type InvokeOptions = {
|
|
13
9
|
sync?: boolean;
|
|
@@ -138,18 +134,28 @@ export type GenericContext = FunctionContext | ScheduledFunctionContext | SyncTa
|
|
|
138
134
|
*/
|
|
139
135
|
export type GenericEvent = DocumentEvent | SyncTagInvalidateEvent;
|
|
140
136
|
/**
|
|
141
|
-
* A
|
|
137
|
+
* A function handler for a pubsub event.
|
|
142
138
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
139
|
+
* A pubsub function can be triggered by any event source, so the envelope is intentionally
|
|
140
|
+
* permissive and needs no narrowing: `context` is any supported context, `event` is any
|
|
141
|
+
* supported event, and `done` is optional (present only for sync-tag-invalidate events).
|
|
142
|
+
*
|
|
143
|
+
* `IResult` is the value the handler resolves to and defaults to `void`. Pubsub is the one
|
|
144
|
+
* function type that may be invoked with {@link invoke | `invoke(name, payload, {sync: true})`},
|
|
145
|
+
* which returns the handler's resolved value to the caller.
|
|
147
146
|
*/
|
|
148
|
-
export type
|
|
147
|
+
export type PubSubEventHandler<IData = any, IResult = void> = (envelope: {
|
|
149
148
|
context: GenericContext;
|
|
150
149
|
event: DocumentEvent<IData> | SyncTagInvalidateEvent;
|
|
151
150
|
done?: SyncTagInvalidateCallback;
|
|
152
|
-
}) =>
|
|
151
|
+
}) => IResult | Promise<IResult>;
|
|
152
|
+
/**
|
|
153
|
+
* A generic function handler that can receive the payload of any function type.
|
|
154
|
+
*
|
|
155
|
+
* @deprecated Renamed to {@link PubSubEventHandler}. This alias will be removed in the next
|
|
156
|
+
* major version.
|
|
157
|
+
*/
|
|
158
|
+
export type EventHandler<IData = any, IResult = void> = PubSubEventHandler<IData, IResult>;
|
|
153
159
|
/**
|
|
154
160
|
* A callback function to invoke once a sync-tag-invalidate event has been processed. Signals to Sanity that sync tag invalidation has completed.
|
|
155
161
|
*/
|
|
@@ -228,29 +234,32 @@ export type FunctionResourceEnvelope = {
|
|
|
228
234
|
[P in Exclude<FunctionResourceKey, K>]?: FunctionResource;
|
|
229
235
|
};
|
|
230
236
|
}[FunctionResourceKey];
|
|
231
|
-
type DurableLogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
232
237
|
/**
|
|
233
|
-
*
|
|
234
|
-
* Exposes console.log through the durable context.
|
|
238
|
+
* Logger interface for durables.
|
|
235
239
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
236
240
|
* @hidden
|
|
237
241
|
*/
|
|
238
|
-
interface DurableLogger {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
export interface DurableLogger {
|
|
243
|
+
debug(message?: string, ...optionalParams: unknown[]): void;
|
|
244
|
+
info(message?: string, ...optionalParams: unknown[]): void;
|
|
245
|
+
warn(message?: string, ...optionalParams: unknown[]): void;
|
|
246
|
+
error(message?: string, ...optionalParams: unknown[]): void;
|
|
247
|
+
log(message?: string, ...optionalParams: unknown[]): void;
|
|
244
248
|
}
|
|
245
249
|
/**
|
|
250
|
+
* // @todo: follow-up to better define separated context
|
|
251
|
+
* @alpha Using durables is considered experimental and may change in the future.
|
|
252
|
+
* @hidden
|
|
253
|
+
*/
|
|
254
|
+
export interface BaseDurableOperationArgs {
|
|
255
|
+
logger: DurableLogger;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @todo: follow-up to better define separated context
|
|
246
259
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
247
260
|
* @hidden
|
|
248
261
|
*/
|
|
249
262
|
export type DurableContext = FunctionContext & {
|
|
250
|
-
/**
|
|
251
|
-
* Durable logger
|
|
252
|
-
*/
|
|
253
|
-
log: DurableLogger;
|
|
254
263
|
/**
|
|
255
264
|
* Current attempt of the active durable operation.
|
|
256
265
|
* Only available in methods that expose the attempt like `waitForCondition`
|
|
@@ -298,7 +307,7 @@ export type DurableWaitForConditionDecision = {
|
|
|
298
307
|
*/
|
|
299
308
|
export interface DurableWaitForConditionOptions<T> {
|
|
300
309
|
initial: T;
|
|
301
|
-
next: (state: T, context:
|
|
310
|
+
next: (state: T, context: BaseDurableOperationArgs) => DurableWaitForConditionDecision;
|
|
302
311
|
}
|
|
303
312
|
/**
|
|
304
313
|
* The interface defining the operations available to a durable function.
|
|
@@ -316,7 +325,7 @@ export interface DurableOperations {
|
|
|
316
325
|
* @param fn - function being executed
|
|
317
326
|
* @returns The value returned by the executed function
|
|
318
327
|
*/
|
|
319
|
-
run<T>(name: string, fn: (
|
|
328
|
+
run<T>(name: string, fn: (args: BaseDurableOperationArgs) => T | Promise<T>): Promise<T>;
|
|
320
329
|
/**
|
|
321
330
|
* Calls another function and awaits its result.
|
|
322
331
|
* similar to ctx.invoke()
|
|
@@ -334,7 +343,7 @@ export interface DurableOperations {
|
|
|
334
343
|
* @param fn - Receives the generated callbackId and returns a delivered promise
|
|
335
344
|
* @returns The value returned by the executed function
|
|
336
345
|
*/
|
|
337
|
-
waitForCallback<T>(name: string, fn: (callbackId: string,
|
|
346
|
+
waitForCallback<T>(name: string, fn: (callbackId: string, args: BaseDurableOperationArgs) => Promise<void>): Promise<T>;
|
|
338
347
|
/**
|
|
339
348
|
* Waits for a specified duration
|
|
340
349
|
* similar to ctx.wait()
|
|
@@ -376,11 +385,8 @@ export interface DurableOperations {
|
|
|
376
385
|
* ```ts
|
|
377
386
|
* await step.waitForCondition(
|
|
378
387
|
* 'waitForCondition',
|
|
379
|
-
* async (state,
|
|
380
|
-
*
|
|
381
|
-
* runId: context.runId,
|
|
382
|
-
* attempt: context.attempt,
|
|
383
|
-
* })
|
|
388
|
+
* async (state, {logger}) => {
|
|
389
|
+
* logger.log('Checking for article')
|
|
384
390
|
*
|
|
385
391
|
* const client = createClient({
|
|
386
392
|
* apiVersion: '2026-08-05',
|
|
@@ -415,7 +421,7 @@ export interface DurableOperations {
|
|
|
415
421
|
* @param options - Configuration options for the condition
|
|
416
422
|
* @returns The value returned by the executed function
|
|
417
423
|
*/
|
|
418
|
-
waitForCondition<T>(name: string, fn: (state: T,
|
|
424
|
+
waitForCondition<T>(name: string, fn: (state: T, args: BaseDurableOperationArgs) => Promise<T>, options: DurableWaitForConditionOptions<T>): Promise<T>;
|
|
419
425
|
/**
|
|
420
426
|
* Waits for a specified condition to be met
|
|
421
427
|
* similar to ctx.waitForCondition()
|
|
@@ -423,11 +429,8 @@ export interface DurableOperations {
|
|
|
423
429
|
* @example
|
|
424
430
|
* ```ts
|
|
425
431
|
* await step.waitForCondition(
|
|
426
|
-
* async (state,
|
|
427
|
-
*
|
|
428
|
-
* runId: context.runId,
|
|
429
|
-
* attempt: context.attempt,
|
|
430
|
-
* })
|
|
432
|
+
* async (state, {logger}) => {
|
|
433
|
+
* logger.log('Checking for article')
|
|
431
434
|
*
|
|
432
435
|
* const client = createClient({
|
|
433
436
|
* apiVersion: '2026-08-05',
|
|
@@ -461,7 +464,7 @@ export interface DurableOperations {
|
|
|
461
464
|
* @param options - Configuration options for the condition
|
|
462
465
|
* @returns The value returned by the executed function
|
|
463
466
|
*/
|
|
464
|
-
waitForCondition<T>(fn: (state: T,
|
|
467
|
+
waitForCondition<T>(fn: (state: T, args: BaseDurableOperationArgs) => Promise<T>, options: DurableWaitForConditionOptions<T>): Promise<T>;
|
|
465
468
|
}
|
|
466
469
|
/**
|
|
467
470
|
* @alpha Using durables is considered experimental and may change in the future.
|
|
@@ -471,5 +474,6 @@ export type DurableHandler = (envelope: {
|
|
|
471
474
|
context: DurableContext;
|
|
472
475
|
event?: GenericEvent;
|
|
473
476
|
step: DurableOperations;
|
|
477
|
+
logger: DurableLogger;
|
|
474
478
|
}) => unknown | Promise<unknown>;
|
|
475
479
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|