sst 2.11.7 → 2.11.9
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/constructs/EventBus.d.ts +1 -0
- package/constructs/EventBus.js +24 -12
- package/package.json +2 -1
- package/sst.mjs +42 -20
- package/stacks/build.js +42 -10
- package/support/{event-bus-redriver → event-bus-retrier}/index.mjs +11 -11
package/constructs/EventBus.d.ts
CHANGED
|
@@ -426,6 +426,7 @@ export declare class EventBus extends Construct implements SSTConstruct {
|
|
|
426
426
|
getFunctionBinding(): FunctionBindingProps;
|
|
427
427
|
private retrierQueue;
|
|
428
428
|
private retrierFn;
|
|
429
|
+
private retrierMap;
|
|
429
430
|
private getRetrier;
|
|
430
431
|
private createEventBus;
|
|
431
432
|
private addRule;
|
package/constructs/EventBus.js
CHANGED
|
@@ -8,7 +8,9 @@ import { getFunctionRef, isCDKConstruct } from "./Construct.js";
|
|
|
8
8
|
import { Function as Fn, } from "./Function.js";
|
|
9
9
|
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
|
|
10
10
|
import { SqsDestination } from "aws-cdk-lib/aws-lambda-destinations";
|
|
11
|
+
import url from "url";
|
|
11
12
|
import path from "path";
|
|
13
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
12
14
|
/////////////////////
|
|
13
15
|
// Construct
|
|
14
16
|
/////////////////////
|
|
@@ -231,12 +233,17 @@ export class EventBus extends Construct {
|
|
|
231
233
|
}
|
|
232
234
|
retrierQueue;
|
|
233
235
|
retrierFn;
|
|
236
|
+
retrierMap = {};
|
|
234
237
|
getRetrier() {
|
|
238
|
+
const app = this.node.root;
|
|
235
239
|
if (this.retrierFn && this.retrierQueue) {
|
|
236
240
|
return { fn: this.retrierFn, queue: this.retrierQueue };
|
|
237
241
|
}
|
|
238
|
-
this.retrierQueue = new sqs.Queue(this, `RetrierQueue
|
|
242
|
+
this.retrierQueue = new sqs.Queue(this, `RetrierQueue`, {
|
|
243
|
+
queueName: app.logicalPrefixedName(this.node.id + "Retrier"),
|
|
244
|
+
});
|
|
239
245
|
this.retrierFn = new lambda.Function(this, `RetrierFunction`, {
|
|
246
|
+
functionName: app.logicalPrefixedName(this.node.id + "Retrier"),
|
|
240
247
|
runtime: lambda.Runtime.NODEJS_14_X,
|
|
241
248
|
handler: "index.handler",
|
|
242
249
|
code: lambda.Code.fromAsset(path.join(__dirname, "../support/event-bus-retrier")),
|
|
@@ -350,7 +357,20 @@ export class EventBus extends Construct {
|
|
|
350
357
|
const count = this.subs.get(type) || 0 + 1;
|
|
351
358
|
this.subs.set(type, count);
|
|
352
359
|
const name = `${type.replaceAll(/[^a-zA-Z_]/g, "_")}_${count}`;
|
|
353
|
-
const
|
|
360
|
+
const retries = props?.retries || this.props.defaults?.retries;
|
|
361
|
+
const fn = (() => {
|
|
362
|
+
if (retries) {
|
|
363
|
+
const retrier = this.getRetrier();
|
|
364
|
+
const fn = Fn.fromDefinition(this, name, target, {
|
|
365
|
+
onFailure: new SqsDestination(retrier.queue),
|
|
366
|
+
});
|
|
367
|
+
this.retrierMap[fn.functionArn] = retries;
|
|
368
|
+
retrier.fn.addEnvironment(`RETRIES`, JSON.stringify(this.retrierMap));
|
|
369
|
+
fn.grantInvoke(retrier.fn);
|
|
370
|
+
return fn;
|
|
371
|
+
}
|
|
372
|
+
return Fn.fromDefinition(this, name, target);
|
|
373
|
+
})();
|
|
354
374
|
this.addRule(this, name + "_rule", {
|
|
355
375
|
pattern: {
|
|
356
376
|
detailType: [type],
|
|
@@ -374,7 +394,8 @@ export class EventBus extends Construct {
|
|
|
374
394
|
target = target;
|
|
375
395
|
targetProps = target.cdk?.target;
|
|
376
396
|
functionDefinition = target.function;
|
|
377
|
-
|
|
397
|
+
if (target.retries)
|
|
398
|
+
retries = target.retries;
|
|
378
399
|
}
|
|
379
400
|
else {
|
|
380
401
|
target = target;
|
|
@@ -385,15 +406,6 @@ export class EventBus extends Construct {
|
|
|
385
406
|
this.targetsData[ruleKey][targetName] = fn;
|
|
386
407
|
// Create target
|
|
387
408
|
eventsRule.addTarget(new LambdaFunctionTarget(fn, targetProps));
|
|
388
|
-
// Configure retrier
|
|
389
|
-
if (retries) {
|
|
390
|
-
const retrier = this.getRetrier();
|
|
391
|
-
retrier.fn.addEnvironment(`RETRIER_${retrier.fn.functionName}`, retries.toString());
|
|
392
|
-
fn.grantInvoke(retrier.fn);
|
|
393
|
-
fn.configureAsyncInvoke({
|
|
394
|
-
onFailure: new SqsDestination(retrier.queue),
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
409
|
// Attach existing permissions
|
|
398
410
|
this.permissionsAttachedForAllTargets.forEach((permissions) => fn.attachPermissions(permissions));
|
|
399
411
|
fn.bind(this.bindingForAllTargets);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sideEffects": false,
|
|
3
3
|
"name": "sst",
|
|
4
|
-
"version": "2.11.
|
|
4
|
+
"version": "2.11.9",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sst": "cli/sst.js"
|
|
7
7
|
},
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"@aws-sdk/smithy-client": "^3.279.0",
|
|
50
50
|
"@babel/core": "^7.0.0-0",
|
|
51
51
|
"@babel/generator": "^7.20.5",
|
|
52
|
+
"@babel/plugin-syntax-typescript": "^7.21.4",
|
|
52
53
|
"@trpc/server": "9.16.0",
|
|
53
54
|
"adm-zip": "^0.5.10",
|
|
54
55
|
"aws-cdk-lib": "2.79.1",
|
package/sst.mjs
CHANGED
|
@@ -239,6 +239,9 @@ var init_fs = __esm({
|
|
|
239
239
|
import esbuild from "esbuild";
|
|
240
240
|
import fs3 from "fs/promises";
|
|
241
241
|
import path3 from "path";
|
|
242
|
+
import babel from "@babel/core";
|
|
243
|
+
import generate from "@babel/generator";
|
|
244
|
+
import ts from "@babel/plugin-syntax-typescript";
|
|
242
245
|
async function load(input, shallow) {
|
|
243
246
|
const parsed = path3.parse(input);
|
|
244
247
|
const root = await findAbove(input, "package.json");
|
|
@@ -248,17 +251,10 @@ async function load(input, shallow) {
|
|
|
248
251
|
const pkg = JSON.parse(
|
|
249
252
|
await fs3.readFile(path3.join(root, "package.json")).then((x) => x.toString())
|
|
250
253
|
);
|
|
251
|
-
let contents = await fs3.readFile(input).then((x) => x.toString());
|
|
252
|
-
if (shallow)
|
|
253
|
-
contents = contents.replaceAll(
|
|
254
|
-
/stacks\(.*?\)\s*{[\s\S]*?}\s*[,;]/gs,
|
|
255
|
-
"stacks() {},"
|
|
256
|
-
);
|
|
257
254
|
try {
|
|
258
255
|
const result = await esbuild.build({
|
|
259
256
|
keepNames: true,
|
|
260
257
|
bundle: true,
|
|
261
|
-
sourcemap: "inline",
|
|
262
258
|
platform: "node",
|
|
263
259
|
target: "esnext",
|
|
264
260
|
metafile: true,
|
|
@@ -276,6 +272,36 @@ async function load(input, shallow) {
|
|
|
276
272
|
...pkg.peerDependencies
|
|
277
273
|
})
|
|
278
274
|
],
|
|
275
|
+
plugins: [
|
|
276
|
+
{
|
|
277
|
+
name: "shallow",
|
|
278
|
+
setup(build2) {
|
|
279
|
+
if (!shallow)
|
|
280
|
+
return;
|
|
281
|
+
build2.onLoad({ filter: /.*/ }, async (args) => {
|
|
282
|
+
if (args.path !== input)
|
|
283
|
+
return;
|
|
284
|
+
let contents = await fs3.readFile(args.path).then((x) => x.toString());
|
|
285
|
+
const ast = babel.parse(contents, {
|
|
286
|
+
sourceType: "module",
|
|
287
|
+
plugins: [ts]
|
|
288
|
+
});
|
|
289
|
+
babel.traverse(ast, {
|
|
290
|
+
ObjectMethod(path20) {
|
|
291
|
+
const { key } = path20.node;
|
|
292
|
+
if ("name" in key && key.name === "stacks") {
|
|
293
|
+
path20.remove();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
return {
|
|
298
|
+
contents: generate.default(ast).code,
|
|
299
|
+
loader: "ts"
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
],
|
|
279
305
|
absWorkingDir: root,
|
|
280
306
|
outfile,
|
|
281
307
|
banner: {
|
|
@@ -284,11 +310,7 @@ async function load(input, shallow) {
|
|
|
284
310
|
`const require = topLevelCreateRequire(import.meta.url);`
|
|
285
311
|
].join("")
|
|
286
312
|
},
|
|
287
|
-
|
|
288
|
-
contents,
|
|
289
|
-
loader: "ts",
|
|
290
|
-
resolveDir: path3.dirname(input)
|
|
291
|
-
}
|
|
313
|
+
entryPoints: [input]
|
|
292
314
|
});
|
|
293
315
|
const mod = await dynamicImport(outfile);
|
|
294
316
|
await fs3.rm(outfile, {
|
|
@@ -6154,15 +6176,15 @@ var pothos_exports = {};
|
|
|
6154
6176
|
__export(pothos_exports, {
|
|
6155
6177
|
Pothos: () => pothos_exports,
|
|
6156
6178
|
extractSchema: () => extractSchema,
|
|
6157
|
-
generate: () =>
|
|
6179
|
+
generate: () => generate2
|
|
6158
6180
|
});
|
|
6159
|
-
import
|
|
6181
|
+
import babel2 from "@babel/core";
|
|
6160
6182
|
import generator from "@babel/generator";
|
|
6161
6183
|
import esbuild3 from "esbuild";
|
|
6162
6184
|
import fs14 from "fs/promises";
|
|
6163
6185
|
import path16 from "path";
|
|
6164
6186
|
import url9 from "url";
|
|
6165
|
-
async function
|
|
6187
|
+
async function generate2(opts) {
|
|
6166
6188
|
const { printSchema, lexicographicSortSchema } = await import("graphql");
|
|
6167
6189
|
const contents = await extractSchema(opts);
|
|
6168
6190
|
const out = path16.join(path16.dirname(opts.schema), "out.mjs");
|
|
@@ -6200,7 +6222,7 @@ async function extractSchema(opts) {
|
|
|
6200
6222
|
]
|
|
6201
6223
|
});
|
|
6202
6224
|
const globalPaths = /* @__PURE__ */ new Set();
|
|
6203
|
-
const transformed =
|
|
6225
|
+
const transformed = babel2.transformSync(result.outputFiles[0].text, {
|
|
6204
6226
|
sourceType: "module",
|
|
6205
6227
|
plugins: [
|
|
6206
6228
|
{
|
|
@@ -6307,7 +6329,7 @@ var init_pothos = __esm({
|
|
|
6307
6329
|
"src/pothos.ts"() {
|
|
6308
6330
|
"use strict";
|
|
6309
6331
|
init_pothos();
|
|
6310
|
-
({ types, template } =
|
|
6332
|
+
({ types, template } = babel2);
|
|
6311
6333
|
dummyResolver = template(
|
|
6312
6334
|
"const %%dummy_resolver%% = { serialize: x => x, parseValue: x => x };"
|
|
6313
6335
|
);
|
|
@@ -6404,7 +6426,7 @@ var init_kysely = __esm({
|
|
|
6404
6426
|
let databases = [];
|
|
6405
6427
|
const bus = useBus();
|
|
6406
6428
|
const logger = Logger.debug.bind(null, "[kysely-codegen]");
|
|
6407
|
-
async function
|
|
6429
|
+
async function generate3(db) {
|
|
6408
6430
|
if (!db.types)
|
|
6409
6431
|
return;
|
|
6410
6432
|
logger("generating types for", db.migratorID);
|
|
@@ -6458,7 +6480,7 @@ var init_kysely = __esm({
|
|
|
6458
6480
|
secretArn: c.data.secretArn
|
|
6459
6481
|
}));
|
|
6460
6482
|
databases.map(
|
|
6461
|
-
(db) =>
|
|
6483
|
+
(db) => generate3(db).catch((err) => {
|
|
6462
6484
|
logger(err);
|
|
6463
6485
|
})
|
|
6464
6486
|
);
|
|
@@ -6471,7 +6493,7 @@ var init_kysely = __esm({
|
|
|
6471
6493
|
);
|
|
6472
6494
|
if (!db)
|
|
6473
6495
|
return;
|
|
6474
|
-
|
|
6496
|
+
generate3(db).catch((err) => {
|
|
6475
6497
|
logger(err);
|
|
6476
6498
|
});
|
|
6477
6499
|
});
|
package/stacks/build.js
CHANGED
|
@@ -4,6 +4,10 @@ import path from "path";
|
|
|
4
4
|
import { dynamicImport } from "../util/module.js";
|
|
5
5
|
import { findAbove } from "../util/fs.js";
|
|
6
6
|
import { VisibleError } from "../error.js";
|
|
7
|
+
import babel from "@babel/core";
|
|
8
|
+
import generate from "@babel/generator";
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
import ts from "@babel/plugin-syntax-typescript";
|
|
7
11
|
export async function load(input, shallow) {
|
|
8
12
|
const parsed = path.parse(input);
|
|
9
13
|
const root = await findAbove(input, "package.json");
|
|
@@ -11,15 +15,11 @@ export async function load(input, shallow) {
|
|
|
11
15
|
throw new VisibleError("Could not find a package.json file");
|
|
12
16
|
const outfile = path.join(parsed.dir, `.${parsed.name}.${Date.now()}.mjs`);
|
|
13
17
|
const pkg = JSON.parse(await fs.readFile(path.join(root, "package.json")).then((x) => x.toString()));
|
|
14
|
-
let contents = await fs.readFile(input).then((x) => x.toString());
|
|
15
|
-
if (shallow)
|
|
16
|
-
contents = contents.replaceAll(/stacks\(.*?\)\s*{[\s\S]*?}\s*[,;]/gs, "stacks() {},");
|
|
17
18
|
try {
|
|
18
19
|
// Logger.debug("running esbuild on", input);
|
|
19
20
|
const result = await esbuild.build({
|
|
20
21
|
keepNames: true,
|
|
21
22
|
bundle: true,
|
|
22
|
-
sourcemap: "inline",
|
|
23
23
|
platform: "node",
|
|
24
24
|
target: "esnext",
|
|
25
25
|
metafile: true,
|
|
@@ -37,6 +37,38 @@ export async function load(input, shallow) {
|
|
|
37
37
|
...pkg.peerDependencies,
|
|
38
38
|
}),
|
|
39
39
|
],
|
|
40
|
+
plugins: [
|
|
41
|
+
{
|
|
42
|
+
name: "shallow",
|
|
43
|
+
setup(build) {
|
|
44
|
+
if (!shallow)
|
|
45
|
+
return;
|
|
46
|
+
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
47
|
+
if (args.path !== input)
|
|
48
|
+
return;
|
|
49
|
+
let contents = await fs
|
|
50
|
+
.readFile(args.path)
|
|
51
|
+
.then((x) => x.toString());
|
|
52
|
+
const ast = babel.parse(contents, {
|
|
53
|
+
sourceType: "module",
|
|
54
|
+
plugins: [ts],
|
|
55
|
+
});
|
|
56
|
+
babel.traverse(ast, {
|
|
57
|
+
ObjectMethod(path) {
|
|
58
|
+
const { key } = path.node;
|
|
59
|
+
if ("name" in key && key.name === "stacks") {
|
|
60
|
+
path.remove();
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
contents: generate.default(ast).code,
|
|
66
|
+
loader: "ts",
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
40
72
|
absWorkingDir: root,
|
|
41
73
|
outfile,
|
|
42
74
|
banner: {
|
|
@@ -48,12 +80,12 @@ export async function load(input, shallow) {
|
|
|
48
80
|
// The entry can have any file name (ie. "stacks/anything.ts"). We want the
|
|
49
81
|
// build output to be always named "lib/index.js". This allow us to always
|
|
50
82
|
// import from "buildDir" without needing to pass "anything" around.
|
|
51
|
-
stdin: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
|
|
83
|
+
// stdin: {
|
|
84
|
+
// contents,
|
|
85
|
+
// loader: "ts",
|
|
86
|
+
// resolveDir: path.dirname(input),
|
|
87
|
+
// },
|
|
88
|
+
entryPoints: [input],
|
|
57
89
|
});
|
|
58
90
|
// Logger.debug("built", input);
|
|
59
91
|
const mod = await dynamicImport(outfile);
|