@sheetxl/scripting 0.8.0-beta.1 → 0.8.0-beta.3
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 +3 -3
- package/browser/cjs/B6RS19boKbA_QGQ6.cjs +2 -0
- package/browser/cjs/Bn3oEXST6uP5oPU2.cjs +1 -0
- package/browser/cjs/C83wXnFq94exmYt9.cjs +1 -0
- package/browser/cjs/C94szTiUbmNQa9FD.cjs +1 -0
- package/browser/cjs/CUd5aIyyU3_3B_V1.cjs +29 -0
- package/browser/cjs/D5np5QScDyDDD_WJ.cjs +1 -0
- package/browser/cjs/DLi7EA_dfez5uwwY.cjs +1 -0
- package/browser/cjs/DZAweI0sdBfrHzAk.cjs +3747 -0
- package/browser/cjs/DcxyEv9XIOa5qfCm.cjs +1 -0
- package/browser/cjs/ZKJrH74dcPwEAgmF.cjs +7 -0
- package/browser/cjs/index.cjs +1 -1
- package/browser/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
- package/browser/esm/B73J41HhbJvswDz1.mjs +17 -0
- package/browser/esm/BXhWTnlrRShaRGS5.mjs +581 -0
- package/browser/esm/B_2CC0NvNtPBw_ad.mjs +22 -0
- package/browser/esm/BxiAkxNyUQseLNBv.mjs +10 -0
- package/browser/esm/D9jTpNifykCuQkTL.mjs +18 -0
- package/browser/esm/DP3uAaeZa0hNHrYJ.mjs +3818 -0
- package/browser/esm/NpFv8YNKRgVPGXOq.mjs +9 -0
- package/browser/esm/SXQ4A1qlBB6JRAEQ.mjs +23 -0
- package/browser/esm/index.mjs +71 -41
- package/browser/esm/zGQXHcrpOlM4m6Nn.mjs +197 -0
- package/node/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
- package/node/esm/BRuHQvNZfkRtcqXr.mjs +196 -0
- package/node/esm/CZo429AzOkBwGTWk.mjs +23 -0
- package/node/esm/ClxOMp6IdEZdW4Qd.mjs +8 -0
- package/node/esm/D0CDObJV23Rxk8-r.mjs +15 -0
- package/node/esm/DyZ4_kNN_urjQyjU.mjs +20 -0
- package/node/esm/byRhqE863Yd8YyB5.mjs +581 -0
- package/node/esm/index.mjs +83 -148
- package/node/esm/og3Pk2ReS3UiORbF.mjs +21 -0
- package/package.json +3 -3
- package/types/src/compiler/insertRunGuard.d.ts +11 -0
- package/types/src/compiler/relaxForRun.d.ts +8 -0
- package/types/src/lib/typescript/typescript.browser.d.ts +6 -0
- package/types/src/lib/typescript/typescript.node.d.ts +11 -0
- package/types/src/linter/Linter.d.ts +20 -0
- package/types/src/runtime/RunGuard.d.ts +31 -0
- package/types/src/runtime/index.d.ts +1 -0
- package/types/src/type/CompileOptions.d.ts +47 -0
- package/types/src/type/CompiledModule.d.ts +36 -6
- package/types/src/type/Diagnostic.d.ts +25 -3
- package/types/src/type/Types.d.ts +44 -5
- package/browser/cjs/BJpcKKDPQlQbi5O5.cjs +0 -7
- package/browser/cjs/Bu4cZ8iSZ3rij-oV.cjs +0 -1
- package/browser/cjs/BvG8N7G_8CXIAlT-.cjs +0 -1
- package/browser/cjs/CY8w1D0xPdaNysFJ.cjs +0 -1
- package/browser/cjs/C_7w8EJZpHw8ueuq.cjs +0 -1
- package/browser/cjs/C_IEgjM-hSJCv6Gm.cjs +0 -1
- package/browser/cjs/CctaCN_w3o34V9AR.cjs +0 -1
- package/browser/cjs/DIf4GvYEqb4ayb6a.cjs +0 -1
- package/browser/cjs/DcNeWEf5ZqALrCr4.cjs +0 -1
- package/browser/cjs/_PKWNtAymIZGtvCb.cjs +0 -21
- package/browser/esm/1kUe1fPM50LHqYNI.mjs +0 -15
- package/browser/esm/3YV545IwjRqG3c1v.mjs +0 -27
- package/browser/esm/CFj5DZ16U361ltLj.mjs +0 -8
- package/browser/esm/CSXzDPdxAeONd9Br.mjs +0 -152
- package/browser/esm/DCIZplzRAR9pzoyD.mjs +0 -12
- package/browser/esm/DL0Hj5P777IybKK1.mjs +0 -25
- package/browser/esm/Dn3tZ47l4kfqm82M.mjs +0 -434
- package/browser/esm/Im_056DAe1M8tSZK.mjs +0 -23
- package/browser/esm/bJcM1PsEX9VZuqnT.mjs +0 -87
- package/browser/esm/v5FtHwExzUecgxho.mjs +0 -112
- package/node/esm/CFj5DZ16U361ltLj.mjs +0 -8
- package/node/esm/CL56uy8tfvhJRKYS.mjs +0 -434
- package/node/esm/CZgThiQ_9yYAaYaW.mjs +0 -152
- package/node/esm/DDDZ5Wv9-gK2v6Qt.mjs +0 -23
- package/node/esm/DEIcuGll5aCjPisP.mjs +0 -27
- package/node/esm/DOv0wuhb-kNvUT7-.mjs +0 -12
- package/node/esm/NgoqymNyfjBf3Vbn.mjs +0 -17
- package/node/esm/P5z0UPrc8__6uFCR.mjs +0 -14
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ import { ScriptCompiler } from '@sheetxl/scripting';
|
|
|
37
37
|
const { module, diagnostics } = await ScriptCompiler.compile({
|
|
38
38
|
source: `
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Calculate compound interest
|
|
41
41
|
*/
|
|
42
42
|
export function compoundInterest(
|
|
43
43
|
principal: number,
|
|
@@ -71,14 +71,14 @@ const scripts = workbook.getScripts();
|
|
|
71
71
|
const module = await scripts.createModule({
|
|
72
72
|
source: `
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Double the value
|
|
75
75
|
*/
|
|
76
76
|
export function DOUBLE(value: number): number {
|
|
77
77
|
return value * 2;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Set active cell value
|
|
82
82
|
*/
|
|
83
83
|
export function setCellValue(cell: ICell, value: any): void {
|
|
84
84
|
cell.setValue(value);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=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"}),a=[{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."}],i=(()=>{const n=new Map;for(const e of a)if(n.set(e.name,e),e.aliases)for(const t of e.aliases)n.set(t,e);return n})();function o(n){return(function(e){if(!e)return;const t=(e.startsWith("@")?e.slice(1):e).toLowerCase();return i.get(t)})(n)?.standalone===!0}Object.defineProperty(exports,"DiagnosticCode",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"DocTags",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"isStandaloneJSDocTag",{enumerable:!0,get:function(){return o}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=Object.defineProperty,o=(t,l)=>{let e={};for(var r in t)n(e,r,{get:t[r],enumerable:!0});return l||n(e,Symbol.toStringTag,{value:"Module"}),e},a=o({GLOBAL_CONTEXT_VARIABLE:()=>u}),u="__SHEETXL";Object.defineProperty(exports,"Constants_exports",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"GLOBAL_CONTEXT_VARIABLE",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"__exportAll",{enumerable:!0,get:function(){return o}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.TypeScriptCompiler=class{constructor(r={}){this.workerWrapper=null}async getWorkerWrapper(){if(this.workerWrapper)return this.workerWrapper;const{createCompilerWorker:r}=await Promise.resolve().then(()=>require("./DZAweI0sdBfrHzAk.cjs"));return this.workerWrapper=await r(),this.workerWrapper}async compileModule(r){try{return(await this.getWorkerWrapper()).execute(r)}catch(e){throw console.error("Failed to compile using worker:",e),e}}terminate(){this.workerWrapper?.terminate(),this.workerWrapper=null}};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const k=require("./C83wXnFq94exmYt9.cjs"),U=require("./Bn3oEXST6uP5oPU2.cjs"),Q=require("./ZKJrH74dcPwEAgmF.cjs"),N=require("./DLi7EA_dfez5uwwY.cjs");let J=require("@sheetxl/utils");var g=null,v=null,H={compilerOptions:{target:"esnext"}};async function Y(t,d,u="/script.js",c=k.GLOBAL_CONTEXT_VARIABLE){try{const e=await(async function(){if(g)return g;if(v){if(await v,!g)throw new Error("ESBuild initialization promise resolved, but instance is not available.");return g}let r,s;v=new Promise((i,f)=>{r=i,s=f});try{const{initialize:i}=await Promise.resolve().then(()=>require("./DcxyEv9XIOa5qfCm.cjs"));return g=await i(),r(),g}catch(i){throw console.error("Failed to import or initialize esbuild:",i),v=null,s(i),i}})(),a="@sheetxl/primitives",l=`
|
|
2
|
+
export const FormulaContext = globalThis.${c}?.FormulaContext;
|
|
3
|
+
export const ScalarType = globalThis.${c}?.ScalarType;
|
|
4
|
+
export const Observable = globalThis.${c}?.Observable;
|
|
5
|
+
export const IRange = globalThis.${c}?.IRange;
|
|
6
|
+
export const FormulaError = globalThis.${c}?.FormulaError;
|
|
7
|
+
// Add more exports as needed
|
|
8
|
+
`,o=await e.build({entryPoints:[u],bundle:!0,write:!1,format:"esm",plugins:[{name:"sheetxl-esbuild-in-memory",setup(r){const s="sheetxl-"+new Date().getTime();r.onResolve({filter:new RegExp(`^(${u.replace("/","\\/")}|${a})$`)},i=>({path:i.path,namespace:s})),r.onResolve({filter:/.*/},i=>{if(i.namespace!==s)return console.warn(`esbuild: Treating import "${i.path}" as external.`),{path:i.path,external:!0}}),r.onLoad({filter:/.*/,namespace:s},i=>{let f;if(i.path===u)f=d;else{if(i.path!==a)return{errors:[{text:`Cannot load unknown path in ${s}: ${i.path}`}]};f=l}return{contents:f,loader:"ts"}})}}],sourcemap:"inline",tsconfigRaw:H,minify:!0,platform:"neutral"});if(o.outputFiles&&o.outputFiles.length>0)return o.outputFiles[0].text;throw o.errors&&o.errors.length>0?new Error(`esbuild bundling failed: ${o.errors.map(r=>r.text).join(`
|
|
9
|
+
`)}`):new Error("esbuild did not produce an output file.")}catch(e){throw console.error("esbuild bundling process failed:",e),e}}function Z(t,d,u){return c=>{const e=c.factory,a=()=>e.createExpressionStatement(e.createCallChain(e.createPropertyAccessExpression(e.createIdentifier(k.GLOBAL_CONTEXT_VARIABLE),"checkRun"),e.createToken(t.SyntaxKind.QuestionDotToken),void 0,[e.createStringLiteral(d),e.createNumericLiteral(u)])),l=r=>{const s=r.statements;let i=0;for(;i<s.length&&t.isExpressionStatement(s[i])&&t.isStringLiteral(s[i].expression);)i++;return e.updateBlock(r,[...s.slice(0,i),a(),...s.slice(i)])},o=r=>{if((s=>t.isForStatement(s)||t.isForInStatement(s)||t.isForOfStatement(s)||t.isWhileStatement(s)||t.isDoStatement(s))(r)){const s=r.statement;return t.visitEachChild(r,i=>{const f=o(i);return i===s?(m=f,t.isBlock(m)?l(m):e.createBlock([a(),m],!0)):f;var m},c)}if(t.isFunctionLike(r)&&r.body){const s=r.body;return t.visitEachChild(r,i=>{const f=o(i);return i===s?(m=f,t.isBlock(m)?l(m):e.createBlock([a(),e.createReturnStatement(m)],!0)):f;var m},c)}return t.visitEachChild(r,o,c)};return r=>t.visitNode(r,o)}}var ee=new Set(["TS2339","TS2551"]);function te(t,d,u){let c=null;const e=a=>{u<a.getStart(d)||u>=a.end||(a.getStart(d)===u&&(c=a),t.forEachChild(a,e))};return t.forEachChild(d,e),c}function ne(t,d){const u=d.parent;if(!u||!t.isPropertyAccessExpression(u)||u.name!==d)return!1;let c=u,e=u.parent;for(;e&&(t.isParenthesizedExpression(e)||t.isNonNullExpression(e));)c=e,e=e.parent;if(!e)return!1;if((t.isCallExpression(e)||t.isPropertyAccessExpression(e)||t.isElementAccessExpression(e))&&e.expression===c)return!!e.questionDotToken;if(t.isTypeOfExpression(e))return!0;if(t.isPrefixUnaryExpression(e))return e.operator===t.SyntaxKind.ExclamationToken;if(t.isConditionalExpression(e))return e.condition===c;if(t.isIfStatement(e)||t.isWhileStatement(e)||t.isDoStatement(e))return e.expression===c;if(t.isBinaryExpression(e)){const a=e.operatorToken.kind,l=t.SyntaxKind;if(a===l.AmpersandAmpersandToken||a===l.BarBarToken||a===l.QuestionQuestionToken)return e.left===c;if(a===l.EqualsEqualsEqualsToken||a===l.ExclamationEqualsEqualsToken||a===l.EqualsEqualsToken||a===l.ExclamationEqualsToken)return((o,r)=>r.kind===o.SyntaxKind.NullKeyword||o.isIdentifier(r)&&r.text==="undefined")(t,e.left===c?e.right:e.left)}return!1}var ie=async()=>`
|
|
10
|
+
interface FirstTest {
|
|
11
|
+
isTrue?: boolean;
|
|
12
|
+
}
|
|
13
|
+
`,w=null,R="sheetxl.d.ts",$="sheetxl-modules.d.ts",re=["lib.webworker.d.ts","lib.es2020.d.ts","lib.esnext.asynciterable.d.ts"],M=new Map,B=null,P=null;async function oe(){return P||(P=Promise.resolve().then(()=>require("./D5np5QScDyDDD_WJ.cjs")).then(async t=>{const d=await _();return t.readLibFile(d,"lib.es5.d.ts")!==void 0?t.readLibFile:null})),P}async function _(){if(w)return w;try{const t=await(await Promise.resolve().then(()=>require("./D5np5QScDyDDD_WJ.cjs"))).initialize();if(!t)throw new Error("TypeScript could not be loaded. Check your connection and try again.");return t}catch(t){throw w=null,t}finally{w=null}}exports.compileModule=async function(t){const d=t?.source??null;if(!d)return{module:null,diagnostics:[]};const u=(t.disableBundle||t.declarationsOnly)??!1,[c,e,a]=await Promise.all([ie(),_(),t.ambientTypes?oe():null]),l=a?t.ambientTypes??null:null;let o="";const r={allowJs:!0,declaration:!1,sourceMap:!1,inlineSourceMap:!1,inlineSources:!1,isolatedModules:!0,preserveConstEnums:!1,module:99,noResolve:!0,emitDeclarationOnly:!1,target:e.ScriptTarget.ES2020,...l?{lib:re,skipLibCheck:!0,strict:!0}:{},...l&&t.lenient?{noImplicitAny:!1}:{}},s="script",i=`${s}.ts`,f="lib.d.ts",m="global.d.ts",y={[i]:d,[f]:`
|
|
14
|
+
/**
|
|
15
|
+
* Represents the completion of an asynchronous operation
|
|
16
|
+
*/
|
|
17
|
+
interface Promise<T> {
|
|
18
|
+
/**
|
|
19
|
+
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
|
|
20
|
+
* resolved value cannot be modified from the callback.
|
|
21
|
+
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
|
|
22
|
+
* @returns A Promise for the completion of the callback.
|
|
23
|
+
*/
|
|
24
|
+
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
|
|
25
|
+
}
|
|
26
|
+
`,[m]:c,...l?{[R]:l,[$]:`declare module '@sheetxl/primitives' { export = SheetXL; }
|
|
27
|
+
`}:{}},C=n=>y[n]??(a&&n.startsWith("lib.")?a(e,n):void 0),z={getSourceFile:(n,b,D,h)=>{if(n===R)return B?.text!==l&&(B={text:l,file:e.createSourceFile(n,l,e.ScriptTarget.Latest,!1)}),B.file;if(y[n]===void 0){let p=M.get(n);if(!p){const x=C(n);if(x===void 0)return;p=e.createSourceFile(n,x,e.ScriptTarget.Latest,!1),M.set(n,p)}return p}return e.createSourceFile(n,y[n],e.ScriptTarget.Latest,!0)},fileExists:n=>C(n)!==void 0,readFile:C,writeFile:(n,b)=>{y[n]=b},getCurrentDirectory:()=>"./",getCanonicalFileName:n=>n,useCaseSensitiveFileNames:()=>!0,getDefaultLibFileName:n=>f,getNewLine:()=>`
|
|
28
|
+
`},E=e.createProgram([i,m,...l?[R,$]:[]],r,z),j=E.getTypeChecker(),T=E.getSourceFile(i),F=t.runGuard;E.emit(void 0,void 0,void 0,void 0,F?{before:[Z(e,F.key,F.timeoutMs)]}:void 0),o=y[`${s}.js`]??"";const O=n=>({start:n.start??0,length:n.length??0,severity:n.category===e.DiagnosticCategory.Warning?"warning":"error",code:`TS${n.code}`,message:e.flattenDiagnosticMessageText(n.messageText,`
|
|
29
|
+
`)}),G=E.getSyntacticDiagnostics(T).map(O),K=l?E.getSemanticDiagnostics(T).filter(n=>n.category===e.DiagnosticCategory.Error||n.category===e.DiagnosticCategory.Warning).map(O):[],L=Q.analyzeModule(e,T,j,{builtInNames:t.builtInNames,isBuiltIn:t.isBuiltIn,lenient:!!l&&t.lenient});let S=[...G,...K,...L.diagnostics];l&&t.lenient&&(S=(function(n,b,D){const h=[];for(const p of D)if(p.code!==U.DiagnosticCode.MissingType)if(p.severity!=="error")h.push(p);else if(p.code==="TS2774")h.push({...p,severity:"warning"});else if(ee.has(p.code)){const x=te(n,b,p.start);h.push(x&&ne(n,x)?{...p,severity:"warning",message:`${p.message} Read as a probe, it is undefined.`}:p)}else h.push(p);return h})(e,T,S));const V=L.functions,q=L.autoRun,W=S.some(n=>n.severity==="error"),X=`${J.CommonUtils.uuidV4()}-script`;let A=null;if(W)o="";else{try{u||(o=await Y(0,o,s))}catch{console.warn("Error bundling script")}const n=o.indexOf(N.SOURCEMAP_IDENTIFIER);n>-1&&(A=o.substring(n+N.SOURCEMAP_IDENTIFIER.length+1,o.length),o=o.substring(0,n),o=o.replaceAll("globalThis."+k.GLOBAL_CONTEXT_VARIABLE,k.GLOBAL_CONTEXT_VARIABLE))}const I={functions:V,commitId:X,source:d,language:"typescript",compiled:o};return A&&(I.sourceMap=A),q&&(I.autoRun=q),{module:I,diagnostics:S}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Object.create;var t=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var y=(r,i,l,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of s(i))!p.call(r,n)&&n!==l&&t(r,n,{get:()=>i[n],enumerable:!(e=c(i,n))||e.enumerable});return r};var f=(r,i,l)=>(l=r!=null?a(u(r)):{},y(i||!r||!r.__esModule?t(l,"default",{value:r,enumerable:!0}):l,r));var o=null;exports.initialize=async function(){return o||(o=new Promise(async(r,i)=>{let l=null;try{l=await import("https://esm.sh/typescript@5.7.2")}catch(e){console.error("Error initializing Browser TypeScript module:",e)}l||(console.log("use script fallback"),o=null),r(l)}))},exports.readLibFile=function(r,i){};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"SOURCEMAP_IDENTIFIER",{enumerable:!0,get:function(){return"//# sourceMappingURL"}});
|