@ricsam/isolate-console 0.1.6 → 0.1.8

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.
@@ -43,35 +43,10 @@ var __export = (target, all) => {
43
43
  // packages/console/src/index.ts
44
44
  var exports_src = {};
45
45
  __export(exports_src, {
46
- simpleConsoleHandler: () => simpleConsoleHandler,
47
46
  setupConsole: () => setupConsole
48
47
  });
49
48
  module.exports = __toCommonJS(exports_src);
50
49
  var import_isolated_vm = __toESM(require("isolated-vm"));
51
- function simpleConsoleHandler(callbacks) {
52
- return {
53
- onEntry: (entry) => {
54
- if (entry.type === "output") {
55
- callbacks[entry.level]?.(...entry.args);
56
- } else if (entry.type === "assert") {
57
- callbacks.error?.("Assertion failed:", ...entry.args);
58
- } else if (entry.type === "trace") {
59
- callbacks.log?.(...entry.args, `
60
- ` + entry.stack);
61
- } else if (entry.type === "dir") {
62
- callbacks.log?.(entry.value);
63
- } else if (entry.type === "table") {
64
- callbacks.log?.(entry.data);
65
- } else if (entry.type === "time") {
66
- callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);
67
- } else if (entry.type === "timeLog") {
68
- callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`, ...entry.args);
69
- } else if (entry.type === "count") {
70
- callbacks.log?.(`${entry.label}: ${entry.count}`);
71
- }
72
- }
73
- };
74
- }
75
50
  async function setupConsole(context, options) {
76
51
  const opts = options ?? {};
77
52
  const timers = new Map;
@@ -252,4 +227,4 @@ async function setupConsole(context, options) {
252
227
  }
253
228
  })
254
229
 
255
- //# debugId=2521806AC72E527C64756E2164756E21
230
+ //# debugId=FC646D9EBBDCC0B464756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": [
5
- "import ivm from \"isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n args: unknown[];\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n args: unknown[];\n timestamp: number;\n }\n | { type: \"dir\"; value: unknown; groupDepth: number }\n | { type: \"table\"; data: unknown; columns?: string[]; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n args: unknown[];\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; args: unknown[]; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; args: unknown[]; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\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 * Simple console callback interface for basic usage.\n */\nexport interface SimpleConsoleCallbacks {\n log?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n debug?: (...args: unknown[]) => void;\n}\n\n/**\n * Helper to create ConsoleOptions from simple callbacks.\n * Routes log-level outputs to the appropriate callback and handles assertions.\n *\n * @example\n * ```typescript\n * const runtime = await createRuntime({\n * console: simpleConsoleHandler({\n * log: (...args) => console.log('[sandbox]', ...args),\n * warn: (...args) => console.warn('[sandbox]', ...args),\n * error: (...args) => console.error('[sandbox]', ...args),\n * })\n * });\n * ```\n */\nexport function simpleConsoleHandler(\n callbacks: SimpleConsoleCallbacks\n): ConsoleOptions {\n return {\n onEntry: (entry) => {\n if (entry.type === \"output\") {\n callbacks[entry.level]?.(...entry.args);\n } else if (entry.type === \"assert\") {\n callbacks.error?.(\"Assertion failed:\", ...entry.args);\n } else if (entry.type === \"trace\") {\n callbacks.log?.(...entry.args, \"\\n\" + entry.stack);\n } else if (entry.type === \"dir\") {\n callbacks.log?.(entry.value);\n } else if (entry.type === \"table\") {\n callbacks.log?.(entry.data);\n } else if (entry.type === \"time\") {\n callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);\n } else if (entry.type === \"timeLog\") {\n callbacks.log?.(\n `${entry.label}: ${entry.duration.toFixed(2)}ms`,\n ...entry.args\n );\n } else if (entry.type === \"count\") {\n callbacks.log?.(`${entry.label}: ${entry.count}`);\n }\n // group, groupEnd, groupEnd, countReset, clear are silently ignored\n },\n };\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 * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\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 (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((...args: unknown[]) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n args,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((value: unknown) => {\n opts.onEntry?.({\n type: \"dir\",\n value,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((data: unknown, columns?: string[]) => {\n opts.onEntry?.({\n type: \"table\",\n data,\n columns,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((...args: unknown[]) => {\n const stack = new Error().stack ?? \"\";\n opts.onEntry?.({\n type: \"trace\",\n args,\n stack,\n groupDepth,\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.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\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.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration,\n args,\n groupDepth,\n });\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.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\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.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((condition: boolean, ...args: unknown[]) => {\n if (!condition) {\n opts.onEntry?.({\n type: \"assert\",\n args,\n groupDepth,\n });\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"
5
+ "import ivm from \"isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n args: unknown[];\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n args: unknown[];\n timestamp: number;\n }\n | { type: \"dir\"; value: unknown; groupDepth: number }\n | { type: \"table\"; data: unknown; columns?: string[]; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n args: unknown[];\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; args: unknown[]; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; args: unknown[]; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\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/**\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 * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\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 (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((...args: unknown[]) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n args,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((value: unknown) => {\n opts.onEntry?.({\n type: \"dir\",\n value,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((data: unknown, columns?: string[]) => {\n opts.onEntry?.({\n type: \"table\",\n data,\n columns,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((...args: unknown[]) => {\n const stack = new Error().stack ?? \"\";\n opts.onEntry?.({\n type: \"trace\",\n args,\n stack,\n groupDepth,\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.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\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.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration,\n args,\n groupDepth,\n });\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.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\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.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((condition: boolean, ...args: unknown[]) => {\n if (!condition) {\n opts.onEntry?.({\n type: \"assert\",\n args,\n groupDepth,\n });\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
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAgB,IAAhB;AA2FO,S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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": "FC646D9EBBDCC0B464756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/isolate-console",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "commonjs"
5
5
  }
@@ -0,0 +1,62 @@
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/console/src/utils.ts
31
+ var exports_utils = {};
32
+ __export(exports_utils, {
33
+ simpleConsoleHandler: () => simpleConsoleHandler
34
+ });
35
+ module.exports = __toCommonJS(exports_utils);
36
+ function simpleConsoleHandler(callbacks) {
37
+ return {
38
+ onEntry: (entry) => {
39
+ if (entry.type === "output") {
40
+ callbacks[entry.level]?.(...entry.args);
41
+ } else if (entry.type === "assert") {
42
+ callbacks.error?.("Assertion failed:", ...entry.args);
43
+ } else if (entry.type === "trace") {
44
+ callbacks.log?.(...entry.args, `
45
+ ` + entry.stack);
46
+ } else if (entry.type === "dir") {
47
+ callbacks.log?.(entry.value);
48
+ } else if (entry.type === "table") {
49
+ callbacks.log?.(entry.data);
50
+ } else if (entry.type === "time") {
51
+ callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);
52
+ } else if (entry.type === "timeLog") {
53
+ callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`, ...entry.args);
54
+ } else if (entry.type === "count") {
55
+ callbacks.log?.(`${entry.label}: ${entry.count}`);
56
+ }
57
+ }
58
+ };
59
+ }
60
+ })
61
+
62
+ //# debugId=752A88C74B87BDF964756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils.ts"],
4
+ "sourcesContent": [
5
+ "import type { ConsoleOptions } from \"./index.cjs\";\n\n/**\n * Simple console callback interface for basic usage.\n */\nexport interface SimpleConsoleCallbacks {\n log?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n debug?: (...args: unknown[]) => void;\n}\n\n/**\n * Helper to create ConsoleOptions from simple callbacks.\n * Routes log-level outputs to the appropriate callback and handles assertions.\n *\n * @example\n * ```typescript\n * const runtime = await createRuntime({\n * console: simpleConsoleHandler({\n * log: (...args) => console.log('[sandbox]', ...args),\n * warn: (...args) => console.warn('[sandbox]', ...args),\n * error: (...args) => console.error('[sandbox]', ...args),\n * })\n * });\n * ```\n */\nexport function simpleConsoleHandler(\n callbacks: SimpleConsoleCallbacks\n): ConsoleOptions {\n return {\n onEntry: (entry) => {\n if (entry.type === \"output\") {\n callbacks[entry.level]?.(...entry.args);\n } else if (entry.type === \"assert\") {\n callbacks.error?.(\"Assertion failed:\", ...entry.args);\n } else if (entry.type === \"trace\") {\n callbacks.log?.(...entry.args, \"\\n\" + entry.stack);\n } else if (entry.type === \"dir\") {\n callbacks.log?.(entry.value);\n } else if (entry.type === \"table\") {\n callbacks.log?.(entry.data);\n } else if (entry.type === \"time\") {\n callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);\n } else if (entry.type === \"timeLog\") {\n callbacks.log?.(\n `${entry.label}: ${entry.duration.toFixed(2)}ms`,\n ...entry.args\n );\n } else if (entry.type === \"count\") {\n callbacks.log?.(`${entry.label}: ${entry.count}`);\n }\n // group, groupEnd, groupEnd, countReset, clear are silently ignored\n },\n };\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,SAAS,oBAAoB,CAClC,WACgB;AAAA,EAChB,OAAO;AAAA,IACL,SAAS,CAAC,UAAU;AAAA,MAClB,IAAI,MAAM,SAAS,UAAU;AAAA,QAC3B,UAAU,MAAM,SAAS,GAAG,MAAM,IAAI;AAAA,MACxC,EAAO,SAAI,MAAM,SAAS,UAAU;AAAA,QAClC,UAAU,QAAQ,qBAAqB,GAAG,MAAM,IAAI;AAAA,MACtD,EAAO,SAAI,MAAM,SAAS,SAAS;AAAA,QACjC,UAAU,MAAM,GAAG,MAAM,MAAM;AAAA,IAAO,MAAM,KAAK;AAAA,MACnD,EAAO,SAAI,MAAM,SAAS,OAAO;AAAA,QAC/B,UAAU,MAAM,MAAM,KAAK;AAAA,MAC7B,EAAO,SAAI,MAAM,SAAS,SAAS;AAAA,QACjC,UAAU,MAAM,MAAM,IAAI;AAAA,MAC5B,EAAO,SAAI,MAAM,SAAS,QAAQ;AAAA,QAChC,UAAU,MAAM,GAAG,MAAM,UAAU,MAAM,SAAS,QAAQ,CAAC,KAAK;AAAA,MAClE,EAAO,SAAI,MAAM,SAAS,WAAW;AAAA,QACnC,UAAU,MACR,GAAG,MAAM,UAAU,MAAM,SAAS,QAAQ,CAAC,OAC3C,GAAG,MAAM,IACX;AAAA,MACF,EAAO,SAAI,MAAM,SAAS,SAAS;AAAA,QACjC,UAAU,MAAM,GAAG,MAAM,UAAU,MAAM,OAAO;AAAA,MAClD;AAAA;AAAA,EAGJ;AAAA;",
8
+ "debugId": "752A88C74B87BDF964756E2164756E21",
9
+ "names": []
10
+ }
@@ -1,30 +1,6 @@
1
1
  // @bun
