@sanity/functions 1.1.0 → 1.2.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/definers.d.ts +10 -1
- package/dist/definers.js +13 -0
- package/dist/definers.js.map +1 -1
- package/dist/types.d.ts +42 -0
- package/package.json +1 -1
- package/src/definers.ts +16 -1
- package/src/types.ts +45 -0
package/dist/definers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentEventHandler } from './types.js';
|
|
1
|
+
import type { DocumentEventHandler, ScheduleEventHandler } 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.
|
|
@@ -7,3 +7,12 @@ import type { DocumentEventHandler } from './types.js';
|
|
|
7
7
|
* @returns The handler function, unmodified.
|
|
8
8
|
*/
|
|
9
9
|
export declare function documentEventHandler<IData = any>(handler: DocumentEventHandler<IData>): DocumentEventHandler<IData>;
|
|
10
|
+
/**
|
|
11
|
+
* Defines a "scheduled event" function handler.
|
|
12
|
+
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
13
|
+
*
|
|
14
|
+
* @beta
|
|
15
|
+
* @param handler - The event handler function to use.
|
|
16
|
+
* @returns The handler function, unmodified.
|
|
17
|
+
*/
|
|
18
|
+
export declare function scheduleEventHandler(handler: ScheduleEventHandler): ScheduleEventHandler;
|
package/dist/definers.js
CHANGED
|
@@ -10,4 +10,17 @@ export function documentEventHandler(handler) {
|
|
|
10
10
|
throw new TypeError('`handler` must be a function');
|
|
11
11
|
return handler;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Defines a "scheduled event" function handler.
|
|
15
|
+
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
16
|
+
*
|
|
17
|
+
* @beta
|
|
18
|
+
* @param handler - The event handler function to use.
|
|
19
|
+
* @returns The handler function, unmodified.
|
|
20
|
+
*/
|
|
21
|
+
export function scheduleEventHandler(handler) {
|
|
22
|
+
if (typeof handler !== 'function')
|
|
23
|
+
throw new TypeError('`handler` must be a function');
|
|
24
|
+
return handler;
|
|
25
|
+
}
|
|
13
26
|
//# sourceMappingURL=definers.js.map
|
package/dist/definers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definers.js","sourceRoot":"","sources":["../src/definers.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAoC;IAEpC,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"definers.js","sourceRoot":"","sources":["../src/definers.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAoC;IAEpC,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAA6B;IAE7B,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;IACtF,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -40,6 +40,40 @@ export interface FunctionContext {
|
|
|
40
40
|
token: string;
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The context object passed to the schedule function handler.
|
|
45
|
+
*
|
|
46
|
+
* @beta
|
|
47
|
+
*/
|
|
48
|
+
export interface ScheduleFunctionContext {
|
|
49
|
+
/**
|
|
50
|
+
* `local` is set to `true` when testing your function locally.
|
|
51
|
+
* i.e. `sanity function test func-name`
|
|
52
|
+
* Otherwise, the property is not set.
|
|
53
|
+
*/
|
|
54
|
+
local?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Options that can be passed to a `@sanity/client` constructor to configure it
|
|
57
|
+
* against the project and dataset which triggered the event. Note that you should
|
|
58
|
+
* always specify an explicit `apiVersion` in YYYY-MM-DD format (e.g. `2025-05-01`).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* Constructing a client with the options from the context:
|
|
62
|
+
* ```ts
|
|
63
|
+
* const client = createClient({
|
|
64
|
+
* apiVersion: '2025-05-01',
|
|
65
|
+
* ...context.clientOptions,
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
* @beta
|
|
69
|
+
*/
|
|
70
|
+
clientOptions?: {
|
|
71
|
+
apiHost?: string;
|
|
72
|
+
dataset?: string;
|
|
73
|
+
projectId?: string;
|
|
74
|
+
token?: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
43
77
|
/**
|
|
44
78
|
* The event object received by the function handler in the case of a document event,
|
|
45
79
|
* such as a publish, unpublish, delete or mutation event and similar.
|
|
@@ -65,3 +99,11 @@ export type DocumentEventHandler<IData = any> = (envelope: {
|
|
|
65
99
|
context: FunctionContext;
|
|
66
100
|
event: DocumentEvent<IData>;
|
|
67
101
|
}) => void | Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* A function handler for a schedule event.
|
|
104
|
+
*
|
|
105
|
+
* @beta
|
|
106
|
+
*/
|
|
107
|
+
export type ScheduleEventHandler = (envelope: {
|
|
108
|
+
context: ScheduleFunctionContext;
|
|
109
|
+
}) => void | Promise<void>;
|
package/package.json
CHANGED
package/src/definers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {DocumentEventHandler} from './types.js'
|
|
1
|
+
import type { DocumentEventHandler, ScheduleEventHandler } from './types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Defines a "document event" function handler.
|
|
@@ -13,3 +13,18 @@ export function documentEventHandler<IData = any>(
|
|
|
13
13
|
if (typeof handler !== 'function') throw new TypeError('`handler` must be a function')
|
|
14
14
|
return handler
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Defines a "scheduled event" function handler.
|
|
19
|
+
* Returns the handler function as-is, only providing the types and doing basic validation.
|
|
20
|
+
*
|
|
21
|
+
* @beta
|
|
22
|
+
* @param handler - The event handler function to use.
|
|
23
|
+
* @returns The handler function, unmodified.
|
|
24
|
+
*/
|
|
25
|
+
export function scheduleEventHandler(
|
|
26
|
+
handler: ScheduleEventHandler,
|
|
27
|
+
): ScheduleEventHandler {
|
|
28
|
+
if (typeof handler !== 'function') throw new TypeError('`handler` must be a function')
|
|
29
|
+
return handler
|
|
30
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -41,6 +41,42 @@ export interface FunctionContext {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* The context object passed to the schedule function handler.
|
|
46
|
+
*
|
|
47
|
+
* @beta
|
|
48
|
+
*/
|
|
49
|
+
export interface ScheduleFunctionContext {
|
|
50
|
+
/**
|
|
51
|
+
* `local` is set to `true` when testing your function locally.
|
|
52
|
+
* i.e. `sanity function test func-name`
|
|
53
|
+
* Otherwise, the property is not set.
|
|
54
|
+
*/
|
|
55
|
+
local?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* Options that can be passed to a `@sanity/client` constructor to configure it
|
|
58
|
+
* against the project and dataset which triggered the event. Note that you should
|
|
59
|
+
* always specify an explicit `apiVersion` in YYYY-MM-DD format (e.g. `2025-05-01`).
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* Constructing a client with the options from the context:
|
|
63
|
+
* ```ts
|
|
64
|
+
* const client = createClient({
|
|
65
|
+
* apiVersion: '2025-05-01',
|
|
66
|
+
* ...context.clientOptions,
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
* @beta
|
|
70
|
+
*/
|
|
71
|
+
clientOptions?: {
|
|
72
|
+
apiHost?: string
|
|
73
|
+
dataset?: string
|
|
74
|
+
projectId?: string
|
|
75
|
+
token?: string
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
44
80
|
/**
|
|
45
81
|
* The event object received by the function handler in the case of a document event,
|
|
46
82
|
* such as a publish, unpublish, delete or mutation event and similar.
|
|
@@ -67,3 +103,12 @@ export type DocumentEventHandler<IData = any> = (envelope: {
|
|
|
67
103
|
context: FunctionContext
|
|
68
104
|
event: DocumentEvent<IData>
|
|
69
105
|
}) => void | Promise<void>
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A function handler for a schedule event.
|
|
109
|
+
*
|
|
110
|
+
* @beta
|
|
111
|
+
*/
|
|
112
|
+
export type ScheduleEventHandler = (envelope: {
|
|
113
|
+
context: ScheduleFunctionContext
|
|
114
|
+
}) => void | Promise<void>
|