@sanity/runtime-cli 17.17.0 → 17.18.0-next.g0d44f9b

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 CHANGED
@@ -45,8 +45,8 @@ All `sanity-run` commands can also be run as `sanity <command>` when `@sanity/cl
45
45
  USAGE
46
46
  $ sanity-run blueprints add TYPE [--json] [--example <value> | -n <value> | --fn-type
47
47
  document-publish|document-create|document-delete|document-update|media-library-asset-create|media-library-asset-dele
48
- te|media-library-asset-update|pub-sub|scheduled-function|sync-tag-invalidate... | --language ts|js | --javascript |
49
- --fn-helpers | --fn-installer skip|npm|pnpm|yarn] [-i | ]
48
+ te|media-library-asset-update|pub-sub|scheduled-function|sync-tag-invalidate|durable-function... | --language ts|js
49
+ | --javascript | --fn-helpers | --fn-installer skip|npm|pnpm|yarn] [-i | ]
50
50
 
51
51
  ARGUMENTS
52
52
  TYPE (function) Type of resource to add (only "function" is supported)
@@ -63,7 +63,7 @@ FLAGS
63
63
  events by specifying this flag multiple times
64
64
  <options: document-publish|document-create|document-delete|document-update|media-library-
65
65
  asset-create|media-library-asset-delete|media-library-asset-update|pub-sub|scheduled-func
66
- tion|sync-tag-invalidate>
66
+ tion|sync-tag-invalidate|durable-function>
67
67
  --javascript Use JavaScript instead of TypeScript
68
68
  --json Format output as json
69
69
  --language=<option> [default: ts] Language of the new function
@@ -90,7 +90,7 @@ EXAMPLES
90
90
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
91
91
  ```
92
92
 
93
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/add.ts)_
93
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/add.ts)_
94
94
 
95
95
  ## `sanity-run blueprints config`
96
96
 
@@ -127,7 +127,7 @@ EXAMPLES
127
127
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
128
128
  ```
129
129
 
130
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/config.ts)_
130
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/config.ts)_
131
131
 
132
132
  ## `sanity-run blueprints deploy`
133
133
 
@@ -183,7 +183,7 @@ EXAMPLES
183
183
  $ sanity-run blueprints deploy --new-stack-name <new-name>
184
184
  ```
185
185
 
186
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/deploy.ts)_
186
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/deploy.ts)_
187
187
 
188
188
  ## `sanity-run blueprints destroy`
189
189
 
@@ -221,7 +221,7 @@ EXAMPLES
221
221
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
222
222
  ```
223
223
 
224
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/destroy.ts)_
224
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/destroy.ts)_
225
225
 
226
226
  ## `sanity-run blueprints doctor`
227
227
 
@@ -253,7 +253,7 @@ EXAMPLES
253
253
  $ sanity-run blueprints doctor --fix
254
254
  ```
255
255
 
256
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/doctor.ts)_
256
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/doctor.ts)_
257
257
 
258
258
  ## `sanity-run blueprints info`
259
259
 
@@ -291,7 +291,7 @@ EXAMPLES
291
291
  $ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
292
292
  ```
293
293
 
294
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/info.ts)_
294
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/info.ts)_
295
295
 
296
296
  ## `sanity-run blueprints init [DIR]`
297
297
 
@@ -355,7 +355,7 @@ EXAMPLES
355
355
  $ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
356
356
  ```
357
357
 
358
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/init.ts)_
358
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/init.ts)_
359
359
 
360
360
  ## `sanity-run blueprints logs`
361
361
 
@@ -401,7 +401,7 @@ EXAMPLES
401
401
  $ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
402
402
  ```
403
403
 
404
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/logs.ts)_
404
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/logs.ts)_
405
405
 
406
406
  ## `sanity-run blueprints mint-deploy-token`
407
407
 
@@ -446,7 +446,7 @@ EXAMPLES
446
446
  $ sanity-run blueprints mint-deploy-token --organization-id <orgId>
447
447
  ```
448
448
 
449
- _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/mint-deploy-token.ts)_
449
+ _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/mint-deploy-token.ts)_
450
450
 
451
451
  ## `sanity-run blueprints plan`
452
452
 
