@next-core/brick-utils 2.33.1 → 2.35.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.
package/dist/index.esm.js CHANGED
@@ -21429,14 +21429,14 @@ var {
21429
21429
  convertUnitValueByPrecision: convertValueByPrecision
21430
21430
  } = utils;
21431
21431
 
21432
- var CTX$1 = "CTX";
21433
21432
  function resolveContextConcurrently(_x, _x2) {
21434
21433
  return _resolveContextConcurrently.apply(this, arguments);
21435
21434
  }
21436
21435
 
21437
21436
  function _resolveContextConcurrently() {
21438
21437
  _resolveContextConcurrently = _asyncToGenerator(function* (contextConfs, resolveContext) {
21439
- var dependencyMap = getDependencyMapOfContext(contextConfs);
21438
+ var keyword = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "CTX";
21439
+ var dependencyMap = getDependencyMapOfContext(contextConfs, keyword);
21440
21440
  var pendingDeps = new Set(Array.from(dependencyMap.keys()).map(contextConf => contextConf.name));
21441
21441
  var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
21442
21442
  var processed = new WeakSet();
@@ -21469,10 +21469,7 @@ function _resolveContextConcurrently() {
21469
21469
 
21470
21470
  function _scheduleNext() {
21471
21471
  _scheduleNext = _asyncToGenerator(function* () {
21472
- var readyContexts = Array.from(dependencyMap.entries()).filter((entry, index) => // When contexts contain computed CTX accesses, it implies a dynamic dependency map.
21473
- // So make them process sequentially, keep the same behavior as before.
21474
- scheduleAsSerial ? index === 0 : // A context is ready when it has no pending dependencies.
21475
- !entry[1].dependencies.some(dep => pendingDeps.has(dep))).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
21472
+ var readyContexts = Array.from(dependencyMap.entries()).filter(predicateNextResolveFactory(pendingDeps, scheduleAsSerial)).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
21476
21473
  yield Promise.all(readyContexts.map(wrapResolve));
21477
21474
  });
21478
21475
  return _scheduleNext.apply(this, arguments);
@@ -21487,7 +21484,7 @@ function _resolveContextConcurrently() {
21487
21484
 
21488
21485
  if (dependencyMap.size > 0) {
21489
21486
  // This will throw if circular contexts detected.
21490
- detectCircularContexts(dependencyMap);
21487
+ detectCircularContexts(dependencyMap, keyword);
21491
21488
  scheduleAsSerial = true;
21492
21489
  yield scheduleNext();
21493
21490
  }
@@ -21495,28 +21492,76 @@ function _resolveContextConcurrently() {
21495
21492
  return _resolveContextConcurrently.apply(this, arguments);
21496
21493
  }
21497
21494
 
21495
+ function syncResolveContextConcurrently(contextConfs, resolveContext) {
21496
+ var keyword = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "CTX";
21497
+ var dependencyMap = getDependencyMapOfContext(contextConfs, keyword);
21498
+ var pendingDeps = new Set(Array.from(dependencyMap.keys()).map(contextConf => contextConf.name));
21499
+ var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
21500
+ var scheduleAsSerial = includesComputed;
21501
+
21502
+ function scheduleNext() {
21503
+ var dep = Array.from(dependencyMap.entries()).find(predicateNextResolveFactory(pendingDeps, scheduleAsSerial));
21504
+
21505
+ if (dep) {
21506
+ var [_contextConf] = dep;
21507
+ var resolved = resolveContext(_contextConf);
21508
+ dependencyMap.delete(_contextConf);
21509
+
21510
+ if (resolved) {
21511
+ if (!pendingDeps.delete(_contextConf.name)) {
21512
+ throw new Error("Duplicated context defined: ".concat(_contextConf.name));
21513
+ }
21514
+ }
21515
+
21516
+ scheduleNext();
21517
+ }
21518
+ }
21519
+
21520
+ scheduleNext(); // If there are still contexts left, it implies one of these situations:
21521
+ // - Circular contexts.
21522
+ // Such as: a depends on b, while b depends on a.
21523
+ // - Related contexts are all ignored.
21524
+ // Such as: a depends on b,
21525
+ // while both them are ignore by a falsy result of `if`.
21526
+
21527
+ if (dependencyMap.size > 0) {
21528
+ // This will throw if circular contexts detected.
21529
+ detectCircularContexts(dependencyMap, keyword);
21530
+ scheduleAsSerial = true;
21531
+ scheduleNext();
21532
+ }
21533
+ }
21534
+
21535
+ function predicateNextResolveFactory(pendingDeps, scheduleAsSerial) {
21536
+ return (entry, index) => // When contexts contain computed CTX accesses, it implies a dynamic dependency map.
21537
+ // So make them process sequentially, keep the same behavior as before.
21538
+ scheduleAsSerial ? index === 0 : // A context is ready when it has no pending dependencies.
21539
+ !entry[1].dependencies.some(dep => pendingDeps.has(dep));
21540
+ }
21541
+
21498
21542
  function getDependencyMapOfContext(contextConfs) {
21543
+ var keyword = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "CTX";
21499
21544
  var depsMap = new Map();
21500
21545
 
21501
- for (var _contextConf of contextConfs) {
21546
+ for (var _contextConf2 of contextConfs) {
21502
21547
  var stats = {
21503
21548
  dependencies: [],
21504
21549
  includesComputed: false
21505
21550
  };
21506
21551
 
21507
- if (!_contextConf.property) {
21508
- visitStoryboardExpressions([_contextConf.if, _contextConf.value, _contextConf.resolve], beforeVisitContextFactory(stats), CTX$1);
21552
+ if (!_contextConf2.property) {
21553
+ visitStoryboardExpressions([_contextConf2.if, _contextConf2.value, _contextConf2.resolve], beforeVisitContextFactory(stats, keyword), keyword);
21509
21554
  }
21510
21555
 
21511
- depsMap.set(_contextConf, stats);
21556
+ depsMap.set(_contextConf2, stats);
21512
21557
  }
21513
21558
 
21514
21559
  return depsMap;
21515
21560
  }
21516
21561
 
21517
- function beforeVisitContextFactory(stats) {
21562
+ function beforeVisitContextFactory(stats, keyword) {
21518
21563
  return function beforeVisitContext(node, parent) {
21519
- if (node.name === CTX$1) {
21564
+ if (node.name === keyword) {
21520
21565
  var memberParent = parent[parent.length - 1];
21521
21566
 
21522
21567
  if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
@@ -21539,17 +21584,17 @@ function beforeVisitContextFactory(stats) {
21539
21584
  };
21540
21585
  }
21541
21586
 
21542
- function detectCircularContexts(dependencyMap) {
21587
+ function detectCircularContexts(dependencyMap, keyword) {
21543
21588
  var duplicatedMap = new Map(dependencyMap);
21544
21589
  var pendingDeps = new Set(Array.from(duplicatedMap.keys()).map(contextConf => contextConf.name));
21545
21590
 
21546
21591
  var next = () => {
21547
21592
  var processedAtLeastOne = false;
21548
21593
 
21549
- for (var [_contextConf2, stats] of duplicatedMap.entries()) {
21594
+ for (var [_contextConf3, stats] of duplicatedMap.entries()) {
21550
21595
  if (!stats.dependencies.some(dep => pendingDeps.has(dep))) {
21551
- duplicatedMap.delete(_contextConf2);
21552
- pendingDeps.delete(_contextConf2.name);
21596
+ duplicatedMap.delete(_contextConf3);
21597
+ pendingDeps.delete(_contextConf3.name);
21553
21598
  processedAtLeastOne = true;
21554
21599
  }
21555
21600
  }
@@ -21562,7 +21607,7 @@ function detectCircularContexts(dependencyMap) {
21562
21607
  next();
21563
21608
 
21564
21609
  if (duplicatedMap.size > 0) {
21565
- throw new ReferenceError("Circular CTX detected: ".concat(Array.from(duplicatedMap.keys()).map(contextConf => contextConf.name).join(", ")));
21610
+ throw new ReferenceError("Circular ".concat(keyword, " detected: ").concat(Array.from(duplicatedMap.keys()).map(contextConf => contextConf.name).join(", ")));
21566
21611
  }
21567
21612
  }
21568
21613
 
@@ -21701,23 +21746,24 @@ var jsonFieldsInBrick = ["properties", "events", "lifeCycle", "params", "if", "t
21701
21746
 
21702
21747
  var yamlFieldsInBrick = ["permissionsPreCheck", "transformFrom"]; // Fields started with `_` will be removed by default.
21703
21748
 
21704
- var fieldsToRemoveInRoute = ["appId", "children", "creator", "ctime", "id", "instanceId", "graphInfo", "modifier", "mountPoint", "mtime", "org", "parent", "sort", "name", "providersBak", "providers_bak", "deleteAuthorizers", "readAuthorizers", "updateAuthorizers"];
21705
- var fieldsToRemoveInBrick = fieldsToRemoveInRoute.concat("type", "alias"); // Those fields can be disposed if value is null.
21749
+ var baseFieldsToRemove = ["appId", "children", "creator", "ctime", "id", "graphInfo", "modifier", "mountPoint", "mtime", "org", "parent", "sort", "name", "providersBak", "providers_bak", "deleteAuthorizers", "readAuthorizers", "updateAuthorizers"];
21750
+ var fieldsToRemoveInRoute = baseFieldsToRemove.concat("instanceId");
21751
+ var fieldsToRemoveInBrick = baseFieldsToRemove.concat("type", "alias"); // Those fields can be disposed if value is null.
21706
21752
 
21707
21753
  var disposableNullFields = ["alias", "documentId", "hybrid", "bg", "context", "exports", "ref", "portal", "analyticsData"];
21708
21754
  function normalizeBuilderNode(node) {
21709
21755
  if (isBrickNode(node)) {
21710
- return normalize(node, fieldsToRemoveInBrick, jsonFieldsInBrick, yamlFieldsInBrick, false);
21756
+ return normalize(node, fieldsToRemoveInBrick, jsonFieldsInBrick, yamlFieldsInBrick, "brick");
21711
21757
  }
21712
21758
 
21713
21759
  if (isRouteNode(node)) {
21714
- return normalize(node, fieldsToRemoveInRoute, jsonFieldsInRoute, yamlFieldsInRoute, true);
21760
+ return normalize(node, fieldsToRemoveInRoute, jsonFieldsInRoute, yamlFieldsInRoute, "route");
21715
21761
  }
21716
21762
 
21717
21763
  return null;
21718
21764
  }
21719
21765
 
21720
- function normalize(node, fieldsToRemove, jsonFields, yamlFields, cleanUpSegues) {
21766
+ function normalize(node, fieldsToRemove, jsonFields, yamlFields, type) {
21721
21767
  return Object.fromEntries(Object.entries(node) // Remove unused fields from CMDB.
21722
21768
  // Consider fields started with `_` as unused.
21723
21769
  .filter(_ref => {
@@ -21726,7 +21772,7 @@ function normalize(node, fieldsToRemove, jsonFields, yamlFields, cleanUpSegues)
21726
21772
  }) // Parse specific fields.
21727
21773
  .map(_ref2 => {
21728
21774
  var [key, value] = _ref2;
21729
- return [key, cleanUpSegues && key === "segues" ? getCleanSegues(value) : jsonFields.includes(key) ? safeJsonParse(value) : yamlFields.includes(key) ? safeYamlParse(value) : cloneDeep(value)];
21775
+ return [key === "instanceId" ? "iid" : key, type === "route" && key === "segues" ? getCleanSegues(value) : jsonFields.includes(key) ? safeJsonParse(value) : yamlFields.includes(key) ? safeYamlParse(value) : cloneDeep(value)];
21730
21776
  }));
21731
21777
  } // Clear `segue._view` which is for development only.
21732
21778
 
@@ -21808,8 +21854,6 @@ function deepFreeze(object) {
21808
21854
  return Object.freeze(object);
21809
21855
  }
21810
21856
 
21811
- var TRACK_CONTEXT = "track context";
21812
- var CTX = "CTX";
21813
21857
  /**
21814
21858
  * Get tracking CTX for an evaluable expression in `track context` mode.
21815
21859
  *
@@ -21838,7 +21882,14 @@ var CTX = "CTX";
21838
21882
  */
21839
21883
 
21840
21884
  function trackContext(raw) {
21841
- if (raw.includes(TRACK_CONTEXT)) {
21885
+ return track(raw, "track context", "CTX");
21886
+ }
21887
+ function trackState(raw) {
21888
+ return track(raw, "track state", "STATE");
21889
+ }
21890
+
21891
+ function track(raw, trackText, variableName) {
21892
+ if (raw.includes(trackText)) {
21842
21893
  var contexts = new Set();
21843
21894
  var {
21844
21895
  expression
@@ -21846,7 +21897,7 @@ function trackContext(raw) {
21846
21897
  withParent: true,
21847
21898
  hooks: {
21848
21899
  beforeVisitGlobal(node, parent) {
21849
- if (node.name === CTX) {
21900
+ if (node.name === variableName) {
21850
21901
  var memberParent = parent[parent.length - 1];
21851
21902
 
21852
21903
  if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
@@ -21865,12 +21916,12 @@ function trackContext(raw) {
21865
21916
  });
21866
21917
  var trackCtxExp;
21867
21918
 
21868
- if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === TRACK_CONTEXT) {
21919
+ if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === trackText) {
21869
21920
  if (contexts.size > 0) {
21870
21921
  return Array.from(contexts);
21871
21922
  } else {
21872
21923
  // eslint-disable-next-line no-console
21873
- console.warn("You are using \"".concat(TRACK_CONTEXT, "\" but no CTX usage found in your expression: \"").concat(raw, "\""));
21924
+ console.warn("You are using \"".concat(trackText, "\" but no `").concat(variableName, "` usage found in your expression: ").concat(JSON.stringify(raw)));
21874
21925
  }
21875
21926
  }
21876
21927
  }
@@ -21878,5 +21929,5 @@ function trackContext(raw) {
21878
21929
  return false;
21879
21930
  }
21880
21931
 
21881
- export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject, isRouteNode, isSnippetNode, lint, loadScript, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseForAnalysis, precook, precookFunction, preevaluate, prefetchScript, resolveContextConcurrently, restoreDynamicTemplates, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, toPath, tokTypes_1 as tokTypes, trackContext, transform, transformAndInject, visitStoryboardExpressions, visitStoryboardFunctions };
21932
+ export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject, isRouteNode, isSnippetNode, lint, loadScript, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseForAnalysis, precook, precookFunction, preevaluate, prefetchScript, resolveContextConcurrently, restoreDynamicTemplates, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackState, transform, transformAndInject, visitStoryboardExpressions, visitStoryboardFunctions };
21882
21933
  //# sourceMappingURL=index.esm.js.map