@super-line/plugin-inspector 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 Mert
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/dist/index.cjs ADDED
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ inspector: () => inspector
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_core = require("@super-line/core");
37
+ var encoder = new TextEncoder();
38
+ function encodedByteSize(encoded) {
39
+ return typeof encoded === "string" ? encoder.encode(encoded).length : encoded.byteLength;
40
+ }
41
+ async function buildInspectedContract(contract) {
42
+ let toJsonSchema;
43
+ try {
44
+ const mod = await import("@standard-community/standard-json");
45
+ toJsonSchema = mod.toJsonSchema;
46
+ } catch {
47
+ return (0, import_core.classifyContract)(contract);
48
+ }
49
+ const schemas = /* @__PURE__ */ new Set();
50
+ (0, import_core.classifyContract)(contract, (s) => {
51
+ schemas.add(s);
52
+ return void 0;
53
+ });
54
+ const converted = /* @__PURE__ */ new Map();
55
+ await Promise.all(
56
+ [...schemas].map(
57
+ (s) => toJsonSchema(s).then(
58
+ (j) => {
59
+ converted.set(s, j);
60
+ },
61
+ () => {
62
+ }
63
+ // unsupported vendor / missing per-vendor converter -> structure-only for this entry
64
+ )
65
+ )
66
+ );
67
+ return (0, import_core.classifyContract)(contract, (s) => converted.get(s));
68
+ }
69
+ function inspector(opts = {}) {
70
+ const redact = new Set(opts.redact ?? []);
71
+ function safeSnapshot(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
72
+ if (value === null) return null;
73
+ const t = typeof value;
74
+ if (t === "bigint") return `${value.toString()}n`;
75
+ if (t === "function") return "[Function]";
76
+ if (t === "symbol") return value.toString();
77
+ if (t !== "object") return value;
78
+ const obj = value;
79
+ if (obj instanceof Date) return obj.toISOString();
80
+ if (seen.has(obj)) return "[Circular]";
81
+ if (depth >= 6) return "[MaxDepth]";
82
+ seen.add(obj);
83
+ try {
84
+ if (Array.isArray(obj)) return obj.slice(0, 1e3).map((v) => safeSnapshot(v, depth + 1, seen));
85
+ const ctor = Object.getPrototypeOf(obj)?.constructor?.name;
86
+ const out = {};
87
+ if (ctor && ctor !== "Object") out["#type"] = ctor;
88
+ for (const [k, v] of Object.entries(obj)) {
89
+ out[k] = redact.has(k) ? "[Redacted]" : safeSnapshot(v, depth + 1, seen);
90
+ }
91
+ return out;
92
+ } finally {
93
+ seen.delete(obj);
94
+ }
95
+ }
96
+ function snapshotEvent(event) {
97
+ switch (event.type) {
98
+ case "msg.request":
99
+ case "msg.serverRequest":
100
+ return { ...event, input: safeSnapshot(event.input) };
101
+ case "msg.response":
102
+ case "msg.serverReply":
103
+ return event.ok ? { ...event, output: safeSnapshot(event.output) } : event;
104
+ case "msg.event":
105
+ case "msg.broadcast":
106
+ case "msg.publish":
107
+ case "store.write":
108
+ return { ...event, data: safeSnapshot(event.data) };
109
+ default:
110
+ return event;
111
+ }
112
+ }
113
+ let channel;
114
+ let originNodeId = "";
115
+ let encode = (v) => JSON.stringify(v);
116
+ return {
117
+ name: "inspector",
118
+ setup(ctx) {
119
+ channel = ctx.channel("events");
120
+ originNodeId = ctx.instanceId;
121
+ encode = (v) => ctx.serializer.encode(v);
122
+ },
123
+ onEvent(event) {
124
+ if (!channel) return;
125
+ const snapped = snapshotEvent(event);
126
+ const payload = (0, import_core.eventPayload)(snapped);
127
+ const envelope = {
128
+ event: snapped,
129
+ ts: Date.now(),
130
+ originNodeId,
131
+ byteSize: payload === void 0 ? void 0 : encodedByteSize(encode(payload))
132
+ };
133
+ channel.publish(envelope);
134
+ },
135
+ connection: {
136
+ role: import_core.INSPECTOR_ROLE,
137
+ subprotocol: import_core.INSPECTOR_SUBPROTOCOL,
138
+ contract: import_core.InspectorContract,
139
+ handlers: (ctx) => ({
140
+ getContract: () => buildInspectedContract(ctx.contract),
141
+ getTopology: () => ctx.cluster.topology(),
142
+ listConnections: () => ctx.cluster.connections(),
143
+ getNode: async () => ({ nodeId: ctx.instanceId, nodeName: ctx.nodeName, rooms: ctx.local.rooms, topics: ctx.local.topics }),
144
+ getConn: async (input) => {
145
+ const id = input?.id;
146
+ if (!id) throw new import_core.SuperLineError("BAD_REQUEST", "getConn requires an id");
147
+ const local = ctx.conns.find((cn) => cn.id === id);
148
+ if (local) {
149
+ return {
150
+ descriptor: ctx.describe(local),
151
+ ctx: safeSnapshot(local.ctx),
152
+ data: safeSnapshot(local.data),
153
+ ctxAvailable: true
154
+ };
155
+ }
156
+ const remote = await ctx.connectionById(id);
157
+ if (!remote) throw new import_core.SuperLineError("NOT_FOUND", `Unknown connection: ${id}`);
158
+ return { descriptor: remote, ctxAvailable: false };
159
+ },
160
+ listStores: async () => ctx.storeInfos(),
161
+ listResources: async (input) => {
162
+ const { store: name, ...opts2 } = input;
163
+ if (!ctx.storeInfos().some((s) => s.name === name)) throw new import_core.SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
164
+ return ctx.store(name).list(opts2);
165
+ },
166
+ searchPrincipals: async (input) => {
167
+ const { store: name, ...opts2 } = input;
168
+ if (!ctx.storeInfos().some((s) => s.name === name)) throw new import_core.SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
169
+ return ctx.store(name).searchPrincipals(opts2);
170
+ },
171
+ readResource: async (input) => {
172
+ const { store: name, id } = input;
173
+ if (!ctx.storeInfos().some((s) => s.name === name)) throw new import_core.SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
174
+ const handle = ctx.store(name);
175
+ const resource = await handle.read(id);
176
+ if (!resource) throw new import_core.SuperLineError("NOT_FOUND", `No resource: ${name}/${id}`);
177
+ let data = resource.data;
178
+ try {
179
+ const replica = handle.open(id);
180
+ data = replica.getSnapshot();
181
+ replica.close();
182
+ } catch {
183
+ }
184
+ return { data: safeSnapshot(data), accessRules: resource.accessRules };
185
+ }
186
+ })
187
+ }
188
+ };
189
+ }
190
+ // Annotate the CommonJS export names for ESM import in node:
191
+ 0 && (module.exports = {
192
+ inspector
193
+ });
@@ -0,0 +1,17 @@
1
+ import { SuperLinePlugin } from '@super-line/server';
2
+
3
+ /** Options for {@link inspector}. */
4
+ interface InspectorOptions {
5
+ /** Field names to mask (`[Redacted]`) in snapshotted payloads / ctx / data. */
6
+ redact?: string[];
7
+ }
8
+ /**
9
+ * The Control Center inspector, packaged as a plugin. It taps every request/event/store write, snapshots +
10
+ * field-redacts the payloads, and publishes them (cluster-wide) on its own plugin channel; and it declares a
11
+ * plugin-owned, observer-invisible connection class (the `superline.inspector.v1` subprotocol) that serves
12
+ * Control Center clients the `InspectorContract` — `getContract`, `getTopology`, `getConn`, … and the
13
+ * `events` feed. Register it with `plugins: [inspector()]`. **Dev / trusted-network only.**
14
+ */
15
+ declare function inspector(opts?: InspectorOptions): SuperLinePlugin;
16
+
17
+ export { type InspectorOptions, inspector };
@@ -0,0 +1,17 @@
1
+ import { SuperLinePlugin } from '@super-line/server';
2
+
3
+ /** Options for {@link inspector}. */
4
+ interface InspectorOptions {
5
+ /** Field names to mask (`[Redacted]`) in snapshotted payloads / ctx / data. */
6
+ redact?: string[];
7
+ }
8
+ /**
9
+ * The Control Center inspector, packaged as a plugin. It taps every request/event/store write, snapshots +
10
+ * field-redacts the payloads, and publishes them (cluster-wide) on its own plugin channel; and it declares a
11
+ * plugin-owned, observer-invisible connection class (the `superline.inspector.v1` subprotocol) that serves
12
+ * Control Center clients the `InspectorContract` — `getContract`, `getTopology`, `getConn`, … and the
13
+ * `events` feed. Register it with `plugins: [inspector()]`. **Dev / trusted-network only.**
14
+ */
15
+ declare function inspector(opts?: InspectorOptions): SuperLinePlugin;
16
+
17
+ export { type InspectorOptions, inspector };
package/dist/index.js ADDED
@@ -0,0 +1,165 @@
1
+ // src/index.ts
2
+ import {
3
+ SuperLineError,
4
+ INSPECTOR_ROLE,
5
+ INSPECTOR_SUBPROTOCOL,
6
+ InspectorContract,
7
+ classifyContract,
8
+ eventPayload
9
+ } from "@super-line/core";
10
+ var encoder = new TextEncoder();
11
+ function encodedByteSize(encoded) {
12
+ return typeof encoded === "string" ? encoder.encode(encoded).length : encoded.byteLength;
13
+ }
14
+ async function buildInspectedContract(contract) {
15
+ let toJsonSchema;
16
+ try {
17
+ const mod = await import("@standard-community/standard-json");
18
+ toJsonSchema = mod.toJsonSchema;
19
+ } catch {
20
+ return classifyContract(contract);
21
+ }
22
+ const schemas = /* @__PURE__ */ new Set();
23
+ classifyContract(contract, (s) => {
24
+ schemas.add(s);
25
+ return void 0;
26
+ });
27
+ const converted = /* @__PURE__ */ new Map();
28
+ await Promise.all(
29
+ [...schemas].map(
30
+ (s) => toJsonSchema(s).then(
31
+ (j) => {
32
+ converted.set(s, j);
33
+ },
34
+ () => {
35
+ }
36
+ // unsupported vendor / missing per-vendor converter -> structure-only for this entry
37
+ )
38
+ )
39
+ );
40
+ return classifyContract(contract, (s) => converted.get(s));
41
+ }
42
+ function inspector(opts = {}) {
43
+ const redact = new Set(opts.redact ?? []);
44
+ function safeSnapshot(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
45
+ if (value === null) return null;
46
+ const t = typeof value;
47
+ if (t === "bigint") return `${value.toString()}n`;
48
+ if (t === "function") return "[Function]";
49
+ if (t === "symbol") return value.toString();
50
+ if (t !== "object") return value;
51
+ const obj = value;
52
+ if (obj instanceof Date) return obj.toISOString();
53
+ if (seen.has(obj)) return "[Circular]";
54
+ if (depth >= 6) return "[MaxDepth]";
55
+ seen.add(obj);
56
+ try {
57
+ if (Array.isArray(obj)) return obj.slice(0, 1e3).map((v) => safeSnapshot(v, depth + 1, seen));
58
+ const ctor = Object.getPrototypeOf(obj)?.constructor?.name;
59
+ const out = {};
60
+ if (ctor && ctor !== "Object") out["#type"] = ctor;
61
+ for (const [k, v] of Object.entries(obj)) {
62
+ out[k] = redact.has(k) ? "[Redacted]" : safeSnapshot(v, depth + 1, seen);
63
+ }
64
+ return out;
65
+ } finally {
66
+ seen.delete(obj);
67
+ }
68
+ }
69
+ function snapshotEvent(event) {
70
+ switch (event.type) {
71
+ case "msg.request":
72
+ case "msg.serverRequest":
73
+ return { ...event, input: safeSnapshot(event.input) };
74
+ case "msg.response":
75
+ case "msg.serverReply":
76
+ return event.ok ? { ...event, output: safeSnapshot(event.output) } : event;
77
+ case "msg.event":
78
+ case "msg.broadcast":
79
+ case "msg.publish":
80
+ case "store.write":
81
+ return { ...event, data: safeSnapshot(event.data) };
82
+ default:
83
+ return event;
84
+ }
85
+ }
86
+ let channel;
87
+ let originNodeId = "";
88
+ let encode = (v) => JSON.stringify(v);
89
+ return {
90
+ name: "inspector",
91
+ setup(ctx) {
92
+ channel = ctx.channel("events");
93
+ originNodeId = ctx.instanceId;
94
+ encode = (v) => ctx.serializer.encode(v);
95
+ },
96
+ onEvent(event) {
97
+ if (!channel) return;
98
+ const snapped = snapshotEvent(event);
99
+ const payload = eventPayload(snapped);
100
+ const envelope = {
101
+ event: snapped,
102
+ ts: Date.now(),
103
+ originNodeId,
104
+ byteSize: payload === void 0 ? void 0 : encodedByteSize(encode(payload))
105
+ };
106
+ channel.publish(envelope);
107
+ },
108
+ connection: {
109
+ role: INSPECTOR_ROLE,
110
+ subprotocol: INSPECTOR_SUBPROTOCOL,
111
+ contract: InspectorContract,
112
+ handlers: (ctx) => ({
113
+ getContract: () => buildInspectedContract(ctx.contract),
114
+ getTopology: () => ctx.cluster.topology(),
115
+ listConnections: () => ctx.cluster.connections(),
116
+ getNode: async () => ({ nodeId: ctx.instanceId, nodeName: ctx.nodeName, rooms: ctx.local.rooms, topics: ctx.local.topics }),
117
+ getConn: async (input) => {
118
+ const id = input?.id;
119
+ if (!id) throw new SuperLineError("BAD_REQUEST", "getConn requires an id");
120
+ const local = ctx.conns.find((cn) => cn.id === id);
121
+ if (local) {
122
+ return {
123
+ descriptor: ctx.describe(local),
124
+ ctx: safeSnapshot(local.ctx),
125
+ data: safeSnapshot(local.data),
126
+ ctxAvailable: true
127
+ };
128
+ }
129
+ const remote = await ctx.connectionById(id);
130
+ if (!remote) throw new SuperLineError("NOT_FOUND", `Unknown connection: ${id}`);
131
+ return { descriptor: remote, ctxAvailable: false };
132
+ },
133
+ listStores: async () => ctx.storeInfos(),
134
+ listResources: async (input) => {
135
+ const { store: name, ...opts2 } = input;
136
+ if (!ctx.storeInfos().some((s) => s.name === name)) throw new SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
137
+ return ctx.store(name).list(opts2);
138
+ },
139
+ searchPrincipals: async (input) => {
140
+ const { store: name, ...opts2 } = input;
141
+ if (!ctx.storeInfos().some((s) => s.name === name)) throw new SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
142
+ return ctx.store(name).searchPrincipals(opts2);
143
+ },
144
+ readResource: async (input) => {
145
+ const { store: name, id } = input;
146
+ if (!ctx.storeInfos().some((s) => s.name === name)) throw new SuperLineError("NOT_FOUND", `Unknown store: ${name}`);
147
+ const handle = ctx.store(name);
148
+ const resource = await handle.read(id);
149
+ if (!resource) throw new SuperLineError("NOT_FOUND", `No resource: ${name}/${id}`);
150
+ let data = resource.data;
151
+ try {
152
+ const replica = handle.open(id);
153
+ data = replica.getSnapshot();
154
+ replica.close();
155
+ } catch {
156
+ }
157
+ return { data: safeSnapshot(data), accessRules: resource.accessRules };
158
+ }
159
+ })
160
+ }
161
+ };
162
+ }
163
+ export {
164
+ inspector
165
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@super-line/plugin-inspector",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Control Center inspector for super-line, packaged as a plugin — taps + a plugin-owned CC connection.",
6
+ "license": "MIT",
7
+ "author": "Mert",
8
+ "keywords": [
9
+ "super-line",
10
+ "plugin",
11
+ "inspector",
12
+ "control-center",
13
+ "observability"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/mertdogar/super-line.git",
18
+ "directory": "packages/plugin-inspector"
19
+ },
20
+ "homepage": "https://mertdogar.github.io/super-line/",
21
+ "bugs": "https://github.com/mertdogar/super-line/issues",
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/index.d.cts",
33
+ "default": "./dist/index.cjs"
34
+ }
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "sideEffects": false,
41
+ "engines": {
42
+ "node": ">=18"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "@standard-community/standard-json": "^0.3.5",
49
+ "@super-line/core": "^0.10.0"
50
+ },
51
+ "peerDependencies": {
52
+ "@super-line/server": "^0.10.0"
53
+ },
54
+ "devDependencies": {
55
+ "@super-line/server": "^0.10.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup"
59
+ }
60
+ }