@sanity/runtime-cli 16.0.3 → 17.1.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.
Files changed (41) hide show
  1. package/README.md +27 -22
  2. package/dist/actions/functions/test.js +1 -1
  3. package/dist/baseCommands.js +13 -2
  4. package/dist/commands/blueprints/init.js +5 -2
  5. package/dist/config.d.ts +1 -0
  6. package/dist/config.js +7 -1
  7. package/dist/constants.d.ts +1 -0
  8. package/dist/constants.js +1 -0
  9. package/dist/cores/blueprints/init.js +16 -2
  10. package/dist/cores/functions/test.js +44 -0
  11. package/dist/server/app.js +31 -3
  12. package/dist/server/handlers/invoke.d.ts +2 -2
  13. package/dist/server/handlers/invoke.js +7 -4
  14. package/dist/server/static/components/console-panel.js +59 -8
  15. package/dist/server/static/components/rule-panel.js +11 -8
  16. package/dist/server/static/components/shared-styles.js +24 -21
  17. package/dist/server/static/index.html +1 -1
  18. package/dist/server/static/vendor/design-tokens/color.css +48 -48
  19. package/dist/server/static/vendor/design-tokens/index.css +0 -1
  20. package/dist/server/static/vendor/vendor.bundle.js +3807 -3259
  21. package/dist/server/static/web-socket.js +41 -0
  22. package/dist/utils/functions/child-process-wrapper.js +62 -7
  23. package/dist/utils/functions/{invoke-local.d.ts → invoke/local.d.ts} +1 -1
  24. package/dist/utils/functions/invoke/local.js +306 -0
  25. package/dist/utils/functions/invoke/nested.d.ts +25 -0
  26. package/dist/utils/functions/invoke/nested.js +41 -0
  27. package/dist/utils/functions/invoke/prepare.d.ts +20 -0
  28. package/dist/utils/functions/invoke/prepare.js +90 -0
  29. package/dist/utils/interactive.d.ts +1 -0
  30. package/dist/utils/interactive.js +4 -0
  31. package/dist/utils/isTrueish.d.ts +6 -0
  32. package/dist/utils/isTrueish.js +9 -0
  33. package/dist/utils/logger.d.ts +1 -0
  34. package/dist/utils/logger.js +1 -0
  35. package/dist/utils/style-text.js +4 -5
  36. package/dist/utils/traced-fetch.js +2 -0
  37. package/dist/utils/types.d.ts +62 -4
  38. package/oclif.manifest.json +928 -927
  39. package/package.json +18 -14
  40. package/dist/server/static/hot-reload.js +0 -16
  41. package/dist/utils/functions/invoke-local.js +0 -185
