@sanity/runtime-cli 14.8.5 → 14.8.6
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 +18 -18
- package/dist/actions/blueprints/blueprint.d.ts +4 -0
- package/dist/actions/blueprints/blueprint.js +6 -0
- package/dist/cores/blueprints/deploy.js +15 -8
- package/dist/cores/blueprints/plan.js +3 -3
- package/dist/cores/functions/add.js +1 -1
- package/dist/cores/functions/build.js +3 -5
- package/dist/cores/functions/logs.js +1 -1
- package/dist/cores/functions/test.js +3 -4
- package/dist/server/handlers/invoke.js +3 -3
- package/dist/utils/find-function.d.ts +7 -6
- package/dist/utils/find-function.js +5 -3
- package/dist/utils/functions/detect-native-modules.js +5 -1
- package/dist/utils/types.d.ts +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
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/14.8.
|
|
23
|
+
@sanity/runtime-cli/14.8.6 linux-x64 node-v24.14.1
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -101,7 +101,7 @@ EXAMPLES
|
|
|
101
101
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
104
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/add.ts)_
|
|
105
105
|
|
|
106
106
|
## `sanity-run blueprints config`
|
|
107
107
|
|
|
@@ -140,7 +140,7 @@ EXAMPLES
|
|
|
140
140
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
143
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/config.ts)_
|
|
144
144
|
|
|
145
145
|
## `sanity-run blueprints deploy`
|
|
146
146
|
|
|
@@ -179,7 +179,7 @@ EXAMPLES
|
|
|
179
179
|
$ sanity-run blueprints deploy --fn-installer npm
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
182
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/deploy.ts)_
|
|
183
183
|
|
|
184
184
|
## `sanity-run blueprints destroy`
|
|
185
185
|
|
|
@@ -215,7 +215,7 @@ EXAMPLES
|
|
|
215
215
|
$ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
218
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/destroy.ts)_
|
|
219
219
|
|
|
220
220
|
## `sanity-run blueprints doctor`
|
|
221
221
|
|
|
@@ -242,7 +242,7 @@ DESCRIPTION
|
|
|
242
242
|
issues.
|
|
243
243
|
```
|
|
244
244
|
|
|
245
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
245
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/doctor.ts)_
|
|
246
246
|
|
|
247
247
|
## `sanity-run blueprints info`
|
|
248
248
|
|
|
@@ -274,7 +274,7 @@ EXAMPLES
|
|
|
274
274
|
$ sanity-run blueprints info --stack <name-or-id>
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
277
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/info.ts)_
|
|
278
278
|
|
|
279
279
|
## `sanity-run blueprints init [DIR]`
|
|
280
280
|
|
|
@@ -328,7 +328,7 @@ EXAMPLES
|
|
|
328
328
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
331
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/init.ts)_
|
|
332
332
|
|
|
333
333
|
## `sanity-run blueprints logs`
|
|
334
334
|
|
|
@@ -359,7 +359,7 @@ EXAMPLES
|
|
|
359
359
|
$ sanity-run blueprints logs --watch
|
|
360
360
|
```
|
|
361
361
|
|
|
362
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
362
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/logs.ts)_
|
|
363
363
|
|
|
364
364
|
## `sanity-run blueprints plan`
|
|
365
365
|
|
|
@@ -387,7 +387,7 @@ EXAMPLES
|
|
|
387
387
|
$ sanity-run blueprints plan
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
390
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/plan.ts)_
|
|
391
391
|
|
|
392
392
|
## `sanity-run blueprints stacks`
|
|
393
393
|
|
|
@@ -419,7 +419,7 @@ EXAMPLES
|
|
|
419
419
|
$ sanity-run blueprints stacks --organization-id <organizationId>
|
|
420
420
|
```
|
|
421
421
|
|
|
422
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
422
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/blueprints/stacks.ts)_
|
|
423
423
|
|
|
424
424
|
## `sanity-run functions add`
|
|
425
425
|
|
|
@@ -472,7 +472,7 @@ EXAMPLES
|
|
|
472
472
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
473
473
|
```
|
|
474
474
|
|
|
475
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
475
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/add.ts)_
|
|
476
476
|
|
|
477
477
|
## `sanity-run functions dev`
|
|
478
478
|
|
|
@@ -508,7 +508,7 @@ EXAMPLES
|
|
|
508
508
|
$ sanity-run functions dev --timeout 60
|
|
509
509
|
```
|
|
510
510
|
|
|
511
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
511
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/dev.ts)_
|
|
512
512
|
|
|
513
513
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
514
514
|
|
|
@@ -539,7 +539,7 @@ EXAMPLES
|
|
|
539
539
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
540
540
|
```
|
|
541
541
|
|
|
542
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
542
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/env/add.ts)_
|
|
543
543
|
|
|
544
544
|
## `sanity-run functions env list NAME`
|
|
545
545
|
|
|
@@ -567,7 +567,7 @@ EXAMPLES
|
|
|
567
567
|
$ sanity-run functions env list MyFunction
|
|
568
568
|
```
|
|
569
569
|
|
|
570
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
570
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/env/list.ts)_
|
|
571
571
|
|
|
572
572
|
## `sanity-run functions env remove NAME KEY`
|
|
573
573
|
|
|
@@ -597,7 +597,7 @@ EXAMPLES
|
|
|
597
597
|
$ sanity-run functions env remove MyFunction API_URL
|
|
598
598
|
```
|
|
599
599
|
|
|
600
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
600
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/env/remove.ts)_
|
|
601
601
|
|
|
602
602
|
## `sanity-run functions logs [NAME]`
|
|
603
603
|
|
|
@@ -639,7 +639,7 @@ EXAMPLES
|
|
|
639
639
|
$ sanity-run functions logs <name> --delete
|
|
640
640
|
```
|
|
641
641
|
|
|
642
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
642
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/logs.ts)_
|
|
643
643
|
|
|
644
644
|
## `sanity-run functions test [NAME]`
|
|
645
645
|
|
|
@@ -697,7 +697,7 @@ EXAMPLES
|
|
|
697
697
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
698
698
|
```
|
|
699
699
|
|
|
700
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.
|
|
700
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.8.6/src/commands/functions/test.ts)_
|
|
701
701
|
|
|
702
702
|
## `sanity-run help [COMMAND]`
|
|
703
703
|
|
|
@@ -39,9 +39,13 @@ export type ConfigSource = 'config' | 'env' | 'module' | 'inferred';
|
|
|
39
39
|
export interface ReadBlueprintResult {
|
|
40
40
|
fileInfo: FileInfo;
|
|
41
41
|
blueprintConfig: LocatedBlueprintsConfig | null;
|
|
42
|
+
/** The raw blueprint data as read from disk */
|
|
42
43
|
rawBlueprint: Record<string, unknown>;
|
|
44
|
+
/** The blueprints-parser blueprint result */
|
|
43
45
|
parsedBlueprint: Blueprint;
|
|
44
46
|
errors: BlueprintParserError[];
|
|
47
|
+
/** Validated resources escaped from parser types */
|
|
48
|
+
resources: BlueprintResource[];
|
|
45
49
|
/** @deprecated - use blueprintConfig.configPath instead */
|
|
46
50
|
configPath?: string;
|
|
47
51
|
scopeType?: ScopeType;
|
|
@@ -229,10 +229,16 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
|
|
|
229
229
|
errors.push(...validateResources(parsedBlueprint.resources));
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
+
// Ceremony to cross from parser's Resource type to BlueprintResource
|
|
233
|
+
// widen from the parser's Resource type assignable to BlueprintResource
|
|
234
|
+
const parserResources = parsedBlueprint?.resources ?? [];
|
|
235
|
+
// filter to valid resources typed as BlueprintResource
|
|
236
|
+
const validResources = parserResources.filter((r) => !!r.type);
|
|
232
237
|
return {
|
|
233
238
|
fileInfo: { blueprintFilePath: foundFilePath, fileName, extension },
|
|
234
239
|
blueprintConfig,
|
|
235
240
|
rawBlueprint,
|
|
241
|
+
resources: validResources,
|
|
236
242
|
errors,
|
|
237
243
|
scopeType,
|
|
238
244
|
scopeId,
|
|
@@ -28,18 +28,17 @@ export async function blueprintDeployCore(options) {
|
|
|
28
28
|
error: 'A Stack operation is already in progress. Please wait for it to complete before deploying.',
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const assetResources = validResources.filter(isAssetResource);
|
|
31
|
+
const resources = [...blueprint.resources];
|
|
32
|
+
const assetResources = resources.filter(isAssetResource);
|
|
34
33
|
if (assetResources.length > 0) {
|
|
35
34
|
log('Processing assets...');
|
|
36
35
|
for (const resource of assetResources) {
|
|
37
36
|
const preDeployResult = await preDeploy(resource, { auth, installer, log });
|
|
38
37
|
if (!preDeployResult.success)
|
|
39
38
|
return preDeployResult;
|
|
40
|
-
const idx =
|
|
39
|
+
const idx = resources.indexOf(resource);
|
|
41
40
|
if (idx !== -1)
|
|
42
|
-
|
|
41
|
+
resources[idx] = preDeployResult.resource;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
const spinner = log.ora('Deploying...').start();
|
|
@@ -50,7 +49,7 @@ export async function blueprintDeployCore(options) {
|
|
|
50
49
|
scopeType,
|
|
51
50
|
scopeId,
|
|
52
51
|
name: stackName,
|
|
53
|
-
document: { resources
|
|
52
|
+
document: { resources },
|
|
54
53
|
},
|
|
55
54
|
auth,
|
|
56
55
|
logger: log,
|
|
@@ -63,7 +62,11 @@ export async function blueprintDeployCore(options) {
|
|
|
63
62
|
if (noWait) {
|
|
64
63
|
log(styleText(['bold', 'green'], 'Stack deployment started!'));
|
|
65
64
|
log(`Use \`npx ${bin} blueprints info\` to check status`);
|
|
66
|
-
return {
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
json: { stackId: stack.id, resources },
|
|
68
|
+
data: { resources },
|
|
69
|
+
};
|
|
67
70
|
}
|
|
68
71
|
log(styleText('dim', 'Stack deployment progress:'));
|
|
69
72
|
let logStreamCleanup = null;
|
|
@@ -102,7 +105,11 @@ export async function blueprintDeployCore(options) {
|
|
|
102
105
|
if (logStreamCleanup)
|
|
103
106
|
logStreamCleanup();
|
|
104
107
|
log(styleText(['bold', 'green'], 'Stack deployment completed!'));
|
|
105
|
-
return {
|
|
108
|
+
return {
|
|
109
|
+
success: true,
|
|
110
|
+
json: { stackId: stack.id, resources },
|
|
111
|
+
data: { resources },
|
|
112
|
+
};
|
|
106
113
|
}
|
|
107
114
|
if (!idleMessageShown && Date.now() - lastLogAt > 60_000) {
|
|
108
115
|
log(`No new activity for 60 seconds. The deployment is still running on Sanity servers.`);
|
|
@@ -4,9 +4,9 @@ import { styleText } from '../../utils/style-text.js';
|
|
|
4
4
|
export async function blueprintPlanCore(options) {
|
|
5
5
|
const { bin = 'sanity', log, blueprint, token, flags } = options;
|
|
6
6
|
const { verbose: _verbose = false } = flags;
|
|
7
|
-
const { scopeType, scopeId, stackId: blueprintStackId, parsedBlueprint, fileInfo } = blueprint;
|
|
7
|
+
const { scopeType, scopeId, stackId: blueprintStackId, parsedBlueprint, resources, fileInfo, } = blueprint;
|
|
8
8
|
log(`${styleText(['bold', 'blueBright'], 'Local Blueprint')} ${styleText('dim', `(${fileInfo.fileName})`)}`);
|
|
9
|
-
log(formatResourceTree(
|
|
9
|
+
log(formatResourceTree(resources));
|
|
10
10
|
if (!token || !scopeType || !scopeId) {
|
|
11
11
|
log(styleText('dim', 'Unable to retrieve live Stack deployment for comparison'));
|
|
12
12
|
const errorMessage = !token
|
|
@@ -66,7 +66,7 @@ export async function blueprintPlanCore(options) {
|
|
|
66
66
|
return {
|
|
67
67
|
success: true,
|
|
68
68
|
json: {
|
|
69
|
-
resources
|
|
69
|
+
resources,
|
|
70
70
|
plan: planResponse.deploymentPlan,
|
|
71
71
|
},
|
|
72
72
|
};
|
|
@@ -127,7 +127,7 @@ export async function functionAddCore(options) {
|
|
|
127
127
|
}
|
|
128
128
|
try {
|
|
129
129
|
const fnName = flagResourceName || (await promptForFunctionName());
|
|
130
|
-
if (blueprint.
|
|
130
|
+
if (blueprint.resources.some((r) => r.name === fnName)) {
|
|
131
131
|
return {
|
|
132
132
|
success: false,
|
|
133
133
|
error: `Function "${styleText('bold', fnName)}" already exists.`,
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToZip } from '../../actions/blueprints/assets.js';
|
|
4
|
-
import {
|
|
4
|
+
import { findFunctionInResources } from '../../utils/find-function.js';
|
|
5
5
|
import { prepareAsset } from '../../utils/functions/prepare-asset.js';
|
|
6
6
|
import { isLocalFunctionResource } from '../../utils/types.js';
|
|
7
7
|
export async function functionBuildCore(options) {
|
|
8
8
|
const { blueprint, log, args, flags } = options;
|
|
9
|
-
const
|
|
10
|
-
const allFunctions = (parsedBlueprint.resources ?? []).filter(isLocalFunctionResource);
|
|
9
|
+
const allFunctions = blueprint.resources.filter(isLocalFunctionResource);
|
|
11
10
|
if (allFunctions.length === 0) {
|
|
12
11
|
return { success: false, error: 'No functions found in blueprint.' };
|
|
13
12
|
}
|
|
14
13
|
let functions;
|
|
15
14
|
if (args.name) {
|
|
16
|
-
|
|
17
|
-
functions = [resource];
|
|
15
|
+
functions = [findFunctionInResources(blueprint.resources, args.name)];
|
|
18
16
|
}
|
|
19
17
|
else {
|
|
20
18
|
functions = allFunctions;
|
|
@@ -10,7 +10,7 @@ export async function functionLogsCore(options) {
|
|
|
10
10
|
const { name } = args;
|
|
11
11
|
const { delete: shouldDelete, watch: shouldWatch, force, limit, json, utc } = flags;
|
|
12
12
|
if (!name) {
|
|
13
|
-
const functionNames = getFunctionNames(blueprint.
|
|
13
|
+
const functionNames = getFunctionNames(blueprint.resources);
|
|
14
14
|
const validNames = functionNames.length > 0
|
|
15
15
|
? `Valid names are: ${functionNames.join(', ')}`
|
|
16
16
|
: 'No functions are defined in the blueprint.';
|
|
@@ -5,7 +5,7 @@ import { testAction } from '../../actions/functions/test.js';
|
|
|
5
5
|
import config from '../../config.js';
|
|
6
6
|
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET } from '../../constants.js';
|
|
7
7
|
import buildPayload from '../../utils/build-payload.js';
|
|
8
|
-
import {
|
|
8
|
+
import { findFunctionInResources, getFunctionNames } from '../../utils/find-function.js';
|
|
9
9
|
import { fetchAsset, fetchDocument } from '../../utils/functions/fetch-document.js';
|
|
10
10
|
import { parseJsonObject } from '../../utils/parse-json-object.js';
|
|
11
11
|
import { isEventType, isGroqContextOptions, } from '../../utils/types.js';
|
|
@@ -13,10 +13,9 @@ export async function functionTestCore(options) {
|
|
|
13
13
|
const { blueprint, log, error, args, flags, helpText } = 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, 'media-library-id': mediaLibraryId, } = flags;
|
|
16
|
-
const { parsedBlueprint } = blueprint;
|
|
17
16
|
const { 'project-id': projectId = blueprint?.projectId, 'organization-id': organizationId = blueprint?.organizationId, } = flags;
|
|
18
17
|
if (!fnName) {
|
|
19
|
-
const functionNames = getFunctionNames(blueprint.
|
|
18
|
+
const functionNames = getFunctionNames(blueprint.resources);
|
|
20
19
|
const validNames = functionNames.length > 0
|
|
21
20
|
? `Valid names are: ${functionNames.join(', ')}`
|
|
22
21
|
: 'No functions are defined in the blueprint.';
|
|
@@ -38,7 +37,7 @@ export async function functionTestCore(options) {
|
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
39
|
try {
|
|
41
|
-
const resource =
|
|
40
|
+
const resource = findFunctionInResources(blueprint.resources, fnName); // throws if not found
|
|
42
41
|
const docFunction = resource.type === SANITY_FUNCTION_DOCUMENT;
|
|
43
42
|
const mediaFunction = resource.type === SANITY_FUNCTION_MEDIA_LIBRARY_ASSET;
|
|
44
43
|
const contextOptions = docFunction || mediaFunction
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { readLocalBlueprint } from '../../actions/blueprints/blueprint.js';
|
|
2
|
-
import {
|
|
2
|
+
import { findFunctionInResources } from '../../utils/find-function.js';
|
|
3
3
|
import invoke from '../../utils/invoke-local.js';
|
|
4
4
|
export async function handleInvokeRequest(functionName, event, metadata, context, logger, validateResources, executionOptions) {
|
|
5
5
|
const start = performance.now();
|
|
6
|
-
const
|
|
7
|
-
const resource =
|
|
6
|
+
const blueprint = await readLocalBlueprint(logger, { resources: validateResources });
|
|
7
|
+
const resource = findFunctionInResources(blueprint.resources, functionName);
|
|
8
8
|
const readBlueprintTime = performance.now() - start;
|
|
9
9
|
const payload = {
|
|
10
10
|
payload: event,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
2
|
import { type DeployedResource, type FunctionResource, type Stack } from './types.js';
|
|
3
|
-
export declare function getFunctionNames(resources:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export declare function getFunctionNames(resources: BlueprintResource[] | undefined): string[];
|
|
4
|
+
export declare function findFunctionInResources(resources: BlueprintResource[], name: string): FunctionResource;
|
|
5
|
+
/** @deprecated Use findFunctionInResources instead */
|
|
6
|
+
export declare const findFunctionInBlueprint: (blueprint: {
|
|
7
|
+
resources?: BlueprintResource[];
|
|
8
|
+
}, name: string) => FunctionResource;
|
|
8
9
|
export declare function findFunctionInStack(stack: Stack, name: string): DeployedResource;
|
|
@@ -2,16 +2,18 @@ import { SANITY_FUNCTION_PREFIX } from '../constants.js';
|
|
|
2
2
|
import { isLocalFunctionResource, } from './types.js';
|
|
3
3
|
export function getFunctionNames(resources) {
|
|
4
4
|
return (resources
|
|
5
|
-
?.filter((r) => r
|
|
5
|
+
?.filter((r) => r.type.startsWith(SANITY_FUNCTION_PREFIX))
|
|
6
6
|
.map((r) => r.name)
|
|
7
7
|
.filter((name) => typeof name === 'string') ?? []);
|
|
8
8
|
}
|
|
9
|
-
export function
|
|
10
|
-
const func =
|
|
9
|
+
export function findFunctionInResources(resources, name) {
|
|
10
|
+
const func = resources.filter(isLocalFunctionResource).find((r) => r.name === name);
|
|
11
11
|
if (!func)
|
|
12
12
|
throw Error(`Unable to find function ${name}`);
|
|
13
13
|
return func;
|
|
14
14
|
}
|
|
15
|
+
/** @deprecated Use findFunctionInResources instead */
|
|
16
|
+
export const findFunctionInBlueprint = (blueprint, name) => findFunctionInResources(blueprint?.resources ?? [], name);
|
|
15
17
|
export function findFunctionInStack(stack, name) {
|
|
16
18
|
const func = stack?.resources?.filter(isLocalFunctionResource).find((r) => r.name === name);
|
|
17
19
|
if (!func)
|
|
@@ -9,7 +9,11 @@ export const errorMessage = (elements) => `Native modules detected:\n${elements.
|
|
|
9
9
|
* Quick helper so we can recurse through pnpm symlinks if they exist
|
|
10
10
|
* Fallback to statSync if it's a symlink
|
|
11
11
|
*/
|
|
12
|
-
const isDirEntry = (dir, parent) =>
|
|
12
|
+
const isDirEntry = (dir, parent) => {
|
|
13
|
+
return (dir.isDirectory() ||
|
|
14
|
+
(dir.isSymbolicLink() &&
|
|
15
|
+
statSync(path.join(parent, dir.name), { throwIfNoEntry: false })?.isDirectory()));
|
|
16
|
+
};
|
|
13
17
|
/**
|
|
14
18
|
* Recursively checks a directory for files that match known native module patterns.
|
|
15
19
|
*/
|
package/dist/utils/types.d.ts
CHANGED
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": "14.8.
|
|
4
|
+
"version": "14.8.6",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"rollup": "^4.59.0",
|
|
146
146
|
"shx": "^0.4.0",
|
|
147
147
|
"ts-node": "^10.9.2",
|
|
148
|
-
"typescript": "^
|
|
148
|
+
"typescript": "^6.0.2",
|
|
149
149
|
"vitest": "4.1.0"
|
|
150
150
|
},
|
|
151
151
|
"oclif": {
|