@sanity/blueprints 0.14.0 → 0.15.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/functions.d.ts +34 -1
- package/dist/definers/functions.js +47 -5
- package/dist/definers/functions.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/functions/event.d.ts +101 -0
- package/dist/types/functions/event.js +3 -0
- package/dist/types/functions/event.js.map +1 -0
- package/dist/types/{functions.d.ts → functions/index.d.ts} +45 -98
- package/dist/types/{functions.js → functions/index.js} +3 -2
- package/dist/types/functions/index.js.map +1 -0
- package/dist/validation/functions.d.ts +9 -0
- package/dist/validation/functions.js +80 -64
- package/dist/validation/functions.js.map +1 -1
- package/package.json +6 -6
- package/src/definers/functions.ts +59 -7
- package/src/index.ts +1 -1
- package/src/types/functions/event.ts +120 -0
- package/src/types/{functions.ts → functions/index.ts} +54 -112
- package/src/validation/functions.ts +79 -58
- package/dist/types/functions.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BlueprintBaseFunctionConfig, type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionConfig, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type BlueprintMediaLibraryAssetFunctionConfig, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintScheduledFunctionConfig, type BlueprintScheduledFunctionResource } from '../index.js';
|
|
1
|
+
import { type BlueprintBaseFunctionConfig, type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionConfig, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type BlueprintMediaLibraryAssetFunctionConfig, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintScheduledFunctionConfig, type BlueprintScheduledFunctionResource, type BlueprintSyncTagInvalidateFunctionConfig, type BlueprintSyncTagInvalidateFunctionResource } from '../index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Defines a function that is triggered by document events in Sanity datasets.
|
|
4
4
|
*
|
|
@@ -91,6 +91,38 @@ export declare function defineScheduledFunction(functionConfig: BlueprintSchedul
|
|
|
91
91
|
* @hidden
|
|
92
92
|
*/
|
|
93
93
|
export declare function defineScheduleFunction(functionConfig: BlueprintScheduledFunctionConfig): BlueprintScheduledFunctionResource;
|
|
94
|
+
/**
|
|
95
|
+
* Defines a function that is triggered on a sync tag invalidate event.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Using implicit event scoping to all datasets in the function project:
|
|
99
|
+
* ```ts
|
|
100
|
+
* defineSyncTagInvalidateFunction({
|
|
101
|
+
* name: 'bustin-caches',
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* Using explicit event scoping to a particular dataset in the function project:
|
|
106
|
+
* ```ts
|
|
107
|
+
* defineSyncTagInvalidateFunction({
|
|
108
|
+
* name: 'bustin-caches',
|
|
109
|
+
* event: {
|
|
110
|
+
* resource: {
|
|
111
|
+
* type: 'dataset',
|
|
112
|
+
* id: 'myProj.myDataset',
|
|
113
|
+
* },
|
|
114
|
+
* },
|
|
115
|
+
* })
|
|
116
|
+
* ```
|
|
117
|
+
* @public
|
|
118
|
+
* @alpha Deploying Sync Tag Invalidate Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
119
|
+
* @hidden
|
|
120
|
+
* @category Definers
|
|
121
|
+
* @expandType BlueprintSyncTagInvalidateFunctionConfig
|
|
122
|
+
* @param functionConfig The configuration for the sync tag invalidate function
|
|
123
|
+
* @returns The validated sync tag invalidate function resource
|
|
124
|
+
*/
|
|
125
|
+
export declare function defineSyncTagInvalidateFunction(functionConfig: BlueprintSyncTagInvalidateFunctionConfig): BlueprintSyncTagInvalidateFunctionResource;
|
|
94
126
|
/**
|
|
95
127
|
* Defines a base function resource with common properties.
|
|
96
128
|
*
|
|
@@ -103,4 +135,5 @@ export declare function defineScheduleFunction(functionConfig: BlueprintSchedule
|
|
|
103
135
|
*/
|
|
104
136
|
export declare function defineFunction(functionConfig: BlueprintBaseFunctionConfig, options?: {
|
|
105
137
|
skipValidation?: boolean;
|
|
138
|
+
scopeType?: 'organization';
|
|
106
139
|
}): BlueprintBaseFunctionResource;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateDocumentFunction, validateFunction, validateMediaLibraryAssetFunction, validateScheduledFunction, } from '../index.js';
|
|
1
|
+
import { validateDocumentFunction, validateFunction, validateMediaLibraryAssetFunction, validateScheduledFunction, validateSyncTagInvalidateFunction, } from '../index.js';
|
|
2
2
|
import { parseScheduledExpression } from '../utils/schedule-parser.js';
|
|
3
3
|
import { runValidation } from '../utils/validation.js';
|
|
4
4
|
const BASE_EVENT_KEYS = new Set(['on', 'filter', 'projection', 'includeDrafts']);
|
|
@@ -134,18 +134,18 @@ export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
|
134
134
|
export function defineScheduledFunction(functionConfig) {
|
|
135
135
|
const { event, timezone } = functionConfig;
|
|
136
136
|
const functionResource = {
|
|
137
|
-
...defineFunction(functionConfig, { skipValidation: true }),
|
|
137
|
+
...defineFunction(functionConfig, { skipValidation: true, scopeType: 'organization' }),
|
|
138
138
|
type: 'sanity.function.cron',
|
|
139
139
|
event: buildScheduledFunctionEvent(event),
|
|
140
140
|
};
|
|
141
141
|
if (timezone)
|
|
142
142
|
functionResource.timezone = timezone;
|
|
143
|
-
runValidation(() => validateScheduledFunction(functionResource));
|
|
144
143
|
// Always normalize to explicit fields (minute, hour, dayOfWeek, month, dayOfMonth)
|
|
145
|
-
if ('expression' in functionResource.event && functionResource.event.expression) {
|
|
144
|
+
if ('expression' in functionResource.event && typeof functionResource.event.expression === 'string') {
|
|
146
145
|
const cron = parseScheduledExpression(functionResource.event.expression);
|
|
147
146
|
functionResource.event = cronStringToExplicitEvent(cron);
|
|
148
147
|
}
|
|
148
|
+
runValidation(() => validateScheduledFunction(functionResource));
|
|
149
149
|
return functionResource;
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
@@ -155,6 +155,47 @@ export function defineScheduledFunction(functionConfig) {
|
|
|
155
155
|
export function defineScheduleFunction(functionConfig) {
|
|
156
156
|
return defineScheduledFunction(functionConfig);
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Defines a function that is triggered on a sync tag invalidate event.
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* Using implicit event scoping to all datasets in the function project:
|
|
163
|
+
* ```ts
|
|
164
|
+
* defineSyncTagInvalidateFunction({
|
|
165
|
+
* name: 'bustin-caches',
|
|
166
|
+
* })
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* Using explicit event scoping to a particular dataset in the function project:
|
|
170
|
+
* ```ts
|
|
171
|
+
* defineSyncTagInvalidateFunction({
|
|
172
|
+
* name: 'bustin-caches',
|
|
173
|
+
* event: {
|
|
174
|
+
* resource: {
|
|
175
|
+
* type: 'dataset',
|
|
176
|
+
* id: 'myProj.myDataset',
|
|
177
|
+
* },
|
|
178
|
+
* },
|
|
179
|
+
* })
|
|
180
|
+
* ```
|
|
181
|
+
* @public
|
|
182
|
+
* @alpha Deploying Sync Tag Invalidate Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
183
|
+
* @hidden
|
|
184
|
+
* @category Definers
|
|
185
|
+
* @expandType BlueprintSyncTagInvalidateFunctionConfig
|
|
186
|
+
* @param functionConfig The configuration for the sync tag invalidate function
|
|
187
|
+
* @returns The validated sync tag invalidate function resource
|
|
188
|
+
*/
|
|
189
|
+
export function defineSyncTagInvalidateFunction(functionConfig) {
|
|
190
|
+
const { event } = functionConfig;
|
|
191
|
+
const functionResource = {
|
|
192
|
+
...defineFunction(functionConfig, { skipValidation: true }),
|
|
193
|
+
type: 'sanity.function.sync-tag-invalidate',
|
|
194
|
+
...(event?.resource ? { event } : {}),
|
|
195
|
+
};
|
|
196
|
+
runValidation(() => validateSyncTagInvalidateFunction(functionResource));
|
|
197
|
+
return functionResource;
|
|
198
|
+
}
|
|
158
199
|
/**
|
|
159
200
|
* Defines a base function resource with common properties.
|
|
160
201
|
*
|
|
@@ -176,9 +217,10 @@ export function defineFunction(functionConfig, options) {
|
|
|
176
217
|
memory,
|
|
177
218
|
env,
|
|
178
219
|
robotToken,
|
|
179
|
-
project,
|
|
180
220
|
runtime,
|
|
181
221
|
};
|
|
222
|
+
if (options?.scopeType !== 'organization' && project)
|
|
223
|
+
functionResource.project = project;
|
|
182
224
|
if (lifecycle)
|
|
183
225
|
functionResource.lifecycle = lifecycle;
|
|
184
226
|
if (options?.skipValidation !== true)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAkBL,wBAAwB,EACxB,gBAAgB,EAChB,iCAAiC,EACjC,yBAAyB,EACzB,iCAAiC,GAClC,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,wBAAwB,EAAC,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAGpD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA;AAEtG,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B,CAAC,oBAAoB,EAAE,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAE9H,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAA+B,CAAC,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAIjH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,YAA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AAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+CAA+C,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,KAAK,CAAA;IAC1D,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAC,CAAA;AACrD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export * from './types/blueprints.js';
|
|
|
28
28
|
export * from './types/cors.js';
|
|
29
29
|
export * from './types/datasets.js';
|
|
30
30
|
export * from './types/errors.js';
|
|
31
|
-
export * from './types/functions.js';
|
|
31
|
+
export * from './types/functions/index.js';
|
|
32
32
|
export * from './types/projects.js';
|
|
33
33
|
export * from './types/resources.js';
|
|
34
34
|
export * from './types/robots.js';
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export * from './types/blueprints.js';
|
|
|
30
30
|
export * from './types/cors.js';
|
|
31
31
|
export * from './types/datasets.js';
|
|
32
32
|
export * from './types/errors.js';
|
|
33
|
-
export * from './types/functions.js';
|
|
33
|
+
export * from './types/functions/index.js';
|
|
34
34
|
export * from './types/projects.js';
|
|
35
35
|
export * from './types/resources.js';
|
|
36
36
|
export * from './types/robots.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD;;;GAGG;AACH;;;GAGG;AACH,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AACpC,cAA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,CAAA;AAExC,yEAAyE;AACzE;;;GAGG"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base event configuration shared by document and media library function types
|
|
3
|
+
* @category Functions Types
|
|
4
|
+
*/
|
|
5
|
+
export interface BlueprintFunctionBaseResourceEvent {
|
|
6
|
+
/**
|
|
7
|
+
* Event types that trigger the function
|
|
8
|
+
* @defaultValue ['publish']
|
|
9
|
+
*/
|
|
10
|
+
on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]];
|
|
11
|
+
/** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
|
|
12
|
+
filter?: string;
|
|
13
|
+
/** GROQ projection to specify which fields to include (e.g., "{_id, title, slug}") */
|
|
14
|
+
projection?: `{${string}}`;
|
|
15
|
+
/** Include draft documents in addition to published documents */
|
|
16
|
+
includeDrafts?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Event configuration for document functions
|
|
20
|
+
* @category Functions Types
|
|
21
|
+
*/
|
|
22
|
+
export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
23
|
+
/** Include all versions of documents, not just the current version */
|
|
24
|
+
includeAllVersions?: boolean;
|
|
25
|
+
/** Optional dataset resource scoping for the function */
|
|
26
|
+
resource?: BlueprintFunctionResourceEventResourceDataset;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Event configuration for media library asset functions
|
|
30
|
+
* @category Functions Types
|
|
31
|
+
*/
|
|
32
|
+
export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
33
|
+
/** Media library resource scoping (required for media library functions) */
|
|
34
|
+
resource: BlueprintFunctionResourceEventResourceMediaLibrary;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Event configuration for sync tag invalidate functions
|
|
38
|
+
* @category Functions Types
|
|
39
|
+
*/
|
|
40
|
+
export interface BlueprintSyncTagInvalidateFunctionResourceEvent {
|
|
41
|
+
/** Optional dataset resource scoping for the function */
|
|
42
|
+
resource?: BlueprintFunctionResourceEventResourceDataset;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Explicit resource event for scheduled functions to specific minutes, hours, days of month, months, and days of week
|
|
46
|
+
* @example { minute: '0', hour: '9', dayOfMonth: '1', month: '1', dayOfWeek: '1' }
|
|
47
|
+
* @category Functions Types
|
|
48
|
+
*/
|
|
49
|
+
export interface BlueprintScheduledFunctionExplicitResourceEvent {
|
|
50
|
+
minute: string;
|
|
51
|
+
hour: string;
|
|
52
|
+
dayOfMonth: string;
|
|
53
|
+
month: string;
|
|
54
|
+
dayOfWeek: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Expression resource for scheduled functions to specific expressions
|
|
58
|
+
* @example { expression: '0 9 * * *' }
|
|
59
|
+
* @category Functions Types
|
|
60
|
+
*/
|
|
61
|
+
export interface BlueprintScheduledFunctionExpressionResourceEvent {
|
|
62
|
+
expression: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Union type of all scheduled function resource events
|
|
66
|
+
* @category Functions Types
|
|
67
|
+
*/
|
|
68
|
+
export type BlueprintScheduledFunctionResourceEvent = BlueprintScheduledFunctionExplicitResourceEvent;
|
|
69
|
+
/**
|
|
70
|
+
* Union type of all scheduled function resource event configurations
|
|
71
|
+
* @category Functions Types
|
|
72
|
+
*/
|
|
73
|
+
export type BlueprintScheduledFunctionConfigEvent = BlueprintScheduledFunctionExplicitResourceEvent | BlueprintScheduledFunctionExpressionResourceEvent;
|
|
74
|
+
/**
|
|
75
|
+
* Union type of all function resource event configurations
|
|
76
|
+
* @category Functions Types
|
|
77
|
+
*/
|
|
78
|
+
export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent | BlueprintScheduledFunctionResourceEvent | BlueprintSyncTagInvalidateFunctionResourceEvent;
|
|
79
|
+
/**
|
|
80
|
+
* Dataset resource for scoping document functions to specific datasets
|
|
81
|
+
* @example { type: 'dataset', id: 'my-project.production' }
|
|
82
|
+
* @category Functions Types
|
|
83
|
+
*/
|
|
84
|
+
export interface BlueprintFunctionResourceEventResourceDataset {
|
|
85
|
+
type: 'dataset';
|
|
86
|
+
/** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
|
|
87
|
+
id: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Media library resource for scoping media library functions
|
|
91
|
+
* @category Functions Types
|
|
92
|
+
*/
|
|
93
|
+
export interface BlueprintFunctionResourceEventResourceMediaLibrary {
|
|
94
|
+
type: 'media-library';
|
|
95
|
+
id: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Events that can trigger a function
|
|
99
|
+
* @category Functions Types
|
|
100
|
+
*/
|
|
101
|
+
export type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/types/functions/event.ts"],"names":[],"mappings":"AAAA,+BAA+B"}
|
|
@@ -1,94 +1,8 @@
|
|
|
1
|
-
import type { BlueprintResource } from '
|
|
1
|
+
import type { BlueprintResource } from '../../index.js';
|
|
2
|
+
import type { BlueprintDocumentFunctionResourceEvent, BlueprintMediaLibraryFunctionResourceEvent, BlueprintScheduledFunctionConfigEvent, BlueprintScheduledFunctionResourceEvent, BlueprintSyncTagInvalidateFunctionResourceEvent } from './event.js';
|
|
3
|
+
export * from './event.js';
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @category Functions Types
|
|
5
|
-
*/
|
|
6
|
-
export interface BlueprintFunctionBaseResourceEvent {
|
|
7
|
-
/**
|
|
8
|
-
* Event types that trigger the function
|
|
9
|
-
* @defaultValue ['publish']
|
|
10
|
-
*/
|
|
11
|
-
on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]];
|
|
12
|
-
/** GROQ filter expression to match specific documents (e.g., "_type == 'post'") */
|
|
13
|
-
filter?: string;
|
|
14
|
-
/** GROQ projection to specify which fields to include (e.g., "{_id, title, slug}") */
|
|
15
|
-
projection?: `{${string}}`;
|
|
16
|
-
/** Include draft documents in addition to published documents */
|
|
17
|
-
includeDrafts?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Event configuration for document functions
|
|
21
|
-
* @category Functions Types
|
|
22
|
-
*/
|
|
23
|
-
export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
24
|
-
/** Include all versions of documents, not just the current version */
|
|
25
|
-
includeAllVersions?: boolean;
|
|
26
|
-
/** Optional dataset resource scoping for the function */
|
|
27
|
-
resource?: BlueprintFunctionResourceEventResourceDataset;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Event configuration for media library asset functions
|
|
31
|
-
* @category Functions Types
|
|
32
|
-
*/
|
|
33
|
-
export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
|
|
34
|
-
/** Media library resource scoping (required for media library functions) */
|
|
35
|
-
resource: BlueprintFunctionResourceEventResourceMediaLibrary;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Union type of all function resource event configurations
|
|
39
|
-
* @category Functions Types
|
|
40
|
-
*/
|
|
41
|
-
export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent;
|
|
42
|
-
/**
|
|
43
|
-
* Explicit resource event for scheduled functions to specific minutes, hours, days of month, months, and days of week
|
|
44
|
-
* @example { minute: '0', hour: '9', dayOfMonth: '1', month: '1', dayOfWeek: '1' }
|
|
45
|
-
* @category Functions Types
|
|
46
|
-
*/
|
|
47
|
-
export interface BlueprintScheduledFunctionExplicitResourceEvent {
|
|
48
|
-
minute: string;
|
|
49
|
-
hour: string;
|
|
50
|
-
dayOfMonth: string;
|
|
51
|
-
month: string;
|
|
52
|
-
dayOfWeek: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Expression resource for scheduled functions to specific expressions
|
|
56
|
-
* @example { expression: '0 9 * * *' }
|
|
57
|
-
* @category Functions Types
|
|
58
|
-
*/
|
|
59
|
-
export interface BlueprintScheduledFunctionExpressionResourceEvent {
|
|
60
|
-
expression: string;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Union type of all scheduled function resource event configurations
|
|
64
|
-
* @category Functions Types
|
|
65
|
-
*/
|
|
66
|
-
export type BlueprintScheduledFunctionResourceEvent = BlueprintScheduledFunctionExplicitResourceEvent | BlueprintScheduledFunctionExpressionResourceEvent;
|
|
67
|
-
/**
|
|
68
|
-
* Dataset resource for scoping document functions to specific datasets
|
|
69
|
-
* @example { type: 'dataset', id: 'my-project.production' }
|
|
70
|
-
* @category Functions Types
|
|
71
|
-
*/
|
|
72
|
-
export interface BlueprintFunctionResourceEventResourceDataset {
|
|
73
|
-
type: 'dataset';
|
|
74
|
-
/** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
|
|
75
|
-
id: string;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Media library resource for scoping media library functions
|
|
79
|
-
* @category Functions Types
|
|
80
|
-
*/
|
|
81
|
-
export interface BlueprintFunctionResourceEventResourceMediaLibrary {
|
|
82
|
-
type: 'media-library';
|
|
83
|
-
id: string;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Events that can trigger a function
|
|
87
|
-
* @category Functions Types
|
|
88
|
-
*/
|
|
89
|
-
export type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update';
|
|
90
|
-
/**
|
|
91
|
-
* Current support Function runtimes
|
|
5
|
+
* Supported Function runtimes
|
|
92
6
|
* @category Functions Types
|
|
93
7
|
*/
|
|
94
8
|
export declare const VALID_RUNTIMES: readonly ["node", "nodejs22.x", "nodejs24.x"];
|
|
@@ -101,7 +15,7 @@ export type FunctionRuntimes = (typeof VALID_RUNTIMES)[number];
|
|
|
101
15
|
* Base function resource with common properties for all function types
|
|
102
16
|
* @category Functions Types
|
|
103
17
|
*/
|
|
104
|
-
|
|
18
|
+
interface BlueprintCommonFunctionResource extends BlueprintResource {
|
|
105
19
|
/** Human-readable display name for the function */
|
|
106
20
|
displayName?: string;
|
|
107
21
|
/** Path to the function source code */
|
|
@@ -114,17 +28,23 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
|
|
|
114
28
|
env?: Record<string, string>;
|
|
115
29
|
/** Token provided during function invocation */
|
|
116
30
|
robotToken?: string;
|
|
117
|
-
/**
|
|
118
|
-
* The project ID of the project that contains your function.
|
|
119
|
-
*
|
|
120
|
-
* The `project` attribute must be defined if your blueprint is scoped to an organization. */
|
|
121
|
-
project?: string;
|
|
122
31
|
/**
|
|
123
32
|
* The runtime environment for the function (currently only Node.js is supported)
|
|
124
33
|
* @defaultValue 'nodejs24.x'
|
|
125
34
|
*/
|
|
126
35
|
runtime?: FunctionRuntimes;
|
|
127
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Base function resource with common properties for all function types that can belong to projects.
|
|
39
|
+
* @category Functions Types
|
|
40
|
+
*/
|
|
41
|
+
export interface BlueprintBaseFunctionResource extends BlueprintCommonFunctionResource {
|
|
42
|
+
/**
|
|
43
|
+
* The project ID of the project that contains your function.
|
|
44
|
+
*
|
|
45
|
+
* The `project` attribute must be defined if your blueprint is scoped to an organization. */
|
|
46
|
+
project?: string;
|
|
47
|
+
}
|
|
128
48
|
/**
|
|
129
49
|
* A function resource triggered by document events in Sanity datasets
|
|
130
50
|
* @category Functions Types
|
|
@@ -147,11 +67,19 @@ export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBas
|
|
|
147
67
|
* A function resource triggered by scheduled events
|
|
148
68
|
* @category Functions Types
|
|
149
69
|
*/
|
|
150
|
-
export interface BlueprintScheduledFunctionResource extends
|
|
70
|
+
export interface BlueprintScheduledFunctionResource extends BlueprintCommonFunctionResource {
|
|
151
71
|
type: 'sanity.function.cron';
|
|
152
72
|
event: BlueprintScheduledFunctionResourceEvent;
|
|
153
73
|
timezone?: string;
|
|
154
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* A function resource triggered by sync tag invalidate events
|
|
77
|
+
* @category Functions Types
|
|
78
|
+
*/
|
|
79
|
+
export interface BlueprintSyncTagInvalidateFunctionResource extends BlueprintBaseFunctionResource {
|
|
80
|
+
type: 'sanity.function.sync-tag-invalidate';
|
|
81
|
+
event?: BlueprintSyncTagInvalidateFunctionResourceEvent;
|
|
82
|
+
}
|
|
155
83
|
/**
|
|
156
84
|
* Configuration for defining a base function.
|
|
157
85
|
* @internal
|
|
@@ -204,7 +132,26 @@ export type BlueprintMediaLibraryAssetFunctionConfig = Omit<BlueprintMediaLibrar
|
|
|
204
132
|
* @category Functions Types
|
|
205
133
|
* @interface
|
|
206
134
|
*/
|
|
207
|
-
export type BlueprintScheduledFunctionConfig = Omit<BlueprintScheduledFunctionResource, 'type' | 'src'> & {
|
|
135
|
+
export type BlueprintScheduledFunctionConfig = Omit<BlueprintScheduledFunctionResource, 'type' | 'src' | 'event'> & {
|
|
136
|
+
/**
|
|
137
|
+
* Path to the function source code
|
|
138
|
+
* @defaultValue `functions/${name}`
|
|
139
|
+
*/
|
|
140
|
+
src?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Event configuration specifying when the function is triggered
|
|
143
|
+
*/
|
|
144
|
+
event: BlueprintScheduledFunctionConfigEvent;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Configuration for defining a sync tag invalidate function.
|
|
148
|
+
* @public
|
|
149
|
+
* @alpha Deploying Sync Tag Invalidate Functions via Blueprints is experimental. This feature is not available publicly yet.
|
|
150
|
+
* @hidden
|
|
151
|
+
* @category Functions Types
|
|
152
|
+
* @interface
|
|
153
|
+
*/
|
|
154
|
+
export type BlueprintSyncTagInvalidateFunctionConfig = Omit<BlueprintSyncTagInvalidateFunctionResource, 'type' | 'src'> & {
|
|
208
155
|
/**
|
|
209
156
|
* Path to the function source code
|
|
210
157
|
* @defaultValue `functions/${name}`
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export * from './event.js';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Supported Function runtimes
|
|
3
4
|
* @category Functions Types
|
|
4
5
|
*/
|
|
5
6
|
export const VALID_RUNTIMES = ['node', 'nodejs22.x', 'nodejs24.x'];
|
|
6
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/functions/index.ts"],"names":[],"mappings":"AASA,cAAc,YAAY,CAAA;AAE1B;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAU,CAAA"}
|
|
@@ -32,3 +32,12 @@ export declare function validateFunction(functionResource: unknown): BlueprintEr
|
|
|
32
32
|
* @returns Array of validation errors, empty if valid
|
|
33
33
|
*/
|
|
34
34
|
export declare function validateScheduledFunction(functionResource: unknown): BlueprintError[];
|
|
35
|
+
/**
|
|
36
|
+
* Validates a sync tag invalidate function resource configuration.
|
|
37
|
+
* @param functionResource The function resource to validate
|
|
38
|
+
* @alpha
|
|
39
|
+
* @hidden
|
|
40
|
+
* @category Functions Types
|
|
41
|
+
* @returns Array of validation errors, empty if valid
|
|
42
|
+
*/
|
|
43
|
+
export declare function validateSyncTagInvalidateFunction(functionResource: unknown): BlueprintError[];
|