@raytio/core 9.0.3 → 10.1.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 (145) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/README.md +77 -4
  3. package/dist/accessApplication/createAA.d.ts +17 -17
  4. package/dist/accessApplication/createAA.js +71 -71
  5. package/dist/accessApplication/index.d.ts +1 -1
  6. package/dist/accessApplication/index.js +17 -13
  7. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  8. package/dist/crypto/cognitoAttributes.js +33 -33
  9. package/dist/crypto/decryptKeys.d.ts +1 -1
  10. package/dist/crypto/decryptKeys.js +33 -33
  11. package/dist/crypto/decryptSharedData.d.ts +26 -26
  12. package/dist/crypto/decryptSharedData.js +38 -38
  13. package/dist/crypto/getAADecryptor.d.ts +16 -11
  14. package/dist/crypto/getAADecryptor.js +20 -20
  15. package/dist/crypto/helpers.d.ts +18 -18
  16. package/dist/crypto/helpers.js +26 -26
  17. package/dist/crypto/index.d.ts +4 -4
  18. package/dist/crypto/index.js +21 -17
  19. package/dist/general/conditional.d.ts +17 -7
  20. package/dist/general/conditional.js +32 -22
  21. package/dist/general/date.d.ts +2 -0
  22. package/dist/general/date.js +18 -0
  23. package/dist/general/index.d.ts +4 -3
  24. package/dist/general/index.js +20 -15
  25. package/dist/general/password.d.ts +10 -8
  26. package/dist/general/password.js +31 -29
  27. package/dist/general/types.d.ts +6 -6
  28. package/dist/general/types.js +13 -13
  29. package/dist/index.d.ts +6 -6
  30. package/dist/index.js +22 -18
  31. package/dist/rules/calculateScore.d.ts +23 -11
  32. package/dist/rules/calculateScore.js +76 -52
  33. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  34. package/dist/rules/convertInstanceToRuleInput.js +139 -139
  35. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  36. package/dist/rules/evaluateScoreCondition.js +45 -45
  37. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  38. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  39. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -3
  40. package/dist/rules/helpers/checkTypeofValue.js +55 -43
  41. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  42. package/dist/rules/helpers/getLhsTypeofValue.js +1 -0
  43. package/dist/rules/helpers/getValueFromPath.d.ts +2 -0
  44. package/dist/rules/helpers/getValueFromPath.js +35 -0
  45. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  46. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  47. package/dist/rules/helpers/index.d.ts +5 -5
  48. package/dist/rules/helpers/index.js +21 -17
  49. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +3 -0
  50. package/dist/rules/helpers/rebuildInfiniteValues.js +6 -0
  51. package/dist/rules/helpers/symbols.d.ts +2 -2
  52. package/dist/rules/helpers/symbols.js +5 -5
  53. package/dist/rules/helpers/thresholds.d.ts +5 -5
  54. package/dist/rules/helpers/thresholds.js +47 -47
  55. package/dist/rules/index.d.ts +7 -6
  56. package/dist/rules/index.js +25 -20
  57. package/dist/rules/isScoreResultValid.d.ts +2 -0
  58. package/dist/rules/isScoreResultValid.js +9 -0
  59. package/dist/rules/operators/array.d.ts +2 -0
  60. package/dist/rules/operators/array.js +74 -0
  61. package/dist/rules/operators/bool.d.ts +2 -2
  62. package/dist/rules/operators/bool.js +17 -17
  63. package/dist/rules/operators/date.d.ts +2 -2
  64. package/dist/rules/operators/date.js +91 -91
  65. package/dist/rules/operators/hfield.d.ts +2 -2
  66. package/dist/rules/operators/hfield.js +33 -33
  67. package/dist/rules/operators/hschema.d.ts +2 -2
  68. package/dist/rules/operators/hschema.js +21 -21
  69. package/dist/rules/operators/index.d.ts +3 -3
  70. package/dist/rules/operators/index.js +11 -11
  71. package/dist/rules/operators/number.d.ts +2 -2
  72. package/dist/rules/operators/number.js +41 -41
  73. package/dist/rules/operators/string.d.ts +2 -2
  74. package/dist/rules/operators/string.js +58 -58
  75. package/dist/rules/types/config.d.ts +91 -86
  76. package/dist/rules/types/config.js +2 -2
  77. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  78. package/dist/rules/types/dataValueTypes.js +4 -4
  79. package/dist/rules/types/index.d.ts +3 -3
  80. package/dist/rules/types/index.js +19 -15
  81. package/dist/rules/types/internal.d.ts +20 -20
  82. package/dist/rules/types/internal.js +2 -2
  83. package/dist/rules/types/operators.d.ts +19 -0
  84. package/dist/rules/types/operators.js +2 -0
  85. package/dist/rules/types/score.d.ts +50 -0
  86. package/dist/rules/types/score.js +2 -0
  87. package/dist/rules/validate.d.ts +6 -0
  88. package/dist/rules/validate.js +14 -0
  89. package/dist/rules/version.d.ts +1 -0
  90. package/dist/rules/version.js +5 -0
  91. package/dist/schema/index.d.ts +1 -1
  92. package/dist/schema/index.js +17 -13
  93. package/dist/schema/labels.d.ts +2 -2
  94. package/dist/schema/labels.js +20 -20
  95. package/dist/util/canonicalJsonify.d.ts +1 -1
  96. package/dist/util/canonicalJsonify.js +50 -50
  97. package/dist/util/conditional.d.ts +7 -0
  98. package/dist/util/conditional.js +15 -0
  99. package/dist/util/handleResponse.d.ts +1 -1
  100. package/dist/util/handleResponse.js +21 -21
  101. package/dist/util/hash.d.ts +1 -0
  102. package/dist/util/hash.js +11 -0
  103. package/dist/util/index.d.ts +2 -2
  104. package/dist/util/index.js +18 -14
  105. package/dist/verifications/checkSingleVerification.d.ts +9 -0
  106. package/dist/verifications/checkSingleVerification.js +29 -0
  107. package/dist/verifications/checkVerifications.d.ts +1 -0
  108. package/dist/verifications/checkVerifications.js +16 -0
  109. package/dist/verifications/checkVerificationsNew.d.ts +1 -0
  110. package/dist/verifications/checkVerificationsNew.js +16 -0
  111. package/dist/verifications/cleanInstance.d.ts +9 -9
  112. package/dist/verifications/cleanInstance.js +15 -15
  113. package/dist/verifications/getOwnRealVerifications.d.ts +14 -0
  114. package/dist/verifications/getOwnRealVerifications.js +64 -0
  115. package/dist/verifications/getPOVerification.d.ts +16 -16
  116. package/dist/verifications/getPOVerification.js +94 -94
  117. package/dist/verifications/getRealVerifications.d.ts +22 -0
  118. package/dist/verifications/getRealVerifications.js +71 -0
  119. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  120. package/dist/verifications/getVerifiedBy.js +19 -19
  121. package/dist/verifications/index.d.ts +5 -5
  122. package/dist/verifications/index.js +21 -17
  123. package/dist/verifications/maybeRereference.d.ts +1 -1
  124. package/dist/verifications/maybeRereference.js +10 -10
  125. package/dist/verifications/safeHarbour.d.ts +20 -20
  126. package/dist/verifications/safeHarbour.js +74 -74
  127. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  128. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +64 -63
  129. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  130. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -71
  131. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  132. package/dist/verifications/verifyCheck/index.js +21 -17
  133. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  134. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  135. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  136. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  137. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  138. package/dist/verifications/verifyCheck/operations/index.js +18 -14
  139. package/dist/verifications/verifyCheck/util/canonicalJsonify.d.ts +1 -0
  140. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +48 -0
  141. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +2 -0
  142. package/dist/verifications/verifyCheck/util/getValuesForAField.js +9 -0
  143. package/dist/verifications/verifyCheck/util/index.d.ts +2 -0
  144. package/dist/verifications/verifyCheck/util/index.js +14 -0
  145. package/package.json +6 -5
