@siggn/core 0.0.5 → 0.1.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/README.md CHANGED
@@ -1,6 +1,8 @@
1
+ [![npm version](https://badge.fury.io/js/%40siggn%2Fcore.svg)](https://www.npmjs.com/package/%40siggn%2Fcore)
2
+
1
3
  # @siggn/core
2
4
 
3
- A lightweight and type-safe event-driven pub/sub system for TypeScript projects.
5
+ A lightweight and type-safe event bus system for TypeScript projects.
4
6
 
5
7
  ## Features
6
8
 
@@ -122,9 +124,9 @@ siggn.publish({ type: 'user_deleted', userId: '123' });
122
124
  logger.unsubscribe();
123
125
  ```
124
126
 
125
- ### Extending message types with `createChild`
127
+ ### Extending message types with `createClone`
126
128
 
127
- The `createChild` method allows you to create a new, independent `Siggn` instance that inherits the
129
+ The `createClone` method allows you to create a new, independent `Siggn` instance that inherits the
128
130
  message types of its parent. This is useful for creating specialized message buses that extend a
129
131
  base set of events without affecting the parent bus.
130
132
 
@@ -136,7 +138,7 @@ const baseSiggn = new Siggn<Message>();
136
138
  type AdminMessage = { type: 'admin_login'; adminId: string };
137
139
 
138
140
  // 2. Create a child bus that understands both `Message` and `AdminMessage`
139
- const adminSiggn = baseSiggn.createChild<AdminMessage>();
141
+ const adminSiggn = baseSiggn.createClone<AdminMessage>();
140
142
 
141
143
  // 3. Subscribe to events on the child bus
142
144
  adminSiggn.subscribe('audit-log', 'user_created', (msg) => {
@@ -160,43 +162,75 @@ baseSiggn.publish({ type: 'user_created', userId: 'def', name: 'Bob' });
160
162
  // No output, because the subscription is on `adminSiggn`.
161
163
  ```
162
164
 
165
+ ### Automatic Garbage Collection
166
+
167
+ Siggn is designed to prevent memory leaks even if subscriptions are not explicitly unsubscribed. It achieves this through the use of `WeakRef` and `FinalizationRegistry`:
168
+
169
+ While explicit `unsubscribe` calls are still good practice for immediate cleanup and control, Siggn provides a robust safety net against common memory leak scenarios.
170
+
163
171
  ## API
164
172
 
165
173
  ### `new Siggn<T>()`
166
174
 
167
- Creates a new message bus instance. `T` is a union type of all possible messages.
175
+ Creates a new message bus instance.
176
+
177
+ - `T`: A union type representing all possible messages.
168
178
 
169
179
  ### `publish(msg)`
170
180
 
171
181
  Publishes a message to all relevant subscribers.
172
182
 
183
+ - `msg`: The message object to be published. It must conform to the `Msg` type.
184
+
173
185
  ### `subscribe(id, type, callback)`
174
186
 
175
- Subscribes a callback to a specific message type with a unique subscriber ID.
187
+ Subscribes a callback to a specific message type.
188
+
189
+ - `id`: A unique `SiggnId` (string) to identify the subscriber.
190
+ - `type`: The `type` of the message to subscribe to.
191
+ - `callback`: A function that executes when a message of the specified `type` is published. It receives the message as its only argument.
176
192
 
177
193
  ### `subscribeAll(id, callback)`
178
194
 
179
- Subscribes a callback to all message types with a unique subscriber ID. The callback will receive
180
- every message published on the bus.
195
+ Subscribes a callback to all message types.
196
+
197
+ - `id`: A unique `SiggnId` to identify the subscriber.
198
+ - `callback`: A function that executes for every message published. It receives the message as its only argument.
181
199
 
182
200
  ### `unsubscribe(id)`
183
201
 
184
- Removes all subscriptions associated with a specific subscriber ID.
202
+ Removes all subscriptions (specific and global) associated with a subscriber ID.
203
+
204
+ - `id`: The `SiggnId` of the subscriber to remove.
205
+
206
+ ### `unsubscribeGlobal(id)`
207
+
208
+ Removes a global subscription for a given subscriber ID.
209
+
210
+ - `id`: The `SiggnId` of the global subscriber to remove.
185
211
 
186
212
  ### `make(id)`
187
213
 
188
- Returns a helper object with `subscribe`, `subscribeMany`, `subscribeAll`, and `unsubscribe` methods
189
- pre-bound to the provided ID. This is useful for encapsulating subscription logic within a component
190
- or service.
214
+ Returns a helper object with `subscribe`, `subscribeMany`, `subscribeAll`, and `unsubscribe` methods pre-bound to the provided ID.
215
+
216
+ - `id`: A `SiggnId` to pre-bind to the subscription methods.
191
217
 
192
218
  ### `subscribeMany(id, setup)`
193
219
 
194
- A convenience method to subscribe to multiple message types for a single ID.
220
+ Subscribes to multiple message types for a single ID.
221
+
222
+ - `id`: A `SiggnId` to identify the subscriber.
223
+ - `setup`: A function that receives a `subscribe` helper to register multiple subscriptions under the same `id`.
224
+
225
+ ### `createClone<C>()`
226
+
227
+ Creates a new, independent `Siggn` instance that inherits the parent's message types and adds new ones.
228
+
229
+ - `C`: A union type of additional message types for the new instance.
195
230
 
196
- ### `createChild<C>()`
231
+ ### `subscriptionsCount()`
197
232
 
198
- Creates a new, independent `Siggn` instance whose message types are a union of the parent's types
199
- and the new child-specific types `C`.
233
+ Returns the total number of subscriptions.
200
234
 
201
235
  ## License
202
236
 
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class r{nextId=0;subscriptions;subscribeAllSubscriptions=[];constructor(){this.subscriptions=new Map}createClone(){return new r}makeId(i){return i??`sub_${(this.nextId++).toString(36)}`}make(i){return{subscribe:(s,t)=>{this.subscribe(i,s,t)},unsubscribe:()=>{this.unsubscribe(i)},subscribeMany:s=>{this.subscribeMany(i,s)},subscribeAll:s=>{this.subscribeAll(i,s)}}}subscribeMany(i,s){s((t,b)=>this.subscribe(i,t,b))}subscribe(i,s,t){this.subscriptions.has(s)||this.subscriptions.set(s,[]),this.subscriptions.get(s)?.push({id:i,callback:t})}subscribeAll(i,s){this.subscribeAllSubscriptions.push({id:i,callback:s})}publish(i){this.subscribeAllSubscriptions.forEach(s=>{s.callback(i)}),this.subscriptions.has(i.type)&&this.subscriptions.get(i.type)?.forEach(s=>{s.callback(i)})}unsubscribe(i){this.subscribeAllSubscriptions=this.subscribeAllSubscriptions.filter(s=>s.id!==i);for(const[s,t]of this.subscriptions)this.subscriptions.set(s,t.filter(b=>b.id!==i))}}exports.Siggn=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class b{nextId=0;subscriptions;globalSubscriptions;middlewares;constructor(){this.subscriptions=new Map,this.globalSubscriptions=[],this.middlewares=[]}use(s){this.middlewares.push(s)}createClone(){return new b}makeId(s){return s??`sub_${(this.nextId++).toString(36)}`}make(s){return{subscribe:(i,t)=>{this.subscribe(s,i,t)},unsubscribe:()=>{this.unsubscribe(s)},subscribeMany:i=>{this.subscribeMany(s,i)},subscribeAll:i=>{this.subscribeAll(s,i)}}}subscribeMany(s,i){i((t,r)=>this.subscribe(s,t,r))}subscribe(s,i,t){this.subscriptions.has(i)||this.subscriptions.set(i,[]),this.subscriptions.get(i)?.push({id:s,ref:t})}subscribeAll(s,i){this.globalSubscriptions.push({id:s,ref:i})}publish(s){this.globalSubscriptions.forEach(i=>{i.ref(s)}),this.subscriptions.has(s.type)&&this.subscriptions.get(s.type)?.forEach(i=>{i.ref(s)})}unsubscribe(s){this.unsubscribeGlobal(s);for(const[i,t]of this.subscriptions)this.subscriptions.set(i,t.filter(r=>r.id!==s))}unsubscribeGlobal(s){this.globalSubscriptions=this.globalSubscriptions.filter(i=>i.id!==s)}}exports.Siggn=b;
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/siggn.ts"],"sourcesContent":["import type { Msg, Subscription, SiggnId } from './types.js';\n\nexport class Siggn<T extends Msg> {\n private nextId = 0;\n private subscriptions: Map<T['type'], Array<Subscription<T, any>>>;\n private subscribeAllSubscriptions: Array<Subscription<T, any>> = [];\n\n constructor() {\n this.subscriptions = new Map();\n }\n\n createClone<C extends Msg>() {\n return new Siggn<C | T>();\n }\n\n makeId(id?: string): SiggnId {\n return id ?? `sub_${(this.nextId++).toString(36)}`;\n }\n\n make(id: SiggnId): {\n subscribe: <K extends T['type']>(\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) => void;\n unsubscribe: () => void;\n subscribeMany: (\n setup: (\n subscribe: <K extends T['type']>(\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) => void,\n ) => void,\n ) => void;\n subscribeAll: (callback: (msg: T) => void) => void;\n } {\n return {\n subscribe: (type, callback) => {\n this.subscribe(id, type, callback);\n },\n unsubscribe: () => {\n this.unsubscribe(id);\n },\n subscribeMany: (setup) => {\n this.subscribeMany(id, setup);\n },\n subscribeAll: (callback) => {\n this.subscribeAll(id, callback);\n },\n };\n }\n\n subscribeMany(\n id: SiggnId,\n setup: (\n subscribe: <K extends T['type']>(\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) => void,\n ) => void,\n ) {\n setup((type, callback) => this.subscribe(id, type, callback));\n }\n\n subscribe<K extends T['type']>(\n id: SiggnId,\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) {\n if (!this.subscriptions.has(type)) {\n this.subscriptions.set(type, []);\n }\n\n this.subscriptions.get(type)?.push({ id, callback });\n }\n\n subscribeAll(id: SiggnId, callback: (msg: T) => void) {\n this.subscribeAllSubscriptions.push({ id, callback });\n }\n\n publish(msg: T) {\n this.subscribeAllSubscriptions.forEach((sub) => {\n sub.callback(msg as Extract<T, { type: any }>);\n });\n\n if (!this.subscriptions.has(msg.type)) {\n return;\n }\n\n this.subscriptions.get(msg.type)?.forEach((sub) => {\n sub.callback(msg as Extract<T, { type: any }>);\n });\n }\n\n unsubscribe(id: SiggnId) {\n this.subscribeAllSubscriptions = this.subscribeAllSubscriptions.filter((s) => s.id !== id);\n\n for (const [type, subscriptions] of this.subscriptions) {\n this.subscriptions.set(\n type,\n subscriptions.filter((sub) => sub.id !== id),\n );\n }\n }\n}\n"],"names":["Siggn","id","type","callback","setup","msg","sub","subscriptions"],"mappings":"gFAEO,MAAMA,CAAqB,CACxB,OAAS,EACT,cACA,0BAAyD,CAAA,EAEjE,aAAc,CACZ,KAAK,kBAAoB,GAC3B,CAEA,aAA6B,CAC3B,OAAO,IAAIA,CACb,CAEA,OAAOC,EAAsB,CAC3B,OAAOA,GAAM,QAAQ,KAAK,UAAU,SAAS,EAAE,CAAC,EAClD,CAEA,KAAKA,EAeH,CACA,MAAO,CACL,UAAW,CAACC,EAAMC,IAAa,CAC7B,KAAK,UAAUF,EAAIC,EAAMC,CAAQ,CACnC,EACA,YAAa,IAAM,CACjB,KAAK,YAAYF,CAAE,CACrB,EACA,cAAgBG,GAAU,CACxB,KAAK,cAAcH,EAAIG,CAAK,CAC9B,EACA,aAAeD,GAAa,CAC1B,KAAK,aAAaF,EAAIE,CAAQ,CAChC,CAAA,CAEJ,CAEA,cACEF,EACAG,EAMA,CACAA,EAAM,CAACF,EAAMC,IAAa,KAAK,UAAUF,EAAIC,EAAMC,CAAQ,CAAC,CAC9D,CAEA,UACEF,EACAC,EACAC,EACA,CACK,KAAK,cAAc,IAAID,CAAI,GAC9B,KAAK,cAAc,IAAIA,EAAM,CAAA,CAAE,EAGjC,KAAK,cAAc,IAAIA,CAAI,GAAG,KAAK,CAAE,GAAAD,EAAI,SAAAE,EAAU,CACrD,CAEA,aAAaF,EAAaE,EAA4B,CACpD,KAAK,0BAA0B,KAAK,CAAE,GAAAF,EAAI,SAAAE,EAAU,CACtD,CAEA,QAAQE,EAAQ,CACd,KAAK,0BAA0B,QAASC,GAAQ,CAC9CA,EAAI,SAASD,CAAgC,CAC/C,CAAC,EAEI,KAAK,cAAc,IAAIA,EAAI,IAAI,GAIpC,KAAK,cAAc,IAAIA,EAAI,IAAI,GAAG,QAASC,GAAQ,CACjDA,EAAI,SAASD,CAAgC,CAC/C,CAAC,CACH,CAEA,YAAYJ,EAAa,CACvB,KAAK,0BAA4B,KAAK,0BAA0B,OAAQ,GAAM,EAAE,KAAOA,CAAE,EAEzF,SAAW,CAACC,EAAMK,CAAa,IAAK,KAAK,cACvC,KAAK,cAAc,IACjBL,EACAK,EAAc,OAAQD,GAAQA,EAAI,KAAOL,CAAE,CAAA,CAGjD,CACF"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/siggn.ts"],"sourcesContent":["import type { Msg, Subscription, SiggnId, Middleware } from './types.js';\n\n/**\n * A type-safe message bus for dispatching and subscribing to events.\n * @template T A union of all possible message types.\n * @since 0.0.5\n */\nexport class Siggn<M extends Msg> {\n private nextId = 0;\n private subscriptions: Map<M['type'], Array<Subscription<M, any>>>;\n private globalSubscriptions: Array<Subscription<M, any>>;\n private middlewares: Middleware<M>[];\n\n /**\n * Creates a new Siggn instance.\n * @category Lifecycle\n * @since 0.0.5\n */\n constructor() {\n this.subscriptions = new Map();\n this.globalSubscriptions = [];\n this.middlewares = [];\n }\n\n use(mw: Middleware<M>) {\n this.middlewares.push(mw);\n }\n\n /**\n * Creates a new, independent `Siggn` instance that inherits the message\n * types of its parent and adds new ones.\n *\n * @template C The new message types to add.\n * @returns A new `Siggn` instance with combined message types.\n * @category Lifecycle\n * @since 0.0.5\n * @example\n * \n```typescript\n * const baseSiggn = new Siggn<{ type: 'A' }>();\n * const childSiggn = baseSiggn.createClone<{ type: 'B' }>();\n * // childSiggn can now publish and subscribe to types 'A' and 'B'.\n * ```\n */\n createClone<C extends Msg>() {\n return new Siggn<M | C>();\n }\n\n /**\n * Generates a unique ID for a subscriber.\n * If an ID is provided, it will be used; otherwise, a new one is generated.\n *\n * @param id An optional ID to use.\n * @returns A unique subscriber ID.\n * @category Utilities\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn();\n * const id1 = siggn.makeId(); // e.g., \"sub_0\"\n * const id2 = siggn.makeId('custom-id'); // \"custom-id\"\n * ```\n */\n makeId(id?: string): SiggnId {\n return id ?? `sub_${(this.nextId++).toString(36)}`;\n }\n\n /**\n * Creates a subscription helper object that is pre-configured with a\n * specific subscriber ID. This simplifies managing multiple subscriptions\n * for a single component or service.\n *\n * @param id The subscriber ID to use for all subscriptions.\n * @returns An object with `subscribe`, `unsubscribe`, `subscribeMany`, and `subscribeAll` methods.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'event' }>();\n * const component = siggn.make('my-component');\n * component.subscribe('event', () => console.log('event received!'));\n * component.unsubscribe();\n * ```\n */\n make(id: SiggnId): {\n subscribe: <T extends M['type']>(\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) => void;\n unsubscribe: () => void;\n subscribeMany: (\n setup: (\n subscribe: <T extends M['type']>(\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) => void,\n ) => void,\n ) => void;\n subscribeAll: (callback: (msg: M) => void) => void;\n } {\n return {\n subscribe: (type, callback) => {\n this.subscribe(id, type, callback);\n },\n unsubscribe: () => {\n this.unsubscribe(id);\n },\n subscribeMany: (setup) => {\n this.subscribeMany(id, setup);\n },\n subscribeAll: (callback) => {\n this.subscribeAll(id, callback);\n },\n };\n }\n\n /**\n * Subscribes to multiple message types using a single subscriber ID.\n *\n * @param id The subscriber ID.\n * @param setup A function that receives a `subscribe` helper to register callbacks.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();\n * siggn.subscribeMany('subscriber-1', (subscribe) => {\n * subscribe('A', () => console.log('A received'));\n * subscribe('B', () => console.log('B received'));\n * });\n * ```\n */\n subscribeMany(\n id: SiggnId,\n setup: (\n subscribe: <T extends M['type']>(\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) => void,\n ) => void,\n ) {\n setup((type, callback) => this.subscribe(id, type, callback));\n }\n\n /**\n * Subscribes to a specific message type.\n *\n * @param id The subscriber ID.\n * @param type The message type to subscribe to.\n * @param callback The function to call when a message of the specified type is published.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event', payload: string }>();\n * siggn.subscribe('subscriber-1', 'my-event', (msg) => {\n * console.log(msg.payload);\n * });\n * ```\n */\n subscribe<T extends M['type']>(\n id: SiggnId,\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) {\n if (!this.subscriptions.has(type)) {\n this.subscriptions.set(type, []);\n }\n\n this.subscriptions.get(type)?.push({ id, ref: callback });\n }\n\n /**\n * Subscribes to all message types. The callback will be invoked for every\n * message published on the bus.\n *\n * @param id The subscriber ID.\n * @param callback The function to call for any message.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();\n * siggn.subscribeAll('logger', (msg) => {\n * console.log(`Received message of type: ${msg.type}`);\n * });\n * ```\n */\n subscribeAll(id: SiggnId, callback: (msg: M) => void) {\n this.globalSubscriptions.push({ id, ref: callback });\n }\n\n /**\n * Publishes a message to all relevant subscribers.\n *\n * @param msg The message to publish.\n * @category Publishing\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event' }>();\n * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));\n * siggn.publish({ type: 'my-event' }); // \"received\"\n * ```\n */\n publish(msg: M) {\n this.globalSubscriptions.forEach((sub) => {\n sub.ref(msg as Extract<M, { type: any }>);\n });\n\n if (!this.subscriptions.has(msg.type)) {\n return;\n }\n\n this.subscriptions.get(msg.type)?.forEach((sub) => {\n sub.ref(msg as Extract<M, { type: any }>);\n });\n }\n\n /**\n * Removes all subscriptions (both specific and global) for a given\n * subscriber ID.\n *\n * @param id The subscriber ID to unsubscribe.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event' }>();\n * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));\n * siggn.unsubscribe('sub-1');\n * siggn.publish({ type: 'my-event' }); // (nothing is logged)\n * ```\n */\n unsubscribe(id: SiggnId) {\n this.unsubscribeGlobal(id);\n\n for (const [type, subscriptions] of this.subscriptions) {\n this.subscriptions.set(\n type,\n subscriptions.filter((sub) => sub.id !== id),\n );\n }\n }\n\n /**\n * Removes a global subscription for a given subscriber ID.\n *\n * @param id The subscriber ID to unsubscribe.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event' }>();\n * siggn.subscribeAll('logger', console.log);\n * siggn.unsubscribeGlobal('logger');\n * siggn.publish({ type: 'my-event' }); // (nothing is logged)\n * ```\n */\n unsubscribeGlobal(id: SiggnId) {\n this.globalSubscriptions = this.globalSubscriptions.filter((s) => s.id !== id);\n }\n}\n"],"names":["Siggn","mw","id","type","callback","setup","msg","sub","subscriptions","s"],"mappings":"gFAOO,MAAMA,CAAqB,CACxB,OAAS,EACT,cACA,oBACA,YAOR,aAAc,CACZ,KAAK,kBAAoB,IACzB,KAAK,oBAAsB,CAAA,EAC3B,KAAK,YAAc,CAAA,CACrB,CAEA,IAAIC,EAAmB,CACrB,KAAK,YAAY,KAAKA,CAAE,CAC1B,CAkBA,aAA6B,CAC3B,OAAO,IAAID,CACb,CAkBA,OAAOE,EAAsB,CAC3B,OAAOA,GAAM,QAAQ,KAAK,UAAU,SAAS,EAAE,CAAC,EAClD,CAoBA,KAAKA,EAeH,CACA,MAAO,CACL,UAAW,CAACC,EAAMC,IAAa,CAC7B,KAAK,UAAUF,EAAIC,EAAMC,CAAQ,CACnC,EACA,YAAa,IAAM,CACjB,KAAK,YAAYF,CAAE,CACrB,EACA,cAAgBG,GAAU,CACxB,KAAK,cAAcH,EAAIG,CAAK,CAC9B,EACA,aAAeD,GAAa,CAC1B,KAAK,aAAaF,EAAIE,CAAQ,CAChC,CAAA,CAEJ,CAmBA,cACEF,EACAG,EAMA,CACAA,EAAM,CAACF,EAAMC,IAAa,KAAK,UAAUF,EAAIC,EAAMC,CAAQ,CAAC,CAC9D,CAmBA,UACEF,EACAC,EACAC,EACA,CACK,KAAK,cAAc,IAAID,CAAI,GAC9B,KAAK,cAAc,IAAIA,EAAM,CAAA,CAAE,EAGjC,KAAK,cAAc,IAAIA,CAAI,GAAG,KAAK,CAAE,GAAAD,EAAI,IAAKE,EAAU,CAC1D,CAmBA,aAAaF,EAAaE,EAA4B,CACpD,KAAK,oBAAoB,KAAK,CAAE,GAAAF,EAAI,IAAKE,EAAU,CACrD,CAgBA,QAAQE,EAAQ,CACd,KAAK,oBAAoB,QAASC,GAAQ,CACxCA,EAAI,IAAID,CAAgC,CAC1C,CAAC,EAEI,KAAK,cAAc,IAAIA,EAAI,IAAI,GAIpC,KAAK,cAAc,IAAIA,EAAI,IAAI,GAAG,QAASC,GAAQ,CACjDA,EAAI,IAAID,CAAgC,CAC1C,CAAC,CACH,CAkBA,YAAYJ,EAAa,CACvB,KAAK,kBAAkBA,CAAE,EAEzB,SAAW,CAACC,EAAMK,CAAa,IAAK,KAAK,cACvC,KAAK,cAAc,IACjBL,EACAK,EAAc,OAAQD,GAAQA,EAAI,KAAOL,CAAE,CAAA,CAGjD,CAiBA,kBAAkBA,EAAa,CAC7B,KAAK,oBAAsB,KAAK,oBAAoB,OAAQO,GAAMA,EAAE,KAAOP,CAAE,CAC/E,CACF"}
package/dist/index.es.js CHANGED
@@ -1,56 +1,214 @@
1
1
  class r {
2
2
  nextId = 0;
3
3
  subscriptions;
4
- subscribeAllSubscriptions = [];
4
+ globalSubscriptions;
5
+ middlewares;
6
+ /**
7
+ * Creates a new Siggn instance.
8
+ * @category Lifecycle
9
+ * @since 0.0.5
10
+ */
5
11
  constructor() {
6
- this.subscriptions = /* @__PURE__ */ new Map();
12
+ this.subscriptions = /* @__PURE__ */ new Map(), this.globalSubscriptions = [], this.middlewares = [];
7
13
  }
14
+ use(s) {
15
+ this.middlewares.push(s);
16
+ }
17
+ /**
18
+ * Creates a new, independent `Siggn` instance that inherits the message
19
+ * types of its parent and adds new ones.
20
+ *
21
+ * @template C The new message types to add.
22
+ * @returns A new `Siggn` instance with combined message types.
23
+ * @category Lifecycle
24
+ * @since 0.0.5
25
+ * @example
26
+ *
27
+ ```typescript
28
+ * const baseSiggn = new Siggn<{ type: 'A' }>();
29
+ * const childSiggn = baseSiggn.createClone<{ type: 'B' }>();
30
+ * // childSiggn can now publish and subscribe to types 'A' and 'B'.
31
+ * ```
32
+ */
8
33
  createClone() {
9
34
  return new r();
10
35
  }
11
- makeId(i) {
12
- return i ?? `sub_${(this.nextId++).toString(36)}`;
36
+ /**
37
+ * Generates a unique ID for a subscriber.
38
+ * If an ID is provided, it will be used; otherwise, a new one is generated.
39
+ *
40
+ * @param id An optional ID to use.
41
+ * @returns A unique subscriber ID.
42
+ * @category Utilities
43
+ * @since 0.0.5
44
+ * @example
45
+ *
46
+ ```typescript
47
+ * const siggn = new Siggn();
48
+ * const id1 = siggn.makeId(); // e.g., "sub_0"
49
+ * const id2 = siggn.makeId('custom-id'); // "custom-id"
50
+ * ```
51
+ */
52
+ makeId(s) {
53
+ return s ?? `sub_${(this.nextId++).toString(36)}`;
13
54
  }
14
- make(i) {
55
+ /**
56
+ * Creates a subscription helper object that is pre-configured with a
57
+ * specific subscriber ID. This simplifies managing multiple subscriptions
58
+ * for a single component or service.
59
+ *
60
+ * @param id The subscriber ID to use for all subscriptions.
61
+ * @returns An object with `subscribe`, `unsubscribe`, `subscribeMany`, and `subscribeAll` methods.
62
+ * @category Subscription
63
+ * @since 0.0.5
64
+ * @example
65
+ *
66
+ ```typescript
67
+ * const siggn = new Siggn<{ type: 'event' }>();
68
+ * const component = siggn.make('my-component');
69
+ * component.subscribe('event', () => console.log('event received!'));
70
+ * component.unsubscribe();
71
+ * ```
72
+ */
73
+ make(s) {
15
74
  return {
16
- subscribe: (s, b) => {
17
- this.subscribe(i, s, b);
75
+ subscribe: (i, t) => {
76
+ this.subscribe(s, i, t);
18
77
  },
19
78
  unsubscribe: () => {
20
- this.unsubscribe(i);
79
+ this.unsubscribe(s);
21
80
  },
22
- subscribeMany: (s) => {
23
- this.subscribeMany(i, s);
81
+ subscribeMany: (i) => {
82
+ this.subscribeMany(s, i);
24
83
  },
25
- subscribeAll: (s) => {
26
- this.subscribeAll(i, s);
84
+ subscribeAll: (i) => {
85
+ this.subscribeAll(s, i);
27
86
  }
28
87
  };
29
88
  }
30
- subscribeMany(i, s) {
31
- s((b, t) => this.subscribe(i, b, t));
89
+ /**
90
+ * Subscribes to multiple message types using a single subscriber ID.
91
+ *
92
+ * @param id The subscriber ID.
93
+ * @param setup A function that receives a `subscribe` helper to register callbacks.
94
+ * @category Subscription
95
+ * @since 0.0.5
96
+ * @example
97
+ *
98
+ ```typescript
99
+ * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();
100
+ * siggn.subscribeMany('subscriber-1', (subscribe) => {
101
+ * subscribe('A', () => console.log('A received'));
102
+ * subscribe('B', () => console.log('B received'));
103
+ * });
104
+ * ```
105
+ */
106
+ subscribeMany(s, i) {
107
+ i((t, b) => this.subscribe(s, t, b));
32
108
  }
33
- subscribe(i, s, b) {
34
- this.subscriptions.has(s) || this.subscriptions.set(s, []), this.subscriptions.get(s)?.push({ id: i, callback: b });
109
+ /**
110
+ * Subscribes to a specific message type.
111
+ *
112
+ * @param id The subscriber ID.
113
+ * @param type The message type to subscribe to.
114
+ * @param callback The function to call when a message of the specified type is published.
115
+ * @category Subscription
116
+ * @since 0.0.5
117
+ * @example
118
+ *
119
+ ```typescript
120
+ * const siggn = new Siggn<{ type: 'my-event', payload: string }>();
121
+ * siggn.subscribe('subscriber-1', 'my-event', (msg) => {
122
+ * console.log(msg.payload);
123
+ * });
124
+ * ```
125
+ */
126
+ subscribe(s, i, t) {
127
+ this.subscriptions.has(i) || this.subscriptions.set(i, []), this.subscriptions.get(i)?.push({ id: s, ref: t });
35
128
  }
36
- subscribeAll(i, s) {
37
- this.subscribeAllSubscriptions.push({ id: i, callback: s });
129
+ /**
130
+ * Subscribes to all message types. The callback will be invoked for every
131
+ * message published on the bus.
132
+ *
133
+ * @param id The subscriber ID.
134
+ * @param callback The function to call for any message.
135
+ * @category Subscription
136
+ * @since 0.0.5
137
+ * @example
138
+ *
139
+ ```typescript
140
+ * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();
141
+ * siggn.subscribeAll('logger', (msg) => {
142
+ * console.log(`Received message of type: ${msg.type}`);
143
+ * });
144
+ * ```
145
+ */
146
+ subscribeAll(s, i) {
147
+ this.globalSubscriptions.push({ id: s, ref: i });
38
148
  }
39
- publish(i) {
40
- this.subscribeAllSubscriptions.forEach((s) => {
41
- s.callback(i);
42
- }), this.subscriptions.has(i.type) && this.subscriptions.get(i.type)?.forEach((s) => {
43
- s.callback(i);
149
+ /**
150
+ * Publishes a message to all relevant subscribers.
151
+ *
152
+ * @param msg The message to publish.
153
+ * @category Publishing
154
+ * @since 0.0.5
155
+ * @example
156
+ *
157
+ ```typescript
158
+ * const siggn = new Siggn<{ type: 'my-event' }>();
159
+ * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));
160
+ * siggn.publish({ type: 'my-event' }); // "received"
161
+ * ```
162
+ */
163
+ publish(s) {
164
+ this.globalSubscriptions.forEach((i) => {
165
+ i.ref(s);
166
+ }), this.subscriptions.has(s.type) && this.subscriptions.get(s.type)?.forEach((i) => {
167
+ i.ref(s);
44
168
  });
45
169
  }
46
- unsubscribe(i) {
47
- this.subscribeAllSubscriptions = this.subscribeAllSubscriptions.filter((s) => s.id !== i);
48
- for (const [s, b] of this.subscriptions)
170
+ /**
171
+ * Removes all subscriptions (both specific and global) for a given
172
+ * subscriber ID.
173
+ *
174
+ * @param id The subscriber ID to unsubscribe.
175
+ * @category Subscription
176
+ * @since 0.0.5
177
+ * @example
178
+ *
179
+ ```typescript
180
+ * const siggn = new Siggn<{ type: 'my-event' }>();
181
+ * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));
182
+ * siggn.unsubscribe('sub-1');
183
+ * siggn.publish({ type: 'my-event' }); // (nothing is logged)
184
+ * ```
185
+ */
186
+ unsubscribe(s) {
187
+ this.unsubscribeGlobal(s);
188
+ for (const [i, t] of this.subscriptions)
49
189
  this.subscriptions.set(
50
- s,
51
- b.filter((t) => t.id !== i)
190
+ i,
191
+ t.filter((b) => b.id !== s)
52
192
  );
53
193
  }
194
+ /**
195
+ * Removes a global subscription for a given subscriber ID.
196
+ *
197
+ * @param id The subscriber ID to unsubscribe.
198
+ * @category Subscription
199
+ * @since 0.0.5
200
+ * @example
201
+ *
202
+ ```typescript
203
+ * const siggn = new Siggn<{ type: 'my-event' }>();
204
+ * siggn.subscribeAll('logger', console.log);
205
+ * siggn.unsubscribeGlobal('logger');
206
+ * siggn.publish({ type: 'my-event' }); // (nothing is logged)
207
+ * ```
208
+ */
209
+ unsubscribeGlobal(s) {
210
+ this.globalSubscriptions = this.globalSubscriptions.filter((i) => i.id !== s);
211
+ }
54
212
  }
55
213
  export {
56
214
  r as Siggn
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/siggn.ts"],"sourcesContent":["import type { Msg, Subscription, SiggnId } from './types.js';\n\nexport class Siggn<T extends Msg> {\n private nextId = 0;\n private subscriptions: Map<T['type'], Array<Subscription<T, any>>>;\n private subscribeAllSubscriptions: Array<Subscription<T, any>> = [];\n\n constructor() {\n this.subscriptions = new Map();\n }\n\n createClone<C extends Msg>() {\n return new Siggn<C | T>();\n }\n\n makeId(id?: string): SiggnId {\n return id ?? `sub_${(this.nextId++).toString(36)}`;\n }\n\n make(id: SiggnId): {\n subscribe: <K extends T['type']>(\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) => void;\n unsubscribe: () => void;\n subscribeMany: (\n setup: (\n subscribe: <K extends T['type']>(\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) => void,\n ) => void,\n ) => void;\n subscribeAll: (callback: (msg: T) => void) => void;\n } {\n return {\n subscribe: (type, callback) => {\n this.subscribe(id, type, callback);\n },\n unsubscribe: () => {\n this.unsubscribe(id);\n },\n subscribeMany: (setup) => {\n this.subscribeMany(id, setup);\n },\n subscribeAll: (callback) => {\n this.subscribeAll(id, callback);\n },\n };\n }\n\n subscribeMany(\n id: SiggnId,\n setup: (\n subscribe: <K extends T['type']>(\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) => void,\n ) => void,\n ) {\n setup((type, callback) => this.subscribe(id, type, callback));\n }\n\n subscribe<K extends T['type']>(\n id: SiggnId,\n type: K,\n callback: (msg: Extract<T, { type: K }>) => void,\n ) {\n if (!this.subscriptions.has(type)) {\n this.subscriptions.set(type, []);\n }\n\n this.subscriptions.get(type)?.push({ id, callback });\n }\n\n subscribeAll(id: SiggnId, callback: (msg: T) => void) {\n this.subscribeAllSubscriptions.push({ id, callback });\n }\n\n publish(msg: T) {\n this.subscribeAllSubscriptions.forEach((sub) => {\n sub.callback(msg as Extract<T, { type: any }>);\n });\n\n if (!this.subscriptions.has(msg.type)) {\n return;\n }\n\n this.subscriptions.get(msg.type)?.forEach((sub) => {\n sub.callback(msg as Extract<T, { type: any }>);\n });\n }\n\n unsubscribe(id: SiggnId) {\n this.subscribeAllSubscriptions = this.subscribeAllSubscriptions.filter((s) => s.id !== id);\n\n for (const [type, subscriptions] of this.subscriptions) {\n this.subscriptions.set(\n type,\n subscriptions.filter((sub) => sub.id !== id),\n );\n }\n }\n}\n"],"names":["Siggn","id","type","callback","setup","msg","sub","subscriptions"],"mappings":"AAEO,MAAMA,EAAqB;AAAA,EACxB,SAAS;AAAA,EACT;AAAA,EACA,4BAAyD,CAAA;AAAA,EAEjE,cAAc;AACZ,SAAK,oCAAoB,IAAA;AAAA,EAC3B;AAAA,EAEA,cAA6B;AAC3B,WAAO,IAAIA,EAAA;AAAA,EACb;AAAA,EAEA,OAAOC,GAAsB;AAC3B,WAAOA,KAAM,QAAQ,KAAK,UAAU,SAAS,EAAE,CAAC;AAAA,EAClD;AAAA,EAEA,KAAKA,GAeH;AACA,WAAO;AAAA,MACL,WAAW,CAACC,GAAMC,MAAa;AAC7B,aAAK,UAAUF,GAAIC,GAAMC,CAAQ;AAAA,MACnC;AAAA,MACA,aAAa,MAAM;AACjB,aAAK,YAAYF,CAAE;AAAA,MACrB;AAAA,MACA,eAAe,CAACG,MAAU;AACxB,aAAK,cAAcH,GAAIG,CAAK;AAAA,MAC9B;AAAA,MACA,cAAc,CAACD,MAAa;AAC1B,aAAK,aAAaF,GAAIE,CAAQ;AAAA,MAChC;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEA,cACEF,GACAG,GAMA;AACA,IAAAA,EAAM,CAACF,GAAMC,MAAa,KAAK,UAAUF,GAAIC,GAAMC,CAAQ,CAAC;AAAA,EAC9D;AAAA,EAEA,UACEF,GACAC,GACAC,GACA;AACA,IAAK,KAAK,cAAc,IAAID,CAAI,KAC9B,KAAK,cAAc,IAAIA,GAAM,CAAA,CAAE,GAGjC,KAAK,cAAc,IAAIA,CAAI,GAAG,KAAK,EAAE,IAAAD,GAAI,UAAAE,GAAU;AAAA,EACrD;AAAA,EAEA,aAAaF,GAAaE,GAA4B;AACpD,SAAK,0BAA0B,KAAK,EAAE,IAAAF,GAAI,UAAAE,GAAU;AAAA,EACtD;AAAA,EAEA,QAAQE,GAAQ;AAKd,IAJA,KAAK,0BAA0B,QAAQ,CAACC,MAAQ;AAC9C,MAAAA,EAAI,SAASD,CAAgC;AAAA,IAC/C,CAAC,GAEI,KAAK,cAAc,IAAIA,EAAI,IAAI,KAIpC,KAAK,cAAc,IAAIA,EAAI,IAAI,GAAG,QAAQ,CAACC,MAAQ;AACjD,MAAAA,EAAI,SAASD,CAAgC;AAAA,IAC/C,CAAC;AAAA,EACH;AAAA,EAEA,YAAYJ,GAAa;AACvB,SAAK,4BAA4B,KAAK,0BAA0B,OAAO,CAAC,MAAM,EAAE,OAAOA,CAAE;AAEzF,eAAW,CAACC,GAAMK,CAAa,KAAK,KAAK;AACvC,WAAK,cAAc;AAAA,QACjBL;AAAA,QACAK,EAAc,OAAO,CAACD,MAAQA,EAAI,OAAOL,CAAE;AAAA,MAAA;AAAA,EAGjD;AACF;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/siggn.ts"],"sourcesContent":["import type { Msg, Subscription, SiggnId, Middleware } from './types.js';\n\n/**\n * A type-safe message bus for dispatching and subscribing to events.\n * @template T A union of all possible message types.\n * @since 0.0.5\n */\nexport class Siggn<M extends Msg> {\n private nextId = 0;\n private subscriptions: Map<M['type'], Array<Subscription<M, any>>>;\n private globalSubscriptions: Array<Subscription<M, any>>;\n private middlewares: Middleware<M>[];\n\n /**\n * Creates a new Siggn instance.\n * @category Lifecycle\n * @since 0.0.5\n */\n constructor() {\n this.subscriptions = new Map();\n this.globalSubscriptions = [];\n this.middlewares = [];\n }\n\n use(mw: Middleware<M>) {\n this.middlewares.push(mw);\n }\n\n /**\n * Creates a new, independent `Siggn` instance that inherits the message\n * types of its parent and adds new ones.\n *\n * @template C The new message types to add.\n * @returns A new `Siggn` instance with combined message types.\n * @category Lifecycle\n * @since 0.0.5\n * @example\n * \n```typescript\n * const baseSiggn = new Siggn<{ type: 'A' }>();\n * const childSiggn = baseSiggn.createClone<{ type: 'B' }>();\n * // childSiggn can now publish and subscribe to types 'A' and 'B'.\n * ```\n */\n createClone<C extends Msg>() {\n return new Siggn<M | C>();\n }\n\n /**\n * Generates a unique ID for a subscriber.\n * If an ID is provided, it will be used; otherwise, a new one is generated.\n *\n * @param id An optional ID to use.\n * @returns A unique subscriber ID.\n * @category Utilities\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn();\n * const id1 = siggn.makeId(); // e.g., \"sub_0\"\n * const id2 = siggn.makeId('custom-id'); // \"custom-id\"\n * ```\n */\n makeId(id?: string): SiggnId {\n return id ?? `sub_${(this.nextId++).toString(36)}`;\n }\n\n /**\n * Creates a subscription helper object that is pre-configured with a\n * specific subscriber ID. This simplifies managing multiple subscriptions\n * for a single component or service.\n *\n * @param id The subscriber ID to use for all subscriptions.\n * @returns An object with `subscribe`, `unsubscribe`, `subscribeMany`, and `subscribeAll` methods.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'event' }>();\n * const component = siggn.make('my-component');\n * component.subscribe('event', () => console.log('event received!'));\n * component.unsubscribe();\n * ```\n */\n make(id: SiggnId): {\n subscribe: <T extends M['type']>(\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) => void;\n unsubscribe: () => void;\n subscribeMany: (\n setup: (\n subscribe: <T extends M['type']>(\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) => void,\n ) => void,\n ) => void;\n subscribeAll: (callback: (msg: M) => void) => void;\n } {\n return {\n subscribe: (type, callback) => {\n this.subscribe(id, type, callback);\n },\n unsubscribe: () => {\n this.unsubscribe(id);\n },\n subscribeMany: (setup) => {\n this.subscribeMany(id, setup);\n },\n subscribeAll: (callback) => {\n this.subscribeAll(id, callback);\n },\n };\n }\n\n /**\n * Subscribes to multiple message types using a single subscriber ID.\n *\n * @param id The subscriber ID.\n * @param setup A function that receives a `subscribe` helper to register callbacks.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();\n * siggn.subscribeMany('subscriber-1', (subscribe) => {\n * subscribe('A', () => console.log('A received'));\n * subscribe('B', () => console.log('B received'));\n * });\n * ```\n */\n subscribeMany(\n id: SiggnId,\n setup: (\n subscribe: <T extends M['type']>(\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) => void,\n ) => void,\n ) {\n setup((type, callback) => this.subscribe(id, type, callback));\n }\n\n /**\n * Subscribes to a specific message type.\n *\n * @param id The subscriber ID.\n * @param type The message type to subscribe to.\n * @param callback The function to call when a message of the specified type is published.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event', payload: string }>();\n * siggn.subscribe('subscriber-1', 'my-event', (msg) => {\n * console.log(msg.payload);\n * });\n * ```\n */\n subscribe<T extends M['type']>(\n id: SiggnId,\n type: T,\n callback: (msg: Extract<M, { type: T }>) => void,\n ) {\n if (!this.subscriptions.has(type)) {\n this.subscriptions.set(type, []);\n }\n\n this.subscriptions.get(type)?.push({ id, ref: callback });\n }\n\n /**\n * Subscribes to all message types. The callback will be invoked for every\n * message published on the bus.\n *\n * @param id The subscriber ID.\n * @param callback The function to call for any message.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();\n * siggn.subscribeAll('logger', (msg) => {\n * console.log(`Received message of type: ${msg.type}`);\n * });\n * ```\n */\n subscribeAll(id: SiggnId, callback: (msg: M) => void) {\n this.globalSubscriptions.push({ id, ref: callback });\n }\n\n /**\n * Publishes a message to all relevant subscribers.\n *\n * @param msg The message to publish.\n * @category Publishing\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event' }>();\n * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));\n * siggn.publish({ type: 'my-event' }); // \"received\"\n * ```\n */\n publish(msg: M) {\n this.globalSubscriptions.forEach((sub) => {\n sub.ref(msg as Extract<M, { type: any }>);\n });\n\n if (!this.subscriptions.has(msg.type)) {\n return;\n }\n\n this.subscriptions.get(msg.type)?.forEach((sub) => {\n sub.ref(msg as Extract<M, { type: any }>);\n });\n }\n\n /**\n * Removes all subscriptions (both specific and global) for a given\n * subscriber ID.\n *\n * @param id The subscriber ID to unsubscribe.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event' }>();\n * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));\n * siggn.unsubscribe('sub-1');\n * siggn.publish({ type: 'my-event' }); // (nothing is logged)\n * ```\n */\n unsubscribe(id: SiggnId) {\n this.unsubscribeGlobal(id);\n\n for (const [type, subscriptions] of this.subscriptions) {\n this.subscriptions.set(\n type,\n subscriptions.filter((sub) => sub.id !== id),\n );\n }\n }\n\n /**\n * Removes a global subscription for a given subscriber ID.\n *\n * @param id The subscriber ID to unsubscribe.\n * @category Subscription\n * @since 0.0.5\n * @example\n * \n```typescript\n * const siggn = new Siggn<{ type: 'my-event' }>();\n * siggn.subscribeAll('logger', console.log);\n * siggn.unsubscribeGlobal('logger');\n * siggn.publish({ type: 'my-event' }); // (nothing is logged)\n * ```\n */\n unsubscribeGlobal(id: SiggnId) {\n this.globalSubscriptions = this.globalSubscriptions.filter((s) => s.id !== id);\n }\n}\n"],"names":["Siggn","mw","id","type","callback","setup","msg","sub","subscriptions","s"],"mappings":"AAOO,MAAMA,EAAqB;AAAA,EACxB,SAAS;AAAA,EACT;AAAA,EACA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,kBAAkBA,GAAa;AAC7B,SAAK,sBAAsB,KAAK,oBAAoB,OAAO,CAACO,MAAMA,EAAE,OAAOP,CAAE;AAAA,EAC/E;AACF;"}
package/dist/siggn.d.ts CHANGED
@@ -1,29 +1,188 @@
1
- import { Msg, SiggnId } from './types.js';
2
- export declare class Siggn<T extends Msg> {
1
+ import { Msg, SiggnId, Middleware } from './types.js';
2
+ /**
3
+ * A type-safe message bus for dispatching and subscribing to events.
4
+ * @template T A union of all possible message types.
5
+ * @since 0.0.5
6
+ */
7
+ export declare class Siggn<M extends Msg> {
3
8
  private nextId;
4
9
  private subscriptions;
5
- private subscribeAllSubscriptions;
10
+ private globalSubscriptions;
11
+ private middlewares;
12
+ /**
13
+ * Creates a new Siggn instance.
14
+ * @category Lifecycle
15
+ * @since 0.0.5
16
+ */
6
17
  constructor();
7
- createClone<C extends Msg>(): Siggn<T | C>;
18
+ use(mw: Middleware<M>): void;
19
+ /**
20
+ * Creates a new, independent `Siggn` instance that inherits the message
21
+ * types of its parent and adds new ones.
22
+ *
23
+ * @template C The new message types to add.
24
+ * @returns A new `Siggn` instance with combined message types.
25
+ * @category Lifecycle
26
+ * @since 0.0.5
27
+ * @example
28
+ *
29
+ ```typescript
30
+ * const baseSiggn = new Siggn<{ type: 'A' }>();
31
+ * const childSiggn = baseSiggn.createClone<{ type: 'B' }>();
32
+ * // childSiggn can now publish and subscribe to types 'A' and 'B'.
33
+ * ```
34
+ */
35
+ createClone<C extends Msg>(): Siggn<M | C>;
36
+ /**
37
+ * Generates a unique ID for a subscriber.
38
+ * If an ID is provided, it will be used; otherwise, a new one is generated.
39
+ *
40
+ * @param id An optional ID to use.
41
+ * @returns A unique subscriber ID.
42
+ * @category Utilities
43
+ * @since 0.0.5
44
+ * @example
45
+ *
46
+ ```typescript
47
+ * const siggn = new Siggn();
48
+ * const id1 = siggn.makeId(); // e.g., "sub_0"
49
+ * const id2 = siggn.makeId('custom-id'); // "custom-id"
50
+ * ```
51
+ */
8
52
  makeId(id?: string): SiggnId;
53
+ /**
54
+ * Creates a subscription helper object that is pre-configured with a
55
+ * specific subscriber ID. This simplifies managing multiple subscriptions
56
+ * for a single component or service.
57
+ *
58
+ * @param id The subscriber ID to use for all subscriptions.
59
+ * @returns An object with `subscribe`, `unsubscribe`, `subscribeMany`, and `subscribeAll` methods.
60
+ * @category Subscription
61
+ * @since 0.0.5
62
+ * @example
63
+ *
64
+ ```typescript
65
+ * const siggn = new Siggn<{ type: 'event' }>();
66
+ * const component = siggn.make('my-component');
67
+ * component.subscribe('event', () => console.log('event received!'));
68
+ * component.unsubscribe();
69
+ * ```
70
+ */
9
71
  make(id: SiggnId): {
10
- subscribe: <K extends T['type']>(type: K, callback: (msg: Extract<T, {
11
- type: K;
72
+ subscribe: <T extends M['type']>(type: T, callback: (msg: Extract<M, {
73
+ type: T;
12
74
  }>) => void) => void;
13
75
  unsubscribe: () => void;
14
- subscribeMany: (setup: (subscribe: <K extends T['type']>(type: K, callback: (msg: Extract<T, {
15
- type: K;
76
+ subscribeMany: (setup: (subscribe: <T extends M['type']>(type: T, callback: (msg: Extract<M, {
77
+ type: T;
16
78
  }>) => void) => void) => void) => void;
17
- subscribeAll: (callback: (msg: T) => void) => void;
79
+ subscribeAll: (callback: (msg: M) => void) => void;
18
80
  };
19
- subscribeMany(id: SiggnId, setup: (subscribe: <K extends T['type']>(type: K, callback: (msg: Extract<T, {
20
- type: K;
81
+ /**
82
+ * Subscribes to multiple message types using a single subscriber ID.
83
+ *
84
+ * @param id The subscriber ID.
85
+ * @param setup A function that receives a `subscribe` helper to register callbacks.
86
+ * @category Subscription
87
+ * @since 0.0.5
88
+ * @example
89
+ *
90
+ ```typescript
91
+ * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();
92
+ * siggn.subscribeMany('subscriber-1', (subscribe) => {
93
+ * subscribe('A', () => console.log('A received'));
94
+ * subscribe('B', () => console.log('B received'));
95
+ * });
96
+ * ```
97
+ */
98
+ subscribeMany(id: SiggnId, setup: (subscribe: <T extends M['type']>(type: T, callback: (msg: Extract<M, {
99
+ type: T;
21
100
  }>) => void) => void) => void): void;
22
- subscribe<K extends T['type']>(id: SiggnId, type: K, callback: (msg: Extract<T, {
23
- type: K;
101
+ /**
102
+ * Subscribes to a specific message type.
103
+ *
104
+ * @param id The subscriber ID.
105
+ * @param type The message type to subscribe to.
106
+ * @param callback The function to call when a message of the specified type is published.
107
+ * @category Subscription
108
+ * @since 0.0.5
109
+ * @example
110
+ *
111
+ ```typescript
112
+ * const siggn = new Siggn<{ type: 'my-event', payload: string }>();
113
+ * siggn.subscribe('subscriber-1', 'my-event', (msg) => {
114
+ * console.log(msg.payload);
115
+ * });
116
+ * ```
117
+ */
118
+ subscribe<T extends M['type']>(id: SiggnId, type: T, callback: (msg: Extract<M, {
119
+ type: T;
24
120
  }>) => void): void;
25
- subscribeAll(id: SiggnId, callback: (msg: T) => void): void;
26
- publish(msg: T): void;
121
+ /**
122
+ * Subscribes to all message types. The callback will be invoked for every
123
+ * message published on the bus.
124
+ *
125
+ * @param id The subscriber ID.
126
+ * @param callback The function to call for any message.
127
+ * @category Subscription
128
+ * @since 0.0.5
129
+ * @example
130
+ *
131
+ ```typescript
132
+ * const siggn = new Siggn<{ type: 'A' } | { type: 'B' }>();
133
+ * siggn.subscribeAll('logger', (msg) => {
134
+ * console.log(`Received message of type: ${msg.type}`);
135
+ * });
136
+ * ```
137
+ */
138
+ subscribeAll(id: SiggnId, callback: (msg: M) => void): void;
139
+ /**
140
+ * Publishes a message to all relevant subscribers.
141
+ *
142
+ * @param msg The message to publish.
143
+ * @category Publishing
144
+ * @since 0.0.5
145
+ * @example
146
+ *
147
+ ```typescript
148
+ * const siggn = new Siggn<{ type: 'my-event' }>();
149
+ * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));
150
+ * siggn.publish({ type: 'my-event' }); // "received"
151
+ * ```
152
+ */
153
+ publish(msg: M): void;
154
+ /**
155
+ * Removes all subscriptions (both specific and global) for a given
156
+ * subscriber ID.
157
+ *
158
+ * @param id The subscriber ID to unsubscribe.
159
+ * @category Subscription
160
+ * @since 0.0.5
161
+ * @example
162
+ *
163
+ ```typescript
164
+ * const siggn = new Siggn<{ type: 'my-event' }>();
165
+ * siggn.subscribe('sub-1', 'my-event', () => console.log('received'));
166
+ * siggn.unsubscribe('sub-1');
167
+ * siggn.publish({ type: 'my-event' }); // (nothing is logged)
168
+ * ```
169
+ */
27
170
  unsubscribe(id: SiggnId): void;
171
+ /**
172
+ * Removes a global subscription for a given subscriber ID.
173
+ *
174
+ * @param id The subscriber ID to unsubscribe.
175
+ * @category Subscription
176
+ * @since 0.0.5
177
+ * @example
178
+ *
179
+ ```typescript
180
+ * const siggn = new Siggn<{ type: 'my-event' }>();
181
+ * siggn.subscribeAll('logger', console.log);
182
+ * siggn.unsubscribeGlobal('logger');
183
+ * siggn.publish({ type: 'my-event' }); // (nothing is logged)
184
+ * ```
185
+ */
186
+ unsubscribeGlobal(id: SiggnId): void;
28
187
  }
29
188
  //# sourceMappingURL=siggn.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"siggn.d.ts","sourceRoot":"","sources":["../src/siggn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAgB,OAAO,EAAE,MAAM,YAAY,CAAC;AAE7D,qBAAa,KAAK,CAAC,CAAC,SAAS,GAAG;IAC9B,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,aAAa,CAA8C;IACnE,OAAO,CAAC,yBAAyB,CAAmC;;IAMpE,WAAW,CAAC,CAAC,SAAS,GAAG;IAIzB,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAI5B,IAAI,CAAC,EAAE,EAAE,OAAO,GAAG;QACjB,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC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AK,IAAI,CAAC;KACpD;IAiBD;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,CACX,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,CACL,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAC7B,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,IAAI,KAC7C,IAAI,KACN,IAAI;IAKX;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAC3B,EAAE,EAAE,OAAO,EACX,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,IAAI;IASlD;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI;IAIpD;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,GAAG,EAAE,CAAC;IAcd;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,EAAE,OAAO;IAWvB;;;;;;;;;;;;;;OAcG;IACH,iBAAiB,CAAC,EAAE,EAAE,OAAO;CAG9B"}
package/dist/types.d.ts CHANGED
@@ -2,14 +2,15 @@ export type Msg = {
2
2
  type: string;
3
3
  [key: string]: unknown;
4
4
  };
5
- export type Subscription<T extends Msg, K extends T['type']> = {
5
+ export type Subscription<M extends Msg, T extends M['type']> = {
6
6
  id: string;
7
- callback: (msg: Extract<T, {
8
- type: K;
7
+ ref: (msg: Extract<M, {
8
+ type: T;
9
9
  }>) => void;
10
10
  };
11
11
  export type SubscriptionMap<T extends Msg> = {
12
12
  [K in T['type']]: Array<Subscription<T, K>>;
13
13
  };
14
14
  export type SiggnId = string;
15
+ export type Middleware<M extends Msg> = (msg: M, next: () => void) => void | Promise<void>;
15
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI;KAC1C,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI;KAC1C,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siggn/core",
3
- "version": "0.0.5",
3
+ "version": "0.1.1",
4
4
  "description": "A lightweight message bus system for Typescript",
5
5
  "keywords": [
6
6
  "pub/sub",
@@ -52,6 +52,7 @@
52
52
  "dev": "vite build --watch",
53
53
  "clean": "rm -rf dist",
54
54
  "test": "vitest run",
55
+ "coverage": "vitest run --coverage",
55
56
  "build": "vite build"
56
57
  }
57
58
  }