@sanity/runtime-cli 17.16.0-app-functions.ge0a25ea → 17.16.0-next.g05d3b7f
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/stacks.d.ts +2 -7
- package/dist/actions/blueprints/stacks.js +6 -10
- package/dist/actions/blueprints/wait-for-operation.d.ts +0 -1
- package/dist/actions/blueprints/wait-for-operation.js +1 -1
- package/dist/cores/blueprints/deploy.d.ts +0 -8
- package/dist/cores/blueprints/deploy.js +4 -12
- package/dist/cores/functions/logs.d.ts +7 -0
- package/dist/cores/functions/logs.js +17 -6
- package/dist/utils/functions/child-runtime/durable.js +43 -2
- package/dist/utils/functions/child-runtime/getBatchResults.js +75 -0
- package/dist/utils/functions/transpile/function.d.ts +1 -7
- package/dist/utils/functions/transpile/function.js +12 -15
- package/oclif.manifest.json +1 -1
- package/package.json +2 -23
- package/dist/functions/artifacts.d.ts +0 -13
- package/dist/functions/artifacts.js +0 -26
- package/dist/functions/build.d.ts +0 -15
- package/dist/functions/build.js +0 -27
- package/dist/functions/contractPlugin.d.ts +0 -7
- package/dist/functions/contractPlugin.js +0 -32
- package/dist/functions/contracts/schema.d.ts +0 -22
- package/dist/functions/contracts/schema.js +0 -99
- package/dist/functions/contracts/validation.d.ts +0 -3
- package/dist/functions/contracts/validation.js +0 -66
- package/dist/functions/contracts.d.ts +0 -20
- package/dist/functions/contracts.js +0 -119
- package/dist/functions/deploy.d.ts +0 -15
- package/dist/functions/deploy.js +0 -60
- package/dist/functions/stack.d.ts +0 -18
- package/dist/functions/stack.js +0 -84
package/dist/functions/stack.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { createStack, getStack, listStacks } from '../actions/blueprints/stacks.js';
|
|
2
|
-
import { Logger } from '../utils/logger.js';
|
|
3
|
-
/** Shared ownership check for provisioning and deploying an app's function stack. */
|
|
4
|
-
export function assertAppFunctionStack(stack, { appId, organizationId }) {
|
|
5
|
-
if (!stack ||
|
|
6
|
-
typeof stack.id !== 'string' ||
|
|
7
|
-
!stack.id ||
|
|
8
|
-
stack.name !== appFunctionStackName(appId) ||
|
|
9
|
-
stack.scopeType !== 'organization' ||
|
|
10
|
-
stack.scopeId !== organizationId) {
|
|
11
|
-
throw new Error(`The function stack does not belong to app "${appId}" in organization "${organizationId}". Check .sanity/app-functions.json.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** Resolve or create a dedicated app stack using the Blueprint stack operations. */
|
|
15
|
-
export async function ensureFunctionStack(options) {
|
|
16
|
-
const { appId, organizationId, token, fetchFn, stackId, dryRun = false } = options;
|
|
17
|
-
const auth = { token, scopeType: 'organization', scopeId: organizationId };
|
|
18
|
-
const name = appFunctionStackName(appId);
|
|
19
|
-
const logger = Logger(() => { }, { json: true });
|
|
20
|
-
const resolved = (stack, created) => {
|
|
21
|
-
assertAppFunctionStack(stack, options);
|
|
22
|
-
return { created, id: stack.id };
|
|
23
|
-
};
|
|
24
|
-
if (stackId) {
|
|
25
|
-
const result = await getStack({ stackId, auth, fetchFn });
|
|
26
|
-
if (result.ok)
|
|
27
|
-
return resolved(result.stack, false);
|
|
28
|
-
if (result.response?.status !== 404)
|
|
29
|
-
throw stackRequestError(result);
|
|
30
|
-
}
|
|
31
|
-
async function findStack() {
|
|
32
|
-
let cursor;
|
|
33
|
-
const cursors = new Set();
|
|
34
|
-
do {
|
|
35
|
-
const result = await listStacks(auth, logger, { fetchFn, cursor, limit: 500 });
|
|
36
|
-
if (!result.ok)
|
|
37
|
-
throw stackRequestError(result);
|
|
38
|
-
if (!Array.isArray(result.stacks))
|
|
39
|
-
throw new Error('Invalid Blueprint stack list response.');
|
|
40
|
-
const stack = result.stacks.find((item) => item?.name === name);
|
|
41
|
-
if (stack)
|
|
42
|
-
return stack;
|
|
43
|
-
if (result.response?.headers.get('x-has-more') !== 'true')
|
|
44
|
-
return undefined;
|
|
45
|
-
cursor = result.response.headers.get('x-cursor') ?? undefined;
|
|
46
|
-
if (!cursor || cursors.has(cursor))
|
|
47
|
-
throw new Error('Cannot read the next page of Blueprint stacks. Try again.');
|
|
48
|
-
cursors.add(cursor);
|
|
49
|
-
} while (cursor);
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
const existing = await findStack();
|
|
53
|
-
if (existing)
|
|
54
|
-
return resolved(existing, false);
|
|
55
|
-
if (dryRun)
|
|
56
|
-
return null;
|
|
57
|
-
const result = await createStack({
|
|
58
|
-
auth,
|
|
59
|
-
logger,
|
|
60
|
-
fetchFn,
|
|
61
|
-
stackMutation: {
|
|
62
|
-
name,
|
|
63
|
-
scopeType: auth.scopeType,
|
|
64
|
-
scopeId: auth.scopeId,
|
|
65
|
-
document: { resources: [] },
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
if (result.ok)
|
|
69
|
-
return resolved(result.stack, true);
|
|
70
|
-
if (result.response?.status === 409) {
|
|
71
|
-
const concurrent = await findStack();
|
|
72
|
-
if (concurrent)
|
|
73
|
-
return resolved(concurrent, false);
|
|
74
|
-
}
|
|
75
|
-
throw stackRequestError(result);
|
|
76
|
-
}
|
|
77
|
-
function appFunctionStackName(appId) {
|
|
78
|
-
return `app-${appId}`;
|
|
79
|
-
}
|
|
80
|
-
function stackRequestError(result) {
|
|
81
|
-
const status = result.response ? ` (${result.response.status})` : '';
|
|
82
|
-
return new Error(`Blueprint stack request failed${status}: ${result.error || result.response?.statusText || 'Unknown error'}`);
|
|
83
|
-
}
|
|
84
|
-
export { BLUEPRINTS_API_VERSION } from '../config.js';
|