@@ -479,7 +479,7 @@ EXAMPLES
479
479
  $ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
480
480
  ```
481
481
 
482
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/plan.ts)_
482
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/plan.ts)_
483
483
 
484
484
  ## `sanity-run blueprints promote`
485
485
 
@@ -515,7 +515,7 @@ EXAMPLES
515
515
  $ sanity-run blueprints promote --new-stack-name <new-name>
516
516
  ```
517
517
 
518
- _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/promote.ts)_
518
+ _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/promote.ts)_
519
519
 
520
520
  ## `sanity-run blueprints stacks`
521
521
 
@@ -556,7 +556,7 @@ EXAMPLES
556
556
  $ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
557
557
  ```
558
558
 
559
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/blueprints/stacks.ts)_
559
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/blueprints/stacks.ts)_
560
560
 
561
561
  ## `sanity-run functions add`
562
562
 
@@ -566,8 +566,8 @@ Add a Function to your Blueprint
566
566
  USAGE
567
567
  $ sanity-run functions add [--json] [--example <value> | -n <value> | --type
568
568
  document-publish|document-create|document-delete|document-update|media-library-asset-create|media-library-asset-dele
569
- te|media-library-asset-update|pub-sub|scheduled-function|sync-tag-invalidate... | --language ts|js | --javascript |
570
- --helpers | --installer skip|npm|pnpm|yarn | -i]
569
+ te|media-library-asset-update|pub-sub|scheduled-function|sync-tag-invalidate|durable-function... | --language ts|js
570
+ | --javascript | --helpers | --installer skip|npm|pnpm|yarn | -i]
571
571
 
572
572
  FLAGS
573
573
  -i, --install Shortcut for --installer npm
@@ -584,7 +584,7 @@ FLAGS
584
584
  by specifying this flag multiple times
585
585
  <options: document-publish|document-create|document-delete|document-update|media-library-ass
586
586
  et-create|media-library-asset-delete|media-library-asset-update|pub-sub|scheduled-function|s
587
- ync-tag-invalidate>
587
+ ync-tag-invalidate|durable-function>
588
588
 
589
589
  DESCRIPTION
590
590
  Add a Function to your Blueprint
@@ -608,7 +608,7 @@ EXAMPLES
608
608
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
609
609
  ```
610
610
 
611
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/add.ts)_
611
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/add.ts)_
612
612
 
613
613
  ## `sanity-run functions dev`
614
614
 
@@ -643,7 +643,7 @@ EXAMPLES
643
643
  $ sanity-run functions dev --timeout 60
644
644
  ```
645
645
 
646
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/dev.ts)_
646
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/dev.ts)_
647
647
 
648
648
  ## `sanity-run functions env add NAME KEY VALUE`
649
649
 
@@ -676,7 +676,7 @@ EXAMPLES
676
676
  $ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
677
677
  ```
678
678
 
679
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/env/add.ts)_
679
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/env/add.ts)_
680
680
 
681
681
  ## `sanity-run functions env list NAME`
682
682
 
@@ -706,7 +706,7 @@ EXAMPLES
706
706
  $ sanity-run functions env list --stack <name-or-id> MyFunction
707
707
  ```
708
708
 
709
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/env/list.ts)_
709
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/env/list.ts)_
710
710
 
711
711
  ## `sanity-run functions env remove NAME KEY`
712
712
 
@@ -738,7 +738,7 @@ EXAMPLES
738
738
  $ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
739
739
  ```
740
740
 
741
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/env/remove.ts)_
741
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/env/remove.ts)_
742
742
 
743
743
  ## `sanity-run functions logs [NAME]`
744
744
 
@@ -778,7 +778,7 @@ EXAMPLES
778
778
  $ sanity-run functions logs <name> --delete
779
779
  ```
780
780
 
781
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/logs.ts)_
781
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/logs.ts)_
782
782
 
783
783
  ## `sanity-run functions test [NAME]`
784
784
 
@@ -836,7 +836,7 @@ EXAMPLES
836
836
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
837
837
  ```
838
838
 
839
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.17.0/src/commands/functions/test.ts)_
839
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.18.0-next.g0d44f9b/src/commands/functions/test.ts)_
840
840
 
