@accordproject/template-engine 2.5.10 → 2.5.12

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/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import jp from 'jsonpath';
2
2
  import traverse from 'traverse';
3
+ import { isBrowser } from 'browser-or-node';
3
4
  import os from 'os';
4
5
  import { Introspector, ModelManager, Factory, Serializer, ModelUtil } from '@accordproject/concerto-core';
5
6
  import dayjs from 'dayjs';
@@ -479,7 +480,7 @@ async function sleep(msec) {
479
480
  }
480
481
  class JavaScriptEvaluator {
481
482
  // queue of work to do
482
- constructor(options) {
483
+ constructor(options = { waitInterval: 50, maxWorkers: 8, maxQueueDepth: 1e3 }) {
483
484
  __publicField$1(this, "options");
484
485
  __publicField$1(this, "workers");
485
486
  // child processes
@@ -611,9 +612,8 @@ function checkCode(code) {
611
612
  throw new Error(`Cannot run ${code.contents} as it is not ES_2020 JavaScript.`);
612
613
  }
613
614
  }
614
- const availableProcessors = process.env.MAX_WORKERS ? Number.parseInt(process.env.MAX_WORKERS) : os.availableParallelism();
615
- const javaScriptEvaluator = new JavaScriptEvaluator({
616
- maxWorkers: availableProcessors,
615
+ const javaScriptEvaluator = isBrowser ? new JavaScriptEvaluator() : new JavaScriptEvaluator({
616
+ maxWorkers: process.env.MAX_WORKERS ? Number.parseInt(process.env.MAX_WORKERS) : os.availableParallelism(),
617
617
  // how many child processes
618
618
  waitInterval: process.env.WAIT_INTERVAL ? Number.parseInt(process.env.WAIT_INTERVAL) : 50,
619
619
  // how long to wait before rescheduling work
@@ -642,6 +642,9 @@ async function evaluateJavaScript(clauseLibrary, data, fn, options) {
642
642
  try {
643
643
  const request = { code: expression, argumentNames: functionArgNames, arguments: functionArgValues };
644
644
  if (options?.childProcessJavaScriptEvaluation) {
645
+ if (isBrowser) {
646
+ throw new Error("Child process evaluation is not supported inside web browser");
647
+ }
645
648
  const evalOptions = options?.timeout ? { timeout: options.timeout } : void 0;
646
649
  const r = await javaScriptEvaluator.evalChildProcess(request, evalOptions);
647
650
  return typeof r.result === "object" ? JSON.stringify(r.result) : r.result.toString();