@baeta/subscriptions-pubsub 2.0.0-next.14 → 2.0.0-next.16

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 CHANGED
@@ -1,56 +1,45 @@
1
1
  # @baeta/subscriptions-pubsub
2
2
 
3
- ## 2.0.0-next.14
3
+ ## 2.0.0-next.16
4
4
 
5
- ### Patch Changes
6
-
7
- - Fix wrong error being thrown in the case for single errors by [@andreisergiu98](https://github.com/andreisergiu98) in [#397](https://github.com/andreisergiu98/baeta/pull/397)
8
-
9
- ## 2.0.0-next.13
10
-
11
- ## 2.0.0-next.12
12
-
13
- ## 2.0.0-next.11
14
-
15
- ## 2.0.0-next.10
16
-
17
- ## 2.0.0-next.9
5
+ ### Major Changes
18
6
 
19
- ## 2.0.0-next.8
7
+ - Drop support for Node.js v23 and v25. Baeta now targets the active LTS releases — Node.js `^22.20.0`, `^24.0.0`, or `>=26.0.0`. by [@andreisergiu98](https://github.com/andreisergiu98) in [#290](https://github.com/andreisergiu98/baeta/pull/290)
20
8
 
21
- ## 2.0.0-next.7
9
+ - `TypedPubSub` is now a concrete class you instantiate with `new`, the `createTypedPubSub()` factory has been removed, and the package targets `graphql-subscriptions` v3 only. Support for `graphql-subscriptions` v2 (and its runtime engine detection) is gone. by [@andreisergiu98](https://github.com/andreisergiu98) in [#290](https://github.com/andreisergiu98/baeta/pull/290)
22
10
 
23
- ## 2.0.0-next.6
11
+ #### Creating the PubSub
24
12
 
25
- ### Patch Changes
13
+ In v1, `TypedPubSub` was a _type_ and you built the instance with the `createTypedPubSub()` factory, which detected the engine version (`asyncIterator` for v2, `asyncIterableIterator` for v3) at runtime. In v2, `TypedPubSub` is the class itself.
26
14
 
27
- - Fix export for subscriptions-pubsub
15
+ **v1:**
28
16
 
29
- ## 2.0.0-next.2
17
+ ```typescript
18
+ import { createTypedPubSub } from "@baeta/subscriptions-pubsub";
19
+ import { PubSub } from "graphql-subscriptions";
30
20
 
31
- ### Patch Changes
21
+ export const pubsub = createTypedPubSub<PubSub, PubSubMap>(new PubSub());
22
+ ```
32
23
 
33
- - Fix broken types
24
+ **v2:**
34
25
 
35
- ## 2.0.0-next.1
26
+ ```typescript
27
+ import { TypedPubSub } from "@baeta/subscriptions-pubsub";
28
+ import { PubSub } from "graphql-subscriptions";
36
29
 
37
- ### Patch Changes
30
+ export const pubsub = new TypedPubSub<PubSub, PubSubMap>(new PubSub());
31
+ ```
38
32
 
39
- - Fix release version
33
+ The optional `{ prefix }` options object is unchanged and still passed as the second argument.
40
34
 
41
- ## 2.0.0-next.0
35
+ #### Removed and changed exports
42
36
 
43
- ### Major Changes
37
+ - `createTypedPubSub()` — removed; use `new TypedPubSub(...)`.
38
+ - `PubSubEngineV2` / `PubSubEngineV3` — removed. The package now targets a single `graphql-subscriptions` v3 engine.
39
+ - `TypedPubSub` — was a type alias in v1; is now the exported class.
40
+ - `TypedPubSubOptions` — unchanged.
44
41
 
45
- - [#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
46
- - **Side-effect-free type generation & resolver definitions.**
47
- The types generator and resolver definitions were reworked to be side-effect free, improving type safety.
48
- - **Stricter type safety.**
49
- You must now **explicitly define resolvers for every field** during development—breakages that used to surface at runtime are now caught at compile time.
50
- - **Removed `@baeta/compiler`.**
51
- 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.
52
- - **Subscriptions update.**
53
- `@baeta/subscriptions-pubsub` now targets **`graphql-subscriptions` v3**.
42
+ Because v2 support is dropped, the `asyncIterator` method (the v2-only iterator) is no longer available — use `asyncIterableIterator(channel)` for the async iterable. `publish`, `subscribe`, and `unsubscribe` are unchanged.
54
43
 
55
44
  ## 1.0.9
56
45
 
package/README.md CHANGED
@@ -5,9 +5,10 @@
5
5
  <div align="center">
6
6
  <h1>Baeta</h1>
7
7
  <a href="https://www.npmjs.com/package/@baeta/cli"><img src="https://img.shields.io/npm/v/@baeta/cli.svg?style=flat" /></a>
8
- <a href="https://github.com/andreisergiu98/baeta/actions/workflows/checks.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/checks.yml" /></a>
8
+ <a href="https://github.com/andreisergiu98/baeta/actions/workflows/build.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/build.yml" /></a>
9
9
  <a href="https://github.com/andreisergiu98/baeta/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
10
10
  <a href="https://github.com/andreisergiu98/baeta/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
11
+ <img alt="nycrc config on GitHub" src="https://img.shields.io/nycrc/andreisergiu98/baeta?config=.nycrc.json&preferredThreshold=branches&color=green">
11
12
  <br />
12
13
  <br />
13
14
  <a href="https://baeta.io/docs/getting-started/installation">Getting Started</a>
@@ -35,10 +36,11 @@ Building GraphQL APIs shouldn't be complicated. **Baeta** is a modern, modular,
35
36
  - **Middleware & Directives**: Easy integration of custom behaviors
36
37
  - **High Performance**: Built for scalability and efficiency
37
38
 
38
- #### And optional extensions and plugins
39
+ #### And optional app plugins and libraries
39
40
 
40
- - **@baeta/extension-auth**: Add powerful scope-based authorization
41
- - **@baeta/extension-cache**: Implement automatic caching with simple update patterns
41
+ - **@baeta/auth**: Add powerful scope-based authorization
42
+ - **@baeta/complexity**: Reject resource-exhausting queries with depth, breadth and complexity limits
43
+ - **@baeta/cache**: Type-safe caching with declarative queries and automatic reconciliation
42
44
  - ... and more!
43
45
 
44
46
  ## Why use Baeta?
@@ -89,7 +91,7 @@ const usersQuery = Query.users.resolve(() => {
89
91
  return dataSource.user.findMany();
90
92
  });
91
93
 
92
- Query.$fields({
94
+ export default Query.$fields({
93
95
  user: userQuery,
94
96
  users: usersQuery,
95
97
  });
@@ -98,17 +100,13 @@ Query.$fields({
98
100
  #### 3. Add authorization
99
101
 
100
102
  ```typescript
103
+ import { auth, rule, scope } from "./lib/auth.ts";
101
104
  import { UserModule } from "./typedef.ts";
102
105
 
103
106
  const { Query } = UserModule;
104
107
 
105
108
  const userQuery = Query.user
106
- .$auth({
107
- $or: {
108
- isPublic: true,
109
- isLoggedIn: true,
110
- },
111
- })
109
+ .$use(auth(rule.or(scope.isPublic, scope.isLoggedIn)))
112
110
  .resolve(async ({ args }) => {
113
111
  // ...
114
112
  });
@@ -117,23 +115,33 @@ const userQuery = Query.user
117
115
  #### 4. Add caching
118
116
 
119
117
  ```typescript
120
- const { Query, Mutation, User } = UserModule;
121
-
122
- export const userCache = User.$createCache();
123
-
124
- const userQuery = Query.user
125
- .$auth({
126
- // ...
118
+ import { createCache, defineQuery } from "@baeta/cache";
119
+ import { redisClient } from "./lib/redis.ts";
120
+
121
+ const { Query, Mutation } = UserModule;
122
+
123
+ export const userCache = createCache(redisClient, {
124
+ name: "UserCache",
125
+ parse: JSON.parse,
126
+ serialize: JSON.stringify,
127
+ })
128
+ .withQueries({
129
+ findUser: defineQuery({
130
+ resolve: async (args: { id: string }) => {
131
+ return dataSource.user.findUnique({ where: args });
132
+ },
133
+ }),
127
134
  })
128
- .$useCache(userCache)
129
- .resolve(async ({ args }) => {
130
- // ...
131
- });
135
+ .build();
136
+
137
+ const userQuery = Query.user.map(({ args }) =>
138
+ userCache.queries.findUser({ id: args.where.id }),
139
+ );
132
140
 
133
141
  const updateUserMutation = Mutation.updateUser
134
142
  .$use(async (next) => {
135
143
  const user = await next();
136
- await userCache.save(user);
144
+ if (user) await userCache.update(user);
137
145
  return user;
138
146
  })
139
147
  .resolve(async ({ args }) => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../lib/typed-pubsub.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: allow any args */\n\nimport type { PubSubEngine } from './pubsub-engine.ts';\n\n/**\n * Configuration options for TypedPubSub\n */\nexport interface TypedPubSubOptions {\n\t/** Optional prefix for channel names */\n\tprefix?: string;\n}\n\ntype PubSubMap = Record<string, any>;\ntype OnMessage<Payload> = (message: Payload) => Promise<void> | void;\n\ntype RestPayloadFnArgs<Fn> = Fn extends (\n\ttriggerName: string,\n\tpayload: any,\n\t...rest: infer Rest\n) => any\n\t? Rest\n\t: never;\n\ntype RestSubscribeFnArgs<Fn> = Fn extends (\n\ttriggerName: string,\n\tonMessage: OnMessage<any>,\n\t...rest: infer Rest\n) => any\n\t? Rest\n\t: never;\n\ntype RestUnsubscribeFnArgs<Fn> = Fn extends (subId: number, ...rest: infer Rest) => any\n\t? Rest\n\t: never;\n\ntype RestAsyncIterableIteratorFnArgs<Fn> = Fn extends (\n\ttriggers: string | readonly string[],\n\t...rest: infer Rest\n) => any\n\t? Rest\n\t: never;\n\n/**\n * Creates a type-safe wrapper around a PubSub implementation.\n *\n * This utility ensures that your subscription channels and their payloads\n * are properly typed, helping catch potential errors at compile time.\n *\n * @param pubsub - The PubSub engine instance (e.g., PubSub, RedisPubSub)\n * @param options - Configuration options\n *\n * @example\n * ```typescript\n * // Define your event map\n * type PubSubMap = {\n * \"user-updated\": User;\n * [c: `user-updated-${string}`]: User;\n * };\n *\n * // Create typed PubSub instance\n * const pubsub = new TypedPubSub<PubSub, PubSubMap>(new PubSub());\n *\n * // Usage with Redis\n * const pubsub = new TypedPubSub<RedisPubSub, PubSubMap>(\n * new RedisPubSub({\n * publisher: new Redis(options),\n * subscriber: new Redis(options),\n * }),\n * {\n * prefix: \"feature-1:\",\n * }\n * );\n * ```\n */\nexport class TypedPubSub<Engine extends PubSubEngine, Map extends PubSubMap> {\n\tprotected channelPrefix: string;\n\tprotected pubsub: Engine;\n\tprotected options?: TypedPubSubOptions;\n\n\tconstructor(pubsub: Engine, options?: TypedPubSubOptions) {\n\t\tthis.channelPrefix = options?.prefix ?? '';\n\t\tthis.pubsub = pubsub;\n\t\tthis.options = options;\n\t}\n\n\tpublish = <C extends keyof Map>(\n\t\tchannel: C,\n\t\tmessage: Map[C],\n\t\t...rest: RestPayloadFnArgs<Engine['publish']>\n\t) => {\n\t\treturn this.pubsub.publish(this.mapChannel(channel), message, ...rest);\n\t};\n\n\tsubscribe = <C extends keyof Map>(\n\t\tchannel: C,\n\t\tonMessage: OnMessage<Map[C]>,\n\t\t...rest: RestSubscribeFnArgs<Engine['subscribe']>\n\t) => {\n\t\treturn this.pubsub.subscribe(this.mapChannel(channel), onMessage, ...rest);\n\t};\n\n\tunsubscribe = (subId: number, ...rest: RestUnsubscribeFnArgs<Engine['unsubscribe']>) => {\n\t\treturn this.pubsub.unsubscribe(subId, ...rest);\n\t};\n\n\tasyncIterableIterator = <C extends keyof Map>(\n\t\ttriggers: C | C[],\n\t\t...rest: RestAsyncIterableIteratorFnArgs<Engine['asyncIterableIterator']>\n\t) => {\n\t\treturn this.pubsub.asyncIterableIterator<Map[C]>(this.mapTriggers(triggers), ...rest);\n\t};\n\n\tprotected mapChannel = <C extends keyof Map>(channel: C): string => {\n\t\treturn `${this.channelPrefix}${channel.toString()}`;\n\t};\n\n\tprotected mapTriggers = <C extends keyof Map>(triggers: C | C[]): string | string[] => {\n\t\treturn Array.isArray(triggers) ? triggers.map(this.mapChannel) : this.mapChannel(triggers);\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,IAAa,cAAb,MAA6E;CAC5E;CACA;CACA;CAEA,YAAY,QAAgB,SAA8B;AACzD,OAAK,gBAAgB,SAAS,UAAU;AACxC,OAAK,SAAS;AACd,OAAK,UAAU;;CAGhB,WACC,SACA,SACA,GAAG,SACC;AACJ,SAAO,KAAK,OAAO,QAAQ,KAAK,WAAW,QAAQ,EAAE,SAAS,GAAG,KAAK;;CAGvE,aACC,SACA,WACA,GAAG,SACC;AACJ,SAAO,KAAK,OAAO,UAAU,KAAK,WAAW,QAAQ,EAAE,WAAW,GAAG,KAAK;;CAG3E,eAAe,OAAe,GAAG,SAAuD;AACvF,SAAO,KAAK,OAAO,YAAY,OAAO,GAAG,KAAK;;CAG/C,yBACC,UACA,GAAG,SACC;AACJ,SAAO,KAAK,OAAO,sBAA8B,KAAK,YAAY,SAAS,EAAE,GAAG,KAAK;;CAGtF,cAA6C,YAAuB;AACnE,SAAO,GAAG,KAAK,gBAAgB,QAAQ,UAAU;;CAGlD,eAA8C,aAAyC;AACtF,SAAO,MAAM,QAAQ,SAAS,GAAG,SAAS,IAAI,KAAK,WAAW,GAAG,KAAK,WAAW,SAAS"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../lib/typed-pubsub.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: allow any args */\n\nimport type { PubSubEngine } from './pubsub-engine.ts';\n\n/**\n * Configuration options for TypedPubSub\n */\nexport interface TypedPubSubOptions {\n\t/** Optional prefix for channel names */\n\tprefix?: string;\n}\n\ntype PubSubMap = Record<string, any>;\ntype OnMessage<Payload> = (message: Payload) => Promise<void> | void;\n\ntype RestPayloadFnArgs<Fn> = Fn extends (\n\ttriggerName: string,\n\tpayload: any,\n\t...rest: infer Rest\n) => any\n\t? Rest\n\t: never;\n\ntype RestSubscribeFnArgs<Fn> = Fn extends (\n\ttriggerName: string,\n\tonMessage: OnMessage<any>,\n\t...rest: infer Rest\n) => any\n\t? Rest\n\t: never;\n\ntype RestUnsubscribeFnArgs<Fn> = Fn extends (subId: number, ...rest: infer Rest) => any\n\t? Rest\n\t: never;\n\ntype RestAsyncIterableIteratorFnArgs<Fn> = Fn extends (\n\ttriggers: string | readonly string[],\n\t...rest: infer Rest\n) => any\n\t? Rest\n\t: never;\n\n/**\n * Creates a type-safe wrapper around a PubSub implementation.\n *\n * This utility ensures that your subscription channels and their payloads\n * are properly typed, helping catch potential errors at compile time.\n *\n * @param pubsub - The PubSub engine instance (e.g., PubSub, RedisPubSub)\n * @param options - Configuration options\n *\n * @example\n * ```typescript\n * // Define your event map\n * type PubSubMap = {\n * \"user-updated\": User;\n * [c: `user-updated-${string}`]: User;\n * };\n *\n * // Create typed PubSub instance\n * const pubsub = new TypedPubSub<PubSub, PubSubMap>(new PubSub());\n *\n * // Usage with Redis\n * const pubsub = new TypedPubSub<RedisPubSub, PubSubMap>(\n * new RedisPubSub({\n * publisher: new Redis(options),\n * subscriber: new Redis(options),\n * }),\n * {\n * prefix: \"feature-1:\",\n * }\n * );\n * ```\n */\nexport class TypedPubSub<Engine extends PubSubEngine, Map extends PubSubMap> {\n\tprotected channelPrefix: string;\n\tprotected pubsub: Engine;\n\tprotected options?: TypedPubSubOptions;\n\n\tconstructor(pubsub: Engine, options?: TypedPubSubOptions) {\n\t\tthis.channelPrefix = options?.prefix ?? '';\n\t\tthis.pubsub = pubsub;\n\t\tthis.options = options;\n\t}\n\n\tpublish = <C extends keyof Map>(\n\t\tchannel: C,\n\t\tmessage: Map[C],\n\t\t...rest: RestPayloadFnArgs<Engine['publish']>\n\t) => {\n\t\treturn this.pubsub.publish(this.mapChannel(channel), message, ...rest);\n\t};\n\n\tsubscribe = <C extends keyof Map>(\n\t\tchannel: C,\n\t\tonMessage: OnMessage<Map[C]>,\n\t\t...rest: RestSubscribeFnArgs<Engine['subscribe']>\n\t) => {\n\t\treturn this.pubsub.subscribe(this.mapChannel(channel), onMessage, ...rest);\n\t};\n\n\tunsubscribe = (subId: number, ...rest: RestUnsubscribeFnArgs<Engine['unsubscribe']>) => {\n\t\treturn this.pubsub.unsubscribe(subId, ...rest);\n\t};\n\n\tasyncIterableIterator = <C extends keyof Map>(\n\t\ttriggers: C | C[],\n\t\t...rest: RestAsyncIterableIteratorFnArgs<Engine['asyncIterableIterator']>\n\t) => {\n\t\treturn this.pubsub.asyncIterableIterator<Map[C]>(this.mapTriggers(triggers), ...rest);\n\t};\n\n\tprotected mapChannel = <C extends keyof Map>(channel: C): string => {\n\t\treturn `${this.channelPrefix}${channel.toString()}`;\n\t};\n\n\tprotected mapTriggers = <C extends keyof Map>(triggers: C | C[]): string | string[] => {\n\t\treturn Array.isArray(triggers) ? triggers.map(this.mapChannel) : this.mapChannel(triggers);\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,IAAa,cAAb,MAA6E;CAC5E;CACA;CACA;CAEA,YAAY,QAAgB,SAA8B;EACzD,KAAK,gBAAgB,SAAS,UAAU;EACxC,KAAK,SAAS;EACd,KAAK,UAAU;CAChB;CAEA,WACC,SACA,SACA,GAAG,SACC;EACJ,OAAO,KAAK,OAAO,QAAQ,KAAK,WAAW,OAAO,GAAG,SAAS,GAAG,IAAI;CACtE;CAEA,aACC,SACA,WACA,GAAG,SACC;EACJ,OAAO,KAAK,OAAO,UAAU,KAAK,WAAW,OAAO,GAAG,WAAW,GAAG,IAAI;CAC1E;CAEA,eAAe,OAAe,GAAG,SAAuD;EACvF,OAAO,KAAK,OAAO,YAAY,OAAO,GAAG,IAAI;CAC9C;CAEA,yBACC,UACA,GAAG,SACC;EACJ,OAAO,KAAK,OAAO,sBAA8B,KAAK,YAAY,QAAQ,GAAG,GAAG,IAAI;CACrF;CAEA,cAA6C,YAAuB;EACnE,OAAO,GAAG,KAAK,gBAAgB,QAAQ,SAAS;CACjD;CAEA,eAA8C,aAAyC;EACtF,OAAO,MAAM,QAAQ,QAAQ,IAAI,SAAS,IAAI,KAAK,UAAU,IAAI,KAAK,WAAW,QAAQ;CAC1F;AACD"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@baeta/subscriptions-pubsub",
3
- "version": "2.0.0-next.14",
3
+ "version": "2.0.0-next.16",
4
+ "description": "Typed PubSub helpers for Baeta subscriptions.",
4
5
  "keywords": [
5
6
  "baeta",
6
7
  "builder",
@@ -21,14 +22,14 @@
21
22
  },
22
23
  "repository": {
23
24
  "type": "git",
24
- "url": "https://github.com/andreisergiu98/baeta.git",
25
+ "url": "git+https://github.com/andreisergiu98/baeta.git",
25
26
  "directory": "packages/subscriptions-pubsub"
26
27
  },
27
28
  "files": [
28
- "dist",
29
- "package.json"
29
+ "dist"
30
30
  ],
31
31
  "type": "module",
32
+ "sideEffects": false,
32
33
  "types": "dist/index.d.ts",
33
34
  "exports": {
34
35
  ".": {
@@ -37,13 +38,13 @@
37
38
  }
38
39
  },
39
40
  "publishConfig": {
40
- "access": "public",
41
41
  "exports": {
42
42
  ".": {
43
43
  "types": "./dist/index.d.ts",
44
44
  "default": "./dist/index.js"
45
45
  }
46
- }
46
+ },
47
+ "access": "public"
47
48
  },
48
49
  "scripts": {
49
50
  "build": "builder build",
@@ -67,7 +68,7 @@
67
68
  ]
68
69
  },
69
70
  "engines": {
70
- "node": ">=22.20.0"
71
+ "node": "^22.20.0 || ^24.0.0 || >=26.0.0"
71
72
  },
72
73
  "typedocOptions": {
73
74
  "entryPoints": [