@baeta/subscriptions-pubsub 1.0.9 → 2.0.0-next.1
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/CHANGELOG.md +20 -0
- package/dist/index.js +0 -46
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/dist/index.d.ts +0 -82
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @baeta/subscriptions-pubsub
|
|
2
2
|
|
|
3
|
+
## 2.0.0-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix release version
|
|
8
|
+
|
|
9
|
+
## 2.0.0-next.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [#214](https://github.com/andreisergiu98/baeta/pull/214) [`31d1a50`](https://github.com/andreisergiu98/baeta/commit/31d1a509f96535b43ae85d19c770eb1a5f09dc94) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Baeta v2 – major refactor
|
|
14
|
+
- **Side-effect-free type generation & resolver definitions.**
|
|
15
|
+
The types generator and resolver definitions were reworked to be side-effect free, improving type safety.
|
|
16
|
+
- **Stricter type safety.**
|
|
17
|
+
You must now **explicitly define resolvers for every field** during development—breakages that used to surface at runtime are now caught at compile time.
|
|
18
|
+
- **Removed `@baeta/compiler`.**
|
|
19
|
+
Since modern runtimes can execute TypeScript natively, the separate compiler package is no longer needed. Use your runtime’s native TS support or your existing build setup.
|
|
20
|
+
- **Subscriptions update.**
|
|
21
|
+
`@baeta/subscriptions-pubsub` now targets **`graphql-subscriptions` v3**.
|
|
22
|
+
|
|
3
23
|
## 1.0.9
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
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.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"baeta",
|
|
6
6
|
"graphql",
|
|
@@ -47,13 +47,12 @@
|
|
|
47
47
|
"@baeta/builder": "^0.0.0",
|
|
48
48
|
"@baeta/testing": "^0.0.0",
|
|
49
49
|
"@baeta/tsconfig": "^0.0.0",
|
|
50
|
-
"graphql": "^16.
|
|
51
|
-
"graphql-subscriptions
|
|
52
|
-
"
|
|
53
|
-
"typescript": "^5.8.2"
|
|
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",
|
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 };
|