solve-engine 2.1.0 → 2.2.0

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 (50) hide show
  1. package/dist/{PackageCompatibility-Bn5jnBtA.d.cts → PackageCompatibility-Cv7zjqSV.d.cts} +1 -1
  2. package/dist/{PackageCompatibility-CIvq2MP5.d.ts → PackageCompatibility-DBsZ0l2a.d.ts} +1 -1
  3. package/dist/{PackageRegistry-dpdurBVO.d.cts → PackageRegistry-BSGQ6saH.d.cts} +9 -2
  4. package/dist/{PackageRegistry-DzeiWcv4.d.ts → PackageRegistry-DRbqNJfI.d.ts} +9 -2
  5. package/dist/{ScopeManager-C2LDOrDx.d.ts → ScopeManager-DkpnlKuz.d.ts} +1 -1
  6. package/dist/{ScopeManager-D7uMXbhS.d.cts → ScopeManager-t6SnP6Ce.d.cts} +1 -1
  7. package/dist/{VMCheckpoints-I9jg3jWR.d.cts → VMCheckpoints-C_jQvABf.d.cts} +2 -2
  8. package/dist/{VMCheckpoints-CGyFhivM.d.ts → VMCheckpoints-CsHmQVaD.d.ts} +2 -2
  9. package/dist/{chunk-JUIJ6NRD.cjs → chunk-6C6IPUBH.cjs} +3 -3
  10. package/dist/chunk-6C6IPUBH.cjs.map +1 -0
  11. package/dist/chunk-7NXAZJDB.js +3 -0
  12. package/dist/chunk-7NXAZJDB.js.map +1 -0
  13. package/dist/{chunk-U4AEVL5Z.js → chunk-KVTOV3TZ.js} +2 -2
  14. package/dist/{chunk-U4AEVL5Z.js.map → chunk-KVTOV3TZ.js.map} +1 -1
  15. package/dist/{chunk-GK2OHWRF.cjs → chunk-U2UZJX5W.cjs} +4 -4
  16. package/dist/chunk-U2UZJX5W.cjs.map +1 -0
  17. package/dist/{chunk-EVI6OHQH.cjs → chunk-X3R7B7XM.cjs} +2 -2
  18. package/dist/{chunk-EVI6OHQH.cjs.map → chunk-X3R7B7XM.cjs.map} +1 -1
  19. package/dist/{chunk-4E4YVQKK.js → chunk-YU3PACLE.js} +4 -4
  20. package/dist/chunk-YU3PACLE.js.map +1 -0
  21. package/dist/constants.cjs +1 -1
  22. package/dist/constants.js +1 -1
  23. package/dist/engine.cjs +1 -1
  24. package/dist/engine.d.cts +48 -5
  25. package/dist/engine.d.ts +48 -5
  26. package/dist/engine.js +1 -1
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.cts +4 -4
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.js +1 -1
  31. package/dist/language.d.cts +3 -3
  32. package/dist/language.d.ts +3 -3
  33. package/dist/packages.d.cts +2 -2
  34. package/dist/packages.d.ts +2 -2
  35. package/dist/testing.cjs +2 -2
  36. package/dist/testing.d.cts +3 -3
  37. package/dist/testing.d.ts +3 -3
  38. package/dist/testing.js +1 -1
  39. package/dist/vm.d.cts +3 -3
  40. package/dist/vm.d.ts +3 -3
  41. package/dist/worker.cjs +2 -2
  42. package/dist/worker.d.cts +2 -2
  43. package/dist/worker.d.ts +2 -2
  44. package/dist/worker.js +1 -1
  45. package/package.json +1 -1
  46. package/dist/chunk-4E4YVQKK.js.map +0 -1
  47. package/dist/chunk-GK2OHWRF.cjs.map +0 -1
  48. package/dist/chunk-I52MYCVI.js +0 -3
  49. package/dist/chunk-I52MYCVI.js.map +0 -1
  50. package/dist/chunk-JUIJ6NRD.cjs.map +0 -1
