@sanity/functions 1.2.0 → 1.2.1
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 +2 -2
- package/dist/definers.js +1 -1
- package/dist/definers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +11 -10
- package/src/definers.ts +3 -7
- package/src/index.ts +1 -1
- package/src/types.ts +3 -9
package/dist/definers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentEventHandler,
|
|
1
|
+
import type { DocumentEventHandler, ScheduledEventHandler } 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.
|
|
@@ -15,4 +15,4 @@ export declare function documentEventHandler<IData = any>(handler: DocumentEvent
|
|
|
15
15
|
* @param handler - The event handler function to use.
|
|
16
16
|
* @returns The handler function, unmodified.
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
18
|
+
export declare function scheduledEventHandler(handler: ScheduledEventHandler): ScheduledEventHandler;
|
package/dist/definers.js
CHANGED
|
@@ -18,7 +18,7 @@ export function documentEventHandler(handler) {
|
|
|
18
18
|
* @param handler - The event handler function to use.
|
|
19
19
|
* @returns The handler function, unmodified.
|
|
20
20
|
*/
|
|
21
|
-
export function
|
|
21
|
+
export function scheduledEventHandler(handler) {
|
|
22
22
|
if (typeof handler !== 'function')
|
|
23
23
|
throw new TypeError('`handler` must be a function');
|
|
24
24
|
return handler;
|
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,
|
|
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;;;;;;;GAOG;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"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface FunctionContext {
|
|
|
45
45
|
*
|
|
46
46
|
* @beta
|
|
47
47
|
*/
|
|
48
|
-
export interface
|
|
48
|
+
export interface ScheduledFunctionContext {
|
|
49
49
|
/**
|
|
50
50
|
* `local` is set to `true` when testing your function locally.
|
|
51
51
|
* i.e. `sanity function test func-name`
|
|
@@ -104,6 +104,6 @@ export type DocumentEventHandler<IData = any> = (envelope: {
|
|
|
104
104
|
*
|
|
105
105
|
* @beta
|
|
106
106
|
*/
|
|
107
|
-
export type
|
|
108
|
-
context:
|
|
107
|
+
export type ScheduledEventHandler = (envelope: {
|
|
108
|
+
context: ScheduledFunctionContext;
|
|
109
109
|
}) => void | Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/functions",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Helper methods and type definitions for Sanity Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -36,23 +36,24 @@
|
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "rimraf dist && tsc",
|
|
39
|
+
"lint": "biome check .",
|
|
40
|
+
"lint:write": "biome check --write .",
|
|
39
41
|
"coverage": "vitest --coverage",
|
|
40
|
-
"
|
|
42
|
+
"typecheck": "tsc --noEmit --project tsconfig.test.json",
|
|
41
43
|
"prepare": "npm run build",
|
|
42
44
|
"test": "vitest run --typecheck --reporter=verbose",
|
|
43
45
|
"test:watch": "vitest --typecheck --reporter=verbose"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"vitest": "3.1.2"
|
|
48
|
+
"@biomejs/biome": "2.3.12",
|
|
49
|
+
"@types/node": "^20",
|
|
50
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
51
|
+
"rimraf": "^6.1.2",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"vitest": "4.0.18"
|
|
53
54
|
},
|
|
54
55
|
"engines": {
|
|
55
|
-
"node": ">=20"
|
|
56
|
+
"node": ">=20.19"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|
package/src/definers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {DocumentEventHandler, ScheduledEventHandler} from './types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Defines a "document event" function handler.
|
|
@@ -7,9 +7,7 @@ import type { DocumentEventHandler, ScheduleEventHandler } from './types.js'
|
|
|
7
7
|
* @param handler - The event handler function to use.
|
|
8
8
|
* @returns The handler function, unmodified.
|
|
9
9
|
*/
|
|
10
|
-
export function documentEventHandler<IData = any>(
|
|
11
|
-
handler: DocumentEventHandler<IData>,
|
|
12
|
-
): DocumentEventHandler<IData> {
|
|
10
|
+
export function documentEventHandler<IData = any>(handler: DocumentEventHandler<IData>): DocumentEventHandler<IData> {
|
|
13
11
|
if (typeof handler !== 'function') throw new TypeError('`handler` must be a function')
|
|
14
12
|
return handler
|
|
15
13
|
}
|
|
@@ -22,9 +20,7 @@ export function documentEventHandler<IData = any>(
|
|
|
22
20
|
* @param handler - The event handler function to use.
|
|
23
21
|
* @returns The handler function, unmodified.
|
|
24
22
|
*/
|
|
25
|
-
export function
|
|
26
|
-
handler: ScheduleEventHandler,
|
|
27
|
-
): ScheduleEventHandler {
|
|
23
|
+
export function scheduledEventHandler(handler: ScheduledEventHandler): ScheduledEventHandler {
|
|
28
24
|
if (typeof handler !== 'function') throw new TypeError('`handler` must be a function')
|
|
29
25
|
return handler
|
|
30
26
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -46,7 +46,7 @@ export interface FunctionContext {
|
|
|
46
46
|
*
|
|
47
47
|
* @beta
|
|
48
48
|
*/
|
|
49
|
-
export interface
|
|
49
|
+
export interface ScheduledFunctionContext {
|
|
50
50
|
/**
|
|
51
51
|
* `local` is set to `true` when testing your function locally.
|
|
52
52
|
* i.e. `sanity function test func-name`
|
|
@@ -76,7 +76,6 @@ export interface ScheduleFunctionContext {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
79
|
/**
|
|
81
80
|
* The event object received by the function handler in the case of a document event,
|
|
82
81
|
* such as a publish, unpublish, delete or mutation event and similar.
|
|
@@ -99,16 +98,11 @@ export interface DocumentEvent<IData = any> {
|
|
|
99
98
|
*
|
|
100
99
|
* @beta
|
|
101
100
|
*/
|
|
102
|
-
export type DocumentEventHandler<IData = any> = (envelope: {
|
|
103
|
-
context: FunctionContext
|
|
104
|
-
event: DocumentEvent<IData>
|
|
105
|
-
}) => void | Promise<void>
|
|
101
|
+
export type DocumentEventHandler<IData = any> = (envelope: {context: FunctionContext; event: DocumentEvent<IData>}) => void | Promise<void>
|
|
106
102
|
|
|
107
103
|
/**
|
|
108
104
|
* A function handler for a schedule event.
|
|
109
105
|
*
|
|
110
106
|
* @beta
|
|
111
107
|
*/
|
|
112
|
-
export type
|
|
113
|
-
context: ScheduleFunctionContext
|
|
114
|
-
}) => void | Promise<void>
|
|
108
|
+
export type ScheduledEventHandler = (envelope: {context: ScheduledFunctionContext}) => void | Promise<void>
|