@youssoufcherif/signals-memory 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Youssouf Cherif Hamed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @youssoufcherif/signals-memory
2
+
3
+ > ⚠️ **Pre-alpha (`0.0.x`)** — built in the open, APIs change without notice.
4
+ > Not yet supported for use outside the author's projects. See the
5
+ > [repo README](https://github.com/yhcherif/signals#readme).
6
+
7
+ In-memory provider for [Signals](https://github.com/yhcherif/signals). A real,
8
+ working implementation that records every span, log, and metric in process
9
+ memory — the test double for code instrumented with Signals, with no mocking
10
+ library involved.
11
+
12
+ ```bash
13
+ pnpm add -D @youssoufcherif/signals-memory
14
+ ```
15
+
16
+ ```ts
17
+ import { createMemorySignals } from '@youssoufcherif/signals-memory';
18
+
19
+ const signals = createMemorySignals();
20
+
21
+ await signals.trace.run('checkout.process', async (ctx) => {
22
+ ctx.metric.counter('payment.attempts');
23
+ });
24
+
25
+ signals.getSpans(); // RecordedSpan[]
26
+ signals.getLogs(); // RecordedLog[]
27
+ signals.getMetrics(); // RecordedMetric[]
28
+ signals.reset();
29
+ ```
30
+
31
+ For readable assertions on top of this, see
32
+ [`@youssoufcherif/signals-testing`](https://www.npmjs.com/package/@youssoufcherif/signals-testing).
33
+
34
+ MIT © Youssouf Cherif Hamed
@@ -0,0 +1,20 @@
1
+ import type { Signals } from '@youssoufcherif/signals-core';
2
+ import type { RecordedLog, RecordedMetric, RecordedSpan } from './make-memory-port.js';
3
+ export type MemorySignals = Signals & {
4
+ getSpans: () => RecordedSpan[];
5
+ getLogs: () => RecordedLog[];
6
+ getMetrics: () => RecordedMetric[];
7
+ reset: () => void;
8
+ };
9
+ /**
10
+ * The one-line convenience matching the "fake strategy is enough" goal:
11
+ *
12
+ * const signals = createMemorySignals();
13
+ * await signals.trace.run('checkout', ...);
14
+ * expect(signals.getSpans()).toHaveLength(1);
15
+ *
16
+ * This is a real, working implementation exercising the exact same
17
+ * `createSignals` composition every other adapter uses — not a mock.
18
+ */
19
+ export declare function createMemorySignals(): MemorySignals;
20
+ //# sourceMappingURL=create-memory-signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-memory-signals.d.ts","sourceRoot":"","sources":["../src/create-memory-signals.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEvF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC,QAAQ,EAAE,MAAM,YAAY,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,WAAW,EAAE,CAAC;IAC7B,UAAU,EAAE,MAAM,cAAc,EAAE,CAAC;IACnC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAUnD"}
@@ -0,0 +1,24 @@
1
+ import { createSignals } from '@youssoufcherif/signals-core';
2
+ import { makeMemoryPort } from './make-memory-port.js';
3
+ /**
4
+ * The one-line convenience matching the "fake strategy is enough" goal:
5
+ *
6
+ * const signals = createMemorySignals();
7
+ * await signals.trace.run('checkout', ...);
8
+ * expect(signals.getSpans()).toHaveLength(1);
9
+ *
10
+ * This is a real, working implementation exercising the exact same
11
+ * `createSignals` composition every other adapter uses — not a mock.
12
+ */
13
+ export function createMemorySignals() {
14
+ const memoryPort = makeMemoryPort();
15
+ const signals = createSignals(memoryPort);
16
+ return {
17
+ ...signals,
18
+ getSpans: memoryPort.getSpans,
19
+ getLogs: memoryPort.getLogs,
20
+ getMetrics: memoryPort.getMetrics,
21
+ reset: memoryPort.reset,
22
+ };
23
+ }
24
+ //# sourceMappingURL=create-memory-signals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-memory-signals.js","sourceRoot":"","sources":["../src/create-memory-signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAUvD;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,UAAU,GAAG,cAAc,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IAC1C,OAAO;QACL,GAAG,OAAO;QACV,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,KAAK,EAAE,UAAU,CAAC,KAAK;KACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { makeMemoryPort } from './make-memory-port.js';
2
+ export type { MemoryPort, RecordedLog, RecordedMetric, RecordedSpan } from './make-memory-port.js';
3
+ export { createMemorySignals } from './create-memory-signals.js';
4
+ export type { MemorySignals } from './create-memory-signals.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { makeMemoryPort } from './make-memory-port.js';
2
+ export { createMemorySignals } from './create-memory-signals.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { AttrRecord, LogLevel, MetricKind, SpanHandle } from '@youssoufcherif/signals-core';
2
+ export type RecordedSpan = {
3
+ id: string;
4
+ name: string;
5
+ parentId?: string | undefined;
6
+ attributes: AttrRecord;
7
+ events: {
8
+ name: string;
9
+ attrs?: AttrRecord | undefined;
10
+ }[];
11
+ exceptions: unknown[];
12
+ ended: boolean;
13
+ };
14
+ export type RecordedLog = {
15
+ level: LogLevel;
16
+ message: string;
17
+ attrs?: AttrRecord | undefined;
18
+ };
19
+ export type RecordedMetric = {
20
+ kind: MetricKind;
21
+ name: string;
22
+ value: number;
23
+ attrs?: AttrRecord | undefined;
24
+ };
25
+ /**
26
+ * The memory strategy: `SignalsPort` implemented with plain closures over
27
+ * arrays, plus three inspection getters that are NOT part of `SignalsPort`
28
+ * — they're extra surface this package adds on top so tests can assert on
29
+ * what happened. Returning "port fields + extra fields" still satisfies
30
+ * `SignalsPort` structurally; nothing here needs a class or a cast.
31
+ */
32
+ export declare function makeMemoryPort(): {
33
+ startSpan: (name: string, parent: SpanHandle | undefined, attrs?: AttrRecord) => SpanHandle;
34
+ log: (level: LogLevel, message: string, attrs?: AttrRecord) => void;
35
+ recordMetric: (kind: MetricKind, name: string, value: number, attrs?: AttrRecord) => void;
36
+ flush: () => Promise<void>;
37
+ getSpans: () => RecordedSpan[];
38
+ getLogs: () => RecordedLog[];
39
+ getMetrics: () => RecordedMetric[];
40
+ reset: () => void;
41
+ };
42
+ export type MemoryPort = ReturnType<typeof makeMemoryPort>;
43
+ //# sourceMappingURL=make-memory-port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-memory-port.d.ts","sourceRoot":"","sources":["../src/make-memory-port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EAEV,UAAU,EACX,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;KAAE,EAAE,CAAC;IAC3D,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,cAAc;;;;;oBAqDZ,YAAY,EAAE;mBACf,WAAW,EAAE;sBACV,cAAc,EAAE;iBACrB,IAAI;EAMlB;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The memory strategy: `SignalsPort` implemented with plain closures over
3
+ * arrays, plus three inspection getters that are NOT part of `SignalsPort`
4
+ * — they're extra surface this package adds on top so tests can assert on
5
+ * what happened. Returning "port fields + extra fields" still satisfies
6
+ * `SignalsPort` structurally; nothing here needs a class or a cast.
7
+ */
8
+ export function makeMemoryPort() {
9
+ const spans = [];
10
+ const logs = [];
11
+ const metrics = [];
12
+ let spanCounter = 0;
13
+ const startSpan = (name, parent, attrs) => {
14
+ const id = `span-${++spanCounter}`;
15
+ const parentSpanId = parent?.getCorrelation()['spanId'];
16
+ const record = {
17
+ id,
18
+ name,
19
+ parentId: typeof parentSpanId === 'string' ? parentSpanId : undefined,
20
+ attributes: { ...attrs },
21
+ events: [],
22
+ exceptions: [],
23
+ ended: false,
24
+ };
25
+ spans.push(record);
26
+ const handle = {
27
+ setAttribute: (key, value) => {
28
+ record.attributes[key] = value;
29
+ },
30
+ addEvent: (eventName, eventAttrs) => {
31
+ record.events.push({ name: eventName, attrs: eventAttrs });
32
+ },
33
+ recordException: (error) => {
34
+ record.exceptions.push(error);
35
+ },
36
+ end: () => {
37
+ record.ended = true;
38
+ },
39
+ getCorrelation: () => ({ traceId: 'memory-trace', spanId: id }),
40
+ };
41
+ return handle;
42
+ };
43
+ const log = (level, message, attrs) => {
44
+ logs.push({ level, message, attrs });
45
+ };
46
+ const recordMetric = (kind, name, value, attrs) => {
47
+ metrics.push({ kind, name, value, attrs });
48
+ };
49
+ const flush = async () => { };
50
+ return {
51
+ startSpan,
52
+ log,
53
+ recordMetric,
54
+ flush,
55
+ getSpans: () => [...spans],
56
+ getLogs: () => [...logs],
57
+ getMetrics: () => [...metrics],
58
+ reset: () => {
59
+ spans.length = 0;
60
+ logs.length = 0;
61
+ metrics.length = 0;
62
+ },
63
+ };
64
+ }
65
+ //# sourceMappingURL=make-memory-port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-memory-port.js","sourceRoot":"","sources":["../src/make-memory-port.ts"],"names":[],"mappings":"AA+BA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAqB,EAAE,CAAC;IACrC,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,MAAM,SAAS,GAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;QAClE,MAAM,EAAE,GAAG,QAAQ,EAAE,WAAW,EAAE,CAAC;QACnC,MAAM,YAAY,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,QAAQ,CAAC,CAAC;QACxD,MAAM,MAAM,GAAiB;YAC3B,EAAE;YACF,IAAI;YACJ,QAAQ,EAAE,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;YACrE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE;YACxB,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,EAAE;YACd,KAAK,EAAE,KAAK;SACb,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnB,MAAM,MAAM,GAAe;YACzB,YAAY,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBAC3B,MAA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AqB,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;QAChD,KAAK,EAAE,GAAS,EAAE;YAChB,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAChB,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@youssoufcherif/signals-memory",
3
+ "version": "0.0.1",
4
+ "description": "In-memory Signals provider for tests - a real, working strategy, not a mock.",
5
+ "license": "MIT",
6
+ "author": "Youssouf Cherif Hamed <youssouf.cherif.hamed@gmail.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/yhcherif/signals.git",
10
+ "directory": "packages/memory"
11
+ },
12
+ "homepage": "https://github.com/yhcherif/signals/tree/main/packages/memory#readme",
13
+ "bugs": "https://github.com/yhcherif/signals/issues",
14
+ "keywords": [
15
+ "telemetry",
16
+ "observability",
17
+ "signals",
18
+ "testing",
19
+ "in-memory"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "LICENSE"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "dependencies": {
43
+ "@youssoufcherif/signals-core": "0.0.1"
44
+ },
45
+ "devDependencies": {
46
+ "typescript": "^5.6.0",
47
+ "vitest": "^2.1.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.json",
51
+ "test": "vitest run"
52
+ }
53
+ }