sst 2.4.0 → 2.4.2
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/cli/commands/bind.js +61 -48
- package/cli/commands/plugins/kysely.js +12 -4
- package/constructs/NextjsSite.js +1 -1
- package/node/actor/index.d.ts +29 -0
- package/node/actor/index.js +17 -0
- package/node/util/index.js +12 -1
- package/package.json +1 -1
- package/runtime/handlers/go.js +7 -4
- package/sst.mjs +95 -70
- package/support/bootstrap-metadata-function/index.mjs +238 -238
- package/support/custom-resources/index.mjs +238 -238
- package/util/error.d.ts +3 -0
- package/util/error.js +6 -0
package/sst.mjs
CHANGED
|
@@ -4327,6 +4327,7 @@ __export(go_exports, {
|
|
|
4327
4327
|
});
|
|
4328
4328
|
import path9 from "path";
|
|
4329
4329
|
import fs9 from "fs/promises";
|
|
4330
|
+
import os3 from "os";
|
|
4330
4331
|
import { spawn as spawn2 } from "child_process";
|
|
4331
4332
|
async function find(dir, target) {
|
|
4332
4333
|
if (dir === "/")
|
|
@@ -4395,8 +4396,9 @@ var init_go = __esm({
|
|
|
4395
4396
|
if (input.mode === "start") {
|
|
4396
4397
|
try {
|
|
4397
4398
|
const target = path9.join(input.out, handlerName);
|
|
4399
|
+
const srcPath = os3.platform() === "win32" ? src.replaceAll("\\", "\\\\") : src;
|
|
4398
4400
|
const result = await execAsync(
|
|
4399
|
-
`go build -ldflags
|
|
4401
|
+
`go build -ldflags "-s -w" -o "${target}" ./${srcPath}`,
|
|
4400
4402
|
{
|
|
4401
4403
|
cwd: project,
|
|
4402
4404
|
env: {
|
|
@@ -4411,17 +4413,21 @@ var init_go = __esm({
|
|
|
4411
4413
|
if (input.mode === "deploy") {
|
|
4412
4414
|
try {
|
|
4413
4415
|
const target = path9.join(input.out, "bootstrap");
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4416
|
+
const srcPath = os3.platform() === "win32" ? src.replaceAll("\\", "\\\\") : src;
|
|
4417
|
+
await execAsync(
|
|
4418
|
+
`go build -ldflags "-s -w" -o "${target}" ./${srcPath}`,
|
|
4419
|
+
{
|
|
4420
|
+
cwd: project,
|
|
4421
|
+
env: {
|
|
4422
|
+
...process.env,
|
|
4423
|
+
CGO_ENABLED: "0",
|
|
4424
|
+
GOARCH: input.props.architecture === "arm_64" ? "arm64" : "amd64",
|
|
4425
|
+
GOOS: "linux"
|
|
4426
|
+
}
|
|
4421
4427
|
}
|
|
4422
|
-
|
|
4423
|
-
} catch {
|
|
4424
|
-
throw new VisibleError(
|
|
4428
|
+
);
|
|
4429
|
+
} catch (ex) {
|
|
4430
|
+
throw new VisibleError(`Failed to build ${ex}`);
|
|
4425
4431
|
}
|
|
4426
4432
|
}
|
|
4427
4433
|
return {
|
|
@@ -4627,7 +4633,7 @@ import path12 from "path";
|
|
|
4627
4633
|
import { exec as exec5, spawn as spawn4 } from "child_process";
|
|
4628
4634
|
import { promisify as promisify3 } from "util";
|
|
4629
4635
|
import { Runtime } from "aws-cdk-lib/aws-lambda";
|
|
4630
|
-
import
|
|
4636
|
+
import os4 from "os";
|
|
4631
4637
|
import url6 from "url";
|
|
4632
4638
|
var execAsync3, RUNTIME_MAP, usePythonHandler;
|
|
4633
4639
|
var init_python = __esm({
|
|
@@ -4676,7 +4682,7 @@ var init_python = __esm({
|
|
|
4676
4682
|
const parsed = path12.parse(path12.relative(src, input.handler));
|
|
4677
4683
|
const target = [...parsed.dir.split(path12.sep), parsed.name].join(".");
|
|
4678
4684
|
const proc = spawn4(
|
|
4679
|
-
|
|
4685
|
+
os4.platform() === "win32" ? "python.exe" : "python3",
|
|
4680
4686
|
[
|
|
4681
4687
|
"-u",
|
|
4682
4688
|
url6.fileURLToPath(
|
|
@@ -4750,7 +4756,7 @@ __export(java_exports, {
|
|
|
4750
4756
|
});
|
|
4751
4757
|
import path13 from "path";
|
|
4752
4758
|
import fs12 from "fs/promises";
|
|
4753
|
-
import
|
|
4759
|
+
import os5 from "os";
|
|
4754
4760
|
import zipLocal from "zip-local";
|
|
4755
4761
|
import { spawn as spawn5 } from "child_process";
|
|
4756
4762
|
import url7 from "url";
|
|
@@ -4795,7 +4801,7 @@ var init_java = __esm({
|
|
|
4795
4801
|
url7.fileURLToPath(
|
|
4796
4802
|
new URL("../../support/java-runtime/release/*", import.meta.url)
|
|
4797
4803
|
)
|
|
4798
|
-
].join(
|
|
4804
|
+
].join(os5.platform() === "win32" ? ";" : ":"),
|
|
4799
4805
|
"com.amazonaws.services.lambda.runtime.api.client.AWSLambda",
|
|
4800
4806
|
input.handler
|
|
4801
4807
|
],
|
|
@@ -6301,10 +6307,11 @@ var init_kysely = __esm({
|
|
|
6301
6307
|
useKyselyTypeGenerator = Context.memo(async () => {
|
|
6302
6308
|
let databases = [];
|
|
6303
6309
|
const bus = useBus();
|
|
6310
|
+
const logger = Logger.debug.bind(null, "[kysely-codegen]");
|
|
6304
6311
|
async function generate2(db) {
|
|
6305
6312
|
if (!db.types)
|
|
6306
6313
|
return;
|
|
6307
|
-
|
|
6314
|
+
logger("generating types for", db.migratorID);
|
|
6308
6315
|
const k = new Kysely({
|
|
6309
6316
|
dialect: new DataApiDialect({
|
|
6310
6317
|
mode: db.engine.includes("postgres") ? "postgres" : "mysql",
|
|
@@ -6317,6 +6324,7 @@ var init_kysely = __esm({
|
|
|
6317
6324
|
})
|
|
6318
6325
|
});
|
|
6319
6326
|
const tables = await k.introspection.getTables();
|
|
6327
|
+
logger("introspected tables");
|
|
6320
6328
|
const metadata3 = db.engine.includes("postgres") ? tables.map((table) => ({
|
|
6321
6329
|
...table,
|
|
6322
6330
|
columns: table.columns.map((column) => {
|
|
@@ -6335,6 +6343,7 @@ var init_kysely = __esm({
|
|
|
6335
6343
|
enumValues: null
|
|
6336
6344
|
}))
|
|
6337
6345
|
}));
|
|
6346
|
+
logger("generated metadata", metadata3.length);
|
|
6338
6347
|
const transformer = new Transformer();
|
|
6339
6348
|
const Dialect = db.engine.includes("postgres") ? new PostgresDialect() : new MysqlDialect();
|
|
6340
6349
|
const nodes = transformer.transform({
|
|
@@ -6342,6 +6351,7 @@ var init_kysely = __esm({
|
|
|
6342
6351
|
camelCase: db.types.camelCase === true,
|
|
6343
6352
|
metadata: new DatabaseMetadata(metadata3, new EnumCollection())
|
|
6344
6353
|
});
|
|
6354
|
+
logger("transformed nodes", nodes.length);
|
|
6345
6355
|
const lastIndex = nodes.length - 1;
|
|
6346
6356
|
const last2 = nodes[lastIndex];
|
|
6347
6357
|
nodes[lastIndex] = {
|
|
@@ -6367,8 +6377,11 @@ var init_kysely = __esm({
|
|
|
6367
6377
|
defaultDatabaseName: c.data.defaultDatabaseName,
|
|
6368
6378
|
secretArn: c.data.secretArn
|
|
6369
6379
|
}));
|
|
6370
|
-
databases.map(
|
|
6371
|
-
|
|
6380
|
+
databases.map(
|
|
6381
|
+
(db) => generate2(db).catch((err) => {
|
|
6382
|
+
logger(err);
|
|
6383
|
+
})
|
|
6384
|
+
);
|
|
6372
6385
|
});
|
|
6373
6386
|
bus.subscribe("function.success", async (evt) => {
|
|
6374
6387
|
if (!evt.properties.body?.results)
|
|
@@ -6378,10 +6391,11 @@ var init_kysely = __esm({
|
|
|
6378
6391
|
);
|
|
6379
6392
|
if (!db)
|
|
6380
6393
|
return;
|
|
6381
|
-
generate2(db).catch(() => {
|
|
6394
|
+
generate2(db).catch((err) => {
|
|
6395
|
+
logger(err);
|
|
6382
6396
|
});
|
|
6383
6397
|
});
|
|
6384
|
-
|
|
6398
|
+
logger("Loaded kyseley type generator");
|
|
6385
6399
|
});
|
|
6386
6400
|
}
|
|
6387
6401
|
});
|
|
@@ -7077,12 +7091,11 @@ Are you sure you want to run this stage in dev mode? [y/N] `,
|
|
|
7077
7091
|
// src/cli/commands/bind.ts
|
|
7078
7092
|
init_error();
|
|
7079
7093
|
import path18 from "path";
|
|
7080
|
-
var
|
|
7094
|
+
var SSR_SITE_CONFIG = {
|
|
7081
7095
|
NextjsSite: "next.config",
|
|
7082
7096
|
AstroSite: "astro.config",
|
|
7083
7097
|
RemixSite: "remix.config",
|
|
7084
7098
|
SolidStartSite: "vite.config",
|
|
7085
|
-
StaticSite: "vite.config",
|
|
7086
7099
|
SlsNextjsSite: "next.config"
|
|
7087
7100
|
};
|
|
7088
7101
|
var bind = (program2) => program2.command(
|
|
@@ -7098,6 +7111,7 @@ var bind = (program2) => program2.command(
|
|
|
7098
7111
|
const { useBus: useBus2 } = await Promise.resolve().then(() => (init_bus(), bus_exports));
|
|
7099
7112
|
const { useIOT: useIOT2 } = await Promise.resolve().then(() => (init_iot(), iot_exports));
|
|
7100
7113
|
const { Colors: Colors2 } = await Promise.resolve().then(() => (init_colors(), colors_exports));
|
|
7114
|
+
const { Logger: Logger2 } = await Promise.resolve().then(() => (init_logger(), logger_exports));
|
|
7101
7115
|
if (args._[0] === "env") {
|
|
7102
7116
|
Colors2.line(
|
|
7103
7117
|
Colors2.warning(
|
|
@@ -7111,17 +7125,18 @@ var bind = (program2) => program2.command(
|
|
|
7111
7125
|
const bus = useBus2();
|
|
7112
7126
|
const project = useProject2();
|
|
7113
7127
|
const command = args.command?.join(" ");
|
|
7114
|
-
const
|
|
7128
|
+
const isSsrSite = await isRunningInSsrSite();
|
|
7115
7129
|
let p;
|
|
7116
7130
|
let timer;
|
|
7117
|
-
let
|
|
7131
|
+
let siteConfigCache;
|
|
7118
7132
|
if (!command) {
|
|
7119
7133
|
throw new VisibleError(
|
|
7120
|
-
`Command is required, e.g. sst bind ${
|
|
7134
|
+
`Command is required, e.g. sst bind ${isSsrSite ? "next dev" : "env"}`
|
|
7121
7135
|
);
|
|
7122
7136
|
}
|
|
7123
7137
|
const initialMetadata = await getSiteMetadata();
|
|
7124
|
-
if (!initialMetadata) {
|
|
7138
|
+
if (!initialMetadata && !isSsrSite) {
|
|
7139
|
+
Logger2.debug("Running in script mode.");
|
|
7125
7140
|
return await bindScript();
|
|
7126
7141
|
}
|
|
7127
7142
|
await bindSite("init");
|
|
@@ -7135,9 +7150,9 @@ var bind = (program2) => program2.command(
|
|
|
7135
7150
|
);
|
|
7136
7151
|
bus.subscribe("config.secret.updated", (payload) => {
|
|
7137
7152
|
const secretName = payload.properties.name;
|
|
7138
|
-
if (
|
|
7153
|
+
if (siteConfigCache?.secrets === void 0)
|
|
7139
7154
|
return;
|
|
7140
|
-
if (!
|
|
7155
|
+
if (!siteConfigCache.secrets.includes(secretName))
|
|
7141
7156
|
return;
|
|
7142
7157
|
Colors2.line(
|
|
7143
7158
|
`
|
|
@@ -7146,21 +7161,28 @@ var bind = (program2) => program2.command(
|
|
|
7146
7161
|
);
|
|
7147
7162
|
bindSite("secrets_updated");
|
|
7148
7163
|
});
|
|
7149
|
-
async function
|
|
7164
|
+
async function isRunningInSsrSite() {
|
|
7150
7165
|
const { existsAsync: existsAsync3 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
7166
|
+
const { readFile } = await import("fs/promises");
|
|
7151
7167
|
const results = await Promise.all(
|
|
7152
|
-
Object.values(
|
|
7153
|
-
(config) => [".js", ".cjs", ".mjs", ".ts"].map(
|
|
7154
|
-
|
|
7155
|
-
|
|
7168
|
+
Object.values(SSR_SITE_CONFIG).map(
|
|
7169
|
+
(config) => [".js", ".cjs", ".mjs", ".ts"].map(async (ext) => {
|
|
7170
|
+
const exists = await existsAsync3(`${config}${ext}`);
|
|
7171
|
+
if (exists && config === "vite.config") {
|
|
7172
|
+
const content = await readFile(`${config}${ext}`);
|
|
7173
|
+
return content.includes("solid-start");
|
|
7174
|
+
}
|
|
7175
|
+
return exists;
|
|
7176
|
+
})
|
|
7156
7177
|
).flat()
|
|
7157
7178
|
);
|
|
7158
7179
|
return results.some(Boolean);
|
|
7159
7180
|
}
|
|
7160
7181
|
async function bindSite(reason) {
|
|
7161
|
-
const
|
|
7182
|
+
const siteMetadata = reason === "init" ? initialMetadata : await getSiteMetadataUntilAvailable();
|
|
7183
|
+
const siteConfig = await parseSiteConfig(siteMetadata);
|
|
7162
7184
|
if (reason === "metadata_updated") {
|
|
7163
|
-
if (areEnvsSame(
|
|
7185
|
+
if (areEnvsSame(siteConfig.envs, siteConfigCache?.envs || {}))
|
|
7164
7186
|
return;
|
|
7165
7187
|
Colors2.line(
|
|
7166
7188
|
`
|
|
@@ -7168,9 +7190,9 @@ var bind = (program2) => program2.command(
|
|
|
7168
7190
|
`SST resources have been updated. Restarting \`${command}\`...`
|
|
7169
7191
|
);
|
|
7170
7192
|
}
|
|
7171
|
-
|
|
7172
|
-
if (
|
|
7173
|
-
const credentials = await assumeSsrRole(
|
|
7193
|
+
siteConfigCache = siteConfig;
|
|
7194
|
+
if (siteConfig.role) {
|
|
7195
|
+
const credentials = await assumeSsrRole(siteConfig.role);
|
|
7174
7196
|
if (credentials) {
|
|
7175
7197
|
const expireAt = credentials.Expiration.getTime() - 6e4;
|
|
7176
7198
|
clearTimeout(timer);
|
|
@@ -7183,7 +7205,7 @@ var bind = (program2) => program2.command(
|
|
|
7183
7205
|
bindSite("iam_expired");
|
|
7184
7206
|
}, expireAt - Date.now());
|
|
7185
7207
|
runCommand({
|
|
7186
|
-
...
|
|
7208
|
+
...siteConfig.envs,
|
|
7187
7209
|
AWS_ACCESS_KEY_ID: credentials.AccessKeyId,
|
|
7188
7210
|
AWS_SECRET_ACCESS_KEY: credentials.SecretAccessKey,
|
|
7189
7211
|
AWS_SESSION_TOKEN: credentials.SessionToken
|
|
@@ -7192,7 +7214,7 @@ var bind = (program2) => program2.command(
|
|
|
7192
7214
|
}
|
|
7193
7215
|
}
|
|
7194
7216
|
runCommand({
|
|
7195
|
-
...
|
|
7217
|
+
...siteConfig.envs,
|
|
7196
7218
|
...await localIamCredentials()
|
|
7197
7219
|
});
|
|
7198
7220
|
}
|
|
@@ -7203,22 +7225,30 @@ var bind = (program2) => program2.command(
|
|
|
7203
7225
|
...await localIamCredentials()
|
|
7204
7226
|
});
|
|
7205
7227
|
}
|
|
7206
|
-
async function
|
|
7207
|
-
const { metadata: metadata3 } = await Promise.resolve().then(() => (init_metadata(), metadata_exports));
|
|
7208
|
-
const { createSpinner: createSpinner2 } = await Promise.resolve().then(() => (init_spinner(), spinner_exports));
|
|
7228
|
+
async function parseSiteConfig(metadata3) {
|
|
7209
7229
|
const { LambdaClient: LambdaClient2, GetFunctionCommand } = await import("@aws-sdk/client-lambda");
|
|
7210
7230
|
const { useAWSClient: useAWSClient2 } = await Promise.resolve().then(() => (init_credentials(), credentials_exports));
|
|
7231
|
+
const isBindSupported = metadata3.type !== "StaticSite" && metadata3.type !== "SlsNextjsSite";
|
|
7232
|
+
if (!isBindSupported) {
|
|
7233
|
+
return { envs: metadata3.data.environment };
|
|
7234
|
+
}
|
|
7235
|
+
const lambda = useAWSClient2(LambdaClient2);
|
|
7236
|
+
const { Configuration: functionConfig } = await lambda.send(
|
|
7237
|
+
new GetFunctionCommand({
|
|
7238
|
+
FunctionName: metadata3.data.server
|
|
7239
|
+
})
|
|
7240
|
+
);
|
|
7241
|
+
return {
|
|
7242
|
+
role: functionConfig?.Role,
|
|
7243
|
+
envs: functionConfig?.Environment?.Variables || {},
|
|
7244
|
+
secrets: metadata3.data.secrets
|
|
7245
|
+
};
|
|
7246
|
+
}
|
|
7247
|
+
async function getSiteMetadataUntilAvailable() {
|
|
7248
|
+
const { createSpinner: createSpinner2 } = await Promise.resolve().then(() => (init_spinner(), spinner_exports));
|
|
7211
7249
|
const spinner = createSpinner2({});
|
|
7212
7250
|
while (true) {
|
|
7213
|
-
const
|
|
7214
|
-
const data2 = Object.values(metadataData).flat().filter(
|
|
7215
|
-
(c) => Boolean(c)
|
|
7216
|
-
).filter((c) => Boolean(SITE_CONFIG[c.type])).find(
|
|
7217
|
-
(c) => path18.resolve(project.paths.root, c.data.path) === process.cwd()
|
|
7218
|
-
);
|
|
7219
|
-
if (!data2 && !isFrontend) {
|
|
7220
|
-
return;
|
|
7221
|
-
}
|
|
7251
|
+
const data2 = await getSiteMetadata();
|
|
7222
7252
|
if (!data2) {
|
|
7223
7253
|
spinner.start(
|
|
7224
7254
|
"Make sure `sst dev` is running..."
|
|
@@ -7235,25 +7265,22 @@ var bind = (program2) => program2.command(
|
|
|
7235
7265
|
continue;
|
|
7236
7266
|
}
|
|
7237
7267
|
spinner.isSpinning && spinner.stop().clear();
|
|
7238
|
-
|
|
7239
|
-
return { envs: data2.data.environment };
|
|
7240
|
-
}
|
|
7241
|
-
const lambda = useAWSClient2(LambdaClient2);
|
|
7242
|
-
const { Configuration: functionConfig } = await lambda.send(
|
|
7243
|
-
new GetFunctionCommand({
|
|
7244
|
-
FunctionName: data2.data.server
|
|
7245
|
-
})
|
|
7246
|
-
);
|
|
7247
|
-
return {
|
|
7248
|
-
role: functionConfig?.Role,
|
|
7249
|
-
envs: functionConfig?.Environment?.Variables || {},
|
|
7250
|
-
secrets: data2.data.secrets
|
|
7251
|
-
};
|
|
7268
|
+
return data2;
|
|
7252
7269
|
}
|
|
7253
7270
|
}
|
|
7271
|
+
async function getSiteMetadata() {
|
|
7272
|
+
const { metadata: metadata3 } = await Promise.resolve().then(() => (init_metadata(), metadata_exports));
|
|
7273
|
+
const metadataData = await metadata3();
|
|
7274
|
+
return Object.values(metadataData).flat().filter(
|
|
7275
|
+
(c) => Boolean(c)
|
|
7276
|
+
).filter(
|
|
7277
|
+
(c) => c.type === "StaticSite" || Boolean(SSR_SITE_CONFIG[c.type])
|
|
7278
|
+
).find(
|
|
7279
|
+
(c) => path18.resolve(project.paths.root, c.data.path) === process.cwd()
|
|
7280
|
+
);
|
|
7281
|
+
}
|
|
7254
7282
|
async function assumeSsrRole(roleArn) {
|
|
7255
7283
|
const { STSClient: STSClient2, AssumeRoleCommand } = await import("@aws-sdk/client-sts");
|
|
7256
|
-
const { Logger: Logger2 } = await Promise.resolve().then(() => (init_logger(), logger_exports));
|
|
7257
7284
|
const { useAWSClient: useAWSClient2 } = await Promise.resolve().then(() => (init_credentials(), credentials_exports));
|
|
7258
7285
|
const sts = useAWSClient2(STSClient2);
|
|
7259
7286
|
const assumeRole = async (duration) => {
|
|
@@ -7280,9 +7307,7 @@ var bind = (program2) => program2.command(
|
|
|
7280
7307
|
}
|
|
7281
7308
|
}
|
|
7282
7309
|
Colors2.line(
|
|
7283
|
-
|
|
7284
|
-
`Failed to assume SSR role ${roleArn}. Falling back to using local IAM credentials.`
|
|
7285
|
-
)
|
|
7310
|
+
"Using local IAM credentials since `sst dev` is not running."
|
|
7286
7311
|
);
|
|
7287
7312
|
Logger2.debug(`Failed to assume ${roleArn}.`, err);
|
|
7288
7313
|
}
|