@@ -1,45 +1,45 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.evaluateScoreCondition = void 0;
4
- /* eslint-disable fp/no-loops */
5
- const ramda_1 = require("ramda");
6
- const general_1 = require("../general");
7
- const operators_1 = require("./operators");
8
- const helpers_1 = require("./helpers");
9
- function evaluateScoreCondition(node, data) {
10
- (0, general_1.assertSafeProperty)(node.operator);
11
- const op = operators_1.operators[node.operator];
12
- if (!op) {
13
- throw new Error(`Operator '${node.operator}' is not known`);
14
- }
15
- if (node.values.length !== op.operands.length) {
16
- throw new Error(`Operator argument length mismatch for '${node.operator}'`);
17
- }
18
- const rawValues = node.values
19
- .map(x => x.value.type === "constant"
20
- ? [x.value.value]
21
- : (0, helpers_1.getValuesFromPath)(x.value.path, data))
22
- .map(valuesForArg => valuesForArg.filter(v => typeof v !== "undefined"));
23
- for (const [i, argType] of op.operands.entries()) {
24
- if (argType !== node.values[i].type) {
25
- throw new TypeError(`Operator argument ${i} expected ${argType} but got ${node.values[i].type} for '${node.operator}'`);
26
- }
27
- const values = rawValues[i];
28
- if (!values.length) {
29
- // TODO: if one of the values required for your rule doesn't exist, then what?
30
- // for now, the rule will return value
31
- return false;
32
- }
33
- // also check if the claimed type of the value matches the actual type of the value
34
- for (const value of values) {
35
- if (!(0, helpers_1.checkTypeofValue)(argType, value)) {
36
- throw new Error(`Operator argument ${i} falsely claimed to be ${argType} for '${node.operator}'`);
37
- }
38
- }
39
- }
40
- const options = (0, ramda_1.transpose)(rawValues);
41
- // everything adds up so far, so we can call the function for each
42
- // data value. Return true if ANY of the values return true.
43
- return options.some(args => op.implementation(...args));
44
- }
45
- exports.evaluateScoreCondition = evaluateScoreCondition;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateScoreCondition = void 0;
4
+ /* eslint-disable fp/no-loops */
5
+ const ramda_1 = require("ramda");
6
+ const general_1 = require("../general");
7
+ const operators_1 = require("./operators");
8
+ const helpers_1 = require("./helpers");
9
+ function evaluateScoreCondition(node, data) {
10
+ (0, general_1.assertSafeProperty)(node.operator);
11
+ const op = operators_1.operators[node.operator];
12
+ if (!op) {
13
+ throw new Error(`Operator '${node.operator}' is not known`);
14
+ }
15
+ if (node.values.length !== op.operands.length) {
16
+ throw new Error(`Operator argument length mismatch for '${node.operator}'`);
17
+ }
18
+ const rawValues = node.values
19
+ .map(x => x.value.type === "constant"
20
+ ? [x.value.value]
21
+ : (0, helpers_1.getValuesFromPath)(x.value.path, data))
22
+ .map(valuesForArg => valuesForArg.filter(v => typeof v !== "undefined"));
23
+ for (const [i, argType] of op.operands.entries()) {
24
+ if ((0, helpers_1.simplifyValueType)(argType) !== (0, helpers_1.simplifyValueType)(node.values[i].type)) {
25
+ throw new TypeError(`Operator argument ${i} expected ${argType} but got ${node.values[i].type} for '${node.operator}'`);
26
+ }
27
+ const values = rawValues[i];
28
+ if (!values.length) {
29
+ // TODO: if one of the values required for your rule doesn't exist, then what?
30
+ // for now, the rule will return false.
31
+ return false;
32
+ }
33
+ // also check if the claimed type of the value matches the actual type of the value
34
+ for (const value of values) {
35
+ if (!(0, helpers_1.checkTypeofValue)(argType, value)) {
36
+ throw new Error(`Operator argument ${i} falsely claimed to be ${argType} for '${node.operator}'`);
37
+ }
38
+ }
39
+ }
40
+ const options = (0, ramda_1.transpose)(rawValues);
41
+ // everything adds up so far, so we can call the function for each
42
+ // data value. Return true if ANY of the values return true.
43
+ return options.some(args => op.implementation(...args));
44
+ }
45
+ exports.evaluateScoreCondition = evaluateScoreCondition;
@@ -1,8 +1,8 @@
1
- import { ScoreThreshold } from "../types";
2
- /**
3
- * @ignore the first and last threshold boundaries are -Infinity and +Infinity.
4
- * We override whatever is specified to ensure these boundaries are infinite.
5
- *
6
- * This is also needed because json converts non-finite numbers to `null`
7
- */
8
- export declare const addInfiniteThresholdBoundaries: (list: readonly ScoreThreshold[]) => ScoreThreshold[];
1
+ import { ScoreThreshold } from "../types";
2
+ /**
3
+ * @ignore the first and last threshold boundaries are -Infinity and +Infinity.
4
+ * We override whatever is specified to ensure these boundaries are infinite.
5
+ *
6
+ * This is also needed because json converts non-finite numbers to `null`
7
+ */
8
+ export declare const addInfiniteThresholdBoundaries: (list: readonly ScoreThreshold[]) => ScoreThreshold[];
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addInfiniteThresholdBoundaries = void 0;
4
- const ramda_1 = require("ramda");
5
- /**
6
- * @ignore the first and last threshold boundaries are -Infinity and +Infinity.
7
- * We override whatever is specified to ensure these boundaries are infinite.
8
- *
9
- * This is also needed because json converts non-finite numbers to `null`
10
- */
11
- exports.addInfiniteThresholdBoundaries = (0, ramda_1.pipe)((0, ramda_1.adjust)(0, v => (Object.assign(Object.assign({}, v), { from: -Infinity }))), (0, ramda_1.adjust)(-1, v => (Object.assign(Object.assign({}, v), { to: Infinity }))));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addInfiniteThresholdBoundaries = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /**
6
+ * @ignore the first and last threshold boundaries are -Infinity and +Infinity.
7
+ * We override whatever is specified to ensure these boundaries are infinite.
8
+ *
9
+ * This is also needed because json converts non-finite numbers to `null`
10
+ */
11
+ exports.addInfiniteThresholdBoundaries = (0, ramda_1.pipe)((0, ramda_1.adjust)(0, v => (Object.assign(Object.assign({}, v), { from: -Infinity }))), (0, ramda_1.adjust)(-1, v => (Object.assign(Object.assign({}, v), { to: Infinity }))));
@@ -1,3 +1,9 @@
1
- import { GetTSType, ValueType } from "../types";
2
- /** asserts that the provided `value` meets the constaints of `type` */
3
- export declare function checkTypeofValue<T extends ValueType>(type: T, value: unknown): value is GetTSType<T>;
1
+ import { GetTSType, ValueType } from "../types";
2
+ /** asserts that the provided `value` meets the constaints of `type` */
3
+ export declare function checkTypeofValue<T extends ValueType>(type: T, value: unknown): value is GetTSType<T>;
4
+ /**
5
+ * Some types are effectively equivilant (e.g. n_id and string).
6
+ * Any exceptions defined here should use the same validator in
7
+ * `checkTypeofValue` above.
8
+ */
9
+ export declare function simplifyValueType(type: ValueType): ValueType;
@@ -1,43 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkTypeofValue = void 0;
4
- const types_1 = require("@raytio/types");
5
- const symbols_1 = require("./symbols");
6
- const types_2 = require("../types");
7
- const VALID_DATE_UNITS = types_2.DATE_UNITS;
8
- // we need this function beacuse TS's typeguards aren't great
9
- const isObjectWithTypeofProp = (x) => typeof x === "object" && !!x && "__typeof__" in x;
10
- /** asserts that the provided `value` meets the constaints of `type` */
11
- function checkTypeofValue(type, value) {
12
- switch (type) {
13
- case "Array":
14
- return Array.isArray(value);
15
- case "Bool":
16
- return typeof value === "boolean";
17
- case "Date":
18
- return value instanceof Date;
19
- case "DateUnit":
20
- return typeof value === "string" && VALID_DATE_UNITS.includes(value);
21
- case "FieldVerification":
22
- return typeof value === "number" && value in types_1.FieldVerification;
23
- case "HField":
24
- // this is fakeable (you could make a constant object with these props),
25
- // but that's not a concern in this context.
26
- return isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HFieldSymbol;
27
- case "HSchema":
28
- // this is fakeable (you could make a constant object with these props),
29
- // but that's not a concern in this context.
30
- return (isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HSchemaSymbol);
31
- case "Number":
32
- return typeof value === "number";
33
- case "POVerification":
34
- return typeof value === "number" && value in types_1.POVerification;
35
- case "RegEx":
36
- return value instanceof RegExp;
37
- case "String":
38
- return typeof value === "string";
39
- default:
40
- return false;
41
- }
42
- }
43
- exports.checkTypeofValue = checkTypeofValue;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simplifyValueType = exports.checkTypeofValue = void 0;
4
+ const types_1 = require("@raytio/types");
5
+ const symbols_1 = require("./symbols");
6
+ const types_2 = require("../types");
7
+ const VALID_DATE_UNITS = types_2.DATE_UNITS;
8
+ // we need this function beacuse TS's typeguards aren't great
9
+ const isObjectWithTypeofProp = (x) => typeof x === "object" && !!x && "__typeof__" in x;
10
+ /** asserts that the provided `value` meets the constaints of `type` */
11
+ function checkTypeofValue(type, value) {
12
+ switch (type) {
13
+ case "Array":
14
+ return Array.isArray(value);
15
+ case "Bool":
16
+ return typeof value === "boolean";
17
+ case "Date":
18
+ return value instanceof Date;
19
+ case "DateUnit":
20
+ return typeof value === "string" && VALID_DATE_UNITS.includes(value);
21
+ case "FieldVerification":
22
+ return typeof value === "number" && value in types_1.FieldVerification;
23
+ case "HField":
24
+ // this is fakeable (you could make a constant object with these props),
25
+ // but that's not a concern in this context.
26
+ return isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HFieldSymbol;
27
+ case "HSchema":
28
+ // this is fakeable (you could make a constant object with these props),
29
+ // but that's not a concern in this context.
30
+ return (isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HSchemaSymbol);
31
+ case "Number":
32
+ return typeof value === "number";
33
+ case "POVerification":
34
+ return typeof value === "number" && value in types_1.POVerification;
35
+ case "RegEx":
36
+ return value instanceof RegExp;
37
+ case "Verifier":
38
+ case "String":
39
+ return typeof value === "string";
40
+ default:
41
+ return false;
42
+ }
43
+ }
44
+ exports.checkTypeofValue = checkTypeofValue;
45
+ /**
46
+ * Some types are effectively equivilant (e.g. n_id and string).
47
+ * Any exceptions defined here should use the same validator in
48
+ * `checkTypeofValue` above.
49
+ */
50
+ function simplifyValueType(type) {
51
+ if (type === "Verifier")
52
+ return "String";
53
+ return type;
54
+ }
55
+ exports.simplifyValueType = simplifyValueType;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+ import { RuleData, ValuePath } from "../types";
2
+ export declare function getValueFromPath(path: ValuePath, data: RuleData): unknown;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValueFromPath = void 0;
4
+ const general_1 = require("../../general");
5
+ function getValueFromPath(path, data) {
6
+ var _a, _b, _c, _d, _e;
7
+ const type = path.split("|")[0];
8
+ switch (type) {
9
+ case "field": {
10
+ const [, schemaName, fieldName, attr] = path.split("|");
11
+ (0, general_1.assertSafeProperty)(schemaName);
12
+ (0, general_1.assertSafeProperty)(fieldName);
13
+ (0, general_1.assertSafeProperty)(attr);
14
+ if (attr === "meta") {
15
+ return (_b = (_a = data[schemaName]) === null || _a === void 0 ? void 0 : _a.properties[fieldName]) === null || _b === void 0 ? void 0 : _b.hField;
16
+ }
17
+ if (attr === "value") {
18
+ return (_d = (_c = data[schemaName]) === null || _c === void 0 ? void 0 : _c.properties[fieldName]) === null || _d === void 0 ? void 0 : _d.value;
19
+ }
20
+ throw new Error(`Invalid ValuePath[3] for field (${attr})`);
21
+ }
22
+ case "schema": {
23
+ const [, schemaName, attr] = path.split("|");
24
+ (0, general_1.assertSafeProperty)(schemaName);
25
+ (0, general_1.assertSafeProperty)(attr);
26
+ if (attr === "meta") {
27
+ return (_e = data[schemaName]) === null || _e === void 0 ? void 0 : _e.hSchema;
28
+ }
29
+ throw new Error(`Invalid ValuePath[2] for schema (${attr})`);
30
+ }
31
+ default:
32
+ throw new Error(`Invalid ValuePath[0] (${type})`);
33
+ }
34
+ }
35
+ exports.getValueFromPath = getValueFromPath;
@@ -1,3 +1,3 @@
1
- import { RuleData, ValuePath } from "../types";
2
- /** this returns an array because there might be multiple of the same schema shared */
3
- export declare function getValuesFromPath(path: ValuePath, data: RuleData): unknown[];
1
+ import { RuleData, ValuePath } from "../types";
2
+ /** this returns an array because there might be multiple of the same schema shared */
3
+ export declare function getValuesFromPath(path: ValuePath, data: RuleData): unknown[];
@@ -1,50 +1,50 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValuesFromPath = void 0;
4
- const general_1 = require("../../general");
5
- /** this returns an array because there might be multiple of the same schema shared */
6
- function getValuesFromPath(path, data) {
7
- var _a, _b, _c, _d;
8
- const type = path[0];
9
- switch (type) {
10
- case "field": {
11
- const [, schemaName, fieldName, attr] = path;
12
- (0, general_1.assertSafeProperty)(schemaName);
13
- (0, general_1.assertSafeProperty)(fieldName);
14
- (0, general_1.assertSafeProperty)(attr);
15
- if (attr === "meta") {
16
- return (((_a = data[schemaName]) === null || _a === void 0 ? void 0 : _a.map(x => { var _a; return (_a = x.properties[fieldName]) === null || _a === void 0 ? void 0 : _a.hField; })) || []);
17
- }
18
- const values = ((_b = data[schemaName]) === null || _b === void 0 ? void 0 : _b.map(x => { var _a; return (_a = x.properties[fieldName]) === null || _a === void 0 ? void 0 : _a.value; })) || [];
19
- if (attr === "value")
20
- return values;
21
- if (attr === "valueLength") {
22
- return values.map(v => {
23
- if (typeof v === "string" || Array.isArray(v))
24
- return v.length;
25
- throw new Error("valueLength may only be used on arrays and strings");
26
- });
27
- }
28
- if (attr === null || attr === void 0 ? void 0 : attr.startsWith("subField|")) {
29
- const subFieldName = attr.slice(9);
30
- (0, general_1.assertSafeProperty)(subFieldName);
31
- const key = `${fieldName}|${subFieldName}`;
32
- const subValueList = ((_c = data[schemaName]) === null || _c === void 0 ? void 0 : _c.map(x => { var _a; return (_a = x.properties[key]) === null || _a === void 0 ? void 0 : _a.value; })) || [];
33
- return subValueList;
34
- }
35
- throw new Error(`Invalid ValuePath[3] for field (${attr})`);
36
- }
37
- case "schema": {
38
- const [, schemaName, attr] = path;
39
- (0, general_1.assertSafeProperty)(schemaName);
40
- (0, general_1.assertSafeProperty)(attr);
41
- if (attr === "meta") {
42
- return ((_d = data[schemaName]) === null || _d === void 0 ? void 0 : _d.map(x => x.hSchema)) || [];
43
- }
44
- throw new Error(`Invalid ValuePath[2] for schema (${attr})`);
45
- }
46
- default:
47
- throw new Error(`Invalid ValuePath[0] (${type})`);
48
- }
49
- }
50
- exports.getValuesFromPath = getValuesFromPath;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValuesFromPath = void 0;
4
+ const general_1 = require("../../general");
5
+ /** this returns an array because there might be multiple of the same schema shared */
6
+ function getValuesFromPath(path, data) {
7
+ var _a, _b, _c, _d;
8
+ const type = path[0];
9
+ switch (type) {
10
+ case "field": {
11
+ const [, schemaName, fieldName, attr] = path;
12
+ (0, general_1.assertSafeProperty)(schemaName);
13
+ (0, general_1.assertSafeProperty)(fieldName);
14
+ (0, general_1.assertSafeProperty)(attr);
15
+ if (attr === "meta") {
16
+ return (((_a = data[schemaName]) === null || _a === void 0 ? void 0 : _a.map(x => { var _a; return (_a = x.properties[fieldName]) === null || _a === void 0 ? void 0 : _a.hField; })) || []);
17
+ }
18
+ const values = ((_b = data[schemaName]) === null || _b === void 0 ? void 0 : _b.map(x => { var _a; return (_a = x.properties[fieldName]) === null || _a === void 0 ? void 0 : _a.value; })) || [];
19
+ if (attr === "value")
20
+ return values;
21
+ if (attr === "valueLength") {
22
+ return values.map(v => {
23
+ if (typeof v === "string" || Array.isArray(v))
24
+ return v.length;
25
+ throw new Error("valueLength may only be used on arrays and strings");
26
+ });
27
+ }
28
+ if (attr === null || attr === void 0 ? void 0 : attr.startsWith("subField|")) {
29
+ const subFieldName = attr.slice(9);
30
+ (0, general_1.assertSafeProperty)(subFieldName);
31
+ const key = `${fieldName}|${subFieldName}`;
32
+ const subValueList = ((_c = data[schemaName]) === null || _c === void 0 ? void 0 : _c.map(x => { var _a; return (_a = x.properties[key]) === null || _a === void 0 ? void 0 : _a.value; })) || [];
33
+ return subValueList;
34
+ }
35
+ throw new Error(`Invalid ValuePath[3] for field (${attr})`);
36
+ }
37
+ case "schema": {
38
+ const [, schemaName, attr] = path;
39
+ (0, general_1.assertSafeProperty)(schemaName);
40
+ (0, general_1.assertSafeProperty)(attr);
41
+ if (attr === "meta") {
42
+ return ((_d = data[schemaName]) === null || _d === void 0 ? void 0 : _d.map(x => x.hSchema)) || [];
43
+ }
44
+ throw new Error(`Invalid ValuePath[2] for schema (${attr})`);
45
+ }
46
+ default:
47
+ throw new Error(`Invalid ValuePath[0] (${type})`);
48
+ }
49
+ }
50
+ exports.getValuesFromPath = getValuesFromPath;
@@ -1,5 +1,5 @@
1
- export * from "./addInfiniteThresholdBoundaries";
2
- export * from "./checkTypeofValue";
3
- export * from "./getValuesFromPath";
4
- export * from "./symbols";
5
- export * from "./thresholds";
1
+ export * from "./addInfiniteThresholdBoundaries";
2
+ export * from "./checkTypeofValue";
3
+ export * from "./getValuesFromPath";
4
+ export * from "./symbols";
5
+ export * from "./thresholds";
@@ -1,17 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./addInfiniteThresholdBoundaries"), exports);
14
- __exportStar(require("./checkTypeofValue"), exports);
15
- __exportStar(require("./getValuesFromPath"), exports);
16
- __exportStar(require("./symbols"), exports);
17
- __exportStar(require("./thresholds"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./addInfiniteThresholdBoundaries"), exports);
18
+ __exportStar(require("./checkTypeofValue"), exports);
19
+ __exportStar(require("./getValuesFromPath"), exports);
20
+ __exportStar(require("./symbols"), exports);
21
+ __exportStar(require("./thresholds"), exports);
@@ -0,0 +1,3 @@
1
+ import { ScoreThreshold } from "../types";
2
+ /** @ignore json converts non-finite numbers to `null` so we need to fix this */
3
+ export declare const rebuildInfiniteValues: (list: readonly ScoreThreshold[]) => ScoreThreshold[];
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rebuildInfiniteValues = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /** @ignore json converts non-finite numbers to `null` so we need to fix this */
6
+ exports.rebuildInfiniteValues = (0, ramda_1.pipe)((0, ramda_1.adjust)(0, v => (Object.assign(Object.assign({}, v), { from: -Infinity }))), (0, ramda_1.adjust)(-1, v => (Object.assign(Object.assign({}, v), { to: Infinity }))));
@@ -1,2 +1,2 @@
1
- export declare const HFieldSymbol: unique symbol;
2
- export declare const HSchemaSymbol: unique symbol;
1
+ export declare const HFieldSymbol: unique symbol;
2
+ export declare const HSchemaSymbol: unique symbol;
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HSchemaSymbol = exports.HFieldSymbol = void 0;
4
- exports.HFieldSymbol = Symbol("HField");
5
- exports.HSchemaSymbol = Symbol("HSchema");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HSchemaSymbol = exports.HFieldSymbol = void 0;
4
+ exports.HFieldSymbol = Symbol("HField");
5
+ exports.HSchemaSymbol = Symbol("HSchema");
@@ -1,5 +1,5 @@
1
- import { Combinator, ScoreRule } from "../types";
2
- /** @ignore */
3
- export declare function getCombinator(combinator: Combinator): [func: (a: number, b: number) => number, initialValue: number];
4
- /** @ignore */
5
- export declare function getThresholdBoundary(combinator: Combinator, rules: ScoreRule[]): [lowest: number, highest: number];
1
+ import { Combinator, ScoreRule } from "../types";
2
+ /** @ignore */
3
+ export declare function getCombinator(combinator: Combinator): [func: (a: number, b: number) => number, initialValue: number];
4
+ /** @ignore */
5
+ export declare function getThresholdBoundary(combinator: Combinator, rules: ScoreRule[]): [lowest: number, highest: number];
@@ -1,47 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getThresholdBoundary = exports.getCombinator = void 0;
4
- /** @ignore */
5
- function getCombinator(combinator) {
6
- switch (combinator) {
7
- case "+":
8
- return [(a, b) => a + b, 0];
9
- case "*":
10
- return [(a, b) => a * b, 1];
11
- default:
12
- throw new Error("Invalid combinator");
13
- }
14
- }
15
- exports.getCombinator = getCombinator;
16
- /** @ignore */
17
- function getThresholdBoundary(combinator, rules) {
18
- switch (combinator) {
19
- case "+": {
20
- const lowest = rules.reduce((ac, r) => ac + Math.min(r.falseWeight, r.trueWeight), 0);
21
- const highest = rules.reduce((ac, r) => ac + Math.max(r.falseWeight, r.trueWeight), 0);
22
- return [lowest, highest];
23
- }
24
- case "*": {
25
- // eslint-disable-next-line fp/no-let
26
- let [lowest, highest] = [Infinity, -Infinity];
27
- // eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation
28
- for (let i = 0; i < 2 * rules.length; i += 1) {
29
- // loop for every possible combination (2*rules.rength), and check that combination
30
- const product = i
31
- .toString(2)
32
- .padStart(rules.length, "0")
33
- .split("")
34
- .map((bool, j) => rules[j][bool === "1" ? "trueWeight" : "falseWeight"])
35
- .reduce((a, b) => a * b, 1);
36
- if (product > highest)
37
- highest = product; // eslint-disable-line fp/no-mutation
38
- if (product < lowest)
39
- lowest = product; // eslint-disable-line fp/no-mutation
40
- }
41
- return [lowest, highest];
42
- }
43
- default:
44
- throw new Error("Invalid combinator");
45
- }
46
- }
47
- exports.getThresholdBoundary = getThresholdBoundary;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getThresholdBoundary = exports.getCombinator = void 0;
4
+ /** @ignore */
5
+ function getCombinator(combinator) {
6
+ switch (combinator) {
7
+ case "+":
8
+ return [(a, b) => a + b, 0];
9
+ case "*":
10
+ return [(a, b) => a * b, 1];
11
+ default:
12
+ throw new Error("Invalid combinator");
13
+ }
14
+ }
15
+ exports.getCombinator = getCombinator;
16
+ /** @ignore */
17
+ function getThresholdBoundary(combinator, rules) {
18
+ switch (combinator) {
19
+ case "+": {
20
+ const lowest = rules.reduce((ac, r) => ac + Math.min(r.falseWeight, r.trueWeight), 0);
21
+ const highest = rules.reduce((ac, r) => ac + Math.max(r.falseWeight, r.trueWeight), 0);
22
+ return [lowest, highest];
23
+ }
24
+ case "*": {
25
+ // eslint-disable-next-line fp/no-let
26
+ let [lowest, highest] = [Infinity, -Infinity];
27
+ // eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation
28
+ for (let i = 0; i < 2 * rules.length; i += 1) {
29
+ // loop for every possible combination (2*rules.rength), and check that combination
30
+ const product = i
31
+ .toString(2)
32
+ .padStart(rules.length, "0")
33
+ .split("")
34
+ .map((bool, j) => rules[j][bool === "1" ? "trueWeight" : "falseWeight"])
35
+ .reduce((a, b) => a * b, 1);
36
+ if (product > highest)
37
+ highest = product; // eslint-disable-line fp/no-mutation
38
+ if (product < lowest)
39
+ lowest = product; // eslint-disable-line fp/no-mutation
40
+ }
41
+ return [lowest, highest];
42
+ }
43
+ default:
44
+ throw new Error("Invalid combinator");
45
+ }
46
+ }
47
+ exports.getThresholdBoundary = getThresholdBoundary;
@@ -1,6 +1,7 @@
1
- export * from "./calculateScore";
2
- export * from "./convertInstanceToRuleInput";
3
- export * from "./types/config";
4
- export * from "./helpers/thresholds";
5
- export * from "./helpers/addInfiniteThresholdBoundaries";
6
- export { operators as scoreOperators } from "./operators";
1
+ export * from "./calculateScore";
2
+ export * from "./convertInstanceToRuleInput";
3
+ export * from "./validate";
4
+ export * from "./types/config";
5
+ export * from "./helpers/thresholds";
6
+ export * from "./helpers/addInfiniteThresholdBoundaries";
7
+ export { operators as scoreOperators } from "./operators";