@sanity/runtime-cli 5.0.0 → 5.0.1

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/5.0.0 linux-x64 node-v22.15.0
23
+ @sanity/runtime-cli/5.0.1 linux-x64 node-v22.15.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -78,7 +78,7 @@ EXAMPLES
78
78
  $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
79
79
  ```
80
80
 
81
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/add.ts)_
81
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/add.ts)_
82
82
 
83
83
  ## `sanity-run blueprints config`
84
84
 
@@ -106,7 +106,7 @@ EXAMPLES
106
106
  $ sanity-run blueprints config --edit --project-id <projectId>
107
107
  ```
108
108
 
109
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/config.ts)_
109
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/config.ts)_
110
110
 
111
111
  ## `sanity-run blueprints deploy`
112
112
 
@@ -128,7 +128,7 @@ EXAMPLES
128
128
  $ sanity-run blueprints deploy --no-wait
129
129
  ```
130
130
 
131
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/deploy.ts)_
131
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/deploy.ts)_
132
132
 
133
133
  ## `sanity-run blueprints destroy`
134
134
 
@@ -148,7 +148,7 @@ EXAMPLES
148
148
  $ sanity-run blueprints destroy
149
149
  ```
150
150
 
151
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/destroy.ts)_
151
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/destroy.ts)_
152
152
 
153
153
  ## `sanity-run blueprints info`
154
154
 
@@ -165,7 +165,7 @@ EXAMPLES
165
165
  $ sanity-run blueprints info
166
166
  ```
167
167
 
168
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/info.ts)_
168
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/info.ts)_
169
169
 
170
170
  ## `sanity-run blueprints init [DIR]`
171
171
 
@@ -197,7 +197,7 @@ EXAMPLES
197
197
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId>
198
198
  ```
199
199
 
200
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/init.ts)_
200
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/init.ts)_
201
201
 
202
202
  ## `sanity-run blueprints logs`
203
203
 
@@ -219,7 +219,7 @@ EXAMPLES
219
219
  $ sanity-run blueprints logs --watch
220
220
  ```
221
221
 
222
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/logs.ts)_
222
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/logs.ts)_
223
223
 
224
224
  ## `sanity-run blueprints plan`
225
225
 
@@ -236,7 +236,7 @@ EXAMPLES
236
236
  $ sanity-run blueprints plan
237
237
  ```
238
238
 
239
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/plan.ts)_
239
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/blueprints/plan.ts)_
240
240
 
241
241
  ## `sanity-run functions dev`
242
242
 
@@ -256,7 +256,7 @@ EXAMPLES
256
256
  $ sanity-run functions dev --port 8974
257
257
  ```
258
258
 
259
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/dev.ts)_
259
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/dev.ts)_
260
260
 
261
261
  ## `sanity-run functions env add NAME KEY VALUE`
262
262
 
@@ -278,7 +278,7 @@ EXAMPLES
278
278
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
279
279
  ```
280
280
 
281
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/env/add.ts)_
281
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/env/add.ts)_
282
282
 
283
283
  ## `sanity-run functions env list NAME`
284
284
 
@@ -298,7 +298,7 @@ EXAMPLES
298
298
  $ sanity-run functions env list MyFunction
299
299
  ```
300
300
 
301
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/env/list.ts)_
301
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/env/list.ts)_
302
302
 
303
303
  ## `sanity-run functions env remove NAME KEY`
304
304
 
@@ -319,7 +319,7 @@ EXAMPLES
319
319
  $ sanity-run functions env remove MyFunction API_URL
320
320
  ```
321
321
 
322
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/env/remove.ts)_
322
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/env/remove.ts)_
323
323
 
324
324
  ## `sanity-run functions invoke NAME`
325
325
 
@@ -345,7 +345,7 @@ EXAMPLES
345
345
  $ sanity-run functions invoke <name> --file 'payload.json'
346
346
  ```
347
347
 
348
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/invoke.ts)_
348
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/invoke.ts)_
349
349
 
350
350
  ## `sanity-run functions logs NAME`
351
351
 
@@ -377,7 +377,7 @@ EXAMPLES
377
377
  $ sanity-run functions logs <name> --delete
378
378
  ```
379
379
 
380
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/logs.ts)_
380
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/logs.ts)_
381
381
 
382
382
  ## `sanity-run functions test NAME`
383
383
 
