@sanity/runtime-cli 17.16.0-next.g91e6dd2 → 17.16.0-next.gfe46ad0
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
|
@@ -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.16.0-next.
|
|
93
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
130
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
186
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
224
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
256
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
294
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
358
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
404
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
449
|
+
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
482
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
518
|
+
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
559
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/src/commands/blueprints/stacks.ts)_
|
|
560
560
|
|
|
561
561
|
## `sanity-run functions add`
|
|
562
562
|
|
|
@@ -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.16.0-next.
|
|
611
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
646
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
679
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
709
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
741
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
781
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/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.16.0-next.
|
|
839
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-next.gfe46ad0/src/commands/functions/test.ts)_
|
|
840
840
|
|
|
841
841
|
## `sanity-run help [COMMAND]`
|
|
842
842
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {performance} from 'node:perf_hooks'
|
|
2
2
|
import {inspect} from 'node:util'
|
|
3
|
+
import {getBatchResults} from './getBatchResults.js'
|
|
3
4
|
import {createStepHistory} from './step-history.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -24,9 +25,10 @@ const formatArgs = (args) =>
|
|
|
24
25
|
* @param handler - callback being run
|
|
25
26
|
* @param context - data to send to the operation
|
|
26
27
|
* @param event - the step being run
|
|
28
|
+
* @param [branchName] - the name of the branch being run
|
|
27
29
|
* @param io
|
|
28
30
|
*/
|
|
29
|
-
export async function runDurable(handler, {context, event}, io) {
|
|
31
|
+
export async function runDurable(handler, {context, event, branchName}, io) {
|
|
30
32
|
const history = createStepHistory()
|
|
31
33
|
let currentStep = null
|
|
32
34
|
|
|
@@ -132,6 +134,14 @@ export async function runDurable(handler, {context, event}, io) {
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
137
|
+
const FANOUT_STATUS = {
|
|
138
|
+
STARTED: 'STARTED',
|
|
139
|
+
ALL_COMPLETED: 'ALL_COMPLETED',
|
|
140
|
+
FAILURE_TOLERANCE_EXCEEDED: 'FAILURE_TOLERANCE_EXCEEDED',
|
|
141
|
+
SUCCEEDED: 'SUCCEEDED',
|
|
142
|
+
FAILED: 'FAILED',
|
|
143
|
+
}
|
|
144
|
+
|
|
135
145
|
const step = {
|
|
136
146
|
run: ({name, handler: fn, retry}) =>
|
|
137
147
|
track(name || '', 'run', (attempt) => fn({logger, attempt}), retry),
|
|
@@ -148,6 +158,36 @@ export async function runDurable(handler, {context, event}, io) {
|
|
|
148
158
|
},
|
|
149
159
|
retry,
|
|
150
160
|
),
|
|
161
|
+
fanout: async ({name, branches}) => {
|
|
162
|
+
if (
|
|
163
|
+
!Array.isArray(branches) ||
|
|
164
|
+
Array.from(branches).some((branch) => typeof branch !== 'function')
|
|
165
|
+
) {
|
|
166
|
+
throw new TypeError('fanout branches must be an array of functions')
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const outcomes = branches.map((_, index) => ({index, status: FANOUT_STATUS.STARTED}))
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
const execs = branches.map(async (branch, index) => {
|
|
172
|
+
try {
|
|
173
|
+
const branchName = `${name || 'fanout'} / branch ${index}`
|
|
174
|
+
const result = await runDurable(branch, {context, event, branchName}, io)
|
|
175
|
+
outcomes[index] = {index, status: FANOUT_STATUS.SUCCEEDED, result}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
|
178
|
+
outcomes[index] = {index, status: FANOUT_STATUS.FAILED, error}
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
Promise.allSettled(execs)
|
|
183
|
+
.then(() => {
|
|
184
|
+
resolve(getBatchResults(outcomes, FANOUT_STATUS.ALL_COMPLETED))
|
|
185
|
+
})
|
|
186
|
+
.catch(() => {
|
|
187
|
+
reject(reject)
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
},
|
|
151
191
|
waitForCondition: ({name, initial, poller, next}) =>
|
|
152
192
|
track(name || '', 'wait-for-condition', async () => {
|
|
153
193
|
let state = initial
|
|
@@ -174,10 +214,11 @@ export async function runDurable(handler, {context, event}, io) {
|
|
|
174
214
|
|
|
175
215
|
let result
|
|
176
216
|
let done = false
|
|
217
|
+
const handlerArgs = branchName !== undefined ? {step, logger} : {context, event, step, logger}
|
|
177
218
|
while (!done) {
|
|
178
219
|
history.startRun()
|
|
179
220
|
try {
|
|
180
|
-
result = await handler(
|
|
221
|
+
result = await handler(handlerArgs)
|
|
181
222
|
settleUnretried()
|
|
182
223
|
done = true
|
|
183
224
|
} catch (err) {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps to runtime APIs from @sanity/functions
|
|
3
|
+
* @param outcomes - array of outcomes from the batch execution, each outcome should have a status and result or error
|
|
4
|
+
* @param reason - a string indicating the reason for the batch result, e.g., 'ALL_COMPLETED' or 'FAILED'
|
|
5
|
+
*/
|
|
6
|
+
export const getBatchResults = (outcomes, reason) => {
|
|
7
|
+
/**
|
|
8
|
+
* Returns an array of all outcomes, regardless of their status.
|
|
9
|
+
*/
|
|
10
|
+
const all = outcomes.map((outcome) => ({...outcome}))
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns an array of outcomes that have failed (status 'FAILED').
|
|
14
|
+
*/
|
|
15
|
+
const failed = () =>
|
|
16
|
+
all.filter((outcome) => outcome.error !== undefined && outcome.status === 'FAILED')
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns an array of outcomes that have succeeded (status 'SUCCEEDED').
|
|
20
|
+
*/
|
|
21
|
+
const succeeded = () =>
|
|
22
|
+
all.filter((outcome) => outcome.result !== undefined && outcome.status === 'SUCCEEDED')
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns an array of outcomes that are still in progress (status 'STARTED').
|
|
26
|
+
*/
|
|
27
|
+
const started = () => all.filter((outcome) => outcome.status === 'STARTED')
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the count of successful outcomes (status 'SUCCEEDED')
|
|
31
|
+
*/
|
|
32
|
+
const successCount = all.filter((item) => item.status === 'SUCCEEDED').length
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns the count of failed outcomes (status 'FAILED')
|
|
36
|
+
*/
|
|
37
|
+
const failureCount = all.filter((item) => item.status === 'FAILED').length
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns an array of results from successful outcomes (status 'SUCCEEDED').
|
|
41
|
+
*/
|
|
42
|
+
const getResults = () => succeeded().map((item) => item.result)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns an array of errors from failed outcomes (status 'FAILED').
|
|
46
|
+
*/
|
|
47
|
+
const getErrors = () => failed().map((item) => item.error)
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Throws the first error found in the failed outcomes (status 'FAILED').
|
|
51
|
+
*/
|
|
52
|
+
const throwIfError = () => {
|
|
53
|
+
const failure = all.find((outcome) => outcome.status === 'FAILED')
|
|
54
|
+
if (failure?.error) {
|
|
55
|
+
throw failure.error
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
all,
|
|
61
|
+
status: failureCount > 0 ? 'FAILED' : 'SUCCEEDED',
|
|
62
|
+
hasFailure: failureCount > 0,
|
|
63
|
+
failed,
|
|
64
|
+
succeeded,
|
|
65
|
+
started,
|
|
66
|
+
reason,
|
|
67
|
+
successCount,
|
|
68
|
+
failureCount,
|
|
69
|
+
startedCount: started().length,
|
|
70
|
+
totalCount: all.length,
|
|
71
|
+
getResults,
|
|
72
|
+
getErrors,
|
|
73
|
+
throwIfError,
|
|
74
|
+
}
|
|
75
|
+
}
|
package/oclif.manifest.json
CHANGED
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": "17.16.0-next.
|
|
4
|
+
"version": "17.16.0-next.gfe46ad0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"@oclif/test": "^4.2.0",
|
|
101
101
|
"@playwright/test": "^1.63.0",
|
|
102
102
|
"@sanity-labs/design-tokens": "^0.0.2-alpha.2",
|
|
103
|
-
"@sanity/functions": "^1.
|
|
103
|
+
"@sanity/functions": "^1.10.1",
|
|
104
104
|
"@types/cardinal": "^2.1.1",
|
|
105
105
|
"@types/mime-types": "^3.0.1",
|
|
106
106
|
"@types/node": "^22",
|