@baeta/subscriptions-pubsub 0.0.0 → 0.0.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,15 @@
1
+ # @baeta/subscriptions-pubsub
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add readme
8
+
9
+ ## 0.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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.
14
+
15
+ - [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Pampu Andrei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/andreisergiu98/baeta/refs/heads/main/website/static/img/logo-baeta.svg" alt="Baeta Logo" width="150"/>
3
+ </p>
4
+
5
+ <div align="center">
6
+ <h1>Baeta</h1>
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/testing.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/testing.yml" /></a>
9
+ <a href="https://github.com/andreisergiu98/baeta/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
10
+ <a href="https://github.com/andreisergiu98/baeta/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
11
+ <br />
12
+ <br />
13
+ <a href="https://baeta.io/docs/getting-started/installation">Getting Started</a>
14
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
15
+ <a href="https://www.baeta.io/">Website</a>
16
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
17
+ <a href="https://baeta.io/docs/intro">Docs</a>
18
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
19
+ <a href="https://github.com/andreisergiu98/baeta/tree/main/examples">Examples</a>
20
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
21
+ <a href="https://discord.gg/BHFXHvyj">Discord</a>
22
+ <br />
23
+ <hr />
24
+ </div>
25
+
26
+ # What is Baeta?
27
+
28
+ Building GraphQL APIs shouldn't be complicated. **Baeta** is a modern, modular, open-source GraphQL framework designed with flexibility in mind. It follows a granular approach where you only add what you need, helping developers focus on what matters most - creating powerful, scalable APIs without the boilerplate.
29
+
30
+ ### Key Features
31
+
32
+ - **Modular Architecture**: Organize your API into manageable modules
33
+ - **Schema-First Development**: Define your API contract upfront
34
+ - **Type Safety**: Automatic code generation for type-safe development
35
+ - **Middleware & Directives**: Easy integration of custom behaviors
36
+ - **High Performance**: Built for scalability and efficiency
37
+
38
+ #### And optional extensions and plugins
39
+
40
+ - **@baeta/extension-auth**: Add powerful scope-based authorization
41
+ - **@baeta/extension-cache**: Implement automatic caching with simple update patterns
42
+ - ... and more!
43
+
44
+ ## Why use Baeta?
45
+
46
+ Baeta makes it easy to build better GraphQL APIs while staying flexible. Here's how:
47
+
48
+ **Granular and Progressive:** Start small and add features as you need them. Whether you're building a simple API or a complex system, Baeta scales with your needs.
49
+
50
+ **Modular architecture:** Baeta's modular design allows you to organize your GraphQL API into smaller, more manageable modules that can be added or removed as needed. This makes it easier to maintain and scale your API over time.
51
+
52
+ **Schema-first approach:** With Baeta, you define your schema first, and then logic and resolvers. This approach ensures a consistent and well-defined API for your clients and reduces boilerplate code.
53
+
54
+ ## How it Works
55
+
56
+ #### 1. Define your schema
57
+
58
+ ```graphql
59
+ type User {
60
+ id: ID!
61
+ name: String!
62
+ email: String!
63
+ age: Int
64
+ }
65
+
66
+ input UserWhereUnique {
67
+ id: ID
68
+ email: String
69
+ }
70
+
71
+ type Query {
72
+ user(where: UserWhereUnique!): User!
73
+ users: [User!]!
74
+ }
75
+ ```
76
+
77
+ #### 2. Implement your resolvers
78
+
79
+ ```typescript
80
+ import { getUserModule } from "./typedef";
81
+
82
+ const { Query } = getUserModule();
83
+
84
+ Query.user(({ args }) => {
85
+ return dataSource.user.find(args.where);
86
+ });
87
+
88
+ Query.users(() => {
89
+ return dataSource.user.findMany();
90
+ });
91
+ ```
92
+
93
+ #### 3. Add authorization
94
+
95
+ ```typescript
96
+ const { Query, Mutation } = getUserModule();
97
+
98
+ Query.users.$auth({
99
+ $or: {
100
+ isPublic: true,
101
+ isLoggedIn: true,
102
+ },
103
+ });
104
+ ```
105
+
106
+ #### 4. Add caching
107
+
108
+ ```typescript
109
+ import { getUserModule } from "./typedef";
110
+
111
+ const { User, Query } = getUserModule();
112
+
113
+ export const userCache = User.$createCache();
114
+
115
+ Query.user.$useCache(userCache);
116
+ Query.users.$useCache(userCache);
117
+ ```
118
+
119
+ ## Compatibility
120
+
121
+ Baeta is compatible with all GraphQL servers, which makes it easy to integrate with your existing stack. It works seamlessly with popular GraphQL server libraries such as **Graphql Yoga** and **Apollo Server**, as well as other popular tools like **Prisma**, **Drizzle** and **Kysely**.
122
+
123
+ Baeta's development tools are built for Node.js, but the runtime code is environment-agnostic. This means your Baeta applications can run anywhere JavaScript runs, including:
124
+
125
+ - Deno
126
+ - Cloudflare Workers
127
+ - AWS Lambda
128
+ - Vercel Edge Functions
129
+ - Bun
130
+ - Node.js
131
+ - Any other JavaScript runtime
132
+
133
+ ## Credits
134
+
135
+ Baeta was inspired by several amazing projects and people in the GraphQL ecosystem. Check out our [Credits page](https://baeta.io/docs/credits) to learn more about the individuals and projects that influenced Baeta's development.
136
+
137
+ ## License
138
+
139
+ Baeta is licensed under the [MIT License](./LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/subscriptions-pubsub",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -28,8 +28,7 @@
28
28
  "exports": {
29
29
  ".": {
30
30
  "types": "./dist/index.d.ts",
31
- "import": "./dist/index.js",
32
- "require": "./dist/index.cjs"
31
+ "default": "./dist/index.js"
33
32
  }
34
33
  },
35
34
  "types": "dist/index.d.ts",
@@ -51,18 +50,17 @@
51
50
  "graphql": "^16.9.0",
52
51
  "graphql-subscriptions-v2": "npm:graphql-subscriptions@^2.0.0",
53
52
  "graphql-subscriptions-v3": "npm:graphql-subscriptions@^3.0.0",
54
- "typescript": "^5.6.3"
53
+ "typescript": "^5.7.2"
55
54
  },
56
55
  "engines": {
57
- "node": ">=22.0.0"
56
+ "node": ">=22.12.0"
58
57
  },
59
58
  "publishConfig": {
60
59
  "access": "public",
61
60
  "exports": {
62
61
  ".": {
63
62
  "types": "./dist/index.d.ts",
64
- "import": "./dist/index.js",
65
- "require": "./dist/index.cjs"
63
+ "default": "./dist/index.js"
66
64
  }
67
65
  }
68
66
  },
@@ -74,5 +72,12 @@
74
72
  "--no-warnings",
75
73
  "--experimental-transform-types"
76
74
  ]
75
+ },
76
+ "typedocOptions": {
77
+ "entryPoints": [
78
+ "./index.ts"
79
+ ],
80
+ "readme": "none",
81
+ "tsconfig": "./tsconfig.json"
77
82
  }