@@ -410,7 +410,7 @@ EXAMPLES
410
410
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
411
411
  ```
412
412
 
413
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/test.ts)_
413
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.1/src/commands/functions/test.ts)_
414
414
 
415
415
  ## `sanity-run help [COMMAND]`
416
416
 
@@ -3,7 +3,8 @@ import { createRequire } from 'node:module';
3
3
  import { basename, dirname, extname, join } from 'node:path';
4
4
  import { cwd } from 'node:process';
5
5
  import { findUpSync } from 'find-up';
6
- import { BlueprintParserErrorType, isLocalFunctionResource } from '../../utils/types.js';
6
+ import { isLocalFunctionResource } from '../../utils/types.js';
7
+ import { validateFunctionResource } from '../../utils/validate/resource.js';
7
8
  import { blueprintParserValidator } from '../../utils/vendor/parser-validator.js';
8
9
  const SUPPORTED_FILE_EXTENSIONS = ['.json', '.js', '.mjs', '.cjs', '.ts'];
9
10
  const SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER = SUPPORTED_FILE_EXTENSIONS.map((ext) => `blueprint${ext}`);
@@ -109,53 +110,23 @@ export async function readLocalBlueprint(blueprintPath) {
109
110
  }
110
111
  }
111
112
  const parserResult = blueprintParserValidator(rawBlueprint);
112
- const { blueprint: parsedBlueprint } = parserResult;
113
+ const parsedBlueprint = parserResult.blueprint;
113
114
  const errors = parserResult.errors || [];
114
115
  // further validation - remove once validator is updated
115
116
  if (parsedBlueprint.resources) {
117
+ // validate function resources
116
118
  const functionResources = parsedBlueprint.resources.filter(isLocalFunctionResource);
117
- for (const fnR of functionResources) {
118
- if (!fnR.event?.on) {
119
- errors.push({
120
- message: 'Function resource must have an event "on" property',
121
- type: BlueprintParserErrorType.InvalidProperty,
122
- });
123
- }
124
- // if (!fnR.src) {
125
- // // this could be a good spot to infer the src from the name
126
- // // for now anyway
127
- // }
128
- }
119
+ const fnErrors = functionResources.map((r) => validateFunctionResource(r));
120
+ errors.push(...fnErrors.flat());
129
121
  }
130
122
  const configIds = readConfigFile(foundPath);
131
123
  const configPath = configIds?.configPath;
132
- const blueprintMetadata = parsedBlueprint.metadata;
133
- // find projectId
134
124
  let projectId;
135
- if (configIds?.projectId) {
125
+ if (configIds?.projectId)
136
126
  projectId = configIds.projectId;
137
- }
138
- else if (blueprintMetadata?.projectId) {
139
- projectId = blueprintMetadata.projectId;
140
- }
141
- else {
142
- const projectResource = parsedBlueprint.resources.find((r) => r.type === 'sanity.project');
143
- if (projectResource)
144
- projectId = projectResource.id;
145
- }
146
- // find stackId
147
127
  let stackId;
148
- if (configIds?.stackId) {
128
+ if (configIds?.stackId)
149
129
  stackId = configIds.stackId;
150
- }
151
- else if (blueprintMetadata?.stackId) {
152
- stackId = blueprintMetadata.stackId;
153
- }
154
- else {
155
- const stackResource = parsedBlueprint.resources.find((r) => r.type === 'sanity.blueprints.stack');
156
- if (stackResource)
157
- stackId = stackResource.id;
158
- }
159
130
  // LAUNCH LIMIT: 1 Stack per Project - infer stackId from projectId
160
131
  if (!stackId && projectId)
161
132
  stackId = `ST-${projectId}`;
@@ -5,7 +5,7 @@ import highlight from 'color-json';
5
5
  import inquirer from 'inquirer';
6
6
  import { findBlueprintFile } from '../../actions/blueprints/blueprint.js';
7
7
  import { createFunctionResource } from '../../actions/blueprints/resources.js';
8
- import { validateFunctionName, validateFunctionType } from '../../utils/validate/resource.js';
8
+ import { validateFunctionName } from '../../utils/validate/resource.js';
9
9
  export default class AddCommand extends Command {
10
10
  static description = 'Add a (function) resource to a Blueprint';
11
11
  static examples = [
@@ -107,7 +107,7 @@ export default class AddCommand extends Command {
107
107
  }
108
108
  const functionType = type || (await this.promptForFunctionType());
109
109
  const functionLang = lang || (await this.promptForFunctionLang());
110
- if (!validateFunctionType(functionType)) {
110
+ if (!['document-publish', 'document-create', 'document-delete'].includes(functionType)) {
111
111
  this.error('Invalid function type. Must be one of: document-publish, document-create, document-delete');
112
112
  }
113
113
  const { filePath, resourceAdded, resource } = createFunctionResource({
@@ -877,7 +877,7 @@ declare class SelectionRange {
877
877
  the character before its position, 1 the character after, and 0
878
878
  means no association.
879
879
  */
880
- get assoc(): 1 | 0 | -1;
880
+ get assoc(): 0 | 1 | -1;
881
881
  /**
882
882
  The bidirectional text level associated with this cursor, if
883
883
  any.
@@ -1274,8 +1274,8 @@ declare class FacetProvider {
1274
1274
  id: number;
1275
1275
  dynamicSlot(addresses: any): {
1276
1276
  create(state: any): number;
1277
- update(state: any, tr: any): 1 | 0;
1278
- reconfigure: (state: any, oldState: any) => 1 | 0;
1277
+ update(state: any, tr: any): 0 | 1;
1278
+ reconfigure: (state: any, oldState: any) => 0 | 1;
1279
1279
  };
1280
1280
  }
1281
1281
  declare class PrecExtension {
@@ -1,2 +1,4 @@
1
+ import type { LocalFunctionResource } from '../types.js';
2
+ import { type BlueprintParserError } from '../types.js';
1
3
  export declare function validateFunctionName(name: string): boolean;
2
- export declare function validateFunctionType(type: string): boolean;
4
+ export declare function validateFunctionResource(resource: LocalFunctionResource): BlueprintParserError[];
@@ -1,8 +1,97 @@
1
+ import { BlueprintParserErrorType } from '../types.js';
1
2
  export function validateFunctionName(name) {
2
3
  // must be 6+ characters, no special characters, no spaces, allow _ and -
3
4
  return /^[a-zA-Z0-9][a-zA-Z0-9_-]{5,}$/.test(name);
4
5
  }
5
- export function validateFunctionType(type) {
6
- const functionType = type.replace('sanity.function.', '');
7
- return ['document-publish', 'document-create', 'document-delete'].includes(functionType);
6
+ export function validateFunctionResource(resource) {
7
+ const { name: fnName } = resource;
8
+ const msgPrefix = `Function "${fnName}":`;
9
+ const errors = [];
10
+ if (!validateFunctionName(resource.name)) {
11
+ errors.push({
12
+ message: `${msgPrefix} Function name must be at least 6 characters, start with a letter or number, and only contain letters, numbers, _ or -`,
13
+ type: BlueprintParserErrorType.InvalidProperty,
14
+ });
15
+ }
16
+ if (!resource.type.startsWith('sanity.function.')) {
17
+ errors.push({
18
+ message: `${msgPrefix} Resource type must start with "sanity.function."`,
19
+ type: BlueprintParserErrorType.InvalidType,
20
+ });
21
+ }
22
+ if (!resource.event || !Array.isArray(resource.event.on) || resource.event.on.length === 0) {
23
+ errors.push({
24
+ message: `${msgPrefix} event.on must be a non-empty array`,
25
+ type: BlueprintParserErrorType.MissingRequiredProperty,
26
+ });
27
+ }
28
+ else if (resource.event.on[0] !== 'publish') {
29
+ errors.push({
30
+ message: `${msgPrefix} First event.on value must be "publish"`,
31
+ type: BlueprintParserErrorType.InvalidValue,
32
+ });
33
+ }
34
+ if (resource.event?.filter && typeof resource.event.filter !== 'string') {
35
+ errors.push({
36
+ message: `${msgPrefix} event.filter must be a string`,
37
+ type: BlueprintParserErrorType.InvalidType,
38
+ });
39
+ }
40
+ if (resource.event?.projection && typeof resource.event.projection !== 'string') {
41
+ errors.push({
42
+ message: `${msgPrefix} event.projection must be a string`,
43
+ type: BlueprintParserErrorType.InvalidType,
44
+ });
45
+ }
46
+ if (resource.memory !== undefined) {
47
+ if (!Number.isInteger(resource.memory)) {
48
+ errors.push({
49
+ message: `${msgPrefix} memory must be an integer`,
50
+ type: BlueprintParserErrorType.InvalidType,
51
+ });
52
+ }
53
+ else if (resource.memory < 1 || resource.memory > 10) {
54
+ errors.push({
55
+ message: `${msgPrefix} memory must be between 1 and 10 (GB)`,
56
+ type: BlueprintParserErrorType.InvalidValue,
57
+ });
58
+ }
59
+ }
60
+ if (resource.timeout !== undefined) {
61
+ if (!Number.isInteger(resource.timeout)) {
62
+ errors.push({
63
+ message: `${msgPrefix} timeout must be an integer`,
64
+ type: BlueprintParserErrorType.InvalidType,
65
+ });
66
+ }
67
+ else if (resource.timeout < 5 || resource.timeout > 900) {
68
+ errors.push({
69
+ message: `${msgPrefix} timeout must be between 5 and 900 (seconds)`,
70
+ type: BlueprintParserErrorType.InvalidValue,
71
+ });
72
+ }
73
+ }
74
+ if (resource.env !== undefined) {
75
+ if (typeof resource.env !== 'object') {
76
+ errors.push({
77
+ message: `${msgPrefix} env must be an object`,
78
+ type: BlueprintParserErrorType.InvalidType,
79
+ });
80
+ }
81
+ else {
82
+ if (!Object.keys(resource.env).every((key) => typeof key === 'string')) {
83
+ errors.push({
84
+ message: `${msgPrefix} All env keys must be strings`,
85
+ type: BlueprintParserErrorType.InvalidFormat,
86
+ });
87
+ }
88
+ if (!Object.values(resource.env).every((value) => typeof value === 'string')) {
89
+ errors.push({
90
+ message: `${msgPrefix} All env values must be strings`,
91
+ type: BlueprintParserErrorType.InvalidFormat,
92
+ });
93
+ }
94
+ }
95
+ }
96
+ return errors;
8
97
  }
@@ -817,5 +817,5 @@
817
817
  ]
818
818
  }
819
819
  },
820
- "version": "5.0.0"
820
+ "version": "5.0.1"
821
821
  }
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": "5.0.0",
4
+ "version": "5.0.1",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",