@sanity/runtime-cli 4.3.5-bundle.0 → 4.4.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 (42) hide show
  1. package/README.md +17 -17
  2. package/dist/actions/blueprints/assets.d.ts +0 -1
  3. package/dist/actions/blueprints/assets.js +4 -21
  4. package/dist/actions/functions/test.d.ts +2 -2
  5. package/dist/actions/functions/test.js +2 -2
  6. package/dist/commands/functions/test.js +6 -3
  7. package/dist/server/app.js +12 -80
  8. package/dist/server/static/api.js +3 -24
  9. package/dist/server/static/components/app.css +117 -0
  10. package/dist/server/static/components/console-panel.d.ts +1 -0
  11. package/dist/server/static/components/console-panel.js +53 -0
  12. package/dist/server/static/components/filters.js +4 -3
  13. package/dist/server/static/components/function-list.js +4 -4
  14. package/dist/server/static/components/response-panel.js +25 -28
  15. package/dist/server/static/index.html +4 -2
  16. package/dist/server/static/vendor/vendor.bundle.d.ts +2 -2
  17. package/dist/utils/build-payload.d.ts +1 -1
  18. package/dist/utils/build-payload.js +3 -3
  19. package/dist/utils/child-process-wrapper.js +6 -8
  20. package/dist/utils/invoke-local.d.ts +2 -2
  21. package/dist/utils/invoke-local.js +7 -48
  22. package/dist/utils/is-json.d.ts +1 -0
  23. package/dist/utils/is-json.js +12 -0
  24. package/dist/utils/types.d.ts +1 -3
  25. package/oclif.manifest.json +1 -1
  26. package/package.json +1 -4
  27. package/dist/utils/bundle/bundle-function.d.ts +0 -8
  28. package/dist/utils/bundle/bundle-function.js +0 -125
  29. package/dist/utils/bundle/cleanup-source-maps.d.ts +0 -10
  30. package/dist/utils/bundle/cleanup-source-maps.js +0 -53
  31. package/dist/utils/bundle/find-up.d.ts +0 -16
  32. package/dist/utils/bundle/find-up.js +0 -39
  33. package/dist/utils/bundle/verify-handler.d.ts +0 -2
  34. package/dist/utils/bundle/verify-handler.js +0 -13
  35. package/dist/utils/functions/find-entry-point.d.ts +0 -11
  36. package/dist/utils/functions/find-entry-point.js +0 -75
  37. package/dist/utils/functions/should-bundle.d.ts +0 -2
  38. package/dist/utils/functions/should-bundle.js +0 -23
  39. package/dist/utils/is-record.d.ts +0 -1
  40. package/dist/utils/is-record.js +0 -3
  41. package/dist/utils/parse-json-object.d.ts +0 -1
  42. package/dist/utils/parse-json-object.js +0 -10
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/4.3.5-bundle.0 darwin-arm64 node-v22.14.0
23
+ @sanity/runtime-cli/4.4.0 linux-x64 node-v22.15.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -74,7 +74,7 @@ EXAMPLES
74
74
  $ sanity-run blueprints add function --name my-function --function-type document-publish
75
75
  ```
76
76
 
77
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/add.ts)_
77
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/add.ts)_
78
78
 
79
79
  ## `sanity-run blueprints config`
80
80
 
@@ -103,7 +103,7 @@ EXAMPLES
103
103
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
104
104
  ```
105
105
 
106
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/config.ts)_
106
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/config.ts)_
107
107
 
108
108
  ## `sanity-run blueprints deploy`
109
109
 
@@ -123,7 +123,7 @@ EXAMPLES
123
123
  $ sanity-run blueprints deploy
124
124
  ```
125
125
 
126
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/deploy.ts)_
126
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/deploy.ts)_
127
127
 
128
128
  ## `sanity-run blueprints destroy`
129
129
 
@@ -146,7 +146,7 @@ EXAMPLES
146
146
  $ sanity-run blueprints destroy --id ST-a1b2c3
147
147
  ```
148
148
 
149
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/destroy.ts)_
149
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/destroy.ts)_
150
150
 
151
151
  ## `sanity-run blueprints info`
152
152
 
@@ -168,7 +168,7 @@ EXAMPLES
168
168
  $ sanity-run blueprints info --id ST-a1b2c3