78
83
  }
package/dist/index.cjs DELETED
@@ -1,47 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;// lib/typed-pubsub.ts
2
- var TypedPubSubBase = (_class = class {
3
- constructor(pubsub, options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);
4
- this.pubsub = pubsub;
5
- this.options = options;
6
- this.channelPrefix = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.prefix]), () => ( ""));
7
- }
8
-
9
- __init() {this.publish = (channel, message, ...rest) => {
10
- return this.pubsub.publish(this.mapChannel(channel), message, ...rest);
11
- }}
12
- __init2() {this.subscribe = (channel, onMessage, ...rest) => {
13
- return this.pubsub.subscribe(this.mapChannel(channel), onMessage, ...rest);
14
- }}
15
- __init3() {this.unsubscribe = (subId, ...rest) => {
16
- return this.pubsub.unsubscribe(subId, ...rest);
17
- }}
18
- __init4() {this.mapChannel = (channel) => {
19
- return `${this.channelPrefix}${channel.toString()}`;
20
- }}
21
- __init5() {this.mapTriggers = (triggers) => {
22
- return Array.isArray(triggers) ? triggers.map(this.mapChannel) : this.mapChannel(triggers);
23
- }}
24
- }, _class);
25
- var TypedPubSubV2 = (_class2 = class extends TypedPubSubBase {constructor(...args) { super(...args); _class2.prototype.__init6.call(this); }
26
- __init6() {this.asyncIterator = (triggers, ...rest) => {
27
- return this.pubsub.asyncIterator(this.mapTriggers(triggers), ...rest);
28
- }}
29
- }, _class2);
30
- var TypedPubSubV3 = (_class3 = class extends TypedPubSubBase {constructor(...args2) { super(...args2); _class3.prototype.__init7.call(this); }
31
- __init7() {this.asyncIterableIterator = (triggers, ...rest) => {
32
- return this.pubsub.asyncIterableIterator(this.mapTriggers(triggers), ...rest);
33
- }}
34
- }, _class3);
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
-
45
-
46
- exports.createTypedPubSub = createTypedPubSub;
47
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/baeta/baeta/packages/subscriptions-pubsub/dist/index.cjs","../lib/typed-pubsub.ts"],"names":[],"mappings":"AAAA;AC6DA,IAAM,gBAAA,YAAN,MAA8E;AAAA,EAG7E,WAAA,CACW,MAAA,EACA,OAAA,EACT;AAFS,IAAA,IAAA,CAAA,OAAA,EAAA,MAAA;AACA,IAAA,IAAA,CAAA,QAAA,EAAA,OAAA;AAEV,IAAA,IAAA,CAAK,cAAA,mCAAgB,OAAA,2BAAS,QAAA,UAAU,IAAA;AAAA,EACzC;AAAA,EAPU;AAAA,iBASV,QAAA,EAAU,CACT,OAAA,EACA,OAAA,EAAA,GACG,IAAA,EAAA,GACC;AACJ,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,UAAA,CAAW,OAAO,CAAA,EAAG,OAAA,EAAS,GAAG,IAAI,CAAA;AAAA,EACtE,EAAA;AAAA,kBAEA,UAAA,EAAY,CACX,OAAA,EACA,SAAA,EAAA,GACG,IAAA,EAAA,GACC;AACJ,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,IAAA,CAAK,UAAA,CAAW,OAAO,CAAA,EAAG,SAAA,EAAW,GAAG,IAAI,CAAA;AAAA,EAC1E,EAAA;AAAA,kBAEA,YAAA,EAAc,CAAC,KAAA,EAAA,GAAkB,IAAA,EAAA,GAAuD;AACvF,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,WAAA,CAAY,KAAA,EAAO,GAAG,IAAI,CAAA;AAAA,EAC9C,EAAA;AAAA,kBAEU,WAAA,EAAa,CAAsB,OAAA,EAAA,GAAuB;AACnE,IAAA,OAAO,CAAA,EAAA;AACR,EAAA;AAEU,kBAAA;AACF,IAAA;AACR,EAAA;AACD;AAEM;AAIL,kBAAA;AAIQ,IAAA;AACR,EAAA;AACD;AAEM;AAIL,kBAAA;AAIQ,IAAA;AACR,EAAA;AACD;AAWgB;AAIX,EAAA;AACI,IAAA;AACR,EAAA;AAEI,EAAA;AACI,IAAA;AAIR,EAAA;AAEU,EAAA;AACX;AD1GY;AACA;AACA","file":"/home/runner/work/baeta/baeta/packages/subscriptions-pubsub/dist/index.cjs","sourcesContent":[null,"export interface TypedPubSubOptions {\n\tprefix?: string;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: we need to use `any` in this file to support dynamic typing\ntype Any = any;\n\ntype PubSubMap = Record<string, Any>;\ntype OnMessage<Payload> = (message: Payload) => Promise<void> | void;\n\ninterface PubSubEngineBase {\n\tpublish: (triggerName: string, payload: Any, ...rest: Any[]) => Promise<void>;\n\tsubscribe: (triggerName: string, onMessage: OnMessage<Any>, ...rest: Any[]) => Promise<number>;\n\tunsubscribe: (subId: number, ...rest: Any[]) => void;\n}\n\ninterface PubSubEngineV2 extends PubSubEngineBase {\n\tasyncIterator: <T>(triggers: string | string[], ...rest: Any[]) => AsyncIterator<T>;\n}\n\ninterface PubSubEngineV3 extends PubSubEngineBase {\n\tasyncIterableIterator: <T>(\n\t\ttriggers: string | readonly string[],\n\t\t...rest: Any[]\n\t) => AsyncIterableIterator<T>;\n}\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 RestAsyncIteratorFnArgs<Fn> = Fn extends (\n\ttriggers: string | string[],\n\t...rest: infer Rest\n) => 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\nclass TypedPubSubBase<Engine extends PubSubEngineBase, Map extends PubSubMap> {\n\tprotected channelPrefix: string;\n\n\tconstructor(\n\t\tprotected pubsub: Engine,\n\t\tprotected options?: TypedPubSubOptions,\n\t) {\n\t\tthis.channelPrefix = options?.prefix ?? '';\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\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\nclass TypedPubSubV2<Engine extends PubSubEngineV2, Map extends PubSubMap> extends TypedPubSubBase<\n\tEngine,\n\tMap\n> {\n\tasyncIterator = <C extends keyof Map>(\n\t\ttriggers: C | C[],\n\t\t...rest: RestAsyncIteratorFnArgs<Engine['asyncIterator']>\n\t) => {\n\t\treturn this.pubsub.asyncIterator<Map[C]>(this.mapTriggers(triggers), ...rest);\n\t};\n}\n\nclass TypedPubSubV3<Engine extends PubSubEngineV3, Map extends PubSubMap> extends TypedPubSubBase<\n\tEngine,\n\tMap\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\nexport type TypedPubSub<\n\tEngine extends PubSubEngineV2 | PubSubEngineV3,\n\tMap extends PubSubMap,\n> = Engine extends PubSubEngineV3\n\t? TypedPubSubV3<Engine, Map>\n\t: Engine extends PubSubEngineV2\n\t\t? TypedPubSubV2<Engine, Map>\n\t\t: never;\n\nexport function createTypedPubSub<\n\tEngine extends PubSubEngineV2 | PubSubEngineV3,\n\tMap extends PubSubMap,\n>(pubsub: Engine, options?: TypedPubSubOptions): TypedPubSub<Engine, Map> {\n\tif ('asyncIterator' in pubsub) {\n\t\treturn new TypedPubSubV2<PubSubEngineV2, Map>(pubsub, options) as TypedPubSub<Engine, Map>;\n\t}\n\n\tif ('asyncIterableIterator' in pubsub) {\n\t\treturn new TypedPubSubV3<PubSubEngineV3, PubSubMap>(pubsub, options) as TypedPubSub<\n\t\t\tEngine,\n\t\t\tMap\n\t\t>;\n\t}\n\n\tthrow new Error('Unsupported PubSub');\n}\n"]}
package/dist/index.d.cts DELETED
@@ -1,43 +0,0 @@
1
- interface TypedPubSubOptions {
2
- prefix?: string;
3
- }
4
- type Any = any;
5
- type PubSubMap = Record<string, Any>;
6
- type OnMessage<Payload> = (message: Payload) => Promise<void> | void;
7
- interface PubSubEngineBase {
8
- publish: (triggerName: string, payload: Any, ...rest: Any[]) => Promise<void>;
9
- subscribe: (triggerName: string, onMessage: OnMessage<Any>, ...rest: Any[]) => Promise<number>;
10
- unsubscribe: (subId: number, ...rest: Any[]) => void;
11
- }
12
- interface PubSubEngineV2 extends PubSubEngineBase {
13
- asyncIterator: <T>(triggers: string | string[], ...rest: Any[]) => AsyncIterator<T>;
14
- }
15
- interface PubSubEngineV3 extends PubSubEngineBase {
16
- asyncIterableIterator: <T>(triggers: string | readonly string[], ...rest: Any[]) => AsyncIterableIterator<T>;
17
- }
18
- type RestPayloadFnArgs<Fn> = Fn extends (triggerName: string, payload: Any, ...rest: infer Rest) => Any ? Rest : never;
19
- type RestSubscribeFnArgs<Fn> = Fn extends (triggerName: string, onMessage: OnMessage<Any>, ...rest: infer Rest) => Any ? Rest : never;
20
- type RestUnsubscribeFnArgs<Fn> = Fn extends (subId: number, ...rest: infer Rest) => Any ? Rest : never;
21
- type RestAsyncIteratorFnArgs<Fn> = Fn extends (triggers: string | string[], ...rest: infer Rest) => Any ? Rest : never;
22
- type RestAsyncIterableIteratorFnArgs<Fn> = Fn extends (triggers: string | readonly string[], ...rest: infer Rest) => Any ? Rest : never;
23
- declare class TypedPubSubBase<Engine extends PubSubEngineBase, Map extends PubSubMap> {
24
- protected pubsub: Engine;
25
- protected options?: TypedPubSubOptions | undefined;
26
- protected channelPrefix: string;
27
- constructor(pubsub: Engine, options?: TypedPubSubOptions | undefined);
28
- publish: <C extends keyof Map>(channel: C, message: Map[C], ...rest: RestPayloadFnArgs<Engine["publish"]>) => Promise<void>;
29
- subscribe: <C extends keyof Map>(channel: C, onMessage: OnMessage<Map[C]>, ...rest: RestSubscribeFnArgs<Engine["subscribe"]>) => Promise<number>;
30
- unsubscribe: (subId: number, ...rest: RestUnsubscribeFnArgs<Engine["unsubscribe"]>) => void;
31
- protected mapChannel: <C extends keyof Map>(channel: C) => string;
32
- protected mapTriggers: <C extends keyof Map>(triggers: C | C[]) => string | string[];
33
- }
34
- declare class TypedPubSubV2<Engine extends PubSubEngineV2, Map extends PubSubMap> extends TypedPubSubBase<Engine, Map> {
35
- asyncIterator: <C extends keyof Map>(triggers: C | C[], ...rest: RestAsyncIteratorFnArgs<Engine["asyncIterator"]>) => AsyncIterator<Map[C], any, any>;
36
- }
37
- declare class TypedPubSubV3<Engine extends PubSubEngineV3, Map extends PubSubMap> extends TypedPubSubBase<Engine, Map> {
38
- asyncIterableIterator: <C extends keyof Map>(triggers: C | C[], ...rest: RestAsyncIterableIteratorFnArgs<Engine["asyncIterableIterator"]>) => AsyncIterableIterator<Map[C]>;
39
- }
40
- type TypedPubSub<Engine extends PubSubEngineV2 | PubSubEngineV3, Map extends PubSubMap> = Engine extends PubSubEngineV3 ? TypedPubSubV3<Engine, Map> : Engine extends PubSubEngineV2 ? TypedPubSubV2<Engine, Map> : never;
41
- declare function createTypedPubSub<Engine extends PubSubEngineV2 | PubSubEngineV3, Map extends PubSubMap>(pubsub: Engine, options?: TypedPubSubOptions): TypedPubSub<Engine, Map>;
42
-
43
- export { type TypedPubSub, type TypedPubSubOptions, createTypedPubSub };