@sanity/runtime-cli 14.10.1 → 14.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 CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/14.10.1 linux-x64 node-v24.14.1
23
+ @sanity/runtime-cli/14.11.0 linux-x64 node-v24.14.1
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -101,7 +101,7 @@ EXAMPLES
101
101
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
102
102
  ```
103
103
 
104
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/add.ts)_
104
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/add.ts)_
105
105
 
106
106
  ## `sanity-run blueprints config`
107
107
 
@@ -140,7 +140,7 @@ EXAMPLES
140
140
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
141
141
  ```
142
142
 
143
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/config.ts)_
143
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/config.ts)_
144
144
 
145
145
  ## `sanity-run blueprints deploy`
146
146
 
@@ -182,7 +182,7 @@ EXAMPLES
182
182
  $ sanity-run blueprints deploy --fn-installer npm
183
183
  ```
184
184
 
185
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/deploy.ts)_
185
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/deploy.ts)_
186
186
 
187
187
  ## `sanity-run blueprints destroy`
188
188
 
@@ -218,7 +218,7 @@ EXAMPLES
218
218
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
219
219
  ```
220
220
 
221
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/destroy.ts)_
221
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/destroy.ts)_
222
222
 
223
223
  ## `sanity-run blueprints doctor`
224
224
 
@@ -250,7 +250,7 @@ EXAMPLES
250
250
  $ sanity-run blueprints doctor --fix
251
251
  ```
252
252
 
253
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/doctor.ts)_
253
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/doctor.ts)_
254
254
 
255
255
  ## `sanity-run blueprints info`
256
256
 
@@ -282,7 +282,7 @@ EXAMPLES
282
282
  $ sanity-run blueprints info --stack <name-or-id>
283
283
  ```
284
284
 
285
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/info.ts)_
285
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/info.ts)_
286
286
 
287
287
  ## `sanity-run blueprints init [DIR]`
288
288
 
@@ -336,7 +336,7 @@ EXAMPLES
336
336
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
337
337
  ```
338
338
 
339
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/init.ts)_
339
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/init.ts)_
340
340
 
341
341
  ## `sanity-run blueprints logs`
342
342
 
@@ -367,7 +367,7 @@ EXAMPLES
367
367
  $ sanity-run blueprints logs --watch
368
368
  ```
369
369
 
370
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/logs.ts)_
370
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/logs.ts)_
371
371
 
372
372
  ## `sanity-run blueprints plan`
373
373
 
@@ -395,7 +395,7 @@ EXAMPLES
395
395
  $ sanity-run blueprints plan
396
396
  ```
397
397
 
398
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/plan.ts)_
398
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/plan.ts)_
399
399
 
400
400
  ## `sanity-run blueprints stacks`
401
401
 
@@ -427,7 +427,7 @@ EXAMPLES
427
427
  $ sanity-run blueprints stacks --organization-id <organizationId>
428
428
  ```
429
429
 
430
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/blueprints/stacks.ts)_
430
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/blueprints/stacks.ts)_
431
431
 
432
432
  ## `sanity-run functions add`
433
433
 
@@ -480,7 +480,7 @@ EXAMPLES
480
480
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
481
481
  ```
482
482
 
483
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/add.ts)_
483
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/add.ts)_
484
484
 
485
485
  ## `sanity-run functions dev`
486
486
 
@@ -516,7 +516,7 @@ EXAMPLES
516
516
  $ sanity-run functions dev --timeout 60
517
517
  ```
518
518
 
519
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/dev.ts)_
519
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/dev.ts)_
520
520
 
521
521
  ## `sanity-run functions env add NAME KEY VALUE`
522
522
 
@@ -547,7 +547,7 @@ EXAMPLES
547
547
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
548
548
  ```
549
549
 
550
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/env/add.ts)_
550
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/env/add.ts)_
551
551
 
552
552
  ## `sanity-run functions env list NAME`
553
553
 
@@ -575,7 +575,7 @@ EXAMPLES
575
575
  $ sanity-run functions env list MyFunction
576
576
  ```
