sst 2.0.0-rc.21 → 2.0.0-rc.23

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.
@@ -9,6 +9,7 @@ import { usePothosBuilder } from "./plugins/pothos.js";
9
9
  import { useKyselyTypeGenerator } from "./plugins/kysely.js";
10
10
  import { useRDSWarmer } from "./plugins/warmer.js";
11
11
  import { useProject } from "../../project.js";
12
+ import { useMetadata } from "../../stacks/metadata.js";
12
13
  export const dev = (program) => program.command(["start", "dev"], "Work on your SST app locally", (yargs) => yargs.option("fullscreen", {
13
14
  type: "boolean",
14
15
  describe: "Disable full screen UI",
@@ -178,6 +179,7 @@ export const dev = (program) => program.command(["start", "dev"], "Work on your
178
179
  useIOTBridge(),
179
180
  useRuntimeServer(),
180
181
  usePothosBuilder(),
182
+ useMetadata(),
181
183
  useKyselyTypeGenerator(),
182
184
  useRDSWarmer(),
183
185
  useFunctionLogger(),
@@ -1,7 +1,6 @@
1
1
  import { useProject } from "../../project.js";
2
2
  import { createSpinner } from "../spinner.js";
3
3
  import fs from "fs/promises";
4
- import path from "path";
5
4
  import { SiteEnv } from "../../site-env.js";
6
5
  import { spawnSync } from "child_process";
7
6
  export const env = (program) => program.command("env <command>", "description", (yargs) => yargs.positional("command", {
@@ -23,9 +22,7 @@ export const env = (program) => program.command("env <command>", "description",
23
22
  }
24
23
  spinner?.succeed();
25
24
  const sites = await SiteEnv.values();
26
- const current = path.relative(project.paths.root, process.cwd());
27
- const env = sites[current] || {};
28
- console.log(args.command);
25
+ const env = sites[process.cwd()] || {};
29
26
  const result = spawnSync(args.command, {
30
27
  env: {
31
28
  ...process.env,
@@ -6,6 +6,8 @@ import { DatabaseMetadata, EnumCollection, PostgresDialect, Serializer, Transfor
6
6
  import { Context } from "../../../context/context.js";
7
7
  import { useBus } from "../../../bus.js";
8
8
  import { useProject } from "../../../project.js";
9
+ import { Logger } from "../../../logger.js";
10
+ import { useAWSCredentials, } from "../../../credentials.js";
9
11
  export const useKyselyTypeGenerator = Context.memo(async () => {
10
12
  let databases = [];
11
13
  const bus = useBus();
@@ -13,6 +15,8 @@ export const useKyselyTypeGenerator = Context.memo(async () => {
13
15
  async function generate(db) {
14
16
  if (!db.types)
15
17
  return;
18
+ Logger.debug("Generating types for", db.migratorID);
19
+ const credentials = await useAWSCredentials();
16
20
  const k = new Kysely({
17
21
  dialect: new DataApiDialect({
18
22
  mode: db.engine.includes("postgres") ? "postgres" : "mysql",
@@ -22,6 +26,7 @@ export const useKyselyTypeGenerator = Context.memo(async () => {
22
26
  database: db.defaultDatabaseName,
23
27
  client: new RDSDataService({
24
28
  region: project.config.region,
29
+ credentials,
25
30
  }),
26
31
  },
27
32
  }),
@@ -67,13 +72,13 @@ export const useKyselyTypeGenerator = Context.memo(async () => {
67
72
  await fs.writeFile(db.types.path, data);
68
73
  }
69
74
  bus.subscribe("stacks.metadata", (evt) => {
70
- databases = Object.values(evt.properties)
71
- .flat()
75
+ const constructs = Object.values(evt.properties).flat();
76
+ databases = constructs
72
77
  .filter((c) => c.type === "RDS")
73
78
  .filter((c) => c.data.migrator)
74
79
  .filter((c) => c.data.types)
75
80
  .map((c) => ({
76
- migratorID: evt.properties.metadata.find((fn) => fn.addr == c.data.migrator?.node).addr,
81
+ migratorID: constructs.find((fn) => fn.addr == c.data.migrator?.node).addr,
77
82
  clusterArn: c.data.clusterArn,
78
83
  types: c.data.types,
79
84
  engine: c.data.engine,
@@ -83,9 +88,12 @@ export const useKyselyTypeGenerator = Context.memo(async () => {
83
88
  databases.map((db) => generate(db));
84
89
  });
85
90
  bus.subscribe("function.success", async (evt) => {
91
+ if (!evt.properties.body?.results)
92
+ return;
86
93
  const db = databases.find((db) => db.migratorID === evt.properties.functionID);
87
94
  if (!db)
88
95
  return;
89
96
  generate(db);
90
97
  });
98
+ Logger.debug("Loaded kyseley type generator");
91
99
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.0-rc.21",
3
+ "version": "2.0.0-rc.23",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/site-env.js CHANGED
@@ -37,6 +37,7 @@ export async function writeValues(input) {
37
37
  await fs.promises.writeFile(file, JSON.stringify(input));
38
38
  }
39
39
  export function append(input) {
40
+ input.path = path.join(useProject().paths.root, input.path);
40
41
  fs.appendFileSync(keysFile(), JSON.stringify(input) + "\n");
41
42
  }
42
43
  export function reset() {
package/sst.mjs CHANGED
@@ -5212,6 +5212,7 @@ async function writeValues(input) {
5212
5212
  await fs13.promises.writeFile(file, JSON.stringify(input));
5213
5213
  }
5214
5214
  function append(input) {
5215
+ input.path = path14.join(useProject().paths.root, input.path);
5215
5216
  fs13.appendFileSync(keysFile(), JSON.stringify(input) + "\n");
5216
5217
  }
5217
5218
  function reset2() {
@@ -5283,15 +5284,15 @@ async function extractSchema(opts) {
5283
5284
  {
5284
5285
  name: "pothos-extractor",
5285
5286
  visitor: {
5286
- Program(path19) {
5287
- const dummyResolverId = path19.scope.generateUidIdentifier("DUMMY_RESOLVER");
5287
+ Program(path18) {
5288
+ const dummyResolverId = path18.scope.generateUidIdentifier("DUMMY_RESOLVER");
5288
5289
  const resolverNode = dummyResolver({
5289
5290
  dummy_resolver: dummyResolverId
5290
5291
  });
5291
- path19.unshiftContainer("body", resolverNode);
5292
- path19.scope.crawl();
5292
+ path18.unshiftContainer("body", resolverNode);
5293
+ path18.scope.crawl();
5293
5294
  let schemaBuilder = null;
5294
- path19.traverse({
5295
+ path18.traverse({
5295
5296
  ImportDeclaration(declarator) {
5296
5297
  if (!declarator)
5297
5298
  return;
@@ -5349,17 +5350,17 @@ async function extractSchema(opts) {
5349
5350
  );
5350
5351
  return contents.code;
5351
5352
  }
5352
- function getBindings(path19, globalPaths) {
5353
+ function getBindings(path18, globalPaths) {
5353
5354
  const bindings = [];
5354
- path19.traverse({
5355
+ path18.traverse({
5355
5356
  Expression(expressionPath) {
5356
5357
  if (!expressionPath.isIdentifier())
5357
5358
  return;
5358
- const binding = path19.scope.getBinding(expressionPath);
5359
+ const binding = path18.scope.getBinding(expressionPath);
5359
5360
  if (!binding || globalPaths.has(binding.path) || bindings.includes(binding.path))
5360
5361
  return;
5361
5362
  const rootBinding = findRootBinding(binding.path);
5362
- if (path19 === rootBinding) {
5363
+ if (path18 === rootBinding) {
5363
5364
  bindings.push(binding.path);
5364
5365
  return;
5365
5366
  }
@@ -5372,8 +5373,8 @@ function getBindings(path19, globalPaths) {
5372
5373
  }
5373
5374
  return bindings;
5374
5375
  }
5375
- function findRootBinding(path19) {
5376
- let rootPath = path19;
5376
+ function findRootBinding(path18) {
5377
+ let rootPath = path18;
5377
5378
  while (rootPath.parentPath?.node !== void 0 && !rootPath.parentPath?.isProgram()) {
5378
5379
  rootPath = rootPath.parentPath;
5379
5380
  }
@@ -5428,6 +5429,8 @@ var usePothosBuilder = Context.memo(() => {
5428
5429
  init_context();
5429
5430
  init_bus();
5430
5431
  init_project();
5432
+ init_logger();
5433
+ init_credentials();
5431
5434
  import { Kysely } from "kysely";
5432
5435
  import { DataApiDialect } from "kysely-data-api";
5433
5436
  import RDSDataService from "aws-sdk/clients/rdsdataservice.js";
@@ -5446,6 +5449,8 @@ var useKyselyTypeGenerator = Context.memo(async () => {
5446
5449
  async function generate2(db) {
5447
5450
  if (!db.types)
5448
5451
  return;
5452
+ Logger.debug("Generating types for", db.migratorID);
5453
+ const credentials = await useAWSCredentials();
5449
5454
  const k = new Kysely({
5450
5455
  dialect: new DataApiDialect({
5451
5456
  mode: db.engine.includes("postgres") ? "postgres" : "mysql",
@@ -5454,7 +5459,8 @@ var useKyselyTypeGenerator = Context.memo(async () => {
5454
5459
  resourceArn: db.clusterArn,
5455
5460
  database: db.defaultDatabaseName,
5456
5461
  client: new RDSDataService({
5457
- region: project.config.region
5462
+ region: project.config.region,
5463
+ credentials
5458
5464
  })
5459
5465
  }
5460
5466
  })
@@ -5498,8 +5504,9 @@ var useKyselyTypeGenerator = Context.memo(async () => {
5498
5504
  await fs16.writeFile(db.types.path, data2);
5499
5505
  }
5500
5506
  bus.subscribe("stacks.metadata", (evt) => {
5501
- databases = Object.values(evt.properties).flat().filter((c) => c.type === "RDS").filter((c) => c.data.migrator).filter((c) => c.data.types).map((c) => ({
5502
- migratorID: evt.properties.metadata.find(
5507
+ const constructs = Object.values(evt.properties).flat();
5508
+ databases = constructs.filter((c) => c.type === "RDS").filter((c) => c.data.migrator).filter((c) => c.data.types).map((c) => ({
5509
+ migratorID: constructs.find(
5503
5510
  (fn) => fn.addr == c.data.migrator?.node
5504
5511
  ).addr,
5505
5512
  clusterArn: c.data.clusterArn,
@@ -5511,6 +5518,8 @@ var useKyselyTypeGenerator = Context.memo(async () => {
5511
5518
  databases.map((db) => generate2(db));
5512
5519
  });
5513
5520
  bus.subscribe("function.success", async (evt) => {
5521
+ if (!evt.properties.body?.results)
5522
+ return;
5514
5523
  const db = databases.find(
5515
5524
  (db2) => db2.migratorID === evt.properties.functionID
5516
5525
  );
@@ -5518,6 +5527,7 @@ var useKyselyTypeGenerator = Context.memo(async () => {
5518
5527
  return;
5519
5528
  generate2(db);
5520
5529
  });
5530
+ Logger.debug("Loaded kyseley type generator");
5521
5531
  });
5522
5532
 
5523
5533
  // src/cli/commands/plugins/warmer.ts
@@ -5555,6 +5565,7 @@ var useRDSWarmer = Context.memo(async () => {
5555
5565
 
5556
5566
  // src/cli/commands/dev.tsx
5557
5567
  init_project();
5568
+ init_metadata();
5558
5569
  var dev = (program2) => program2.command(
5559
5570
  ["start", "dev"],
5560
5571
  "Work on your SST app locally",
@@ -5755,6 +5766,7 @@ var dev = (program2) => program2.command(
5755
5766
  useIOTBridge2(),
5756
5767
  useRuntimeServer2(),
5757
5768
  usePothosBuilder(),
5769
+ useMetadata(),
5758
5770
  useKyselyTypeGenerator(),
5759
5771
  useRDSWarmer(),
5760
5772
  useFunctionLogger(),
@@ -5940,7 +5952,6 @@ import dotenv2 from "dotenv";
5940
5952
  init_project();
5941
5953
  init_spinner();
5942
5954
  import fs19 from "fs/promises";
5943
- import path18 from "path";
5944
5955
  import { spawnSync } from "child_process";
5945
5956
  var env = (program2) => program2.command(
5946
5957
  "env <command>",
@@ -5962,9 +5973,7 @@ var env = (program2) => program2.command(
5962
5973
  }
5963
5974
  spinner?.succeed();
5964
5975
  const sites = await site_env_exports.values();
5965
- const current = path18.relative(project.paths.root, process.cwd());
5966
- const env2 = sites[current] || {};
5967
- console.log(args.command);
5976
+ const env2 = sites[process.cwd()] || {};
5968
5977
  const result = spawnSync(args.command, {
5969
5978
  env: {
5970
5979
  ...process.env,