2
2
  // packages/console/src/index.ts
3
3
  import ivm from "isolated-vm";
4
- function simpleConsoleHandler(callbacks) {
5
- return {
6
- onEntry: (entry) => {
7
- if (entry.type === "output") {
8
- callbacks[entry.level]?.(...entry.args);
9
- } else if (entry.type === "assert") {
10
- callbacks.error?.("Assertion failed:", ...entry.args);
11
- } else if (entry.type === "trace") {
12
- callbacks.log?.(...entry.args, `
13
- ` + entry.stack);
14
- } else if (entry.type === "dir") {
15
- callbacks.log?.(entry.value);
16
- } else if (entry.type === "table") {
17
- callbacks.log?.(entry.data);
18
- } else if (entry.type === "time") {
19
- callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);
20
- } else if (entry.type === "timeLog") {
21
- callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`, ...entry.args);
22
- } else if (entry.type === "count") {
23
- callbacks.log?.(`${entry.label}: ${entry.count}`);
24
- }
25
- }
26
- };
27
- }
28
4
  async function setupConsole(context, options) {
29
5
  const opts = options ?? {};
30
6
  const timers = new Map;
@@ -204,8 +180,7 @@ async function setupConsole(context, options) {
204
180
  };
205
181
  }
206
182
  export {
207
- simpleConsoleHandler,
208
183
  setupConsole
209
184
  };
210
185
 
211
- //# debugId=763E37163F3CD31764756E2164756E21
186
+ //# debugId=1AFBE2B996BA5ED464756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": [
5
- "import ivm from \"isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n args: unknown[];\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n args: unknown[];\n timestamp: number;\n }\n | { type: \"dir\"; value: unknown; groupDepth: number }\n | { type: \"table\"; data: unknown; columns?: string[]; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n args: unknown[];\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; args: unknown[]; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; args: unknown[]; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\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 * Simple console callback interface for basic usage.\n */\nexport interface SimpleConsoleCallbacks {\n log?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n debug?: (...args: unknown[]) => void;\n}\n\n/**\n * Helper to create ConsoleOptions from simple callbacks.\n * Routes log-level outputs to the appropriate callback and handles assertions.\n *\n * @example\n * ```typescript\n * const runtime = await createRuntime({\n * console: simpleConsoleHandler({\n * log: (...args) => console.log('[sandbox]', ...args),\n * warn: (...args) => console.warn('[sandbox]', ...args),\n * error: (...args) => console.error('[sandbox]', ...args),\n * })\n * });\n * ```\n */\nexport function simpleConsoleHandler(\n callbacks: SimpleConsoleCallbacks\n): ConsoleOptions {\n return {\n onEntry: (entry) => {\n if (entry.type === \"output\") {\n callbacks[entry.level]?.(...entry.args);\n } else if (entry.type === \"assert\") {\n callbacks.error?.(\"Assertion failed:\", ...entry.args);\n } else if (entry.type === \"trace\") {\n callbacks.log?.(...entry.args, \"\\n\" + entry.stack);\n } else if (entry.type === \"dir\") {\n callbacks.log?.(entry.value);\n } else if (entry.type === \"table\") {\n callbacks.log?.(entry.data);\n } else if (entry.type === \"time\") {\n callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);\n } else if (entry.type === \"timeLog\") {\n callbacks.log?.(\n `${entry.label}: ${entry.duration.toFixed(2)}ms`,\n ...entry.args\n );\n } else if (entry.type === \"count\") {\n callbacks.log?.(`${entry.label}: ${entry.count}`);\n }\n // group, groupEnd, groupEnd, countReset, clear are silently ignored\n },\n };\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 * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\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 (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((...args: unknown[]) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n args,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((value: unknown) => {\n opts.onEntry?.({\n type: \"dir\",\n value,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((data: unknown, columns?: string[]) => {\n opts.onEntry?.({\n type: \"table\",\n data,\n columns,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((...args: unknown[]) => {\n const stack = new Error().stack ?? \"\";\n opts.onEntry?.({\n type: \"trace\",\n args,\n stack,\n groupDepth,\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.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\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.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration,\n args,\n groupDepth,\n });\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.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\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.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((condition: boolean, ...args: unknown[]) => {\n if (!condition) {\n opts.onEntry?.({\n type: \"assert\",\n args,\n groupDepth,\n });\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"
5
+ "import ivm from \"isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n args: unknown[];\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n args: unknown[];\n timestamp: number;\n }\n | { type: \"dir\"; value: unknown; groupDepth: number }\n | { type: \"table\"; data: unknown; columns?: string[]; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n args: unknown[];\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; args: unknown[]; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; args: unknown[]; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\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/**\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 * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\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 (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((...args: unknown[]) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n args,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((value: unknown) => {\n opts.onEntry?.({\n type: \"dir\",\n value,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((data: unknown, columns?: string[]) => {\n opts.onEntry?.({\n type: \"table\",\n data,\n columns,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((...args: unknown[]) => {\n const stack = new Error().stack ?? \"\";\n opts.onEntry?.({\n type: \"trace\",\n args,\n stack,\n groupDepth,\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.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\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.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration,\n args,\n groupDepth,\n });\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.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\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.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((condition: boolean, ...args: unknown[]) => {\n if (!condition) {\n opts.onEntry?.({\n type: \"assert\",\n args,\n groupDepth,\n });\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
6
  ],
7
- "mappings": ";;AAAA;AA2FO,SAAS,oBAAoB,CAClC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AA,MACZ,OAAO,IAAI,IAAI,QAAQ;AAAA;AAAA,IAEzB,aAAa,GAAG;AAAA,MACd,OAAO;AAAA;AAAA,EAEX;AAAA;",
8
+ "debugId": "1AFBE2B996BA5ED464756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/isolate-console",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module"
5
5
  }
@@ -0,0 +1,31 @@
1
+ // @bun
2
+ // packages/console/src/utils.ts
3
+ function simpleConsoleHandler(callbacks) {
4
+ return {
5
+ onEntry: (entry) => {
6
+ if (entry.type === "output") {
7
+ callbacks[entry.level]?.(...entry.args);
8
+ } else if (entry.type === "assert") {
9
+ callbacks.error?.("Assertion failed:", ...entry.args);
10
+ } else if (entry.type === "trace") {
11
+ callbacks.log?.(...entry.args, `
12
+ ` + entry.stack);
13
+ } else if (entry.type === "dir") {
14
+ callbacks.log?.(entry.value);
15
+ } else if (entry.type === "table") {
16
+ callbacks.log?.(entry.data);
17
+ } else if (entry.type === "time") {
18
+ callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);
19
+ } else if (entry.type === "timeLog") {
20
+ callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`, ...entry.args);
21
+ } else if (entry.type === "count") {
22
+ callbacks.log?.(`${entry.label}: ${entry.count}`);
23
+ }
24
+ }
25
+ };
26
+ }
27
+ export {
28
+ simpleConsoleHandler
29
+ };
30
+
31
+ //# debugId=4B887163234FF74964756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils.ts"],
4
+ "sourcesContent": [
5
+ "import type { ConsoleOptions } from \"./index.mjs\";\n\n/**\n * Simple console callback interface for basic usage.\n */\nexport interface SimpleConsoleCallbacks {\n log?: (...args: unknown[]) => void;\n warn?: (...args: unknown[]) => void;\n error?: (...args: unknown[]) => void;\n info?: (...args: unknown[]) => void;\n debug?: (...args: unknown[]) => void;\n}\n\n/**\n * Helper to create ConsoleOptions from simple callbacks.\n * Routes log-level outputs to the appropriate callback and handles assertions.\n *\n * @example\n * ```typescript\n * const runtime = await createRuntime({\n * console: simpleConsoleHandler({\n * log: (...args) => console.log('[sandbox]', ...args),\n * warn: (...args) => console.warn('[sandbox]', ...args),\n * error: (...args) => console.error('[sandbox]', ...args),\n * })\n * });\n * ```\n */\nexport function simpleConsoleHandler(\n callbacks: SimpleConsoleCallbacks\n): ConsoleOptions {\n return {\n onEntry: (entry) => {\n if (entry.type === \"output\") {\n callbacks[entry.level]?.(...entry.args);\n } else if (entry.type === \"assert\") {\n callbacks.error?.(\"Assertion failed:\", ...entry.args);\n } else if (entry.type === \"trace\") {\n callbacks.log?.(...entry.args, \"\\n\" + entry.stack);\n } else if (entry.type === \"dir\") {\n callbacks.log?.(entry.value);\n } else if (entry.type === \"table\") {\n callbacks.log?.(entry.data);\n } else if (entry.type === \"time\") {\n callbacks.log?.(`${entry.label}: ${entry.duration.toFixed(2)}ms`);\n } else if (entry.type === \"timeLog\") {\n callbacks.log?.(\n `${entry.label}: ${entry.duration.toFixed(2)}ms`,\n ...entry.args\n );\n } else if (entry.type === \"count\") {\n callbacks.log?.(`${entry.label}: ${entry.count}`);\n }\n // group, groupEnd, groupEnd, countReset, clear are silently ignored\n },\n };\n}\n"
6
+ ],
7
+ "mappings": ";;AA4BO,SAAS,oBAAoB,CAClC,WACgB;AAAA,EAChB,OAAO;AAAA,IACL,SAAS,CAAC,UAAU;AAAA,MAClB,IAAI,MAAM,SAAS,UAAU;AAAA,QAC3B,UAAU,MAAM,SAAS,GAAG,MAAM,IAAI;AAAA,MACxC,EAAO,SAAI,MAAM,SAAS,UAAU;AAAA,QAClC,UAAU,QAAQ,qBAAqB,GAAG,MAAM,IAAI;AAAA,MACtD,EAAO,SAAI,MAAM,SAAS,SAAS;AAAA,QACjC,UAAU,MAAM,GAAG,MAAM,MAAM;AAAA,IAAO,MAAM,KAAK;AAAA,MACnD,EAAO,SAAI,MAAM,SAAS,OAAO;AAAA,QAC/B,UAAU,MAAM,MAAM,KAAK;AAAA,MAC7B,EAAO,SAAI,MAAM,SAAS,SAAS;AAAA,QACjC,UAAU,MAAM,MAAM,IAAI;AAAA,MAC5B,EAAO,SAAI,MAAM,SAAS,QAAQ;AAAA,QAChC,UAAU,MAAM,GAAG,MAAM,UAAU,MAAM,SAAS,QAAQ,CAAC,KAAK;AAAA,MAClE,EAAO,SAAI,MAAM,SAAS,WAAW;AAAA,QACnC,UAAU,MACR,GAAG,MAAM,UAAU,MAAM,SAAS,QAAQ,CAAC,OAC3C,GAAG,MAAM,IACX;AAAA,MACF,EAAO,SAAI,MAAM,SAAS,SAAS;AAAA,QACjC,UAAU,MAAM,GAAG,MAAM,UAAU,MAAM,OAAO;AAAA,MAClD;AAAA;AAAA,EAGJ;AAAA;",
8
+ "debugId": "4B887163234FF74964756E2164756E21",
9
+ "names": []
10
+ }
@@ -83,32 +83,6 @@ export interface ConsoleHandle {
83
83
  getCounters(): Map<string, number>;
84
84
  getGroupDepth(): number;
85
85
  }
