@sheetxl/scripting 0.7.28-beta.4 → 0.8.0-beta.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.
Files changed (72) hide show
  1. package/README.md +3 -3
  2. package/browser/cjs/B6RS19boKbA_QGQ6.cjs +2 -0
  3. package/browser/cjs/Bn3oEXST6uP5oPU2.cjs +1 -0
  4. package/browser/cjs/C83wXnFq94exmYt9.cjs +1 -0
  5. package/browser/cjs/C94szTiUbmNQa9FD.cjs +1 -0
  6. package/browser/cjs/CUd5aIyyU3_3B_V1.cjs +29 -0
  7. package/browser/cjs/D5np5QScDyDDD_WJ.cjs +1 -0
  8. package/browser/cjs/DLi7EA_dfez5uwwY.cjs +1 -0
  9. package/browser/cjs/DZAweI0sdBfrHzAk.cjs +3747 -0
  10. package/browser/cjs/DcxyEv9XIOa5qfCm.cjs +1 -0
  11. package/browser/cjs/ZKJrH74dcPwEAgmF.cjs +7 -0
  12. package/browser/cjs/index.cjs +1 -1
  13. package/browser/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
  14. package/browser/esm/B73J41HhbJvswDz1.mjs +17 -0
  15. package/browser/esm/BXhWTnlrRShaRGS5.mjs +581 -0
  16. package/browser/esm/B_2CC0NvNtPBw_ad.mjs +22 -0
  17. package/browser/esm/BxiAkxNyUQseLNBv.mjs +10 -0
  18. package/browser/esm/D9jTpNifykCuQkTL.mjs +18 -0
  19. package/browser/esm/DP3uAaeZa0hNHrYJ.mjs +3818 -0
  20. package/browser/esm/NpFv8YNKRgVPGXOq.mjs +9 -0
  21. package/browser/esm/SXQ4A1qlBB6JRAEQ.mjs +23 -0
  22. package/browser/esm/index.mjs +71 -41
  23. package/browser/esm/zGQXHcrpOlM4m6Nn.mjs +197 -0
  24. package/node/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
  25. package/node/esm/BRuHQvNZfkRtcqXr.mjs +196 -0
  26. package/node/esm/CZo429AzOkBwGTWk.mjs +23 -0
  27. package/node/esm/ClxOMp6IdEZdW4Qd.mjs +8 -0
  28. package/node/esm/D0CDObJV23Rxk8-r.mjs +15 -0
  29. package/node/esm/DyZ4_kNN_urjQyjU.mjs +20 -0
  30. package/node/esm/byRhqE863Yd8YyB5.mjs +581 -0
  31. package/node/esm/index.mjs +83 -141
  32. package/node/esm/og3Pk2ReS3UiORbF.mjs +21 -0
  33. package/package.json +3 -3
  34. package/types/src/compiler/insertRunGuard.d.ts +11 -0
  35. package/types/src/compiler/relaxForRun.d.ts +8 -0
  36. package/types/src/lib/typescript/typescript.browser.d.ts +6 -0
  37. package/types/src/lib/typescript/typescript.node.d.ts +11 -0
  38. package/types/src/linter/Linter.d.ts +7 -0
  39. package/types/src/runtime/RunGuard.d.ts +31 -0
  40. package/types/src/runtime/index.d.ts +1 -0
  41. package/types/src/type/CompileOptions.d.ts +47 -0
  42. package/types/src/type/CompiledModule.d.ts +36 -6
  43. package/types/src/type/Diagnostic.d.ts +25 -1
  44. package/types/src/type/Types.d.ts +43 -3
  45. package/browser/cjs/1_xhnTjP6m5oj6za.cjs +0 -21
  46. package/browser/cjs/B_2b6uA3WKl7970Q.cjs +0 -1
  47. package/browser/cjs/Bu4cZ8iSZ3rij-oV.cjs +0 -1
  48. package/browser/cjs/BvG8N7G_8CXIAlT-.cjs +0 -1
  49. package/browser/cjs/BwpBc8k-Fp1SAn7l.cjs +0 -1
  50. package/browser/cjs/C_7w8EJZpHw8ueuq.cjs +0 -1
  51. package/browser/cjs/C_IEgjM-hSJCv6Gm.cjs +0 -1
  52. package/browser/cjs/CctaCN_w3o34V9AR.cjs +0 -1
  53. package/browser/cjs/DSEShe7kGtxvljOr.cjs +0 -1
  54. package/browser/cjs/qWYyYsBboXc9p0Lw.cjs +0 -7
  55. package/browser/esm/80oYnILw-_ixsNjP.mjs +0 -15
  56. package/browser/esm/BIKWt7VvnYQGipn8.mjs +0 -87
  57. package/browser/esm/BvzriDVNz7rvv-CN.mjs +0 -12
  58. package/browser/esm/BzbjwP47XqWR_dLy.mjs +0 -421
  59. package/browser/esm/CDBoNa-_uINySbpK.mjs +0 -152
  60. package/browser/esm/CUE7cb3UPOJM-3kD.mjs +0 -25
  61. package/browser/esm/DQW5CKiti4COASaz.mjs +0 -23
  62. package/browser/esm/NC0vOHwL24BJSQ_l.mjs +0 -27
  63. package/browser/esm/boW6I_VE4ZlDrs3P.mjs +0 -8
  64. package/browser/esm/iMHa0nIFHsIvws4V.mjs +0 -105
  65. package/node/esm/BHErJ0QgPjNC4lWi.mjs +0 -152
  66. package/node/esm/BOT12k_HrUajuNNO.mjs +0 -12
  67. package/node/esm/CUJYmJq64kAxqquM.mjs +0 -421
  68. package/node/esm/Dyqi5Bjd6JfFkMrp.mjs +0 -17
  69. package/node/esm/GDpQxq3gDBro-Loq.mjs +0 -27
  70. package/node/esm/VR8Qx9rC5rrXqlNV.mjs +0 -23
  71. package/node/esm/bmKxP3gmEczTpaFo.mjs +0 -14
  72. package/node/esm/boW6I_VE4ZlDrs3P.mjs +0 -8
