@sanity/runtime-cli 10.1.4 → 10.2.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/10.1.4 linux-x64 node-v22.18.0
23
+ @sanity/runtime-cli/10.2.0 linux-x64 node-v22.18.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -52,8 +52,9 @@ Add a Resource to a Blueprint
52
52
 
53
53
  ```
54
54
  USAGE
55
- $ sanity-run blueprints add TYPE [--example <value> | -n <value> | --fn-type document-publish | --fn-language
56
- ts|js | --javascript | --fn-helpers | --fn-installer skip|npm|pnpm|yarn] [-i | ]
55
+ $ sanity-run blueprints add TYPE [--example <value> | -n <value> | --fn-type
56
+ document-publish|document-create|document-delete|document-update | --fn-language ts|js | --javascript | --fn-helpers
57
+ | --fn-installer skip|npm|pnpm|yarn] [-i | ]
57
58
 
58
59
  ARGUMENTS
59
60
  TYPE (function) Type of Resource to add (e.g. function)
@@ -68,7 +69,7 @@ FLAGS
68
69
  --fn-language=<option> [default: ts] Language of the new Function
69
70
  <options: ts|js>
70
71
  --fn-type=<option> Type of new Function
71
- <options: document-publish>
72
+ <options: document-publish|document-create|document-delete|document-update>
72
73
  --javascript Use JavaScript instead of TypeScript
73
74
 
74
75
  DESCRIPTION
@@ -83,10 +84,10 @@ EXAMPLES
83
84
 
84
85
  $ sanity-run blueprints add function --name my-function --fn-type document-publish
85
86
 
86
- $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
87
+ $ sanity-run blueprints add function --name my-function --fn-type document-update --lang js
87
88
  ```
88
89
 
89
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/add.ts)_
90
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/add.ts)_
90
91
 
91
92
  ## `sanity-run blueprints config`
92
93
 
@@ -117,7 +118,7 @@ EXAMPLES
117
118
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
118
119
  ```
119
120
 
120
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/config.ts)_
121
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/config.ts)_
121
122
 
122
123
  ## `sanity-run blueprints deploy`
123
124
 
@@ -139,7 +140,7 @@ EXAMPLES
139
140
  $ sanity-run blueprints deploy --no-wait
140
141
  ```
141
142
 
142
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/deploy.ts)_
143
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/deploy.ts)_
143
144
 
144
145
  ## `sanity-run blueprints destroy`
145
146
 
@@ -164,7 +165,7 @@ EXAMPLES
164
165
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
165
166
  ```
166
167
 
167
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/destroy.ts)_
168
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/destroy.ts)_
168
169
 
169
170
  ## `sanity-run blueprints info`
170
171
 
@@ -186,7 +187,7 @@ EXAMPLES
186
187
  $ sanity-run blueprints info --stack-id <stackId>
187
188
  ```
188
189
 
189
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/info.ts)_
190
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/info.ts)_
190
191
 
191
192
  ## `sanity-run blueprints init [DIR]`
192
193
 
@@ -224,7 +225,7 @@ EXAMPLES
224
225
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
225
226
  ```
226
227
 
227
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/init.ts)_
228
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/init.ts)_
228
229
 
229
230
  ## `sanity-run blueprints logs`
230
231
 
@@ -246,7 +247,7 @@ EXAMPLES
246
247
  $ sanity-run blueprints logs --watch
247
248
  ```
248
249
 
249
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/logs.ts)_
250
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/logs.ts)_
250
251
 
251
252
  ## `sanity-run blueprints plan`
252
253
 
@@ -263,7 +264,7 @@ EXAMPLES
263
264
  $ sanity-run blueprints plan
264
265
  ```
265
266
 
266
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/plan.ts)_
267
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/plan.ts)_
267
268
 
268
269
  ## `sanity-run blueprints stacks`
269
270
 
@@ -285,7 +286,7 @@ EXAMPLES
285
286
  $ sanity-run blueprints stacks --project-id <projectId>
286
287
  ```
287
288
 
288
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/blueprints/stacks.ts)_
289
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/blueprints/stacks.ts)_
289
290
 
290
291
  ## `sanity-run functions dev`
291
292
 
@@ -305,7 +306,7 @@ EXAMPLES
305
306
  $ sanity-run functions dev --port 8974
306
307
  ```
307
308
 
308
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/functions/dev.ts)_
309
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/functions/dev.ts)_
309
310
 
310
311
  ## `sanity-run functions env add NAME KEY VALUE`
311
312
 
@@ -327,7 +328,7 @@ EXAMPLES
327
328
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
328
329
  ```
