@sanity/runtime-cli 7.5.0 → 7.6.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.
- package/README.md +15 -15
- package/dist/server/app.js +10 -1
- package/dist/server/static/components/payload-panel.js +5 -4
- package/dist/server/static/components/response-panel.js +1 -1
- package/dist/server/static/components/rule-panel.d.ts +1 -0
- package/dist/server/static/components/rule-panel.js +62 -0
- package/dist/server/static/hot-reload.d.ts +1 -0
- package/dist/server/static/hot-reload.js +15 -0
- package/dist/server/static/index.html +6 -1
- package/dist/utils/invoke-local.d.ts +8 -1
- package/dist/utils/invoke-local.js +37 -1
- package/dist/utils/types.d.ts +8 -10
- package/oclif.manifest.json +1 -1
- package/package.json +4 -1
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/7.
|
|
23
|
+
@sanity/runtime-cli/7.6.0 linux-x64 node-v22.15.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -84,7 +84,7 @@ EXAMPLES
|
|
|
84
84
|
$ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
87
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/add.ts)_
|
|
88
88
|
|
|
89
89
|
## `sanity-run blueprints config`
|
|
90
90
|
|
|
@@ -112,7 +112,7 @@ EXAMPLES
|
|
|
112
112
|
$ sanity-run blueprints config --edit --project-id <projectId>
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
115
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/config.ts)_
|
|
116
116
|
|
|
117
117
|
## `sanity-run blueprints deploy`
|
|
118
118
|
|
|
@@ -134,7 +134,7 @@ EXAMPLES
|
|
|
134
134
|
$ sanity-run blueprints deploy --no-wait
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
137
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/deploy.ts)_
|
|
138
138
|
|
|
139
139
|
## `sanity-run blueprints destroy`
|
|
140
140
|
|
|
@@ -155,7 +155,7 @@ EXAMPLES
|
|
|
155
155
|
$ sanity-run blueprints destroy
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
158
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/destroy.ts)_
|
|
159
159
|
|
|
160
160
|
## `sanity-run blueprints info`
|
|
161
161
|
|
|
@@ -172,7 +172,7 @@ EXAMPLES
|
|
|
172
172
|
$ sanity-run blueprints info
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
175
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/info.ts)_
|
|
176
176
|
|
|
177
177
|
## `sanity-run blueprints init [DIR]`
|
|
178
178
|
|
|
@@ -204,7 +204,7 @@ EXAMPLES
|
|
|
204
204
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId>
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
207
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/init.ts)_
|
|
208
208
|
|
|
209
209
|
## `sanity-run blueprints logs`
|
|
210
210
|
|
|
@@ -226,7 +226,7 @@ EXAMPLES
|
|
|
226
226
|
$ sanity-run blueprints logs --watch
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
229
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/logs.ts)_
|
|
230
230
|
|
|
231
231
|
## `sanity-run blueprints plan`
|
|
232
232
|
|
|
@@ -243,7 +243,7 @@ EXAMPLES
|
|
|
243
243
|
$ sanity-run blueprints plan
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
246
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/blueprints/plan.ts)_
|
|
247
247
|
|
|
248
248
|
## `sanity-run functions dev`
|
|
249
249
|
|
|
@@ -263,7 +263,7 @@ EXAMPLES
|
|
|
263
263
|
$ sanity-run functions dev --port 8974
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
266
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/functions/dev.ts)_
|
|
267
267
|
|
|
268
268
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
269
269
|
|
|
@@ -285,7 +285,7 @@ EXAMPLES
|
|
|
285
285
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
288
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/functions/env/add.ts)_
|
|
289
289
|
|
|
290
290
|
## `sanity-run functions env list NAME`
|
|
291
291
|
|
|
@@ -305,7 +305,7 @@ EXAMPLES
|
|
|
305
305
|
$ sanity-run functions env list MyFunction
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
308
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/functions/env/list.ts)_
|
|
309
309
|
|
|
310
310
|
## `sanity-run functions env remove NAME KEY`
|
|
311
311
|
|
|
@@ -326,7 +326,7 @@ EXAMPLES
|
|
|
326
326
|
$ sanity-run functions env remove MyFunction API_URL
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
329
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/functions/env/remove.ts)_
|
|
330
330
|
|
|
331
331
|
## `sanity-run functions logs NAME`
|
|
332
332
|
|
|
@@ -360,7 +360,7 @@ EXAMPLES
|
|
|
360
360
|
$ sanity-run functions logs <name> --delete
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
363
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/functions/logs.ts)_
|
|
364
364
|
|
|
365
365
|
## `sanity-run functions test NAME`
|
|
366
366
|
|
|
@@ -393,7 +393,7 @@ EXAMPLES
|
|
|
393
393
|
$ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
|
|
394
394
|
```
|
|
395
395
|
|
|
396
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
396
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v7.6.0/src/commands/functions/test.ts)_
|
|
397
397
|
|
|
398
398
|
## `sanity-run help [COMMAND]`
|
|
399
399
|
|
package/dist/server/app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
1
|
+
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
|
+
import { WebSocketServer } from 'ws';
|
|
4
5
|
import { readLocalBlueprint } from '../actions/blueprints/blueprint.js';
|
|
5
6
|
import config from '../config.js';
|
|
6
7
|
import { findFunctionByName } from '../utils/find-function.js';
|
|
@@ -123,6 +124,14 @@ const app = (port) => {
|
|
|
123
124
|
};
|
|
124
125
|
const server = http.createServer(requestListener);
|
|
125
126
|
server.listen(port, host, () => { });
|
|
127
|
+
const wss = new WebSocketServer({ port: 8974 });
|
|
128
|
+
wss.on('connection', async function connection(ws) {
|
|
129
|
+
ws.on('error', console.error);
|
|
130
|
+
const { fileInfo } = await readLocalBlueprint();
|
|
131
|
+
watchFile(fileInfo.blueprintFilePath, { interval: 2007 }, async () => {
|
|
132
|
+
ws.send('reload-blueprint');
|
|
133
|
+
});
|
|
134
|
+
});
|
|
126
135
|
};
|
|
127
136
|
function parseInvokeRequest(body) {
|
|
128
137
|
let json;
|
|
@@ -4,13 +4,15 @@ import {sanityCodeMirrorTheme} from './codemirror-theme.js'
|
|
|
4
4
|
import {EditorView, basicSetup, json} from '../vendor/vendor.bundle.js'
|
|
5
5
|
import {ApiBaseElement} from './api-base.js'
|
|
6
6
|
|
|
7
|
+
const runTemplate = `<span>Run</span>
|
|
8
|
+
<svg data-sanity-icon="play" width="1em" height="1em" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.5 18.5V6.5L17.5 12.5L7.5 18.5Z" fill="currentColor" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"></path></svg>`
|
|
9
|
+
|
|
7
10
|
const template = `<div class="gutter-gradient relative h-100 max-h-100 y-scroll border-top border-top-none-l">
|
|
8
11
|
<div class="bg gutter-gradient sticky top-0 right-0 left-0 z-100">
|
|
9
12
|
<div class="flex items-center space-between" style="padding: 8px 20px 8px 48px;">
|
|
10
13
|
<h2 class="config-label mar-t-0 mar-b-0">Event</h2>
|
|
11
14
|
<button ord="primary" class="sanity-button">
|
|
12
|
-
|
|
13
|
-
<svg data-sanity-icon="play" width="1em" height="1em" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.5 18.5V6.5L17.5 12.5L7.5 18.5Z" fill="currentColor" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"></path></svg>
|
|
15
|
+
${runTemplate}
|
|
14
16
|
</button>
|
|
15
17
|
</div>
|
|
16
18
|
<hr class='hr-border' style='margin-left: 31px; ' />
|
|
@@ -46,8 +48,7 @@ class PayloadPanel extends ApiBaseElement {
|
|
|
46
48
|
this.button.innerHTML = '<network-spinner></network-spinner>'
|
|
47
49
|
} else {
|
|
48
50
|
this.button.removeAttribute('disabled')
|
|
49
|
-
this.button.innerHTML =
|
|
50
|
-
<svg data-sanity-icon="play" width="1em" height="1em" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.5 18.5V6.5L17.5 12.5L7.5 18.5Z" fill="currentColor" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"></path></svg>`
|
|
51
|
+
this.button.innerHTML = runTemplate
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -36,7 +36,7 @@ class ResponsePanel extends ApiBaseElement {
|
|
|
36
36
|
updateResponse = ({result}) => {
|
|
37
37
|
if (!result) return
|
|
38
38
|
|
|
39
|
-
const {error, json,
|
|
39
|
+
const {error, json, time, timings} = result
|
|
40
40
|
if (!error) {
|
|
41
41
|
const transaction = this.api.store.response.state.update({
|
|
42
42
|
changes: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* globals customElements document */
|
|
2
|
+
/* eslint-disable unicorn/prefer-dom-node-text-content */
|
|
3
|
+
import {sanityCodeMirrorTheme} from './codemirror-theme.js'
|
|
4
|
+
|
|
5
|
+
import {EditorState, EditorView, basicSetup, json} from '../vendor/vendor.bundle.js'
|
|
6
|
+
import {ApiBaseElement} from './api-base.js'
|
|
7
|
+
|
|
8
|
+
const template = `<div style='overflow-y:scroll; min-height: 0;'>
|
|
9
|
+
<div>
|
|
10
|
+
<h3 class="config-label" style='display: none; margin-top: 0;'>Filter/Projection</h3>
|
|
11
|
+
<header class='flex space-between'>
|
|
12
|
+
<dl class='slab-stat'>
|
|
13
|
+
<dt style='white-space:nowrap;'>Filter/Projection</dt>
|
|
14
|
+
</dl>
|
|
15
|
+
</header>
|
|
16
|
+
<div id="rule" name="rule" class="cm-s-dracula"></div>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
`
|
|
20
|
+
class RulePanel extends ApiBaseElement {
|
|
21
|
+
updateRule = () => {
|
|
22
|
+
const {functions, rule, selectedIndex} = this.api.store
|
|
23
|
+
const func = functions.find((func) => func.name === selectedIndex)
|
|
24
|
+
|
|
25
|
+
if (func.event) {
|
|
26
|
+
const transaction = rule.state.update({
|
|
27
|
+
changes: {
|
|
28
|
+
from: 0,
|
|
29
|
+
insert: JSON.stringify(func.event, null, 2),
|
|
30
|
+
to: rule.state.doc.length,
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
rule.dispatch(transaction)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
this.innerHTML = template
|
|
39
|
+
this.rule = this.querySelector('#rule')
|
|
40
|
+
|
|
41
|
+
if (this.api) {
|
|
42
|
+
this.api.subscribe(this.updateRule, ['selectedIndex', 'functions'])
|
|
43
|
+
if (this.api.store.selectedIndex) {
|
|
44
|
+
this.updateRule({selectedIndex: this.api.store.selectedIndex})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.api.store.rule = new EditorView({
|
|
49
|
+
doc: '\n\n\n\n',
|
|
50
|
+
extensions: [basicSetup, json(), sanityCodeMirrorTheme, EditorState.readOnly.of(true)],
|
|
51
|
+
parent: this.rule,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
disconnectedCallback() {
|
|
56
|
+
if (this.api) {
|
|
57
|
+
this.api.unsubscribe(this.updateResponse)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
customElements.define('rule-panel', RulePanel)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import apiConstructor from '../api.js'
|
|
2
|
+
const api = apiConstructor()
|
|
3
|
+
|
|
4
|
+
// Create WebSocket connection.
|
|
5
|
+
const socket = new WebSocket('ws://localhost:8974')
|
|
6
|
+
|
|
7
|
+
// Connection opened
|
|
8
|
+
socket.addEventListener('open', () => {
|
|
9
|
+
console.log('Watching for Blueprint changes')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
// Listen for messages
|
|
13
|
+
socket.addEventListener('message', (event) => {
|
|
14
|
+
if (event.data === 'reload-blueprint') api.blueprint()
|
|
15
|
+
})
|
|
@@ -36,7 +36,10 @@
|
|
|
36
36
|
</nav>
|
|
37
37
|
<main id="main-content" style='max-height: 100%; overflow: hidden;'>
|
|
38
38
|
<payload-panel></payload-panel>
|
|
39
|
-
<
|
|
39
|
+
<div>
|
|
40
|
+
<rule-panel></rule-paneL>
|
|
41
|
+
<response-panel></response-panel>
|
|
42
|
+
</div>
|
|
40
43
|
<console-panel></console-panel>
|
|
41
44
|
</main>
|
|
42
45
|
|
|
@@ -48,6 +51,8 @@
|
|
|
48
51
|
<script src="./components/network-spinner.js" type="module"></script>
|
|
49
52
|
<script src="./components/payload-panel.js" type="module"></script>
|
|
50
53
|
<script src="./components/response-panel.js" type="module"></script>
|
|
54
|
+
<script src="./components/rule-panel.js" type="module"></script>
|
|
51
55
|
<script src="./components/console-panel.js" type="module"></script>
|
|
56
|
+
<script src="./hot-reload.js" type="module"></script>
|
|
52
57
|
</body>
|
|
53
58
|
</html>
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type { InvocationResponse, InvokeContextOptions, LocalFunctionResource } from './types.js';
|
|
1
|
+
import type { GroqRule, InvocationResponse, InvokeContextOptions, LocalFunctionResource } from './types.js';
|
|
2
2
|
export declare function sanitizeLogs(logs: string): string;
|
|
3
|
+
export declare const DEFAULT_GROQ_RULE: {
|
|
4
|
+
on: string[];
|
|
5
|
+
filter: string;
|
|
6
|
+
projection: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function isDefaultGROQRule(rule: GroqRule | undefined): boolean;
|
|
9
|
+
export declare function applyGroqRule(resource: LocalFunctionResource, data: Record<string, unknown> | null): Promise<any>;
|
|
3
10
|
export default function invoke(resource: LocalFunctionResource, data: Record<string, unknown> | null, context: InvokeContextOptions, timeout?: number): Promise<InvocationResponse>;
|
|
@@ -3,6 +3,7 @@ import { performance } from 'node:perf_hooks';
|
|
|
3
3
|
import { cwd } from 'node:process';
|
|
4
4
|
import { setTimeout } from 'node:timers';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import * as groq from 'groq-js';
|
|
6
7
|
import config from '../config.js';
|
|
7
8
|
import { bundleFunction } from './bundle/bundle-function.js';
|
|
8
9
|
import { findFunctionEntryPoint } from './functions/find-entry-point.js';
|
|
@@ -13,10 +14,45 @@ function getChildProcessWrapperPath() {
|
|
|
13
14
|
export function sanitizeLogs(logs) {
|
|
14
15
|
return logs.replace(/([a-zA-Z0-9]{10})[a-zA-Z0-9]{65,}/g, '$1**********');
|
|
15
16
|
}
|
|
17
|
+
export const DEFAULT_GROQ_RULE = { on: ['publish'], filter: '', projection: '' };
|
|
18
|
+
export function isDefaultGROQRule(rule) {
|
|
19
|
+
if (!rule)
|
|
20
|
+
return true;
|
|
21
|
+
return (Array.isArray(rule.on) &&
|
|
22
|
+
rule.on.length === DEFAULT_GROQ_RULE.on.length &&
|
|
23
|
+
rule.on.every((v) => DEFAULT_GROQ_RULE.on.includes(v)) &&
|
|
24
|
+
rule.filter === DEFAULT_GROQ_RULE.filter &&
|
|
25
|
+
rule.projection === DEFAULT_GROQ_RULE.projection);
|
|
26
|
+
}
|
|
27
|
+
export async function applyGroqRule(resource, data) {
|
|
28
|
+
// If there is no rule set return everything
|
|
29
|
+
if (!resource.event)
|
|
30
|
+
return data;
|
|
31
|
+
// default groq rule is: gimme full doc content. otherwise, parse + eval custom rule
|
|
32
|
+
// applying the GROQ filter may result in a slimmer set of documents
|
|
33
|
+
if (!isDefaultGROQRule(resource.event)) {
|
|
34
|
+
const hasProjection = resource?.event?.projection?.length;
|
|
35
|
+
const projection = hasProjection ? `{${resource?.event?.projection}}` : '';
|
|
36
|
+
const query = `*[${resource?.event?.filter}]${projection}`;
|
|
37
|
+
try {
|
|
38
|
+
const rule = groq.parse(query);
|
|
39
|
+
const queryResults = await groq.evaluate(rule, { dataset: [data] });
|
|
40
|
+
const currentFunctionDocumentSet = await queryResults.get();
|
|
41
|
+
// TODO can this be multiple documents?
|
|
42
|
+
return currentFunctionDocumentSet[0] || {};
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
// parsing/validating the groq rule we do up front as part of functions HTTP API
|
|
46
|
+
// so this likely would be triggered by evaluating the query, if anything
|
|
47
|
+
throw Error('⚠️ failed parsing/evaluating GROQ rule! Skipping invoke.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
16
51
|
export default async function invoke(resource, data, context, timeout = 10) {
|
|
17
52
|
if (!resource.src) {
|
|
18
53
|
throw new Error(`Function resource "${resource.name}" is missing the 'src' property.`);
|
|
19
54
|
}
|
|
55
|
+
const filteredData = await applyGroqRule(resource, data);
|
|
20
56
|
let cleanupBundle = async () => { };
|
|
21
57
|
let functionPath = '';
|
|
22
58
|
let bundleTimings = undefined;
|
|
@@ -80,7 +116,7 @@ export default async function invoke(resource, data, context, timeout = 10) {
|
|
|
80
116
|
reject(new Error(`Timed out after hitting its ${timeout}s timeout!`));
|
|
81
117
|
}, timeout * 1000);
|
|
82
118
|
const payload = {
|
|
83
|
-
...
|
|
119
|
+
...filteredData,
|
|
84
120
|
context: {
|
|
85
121
|
...context,
|
|
86
122
|
clientOptions: {
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface AuthParams {
|
|
|
12
12
|
projectId: string;
|
|
13
13
|
}
|
|
14
14
|
/** @internal */
|
|
15
|
+
export interface GroqRule {
|
|
16
|
+
on: Array<string>;
|
|
17
|
+
filter?: string;
|
|
18
|
+
projection?: string;
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
15
21
|
export interface LocalBlueprint {
|
|
16
22
|
/** @link https://github.com/sanity-io/blueprints-rfc/blob/main/readme.md#versioning */
|
|
17
23
|
blueprintVersion?: string;
|
|
@@ -63,11 +69,7 @@ export interface LocalFunctionResource extends LocalResource {
|
|
|
63
69
|
memory?: number;
|
|
64
70
|
timeout?: number;
|
|
65
71
|
env?: Record<string, string>;
|
|
66
|
-
event?:
|
|
67
|
-
on: Array<string>;
|
|
68
|
-
filter?: string;
|
|
69
|
-
projection?: string;
|
|
70
|
-
};
|
|
72
|
+
event?: GroqRule;
|
|
71
73
|
}
|
|
72
74
|
export interface Stack {
|
|
73
75
|
id: string;
|
|
@@ -95,11 +97,7 @@ export interface StackFunctionResource extends StackResource {
|
|
|
95
97
|
memory?: number;
|
|
96
98
|
timeout?: number;
|
|
97
99
|
env?: Record<string, string>;
|
|
98
|
-
event?:
|
|
99
|
-
on: Array<string>;
|
|
100
|
-
filter?: string;
|
|
101
|
-
projection?: string;
|
|
102
|
-
};
|
|
100
|
+
event?: GroqRule;
|
|
103
101
|
};
|
|
104
102
|
}
|
|
105
103
|
/** @internal */
|
package/oclif.manifest.json
CHANGED
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": "7.
|
|
4
|
+
"version": "7.6.0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -84,11 +84,13 @@
|
|
|
84
84
|
"color-json": "^3.0.5",
|
|
85
85
|
"eventsource": "^4.0.0",
|
|
86
86
|
"find-up": "^7.0.0",
|
|
87
|
+
"groq-js": "^1.16.1",
|
|
87
88
|
"inquirer": "^12.6.1",
|
|
88
89
|
"mime-types": "^3.0.1",
|
|
89
90
|
"ora": "^8.2.0",
|
|
90
91
|
"vite": "^6.3.5",
|
|
91
92
|
"vite-tsconfig-paths": "^5.1.4",
|
|
93
|
+
"ws": "^8.18.2",
|
|
92
94
|
"xdg-basedir": "^5.1.0"
|
|
93
95
|
},
|
|
94
96
|
"devDependencies": {
|
|
@@ -103,6 +105,7 @@
|
|
|
103
105
|
"@types/adm-zip": "^0.5.7",
|
|
104
106
|
"@types/mime-types": "^2.1.4",
|
|
105
107
|
"@types/node": "20",
|
|
108
|
+
"@types/ws": "^8.18.1",
|
|
106
109
|
"codemirror": "^6.0.1",
|
|
107
110
|
"mentoss": "^0.11.0",
|
|
108
111
|
"oclif": "^4.17.46",
|