sst 2.11.2 → 2.11.3
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/node/event-bus/index.d.ts +25 -0
- package/node/event-bus/index.js +50 -0
- package/package.json +4 -2
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
export interface EventBusResources {
|
|
2
2
|
}
|
|
3
3
|
export declare const EventBus: EventBusResources;
|
|
4
|
+
import { EventBridgeEvent } from "aws-lambda";
|
|
5
|
+
import { ZodAny, ZodObject, ZodRawShape, z } from "zod";
|
|
6
|
+
export declare function createEventBuilder<Bus extends keyof typeof EventBus, MetadataShape extends ZodRawShape | undefined, MetadataFunction extends () => any>(props: {
|
|
7
|
+
bus: Bus;
|
|
8
|
+
metadata?: MetadataShape;
|
|
9
|
+
metadataFn?: MetadataFunction;
|
|
10
|
+
}): <Type extends string, Shape extends ZodRawShape, Properties = z.objectOutputType<Shape, ZodAny, "strip">>(type: Type, properties: Shape) => {
|
|
11
|
+
publish: undefined extends MetadataShape ? (properties: Properties) => Promise<void> : (properties: Properties, metadata: z.infer<ZodObject<Exclude<MetadataShape, undefined>, "strip", ZodAny>>) => Promise<void>;
|
|
12
|
+
type: Type;
|
|
13
|
+
shape: {
|
|
14
|
+
metadata: Parameters<undefined extends MetadataShape ? (properties: Properties) => Promise<void> : (properties: Properties, metadata: z.infer<ZodObject<Exclude<MetadataShape, undefined>, "strip", ZodAny>>) => Promise<void>>[1];
|
|
15
|
+
properties: Properties;
|
|
16
|
+
metadataFn: ReturnType<MetadataFunction>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type inferEvent<T extends {
|
|
20
|
+
shape: ZodObject<any>;
|
|
21
|
+
}> = z.infer<T["shape"]>;
|
|
22
|
+
export declare function EventHandler<Event extends {
|
|
23
|
+
shape: {
|
|
24
|
+
properties: any;
|
|
25
|
+
metadata: any;
|
|
26
|
+
metadataFn: any;
|
|
27
|
+
};
|
|
28
|
+
}>(_events: Event, cb: (properties: Event["shape"]["properties"], metadata: undefined extends Event["shape"]["metadata"] ? Event["shape"]["metadataFn"] : Event["shape"]["metadata"]) => Promise<void>): (event: EventBridgeEvent<string, any>) => Promise<void>;
|
package/node/event-bus/index.js
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
1
|
import { createProxy } from "../util/index.js";
|
|
2
2
|
export const EventBus =
|
|
3
3
|
/* @__PURE__ */ createProxy("EventBus");
|
|
4
|
+
import { EventBridgeClient, PutEventsCommand, } from "@aws-sdk/client-eventbridge";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const client = new EventBridgeClient({});
|
|
7
|
+
export function createEventBuilder(props) {
|
|
8
|
+
return function createEvent(type, properties) {
|
|
9
|
+
const propertiesSchema = z.object(properties);
|
|
10
|
+
const metadataSchema = props.metadata
|
|
11
|
+
? z.object(props.metadata)
|
|
12
|
+
: undefined;
|
|
13
|
+
const publish = async (properties, metadata) => {
|
|
14
|
+
console.log("publishing", type, properties);
|
|
15
|
+
await client.send(new PutEventsCommand({
|
|
16
|
+
Entries: [
|
|
17
|
+
{
|
|
18
|
+
// @ts-expect-error
|
|
19
|
+
EventBusName: EventBus[props.bus].busName,
|
|
20
|
+
Source: "console",
|
|
21
|
+
Detail: JSON.stringify({
|
|
22
|
+
properties: propertiesSchema.parse(properties),
|
|
23
|
+
metadata: (() => {
|
|
24
|
+
if (metadataSchema) {
|
|
25
|
+
return metadataSchema.parse(metadata);
|
|
26
|
+
}
|
|
27
|
+
if (props.metadataFn) {
|
|
28
|
+
return props.metadataFn();
|
|
29
|
+
}
|
|
30
|
+
})(),
|
|
31
|
+
}),
|
|
32
|
+
DetailType: type,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
publish: publish,
|
|
39
|
+
type,
|
|
40
|
+
shape: {
|
|
41
|
+
metadata: {},
|
|
42
|
+
properties: {},
|
|
43
|
+
metadataFn: {},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function EventHandler(_events, cb) {
|
|
49
|
+
return async (event) => {
|
|
50
|
+
console.log("received", event);
|
|
51
|
+
await cb(event.detail.properties, event.detail.metadata);
|
|
52
|
+
};
|
|
53
|
+
}
|
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.3",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sst": "cli/sst.js"
|
|
7
7
|
},
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@aws-cdk/cloudformation-diff": "2.79.1",
|
|
33
33
|
"@aws-cdk/cx-api": "2.79.1",
|
|
34
34
|
"@aws-sdk/client-cloudformation": "^3.279.0",
|
|
35
|
+
"@aws-sdk/client-eventbridge": "^3.342.0",
|
|
35
36
|
"@aws-sdk/client-iam": "^3.279.0",
|
|
36
37
|
"@aws-sdk/client-iot": "^3.279.0",
|
|
37
38
|
"@aws-sdk/client-iot-data-plane": "^3.279.0",
|
|
@@ -87,7 +88,8 @@
|
|
|
87
88
|
"undici": "^5.12.0",
|
|
88
89
|
"uuid": "^9.0.0",
|
|
89
90
|
"ws": "^8.11.0",
|
|
90
|
-
"yargs": "^17.6.2"
|
|
91
|
+
"yargs": "^17.6.2",
|
|
92
|
+
"zod": "^3.21.4"
|
|
91
93
|
},
|
|
92
94
|
"devDependencies": {
|
|
93
95
|
"@aws-sdk/client-api-gateway": "^3.208.0",
|