@reqray/store-memory 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ruslan Kryklyvyi
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 CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # @reqray/store-memory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reqray in-memory store: the ring buffer the panel reads from, and the transport that fills it.
4
+
5
+ Part of [Reqray](https://github.com/reqray/reqray) — a dev panel and request-inspection tool for
6
+ Node.js. It instruments HTTP, SQL, outgoing calls and cache on its own, shows
7
+ every request as a waterfall, and finds N+1 down to the file and the line.
8
+
9
+ Documentation, screenshots and a demo that runs with one command are in the
10
+ [main README](https://github.com/reqray/reqray#readme).
11
+
12
+ ## License
13
+
14
+ [MIT](https://github.com/reqray/reqray/blob/main/LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PIN_LIMIT: () => PIN_LIMIT,
24
+ memoryTransport: () => memoryTransport
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_core = require("@reqray/core");
28
+ var import_panel = require("@reqray/core/panel");
29
+ var PIN_LIMIT = 50;
30
+ function memoryTransport(options = {}) {
31
+ const buffer = new import_core.RingBuffer(options.capacity ?? 500);
32
+ const byId = /* @__PURE__ */ new Map();
33
+ const listeners = /* @__PURE__ */ new Set();
34
+ const pinned = /* @__PURE__ */ new Map();
35
+ const findingStates = /* @__PURE__ */ new Map();
36
+ function listAll() {
37
+ const items = buffer.toArray();
38
+ if (pinned.size === 0) return items;
39
+ const inRing = new Set(items.map((item) => item.id));
40
+ const survivors = [...pinned.values()].filter((item) => !inRing.has(item.id));
41
+ if (survivors.length === 0) return items;
42
+ return [...items, ...survivors].sort((a, b) => b.startedAt - a.startedAt);
43
+ }
44
+ return {
45
+ name: "memory",
46
+ send(request) {
47
+ const displaced = buffer.push(request);
48
+ if (displaced) byId.delete(displaced.id);
49
+ byId.set(request.id, request);
50
+ for (const listener of listeners) {
51
+ try {
52
+ listener(request);
53
+ } catch {
54
+ }
55
+ }
56
+ },
57
+ list: listAll,
58
+ durations(query) {
59
+ const samples = [];
60
+ for (const item of listAll()) {
61
+ if (item.id === query.excludeId) continue;
62
+ if (query.from !== void 0 && item.startedAt < query.from) continue;
63
+ if (query.to !== void 0 && item.startedAt > query.to) continue;
64
+ if (item.method !== query.method) continue;
65
+ if ((0, import_panel.normalizeRoute)(item.path) !== query.route) continue;
66
+ samples.push({
67
+ durationMs: item.durationMs,
68
+ startedAt: item.startedAt,
69
+ hasError: item.error !== null || item.status >= 500,
70
+ loopDelayMs: item.host?.loopDelayMs ?? null
71
+ });
72
+ }
73
+ return samples;
74
+ },
75
+ counts(query) {
76
+ const grouped = /* @__PURE__ */ new Map();
77
+ for (const item of listAll()) {
78
+ if (item.startedAt < query.from || item.startedAt > query.to) continue;
79
+ const route = (0, import_panel.normalizeRoute)(item.path);
80
+ const key = `${item.method} ${route}`;
81
+ const found = grouped.get(key);
82
+ if (found) {
83
+ found.calls++;
84
+ found.ms += item.durationMs;
85
+ } else {
86
+ grouped.set(key, { method: item.method, route, calls: 1, ms: item.durationMs });
87
+ }
88
+ }
89
+ return [...grouped.values()].map((entry) => ({
90
+ method: entry.method,
91
+ route: entry.route,
92
+ calls: entry.calls,
93
+ avgMs: entry.ms / entry.calls
94
+ }));
95
+ },
96
+ timeSeries() {
97
+ return listAll().map((item) => ({
98
+ startedAt: item.startedAt,
99
+ durationMs: item.durationMs,
100
+ hasError: item.error !== null || item.status >= 500
101
+ }));
102
+ },
103
+ findings(query) {
104
+ const from = query.from ?? Number.NEGATIVE_INFINITY;
105
+ const to = query.to ?? Number.POSITIVE_INFINITY;
106
+ const samples = listAll().filter(
107
+ (item) => item.findings.length > 0 && item.startedAt >= from && item.startedAt <= to
108
+ ).flatMap(import_panel.findingSamplesOf);
109
+ return { samples, truncated: false };
110
+ },
111
+ findingStates() {
112
+ return findingStates;
113
+ },
114
+ setFindingState(id, state) {
115
+ if (state === "new") findingStates.delete(id);
116
+ else findingStates.set(id, state);
117
+ },
118
+ history(query) {
119
+ const samples = (0, import_panel.filterRequests)(listAll(), query.filter).map(import_panel.historySampleOf);
120
+ return { samples, truncated: false };
121
+ },
122
+ page(query) {
123
+ return (0, import_panel.pageFromList)(listAll(), query, { pinned: new Set(pinned.keys()) });
124
+ },
125
+ get(id) {
126
+ return byId.get(id) ?? pinned.get(id);
127
+ },
128
+ clear() {
129
+ buffer.clear();
130
+ byId.clear();
131
+ pinned.clear();
132
+ },
133
+ stats() {
134
+ const items = listAll();
135
+ const oldest = items[items.length - 1];
136
+ return {
137
+ // The ring's own occupancy; pinned survivors are counted separately.
138
+ size: buffer.size,
139
+ capacity: buffer.capacity,
140
+ evicted: buffer.evicted,
141
+ oldestAt: oldest ? oldest.startedAt : null,
142
+ pinned: pinned.size
143
+ };
144
+ },
145
+ pin(id, wanted) {
146
+ if (!wanted) {
147
+ pinned.delete(id);
148
+ return true;
149
+ }
150
+ if (pinned.has(id)) return true;
151
+ if (pinned.size >= PIN_LIMIT) return false;
152
+ const record = byId.get(id);
153
+ if (!record) return false;
154
+ pinned.set(id, record);
155
+ return true;
156
+ },
157
+ pinned() {
158
+ return [...pinned.keys()];
159
+ },
160
+ subscribe(listener) {
161
+ listeners.add(listener);
162
+ return () => {
163
+ listeners.delete(listener);
164
+ };
165
+ }
166
+ };
167
+ }
168
+ // Annotate the CommonJS export names for ESM import in node:
169
+ 0 && (module.exports = {
170
+ PIN_LIMIT,
171
+ memoryTransport
172
+ });
173
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reqray/store-memory` — transport and store for local development.\n *\n * Data sits in a ring buffer inside the application itself. Nothing leaves the\n * process, nothing is written to disk: this is the default for\n * `NODE_ENV=development`. In staging and production an HTTP transport to an\n * external collector takes its place.\n */\n\nimport { RingBuffer, type Transport } from '@reqray/core';\nimport {\n type BaselineQuery,\n type DurationSample,\n type FindingSamples,\n type FindingsQuery,\n filterRequests,\n findingSamplesOf,\n type HistoryQuery,\n type HistorySamples,\n historySampleOf,\n normalizeRoute,\n type PageQuery,\n pageFromList,\n type RequestPage,\n type RouteWindow,\n type TimePoint,\n} from '@reqray/core/panel';\nimport type { FiledPatternState, RecordedRequest, StoredPatternState } from '@reqray/protocol';\n\n/** Options for {@link memoryTransport}. */\nexport interface MemoryTransportOptions {\n /** How many requests to keep. Older ones are evicted. */\n readonly capacity?: number;\n}\n\n/**\n * How many requests may be pinned at once.\n *\n * Pinning suspends the ring buffer's promise that memory is bounded, so it\n * gets a bound of its own. Fifty full records with capped bodies is a few\n * megabytes — the price of keeping the incident you are working on.\n */\nexport const PIN_LIMIT = 50;\n\n/** Buffer summary — what the panel shows in its status bar. */\nexport interface MemoryStoreStats {\n readonly size: number;\n readonly capacity: number;\n /** How many requests have been evicted since the start. */\n readonly evicted: number;\n /** Start time of the oldest request in the buffer, epoch ms. */\n readonly oldestAt: number | null;\n /** How many requests are pinned, out of {@link PIN_LIMIT}. */\n readonly pinned: number;\n}\n\n/** Subscriber for new requests. Needed by the panel's live feed. */\nexport type MemoryStoreListener = (request: RecordedRequest) => void;\n\n/** A transport that is also the store the panel reads from. */\nexport interface MemoryStore extends Transport {\n /** Requests newest first — the order the panel displays them in. */\n list(): RecordedRequest[];\n get(id: string): RecordedRequest | undefined;\n clear(): void;\n stats(): MemoryStoreStats;\n /** @returns unsubscribe function. */\n subscribe(listener: MemoryStoreListener): () => void;\n /**\n * Holds a request past its turn in the ring, or lets it go again.\n *\n * @returns `false` when the request is already gone or {@link PIN_LIMIT} is\n * reached. Unpinning always succeeds.\n */\n pin(id: string, pinned: boolean): boolean;\n /** Ids currently pinned. */\n pinned(): string[];\n /**\n * One page of the list, newest first.\n *\n * A ring this size could be served whole, and was — but the panel must not\n * behave differently depending on which store is behind it, and a store\n * that can page is the shape the panel now asks for.\n */\n page(query: PageQuery): RequestPage;\n /** Durations of other calls of one route, for the detail page's verdict. */\n durations(query: BaselineQuery): DurationSample[];\n /** Traffic grouped by route over a stretch of time. */\n counts(query: { from: number; to: number }): RouteWindow[];\n /** Three numbers per request, for the strip above the list. */\n timeSeries(): TimePoint[];\n /** A period's requests, a handful of numbers each, for the history screen. */\n history(query: HistoryQuery): HistorySamples;\n /** Finding occurrences over a stretch, one row each, for the findings tab. */\n findings(query: FindingsQuery): FindingSamples;\n /** `ack`/`muted` per pattern id, as the reader left them. */\n findingStates(): ReadonlyMap<string, FiledPatternState>;\n /** Remembers a state; `new` forgets the pattern. */\n setFindingState(id: string, state: StoredPatternState): void;\n}\n\nexport function memoryTransport(options: MemoryTransportOptions = {}): MemoryStore {\n const buffer = new RingBuffer<RecordedRequest>(options.capacity ?? 500);\n const byId = new Map<string, RecordedRequest>();\n const listeners = new Set<MemoryStoreListener>();\n /**\n * Pinned records, held here rather than inside the ring: the ring is a plain\n * \"drop the oldest\" structure and stays that way — skipping slots would cost\n * every push a branch, on the path that has to stay cheap.\n */\n const pinned = new Map<string, RecordedRequest>();\n /**\n * The reader's bookkeeping per finding pattern.\n *\n * In memory beside the requests, and gone with them: a buffer that forgets\n * its requests on restart has nothing for a remembered `ack` to be about.\n * The SQLite store is the one that keeps both.\n */\n const findingStates = new Map<string, FiledPatternState>();\n\n /** The ring plus any pinned records it has already dropped, newest first. */\n function listAll(): RecordedRequest[] {\n const items = buffer.toArray();\n if (pinned.size === 0) return items;\n\n const inRing = new Set(items.map((item) => item.id));\n const survivors = [...pinned.values()].filter((item) => !inRing.has(item.id));\n if (survivors.length === 0) return items;\n // Survivors are older than everything in the ring, but sorting keeps the\n // \"newest first\" promise without depending on that.\n return [...items, ...survivors].sort((a, b) => b.startedAt - a.startedAt);\n }\n\n return {\n name: 'memory',\n\n send(request) {\n const displaced = buffer.push(request);\n // A displaced record that is pinned lives on in `pinned`; `get` and\n // `list` look there too.\n if (displaced) byId.delete(displaced.id);\n byId.set(request.id, request);\n\n for (const listener of listeners) {\n try {\n listener(request);\n } catch {\n // A broken subscriber must not break data collection.\n }\n }\n },\n\n list: listAll,\n\n durations(query: BaselineQuery): DurationSample[] {\n const samples: DurationSample[] = [];\n for (const item of listAll()) {\n if (item.id === query.excludeId) continue;\n if (query.from !== undefined && item.startedAt < query.from) continue;\n if (query.to !== undefined && item.startedAt > query.to) continue;\n if (item.method !== query.method) continue;\n if (normalizeRoute(item.path) !== query.route) continue;\n samples.push({\n durationMs: item.durationMs,\n startedAt: item.startedAt,\n hasError: item.error !== null || item.status >= 500,\n loopDelayMs: item.host?.loopDelayMs ?? null,\n });\n }\n return samples;\n },\n\n counts(query: { from: number; to: number }): RouteWindow[] {\n const grouped = new Map<\n string,\n { method: string; route: string; calls: number; ms: number }\n >();\n for (const item of listAll()) {\n if (item.startedAt < query.from || item.startedAt > query.to) continue;\n const route = normalizeRoute(item.path);\n const key = `${item.method} ${route}`;\n const found = grouped.get(key);\n if (found) {\n found.calls++;\n found.ms += item.durationMs;\n } else {\n grouped.set(key, { method: item.method, route, calls: 1, ms: item.durationMs });\n }\n }\n return [...grouped.values()].map((entry) => ({\n method: entry.method,\n route: entry.route,\n calls: entry.calls,\n avgMs: entry.ms / entry.calls,\n }));\n },\n\n timeSeries(): TimePoint[] {\n return listAll().map((item) => ({\n startedAt: item.startedAt,\n durationMs: item.durationMs,\n hasError: item.error !== null || item.status >= 500,\n }));\n },\n\n findings(query: FindingsQuery): FindingSamples {\n const from = query.from ?? Number.NEGATIVE_INFINITY;\n const to = query.to ?? Number.POSITIVE_INFINITY;\n // Bounded by the ring itself, so never truncated — the same honesty\n // deal `history` makes.\n const samples = listAll()\n .filter(\n (item) => item.findings.length > 0 && item.startedAt >= from && item.startedAt <= to,\n )\n .flatMap(findingSamplesOf);\n return { samples, truncated: false };\n },\n\n findingStates(): ReadonlyMap<string, FiledPatternState> {\n return findingStates;\n },\n\n setFindingState(id: string, state: StoredPatternState): void {\n if (state === 'new') findingStates.delete(id);\n else findingStates.set(id, state);\n },\n\n history(query: HistoryQuery): HistorySamples {\n // Never truncated, and not out of generosity: the ring holds what it\n // holds, so reading all of it is bounded by its own capacity. Whether\n // the period reaches further back than the ring does is a different\n // question, and one the retention card on the Project tab answers.\n const samples = filterRequests(listAll(), query.filter).map(historySampleOf);\n return { samples, truncated: false };\n },\n\n page(query: PageQuery): RequestPage {\n // The rule — pinned rows survive a filter, the cursor counts in whatever\n // the sort orders by — lives in core, so that this store and the panel's\n // own fallback cannot answer differently.\n return pageFromList(listAll(), query, { pinned: new Set(pinned.keys()) });\n },\n\n get(id) {\n return byId.get(id) ?? pinned.get(id);\n },\n\n clear() {\n buffer.clear();\n byId.clear();\n // `clear` is someone asking for an empty panel; keeping pinned rows\n // around would leave the list stubbornly non-empty.\n pinned.clear();\n },\n\n stats() {\n const items = listAll();\n const oldest = items[items.length - 1];\n return {\n // The ring's own occupancy; pinned survivors are counted separately.\n size: buffer.size,\n capacity: buffer.capacity,\n evicted: buffer.evicted,\n oldestAt: oldest ? oldest.startedAt : null,\n pinned: pinned.size,\n };\n },\n\n pin(id, wanted) {\n if (!wanted) {\n pinned.delete(id);\n return true;\n }\n if (pinned.has(id)) return true;\n if (pinned.size >= PIN_LIMIT) return false;\n const record = byId.get(id);\n if (!record) return false;\n pinned.set(id, record);\n return true;\n },\n\n pinned() {\n return [...pinned.keys()];\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,kBAA2C;AAC3C,mBAgBO;AAgBA,IAAM,YAAY;AA2DlB,SAAS,gBAAgB,UAAkC,CAAC,GAAgB;AACjF,QAAM,SAAS,IAAI,uBAA4B,QAAQ,YAAY,GAAG;AACtE,QAAM,OAAO,oBAAI,IAA6B;AAC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;AACP,aAAO,CAAC,GAAG,OAAO,KAAK,CAAC;AAAA,IAC1B;AAAA,IAEA,UAAU,UAAU;AAClB,gBAAU,IAAI,QAAQ;AACtB,aAAO,MAAM;AACX,kBAAU,OAAO,QAAQ;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,86 @@
1
+ import { Transport } from '@reqray/core';
2
+ import { PageQuery, RequestPage, BaselineQuery, DurationSample, RouteWindow, TimePoint, HistoryQuery, HistorySamples, FindingsQuery, FindingSamples } from '@reqray/core/panel';
3
+ import { RecordedRequest, FiledPatternState, StoredPatternState } from '@reqray/protocol';
4
+
5
+ /**
6
+ * `@reqray/store-memory` — transport and store for local development.
7
+ *
8
+ * Data sits in a ring buffer inside the application itself. Nothing leaves the
9
+ * process, nothing is written to disk: this is the default for
10
+ * `NODE_ENV=development`. In staging and production an HTTP transport to an
11
+ * external collector takes its place.
12
+ */
13
+
14
+ /** Options for {@link memoryTransport}. */
15
+ interface MemoryTransportOptions {
16
+ /** How many requests to keep. Older ones are evicted. */
17
+ readonly capacity?: number;
18
+ }
19
+ /**
20
+ * How many requests may be pinned at once.
21
+ *
22
+ * Pinning suspends the ring buffer's promise that memory is bounded, so it
23
+ * gets a bound of its own. Fifty full records with capped bodies is a few
24
+ * megabytes — the price of keeping the incident you are working on.
25
+ */
26
+ declare const PIN_LIMIT = 50;
27
+ /** Buffer summary — what the panel shows in its status bar. */
28
+ interface MemoryStoreStats {
29
+ readonly size: number;
30
+ readonly capacity: number;
31
+ /** How many requests have been evicted since the start. */
32
+ readonly evicted: number;
33
+ /** Start time of the oldest request in the buffer, epoch ms. */
34
+ readonly oldestAt: number | null;
35
+ /** How many requests are pinned, out of {@link PIN_LIMIT}. */
36
+ readonly pinned: number;
37
+ }
38
+ /** Subscriber for new requests. Needed by the panel's live feed. */
39
+ type MemoryStoreListener = (request: RecordedRequest) => void;
40
+ /** A transport that is also the store the panel reads from. */
41
+ interface MemoryStore extends Transport {
42
+ /** Requests newest first — the order the panel displays them in. */
43
+ list(): RecordedRequest[];
44
+ get(id: string): RecordedRequest | undefined;
45
+ clear(): void;
46
+ stats(): MemoryStoreStats;
47
+ /** @returns unsubscribe function. */
48
+ subscribe(listener: MemoryStoreListener): () => void;
49
+ /**
50
+ * Holds a request past its turn in the ring, or lets it go again.
51
+ *
52
+ * @returns `false` when the request is already gone or {@link PIN_LIMIT} is
53
+ * reached. Unpinning always succeeds.
54
+ */
55
+ pin(id: string, pinned: boolean): boolean;
56
+ /** Ids currently pinned. */
57
+ pinned(): string[];
58
+ /**
59
+ * One page of the list, newest first.
60
+ *
61
+ * A ring this size could be served whole, and was — but the panel must not
62
+ * behave differently depending on which store is behind it, and a store
63
+ * that can page is the shape the panel now asks for.
64
+ */
65
+ page(query: PageQuery): RequestPage;
66
+ /** Durations of other calls of one route, for the detail page's verdict. */
67
+ durations(query: BaselineQuery): DurationSample[];
68
+ /** Traffic grouped by route over a stretch of time. */
69
+ counts(query: {
70
+ from: number;
71
+ to: number;
72
+ }): RouteWindow[];
73
+ /** Three numbers per request, for the strip above the list. */
74
+ timeSeries(): TimePoint[];
75
+ /** A period's requests, a handful of numbers each, for the history screen. */
76
+ history(query: HistoryQuery): HistorySamples;
77
+ /** Finding occurrences over a stretch, one row each, for the findings tab. */
78
+ findings(query: FindingsQuery): FindingSamples;
79
+ /** `ack`/`muted` per pattern id, as the reader left them. */
80
+ findingStates(): ReadonlyMap<string, FiledPatternState>;
81
+ /** Remembers a state; `new` forgets the pattern. */
82
+ setFindingState(id: string, state: StoredPatternState): void;
83
+ }
84
+ declare function memoryTransport(options?: MemoryTransportOptions): MemoryStore;
85
+
86
+ export { type MemoryStore, type MemoryStoreListener, type MemoryStoreStats, type MemoryTransportOptions, PIN_LIMIT, memoryTransport };
@@ -0,0 +1,86 @@
1
+ import { Transport } from '@reqray/core';
2
+ import { PageQuery, RequestPage, BaselineQuery, DurationSample, RouteWindow, TimePoint, HistoryQuery, HistorySamples, FindingsQuery, FindingSamples } from '@reqray/core/panel';
3
+ import { RecordedRequest, FiledPatternState, StoredPatternState } from '@reqray/protocol';
4
+
5
+ /**
6
+ * `@reqray/store-memory` — transport and store for local development.
7
+ *
8
+ * Data sits in a ring buffer inside the application itself. Nothing leaves the
9
+ * process, nothing is written to disk: this is the default for
10
+ * `NODE_ENV=development`. In staging and production an HTTP transport to an
11
+ * external collector takes its place.
12
+ */
13
+
14
+ /** Options for {@link memoryTransport}. */
15
+ interface MemoryTransportOptions {
16
+ /** How many requests to keep. Older ones are evicted. */
17
+ readonly capacity?: number;
18
+ }
19
+ /**
20
+ * How many requests may be pinned at once.
21
+ *
22
+ * Pinning suspends the ring buffer's promise that memory is bounded, so it
23
+ * gets a bound of its own. Fifty full records with capped bodies is a few
24
+ * megabytes — the price of keeping the incident you are working on.
25
+ */
26
+ declare const PIN_LIMIT = 50;
27
+ /** Buffer summary — what the panel shows in its status bar. */
28
+ interface MemoryStoreStats {
29
+ readonly size: number;
30
+ readonly capacity: number;
31
+ /** How many requests have been evicted since the start. */
32
+ readonly evicted: number;
33
+ /** Start time of the oldest request in the buffer, epoch ms. */
34
+ readonly oldestAt: number | null;
35
+ /** How many requests are pinned, out of {@link PIN_LIMIT}. */
36
+ readonly pinned: number;
37
+ }
38
+ /** Subscriber for new requests. Needed by the panel's live feed. */
39
+ type MemoryStoreListener = (request: RecordedRequest) => void;
40
+ /** A transport that is also the store the panel reads from. */
41
+ interface MemoryStore extends Transport {
42
+ /** Requests newest first — the order the panel displays them in. */
43
+ list(): RecordedRequest[];
44
+ get(id: string): RecordedRequest | undefined;
45
+ clear(): void;
46
+ stats(): MemoryStoreStats;
47
+ /** @returns unsubscribe function. */
48
+ subscribe(listener: MemoryStoreListener): () => void;
49
+ /**
50
+ * Holds a request past its turn in the ring, or lets it go again.
51
+ *
52
+ * @returns `false` when the request is already gone or {@link PIN_LIMIT} is
53
+ * reached. Unpinning always succeeds.
54
+ */
55
+ pin(id: string, pinned: boolean): boolean;
56
+ /** Ids currently pinned. */
57
+ pinned(): string[];
58
+ /**
59
+ * One page of the list, newest first.
60
+ *
61
+ * A ring this size could be served whole, and was — but the panel must not
62
+ * behave differently depending on which store is behind it, and a store
63
+ * that can page is the shape the panel now asks for.
64
+ */
65
+ page(query: PageQuery): RequestPage;
66
+ /** Durations of other calls of one route, for the detail page's verdict. */
67
+ durations(query: BaselineQuery): DurationSample[];
68
+ /** Traffic grouped by route over a stretch of time. */
69
+ counts(query: {
70
+ from: number;
71
+ to: number;
72
+ }): RouteWindow[];
73
+ /** Three numbers per request, for the strip above the list. */
74
+ timeSeries(): TimePoint[];
75
+ /** A period's requests, a handful of numbers each, for the history screen. */
76
+ history(query: HistoryQuery): HistorySamples;
77
+ /** Finding occurrences over a stretch, one row each, for the findings tab. */
78
+ findings(query: FindingsQuery): FindingSamples;
79
+ /** `ack`/`muted` per pattern id, as the reader left them. */
80
+ findingStates(): ReadonlyMap<string, FiledPatternState>;
81
+ /** Remembers a state; `new` forgets the pattern. */
82
+ setFindingState(id: string, state: StoredPatternState): void;
83
+ }
84
+ declare function memoryTransport(options?: MemoryTransportOptions): MemoryStore;
85
+
86
+ export { type MemoryStore, type MemoryStoreListener, type MemoryStoreStats, type MemoryTransportOptions, PIN_LIMIT, memoryTransport };
package/dist/index.js ADDED
@@ -0,0 +1,153 @@
1
+ // src/index.ts
2
+ import { RingBuffer } from "@reqray/core";
3
+ import {
4
+ filterRequests,
5
+ findingSamplesOf,
6
+ historySampleOf,
7
+ normalizeRoute,
8
+ pageFromList
9
+ } from "@reqray/core/panel";
10
+ var PIN_LIMIT = 50;
11
+ function memoryTransport(options = {}) {
12
+ const buffer = new RingBuffer(options.capacity ?? 500);
13
+ const byId = /* @__PURE__ */ new Map();
14
+ const listeners = /* @__PURE__ */ new Set();
15
+ const pinned = /* @__PURE__ */ new Map();
16
+ const findingStates = /* @__PURE__ */ new Map();
17
+ function listAll() {
18
+ const items = buffer.toArray();
19
+ if (pinned.size === 0) return items;
20
+ const inRing = new Set(items.map((item) => item.id));
21
+ const survivors = [...pinned.values()].filter((item) => !inRing.has(item.id));
22
+ if (survivors.length === 0) return items;
23
+ return [...items, ...survivors].sort((a, b) => b.startedAt - a.startedAt);
24
+ }
25
+ return {
26
+ name: "memory",
27
+ send(request) {
28
+ const displaced = buffer.push(request);
29
+ if (displaced) byId.delete(displaced.id);
30
+ byId.set(request.id, request);
31
+ for (const listener of listeners) {
32
+ try {
33
+ listener(request);
34
+ } catch {
35
+ }
36
+ }
37
+ },
38
+ list: listAll,
39
+ durations(query) {
40
+ const samples = [];
41
+ for (const item of listAll()) {
42
+ if (item.id === query.excludeId) continue;
43
+ if (query.from !== void 0 && item.startedAt < query.from) continue;
44
+ if (query.to !== void 0 && item.startedAt > query.to) continue;
45
+ if (item.method !== query.method) continue;
46
+ if (normalizeRoute(item.path) !== query.route) continue;
47
+ samples.push({
48
+ durationMs: item.durationMs,
49
+ startedAt: item.startedAt,
50
+ hasError: item.error !== null || item.status >= 500,
51
+ loopDelayMs: item.host?.loopDelayMs ?? null
52
+ });
53
+ }
54
+ return samples;
55
+ },
56
+ counts(query) {
57
+ const grouped = /* @__PURE__ */ new Map();
58
+ for (const item of listAll()) {
59
+ if (item.startedAt < query.from || item.startedAt > query.to) continue;
60
+ const route = normalizeRoute(item.path);
61
+ const key = `${item.method} ${route}`;
62
+ const found = grouped.get(key);
63
+ if (found) {
64
+ found.calls++;
65
+ found.ms += item.durationMs;
66
+ } else {
67
+ grouped.set(key, { method: item.method, route, calls: 1, ms: item.durationMs });
68
+ }
69
+ }
70
+ return [...grouped.values()].map((entry) => ({
71
+ method: entry.method,
72
+ route: entry.route,
73
+ calls: entry.calls,
74
+ avgMs: entry.ms / entry.calls
75
+ }));
76
+ },
77
+ timeSeries() {
78
+ return listAll().map((item) => ({
79
+ startedAt: item.startedAt,
80
+ durationMs: item.durationMs,
81
+ hasError: item.error !== null || item.status >= 500
82
+ }));
83
+ },
84
+ findings(query) {
85
+ const from = query.from ?? Number.NEGATIVE_INFINITY;
86
+ const to = query.to ?? Number.POSITIVE_INFINITY;
87
+ const samples = listAll().filter(
88
+ (item) => item.findings.length > 0 && item.startedAt >= from && item.startedAt <= to
89
+ ).flatMap(findingSamplesOf);
90
+ return { samples, truncated: false };
91
+ },
92
+ findingStates() {
93
+ return findingStates;
94
+ },
95
+ setFindingState(id, state) {
96
+ if (state === "new") findingStates.delete(id);
97
+ else findingStates.set(id, state);
98
+ },
99
+ history(query) {
100
+ const samples = filterRequests(listAll(), query.filter).map(historySampleOf);
101
+ return { samples, truncated: false };
102
+ },
103
+ page(query) {
104
+ return pageFromList(listAll(), query, { pinned: new Set(pinned.keys()) });
105
+ },
106
+ get(id) {
107
+ return byId.get(id) ?? pinned.get(id);
108
+ },
109
+ clear() {
110
+ buffer.clear();
111
+ byId.clear();
112
+ pinned.clear();
113
+ },
114
+ stats() {
115
+ const items = listAll();
116
+ const oldest = items[items.length - 1];
117
+ return {
118
+ // The ring's own occupancy; pinned survivors are counted separately.
119
+ size: buffer.size,
120
+ capacity: buffer.capacity,
121
+ evicted: buffer.evicted,
122
+ oldestAt: oldest ? oldest.startedAt : null,
123
+ pinned: pinned.size
124
+ };
125
+ },
126
+ pin(id, wanted) {
127
+ if (!wanted) {
128
+ pinned.delete(id);
129
+ return true;
130
+ }
131
+ if (pinned.has(id)) return true;
132
+ if (pinned.size >= PIN_LIMIT) return false;
133
+ const record = byId.get(id);
134
+ if (!record) return false;
135
+ pinned.set(id, record);
136
+ return true;
137
+ },
138
+ pinned() {
139
+ return [...pinned.keys()];
140
+ },
141
+ subscribe(listener) {
142
+ listeners.add(listener);
143
+ return () => {
144
+ listeners.delete(listener);
145
+ };
146
+ }
147
+ };
148
+ }
149
+ export {
150
+ PIN_LIMIT,
151
+ memoryTransport
152
+ };
153
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reqray/store-memory` — transport and store for local development.\n *\n * Data sits in a ring buffer inside the application itself. Nothing leaves the\n * process, nothing is written to disk: this is the default for\n * `NODE_ENV=development`. In staging and production an HTTP transport to an\n * external collector takes its place.\n */\n\nimport { RingBuffer, type Transport } from '@reqray/core';\nimport {\n type BaselineQuery,\n type DurationSample,\n type FindingSamples,\n type FindingsQuery,\n filterRequests,\n findingSamplesOf,\n type HistoryQuery,\n type HistorySamples,\n historySampleOf,\n normalizeRoute,\n type PageQuery,\n pageFromList,\n type RequestPage,\n type RouteWindow,\n type TimePoint,\n} from '@reqray/core/panel';\nimport type { FiledPatternState, RecordedRequest, StoredPatternState } from '@reqray/protocol';\n\n/** Options for {@link memoryTransport}. */\nexport interface MemoryTransportOptions {\n /** How many requests to keep. Older ones are evicted. */\n readonly capacity?: number;\n}\n\n/**\n * How many requests may be pinned at once.\n *\n * Pinning suspends the ring buffer's promise that memory is bounded, so it\n * gets a bound of its own. Fifty full records with capped bodies is a few\n * megabytes — the price of keeping the incident you are working on.\n */\nexport const PIN_LIMIT = 50;\n\n/** Buffer summary — what the panel shows in its status bar. */\nexport interface MemoryStoreStats {\n readonly size: number;\n readonly capacity: number;\n /** How many requests have been evicted since the start. */\n readonly evicted: number;\n /** Start time of the oldest request in the buffer, epoch ms. */\n readonly oldestAt: number | null;\n /** How many requests are pinned, out of {@link PIN_LIMIT}. */\n readonly pinned: number;\n}\n\n/** Subscriber for new requests. Needed by the panel's live feed. */\nexport type MemoryStoreListener = (request: RecordedRequest) => void;\n\n/** A transport that is also the store the panel reads from. */\nexport interface MemoryStore extends Transport {\n /** Requests newest first — the order the panel displays them in. */\n list(): RecordedRequest[];\n get(id: string): RecordedRequest | undefined;\n clear(): void;\n stats(): MemoryStoreStats;\n /** @returns unsubscribe function. */\n subscribe(listener: MemoryStoreListener): () => void;\n /**\n * Holds a request past its turn in the ring, or lets it go again.\n *\n * @returns `false` when the request is already gone or {@link PIN_LIMIT} is\n * reached. Unpinning always succeeds.\n */\n pin(id: string, pinned: boolean): boolean;\n /** Ids currently pinned. */\n pinned(): string[];\n /**\n * One page of the list, newest first.\n *\n * A ring this size could be served whole, and was — but the panel must not\n * behave differently depending on which store is behind it, and a store\n * that can page is the shape the panel now asks for.\n */\n page(query: PageQuery): RequestPage;\n /** Durations of other calls of one route, for the detail page's verdict. */\n durations(query: BaselineQuery): DurationSample[];\n /** Traffic grouped by route over a stretch of time. */\n counts(query: { from: number; to: number }): RouteWindow[];\n /** Three numbers per request, for the strip above the list. */\n timeSeries(): TimePoint[];\n /** A period's requests, a handful of numbers each, for the history screen. */\n history(query: HistoryQuery): HistorySamples;\n /** Finding occurrences over a stretch, one row each, for the findings tab. */\n findings(query: FindingsQuery): FindingSamples;\n /** `ack`/`muted` per pattern id, as the reader left them. */\n findingStates(): ReadonlyMap<string, FiledPatternState>;\n /** Remembers a state; `new` forgets the pattern. */\n setFindingState(id: string, state: StoredPatternState): void;\n}\n\nexport function memoryTransport(options: MemoryTransportOptions = {}): MemoryStore {\n const buffer = new RingBuffer<RecordedRequest>(options.capacity ?? 500);\n const byId = new Map<string, RecordedRequest>();\n const listeners = new Set<MemoryStoreListener>();\n /**\n * Pinned records, held here rather than inside the ring: the ring is a plain\n * \"drop the oldest\" structure and stays that way — skipping slots would cost\n * every push a branch, on the path that has to stay cheap.\n */\n const pinned = new Map<string, RecordedRequest>();\n /**\n * The reader's bookkeeping per finding pattern.\n *\n * In memory beside the requests, and gone with them: a buffer that forgets\n * its requests on restart has nothing for a remembered `ack` to be about.\n * The SQLite store is the one that keeps both.\n */\n const findingStates = new Map<string, FiledPatternState>();\n\n /** The ring plus any pinned records it has already dropped, newest first. */\n function listAll(): RecordedRequest[] {\n const items = buffer.toArray();\n if (pinned.size === 0) return items;\n\n const inRing = new Set(items.map((item) => item.id));\n const survivors = [...pinned.values()].filter((item) => !inRing.has(item.id));\n if (survivors.length === 0) return items;\n // Survivors are older than everything in the ring, but sorting keeps the\n // \"newest first\" promise without depending on that.\n return [...items, ...survivors].sort((a, b) => b.startedAt - a.startedAt);\n }\n\n return {\n name: 'memory',\n\n send(request) {\n const displaced = buffer.push(request);\n // A displaced record that is pinned lives on in `pinned`; `get` and\n // `list` look there too.\n if (displaced) byId.delete(displaced.id);\n byId.set(request.id, request);\n\n for (const listener of listeners) {\n try {\n listener(request);\n } catch {\n // A broken subscriber must not break data collection.\n }\n }\n },\n\n list: listAll,\n\n durations(query: BaselineQuery): DurationSample[] {\n const samples: DurationSample[] = [];\n for (const item of listAll()) {\n if (item.id === query.excludeId) continue;\n if (query.from !== undefined && item.startedAt < query.from) continue;\n if (query.to !== undefined && item.startedAt > query.to) continue;\n if (item.method !== query.method) continue;\n if (normalizeRoute(item.path) !== query.route) continue;\n samples.push({\n durationMs: item.durationMs,\n startedAt: item.startedAt,\n hasError: item.error !== null || item.status >= 500,\n loopDelayMs: item.host?.loopDelayMs ?? null,\n });\n }\n return samples;\n },\n\n counts(query: { from: number; to: number }): RouteWindow[] {\n const grouped = new Map<\n string,\n { method: string; route: string; calls: number; ms: number }\n >();\n for (const item of listAll()) {\n if (item.startedAt < query.from || item.startedAt > query.to) continue;\n const route = normalizeRoute(item.path);\n const key = `${item.method} ${route}`;\n const found = grouped.get(key);\n if (found) {\n found.calls++;\n found.ms += item.durationMs;\n } else {\n grouped.set(key, { method: item.method, route, calls: 1, ms: item.durationMs });\n }\n }\n return [...grouped.values()].map((entry) => ({\n method: entry.method,\n route: entry.route,\n calls: entry.calls,\n avgMs: entry.ms / entry.calls,\n }));\n },\n\n timeSeries(): TimePoint[] {\n return listAll().map((item) => ({\n startedAt: item.startedAt,\n durationMs: item.durationMs,\n hasError: item.error !== null || item.status >= 500,\n }));\n },\n\n findings(query: FindingsQuery): FindingSamples {\n const from = query.from ?? Number.NEGATIVE_INFINITY;\n const to = query.to ?? Number.POSITIVE_INFINITY;\n // Bounded by the ring itself, so never truncated — the same honesty\n // deal `history` makes.\n const samples = listAll()\n .filter(\n (item) => item.findings.length > 0 && item.startedAt >= from && item.startedAt <= to,\n )\n .flatMap(findingSamplesOf);\n return { samples, truncated: false };\n },\n\n findingStates(): ReadonlyMap<string, FiledPatternState> {\n return findingStates;\n },\n\n setFindingState(id: string, state: StoredPatternState): void {\n if (state === 'new') findingStates.delete(id);\n else findingStates.set(id, state);\n },\n\n history(query: HistoryQuery): HistorySamples {\n // Never truncated, and not out of generosity: the ring holds what it\n // holds, so reading all of it is bounded by its own capacity. Whether\n // the period reaches further back than the ring does is a different\n // question, and one the retention card on the Project tab answers.\n const samples = filterRequests(listAll(), query.filter).map(historySampleOf);\n return { samples, truncated: false };\n },\n\n page(query: PageQuery): RequestPage {\n // The rule — pinned rows survive a filter, the cursor counts in whatever\n // the sort orders by — lives in core, so that this store and the panel's\n // own fallback cannot answer differently.\n return pageFromList(listAll(), query, { pinned: new Set(pinned.keys()) });\n },\n\n get(id) {\n return byId.get(id) ?? pinned.get(id);\n },\n\n clear() {\n buffer.clear();\n byId.clear();\n // `clear` is someone asking for an empty panel; keeping pinned rows\n // around would leave the list stubbornly non-empty.\n pinned.clear();\n },\n\n stats() {\n const items = listAll();\n const oldest = items[items.length - 1];\n return {\n // The ring's own occupancy; pinned survivors are counted separately.\n size: buffer.size,\n capacity: buffer.capacity,\n evicted: buffer.evicted,\n oldestAt: oldest ? oldest.startedAt : null,\n pinned: pinned.size,\n };\n },\n\n pin(id, wanted) {\n if (!wanted) {\n pinned.delete(id);\n return true;\n }\n if (pinned.has(id)) return true;\n if (pinned.size >= PIN_LIMIT) return false;\n const record = byId.get(id);\n if (!record) return false;\n pinned.set(id, record);\n return true;\n },\n\n pinned() {\n return [...pinned.keys()];\n },\n\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n"],"mappings":";AASA,SAAS,kBAAkC;AAC3C;AAAA,EAKE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EAEA;AAAA,OAIK;AAgBA,IAAM,YAAY;AA2DlB,SAAS,gBAAgB,UAAkC,CAAC,GAAgB;AACjF,QAAM,SAAS,IAAI,W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,IAAI,MAAM;AACrB,aAAO;AAAA,IACT;AAAA,IAEA,SAAS;AACP,aAAO,CAAC,GAAG,OAAO,KAAK,CAAC;AAAA,IAC1B;AAAA,IAEA,UAAU,UAAU;AAClB,gBAAU,IAAI,QAAQ;AACtB,aAAO,MAAM;AACX,kBAAU,OAAO,QAAQ;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@reqray/store-memory",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Reqray in-memory store: the ring buffer the panel reads from, and the transport that fills it.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "nodejs",
8
+ "debugging",
9
+ "profiling",
10
+ "n+1",
11
+ "sql",
12
+ "observability",
13
+ "devtools",
14
+ "fastify",
15
+ "express",
16
+ "nestjs"
17
+ ],
18
+ "homepage": "https://github.com/reqray/reqray#readme",
19
+ "bugs": "https://github.com/reqray/reqray/issues",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/reqray/reqray.git",
23
+ "directory": "packages/store-memory"
24
+ },
25
+ "type": "module",
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ }
40
+ },
41
+ "main": "./dist/index.cjs",
42
+ "module": "./dist/index.js",
43
+ "types": "./dist/index.d.ts",
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "dependencies": {
51
+ "@reqray/core": "^0.1.0",
52
+ "@reqray/protocol": "^0.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^26.2.0",
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^6.0.3"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "typecheck": "tsc --noEmit"
62
+ }
6
63
  }