@baeta/subscriptions-pubsub 2.0.0-next.0 → 2.0.0-next.2

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 ADDED
@@ -0,0 +1,55 @@
1
+ # @baeta/subscriptions-pubsub
2
+
3
+ ## 2.0.0-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix broken types
8
+
9
+ ## 2.0.0-next.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix release version
14
+
15
+ ## 2.0.0-next.0
16
+
17
+ ### Major Changes
18
+
19
+ - [#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
20
+ - **Side-effect-free type generation & resolver definitions.**
21
+ The types generator and resolver definitions were reworked to be side-effect free, improving type safety.
22
+ - **Stricter type safety.**
23
+ You must now **explicitly define resolvers for every field** during development—breakages that used to surface at runtime are now caught at compile time.
24
+ - **Removed `@baeta/compiler`.**
25
+ 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.
26
+ - **Subscriptions update.**
27
+ `@baeta/subscriptions-pubsub` now targets **`graphql-subscriptions` v3**.
28
+
29
+ ## 1.0.9
30
+
31
+ ### Patch Changes
32
+
33
+ - [`583014f`](https://github.com/andreisergiu98/baeta/commit/583014f0bac810b25d9a8226bda2df4c9039f5e3) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Update dependencies
34
+
35
+ ## 1.0.8
36
+
37
+ ### Patch Changes
38
+
39
+ - [#189](https://github.com/andreisergiu98/baeta/pull/189) [`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add jsdocs
40
+
41
+ - [#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
42
+
43
+ ## 0.0.2
44
+
45
+ ### Patch Changes
46
+
47
+ - [`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add readme
48
+
49
+ ## 0.0.1
50
+
51
+ ### Patch Changes
52
+
53
+ - [#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.
54
+
55
+ - [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
@@ -0,0 +1,68 @@
1
+ type Any$1 = any;
2
+ interface PubSubEngine {
3
+ publish: (triggerName: string, payload: Any$1, ...rest: Any$1[]) => Promise<void>;
4
+ subscribe: (triggerName: string, onMessage: (message: Any$1) => Promise<void> | void, ...rest: Any$1[]) => Promise<number>;
5
+ unsubscribe: (subId: number, ...rest: Any$1[]) => void;
6
+ asyncIterableIterator: <T>(triggers: string | readonly string[], ...rest: Any$1[]) => AsyncIterableIterator<T>;
7
+ }
8
+
9
+ /**
10
+ * Configuration options for TypedPubSub
11
+ */
12
+ interface TypedPubSubOptions {
13
+ /** Optional prefix for channel names */
14
+ prefix?: string;
15
+ }
16
+ type Any = any;
17
+ type PubSubMap = Record<string, Any>;
18
+ type OnMessage<Payload> = (message: Payload) => Promise<void> | void;
19
+ type RestPayloadFnArgs<Fn> = Fn extends (triggerName: string, payload: Any, ...rest: infer Rest) => Any ? Rest : never;
20
+ type RestSubscribeFnArgs<Fn> = Fn extends (triggerName: string, onMessage: OnMessage<Any>, ...rest: infer Rest) => Any ? Rest : never;
21
+ type RestUnsubscribeFnArgs<Fn> = Fn extends (subId: number, ...rest: infer Rest) => Any ? Rest : never;
22
+ type RestAsyncIterableIteratorFnArgs<Fn> = Fn extends (triggers: string | readonly string[], ...rest: infer Rest) => Any ? Rest : never;
23
+ /**
24
+ * Creates a type-safe wrapper around a PubSub implementation.
25
+ *
26
+ * This utility ensures that your subscription channels and their payloads
27
+ * are properly typed, helping catch potential errors at compile time.
28
+ *
29
+ * @param pubsub - The PubSub engine instance (e.g., PubSub, RedisPubSub)
30
+ * @param options - Configuration options
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Define your event map
35
+ * type PubSubMap = {
36
+ * "user-updated": User;
37
+ * [c: `user-updated-${string}`]: User;
38
+ * };
39
+ *
40
+ * // Create typed PubSub instance
41
+ * const pubsub = new TypedPubSub<PubSub, PubSubMap>(new PubSub());
42
+ *
43
+ * // Usage with Redis
44
+ * const pubsub = new TypedPubSub<RedisPubSub, PubSubMap>(
45
+ * new RedisPubSub({
46
+ * publisher: new Redis(options),
47
+ * subscriber: new Redis(options),
48
+ * }),
49
+ * {
50
+ * prefix: "feature-1:",
51
+ * }
52
+ * );
53
+ * ```
54
+ */
55
+ declare class TypedPubSub<Engine extends PubSubEngine, Map extends PubSubMap> {
56
+ protected channelPrefix: string;
57
+ protected pubsub: Engine;
58
+ protected options?: TypedPubSubOptions;
59
+ constructor(pubsub: Engine, options?: TypedPubSubOptions);
60
+ publish: <C extends keyof Map>(channel: C, message: Map[C], ...rest: RestPayloadFnArgs<Engine["publish"]>) => Promise<void>;
61
+ subscribe: <C extends keyof Map>(channel: C, onMessage: OnMessage<Map[C]>, ...rest: RestSubscribeFnArgs<Engine["subscribe"]>) => Promise<number>;
62
+ unsubscribe: (subId: number, ...rest: RestUnsubscribeFnArgs<Engine["unsubscribe"]>) => void;
63
+ asyncIterableIterator: <C extends keyof Map>(triggers: C | C[], ...rest: RestAsyncIterableIteratorFnArgs<Engine["asyncIterableIterator"]>) => AsyncIterableIterator<Map[C]>;
64
+ protected mapChannel: <C extends keyof Map>(channel: C) => string;
65
+ protected mapTriggers: <C extends keyof Map>(triggers: C | C[]) => string | string[];
66
+ }
67
+
68
+ export { TypedPubSub, type TypedPubSubOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/subscriptions-pubsub",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.2",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -27,8 +27,8 @@
27
27
  "type": "module",
28
28
  "exports": {
29
29
  ".": {
30
- "types": "./index.ts",
31
- "default": "./index.ts"
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
32
  }
33
33
  },
34
34
  "types": "dist/index.d.ts",
@@ -44,9 +44,9 @@
44
44
  "types": "tsc --noEmit"
45
45
  },
46
46
  "devDependencies": {
47
- "@baeta/builder": "workspace:^",
48
- "@baeta/testing": "workspace:^",
49
- "@baeta/tsconfig": "workspace:^",
47
+ "@baeta/builder": "^0.0.0",
48
+ "@baeta/testing": "^0.0.0",
49
+ "@baeta/tsconfig": "^0.0.0",
50
50
  "graphql": "^16.11.0",
51
51
  "graphql-subscriptions": "^3.0.0",
52
52
  "typescript": "^5.9.3"
@@ -89,4 +89,4 @@
89
89
  "alphabetical-ignoring-documents"
90
90
  ]
91
91
  }
92
- }
92
+ }