@kb-labs/studio-devtools 0.2.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/index.d.ts +102 -0
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface DevToolsChannel<T = unknown> {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly icon?: string;
|
|
7
|
+
getEvents(): readonly T[];
|
|
8
|
+
push(event: T): void;
|
|
9
|
+
clear(): void;
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
}
|
|
12
|
+
interface DevToolsLogRow {
|
|
13
|
+
/** Channel this row belongs to */
|
|
14
|
+
channelId: string;
|
|
15
|
+
/** Timestamp for chronological sorting */
|
|
16
|
+
timestamp: number;
|
|
17
|
+
/** Unique row id */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Searchable text — all fields concatenated */
|
|
20
|
+
searchText: string;
|
|
21
|
+
/** The original event */
|
|
22
|
+
event: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface DevToolsPlugin<T = unknown> {
|
|
25
|
+
channel: DevToolsChannel<T>;
|
|
26
|
+
/** Render a single log row for this channel's event */
|
|
27
|
+
renderRow(event: T): DevToolsRowContent;
|
|
28
|
+
}
|
|
29
|
+
interface DevToolsRowContent {
|
|
30
|
+
/** Status indicator: 'success' | 'warning' | 'error' | 'pending' */
|
|
31
|
+
status: 'success' | 'warning' | 'error' | 'pending';
|
|
32
|
+
/** Main summary text shown in the row */
|
|
33
|
+
summary: string;
|
|
34
|
+
/** Optional right-side label (e.g. "234ms") */
|
|
35
|
+
meta?: string;
|
|
36
|
+
/** Optional detail node shown when row is expanded */
|
|
37
|
+
detail?: ComponentType;
|
|
38
|
+
}
|
|
39
|
+
type MFEventStatus = 'loading' | 'success' | 'error' | 'warning';
|
|
40
|
+
interface MFEvent {
|
|
41
|
+
id: string;
|
|
42
|
+
remoteName: string;
|
|
43
|
+
exposedModule: string;
|
|
44
|
+
status: MFEventStatus;
|
|
45
|
+
startedAt: number;
|
|
46
|
+
durationMs?: number;
|
|
47
|
+
attempt: number;
|
|
48
|
+
error?: {
|
|
49
|
+
message: string;
|
|
50
|
+
cause?: string;
|
|
51
|
+
};
|
|
52
|
+
isDefaultUndefined?: boolean;
|
|
53
|
+
}
|
|
54
|
+
interface EventBusEvent {
|
|
55
|
+
id: string;
|
|
56
|
+
event: string;
|
|
57
|
+
payload: unknown;
|
|
58
|
+
sourcePluginId: string;
|
|
59
|
+
sourcePageId: string;
|
|
60
|
+
timestamp: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Generic ring-buffer channel. Push events in, read them back.
|
|
65
|
+
* Notifies all subscribers on every push/clear.
|
|
66
|
+
*/
|
|
67
|
+
declare class GenericChannel<T = unknown> implements DevToolsChannel<T> {
|
|
68
|
+
readonly id: string;
|
|
69
|
+
readonly label: string;
|
|
70
|
+
readonly icon?: string;
|
|
71
|
+
private events;
|
|
72
|
+
private readonly maxSize;
|
|
73
|
+
private listeners;
|
|
74
|
+
constructor(id: string, label: string, icon?: string, maxSize?: number);
|
|
75
|
+
getEvents(): readonly T[];
|
|
76
|
+
push(event: T): void;
|
|
77
|
+
clear(): void;
|
|
78
|
+
subscribe(listener: () => void): () => void;
|
|
79
|
+
private notify;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Registry of all DevTools channels.
|
|
84
|
+
* Module-level singleton — instruments code outside the React tree.
|
|
85
|
+
*/
|
|
86
|
+
declare class DevToolsStore {
|
|
87
|
+
private channels;
|
|
88
|
+
private listeners;
|
|
89
|
+
private channelUnsubs;
|
|
90
|
+
registerChannel<T>(channel: DevToolsChannel<T>): void;
|
|
91
|
+
unregisterChannel(id: string): void;
|
|
92
|
+
registerPlugin<T>(plugin: DevToolsPlugin<T>): void;
|
|
93
|
+
getChannel<T = unknown>(id: string): DevToolsChannel<T> | undefined;
|
|
94
|
+
getChannels(): readonly DevToolsChannel[];
|
|
95
|
+
clear(): void;
|
|
96
|
+
subscribe(listener: () => void): () => void;
|
|
97
|
+
private notify;
|
|
98
|
+
}
|
|
99
|
+
/** Global singleton — import this everywhere you want to push events */
|
|
100
|
+
declare const devToolsStore: DevToolsStore;
|
|
101
|
+
|
|
102
|
+
export { type DevToolsChannel, type DevToolsLogRow, type DevToolsPlugin, type DevToolsRowContent, DevToolsStore, type EventBusEvent, GenericChannel, type MFEvent, type MFEventStatus, devToolsStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/channel.ts
|
|
2
|
+
var GenericChannel = class {
|
|
3
|
+
id;
|
|
4
|
+
label;
|
|
5
|
+
icon;
|
|
6
|
+
events = [];
|
|
7
|
+
maxSize;
|
|
8
|
+
listeners = /* @__PURE__ */ new Set();
|
|
9
|
+
constructor(id, label, icon, maxSize = 200) {
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.label = label;
|
|
12
|
+
this.icon = icon;
|
|
13
|
+
this.maxSize = maxSize;
|
|
14
|
+
}
|
|
15
|
+
getEvents() {
|
|
16
|
+
return this.events;
|
|
17
|
+
}
|
|
18
|
+
push(event) {
|
|
19
|
+
this.events.push(event);
|
|
20
|
+
if (this.events.length > this.maxSize) {
|
|
21
|
+
this.events.shift();
|
|
22
|
+
}
|
|
23
|
+
this.notify();
|
|
24
|
+
}
|
|
25
|
+
clear() {
|
|
26
|
+
this.events = [];
|
|
27
|
+
this.notify();
|
|
28
|
+
}
|
|
29
|
+
subscribe(listener) {
|
|
30
|
+
this.listeners.add(listener);
|
|
31
|
+
return () => {
|
|
32
|
+
this.listeners.delete(listener);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
notify() {
|
|
36
|
+
this.listeners.forEach((l) => {
|
|
37
|
+
l();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/store.ts
|
|
43
|
+
var DevToolsStore = class {
|
|
44
|
+
channels = /* @__PURE__ */ new Map();
|
|
45
|
+
listeners = /* @__PURE__ */ new Set();
|
|
46
|
+
channelUnsubs = /* @__PURE__ */ new Map();
|
|
47
|
+
registerChannel(channel) {
|
|
48
|
+
if (this.channels.has(channel.id)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.channels.set(channel.id, channel);
|
|
52
|
+
const unsub = channel.subscribe(() => {
|
|
53
|
+
this.notify();
|
|
54
|
+
});
|
|
55
|
+
this.channelUnsubs.set(channel.id, unsub);
|
|
56
|
+
this.notify();
|
|
57
|
+
}
|
|
58
|
+
unregisterChannel(id) {
|
|
59
|
+
this.channelUnsubs.get(id)?.();
|
|
60
|
+
this.channelUnsubs.delete(id);
|
|
61
|
+
this.channels.delete(id);
|
|
62
|
+
this.notify();
|
|
63
|
+
}
|
|
64
|
+
registerPlugin(plugin) {
|
|
65
|
+
this.registerChannel(plugin.channel);
|
|
66
|
+
}
|
|
67
|
+
getChannel(id) {
|
|
68
|
+
return this.channels.get(id);
|
|
69
|
+
}
|
|
70
|
+
getChannels() {
|
|
71
|
+
return [...this.channels.values()];
|
|
72
|
+
}
|
|
73
|
+
clear() {
|
|
74
|
+
this.channels.forEach((ch) => {
|
|
75
|
+
ch.clear();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
subscribe(listener) {
|
|
79
|
+
this.listeners.add(listener);
|
|
80
|
+
return () => {
|
|
81
|
+
this.listeners.delete(listener);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
notify() {
|
|
85
|
+
this.listeners.forEach((l) => {
|
|
86
|
+
l();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var devToolsStore = new DevToolsStore();
|
|
91
|
+
|
|
92
|
+
export { DevToolsStore, GenericChannel, devToolsStore };
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/channel.ts","../src/store.ts"],"names":[],"mappings":";AAMO,IAAM,iBAAN,MAAgE;AAAA,EAC5D,EAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EAED,SAAc,EAAC;AAAA,EACN,OAAA;AAAA,EACT,SAAA,uBAAgB,GAAA,EAAgB;AAAA,EAExC,WAAA,CAAY,EAAA,EAAY,KAAA,EAAe,IAAA,EAAe,UAAU,GAAA,EAAK;AACnE,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AACV,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AAAA,EAEA,SAAA,GAA0B;AACxB,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEA,KAAK,KAAA,EAAgB;AACnB,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,KAAK,CAAA;AACtB,IAAA,IAAI,IAAA,CAAK,MAAA,CAAO,MAAA,GAAS,IAAA,CAAK,OAAA,EAAS;AACrC,MAAA,IAAA,CAAK,OAAO,KAAA,EAAM;AAAA,IACpB;AACA,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd;AAAA,EAEA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,SAAS,EAAC;AACf,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd;AAAA,EAEA,UAAU,QAAA,EAAkC;AAC1C,IAAA,IAAA,CAAK,SAAA,CAAU,IAAI,QAAQ,CAAA;AAC3B,IAAA,OAAO,MAAM;AAAE,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,IAAG,CAAA;AAAA,EAClD;AAAA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I,EAAE,CAAA;AAAA,EAC7B;AAAA,EAEA,WAAA,GAA0C;AACxC,IAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA;AAAA,EACnC;AAAA,EAEA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,QAAA,CAAS,OAAA,CAAQ,CAAC,EAAA,KAAO;AAAE,MAAA,EAAA,CAAG,KAAA,EAAM;AAAA,IAAG,CAAC,CAAA;AAAA,EAC/C;AAAA,EAEA,UAAU,QAAA,EAAkC;AAC1C,IAAA,IAAA,CAAK,SAAA,CAAU,IAAI,QAAQ,CAAA;AAC3B,IAAA,OAAO,MAAM;AAAE,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,IAAG,CAAA;AAAA,EAClD;AAAA,EAEQ,MAAA,GAAe;AACrB,IAAA,IAAA,CAAK,SAAA,CAAU,OAAA,CAAQ,CAAC,CAAA,KAAM;AAAE,MAAA,CAAA,EAAE;AAAA,IAAG,CAAC,CAAA;AAAA,EACxC;AACF;AAGO,IAAM,aAAA,GAAgB,IAAI,aAAA","file":"index.js","sourcesContent":["import type { DevToolsChannel } from './types.js';\n\n/**\n * Generic ring-buffer channel. Push events in, read them back.\n * Notifies all subscribers on every push/clear.\n */\nexport class GenericChannel<T = unknown> implements DevToolsChannel<T> {\n readonly id: string;\n readonly label: string;\n readonly icon?: string;\n\n private events: T[] = [];\n private readonly maxSize: number;\n private listeners = new Set<() => void>();\n\n constructor(id: string, label: string, icon?: string, maxSize = 200) {\n this.id = id;\n this.label = label;\n this.icon = icon;\n this.maxSize = maxSize;\n }\n\n getEvents(): readonly T[] {\n return this.events;\n }\n\n push(event: T): void {\n this.events.push(event);\n if (this.events.length > this.maxSize) {\n this.events.shift();\n }\n this.notify();\n }\n\n clear(): void {\n this.events = [];\n this.notify();\n }\n\n subscribe(listener: () => void): () => void {\n this.listeners.add(listener);\n return () => { this.listeners.delete(listener); };\n }\n\n private notify(): void {\n this.listeners.forEach((l) => { l(); });\n }\n}\n","import type { DevToolsChannel, DevToolsPlugin } from './types.js';\n\n/**\n * Registry of all DevTools channels.\n * Module-level singleton — instruments code outside the React tree.\n */\nexport class DevToolsStore {\n private channels = new Map<string, DevToolsChannel>();\n private listeners = new Set<() => void>();\n private channelUnsubs = new Map<string, () => void>();\n\n registerChannel<T>(channel: DevToolsChannel<T>): void {\n if (this.channels.has(channel.id)) { return; }\n this.channels.set(channel.id, channel as DevToolsChannel);\n // Propagate channel notifications to global listeners\n const unsub = channel.subscribe(() => { this.notify(); });\n this.channelUnsubs.set(channel.id, unsub);\n this.notify();\n }\n\n unregisterChannel(id: string): void {\n this.channelUnsubs.get(id)?.();\n this.channelUnsubs.delete(id);\n this.channels.delete(id);\n this.notify();\n }\n\n registerPlugin<T>(plugin: DevToolsPlugin<T>): void {\n this.registerChannel(plugin.channel);\n }\n\n getChannel<T = unknown>(id: string): DevToolsChannel<T> | undefined {\n return this.channels.get(id) as DevToolsChannel<T> | undefined;\n }\n\n getChannels(): readonly DevToolsChannel[] {\n return [...this.channels.values()];\n }\n\n clear(): void {\n this.channels.forEach((ch) => { ch.clear(); });\n }\n\n subscribe(listener: () => void): () => void {\n this.listeners.add(listener);\n return () => { this.listeners.delete(listener); };\n }\n\n private notify(): void {\n this.listeners.forEach((l) => { l(); });\n }\n}\n\n/** Global singleton — import this everywhere you want to push events */\nexport const devToolsStore = new DevToolsStore();\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kb-labs/studio-devtools",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Studio DevTools — extensible event channel store for developer debugging",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup --watch",
|
|
22
|
+
"type-check": "tsc --noEmit",
|
|
23
|
+
"lint": "eslint . --max-warnings=0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^18.3.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@kb-labs/devkit": "link:../../../../infra/kb-labs-devkit",
|
|
30
|
+
"@types/react": "^18.3.18",
|
|
31
|
+
"rimraf": "^6.0.1",
|
|
32
|
+
"tsup": "^8.5.0",
|
|
33
|
+
"typescript": "^5.6.3"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20.0.0",
|
|
37
|
+
"pnpm": ">=9.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|