577
577
 
578
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/env/list.ts)_
578
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/env/list.ts)_
579
579
 
580
580
  ## `sanity-run functions env remove NAME KEY`
581
581
 
@@ -605,7 +605,7 @@ EXAMPLES
605
605
  $ sanity-run functions env remove MyFunction API_URL
606
606
  ```
607
607
 
608
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/env/remove.ts)_
608
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/env/remove.ts)_
609
609
 
610
610
  ## `sanity-run functions logs [NAME]`
611
611
 
@@ -647,7 +647,7 @@ EXAMPLES
647
647
  $ sanity-run functions logs <name> --delete
648
648
  ```
649
649
 
650
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/logs.ts)_
650
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/logs.ts)_
651
651
 
652
652
  ## `sanity-run functions test [NAME]`
653
653
 
@@ -705,7 +705,7 @@ EXAMPLES
705
705
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
706
706
  ```
707
707
 
708
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.10.1/src/commands/functions/test.ts)_
708
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.11.0/src/commands/functions/test.ts)_
709
709
 
710
710
  ## `sanity-run help [COMMAND]`
711
711
 
@@ -10,5 +10,6 @@ export class ApiBaseElement extends HTMLElement {
10
10
  this.SANITY_FUNCTION_DOCUMENT = 'sanity.function.document'
11
11
  this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset'
12
12
  this.SANITY_FUNCTION_SCHEDULED = 'sanity.function.cron'
13
+ this.SANITY_FUNCTION_SYNC_TAG_INVALIDATE = 'sanity.function.sync-tag-invalidate'
13
14
  }
14
15
  }
@@ -80,17 +80,24 @@ class FiltersComponent extends ApiBaseElement {
80
80
  this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
81
81
  )
82
82
  const scheduleFunction = this.api.store.selectedFunctionType === this.SANITY_FUNCTION_SCHEDULED
83
+ const stiFunction =
84
+ this.api.store.selectedFunctionType === this.SANITY_FUNCTION_SYNC_TAG_INVALIDATE
83
85
 
84
86
  const container = this.shadowRoot.querySelector('fieldset')
85
- container.innerHTML = this.buildFilters(docFunction, mediaFunction, scheduleFunction)
87
+ container.innerHTML = this.buildFilters(
88
+ docFunction,
89
+ mediaFunction,
90
+ scheduleFunction,
91
+ stiFunction,
92
+ )
86
93
  }
87
94
 
88
- buildFilters = (docFunction, mediaFunction, scheduleFunction) => {
95
+ buildFilters = (docFunction, mediaFunction, scheduleFunction, stiFunction) => {
89
96
  return `
90
97
  <legend class="config-label">Client Options</legend>
91
98
  <div id="dynamic-dropdowns" class="flex gap-2">