package/dist/worker.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { E as EngineConfigOverride } from './Configuration-B6W0-T67.cjs';
2
- import { U as UnifiedParsingOptions, I as IEnginePackage, P as ParsedLine, J as ParsingResult } from './PackageRegistry-dpdurBVO.cjs';
2
+ import { U as UnifiedParsingOptions, I as IEnginePackage, J as ParsedLine, P as ParsingResult } from './PackageRegistry-BSGQ6saH.cjs';
3
3
  import { F as FormattingSettings } from './FormattingSettings-CJHyxcYu.cjs';
4
4
  import { E as EngineError } from './EngineError-Ce1lPkjZ.cjs';
5
5
  import { b as ValueType, g as ColourFormat, V as Value } from './Value-CCi_Eecs.cjs';
@@ -12,7 +12,7 @@ import './Lexer-B4C1qHXu.cjs';
12
12
  import './resolvers.cjs';
13
13
  import '@tanstack/query-core';
14
14
  import './TokenNormalizer-DnlL7_8c.cjs';
15
- import './ScopeManager-D7uMXbhS.cjs';
15
+ import './ScopeManager-t6SnP6Ce.cjs';
16
16
 
17
17
  /**
18
18
  * The seam between the harness and whatever actually carries messages.
package/dist/worker.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { E as EngineConfigOverride } from './Configuration-B6W0-T67.js';
2
- import { U as UnifiedParsingOptions, I as IEnginePackage, P as ParsedLine, J as ParsingResult } from './PackageRegistry-DzeiWcv4.js';
2
+ import { U as UnifiedParsingOptions, I as IEnginePackage, J as ParsedLine, P as ParsingResult } from './PackageRegistry-DRbqNJfI.js';
3
3
  import { F as FormattingSettings } from './FormattingSettings-CJHyxcYu.js';
4
4
  import { E as EngineError } from './EngineError-Ce1lPkjZ.js';
5
5
  import { b as ValueType, g as ColourFormat, V as Value } from './Value-CCi_Eecs.js';
@@ -12,7 +12,7 @@ import './Lexer-DKMlj7Sy.js';
12
12
  import './resolvers.js';
13
13
  import '@tanstack/query-core';
14
14
  import './TokenNormalizer-DCWdZjGz.js';
15
- import './ScopeManager-C2LDOrDx.js';
15
+ import './ScopeManager-DkpnlKuz.js';
16
16
 
17
17
  /**
18
18
  * The seam between the harness and whatever actually carries messages.
package/dist/worker.js CHANGED
@@ -1,3 +1,3 @@
1
- import {a,e,d,c as c$2,b}from'./chunk-MVZUTETT.js';import {n}from'./chunk-4E4YVQKK.js';import'./chunk-XNIWQHXY.js';import'./chunk-2RWAXT6O.js';import'./chunk-7GK3XEZF.js';import'./chunk-MIQBJGGR.js';import'./chunk-YJ2OPULK.js';import'./chunk-TWC7K3ZX.js';import {c}from'./chunk-J4LZD4ZY.js';import'./chunk-XEIDV5JP.js';import {y as y$1}from'./chunk-E2Q3PQ2G.js';import'./chunk-6G3PMEPA.js';import'./chunk-TN5E6JU6.js';import'./chunk-YVKHEAFT.js';import'./chunk-5FO4PDIG.js';import'./chunk-76F3LCIL.js';import'./chunk-TCZSPH4A.js';import'./chunk-W2JAR233.js';import'./chunk-YAYBVVG2.js';import'./chunk-E6Z4NQAS.js';import'./chunk-HFKDWQUL.js';import {g,f}from'./chunk-R2ENWQ76.js';import {R}from'./chunk-RSF25YSJ.js';import'./chunk-EVAOPEO4.js';import'./chunk-WGZ3FNHI.js';import'./chunk-U4AEVL5Z.js';import'./chunk-YAHGSBMC.js';import'./chunk-JPFCXLJV.js';import'./chunk-G7TBEQRQ.js';import'./chunk-IJMNVBIS.js';import'./chunk-62LMTO4F.js';import'./chunk-TRBXW6HW.js';import'./chunk-2JMFUQZH.js';import {c as c$1,d as d$1}from'./chunk-MPB7KUN5.js';var W=class{constructor(r){this.nextId=1;this.pending=new Map;this.resolvedListeners=new Set;this.asyncErrorListeners=new Set;this.terminated=false;this.transport=r,this.transport.onMessage(n=>this.onMessage(n));}init(r){let n=this.nextId++;return new Promise((t,o)=>{this.pending.set(n,{resolve:()=>t(),reject:o}),this.transport.postMessage({kind:"init",id:n,localeCode:r.localeCode,diagnostics:r.diagnostics,config:r.config,packages:r.packages,formatting:r.formatting});})}parseDocument(r,n){let{signal:t,...o}=n??{},a=Object.keys(o).length>0?o:void 0;return this.call("parseDocument",[r,a],t)}evaluateLines(r,n){return this.call("evaluateLines",[r],n?.signal)}evaluateExpression(r,n){return this.call("evaluateExpression",[r],n?.signal)}onResolved(r){return this.resolvedListeners.add(r),()=>this.resolvedListeners.delete(r)}onAsyncError(r){return this.asyncErrorListeners.add(r),()=>this.asyncErrorListeners.delete(r)}terminate(){if(this.terminated)return;this.terminated=true;let r=e();for(let n of this.pending.values())this.unhook(n),n.reject(r);this.pending.clear(),this.resolvedListeners.clear(),this.asyncErrorListeners.clear(),this.transport.terminate();}call(r,n,t){if(this.terminated)return Promise.reject(e());if(t?.aborted)return Promise.reject(d(r));let o=this.nextId++;return new Promise((a,u)=>{let c={resolve:a,reject:u};if(t){let g=()=>{this.pending.has(o)&&(this.pending.delete(o),this.transport.postMessage({kind:"cancel",id:o}),u(d(r)));};c.signal=t,c.onAbort=g,t.addEventListener("abort",g,{once:true});}this.pending.set(o,c),this.transport.postMessage({kind:"request",id:o,method:r,args:n});})}onMessage(r){let n=r;switch(n.kind){case "ready":case "result":{let t=n.kind==="result"?n.value:void 0;this.settle(n.id,o=>o.resolve(t));break}case "error":this.settle(n.id,t=>t.reject(c$2(n.error)));break;case "async-update":for(let t of [...this.resolvedListeners])t(n.lines);break;case "async-error":for(let t of [...this.asyncErrorListeners])t({queryKey:n.queryKey,packageId:n.packageId,error:c$2(n.error)});break}}settle(r,n){let t=this.pending.get(r);t&&(this.pending.delete(r),this.unhook(t),n(t));}unhook(r){r.signal&&r.onAbort&&r.signal.removeEventListener("abort",r.onAbort);}};async function K(e){let r=new W(e.transport);return await r.init(e),r}function O(e){return e>0?"Infinity":e<0?"-Infinity":"NaN"}function U(e){let r=e.data.map(n=>typeof n=="object"&&n!==null?R(n):typeof n=="number"&&!Number.isFinite(n)?O(n):n);return {rows:e.rows,cols:e.cols,cells:r,hasSymbolic:e.hasSymbolic}}function m(e,r){let n=e.toNumber(),t={type:e.type,text:c(e,r),number:Number.isFinite(n)?n:0};Number.isFinite(n)||(t.nonFinite=O(n)),e.unit!==void 0&&(t.unit=e.unit),e.timedOut!==void 0&&(t.timedOut=e.timedOut);let o=e.value;if(typeof o=="bigint")t.bigint=o.toString();else if(e.type===7)t.matrix=U(o);else if(e.type===8){let a=o;t.range={min:a.min,max:a.max};}else if(e.type===14){let a=o;t.colour={hex:f(a),r:a.r,g:a.g,b:a.b,a:a.a,format:a.format,css:g(a)};}return t}function N(e,r){return e?m(e,r):null}function _(e,r){return {start:e.start,end:e.end,expression:e.expression,lineNumber:e.lineNumber,columnNumber:e.columnNumber,result:N(e.result,r),error:e.error??null}}function y(e,r){return {lineNumber:e.lineNumber,text:e.text,startPosition:e.startPosition,endPosition:e.endPosition,isEmpty:e.isEmpty,hasInlineSolves:e.hasInlineSolves,inlineSolves:e.inlineSolves.map(n=>_(n,r)),expression:e.expression,result:N(e.result,r),error:e.error}}function x(e,r){let n={lines:e.lines.map(t=>y(t,r)),totalLines:e.totalLines,errors:[...e.errors]};return e.diagnostics!==void 0&&(n.diagnostics=e.diagnostics),n}function H(e,r){if(r===void 0)return e;let n=new Map(e.map(o=>[o.name,o])),t=[];for(let o of r){let a$1=n.get(o);if(!a$1)throw c$1.config(a.WORKER_UNKNOWN_PACKAGE,`No package named "${o}" is available in this worker runtime`,{name:o,available:[...n.keys()]});t.push(a$1);}return t}function B(e,r={}){let n$1=r.packages??y$1,t=null,o,a$1=new Map,u=new Map,c=null,g=null,p=i=>e.postMessage(i),h=(i,s)=>{p({kind:"error",id:i,error:b(d$1(s))});},C=i=>{let s=new Map;return i.method==="parseDocument"?i.args[0].split(`
1
+ import {a,e,d,c as c$2,b}from'./chunk-MVZUTETT.js';import {n}from'./chunk-YU3PACLE.js';import'./chunk-XNIWQHXY.js';import'./chunk-2RWAXT6O.js';import'./chunk-7GK3XEZF.js';import'./chunk-MIQBJGGR.js';import'./chunk-YJ2OPULK.js';import'./chunk-TWC7K3ZX.js';import {c}from'./chunk-J4LZD4ZY.js';import'./chunk-XEIDV5JP.js';import {y as y$1}from'./chunk-E2Q3PQ2G.js';import'./chunk-6G3PMEPA.js';import'./chunk-TN5E6JU6.js';import'./chunk-YVKHEAFT.js';import'./chunk-5FO4PDIG.js';import'./chunk-76F3LCIL.js';import'./chunk-TCZSPH4A.js';import'./chunk-W2JAR233.js';import'./chunk-YAYBVVG2.js';import'./chunk-E6Z4NQAS.js';import'./chunk-HFKDWQUL.js';import {g,f}from'./chunk-R2ENWQ76.js';import {R}from'./chunk-RSF25YSJ.js';import'./chunk-EVAOPEO4.js';import'./chunk-WGZ3FNHI.js';import'./chunk-KVTOV3TZ.js';import'./chunk-YAHGSBMC.js';import'./chunk-JPFCXLJV.js';import'./chunk-G7TBEQRQ.js';import'./chunk-IJMNVBIS.js';import'./chunk-62LMTO4F.js';import'./chunk-TRBXW6HW.js';import'./chunk-2JMFUQZH.js';import {c as c$1,d as d$1}from'./chunk-MPB7KUN5.js';var W=class{constructor(r){this.nextId=1;this.pending=new Map;this.resolvedListeners=new Set;this.asyncErrorListeners=new Set;this.terminated=false;this.transport=r,this.transport.onMessage(n=>this.onMessage(n));}init(r){let n=this.nextId++;return new Promise((t,o)=>{this.pending.set(n,{resolve:()=>t(),reject:o}),this.transport.postMessage({kind:"init",id:n,localeCode:r.localeCode,diagnostics:r.diagnostics,config:r.config,packages:r.packages,formatting:r.formatting});})}parseDocument(r,n){let{signal:t,...o}=n??{},a=Object.keys(o).length>0?o:void 0;return this.call("parseDocument",[r,a],t)}evaluateLines(r,n){return this.call("evaluateLines",[r],n?.signal)}evaluateExpression(r,n){return this.call("evaluateExpression",[r],n?.signal)}onResolved(r){return this.resolvedListeners.add(r),()=>this.resolvedListeners.delete(r)}onAsyncError(r){return this.asyncErrorListeners.add(r),()=>this.asyncErrorListeners.delete(r)}terminate(){if(this.terminated)return;this.terminated=true;let r=e();for(let n of this.pending.values())this.unhook(n),n.reject(r);this.pending.clear(),this.resolvedListeners.clear(),this.asyncErrorListeners.clear(),this.transport.terminate();}call(r,n,t){if(this.terminated)return Promise.reject(e());if(t?.aborted)return Promise.reject(d(r));let o=this.nextId++;return new Promise((a,u)=>{let c={resolve:a,reject:u};if(t){let g=()=>{this.pending.has(o)&&(this.pending.delete(o),this.transport.postMessage({kind:"cancel",id:o}),u(d(r)));};c.signal=t,c.onAbort=g,t.addEventListener("abort",g,{once:true});}this.pending.set(o,c),this.transport.postMessage({kind:"request",id:o,method:r,args:n});})}onMessage(r){let n=r;switch(n.kind){case "ready":case "result":{let t=n.kind==="result"?n.value:void 0;this.settle(n.id,o=>o.resolve(t));break}case "error":this.settle(n.id,t=>t.reject(c$2(n.error)));break;case "async-update":for(let t of [...this.resolvedListeners])t(n.lines);break;case "async-error":for(let t of [...this.asyncErrorListeners])t({queryKey:n.queryKey,packageId:n.packageId,error:c$2(n.error)});break}}settle(r,n){let t=this.pending.get(r);t&&(this.pending.delete(r),this.unhook(t),n(t));}unhook(r){r.signal&&r.onAbort&&r.signal.removeEventListener("abort",r.onAbort);}};async function K(e){let r=new W(e.transport);return await r.init(e),r}function O(e){return e>0?"Infinity":e<0?"-Infinity":"NaN"}function U(e){let r=e.data.map(n=>typeof n=="object"&&n!==null?R(n):typeof n=="number"&&!Number.isFinite(n)?O(n):n);return {rows:e.rows,cols:e.cols,cells:r,hasSymbolic:e.hasSymbolic}}function m(e,r){let n=e.toNumber(),t={type:e.type,text:c(e,r),number:Number.isFinite(n)?n:0};Number.isFinite(n)||(t.nonFinite=O(n)),e.unit!==void 0&&(t.unit=e.unit),e.timedOut!==void 0&&(t.timedOut=e.timedOut);let o=e.value;if(typeof o=="bigint")t.bigint=o.toString();else if(e.type===7)t.matrix=U(o);else if(e.type===8){let a=o;t.range={min:a.min,max:a.max};}else if(e.type===14){let a=o;t.colour={hex:f(a),r:a.r,g:a.g,b:a.b,a:a.a,format:a.format,css:g(a)};}return t}function N(e,r){return e?m(e,r):null}function _(e,r){return {start:e.start,end:e.end,expression:e.expression,lineNumber:e.lineNumber,columnNumber:e.columnNumber,result:N(e.result,r),error:e.error??null}}function y(e,r){return {lineNumber:e.lineNumber,text:e.text,startPosition:e.startPosition,endPosition:e.endPosition,isEmpty:e.isEmpty,hasInlineSolves:e.hasInlineSolves,inlineSolves:e.inlineSolves.map(n=>_(n,r)),expression:e.expression,result:N(e.result,r),error:e.error}}function x(e,r){let n={lines:e.lines.map(t=>y(t,r)),totalLines:e.totalLines,errors:[...e.errors]};return e.diagnostics!==void 0&&(n.diagnostics=e.diagnostics),n}function H(e,r){if(r===void 0)return e;let n=new Map(e.map(o=>[o.name,o])),t=[];for(let o of r){let a$1=n.get(o);if(!a$1)throw c$1.config(a.WORKER_UNKNOWN_PACKAGE,`No package named "${o}" is available in this worker runtime`,{name:o,available:[...n.keys()]});t.push(a$1);}return t}function B(e,r={}){let n$1=r.packages??y$1,t=null,o,a$1=new Map,u=new Map,c=null,g=null,p=i=>e.postMessage(i),h=(i,s)=>{p({kind:"error",id:i,error:b(d$1(s))});},C=i=>{let s=new Map;return i.method==="parseDocument"?i.args[0].split(`
2
2
  `).forEach((d,l)=>s.set(l+1,d)):i.method==="evaluateLines"?i.args[0].forEach((d,l)=>s.set(l+1,d)):s.set(-1,i.args[0]),s},q=(i,s)=>{if(s.type==="error"){p({kind:"async-error",queryKey:s.queryKey,packageId:s.packageId,error:b(d$1(s.error))});return}let d=[];for(let l of s.lineNumbers){let f=u.get(l);if(f!==void 0)try{let R=i.evaluateLine(l,f);R&&d.push({lineNumber:l,value:m(R,o)});}catch{}}d.length>0&&p({kind:"async-update",lines:d});},F=i=>{g?.();let s=i.getEventStream().getReader();g=()=>{s.cancel();},(async()=>{try{for(;;){let{done:d,value:l}=await s.read();if(d)return;q(i,l);}}catch{}})();},V=i=>{try{let s=H(n$1,i.packages);t=new n({locale:i.localeCode??"en",diagnostics:i.diagnostics??!1,config:i.config,packages:s}),o=i.formatting,F(t),p({kind:"ready",id:i.id});}catch(s){h(i.id,s);}},j=(i,s)=>{let{method:d,args:l}=s;switch(d){case "parseDocument":return x(i.parseDocument(l[0],l[1]),o);case "evaluateLines":return i.evaluateLines(l[0]).map(f=>y(f,o));case "evaluateExpression":return m(i.evaluateExpression(l[0]),o);default:throw c$1.execution(a.WORKER_UNKNOWN_METHOD,`The worker runtime has no method named "${String(d)}"`,{method:d})}},D=i=>{let s=t;if(!s){h(i.id,c$1.execution(a.WORKER_NOT_INITIALISED,"The worker received a request before its engine finished initialising"));return}c?.abort();let d=new AbortController;c=d,u=C(i),a$1.set(i.id,d),s.setKeystrokeSignal(d.signal);try{let l=j(s,i);p({kind:"result",id:i.id,value:l});}catch(l){h(i.id,l);}finally{a$1.delete(i.id),s.setKeystrokeSignal(null);}};return e.onMessage(i=>{let s=i;switch(s.kind){case "init":V(s);break;case "request":D(s);break;case "cancel":a$1.get(s.id)?.abort();break}}),()=>{g?.(),g=null,c?.abort(),c=null,u=new Map;for(let i of a$1.values())i.abort();a$1.clear(),t?.clear(),t=null,e.terminate();}}function G(e){return typeof globalThis.structuredClone=="function"?globalThis.structuredClone(e):JSON.parse(JSON.stringify(e))}function J(){let e=null,r=null,n=true,t=(u,c)=>{let g=G(c);queueMicrotask(()=>{n&&u()?.(g);});};return {client:{postMessage:u=>t(()=>r,u),onMessage:u=>{e=u;},terminate:()=>{n=false;}},host:{postMessage:u=>t(()=>e,u),onMessage:u=>{r=u;},terminate:()=>{n=false;}}}}function $(e){return {postMessage:r=>e.postMessage(r),onMessage:r=>{let n=t=>r(t.data);typeof e.addEventListener=="function"?e.addEventListener("message",n):e.onmessage=n,e.start?.();},terminate:()=>{e.terminate?.(),e.close?.();}}}function Q(e){return {postMessage:r=>e.postMessage(r),onMessage:r=>{e.on("message",n=>r(n));},terminate:()=>{e.terminate?.(),e.close?.();}}}export{J as createLinkedTransports,K as createWorkerEngine,$ as eventTargetTransport,Q as messagePortTransport,y as serializeParsedLine,x as serializeParsingResult,m as serializeValue,B as startWorkerRuntime};//# sourceMappingURL=worker.js.map
3
3
  //# sourceMappingURL=worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solve-engine",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "An embeddable expression engine for natural-language calculations: units, currencies, percentages, dates and matrices, with the parsing and evaluation plumbing already built.",
5
5
  "keywords": [
6
6
  "expression-evaluator",