@sanity/blueprints 0.9.0 → 0.11.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/README.md +326 -14
- package/dist/definers/blueprints.d.ts +2 -0
- package/dist/definers/blueprints.js +2 -0
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +4 -0
- package/dist/definers/cors.js +4 -0
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +5 -0
- package/dist/definers/datasets.js +5 -0
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +41 -12
- package/dist/definers/functions.js +60 -16
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +2 -0
- package/dist/definers/resources.js +2 -0
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robots.d.ts +4 -0
- package/dist/definers/robots.js +4 -0
- package/dist/definers/robots.js.map +1 -1
- package/dist/definers/roles.d.ts +6 -0
- package/dist/definers/roles.js +6 -0
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +4 -0
- package/dist/definers/webhooks.js +4 -0
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +20 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/types/blueprints.d.ts +16 -4
- package/dist/types/cors.d.ts +4 -0
- package/dist/types/datasets.d.ts +14 -2
- package/dist/types/errors.d.ts +4 -1
- package/dist/types/functions.d.ts +81 -16
- package/dist/types/functions.js +5 -1
- package/dist/types/functions.js.map +1 -1
- package/dist/types/resources.d.ts +16 -1
- package/dist/types/robots.d.ts +12 -3
- package/dist/types/roles.d.ts +11 -3
- package/dist/types/webhooks.d.ts +18 -6
- package/dist/utils/schedule-parser.d.ts +42 -0
- package/dist/utils/schedule-parser.js +450 -0
- package/dist/utils/schedule-parser.js.map +1 -0
- package/dist/utils/validation.d.ts +1 -0
- package/dist/utils/validation.js +1 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/validation/blueprints.d.ts +1 -0
- package/dist/validation/blueprints.js +1 -0
- package/dist/validation/blueprints.js.map +1 -1
- package/dist/validation/cors.d.ts +1 -0
- package/dist/validation/cors.js +1 -0
- package/dist/validation/cors.js.map +1 -1
- package/dist/validation/datasets.d.ts +2 -0
- package/dist/validation/datasets.js +2 -0
- package/dist/validation/datasets.js.map +1 -1
- package/dist/validation/functions.d.ts +11 -0
- package/dist/validation/functions.js +37 -1
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/resources.d.ts +7 -1
- package/dist/validation/resources.js +23 -16
- package/dist/validation/resources.js.map +1 -1
- package/dist/validation/robots.d.ts +7 -0
- package/dist/validation/robots.js +7 -0
- package/dist/validation/robots.js.map +1 -1
- package/dist/validation/roles.d.ts +3 -1
- package/dist/validation/roles.js +3 -1
- package/dist/validation/roles.js.map +1 -1
- package/dist/validation/webhooks.d.ts +1 -0
- package/dist/validation/webhooks.js +1 -0
- package/dist/validation/webhooks.js.map +1 -1
- package/package.json +4 -1
- package/src/definers/blueprints.ts +2 -0
- package/src/definers/cors.ts +4 -0
- package/src/definers/datasets.ts +5 -0
- package/src/definers/functions.ts +65 -18
- package/src/definers/resources.ts +2 -0
- package/src/definers/robots.ts +4 -0
- package/src/definers/roles.ts +6 -0
- package/src/definers/webhooks.ts +4 -0
- package/src/index.ts +22 -0
- package/src/types/blueprints.ts +16 -4
- package/src/types/cors.ts +4 -0
- package/src/types/datasets.ts +14 -2
- package/src/types/errors.ts +4 -1
- package/src/types/functions.ts +93 -15
- package/src/types/resources.ts +16 -1
- package/src/types/robots.ts +12 -3
- package/src/types/roles.ts +11 -3
- package/src/types/webhooks.ts +18 -6
- package/src/utils/schedule-parser.ts +502 -0
- package/src/utils/validation.ts +1 -0
- package/src/validation/blueprints.ts +1 -0
- package/src/validation/cors.ts +1 -0
- package/src/validation/datasets.ts +2 -0
- package/src/validation/functions.ts +37 -0
- package/src/validation/resources.ts +24 -16
- package/src/validation/robots.ts +7 -0
- package/src/validation/roles.ts +3 -1
- package/src/validation/webhooks.ts +1 -0
|
@@ -3,8 +3,11 @@ import {
|
|
|
3
3
|
type BlueprintError,
|
|
4
4
|
type BlueprintFunctionBaseResourceEvent,
|
|
5
5
|
type BlueprintMediaLibraryFunctionResourceEvent,
|
|
6
|
+
type FunctionRuntimes,
|
|
7
|
+
VALID_RUNTIMES,
|
|
6
8
|
validateResource,
|
|
7
9
|
} from '../index.js'
|
|
10
|
+
import {validateScheduleExpression} from '../utils/schedule-parser.js'
|
|
8
11
|
|
|
9
12
|
type BaseFunctionEventKey = keyof BlueprintFunctionBaseResourceEvent
|
|
10
13
|
const BASE_EVENT_KEYS = new Set<BaseFunctionEventKey>(['on', 'filter', 'projection', 'includeDrafts'])
|
|
@@ -17,6 +20,7 @@ const MEDIA_LIBRARY_EVENT_KEYS = new Set<MediaLibraryFunctionEventKey>(['resourc
|
|
|
17
20
|
* Validates a document function resource configuration.
|
|
18
21
|
* Checks that the function has a valid event configuration, correct type, and all required base properties.
|
|
19
22
|
* @param functionResource The function resource to validate
|
|
23
|
+
* @category Functions Types
|
|
20
24
|
* @returns Array of validation errors, empty if valid
|
|
21
25
|
*/
|
|
22
26
|
export function validateDocumentFunction(functionResource: unknown): BlueprintError[] {
|
|
@@ -52,6 +56,7 @@ export function validateDocumentFunction(functionResource: unknown): BlueprintEr
|
|
|
52
56
|
* Validates a media library asset function resource configuration.
|
|
53
57
|
* Checks that the function has a valid event configuration with required resource, correct type, and all required base properties.
|
|
54
58
|
* @param functionResource The function resource to validate
|
|
59
|
+
* @category Functions Types
|
|
55
60
|
* @returns Array of validation errors, empty if valid
|
|
56
61
|
*/
|
|
57
62
|
export function validateMediaLibraryAssetFunction(functionResource: unknown): BlueprintError[] {
|
|
@@ -77,6 +82,7 @@ export function validateMediaLibraryAssetFunction(functionResource: unknown): Bl
|
|
|
77
82
|
* Validates base function resource properties.
|
|
78
83
|
* Checks that required fields (name, type) are present and that optional fields have correct types.
|
|
79
84
|
* @param functionResource The function resource to validate
|
|
85
|
+
* @internal
|
|
80
86
|
* @returns Array of validation errors, empty if valid
|
|
81
87
|
*/
|
|
82
88
|
export function validateFunction(functionResource: unknown): BlueprintError[] {
|
|
@@ -115,6 +121,12 @@ export function validateFunction(functionResource: unknown): BlueprintError[] {
|
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
if ('runtime' in functionResource) {
|
|
125
|
+
if (typeof functionResource.runtime !== 'undefined' && !VALID_RUNTIMES.includes(functionResource.runtime as FunctionRuntimes)) {
|
|
126
|
+
errors.push({type: 'invalid_value', message: `\`runtime\` must be one of ${VALID_RUNTIMES.join(', ')}`})
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
118
130
|
return errors
|
|
119
131
|
}
|
|
120
132
|
|
|
@@ -176,6 +188,14 @@ function validateMediaLibraryFunctionEvent(event: unknown): BlueprintError[] {
|
|
|
176
188
|
return errors
|
|
177
189
|
}
|
|
178
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Validates a schedule function resource configuration.
|
|
193
|
+
* @param functionResource The function resource to validate
|
|
194
|
+
* @alpha
|
|
195
|
+
* @hidden
|
|
196
|
+
* @category Functions Types
|
|
197
|
+
* @returns Array of validation errors, empty if valid
|
|
198
|
+
*/
|
|
179
199
|
export function validateScheduleFunction(functionResource: unknown): BlueprintError[] {
|
|
180
200
|
if (!functionResource) return [{type: 'invalid_value', message: 'Function config must be provided'}]
|
|
181
201
|
if (typeof functionResource !== 'object') return [{type: 'invalid_type', message: 'Function config must be an object'}]
|
|
@@ -201,6 +221,11 @@ export function validateScheduleFunction(functionResource: unknown): BlueprintEr
|
|
|
201
221
|
return errors
|
|
202
222
|
}
|
|
203
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Validates a schedule function event configuration.
|
|
226
|
+
* @param event The event configuration to validate
|
|
227
|
+
* @returns Array of validation errors, empty if valid
|
|
228
|
+
*/
|
|
204
229
|
function validateScheduleFunctionEvent(event: unknown): BlueprintError[] {
|
|
205
230
|
if (!event) return [{type: 'invalid_value', message: 'Function event must be provided'}]
|
|
206
231
|
if (typeof event !== 'object') return [{type: 'invalid_type', message: 'Function event must be an object'}]
|
|
@@ -220,6 +245,13 @@ function validateScheduleFunctionEvent(event: unknown): BlueprintError[] {
|
|
|
220
245
|
type: 'missing_parameter',
|
|
221
246
|
message: 'Either `expression` or explicit cron fields (`minute`, `hour`, `dayOfMonth`, `month`, `dayOfWeek`) must be provided',
|
|
222
247
|
})
|
|
248
|
+
} else if (hasExpression) {
|
|
249
|
+
const expr = (event as {expression: unknown}).expression
|
|
250
|
+
if (typeof expr !== 'string') {
|
|
251
|
+
errors.push({type: 'invalid_type', message: '`expression` must be a string'})
|
|
252
|
+
} else {
|
|
253
|
+
errors.push(...validateScheduleExpression(expr))
|
|
254
|
+
}
|
|
223
255
|
} else if (hasExplicitFields) {
|
|
224
256
|
if (!('minute' in event)) {
|
|
225
257
|
errors.push({
|
|
@@ -266,6 +298,11 @@ function validateScheduleFunctionEvent(event: unknown): BlueprintError[] {
|
|
|
266
298
|
return errors
|
|
267
299
|
}
|
|
268
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Validates a schedule function timezone configuration.
|
|
303
|
+
* @param timezone The timezone to validate
|
|
304
|
+
* @returns Array of validation errors, empty if valid
|
|
305
|
+
*/
|
|
269
306
|
function validateScheduleFunctionTimezone(timezone: unknown): BlueprintError[] {
|
|
270
307
|
if (typeof timezone !== 'string') return [{type: 'invalid_type', message: 'Function timezone must be a string'}]
|
|
271
308
|
|
|
@@ -5,48 +5,51 @@ import {runValidation} from '../utils/validation.js'
|
|
|
5
5
|
* Validates that the given resource is a valid resource.
|
|
6
6
|
* @param resource The resource
|
|
7
7
|
* @param options Validation options
|
|
8
|
+
* @internal
|
|
8
9
|
* @returns A list of validation errors
|
|
9
10
|
*/
|
|
10
|
-
export function validateResource(
|
|
11
|
-
if (!
|
|
12
|
-
if (typeof
|
|
11
|
+
export function validateResource(resource: unknown, options?: {projectContained?: boolean}): BlueprintError[] {
|
|
12
|
+
if (!resource) return [{type: 'invalid_value', message: 'Resource config must be provided'}]
|
|
13
|
+
if (typeof resource !== 'object') return [{type: 'invalid_type', message: 'Resource config must be an object'}]
|
|
13
14
|
|
|
14
15
|
const errors: BlueprintError[] = []
|
|
15
16
|
|
|
16
|
-
if (!('name' in
|
|
17
|
+
if (!('name' in resource)) {
|
|
17
18
|
errors.push({type: 'missing_parameter', message: '`name` is required'})
|
|
18
|
-
} else if (typeof
|
|
19
|
+
} else if (typeof resource.name !== 'string') {
|
|
19
20
|
errors.push({type: 'invalid_type', message: '`name` must be a string'})
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
if (!('type' in
|
|
23
|
+
if (!('type' in resource)) {
|
|
23
24
|
errors.push({type: 'missing_parameter', message: '`type` is required'})
|
|
24
|
-
} else if (typeof
|
|
25
|
+
} else if (typeof resource.type !== 'string') {
|
|
25
26
|
errors.push({type: 'invalid_type', message: '`type` must be a string'})
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
if ('lifecycle' in
|
|
29
|
-
if (typeof
|
|
29
|
+
if ('lifecycle' in resource) {
|
|
30
|
+
if (typeof resource.lifecycle !== 'object' || resource.lifecycle === null) {
|
|
30
31
|
errors.push({type: 'invalid_type', message: '`lifecycle` must be an object'})
|
|
31
32
|
} else {
|
|
32
|
-
if ('deletionPolicy' in
|
|
33
|
-
if (typeof
|
|
33
|
+
if ('deletionPolicy' in resource.lifecycle) {
|
|
34
|
+
if (typeof resource.lifecycle.deletionPolicy !== 'string') {
|
|
34
35
|
errors.push({type: 'invalid_type', message: '`deletionPolicy` must be a string'})
|
|
35
|
-
} else if (!['allow', 'retain', 'replace', 'protect'].includes(
|
|
36
|
+
} else if (!['allow', 'retain', 'replace', 'protect'].includes(resource.lifecycle.deletionPolicy)) {
|
|
36
37
|
errors.push({type: 'invalid_value', message: '`deletionPolicy` must be one of allow, retain, replace, protect'})
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
if ('ownershipAction' in
|
|
41
|
-
const
|
|
41
|
+
if ('ownershipAction' in resource.lifecycle) {
|
|
42
|
+
const ownershipActionTypes = ['attach', 'detach']
|
|
43
|
+
const ownershipAction = resource.lifecycle.ownershipAction
|
|
44
|
+
|
|
42
45
|
if (typeof ownershipAction !== 'object' || ownershipAction === null) {
|
|
43
46
|
errors.push({type: 'invalid_type', message: '`ownershipAction` must be an object'})
|
|
44
47
|
} else if (!('type' in ownershipAction)) {
|
|
45
48
|
errors.push({type: 'missing_parameter', message: '`ownershipAction.type` is required'})
|
|
46
49
|
} else if (typeof ownershipAction.type !== 'string') {
|
|
47
50
|
errors.push({type: 'invalid_type', message: '`ownershipAction.type` must be a string'})
|
|
48
|
-
} else if (!
|
|
49
|
-
errors.push({type: 'invalid_value', message:
|
|
51
|
+
} else if (!ownershipActionTypes.includes(ownershipAction.type)) {
|
|
52
|
+
errors.push({type: 'invalid_value', message: `\`ownershipAction.type\` must be one of ${ownershipActionTypes.join(', ')}`})
|
|
50
53
|
} else {
|
|
51
54
|
if (ownershipAction.type === 'attach') {
|
|
52
55
|
if (!('id' in ownershipAction)) {
|
|
@@ -71,6 +74,11 @@ export function validateResource(resourceConfig: unknown, options?: {projectCont
|
|
|
71
74
|
return errors
|
|
72
75
|
}
|
|
73
76
|
|
|
77
|
+
/**
|
|
78
|
+
* @param resource The resource
|
|
79
|
+
* @internal
|
|
80
|
+
* @returns The resource
|
|
81
|
+
*/
|
|
74
82
|
export function assertResource(resource: unknown): asserts resource is BlueprintResource {
|
|
75
83
|
runValidation(() => validateResource(resource))
|
|
76
84
|
}
|
package/src/validation/robots.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {type BlueprintError, validateResource} from '../index.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Validates that the given resource is a valid Robot.
|
|
5
5
|
* @param resource The Robot resource
|
|
6
|
+
* @category Validation
|
|
6
7
|
* @returns A list of validation errors
|
|
7
8
|
*/
|
|
8
9
|
export function validateRobot(resource: unknown): BlueprintError[] {
|
|
@@ -60,6 +61,12 @@ export function validateRobot(resource: unknown): BlueprintError[] {
|
|
|
60
61
|
return errors
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Validates that the given membership is a valid Robot membership.
|
|
66
|
+
* @param membership The membership to validate
|
|
67
|
+
* @internal
|
|
68
|
+
* @returns A list of validation errors
|
|
69
|
+
*/
|
|
63
70
|
export function validateRobotMembership(membership: unknown): BlueprintError[] {
|
|
64
71
|
if (!membership) return [{type: 'invalid_value', message: 'Membership config must be provided'}]
|
|
65
72
|
if (typeof membership !== 'object') return [{type: 'invalid_type', message: 'Membership config must be an object'}]
|
package/src/validation/roles.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {type BlueprintError, validateResource} from '../index.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Validates that the given resource is a valid Role.
|
|
5
5
|
* @param resource The Role resource
|
|
6
|
+
* @category Validation
|
|
6
7
|
* @returns A list of validation errors
|
|
7
8
|
*/
|
|
8
9
|
export function validateRole(resource: unknown): BlueprintError[] {
|
|
@@ -39,8 +40,9 @@ export function validateRole(resource: unknown): BlueprintError[] {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
* Validates that the given resource is a valid Role.
|
|
43
|
+
* Validates that the given resource is a valid Project Role.
|
|
43
44
|
* @param resource The Role resource
|
|
45
|
+
* @category Validation
|
|
44
46
|
* @returns A list of validation errors
|
|
45
47
|
*/
|
|
46
48
|
export function validateProjectRole(resource: unknown): BlueprintError[] {
|
|
@@ -3,6 +3,7 @@ import {type BlueprintError, validateResource} from '../index.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Validates that the given resource is a valid Document Webhook.
|
|
5
5
|
* @param resource The Document Webhook resource
|
|
6
|
+
* @category Validation
|
|
6
7
|
* @returns A list of validation errors
|
|
7
8
|
*/
|
|
8
9
|
export function validateDocumentWebhook(resource: unknown): BlueprintError[] {
|