@sanity/blueprints 0.26.1 → 0.28.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 +22 -0
- package/dist/definers/functions/durable.d.ts +0 -1
- package/dist/definers/functions/durable.js +5 -5
- 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/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/functions/index.d.ts +64 -12
- package/dist/types/installation-config.d.ts +2 -0
- package/dist/types/resources.d.ts +11 -5
- 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/utils/parse-duration.d.ts +9 -0
- package/dist/utils/parse-duration.js +30 -0
- package/dist/utils/parse-duration.js.map +1 -0
- package/dist/validation/functions.d.ts +9 -0
- package/dist/validation/functions.js +67 -10
- package/dist/validation/functions.js.map +1 -1
- package/package.json +19 -7
- package/src/definers/functions/durable.ts +5 -5
- package/src/definers/functions/queue.ts +3 -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/functions/index.ts +76 -21
- package/src/types/installation-config.ts +3 -0
- package/src/types/resources.ts +11 -5
- package/src/utils/debounce.ts +53 -0
- package/src/utils/parse-duration.ts +38 -0
- package/src/validation/functions.ts +79 -13
|
@@ -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
|
}
|
|
@@ -576,7 +569,7 @@ export function validateDurableFunction(functionResource: unknown): BlueprintErr
|
|
|
576
569
|
errors.push({type: 'invalid_value', message: '`durableTimeout` must be at least 60 seconds'})
|
|
577
570
|
}
|
|
578
571
|
if (functionResource.durableTimeout > 31_536_000) {
|
|
579
|
-
errors.push({type: 'invalid_value', message: '`durableTimeout` must be at most a year
|
|
572
|
+
errors.push({type: 'invalid_value', message: '`durableTimeout` must be at most a year'})
|
|
580
573
|
}
|
|
581
574
|
}
|
|
582
575
|
|
|
@@ -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
|
+
}
|