@sanity/runtime-cli 10.11.2 → 11.0.2

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.
Files changed (54) hide show
  1. package/README.md +84 -34
  2. package/dist/actions/blueprints/index.d.ts +2 -29
  3. package/dist/actions/blueprints/index.js +0 -42
  4. package/dist/baseCommands.d.ts +5 -4
  5. package/dist/baseCommands.js +6 -4
  6. package/dist/commands/blueprints/add.d.ts +5 -0
  7. package/dist/commands/blueprints/add.js +35 -9
  8. package/dist/commands/blueprints/config.d.ts +1 -0
  9. package/dist/commands/blueprints/config.js +6 -0
  10. package/dist/commands/blueprints/deploy.js +2 -1
  11. package/dist/commands/blueprints/destroy.d.ts +1 -0
  12. package/dist/commands/blueprints/destroy.js +6 -1
  13. package/dist/commands/blueprints/init.d.ts +1 -0
  14. package/dist/commands/blueprints/init.js +4 -0
  15. package/dist/commands/blueprints/stacks.d.ts +1 -0
  16. package/dist/commands/blueprints/stacks.js +7 -0
  17. package/dist/commands/functions/add.d.ts +16 -0
  18. package/dist/commands/functions/add.js +65 -0
  19. package/dist/commands/functions/env/add.js +2 -1
  20. package/dist/commands/functions/env/list.js +2 -1
  21. package/dist/commands/functions/env/remove.js +2 -1
  22. package/dist/commands/functions/logs.js +2 -1
  23. package/dist/commands/functions/test.d.ts +1 -0
  24. package/dist/commands/functions/test.js +5 -0
  25. package/dist/cores/blueprints/config.d.ts +1 -0
  26. package/dist/cores/blueprints/config.js +48 -148
  27. package/dist/cores/blueprints/deploy.d.ts +3 -2
  28. package/dist/cores/blueprints/deploy.js +3 -3
  29. package/dist/cores/blueprints/destroy.d.ts +1 -0
  30. package/dist/cores/blueprints/destroy.js +20 -7
  31. package/dist/cores/blueprints/doctor.js +43 -4
  32. package/dist/cores/blueprints/index.d.ts +0 -2
  33. package/dist/cores/blueprints/index.js +0 -1
  34. package/dist/cores/blueprints/init.d.ts +1 -0
  35. package/dist/cores/blueprints/init.js +3 -1
  36. package/dist/cores/blueprints/plan.js +3 -3
  37. package/dist/cores/blueprints/stacks.d.ts +1 -0
  38. package/dist/cores/blueprints/stacks.js +22 -7
  39. package/dist/cores/{blueprints → functions}/add.d.ts +5 -8
  40. package/dist/cores/{blueprints → functions}/add.js +22 -43
  41. package/dist/cores/functions/index.d.ts +2 -0
  42. package/dist/cores/functions/index.js +1 -0
  43. package/dist/cores/functions/test.d.ts +1 -0
  44. package/dist/cores/functions/test.js +2 -4
  45. package/dist/cores/index.d.ts +3 -2
  46. package/dist/cores/index.js +9 -8
  47. package/dist/server/static/index.html +1 -1
  48. package/dist/server/static/vendor/vendor.bundle.js +30 -5
  49. package/dist/utils/display/errors.js +5 -2
  50. package/dist/utils/display/presenters.d.ts +1 -0
  51. package/dist/utils/display/presenters.js +3 -0
  52. package/dist/utils/types.d.ts +1 -0
  53. package/oclif.manifest.json +213 -3
  54. package/package.json +23 -26
@@ -1,24 +1,39 @@
1
1
  import chalk from 'chalk';
2
2
  import { listStacks } from '../../actions/blueprints/stacks.js';
3
3
  import { formatStacksListing } from '../../utils/display/blueprints-formatting.js';
