@sanity/blueprints 0.27.0 → 0.29.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 +38 -14
- package/dist/definers/functions/durable.d.ts +0 -1
- package/dist/definers/functions/durable.js +3 -4
- package/dist/definers/functions/durable.js.map +1 -1
- package/dist/definers/functions/queue.js +3 -3
- package/dist/definers/functions/queue.js.map +1 -1
- package/dist/definers/functions/scheduled.d.ts +1 -3
- package/dist/definers/functions/scheduled.js +1 -3
- package/dist/definers/functions/scheduled.js.map +1 -1
- package/dist/resolve/by-name.d.ts +7 -0
- package/dist/resolve/by-name.js +13 -0
- package/dist/resolve/by-name.js.map +1 -0
- package/dist/resolve/import.d.ts +16 -0
- package/dist/resolve/import.js +48 -0
- package/dist/resolve/import.js.map +1 -0
- package/dist/resolve/index.d.ts +18 -0
- package/dist/resolve/index.js +19 -0
- package/dist/resolve/index.js.map +1 -0
- package/dist/resolve/load.d.ts +53 -0
- package/dist/resolve/load.js +155 -0
- package/dist/resolve/load.js.map +1 -0
- package/dist/resolve/stack-config.d.ts +49 -0
- package/dist/resolve/stack-config.js +108 -0
- package/dist/resolve/stack-config.js.map +1 -0
- package/dist/resolve/stack.d.ts +23 -0
- package/dist/resolve/stack.js +91 -0
- package/dist/resolve/stack.js.map +1 -0
- package/dist/resolve/types.d.ts +165 -0
- package/dist/resolve/types.js +2 -0
- package/dist/resolve/types.js.map +1 -0
- package/dist/types/applications.d.ts +3 -1
- package/dist/types/applications.js +1 -1
- package/dist/types/applications.js.map +1 -1
- package/dist/types/functions/index.d.ts +58 -10
- package/dist/types/installation-config.d.ts +2 -0
- package/dist/types/studios.d.ts +9 -1
- package/dist/types/studios.js.map +1 -1
- package/dist/utils/debounce.d.ts +20 -0
- package/dist/utils/debounce.js +46 -0
- package/dist/utils/debounce.js.map +1 -0
- package/dist/validation/functions.d.ts +9 -0
- package/dist/validation/functions.js +66 -9
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/resources.js +14 -4
- package/dist/validation/resources.js.map +1 -1
- package/package.json +22 -7
- package/src/definers/functions/durable.ts +3 -4
- package/src/definers/functions/queue.ts +3 -3
- package/src/definers/functions/scheduled.ts +1 -3
- package/src/resolve/by-name.ts +11 -0
- package/src/resolve/import.ts +52 -0
- package/src/resolve/index.ts +33 -0
- package/src/resolve/load.ts +166 -0
- package/src/resolve/stack-config.ts +116 -0
- package/src/resolve/stack.ts +100 -0
- package/src/resolve/types.ts +179 -0
- package/src/types/applications.ts +4 -1
- package/src/types/functions/index.ts +70 -19
- package/src/types/installation-config.ts +3 -0
- package/src/types/studios.ts +11 -1
- package/src/utils/debounce.ts +53 -0
- package/src/validation/functions.ts +78 -12
- package/src/validation/resources.ts +13 -4
|
@@ -63,15 +63,10 @@ interface QueueConfig {
|
|
|
63
63
|
*/
|
|
64
64
|
concurrency?: number
|
|
65
65
|
/**
|
|
66
|
-
* Debounce
|
|
67
|
-
*
|
|
68
|
-
*/
|
|
69
|
-
debounce?: number
|
|
70
|
-
/**
|
|
71
|
-
* Path used to group debounced events, e.g. 'document._id'
|
|
72
|
-
* @todo: not implemented - and should this always be provided with debounce window?
|
|
66
|
+
* Debounce configuration, with any durations already resolved to seconds.
|
|
67
|
+
* Definers accept the wider {@link DebounceInput} and parse it into this shape.
|
|
73
68
|
*/
|
|
74
|
-
|
|
69
|
+
debounce?: DebounceConfig
|
|
75
70
|
/**
|
|
76
71
|
* Whether to place messages that failed processing into a Dead Letter Queue.
|
|
77
72
|
* @todo: not implemented
|
|
@@ -87,6 +82,56 @@ interface QueueConfig {
|
|
|
87
82
|
fifo?: boolean
|
|
88
83
|
}
|
|
89
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Configuration used when debouncing Queue or Workflow function types.
|
|
87
|
+
* @category Functions Types
|
|
88
|
+
* @alpha
|
|
89
|
+
* @hidden
|
|
90
|
+
*/
|
|
91
|
+
export interface DebounceConfig {
|
|
92
|
+
/**
|
|
93
|
+
* Debounce window in seconds
|
|
94
|
+
*/
|
|
95
|
+
window: number
|
|
96
|
+
/**
|
|
97
|
+
* Maximum time in seconds to extend a debounce window from the first event
|
|
98
|
+
*/
|
|
99
|
+
maxWindow?: number
|
|
100
|
+
/**
|
|
101
|
+
* Dotted path into {event, context} used to debounce events
|
|
102
|
+
*/
|
|
103
|
+
key?: string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Debounce configuration as accepted by a function definer, before durations are parsed.
|
|
108
|
+
* @category Functions Types
|
|
109
|
+
* @alpha
|
|
110
|
+
* @hidden
|
|
111
|
+
*/
|
|
112
|
+
export interface DebounceConfigInput extends Omit<DebounceConfig, 'window' | 'maxWindow'> {
|
|
113
|
+
/**
|
|
114
|
+
* Debounce window
|
|
115
|
+
* A number is read as seconds, a string is parsed as a duration, e.g. `'5 minutes'`.
|
|
116
|
+
*/
|
|
117
|
+
window: string | number
|
|
118
|
+
/**
|
|
119
|
+
* Maximum time to extend a debounce window from the first event.
|
|
120
|
+
* Must be greater than `window`.
|
|
121
|
+
* A number is read as seconds, a string is parsed as a duration, e.g. `'1 hour'`.
|
|
122
|
+
*/
|
|
123
|
+
maxWindow?: string | number
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Debounce configuration accepted by a function definer, either as a bare duration
|
|
128
|
+
* used as the window, or as a full config.
|
|
129
|
+
* @category Functions Types
|
|
130
|
+
* @alpha
|
|
131
|
+
* @hidden
|
|
132
|
+
*/
|
|
133
|
+
export type DebounceInput = string | number | DebounceConfigInput
|
|
134
|
+
|
|
90
135
|
/**
|
|
91
136
|
* Base function resource with common properties for all function types that can belong to projects.
|
|
92
137
|
* @category Functions Types
|
|
@@ -262,17 +307,19 @@ export type BlueprintSyncTagInvalidateFunctionConfig = Omit<BlueprintSyncTagInva
|
|
|
262
307
|
* @category Functions Types
|
|
263
308
|
* @interface
|
|
264
309
|
*/
|
|
265
|
-
export type BlueprintQueueFunctionConfig = Omit<BlueprintQueueFunctionResource, 'type' | 'src' | 'event'> &
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
src?: string
|
|
310
|
+
export type BlueprintQueueFunctionConfig = Omit<BlueprintQueueFunctionResource, 'type' | 'src' | 'event' | 'debounce'> & {
|
|
311
|
+
/**
|
|
312
|
+
* Path to the function source code
|
|
313
|
+
* @defaultValue `functions/${name}`
|
|
314
|
+
*/
|
|
315
|
+
src?: string
|
|
272
316
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
317
|
+
/** Optional event configuration that triggers the queue function */
|
|
318
|
+
event?: BlueprintFunctionResourceContentLakeEvent
|
|
319
|
+
|
|
320
|
+
/** Optional debounce configuration, as a duration or a full config */
|
|
321
|
+
debounce?: DebounceInput
|
|
322
|
+
}
|
|
276
323
|
|
|
277
324
|
/**
|
|
278
325
|
* Configuration for defining an event function.
|
|
@@ -296,7 +343,7 @@ export type BlueprintPubSubFunctionConfig = Omit<BlueprintPubSubFunctionResource
|
|
|
296
343
|
* @category Functions Types
|
|
297
344
|
* @interface
|
|
298
345
|
*/
|
|
299
|
-
export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout'> & {
|
|
346
|
+
export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'type' | 'src' | 'event' | 'durableTimeout' | 'debounce'> & {
|
|
300
347
|
/**
|
|
301
348
|
* Path to the function source code
|
|
302
349
|
* @defaultValue `functions/${name}`
|
|
@@ -311,4 +358,8 @@ export type BlueprintDurableConfig = Omit<BlueprintDurableFunctionResource, 'typ
|
|
|
311
358
|
* @defaultValue 86_400 (24 hours)
|
|
312
359
|
*/
|
|
313
360
|
durableTimeout?: string | number
|
|
361
|
+
/**
|
|
362
|
+
* Optional debounce configuration, as a duration or a full config
|
|
363
|
+
*/
|
|
364
|
+
debounce?: DebounceInput
|
|
314
365
|
}
|
|
@@ -65,6 +65,9 @@ export interface BlueprintMediaLibraryConfigResource extends BlueprintInstallati
|
|
|
65
65
|
|
|
66
66
|
/** The local version of `sanity` at deployment. Populated during deployment. */
|
|
67
67
|
version?: string
|
|
68
|
+
|
|
69
|
+
/** Module federation manifest */
|
|
70
|
+
mfManifest?: Record<string, unknown>
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
package/src/types/studios.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {WorkspaceSchemaInput} from '@sanity/cli-build/_internal/manifest'
|
|
1
2
|
import type {ConfigEnv, InlineConfig} from 'vite'
|
|
2
3
|
import type {BlueprintProjectResourceLifecycle, BlueprintResource} from '../index.js'
|
|
3
4
|
|
|
@@ -81,8 +82,17 @@ export interface BlueprintStudioResource extends BlueprintResource<BlueprintProj
|
|
|
81
82
|
/** Whether or not to generate source maps. Defaults to false. */
|
|
82
83
|
sourceMap?: boolean
|
|
83
84
|
|
|
84
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Custom Vite configuration for the Studio so it can be changed and extended.
|
|
87
|
+
* Install vite to dev dependencies to get detailed type information.
|
|
88
|
+
*/
|
|
85
89
|
vite?: UserViteConfig
|
|
90
|
+
|
|
91
|
+
/** Schema inputs extracted from the studio's schema definition. */
|
|
92
|
+
schemaInputs?: WorkspaceSchemaInput[]
|
|
93
|
+
|
|
94
|
+
/** Module federation manifest */
|
|
95
|
+
mfManifest?: Record<string, unknown>
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
/**
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {BlueprintError} from '../types/errors.js'
|
|
2
|
+
import type {DebounceConfig, DebounceInput} from '../types/functions/index.js'
|
|
3
|
+
import {parseDuration} from './parse-duration.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes the debounce config accepted by a definer into the shape held by a resource,
|
|
7
|
+
* parsing any duration into seconds. A bare duration is shorthand for `{window: <duration>}`.
|
|
8
|
+
* @param debounce The debounce config or duration to normalize
|
|
9
|
+
* @internal
|
|
10
|
+
* @returns The debounce config, with `window` and `maxWindow` in seconds
|
|
11
|
+
*/
|
|
12
|
+
export function createDebounceObject(debounce: DebounceInput): DebounceConfig {
|
|
13
|
+
if (typeof debounce !== 'object') {
|
|
14
|
+
return {window: parseDuration(debounce, 's')}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {window, maxWindow, key} = debounce
|
|
18
|
+
|
|
19
|
+
// `window` is required, so there is nothing sensible to parse without it
|
|
20
|
+
if (window === undefined) {
|
|
21
|
+
throw new Error('Invalid debounce config: `window` must be provided')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
window: parseDuration(window, 's'),
|
|
26
|
+
...(maxWindow !== undefined && {maxWindow: parseDuration(maxWindow, 's')}),
|
|
27
|
+
...(key !== undefined && {key}),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a debounce duration, given either as a number of seconds or as a duration string, to seconds.
|
|
33
|
+
* @param field The name of the field being resolved, used in error messages
|
|
34
|
+
* @param value The value to resolve
|
|
35
|
+
* @returns The value in seconds, or the errors that prevented it from being resolved
|
|
36
|
+
*/
|
|
37
|
+
export function resolveDebounceDuration(field: string, value: unknown): {seconds?: number; errors: BlueprintError[]} {
|
|
38
|
+
if (typeof value === 'number') {
|
|
39
|
+
return Number.isFinite(value)
|
|
40
|
+
? {seconds: value, errors: []}
|
|
41
|
+
: {errors: [{type: 'invalid_value', message: `\`${field}\` must be a valid duration`}]}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (typeof value === 'string') {
|
|
45
|
+
try {
|
|
46
|
+
return {seconds: parseDuration(value, 's'), errors: []}
|
|
47
|
+
} catch {
|
|
48
|
+
return {errors: [{type: 'invalid_value', message: `\`${field}\` must be a valid duration`}]}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {errors: [{type: 'invalid_type', message: `\`${field}\` must be a number of seconds or a duration string`}]}
|
|
53
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
VALID_RUNTIMES,
|
|
8
8
|
validateResource,
|
|
9
9
|
} from '../index.js'
|
|
10
|
+
import {resolveDebounceDuration} from '../utils/debounce.js'
|
|
10
11
|
import {isReference} from '../utils/validation.js'
|
|
11
12
|
|
|
12
13
|
type BaseFunctionEventKey = keyof BlueprintFunctionBaseResourceEvent
|
|
@@ -469,6 +470,10 @@ export function validateQueueFunction(functionResource: unknown): BlueprintError
|
|
|
469
470
|
errors.push(...validateFunctionContentLakeEvent(functionResource.event))
|
|
470
471
|
}
|
|
471
472
|
|
|
473
|
+
if ('debounce' in functionResource) {
|
|
474
|
+
errors.push(...validateDebounceConfig(functionResource.debounce))
|
|
475
|
+
}
|
|
476
|
+
|
|
472
477
|
errors.push(...validateFunction(functionResource))
|
|
473
478
|
|
|
474
479
|
return errors
|
|
@@ -543,14 +548,6 @@ export function validateDurableFunction(functionResource: unknown): BlueprintErr
|
|
|
543
548
|
errors.push({type: 'invalid_value', message: '`type` must be `sanity.function.durable`'})
|
|
544
549
|
}
|
|
545
550
|
|
|
546
|
-
if ('debounceKey' in functionResource && typeof functionResource.debounceKey !== 'string') {
|
|
547
|
-
errors.push({type: 'invalid_type', message: '`debounceKey` must be a string'})
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
if ('debounceKey' in functionResource && !('debounce' in functionResource)) {
|
|
551
|
-
errors.push({type: 'invalid_value', message: '`debounceKey` requires a `debounce` to be set'})
|
|
552
|
-
}
|
|
553
|
-
|
|
554
551
|
if ('concurrency' in functionResource && typeof functionResource.concurrency !== 'number') {
|
|
555
552
|
errors.push({type: 'invalid_type', message: '`concurrency` must be a number'})
|
|
556
553
|
}
|
|
@@ -563,10 +560,6 @@ export function validateDurableFunction(functionResource: unknown): BlueprintErr
|
|
|
563
560
|
errors.push({type: 'invalid_value', message: '`concurrency` must be less than 500'})
|
|
564
561
|
}
|
|
565
562
|
|
|
566
|
-
if ('debounce' in functionResource && typeof functionResource.debounce !== 'number') {
|
|
567
|
-
errors.push({type: 'invalid_type', message: '`debounce` must be a number'})
|
|
568
|
-
}
|
|
569
|
-
|
|
570
563
|
if ('durableTimeout' in functionResource && typeof functionResource.durableTimeout !== 'number') {
|
|
571
564
|
errors.push({type: 'invalid_type', message: '`durableTimeout` must be a number'})
|
|
572
565
|
}
|
|
@@ -584,7 +577,80 @@ export function validateDurableFunction(functionResource: unknown): BlueprintErr
|
|
|
584
577
|
errors.push(...validateFunctionContentLakeEvent(functionResource.event))
|
|
585
578
|
}
|
|
586
579
|
|
|
580
|
+
if ('debounce' in functionResource) {
|
|
581
|
+
errors.push(...validateDebounceConfig(functionResource.debounce))
|
|
582
|
+
}
|
|
583
|
+
|
|
587
584
|
errors.push(...validateFunction(functionResource))
|
|
588
585
|
|
|
589
586
|
return errors
|
|
590
587
|
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Validates a debounce config.
|
|
591
|
+
* @param debounce The config to validate
|
|
592
|
+
* @alpha
|
|
593
|
+
* @hidden
|
|
594
|
+
* @category Functions Types
|
|
595
|
+
* @returns Array of validation errors, empty if valid
|
|
596
|
+
*/
|
|
597
|
+
export function validateDebounceConfig(debounce: unknown): BlueprintError[] {
|
|
598
|
+
if (debounce === undefined || debounce === null) {
|
|
599
|
+
return [{type: 'invalid_value', message: 'Debounce config must be provided'}]
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// A bare duration is shorthand for `{window: <duration>}`
|
|
603
|
+
if (typeof debounce === 'string' || typeof debounce === 'number') {
|
|
604
|
+
const resolved = resolveDebounceDuration('debounce', debounce)
|
|
605
|
+
return resolved.seconds === undefined ? resolved.errors : validateDebounceConfig({window: resolved.seconds})
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (typeof debounce !== 'object') return [{type: 'invalid_type', message: 'Debounce config must be an object'}]
|
|
609
|
+
|
|
610
|
+
const errors: BlueprintError[] = []
|
|
611
|
+
|
|
612
|
+
// each window is only kept when it is individually valid, so the comparison below doesn't pile onto an existing error
|
|
613
|
+
let window: number | undefined
|
|
614
|
+
let maxWindow: number | undefined
|
|
615
|
+
|
|
616
|
+
if (!('window' in debounce)) {
|
|
617
|
+
errors.push({type: 'missing_parameter', message: '`window` must be provided'})
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if ('window' in debounce) {
|
|
621
|
+
const resolved = resolveDebounceDuration('window', debounce.window)
|
|
622
|
+
errors.push(...resolved.errors)
|
|
623
|
+
|
|
624
|
+
if (resolved.seconds !== undefined) {
|
|
625
|
+
if (resolved.seconds < 1) {
|
|
626
|
+
errors.push({type: 'invalid_value', message: '`window` must be greater than 1 second'})
|
|
627
|
+
} else {
|
|
628
|
+
window = resolved.seconds
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if ('maxWindow' in debounce) {
|
|
634
|
+
const resolved = resolveDebounceDuration('maxWindow', debounce.maxWindow)
|
|
635
|
+
errors.push(...resolved.errors)
|
|
636
|
+
|
|
637
|
+
if (resolved.seconds !== undefined) {
|
|
638
|
+
if (resolved.seconds < 1) {
|
|
639
|
+
errors.push({type: 'invalid_value', message: '`maxWindow` must be greater than 1 second'})
|
|
640
|
+
} else {
|
|
641
|
+
maxWindow = resolved.seconds
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// `maxWindow` caps how far `window` can be extended from the first event, so it has to leave room to extend
|
|
647
|
+
if (window !== undefined && maxWindow !== undefined && maxWindow <= window) {
|
|
648
|
+
errors.push({type: 'invalid_value', message: '`maxWindow` must be greater than `window`'})
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if ('key' in debounce && typeof debounce.key !== 'string') {
|
|
652
|
+
errors.push({type: 'invalid_type', message: '`key` must be a string'})
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
return errors
|
|
656
|
+
}
|
|
@@ -82,10 +82,19 @@ export function validateResource(resource: unknown, options?: {projectContained?
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if ('dependsOn' in resource.lifecycle) {
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
if (Array.isArray(resource.lifecycle.dependsOn)) {
|
|
86
|
+
if (!resource.lifecycle.dependsOn.every((dep) => dep.startsWith('$.resources.'))) {
|
|
87
|
+
errors.push({
|
|
88
|
+
type: 'invalid_value',
|
|
89
|
+
message: '`lifecycle.dependsOn` elements must be resource references starting with `$.resources.`',
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
} else if (typeof resource.lifecycle.dependsOn === 'string') {
|
|
93
|
+
if (!resource.lifecycle.dependsOn.startsWith('$.resources.')) {
|
|
94
|
+
errors.push({type: 'invalid_value', message: '`lifecycle.dependsOn` must be a resource reference starting with `$.resources.`'})
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
errors.push({type: 'invalid_type', message: '`lifecycle.dependsOn` must be a string or an array'})
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
}
|