@oneblink/sdk-core 10.1.1 → 10.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.
@@ -1,11 +1,30 @@
1
1
  import evaluateFormElementConditionalPredicate from './evaluateFormElementConditionalPredicate.js';
2
+ // A `FormElementsCtrl` is never mutated after it is created, so results can be
3
+ // cached against it. Without caching, forms that chain pages together (e.g.
4
+ // page N is shown based on an element on page N - 1) re-evaluate every previous
5
+ // page for each predicate, which grows exponentially with the number of pages.
6
+ const parentElementsCache = new WeakMap();
7
+ const conditionallyShownCache = new WeakMap();
8
+ const getParentElementsById = (formElementsCtrl) => {
9
+ let parentElementsById = parentElementsCache.get(formElementsCtrl);
10
+ if (!parentElementsById) {
11
+ parentElementsById = new Map();
12
+ for (const element of formElementsCtrl.flattenedElements) {
13
+ if (element.type === 'page' || element.type === 'section') {
14
+ for (const { id } of element.elements) {
15
+ if (!parentElementsById.has(id)) {
16
+ parentElementsById.set(id, element);
17
+ }
18
+ }
19
+ }
20
+ }
21
+ parentElementsCache.set(formElementsCtrl, parentElementsById);
22
+ }
23
+ return parentElementsById;
24
+ };
2
25
  const getParentFormElements = (formElementsCtrl, childElement) => {
3
- const parentElement = formElementsCtrl.flattenedElements.find((element) => {
4
- return ((element.type === 'page' || element.type === 'section') &&
5
- element.elements.some(({ id }) => id === childElement.id));
6
- });
7
- if (parentElement &&
8
- (parentElement.type === 'page' || parentElement.type === 'section')) {
26
+ const parentElement = getParentElementsById(formElementsCtrl).get(childElement.id);
27
+ if (parentElement) {
9
28
  return [
10
29
  parentElement,
11
30
  ...getParentFormElements(formElementsCtrl, parentElement),
@@ -52,6 +71,15 @@ export default function conditionallyShowElement({ formElementsCtrl, elementToEv
52
71
  return true;
53
72
  }
54
73
  const conditionallyShowPredicates = elementToEvaluate.conditionallyShowPredicates;
74
+ let conditionallyShownByElement = conditionallyShownCache.get(formElementsCtrl);
75
+ if (!conditionallyShownByElement) {
76
+ conditionallyShownByElement = new Map();
77
+ conditionallyShownCache.set(formElementsCtrl, conditionallyShownByElement);
78
+ }
79
+ const cachedResult = conditionallyShownByElement.get(elementToEvaluate);
80
+ if (cachedResult !== undefined) {
81
+ return cachedResult;
82
+ }
55
83
  // Check to see if this element has already been used to evaluate
56
84
  // if the element should be shown based on parent element conditional logic
57
85
  const elementAlreadyEvaluated = elementsEvaluated.find(({ id }) => id === elementToEvaluate.id);
@@ -76,11 +104,10 @@ export default function conditionallyShowElement({ formElementsCtrl, elementToEv
76
104
  elementsEvaluated: [...elementsEvaluated],
77
105
  });
78
106
  };
79
- if (elementToEvaluate.requiresAllConditionallyShowPredicates) {
80
- return conditionallyShowPredicates.every(predicateFunction);
81
- }
82
- else {
83
- return conditionallyShowPredicates.some(predicateFunction);
84
- }
107
+ const result = elementToEvaluate.requiresAllConditionallyShowPredicates
108
+ ? conditionallyShowPredicates.every(predicateFunction)
109
+ : conditionallyShowPredicates.some(predicateFunction);
110
+ conditionallyShownByElement.set(elementToEvaluate, result);
111
+ return result;
85
112
  }
86
113
  //# sourceMappingURL=conditionallyShowElement.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":"AAEA,OAAO,uCAAuC,MAAM,8CAA8C,CAAA;AAElG,MAAM,qBAAqB,GAAG,CAC5B,gBAAkC,EAClC,YAAmC,EACsB,EAAE;IAC3D,MAAM,aAAa,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxE,OAAO,CACL,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;YACvD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAC1D,CAAA;IACH,CAAC,C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AAC,2BAA2B,CAAC;QAC7D,CAAC,iBAAiB,CAAC,2BAA2B,CAAC,MAAM,EACrD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,2BAA2B,GAC/B,iBAAiB,CAAC,2BAA2B,CAAA;IAE/C,iEAAiE;IACjE,2EAA2E;IAC3E,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI,CACpD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,iBAAiB,CAAC,EAAE,CACxC,CAAA;IACD,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,kEAAkE,uBAAuB,CAAC,KAAK,sGAAsG,CACtM,CAAA;IACH,CAAC;SAAM,CAAC;QACN,iBAAiB,CAAC,IAAI,CAAC;YACrB,EAAE,EAAE,iBAAiB,CAAC,EAAE;YACxB,KAAK,EACH,OAAO,IAAI,iBAAiB;gBAC1B,CAAC,CAAC,iBAAiB,CAAC,KAAK;gBACzB,CAAC,CAAC,iBAAiB,CAAC,IAAI;SAC7B,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,iBAAiB,GAAG,CACxB,SAAyD,EACzD,EAAE;QACF,oEAAoE;QACpE,iEAAiE;QACjE,yBAAyB;QACzB,OAAO,4BAA4B,CAAC;YAClC,gBAAgB;YAChB,SAAS;YACT,iBAAiB,EAAE,CAAC,GAAG,iBAAiB,CAAC;SAC1C,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,IAAI,iBAAiB,CAAC,sCAAsC,EAAE,CAAC;QAC7D,OAAO,2BAA2B,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAC7D,CAAC;SAAM,CAAC;QACN,OAAO,2BAA2B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types.js'\nimport evaluateFormElementConditionalPredicate from './evaluateFormElementConditionalPredicate.js'\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = formElementsCtrl.flattenedElements.find((element) => {\n return (\n (element.type === 'page' || element.type === 'section') &&\n element.elements.some(({ id }) => id === childElement.id)\n )\n })\n if (\n parentElement &&\n (parentElement.type === 'page' || parentElement.type === 'section')\n ) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nexport function conditionallyShowByPredicate({\n formElementsCtrl,\n predicate,\n elementsEvaluated,\n}: {\n formElementsCtrl: FormElementsCtrl\n predicate: ConditionTypes.FormElementConditionalPredicate\n elementsEvaluated: Array<{ id: string; label: string }>\n}): boolean {\n const predicateElement = evaluateFormElementConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n\n if (!predicateElement) {\n return false\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement({\n formElementsCtrl,\n elementToEvaluate: parentFormElement,\n elementsEvaluated: [...elementsEvaluated],\n })\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return conditionallyShowElement({\n formElementsCtrl,\n elementToEvaluate: predicateElement,\n elementsEvaluated,\n })\n}\n\nexport default function conditionallyShowElement({\n formElementsCtrl,\n elementToEvaluate,\n elementsEvaluated,\n}: {\n formElementsCtrl: FormElementsCtrl\n elementToEvaluate: FormTypes.FormElement\n elementsEvaluated: Array<{ id: string; label: string }>\n}): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n 'label' in elementToEvaluate\n ? elementToEvaluate.label\n : elementToEvaluate.name,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.FormElementConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate({\n formElementsCtrl,\n predicate,\n elementsEvaluated: [...elementsEvaluated],\n })\n }\n\n if (elementToEvaluate.requiresAllConditionallyShowPredicates) {\n return conditionallyShowPredicates.every(predicateFunction)\n } else {\n return conditionallyShowPredicates.some(predicateFunction)\n }\n}\n"]}
1
+ {"version":3,"file":"conditionallyShowElement.js","sourceRoot":"","sources":["../../src/conditionalLogicService/conditionallyShowElement.ts"],"names":[],"mappings":"AAEA,OAAO,uCAAuC,MAAM,8CAA8C,CAAA;AAElG,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,+EAA+E;AAC/E,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAGpC,CAAA;AACH,MAAM,uBAAuB,GAAG,IAAI,OAAO,EAGxC,CAAA;AAEH,MAAM,qBAAqB,GAAG,CAAC,gBAAkC,EAAE,EAAE;IACnE,IAAI,kBAAkB,GAAG,mBAAmB,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IAClE,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAA;QAC9B,KAAK,M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I,CACpD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,iBAAiB,CAAC,EAAE,CACxC,CAAA;IACD,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,kEAAkE,uBAAuB,CAAC,KAAK,sGAAsG,CACtM,CAAA;IACH,CAAC;SAAM,CAAC;QACN,iBAAiB,CAAC,IAAI,CAAC;YACrB,EAAE,EAAE,iBAAiB,CAAC,EAAE;YACxB,KAAK,EACH,OAAO,IAAI,iBAAiB;gBAC1B,CAAC,CAAC,iBAAiB,CAAC,KAAK;gBACzB,CAAC,CAAC,iBAAiB,CAAC,IAAI;SAC7B,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,iBAAiB,GAAG,CACxB,SAAyD,EACzD,EAAE;QACF,oEAAoE;QACpE,iEAAiE;QACjE,yBAAyB;QACzB,OAAO,4BAA4B,CAAC;YAClC,gBAAgB;YAChB,SAAS;YACT,iBAAiB,EAAE,CAAC,GAAG,iBAAiB,CAAC;SAC1C,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,sCAAsC;QACrE,CAAC,CAAC,2BAA2B,CAAC,KAAK,CAAC,iBAAiB,CAAC;QACtD,CAAC,CAAC,2BAA2B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IACvD,2BAA2B,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;IAC1D,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { FormTypes, ConditionTypes } from '@oneblink/types'\nimport { FormElementsCtrl } from './types.js'\nimport evaluateFormElementConditionalPredicate from './evaluateFormElementConditionalPredicate.js'\n\n// A `FormElementsCtrl` is never mutated after it is created, so results can be\n// cached against it. Without caching, forms that chain pages together (e.g.\n// page N is shown based on an element on page N - 1) re-evaluate every previous\n// page for each predicate, which grows exponentially with the number of pages.\nconst parentElementsCache = new WeakMap<\n FormElementsCtrl,\n Map<string, FormTypes.SectionElement | FormTypes.PageElement>\n>()\nconst conditionallyShownCache = new WeakMap<\n FormElementsCtrl,\n Map<FormTypes.FormElement, boolean>\n>()\n\nconst getParentElementsById = (formElementsCtrl: FormElementsCtrl) => {\n let parentElementsById = parentElementsCache.get(formElementsCtrl)\n if (!parentElementsById) {\n parentElementsById = new Map()\n for (const element of formElementsCtrl.flattenedElements) {\n if (element.type === 'page' || element.type === 'section') {\n for (const { id } of element.elements) {\n if (!parentElementsById.has(id)) {\n parentElementsById.set(id, element)\n }\n }\n }\n }\n parentElementsCache.set(formElementsCtrl, parentElementsById)\n }\n return parentElementsById\n}\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = getParentElementsById(formElementsCtrl).get(\n childElement.id,\n )\n if (parentElement) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nexport function conditionallyShowByPredicate({\n formElementsCtrl,\n predicate,\n elementsEvaluated,\n}: {\n formElementsCtrl: FormElementsCtrl\n predicate: ConditionTypes.FormElementConditionalPredicate\n elementsEvaluated: Array<{ id: string; label: string }>\n}): boolean {\n const predicateElement = evaluateFormElementConditionalPredicate({\n predicate,\n formElementsCtrl,\n })\n\n if (!predicateElement) {\n return false\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement({\n formElementsCtrl,\n elementToEvaluate: parentFormElement,\n elementsEvaluated: [...elementsEvaluated],\n })\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return conditionallyShowElement({\n formElementsCtrl,\n elementToEvaluate: predicateElement,\n elementsEvaluated,\n })\n}\n\nexport default function conditionallyShowElement({\n formElementsCtrl,\n elementToEvaluate,\n elementsEvaluated,\n}: {\n formElementsCtrl: FormElementsCtrl\n elementToEvaluate: FormTypes.FormElement\n elementsEvaluated: Array<{ id: string; label: string }>\n}): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n let conditionallyShownByElement =\n conditionallyShownCache.get(formElementsCtrl)\n if (!conditionallyShownByElement) {\n conditionallyShownByElement = new Map()\n conditionallyShownCache.set(formElementsCtrl, conditionallyShownByElement)\n }\n const cachedResult = conditionallyShownByElement.get(elementToEvaluate)\n if (cachedResult !== undefined) {\n return cachedResult\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n 'label' in elementToEvaluate\n ? elementToEvaluate.label\n : elementToEvaluate.name,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.FormElementConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate({\n formElementsCtrl,\n predicate,\n elementsEvaluated: [...elementsEvaluated],\n })\n }\n\n const result = elementToEvaluate.requiresAllConditionallyShowPredicates\n ? conditionallyShowPredicates.every(predicateFunction)\n : conditionallyShowPredicates.some(predicateFunction)\n conditionallyShownByElement.set(elementToEvaluate, result)\n return result\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/sdk-core",
3
3
  "description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
4
- "version": "10.1.1",
4
+ "version": "10.2.0",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/sdk-core-js/issues"