86
- /**
87
- * Simple console callback interface for basic usage.
88
- */
89
- export interface SimpleConsoleCallbacks {
90
- log?: (...args: unknown[]) => void;
91
- warn?: (...args: unknown[]) => void;
92
- error?: (...args: unknown[]) => void;
93
- info?: (...args: unknown[]) => void;
94
- debug?: (...args: unknown[]) => void;
95
- }
96
- /**
97
- * Helper to create ConsoleOptions from simple callbacks.
98
- * Routes log-level outputs to the appropriate callback and handles assertions.
99
- *
100
- * @example
101
- * ```typescript
102
- * const runtime = await createRuntime({
103
- * console: simpleConsoleHandler({
104
- * log: (...args) => console.log('[sandbox]', ...args),
105
- * warn: (...args) => console.warn('[sandbox]', ...args),
106
- * error: (...args) => console.error('[sandbox]', ...args),
107
- * })
108
- * });
109
- * ```
110
- */
111
- export declare function simpleConsoleHandler(callbacks: SimpleConsoleCallbacks): ConsoleOptions;
112
86
  /**
113
87
  * Setup console API in an isolated-vm context
114
88
  *
@@ -0,0 +1,27 @@
1
+ import type { ConsoleOptions } from "./index.ts";
2
+ /**
3
+ * Simple console callback interface for basic usage.
4
+ */
5
+ export interface SimpleConsoleCallbacks {
6
+ log?: (...args: unknown[]) => void;
7
+ warn?: (...args: unknown[]) => void;
8
+ error?: (...args: unknown[]) => void;
9
+ info?: (...args: unknown[]) => void;
10
+ debug?: (...args: unknown[]) => void;
11
+ }
12
+ /**
13
+ * Helper to create ConsoleOptions from simple callbacks.
14
+ * Routes log-level outputs to the appropriate callback and handles assertions.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const runtime = await createRuntime({
19
+ * console: simpleConsoleHandler({
20
+ * log: (...args) => console.log('[sandbox]', ...args),
21
+ * warn: (...args) => console.warn('[sandbox]', ...args),
22
+ * error: (...args) => console.error('[sandbox]', ...args),
23
+ * })
24
+ * });
25
+ * ```
26
+ */
27
+ export declare function simpleConsoleHandler(callbacks: SimpleConsoleCallbacks): ConsoleOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/isolate-console",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "main": "./dist/cjs/index.cjs",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "exports": {
@@ -9,6 +9,11 @@
9
9
  "require": "./dist/cjs/index.cjs",
10
10
  "import": "./dist/mjs/index.mjs"
11
11
  },
12
+ "./utils": {
13
+ "types": "./dist/types/utils.d.ts",
14
+ "require": "./dist/cjs/utils.cjs",
15
+ "import": "./dist/mjs/utils.mjs"
16
+ },
12
17
  "./isolate": {
13
18
  "types": "./dist/types/isolate.d.ts"
14
19
  }