841
841
  ## `sanity-run help [COMMAND]`
842
842
 
@@ -2,7 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { cwd } from 'node:process';
5
- import { MAP_EVENT_TO_FUNCTION_TYPE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PUBSUB, SANITY_FUNCTION_SCHEDULED, SANITY_FUNCTION_SYNC_TAG_INVALIDATE, } from '../../constants.js';
5
+ import { MAP_EVENT_TO_FUNCTION_TYPE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_DURABLE, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PUBSUB, SANITY_FUNCTION_SCHEDULED, SANITY_FUNCTION_SYNC_TAG_INVALIDATE, } from '../../constants.js';
6
6
  import { styleText } from '../../utils/style-text.js';
7
7
  import { writeOrUpdateNodeDependency } from '../node.js';
8
8
  import { addResourceToBlueprint } from './blueprint.js';
@@ -42,6 +42,89 @@ export const handler = pubSubEventHandler(async ({ context, event }) => {
42
42
  const time = new Date().toLocaleTimeString()
43
43
  console.log(\`Your pubsub Sanity Function was called at \${time}\`)
44
44
  })`;
45
+ const DEFAULT_DURABLE_HELPER_FUNCTION_TEMPLATE = /*ts*/ `import { durableEventHandler, invoke } from '@sanity/functions'
46
+
47
+ export const handler = durableEventHandler({
48
+ // Optional: define the durable config here instead of in the blueprint resource definition
49
+ // name: 'my-durable-function',
50
+ // Optional: trigger this function from a document event
51
+ // event: {type: 'document', on: ['create', 'update'], filter: "_type == 'post'"},
52
+ },
53
+ async ({ context, event, logger, step }) => {
54
+ const time = new Date().toLocaleTimeString()
55
+ logger.log(\`Your Durable Sanity Function was called at \${time}\`)
56
+
57
+ // await step.run({
58
+ // name: 'run-step',
59
+ // handler: async ({logger: runLogger}) => {
60
+ // runLogger.log('running a run step in the durable function')
61
+ // },
62
+ // retry: { maxAttempts: 5 }
63
+ // })
64
+
65
+ // await step.wait({
66
+ // name: 'wait-step',
67
+ // duration: { seconds: 5 },
68
+ // })
69
+
70
+ // await step.delegate({
71
+ // name: 'delegate-step',
72
+ // handler: context.resources.function('some-other-func') || 'some-other-func',
73
+ // event: { data: { hello: 'world' } },
74
+ // })
75
+
76
+ // await step.waitForCallback({
77
+ // name: 'wait-for-callback-step',
78
+ // submitter: async ({ callbackId, logger: submitLogger }) => {
79
+ // submitLogger.log('sending callback ID to some-other-func', callbackId)
80
+ // await invoke('some-other-func', { context, event: { data: { callbackId } } })
81
+ // },
82
+ // })
83
+
84
+ // const user = await step.waitForCondition({
85
+ // name: 'wait-for-condition-step',
86
+ // initial: { name: null },
87
+ // poller: async (state, waitContext) => {
88
+ // waitContext.logger.log('checking for condition in the durable function')
89
+ // const userLookup = await fetch('/user/lookup')
90
+ // if (userLookup.ok) {
91
+ // const user = await userLookup.json()
92
+ // if (user) {
93
+ // return {name: user.name}
94
+ // }
95
+ // }
96
+ //
97
+ // return {
98
+ // name: null
99
+ // }
100
+ // },
101
+ // next: (state, _waitContext) => {
102
+ // if (state.name) {
103
+ // return { shouldRetry: false }
104
+ // }
105
+ // return { shouldRetry: true, delay: { seconds: 3 } }
106
+ // },
107
+ // })
108
+
109
+ // await step.fanout({
110
+ // name: 'fanout-step',
111
+ // branches: [
112
+ // async ({ step, logger }) => {
113
+ // logger.log('running branch 1 of fanout')
114
+ // await step.run({
115
+ // name: 'fanout-branch-1-run',
116
+ // handler: async ({ logger: runLogger }) => {
117
+ // runLogger.log('running a step inside branch 1')
118
+ // },
119
+ // })
120
+ // },
121
+ // async ({ logger }) => {
122
+ // logger.log('running branch 2 of fanout')
123
+ // },
124
+ // ],
125
+ // })
126
+ }
127
+ )`;
45
128
  /**
46
129
  * Creates a new function resource file and adds it to the blueprint
47
130
  */
@@ -83,6 +166,9 @@ export async function createFunctionResource(options, logger) {
83
166
  case SANITY_FUNCTION_SYNC_TAG_INVALIDATE:
84
167
  template = DEFAULT_SYNC_TAG_HELPER_FUNCTION_TEMPLATE;
85
168
  break;
169
+ case SANITY_FUNCTION_DURABLE:
170
+ template = DEFAULT_DURABLE_HELPER_FUNCTION_TEMPLATE;
171
+ break;
86
172
  default:
87
173
  template = DEFAULT_HELPER_FUNCTION_TEMPLATE;
88
174
  break;
@@ -153,6 +239,13 @@ export async function createFunctionResource(options, logger) {
153
239
  type: SANITY_FUNCTION_SYNC_TAG_INVALIDATE,
154
240
  };
155
241
  break;
242
+ case SANITY_FUNCTION_DURABLE:
243
+ resourceJson = {
244
+ name,
245
+ src: `functions/${name}`,
246
+ type: SANITY_FUNCTION_DURABLE,
247
+ };
248
+ break;
156
249
  }
157
250
  if (!resourceJson) {
158
251
  throw new Error('Could not create function resource based on selections');
@@ -25,6 +25,7 @@ export declare const EVENT_MEDIA_LIBRARY_ASSET_DELETE = "media-library-asset-del
25
25
  export declare const EVENT_PUBSUB = "pub-sub";
26
26
  export declare const EVENT_SCHEDULED = "scheduled-function";
27
27
  export declare const EVENT_SYNC_TAG_INVALIDATE = "sync-tag-invalidate";
28
+ export declare const EVENT_DURABLE = "durable-function";
28
29
  export declare const MAP_EVENT_TO_FUNCTION_TYPE: {
29
30
  readonly "document-publish": "sanity.function.document";
30
31
  readonly "document-create": "sanity.function.document";
@@ -36,6 +37,7 @@ export declare const MAP_EVENT_TO_FUNCTION_TYPE: {
36
37
  readonly "pub-sub": "sanity.function.pubsub";
37
38
  readonly "scheduled-function": "sanity.function.cron";
38
39
  readonly "sync-tag-invalidate": "sanity.function.sync-tag-invalidate";
40
+ readonly "durable-function": "sanity.function.durable";
39
41
  };
40
42
  export declare const FUNCTION_TYPES: (keyof typeof MAP_EVENT_TO_FUNCTION_TYPE)[];
41
43
  export type ARRAY_OF_FUNCTION_TYPES = typeof FUNCTION_TYPES;
@@ -52,6 +54,7 @@ export declare const LABEL_MEDIA_LIBRARY_ASSET_DELETE = "Media Library Asset Del
52
54
  export declare const LABEL_PUBSUB = "PubSub";
53
55
  export declare const LABEL_SCHEDULED = "Scheduled";
54
56
  export declare const LABEL_SYNC_TAG_INVALIDATE = "Sync Tag Invalidate";
57
+ export declare const LABEL_DURABLE = "Durable";
55
58
  export declare const CI_SETUP_DOCS_URL = "https://www.sanity.io/docs/blueprints/deploy-blueprints-from-ci";
56
59
  export declare const STACKS_DOCS_URL = "https://www.sanity.io/docs/blueprints/stacks-and-scope";
57
60
  export declare const STEP_PHASE_GLYPH: Record<DurableStepPhase, string>;
package/dist/constants.js CHANGED
@@ -24,6 +24,7 @@ export const EVENT_MEDIA_LIBRARY_ASSET_DELETE = 'media-library-asset-delete';
24
24
  export const EVENT_PUBSUB = 'pub-sub';
25
25
  export const EVENT_SCHEDULED = 'scheduled-function';
26
26
  export const EVENT_SYNC_TAG_INVALIDATE = 'sync-tag-invalidate';
27
+ export const EVENT_DURABLE = 'durable-function';
27
28
  export const MAP_EVENT_TO_FUNCTION_TYPE = {
28
29
  [EVENT_DOCUMENT_PUBLISH]: SANITY_FUNCTION_DOCUMENT,
29
30
  [EVENT_DOCUMENT_CREATE]: SANITY_FUNCTION_DOCUMENT,
@@ -35,6 +36,7 @@ export const MAP_EVENT_TO_FUNCTION_TYPE = {
35
36
  [EVENT_PUBSUB]: SANITY_FUNCTION_PUBSUB,
36
37
  [EVENT_SCHEDULED]: SANITY_FUNCTION_SCHEDULED,
37
38
  [EVENT_SYNC_TAG_INVALIDATE]: SANITY_FUNCTION_SYNC_TAG_INVALIDATE,
39
+ [EVENT_DURABLE]: SANITY_FUNCTION_DURABLE,
38
40
  };
39
41
  export const FUNCTION_TYPES = Object.keys(MAP_EVENT_TO_FUNCTION_TYPE);
40
42
  export const PROJECT_SCOPED_FUNCTION_TYPES = new Set([
@@ -57,6 +59,7 @@ export const LABEL_MEDIA_LIBRARY_ASSET_DELETE = 'Media Library Asset Delete';
57
59
  export const LABEL_PUBSUB = 'PubSub';
58
60
  export const LABEL_SCHEDULED = 'Scheduled';
59
61
  export const LABEL_SYNC_TAG_INVALIDATE = 'Sync Tag Invalidate';
62
+ export const LABEL_DURABLE = 'Durable';
60
63
  export const CI_SETUP_DOCS_URL = 'https://www.sanity.io/docs/blueprints/deploy-blueprints-from-ci';
61
64
  export const STACKS_DOCS_URL = 'https://www.sanity.io/docs/blueprints/stacks-and-scope';
62
65
  export const STEP_PHASE_GLYPH = {
@@ -5,7 +5,7 @@ import { checkbox, confirm, input, select } from '@inquirer/prompts';
5
5
  import { highlight } from 'cardinal';
6
6
  import { createFunctionResource } from '../../actions/blueprints/resources.js';
7
7
  import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
8
- import { EVENT_DOCUMENT_CREATE, EVENT_DOCUMENT_DELETE, EVENT_DOCUMENT_UPDATE, EVENT_MEDIA_LIBRARY_ASSET_CREATE, EVENT_MEDIA_LIBRARY_ASSET_DELETE, EVENT_MEDIA_LIBRARY_ASSET_UPDATE, EVENT_PUBSUB, EVENT_SCHEDULED, EVENT_SYNC_TAG_INVALIDATE, FUNCTION_TYPES, LABEL_DOCUMENT_CREATE, LABEL_DOCUMENT_DELETE, LABEL_DOCUMENT_UPDATE, LABEL_MEDIA_LIBRARY_ASSET_CREATE, LABEL_MEDIA_LIBRARY_ASSET_DELETE, LABEL_MEDIA_LIBRARY_ASSET_UPDATE, LABEL_PUBSUB, LABEL_SCHEDULED, LABEL_SYNC_TAG_INVALIDATE, MAP_EVENT_TO_FUNCTION_TYPE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PUBSUB, SANITY_FUNCTION_SCHEDULED, SANITY_FUNCTION_SYNC_TAG_INVALIDATE, } from '../../constants.js';
8
+ import { EVENT_DOCUMENT_CREATE, EVENT_DOCUMENT_DELETE, EVENT_DOCUMENT_UPDATE, EVENT_DURABLE, EVENT_MEDIA_LIBRARY_ASSET_CREATE, EVENT_MEDIA_LIBRARY_ASSET_DELETE, EVENT_MEDIA_LIBRARY_ASSET_UPDATE, EVENT_PUBSUB, EVENT_SCHEDULED, EVENT_SYNC_TAG_INVALIDATE, FUNCTION_TYPES, LABEL_DOCUMENT_CREATE, LABEL_DOCUMENT_DELETE, LABEL_DOCUMENT_UPDATE, LABEL_DURABLE, LABEL_MEDIA_LIBRARY_ASSET_CREATE, LABEL_MEDIA_LIBRARY_ASSET_DELETE, LABEL_MEDIA_LIBRARY_ASSET_UPDATE, LABEL_PUBSUB, LABEL_SCHEDULED, LABEL_SYNC_TAG_INVALIDATE, MAP_EVENT_TO_FUNCTION_TYPE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_DURABLE, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PUBSUB, SANITY_FUNCTION_SCHEDULED, SANITY_FUNCTION_SYNC_TAG_INVALIDATE, } from '../../constants.js';
9
9
  import { check, indent, warn } from '../../utils/display/presenters.js';
10
10
  import { validateFunctionName } from '../../utils/functions/validate-name.js';
11
11
  import { detectPackageManager } from '../../utils/package-manager.js';
@@ -32,6 +32,15 @@ export const generateFunctionBlueprintResourceTemplate = (fnName, eventNames) =>
32
32
  case SANITY_FUNCTION_SYNC_TAG_INVALIDATE:
33
33
  definer = `defineSyncTagInvalidateFunction({name: '${fnName}'}), // ← add this line`;
34
34
  break;
35
+ case SANITY_FUNCTION_DURABLE:
36
+ definer = `defineDurableFunction({
37
+ name: '${fnName}',
38
+ // Optional: trigger this function from a document event
39
+ // event: {type: 'document', on: ['create', 'update'], filter: "_type == 'post'"},
40
+ // Optional: total run time limit. Default '24h', min '1m', max '1y'
41
+ // durableTimeout: "24h",
42
+ }), // ← add this line`;
43
+ break;
35
44
  }
36
45
  return `
37
46
  export default defineBlueprint({
@@ -236,7 +245,7 @@ async function promptForFunctionName() {
236
245
  }
237
246
  async function promptForFunctionType() {
238
247
  function hasAtLeastOne(arr) {
239
- // TypeScript believes me when I make a funciton to "guard" the type
248
+ // TypeScript believes me when I make a function to "guard" the type
240
249
  return arr.length > 0;
241
250
  }
242
251
  const functionTypes = await checkbox({
@@ -251,6 +260,7 @@ async function promptForFunctionType() {
251
260
  { name: LABEL_PUBSUB, value: EVENT_PUBSUB },
252
261
  { name: LABEL_SCHEDULED, value: EVENT_SCHEDULED },
253
262
  { name: LABEL_SYNC_TAG_INVALIDATE, value: EVENT_SYNC_TAG_INVALIDATE },
263
+ { name: LABEL_DURABLE, value: EVENT_DURABLE },
254
264
  ],
255
265
  validate(choices) {
256
266
  if (choices.length === 0) {
@@ -8,6 +8,7 @@ import { buildApp, buildStudio, compareDependencyVersions, } from '@sanity/cli-b
8
8
  import { buildStudioSchemasAndManifests } from '@sanity/cli-build/_internal/extract';
9
9
  import { getLocalPackageVersion } from '@sanity/cli-core';
10
10
  import { pack } from 'tar-fs';
11
+ import { isRecord } from '../is-record.js';
11
12
  export const BUNDLE_SPECS = {
12
13
  'sanity.studio': { requiresAppId: true, build: buildStudioBundle },
13
14
  'sanity.application': { requiresAppId: true, build: buildApplicationBundle },
@@ -148,7 +149,7 @@ async function buildStudioBundle({ resource, appId, workDir, outDir, output, eve
148
149
  if (mfManifest) {
149
150
  resource.mfManifest = mfManifest;
150
151
  }
151
- const { schemaInputs } = await buildStudioSchemasAndManifests(appId, {
152
+ const { schemaInputs, studioManifest } = await buildStudioSchemasAndManifests(appId, {
152
153
  configPath: resource.root,
153
154
  isExternal: false,
154
155
  outPath: outDir,
@@ -160,8 +161,39 @@ async function buildStudioBundle({ resource, appId, workDir, outDir, output, eve
160
161
  if (schemaInputs) {
161
162
  resource.schemaInputs = schemaInputs;
162
163
  }
164
+ if (studioManifest) {
165
+ resource.workspaces = toStudioWorkspaces(studioManifest, resource.name);
166
+ }
163
167
  return { mismatchedPackages };
164
168
  }
169
+ const REQUIRED_WORKSPACE_KEYS = ['projectId', 'dataset', 'schemaDescriptorId', 'name'];
170
+ const OPTIONAL_WORKSPACE_KEYS = ['title', 'subtitle', 'basePath', 'icon'];
171
+ function isManifestWorkspace(value) {
172
+ if (!isRecord(value))
173
+ return false;
174
+ return (REQUIRED_WORKSPACE_KEYS.every((key) => typeof value[key] === 'string') &&
175
+ OPTIONAL_WORKSPACE_KEYS.every((key) => value[key] === undefined || typeof value[key] === 'string'));
176
+ }
177
+ function toStudioWorkspaces(studioManifest, resourceName) {
178
+ if (!isRecord(studioManifest) || !Array.isArray(studioManifest.workspaces)) {
179
+ throw new Error(`Studio manifest for resource '${resourceName}' has no workspaces list`);
180
+ }
181
+ return studioManifest.workspaces.map((w, index) => {
182
+ if (!isManifestWorkspace(w)) {
183
+ throw new Error(`Studio manifest for resource '${resourceName}' has an invalid workspace at index ${index}`);
184
+ }
185
+ return {
186
+ projectId: w.projectId,
187
+ dataset: w.dataset,
188
+ schemaDescriptorId: w.schemaDescriptorId,
189
+ name: w.name,
190
+ title: w.title,
191
+ subtitle: w.subtitle,
192
+ basePath: w.basePath,
193
+ icon: w.icon,
194
+ };
195
+ });
196
+ }
165
197
  async function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }) {
166
198
  const views = resource.views ?? [];
167
199
  const [window, extraWindow] = views.filter((v) => v.type === 'app');
@@ -1,4 +1,4 @@
1
- import { type BlueprintResource } from '@sanity/blueprints';
1
+ import type { BlueprintResource } from '@sanity/blueprints';
2
2
  /**
3
3
  * Extracts the blueprint config from the function source code and mutates it to the resource object.
4
4
  * This is used for durable functions that may not have a config defined in the blueprint.
@@ -1,11 +1,10 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { pathToFileURL } from 'node:url';
3
- import { validateDurableFunction, } from '@sanity/blueprints';
4
3
  import { SANITY_FUNCTION_DURABLE } from '../../constants.js';
5
4
  import { isLocalFunctionResource } from '../types.js';
6
5
  import { findFunctionEntryPoint } from './find-entry-point.js';
7
6
  import { transpileFunction } from './transpile/function.js';
8
- const DURABLE_CONFIG_KEYS = ['event', 'concurrency', 'debounce'];
7
+ const DURABLE_CONFIG_KEYS = ['event', 'durableTimeout'];
9
8
  /**
10
9
  * Extracts the blueprint config from the function source code and mutates it to the resource object.
11
10
  * This is used for durable functions that may not have a config defined in the blueprint.
@@ -37,19 +36,13 @@ export const extractDurableConfig = async (resource, blueprintFileDir) => {
37
36
  finally {
38
37
  await cleanup();
39
38
  }
40
- // Update values not included in the blueprint.
41
- if (resource.event === undefined && config?.event !== undefined) {
42
- resource.event = config.event;
43
- }
44
- if (resource.concurrency === undefined && config?.concurrency !== undefined) {
45
- resource.concurrency = config.concurrency;
46
- }
47
- if (resource.debounce === undefined && config?.debounce !== undefined) {
48
- resource.debounce = config.debounce;
49
- }
50
- // Validate the resource after merging the config values
51
- const errors = validateDurableFunction(resource);
52
- if (errors.length > 0) {
53
- throw new Error(`Invalid durable resource "${resource.name}": ${errors.map((error) => error.message).join('; ')}`);
39
+ // Update values not included in the blueprint, but set in the config
40
+ if (config) {
41
+ if (resource.event === undefined && config.event !== undefined) {
42
+ resource.event = config.event;
43
+ }
44
+ if (resource.durableTimeout === undefined && config.durableTimeout !== undefined) {
45
+ resource.durableTimeout = config.durableTimeout;
46
+ }
54
47
  }
55
48
  };