@@ -5,6 +5,7 @@ export declare function Logger(log: (msg: string) => void, flags?: {
5
5
  json?: boolean;
6
6
  }): {
7
7
  (msg: string): void;
8
+ isTraceEnabled: boolean;
8
9
  trace(formatter: unknown, ...args: unknown[]): false | void;
9
10
  verbose(formatter: unknown, ...args: unknown[]): false | void;
10
11
  info(formatter: unknown, ...args: unknown[]): false | void;
@@ -13,6 +13,7 @@ export function Logger(log, flags = {}) {
13
13
  log(msg);
14
14
  };
15
15
  const level = flags.verbose ? LogLevel.VERBOSE : flags.trace ? LogLevel.TRACE : LogLevel.INFO;
16
+ logger.isTraceEnabled = level <= LogLevel.TRACE;
16
17
  logger.trace = (formatter, ...args) => level <= LogLevel.TRACE && logger(format(formatter, ...args));
17
18
  logger.verbose = (formatter, ...args) => level <= LogLevel.VERBOSE && logger(format(formatter, ...args));
18
19
  logger.info = (formatter, ...args) => level <= LogLevel.INFO && logger(format(formatter, ...args));
@@ -1,5 +1,6 @@
1
- import { env, stdout } from 'node:process';
1
+ import { env } from 'node:process';
2
2
  import { styleText as nodeStyleText } from 'node:util';
3
+ import { isInteractive } from './interactive.js';
3
4
  function supportsColor() {
4
5
  /*
5
6
  * https://force-color.org
@@ -32,10 +33,8 @@ function supportsColor() {
32
33
  if (env.NODE_DISABLE_COLORS !== undefined && env.NODE_DISABLE_COLORS !== '') {
33
34
  return false;
34
35
  }
35
- /*
36
- * If the stdout is a TTY, use colors.
37
- */
38
- return typeof stdout?.isTTY === 'boolean' && stdout.isTTY;
36
+ // if interactive, use colors
37
+ return isInteractive;
39
38
  }
40
39
  export const styleText = (format, text) => {
41
40
  if (!supportsColor())
@@ -173,6 +173,8 @@ export function createTracedFetch(logger, options) {
173
173
  ...options,
174
174
  };
175
175
  return async (input, init) => {
176
+ if (!logger.isTraceEnabled)
177
+ return fetch(input, init);
176
178
  const requestId = randomUUID().slice(0, 3);
177
179
  const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;
178
180
  const method = init?.method || 'GET';
@@ -98,13 +98,14 @@ export interface InvokeGroqPayloadOptions {
98
98
  before: Record<string, unknown> | null;
99
99
  after: Record<string, unknown> | null;
100
100
  }
101
- export interface InvokeSchedulePayloadOptions {
101
+ export interface InvokeNonGroqPayloadOptions {
102
102
  payload?: Record<string, unknown>;
103
- event: 'scheduled';
103
+ event: NonGroqEventType;
104
104
  }
105
- export type InvokePayloadOptions = InvokeGroqPayloadOptions | InvokeSchedulePayloadOptions;
106
- export type InvokePayloadMetadata = Pick<InvokeGroqPayloadOptions, 'event' | 'before' | 'after'> | Pick<InvokeSchedulePayloadOptions, 'event'>;
105
+ export type InvokePayloadOptions = InvokeGroqPayloadOptions | InvokeNonGroqPayloadOptions;
106
+ export type InvokePayloadMetadata = Pick<InvokeGroqPayloadOptions, 'event' | 'before' | 'after'> | Pick<InvokeNonGroqPayloadOptions, 'event'>;
107
107
  export type EventType = 'create' | 'update' | 'delete';
108
+ export type NonGroqEventType = 'scheduled' | 'nested';
108
109
  export declare function isEventType(arg: string): arg is EventType;
109
110
  /** @internal */
110
111
  export interface InvokeGroqContextOptions {
@@ -140,7 +141,64 @@ export declare function isGroqContextOptions(context: InvokeContextOptions): con
140
141
  export interface InvokeExecutionOptions {
141
142
  forceColor?: boolean;
142
143
  timeout?: number;
144
+ /**
145
+ * Callback used to resolve a nested `context.invoke(name, payload)` made from
146
+ * within a running function. When absent, nested invokes are rejected.
147
+ * @internal
148
+ */
149
+ onNestedInvoke?: NestedInvoke;
150
+ /** Current invocation depth, used to bound nested `context.invoke` recursion. @internal */
151
+ depth?: number;
152
+ /** Function names already on the invoke call stack (innermost last), used to detect cycles. @internal */
153
+ callStack?: string[];
143
154
  }
155
+ /**
156
+ * Re-entrant callback that executes a named function from the blueprint on behalf
157
+ * of a nested `context.invoke(name, payload)` and returns its invocation result.
158
+ * @internal
159
+ */
160
+ export type NestedInvoke = (name: string, payload: Record<string, unknown>, context: InvokeContextOptions, depth: number, callStack: string[]) => Promise<InvocationResponse & {
161
+ timings: Record<string, number>;
162
+ }>;
163
+ /**
164
+ * IPC messages sent from the parent (invoke-local) down to a function child process.
165
+ * @internal
166
+ */
167
+ export type ParentToChildMessage = {
168
+ type: 'start';
169
+ srcPath: string;
170
+ payload: unknown;
171
+ } | {
172
+ type: 'invoke-response';
173
+ id: string;
174
+ ok: true;
175
+ result: {
176
+ json: JsonInvocationResponse | undefined;
177
+ };
178
+ } | {
179
+ type: 'invoke-response';
180
+ id: string;
181
+ ok: false;
182
+ error: InvocationError;
183
+ };
184
+ /**
185
+ * IPC messages sent from a function child process back up to the parent.
186
+ * `result` is terminal and triggers shutdown; `invoke-request` is a nested
187
+ * `context.invoke` awaiting a correlated `invoke-response`.
188
+ * @internal
189
+ */
190
+ export type ChildToParentMessage = {
191
+ type: 'invoke-request';
192
+ id: string;
193
+ name: string;
194
+ payload: Record<string, unknown>;
195
+ } | {
196
+ type: 'result';
197
+ json?: JsonInvocationResponse;
198
+ logs?: string;
199
+ errorLogs?: string;
200
+ error?: InvocationError;
201
+ };
144
202
  /** @internal */
145
203
  export interface InvocationResponse {
146
204
  error: InvocationError | undefined;