@accordproject/template-engine 2.5.11 → 2.5.13

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.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var jp = require('jsonpath');
4
4
  var traverse = require('traverse');
5
+ var browserOrNode = require('browser-or-node');
5
6
  var os = require('os');
6
7
  var concertoCore = require('@accordproject/concerto-core');
7
8
  var dayjs = require('dayjs');
@@ -500,7 +501,7 @@ async function sleep(msec) {
500
501
  }
501
502
  class JavaScriptEvaluator {
502
503
  // queue of work to do
503
- constructor(options) {
504
+ constructor(options = { waitInterval: 50, maxWorkers: 8, maxQueueDepth: 1e3 }) {
504
505
  __publicField$1(this, "options");
505
506
  __publicField$1(this, "workers");
506
507
  // child processes
@@ -632,9 +633,8 @@ function checkCode(code) {
632
633
  throw new Error(`Cannot run ${code.contents} as it is not ES_2020 JavaScript.`);
633
634
  }
634
635
  }
635
- const availableProcessors = process.env.MAX_WORKERS ? Number.parseInt(process.env.MAX_WORKERS) : os.availableParallelism();
636
- const javaScriptEvaluator = new JavaScriptEvaluator({
637
- maxWorkers: availableProcessors,
636
+ const javaScriptEvaluator = browserOrNode.isBrowser ? new JavaScriptEvaluator() : new JavaScriptEvaluator({
637
+ maxWorkers: process.env.MAX_WORKERS ? Number.parseInt(process.env.MAX_WORKERS) : os.availableParallelism(),
638
638
  // how many child processes
639
639
  waitInterval: process.env.WAIT_INTERVAL ? Number.parseInt(process.env.WAIT_INTERVAL) : 50,
640
640
  // how long to wait before rescheduling work
@@ -663,6 +663,9 @@ async function evaluateJavaScript(clauseLibrary, data, fn, options) {
663
663
  try {
664
664
  const request = { code: expression, argumentNames: functionArgNames, arguments: functionArgValues };
665
665
  if (options?.childProcessJavaScriptEvaluation) {
666
+ if (browserOrNode.isBrowser) {
667
+ throw new Error("Child process evaluation is not supported inside web browser");
668
+ }
666
669
  const evalOptions = options?.timeout ? { timeout: options.timeout } : void 0;
667
670
  const r = await javaScriptEvaluator.evalChildProcess(request, evalOptions);
668
671
  return typeof r.result === "object" ? JSON.stringify(r.result) : r.result.toString();