92
99
  ${
93
- docFunction || scheduleFunction
100
+ docFunction || scheduleFunction || stiFunction
94
101
  ? `<select-dropdown
95
102
  label="Project"
96
103
  store-key="projects"
@@ -61,6 +61,7 @@ class FunctionList extends ApiBaseElement {
61
61
  case this.SANITY_FUNCTION_SCHEDULED:
62
62
  return 'Scheduled'
63
63
  default:
64
+ // this works well for sync-tag-invalidate functions!
64
65
  return type.split('.').pop().replaceAll('-', ' ')
65
66
  }
66
67
  }
@@ -29,7 +29,7 @@ template.innerHTML = `
29
29
  <div id="payloadContainer" class="gutter-gradient relative h-100 max-h-100 y-scroll border-top border-top-none-l">
30
30
  <div class="bg gutter-gradient sticky top-0 right-0 left-0 z-100">
31
31
  <div class="flex items-center space-between pad-t-2 pad-r-5 pad-b-2 pad-l-12">
32
- <h2 class="config-label mar-t-0 mar-b-0">Document</h2>
32
+ <h2 id="payloadTitle" class="config-label mar-t-0 mar-b-0">Document</h2>
33
33
  </div>
34
34
  <hr class='hr-border mar-l-specific' />
35
35
  </div>
@@ -75,11 +75,35 @@ class PayloadPanel extends ApiBaseElement {
75
75
 
76
76
  this.api.subscribe(this.updatePayload, ['document'])
77
77
  this.api.subscribe(this.updateSelectedEvent, ['selectedEvent'])
78
- this.api.subscribe(this.updateCodeMirror, ['selectedFunctionType'])
78
+ this.api.subscribe(this.updateCodeMirror, ['selectedIndex', 'functions'])
79
+ this.api.subscribe(this.updatePanelTitle, ['selectedFunctionType'])
80
+ this.documentCacheByFunction = {}
81
+ this.currentIndex = -1
79
82
  }
80
83
 
81
- updateCodeMirror = ({selectedFunctionType}) => {
82
- if (selectedFunctionType === this.SANITY_FUNCTION_SCHEDULED) {
84
+ updateCodeMirror = () => {
85
+ const {
86
+ functions,
87
+ selectedIndex: selectedFuncName,
88
+ payload: {state},
89
+ } = this.api.store
90
+ const docText = state.doc.text.join('')
91
+ // save the previous payload in the cache before we do anything else
92
+ if (docText) {
93
+ const currentDoc = JSON.parse(docText)
94
+ this.documentCacheByFunction[this.currentIndex] = currentDoc
95
+ } else {
96
+ this.documentCacheByFunction[this.currentIndex] = ''
97
+ }
98
+ const selectedIndex = functions.findIndex((f) => f.name === selectedFuncName)
99
+ if (selectedIndex === this.currentIndex) return
100
+ const selectedFunction = functions[selectedIndex]
101
+ // flip editable of code mirror textarea based on function type
102
+ if (
103
+ [this.SANITY_FUNCTION_SCHEDULED, this.SANITY_FUNCTION_SYNC_TAG_INVALIDATE].includes(
104
+ selectedFunction.type,
105
+ )
106
+ ) {
83
107
  this.api.store.beforePayload.dispatch({
84
108
  effects: editableCompartment.reconfigure(EditorView.editable.of(false)),
85
109
  })
@@ -100,6 +124,16 @@ class PayloadPanel extends ApiBaseElement {
100
124
  effects: editableCompartment.reconfigure(EditorView.editable.of(true)),
101
125
  })
102
126
  }
127
+ // for certain other specific function types, set the payload to something specific, or reload whatever was loaded into its document payload before
128
+ switch (selectedFunction.type) {
129
+ case this.SANITY_FUNCTION_SYNC_TAG_INVALIDATE:
130
+ this.#updateCodeView(this.api.store.payload, {data: {syncTags: ['s1:1234', 's2:5678']}})
131
+ break
132
+ default:
133
+ this.#updateCodeView(this.api.store.payload, this.documentCacheByFunction[selectedIndex])
134
+ break
135
+ }
136
+ this.currentIndex = selectedIndex
103
137
  }
104
138
  updatePayload = ({document}) => {
105
139
  if (!document) return
@@ -112,7 +146,7 @@ class PayloadPanel extends ApiBaseElement {
112
146
  const transaction = view.state.update({
113
147
  changes: {
114
148
  from: 0,
115
- insert: JSON.stringify(document, null, 2),
149
+ insert: document ? JSON.stringify(document, null, 2) : '',
116
150
  to: view.state.doc.length,
117
151
  },
118
152
  })
@@ -126,6 +160,22 @@ class PayloadPanel extends ApiBaseElement {
126
160
  payloadContainer.style.display = isUpdateEvent ? 'none' : 'block'
127
161
  deltaPayloadContainer.style.display = isUpdateEvent ? 'block' : 'none'
128
162
  }
163
+ updatePanelTitle = ({selectedFunctionType}) => {
164
+ const payloadTitle = this.shadowRoot.querySelector('#payloadTitle')
165
+ let title = 'Document'
166
+ switch (selectedFunctionType) {
167
+ case this.SANITY_FUNCTION_SYNC_TAG_INVALIDATE:
168
+ title = 'Sync Tag Payload'
169
+ break
170
+ case this.SANITY_FUNCTION_SCHEDULED:
171
+ title = 'Schedule Payload'
172
+ break
173
+ case this.SANITY_FUNCTION_DOCUMENT:
174
+ case this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET:
175
+ title = 'Document'
176
+ }
177
+ payloadTitle.innerHTML = title
178
+ }
129
179
 
130
180
  disconnectedCallback() {
131
181
  if (this.api) {
@@ -14,7 +14,7 @@ template.innerHTML = `<div class="border-left y-scroll min-h-0">
14
14
  <h3 class="config-label mar-t-0 hidden">Filter/Projection</h3>
15
15
  <header class='flex space-between'>
16
16
  <dl class='flex items-center margin-0 pad-3 slab-stat'>
17
- <dt class='nowrap'>Filter/Projection</dt>
17
+ <dt id="ruleTitle" class="nowrap">Filter/Projection</dt>
18
18
  </dl>
19
19
  </header>
20
20
  <div id="rule" name="rule" class="cm-s-dracula"></div>
@@ -30,6 +30,18 @@ class RulePanel extends ApiBaseElement {
30
30
  updateRule = () => {
31
31
  const {functions, rule, selectedIndex} = this.api.store
32
32
  const func = functions.find((func) => func.name === selectedIndex)
33
+ switch (func.type) {
34
+ case this.SANITY_FUNCTION_SCHEDULED:
35
+ this.ruleTitle.innerHTML = 'Schedule Rule'
36
+ break
37
+ case this.SANITY_FUNCTION_DOCUMENT:
38
+ case this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET:
39
+ this.ruleTitle.innerHTML = 'Filter/Projection'
40
+ break
41
+ case this.SANITY_FUNCTION_SYNC_TAG_INVALIDATE:
42
+ this.ruleTitle.innerHTML = 'Resource'
43
+ break
44
+ }
33
45
 
34
46
  if (func.event) {
35
47
  const transaction = rule.state.update({
@@ -48,6 +60,7 @@ class RulePanel extends ApiBaseElement {
48
60
  this.shadowRoot.adoptedStyleSheets = sheets
49
61
 
50
62
  this.rule = this.shadowRoot.querySelector('#rule')
63
+ this.ruleTitle = this.shadowRoot.querySelector('#ruleTitle')
51
64
 
52
65
  if (this.api) {
53
66
  this.api.subscribe(this.updateRule, ['selectedIndex', 'functions'])
@@ -117,7 +117,12 @@ process.on('message', async (data) => {
117
117
  )
118
118
  }
119
119
 
120
- json = await eventHandler({context, event})
120
+ json = await eventHandler({
121
+ context,
122
+ event,
123
+ // mock sync-tag-invalidate done callback
124
+ done: async (_tags) => new Response(null, {status: 204}),
125
+ })
121
126
 
122
127
  // Restore streams
123
128
  process.stdout.write = originalStdoutWrite
@@ -70,7 +70,7 @@ export default async function invoke(resource, payload, context, options) {
70
70
  createTempPackageJson(functionPath);
71
71
  }
72
72
  const { forceColor = true, timeout = 10 } = options;
73
- let filteredData = {};
73
+ let filteredData = payload?.payload?.data || {};
74
74
  if (resource.type === 'sanity.function.document' ||
75
75
  resource.type === 'sanity.function.media-library.asset') {
76
76
  if (!isGroqContextOptions(context)) {
@@ -2247,5 +2247,5 @@
2247
2247
  ]
2248
2248
  }
2249
2249
  },
2250
- "version": "14.10.1"
2250
+ "version": "14.11.0"
2251
2251
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "Sanity's Runtime CLI for Blueprints and Functions",
4
- "version": "14.10.1",
4
+ "version": "14.11.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",