4
- import { niceId } from '../../utils/display/presenters.js';
4
+ import { capitalize, niceId } from '../../utils/display/presenters.js';
5
5
  export async function blueprintStacksCore(options) {
6
6
  const { log, token, blueprint, flags } = options;
7
- const { projectId: blueprintProjectId, stackId: blueprintStackId } = blueprint;
8
- const projectId = flags['project-id'] || blueprintProjectId;
9
- if (!projectId) {
7
+ const { scopeType: blueprintScopeType, scopeId: blueprintScopeId, stackId: blueprintStackId, } = blueprint;
8
+ const flagProjectId = flags['project-id'];
9
+ const flagOrganizationId = flags['organization-id'];
10
+ if (flagOrganizationId && flagProjectId) {
11
+ log('Cannot specify both --organization-id and --project-id');
12
+ return { success: false, error: 'Cannot specify both --organization-id and --project-id' };
13
+ }
14
+ let scopeType = blueprintScopeType;
15
+ let scopeId = blueprintScopeId;
16
+ if (flagOrganizationId) {
17
+ scopeType = 'organization';
18
+ scopeId = flagOrganizationId;
19
+ }
20
+ if (flagProjectId) {
21
+ scopeType = 'project';
22
+ scopeId = flagProjectId;
23
+ }
24
+ if (!scopeType || !scopeId) {
10
25
  log('Run in a Blueprint directory or provide a Project with --project-id');
11
- return { success: false, error: 'No Project ID provided' };
26
+ return { success: false, error: 'Unable to determine scope for Blueprint Stacks' };
12
27
  }
13
28
  try {
14
- const { ok, stacks, error } = await listStacks({ token, scopeType: 'project', scopeId: projectId });
29
+ const { ok, stacks, error } = await listStacks({ token, scopeType, scopeId });
15
30
  if (!ok)
16
31
  return { success: false, error: error || 'Failed to list stacks' };
17
32
  if (!stacks || stacks.length === 0) {
18
33
  log('No stacks found');
19
34
  return { success: true };
20
35
  }
21
- log(`${chalk.bold('Project')} ${niceId(projectId)} ${chalk.bold('Stacks')}:\n`);
36
+ log(`${chalk.bold(capitalize(scopeType))} ${niceId(scopeId)} ${chalk.bold('Stacks')}:\n`);
22
37
  log(formatStacksListing(stacks, blueprintStackId));
23
38
  return { success: true };
24
39
  }
@@ -1,19 +1,16 @@
1
1
  import type { ReadBlueprintResult } from '../../actions/blueprints/blueprint.js';
2
2
  import type { CoreConfig, CoreResult } from '../index.js';
3
- export interface BlueprintAddOptions extends CoreConfig {
3
+ export interface FunctionAddOptions extends CoreConfig {
4
4
  blueprint: ReadBlueprintResult;
5
- args: {
6
- type: string;
7
- };
8
5
  flags: {
9
6
  example?: string;
10
7
  name?: string;
11
- 'fn-type'?: string | string[];
8
+ type?: string | string[];
12
9
  language?: string;
13
10
  javascript?: boolean;
14
- 'fn-helpers'?: boolean;
15
- 'fn-installer'?: string;
11
+ helpers?: boolean;
12
+ installer?: string;
16
13
  install?: boolean;
17
14
  };
18
15
  }
19
- export declare function blueprintAddCore(options: BlueprintAddOptions): Promise<CoreResult>;
16
+ export declare function functionAddCore(options: FunctionAddOptions): Promise<CoreResult>;
@@ -16,31 +16,20 @@ const generateFunctionBlueprintResourceTemplate = (fnName, eventNames) => `
16
16
  ],
17
17
  })
18
18
  `;
19
- export async function blueprintAddCore(options) {
19
+ export async function functionAddCore(options) {
20
20
  const root = cwd();
21
- const { log, blueprint, args, flags } = options;
21
+ const { log, blueprint, flags } = options;
22
22
  const { blueprintFilePath } = blueprint.fileInfo;
23
- const { type: resourceType } = args;
24
- const { example: flagExample, name: flagResourceName, 'fn-type': flagFnType, javascript: flagJs, 'fn-helpers': flagFnHelpers, install: flagI, 'fn-installer': flagFnInstaller, // can be 'skip'!
25
- } = flags;
26
- let { language: flagFnLang } = flags;
27
- flagFnLang = flagJs ? 'js' : flagFnLang;
28
- if (resourceType !== 'function') {
29
- return {
30
- success: false,
31
- error: `Unsupported Resource type: ${resourceType}`,
32
- };
33
- }
23
+ const { example: flagExample, name: flagResourceName, type: flagType, javascript: flagJs, helpers: flagHelpers, install: flagI, installer: flagInstaller, } = flags;
24
+ let { language: flagLang } = flags;
25
+ flagLang = flagJs ? 'js' : flagLang;
34
26
  if (flagExample) {
35
- // ! short circuit for examples
36
- log(warn(`Example feature is experimental. Setting up "${flagExample}"...`)); // we need to...
37
- // * 1. verify example exists in the recipes repo
27
+ // short circuit whole command for example flag
28
+ log(`Setting up "${flagExample}"...`);
38
29
  const exampleExists = await verifyExampleExists({ type: 'function', name: flagExample });
39
30
  if (!exampleExists) {
40
31
  return { success: false, error: `Function example "${flagExample}" does not exist.` };
41
32
  }
42
- // * 2. download and write example to disk
43
- // TODO: revisit path string handling; differs for fs operations vs. display
44
33
  const exampleDir = join(dirname(blueprintFilePath), 'functions', flagExample);
45
34
  if (existsSync(exampleDir)) {
46
35
  return {
@@ -61,7 +50,6 @@ export async function blueprintAddCore(options) {
61
50
  for (const filePath of Object.keys(files)) {
62
51
  log(check(`${chalk.bold('Created:')} ${newDir}/${filePath}`));
63
52
  }
64
- // * 3. print instructions
65
53
  if (functionConfig) {
66
54
  log('');
67
55
  log(chalk.bold(`Add the following to ${blueprint.fileInfo.fileName}:`));
@@ -70,7 +58,6 @@ export async function blueprintAddCore(options) {
70
58
  log(indent(highlight(configString)));
71
59
  }
72
60
  else {
73
- // modify configString so it doesn't have quoted keys
74
61
  const objectLiteral = configString.replace(/^(\s*)"([a-zA-Z_$][a-zA-Z0-9_$]*)":/gm, '$1$2:');
75
62
  log(indent(highlight(`defineDocumentFunction(${objectLiteral})`)));
76
63
  }
@@ -85,29 +72,27 @@ export async function blueprintAddCore(options) {
85
72
  return { success: true };
86
73
  }
87
74
  if (flagI) {
88
- if (flagFnInstaller) {
75
+ if (flagInstaller) {
89
76
  return {
90
77
  success: false,
91
- error: 'Cannot use --fn-installer flag with the --install flag',
78
+ error: 'Cannot use --installer flag with the --install flag',
92
79
  };
93
80
  }
94
- if (!flagFnHelpers) {
81
+ if (!flagHelpers) {
95
82
  return {
96
83
  success: false,
97
- error: 'Cannot use --no-fn-helpers flag with the --install flag',
84
+ error: 'Cannot use --no-helpers flag with the --install flag',
98
85
  };
99
86
  }
100
87
  }
101
88
  if (flagResourceName && !validateFunctionName(flagResourceName)) {
102
- // if provided && invalid, return error ASAP
103
89
  return {
104
90
  success: false,
105
- error: `Invalid function name: ${flagResourceName}`,
91
+ error: `Invalid function name: "${chalk.bold(flagResourceName)}"`,
106
92
  };
107
93
  }
108
94
  try {
109
95
  const fnName = flagResourceName || (await promptForFunctionName());
110
- // look for existing function with same name
111
96
  if (blueprint.parsedBlueprint.resources?.some((r) => r.name === fnName)) {
112
97
  return {
113
98
  success: false,
@@ -115,18 +100,18 @@ export async function blueprintAddCore(options) {
115
100
  };
116
101
  }
117
102
  let fnTypes;
118
- if (flagFnType) {
119
- if (Array.isArray(flagFnType)) {
120
- fnTypes = flagFnType;
103
+ if (flagType) {
104
+ if (Array.isArray(flagType)) {
105
+ fnTypes = flagType;
121
106
  }
122
107
  else {
123
- fnTypes = [flagFnType];
108
+ fnTypes = [flagType];
124
109
  }
125
110
  }
126
111
  else {
127
112
  fnTypes = await promptForFunctionType();
128
113
  }
129
- const fnLang = flagFnLang || (await promptForFunctionLang());
114
+ const fnLang = flagLang || (await promptForFunctionLang());
130
115
  if (fnTypes.length === 0) {
131
116
  throw new Error('At least one function type must be provided.');
132
117
  }
@@ -136,27 +121,23 @@ export async function blueprintAddCore(options) {
136
121
  let addHelpers;
137
122
  let installCommand;
138
123
  if (!['ts', 'js'].includes(fnLang)) {
139
- // language is not supported
140
124
  addHelpers = false;
141
125
  installCommand = null;
142
126
  }
143
- else if (flagFnHelpers === false) {
144
- // explicit "false" means user does not want helpers: "--no-fn-helpers"
127
+ else if (flagHelpers === false) {
145
128
  addHelpers = false;
146
129
  installCommand = null;
147
130
  }
148
131
  else if (flagI) {
149
- // user wants to install helpers with npm
150
132
  addHelpers = true;
151
133
  installCommand = 'npm';
152
134
  }
153
- else if (flagFnInstaller) {
154
- addHelpers = true; // if installer is passed, assume addHelpers
155
- installCommand = flagFnInstaller === 'skip' ? null : flagFnInstaller;
135
+ else if (flagInstaller) {
136
+ addHelpers = true;
137
+ installCommand = flagInstaller === 'skip' ? null : flagInstaller;
156
138
  }
157
139
  else {
158
- // unsure; ask...
159
- addHelpers = flagFnHelpers || (await promptForAddHelpers());
140
+ addHelpers = flagHelpers || (await promptForAddHelpers());
160
141
  installCommand = addHelpers ? await promptForInstallCommand() : null;
161
142
  }
162
143
  if (installCommand)
@@ -171,7 +152,6 @@ export async function blueprintAddCore(options) {
171
152
  });
172
153
  log(`\nCreated function: ${filePath.replace(root, '')}`);
173
154
  if (!resourceAdded) {
174
- // print the resource definition for manual addition
175
155
  log(`\n${chalk.bold('Add the Resource to your Blueprint:')}`);
176
156
  switch (blueprint.fileInfo.extension) {
177
157
  case '.ts':
@@ -186,7 +166,6 @@ export async function blueprintAddCore(options) {
186
166
  }
187
167
  }
188
168
  else {
189
- // added to blueprint.json
190
169
  log(`Function "${chalk.bold(fnName)}" added to Blueprint file.`);
191
170
  }
192
171
  return { success: true };
@@ -1,3 +1,5 @@
1
+ export type { FunctionAddOptions } from './add.js';
2
+ export { functionAddCore } from './add.js';
1
3
  export type { FunctionDevOptions } from './dev.js';
2
4
  export { functionDevCore } from './dev.js';
3
5
  export type { FunctionEnvAddOptions as EnvAddOptions } from './env/add.js';
@@ -1,3 +1,4 @@
1
+ export { functionAddCore } from './add.js';
1
2
  export { functionDevCore } from './dev.js';
2
3
  export { functionEnvAddCore } from './env/add.js';
3
4
  export { functionEnvListCore } from './env/list.js';
@@ -13,6 +13,7 @@ export interface FunctionTestOptions extends CoreConfig {
13
13
  api?: string;
14
14
  dataset?: string;
15
15
  'project-id'?: string;
16
+ 'organization-id'?: string;
16
17
  'document-id'?: string;
17
18
  'with-user-token'?: boolean;
18
19
  'data-before'?: string;
@@ -13,11 +13,8 @@ export async function functionTestCore(options) {
13
13
  const { blueprint, log, args, flags } = options;
14
14
  const { name: fnName } = args;
15
15
  const { data, event, file, timeout, api, dataset, 'document-id': documentId, 'with-user-token': withUserToken, 'data-before': dataBefore, 'data-after': dataAfter, 'file-before': fileBefore, 'file-after': fileAfter, 'document-id-before': documentIdBefore, 'document-id-after': documentIdAfter, } = flags;
16
- let { 'project-id': projectId } = flags;
17
16
  const { parsedBlueprint } = blueprint;
18
- if (!projectId && blueprint?.projectId) {
19
- projectId = blueprint.projectId;
20
- }
17
+ const { 'project-id': projectId = blueprint?.projectId, 'organization-id': organizationId = blueprint?.organizationId, } = flags;
21
18
  let eventType;
22
19
  if (!event) {
23
20
  eventType = 'create';
@@ -38,6 +35,7 @@ export async function functionTestCore(options) {
38
35
  apiVersion: api,
39
36
  dataset,
40
37
  projectId,
38
+ organizationId,
41
39
  },
42
40
  };
43
41
  // If the user sets the flag to use the real token set it in our options
@@ -1,5 +1,5 @@
1
1
  import { type ReadBlueprintResult } from '../actions/blueprints/blueprint.js';
2
- import type { AuthParams, Result, Stack } from '../utils/types.js';
2
+ import type { AuthParams, Result, ScopeType, Stack } from '../utils/types.js';
3
3
  export * as blueprintsCores from './blueprints/index.js';
4
4
  export * as functionsCores from './functions/index.js';
5
5
  export interface CoreConfig {
@@ -14,7 +14,8 @@ export interface BlueprintConfig extends CoreConfig {
14
14
  }
15
15
  export interface DeployedBlueprintConfig extends BlueprintConfig {
16
16
  stackId: string;
17
- projectId: string;
17
+ scopeType: ScopeType;
18
+ scopeId: string;
18
19
  auth: AuthParams;
19
20
  deployedStack: Stack;
20
21
  }
@@ -40,19 +40,19 @@ export async function initDeployedBlueprintConfig(config) {
40
40
  config.blueprint = blueprintResult.value.blueprint;
41
41
  config.token = blueprintResult.value.token;
42
42
  }
43
- const { projectId, stackId } = config.blueprint;
44
- if (!(projectId && stackId)) {
45
- config.log(`Run \`${config.bin} blueprints config --edit --test\` to update your config`);
46
- if (!projectId)
47
- return { ok: false, error: 'Missing Project configuration for Blueprint' };
43
+ const { scopeType, scopeId, stackId } = config.blueprint;
44
+ if (!(scopeType && scopeId && stackId)) {
45
+ config.log(`Incomplete configuration. Run \`${config.bin} blueprints doctor\` for diagnostics.`);
46
+ if (!scopeType || !scopeId)
47
+ return { ok: false, error: 'Missing scope configuration for Blueprint' };
48
48
  if (!stackId)
49
49
  return { ok: false, error: 'Missing deployment configuration for Blueprint' };
50
50
  }
51
- const auth = { token: config.token, scopeType: 'project', scopeId: projectId };
51
+ const auth = { token: config.token, scopeType, scopeId };
52
52
  const stackResponse = await getStack({ stackId, auth });
53
53
  if (!stackResponse.ok) {
54
54
  config.log(`Could not retrieve deployment info for ${niceId(stackId)}. Was it destroyed?`);
55
- config.log(`Run \`${config.bin} blueprints config --edit --test\` to update your config`);
55
+ config.log(`Run \`${config.bin} blueprints doctor\` for diagnostics.`);
56
56
  return { ok: false, error: 'Missing deployment' };
57
57
  }
58
58
  return {
@@ -62,7 +62,8 @@ export async function initDeployedBlueprintConfig(config) {
62
62
  log: config.log,
63
63
  blueprint: config.blueprint,
64
64
  token: config.token,
65
- projectId,
65
+ scopeType,
66
+ scopeId,
66
67
  stackId,
67
68
  auth,
68
69
  deployedStack: stackResponse.stack,
@@ -39,7 +39,7 @@
39
39
  <main id="main-content" style='max-height: 100%; overflow: hidden;'>
40
40
  <payload-panel></payload-panel>
41
41
  <div>
42
- <rule-panel></rule-paneL>
42
+ <rule-panel></rule-panel>
43
43
  <response-panel></response-panel>
44
44
  </div>
45
45
  <console-panel></console-panel>
@@ -24,6 +24,7 @@ class NodeProp {
24
24
  this.deserialize = config.deserialize || (() => {
25
25
  throw new Error("This node type doesn't define a deserialize function");
26
26
  });
27
+ this.combine = config.combine || null;
27
28
  }
28
29
  /**
29
30
  This is meant to be used with
@@ -288,7 +289,10 @@ class NodeSet {
288
289
  if (add) {
289
290
  if (!newProps)
290
291
  newProps = Object.assign({}, type.props);
291
- newProps[add[0].id] = add[1];
292
+ let value = add[1], prop = add[0];
293
+ if (prop.combine && prop.id in newProps)
294
+ value = prop.combine(newProps[prop.id], value);
295
+ newProps[prop.id] = value;
292
296
  }
293
297
  }
294
298
  newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
@@ -1271,7 +1275,7 @@ function buildTree(data) {
1271
1275
  function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
1272
1276
  let { id, start, end, size } = cursor;
1273
1277
  let lookAheadAtStart = lookAhead, contextAtStart = contextHash;
1274
- while (size < 0) {
1278
+ if (size < 0) {
1275
1279
  cursor.next();
1276
1280
  if (size == -1 /* SpecialRecord.Reuse */) {
1277
1281
  let node = reused[id];
@@ -3663,7 +3667,7 @@ must be quoted as JSON strings.
3663
3667
  For example:
3664
3668
 
3665
3669
  ```javascript
3666
- parser.withProps(
3670
+ parser.configure({props: [
3667
3671
  styleTags({
3668
3672
  // Style Number and BigNumber nodes
3669
3673
  "Number BigNumber": tags.number,
@@ -3678,7 +3682,7 @@ parser.withProps(
3678
3682
  // Style the node named "/" as punctuation
3679
3683
  '"/"': tags.punctuation
3680
3684
  })
3681
- )
3685
+ ]})
3682
3686
  ```
3683
3687
  */
3684
3688
  function styleTags(spec) {
@@ -3720,7 +3724,28 @@ function styleTags(spec) {
3720
3724
  }
3721
3725
  return ruleNodeProp.add(byName);
3722
3726
  }
3723
- const ruleNodeProp = new NodeProp();
3727
+ const ruleNodeProp = new NodeProp({
3728
+ combine(a, b) {
3729
+ let cur, root, take;
3730
+ while (a || b) {
3731
+ if (!a || a.depth > b.depth) {
3732
+ take = b;
3733
+ b = b.next;
3734
+ }
3735
+ else {
3736
+ take = a;
3737
+ a = a.next;
3738
+ }
3739
+ let copy = new Rule(take.tags, take.mode, take.context);
3740
+ if (cur)
3741
+ cur.next = copy;
3742
+ else
3743
+ root = copy;
3744
+ cur = copy;
3745
+ }
3746
+ return root;
3747
+ }
3748
+ });
3724
3749
  class Rule {
3725
3750
  constructor(tags, mode, context, next) {
3726
3751
  this.tags = tags;
@@ -10,8 +10,11 @@ export function presentBlueprintIssues(issues) {
10
10
  case 'NO_STACK_ID':
11
11
  report.push('Existing deployment not found.');
12
12
  break;
13
- case 'NO_PROJECT_ID':
14
- report.push('Project ID not found.');
13
+ case 'NO_SCOPE_TYPE':
14
+ report.push('Scope type not found.');
15
+ break;
16
+ case 'NO_SCOPE_ID':
17
+ report.push('Scope ID not found.');
15
18
  break;
16
19
  case 'NO_STACK':
17
20
  report.push('Existing deployment not found.');
@@ -4,3 +4,4 @@ export declare function warn(str: string): string;
4
4
  export declare function severe(str: string): string;
5
5
  export declare function niceId(id: string | undefined): string;
6
6
  export declare function indent(str: string, spaces?: number): string;
7
+ export declare function capitalize(str: string): string;
@@ -23,3 +23,6 @@ export function indent(str, spaces = 2) {
23
23
  .map((line) => (line.length > 0 ? pad + line : line))
24
24
  .join('\n');
25
25
  }
26
+ export function capitalize(str) {
27
+ return str.charAt(0).toUpperCase() + str.slice(1);
28
+ }
@@ -99,6 +99,7 @@ export interface InvokeContextOptions {
99
99
  apiVersion?: string;
100
100
  dataset?: string;
101
101
  projectId?: string;
102
+ organizationId?: string;
102
103
  token?: string;
103
104
  };
104
105
  }