zodbus 1.1.1 → 1.1.3
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/dist/bus.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +4 -4
- package/package.json +1 -1
package/dist/bus.d.ts
CHANGED
|
@@ -27,4 +27,6 @@ declare function create<T extends Schema>({ schema, validate }: BusOptions<T>):
|
|
|
27
27
|
export type InferBusType<T extends Schema> = ReturnType<typeof create<T>>;
|
|
28
28
|
export type InferPublishHandler<T extends Schema> = InferBusType<T>["publish"];
|
|
29
29
|
export type InferSubscribeHandler<T extends Schema> = InferBusType<T>["subscribe"];
|
|
30
|
+
export type InferSubscriptionKey<T extends Schema> = SubscriptionKey<T>;
|
|
31
|
+
export type InferPublishKey<T extends Schema> = PublishKey<T>;
|
|
30
32
|
export { create };
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var O=(i,s)=>{for(var u in s)h(i,u,{get:s[u],enumerable:!0})},E=(i,s,u,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of k(s))!I.call(i,t)&&t!==u&&h(i,t,{get:()=>s[t],enumerable:!(a=$(s,t))||a.enumerable});return i};var R=i=>E(h({},"__esModule",{value:!0}),i);var N={};O(N,{create:()=>B});module.exports=R(N);var v=require("zod");var y="[zodbus] ";var l=class extends Error{constructor(s){super(`${y}${s}`),this.name="ValidationError"}},K=class extends Error{constructor(s){super(`${y}${s}`),this.name="RuntimeError"}};var L=(i,s="")=>{let u=[];for(let[a,t]of Object.entries(i)){let p=s?`${s}.${a}`:a;typeof t.parse=="function"?u.push(p):u.push(...L(t,p))}return u},m=(i,s="")=>{let u=[];for(let[a,t]of Object.entries(i)){let p=s?`${s}.${a}`:a,d=s?`${s}.*`:"*";typeof t.parse=="function"?u.push(p,d):u.push(...m(t,p),...m(t,d))}return u},w=i=>{let s={},u=L(i),a=m(i);for(let t of a){let p=t.split(".");s[t]=u.filter(d=>{let b=d.split(".");if(b.length!==p.length)return!1;for(let[f,P]of b.entries())if(p[f]!=="*"&&P!==p[f])return!1;return!0})}return s};function B({schema:i,validate:s=!0}){let u=w(i),a=Array.from(new Set(Object.values(u).flat())),t=new Map,p=e=>{if(e==="*")return Array.from(t.values());let n=[],o=u[e];if(!o)throw new l(`Invalid event: "${e}"`);for(let r of o){let c=t.get(r);c&&n.push(c)}return n},d=(e,n)=>{let o=e.split("."),r=i;for(let c of o)if(r=r[c],!r)throw new l(`Invalid event: "${e}". Could not resolve "${c}" fragment.`);if(r instanceof v.ZodType)r.parse(n);else throw new l(`Reached invalid payload schema for: "${e}"`)},b=(e,n)=>{let o=p(e);for(let r of o)n===void 0?r.clear():r.delete(n)},f=(e,n)=>{var r;if(typeof n!="function")throw new l(`Invalid listener for event: "${e}". Expected function, got ${typeof n}`);let o=e==="*"?a:u[e];if(!o)throw new l(`Invalid event: "${e}"`);for(let c of o){let T=(r=t.get(c))!=null?r:new Set;T.add(n),t.set(c,T)}return{event:e,listener:n,unsubscribe:()=>b(e,n)}};return{publish:(e,n)=>{if(s&&d(e,n),!!t.has(e))for(let o of t.get(e))o(n,e)},subscribe:f,subscribeOnce:(e,n)=>{let o=(r,c)=>{n(r,c),b(e,o)};return f(e,o)},unsubscribe:b,getEventNames:()=>a,getListeners:e=>{let n=[],o=e?p(e):Array.from(t.values());for(let r of o)for(let c of r)n.push(c);return n},waitFor:(e,n={})=>{let{timeout:o=5e3,filter:r}=n;return new Promise((c,T)=>{let g,S=x=>{r&&!r(x)||(b(e,S),c(x),clearTimeout(g))};f(e,S),o&&(g=setTimeout(()=>{b(e,S),T(new K(`Timeout waiting for event: "${e}"`))},o))})}}}
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../src/
|
|
4
|
-
"sourcesContent": ["export * from \"./bus\";\n", "export const errorPrefix = \"[zodbus] \";\n", "import { errorPrefix } from \"./constants\";\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"ValidationError\";\n }\n}\n\nexport class RuntimeError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"RuntimeError\";\n }\n}\n", "import { ZodType } from \"zod\";\nimport { Schema } from \"../types\";\n\nexport const hasWildcard = (path: string): boolean => path.split(\".\").includes(\"*\");\n\nexport const getPublishPaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix);\n } else {\n paths.push(...getPublishPaths(v, newPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubscribePaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n const newWildcardPrefix = prefix ? `${prefix}.*` : \"*\";\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix, newWildcardPrefix);\n } else {\n paths.push(...getSubscribePaths(v, newPrefix), ...getSubscribePaths(v, newWildcardPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubPubPathMap = (schema: Schema | ZodType): Record<string, string[]> => {\n const map: Record<string, string[]> = {};\n const publishPaths = getPublishPaths(schema);\n const subscribePaths = getSubscribePaths(schema);\n\n for (const subscribePath of subscribePaths) {\n const subscribeParts = subscribePath.split(\".\");\n map[subscribePath] = publishPaths.filter((publishPath) => {\n const publishParts = publishPath.split(\".\");\n if (publishParts.length !== subscribeParts.length) return false;\n for (const [i, publishPart] of publishParts.entries()) {\n if (subscribeParts[i] !== \"*\" && publishPart !== subscribeParts[i]) return false;\n }\n return true;\n });\n }\n\n return map;\n};\n", "import { ZodType, z } from \"zod\";\nimport { RuntimeError, ValidationError } from \"./errors\";\nimport type { PublishKey, Schema, SubscriptionKey, SubscriptionListenerPayloads, SubscriptionListeners } from \"./types\";\nimport { getSubPubPathMap } from \"./utils/schema\";\n\ntype BusOptions<T extends Schema> = {\n schema: T;\n validate?: boolean;\n};\n\ninterface Bus<T extends Schema> {\n publish: <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => void;\n subscribe: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n subscribeOnce: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n unsubscribe: <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]) => void;\n getEventNames: () => PublishKey<T>[];\n getListeners: <K extends SubscriptionKey<T>>(event?: K) => ((data: unknown, eventName: string) => void)[];\n waitFor: <K extends SubscriptionKey<T>>(\n event: K,\n options?: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean }\n ) => Promise<SubscriptionListenerPayloads<T>[K]>;\n}\n\nfunction create<T extends Schema>({ schema, validate = true }: BusOptions<T>): Bus<T> {\n const subPubPathMap = getSubPubPathMap(schema) as Record<SubscriptionKey<T>, PublishKey<T>[]>;\n const eventNames = Array.from(new Set(Object.values(subPubPathMap).flat())) as PublishKey<T>[];\n const listeners = new Map<PublishKey<T>, Set<SubscriptionListeners<T>[PublishKey<T>]>>();\n\n const getListenerSetsForSubscriptionKey = (event: SubscriptionKey<T>): Set<unknown>[] => {\n if (event === \"*\") return Array.from(listeners.values());\n const listenerSets: Set<SubscriptionListeners<T>[PublishKey<T>]>[] = [];\n const publishPaths = subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath);\n if (listenerSet) listenerSets.push(listenerSet);\n }\n return listenerSets;\n };\n\n const validatePayloadOrPanic = (event: string, data: unknown): void => {\n const pathFragments = event.split(\".\");\n let currentSchema: Schema | ZodType = schema;\n for (const fragment of pathFragments) {\n currentSchema = (currentSchema as Record<string, Schema | ZodType>)[fragment];\n if (!currentSchema) {\n throw new ValidationError(`Invalid event: \"${event}\". Could not resolve \"${fragment}\" fragment.`);\n }\n }\n if (\"constructor\" in currentSchema && [\"ZodType\", \"ZodObject\"].includes(currentSchema.constructor.name)) {\n (currentSchema as ZodType).parse(data);\n } else {\n throw new ValidationError(`Reached invalid payload schema for: \"${event}\"`);\n }\n };\n\n /** Unsubscribe from an event. If no listener is provided, all listeners for the event will be removed.\n * @param event The event to unsubscribe from. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to remove. If no listener is provided, all listeners for the event will be removed.\n *\n * Examples:\n * - `unsubscribe(\"foo.bar\", listener)` will unsubscribe the listener from `foo.bar`\n * - `unsubscribe(\"foo.*\", listener)` will unsubscribe the listener from all events under `foo`\n * - `unsubscribe(\"*\", listener)` will unsubscribe the listener from all events\n * - `unsubscribe(\"*\")` will unsubscribe all listeners from all events\n * - `unsubscribe(\"*.*\")` will unsubscribe all listeners from all events on the second level\n */\n const unsubscribe = <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]): void => {\n const eventListeners = getListenerSetsForSubscriptionKey(event);\n for (const listenerSet of eventListeners) {\n if (listener === undefined) {\n listenerSet.clear();\n } else {\n listenerSet.delete(listener);\n }\n }\n };\n\n /** Subscribe to an event. Returns an object with the event name, listener, and an unsubscribe function.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n */\n const subscribe = <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ): {\n event: K;\n listener: SubscriptionListeners<T>[K];\n unsubscribe: () => void;\n } => {\n if (typeof listener !== \"function\") {\n throw new ValidationError(`Invalid listener for event: \"${event}\". Expected function, got ${typeof listener}`);\n }\n const publishPaths = event === \"*\" ? eventNames : subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath) ?? new Set();\n listenerSet.add(listener as SubscriptionListeners<T>[PublishKey<T>]);\n listeners.set(publishPath, listenerSet);\n }\n return { event, listener, unsubscribe: () => unsubscribe(event, listener) };\n };\n\n /** Subscribe to an event once. The listener will be unsubscribed after the first time it is called.\n * You cannot cancel this subscription using unsubscribe() with the original listener.\n * Use the returned unsubscribe function / listener instead.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n * */\n const subscribeOnce = <K extends SubscriptionKey<T>>(event: K, listener: SubscriptionListeners<T>[K]) => {\n const wrappedListener = (data: unknown, eventName: string) => {\n listener(data, eventName);\n unsubscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n return subscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n\n /** Publish an event. All listeners for the event will be called with the provided data.\n * @param event The event to publish.\n * @param data The data to pass to the listeners.*/\n const publish = <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => {\n if (validate) validatePayloadOrPanic(event, data);\n if (!listeners.has(event)) return;\n for (const listener of listeners.get(event)!) {\n (listener as SubscriptionListeners<T>[K])(data, event);\n }\n };\n\n /** Returns a list of all the event names.\n * @returns An array of event names. */\n const getEventNames = () => eventNames;\n\n /** Get the list of listeners for an event or all listeners if no event is provided.\n * @param event The event to get listeners for.\n * @returns An array of listeners for the event. */\n const getListeners = <K extends SubscriptionKey<T>>(event?: K) => {\n const targetListeners: ((data: unknown, eventName: string) => void)[] = [];\n const targetListenerSets = event ? getListenerSetsForSubscriptionKey(event) : Array.from(listeners.values());\n for (const listenerSet of targetListenerSets) {\n for (const listener of listenerSet) {\n targetListeners.push(listener as (data: unknown, eventName: string) => void);\n }\n }\n return targetListeners;\n };\n\n /** Waits for an event to be published.\n * Returns a promise that resolves when the event is published.\n * @param event The event to wait for.\n * @param options.timeout The timeout in milliseconds. Defaults to 10000.\n * @param options.filter A function that returns true if the event should be accepted.\n * @returns A promise that resolves when the event is published with the data passed to the listener. */\n const waitFor = <K extends SubscriptionKey<T>>(\n event: K,\n options: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean } = {}\n ) => {\n const { timeout = 5000, filter } = options;\n return new Promise<SubscriptionListenerPayloads<T>[K]>((resolve, reject) => {\n let timeoutId: ReturnType<typeof setTimeout>;\n const listener = (data: unknown) => {\n if (filter && !filter(data as SubscriptionListenerPayloads<T>[K])) return;\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n resolve(data as SubscriptionListenerPayloads<T>[K]);\n clearTimeout(timeoutId);\n };\n subscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n if (timeout) {\n timeoutId = setTimeout(() => {\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n reject(new RuntimeError(`Timeout waiting for event: \"${event}\"`));\n }, timeout);\n }\n });\n };\n\n return {\n publish,\n subscribe,\n subscribeOnce,\n unsubscribe,\n getEventNames,\n getListeners,\n waitFor,\n };\n}\n\nexport type InferBusType<T extends Schema> = ReturnType<typeof create<T>>;\nexport type InferPublishHandler<T extends Schema> = InferBusType<T>[\"publish\"];\nexport type InferSubscribeHandler<T extends Schema> = InferBusType<T>[\"subscribe\"];\n\nexport { create };\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["src_exports", "__export", "create", "__toCommonJS", "errorPrefix", "ValidationError", "message", "errorPrefix", "RuntimeError", "getPublishPaths", "schema", "prefix", "paths", "k", "v", "newPrefix", "getSubscribePaths", "newWildcardPrefix", "getSubPubPathMap", "map", "publishPaths", "subscribePaths", "subscribePath", "subscribeParts", "publishPath", "publishParts", "i", "publishPart", "create", "schema", "validate", "subPubPathMap", "getSubPubPathMap", "eventNames", "listeners", "getListenerSetsForSubscriptionKey", "event", "listenerSets", "publishPaths", "ValidationError", "publishPath", "listenerSet", "validatePayloadOrPanic", "data", "pathFragments", "currentSchema", "fragment", "unsubscribe", "listener", "eventListeners", "subscribe", "_a", "wrappedListener", "eventName", "targetListeners", "targetListenerSets", "options", "timeout", "filter", "resolve", "reject", "timeoutId", "RuntimeError"]
|
|
3
|
+
"sources": ["../src/index.ts", "../src/bus.ts", "../src/constants.ts", "../src/errors.ts", "../src/utils/schema.ts"],
|
|
4
|
+
"sourcesContent": ["export * from \"./bus\";\n", "import { ZodType } from \"zod\";\nimport { RuntimeError, ValidationError } from \"./errors\";\nimport type { PublishKey, Schema, SubscriptionKey, SubscriptionListenerPayloads, SubscriptionListeners } from \"./types\";\nimport { getSubPubPathMap } from \"./utils/schema\";\n\ntype BusOptions<T extends Schema> = {\n schema: T;\n validate?: boolean;\n};\n\ninterface Bus<T extends Schema> {\n publish: <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => void;\n subscribe: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n subscribeOnce: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n unsubscribe: <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]) => void;\n getEventNames: () => PublishKey<T>[];\n getListeners: <K extends SubscriptionKey<T>>(event?: K) => ((data: unknown, eventName: string) => void)[];\n waitFor: <K extends SubscriptionKey<T>>(\n event: K,\n options?: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean }\n ) => Promise<SubscriptionListenerPayloads<T>[K]>;\n}\n\nfunction create<T extends Schema>({ schema, validate = true }: BusOptions<T>): Bus<T> {\n const subPubPathMap = getSubPubPathMap(schema) as Record<SubscriptionKey<T>, PublishKey<T>[]>;\n const eventNames = Array.from(new Set(Object.values(subPubPathMap).flat())) as PublishKey<T>[];\n const listeners = new Map<PublishKey<T>, Set<SubscriptionListeners<T>[PublishKey<T>]>>();\n\n const getListenerSetsForSubscriptionKey = (event: SubscriptionKey<T>): Set<unknown>[] => {\n if (event === \"*\") return Array.from(listeners.values());\n const listenerSets: Set<SubscriptionListeners<T>[PublishKey<T>]>[] = [];\n const publishPaths = subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath);\n if (listenerSet) listenerSets.push(listenerSet);\n }\n return listenerSets;\n };\n\n const validatePayloadOrPanic = (event: string, data: unknown): void => {\n const pathFragments = event.split(\".\");\n let currentSchema: Schema | ZodType = schema;\n for (const fragment of pathFragments) {\n currentSchema = (currentSchema as Record<string, Schema | ZodType>)[fragment];\n if (!currentSchema) {\n throw new ValidationError(`Invalid event: \"${event}\". Could not resolve \"${fragment}\" fragment.`);\n }\n }\n if (currentSchema instanceof ZodType) {\n currentSchema.parse(data);\n } else {\n throw new ValidationError(`Reached invalid payload schema for: \"${event}\"`);\n }\n };\n\n /** Unsubscribe from an event. If no listener is provided, all listeners for the event will be removed.\n * @param event The event to unsubscribe from. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to remove. If no listener is provided, all listeners for the event will be removed.\n *\n * Examples:\n * - `unsubscribe(\"foo.bar\", listener)` will unsubscribe the listener from `foo.bar`\n * - `unsubscribe(\"foo.*\", listener)` will unsubscribe the listener from all events under `foo`\n * - `unsubscribe(\"*\", listener)` will unsubscribe the listener from all events\n * - `unsubscribe(\"*\")` will unsubscribe all listeners from all events\n * - `unsubscribe(\"*.*\")` will unsubscribe all listeners from all events on the second level\n */\n const unsubscribe = <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]): void => {\n const eventListeners = getListenerSetsForSubscriptionKey(event);\n for (const listenerSet of eventListeners) {\n if (listener === undefined) {\n listenerSet.clear();\n } else {\n listenerSet.delete(listener);\n }\n }\n };\n\n /** Subscribe to an event. Returns an object with the event name, listener, and an unsubscribe function.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n */\n const subscribe = <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ): {\n event: K;\n listener: SubscriptionListeners<T>[K];\n unsubscribe: () => void;\n } => {\n if (typeof listener !== \"function\") {\n throw new ValidationError(`Invalid listener for event: \"${event}\". Expected function, got ${typeof listener}`);\n }\n const publishPaths = event === \"*\" ? eventNames : subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath) ?? new Set();\n listenerSet.add(listener as SubscriptionListeners<T>[PublishKey<T>]);\n listeners.set(publishPath, listenerSet);\n }\n return { event, listener, unsubscribe: () => unsubscribe(event, listener) };\n };\n\n /** Subscribe to an event once. The listener will be unsubscribed after the first time it is called.\n * You cannot cancel this subscription using unsubscribe() with the original listener.\n * Use the returned unsubscribe function / listener instead.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n * */\n const subscribeOnce = <K extends SubscriptionKey<T>>(event: K, listener: SubscriptionListeners<T>[K]) => {\n const wrappedListener = (data: unknown, eventName: string) => {\n listener(data, eventName);\n unsubscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n return subscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n\n /** Publish an event. All listeners for the event will be called with the provided data.\n * @param event The event to publish.\n * @param data The data to pass to the listeners.*/\n const publish = <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => {\n if (validate) validatePayloadOrPanic(event, data);\n if (!listeners.has(event)) return;\n for (const listener of listeners.get(event)!) {\n (listener as SubscriptionListeners<T>[K])(data, event);\n }\n };\n\n /** Returns a list of all the event names.\n * @returns An array of event names. */\n const getEventNames = () => eventNames;\n\n /** Get the list of listeners for an event or all listeners if no event is provided.\n * @param event The event to get listeners for.\n * @returns An array of listeners for the event. */\n const getListeners = <K extends SubscriptionKey<T>>(event?: K) => {\n const targetListeners: ((data: unknown, eventName: string) => void)[] = [];\n const targetListenerSets = event ? getListenerSetsForSubscriptionKey(event) : Array.from(listeners.values());\n for (const listenerSet of targetListenerSets) {\n for (const listener of listenerSet) {\n targetListeners.push(listener as (data: unknown, eventName: string) => void);\n }\n }\n return targetListeners;\n };\n\n /** Waits for an event to be published.\n * Returns a promise that resolves when the event is published.\n * @param event The event to wait for.\n * @param options.timeout The timeout in milliseconds. Defaults to 10000.\n * @param options.filter A function that returns true if the event should be accepted.\n * @returns A promise that resolves when the event is published with the data passed to the listener. */\n const waitFor = <K extends SubscriptionKey<T>>(\n event: K,\n options: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean } = {}\n ) => {\n const { timeout = 5000, filter } = options;\n return new Promise<SubscriptionListenerPayloads<T>[K]>((resolve, reject) => {\n let timeoutId: ReturnType<typeof setTimeout>;\n const listener = (data: unknown) => {\n if (filter && !filter(data as SubscriptionListenerPayloads<T>[K])) return;\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n resolve(data as SubscriptionListenerPayloads<T>[K]);\n clearTimeout(timeoutId);\n };\n subscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n if (timeout) {\n timeoutId = setTimeout(() => {\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n reject(new RuntimeError(`Timeout waiting for event: \"${event}\"`));\n }, timeout);\n }\n });\n };\n\n return {\n publish,\n subscribe,\n subscribeOnce,\n unsubscribe,\n getEventNames,\n getListeners,\n waitFor,\n };\n}\n\nexport type InferBusType<T extends Schema> = ReturnType<typeof create<T>>;\nexport type InferPublishHandler<T extends Schema> = InferBusType<T>[\"publish\"];\nexport type InferSubscribeHandler<T extends Schema> = InferBusType<T>[\"subscribe\"];\nexport type InferSubscriptionKey<T extends Schema> = SubscriptionKey<T>;\nexport type InferPublishKey<T extends Schema> = PublishKey<T>;\n\nexport { create };\n", "export const errorPrefix = \"[zodbus] \";\n", "import { errorPrefix } from \"./constants\";\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"ValidationError\";\n }\n}\n\nexport class RuntimeError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"RuntimeError\";\n }\n}\n", "import { ZodType } from \"zod\";\nimport { Schema } from \"../types\";\n\nexport const hasWildcard = (path: string): boolean => path.split(\".\").includes(\"*\");\n\nexport const getPublishPaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix);\n } else {\n paths.push(...getPublishPaths(v, newPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubscribePaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n const newWildcardPrefix = prefix ? `${prefix}.*` : \"*\";\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix, newWildcardPrefix);\n } else {\n paths.push(...getSubscribePaths(v, newPrefix), ...getSubscribePaths(v, newWildcardPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubPubPathMap = (schema: Schema | ZodType): Record<string, string[]> => {\n const map: Record<string, string[]> = {};\n const publishPaths = getPublishPaths(schema);\n const subscribePaths = getSubscribePaths(schema);\n\n for (const subscribePath of subscribePaths) {\n const subscribeParts = subscribePath.split(\".\");\n map[subscribePath] = publishPaths.filter((publishPath) => {\n const publishParts = publishPath.split(\".\");\n if (publishParts.length !== subscribeParts.length) return false;\n for (const [i, publishPart] of publishParts.entries()) {\n if (subscribeParts[i] !== \"*\" && publishPart !== subscribeParts[i]) return false;\n }\n return true;\n });\n }\n\n return map;\n};\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAwB,eCAjB,IAAMC,EAAc,YCEpB,IAAMC,EAAN,cAA8B,KAAM,CACzC,YAAYC,EAAiB,CAC3B,MAAM,GAAGC,CAAW,GAAGD,CAAO,EAAE,EAChC,KAAK,KAAO,iBACd,CACF,EAEaE,EAAN,cAA2B,KAAM,CACtC,YAAYF,EAAiB,CAC3B,MAAM,GAAGC,CAAW,GAAGD,CAAO,EAAE,EAChC,KAAK,KAAO,cACd,CACF,ECTO,IAAMG,EAAkB,CAACC,EAA0BC,EAAS,KAAiB,CAClF,IAAMC,EAAkB,CAAC,EACzB,OAAW,CAACC,EAAGC,CAAC,IAAK,OAAO,QAAQ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,EACrEY,EAAO,IAAIE,EAAa,+BAA+B1B,CAAK,GAAG,CAAC,CAClE,EAAGqB,CAAO,EAEd,CAAC,CACH,CAUA,CACF",
|
|
6
|
+
"names": ["src_exports", "__export", "create", "__toCommonJS", "import_zod", "errorPrefix", "ValidationError", "message", "errorPrefix", "RuntimeError", "getPublishPaths", "schema", "prefix", "paths", "k", "v", "newPrefix", "getSubscribePaths", "newWildcardPrefix", "getSubPubPathMap", "map", "publishPaths", "subscribePaths", "subscribePath", "subscribeParts", "publishPath", "publishParts", "i", "publishPart", "create", "schema", "validate", "subPubPathMap", "getSubPubPathMap", "eventNames", "listeners", "getListenerSetsForSubscriptionKey", "event", "listenerSets", "publishPaths", "ValidationError", "publishPath", "listenerSet", "validatePayloadOrPanic", "data", "pathFragments", "currentSchema", "fragment", "unsubscribe", "listener", "eventListeners", "subscribe", "_a", "wrappedListener", "eventName", "targetListeners", "targetListenerSets", "options", "timeout", "filter", "resolve", "reject", "timeoutId", "RuntimeError"]
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var h="[zodbus] ";var l=class extends Error{constructor(i){super(`${h}${i}`),this.name="ValidationError"}},K=class extends Error{constructor(i){super(`${h}${i}`),this.name="RuntimeError"}};var
|
|
1
|
+
import{ZodType as w}from"zod";var h="[zodbus] ";var l=class extends Error{constructor(i){super(`${h}${i}`),this.name="ValidationError"}},K=class extends Error{constructor(i){super(`${h}${i}`),this.name="RuntimeError"}};var x=(a,i="")=>{let u=[];for(let[p,r]of Object.entries(a)){let c=i?`${i}.${p}`:p;typeof r.parse=="function"?u.push(c):u.push(...x(r,c))}return u},y=(a,i="")=>{let u=[];for(let[p,r]of Object.entries(a)){let c=i?`${i}.${p}`:p,d=i?`${i}.*`:"*";typeof r.parse=="function"?u.push(c,d):u.push(...y(r,c),...y(r,d))}return u},L=a=>{let i={},u=x(a),p=y(a);for(let r of p){let c=r.split(".");i[r]=u.filter(d=>{let b=d.split(".");if(b.length!==c.length)return!1;for(let[f,m]of b.entries())if(c[f]!=="*"&&m!==c[f])return!1;return!0})}return i};function M({schema:a,validate:i=!0}){let u=L(a),p=Array.from(new Set(Object.values(u).flat())),r=new Map,c=e=>{if(e==="*")return Array.from(r.values());let s=[],n=u[e];if(!n)throw new l(`Invalid event: "${e}"`);for(let t of n){let o=r.get(t);o&&s.push(o)}return s},d=(e,s)=>{let n=e.split("."),t=a;for(let o of n)if(t=t[o],!t)throw new l(`Invalid event: "${e}". Could not resolve "${o}" fragment.`);if(t instanceof w)t.parse(s);else throw new l(`Reached invalid payload schema for: "${e}"`)},b=(e,s)=>{let n=c(e);for(let t of n)s===void 0?t.clear():t.delete(s)},f=(e,s)=>{var t;if(typeof s!="function")throw new l(`Invalid listener for event: "${e}". Expected function, got ${typeof s}`);let n=e==="*"?p:u[e];if(!n)throw new l(`Invalid event: "${e}"`);for(let o of n){let T=(t=r.get(o))!=null?t:new Set;T.add(s),r.set(o,T)}return{event:e,listener:s,unsubscribe:()=>b(e,s)}};return{publish:(e,s)=>{if(i&&d(e,s),!!r.has(e))for(let n of r.get(e))n(s,e)},subscribe:f,subscribeOnce:(e,s)=>{let n=(t,o)=>{s(t,o),b(e,n)};return f(e,n)},unsubscribe:b,getEventNames:()=>p,getListeners:e=>{let s=[],n=e?c(e):Array.from(r.values());for(let t of n)for(let o of t)s.push(o);return s},waitFor:(e,s={})=>{let{timeout:n=5e3,filter:t}=s;return new Promise((o,T)=>{let P,S=g=>{t&&!t(g)||(b(e,S),o(g),clearTimeout(P))};f(e,S),n&&(P=setTimeout(()=>{b(e,S),T(new K(`Timeout waiting for event: "${e}"`))},n))})}}}export{M as create};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["export const errorPrefix = \"[zodbus] \";\n", "import { errorPrefix } from \"./constants\";\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"ValidationError\";\n }\n}\n\nexport class RuntimeError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"RuntimeError\";\n }\n}\n", "import { ZodType } from \"zod\";\nimport { Schema } from \"../types\";\n\nexport const hasWildcard = (path: string): boolean => path.split(\".\").includes(\"*\");\n\nexport const getPublishPaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix);\n } else {\n paths.push(...getPublishPaths(v, newPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubscribePaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n const newWildcardPrefix = prefix ? `${prefix}.*` : \"*\";\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix, newWildcardPrefix);\n } else {\n paths.push(...getSubscribePaths(v, newPrefix), ...getSubscribePaths(v, newWildcardPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubPubPathMap = (schema: Schema | ZodType): Record<string, string[]> => {\n const map: Record<string, string[]> = {};\n const publishPaths = getPublishPaths(schema);\n const subscribePaths = getSubscribePaths(schema);\n\n for (const subscribePath of subscribePaths) {\n const subscribeParts = subscribePath.split(\".\");\n map[subscribePath] = publishPaths.filter((publishPath) => {\n const publishParts = publishPath.split(\".\");\n if (publishParts.length !== subscribeParts.length) return false;\n for (const [i, publishPart] of publishParts.entries()) {\n if (subscribeParts[i] !== \"*\" && publishPart !== subscribeParts[i]) return false;\n }\n return true;\n });\n }\n\n return map;\n};\n", "import { ZodType, z } from \"zod\";\nimport { RuntimeError, ValidationError } from \"./errors\";\nimport type { PublishKey, Schema, SubscriptionKey, SubscriptionListenerPayloads, SubscriptionListeners } from \"./types\";\nimport { getSubPubPathMap } from \"./utils/schema\";\n\ntype BusOptions<T extends Schema> = {\n schema: T;\n validate?: boolean;\n};\n\ninterface Bus<T extends Schema> {\n publish: <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => void;\n subscribe: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n subscribeOnce: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n unsubscribe: <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]) => void;\n getEventNames: () => PublishKey<T>[];\n getListeners: <K extends SubscriptionKey<T>>(event?: K) => ((data: unknown, eventName: string) => void)[];\n waitFor: <K extends SubscriptionKey<T>>(\n event: K,\n options?: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean }\n ) => Promise<SubscriptionListenerPayloads<T>[K]>;\n}\n\nfunction create<T extends Schema>({ schema, validate = true }: BusOptions<T>): Bus<T> {\n const subPubPathMap = getSubPubPathMap(schema) as Record<SubscriptionKey<T>, PublishKey<T>[]>;\n const eventNames = Array.from(new Set(Object.values(subPubPathMap).flat())) as PublishKey<T>[];\n const listeners = new Map<PublishKey<T>, Set<SubscriptionListeners<T>[PublishKey<T>]>>();\n\n const getListenerSetsForSubscriptionKey = (event: SubscriptionKey<T>): Set<unknown>[] => {\n if (event === \"*\") return Array.from(listeners.values());\n const listenerSets: Set<SubscriptionListeners<T>[PublishKey<T>]>[] = [];\n const publishPaths = subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath);\n if (listenerSet) listenerSets.push(listenerSet);\n }\n return listenerSets;\n };\n\n const validatePayloadOrPanic = (event: string, data: unknown): void => {\n const pathFragments = event.split(\".\");\n let currentSchema: Schema | ZodType = schema;\n for (const fragment of pathFragments) {\n currentSchema = (currentSchema as Record<string, Schema | ZodType>)[fragment];\n if (!currentSchema) {\n throw new ValidationError(`Invalid event: \"${event}\". Could not resolve \"${fragment}\" fragment.`);\n }\n }\n if (\"constructor\" in currentSchema && [\"ZodType\", \"ZodObject\"].includes(currentSchema.constructor.name)) {\n (currentSchema as ZodType).parse(data);\n } else {\n throw new ValidationError(`Reached invalid payload schema for: \"${event}\"`);\n }\n };\n\n /** Unsubscribe from an event. If no listener is provided, all listeners for the event will be removed.\n * @param event The event to unsubscribe from. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to remove. If no listener is provided, all listeners for the event will be removed.\n *\n * Examples:\n * - `unsubscribe(\"foo.bar\", listener)` will unsubscribe the listener from `foo.bar`\n * - `unsubscribe(\"foo.*\", listener)` will unsubscribe the listener from all events under `foo`\n * - `unsubscribe(\"*\", listener)` will unsubscribe the listener from all events\n * - `unsubscribe(\"*\")` will unsubscribe all listeners from all events\n * - `unsubscribe(\"*.*\")` will unsubscribe all listeners from all events on the second level\n */\n const unsubscribe = <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]): void => {\n const eventListeners = getListenerSetsForSubscriptionKey(event);\n for (const listenerSet of eventListeners) {\n if (listener === undefined) {\n listenerSet.clear();\n } else {\n listenerSet.delete(listener);\n }\n }\n };\n\n /** Subscribe to an event. Returns an object with the event name, listener, and an unsubscribe function.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n */\n const subscribe = <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ): {\n event: K;\n listener: SubscriptionListeners<T>[K];\n unsubscribe: () => void;\n } => {\n if (typeof listener !== \"function\") {\n throw new ValidationError(`Invalid listener for event: \"${event}\". Expected function, got ${typeof listener}`);\n }\n const publishPaths = event === \"*\" ? eventNames : subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath) ?? new Set();\n listenerSet.add(listener as SubscriptionListeners<T>[PublishKey<T>]);\n listeners.set(publishPath, listenerSet);\n }\n return { event, listener, unsubscribe: () => unsubscribe(event, listener) };\n };\n\n /** Subscribe to an event once. The listener will be unsubscribed after the first time it is called.\n * You cannot cancel this subscription using unsubscribe() with the original listener.\n * Use the returned unsubscribe function / listener instead.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n * */\n const subscribeOnce = <K extends SubscriptionKey<T>>(event: K, listener: SubscriptionListeners<T>[K]) => {\n const wrappedListener = (data: unknown, eventName: string) => {\n listener(data, eventName);\n unsubscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n return subscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n\n /** Publish an event. All listeners for the event will be called with the provided data.\n * @param event The event to publish.\n * @param data The data to pass to the listeners.*/\n const publish = <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => {\n if (validate) validatePayloadOrPanic(event, data);\n if (!listeners.has(event)) return;\n for (const listener of listeners.get(event)!) {\n (listener as SubscriptionListeners<T>[K])(data, event);\n }\n };\n\n /** Returns a list of all the event names.\n * @returns An array of event names. */\n const getEventNames = () => eventNames;\n\n /** Get the list of listeners for an event or all listeners if no event is provided.\n * @param event The event to get listeners for.\n * @returns An array of listeners for the event. */\n const getListeners = <K extends SubscriptionKey<T>>(event?: K) => {\n const targetListeners: ((data: unknown, eventName: string) => void)[] = [];\n const targetListenerSets = event ? getListenerSetsForSubscriptionKey(event) : Array.from(listeners.values());\n for (const listenerSet of targetListenerSets) {\n for (const listener of listenerSet) {\n targetListeners.push(listener as (data: unknown, eventName: string) => void);\n }\n }\n return targetListeners;\n };\n\n /** Waits for an event to be published.\n * Returns a promise that resolves when the event is published.\n * @param event The event to wait for.\n * @param options.timeout The timeout in milliseconds. Defaults to 10000.\n * @param options.filter A function that returns true if the event should be accepted.\n * @returns A promise that resolves when the event is published with the data passed to the listener. */\n const waitFor = <K extends SubscriptionKey<T>>(\n event: K,\n options: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean } = {}\n ) => {\n const { timeout = 5000, filter } = options;\n return new Promise<SubscriptionListenerPayloads<T>[K]>((resolve, reject) => {\n let timeoutId: ReturnType<typeof setTimeout>;\n const listener = (data: unknown) => {\n if (filter && !filter(data as SubscriptionListenerPayloads<T>[K])) return;\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n resolve(data as SubscriptionListenerPayloads<T>[K]);\n clearTimeout(timeoutId);\n };\n subscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n if (timeout) {\n timeoutId = setTimeout(() => {\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n reject(new RuntimeError(`Timeout waiting for event: \"${event}\"`));\n }, timeout);\n }\n });\n };\n\n return {\n publish,\n subscribe,\n subscribeOnce,\n unsubscribe,\n getEventNames,\n getListeners,\n waitFor,\n };\n}\n\nexport type InferBusType<T extends Schema> = ReturnType<typeof create<T>>;\nexport type InferPublishHandler<T extends Schema> = InferBusType<T>[\"publish\"];\nexport type InferSubscribeHandler<T extends Schema> = InferBusType<T>[\"subscribe\"];\n\nexport { create };\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["errorPrefix", "ValidationError", "message", "errorPrefix", "RuntimeError", "getPublishPaths", "schema", "prefix", "paths", "k", "v", "newPrefix", "getSubscribePaths", "newWildcardPrefix", "getSubPubPathMap", "map", "publishPaths", "subscribePaths", "subscribePath", "subscribeParts", "publishPath", "publishParts", "i", "publishPart", "create", "schema", "validate", "subPubPathMap", "getSubPubPathMap", "eventNames", "listeners", "getListenerSetsForSubscriptionKey", "event", "listenerSets", "publishPaths", "ValidationError", "publishPath", "listenerSet", "validatePayloadOrPanic", "data", "pathFragments", "currentSchema", "fragment", "unsubscribe", "listener", "eventListeners", "subscribe", "_a", "wrappedListener", "eventName", "targetListeners", "targetListenerSets", "options", "timeout", "filter", "resolve", "reject", "timeoutId", "RuntimeError"]
|
|
3
|
+
"sources": ["../src/bus.ts", "../src/constants.ts", "../src/errors.ts", "../src/utils/schema.ts"],
|
|
4
|
+
"sourcesContent": ["import { ZodType } from \"zod\";\nimport { RuntimeError, ValidationError } from \"./errors\";\nimport type { PublishKey, Schema, SubscriptionKey, SubscriptionListenerPayloads, SubscriptionListeners } from \"./types\";\nimport { getSubPubPathMap } from \"./utils/schema\";\n\ntype BusOptions<T extends Schema> = {\n schema: T;\n validate?: boolean;\n};\n\ninterface Bus<T extends Schema> {\n publish: <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => void;\n subscribe: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n subscribeOnce: <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ) => { event: K; listener: SubscriptionListeners<T>[K]; unsubscribe: () => void };\n unsubscribe: <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]) => void;\n getEventNames: () => PublishKey<T>[];\n getListeners: <K extends SubscriptionKey<T>>(event?: K) => ((data: unknown, eventName: string) => void)[];\n waitFor: <K extends SubscriptionKey<T>>(\n event: K,\n options?: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean }\n ) => Promise<SubscriptionListenerPayloads<T>[K]>;\n}\n\nfunction create<T extends Schema>({ schema, validate = true }: BusOptions<T>): Bus<T> {\n const subPubPathMap = getSubPubPathMap(schema) as Record<SubscriptionKey<T>, PublishKey<T>[]>;\n const eventNames = Array.from(new Set(Object.values(subPubPathMap).flat())) as PublishKey<T>[];\n const listeners = new Map<PublishKey<T>, Set<SubscriptionListeners<T>[PublishKey<T>]>>();\n\n const getListenerSetsForSubscriptionKey = (event: SubscriptionKey<T>): Set<unknown>[] => {\n if (event === \"*\") return Array.from(listeners.values());\n const listenerSets: Set<SubscriptionListeners<T>[PublishKey<T>]>[] = [];\n const publishPaths = subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath);\n if (listenerSet) listenerSets.push(listenerSet);\n }\n return listenerSets;\n };\n\n const validatePayloadOrPanic = (event: string, data: unknown): void => {\n const pathFragments = event.split(\".\");\n let currentSchema: Schema | ZodType = schema;\n for (const fragment of pathFragments) {\n currentSchema = (currentSchema as Record<string, Schema | ZodType>)[fragment];\n if (!currentSchema) {\n throw new ValidationError(`Invalid event: \"${event}\". Could not resolve \"${fragment}\" fragment.`);\n }\n }\n if (currentSchema instanceof ZodType) {\n currentSchema.parse(data);\n } else {\n throw new ValidationError(`Reached invalid payload schema for: \"${event}\"`);\n }\n };\n\n /** Unsubscribe from an event. If no listener is provided, all listeners for the event will be removed.\n * @param event The event to unsubscribe from. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to remove. If no listener is provided, all listeners for the event will be removed.\n *\n * Examples:\n * - `unsubscribe(\"foo.bar\", listener)` will unsubscribe the listener from `foo.bar`\n * - `unsubscribe(\"foo.*\", listener)` will unsubscribe the listener from all events under `foo`\n * - `unsubscribe(\"*\", listener)` will unsubscribe the listener from all events\n * - `unsubscribe(\"*\")` will unsubscribe all listeners from all events\n * - `unsubscribe(\"*.*\")` will unsubscribe all listeners from all events on the second level\n */\n const unsubscribe = <K extends SubscriptionKey<T>>(event: K, listener?: SubscriptionListeners<T>[K]): void => {\n const eventListeners = getListenerSetsForSubscriptionKey(event);\n for (const listenerSet of eventListeners) {\n if (listener === undefined) {\n listenerSet.clear();\n } else {\n listenerSet.delete(listener);\n }\n }\n };\n\n /** Subscribe to an event. Returns an object with the event name, listener, and an unsubscribe function.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n */\n const subscribe = <K extends SubscriptionKey<T>>(\n event: K,\n listener: SubscriptionListeners<T>[K]\n ): {\n event: K;\n listener: SubscriptionListeners<T>[K];\n unsubscribe: () => void;\n } => {\n if (typeof listener !== \"function\") {\n throw new ValidationError(`Invalid listener for event: \"${event}\". Expected function, got ${typeof listener}`);\n }\n const publishPaths = event === \"*\" ? eventNames : subPubPathMap[event];\n if (!publishPaths) throw new ValidationError(`Invalid event: \"${event}\"`);\n for (const publishPath of publishPaths) {\n const listenerSet = listeners.get(publishPath) ?? new Set();\n listenerSet.add(listener as SubscriptionListeners<T>[PublishKey<T>]);\n listeners.set(publishPath, listenerSet);\n }\n return { event, listener, unsubscribe: () => unsubscribe(event, listener) };\n };\n\n /** Subscribe to an event once. The listener will be unsubscribed after the first time it is called.\n * You cannot cancel this subscription using unsubscribe() with the original listener.\n * Use the returned unsubscribe function / listener instead.\n * @param event The event to subscribe to. Wildcards `foo.*.bar.*` are supported.\n * Using `*` will match any event on any level.\n * More specific wildcard patterns like `*.*` will only match events on that level.\n * @param listener The listener to call when the event is published.\n * @returns A subscription object with the event name, listener, and an unsubscribe function.\n * */\n const subscribeOnce = <K extends SubscriptionKey<T>>(event: K, listener: SubscriptionListeners<T>[K]) => {\n const wrappedListener = (data: unknown, eventName: string) => {\n listener(data, eventName);\n unsubscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n return subscribe(event, wrappedListener as unknown as SubscriptionListeners<T>[K]);\n };\n\n /** Publish an event. All listeners for the event will be called with the provided data.\n * @param event The event to publish.\n * @param data The data to pass to the listeners.*/\n const publish = <K extends PublishKey<T>>(event: K, data: SubscriptionListenerPayloads<T>[K]) => {\n if (validate) validatePayloadOrPanic(event, data);\n if (!listeners.has(event)) return;\n for (const listener of listeners.get(event)!) {\n (listener as SubscriptionListeners<T>[K])(data, event);\n }\n };\n\n /** Returns a list of all the event names.\n * @returns An array of event names. */\n const getEventNames = () => eventNames;\n\n /** Get the list of listeners for an event or all listeners if no event is provided.\n * @param event The event to get listeners for.\n * @returns An array of listeners for the event. */\n const getListeners = <K extends SubscriptionKey<T>>(event?: K) => {\n const targetListeners: ((data: unknown, eventName: string) => void)[] = [];\n const targetListenerSets = event ? getListenerSetsForSubscriptionKey(event) : Array.from(listeners.values());\n for (const listenerSet of targetListenerSets) {\n for (const listener of listenerSet) {\n targetListeners.push(listener as (data: unknown, eventName: string) => void);\n }\n }\n return targetListeners;\n };\n\n /** Waits for an event to be published.\n * Returns a promise that resolves when the event is published.\n * @param event The event to wait for.\n * @param options.timeout The timeout in milliseconds. Defaults to 10000.\n * @param options.filter A function that returns true if the event should be accepted.\n * @returns A promise that resolves when the event is published with the data passed to the listener. */\n const waitFor = <K extends SubscriptionKey<T>>(\n event: K,\n options: { timeout?: number; filter?: (data: SubscriptionListenerPayloads<T>[K]) => boolean } = {}\n ) => {\n const { timeout = 5000, filter } = options;\n return new Promise<SubscriptionListenerPayloads<T>[K]>((resolve, reject) => {\n let timeoutId: ReturnType<typeof setTimeout>;\n const listener = (data: unknown) => {\n if (filter && !filter(data as SubscriptionListenerPayloads<T>[K])) return;\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n resolve(data as SubscriptionListenerPayloads<T>[K]);\n clearTimeout(timeoutId);\n };\n subscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n if (timeout) {\n timeoutId = setTimeout(() => {\n unsubscribe(event, listener as unknown as SubscriptionListeners<T>[K]);\n reject(new RuntimeError(`Timeout waiting for event: \"${event}\"`));\n }, timeout);\n }\n });\n };\n\n return {\n publish,\n subscribe,\n subscribeOnce,\n unsubscribe,\n getEventNames,\n getListeners,\n waitFor,\n };\n}\n\nexport type InferBusType<T extends Schema> = ReturnType<typeof create<T>>;\nexport type InferPublishHandler<T extends Schema> = InferBusType<T>[\"publish\"];\nexport type InferSubscribeHandler<T extends Schema> = InferBusType<T>[\"subscribe\"];\nexport type InferSubscriptionKey<T extends Schema> = SubscriptionKey<T>;\nexport type InferPublishKey<T extends Schema> = PublishKey<T>;\n\nexport { create };\n", "export const errorPrefix = \"[zodbus] \";\n", "import { errorPrefix } from \"./constants\";\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"ValidationError\";\n }\n}\n\nexport class RuntimeError extends Error {\n constructor(message: string) {\n super(`${errorPrefix}${message}`);\n this.name = \"RuntimeError\";\n }\n}\n", "import { ZodType } from \"zod\";\nimport { Schema } from \"../types\";\n\nexport const hasWildcard = (path: string): boolean => path.split(\".\").includes(\"*\");\n\nexport const getPublishPaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix);\n } else {\n paths.push(...getPublishPaths(v, newPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubscribePaths = (schema: Schema | ZodType, prefix = \"\"): string[] => {\n const paths: string[] = [];\n for (const [k, v] of Object.entries(schema)) {\n const newPrefix = prefix ? `${prefix}.${k}` : k;\n const newWildcardPrefix = prefix ? `${prefix}.*` : \"*\";\n if (typeof v.parse === \"function\") {\n paths.push(newPrefix, newWildcardPrefix);\n } else {\n paths.push(...getSubscribePaths(v, newPrefix), ...getSubscribePaths(v, newWildcardPrefix));\n }\n }\n return paths;\n};\n\nexport const getSubPubPathMap = (schema: Schema | ZodType): Record<string, string[]> => {\n const map: Record<string, string[]> = {};\n const publishPaths = getPublishPaths(schema);\n const subscribePaths = getSubscribePaths(schema);\n\n for (const subscribePath of subscribePaths) {\n const subscribeParts = subscribePath.split(\".\");\n map[subscribePath] = publishPaths.filter((publishPath) => {\n const publishParts = publishPath.split(\".\");\n if (publishParts.length !== subscribeParts.length) return false;\n for (const [i, publishPart] of publishParts.entries()) {\n if (subscribeParts[i] !== \"*\" && publishPart !== subscribeParts[i]) return false;\n }\n return true;\n });\n }\n\n return map;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,WAAAA,MAAe,MCAjB,IAAMC,EAAc,YCEpB,IAAMC,EAAN,cAA8B,KAAM,CACzC,YAAYC,EAAiB,CAC3B,MAAM,GAAGC,CAAW,GAAGD,CAAO,EAAE,EAChC,KAAK,KAAO,iBACd,CACF,EAEaE,EAAN,cAA2B,KAAM,CACtC,YAAYF,EAAiB,CAC3B,MAAM,GAAGC,CAAW,GAAGD,CAAO,EAAE,EAChC,KAAK,KAAO,cACd,CACF,ECTO,IAAMG,EAAkB,CAACC,EAA0BC,EAAS,KAAiB,CAClF,IAAMC,EAAkB,CAAC,EACzB,OAAW,CAACC,EAAGC,CAAC,IAAK,OAAO,QAAQJ,CAAM,EAAG,CAC3C,IAAMK,EAAYJ,EAAS,GAAGA,CAAM,IAAIE,CAAC,GAAKA,EAC1C,OAAOC,EAAE,OAAU,WACrBF,EAAM,KAAKG,CAAS,EAEpBH,EAAM,KAAK,GAAGH,EAAgBK,EAAGC,CAAS,CAAC,CAE/C,CACA,OAAOH,CACT,EAEaI,EAAoB,CAACN,EAA0BC,EAAS,KAAiB,CACpF,IAAMC,EAAkB,CAAC,EACzB,OAAW,CAACC,EAAGC,CAAC,IAAK,OAAO,QAAQJ,CAAM,EAAG,CAC3C,IAAMK,EAAYJ,EAAS,GAAGA,CAAM,IAAIE,CAAC,GAA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AmDE,UAAAe,EACA,cArEoB,CAA+Bf,EAAUa,IAA0C,CACvG,IAAMI,EAAkB,CAACV,EAAeW,IAAsB,CAC5DL,EAASN,EAAMW,CAAS,EACxBN,EAAYZ,EAAOiB,CAAyD,CAC9E,EACA,OAAOF,EAAUf,EAAOiB,CAAyD,CACnF,EAgEE,YAAAL,EACA,cAlDoB,IAAMf,EAmD1B,aA9CkDG,GAAc,CAChE,IAAMmB,EAAkE,CAAC,EACnEC,EAAqBpB,EAAQD,EAAkCC,CAAK,EAAI,MAAM,KAAKF,EAAU,OAAO,CAAC,EAC3G,QAAWO,KAAee,EACxB,QAAWP,KAAYR,EACrBc,EAAgB,KAAKN,CAAsD,EAG/E,OAAOM,CACT,EAsCE,QA9Bc,CACdnB,EACAqB,EAAgG,CAAC,IAC9F,CACH,GAAM,CAAE,QAAAC,EAAU,IAAM,OAAAC,CAAO,EAAIF,EACnC,OAAO,IAAI,QAA4C,CAACG,EAASC,IAAW,CAC1E,IAAIC,EACEb,EAAYN,GAAkB,CAC9BgB,GAAU,CAACA,EAAOhB,CAA0C,IAChEK,EAAYZ,EAAOa,CAAkD,EACrEW,EAAQjB,CAA0C,EAClD,aAAamB,CAAS,EACxB,EACAX,EAAUf,EAAOa,CAAkD,EAC/DS,IACFI,EAAY,WAAW,IAAM,CAC3Bd,EAAYZ,EAAOa,CAAkD,EACrEY,EAAO,IAAIE,EAAa,+BAA+B3B,CAAK,GAAG,CAAC,CAClE,EAAGsB,CAAO,EAEd,CAAC,CACH,CAUA,CACF",
|
|
6
|
+
"names": ["ZodType", "errorPrefix", "ValidationError", "message", "errorPrefix", "RuntimeError", "getPublishPaths", "schema", "prefix", "paths", "k", "v", "newPrefix", "getSubscribePaths", "newWildcardPrefix", "getSubPubPathMap", "map", "publishPaths", "subscribePaths", "subscribePath", "subscribeParts", "publishPath", "publishParts", "i", "publishPart", "create", "schema", "validate", "subPubPathMap", "getSubPubPathMap", "eventNames", "listeners", "getListenerSetsForSubscriptionKey", "event", "listenerSets", "publishPaths", "ValidationError", "publishPath", "listenerSet", "validatePayloadOrPanic", "data", "pathFragments", "currentSchema", "fragment", "ZodType", "unsubscribe", "listener", "eventListeners", "subscribe", "_a", "wrappedListener", "eventName", "targetListeners", "targetListenerSets", "options", "timeout", "filter", "resolve", "reject", "timeoutId", "RuntimeError"]
|
|
7
7
|
}
|