169
169
  ```
170
170
 
171
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/info.ts)_
171
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/info.ts)_
172
172
 
173
173
  ## `sanity-run blueprints init`
174
174
 
@@ -198,7 +198,7 @@ EXAMPLES
198
198
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId> --stack-name <stackName>
199
199
  ```
200
200
 
201
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/init.ts)_
201
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/init.ts)_
202
202
 
203
203
  ## `sanity-run blueprints logs`
204
204
 
@@ -220,7 +220,7 @@ EXAMPLES
220
220
  $ sanity-run blueprints logs --watch
221
221
  ```
222
222
 
223
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/logs.ts)_
223
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/logs.ts)_
224
224
 
225
225
  ## `sanity-run blueprints plan`
226
226
 
@@ -237,7 +237,7 @@ EXAMPLES
237
237
  $ sanity-run blueprints plan
238
238
  ```
239
239
 
240
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/plan.ts)_
240
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/plan.ts)_
241
241
 
242
242
  ## `sanity-run blueprints stacks`
243
243
 
@@ -259,7 +259,7 @@ EXAMPLES
259
259
  $ sanity-run blueprints stacks --projectId a1b2c3
260
260
  ```
261
261
 
262
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/blueprints/stacks.ts)_
262
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/blueprints/stacks.ts)_
263
263
 
264
264
  ## `sanity-run functions dev`
265
265
 
@@ -279,7 +279,7 @@ EXAMPLES
279
279
  $ sanity-run functions dev --port 8974
280
280
  ```
281
281
 
282
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/dev.ts)_
282
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/dev.ts)_
283
283
 
284
284
  ## `sanity-run functions env add NAME KEY VALUE`
285
285
 
@@ -301,7 +301,7 @@ EXAMPLES
301
301
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
302
302
  ```
303
303
 
304
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/env/add.ts)_
304
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/env/add.ts)_
305
305
 
306
306
  ## `sanity-run functions env list NAME`
307
307
 
@@ -321,7 +321,7 @@ EXAMPLES
321
321
  $ sanity-run functions env list MyFunction
322
322
  ```
323
323
 
324
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/env/list.ts)_
324
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/env/list.ts)_
325
325
 
326
326
  ## `sanity-run functions env remove NAME KEY`
327
327
 
@@ -342,7 +342,7 @@ EXAMPLES
342
342
  $ sanity-run functions env remove MyFunction API_URL
343
343
  ```
344
344
 
345
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/env/remove.ts)_
345
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/env/remove.ts)_
346
346
 
347
347
  ## `sanity-run functions invoke NAME`
348
348
 
@@ -368,7 +368,7 @@ EXAMPLES
368
368
  $ sanity-run functions invoke <name> --file 'payload.json'
369
369
  ```
370
370
 
371
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/invoke.ts)_
371
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/invoke.ts)_
372
372
 
373
373
  ## `sanity-run functions logs NAME`
374
374
 
@@ -400,7 +400,7 @@ EXAMPLES
400
400
  $ sanity-run functions logs <name> --delete
401
401
  ```
402
402
 
403
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/logs.ts)_
403
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/logs.ts)_
404
404
 
405
405
  ## `sanity-run functions test NAME`
406
406
 
@@ -433,7 +433,7 @@ EXAMPLES
433
433
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
434
434
  ```
435
435
 
436
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.5-bundle.0/src/commands/functions/test.ts)_
436
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.4.0/src/commands/functions/test.ts)_
437
437
 
438
438
  ## `sanity-run help [COMMAND]`
439
439
 
@@ -6,6 +6,5 @@ export declare function stashAsset({ resource, auth, }: {
6
6
  }): Promise<{
7
7
  success: boolean;
8
8
  assetId?: string;
9
- outputPath?: string;
10
9
  error?: string;
11
10
  }>;
@@ -3,35 +3,21 @@ import path from 'node:path';
3
3
  import { cwd } from 'node:process';
4
4
  import AdmZip from 'adm-zip';
5
5
  import config from '../../config.js';
6
- import { bundleFunction } from '../../utils/bundle/bundle-function.js';
7
- import { shouldBundleFunction } from '../../utils/functions/should-bundle.js';
8
6
  import getHeaders from '../../utils/get-headers.js';
9
7
  const { apiUrl } = config;
