sst 2.25.6 → 2.26.1
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/bootstrap.js +3 -3
- package/bus.js +2 -2
- package/cache.js +2 -2
- package/cdk/deployments-wrapper.js +2 -2
- package/cli/commands/dev.js +6 -5
- package/cli/commands/plugins/kysely.js +2 -2
- package/cli/commands/plugins/pothos.js +2 -2
- package/cli/commands/plugins/warmer.js +2 -2
- package/cli/local/server.js +75 -26
- package/cli/spinner.js +2 -2
- package/constructs/App.js +4 -3
- package/constructs/Function.d.ts +2 -2
- package/constructs/Function.js +1 -1
- package/constructs/context.d.ts +2 -7
- package/constructs/context.js +26 -8
- package/context/context2.d.ts +16 -0
- package/context/context2.js +108 -0
- package/context/handler.js +3 -4
- package/credentials.d.ts +3 -10
- package/credentials.js +5 -5
- package/iot.js +3 -3
- package/logger.js +2 -2
- package/node/actor/index.d.ts +2 -2
- package/node/actor/index.js +3 -3
- package/node/api/index.js +7 -7
- package/node/auth/session.js +1 -1
- package/node/event-bus/index.js +0 -1
- package/node/future/auth/session.js +1 -1
- package/node/util/loader.js +4 -4
- package/package.json +20 -19
- package/project.d.ts +0 -5
- package/project.js +5 -5
- package/runtime/handlers/python.js +1 -3
- package/runtime/handlers.js +3 -3
- package/runtime/iot.js +2 -2
- package/runtime/server.js +3 -3
- package/runtime/workers.js +2 -2
- package/stacks/app-metadata.js +2 -3
- package/stacks/metadata.d.ts +1 -1
- package/stacks/metadata.js +2 -5
- package/support/bootstrap-metadata-function/index.mjs +41338 -45328
- package/support/bridge/bridge.mjs +55 -65
- package/support/custom-resources/index.mjs +90699 -90561
- package/support/event-bus-retrier/index.mjs +57 -27
- package/support/job-manager/index.mjs +22257 -7697
- package/support/rds-migrator/index.mjs +41 -17
- package/support/script-function/index.mjs +33731 -35450
- package/support/signing-function/index.mjs +578 -32
- package/support/ssr-warmer/index.mjs +26855 -26892
- package/util/lazy.d.ts +1 -0
- package/util/lazy.js +11 -0
- package/watcher.js +2 -2
package/iot.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { IoTClient, DescribeEndpointCommand } from "@aws-sdk/client-iot";
|
|
2
|
-
import { Context } from "./context/context.js";
|
|
3
2
|
import { useAWSClient, useAWSCredentials } from "./credentials.js";
|
|
4
3
|
import { VisibleError } from "./error.js";
|
|
5
|
-
export const useIOTEndpoint =
|
|
4
|
+
export const useIOTEndpoint = lazy(async () => {
|
|
6
5
|
const iot = useAWSClient(IoTClient);
|
|
7
6
|
Logger.debug("Getting IoT endpoint");
|
|
8
7
|
const response = await iot.send(new DescribeEndpointCommand({
|
|
@@ -19,7 +18,8 @@ import { useProject } from "./project.js";
|
|
|
19
18
|
import { Logger } from "./logger.js";
|
|
20
19
|
import { useBootstrap } from "./bootstrap.js";
|
|
21
20
|
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
22
|
-
|
|
21
|
+
import { lazy } from "./util/lazy.js";
|
|
22
|
+
export const useIOT = lazy(async () => {
|
|
23
23
|
const bus = useBus();
|
|
24
24
|
const endpoint = await useIOTEndpoint();
|
|
25
25
|
const creds = await useAWSCredentials();
|
package/logger.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { Context } from "./context/context.js";
|
|
4
3
|
import { useProject } from "./project.js";
|
|
4
|
+
import { lazy } from "./util/lazy.js";
|
|
5
5
|
let previous = new Date();
|
|
6
|
-
const useFile =
|
|
6
|
+
const useFile = lazy(() => {
|
|
7
7
|
const project = useProject();
|
|
8
8
|
const filePath = path.join(project.paths.out, "debug.log");
|
|
9
9
|
const file = fs.createWriteStream(filePath);
|
package/node/actor/index.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export declare function createActors<T extends Definition>(): {
|
|
|
10
10
|
type: "public";
|
|
11
11
|
properties: {};
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
withActor: <R>(value: T | {
|
|
14
14
|
type: "public";
|
|
15
15
|
properties: {};
|
|
16
|
-
}) =>
|
|
16
|
+
}, cb: () => R) => R;
|
|
17
17
|
assertActor<T_1 extends (T | {
|
|
18
18
|
type: "public";
|
|
19
19
|
properties: {};
|
package/node/actor/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { create } from "../../context/context2.js";
|
|
2
2
|
import { SSTError } from "../../util/error.js";
|
|
3
3
|
export class WrongActorError extends SSTError {
|
|
4
4
|
}
|
|
5
5
|
export function createActors() {
|
|
6
|
-
const ctx =
|
|
6
|
+
const ctx = create("Actors");
|
|
7
7
|
return {
|
|
8
8
|
useActor: ctx.use,
|
|
9
|
-
|
|
9
|
+
withActor: ctx.with,
|
|
10
10
|
assertActor(type) {
|
|
11
11
|
const actor = ctx.use();
|
|
12
12
|
if (actor.type === type)
|
package/node/api/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createProxy } from "../util/index.js";
|
|
2
|
-
import { Context } from "../../context/context.js";
|
|
3
2
|
import { useEvent, Handler, useContextType, } from "../../context/handler.js";
|
|
3
|
+
import { memo } from "../../context/context2.js";
|
|
4
4
|
export const Api = /* @__PURE__ */ createProxy("Api");
|
|
5
5
|
export const AppSyncApi =
|
|
6
6
|
/* @__PURE__ */ createProxy("AppSyncApi");
|
|
@@ -38,7 +38,7 @@ export function ApiHandler(cb) {
|
|
|
38
38
|
return serialized;
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
export const useCookies = /* @__PURE__ */
|
|
41
|
+
export const useCookies = /* @__PURE__ */ memo(() => {
|
|
42
42
|
const evt = useEvent("api");
|
|
43
43
|
const cookies = evt.cookies || [];
|
|
44
44
|
return Object.fromEntries(cookies.map((c) => c.split("=")).map(([k, v]) => [k, decodeURIComponent(v)]));
|
|
@@ -47,7 +47,7 @@ export function useCookie(name) {
|
|
|
47
47
|
const cookies = useCookies();
|
|
48
48
|
return cookies[name];
|
|
49
49
|
}
|
|
50
|
-
export const useBody = /* @__PURE__ */
|
|
50
|
+
export const useBody = /* @__PURE__ */ memo(() => {
|
|
51
51
|
const type = useContextType();
|
|
52
52
|
const evt = useEvent(type);
|
|
53
53
|
if (!evt.body)
|
|
@@ -57,24 +57,24 @@ export const useBody = /* @__PURE__ */ Context.memo(() => {
|
|
|
57
57
|
: evt.body;
|
|
58
58
|
return body;
|
|
59
59
|
});
|
|
60
|
-
export const useJsonBody = /* @__PURE__ */
|
|
60
|
+
export const useJsonBody = /* @__PURE__ */ memo(() => {
|
|
61
61
|
const body = useBody();
|
|
62
62
|
if (!body)
|
|
63
63
|
return;
|
|
64
64
|
return JSON.parse(body);
|
|
65
65
|
});
|
|
66
|
-
export const useFormData = /* @__PURE__ */
|
|
66
|
+
export const useFormData = /* @__PURE__ */ memo(() => {
|
|
67
67
|
const body = useBody();
|
|
68
68
|
if (!body)
|
|
69
69
|
return;
|
|
70
70
|
const params = new URLSearchParams(body);
|
|
71
71
|
return params;
|
|
72
72
|
});
|
|
73
|
-
export const usePath = /* @__PURE__ */
|
|
73
|
+
export const usePath = /* @__PURE__ */ memo(() => {
|
|
74
74
|
const evt = useEvent("api");
|
|
75
75
|
return evt.rawPath.split("/").filter(Boolean);
|
|
76
76
|
});
|
|
77
|
-
export const useResponse = /* @__PURE__ */
|
|
77
|
+
export const useResponse = /* @__PURE__ */ memo(() => {
|
|
78
78
|
const response = {
|
|
79
79
|
headers: {},
|
|
80
80
|
cookies: [],
|
package/node/auth/session.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSigner, createVerifier } from "fast-jwt";
|
|
2
|
-
import { Context } from "../../context/
|
|
2
|
+
import { Context } from "../../context/context2.js";
|
|
3
3
|
import { useCookie, useHeader } from "../api/index.js";
|
|
4
4
|
import { getPrivateKey, getPublicKey } from "./auth.js";
|
|
5
5
|
import { useContextType } from "../../context/handler.js";
|
package/node/event-bus/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export function createEventBuilder(props) {
|
|
|
13
13
|
? z.object(props.metadata)
|
|
14
14
|
: undefined;
|
|
15
15
|
const publish = async (properties, metadata) => {
|
|
16
|
-
console.log("publishing", type, properties);
|
|
17
16
|
const result = await useLoader("sst.bus.publish", async (input) => {
|
|
18
17
|
const size = 10;
|
|
19
18
|
const promises = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSigner, createVerifier } from "fast-jwt";
|
|
2
|
-
import { Context } from "../../../context/
|
|
2
|
+
import { Context } from "../../../context/context2.js";
|
|
3
3
|
import { useCookie, useHeader } from "../../api/index.js";
|
|
4
4
|
import { Auth } from "../../auth/index.js";
|
|
5
5
|
import { Config } from "../../config/index.js";
|
package/node/util/loader.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Context } from "../../context/
|
|
2
|
-
const LoaderContext = Context.
|
|
1
|
+
import { Context } from "../../context/context2.js";
|
|
2
|
+
const LoaderContext = Context.memo(() => {
|
|
3
3
|
const loaders = new Map();
|
|
4
4
|
return loaders;
|
|
5
|
-
}
|
|
5
|
+
});
|
|
6
6
|
export function createLoader(batchFn) {
|
|
7
7
|
let current;
|
|
8
8
|
async function run() {
|
|
@@ -41,7 +41,7 @@ export function createLoader(batchFn) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
export function useLoader(key, batchFn) {
|
|
44
|
-
const loaders = LoaderContext
|
|
44
|
+
const loaders = LoaderContext();
|
|
45
45
|
if (loaders.has(key)) {
|
|
46
46
|
return loaders.get(key);
|
|
47
47
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sideEffects": false,
|
|
3
3
|
"name": "sst",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.26.1",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sst": "cli/sst.js"
|
|
7
7
|
},
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
"@aws-cdk/cloudformation-diff": "2.95.1",
|
|
33
33
|
"@aws-cdk/cx-api": "2.95.1",
|
|
34
34
|
"@aws-crypto/sha256-js": "^5.0.0",
|
|
35
|
-
"@aws-sdk/client-cloudformation": "^3.
|
|
36
|
-
"@aws-sdk/client-ecs": "^3.
|
|
37
|
-
"@aws-sdk/client-eventbridge": "^3.
|
|
38
|
-
"@aws-sdk/client-iam": "^3.
|
|
39
|
-
"@aws-sdk/client-iot": "^3.
|
|
40
|
-
"@aws-sdk/client-iot-data-plane": "^3.
|
|
41
|
-
"@aws-sdk/client-lambda": "^3.
|
|
42
|
-
"@aws-sdk/client-rds-data": "^3.
|
|
43
|
-
"@aws-sdk/client-s3": "^3.
|
|
44
|
-
"@aws-sdk/client-ssm": "^3.
|
|
45
|
-
"@aws-sdk/client-sts": "^3.
|
|
46
|
-
"@aws-sdk/config-resolver": "^3.
|
|
47
|
-
"@aws-sdk/credential-providers": "^3.
|
|
48
|
-
"@aws-sdk/middleware-retry": "^3.
|
|
49
|
-
"@aws-sdk/middleware-signing": "^3.
|
|
50
|
-
"@aws-sdk/signature-v4-crt": "^3.
|
|
51
|
-
"@aws-sdk/smithy-client": "^3.
|
|
35
|
+
"@aws-sdk/client-cloudformation": "^3.405.0",
|
|
36
|
+
"@aws-sdk/client-ecs": "^3.405.0",
|
|
37
|
+
"@aws-sdk/client-eventbridge": "^3.405.0",
|
|
38
|
+
"@aws-sdk/client-iam": "^3.405.0",
|
|
39
|
+
"@aws-sdk/client-iot": "^3.405.0",
|
|
40
|
+
"@aws-sdk/client-iot-data-plane": "^3.405.0",
|
|
41
|
+
"@aws-sdk/client-lambda": "^3.405.0",
|
|
42
|
+
"@aws-sdk/client-rds-data": "^3.405.0",
|
|
43
|
+
"@aws-sdk/client-s3": "^3.405.0",
|
|
44
|
+
"@aws-sdk/client-ssm": "^3.405.0",
|
|
45
|
+
"@aws-sdk/client-sts": "^3.405.0",
|
|
46
|
+
"@aws-sdk/config-resolver": "^3.374.0",
|
|
47
|
+
"@aws-sdk/credential-providers": "^3.405.0",
|
|
48
|
+
"@aws-sdk/middleware-retry": "^3.374.0",
|
|
49
|
+
"@aws-sdk/middleware-signing": "^3.398.0",
|
|
50
|
+
"@aws-sdk/signature-v4-crt": "^3.398.0",
|
|
51
|
+
"@aws-sdk/smithy-client": "^3.374.0",
|
|
52
52
|
"@babel/core": "^7.0.0-0",
|
|
53
53
|
"@babel/generator": "^7.20.5",
|
|
54
54
|
"@babel/plugin-syntax-typescript": "^7.21.4",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"@aws-sdk/types": "^3.272.0",
|
|
104
104
|
"@graphql-tools/merge": "^8.3.16",
|
|
105
105
|
"@sls-next/lambda-at-edge": "^3.7.0",
|
|
106
|
+
"@smithy/types": "^2.2.2",
|
|
106
107
|
"@tsconfig/node16": "^1.0.3",
|
|
107
108
|
"@types/adm-zip": "^0.5.0",
|
|
108
109
|
"@types/aws-iot-device-sdk": "^2.2.4",
|
|
@@ -119,7 +120,7 @@
|
|
|
119
120
|
"@types/yargs": "^17.0.13",
|
|
120
121
|
"archiver": "^5.3.1",
|
|
121
122
|
"tsx": "^3.12.1",
|
|
122
|
-
"typescript": "^
|
|
123
|
+
"typescript": "^5.2.2",
|
|
123
124
|
"vitest": "^0.33.0"
|
|
124
125
|
},
|
|
125
126
|
"peerDependencies": {
|
package/project.d.ts
CHANGED
|
@@ -57,11 +57,6 @@ interface Project {
|
|
|
57
57
|
metafile: Metafile;
|
|
58
58
|
stacks: SSTConfig["stacks"];
|
|
59
59
|
}
|
|
60
|
-
export declare const ProjectContext: {
|
|
61
|
-
use(): Project;
|
|
62
|
-
reset(): void;
|
|
63
|
-
provide(value: Project): void;
|
|
64
|
-
};
|
|
65
60
|
export declare function useProject(): Project;
|
|
66
61
|
interface GlobalOptions {
|
|
67
62
|
profile?: string;
|
package/project.js
CHANGED
|
@@ -4,7 +4,6 @@ import path from "path";
|
|
|
4
4
|
import url from "url";
|
|
5
5
|
import os from "os";
|
|
6
6
|
import { Logger } from "./logger.js";
|
|
7
|
-
import { Context } from "./context/context.js";
|
|
8
7
|
import { VisibleError } from "./error.js";
|
|
9
8
|
import { blue } from "colorette";
|
|
10
9
|
import dotenv from "dotenv";
|
|
@@ -13,9 +12,11 @@ const DEFAULTS = {
|
|
|
13
12
|
stage: undefined,
|
|
14
13
|
ssmPrefix: undefined,
|
|
15
14
|
};
|
|
16
|
-
|
|
15
|
+
let project;
|
|
17
16
|
export function useProject() {
|
|
18
|
-
|
|
17
|
+
if (!project)
|
|
18
|
+
throw new Error("Project not initialized");
|
|
19
|
+
return project;
|
|
19
20
|
}
|
|
20
21
|
const CONFIG_EXTENSIONS = [
|
|
21
22
|
".config.ts",
|
|
@@ -73,7 +74,7 @@ export async function initProject(globals) {
|
|
|
73
74
|
return ["unknown", "unknown"];
|
|
74
75
|
}
|
|
75
76
|
})();
|
|
76
|
-
|
|
77
|
+
project = {
|
|
77
78
|
version,
|
|
78
79
|
cdkVersion,
|
|
79
80
|
constructsVersion,
|
|
@@ -98,7 +99,6 @@ export async function initProject(globals) {
|
|
|
98
99
|
artifacts: path.join(out, "artifacts"),
|
|
99
100
|
},
|
|
100
101
|
};
|
|
101
|
-
ProjectContext.provide(project);
|
|
102
102
|
// Cleanup old config files
|
|
103
103
|
(async function () {
|
|
104
104
|
const files = await fs.readdir(project.paths.root);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { useRuntimeWorkers } from "../workers.js";
|
|
3
|
-
import {
|
|
4
|
-
import { promisify } from "util";
|
|
3
|
+
import { spawn } from "child_process";
|
|
5
4
|
import { useRuntimeServerConfig } from "../server.js";
|
|
6
5
|
import { findAbove, isChild } from "../../util/fs.js";
|
|
7
6
|
import { Runtime } from "aws-cdk-lib/aws-lambda";
|
|
8
7
|
import { bundle } from "./pythonBundling.js";
|
|
9
|
-
const execAsync = promisify(exec);
|
|
10
8
|
import os from "os";
|
|
11
9
|
import url from "url";
|
|
12
10
|
const RUNTIME_MAP = {
|
package/runtime/handlers.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Context } from "../context/context.js";
|
|
2
1
|
import { Logger } from "../logger.js";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import fs from "fs/promises";
|
|
@@ -13,7 +12,8 @@ import { useGoHandler } from "./handlers/go.js";
|
|
|
13
12
|
import { useJavaHandler } from "./handlers/java.js";
|
|
14
13
|
import { usePythonHandler } from "./handlers/python.js";
|
|
15
14
|
import { useRustHandler } from "./handlers/rust.js";
|
|
16
|
-
|
|
15
|
+
import { lazy } from "../util/lazy.js";
|
|
16
|
+
export const useRuntimeHandlers = lazy(() => {
|
|
17
17
|
const handlers = [
|
|
18
18
|
useNodeHandler(),
|
|
19
19
|
useGoHandler(),
|
|
@@ -111,7 +111,7 @@ export const useRuntimeHandlers = Context.memo(() => {
|
|
|
111
111
|
};
|
|
112
112
|
return result;
|
|
113
113
|
});
|
|
114
|
-
export const useFunctionBuilder =
|
|
114
|
+
export const useFunctionBuilder = lazy(() => {
|
|
115
115
|
const artifacts = new Map();
|
|
116
116
|
const handlers = useRuntimeHandlers();
|
|
117
117
|
const result = {
|
package/runtime/iot.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Context } from "../context/context.js";
|
|
2
1
|
import { useBus } from "../bus.js";
|
|
3
2
|
import { useIOT } from "../iot.js";
|
|
4
|
-
|
|
3
|
+
import { lazy } from "../util/lazy.js";
|
|
4
|
+
export const useIOTBridge = lazy(async () => {
|
|
5
5
|
const bus = useBus();
|
|
6
6
|
const iot = await useIOT();
|
|
7
7
|
const topic = `${iot.prefix}/events`;
|
package/runtime/server.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Context } from "../context/context.js";
|
|
2
1
|
import express from "express";
|
|
3
2
|
import { useBus } from "../bus.js";
|
|
4
3
|
import { Logger } from "../logger.js";
|
|
5
4
|
import { useRuntimeWorkers } from "./workers.js";
|
|
6
5
|
import https from "https";
|
|
7
6
|
import getPort from "get-port";
|
|
8
|
-
|
|
7
|
+
import { lazy } from "../util/lazy.js";
|
|
8
|
+
export const useRuntimeServerConfig = lazy(async () => {
|
|
9
9
|
const port = await getPort({
|
|
10
10
|
port: 12557,
|
|
11
11
|
});
|
|
@@ -15,7 +15,7 @@ export const useRuntimeServerConfig = Context.memo(async () => {
|
|
|
15
15
|
url: `http://localhost:${port}`,
|
|
16
16
|
};
|
|
17
17
|
});
|
|
18
|
-
export const useRuntimeServer =
|
|
18
|
+
export const useRuntimeServer = lazy(async () => {
|
|
19
19
|
const bus = useBus();
|
|
20
20
|
const app = express();
|
|
21
21
|
const workers = await useRuntimeWorkers();
|
package/runtime/workers.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Context } from "../context/context.js";
|
|
2
1
|
import { useBus } from "../bus.js";
|
|
3
2
|
import { useFunctionBuilder, useRuntimeHandlers } from "./handlers.js";
|
|
4
3
|
import { useRuntimeServerConfig } from "./server.js";
|
|
5
4
|
import { useFunctions } from "../constructs/Function.js";
|
|
6
|
-
|
|
5
|
+
import { lazy } from "../util/lazy.js";
|
|
6
|
+
export const useRuntimeWorkers = lazy(async () => {
|
|
7
7
|
const workers = new Map();
|
|
8
8
|
const bus = useBus();
|
|
9
9
|
const handlers = useRuntimeHandlers();
|
package/stacks/app-metadata.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useBootstrap } from "../bootstrap.js";
|
|
2
2
|
import { useAWSCredentials } from "../credentials.js";
|
|
3
3
|
import { S3Client, GetObjectCommand, PutObjectCommand, DeleteObjectCommand, } from "@aws-sdk/client-s3";
|
|
4
|
-
import { Context } from "../context/context.js";
|
|
5
4
|
import { Logger } from "../logger.js";
|
|
6
5
|
import { useProject } from "../project.js";
|
|
6
|
+
import { lazy } from "../util/lazy.js";
|
|
7
7
|
async function metadata() {
|
|
8
8
|
Logger.debug("Fetching app metadata");
|
|
9
9
|
const [project, credentials, bootstrap] = await Promise.all([
|
|
@@ -69,8 +69,7 @@ function useS3Key() {
|
|
|
69
69
|
const project = useProject();
|
|
70
70
|
return `appMetadata/app.${project.config.name}/stage.${project.config.stage}.json`;
|
|
71
71
|
}
|
|
72
|
-
const
|
|
72
|
+
export const useAppMetadata = lazy(async () => {
|
|
73
73
|
const data = await metadata();
|
|
74
74
|
return data;
|
|
75
75
|
});
|
|
76
|
-
export const useAppMetadata = MetadataContext.use;
|
package/stacks/metadata.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ declare module "../bus.js" {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function metadataForStack(stack: String): Promise<Metadata[] | undefined>;
|
|
10
10
|
export declare function metadata(): Promise<Record<string, Metadata[]>>;
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const useMetadataCache: () => Promise<Record<string, Metadata[]>>;
|
package/stacks/metadata.js
CHANGED
|
@@ -2,10 +2,10 @@ import { useBootstrap } from "../bootstrap.js";
|
|
|
2
2
|
import { useAWSCredentials, } from "../credentials.js";
|
|
3
3
|
import { S3Client, GetObjectCommand, ListObjectsV2Command, } from "@aws-sdk/client-s3";
|
|
4
4
|
import { useCache } from "../cache.js";
|
|
5
|
-
import { Context } from "../context/context.js";
|
|
6
5
|
import { useBus } from "../bus.js";
|
|
7
6
|
import { Logger } from "../logger.js";
|
|
8
7
|
import { useProject } from "../project.js";
|
|
8
|
+
import { lazy } from "../util/lazy.js";
|
|
9
9
|
export async function metadataForStack(stack) {
|
|
10
10
|
const project = useProject();
|
|
11
11
|
const [credentials, bootstrap] = await Promise.all([
|
|
@@ -57,20 +57,18 @@ export async function metadata() {
|
|
|
57
57
|
Logger.debug("Fetched metadata from", list.KeyCount, "stacks");
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
|
-
const
|
|
60
|
+
export const useMetadataCache = lazy(async () => {
|
|
61
61
|
const bus = useBus();
|
|
62
62
|
const cache = await useCache();
|
|
63
63
|
bus.subscribe("stacks.metadata.updated", async () => {
|
|
64
64
|
const data = await metadata();
|
|
65
65
|
await cache.write(`metadata.json`, JSON.stringify(data));
|
|
66
66
|
bus.publish("stacks.metadata", data);
|
|
67
|
-
MetadataContext.provide(Promise.resolve(data));
|
|
68
67
|
});
|
|
69
68
|
bus.subscribe("stacks.metadata.deleted", async () => {
|
|
70
69
|
const data = await metadata();
|
|
71
70
|
await cache.write(`metadata.json`, JSON.stringify(data));
|
|
72
71
|
bus.publish("stacks.metadata", data);
|
|
73
|
-
MetadataContext.provide(Promise.resolve(data));
|
|
74
72
|
});
|
|
75
73
|
while (true) {
|
|
76
74
|
try {
|
|
@@ -83,4 +81,3 @@ const MetadataContext = Context.create(async () => {
|
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
83
|
});
|
|
86
|
-
export const useMetadata = MetadataContext.use;
|