@vielzeug/herald 2.0.0 → 2.1.0
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.cjs +1 -1
- package/dist/bus.cjs.map +1 -1
- package/dist/bus.d.ts +2 -2
- package/dist/bus.d.ts.map +1 -1
- package/dist/bus.js +6 -3
- package/dist/bus.js.map +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.d.ts.map +1 -1
- package/dist/devtools.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +0 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -9
- package/dist/errors.js.map +1 -1
- package/dist/herald.cjs +1 -1
- package/dist/herald.cjs.map +1 -1
- package/dist/herald.iife.js +1 -1
- package/dist/herald.iife.js.map +1 -1
- package/dist/herald.js +1 -1
- package/dist/herald.js.map +1 -1
- package/dist/pipe.cjs.map +1 -1
- package/dist/pipe.d.ts.map +1 -1
- package/dist/pipe.js.map +1 -1
- package/dist/testing/testing.cjs +1 -1
- package/dist/testing/testing.cjs.map +1 -1
- package/dist/testing/testing.d.ts.map +1 -1
- package/dist/testing/testing.js +7 -3
- package/dist/testing/testing.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +35 -30
- package/dist/_prototype.cjs +0 -2
- package/dist/_prototype.cjs.map +0 -1
- package/dist/_prototype.d.ts +0 -2
- package/dist/_prototype.d.ts.map +0 -1
- package/dist/_prototype.js +0 -13
- package/dist/_prototype.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.cjs","names":[],"sources":["../../src/testing/testing.ts"],"sourcesContent":["import type { Bus, BusOptions, EventKey, EventMap } from '..';\nimport
|
|
1
|
+
{"version":3,"file":"testing.cjs","names":[],"sources":["../../src/testing/testing.ts"],"sourcesContent":["import type { Bus, BusOptions, EventKey, EventMap } from '..';\nimport { createBusInternal } from '../bus';\n\n// Property names that must never be used as a bracket-assignment key on a plain object literal —\n// `obj[key] = value` for `key === '__proto__'` invokes `Object.prototype`'s `__proto__` accessor\n// and reassigns `obj`'s own prototype instead of setting an own property. `constructor` and\n// `prototype` are excluded defensively for the same class of risk.\n// Event names come from a caller-supplied `EventMap` type, but nothing prevents a caller from\n// wiring in a dynamically-determined (e.g. user-supplied) event name at runtime.\nconst UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/** A test bus is a regular bus with typed emission recording on top. */\nexport type TestBus<T extends EventMap> = Bus<T> & {\n /** Returns a snapshot of all payloads dispatched across every recorded event, keyed by event name. */\n allEmitted(): { [K in EventKey<T>]?: T[K][] };\n /** Snapshot of all payloads that were successfully dispatched for the given event key, in order. */\n emitted<K extends EventKey<T>>(event: K): T[K][];\n /** Number of times the given event was successfully dispatched. Shorthand for `emitted(event).length`. */\n emittedCount<K extends EventKey<T>>(event: K): number;\n /** Clear emitted records without disposing the bus. */\n reset(): void;\n};\n\nexport function createTestBus<T extends EventMap = Record<string, unknown>>(options?: BusOptions<T>): TestBus<T> {\n const records = new Map<string, unknown[]>();\n const bus = createBusInternal<T>({\n ...options,\n _onDispatch: (event: EventKey<T>, payload: unknown) => {\n const list = records.get(event);\n\n if (list) list.push(payload);\n else records.set(event, [payload]);\n },\n });\n const disposeBus = bus.dispose;\n\n function allEmitted(): { [K in EventKey<T>]?: T[K][] } {\n const result: { [K in EventKey<T>]?: T[K][] } = {};\n\n for (const [key, list] of records) {\n if (UNSAFE_OBJECT_KEYS.has(key)) continue;\n\n (result as Record<string, unknown[]>)[key] = [...list];\n }\n\n return result;\n }\n\n function emitted<K extends EventKey<T>>(event: K): T[K][] {\n return [...(records.get(event) ?? [])] as T[K][];\n }\n\n function emittedCount<K extends EventKey<T>>(event: K): number {\n return records.get(event)?.length ?? 0;\n }\n\n function dispose(): void {\n disposeBus();\n records.clear();\n }\n\n return Object.assign(bus, {\n allEmitted,\n dispose,\n emitted,\n emittedCount,\n reset: () => records.clear(),\n [Symbol.dispose]: dispose,\n }) as TestBus<T>;\n}\n"],"mappings":"8BASA,IAAM,EAAqB,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAc5E,SAAgB,EAA4D,EAAqC,CAC/G,IAAM,EAAU,IAAI,IACd,EAAM,EAAA,kBAAqB,CAC/B,GAAG,EACH,aAAc,EAAoB,IAAqB,CACrD,IAAM,EAAO,EAAQ,IAAI,CAAK,EAE1B,EAAM,EAAK,KAAK,CAAO,EACtB,EAAQ,IAAI,EAAO,CAAC,CAAO,CAAC,CACnC,CACF,CAAC,EACK,EAAa,EAAI,QAEvB,SAAS,GAA8C,CACrD,IAAM,EAA0C,CAAC,EAEjD,IAAK,GAAM,CAAC,EAAK,KAAS,EACpB,EAAmB,IAAI,CAAG,IAE9B,EAAsC,GAAO,CAAC,GAAG,CAAI,GAGvD,OAAO,CACT,CAEA,SAAS,EAA+B,EAAkB,CACxD,MAAO,CAAC,GAAI,EAAQ,IAAI,CAAK,GAAK,CAAC,CAAE,CACvC,CAEA,SAAS,EAAoC,EAAkB,CAC7D,OAAO,EAAQ,IAAI,CAAK,CAAC,EAAE,QAAU,CACvC,CAEA,SAAS,GAAgB,CACvB,EAAW,EACX,EAAQ,MAAM,CAChB,CAEA,OAAO,OAAO,OAAO,EAAK,CACxB,aACA,UACA,UACA,eACA,UAAa,EAAQ,MAAM,GAC1B,OAAO,SAAU,CACpB,CAAC,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/testing/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/testing/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAW9D,wEAAwE;AACxE,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG;IACjD,sGAAsG;IACtG,UAAU,IAAI;SAAG,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;KAAE,CAAC;IAC9C,oGAAoG;IACpG,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,0GAA0G;IAC1G,YAAY,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IACtD,uDAAuD;IACvD,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,wBAAgB,aAAa,CAAC,CAAC,SAAS,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA8C/G"}
|
package/dist/testing/testing.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isUnsafeObjectKey as t } from "../_prototype.js";
|
|
1
|
+
import { createBusInternal as e } from "../bus.js";
|
|
3
2
|
//#region src/testing/testing.ts
|
|
3
|
+
var t = /* @__PURE__ */ new Set([
|
|
4
|
+
"__proto__",
|
|
5
|
+
"constructor",
|
|
6
|
+
"prototype"
|
|
7
|
+
]);
|
|
4
8
|
function n(n) {
|
|
5
9
|
let r = /* @__PURE__ */ new Map(), i = e({
|
|
6
10
|
...n,
|
|
@@ -11,7 +15,7 @@ function n(n) {
|
|
|
11
15
|
}), a = i.dispose;
|
|
12
16
|
function o() {
|
|
13
17
|
let e = {};
|
|
14
|
-
for (let [n, i] of r) t(n) || (e[n] = [...i]);
|
|
18
|
+
for (let [n, i] of r) t.has(n) || (e[n] = [...i]);
|
|
15
19
|
return e;
|
|
16
20
|
}
|
|
17
21
|
function s(e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","names":[],"sources":["../../src/testing/testing.ts"],"sourcesContent":["import type { Bus, BusOptions, EventKey, EventMap } from '..';\nimport
|
|
1
|
+
{"version":3,"file":"testing.js","names":[],"sources":["../../src/testing/testing.ts"],"sourcesContent":["import type { Bus, BusOptions, EventKey, EventMap } from '..';\nimport { createBusInternal } from '../bus';\n\n// Property names that must never be used as a bracket-assignment key on a plain object literal —\n// `obj[key] = value` for `key === '__proto__'` invokes `Object.prototype`'s `__proto__` accessor\n// and reassigns `obj`'s own prototype instead of setting an own property. `constructor` and\n// `prototype` are excluded defensively for the same class of risk.\n// Event names come from a caller-supplied `EventMap` type, but nothing prevents a caller from\n// wiring in a dynamically-determined (e.g. user-supplied) event name at runtime.\nconst UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/** A test bus is a regular bus with typed emission recording on top. */\nexport type TestBus<T extends EventMap> = Bus<T> & {\n /** Returns a snapshot of all payloads dispatched across every recorded event, keyed by event name. */\n allEmitted(): { [K in EventKey<T>]?: T[K][] };\n /** Snapshot of all payloads that were successfully dispatched for the given event key, in order. */\n emitted<K extends EventKey<T>>(event: K): T[K][];\n /** Number of times the given event was successfully dispatched. Shorthand for `emitted(event).length`. */\n emittedCount<K extends EventKey<T>>(event: K): number;\n /** Clear emitted records without disposing the bus. */\n reset(): void;\n};\n\nexport function createTestBus<T extends EventMap = Record<string, unknown>>(options?: BusOptions<T>): TestBus<T> {\n const records = new Map<string, unknown[]>();\n const bus = createBusInternal<T>({\n ...options,\n _onDispatch: (event: EventKey<T>, payload: unknown) => {\n const list = records.get(event);\n\n if (list) list.push(payload);\n else records.set(event, [payload]);\n },\n });\n const disposeBus = bus.dispose;\n\n function allEmitted(): { [K in EventKey<T>]?: T[K][] } {\n const result: { [K in EventKey<T>]?: T[K][] } = {};\n\n for (const [key, list] of records) {\n if (UNSAFE_OBJECT_KEYS.has(key)) continue;\n\n (result as Record<string, unknown[]>)[key] = [...list];\n }\n\n return result;\n }\n\n function emitted<K extends EventKey<T>>(event: K): T[K][] {\n return [...(records.get(event) ?? [])] as T[K][];\n }\n\n function emittedCount<K extends EventKey<T>>(event: K): number {\n return records.get(event)?.length ?? 0;\n }\n\n function dispose(): void {\n disposeBus();\n records.clear();\n }\n\n return Object.assign(bus, {\n allEmitted,\n dispose,\n emitted,\n emittedCount,\n reset: () => records.clear(),\n [Symbol.dispose]: dispose,\n }) as TestBus<T>;\n}\n"],"mappings":";;AASA,IAAM,oBAAqB,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAc5E,SAAgB,EAA4D,GAAqC;CAC/G,IAAM,oBAAU,IAAI,IAAuB,GACrC,IAAM,EAAqB;EAC/B,GAAG;EACH,cAAc,GAAoB,MAAqB;GACrD,IAAM,IAAO,EAAQ,IAAI,CAAK;GAE9B,AAAI,IAAM,EAAK,KAAK,CAAO,IACtB,EAAQ,IAAI,GAAO,CAAC,CAAO,CAAC;EACnC;CACF,CAAC,GACK,IAAa,EAAI;CAEvB,SAAS,IAA8C;EACrD,IAAM,IAA0C,CAAC;EAEjD,KAAK,IAAM,CAAC,GAAK,MAAS,GACpB,EAAmB,IAAI,CAAG,MAE9B,EAAsC,KAAO,CAAC,GAAG,CAAI;EAGvD,OAAO;CACT;CAEA,SAAS,EAA+B,GAAkB;EACxD,OAAO,CAAC,GAAI,EAAQ,IAAI,CAAK,KAAK,CAAC,CAAE;CACvC;CAEA,SAAS,EAAoC,GAAkB;EAC7D,OAAO,EAAQ,IAAI,CAAK,CAAC,EAAE,UAAU;CACvC;CAEA,SAAS,IAAgB;EAEvB,AADA,EAAW,GACX,EAAQ,MAAM;CAChB;CAEA,OAAO,OAAO,OAAO,GAAK;EACxB;EACA;EACA;EACA;EACA,aAAa,EAAQ,MAAM;GAC1B,OAAO,UAAU;CACpB,CAAC;AACH"}
|
package/dist/types.d.ts
CHANGED
|
@@ -169,7 +169,7 @@ export type Bus<T extends EventMap> = {
|
|
|
169
169
|
*
|
|
170
170
|
* @remarks **Buffer:** Internal buffer is unbounded by default. Pass `maxBuffer` to cap it — oldest
|
|
171
171
|
* values are dropped when the buffer is full. Validation is synchronous: `maxBuffer ≤ 0` throws
|
|
172
|
-
* `
|
|
172
|
+
* `HeraldConfigError` at call time, before any iteration.
|
|
173
173
|
*
|
|
174
174
|
* @remarks **Cleanup:** Returns an `EventStream` — use `await using` for guaranteed cleanup:
|
|
175
175
|
* ```ts
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/herald",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Typed event bus — pub/sub with namespaces, wildcards, and once-listeners",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/helmuthdu/vielzeug",
|
|
8
|
+
"directory": "packages/herald"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22"
|
|
13
|
+
},
|
|
6
14
|
"files": [
|
|
7
15
|
"dist"
|
|
8
16
|
],
|
|
@@ -11,53 +19,50 @@
|
|
|
11
19
|
"types": "dist/index.d.ts",
|
|
12
20
|
"exports": {
|
|
13
21
|
".": {
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
22
|
"import": "./dist/index.js",
|
|
16
|
-
"require": "./dist/index.cjs"
|
|
23
|
+
"require": "./dist/index.cjs",
|
|
24
|
+
"types": "./dist/index.d.ts"
|
|
17
25
|
},
|
|
18
26
|
"./devtools": {
|
|
19
|
-
"types": "./dist/devtools.d.ts",
|
|
20
27
|
"import": "./dist/devtools.js",
|
|
21
|
-
"require": "./dist/devtools.cjs"
|
|
28
|
+
"require": "./dist/devtools.cjs",
|
|
29
|
+
"types": "./dist/devtools.d.ts"
|
|
22
30
|
},
|
|
23
31
|
"./testing": {
|
|
24
|
-
"types": "./dist/testing/index.d.ts",
|
|
25
32
|
"import": "./dist/testing.js",
|
|
26
|
-
"require": "./dist/testing.cjs"
|
|
33
|
+
"require": "./dist/testing.cjs",
|
|
34
|
+
"types": "./dist/testing/index.d.ts"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"typesVersions": {
|
|
38
|
+
"*": {
|
|
39
|
+
"devtools": [
|
|
40
|
+
"dist/devtools.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"testing": [
|
|
43
|
+
"dist/testing/index.d.ts"
|
|
44
|
+
]
|
|
27
45
|
}
|
|
28
46
|
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"registry": "https://registry.npmjs.org/"
|
|
50
|
+
},
|
|
29
51
|
"scripts": {
|
|
30
52
|
"bench": "vitest bench",
|
|
31
53
|
"build": "vite build && pnpm run build:bundle && pnpm run build:types",
|
|
54
|
+
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
32
55
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
33
|
-
"fix": "
|
|
34
|
-
"lint": "
|
|
56
|
+
"fix": "biome check --write src",
|
|
57
|
+
"lint": "biome ci src",
|
|
35
58
|
"prepublishOnly": "pnpm run build",
|
|
36
59
|
"preview": "vite preview",
|
|
37
|
-
"test": "vitest"
|
|
38
|
-
"build:bundle": "vite build --config vite.bundle.config.ts"
|
|
39
|
-
},
|
|
40
|
-
"publishConfig": {
|
|
41
|
-
"access": "public",
|
|
42
|
-
"registry": "https://registry.npmjs.org/"
|
|
43
|
-
},
|
|
44
|
-
"engines": {
|
|
45
|
-
"node": ">=22"
|
|
60
|
+
"test": "vitest"
|
|
46
61
|
},
|
|
47
62
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^26.
|
|
63
|
+
"@types/node": "^26.2.0",
|
|
49
64
|
"typescript": "^6.0.3",
|
|
50
|
-
"vite": "^8.2.
|
|
65
|
+
"vite": "^8.2.1",
|
|
51
66
|
"vitest": "^4.1.10"
|
|
52
|
-
},
|
|
53
|
-
"typesVersions": {
|
|
54
|
-
"*": {
|
|
55
|
-
"devtools": [
|
|
56
|
-
"dist/devtools.d.ts"
|
|
57
|
-
],
|
|
58
|
-
"testing": [
|
|
59
|
-
"dist/testing/index.d.ts"
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
67
|
}
|
|
63
68
|
}
|
package/dist/_prototype.cjs
DELETED
package/dist/_prototype.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_prototype.cjs","names":[],"sources":["../src/_prototype.ts"],"sourcesContent":["/**\n * Property names that must never be used as a bracket-assignment key on a plain object literal —\n * `obj[key] = value` for `key === '__proto__'` invokes `Object.prototype`'s `__proto__` accessor\n * and reassigns `obj`'s own prototype instead of setting an own property. `constructor` and\n * `prototype` are excluded defensively for the same class of risk.\n *\n * Used when copying event-name-keyed `Map` entries into a plain object (`behavior-bus.ts`'s\n * `snapshot()`, `testing/testing.ts`'s `allEmitted()`) — event names ultimately come from a\n * caller-supplied `EventMap` type, but nothing prevents a caller from wiring in a\n * dynamically-determined (e.g. user-supplied) event name at runtime.\n *\n * @internal\n */\nconst UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/** @internal */\nexport function isUnsafeObjectKey(key: string): boolean {\n return UNSAFE_OBJECT_KEYS.has(key);\n}\n"],"mappings":"AAaA,IAAM,EAAqB,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAG5E,SAAgB,EAAkB,EAAsB,CACtD,OAAO,EAAmB,IAAI,CAAG,CACnC"}
|
package/dist/_prototype.d.ts
DELETED
package/dist/_prototype.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_prototype.d.ts","sourceRoot":"","sources":["../src/_prototype.ts"],"names":[],"mappings":""}
|
package/dist/_prototype.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/_prototype.ts
|
|
2
|
-
var e = /* @__PURE__ */ new Set([
|
|
3
|
-
"__proto__",
|
|
4
|
-
"constructor",
|
|
5
|
-
"prototype"
|
|
6
|
-
]);
|
|
7
|
-
function t(t) {
|
|
8
|
-
return e.has(t);
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { t as isUnsafeObjectKey };
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=_prototype.js.map
|
package/dist/_prototype.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_prototype.js","names":[],"sources":["../src/_prototype.ts"],"sourcesContent":["/**\n * Property names that must never be used as a bracket-assignment key on a plain object literal —\n * `obj[key] = value` for `key === '__proto__'` invokes `Object.prototype`'s `__proto__` accessor\n * and reassigns `obj`'s own prototype instead of setting an own property. `constructor` and\n * `prototype` are excluded defensively for the same class of risk.\n *\n * Used when copying event-name-keyed `Map` entries into a plain object (`behavior-bus.ts`'s\n * `snapshot()`, `testing/testing.ts`'s `allEmitted()`) — event names ultimately come from a\n * caller-supplied `EventMap` type, but nothing prevents a caller from wiring in a\n * dynamically-determined (e.g. user-supplied) event name at runtime.\n *\n * @internal\n */\nconst UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/** @internal */\nexport function isUnsafeObjectKey(key: string): boolean {\n return UNSAFE_OBJECT_KEYS.has(key);\n}\n"],"mappings":";AAaA,IAAM,oBAAqB,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAG5E,SAAgB,EAAkB,GAAsB;CACtD,OAAO,EAAmB,IAAI,CAAG;AACnC"}
|