10
8
  export const stashUrl = `${apiUrl}vX/blueprints/assets/stash`;
11
9
  export async function stashAsset({ resource, auth, }) {
12
10
  if (!resource.src)
13
11
  throw new Error('Resource src is required');
14
- let functionPath = path.join(cwd(), resource.src);
15
- let cleanup = async () => { };
16
- const shouldBundle = await shouldBundleFunction(resource);
17
- if (shouldBundle) {
18
- try {
19
- const result = await bundleFunction(resource);
20
- functionPath = result.outputDir;
21
- cleanup = result.cleanup;
22
- }
23
- catch (err) {
24
- return { success: false, error: err instanceof Error ? err.message : `${err}` };
25
- }
26
- }
27
12
  try {
28
- const stats = await fs.promises.stat(functionPath);
13
+ const sourcePath = path.join(cwd(), resource.src);
14
+ const stats = await fs.promises.stat(sourcePath);
29
15
  const zip = new AdmZip();
30
16
  if (stats.isDirectory()) {
31
- zip.addLocalFolder(functionPath);
17
+ zip.addLocalFolder(sourcePath);
32
18
  }
33
19
  else {
34
- zip.addLocalFile(functionPath, '', 'index.js');
20
+ zip.addLocalFile(sourcePath, '', 'index.js');
35
21
  }
36
22
  const zipBuffer = zip.toBuffer();
37
23
  const base64Zip = zipBuffer.toString('base64');
@@ -55,7 +41,4 @@ export async function stashAsset({ resource, auth, }) {
55
41
  error = err.message;
56
42
  return { success: false, error };
57
43
  }
58
- finally {
59
- await cleanup();
60
- }
61
44
  }
@@ -1,2 +1,2 @@
1
- import type { InvocationResponse, InvokeContextOptions, InvokePayloadOptions, LocalFunctionResource } from '../../utils/types.js';
2
- export declare function testAction(resource: LocalFunctionResource, options: InvokePayloadOptions, context: InvokeContextOptions): Promise<InvocationResponse>;
1
+ import type { InvocationResponse, InvokeContextOptions, InvokePayloadOptions } from '../../utils/types.js';
2
+ export declare function testAction(srcPath: string, options: InvokePayloadOptions, context: InvokeContextOptions): Promise<InvocationResponse>;
@@ -1,10 +1,10 @@
1
1
  import buildPayload from '../../utils/build-payload.js';
2
2
  import invoke from '../../utils/invoke-local.js';
3
- export async function testAction(resource, options, context) {
3
+ export async function testAction(srcPath, options, context) {
4
4
  const payload = buildPayload(options);
5
5
  const { timeout } = options;
6
6
  try {
7
- const { json, logs } = await invoke(resource, payload, context, timeout);
7
+ const { json, logs } = await invoke(srcPath, payload, context, timeout);
8
8
  return { error: undefined, json, logs };
9
9
  }
10
10
  catch (error) {
@@ -1,7 +1,7 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
3
3
  import { testAction } from '../../actions/functions/test.js';
4
- import { findFunctionByName } from '../../utils/find-function.js';
4
+ import { getFunctionSource } from '../../utils/find-function.js';
5
5
  export default class Test extends Command {
6
6
  static args = {
7
7
  name: Args.string({ description: 'The name of the Sanity Function', required: true }),
@@ -42,8 +42,11 @@ export default class Test extends Command {
42
42
  const { args, flags } = await this.parse(Test);
43
43
  const { parsedBlueprint } = await readBlueprintOnDisk({ getStack: false });
44
44
  try {
45
- const resource = findFunctionByName(parsedBlueprint, args.name);
46
- const { json, logs, error } = await testAction(resource, {
45
+ const src = getFunctionSource(parsedBlueprint, args.name);
46
+ if (!src) {
47
+ this.error(`Error: Function ${args.name} has no source code`);
48
+ }
49
+ const { json, logs, error } = await testAction(src, {
47
50
  data: flags.data,
48
51
  file: flags.file,
49
52
  timeout: flags.timeout,
@@ -1,11 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
- import * as http from 'node:http';
3
2
  import { default as mime } from 'mime-types';
4
3
  import { readBlueprintOnDisk } from '../actions/blueprints/blueprint.js';
5
4
  import config from '../config.js';
6
- import { findFunctionByName } from '../utils/find-function.js';
7
5
  import invoke from '../utils/invoke-local.js';
8
- import { isRecord } from '../utils/is-record.js';
6
+ import * as http from 'node:http';
9
7
  const host = 'localhost';
10
8
  const app = (port) => {
11
9
  const requestListener = async (req, res) => {
@@ -16,40 +14,30 @@ const app = (port) => {
16
14
  const { parsedBlueprint } = await readBlueprintOnDisk({ getStack: false });
17
15
  res.setHeader('Content-Type', 'application/json');
18
16
  res.writeHead(200);
19
- res.end(JSON.stringify(parsedBlueprint)); // Use parsedBlueprint directly
17
+ res.end(JSON.stringify(parsedBlueprint));
20
18
  }
21
- catch (error) {
19
+ catch {
22
20
  res.writeHead(404);
23
- res.end(JSON.stringify({ error: error instanceof Error ? error.message : 'Unknown error' }));
21
+ res.end();
24
22
  }
25
23
  break;
26
24
  }
27
25
  case req.url === '/invoke': {
28
26
  if (req.method === 'POST') {
29
- const body = [];
30
- req.on('data', (data) => body.push(data));
27
+ let body = '';
28
+ req.on('data', (data) => {
29
+ body += data;
30
+ });
31
31
  req.on('end', async () => {
32
+ const { data, func } = JSON.parse(body);
33
+ const { context, event } = data;
32
34
  res.setHeader('Content-Type', 'application/json');
33
35
  try {
34
- const { data, func: functionName } = parseInvokeRequest(Buffer.concat(body));
35
- const { context, event } = data;
36
- const start = performance.now();
37
- const { parsedBlueprint } = await readBlueprintOnDisk({ getStack: false });
38
- const resource = findFunctionByName(parsedBlueprint, functionName);
39
- const readBlueprintTime = performance.now() - start;
40
- const response = await invoke(resource, event, context);
41
- const timings = { ...response.timings, 'blueprint:read': readBlueprintTime };
42
- const timingHeaders = [];
43
- for (const [key, value] of Object.entries(timings)) {
44
- timingHeaders.push(`${key.replace(/:/g, '-')};dur=${Math.abs(value).toFixed(1)}`);
45
- }
46
- if (timingHeaders.length > 0) {
47
- res.setHeader('Server-Timing', timingHeaders.join(', '));
48
- }
36
+ const response = await invoke(func, event, context);
37
+ res.writeHead(200);
49
38
  res.end(JSON.stringify(response));
50
39
  }
51
40
  catch (error) {
52
- console.error(error);
53
41
  const response = { logs: '', error: '' };
54
42
  if (error instanceof Error) {
55
43
  response.logs = error.message;
@@ -124,60 +112,4 @@ const app = (port) => {
124
112
  const server = http.createServer(requestListener);
125
113
  server.listen(port, host, () => { });
126
114
  };
127
- function parseInvokeRequest(body) {
128
- let json;
129
- try {
130
- json = JSON.parse(body.toString('utf8'));
131
- }
132
- catch (error) {
133
- throw new Error('Request body is not valid JSON', { cause: error });
134
- }
135
- if (!isRecord(json)) {
136
- throw new Error('Request body is not valid, must be an object');
137
- }
138
- if (!('func' in json)) {
139
- throw new Error('Request body is not valid, missing `func` field');
140
- }
141
- if (!('data' in json)) {
142
- throw new Error('Request body is not valid, missing `data` field');
143
- }
144
- const { data, func } = json;
145
- if (typeof func !== 'string') {
146
- throw new Error('Request body is not valid, `func` field is not a string');
147
- }
148
- if (!isRecord(data)) {
149
- throw new Error('Request body is not valid, `data` field is not an object');
150
- }
151
- const { context, event } = data;
152
- if (!isRecord(context)) {
153
- throw new Error('Request body is not valid, `context` field is not an object');
154
- }
155
- if (!isRecord(event)) {
156
- throw new Error('Request body is not valid, `event` field is not an object');
157
- }
158
- if (!('clientOptions' in context)) {
159
- throw new Error('Request body is not valid, `context.clientOptions` field is missing');
160
- }
161
- if (!isRecord(context.clientOptions)) {
162
- throw new Error('Request body is not valid, `context.clientOptions` field is not an object');
163
- }
164
- const { projectId, dataset, apiVersion } = context.clientOptions;
165
- if (typeof projectId !== 'string' && typeof projectId !== 'undefined') {
166
- throw new Error('Request body is not valid, `context.clientOptions.projectId` field is not a string');
167
- }
168
- if (typeof dataset !== 'string' && typeof dataset !== 'undefined') {
169
- throw new Error('Request body is not valid, `context.clientOptions.dataset` field is not a string');
170
- }
171
- if (typeof apiVersion !== 'string' && typeof apiVersion !== 'undefined') {
172
- throw new Error('Request body is not valid, `context.clientOptions.apiVersion` field is not a string');
173
- }
174
- const clientOptions = {
175
- ...context.clientOptions,
176
- projectId,
177
- dataset,
178
- // Prefer `undefined` over empty string, triggering the right warnings in the client
179
- apiVersion: apiVersion || undefined,
180
- };
181
- return { func, data: { context: { ...context, clientOptions }, event } };
182
- }
183
115
  export default app;
@@ -30,15 +30,12 @@ function invoke(payloadText = '{}') {
30
30
  },
31
31
  method: 'POST',
32
32
  })
33
- .then((response) => {
34
- return response.json().then((data) => ({data, timings: getServerTimings(response)}))
35
- })
36
- .then(({data, timings}) => {
33
+ .then((response) => response.json())
34
+ .then((data) => {
37
35
  store.inprogress = false
38
36
  store.result = {
39
37
  ...data,
40
38
  time: Date.now() - start,
41
- timings,
42
39
  }
43
40
  })
44
41
  }
@@ -50,7 +47,7 @@ function blueprint() {
50
47
  const functions = blueprint?.resources.filter((r) => r.type.startsWith('sanity.function.'))
51
48
 
52
49
  store.functions = functions
53
- store.selectedIndex = functions[0].name
50
+ store.selectedIndex = functions[0].src
54
51
  })
55
52
  .catch(() => {
56
53
  store.functions = []
@@ -80,21 +77,3 @@ function datasets(selectedProject) {
80
77
  store.datasets = []
81
78
  })
82
79
  }
83
-
84
- function getServerTimings(response) {
85
- const timings = {}
86
- const serverTiming = response.headers.get('Server-Timing')
87
- if (!serverTiming) {
88
- return timings
89
- }
90
-
91
- for (const entry of serverTiming.split(',')) {
92
- const [name, ...params] = entry.split(';')
93
- const durationParam = params.find((p) => p.startsWith('dur='))
94
- if (durationParam) {
95
- timings[name.trim()] = Number.parseFloat(durationParam.slice(4))
96
- }
97
- }
98
-
99
- return timings
100
- }
@@ -771,9 +771,105 @@ body > nav {
771
771
  }
772
772
  body > main {
773
773
  grid-area: main;
774
+ /* Ensure main takes up available space if body is grid/flex */
775
+ overflow: hidden; /* Prevent main itself from scrolling */
776
+ min-height: 0; /* Needed for grid children height */
777
+ }
778
+
779
+ /* Add styles for filters-component form */
780
+ /* Default (Mobile) Styles */
781
+ filters-component form {
782
+ display: block; /* Stack direct children */
783
+ padding: var(--space-3); /* Consistent padding */
784
+ border-bottom: 1px solid var(--card-border-color);
785
+ }
786
+
787
+ filters-component form > * {
788
+ /* Target direct children: dropdowns, fieldset */
789
+ display: block; /* Ensure they are block level */
790
+ width: 100%; /* Make them take full width */
791
+ margin-bottom: var(--space-3); /* Add space below each item when stacked */
792
+ }
793
+
794
+ filters-component form > *:last-child {
795
+ margin-bottom: 0; /* Remove margin from the last stacked item */
796
+ }
797
+
798
+ filters-component form label {
799
+ display: block; /* Ensure label stacks above input if needed */
800
+ margin-bottom: var(--space-1); /* Small space between label and input */
801
+ }
802
+
803
+ filters-component form input {
804
+ width: 100%; /* Make input fill its container */
805
+ box-sizing: border-box; /* Include padding/border in width calculation */
806
+ }
807
+ /* End of Mobile Styles */
808
+
809
+ /* Apply grid styles to main#main-content */
810
+ #main-content {
811
+ display: grid;
812
+ grid-template-areas:
813
+ 'payload response'
814
+ 'console console';
815
+ grid-template-columns: 1fr 1fr;
816
+ /* Let console height be flexible based on content, up to a max */
817
+ grid-template-rows: 1fr 1fr;
818
+ /* Ensure grid takes full height of its container (main) */
819
+ height: 100%;
820
+ max-height: 100%;
821
+ min-height: 0; /* Important for nested overflow/height */
822
+ }
823
+
824
+ payload-panel {
825
+ grid-area: payload;
826
+ max-height: 100%; /* Fit within allocated grid row space */
827
+ overflow: hidden; /* Let internal elements scroll */
828
+ min-height: 0; /* Allow shrinking */
829
+ }
830
+
831
+ response-panel {
832
+ grid-area: response;
833
+ max-height: 100%;
834
+ overflow: hidden;
835
+ min-height: 0;
836
+ }
837
+
838
+ /* Target console-panel for grid area and height constraints */
839
+ console-panel {
840
+ grid-area: console;
841
+ overflow: hidden; /* The inner div handles scrolling */
774
842
  }
775
843
 
776
844
  @media (max-width: 40rem) {
845
+ /* Mobile layout: stack elements vertically */
846
+ #main-content {
847
+ grid-template-areas:
848
+ 'payload'
849
+ 'response'
850
+ 'console';
851
+ grid-template-columns: 1fr;
852
+ /* Adjust row heights for mobile, maybe allow content to determine height */
853
+ grid-template-rows: auto auto auto;
854
+ height: auto; /* Allow main content to scroll if needed */
855
+ max-height: none;
856
+ overflow-y: auto; /* Allow scrolling for the whole main area */
857
+ }
858
+
859
+ /* Reset max-heights on mobile if they cause layout issues */
860
+ payload-panel,
861
+ response-panel,
862
+ console-panel {
863
+ max-height: none;
864
+ min-height: 200px; /* Give some minimum space on mobile */
865
+ overflow: auto; /* Allow individual scrolling if content is large */
866
+ }
867
+
868
+ /* Ensure console has reasonable height on mobile */
869
+ console-panel {
870
+ max-height: 400px; /* Allow more console height on mobile maybe */
871
+ }
872
+
777
873
  .block-lg {
778
874
  display: block !important;
779
875
  }
@@ -794,6 +890,27 @@ body > main {
794
890
  .border-top-none-l {
795
891
  border-top: 0;
796
892
  }
893
+
894
+ /* Revert filters-component form to horizontal layout on larger screens */
895
+ filters-component form {
896
+ display: flex;
897
+ flex-direction: row;
898
+ align-items: flex-end; /* Align form elements along their bottom edge */
899
+ gap: var(--space-3); /* Space between elements */
900
+ padding-left: var(--space-3);
901
+ padding-bottom: var(--space-3);
902
+ }
903
+
904
+ filters-component form > * {
905
+ width: auto; /* Allow elements to size based on content/flex rules */
906
+ margin-bottom: 0; /* Remove stacking margin */
907
+ }
908
+
909
+ /* Optional: Give API version input a specific width or allow growth */
910
+ filters-component form fieldset {
911
+ min-width: 150px; /* Example minimum width */
912
+ /* flex-grow: 1; */ /* Uncomment to allow it to fill space */
913
+ }
797
914
  }
798
915
 
799
916
  header {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ /* globals customElements document */
2
+ import {ApiBaseElement} from './api-base.js'
3
+
4
+ // Template for the console panel
5
+ const template = `
6
+ <div id="console-container" style='position: relative; background: var(--base-background-color); padding: var(--space-0) var(--space-3) var(--space-7) var(--space-4);overflow-y:scroll; border-top: 1px solid var(--card-border-color); height: 100%; max-height: 100%;'>
7
+ <h3 class="config-label" style="padding-top: var(--space-3); padding-bottom: var(--space-3); z-index: 32; background: var(--base-background-color); position: sticky; top: 0; left: 0; right: 0; margin-top:0;margin-bottom:0;">Console</h3>
8
+ <pre id="console-output" style="padding: 0; margin: 0 0 var(--space-4) 0; white-space: pre-wrap; word-wrap: break-word;"></pre>
9
+ </div>
10
+ `
11
+
12
+ class ConsolePanel extends ApiBaseElement {
13
+ updateConsole = ({result}) => {
14
+ // Guard against element not being ready or API not injected yet
15
+ if (!this.consoleOutput || !result) return
16
+
17
+ const {error, logs} = result
18
+ if (error) {
19
+ // Display error details in the console
20
+ this.consoleOutput.innerText = error?.details?.error ?? 'An error occurred.'
21
+ } else {
22
+ // Display regular logs
23
+ this.consoleOutput.innerText = logs ?? '' // Handle case where logs might be null/undefined
24
+ }
25
+ }
26
+
27
+ connectedCallback() {
28
+ this.innerHTML = template
29
+ this.consoleOutput = this.querySelector('#console-output')
30
+
31
+ // Subscribe to changes in the result state to update the console
32
+ if (this.api) {
33
+ this.api.subscribe(this.updateConsole, ['result'])
34
+ // Initial update in case result is already populated
35
+ if (this.api.store.result) {
36
+ this.updateConsole({result: this.api.store.result})
37
+ }
38
+ } else {
39
+ console.error('API context not available for console-panel on connect.')
40
+ // Optionally, set up a mechanism to wait for API initialization if needed
41
+ }
42
+ }
43
+
44
+ disconnectedCallback() {
45
+ // Unsubscribe when the element is removed from the DOM
46
+ if (this.api) {
47
+ this.api.unsubscribe(this.updateConsole)
48
+ }
49
+ }
50
+ }
51
+
52
+ // Define the new custom element
53
+ customElements.define('console-panel', ConsolePanel)
@@ -1,8 +1,9 @@
1
1
  class FiltersComponent extends HTMLElement {
2
2
  connectedCallback() {
3
3
  this.innerHTML = `
4
- <form style="display:flex; gap: 8px;padding-left: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--card-border-color);">
5
- <dataset-dropdown></dataset-dropdown>
4
+ <form style="gap: 8px;padding-left: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--card-border-color);">
5
+ <projects-dropdown></projects-dropdown>
6
+ <dataset-dropdown></dataset-dropdown>
6
7
  <fieldset class="mar-t-sm">
7
8
  <label class="config-label">
8
9
  <span>API Version</span>
@@ -10,7 +11,7 @@ class FiltersComponent extends HTMLElement {
10
11
  <input name="apiVersion" id="apiversion" style="background: transparent; border-color: light-dark(var(--gray-200), var(--gray-700))">
11
12
  </label>
12
13
  </fieldset>
13
- <projects-dropdown></projects-dropdown>
14
+
14
15
 
15
16
  </form>
16
17
  `
@@ -9,7 +9,7 @@ class FunctionList extends ApiBaseElement {
9
9
  functionClicked = (event) => {
10
10
  // eslint-disable-next-line unicorn/prefer-dom-node-text-content
11
11
  const target = this.api.store.functions.find((func) => func.name === event.srcElement.innerText)
12
- this.api.store.selectedIndex = target.name
12
+ this.api.store.selectedIndex = target.src
13
13
  }
14
14
  functionSelected = (event) => {
15
15
  this.api.store.selectedIndex = event.srcElement.value
@@ -18,14 +18,14 @@ class FunctionList extends ApiBaseElement {
18
18
  if (this.api.store.functions.length > 0) {
19
19
  this.list.innerHTML = this.api.store.functions
20
20
  .map((func) => {
21
- const selected = this.api.store.selectedIndex === func.name ? 'selected' : ''
21
+ const selected = this.api.store.selectedIndex === func.src ? 'selected' : ''
22
22
  return `<li class="function-list-item ${selected}" style="padding: 16px 24px;">${func.name}</li>`
23
23
  })
24
24
  .join('')
25
25
  this.select.innerHTML = this.api.store.functions
26
26
  .map((func) => {
27
- const selected = this.api.store.selectedIndex === func.name ? 'selected' : ''
28
- return `<option value="${func.name}" ${selected}>${func.name}</option>`
27
+ const selected = this.api.store.selectedIndex === func.src ? 'selected' : ''
28
+ return `<option value="${func.src}" ${selected}>${func.name}</option>`
29
29
  })
30
30
  .join('')
31
31
  } else {