@danielsimonjr/mathts-workbook 0.4.0 → 0.4.1
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 +247 -247
- package/dist/{chunk-ZVCYWKM5.js → chunk-JM3ZAYJC.js} +1 -1
- package/dist/cli.d.ts +18 -19
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/contract.d.ts +16 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/doc.d.ts +29 -0
- package/dist/doc.d.ts.map +1 -0
- package/dist/edit.d.ts +44 -0
- package/dist/edit.d.ts.map +1 -0
- package/dist/executor.d.ts +98 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/formatter.d.ts +9 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/fs-atomic.d.ts +11 -0
- package/dist/fs-atomic.d.ts.map +1 -0
- package/dist/graph.d.ts +41 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/html.d.ts +43 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/index.d.ts +18 -501
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/introspect.d.ts +29 -0
- package/dist/introspect.d.ts.map +1 -0
- package/dist/ipynb.d.ts +24 -0
- package/dist/ipynb.d.ts.map +1 -0
- package/dist/markdown.d.ts +13 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/parser.d.ts +47 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/pdf.d.ts +12 -0
- package/dist/pdf.d.ts.map +1 -0
- package/dist/rpc.d.ts +45 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/run-worker.d.ts +2 -2
- package/dist/run-worker.d.ts.map +1 -0
- package/dist/session.d.ts +68 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/svg-math.d.ts +19 -0
- package/dist/svg-math.d.ts.map +1 -0
- package/dist/svg.d.ts +9 -0
- package/dist/svg.d.ts.map +1 -0
- package/dist/tex.d.ts +17 -0
- package/dist/tex.d.ts.map +1 -0
- package/dist/timeout-runner.d.ts +22 -0
- package/dist/timeout-runner.d.ts.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/worker-protocol.d.ts +44 -0
- package/dist/worker-protocol.d.ts.map +1 -0
- package/dist/yaml-safe.d.ts +34 -0
- package/dist/yaml-safe.d.ts.map +1 -0
- package/package.json +13 -13
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure JSON-RPC 2.0 router for `mtsw serve`. `handleRequest(session, request)`
|
|
3
|
+
* maps a request to a Session call and returns the response plus any streamed
|
|
4
|
+
* `cell/event` notifications — no stdio, so the protocol logic is unit-testable.
|
|
5
|
+
*/
|
|
6
|
+
import type { Session } from './session';
|
|
7
|
+
export interface JsonRpcRequest {
|
|
8
|
+
jsonrpc?: string;
|
|
9
|
+
id?: string | number | null;
|
|
10
|
+
method?: string;
|
|
11
|
+
params?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export interface JsonRpcResponse {
|
|
14
|
+
jsonrpc: '2.0';
|
|
15
|
+
id: string | number | null;
|
|
16
|
+
result?: unknown;
|
|
17
|
+
error?: {
|
|
18
|
+
code: number;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface JsonRpcEvent {
|
|
23
|
+
jsonrpc: '2.0';
|
|
24
|
+
method: 'cell/event';
|
|
25
|
+
params: {
|
|
26
|
+
type: string;
|
|
27
|
+
cellId?: string;
|
|
28
|
+
error?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface HandleResult {
|
|
32
|
+
response: JsonRpcResponse;
|
|
33
|
+
events: JsonRpcEvent[];
|
|
34
|
+
shutdown: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare const CODE: {
|
|
37
|
+
readonly PARSE: -32700;
|
|
38
|
+
readonly INVALID_REQUEST: -32600;
|
|
39
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
40
|
+
readonly INVALID_PARAMS: -32602;
|
|
41
|
+
readonly INTERNAL: -32603;
|
|
42
|
+
};
|
|
43
|
+
export declare function handleRequest(session: Session, request: JsonRpcRequest): Promise<HandleResult>;
|
|
44
|
+
export { CODE as JSON_RPC_CODES };
|
|
45
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3D;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,QAAA,MAAM,IAAI;aACR,KAAK,EAAE,CAAC,KAAK;aACb,eAAe,EAAE,CAAC,KAAK;aACvB,gBAAgB,EAAE,CAAC,KAAK;aACxB,cAAc,EAAE,CAAC,KAAK;aACtB,QAAQ,EAAE,CAAC,KAAK;CACR,CAAC;AAMX,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAiGpG;AAED,OAAO,EAAE,IAAI,IAAI,cAAc,EAAE,CAAC"}
|
package/dist/run-worker.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=run-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-worker.d.ts","sourceRoot":"","sources":["../src/run-worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory editing/execution session for a single workbook — the stateful
|
|
3
|
+
* core behind `mtsw serve`. Holds the workbook, a per-cell result cache, and a
|
|
4
|
+
* stale set so a `run` only re-executes what an edit invalidated.
|
|
5
|
+
*
|
|
6
|
+
* File I/O is limited to `open`/`save`; everything else is in-memory. Edits are
|
|
7
|
+
* not persisted until `save`.
|
|
8
|
+
*/
|
|
9
|
+
import type { Workbook, RunResult, CellType } from './types';
|
|
10
|
+
import * as edit from './edit';
|
|
11
|
+
export declare class Session {
|
|
12
|
+
workbook: Workbook | null;
|
|
13
|
+
path: string | null;
|
|
14
|
+
dirty: boolean;
|
|
15
|
+
private cache;
|
|
16
|
+
private stale;
|
|
17
|
+
private require;
|
|
18
|
+
/** A cell has a usable, up-to-date result (the basis for "not stale"). */
|
|
19
|
+
private hasValidResult;
|
|
20
|
+
/** Load a workbook file into the session. Refuses to discard unsaved edits. */
|
|
21
|
+
open(path: string, options?: {
|
|
22
|
+
force?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
/** Replace the workbook and recompute the stale set by diffing old vs new. */
|
|
25
|
+
private commit;
|
|
26
|
+
addCell(spec: {
|
|
27
|
+
id: string;
|
|
28
|
+
type: CellType;
|
|
29
|
+
content?: string;
|
|
30
|
+
dependsOn?: string[];
|
|
31
|
+
}, position?: edit.CellPosition): void;
|
|
32
|
+
editCell(id: string, changes: {
|
|
33
|
+
content?: string;
|
|
34
|
+
type?: CellType;
|
|
35
|
+
dependsOn?: string[];
|
|
36
|
+
}): void;
|
|
37
|
+
removeCell(id: string, options?: {
|
|
38
|
+
force?: boolean;
|
|
39
|
+
}): string[];
|
|
40
|
+
moveCell(id: string, position: edit.CellPosition): void;
|
|
41
|
+
renameCell(oldId: string, newId: string): void;
|
|
42
|
+
setMetadata(changes: {
|
|
43
|
+
title?: string;
|
|
44
|
+
author?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
}): void;
|
|
48
|
+
/**
|
|
49
|
+
* Incremental run: execute only stale cells in the target set (`only` + its
|
|
50
|
+
* ancestors, or the whole workbook), reusing cached outputs for the rest.
|
|
51
|
+
* Returns the merged report over the target plus the streamed events.
|
|
52
|
+
*/
|
|
53
|
+
run(only?: string): Promise<{
|
|
54
|
+
result: RunResult;
|
|
55
|
+
events: WorkbookEventLite[];
|
|
56
|
+
}>;
|
|
57
|
+
/** The set of cells awaiting (re-)execution. */
|
|
58
|
+
staleIds(): string[];
|
|
59
|
+
/** Serialize the current workbook and write it atomically. */
|
|
60
|
+
save(path?: string): string;
|
|
61
|
+
}
|
|
62
|
+
/** Slimmed event for streaming (avoids leaking timestamps / handler internals). */
|
|
63
|
+
export interface WorkbookEventLite {
|
|
64
|
+
type: string;
|
|
65
|
+
cellId?: string;
|
|
66
|
+
error?: string;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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E,QAAQ,EAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAEtD;IACD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE7C;IACD,WAAW,CAAC,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAErG;IAED;;;;OAIG;IACG,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,MAAM,EAAE,iBAAiB,EAAE,CAAA;KAAE,CAAC,CAwCpF;IAED,gDAAgD;IAChD,QAAQ,IAAI,MAAM,EAAE,CAEnB;IAED,8DAA8D;IAC9D,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1B;CACF;AAED,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MathML → SVG typesetting. Wraps a MathML fragment in an SVG document so
|
|
3
|
+
* rendered workbooks can emit SVG (browsers, rsvg, inkscape) instead of raw
|
|
4
|
+
* MathML. The glyph metrics are a conservative estimate — consumers that need
|
|
5
|
+
* pixel-perfect layout should typeset with a real engine; this is the
|
|
6
|
+
* no-dependency path the CLI/export uses.
|
|
7
|
+
*/
|
|
8
|
+
export interface MathSvgOptions {
|
|
9
|
+
/** Display (`block`) or inline. Default `block`. */
|
|
10
|
+
display?: 'block' | 'inline';
|
|
11
|
+
/** Extra padding in CSS pixels. Default 4. */
|
|
12
|
+
padding?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Wrap a MathML fragment (or a full `<math>` document) in an SVG with a
|
|
16
|
+
* `foreignObject` so the math remains selectable and scalable.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mathMLToSVG(mathml: string, options?: MathSvgOptions): string;
|
|
19
|
+
//# sourceMappingURL=svg-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg-math.d.ts","sourceRoot":"","sources":["../src/svg-math.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CAmBhF"}
|
package/dist/svg.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ChartSpec {
|
|
2
|
+
type?: 'line' | 'scatter' | 'bar';
|
|
3
|
+
title?: string;
|
|
4
|
+
xLabel?: string;
|
|
5
|
+
yLabel?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Render an SVG (default) or embeddable TikZ chart from a spec plus raw x/y data. */
|
|
8
|
+
export declare function renderChart(spec: ChartSpec, xRaw: unknown, yRaw: unknown, format?: 'svg' | 'tikz'): string;
|
|
9
|
+
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA6BD,sFAAsF;AACtF,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,OAAO,EACb,MAAM,GAAE,KAAK,GAAG,MAAc,GAC7B,MAAM,CAgBR"}
|
package/dist/tex.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assemble a RenderDoc into one self-contained LaTeX document (or a fragment
|
|
3
|
+
* for \input) — the TeX analog of html.ts's toHTML. Markdown prose via
|
|
4
|
+
* markdownToTex, equations via the injected parser's .toTex(), code via
|
|
5
|
+
* listings, tests as colored status lines, charts as embedded TikZ. All plain
|
|
6
|
+
* text is LaTeX-escaped; never throws.
|
|
7
|
+
*/
|
|
8
|
+
import type { RenderDoc } from './html.js';
|
|
9
|
+
export interface ToTexOptions {
|
|
10
|
+
/** Parser for equation expressions (e.g. the functions package `parse`). */
|
|
11
|
+
parse?: (expr: string) => unknown;
|
|
12
|
+
/** Emit only the cell bodies (for \input) instead of a standalone document. */
|
|
13
|
+
fragment?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Render a document structure to a standalone (or fragment) LaTeX string. Never throws. */
|
|
16
|
+
export declare function toTeX(doc: RenderDoc, options?: ToTexOptions): string;
|
|
17
|
+
//# sourceMappingURL=tex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tex.d.ts","sourceRoot":"","sources":["../src/tex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;AAGvD,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA+DD,4FAA4F;AAC5F,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAUxE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SerializedRunResult } from './worker-protocol.js';
|
|
2
|
+
export type { SerializedCellResult, SerializedRunResult, WorkerMessage, } from './worker-protocol.js';
|
|
3
|
+
export interface RunWorkbookWithTimeoutOptions {
|
|
4
|
+
/** Wall-clock budget in milliseconds. Exceeding it terminates the worker. */
|
|
5
|
+
timeoutMs: number;
|
|
6
|
+
}
|
|
7
|
+
/** Thrown when a workbook run is terminated for exceeding its time budget. */
|
|
8
|
+
export declare class WorkbookTimeoutError extends Error {
|
|
9
|
+
readonly timeoutMs: number;
|
|
10
|
+
constructor(timeoutMs: number);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Run a workbook's `.mtsw` source to completion (a continue-on-error report,
|
|
14
|
+
* like `runReport()`) inside a worker thread, killing that worker if it
|
|
15
|
+
* exceeds `timeoutMs`. The worker is ALWAYS terminated before this promise
|
|
16
|
+
* settles — on timeout, on success, and on error — so no handle is left open
|
|
17
|
+
* keeping the process alive.
|
|
18
|
+
*
|
|
19
|
+
* @throws {WorkbookTimeoutError} if the run is terminated for exceeding the budget.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runWorkbookWithTimeout(source: string, options: RunWorkbookWithTimeoutOptions): Promise<SerializedRunResult>;
|
|
22
|
+
//# sourceMappingURL=timeout-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout-runner.d.ts","sourceRoot":"","sources":["../src/timeout-runner.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,mBAAmB,EAAiB,MAAM,sBAAsB,CAAC;AAE/E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,6BAA6B;IAC5C,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,YAAY,SAAS,EAAE,MAAM,EAI5B;CACF;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,mBAAmB,CAAC,CA2C9B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workbook type definitions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Supported cell types
|
|
6
|
+
*/
|
|
7
|
+
export type CellType = 'markdown' | 'code' | 'tensor' | 'equation' | 'visualization' | 'data' | 'test' | 'export';
|
|
8
|
+
/**
|
|
9
|
+
* Execution modes
|
|
10
|
+
*/
|
|
11
|
+
export type ExecutionMode = 'reactive' | 'sequential' | 'manual';
|
|
12
|
+
/**
|
|
13
|
+
* Workbook metadata
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkbookMetadata {
|
|
16
|
+
title?: string;
|
|
17
|
+
author?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
created?: string;
|
|
21
|
+
modified?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Runtime configuration
|
|
25
|
+
*/
|
|
26
|
+
export interface RuntimeConfig {
|
|
27
|
+
engine: 'mathts' | 'custom';
|
|
28
|
+
execution: ExecutionMode;
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Individual cell in a workbook
|
|
33
|
+
*/
|
|
34
|
+
export interface Cell {
|
|
35
|
+
id: string;
|
|
36
|
+
type: CellType;
|
|
37
|
+
content: string;
|
|
38
|
+
dependsOn?: string[];
|
|
39
|
+
output?: unknown;
|
|
40
|
+
error?: string;
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Complete workbook structure
|
|
45
|
+
*/
|
|
46
|
+
export interface Workbook {
|
|
47
|
+
version: string;
|
|
48
|
+
metadata: WorkbookMetadata;
|
|
49
|
+
runtime: RuntimeConfig;
|
|
50
|
+
cells: Cell[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse result with validation
|
|
54
|
+
*/
|
|
55
|
+
export interface ParseResult {
|
|
56
|
+
success: boolean;
|
|
57
|
+
workbook?: Workbook;
|
|
58
|
+
errors?: string[];
|
|
59
|
+
warnings?: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Workbook execution events
|
|
63
|
+
*/
|
|
64
|
+
export interface WorkbookEvent {
|
|
65
|
+
type: 'cell:start' | 'cell:success' | 'cell:error' | 'cell:stale' | 'workbook:complete';
|
|
66
|
+
cellId?: string;
|
|
67
|
+
output?: unknown;
|
|
68
|
+
error?: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Result of executing a single cell in a run report.
|
|
73
|
+
*/
|
|
74
|
+
export interface CellResult {
|
|
75
|
+
id: string;
|
|
76
|
+
type: CellType;
|
|
77
|
+
status: 'success' | 'error' | 'pass' | 'fail';
|
|
78
|
+
output?: unknown;
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Aggregated result of running an entire workbook (continue-on-error).
|
|
83
|
+
*/
|
|
84
|
+
export interface RunResult {
|
|
85
|
+
cells: CellResult[];
|
|
86
|
+
ok: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Dependency graph node
|
|
90
|
+
*/
|
|
91
|
+
export interface DependencyNode {
|
|
92
|
+
id: string;
|
|
93
|
+
dependencies: string[];
|
|
94
|
+
dependents: string[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Dependency graph
|
|
98
|
+
*/
|
|
99
|
+
export interface DependencyGraph {
|
|
100
|
+
nodes: Map<string, DependencyNode>;
|
|
101
|
+
executionOrder: string[];
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,MAAM,GACN,QAAQ,GACR,UAAU,GACV,eAAe,GACf,MAAM,GACN,MAAM,GACN,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAA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|
+
* Shared message/result shapes between `timeout-runner.ts` (the coordinator,
|
|
3
|
+
* running on the caller's thread) and `run-worker.ts` (the `worker_threads`
|
|
4
|
+
* entry point that actually executes the workbook). Kept in its own module so
|
|
5
|
+
* neither side needs to import the other's runtime code — the worker script
|
|
6
|
+
* stays a minimal, independently loadable entry point.
|
|
7
|
+
*
|
|
8
|
+
* Cell outputs are pre-formatted to strings (via `formatResult`) before they
|
|
9
|
+
* cross the worker boundary: `postMessage` uses the structured-clone
|
|
10
|
+
* algorithm, which cannot faithfully reproduce engine class instances
|
|
11
|
+
* (Complex, matrices, BigNumber, …) — it either drops their prototype or
|
|
12
|
+
* throws. Formatting to a string in the worker (the same rendering every
|
|
13
|
+
* other report consumer already uses) sidesteps that entirely.
|
|
14
|
+
*/
|
|
15
|
+
import type { CellResult } from './types.js';
|
|
16
|
+
/** A `CellResult` with its output pre-formatted to a string (or absent). */
|
|
17
|
+
export interface SerializedCellResult {
|
|
18
|
+
id: string;
|
|
19
|
+
type: CellResult['type'];
|
|
20
|
+
status: CellResult['status'];
|
|
21
|
+
output?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
/** A `RunResult` whose cells are `SerializedCellResult`s. */
|
|
25
|
+
export interface SerializedRunResult {
|
|
26
|
+
cells: SerializedCellResult[];
|
|
27
|
+
ok: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface WorkerSuccessMessage {
|
|
30
|
+
ok: true;
|
|
31
|
+
report: SerializedRunResult;
|
|
32
|
+
}
|
|
33
|
+
export interface WorkerFailureMessage {
|
|
34
|
+
ok: false;
|
|
35
|
+
error: string;
|
|
36
|
+
}
|
|
37
|
+
/** The single message a worker posts back before exiting. */
|
|
38
|
+
export type WorkerMessage = WorkerSuccessMessage | WorkerFailureMessage;
|
|
39
|
+
/** `workerData` passed to `run-worker.ts` when it is spawned. */
|
|
40
|
+
export interface RunWorkerData {
|
|
41
|
+
/** Raw `.mtsw` source (YAML) — the worker parses it itself. */
|
|
42
|
+
source: string;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=worker-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-protocol.d.ts","sourceRoot":"","sources":["../src/worker-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,4EAA4E;AAC5E,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,6DAA6D;AAC7D,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,EAAE,CAAC;IAC9B,EAAE,EAAE,OAAO,CAAC;CACb;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,IAAI,CAAC;IACT,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;CACf;AAED,6DAA6D;AAC7D,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAExE,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardened YAML parsing shared by the workbook parser (document load) and the
|
|
3
|
+
* executor (data-cell payloads). Centralizing it keeps the two YAML entry
|
|
4
|
+
* points consistent: core schema only (no YAML 1.1 / custom-tag surprises),
|
|
5
|
+
* merge keys disabled, library warnings silenced, plus a prototype-pollution
|
|
6
|
+
* guard.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Parse YAML with the hardened schema options (core schema, no merge keys).
|
|
10
|
+
* Does **not** walk the result for pollution keys — callers that want
|
|
11
|
+
* structured errors (the document parser) use {@link findPollutionKeys};
|
|
12
|
+
* callers that should fail closed use {@link parseYamlSafe}.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseYamlHardened(content: string): unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Parse YAML with hardened options and reject prototype-pollution keys.
|
|
17
|
+
* Use this at CLI / executor entry points that should throw rather than
|
|
18
|
+
* collect structured errors.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseYamlSafe(content: string): unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Collect every prototype-pollution key found anywhere in a parsed value.
|
|
23
|
+
* Only traverses plain objects and arrays (never class instances / built-in
|
|
24
|
+
* prototypes); a `seen` set guards against alias cycles.
|
|
25
|
+
*
|
|
26
|
+
* Also flags an object whose [[Prototype]] is neither `Object.prototype`
|
|
27
|
+
* nor `null` — that is the shape of `obj['__proto__'] = payload`, which
|
|
28
|
+
* does not create an own `__proto__` property for `getOwnPropertyNames`
|
|
29
|
+
* to find.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findPollutionKeys(value: unknown, seen?: WeakSet<object>, found?: string[]): string[];
|
|
32
|
+
/** Throw if a parsed value contains any prototype-pollution key. */
|
|
33
|
+
export declare function assertNoPollution(value: unknown): void;
|
|
34
|
+
//# sourceMappingURL=yaml-safe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-safe.d.ts","sourceRoot":"","sources":["../src/yaml-safe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAItD;AAMD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,OAAO,CAAC,MAAM,CAAiB,EACrC,KAAK,GAAE,MAAM,EAAO,GACnB,MAAM,EAAE,CAuBV;AAED,oEAAoE;AACpE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAKtD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-workbook",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Scientific workbook runtime for MathTS (.mtsw format)",
|
|
5
5
|
"author": "Daniel Simon Jr.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,29 +22,29 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
25
|
+
"build": "tsup && tsc -p tsconfig.dts.json",
|
|
26
26
|
"dev": "tsup --watch",
|
|
27
|
-
"test": "
|
|
27
|
+
"test": "bun test --isolate --timeout 30000",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
|
-
"test:coverage": "
|
|
29
|
+
"test:coverage": "bun test --isolate --timeout 30000 --coverage",
|
|
30
30
|
"typecheck": "tsc --noEmit",
|
|
31
|
-
"lint": "
|
|
32
|
-
"lint:fix": "
|
|
31
|
+
"lint": "oxlint src",
|
|
32
|
+
"lint:fix": "oxlint src --fix",
|
|
33
33
|
"clean": "rm -rf dist",
|
|
34
34
|
"build:prod": "tsup --minify --treeshake"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@danielsimonjr/mathts-core": "^0.
|
|
38
|
-
"@danielsimonjr/mathts-expression": "^0.
|
|
39
|
-
"@danielsimonjr/mathts-functions": "^0.64.
|
|
40
|
-
"@danielsimonjr/mathts-plot": "^0.4.
|
|
37
|
+
"@danielsimonjr/mathts-core": "^0.15.0",
|
|
38
|
+
"@danielsimonjr/mathts-expression": "^0.8.0",
|
|
39
|
+
"@danielsimonjr/mathts-functions": "^0.64.1",
|
|
40
|
+
"@danielsimonjr/mathts-plot": "^0.4.3",
|
|
41
41
|
"yaml": "^2.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/node": "^26.
|
|
44
|
+
"@types/node": "^26.4.0",
|
|
45
45
|
"tsup": "^8.0.0",
|
|
46
|
-
"typescript": "^
|
|
47
|
-
"vitest": "^
|
|
46
|
+
"typescript": "^7.0.2",
|
|
47
|
+
"vitest": "^5.0.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|