329
330
 
330
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/functions/env/add.ts)_
331
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/functions/env/add.ts)_
331
332
 
332
333
  ## `sanity-run functions env list NAME`
333
334
 
@@ -347,7 +348,7 @@ EXAMPLES
347
348
  $ sanity-run functions env list MyFunction
348
349
  ```
349
350
 
350
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/functions/env/list.ts)_
351
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/functions/env/list.ts)_
351
352
 
352
353
  ## `sanity-run functions env remove NAME KEY`
353
354
 
@@ -368,7 +369,7 @@ EXAMPLES
368
369
  $ sanity-run functions env remove MyFunction API_URL
369
370
  ```
370
371
 
371
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/functions/env/remove.ts)_
372
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/functions/env/remove.ts)_
372
373
 
373
374
  ## `sanity-run functions logs NAME`
374
375
 
@@ -402,7 +403,7 @@ EXAMPLES
402
403
  $ sanity-run functions logs <name> --delete
403
404
  ```
404
405
 
405
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/functions/logs.ts)_
406
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/functions/logs.ts)_
406
407
 
407
408
  ## `sanity-run functions test NAME`
408
409
 
@@ -437,7 +438,7 @@ EXAMPLES
437
438
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
438
439
  ```
439
440
 
440
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v10.1.4/src/commands/functions/test.ts)_
441
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v10.2.0/src/commands/functions/test.ts)_
441
442
 
442
443
  ## `sanity-run help [COMMAND]`
443
444
 
@@ -8,7 +8,7 @@ export default class AddCommand extends BlueprintCommand {
8
8
  '<%= config.bin %> <%= command.id %> function --helpers',
9
9
  '<%= config.bin %> <%= command.id %> function --name my-function',
10
10
  '<%= config.bin %> <%= command.id %> function --name my-function --fn-type document-publish',
11
- '<%= config.bin %> <%= command.id %> function --name my-function --fn-type document-publish --lang js',
11
+ '<%= config.bin %> <%= command.id %> function --name my-function --fn-type document-update --lang js',
12
12
  ];
