@ricsam/isolate-console 0.1.1 → 0.1.2
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/README.md +69 -0
- package/dist/cjs/index.cjs +173 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/mjs/index.mjs +129 -0
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/isolate.d.ts +131 -0
- package/package.json +41 -12
- package/CHANGELOG.md +0 -9
- package/src/index.ts +0 -215
- package/src/setup.test.ts +0 -509
- package/tsconfig.json +0 -8
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @ricsam/isolate-console
|
|
2
|
+
|
|
3
|
+
Console API with logging, timing, counting, and grouping.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { setupConsole } from "@ricsam/isolate-console";
|
|
7
|
+
|
|
8
|
+
const handle = await setupConsole(context, {
|
|
9
|
+
onLog: (level, ...args) => {
|
|
10
|
+
console.log(`[${level}]`, ...args);
|
|
11
|
+
},
|
|
12
|
+
onTime: (label, duration) => {
|
|
13
|
+
console.log(`${label}: ${duration}ms`);
|
|
14
|
+
},
|
|
15
|
+
onCount: (label, count) => {
|
|
16
|
+
console.log(`${label}: ${count}`);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Injected Globals:**
|
|
22
|
+
- `console.log`, `console.warn`, `console.error`, `console.debug`, `console.info`
|
|
23
|
+
- `console.trace`, `console.dir`, `console.table`
|
|
24
|
+
- `console.time`, `console.timeEnd`, `console.timeLog`
|
|
25
|
+
- `console.count`, `console.countReset`
|
|
26
|
+
- `console.group`, `console.groupCollapsed`, `console.groupEnd`
|
|
27
|
+
- `console.assert`, `console.clear`
|
|
28
|
+
|
|
29
|
+
**Usage in Isolate:**
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
// Basic logging
|
|
33
|
+
console.log("Hello", { name: "World" });
|
|
34
|
+
console.warn("Warning message");
|
|
35
|
+
console.error("Error occurred");
|
|
36
|
+
|
|
37
|
+
// Timing
|
|
38
|
+
console.time("operation");
|
|
39
|
+
// ... do work ...
|
|
40
|
+
console.timeLog("operation", "checkpoint");
|
|
41
|
+
// ... more work ...
|
|
42
|
+
console.timeEnd("operation"); // Logs: "operation: 123ms"
|
|
43
|
+
|
|
44
|
+
// Counting
|
|
45
|
+
console.count("clicks"); // clicks: 1
|
|
46
|
+
console.count("clicks"); // clicks: 2
|
|
47
|
+
console.countReset("clicks");
|
|
48
|
+
console.count("clicks"); // clicks: 1
|
|
49
|
+
|
|
50
|
+
// Grouping
|
|
51
|
+
console.group("User Info");
|
|
52
|
+
console.log("Name: John");
|
|
53
|
+
console.log("Age: 30");
|
|
54
|
+
console.groupEnd();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Event Handlers:**
|
|
58
|
+
|
|
59
|
+
| Handler | Description |
|
|
60
|
+
|---------|-------------|
|
|
61
|
+
| `onLog` | Called for log, warn, error, debug, info, trace, dir, table |
|
|
62
|
+
| `onTime` | Called when `console.timeEnd` completes a timer |
|
|
63
|
+
| `onTimeLog` | Called when `console.timeLog` logs without ending |
|
|
64
|
+
| `onCount` | Called when `console.count` increments |
|
|
65
|
+
| `onCountReset` | Called when `console.countReset` resets a counter |
|
|
66
|
+
| `onGroup` | Called when `console.group` or `groupCollapsed` is invoked |
|
|
67
|
+
| `onGroupEnd` | Called when `console.groupEnd` is invoked |
|
|
68
|
+
| `onAssert` | Called when `console.assert` fails |
|
|
69
|
+
| `onClear` | Called when `console.clear` is invoked |
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
20
|
+
var __toCommonJS = (from) => {
|
|
21
|
+
var entry = __moduleCache.get(from), desc;
|
|
22
|
+
if (entry)
|
|
23
|
+
return entry;
|
|
24
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
26
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
27
|
+
get: () => from[key],
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
}));
|
|
30
|
+
__moduleCache.set(from, entry);
|
|
31
|
+
return entry;
|
|
32
|
+
};
|
|
33
|
+
var __export = (target, all) => {
|
|
34
|
+
for (var name in all)
|
|
35
|
+
__defProp(target, name, {
|
|
36
|
+
get: all[name],
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
set: (newValue) => all[name] = () => newValue
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// packages/console/src/index.ts
|
|
44
|
+
var exports_src = {};
|
|
45
|
+
__export(exports_src, {
|
|
46
|
+
setupConsole: () => setupConsole
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(exports_src);
|
|
49
|
+
var import_isolated_vm = __toESM(require("isolated-vm"));
|
|
50
|
+
async function setupConsole(context, options) {
|
|
51
|
+
const opts = options ?? {};
|
|
52
|
+
const timers = new Map;
|
|
53
|
+
const counters = new Map;
|
|
54
|
+
let groupDepth = 0;
|
|
55
|
+
const global = context.global;
|
|
56
|
+
const logLevels = [
|
|
57
|
+
"log",
|
|
58
|
+
"warn",
|
|
59
|
+
"error",
|
|
60
|
+
"debug",
|
|
61
|
+
"info",
|
|
62
|
+
"trace",
|
|
63
|
+
"dir",
|
|
64
|
+
"table"
|
|
65
|
+
];
|
|
66
|
+
for (const level of logLevels) {
|
|
67
|
+
global.setSync(`__console_${level}`, new import_isolated_vm.default.Callback((...args) => {
|
|
68
|
+
opts.onLog?.(level, ...args);
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
global.setSync("__console_time", new import_isolated_vm.default.Callback((label) => {
|
|
72
|
+
const l = label ?? "default";
|
|
73
|
+
timers.set(l, performance.now());
|
|
74
|
+
}));
|
|
75
|
+
global.setSync("__console_timeEnd", new import_isolated_vm.default.Callback((label) => {
|
|
76
|
+
const l = label ?? "default";
|
|
77
|
+
const start = timers.get(l);
|
|
78
|
+
if (start !== undefined) {
|
|
79
|
+
const duration = performance.now() - start;
|
|
80
|
+
timers.delete(l);
|
|
81
|
+
opts.onTime?.(l, duration);
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
global.setSync("__console_timeLog", new import_isolated_vm.default.Callback((label, ...args) => {
|
|
85
|
+
const l = label ?? "default";
|
|
86
|
+
const start = timers.get(l);
|
|
87
|
+
if (start !== undefined) {
|
|
88
|
+
const duration = performance.now() - start;
|
|
89
|
+
opts.onTimeLog?.(l, duration, ...args);
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
global.setSync("__console_count", new import_isolated_vm.default.Callback((label) => {
|
|
93
|
+
const l = label ?? "default";
|
|
94
|
+
const count = (counters.get(l) ?? 0) + 1;
|
|
95
|
+
counters.set(l, count);
|
|
96
|
+
opts.onCount?.(l, count);
|
|
97
|
+
}));
|
|
98
|
+
global.setSync("__console_countReset", new import_isolated_vm.default.Callback((label) => {
|
|
99
|
+
const l = label ?? "default";
|
|
100
|
+
counters.delete(l);
|
|
101
|
+
opts.onCountReset?.(l);
|
|
102
|
+
}));
|
|
103
|
+
global.setSync("__console_group", new import_isolated_vm.default.Callback((label) => {
|
|
104
|
+
const l = label ?? "default";
|
|
105
|
+
groupDepth++;
|
|
106
|
+
opts.onGroup?.(l, false);
|
|
107
|
+
}));
|
|
108
|
+
global.setSync("__console_groupCollapsed", new import_isolated_vm.default.Callback((label) => {
|
|
109
|
+
const l = label ?? "default";
|
|
110
|
+
groupDepth++;
|
|
111
|
+
opts.onGroup?.(l, true);
|
|
112
|
+
}));
|
|
113
|
+
global.setSync("__console_groupEnd", new import_isolated_vm.default.Callback(() => {
|
|
114
|
+
if (groupDepth > 0) {
|
|
115
|
+
groupDepth--;
|
|
116
|
+
}
|
|
117
|
+
opts.onGroupEnd?.();
|
|
118
|
+
}));
|
|
119
|
+
global.setSync("__console_clear", new import_isolated_vm.default.Callback(() => {
|
|
120
|
+
opts.onClear?.();
|
|
121
|
+
}));
|
|
122
|
+
global.setSync("__console_assert", new import_isolated_vm.default.Callback((condition, ...args) => {
|
|
123
|
+
if (!condition) {
|
|
124
|
+
opts.onAssert?.(condition, ...args);
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
context.evalSync(`
|
|
128
|
+
globalThis.console = {
|
|
129
|
+
log: __console_log,
|
|
130
|
+
warn: __console_warn,
|
|
131
|
+
error: __console_error,
|
|
132
|
+
debug: __console_debug,
|
|
133
|
+
info: __console_info,
|
|
134
|
+
trace: __console_trace,
|
|
135
|
+
dir: __console_dir,
|
|
136
|
+
table: __console_table,
|
|
137
|
+
time: __console_time,
|
|
138
|
+
timeEnd: __console_timeEnd,
|
|
139
|
+
timeLog: __console_timeLog,
|
|
140
|
+
count: __console_count,
|
|
141
|
+
countReset: __console_countReset,
|
|
142
|
+
group: __console_group,
|
|
143
|
+
groupCollapsed: __console_groupCollapsed,
|
|
144
|
+
groupEnd: __console_groupEnd,
|
|
145
|
+
clear: __console_clear,
|
|
146
|
+
assert: __console_assert,
|
|
147
|
+
};
|
|
148
|
+
`);
|
|
149
|
+
return {
|
|
150
|
+
dispose() {
|
|
151
|
+
timers.clear();
|
|
152
|
+
counters.clear();
|
|
153
|
+
groupDepth = 0;
|
|
154
|
+
},
|
|
155
|
+
reset() {
|
|
156
|
+
timers.clear();
|
|
157
|
+
counters.clear();
|
|
158
|
+
groupDepth = 0;
|
|
159
|
+
},
|
|
160
|
+
getTimers() {
|
|
161
|
+
return new Map(timers);
|
|
162
|
+
},
|
|
163
|
+
getCounters() {
|
|
164
|
+
return new Map(counters);
|
|
165
|
+
},
|
|
166
|
+
getGroupDepth() {
|
|
167
|
+
return groupDepth;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
//# debugId=4D8B064A0F23B8BC64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import ivm from \"isolated-vm\";\n\nexport interface ConsoleOptions {\n onLog?: (level: string, ...args: unknown[]) => void;\n onTime?: (label: string, duration: number) => void;\n onTimeLog?: (label: string, duration: number, ...args: unknown[]) => void;\n onCount?: (label: string, count: number) => void;\n onCountReset?: (label: string) => void;\n onGroup?: (label: string, collapsed: boolean) => void;\n onGroupEnd?: () => void;\n onClear?: () => void;\n onAssert?: (condition: boolean, ...args: unknown[]) => void;\n}\n\nexport interface ConsoleHandle {\n dispose(): void;\n reset(): void;\n getTimers(): Map<string, number>;\n getCounters(): Map<string, number>;\n getGroupDepth(): number;\n}\n\n/**\n * Setup console API in an isolated-vm context\n *\n * Injects console.log, console.warn, console.error, console.info, console.debug,\n * console.trace, console.dir, console.table, console.time, console.timeEnd,\n * console.timeLog, console.count, console.countReset, console.group,\n * console.groupCollapsed, console.groupEnd, console.clear, console.assert\n *\n * @example\n * const handle = await setupConsole(context, {\n * onLog: (level, ...args) => console.log(`[${level}]`, ...args)\n * });\n */\nexport async function setupConsole(\n context: ivm.Context,\n options?: ConsoleOptions\n): Promise<ConsoleHandle> {\n const opts = options ?? {};\n\n // State management\n const timers = new Map<string, number>();\n const counters = new Map<string, number>();\n let groupDepth = 0;\n\n const global = context.global;\n\n // Log-level methods\n const logLevels = [\n \"log\",\n \"warn\",\n \"error\",\n \"debug\",\n \"info\",\n \"trace\",\n \"dir\",\n \"table\",\n ];\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((...args: unknown[]) => {\n opts.onLog?.(level, ...args);\n })\n );\n }\n\n // Timing methods\n global.setSync(\n \"__console_time\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n timers.set(l, performance.now());\n })\n );\n\n global.setSync(\n \"__console_timeEnd\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n timers.delete(l);\n opts.onTime?.(l, duration);\n }\n })\n );\n\n global.setSync(\n \"__console_timeLog\",\n new ivm.Callback((label?: string, ...args: unknown[]) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n opts.onTimeLog?.(l, duration, ...args);\n }\n })\n );\n\n // Counting methods\n global.setSync(\n \"__console_count\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const count = (counters.get(l) ?? 0) + 1;\n counters.set(l, count);\n opts.onCount?.(l, count);\n })\n );\n\n global.setSync(\n \"__console_countReset\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n counters.delete(l);\n opts.onCountReset?.(l);\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n groupDepth++;\n opts.onGroup?.(l, false);\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n groupDepth++;\n opts.onGroup?.(l, true);\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onGroupEnd?.();\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onClear?.();\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((condition: boolean, ...args: unknown[]) => {\n if (!condition) {\n opts.onAssert?.(condition, ...args);\n }\n })\n );\n\n // Inject console object\n context.evalSync(`\n globalThis.console = {\n log: __console_log,\n warn: __console_warn,\n error: __console_error,\n debug: __console_debug,\n info: __console_info,\n trace: __console_trace,\n dir: __console_dir,\n table: __console_table,\n time: __console_time,\n timeEnd: __console_timeEnd,\n timeLog: __console_timeLog,\n count: __console_count,\n countReset: __console_countReset,\n group: __console_group,\n groupCollapsed: __console_groupCollapsed,\n groupEnd: __console_groupEnd,\n clear: __console_clear,\n assert: __console_assert,\n };\n `);\n\n return {\n dispose() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n reset() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n getTimers() {\n return new Map(timers);\n },\n getCounters() {\n return new Map(counters);\n },\n getGroupDepth() {\n return groupDepth;\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAgB,IAAhB;AAmCA,eAAsB,YAAY,CAChC,SACA,SACwB;AAAA,EACxB,MAAM,OAAO,WAAW,CAAC;AAAA,EAGzB,MAAM,SAAS,IAAI;AAAA,EACnB,MAAM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A,MACb,SAAS,MAAM;AAAA,MACf,aAAa;AAAA;AAAA,IAEf,KAAK,GAAG;AAAA,MACN,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,MACf,aAAa;AAAA;AAAA,IAEf,SAAS,GAAG;AAAA,MACV,OAAO,IAAI,IAAI,MAAM;AAAA;AAAA,IAEvB,WAAW,GAAG;AAAA,MACZ,OAAO,IAAI,IAAI,QAAQ;AAAA;AAAA,IAEzB,aAAa,GAAG;AAAA,MACd,OAAO;AAAA;AAAA,EAEX;AAAA;",
|
|
8
|
+
"debugId": "4D8B064A0F23B8BC64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/console/src/index.ts
|
|
3
|
+
import ivm from "isolated-vm";
|
|
4
|
+
async function setupConsole(context, options) {
|
|
5
|
+
const opts = options ?? {};
|
|
6
|
+
const timers = new Map;
|
|
7
|
+
const counters = new Map;
|
|
8
|
+
let groupDepth = 0;
|
|
9
|
+
const global = context.global;
|
|
10
|
+
const logLevels = [
|
|
11
|
+
"log",
|
|
12
|
+
"warn",
|
|
13
|
+
"error",
|
|
14
|
+
"debug",
|
|
15
|
+
"info",
|
|
16
|
+
"trace",
|
|
17
|
+
"dir",
|
|
18
|
+
"table"
|
|
19
|
+
];
|
|
20
|
+
for (const level of logLevels) {
|
|
21
|
+
global.setSync(`__console_${level}`, new ivm.Callback((...args) => {
|
|
22
|
+
opts.onLog?.(level, ...args);
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
global.setSync("__console_time", new ivm.Callback((label) => {
|
|
26
|
+
const l = label ?? "default";
|
|
27
|
+
timers.set(l, performance.now());
|
|
28
|
+
}));
|
|
29
|
+
global.setSync("__console_timeEnd", new ivm.Callback((label) => {
|
|
30
|
+
const l = label ?? "default";
|
|
31
|
+
const start = timers.get(l);
|
|
32
|
+
if (start !== undefined) {
|
|
33
|
+
const duration = performance.now() - start;
|
|
34
|
+
timers.delete(l);
|
|
35
|
+
opts.onTime?.(l, duration);
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
global.setSync("__console_timeLog", new ivm.Callback((label, ...args) => {
|
|
39
|
+
const l = label ?? "default";
|
|
40
|
+
const start = timers.get(l);
|
|
41
|
+
if (start !== undefined) {
|
|
42
|
+
const duration = performance.now() - start;
|
|
43
|
+
opts.onTimeLog?.(l, duration, ...args);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
global.setSync("__console_count", new ivm.Callback((label) => {
|
|
47
|
+
const l = label ?? "default";
|
|
48
|
+
const count = (counters.get(l) ?? 0) + 1;
|
|
49
|
+
counters.set(l, count);
|
|
50
|
+
opts.onCount?.(l, count);
|
|
51
|
+
}));
|
|
52
|
+
global.setSync("__console_countReset", new ivm.Callback((label) => {
|
|
53
|
+
const l = label ?? "default";
|
|
54
|
+
counters.delete(l);
|
|
55
|
+
opts.onCountReset?.(l);
|
|
56
|
+
}));
|
|
57
|
+
global.setSync("__console_group", new ivm.Callback((label) => {
|
|
58
|
+
const l = label ?? "default";
|
|
59
|
+
groupDepth++;
|
|
60
|
+
opts.onGroup?.(l, false);
|
|
61
|
+
}));
|
|
62
|
+
global.setSync("__console_groupCollapsed", new ivm.Callback((label) => {
|
|
63
|
+
const l = label ?? "default";
|
|
64
|
+
groupDepth++;
|
|
65
|
+
opts.onGroup?.(l, true);
|
|
66
|
+
}));
|
|
67
|
+
global.setSync("__console_groupEnd", new ivm.Callback(() => {
|
|
68
|
+
if (groupDepth > 0) {
|
|
69
|
+
groupDepth--;
|
|
70
|
+
}
|
|
71
|
+
opts.onGroupEnd?.();
|
|
72
|
+
}));
|
|
73
|
+
global.setSync("__console_clear", new ivm.Callback(() => {
|
|
74
|
+
opts.onClear?.();
|
|
75
|
+
}));
|
|
76
|
+
global.setSync("__console_assert", new ivm.Callback((condition, ...args) => {
|
|
77
|
+
if (!condition) {
|
|
78
|
+
opts.onAssert?.(condition, ...args);
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
context.evalSync(`
|
|
82
|
+
globalThis.console = {
|
|
83
|
+
log: __console_log,
|
|
84
|
+
warn: __console_warn,
|
|
85
|
+
error: __console_error,
|
|
86
|
+
debug: __console_debug,
|
|
87
|
+
info: __console_info,
|
|
88
|
+
trace: __console_trace,
|
|
89
|
+
dir: __console_dir,
|
|
90
|
+
table: __console_table,
|
|
91
|
+
time: __console_time,
|
|
92
|
+
timeEnd: __console_timeEnd,
|
|
93
|
+
timeLog: __console_timeLog,
|
|
94
|
+
count: __console_count,
|
|
95
|
+
countReset: __console_countReset,
|
|
96
|
+
group: __console_group,
|
|
97
|
+
groupCollapsed: __console_groupCollapsed,
|
|
98
|
+
groupEnd: __console_groupEnd,
|
|
99
|
+
clear: __console_clear,
|
|
100
|
+
assert: __console_assert,
|
|
101
|
+
};
|
|
102
|
+
`);
|
|
103
|
+
return {
|
|
104
|
+
dispose() {
|
|
105
|
+
timers.clear();
|
|
106
|
+
counters.clear();
|
|
107
|
+
groupDepth = 0;
|
|
108
|
+
},
|
|
109
|
+
reset() {
|
|
110
|
+
timers.clear();
|
|
111
|
+
counters.clear();
|
|
112
|
+
groupDepth = 0;
|
|
113
|
+
},
|
|
114
|
+
getTimers() {
|
|
115
|
+
return new Map(timers);
|
|
116
|
+
},
|
|
117
|
+
getCounters() {
|
|
118
|
+
return new Map(counters);
|
|
119
|
+
},
|
|
120
|
+
getGroupDepth() {
|
|
121
|
+
return groupDepth;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
setupConsole
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
//# debugId=5ED37B6ACE7B494E64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import ivm from \"isolated-vm\";\n\nexport interface ConsoleOptions {\n onLog?: (level: string, ...args: unknown[]) => void;\n onTime?: (label: string, duration: number) => void;\n onTimeLog?: (label: string, duration: number, ...args: unknown[]) => void;\n onCount?: (label: string, count: number) => void;\n onCountReset?: (label: string) => void;\n onGroup?: (label: string, collapsed: boolean) => void;\n onGroupEnd?: () => void;\n onClear?: () => void;\n onAssert?: (condition: boolean, ...args: unknown[]) => void;\n}\n\nexport interface ConsoleHandle {\n dispose(): void;\n reset(): void;\n getTimers(): Map<string, number>;\n getCounters(): Map<string, number>;\n getGroupDepth(): number;\n}\n\n/**\n * Setup console API in an isolated-vm context\n *\n * Injects console.log, console.warn, console.error, console.info, console.debug,\n * console.trace, console.dir, console.table, console.time, console.timeEnd,\n * console.timeLog, console.count, console.countReset, console.group,\n * console.groupCollapsed, console.groupEnd, console.clear, console.assert\n *\n * @example\n * const handle = await setupConsole(context, {\n * onLog: (level, ...args) => console.log(`[${level}]`, ...args)\n * });\n */\nexport async function setupConsole(\n context: ivm.Context,\n options?: ConsoleOptions\n): Promise<ConsoleHandle> {\n const opts = options ?? {};\n\n // State management\n const timers = new Map<string, number>();\n const counters = new Map<string, number>();\n let groupDepth = 0;\n\n const global = context.global;\n\n // Log-level methods\n const logLevels = [\n \"log\",\n \"warn\",\n \"error\",\n \"debug\",\n \"info\",\n \"trace\",\n \"dir\",\n \"table\",\n ];\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((...args: unknown[]) => {\n opts.onLog?.(level, ...args);\n })\n );\n }\n\n // Timing methods\n global.setSync(\n \"__console_time\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n timers.set(l, performance.now());\n })\n );\n\n global.setSync(\n \"__console_timeEnd\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n timers.delete(l);\n opts.onTime?.(l, duration);\n }\n })\n );\n\n global.setSync(\n \"__console_timeLog\",\n new ivm.Callback((label?: string, ...args: unknown[]) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n opts.onTimeLog?.(l, duration, ...args);\n }\n })\n );\n\n // Counting methods\n global.setSync(\n \"__console_count\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const count = (counters.get(l) ?? 0) + 1;\n counters.set(l, count);\n opts.onCount?.(l, count);\n })\n );\n\n global.setSync(\n \"__console_countReset\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n counters.delete(l);\n opts.onCountReset?.(l);\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n groupDepth++;\n opts.onGroup?.(l, false);\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n groupDepth++;\n opts.onGroup?.(l, true);\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onGroupEnd?.();\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onClear?.();\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((condition: boolean, ...args: unknown[]) => {\n if (!condition) {\n opts.onAssert?.(condition, ...args);\n }\n })\n );\n\n // Inject console object\n context.evalSync(`\n globalThis.console = {\n log: __console_log,\n warn: __console_warn,\n error: __console_error,\n debug: __console_debug,\n info: __console_info,\n trace: __console_trace,\n dir: __console_dir,\n table: __console_table,\n time: __console_time,\n timeEnd: __console_timeEnd,\n timeLog: __console_timeLog,\n count: __console_count,\n countReset: __console_countReset,\n group: __console_group,\n groupCollapsed: __console_groupCollapsed,\n groupEnd: __console_groupEnd,\n clear: __console_clear,\n assert: __console_assert,\n };\n `);\n\n return {\n dispose() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n reset() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n getTimers() {\n return new Map(timers);\n },\n getCounters() {\n return new Map(counters);\n },\n getGroupDepth() {\n return groupDepth;\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAAA;AAmCA,eAAsB,YAAY,CAChC,SACA,SACwB;AAAA,EACxB,MAAM,OAAO,WAAW,CAAC;AAAA,EAGzB,MAAM,SAAS,IAAI;AAAA,EACnB,MAAM,WAAW,IAAI;AAAA,EACrB,IAAI,aAAa;AAAA,EAEjB,MAAM,SAAS,QAAQ;AAAA,EAGvB,MAAM,YAAY;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,WAAW,SAAS,WAAW;AAAA,IAC7B,OAAO,QACL,aAAa,SACb,IAAI,IAAI,SAAS,IAAI,SAAoB;AAAA,MACvC,KAAK,QAAQ,OAAO,GAAG,IAAI;AAAA,KAC5B,CACH;AAAA,EACF;AAAA,EAGA,OAAO,QACL,kBACA,IAAI,IAAI,SAAS,CAAC,UAAmB;AAAA,IACnC,MAAM,IAAI,SAAS;AAAA,IACnB,OAAO,IAAI,GAAG,YAAY,IAAI,CAAC;AAAA,GAChC,CACH;AAAA,EAEA,OAAO,QACL,qBACA,IAAI,IAAI,SAAS,CAAC,UAAmB;AAAA,IACnC,MAAM,IAAI,SAAS;AAAA,IACnB,MAAM,QAAQ,OAAO,IAAI,CAAC;AAAA,IAC1B,IAAI,UAAU,WAAW;AAAA,MACvB,MAAM,WAAW,YAAY,IAAI,IAAI;AAAA,MACrC,OAAO,OAAO,CAAC;AAAA,MACf,KAAK,SAAS,GAAG,QAAQ;AAAA,IAC3B;AAAA,GACD,CACH;AAAA,EAEA,OAAO,QACL,qBACA,IAAI,IAAI,SAAS,CAAC,UAAmB,SAAoB;AAAA,IACvD,MAAM,IAAI,SAAS;AAAA,IACnB,MAAM,QAAQ,OAA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,WAAW,GAAG,IAAI;AAAA,IACpC;AAAA,GACD,CACH;AAAA,EAGA,QAAQ,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAqBhB;AAAA,EAED,OAAO;AAAA,IACL,OAAO,GAAG;AAAA,MACR,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,MACf,aAAa;AAAA;AAAA,IAEf,KAAK,GAAG;AAAA,MACN,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,MACf,aAAa;AAAA;AAAA,IAEf,SAAS,GAAG;AAAA,MACV,OAAO,IAAI,IAAI,MAAM;AAAA;AAAA,IAEvB,WAAW,GAAG;AAAA,MACZ,OAAO,IAAI,IAAI,QAAQ;AAAA;AAAA,IAEzB,aAAa,GAAG;AAAA,MACd,OAAO;AAAA;AAAA,EAEX;AAAA;",
|
|
8
|
+
"debugId": "5ED37B6ACE7B494E64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ivm from "isolated-vm";
|
|
2
|
+
export interface ConsoleOptions {
|
|
3
|
+
onLog?: (level: string, ...args: unknown[]) => void;
|
|
4
|
+
onTime?: (label: string, duration: number) => void;
|
|
5
|
+
onTimeLog?: (label: string, duration: number, ...args: unknown[]) => void;
|
|
6
|
+
onCount?: (label: string, count: number) => void;
|
|
7
|
+
onCountReset?: (label: string) => void;
|
|
8
|
+
onGroup?: (label: string, collapsed: boolean) => void;
|
|
9
|
+
onGroupEnd?: () => void;
|
|
10
|
+
onClear?: () => void;
|
|
11
|
+
onAssert?: (condition: boolean, ...args: unknown[]) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface ConsoleHandle {
|
|
14
|
+
dispose(): void;
|
|
15
|
+
reset(): void;
|
|
16
|
+
getTimers(): Map<string, number>;
|
|
17
|
+
getCounters(): Map<string, number>;
|
|
18
|
+
getGroupDepth(): number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Setup console API in an isolated-vm context
|
|
22
|
+
*
|
|
23
|
+
* Injects console.log, console.warn, console.error, console.info, console.debug,
|
|
24
|
+
* console.trace, console.dir, console.table, console.time, console.timeEnd,
|
|
25
|
+
* console.timeLog, console.count, console.countReset, console.group,
|
|
26
|
+
* console.groupCollapsed, console.groupEnd, console.clear, console.assert
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const handle = await setupConsole(context, {
|
|
30
|
+
* onLog: (level, ...args) => console.log(`[${level}]`, ...args)
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export declare function setupConsole(context: ivm.Context, options?: ConsoleOptions): Promise<ConsoleHandle>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global Type Definitions for @ricsam/isolate-console
|
|
3
|
+
*
|
|
4
|
+
* These types define the globals injected by setupConsole() into an isolated-vm context.
|
|
5
|
+
* Use these types to typecheck user code that will run inside the V8 isolate.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export {};
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
/**
|
|
12
|
+
* Console interface for logging and debugging.
|
|
13
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Console
|
|
14
|
+
*/
|
|
15
|
+
interface Console {
|
|
16
|
+
/**
|
|
17
|
+
* Log a message to the console.
|
|
18
|
+
* @param data - Values to log
|
|
19
|
+
*/
|
|
20
|
+
log(...data: unknown[]): void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Log a warning message.
|
|
24
|
+
* @param data - Values to log
|
|
25
|
+
*/
|
|
26
|
+
warn(...data: unknown[]): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Log an error message.
|
|
30
|
+
* @param data - Values to log
|
|
31
|
+
*/
|
|
32
|
+
error(...data: unknown[]): void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Log a debug message.
|
|
36
|
+
* @param data - Values to log
|
|
37
|
+
*/
|
|
38
|
+
debug(...data: unknown[]): void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Log an info message.
|
|
42
|
+
* @param data - Values to log
|
|
43
|
+
*/
|
|
44
|
+
info(...data: unknown[]): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Log a stack trace.
|
|
48
|
+
* @param data - Values to log with the trace
|
|
49
|
+
*/
|
|
50
|
+
trace(...data: unknown[]): void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Display an object in a formatted way.
|
|
54
|
+
* @param item - Object to display
|
|
55
|
+
* @param options - Display options
|
|
56
|
+
*/
|
|
57
|
+
dir(item: unknown, options?: object): void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Display tabular data.
|
|
61
|
+
* @param tabularData - Data to display as a table
|
|
62
|
+
* @param properties - Optional array of property names to include
|
|
63
|
+
*/
|
|
64
|
+
table(tabularData: unknown, properties?: string[]): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Start a timer.
|
|
68
|
+
* @param label - Timer label (default: "default")
|
|
69
|
+
*/
|
|
70
|
+
time(label?: string): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* End a timer and log the elapsed time.
|
|
74
|
+
* @param label - Timer label (default: "default")
|
|
75
|
+
*/
|
|
76
|
+
timeEnd(label?: string): void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Log the elapsed time of a timer without ending it.
|
|
80
|
+
* @param label - Timer label (default: "default")
|
|
81
|
+
* @param data - Additional values to log
|
|
82
|
+
*/
|
|
83
|
+
timeLog(label?: string, ...data: unknown[]): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Log an error if the assertion is false.
|
|
87
|
+
* @param condition - Condition to test
|
|
88
|
+
* @param data - Values to log if assertion fails
|
|
89
|
+
*/
|
|
90
|
+
assert(condition?: boolean, ...data: unknown[]): void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Increment and log a counter.
|
|
94
|
+
* @param label - Counter label (default: "default")
|
|
95
|
+
*/
|
|
96
|
+
count(label?: string): void;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Reset a counter.
|
|
100
|
+
* @param label - Counter label (default: "default")
|
|
101
|
+
*/
|
|
102
|
+
countReset(label?: string): void;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Clear the console.
|
|
106
|
+
*/
|
|
107
|
+
clear(): void;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Start an inline group.
|
|
111
|
+
* @param data - Group label
|
|
112
|
+
*/
|
|
113
|
+
group(...data: unknown[]): void;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Start a collapsed inline group.
|
|
117
|
+
* @param data - Group label
|
|
118
|
+
*/
|
|
119
|
+
groupCollapsed(...data: unknown[]): void;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* End the current inline group.
|
|
123
|
+
*/
|
|
124
|
+
groupEnd(): void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Console object for logging and debugging.
|
|
129
|
+
*/
|
|
130
|
+
const console: Console;
|
|
131
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/isolate-console",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"types": "./src/index.ts",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"main": "./dist/cjs/index.cjs",
|
|
5
|
+
"types": "./dist/types/index.d.ts",
|
|
7
6
|
"exports": {
|
|
8
7
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"require": "./dist/cjs/index.cjs",
|
|
10
|
+
"import": "./dist/mjs/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./isolate": {
|
|
13
|
+
"types": "./dist/types/isolate.d.ts"
|
|
11
14
|
}
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
@@ -19,11 +22,37 @@
|
|
|
19
22
|
"@ricsam/isolate-core": "*",
|
|
20
23
|
"isolated-vm": "^6"
|
|
21
24
|
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/node": "^24",
|
|
24
|
-
"typescript": "^5"
|
|
25
|
-
},
|
|
26
25
|
"peerDependencies": {
|
|
27
26
|
"isolated-vm": "^6"
|
|
28
|
-
}
|
|
29
|
-
|
|
27
|
+
},
|
|
28
|
+
"author": "Richard Samuelsson",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ricsam/isolate.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/ricsam/isolate/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/ricsam/isolate#readme",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"isolated-vm",
|
|
40
|
+
"sandbox",
|
|
41
|
+
"javascript",
|
|
42
|
+
"runtime",
|
|
43
|
+
"fetch",
|
|
44
|
+
"filesystem",
|
|
45
|
+
"streams",
|
|
46
|
+
"v8",
|
|
47
|
+
"isolate"
|
|
48
|
+
],
|
|
49
|
+
"description": "Console API implementation for isolated-vm V8 sandbox",
|
|
50
|
+
"module": "./dist/mjs/index.mjs",
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"README.md"
|
|
57
|
+
]
|
|
58
|
+
}
|