@sanity/runtime-cli 14.11.0 → 14.12.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.
Files changed (63) hide show
  1. package/README.md +45 -43
  2. package/dist/actions/blueprints/blueprint.d.ts +49 -16
  3. package/dist/actions/blueprints/blueprint.js +97 -139
  4. package/dist/actions/blueprints/resolve.d.ts +51 -0
  5. package/dist/actions/blueprints/resolve.js +52 -0
  6. package/dist/actions/blueprints/resources.js +35 -12
  7. package/dist/actions/functions/dev.d.ts +1 -2
  8. package/dist/actions/functions/dev.js +2 -2
  9. package/dist/baseCommands.d.ts +47 -30
  10. package/dist/baseCommands.js +187 -72
  11. package/dist/commands/blueprints/add.d.ts +3 -2
  12. package/dist/commands/blueprints/add.js +3 -2
  13. package/dist/commands/blueprints/config.d.ts +3 -2
  14. package/dist/commands/blueprints/config.js +3 -2
  15. package/dist/commands/blueprints/deploy.d.ts +3 -2
  16. package/dist/commands/blueprints/deploy.js +4 -3
  17. package/dist/commands/blueprints/destroy.d.ts +3 -2
  18. package/dist/commands/blueprints/destroy.js +3 -2
  19. package/dist/commands/blueprints/doctor.d.ts +0 -1
  20. package/dist/commands/blueprints/doctor.js +2 -3
  21. package/dist/commands/blueprints/info.d.ts +4 -2
  22. package/dist/commands/blueprints/info.js +6 -3
  23. package/dist/commands/blueprints/init.d.ts +0 -1
  24. package/dist/commands/blueprints/init.js +1 -2
  25. package/dist/commands/blueprints/logs.d.ts +3 -2
  26. package/dist/commands/blueprints/logs.js +4 -3
  27. package/dist/commands/blueprints/plan.d.ts +3 -2
  28. package/dist/commands/blueprints/plan.js +5 -3
  29. package/dist/commands/blueprints/promote.d.ts +3 -2
  30. package/dist/commands/blueprints/promote.js +3 -2
  31. package/dist/commands/blueprints/stacks.d.ts +3 -2
  32. package/dist/commands/blueprints/stacks.js +3 -2
  33. package/dist/commands/functions/add.d.ts +3 -2
  34. package/dist/commands/functions/add.js +4 -3
  35. package/dist/commands/functions/build.d.ts +3 -2
  36. package/dist/commands/functions/build.js +3 -2
  37. package/dist/commands/functions/dev.d.ts +3 -2
  38. package/dist/commands/functions/dev.js +3 -2
  39. package/dist/commands/functions/env/add.d.ts +3 -2
  40. package/dist/commands/functions/env/add.js +3 -2
  41. package/dist/commands/functions/env/list.d.ts +3 -2
  42. package/dist/commands/functions/env/list.js +3 -2
  43. package/dist/commands/functions/env/remove.d.ts +3 -2
  44. package/dist/commands/functions/env/remove.js +3 -2
  45. package/dist/commands/functions/logs.d.ts +3 -2
  46. package/dist/commands/functions/logs.js +4 -3
  47. package/dist/commands/functions/test.d.ts +3 -2
  48. package/dist/commands/functions/test.js +3 -2
  49. package/dist/constants.d.ts +15 -2
  50. package/dist/constants.js +14 -10
  51. package/dist/cores/blueprints/config.js +9 -4
  52. package/dist/cores/blueprints/destroy.js +78 -56
  53. package/dist/cores/blueprints/doctor.js +19 -5
  54. package/dist/cores/blueprints/init.js +2 -2
  55. package/dist/cores/functions/add.js +11 -7
  56. package/dist/cores/functions/dev.js +1 -1
  57. package/dist/server/app.d.ts +1 -2
  58. package/dist/server/app.js +16 -8
  59. package/dist/server/handlers/invoke.d.ts +1 -2
  60. package/dist/server/handlers/invoke.js +4 -4
  61. package/dist/server/static/components/rule-panel.js +8 -10
  62. package/oclif.manifest.json +503 -73
  63. package/package.json +2 -2
@@ -2,19 +2,25 @@ import { existsSync, readFileSync, watchFile } from 'node:fs';
2
2
  import * as http from 'node:http';
3
3
  import { default as mime } from 'mime-types';
4
4
  import { WebSocketServer } from 'ws';
5
- import { readLocalBlueprint } from '../actions/blueprints/blueprint.js';
5
+ import { findBlueprintFile, loadAndParseBlueprint } from '../actions/blueprints/blueprint.js';
6
+ import { readConfigFile } from '../actions/blueprints/config.js';
7
+ import { resolveIds } from '../actions/blueprints/resolve.js';
6
8
  import config from '../config.js';
7
9
  import { isRecord } from '../utils/is-record.js';
8
10
  import { isEventType, isGroqContextOptions, } from '../utils/types.js';
9
11
  import { handleInvokeRequest } from './handlers/invoke.js';