13
13
  static args = {
14
14
  type: Args.string({
@@ -29,7 +29,7 @@ export default class AddCommand extends BlueprintCommand {
29
29
  }),
30
30
  'fn-type': Flags.string({
31
31
  description: 'Type of new Function',
32
- options: ['document-publish' /*, 'document-create', 'document-delete'*/],
32
+ options: ['document-publish', 'document-create', 'document-delete', 'document-update'],
33
33
  aliases: ['function-type'],
34
34
  dependsOn: ['name'],
35
35
  }),
@@ -8,11 +8,11 @@ import { createFunctionResource } from '../../actions/blueprints/resources.js';
8
8
  import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
9
9
  import { check, indent, warn } from '../../utils/display/presenters.js';
10
10
  import { validateFunctionName } from '../../utils/validate/resource.js';
11
- const FUNCTION_BLUEPRINT_RESOURCE_TEMPLATE = `
11
+ const generateFunctionBlueprintResourceTemplate = (fnName, eventName) => `
12
12
  export default defineBlueprint({
13
13
  resources: [
14
14
  // ...
15
- defineDocumentFunction({name: '{{fnName}}'}), // ← add this line
15
+ defineDocumentFunction({name: '${fnName}', event: {on: ['${eventName}']}}), // ← add this line
16
16
  ],
17
17
  })
18
18
  `;
@@ -116,8 +116,8 @@ export async function blueprintAddCore(options) {
116
116
  }
117
117
  const fnType = flagFnType || (await promptForFunctionType());
118
118
  const fnLang = flagFnLang || (await promptForFunctionLang());
119
- if (!['document-publish', 'document-create', 'document-delete'].includes(fnType)) {
120
- throw new Error('Invalid function type. Must be one of: document-publish, document-create, document-delete');
119
+ if (!['document-publish', 'document-create', 'document-delete', 'document-update'].includes(fnType)) {
120
+ throw new Error('Invalid function type. Must be one of: document-publish, document-create, document-delete, document-update');
121
121
  }
122
122
  let addHelpers;
123
123
  let installCommand;
@@ -163,7 +163,7 @@ export async function blueprintAddCore(options) {
163
163
  case '.ts':
164
164
  case '.js':
165
165
  case '.mjs': {
166
- log(highlight(FUNCTION_BLUEPRINT_RESOURCE_TEMPLATE.replace('{{fnName}}', fnName)));
166
+ log(highlight(generateFunctionBlueprintResourceTemplate(fnName, fnType.split('-')[1])));
167
167
  break;
168
168
  }
169
169
  default:
@@ -205,8 +205,9 @@ async function promptForFunctionType() {
205
205
  message: 'Choose function type:',
206
206
  choices: [
207
207
  { name: 'Document Publish', value: 'document-publish' },
208
- { name: 'Document Create', value: 'document-create', disabled: '(Coming soon)' },
209
- { name: 'Document Delete', value: 'document-delete', disabled: '(Coming soon)' },
208
+ { name: 'Document Create', value: 'document-create' },
209
+ { name: 'Document Delete', value: 'document-delete' },
210
+ { name: 'Document Update', value: 'document-update' },
210
211
  ],
211
212
  default: 'document-publish',
212
213
  },
@@ -15,6 +15,8 @@ export interface AuthParams {
15
15
  export interface GroqRule {
16
16
  on: Array<string>;
17
17
  filter?: string;
18
+ includeDrafts?: boolean;
19
+ includeAllVersions?: boolean;
18
20
  projection?: string;
19
21
  }
20
22
  /** @internal */
@@ -3,6 +3,7 @@ export function validateFunctionName(name) {
3
3
  // must be 6+ characters, no special characters, no spaces, allow _ and -
4
4
  return /^[a-zA-Z0-9][a-zA-Z0-9_-]{5,}$/.test(name);
5
5
  }
6
+ const validFunctionEventNames = ['publish', 'create', 'update', 'delete'];
6
7
  export function validateFunctionResource(resource) {
7
8
  const { name: fnName } = resource;
8
9
  const msgPrefix = `Function "${fnName}":`;
@@ -25,9 +26,9 @@ export function validateFunctionResource(resource) {
25
26
  type: BlueprintParserErrorType.MissingRequiredProperty,
26
27
  });
27
28
  }
28
- else if (resource.event.on[0] !== 'publish') {
29
+ else if (!resource.event.on.every((evt) => validFunctionEventNames.includes(evt))) {
29
30
  errors.push({
30
- message: `${msgPrefix} First event.on value must be "publish"`,
31
+ message: `${msgPrefix} event.on values must be one of ${validFunctionEventNames.map((e) => `"${e}"`).join(', ')}`,
31
32
  type: BlueprintParserErrorType.InvalidValue,
32
33
  });
33
34
  }
@@ -43,6 +44,19 @@ export function validateFunctionResource(resource) {
43
44
  type: BlueprintParserErrorType.InvalidType,
44
45
  });
45
46
  }
47
+ if (resource.event?.includeDrafts && typeof resource.event.includeDrafts !== 'boolean') {
48
+ errors.push({
49
+ message: `${msgPrefix} event.includeDrafts must be a boolean`,
50
+ type: BlueprintParserErrorType.InvalidType,
51
+ });
52
+ }
53
+ if (resource.event?.includeAllVersions &&
54
+ typeof resource.event.includeAllVersions !== 'boolean') {
55
+ errors.push({
56
+ message: `${msgPrefix} event.includeAllVersions must be a boolean`,
57
+ type: BlueprintParserErrorType.InvalidType,
58
+ });
59
+ }
46
60
  if (resource.memory !== undefined) {
47
61
  if (!Number.isInteger(resource.memory)) {
48
62
  errors.push({
@@ -18,7 +18,7 @@
18
18
  "<%= config.bin %> <%= command.id %> function --helpers",
19
19
  "<%= config.bin %> <%= command.id %> function --name my-function",
20
20
  "<%= config.bin %> <%= command.id %> function --name my-function --fn-type document-publish",
21
- "<%= config.bin %> <%= command.id %> function --name my-function --fn-type document-publish --lang js"
21
+ "<%= config.bin %> <%= command.id %> function --name my-function --fn-type document-update --lang js"
22
22
  ],
23
23
  "flags": {
24
24
  "example": {
@@ -59,7 +59,10 @@
59
59
  "hasDynamicHelp": false,
60
60
  "multiple": false,
61
61
  "options": [
62
- "document-publish"
62
+ "document-publish",
63
+ "document-create",
64
+ "document-delete",
65
+ "document-update"
63
66
  ],
64
67
  "type": "option"
65
68
  },
@@ -901,5 +904,5 @@
901
904
  ]
902
905
  }
903
906
  },
904
- "version": "10.1.4"
907
+ "version": "10.2.0"
905
908
  }
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": "10.1.4",
4
+ "version": "10.2.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",