@@ -1,145 +1,87 @@
1
- /**
2
- * @license @sheetxl/scripting - Scripting - Scripting engine for Macros and formulas; includes TypeScript and EsBuild. - v0.7.28-beta.4
3
- *
4
- * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
- * License: The license can be found at https://www.sheetxl.com/license.
6
- */
7
- import { CommonUtils as e } from "@sheetxl/utils";
8
- var t = Object.defineProperty, n = (e, n) => {
9
- let r = {};
10
- for (var i in e) t(r, i, {
11
- get: e[i],
12
- enumerable: !0
13
- });
14
- return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
15
- }, r = Object.freeze({
16
- NoBody: "SXL1001",
17
- Anonymous: "SXL1002",
18
- ParseError: "SXL1003",
19
- InvalidParamType: "SXL2001",
20
- InvalidReturnType: "SXL2002",
21
- UndefinedInput: "SXL2003",
22
- MissingType: "SXL2004",
23
- UntypedArray: "SXL2005",
24
- GenericArity: "SXL2006",
25
- MultipleModifiers: "SXL2007",
26
- ContextNotFirst: "SXL2010",
27
- MultipleLambda: "SXL2020",
28
- LambdaNotLast: "SXL2021",
29
- LambdaScalarMismatch: "SXL2022",
30
- LambdaReturn: "SXL2023",
31
- FunctionReturn: "SXL2024",
32
- LambdaArity: "SXL2025",
33
- ArrayDepth: "SXL2030",
34
- RepeatingPosition: "SXL2040",
35
- MultipleRepeating: "SXL2041",
36
- RepeatingSlots: "SXL2042",
37
- RepeatingOptional: "SXL2043",
38
- NoExports: "SXL3001",
39
- UnknownParam: "SXL3002",
40
- BuiltInName: "SXL3003",
41
- MissingSummary: "SXL9001",
42
- MissingParamDescription: "SXL9002",
43
- MissingReturns: "SXL9003"
44
- }), i = [
45
- {
46
- name: "summary",
47
- group: "sheetxl",
48
- description: "Short description shown in function tooltips and autocomplete."
49
- },
50
- {
51
- name: "param",
52
- group: "jsdoc",
53
- description: "Document a parameter. A string union type becomes a dropdown of allowed options.",
54
- snippet: "param ${1:name} ${2:description}"
55
- },
56
- {
57
- name: "returns",
58
- aliases: ["return"],
59
- group: "jsdoc",
60
- description: "Describe the return value."
61
- },
62
- {
63
- name: "category",
64
- group: "sheetxl",
65
- description: "Group the function under a category in the function list.",
66
- snippet: "category ${1:name}"
67
- },
68
- {
69
- name: "name",
70
- group: "sheetxl",
71
- description: "Override the displayed function name.",
72
- snippet: "name ${1:NAME}"
73
- },
74
- {
75
- name: "description",
76
- group: "sheetxl",
77
- description: "A longer description of the function."
78
- },
79
- {
80
- name: "deprecated",
81
- group: "sheetxl",
82
- standalone: !0,
83
- description: "Mark the function as deprecated (optionally with a reason)."
84
- },
85
- {
86
- name: "hidden",
87
- group: "sheetxl",
88
- standalone: !0,
89
- description: "Hide the function from the function list."
90
- },
91
- {
92
- name: "example",
93
- group: "jsdoc",
94
- description: "Provide a usage example."
95
- },
96
- {
97
- name: "see",
98
- group: "jsdoc",
99
- description: "Reference a related function or link."
100
- }
101
- ], a = (() => {
102
- let e = /* @__PURE__ */ new Map();
103
- for (let t of i) if (e.set(t.name, t), t.aliases) for (let n of t.aliases) e.set(n, t);
104
- return e;
1
+ import { CommonUtils as f } from "@sheetxl/utils";
2
+ var c = Object.defineProperty, p = (e, n) => {
3
+ let t = {};
4
+ for (var i in e) c(t, i, { get: e[i], enumerable: !0 });
5
+ return n || c(t, Symbol.toStringTag, { value: "Module" }), t;
6
+ }, x = Object.freeze({ NoBody: "SXL1001", Anonymous: "SXL1002", ParseError: "SXL1003", InvalidParamType: "SXL2001", InvalidReturnType: "SXL2002", UndefinedInput: "SXL2003", MissingType: "SXL2004", UntypedArray: "SXL2005", GenericArity: "SXL2006", MultipleModifiers: "SXL2007", ContextNotFirst: "SXL2010", MultipleLambda: "SXL2020", LambdaNotLast: "SXL2021", LambdaScalarMismatch: "SXL2022", LambdaReturn: "SXL2023", FunctionReturn: "SXL2024", LambdaArity: "SXL2025", ArrayDepth: "SXL2030", RepeatingPosition: "SXL2040", MultipleRepeating: "SXL2041", RepeatingSlots: "SXL2042", RepeatingOptional: "SXL2043", RepeatingMax: "SXL2044", EnumMixed: "SXL2050", EnumMemberNotConstant: "SXL2051", EnumNotLocal: "SXL2052", EnumMissingAlias: "SXL2053", EnumPosition: "SXL2054", EnumOmittedValue: "SXL2055", NoExports: "SXL3001", UnknownParam: "SXL3002", BuiltInName: "SXL3003", UnknownReturnKind: "SXL3005", InvalidName: "SXL3006", DuplicateName: "SXL3007", MissingSummary: "SXL9001", MissingParamDescription: "SXL9002", MissingReturns: "SXL9003", EnumDuplicateValue: "SXL9004", EnumMemberUndocumented: "SXL9005" }), L = [{ name: "param", group: "jsdoc", description: "Document a parameter. A string union type becomes a dropdown of allowed options.", snippet: "param ${1:name} ${2:description}" }, { name: "returns", aliases: ["return"], group: "jsdoc", description: "Describe the return value." }, { name: "category", group: "sheetxl", description: "Group the function under a category in the function list.", snippet: "category ${1:name}" }, { name: "name", group: "sheetxl", description: "A name an identifier cannot spell: the name formulas call a function by (MY.FUNC), or an enum member's label.", snippet: "name ${1:NAME}" }, { name: "description", group: "sheetxl", description: "A longer description of the function." }, { name: "deprecated", group: "sheetxl", standalone: !0, description: "Mark the function as deprecated (optionally with a reason)." }, { name: "hidden", group: "sheetxl", standalone: !0, description: "Hide the function from the function list." }, { name: "returnkind", group: "sheetxl", description: "Declare the value kind of the return (a ValueKind word, e.g. `number`, `array`, `reference`) where the type spelling cannot say it (a union return collapses to any).", snippet: "returnKind ${1:number}" }, { name: "example", group: "jsdoc", description: "Provide a usage example." }, { name: "see", group: "jsdoc", description: "Reference a related function or link." }], S = (() => {
7
+ const e = /* @__PURE__ */ new Map();
8
+ for (const n of L) if (e.set(n.name, n), n.aliases) for (const t of n.aliases) e.set(t, n);
9
+ return e;
105
10
  })();
106
- function o(e) {
107
- return !0 === function(e) {
108
- if (!e) return;
109
- let t = (e.startsWith("@") ? e.slice(1) : e).toLowerCase();
110
- return a.get(t);
111
- }(e)?.standalone;
11
+ function v(e) {
12
+ return (function(n) {
13
+ if (!n) return;
14
+ const t = (n.startsWith("@") ? n.slice(1) : n).toLowerCase();
15
+ return S.get(t);
16
+ })(e)?.standalone === !0;
112
17
  }
113
- var s = n({ GLOBAL_CONTEXT_VARIABLE: () => c }), c = "__SHEETXL";
114
- async function l(e, t) {
115
- let { loadCompiledModule: n } = await import("./Dyqi5Bjd6JfFkMrp.mjs");
116
- return n(e, t);
18
+ var N = p({ GLOBAL_CONTEXT_VARIABLE: () => X }), X = "__SHEETXL", A = p({ RUN_INTERRUPTED: () => l, abort: () => w, check: () => h, isInterrupted: () => b, release: () => M }), a = /* @__PURE__ */ new Map(), g = 256, y = 16, l = "RunInterrupted";
19
+ function d(e) {
20
+ const n = new Error(e);
21
+ return n.name = l, n;
117
22
  }
118
- var u = null, d = null, f = null, p = null;
119
- async function m() {
120
- return p ||= (async () => (await import("./bmKxP3gmEczTpaFo.mjs")).initialize())(), p;
23
+ function m(e) {
24
+ let n = a.get(e);
25
+ if (!n) {
26
+ if (a.size >= g) {
27
+ const t = a.keys().next().value;
28
+ t !== void 0 && a.delete(t);
29
+ }
30
+ n = { started: Date.now(), calls: 0, stopped: null }, a.set(e, n);
31
+ }
32
+ return n;
121
33
  }
122
- var h = Object.freeze({
123
- compile: async function(t) {
124
- if (!t?.source) return {
125
- module: null,
126
- diagnostics: []
127
- };
128
- if (d && e.deepEqual(d, t)) return u;
129
- let n = await (await async function() {
130
- if (f) return f;
131
- let { TypeScriptCompiler: e } = await import("./GDpQxq3gDBro-Loq.mjs");
132
- return f = new e();
133
- }()).compileModule(t);
134
- return u = n, d = t, n;
135
- },
136
- lint: async function(e, t) {
137
- if (!e) return [];
138
- let [n, { lintScript: r }] = await Promise.all([m(), import("./CUJYmJq64kAxqquM.mjs")]);
139
- return r(n, e, t);
140
- },
141
- cleanup: function() {
142
- f && (f.terminate(), f = null, u = null);
143
- }
144
- });
145
- export { s as Constants, r as DiagnosticCode, i as DocTags, h as ScriptCompiler, l as loadCompiledModule, o as n, c as t };
34
+ function h(e, n) {
35
+ const t = m(e);
36
+ if (t.stopped) throw t.stopped;
37
+ if (++t.calls % y === 0 && Date.now() - t.started > n) throw t.stopped = d(`Run stopped: it exceeded the ${Math.round(n / 1e3)} s time limit.`), t.stopped;
38
+ }
39
+ function w(e, n = "Run cancelled.") {
40
+ m(e).stopped = d(n);
41
+ }
42
+ function M(e) {
43
+ a.delete(e);
44
+ }
45
+ function b(e) {
46
+ return e?.name === l;
47
+ }
48
+ async function C(e, n) {
49
+ const { loadCompiledModule: t } = await import("./D0CDObJV23Rxk8-r.mjs");
50
+ return t(e, n);
51
+ }
52
+ var s = null, u = null, r = null, o = null;
53
+ async function E() {
54
+ return o || (o = (async () => {
55
+ const e = await (await import("./og3Pk2ReS3UiORbF.mjs")).initialize();
56
+ if (!e) throw new Error("TypeScript could not be loaded. Check your connection and try again.");
57
+ return e;
58
+ })()).catch(() => {
59
+ o = null;
60
+ }), o;
61
+ }
62
+ var D = Object.freeze({ compile: async function(e) {
63
+ if (!e?.source) return { module: null, diagnostics: [] };
64
+ if (u && f.deepEqual(u, e)) return s;
65
+ const n = await (await (async function() {
66
+ if (r) return r;
67
+ const { TypeScriptCompiler: t } = await import("./CZo429AzOkBwGTWk.mjs");
68
+ return r = new t();
69
+ })()).compileModule(e);
70
+ return s = n, u = e, n;
71
+ }, lint: async function(e, n) {
72
+ if (!e) return [];
73
+ const [t, { lintScript: i }] = await Promise.all([E(), import("./byRhqE863Yd8YyB5.mjs")]);
74
+ return i(t, e, n);
75
+ }, cleanup: function() {
76
+ r && (r.terminate(), r = null, s = null);
77
+ } });
78
+ export {
79
+ N as Constants,
80
+ x as DiagnosticCode,
81
+ L as DocTags,
82
+ A as RunGuard,
83
+ D as ScriptCompiler,
84
+ C as loadCompiledModule,
85
+ v as n,
86
+ X as t
87
+ };
@@ -0,0 +1,21 @@
1
+ import { readFileSync as e } from "node:fs";
2
+ import { dirname as o, join as a } from "node:path";
3
+ async function l() {
4
+ try {
5
+ return await import("typescript");
6
+ } catch (r) {
7
+ throw console.error("Error initializing Node TypeScript module:", r), r;
8
+ }
9
+ }
10
+ function s(r, t) {
11
+ const i = o(r.getDefaultLibFilePath({}));
12
+ try {
13
+ return e(a(i, t), "utf8");
14
+ } catch {
15
+ return;
16
+ }
17
+ }
18
+ export {
19
+ l as initialize,
20
+ s as readLibFile
21
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/scripting",
3
3
  "description": "Scripting - Scripting engine for Macros and formulas; includes TypeScript and EsBuild.",
4
- "version": "0.7.28-beta.4",
4
+ "version": "0.8.0-beta.2",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -40,8 +40,8 @@
40
40
  "scripting"
41
41
  ],
42
42
  "dependencies": {
43
- "@sheetxl/primitives": "^0.7.28-beta.4",
44
- "@sheetxl/utils": "^0.7.28-beta.4"
43
+ "@sheetxl/primitives": "^0.8.0-beta.2",
44
+ "@sheetxl/utils": "^0.8.0-beta.2"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "esbuild-wasm": ">=0.25.7",
@@ -0,0 +1,11 @@
1
+ import { default as ts } from 'typescript';
2
+ /**
3
+ * An emit transformer that puts `__SHEETXL.checkRun?.(key, timeoutMs)` at the top of every loop body
4
+ * and every function body, so a runaway run can be stopped from inside (see `RunGuard`).
5
+ *
6
+ * @remarks
7
+ * Loops are what run away; function bodies cover recursion. An arrow's expression body becomes a
8
+ * block that checks and returns. A directive prologue (`'use strict'`) stays first.
9
+ */
10
+ export declare function createRunGuardTransformer(ts: typeof import('typescript'), key: string, timeoutMs: number): ts.TransformerFactory<ts.SourceFile>;
11
+ //# sourceMappingURL=insertRunGuard.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { default as ts } from 'typescript';
2
+ import { Diagnostic } from '../type';
3
+ /**
4
+ * The diagnostics of a `lenient` compile ({@link CompileOptions.lenient}): what cannot fail at run
5
+ * time is a warning, and a missing annotation is not reported.
6
+ */
7
+ export declare function relaxForRun(tsm: typeof ts, sourceFile: ts.SourceFile, diagnostics: Diagnostic[]): Diagnostic[];
8
+ //# sourceMappingURL=relaxForRun.d.ts.map
@@ -1,4 +1,10 @@
1
1
  type TypeScriptModule = typeof import('typescript');
2
2
  export declare function initialize(): Promise<TypeScriptModule>;
3
+ /**
4
+ * The browser has no copy of TypeScript's library declarations, so a type-checking compile cannot
5
+ * run here; the editor's own language worker covers semantic checking interactively. Always
6
+ * `undefined` — see the node half for the contract.
7
+ */
8
+ export declare function readLibFile(_ts: TypeScriptModule, _fileName: string): string | undefined;
3
9
  export {};
4
10
  //# sourceMappingURL=typescript.browser.d.ts.map
@@ -1,4 +1,15 @@
1
1
  type TypeScriptModule = typeof import('typescript');
2
2
  export declare function initialize(): Promise<TypeScriptModule>;
3
+ /**
4
+ * Reads one of TypeScript's own library declaration files (`lib.es2020.d.ts`, ...) from the
5
+ * installed package, or `undefined` when there is no such file.
6
+ *
7
+ * @remarks
8
+ * Synchronous because a compiler host's `readFile` is. Under Node the libs sit beside the module
9
+ * on disk, so a type-checking compile can resolve `lib` references the way `tsc` does; the browser
10
+ * half of this conditional export has no such directory and answers `undefined`, which is how the
11
+ * compiler learns that semantic checking is unavailable there.
12
+ */
13
+ export declare function readLibFile(ts: TypeScriptModule, fileName: string): string | undefined;
3
14
  export {};
4
15
  //# sourceMappingURL=typescript.node.d.ts.map
@@ -31,6 +31,13 @@ export interface AnalyzeOptions {
31
31
  * case-insensitively.
32
32
  */
33
33
  builtInNames?: readonly string[];
34
+ /** Whether the source is the built-in library - see `CompileOptions.isBuiltIn`. */
35
+ isBuiltIn?: boolean;
36
+ /**
37
+ * Code that runs once - see `CompileOptions.lenient`. The default export IS the entry, so its
38
+ * first parameter, left untyped, is the script context (`export default function main(ctx)`).
39
+ */
40
+ lenient?: boolean;
34
41
  }
35
42
  /**
36
43
  * Walks an already-parsed/checked source file and applies SheetXL's semantic authoring rules.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Stops a runaway run from inside its own code.
3
+ *
4
+ * @remarks
5
+ * A script runs on the host's thread, so nothing outside it can interrupt a synchronous loop. A
6
+ * compile that asks for a guard (`CompileOptions.runGuard`) inserts `check(key, timeoutMs)` at the
7
+ * top of every loop body and function body; the check throws once the run has been going longer
8
+ * than `timeoutMs`, or once {@link abort} has been called for its key.
9
+ *
10
+ * The key and the limit are compiled into the module, so any host that executes it enforces the
11
+ * limit — the MCP server in-process, the VS Code webview for an attended session — and concurrent
12
+ * runs never read each other's state. The clock starts at the first check, which is the entry
13
+ * function's own.
14
+ *
15
+ * Not covered: a single engine call that never returns, with no user loop around it.
16
+ */
17
+ /** `error.name` of what a stopped run throws. */
18
+ export declare const RUN_INTERRUPTED = "RunInterrupted";
19
+ /**
20
+ * The compiled-in check. Throws when the run keyed `key` has exceeded `timeoutMs` or was aborted.
21
+ */
22
+ export declare function check(key: string, timeoutMs: number): void;
23
+ /**
24
+ * Stops the run keyed `key` at its next check — including a run that has not reached its first one.
25
+ */
26
+ export declare function abort(key: string, reason?: string): void;
27
+ /** Forgets a finished run. */
28
+ export declare function release(key: string): void;
29
+ /** True when `error` is what {@link check} throws. */
30
+ export declare function isInterrupted(error: unknown): boolean;
31
+ //# sourceMappingURL=RunGuard.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export * as Constants from './Constants';
2
+ export * as RunGuard from './RunGuard';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -38,6 +38,53 @@ export interface CompileOptions {
38
38
  * without a position. Compared case-insensitively.
39
39
  */
40
40
  builtInNames?: readonly string[];
41
+ /**
42
+ * Whether the source IS the built-in library rather than a script written against it.
43
+ *
44
+ * @remarks
45
+ * A built-in name is resolved before a formula reads it any other way, so it may take a name
46
+ * that is refused to a user function - `LOG10`, which also reads as a cell address.
47
+ */
48
+ isBuiltIn?: boolean;
49
+ /**
50
+ * The ambient declarations the script is written against — the shipped `scripting.d.ts`.
51
+ *
52
+ * @remarks
53
+ * Supplied, the compile type-checks the script against that surface and reports what TypeScript
54
+ * finds: a member the receiver does not have (with TypeScript's own "did you mean"), a wrong
55
+ * argument, an unknown name. Omitted, the compile reports syntax and authoring rules only. The
56
+ * check also needs TypeScript's own libs, which only Node has on disk; a browser compile ignores
57
+ * this option and leaves semantic checking to the editor's language worker.
58
+ */
59
+ ambientTypes?: string;
60
+ /**
61
+ * Compile in a stop check, for a host running agent-written code on its own thread.
62
+ *
63
+ * @remarks
64
+ * Every loop body and function body calls `RunGuard.check(key, timeoutMs)`, which throws once the
65
+ * run has gone on longer than `timeoutMs` or `RunGuard.abort(key)` was called. `key` identifies
66
+ * this compile's run, so give each run its own. Omitted, the module carries no checks.
67
+ */
68
+ runGuard?: {
69
+ key: string;
70
+ timeoutMs: number;
71
+ };
72
+ /**
73
+ * Check the source as code that runs once, not as code kept to be run again.
74
+ *
75
+ * @remarks
76
+ * For an agent's ad hoc run. Only a finding that would fail at run time stops the run; the rest
77
+ * are reported as warnings:
78
+ *
79
+ * - Annotations are not required: an untyped parameter is `any` (no `noImplicitAny`), and a
80
+ * missing type on an entry is not reported.
81
+ * - A member the receiver does not have, read where a missing member is expected - `r.getFormat?.()`,
82
+ * `r.getFormulas ? … : …`, `typeof r.x` - is a probe, and a warning: it reads `undefined`.
83
+ * - A condition on a function that is never called (TS2774) is a warning.
84
+ *
85
+ * Only meaningful with {@link ambientTypes}; without them there is no semantic check to relax.
86
+ */
87
+ lenient?: boolean;
41
88
  }
42
89
  /**
43
90
  * The result of a compile operation: the compiled artifact plus this compile's positioned
@@ -16,9 +16,11 @@ export interface CompiledModule {
16
16
  * An array of `Declaration` and `Description pairs describing the functions within the script.
17
17
  *
18
18
  * @remarks
19
- * This array can be empty. It is possible that a script might contain only comments or other non-executable code.
19
+ * Absent when the module declares none — a script of only comments, or source in a language
20
+ * SheetXL does not execute. An empty array means the same thing and is accepted, but is not
21
+ * written: it is a row of nothing in every persisted workbook that imported a macro file.
20
22
  */
21
- functions: [IFunction.DeclarationJSON, IFunction.DescriptorJSON][];
23
+ functions?: [IFunction.DeclarationJSON, IFunction.DescriptorJSON][];
22
24
  /**
23
25
  * The human-readable source code of the script.
24
26
  *
@@ -37,6 +39,26 @@ export interface CompiledModule {
37
39
  * If provided this will include a source map for the compiled script.
38
40
  */
39
41
  sourceMap?: string;
42
+ /**
43
+ * Text that belongs to {@link CompiledModule.source} in its original format but is not source
44
+ * anyone reads or edits.
45
+ *
46
+ * @remarks
47
+ * VBA is why this exists: every module begins with a hidden `Attribute VB_*` block that the VBA
48
+ * editor never shows, and for a document module nobody has written in, that block is the ENTIRE
49
+ * content. Leaving it in `source` means the model claims a module has source when it has none,
50
+ * and every reader — an agent, an editor, a line count — has to know to strip it first.
51
+ *
52
+ * Kept rather than discarded because it cannot be derived on the way back out: `VB_Base` names
53
+ * an interface GUID and `VB_PredeclaredId`/`VB_Exposed` are per-module settings. This is
54
+ * interop residue, in the same sense as the workbook's `fileVersion` — carried, never
55
+ * synthesized.
56
+ *
57
+ * If a second kind of residue ever appears, this and {@link CompiledModule.sourceMap} are the
58
+ * two candidates for folding into one language-agnostic `meta` bag. One field for one known
59
+ * thing until then.
60
+ */
61
+ sourceHeader?: string;
40
62
  /**
41
63
  * The language the function is written in.
42
64
  *
@@ -44,9 +66,18 @@ export interface CompiledModule {
44
66
  */
45
67
  language?: string;
46
68
  /**
47
- * The name of the module.
69
+ * What the module is bound to, for the one case its location cannot say.
70
+ *
71
+ * - `'workbook'` — owned by the workbook itself. Its functions are NOT in the formula namespace.
72
+ * - absent — global. Its functions are.
73
+ *
74
+ * @remarks
75
+ * There is deliberately no sheet value here. A sheet's modules are stored BY the sheet
76
+ * (`ISheet.JSON.modules`), so nothing has to name it and a module cannot be left behind pointing
77
+ * at a sheet that no longer exists. This field exists only because a workbook holds both its
78
+ * global modules and its own in one collection, which is the single case nesting cannot express.
48
79
  */
49
- name?: string;
80
+ scope?: 'workbook';
50
81
  /**
51
82
  * A unique identifier for the function (e.g., a Git commit ID).
52
83
  * // https://stackoverflow.com/questions/29106996/what-is-a-git-commit-id
@@ -63,8 +94,7 @@ export interface CompiledModule {
63
94
  *
64
95
  * TODO - this doesn't belong here.
65
96
  * Create a new interface for session state.
66
- * TODO - rename to sessionData
67
97
  */
68
- scope?: any;
98
+ sessionData?: any;
69
99
  }
70
100
  //# sourceMappingURL=CompiledModule.d.ts.map
@@ -96,13 +96,33 @@ export declare const DiagnosticCode: Readonly<{
96
96
  readonly RepeatingSlots: "SXL2042";
97
97
  /** An optional parameter/slot where a repeating group does not allow one. */
98
98
  readonly RepeatingOptional: "SXL2043";
99
+ /** `Repeating<T, Max>`'s maximum argument count is not a whole number in range. */
100
+ readonly RepeatingMax: "SXL2044";
101
+ /** An enum mixes number and string members. */
102
+ readonly EnumMixed: "SXL2050";
103
+ /** An enum member is not a constant number or string. */
104
+ readonly EnumMemberNotConstant: "SXL2051";
105
+ /** A parameter type that is not declared in this module, so an enum behind it cannot be read. */
106
+ readonly EnumNotLocal: "SXL2052";
107
+ /** An `as const` object used as a parameter type without its same-name type alias. */
108
+ readonly EnumMissingAlias: "SXL2053";
109
+ /** An enum where no single argument is coerced to it (`IRange<E>`, `Lazy<E>`). */
110
+ readonly EnumPosition: "SXL2054";
111
+ /** `Omittable<E, V>` whose `V` is neither a member of `E` nor `null`. */
112
+ readonly EnumOmittedValue: "SXL2055";
99
113
  /** No exported functions found in the module. */
100
114
  readonly NoExports: "SXL3001";
101
115
  /** A `@param` tag references a parameter that does not exist. */
102
116
  readonly UnknownParam: "SXL3002";
103
117
  /** A calculation function takes a built-in function's name. */
104
118
  readonly BuiltInName: "SXL3003";
105
- /** Missing `@summary` / function description. */
119
+ /** A `@returnKind` tag names a value kind that does not exist, or names none at all. */
120
+ readonly UnknownReturnKind: "SXL3005";
121
+ /** A calculation function's name (its `@name`, or else its own) is not a name a formula can call. */
122
+ readonly InvalidName: "SXL3006";
123
+ /** Two functions in one module register under the same name (an `@name` repeats another's). */
124
+ readonly DuplicateName: "SXL3007";
125
+ /** A function has no JSDoc description. */
106
126
  readonly MissingSummary: "SXL9001";
107
127
  /** A `@param` is missing a description. */
108
128
  readonly MissingParamDescription: "SXL9002";
@@ -112,6 +132,10 @@ export declare const DiagnosticCode: Readonly<{
112
132
  * behavior via the summary, so a standalone `@returns` warning is noise.
113
133
  */
114
134
  readonly MissingReturns: "SXL9003";
135
+ /** Two enum members share a value. */
136
+ readonly EnumDuplicateValue: "SXL9004";
137
+ /** An enum member has no doc comment. */
138
+ readonly EnumMemberUndocumented: "SXL9005";
115
139
  }>;
116
140
  /**
117
141
  * Union of the stable diagnostic code string values.
@@ -3,7 +3,7 @@ import { IFunction, ScalarType, Scalar, IFormulaContext } from '@sheetxl/primiti
3
3
  * Type for bind signature for typed functions.
4
4
  */
5
5
  export interface FunctionBinder {
6
- (mapBind: Map<string, IFunction>, getContext: () => IFormulaContext, implementations: Implementations, declarations: MinifiedDeclarations, getDynamicDescriptors?: DynamicDescriptors, defaultCategory?: string): void;
6
+ (mapBind: Map<string, IFunction>, getContext: () => IFormulaContext, implementations: Implementations, declarations: MinifiedDeclarations, getDynamicDescriptors?: DynamicDescriptors, defaultCategory?: string, enums?: MinifiedEnums): void;
7
7
  }
8
8
  /**
9
9
  * The default export of a compiled formula module (produced by the FormulaCompiler): given the
@@ -23,6 +23,8 @@ export interface MinifiedValue {
23
23
  l?: ScalarType | '*' | 'raw';
24
24
  a?: number;
25
25
  d?: number;
26
+ k?: string;
27
+ vol?: 1;
26
28
  }
27
29
  /**
28
30
  * Minified params.
@@ -30,12 +32,17 @@ export interface MinifiedValue {
30
32
  export interface MinifiedParameter extends MinifiedValue {
31
33
  n: string;
32
34
  m?: '?' | '...';
33
- e?: string[];
34
- o?: 'accept' | 'accept-ref';
35
+ e?: string;
36
+ ae?: 1;
35
37
  g?: MinifiedParameter[];
36
38
  v?: Scalar;
37
39
  u?: 1;
38
40
  w?: Scalar;
41
+ nl?: 1;
42
+ nf?: 1;
43
+ lz?: 1;
44
+ rt?: 1;
45
+ vr?: 1;
39
46
  }
40
47
  /**
41
48
  * The function declaration needed to autoMarshall and execute.
@@ -45,6 +52,7 @@ export interface MinifiedDeclaration {
45
52
  c?: boolean;
46
53
  p?: MinifiedParameter[];
47
54
  r?: MinifiedValue;
55
+ mx?: number;
48
56
  }
49
57
  /**
50
58
  * The descriptor used for a function
@@ -59,14 +67,46 @@ export interface MinifiedDescriptor {
59
67
  export type MinifiedDeclarations = {
60
68
  [name: string]: MinifiedDeclaration;
61
69
  };
70
+ /**
71
+ * Minified enum. One per declared enum, however many parameters use it.
72
+ */
73
+ export interface MinifiedEnum {
74
+ s?: 'string';
75
+ m: [name: string, value: number | string, deprecated?: string | true][];
76
+ }
77
+ /**
78
+ * A module's enums by id. An id is unique within the module that declares it, not across modules.
79
+ */
80
+ export type MinifiedEnums = {
81
+ [id: string]: MinifiedEnum;
82
+ };
62
83
  export interface Implementations {
63
84
  [functionName: string]: (...args: any) => any;
64
85
  }
65
86
  export interface MinifiedDescriptors {
66
87
  [name: string]: MinifiedDescriptor;
67
88
  }
89
+ /**
90
+ * The copy for one enum. `n` is a LOCALIZED name and appears only in a language pack: the English
91
+ * module's names are the declared ones, which the declaration already carries.
92
+ */
93
+ export interface MinifiedEnumDescriptor {
94
+ n?: string;
95
+ s?: string;
96
+ m?: Record<string, {
97
+ n?: string;
98
+ d?: string;
99
+ }>;
100
+ }
101
+ /**
102
+ * A module's enum copy by id - the descriptor-side twin of {@link MinifiedEnums}.
103
+ */
104
+ export type MinifiedEnumDescriptors = {
105
+ [id: string]: MinifiedEnumDescriptor;
106
+ };
68
107
  export interface DescriptorModule {
69
108
  default: MinifiedDescriptors;
109
+ enums?: MinifiedEnumDescriptors;
70
110
  }
71
111
  export type DynamicDescriptors = () => Promise<DescriptorModule>;
72
112
  //# sourceMappingURL=Types.d.ts.map