@sanity/runtime-cli 17.16.0-next.g8d59d6f → 17.16.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 +19 -19
- package/dist/actions/blueprints/assets.d.ts +3 -3
- package/dist/actions/blueprints/assets.js +3 -3
- package/dist/actions/blueprints/pre-deploy.js +3 -3
- package/dist/actions/blueprints/process-assets.js +2 -3
- package/dist/cores/functions/test.js +1 -1
- package/dist/server/app.js +2 -2
- package/dist/utils/blueprints/group-resources.d.ts +1 -2
- package/dist/utils/blueprints/group-resources.js +3 -3
- package/dist/utils/blueprints/resolve-deployed-resources.d.ts +2 -2
- package/dist/utils/blueprints/resolve-deployed-resources.js +4 -4
- package/dist/utils/bundles/prepare-asset.d.ts +3 -3
- package/dist/utils/bundles/prepare-asset.js +7 -8
- package/dist/utils/functions/invoke/local.js +2 -3
- package/dist/utils/functions/invoke/resolve-invoke-type.d.ts +2 -2
- package/dist/utils/functions/invoke/resolve-invoke-type.js +2 -2
- package/dist/utils/types.d.ts +12 -15
- package/dist/utils/types.js +1 -1
- package/oclif.manifest.json +1002 -1002
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ EXAMPLES
|
|
|
90
90
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
93
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/add.ts)_
|
|
94
94
|
|
|
95
95
|
## `sanity-run blueprints config`
|
|
96
96
|
|
|
@@ -127,7 +127,7 @@ EXAMPLES
|
|
|
127
127
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
130
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/config.ts)_
|
|
131
131
|
|
|
132
132
|
## `sanity-run blueprints deploy`
|
|
133
133
|
|
|
@@ -183,7 +183,7 @@ EXAMPLES
|
|
|
183
183
|
$ sanity-run blueprints deploy --new-stack-name <new-name>
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
186
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/deploy.ts)_
|
|
187
187
|
|
|
188
188
|
## `sanity-run blueprints destroy`
|
|
189
189
|
|
|
@@ -221,7 +221,7 @@ EXAMPLES
|
|
|
221
221
|
$ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
224
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/destroy.ts)_
|
|
225
225
|
|
|
226
226
|
## `sanity-run blueprints doctor`
|
|
227
227
|
|
|
@@ -253,7 +253,7 @@ EXAMPLES
|
|
|
253
253
|
$ sanity-run blueprints doctor --fix
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
256
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/doctor.ts)_
|
|
257
257
|
|
|
258
258
|
## `sanity-run blueprints info`
|
|
259
259
|
|
|
@@ -291,7 +291,7 @@ EXAMPLES
|
|
|
291
291
|
$ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
294
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/info.ts)_
|
|
295
295
|
|
|
296
296
|
## `sanity-run blueprints init [DIR]`
|
|
297
297
|
|
|
@@ -355,7 +355,7 @@ EXAMPLES
|
|
|
355
355
|
$ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
|
|
356
356
|
```
|
|
357
357
|
|
|
358
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
358
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/init.ts)_
|
|
359
359
|
|
|
360
360
|
## `sanity-run blueprints logs`
|
|
361
361
|
|
|
@@ -401,7 +401,7 @@ EXAMPLES
|
|
|
401
401
|
$ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
|
|
402
402
|
```
|
|
403
403
|
|
|
404
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
404
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/logs.ts)_
|
|
405
405
|
|
|
406
406
|
## `sanity-run blueprints mint-deploy-token`
|
|
407
407
|
|
|
@@ -446,7 +446,7 @@ EXAMPLES
|
|
|
446
446
|
$ sanity-run blueprints mint-deploy-token --organization-id <orgId>
|
|
447
447
|
```
|
|
448
448
|
|
|
449
|
-
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
449
|
+
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/mint-deploy-token.ts)_
|
|
450
450
|
|
|
451
451
|
## `sanity-run blueprints plan`
|
|
452
452
|
|
|
@@ -479,7 +479,7 @@ EXAMPLES
|
|
|
479
479
|
$ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
|
|
480
480
|
```
|
|
481
481
|
|
|
482
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
482
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/plan.ts)_
|
|
483
483
|
|
|
484
484
|
## `sanity-run blueprints promote`
|
|
485
485
|
|
|
@@ -515,7 +515,7 @@ EXAMPLES
|
|
|
515
515
|
$ sanity-run blueprints promote --new-stack-name <new-name>
|
|
516
516
|
```
|
|
517
517
|
|
|
518
|
-
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
518
|
+
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/promote.ts)_
|
|
519
519
|
|
|
520
520
|
## `sanity-run blueprints stacks`
|
|
521
521
|
|
|
@@ -556,7 +556,7 @@ EXAMPLES
|
|
|
556
556
|
$ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
|
|
557
557
|
```
|
|
558
558
|
|
|
559
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
559
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/blueprints/stacks.ts)_
|
|
560
560
|
|
|
561
561
|
## `sanity-run functions add`
|
|
562
562
|
|
|
@@ -608,7 +608,7 @@ EXAMPLES
|
|
|
608
608
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
609
609
|
```
|
|
610
610
|
|
|
611
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
611
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/add.ts)_
|
|
612
612
|
|
|
613
613
|
## `sanity-run functions dev`
|
|
614
614
|
|
|
@@ -643,7 +643,7 @@ EXAMPLES
|
|
|
643
643
|
$ sanity-run functions dev --timeout 60
|
|
644
644
|
```
|
|
645
645
|
|
|
646
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
646
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/dev.ts)_
|
|
647
647
|
|
|
648
648
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
649
649
|
|
|
@@ -676,7 +676,7 @@ EXAMPLES
|
|
|
676
676
|
$ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
|
|
677
677
|
```
|
|
678
678
|
|
|
679
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
679
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/env/add.ts)_
|
|
680
680
|
|
|
681
681
|
## `sanity-run functions env list NAME`
|
|
682
682
|
|
|
@@ -706,7 +706,7 @@ EXAMPLES
|
|
|
706
706
|
$ sanity-run functions env list --stack <name-or-id> MyFunction
|
|
707
707
|
```
|
|
708
708
|
|
|
709
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
709
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/env/list.ts)_
|
|
710
710
|
|
|
711
711
|
## `sanity-run functions env remove NAME KEY`
|
|
712
712
|
|
|
@@ -738,7 +738,7 @@ EXAMPLES
|
|
|
738
738
|
$ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
|
|
739
739
|
```
|
|
740
740
|
|
|
741
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
741
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/env/remove.ts)_
|
|
742
742
|
|
|
743
743
|
## `sanity-run functions logs [NAME]`
|
|
744
744
|
|
|
@@ -778,7 +778,7 @@ EXAMPLES
|
|
|
778
778
|
$ sanity-run functions logs <name> --delete
|
|
779
779
|
```
|
|
780
780
|
|
|
781
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
781
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/logs.ts)_
|
|
782
782
|
|
|
783
783
|
## `sanity-run functions test [NAME]`
|
|
784
784
|
|
|
@@ -836,7 +836,7 @@ EXAMPLES
|
|
|
836
836
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
837
837
|
```
|
|
838
838
|
|
|
839
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0
|
|
839
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0/src/commands/functions/test.ts)_
|
|
840
840
|
|
|
841
841
|
## `sanity-run help [COMMAND]`
|
|
842
842
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
|
-
import type { AuthParams, InstallerType, PrepAssetFn
|
|
2
|
+
import type { AuthParams, InstallerType, PrepAssetFn } from '../../utils/types.js';
|
|
3
3
|
export declare const assetCheckUrl: string;
|
|
4
4
|
export declare const assetStashUrl: string;
|
|
5
5
|
export type StashAssetResult = {
|
|
@@ -18,8 +18,8 @@ export type StashAssetResult = {
|
|
|
18
18
|
success: false;
|
|
19
19
|
error: string;
|
|
20
20
|
};
|
|
21
|
-
export declare function stashAsset<R extends BlueprintResource>({
|
|
22
|
-
|
|
21
|
+
export declare function stashAsset<R extends BlueprintResource>({ resource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }: {
|
|
22
|
+
resource: R;
|
|
23
23
|
prepAsset: PrepAssetFn<R>;
|
|
24
24
|
auth: AuthParams;
|
|
25
25
|
blueprintFileDir: string;
|
|
@@ -4,10 +4,10 @@ import getHeaders from '../../utils/get-headers.js';
|
|
|
4
4
|
const assetsUrl = blueprintsUrl('assets');
|
|
5
5
|
export const assetCheckUrl = `${assetsUrl}/check`;
|
|
6
6
|
export const assetStashUrl = `${assetsUrl}/stash`;
|
|
7
|
-
export async function stashAsset({
|
|
7
|
+
export async function stashAsset({ resource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }) {
|
|
8
8
|
let cleanup = async () => { };
|
|
9
9
|
try {
|
|
10
|
-
const prepResult = await prepAsset({
|
|
10
|
+
const prepResult = await prepAsset({ resource, blueprintFileDir, installer });
|
|
11
11
|
if (prepResult.success === false) {
|
|
12
12
|
await prepResult.cleanup();
|
|
13
13
|
return {
|
|
@@ -26,7 +26,7 @@ export async function stashAsset({ resolvedResource, prepAsset, auth, blueprintF
|
|
|
26
26
|
assetParameter: prepResult.assetParameter,
|
|
27
27
|
metadata: prepResult.metadata,
|
|
28
28
|
cleanup,
|
|
29
|
-
resourceName:
|
|
29
|
+
resourceName: resource.name,
|
|
30
30
|
auth,
|
|
31
31
|
fetchFn,
|
|
32
32
|
});
|
|
@@ -18,7 +18,7 @@ const preDeployConfigs = [
|
|
|
18
18
|
resourceType: (type) => type in BUNDLE_SPECS,
|
|
19
19
|
async prepareAsset(options) {
|
|
20
20
|
return prepareBundleAsset({
|
|
21
|
-
|
|
21
|
+
resource: options.resource,
|
|
22
22
|
blueprintFileDir: options.blueprintFileDir,
|
|
23
23
|
});
|
|
24
24
|
},
|
|
@@ -30,7 +30,7 @@ const preDeployConfigs = [
|
|
|
30
30
|
resourceType: (type) => type.startsWith(SANITY_FUNCTION_PREFIX),
|
|
31
31
|
async prepareAsset(options) {
|
|
32
32
|
return prepareFunctionAsset({
|
|
33
|
-
resource: options.
|
|
33
|
+
resource: options.resource,
|
|
34
34
|
blueprintFileDir: options.blueprintFileDir,
|
|
35
35
|
installer: options.installer,
|
|
36
36
|
});
|
|
@@ -74,7 +74,7 @@ export async function preDeploy(options) {
|
|
|
74
74
|
});
|
|
75
75
|
const assetResources = [];
|
|
76
76
|
for (const r of resolvedResources) {
|
|
77
|
-
const config = getPredeployConfig(r
|
|
77
|
+
const config = getPredeployConfig(r);
|
|
78
78
|
if (typeof config !== 'undefined' && typeof config.prepareAsset === 'function') {
|
|
79
79
|
assetResources.push({ resource: r, prepareAsset: config.prepareAsset });
|
|
80
80
|
}
|
|
@@ -42,14 +42,13 @@ function getAssetConcurrency() {
|
|
|
42
42
|
const configured = Number(env.SANITY_ASSET_CONCURRENCY);
|
|
43
43
|
return Number.isSafeInteger(configured) && configured > 0 ? configured : DEFAULT_ASSET_CONCURRENCY;
|
|
44
44
|
}
|
|
45
|
-
async function processAsset(
|
|
46
|
-
const { resource } = resolvedResource;
|
|
45
|
+
async function processAsset(resource, prepAsset, options) {
|
|
47
46
|
const { auth, blueprintFileDir, installer, fetchFn } = options;
|
|
48
47
|
let assetTimeoutTimer;
|
|
49
48
|
let result;
|
|
50
49
|
try {
|
|
51
50
|
result = await Promise.race([
|
|
52
|
-
stashAsset({
|
|
51
|
+
stashAsset({ resource, prepAsset, blueprintFileDir, auth, fetchFn, installer }),
|
|
53
52
|
new Promise((_, reject) => {
|
|
54
53
|
assetTimeoutTimer = setTimeout(() => {
|
|
55
54
|
reject(new Error(`Processing ${resource.name} timed out after ${assetTimeoutS}s`));
|
|
@@ -55,7 +55,7 @@ export async function functionTestCore(options) {
|
|
|
55
55
|
apiHost: config.apiUrl,
|
|
56
56
|
token: config.token || undefined,
|
|
57
57
|
withUserToken,
|
|
58
|
-
resolvedResources,
|
|
58
|
+
resources: resolvedResources,
|
|
59
59
|
blueprintFileDir: dirname(blueprint.fileInfo.blueprintFilePath),
|
|
60
60
|
log,
|
|
61
61
|
};
|
package/dist/server/app.js
CHANGED
|
@@ -8,7 +8,7 @@ import { findBlueprintFile, loadAndParseBlueprint } from '../actions/blueprints/
|
|
|
8
8
|
import { readConfigFile } from '../actions/blueprints/config.js';
|
|
9
9
|
import config from '../config.js';
|
|
10
10
|
import { isRecord } from '../utils/is-record.js';
|
|
11
|
-
import { isEventType, } from '../utils/types.js';
|
|
11
|
+
import { isEventType, isGroqContextOptions, } from '../utils/types.js';
|
|
12
12
|
import { handleInvokeRequest } from './handlers/invoke.js';
|
|
13
13
|
const app = (host, port, validateResources, executionOptions) => {
|
|
14
14
|
// Send a JSON envelope to every connected UI client.
|
|
@@ -75,7 +75,7 @@ const app = (host, port, validateResources, executionOptions) => {
|
|
|
75
75
|
const { data, func: functionName, metadata, } = parseInvokeRequest(Buffer.concat(body), dirname(fileInfo.blueprintFilePath));
|
|
76
76
|
const { context, event } = data;
|
|
77
77
|
// replace user token if required
|
|
78
|
-
if (
|
|
78
|
+
if (isGroqContextOptions(context)) {
|
|
79
79
|
if (context.clientOptions.token) {
|
|
80
80
|
context.clientOptions.token = config.token || undefined;
|
|
81
81
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
|
-
import type { ResolvedResource } from '../types.js';
|
|
3
2
|
export type GroupedBlueprintResource = {
|
|
4
3
|
id: string;
|
|
5
4
|
name: string;
|
|
6
5
|
type: string;
|
|
7
6
|
};
|
|
8
7
|
export type GroupedBlueprintResources = Record<string, GroupedBlueprintResource[]>;
|
|
9
|
-
export declare function groupBlueprintResources(blueprintResources:
|
|
8
|
+
export declare function groupBlueprintResources(blueprintResources: BlueprintResource[]): GroupedBlueprintResources;
|
|
@@ -8,8 +8,7 @@ const BLUEPRINT_TYPE_TO_KEY = {
|
|
|
8
8
|
};
|
|
9
9
|
export function groupBlueprintResources(blueprintResources) {
|
|
10
10
|
const grouped = {};
|
|
11
|
-
for (const
|
|
12
|
-
const resource = resolvedResource.resource;
|
|
11
|
+
for (const resource of blueprintResources) {
|
|
13
12
|
if (resource.type === 'sanity.access.robot')
|
|
14
13
|
continue;
|
|
15
14
|
const key = (resource.type?.startsWith('sanity.function.')
|
|
@@ -19,8 +18,9 @@ export function groupBlueprintResources(blueprintResources) {
|
|
|
19
18
|
continue;
|
|
20
19
|
if (!grouped[key])
|
|
21
20
|
grouped[key] = [];
|
|
21
|
+
const externalId = resource.externalId;
|
|
22
22
|
grouped[key].push({
|
|
23
|
-
id:
|
|
23
|
+
id: externalId || 'not-deployed',
|
|
24
24
|
name: resource.name,
|
|
25
25
|
type: resource.type,
|
|
26
26
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
|
-
import type { AuthParams
|
|
2
|
+
import type { AuthParams } from '../types.js';
|
|
3
3
|
interface ResolveOptions {
|
|
4
4
|
resources: BlueprintResource[];
|
|
5
5
|
stackId?: string;
|
|
@@ -12,5 +12,5 @@ interface ResolveOptions {
|
|
|
12
12
|
* resources that aren't yet deployed are preserved without an externalId.
|
|
13
13
|
* Any failure to fetch the stack falls back to the raw local resources.
|
|
14
14
|
*/
|
|
15
|
-
export declare function resolveDeployedResources({ resources, stackId, auth, fetchFn, }: ResolveOptions): Promise<
|
|
15
|
+
export declare function resolveDeployedResources({ resources, stackId, auth, fetchFn, }: ResolveOptions): Promise<BlueprintResource[]>;
|
|
16
16
|
export {};
|
|
@@ -7,11 +7,11 @@ import { getStack } from '../../actions/blueprints/stacks.js';
|
|
|
7
7
|
*/
|
|
8
8
|
export async function resolveDeployedResources({ resources, stackId, auth, fetchFn, }) {
|
|
9
9
|
if (!stackId || !auth?.token || !auth.scopeType || !auth.scopeId)
|
|
10
|
-
return resources
|
|
10
|
+
return resources;
|
|
11
11
|
try {
|
|
12
12
|
const response = await getStack({ stackId, auth, fetchFn });
|
|
13
13
|
if (!response.ok || !Array.isArray(response.stack?.resources))
|
|
14
|
-
return resources
|
|
14
|
+
return resources;
|
|
15
15
|
const deployedByKey = new Map();
|
|
16
16
|
for (const deployed of response.stack.resources) {
|
|
17
17
|
if (deployed.externalId) {
|
|
@@ -20,10 +20,10 @@ export async function resolveDeployedResources({ resources, stackId, auth, fetch
|
|
|
20
20
|
}
|
|
21
21
|
return resources.map((resource) => {
|
|
22
22
|
const externalId = deployedByKey.get(`${resource.type}:${resource.name}`);
|
|
23
|
-
return { resource, externalId };
|
|
23
|
+
return externalId ? { ...resource, externalId } : resource;
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
catch {
|
|
27
|
-
return resources
|
|
27
|
+
return resources;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BlueprintApplicationResource, BlueprintInstallationConfigResource, BlueprintStudioResource } from '@sanity/blueprints';
|
|
2
2
|
import { type BuildStudioEventListener } from '@sanity/cli-build/_internal/build';
|
|
3
3
|
import type { Output } from '@sanity/cli-core';
|
|
4
|
-
import type { AssetPrepResult
|
|
4
|
+
import type { AssetPrepResult } from '../types.js';
|
|
5
5
|
export type BundleResource = BlueprintStudioResource | BlueprintApplicationResource | BlueprintInstallationConfigResource;
|
|
6
6
|
type BuildContext<R extends BundleResource> = {
|
|
7
7
|
resource: R;
|
|
@@ -28,9 +28,9 @@ export declare const BUNDLE_SPECS: {
|
|
|
28
28
|
build: typeof buildInstallationConfigBundle;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
export declare function prepareBundleAsset<R extends BundleResource>({ blueprintFileDir,
|
|
31
|
+
export declare function prepareBundleAsset<R extends BundleResource>({ blueprintFileDir, resource, }: {
|
|
32
32
|
blueprintFileDir: string;
|
|
33
|
-
|
|
33
|
+
resource: R;
|
|
34
34
|
}): Promise<AssetPrepResult>;
|
|
35
35
|
declare function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintStudioResource>): Promise<BuildResult>;
|
|
36
36
|
declare function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintApplicationResource>): Promise<BuildResult>;
|
|
@@ -12,11 +12,10 @@ export const BUNDLE_SPECS = {
|
|
|
12
12
|
'sanity.application': { requiresAppId: true, build: buildApplicationBundle },
|
|
13
13
|
'sanity.installation.config': { requiresAppId: false, build: buildInstallationConfigBundle },
|
|
14
14
|
};
|
|
15
|
-
export async function prepareBundleAsset({ blueprintFileDir,
|
|
16
|
-
const resource = resolvedResource.resource;
|
|
15
|
+
export async function prepareBundleAsset({ blueprintFileDir, resource, }) {
|
|
17
16
|
// The lookup can't prove it yields the spec matching this R, so it's asserted once here.
|
|
18
17
|
const spec = BUNDLE_SPECS[resource.type];
|
|
19
|
-
const appId = getAppId(
|
|
18
|
+
const appId = getAppId(resource);
|
|
20
19
|
if (spec.requiresAppId && !appId) {
|
|
21
20
|
return {
|
|
22
21
|
success: false,
|
|
@@ -261,12 +260,12 @@ async function getInstalledSanityVersion(workDir) {
|
|
|
261
260
|
return undefined;
|
|
262
261
|
}
|
|
263
262
|
}
|
|
264
|
-
function getAppId(
|
|
265
|
-
if (
|
|
266
|
-
return
|
|
263
|
+
function getAppId(resource) {
|
|
264
|
+
if ('externalId' in resource && typeof resource.externalId === 'string' && resource.externalId) {
|
|
265
|
+
return resource.externalId;
|
|
267
266
|
}
|
|
268
|
-
else if (
|
|
269
|
-
return
|
|
267
|
+
else if (resource.lifecycle?.ownershipAction?.type === 'attach') {
|
|
268
|
+
return resource.lifecycle.ownershipAction.id;
|
|
270
269
|
}
|
|
271
270
|
return undefined;
|
|
272
271
|
}
|
|
@@ -64,11 +64,10 @@ export default async function invoke(resource, payload, context, options) {
|
|
|
64
64
|
// Apply the GROQ rule before preparing a build so a filtered-out event skips
|
|
65
65
|
// the (potentially expensive) transpile entirely.
|
|
66
66
|
if (isGroqInvocation(resource)) {
|
|
67
|
-
if (!(
|
|
67
|
+
if (!isGroqContextOptions(context)) {
|
|
68
68
|
throw new Error('GROQ-based functions require a context with clientOptions');
|
|
69
69
|
}
|
|
70
|
-
const
|
|
71
|
-
const dataset = 'dataset' in context.clientOptions ? context.clientOptions.dataset : undefined;
|
|
70
|
+
const { projectId, dataset } = context.clientOptions;
|
|
72
71
|
if ('before' in payload) {
|
|
73
72
|
filteredData = await applyGroqRule(resource, payload, projectId, dataset);
|
|
74
73
|
const filter = resource.event && 'filter' in resource.event ? resource.event.filter : '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
2
|
import type { Logger } from '../../logger.js';
|
|
3
|
-
import type { EventType, FunctionGroqResource, FunctionResource, FunctionTestFlags, InvokeContextOptions, InvokePayloadOptions
|
|
3
|
+
import type { EventType, FunctionGroqResource, FunctionResource, FunctionTestFlags, InvokeContextOptions, InvokePayloadOptions } from '../../types.js';
|
|
4
4
|
import buildPayload from '../build-payload.js';
|
|
5
5
|
import { fetchAsset, fetchDocument } from '../fetch-document.js';
|
|
6
6
|
export type InvocationPlan = {
|
|
@@ -23,7 +23,7 @@ export type InputContext = {
|
|
|
23
23
|
apiHost: string;
|
|
24
24
|
token?: string;
|
|
25
25
|
withUserToken?: boolean;
|
|
26
|
-
|
|
26
|
+
resources: BlueprintResource[];
|
|
27
27
|
blueprintFileDir: string;
|
|
28
28
|
log: Logger;
|
|
29
29
|
};
|
|
@@ -51,7 +51,7 @@ export const buildContext = (plan, input) => {
|
|
|
51
51
|
if (plan.kind === 'plain') {
|
|
52
52
|
return {
|
|
53
53
|
clientOptions: { ...withToken },
|
|
54
|
-
resources: input.
|
|
54
|
+
resources: input.resources,
|
|
55
55
|
blueprintFileDir: input.blueprintFileDir,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
@@ -69,7 +69,7 @@ export const buildContext = (plan, input) => {
|
|
|
69
69
|
'',
|
|
70
70
|
functionResourceType: 'project',
|
|
71
71
|
functionResourceId: input.projectId || '',
|
|
72
|
-
resources: input.
|
|
72
|
+
resources: input.resources,
|
|
73
73
|
blueprintFileDir: input.blueprintFileDir,
|
|
74
74
|
};
|
|
75
75
|
};
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -40,11 +40,6 @@ export interface BlueprintResourceRecord extends BlueprintResource {
|
|
|
40
40
|
export interface DeployedResource extends BlueprintResourceRecord {
|
|
41
41
|
externalId: string;
|
|
42
42
|
}
|
|
43
|
-
/** Wrap a resource and its externalId if it has one. */
|
|
44
|
-
export interface ResolvedResource<R extends BlueprintResource> {
|
|
45
|
-
resource: R;
|
|
46
|
-
externalId?: string;
|
|
47
|
-
}
|
|
48
43
|
export declare function isLocalFunctionResource(r: BlueprintResource): r is FunctionResource;
|
|
49
44
|
export declare function hasEventSource(r: FunctionResource): r is EventFunctionResource;
|
|
50
45
|
export declare function isScheduleEvent(e: unknown): e is BlueprintScheduledFunctionResource['event'];
|
|
@@ -139,14 +134,8 @@ export type InvokePayloadMetadata = Pick<InvokeGroqPayloadOptions, 'event' | 'be
|
|
|
139
134
|
export type EventType = 'create' | 'update' | 'delete';
|
|
140
135
|
export type NonGroqEventType = 'plain' | 'nested' | 'durable';
|
|
141
136
|
export declare function isEventType(arg: string): arg is EventType;
|
|
142
|
-
interface BaseContextOptions {
|
|
143
|
-
/** All resources declared by the blueprint, used to populate `context.resources` at invoke time. */
|
|
144
|
-
resources?: ResolvedResource<BlueprintResource>[];
|
|
145
|
-
/** The directory where the blueprint manifest is located. */
|
|
146
|
-
blueprintFileDir: string;
|
|
147
|
-
}
|
|
148
137
|
/** @internal */
|
|
149
|
-
export interface InvokeGroqContextOptions
|
|
138
|
+
export interface InvokeGroqContextOptions {
|
|
150
139
|
clientOptions: {
|
|
151
140
|
apiVersion?: string;
|
|
152
141
|
dataset?: string;
|
|
@@ -162,12 +151,20 @@ export interface InvokeGroqContextOptions extends BaseContextOptions {
|
|
|
162
151
|
functionResourceType: string;
|
|
163
152
|
/** The resource ID of the function container; resource ID that houses the function. */
|
|
164
153
|
functionResourceId: string;
|
|
154
|
+
/** All resources declared by the blueprint, used to populate `context.resources` at invoke time. */
|
|
155
|
+
resources?: BlueprintResource[];
|
|
156
|
+
/** The directory where the blueprint manifest is located. */
|
|
157
|
+
blueprintFileDir: string;
|
|
165
158
|
}
|
|
166
159
|
/** @internal */
|
|
167
|
-
export interface InvokeScheduleContextOptions
|
|
160
|
+
export interface InvokeScheduleContextOptions {
|
|
168
161
|
clientOptions: {
|
|
169
162
|
token?: string;
|
|
170
163
|
};
|
|
164
|
+
/** All resources declared by the blueprint, used to populate `context.resources` at invoke time. */
|
|
165
|
+
resources?: BlueprintResource[];
|
|
166
|
+
/** The directory where the blueprint manifest is located. */
|
|
167
|
+
blueprintFileDir: string;
|
|
171
168
|
}
|
|
172
169
|
export type InvokeContextOptions = InvokeGroqContextOptions | InvokeScheduleContextOptions;
|
|
173
170
|
export declare function isGroqContextOptions(context: InvokeContextOptions): context is InvokeGroqContextOptions;
|
|
@@ -341,7 +338,7 @@ export type AssetPrepResult = {
|
|
|
341
338
|
error: string;
|
|
342
339
|
};
|
|
343
340
|
export type PrepAssetFn<R extends BlueprintResource> = (options: {
|
|
344
|
-
|
|
341
|
+
resource: R;
|
|
345
342
|
blueprintFileDir: string;
|
|
346
343
|
installer?: InstallerType;
|
|
347
344
|
}) => Promise<AssetPrepResult>;
|
|
@@ -358,7 +355,7 @@ export type PreDeployConfig = {
|
|
|
358
355
|
prepareResource?: PrepResourceFn<BlueprintResource>;
|
|
359
356
|
};
|
|
360
357
|
export type AssetResource<R extends BlueprintResource> = {
|
|
361
|
-
resource:
|
|
358
|
+
resource: R;
|
|
362
359
|
prepareAsset: PrepAssetFn<R>;
|
|
363
360
|
};
|
|
364
361
|
export type Warning = {
|
package/dist/utils/types.js
CHANGED
|
@@ -38,7 +38,7 @@ export function isEventType(arg) {
|
|
|
38
38
|
return ['create', 'update', 'delete'].includes(arg);
|
|
39
39
|
}
|
|
40
40
|
export function isGroqContextOptions(context) {
|
|
41
|
-
return '
|
|
41
|
+
return 'clientOptions' in context;
|
|
42
42
|
}
|
|
43
43
|
/** @internal */
|
|
44
44
|
export var BlueprintParserErrorType;
|