@baeta/subscriptions-pubsub 1.0.8 → 2.0.0-next.0
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/index.js +0 -46
- package/dist/index.js.map +1 -1
- package/package.json +11 -12
- package/CHANGELOG.md +0 -23
- package/dist/index.d.ts +0 -82
package/dist/index.js
CHANGED
|
@@ -1,47 +1 @@
|
|
|
1
|
-
// lib/typed-pubsub.ts
|
|
2
|
-
var TypedPubSubBase = class {
|
|
3
|
-
constructor(pubsub, options) {
|
|
4
|
-
this.pubsub = pubsub;
|
|
5
|
-
this.options = options;
|
|
6
|
-
this.channelPrefix = options?.prefix ?? "";
|
|
7
|
-
}
|
|
8
|
-
channelPrefix;
|
|
9
|
-
publish = (channel, message, ...rest) => {
|
|
10
|
-
return this.pubsub.publish(this.mapChannel(channel), message, ...rest);
|
|
11
|
-
};
|
|
12
|
-
subscribe = (channel, onMessage, ...rest) => {
|
|
13
|
-
return this.pubsub.subscribe(this.mapChannel(channel), onMessage, ...rest);
|
|
14
|
-
};
|
|
15
|
-
unsubscribe = (subId, ...rest) => {
|
|
16
|
-
return this.pubsub.unsubscribe(subId, ...rest);
|
|
17
|
-
};
|
|
18
|
-
mapChannel = (channel) => {
|
|
19
|
-
return `${this.channelPrefix}${channel.toString()}`;
|
|
20
|
-
};
|
|
21
|
-
mapTriggers = (triggers) => {
|
|
22
|
-
return Array.isArray(triggers) ? triggers.map(this.mapChannel) : this.mapChannel(triggers);
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
var TypedPubSubV2 = class extends TypedPubSubBase {
|
|
26
|
-
asyncIterator = (triggers, ...rest) => {
|
|
27
|
-
return this.pubsub.asyncIterator(this.mapTriggers(triggers), ...rest);
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
var TypedPubSubV3 = class extends TypedPubSubBase {
|
|
31
|
-
asyncIterableIterator = (triggers, ...rest) => {
|
|
32
|
-
return this.pubsub.asyncIterableIterator(this.mapTriggers(triggers), ...rest);
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
function createTypedPubSub(pubsub, options) {
|
|
36
|
-
if ("asyncIterator" in pubsub) {
|
|
37
|
-
return new TypedPubSubV2(pubsub, options);
|
|
38
|
-
}
|
|
39
|
-
if ("asyncIterableIterator" in pubsub) {
|
|
40
|
-
return new TypedPubSubV3(pubsub, options);
|
|
41
|
-
}
|
|
42
|
-
throw new Error("Unsupported PubSub");
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
createTypedPubSub
|
|
46
|
-
};
|
|
47
1
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baeta/subscriptions-pubsub",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"baeta",
|
|
6
6
|
"graphql",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"type": "module",
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
|
-
"types": "./
|
|
31
|
-
"default": "./
|
|
30
|
+
"types": "./index.ts",
|
|
31
|
+
"default": "./index.ts"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
@@ -44,16 +44,15 @@
|
|
|
44
44
|
"types": "tsc --noEmit"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@baeta/builder": "
|
|
48
|
-
"@baeta/
|
|
49
|
-
"
|
|
50
|
-
"graphql": "^16.
|
|
51
|
-
"graphql-subscriptions
|
|
52
|
-
"
|
|
53
|
-
"typescript": "^5.7.2"
|
|
47
|
+
"@baeta/builder": "workspace:^",
|
|
48
|
+
"@baeta/testing": "workspace:^",
|
|
49
|
+
"@baeta/tsconfig": "workspace:^",
|
|
50
|
+
"graphql": "^16.11.0",
|
|
51
|
+
"graphql-subscriptions": "^3.0.0",
|
|
52
|
+
"typescript": "^5.9.3"
|
|
54
53
|
},
|
|
55
54
|
"engines": {
|
|
56
|
-
"node": ">=22.
|
|
55
|
+
"node": ">=22.20.0"
|
|
57
56
|
},
|
|
58
57
|
"publishConfig": {
|
|
59
58
|
"access": "public",
|
|
@@ -90,4 +89,4 @@
|
|
|
90
89
|
"alphabetical-ignoring-documents"
|
|
91
90
|
]
|
|
92
91
|
}
|
|
93
|
-
}
|
|
92
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# @baeta/subscriptions-pubsub
|
|
2
|
-
|
|
3
|
-
## 1.0.8
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#189](https://github.com/andreisergiu98/baeta/pull/189) [`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add jsdocs
|
|
8
|
-
|
|
9
|
-
- [#165](https://github.com/andreisergiu98/baeta/pull/165) [`1334c2a`](https://github.com/andreisergiu98/baeta/commit/1334c2a866676c88f0f3d380b22133d81c4e98bc) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - mark as stable
|
|
10
|
-
|
|
11
|
-
## 0.0.2
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- [`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add readme
|
|
16
|
-
|
|
17
|
-
## 0.0.1
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- [#180](https://github.com/andreisergiu98/baeta/pull/180) [`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Raise minimum required NodeJS version to 22.12.0. Drop CommonJS builds in favor of the require_esm feature from NodeJS 22.12.0 onwards.
|
|
22
|
-
|
|
23
|
-
- [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
|
package/dist/index.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
interface PubSubEngineV2 {
|
|
2
|
-
publish: (triggerName: string, payload: any, ...rest: any[]) => Promise<void>;
|
|
3
|
-
subscribe: (triggerName: string, onMessage: (message: any) => Promise<void> | void, ...rest: any[]) => Promise<number>;
|
|
4
|
-
unsubscribe: (subId: number, ...rest: any[]) => void;
|
|
5
|
-
asyncIterator: <T>(triggers: string | string[], ...rest: any[]) => AsyncIterator<T>;
|
|
6
|
-
}
|
|
7
|
-
interface PubSubEngineV3 {
|
|
8
|
-
publish: (triggerName: string, payload: any, ...rest: any[]) => Promise<void>;
|
|
9
|
-
subscribe: (triggerName: string, onMessage: (message: any) => Promise<void> | void, ...rest: any[]) => Promise<number>;
|
|
10
|
-
unsubscribe: (subId: number, ...rest: any[]) => void;
|
|
11
|
-
asyncIterableIterator: <T>(triggers: string | readonly string[], ...rest: any[]) => AsyncIterableIterator<T>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Configuration options for TypedPubSub
|
|
16
|
-
*/
|
|
17
|
-
interface TypedPubSubOptions {
|
|
18
|
-
/** Optional prefix for channel names */
|
|
19
|
-
prefix?: string;
|
|
20
|
-
}
|
|
21
|
-
type Any = any;
|
|
22
|
-
type PubSubMap = Record<string, Any>;
|
|
23
|
-
type OnMessage<Payload> = (message: Payload) => Promise<void> | void;
|
|
24
|
-
type RestPayloadFnArgs<Fn> = Fn extends (triggerName: string, payload: Any, ...rest: infer Rest) => Any ? Rest : never;
|
|
25
|
-
type RestSubscribeFnArgs<Fn> = Fn extends (triggerName: string, onMessage: OnMessage<Any>, ...rest: infer Rest) => Any ? Rest : never;
|
|
26
|
-
type RestUnsubscribeFnArgs<Fn> = Fn extends (subId: number, ...rest: infer Rest) => Any ? Rest : never;
|
|
27
|
-
type RestAsyncIteratorFnArgs<Fn> = Fn extends (triggers: string | string[], ...rest: infer Rest) => Any ? Rest : never;
|
|
28
|
-
type RestAsyncIterableIteratorFnArgs<Fn> = Fn extends (triggers: string | readonly string[], ...rest: infer Rest) => Any ? Rest : never;
|
|
29
|
-
declare class TypedPubSubBase<Engine extends PubSubEngineV2 | PubSubEngineV3, Map extends PubSubMap> {
|
|
30
|
-
protected pubsub: Engine;
|
|
31
|
-
protected options?: TypedPubSubOptions | undefined;
|
|
32
|
-
protected channelPrefix: string;
|
|
33
|
-
constructor(pubsub: Engine, options?: TypedPubSubOptions | undefined);
|
|
34
|
-
publish: <C extends keyof Map>(channel: C, message: Map[C], ...rest: RestPayloadFnArgs<Engine["publish"]>) => Promise<void>;
|
|
35
|
-
subscribe: <C extends keyof Map>(channel: C, onMessage: OnMessage<Map[C]>, ...rest: RestSubscribeFnArgs<Engine["subscribe"]>) => Promise<number>;
|
|
36
|
-
unsubscribe: (subId: number, ...rest: RestUnsubscribeFnArgs<Engine["unsubscribe"]>) => void;
|
|
37
|
-
protected mapChannel: <C extends keyof Map>(channel: C) => string;
|
|
38
|
-
protected mapTriggers: <C extends keyof Map>(triggers: C | C[]) => string | string[];
|
|
39
|
-
}
|
|
40
|
-
declare class TypedPubSubV2<Engine extends PubSubEngineV2, Map extends PubSubMap> extends TypedPubSubBase<Engine, Map> {
|
|
41
|
-
asyncIterator: <C extends keyof Map>(triggers: C | C[], ...rest: RestAsyncIteratorFnArgs<Engine["asyncIterator"]>) => AsyncIterator<Map[C], any, any>;
|
|
42
|
-
}
|
|
43
|
-
/** @hidden */
|
|
44
|
-
declare class TypedPubSubV3<Engine extends PubSubEngineV3, Map extends PubSubMap> extends TypedPubSubBase<Engine, Map> {
|
|
45
|
-
asyncIterableIterator: <C extends keyof Map>(triggers: C | C[], ...rest: RestAsyncIterableIteratorFnArgs<Engine["asyncIterableIterator"]>) => AsyncIterableIterator<Map[C]>;
|
|
46
|
-
}
|
|
47
|
-
type TypedPubSub<Engine extends PubSubEngineV2 | PubSubEngineV3, Map extends Record<string, any>> = Engine extends PubSubEngineV3 ? TypedPubSubV3<Engine, Map> : Engine extends PubSubEngineV2 ? TypedPubSubV2<Engine, Map> : never;
|
|
48
|
-
/**
|
|
49
|
-
* Creates a type-safe wrapper around a PubSub implementation.
|
|
50
|
-
*
|
|
51
|
-
* This utility ensures that your subscription channels and their payloads
|
|
52
|
-
* are properly typed, helping catch potential errors at compile time.
|
|
53
|
-
*
|
|
54
|
-
* @param pubsub - The PubSub engine instance (e.g., PubSub, RedisPubSub)
|
|
55
|
-
* @param options - Configuration options
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* // Define your event map
|
|
60
|
-
* type PubSubMap = {
|
|
61
|
-
* "user-updated": User;
|
|
62
|
-
* [c: `user-updated-${string}`]: User;
|
|
63
|
-
* };
|
|
64
|
-
*
|
|
65
|
-
* // Create typed PubSub instance
|
|
66
|
-
* const pubsub = createTypedPubSub<PubSub, PubSubMap>(new PubSub());
|
|
67
|
-
*
|
|
68
|
-
* // Usage with Redis
|
|
69
|
-
* const pubsub = createTypedPubSub<RedisPubSub, PubSubMap>(
|
|
70
|
-
* new RedisPubSub({
|
|
71
|
-
* publisher: new Redis(options),
|
|
72
|
-
* subscriber: new Redis(options),
|
|
73
|
-
* }),
|
|
74
|
-
* {
|
|
75
|
-
* prefix: "feature-1:",
|
|
76
|
-
* }
|
|
77
|
-
* );
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare function createTypedPubSub<Engine extends PubSubEngineV2 | PubSubEngineV3, Map extends Record<string, any>>(pubsub: Engine, options?: TypedPubSubOptions): TypedPubSub<Engine, Map>;
|
|
81
|
-
|
|
82
|
-
export { type PubSubEngineV2, type PubSubEngineV3, type TypedPubSub, type TypedPubSubOptions, createTypedPubSub };
|