@geekmidas/events 10.0.0-alpha.12 → 10.0.0-alpha.13
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/dist/PgBossConnection-CywKoAZU.cjs +2 -0
- package/dist/PgBossConnection-DjoqT84r.mjs +2 -0
- package/dist/RabbitMQConnection-C9eccBL8.cjs +2 -0
- package/dist/RabbitMQConnection-CAp7VqyT.mjs +2 -0
- package/dist/SNSConnection-BWDC1wAF.cjs +2 -0
- package/dist/SNSConnection-ezQvVrDv.mjs +2 -0
- package/dist/{SQSSubscriber-YXPlg2rm.cjs → SQSSubscriber-DLPZCzFE.cjs} +91 -14
- package/dist/SQSSubscriber-DLPZCzFE.cjs.map +1 -0
- package/dist/{SQSSubscriber-BMWZ3s5q.mjs → SQSSubscriber-cpo624qU.mjs} +73 -7
- package/dist/SQSSubscriber-cpo624qU.mjs.map +1 -0
- package/dist/basic/index.cjs +7 -8
- package/dist/basic/index.cjs.map +1 -1
- package/dist/basic/index.d.cts +4 -10
- package/dist/basic/index.d.cts.map +1 -1
- package/dist/basic/index.d.mts +4 -10
- package/dist/basic/index.d.mts.map +1 -1
- package/dist/basic/index.mjs +5 -6
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +33 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +32 -41
- package/dist/index.mjs.map +1 -1
- package/dist/pgboss/index.cjs +86 -19
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts +5 -10
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts +5 -10
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +83 -18
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +123 -20
- package/dist/rabbitmq/index.cjs.map +1 -1
- package/dist/rabbitmq/index.d.cts +5 -10
- package/dist/rabbitmq/index.d.cts.map +1 -1
- package/dist/rabbitmq/index.d.mts +5 -10
- package/dist/rabbitmq/index.d.mts.map +1 -1
- package/dist/rabbitmq/index.mjs +118 -19
- package/dist/rabbitmq/index.mjs.map +1 -1
- package/dist/{chunk-CsX-DzYB.cjs → rolldown-runtime-C0BPl7ul.cjs} +17 -16
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sns/index.cjs +92 -33
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +6 -11
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +6 -11
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +74 -16
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sns/snsUrl.cjs +91 -6
- package/dist/sns/snsUrl.cjs.map +1 -0
- package/dist/sns/snsUrl.d.cts +57 -2
- package/dist/sns/snsUrl.d.cts.map +1 -0
- package/dist/sns/snsUrl.d.mts +57 -2
- package/dist/sns/snsUrl.d.mts.map +1 -0
- package/dist/sns/snsUrl.mjs +81 -2
- package/dist/sns/snsUrl.mjs.map +1 -0
- package/dist/sqs/index.cjs +19 -20
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +6 -11
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +6 -11
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +7 -10
- package/dist/sqs/index.mjs.map +1 -1
- package/dist/sqs/sqsUrl.cjs +92 -6
- package/dist/sqs/sqsUrl.cjs.map +1 -0
- package/dist/sqs/sqsUrl.d.cts +56 -2
- package/dist/sqs/sqsUrl.d.cts.map +1 -0
- package/dist/sqs/sqsUrl.d.mts +56 -2
- package/dist/sqs/sqsUrl.d.mts.map +1 -0
- package/dist/sqs/sqsUrl.mjs +82 -2
- package/dist/sqs/sqsUrl.mjs.map +1 -0
- package/dist/types-C15FC0qp.mjs +18 -0
- package/dist/{types-Byv8N9ma.cjs.map → types-C15FC0qp.mjs.map} +1 -1
- package/dist/types-DXNwyRyg.cjs +23 -0
- package/dist/{types-CYDt-2RQ.mjs.map → types-DXNwyRyg.cjs.map} +1 -1
- package/dist/types-lnM-qoe_.d.cts +140 -0
- package/dist/types-lnM-qoe_.d.cts.map +1 -0
- package/dist/types-lnM-qoe_.d.mts +140 -0
- package/dist/types-lnM-qoe_.d.mts.map +1 -0
- package/package.json +3 -3
- package/dist/PgBossConnection-23soZ_aM.cjs +0 -80
- package/dist/PgBossConnection-23soZ_aM.cjs.map +0 -1
- package/dist/PgBossConnection-CCXhoNzb.cjs +0 -4
- package/dist/PgBossConnection-DvNbd4Zk.mjs +0 -74
- package/dist/PgBossConnection-DvNbd4Zk.mjs.map +0 -1
- package/dist/PgBossConnection-_gdM40JB.mjs +0 -4
- package/dist/RabbitMQConnection-BKEdCUro.cjs +0 -113
- package/dist/RabbitMQConnection-BKEdCUro.cjs.map +0 -1
- package/dist/RabbitMQConnection-CCOqDDnb.cjs +0 -4
- package/dist/RabbitMQConnection-DJEyM-Bu.mjs +0 -4
- package/dist/RabbitMQConnection-DJgUPc19.mjs +0 -107
- package/dist/RabbitMQConnection-DJgUPc19.mjs.map +0 -1
- package/dist/SNSConnection-B2K86hpz.cjs +0 -75
- package/dist/SNSConnection-B2K86hpz.cjs.map +0 -1
- package/dist/SNSConnection-BVo84FeW.mjs +0 -5
- package/dist/SNSConnection-DIHRjrQF.cjs +0 -5
- package/dist/SNSConnection-v9jjF99w.mjs +0 -69
- package/dist/SNSConnection-v9jjF99w.mjs.map +0 -1
- package/dist/SQSConnection-4tBMkVZE.mjs +0 -69
- package/dist/SQSConnection-4tBMkVZE.mjs.map +0 -1
- package/dist/SQSConnection-BBLAvF-1.cjs +0 -5
- package/dist/SQSConnection-BaC7rGhI.cjs +0 -75
- package/dist/SQSConnection-BaC7rGhI.cjs.map +0 -1
- package/dist/SQSConnection-DbavOq8_.mjs +0 -5
- package/dist/SQSSubscriber-BMWZ3s5q.mjs.map +0 -1
- package/dist/SQSSubscriber-YXPlg2rm.cjs.map +0 -1
- package/dist/chunk-B9dir_RE.mjs +0 -11
- package/dist/snsUrl-ASdc0D1v.d.cts +0 -61
- package/dist/snsUrl-ASdc0D1v.d.cts.map +0 -1
- package/dist/snsUrl-CifYhPAa.mjs +0 -79
- package/dist/snsUrl-CifYhPAa.mjs.map +0 -1
- package/dist/snsUrl-FRbRcwF0.d.mts +0 -61
- package/dist/snsUrl-FRbRcwF0.d.mts.map +0 -1
- package/dist/snsUrl-f2gU3CzK.cjs +0 -114
- package/dist/snsUrl-f2gU3CzK.cjs.map +0 -1
- package/dist/sqsUrl-BV6zS-mi.d.mts +0 -60
- package/dist/sqsUrl-BV6zS-mi.d.mts.map +0 -1
- package/dist/sqsUrl-CbAsBFHI.mjs +0 -80
- package/dist/sqsUrl-CbAsBFHI.mjs.map +0 -1
- package/dist/sqsUrl-CdisN3GU.cjs +0 -115
- package/dist/sqsUrl-CdisN3GU.cjs.map +0 -1
- package/dist/sqsUrl-DZDPHxIk.d.cts +0 -60
- package/dist/sqsUrl-DZDPHxIk.d.cts.map +0 -1
- package/dist/types-BmixGrOD.d.cts +0 -67
- package/dist/types-BmixGrOD.d.cts.map +0 -1
- package/dist/types-Byv8N9ma.cjs +0 -24
- package/dist/types-CYDt-2RQ.mjs +0 -18
- package/dist/types-DycjsYms.d.mts +0 -67
- package/dist/types-DycjsYms.d.mts.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { InferStandardSchema } from "@geekmidas/schema";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
3
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
4
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
5
|
+
/** The Standard properties. */
|
|
6
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
declare namespace StandardTypedV1 {
|
|
9
|
+
/** The Standard Typed properties interface. */
|
|
10
|
+
interface Props<Input = unknown, Output = Input> {
|
|
11
|
+
/** The version number of the standard. */
|
|
12
|
+
readonly version: 1;
|
|
13
|
+
/** The vendor name of the schema library. */
|
|
14
|
+
readonly vendor: string;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The Standard Typed types interface. */
|
|
19
|
+
interface Types<Input = unknown, Output = Input> {
|
|
20
|
+
/** The input type of the schema. */
|
|
21
|
+
readonly input: Input;
|
|
22
|
+
/** The output type of the schema. */
|
|
23
|
+
readonly output: Output;
|
|
24
|
+
}
|
|
25
|
+
/** Infers the input type of a Standard Typed. */
|
|
26
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
27
|
+
/** Infers the output type of a Standard Typed. */
|
|
28
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
29
|
+
}
|
|
30
|
+
/** The Standard Schema interface. */
|
|
31
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
32
|
+
/** The Standard Schema properties. */
|
|
33
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
34
|
+
}
|
|
35
|
+
declare namespace StandardSchemaV1 {
|
|
36
|
+
/** The Standard Schema properties interface. */
|
|
37
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
38
|
+
/** Validates unknown input values. */
|
|
39
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
40
|
+
}
|
|
41
|
+
/** The result interface of the validate function. */
|
|
42
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
43
|
+
/** The result interface if validation succeeds. */
|
|
44
|
+
interface SuccessResult<Output> {
|
|
45
|
+
/** The typed output value. */
|
|
46
|
+
readonly value: Output;
|
|
47
|
+
/** A falsy value for `issues` indicates success. */
|
|
48
|
+
readonly issues?: undefined;
|
|
49
|
+
}
|
|
50
|
+
interface Options {
|
|
51
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
52
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The result interface if validation fails. */
|
|
55
|
+
interface FailureResult {
|
|
56
|
+
/** The issues of failed validation. */
|
|
57
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
58
|
+
}
|
|
59
|
+
/** The issue interface of the failure output. */
|
|
60
|
+
interface Issue {
|
|
61
|
+
/** The error message of the issue. */
|
|
62
|
+
readonly message: string;
|
|
63
|
+
/** The path of the issue, if any. */
|
|
64
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
65
|
+
}
|
|
66
|
+
/** The path segment interface of the issue. */
|
|
67
|
+
interface PathSegment {
|
|
68
|
+
/** The key representing a path segment. */
|
|
69
|
+
readonly key: PropertyKey;
|
|
70
|
+
}
|
|
71
|
+
/** The Standard types interface. */
|
|
72
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
73
|
+
/** Infers the input type of a Standard. */
|
|
74
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
75
|
+
/** Infers the output type of a Standard. */
|
|
76
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/types.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Represents a publishable event message with a type and payload.
|
|
82
|
+
*
|
|
83
|
+
* @template TType - The event type/name (e.g., 'user.created')
|
|
84
|
+
* @template TPayload - The event payload data
|
|
85
|
+
*/
|
|
86
|
+
type PublishableMessage<TType extends string, TPayload> = {
|
|
87
|
+
type: TType;
|
|
88
|
+
payload: TPayload;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Event publisher/subscriber types
|
|
92
|
+
*/
|
|
93
|
+
declare enum EventPublisherType {
|
|
94
|
+
Basic = "basic",
|
|
95
|
+
EventBridge = "eventbridge",
|
|
96
|
+
SQS = "sqs",
|
|
97
|
+
SNS = "sns",
|
|
98
|
+
Kafka = "kafka",
|
|
99
|
+
RabbitMQ = "rabbitmq",
|
|
100
|
+
PgBoss = "pgboss"
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Base interface for event connections
|
|
104
|
+
* Connections manage the underlying transport (RabbitMQ channel, SQS client, etc.)
|
|
105
|
+
*/
|
|
106
|
+
interface EventConnection {
|
|
107
|
+
readonly type: EventPublisherType;
|
|
108
|
+
connect(): Promise<void>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
isConnected(): boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Interface for event publishers that handle the actual publishing of events.
|
|
114
|
+
* Implementations can send to EventBridge, SQS, Kafka, or any other event system.
|
|
115
|
+
*
|
|
116
|
+
* @template TMessage - The union type of all publishable messages
|
|
117
|
+
*/
|
|
118
|
+
type EventPublisher<TMessage extends PublishableMessage<string, any>> = {
|
|
119
|
+
publish: (message: TMessage[]) => Promise<void>;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Interface for event subscribers that handle receiving and processing events.
|
|
123
|
+
*
|
|
124
|
+
* @template TMessage - The union type of all publishable messages
|
|
125
|
+
*/
|
|
126
|
+
type EventSubscriber<TMessage extends PublishableMessage<string, any>> = {
|
|
127
|
+
subscribe: (messages: TMessage['type'][], listener: (payload: TMessage) => Promise<void>) => Promise<void>;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Utility type to extract the message from EventPublisher
|
|
131
|
+
*/
|
|
132
|
+
type ExtractPublisherMessage<T> = T extends EventPublisher<infer M> ? M : never;
|
|
133
|
+
type MappedEvent<T extends EventPublisher<any> | undefined, OutSchema extends StandardSchemaV1 | undefined = undefined> = {
|
|
134
|
+
type: ExtractPublisherMessage<T>['type'];
|
|
135
|
+
payload: (ctx: InferStandardSchema<OutSchema>) => ExtractPublisherMessage<T>['payload'];
|
|
136
|
+
when?: (ctx: InferStandardSchema<OutSchema>) => boolean;
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
export { ExtractPublisherMessage as a, EventSubscriber as i, EventPublisher as n, MappedEvent as o, EventPublisherType as r, PublishableMessage as s, EventConnection as t };
|
|
140
|
+
//# sourceMappingURL=types-lnM-qoe_.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-lnM-qoe_.d.cts","names":[],"sources":["../../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts","../src/types.ts"],"x_google_ignoreList":[0],"mappings":";;;UACU,gBAAgB,iBAAiB,SAAS;;WAEvC,aAAa,gBAAgB,MAAM,OAAO;;kBAErC;;YAEJ,MAAM,iBAAiB,SAAS;;aAE7B;;aAEA;;aAEA,QAAQ,MAAM,OAAO;;;YAGxB,MAAM,iBAAiB,SAAS;;aAE7B,OAAO;;aAEP,QAAQ;;;OAGhB,WAAW,eAAe,mBAAmB,YAAY;;OAEzD,YAAY,eAAe,mBAAmB,YAAY;;;UAGzD,iBAAiB,iBAAiB,SAAS;;WAExC,aAAa,iBAAiB,MAAM,OAAO;;kBAEtC;;YAEJ,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;aAEzE,WAAW,gBAAgB,UAAU,iBAAiB,wBAAwB,OAAO,UAAU,QAAQ,OAAO;;;OAGtH,OAAO,UAAU,cAAc,UAAU;;YAEpC,cAAc;;aAEX,OAAO;;aAEP;;YAEH;;aAEG,iBAAiB;;;YAGpB;;aAEG,QAAQ,cAAc;;;YAGzB;;aAEG;;aAEA,OAAO,cAAc,cAAc;;;YAGtC;;aAEG,KAAK;;;YAGR,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;OAGjF,WAAW,eAAe,mBAAmB,gBAAgB,WAAW;;OAExE,YAAY,eAAe,mBAAmB,gBAAgB,YAAY;;;;;;;;;;KCjEvE,mBAAmB,sBAAsB;EACpD,MAAM;EACN,SAAS;;;;;aAME;EACX;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;UAOgB;WACP,MAAM;EACf,WAAW;EACX,SAAS;EACT;;;;;;;;KASW,eAAe,iBAAiB;EAC3C,UAAU,SAAS,eAAe;;;;;;;KAQvB,gBAAgB,iBAAiB;EAE3C,YACC,UAAU,oBACV,WAAW,SAAS,aAAa,kBAC7B;;;;;KAKK,wBAAwB,KACnC,UAAU,qBAAqB,KAAK;KAEzB,YACX,UAAU,iCACV,kBAAkB;EAElB,MAAM,wBAAwB;EAC9B,UACC,KAAK,oBAAoB,eACrB,wBAAwB;EAC7B,QAAQ,KAAK,oBAAoB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { InferStandardSchema } from "@geekmidas/schema";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
3
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
4
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
5
|
+
/** The Standard properties. */
|
|
6
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
declare namespace StandardTypedV1 {
|
|
9
|
+
/** The Standard Typed properties interface. */
|
|
10
|
+
interface Props<Input = unknown, Output = Input> {
|
|
11
|
+
/** The version number of the standard. */
|
|
12
|
+
readonly version: 1;
|
|
13
|
+
/** The vendor name of the schema library. */
|
|
14
|
+
readonly vendor: string;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The Standard Typed types interface. */
|
|
19
|
+
interface Types<Input = unknown, Output = Input> {
|
|
20
|
+
/** The input type of the schema. */
|
|
21
|
+
readonly input: Input;
|
|
22
|
+
/** The output type of the schema. */
|
|
23
|
+
readonly output: Output;
|
|
24
|
+
}
|
|
25
|
+
/** Infers the input type of a Standard Typed. */
|
|
26
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
27
|
+
/** Infers the output type of a Standard Typed. */
|
|
28
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
29
|
+
}
|
|
30
|
+
/** The Standard Schema interface. */
|
|
31
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
32
|
+
/** The Standard Schema properties. */
|
|
33
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
34
|
+
}
|
|
35
|
+
declare namespace StandardSchemaV1 {
|
|
36
|
+
/** The Standard Schema properties interface. */
|
|
37
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
38
|
+
/** Validates unknown input values. */
|
|
39
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
40
|
+
}
|
|
41
|
+
/** The result interface of the validate function. */
|
|
42
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
43
|
+
/** The result interface if validation succeeds. */
|
|
44
|
+
interface SuccessResult<Output> {
|
|
45
|
+
/** The typed output value. */
|
|
46
|
+
readonly value: Output;
|
|
47
|
+
/** A falsy value for `issues` indicates success. */
|
|
48
|
+
readonly issues?: undefined;
|
|
49
|
+
}
|
|
50
|
+
interface Options {
|
|
51
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
52
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The result interface if validation fails. */
|
|
55
|
+
interface FailureResult {
|
|
56
|
+
/** The issues of failed validation. */
|
|
57
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
58
|
+
}
|
|
59
|
+
/** The issue interface of the failure output. */
|
|
60
|
+
interface Issue {
|
|
61
|
+
/** The error message of the issue. */
|
|
62
|
+
readonly message: string;
|
|
63
|
+
/** The path of the issue, if any. */
|
|
64
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
65
|
+
}
|
|
66
|
+
/** The path segment interface of the issue. */
|
|
67
|
+
interface PathSegment {
|
|
68
|
+
/** The key representing a path segment. */
|
|
69
|
+
readonly key: PropertyKey;
|
|
70
|
+
}
|
|
71
|
+
/** The Standard types interface. */
|
|
72
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
73
|
+
/** Infers the input type of a Standard. */
|
|
74
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
75
|
+
/** Infers the output type of a Standard. */
|
|
76
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/types.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Represents a publishable event message with a type and payload.
|
|
82
|
+
*
|
|
83
|
+
* @template TType - The event type/name (e.g., 'user.created')
|
|
84
|
+
* @template TPayload - The event payload data
|
|
85
|
+
*/
|
|
86
|
+
type PublishableMessage<TType extends string, TPayload> = {
|
|
87
|
+
type: TType;
|
|
88
|
+
payload: TPayload;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Event publisher/subscriber types
|
|
92
|
+
*/
|
|
93
|
+
declare enum EventPublisherType {
|
|
94
|
+
Basic = "basic",
|
|
95
|
+
EventBridge = "eventbridge",
|
|
96
|
+
SQS = "sqs",
|
|
97
|
+
SNS = "sns",
|
|
98
|
+
Kafka = "kafka",
|
|
99
|
+
RabbitMQ = "rabbitmq",
|
|
100
|
+
PgBoss = "pgboss"
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Base interface for event connections
|
|
104
|
+
* Connections manage the underlying transport (RabbitMQ channel, SQS client, etc.)
|
|
105
|
+
*/
|
|
106
|
+
interface EventConnection {
|
|
107
|
+
readonly type: EventPublisherType;
|
|
108
|
+
connect(): Promise<void>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
isConnected(): boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Interface for event publishers that handle the actual publishing of events.
|
|
114
|
+
* Implementations can send to EventBridge, SQS, Kafka, or any other event system.
|
|
115
|
+
*
|
|
116
|
+
* @template TMessage - The union type of all publishable messages
|
|
117
|
+
*/
|
|
118
|
+
type EventPublisher<TMessage extends PublishableMessage<string, any>> = {
|
|
119
|
+
publish: (message: TMessage[]) => Promise<void>;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Interface for event subscribers that handle receiving and processing events.
|
|
123
|
+
*
|
|
124
|
+
* @template TMessage - The union type of all publishable messages
|
|
125
|
+
*/
|
|
126
|
+
type EventSubscriber<TMessage extends PublishableMessage<string, any>> = {
|
|
127
|
+
subscribe: (messages: TMessage['type'][], listener: (payload: TMessage) => Promise<void>) => Promise<void>;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Utility type to extract the message from EventPublisher
|
|
131
|
+
*/
|
|
132
|
+
type ExtractPublisherMessage<T> = T extends EventPublisher<infer M> ? M : never;
|
|
133
|
+
type MappedEvent<T extends EventPublisher<any> | undefined, OutSchema extends StandardSchemaV1 | undefined = undefined> = {
|
|
134
|
+
type: ExtractPublisherMessage<T>['type'];
|
|
135
|
+
payload: (ctx: InferStandardSchema<OutSchema>) => ExtractPublisherMessage<T>['payload'];
|
|
136
|
+
when?: (ctx: InferStandardSchema<OutSchema>) => boolean;
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
export { ExtractPublisherMessage as a, EventSubscriber as i, EventPublisher as n, MappedEvent as o, EventPublisherType as r, PublishableMessage as s, EventConnection as t };
|
|
140
|
+
//# sourceMappingURL=types-lnM-qoe_.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-lnM-qoe_.d.mts","names":[],"sources":["../../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts","../src/types.ts"],"x_google_ignoreList":[0],"mappings":";;;UACU,gBAAgB,iBAAiB,SAAS;;WAEvC,aAAa,gBAAgB,MAAM,OAAO;;kBAErC;;YAEJ,MAAM,iBAAiB,SAAS;;aAE7B;;aAEA;;aAEA,QAAQ,MAAM,OAAO;;;YAGxB,MAAM,iBAAiB,SAAS;;aAE7B,OAAO;;aAEP,QAAQ;;;OAGhB,WAAW,eAAe,mBAAmB,YAAY;;OAEzD,YAAY,eAAe,mBAAmB,YAAY;;;UAGzD,iBAAiB,iBAAiB,SAAS;;WAExC,aAAa,iBAAiB,MAAM,OAAO;;kBAEtC;;YAEJ,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;aAEzE,WAAW,gBAAgB,UAAU,iBAAiB,wBAAwB,OAAO,UAAU,QAAQ,OAAO;;;OAGtH,OAAO,UAAU,cAAc,UAAU;;YAEpC,cAAc;;aAEX,OAAO;;aAEP;;YAEH;;aAEG,iBAAiB;;;YAGpB;;aAEG,QAAQ,cAAc;;;YAGzB;;aAEG;;aAEA,OAAO,cAAc,cAAc;;;YAGtC;;aAEG,KAAK;;;YAGR,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;OAGjF,WAAW,eAAe,mBAAmB,gBAAgB,WAAW;;OAExE,YAAY,eAAe,mBAAmB,gBAAgB,YAAY;;;;;;;;;;KCjEvE,mBAAmB,sBAAsB;EACpD,MAAM;EACN,SAAS;;;;;aAME;EACX;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;UAOgB;WACP,MAAM;EACf,WAAW;EACX,SAAS;EACT;;;;;;;;KASW,eAAe,iBAAiB;EAC3C,UAAU,SAAS,eAAe;;;;;;;KAQvB,gBAAgB,iBAAiB;EAE3C,YACC,UAAU,oBACV,WAAW,SAAS,aAAa,kBAC7B;;;;;KAKK,wBAAwB,KACnC,UAAU,qBAAqB,KAAK;KAEzB,YACX,UAAU,iCACV,kBAAkB;EAElB,MAAM,wBAAwB;EAC9B,UACC,KAAK,oBAAoB,eACrB,wBAAwB;EAC7B,QAAQ,KAAK,oBAAoB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/events",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"@aws-sdk/client-sqs": ">=3.1136.0",
|
|
104
104
|
"@aws-sdk/client-sns": ">=3.1136.0",
|
|
105
105
|
"pg-boss": ">=12.33.3",
|
|
106
|
-
"@geekmidas/schema": "^10.0.0-alpha.
|
|
106
|
+
"@geekmidas/schema": "^10.0.0-alpha.13"
|
|
107
107
|
},
|
|
108
108
|
"peerDependenciesMeta": {
|
|
109
109
|
"@geekmidas/schema": {
|
|
@@ -128,6 +128,6 @@
|
|
|
128
128
|
"@types/pg": "~8.23.1",
|
|
129
129
|
"pg": "~8.23.0",
|
|
130
130
|
"pg-boss": "~12.33.3",
|
|
131
|
-
"@geekmidas/schema": "^10.0.0-alpha.
|
|
131
|
+
"@geekmidas/schema": "^10.0.0-alpha.13"
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
const require_types = require('./types-Byv8N9ma.cjs');
|
|
3
|
-
const pg_boss = require_chunk.__toESM(require("pg-boss"));
|
|
4
|
-
|
|
5
|
-
//#region src/pgboss/PgBossConnection.ts
|
|
6
|
-
var PgBossConnection = class PgBossConnection {
|
|
7
|
-
type = require_types.EventPublisherType.PgBoss;
|
|
8
|
-
boss;
|
|
9
|
-
connecting;
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create a PgBossConnection from a connection string.
|
|
15
|
-
* Format: pgboss://user:pass@host:5432/database?schema=pgboss
|
|
16
|
-
*/
|
|
17
|
-
static async fromConnectionString(connectionString) {
|
|
18
|
-
const url = new URL(connectionString);
|
|
19
|
-
const params = url.searchParams;
|
|
20
|
-
const postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ""}${url.host}${url.pathname}`;
|
|
21
|
-
const config = {
|
|
22
|
-
connectionString: postgresUrl,
|
|
23
|
-
schema: params.get("schema") || void 0
|
|
24
|
-
};
|
|
25
|
-
const connection = new PgBossConnection(config);
|
|
26
|
-
await connection.connect();
|
|
27
|
-
return connection;
|
|
28
|
-
}
|
|
29
|
-
async connect() {
|
|
30
|
-
if (this.boss) return;
|
|
31
|
-
if (this.connecting) {
|
|
32
|
-
await this.connecting;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.connecting = (async () => {
|
|
36
|
-
try {
|
|
37
|
-
const boss = new pg_boss.PgBoss({
|
|
38
|
-
connectionString: this.config.connectionString,
|
|
39
|
-
...this.config.schema && { schema: this.config.schema }
|
|
40
|
-
});
|
|
41
|
-
await boss.start();
|
|
42
|
-
this.boss = boss;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
this.cleanup();
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
})();
|
|
48
|
-
await this.connecting;
|
|
49
|
-
this.connecting = void 0;
|
|
50
|
-
}
|
|
51
|
-
async close() {
|
|
52
|
-
try {
|
|
53
|
-
await this.boss?.stop({ graceful: true });
|
|
54
|
-
} catch {} finally {
|
|
55
|
-
this.cleanup();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
isConnected() {
|
|
59
|
-
return !!this.boss;
|
|
60
|
-
}
|
|
61
|
-
cleanup() {
|
|
62
|
-
this.boss = void 0;
|
|
63
|
-
this.connecting = void 0;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get the underlying pg-boss instance for publishing/subscribing
|
|
67
|
-
*/
|
|
68
|
-
get instance() {
|
|
69
|
-
return this.boss;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
//#endregion
|
|
74
|
-
Object.defineProperty(exports, 'PgBossConnection', {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
get: function () {
|
|
77
|
-
return PgBossConnection;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
//# sourceMappingURL=PgBossConnection-23soZ_aM.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PgBossConnection-23soZ_aM.cjs","names":["EventPublisherType","config: PgBossConnectionConfig","connectionString: string","PgBoss"],"sources":["../src/pgboss/PgBossConnection.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n"],"mappings":";;;;;AASA,IAAa,mBAAb,MAAa,iBAA4C;CACxD,AAAS,OAAOA,iCAAmB;CACnC,AAAQ;CACR,AAAQ;CAER,YAAoBC,QAAgC;EAAhC;CAAkC;;;;;CAMtD,aAAa,qBACZC,kBAC4B;EAC5B,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAEnB,MAAM,eAAe,aAAa,IAAI,YAAY,EAAE,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,IAAI,KAAK,EAAE,IAAI,SAAS;EAEnH,MAAMD,SAAiC;GACtC,kBAAkB;GAClB,QAAQ,OAAO,IAAI,SAAS;EAC5B;EAED,MAAM,aAAa,IAAI,iBAAiB;AACxC,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,MAAI,KAAK,KAAM;AAEf,MAAI,KAAK,YAAY;AACpB,SAAM,KAAK;AACX;EACA;AAED,OAAK,aAAa,CAAC,YAAY;AAC9B,OAAI;IACH,MAAM,OAAO,IAAIE,eAAO;KACvB,kBAAkB,KAAK,OAAO;KAC9B,GAAI,KAAK,OAAO,UAAU,EAAE,QAAQ,KAAK,OAAO,OAAQ;IACxD;AAED,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;GACZ,SAAQ,OAAO;AACf,SAAK,SAAS;AACd,UAAM;GACN;EACD,IAAG;AAEJ,QAAM,KAAK;AACX,OAAK;CACL;CAED,MAAM,QAAuB;AAC5B,MAAI;AACH,SAAM,KAAK,MAAM,KAAK,EAAE,UAAU,KAAM,EAAC;EACzC,QAAO,CAEP,UAAS;AACT,QAAK,SAAS;EACd;CACD;CAED,cAAuB;AACtB,WAAS,KAAK;CACd;CAED,AAAQ,UAAgB;AACvB,OAAK;AACL,OAAK;CACL;;;;CAKD,IAAI,WAA+B;AAClC,SAAO,KAAK;CACZ;AACD"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { EventPublisherType } from "./types-CYDt-2RQ.mjs";
|
|
2
|
-
import { PgBoss } from "pg-boss";
|
|
3
|
-
|
|
4
|
-
//#region src/pgboss/PgBossConnection.ts
|
|
5
|
-
var PgBossConnection = class PgBossConnection {
|
|
6
|
-
type = EventPublisherType.PgBoss;
|
|
7
|
-
boss;
|
|
8
|
-
connecting;
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Create a PgBossConnection from a connection string.
|
|
14
|
-
* Format: pgboss://user:pass@host:5432/database?schema=pgboss
|
|
15
|
-
*/
|
|
16
|
-
static async fromConnectionString(connectionString) {
|
|
17
|
-
const url = new URL(connectionString);
|
|
18
|
-
const params = url.searchParams;
|
|
19
|
-
const postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ""}${url.host}${url.pathname}`;
|
|
20
|
-
const config = {
|
|
21
|
-
connectionString: postgresUrl,
|
|
22
|
-
schema: params.get("schema") || void 0
|
|
23
|
-
};
|
|
24
|
-
const connection = new PgBossConnection(config);
|
|
25
|
-
await connection.connect();
|
|
26
|
-
return connection;
|
|
27
|
-
}
|
|
28
|
-
async connect() {
|
|
29
|
-
if (this.boss) return;
|
|
30
|
-
if (this.connecting) {
|
|
31
|
-
await this.connecting;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
this.connecting = (async () => {
|
|
35
|
-
try {
|
|
36
|
-
const boss = new PgBoss({
|
|
37
|
-
connectionString: this.config.connectionString,
|
|
38
|
-
...this.config.schema && { schema: this.config.schema }
|
|
39
|
-
});
|
|
40
|
-
await boss.start();
|
|
41
|
-
this.boss = boss;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
this.cleanup();
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
47
|
-
await this.connecting;
|
|
48
|
-
this.connecting = void 0;
|
|
49
|
-
}
|
|
50
|
-
async close() {
|
|
51
|
-
try {
|
|
52
|
-
await this.boss?.stop({ graceful: true });
|
|
53
|
-
} catch {} finally {
|
|
54
|
-
this.cleanup();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
isConnected() {
|
|
58
|
-
return !!this.boss;
|
|
59
|
-
}
|
|
60
|
-
cleanup() {
|
|
61
|
-
this.boss = void 0;
|
|
62
|
-
this.connecting = void 0;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get the underlying pg-boss instance for publishing/subscribing
|
|
66
|
-
*/
|
|
67
|
-
get instance() {
|
|
68
|
-
return this.boss;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
//#endregion
|
|
73
|
-
export { PgBossConnection };
|
|
74
|
-
//# sourceMappingURL=PgBossConnection-DvNbd4Zk.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PgBossConnection-DvNbd4Zk.mjs","names":["config: PgBossConnectionConfig","connectionString: string"],"sources":["../src/pgboss/PgBossConnection.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n"],"mappings":";;;;AASA,IAAa,mBAAb,MAAa,iBAA4C;CACxD,AAAS,OAAO,mBAAmB;CACnC,AAAQ;CACR,AAAQ;CAER,YAAoBA,QAAgC;EAAhC;CAAkC;;;;;CAMtD,aAAa,qBACZC,kBAC4B;EAC5B,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAEnB,MAAM,eAAe,aAAa,IAAI,YAAY,EAAE,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,IAAI,KAAK,EAAE,IAAI,SAAS;EAEnH,MAAMD,SAAiC;GACtC,kBAAkB;GAClB,QAAQ,OAAO,IAAI,SAAS;EAC5B;EAED,MAAM,aAAa,IAAI,iBAAiB;AACxC,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,MAAI,KAAK,KAAM;AAEf,MAAI,KAAK,YAAY;AACpB,SAAM,KAAK;AACX;EACA;AAED,OAAK,aAAa,CAAC,YAAY;AAC9B,OAAI;IACH,MAAM,OAAO,IAAI,OAAO;KACvB,kBAAkB,KAAK,OAAO;KAC9B,GAAI,KAAK,OAAO,UAAU,EAAE,QAAQ,KAAK,OAAO,OAAQ;IACxD;AAED,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;GACZ,SAAQ,OAAO;AACf,SAAK,SAAS;AACd,UAAM;GACN;EACD,IAAG;AAEJ,QAAM,KAAK;AACX,OAAK;CACL;CAED,MAAM,QAAuB;AAC5B,MAAI;AACH,SAAM,KAAK,MAAM,KAAK,EAAE,UAAU,KAAM,EAAC;EACzC,QAAO,CAEP,UAAS;AACT,QAAK,SAAS;EACd;CACD;CAED,cAAuB;AACtB,WAAS,KAAK;CACd;CAED,AAAQ,UAAgB;AACvB,OAAK;AACL,OAAK;CACL;;;;CAKD,IAAI,WAA+B;AAClC,SAAO,KAAK;CACZ;AACD"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
const require_types = require('./types-Byv8N9ma.cjs');
|
|
3
|
-
const amqplib = require_chunk.__toESM(require("amqplib"));
|
|
4
|
-
|
|
5
|
-
//#region src/rabbitmq/RabbitMQConnection.ts
|
|
6
|
-
var RabbitMQConnection = class RabbitMQConnection {
|
|
7
|
-
type = require_types.EventPublisherType.RabbitMQ;
|
|
8
|
-
connection;
|
|
9
|
-
channel;
|
|
10
|
-
connecting;
|
|
11
|
-
config;
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.config = {
|
|
14
|
-
...config,
|
|
15
|
-
exchange: config.exchange || "geekmidas.events",
|
|
16
|
-
exchangeType: config.exchangeType || "topic",
|
|
17
|
-
timeout: config.timeout ?? 5e3,
|
|
18
|
-
exchangeOptions: {
|
|
19
|
-
durable: true,
|
|
20
|
-
...config.exchangeOptions
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Create a RabbitMQConnection from a connection string
|
|
26
|
-
* Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000
|
|
27
|
-
*/
|
|
28
|
-
static async fromConnectionString(connectionString) {
|
|
29
|
-
const url = new URL(connectionString);
|
|
30
|
-
const params = url.searchParams;
|
|
31
|
-
const baseUrl = `amqp://${url.username ? `${url.username}:${url.password}@` : ""}${url.host}${url.pathname}`;
|
|
32
|
-
const timeoutParam = params.get("timeout");
|
|
33
|
-
const config = {
|
|
34
|
-
url: baseUrl,
|
|
35
|
-
exchange: params.get("exchange") || "geekmidas.events",
|
|
36
|
-
exchangeType: params.get("type") || "topic",
|
|
37
|
-
timeout: timeoutParam ? Number.parseInt(timeoutParam, 10) : void 0
|
|
38
|
-
};
|
|
39
|
-
const connection = new RabbitMQConnection(config);
|
|
40
|
-
await connection.connect();
|
|
41
|
-
return connection;
|
|
42
|
-
}
|
|
43
|
-
async connect() {
|
|
44
|
-
if (this.channel) return;
|
|
45
|
-
if (this.connecting) {
|
|
46
|
-
await this.connecting;
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this.connecting = (async () => {
|
|
50
|
-
try {
|
|
51
|
-
const connection = await amqplib.default.connect(this.config.url, { timeout: this.config.timeout });
|
|
52
|
-
const channel = await connection.createChannel();
|
|
53
|
-
await channel.assertExchange(this.config.exchange, this.config.exchangeType, this.config.exchangeOptions);
|
|
54
|
-
connection.on("error", (_err) => {
|
|
55
|
-
this.cleanup();
|
|
56
|
-
});
|
|
57
|
-
connection.on("close", () => {
|
|
58
|
-
this.cleanup();
|
|
59
|
-
});
|
|
60
|
-
this.connection = connection;
|
|
61
|
-
this.channel = channel;
|
|
62
|
-
} catch (error) {
|
|
63
|
-
this.cleanup();
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
})();
|
|
67
|
-
await this.connecting;
|
|
68
|
-
this.connecting = void 0;
|
|
69
|
-
}
|
|
70
|
-
async close() {
|
|
71
|
-
try {
|
|
72
|
-
await this.channel?.close();
|
|
73
|
-
await this.connection?.close();
|
|
74
|
-
} catch (_error) {} finally {
|
|
75
|
-
this.cleanup();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
isConnected() {
|
|
79
|
-
return !!this.channel;
|
|
80
|
-
}
|
|
81
|
-
cleanup() {
|
|
82
|
-
this.channel = void 0;
|
|
83
|
-
this.connection = void 0;
|
|
84
|
-
this.connecting = void 0;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Get the underlying channel for publishing/subscribing
|
|
88
|
-
*/
|
|
89
|
-
get amqpChannel() {
|
|
90
|
-
return this.channel;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Get the exchange name for this connection
|
|
94
|
-
*/
|
|
95
|
-
get exchangeName() {
|
|
96
|
-
return this.config.exchange;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Get the exchange type for this connection
|
|
100
|
-
*/
|
|
101
|
-
get exchangeType() {
|
|
102
|
-
return this.config.exchangeType;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
Object.defineProperty(exports, 'RabbitMQConnection', {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function () {
|
|
110
|
-
return RabbitMQConnection;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
//# sourceMappingURL=RabbitMQConnection-BKEdCUro.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQConnection-BKEdCUro.cjs","names":["EventPublisherType","config: RabbitMQConnectionConfig","connectionString: string","_err: Error"],"sources":["../src/rabbitmq/RabbitMQConnection.ts"],"sourcesContent":["import amqplib from 'amqplib';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface RabbitMQConnectionConfig {\n\turl: string;\n\texchange?: string;\n\texchangeType?: 'topic' | 'direct' | 'fanout' | 'headers';\n\texchangeOptions?: amqplib.Options.AssertExchange;\n\ttimeout?: number; // Connection timeout in milliseconds (default: 5000)\n}\n\nexport class RabbitMQConnection implements EventConnection {\n\treadonly type = EventPublisherType.RabbitMQ;\n\tprivate connection?: amqplib.ChannelModel;\n\tprivate channel?: amqplib.Channel;\n\tprivate connecting?: Promise<void>;\n\tprivate config: Required<\n\t\tPick<RabbitMQConnectionConfig, 'exchange' | 'exchangeType' | 'timeout'>\n\t> &\n\t\tRabbitMQConnectionConfig;\n\n\tconstructor(config: RabbitMQConnectionConfig) {\n\t\tthis.config = {\n\t\t\t...config,\n\t\t\texchange: config.exchange || 'geekmidas.events',\n\t\t\texchangeType: config.exchangeType || 'topic',\n\t\t\ttimeout: config.timeout ?? 5000,\n\t\t\texchangeOptions: {\n\t\t\t\tdurable: true,\n\t\t\t\t...config.exchangeOptions,\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Create a RabbitMQConnection from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<RabbitMQConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\t// Extract connection URL without query params\n\t\tconst baseUrl = `amqp://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst timeoutParam = params.get('timeout');\n\t\tconst config: RabbitMQConnectionConfig = {\n\t\t\turl: baseUrl,\n\t\t\texchange: params.get('exchange') || 'geekmidas.events',\n\t\t\texchangeType: (params.get('type') as any) || 'topic',\n\t\t\ttimeout: timeoutParam ? Number.parseInt(timeoutParam, 10) : undefined,\n\t\t};\n\n\t\tconst connection = new RabbitMQConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.channel) return;\n\n\t\t// Prevent multiple simultaneous connection attempts\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst connection = await amqplib.connect(this.config.url, {\n\t\t\t\t\ttimeout: this.config.timeout,\n\t\t\t\t});\n\t\t\t\tconst channel = await connection.createChannel();\n\n\t\t\t\t// Assert the exchange exists\n\t\t\t\tawait channel.assertExchange(\n\t\t\t\t\tthis.config.exchange!,\n\t\t\t\t\tthis.config.exchangeType!,\n\t\t\t\t\tthis.config.exchangeOptions,\n\t\t\t\t);\n\n\t\t\t\t// Handle connection errors\n\t\t\t\tconnection.on('error', (_err: Error) => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\tconnection.on('close', () => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\t// Only set after successful setup\n\t\t\t\tthis.connection = connection;\n\t\t\t\tthis.channel = channel;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.channel?.close();\n\t\t\tawait this.connection?.close();\n\t\t} catch (_error) {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.channel;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.channel = undefined;\n\t\tthis.connection = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying channel for publishing/subscribing\n\t */\n\tget amqpChannel(): amqplib.Channel | undefined {\n\t\treturn this.channel;\n\t}\n\n\t/**\n\t * Get the exchange name for this connection\n\t */\n\tget exchangeName(): string {\n\t\treturn this.config.exchange;\n\t}\n\n\t/**\n\t * Get the exchange type for this connection\n\t */\n\tget exchangeType(): string {\n\t\treturn this.config.exchangeType;\n\t}\n}\n"],"mappings":";;;;;AAYA,IAAa,qBAAb,MAAa,mBAA8C;CAC1D,AAAS,OAAOA,iCAAmB;CACnC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAKR,YAAYC,QAAkC;AAC7C,OAAK,SAAS;GACb,GAAG;GACH,UAAU,OAAO,YAAY;GAC7B,cAAc,OAAO,gBAAgB;GACrC,SAAS,OAAO,WAAW;GAC3B,iBAAiB;IAChB,SAAS;IACT,GAAG,OAAO;GACV;EACD;CACD;;;;;CAMD,aAAa,qBACZC,kBAC8B;EAC9B,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAGnB,MAAM,WAAW,SAAS,IAAI,YAAY,EAAE,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,IAAI,KAAK,EAAE,IAAI,SAAS;EAE3G,MAAM,eAAe,OAAO,IAAI,UAAU;EAC1C,MAAMD,SAAmC;GACxC,KAAK;GACL,UAAU,OAAO,IAAI,WAAW,IAAI;GACpC,cAAe,OAAO,IAAI,OAAO,IAAY;GAC7C,SAAS,eAAe,OAAO,SAAS,cAAc,GAAG;EACzD;EAED,MAAM,aAAa,IAAI,mBAAmB;AAC1C,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,MAAI,KAAK,QAAS;AAGlB,MAAI,KAAK,YAAY;AACpB,SAAM,KAAK;AACX;EACA;AAED,OAAK,aAAa,CAAC,YAAY;AAC9B,OAAI;IACH,MAAM,aAAa,MAAM,gBAAQ,QAAQ,KAAK,OAAO,KAAK,EACzD,SAAS,KAAK,OAAO,QACrB,EAAC;IACF,MAAM,UAAU,MAAM,WAAW,eAAe;AAGhD,UAAM,QAAQ,eACb,KAAK,OAAO,UACZ,KAAK,OAAO,cACZ,KAAK,OAAO,gBACZ;AAGD,eAAW,GAAG,SAAS,CAACE,SAAgB;AACvC,UAAK,SAAS;IACd,EAAC;AAEF,eAAW,GAAG,SAAS,MAAM;AAC5B,UAAK,SAAS;IACd,EAAC;AAGF,SAAK,aAAa;AAClB,SAAK,UAAU;GACf,SAAQ,OAAO;AACf,SAAK,SAAS;AACd,UAAM;GACN;EACD,IAAG;AAEJ,QAAM,KAAK;AACX,OAAK;CACL;CAED,MAAM,QAAuB;AAC5B,MAAI;AACH,SAAM,KAAK,SAAS,OAAO;AAC3B,SAAM,KAAK,YAAY,OAAO;EAC9B,SAAQ,QAAQ,CAEhB,UAAS;AACT,QAAK,SAAS;EACd;CACD;CAED,cAAuB;AACtB,WAAS,KAAK;CACd;CAED,AAAQ,UAAgB;AACvB,OAAK;AACL,OAAK;AACL,OAAK;CACL;;;;CAKD,IAAI,cAA2C;AAC9C,SAAO,KAAK;CACZ;;;;CAKD,IAAI,eAAuB;AAC1B,SAAO,KAAK,OAAO;CACnB;;;;CAKD,IAAI,eAAuB;AAC1B,SAAO,KAAK,OAAO;CACnB;AACD"}
|