10
- const app = (host, port, logger, validateResources, executionOptions) => {
12
+ const app = (host, port, validateResources, executionOptions) => {
11
13
  const requestListener = async (req, res) => {
12
14
  res.setHeader('Content-Type', 'application/json');
13
15
  switch (true) {
14
16
  case req.url === '/blueprint': {
15
17
  try {
16
- const { parsedBlueprint, projectId, organizationId } = await readLocalBlueprint(logger, {
17
- resources: validateResources,
18
+ const blueprint = await loadAndParseBlueprint(undefined, { validateResources });
19
+ const { parsedBlueprint, fileInfo, module: blueprintModule } = blueprint;
20
+ const blueprintConfig = readConfigFile(fileInfo.blueprintFilePath);
21
+ const { projectId, organizationId } = resolveIds({
22
+ module: blueprintModule,
23
+ config: blueprintConfig,
18
24
  });
19
25
  res.setHeader('Content-Type', 'application/json');
20
26
  res.writeHead(200);
@@ -44,7 +50,7 @@ const app = (host, port, logger, validateResources, executionOptions) => {
44
50
  delete context.clientOptions.token;
45
51
  }
46
52
  }
47
- const result = await handleInvokeRequest(functionName, event, metadata, context, logger, validateResources, executionOptions);
53
+ const result = await handleInvokeRequest(functionName, event, metadata, context, validateResources, executionOptions);
48
54
  // Add Server-Timing header
49
55
  const timingHeaders = [];
50
56
  for (const [key, value] of Object.entries(result.timings)) {
@@ -230,10 +236,12 @@ const app = (host, port, logger, validateResources, executionOptions) => {
230
236
  const server = http.createServer(requestListener);
231
237
  server.listen(port, host, () => { });
232
238
  const wss = new WebSocketServer({ port: 8974 });
233
- wss.on('connection', async function connection(ws) {
239
+ wss.on('connection', function connection(ws) {
234
240
  ws.on('error', console.error);
235
- const { fileInfo } = await readLocalBlueprint(logger, { resources: validateResources });
236
- watchFile(fileInfo.blueprintFilePath, { interval: 2007 }, async () => {
241
+ const fileInfo = findBlueprintFile();
242
+ if (!fileInfo)
243
+ return;
244
+ watchFile(fileInfo.blueprintFilePath, { interval: 2007 }, () => {
237
245
  ws.send('reload-blueprint');
238
246
  });
239
247
  });
@@ -1,5 +1,4 @@
1
- import type { Logger } from '../../utils/logger.js';
2
1
  import type { InvocationResponse, InvokeContextOptions, InvokeExecutionOptions, InvokePayloadMetadata } from '../../utils/types.js';
3
- export declare function handleInvokeRequest(functionName: string, event: Record<string, unknown>, metadata: InvokePayloadMetadata, context: InvokeContextOptions, logger: Logger, validateResources: boolean, executionOptions?: Partial<InvokeExecutionOptions>): Promise<InvocationResponse & {
2
+ export declare function handleInvokeRequest(functionName: string, event: Record<string, unknown>, metadata: InvokePayloadMetadata, context: InvokeContextOptions, validateResources: boolean, executionOptions?: Partial<InvokeExecutionOptions>): Promise<InvocationResponse & {
4
3
  timings: Record<string, number>;
5
4
  }>;
@@ -1,10 +1,10 @@
1
- import { readLocalBlueprint } from '../../actions/blueprints/blueprint.js';
1
+ import { loadAndParseBlueprint } from '../../actions/blueprints/blueprint.js';
2
2
  import { findFunctionInResources } from '../../utils/find-function.js';
3
3
  import invoke from '../../utils/invoke-local.js';
4
- export async function handleInvokeRequest(functionName, event, metadata, context, logger, validateResources, executionOptions) {
4
+ export async function handleInvokeRequest(functionName, event, metadata, context, validateResources, executionOptions) {
5
5
  const start = performance.now();
6
- const blueprint = await readLocalBlueprint(logger, { resources: validateResources });
7
- const resource = findFunctionInResources(blueprint.resources, functionName);
6
+ const { resources } = await loadAndParseBlueprint(undefined, { validateResources });
7
+ const resource = findFunctionInResources(resources, functionName);
8
8
  const readBlueprintTime = performance.now() - start;
9
9
  const payload = {
10
10
  payload: event,
@@ -43,16 +43,14 @@ class RulePanel extends ApiBaseElement {
43
43
  break
44
44
  }
45
45
 
46
- if (func.event) {
47
- const transaction = rule.state.update({
48
- changes: {
49
- from: 0,
50
- insert: JSON.stringify(func.event, null, 2),
51
- to: rule.state.doc.length,
52
- },
53
- })
54
- rule.dispatch(transaction)
55
- }
46
+ const transaction = rule.state.update({
47
+ changes: {
48
+ from: 0,
49
+ insert: func.event ? JSON.stringify(func.event, null, 2) : '',
50
+ to: rule.state.doc.length,
51
+ },
52
+ })
53
+ rule.dispatch(transaction)
56
54
  }
57
55
 
58
56
  async connectedCallback() {