@raytio/core 10.1.0 → 11.0.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 (172) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +100 -59
  3. package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
  4. package/dist/__tests__/docs.test.js +24 -0
  5. package/dist/accessApplication/createAA.d.ts +17 -17
  6. package/dist/accessApplication/createAA.js +71 -71
  7. package/dist/accessApplication/index.d.ts +1 -1
  8. package/dist/accessApplication/index.js +17 -17
  9. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  10. package/dist/crypto/cognitoAttributes.js +33 -33
  11. package/dist/crypto/decryptKeys.d.ts +1 -1
  12. package/dist/crypto/decryptKeys.js +33 -33
  13. package/dist/crypto/decryptSharedData.d.ts +26 -26
  14. package/dist/crypto/decryptSharedData.js +38 -38
  15. package/dist/crypto/getAADecryptor.d.ts +16 -16
  16. package/dist/crypto/getAADecryptor.js +20 -20
  17. package/dist/crypto/helpers.d.ts +18 -18
  18. package/dist/crypto/helpers.js +26 -26
  19. package/dist/crypto/index.d.ts +4 -4
  20. package/dist/crypto/index.js +21 -21
  21. package/dist/general/conditional.d.ts +17 -17
  22. package/dist/general/conditional.js +32 -32
  23. package/dist/general/date.d.ts +2 -2
  24. package/dist/general/date.js +18 -18
  25. package/dist/general/index.d.ts +4 -4
  26. package/dist/general/index.js +20 -20
  27. package/dist/general/password.d.ts +10 -10
  28. package/dist/general/password.js +31 -31
  29. package/dist/general/types.d.ts +6 -6
  30. package/dist/general/types.js +13 -13
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +22 -22
  33. package/dist/rules/calculateScore.d.ts +28 -23
  34. package/dist/rules/calculateScore.js +82 -76
  35. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  36. package/dist/rules/convertInstanceToRuleInput.js +138 -139
  37. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  38. package/dist/rules/evaluateScoreCondition.js +44 -45
  39. package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
  40. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
  41. package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
  42. package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
  43. package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
  44. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
  45. package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
  46. package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
  47. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  48. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  49. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
  50. package/dist/rules/helpers/checkTypeofValue.js +60 -55
  51. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  52. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  53. package/dist/rules/helpers/index.d.ts +5 -5
  54. package/dist/rules/helpers/index.js +21 -21
  55. package/dist/rules/helpers/symbols.d.ts +2 -2
  56. package/dist/rules/helpers/symbols.js +5 -5
  57. package/dist/rules/helpers/thresholds.d.ts +5 -5
  58. package/dist/rules/helpers/thresholds.js +46 -47
  59. package/dist/rules/index.d.ts +7 -7
  60. package/dist/rules/index.js +25 -25
  61. package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
  62. package/dist/rules/operators/__tests__/bool.test.js +21 -0
  63. package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
  64. package/dist/rules/operators/__tests__/date.test.js +81 -0
  65. package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
  66. package/dist/rules/operators/__tests__/hfield.test.js +38 -0
  67. package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
  68. package/dist/rules/operators/__tests__/hschema.test.js +24 -0
  69. package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
  70. package/dist/rules/operators/__tests__/number.test.js +53 -0
  71. package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
  72. package/dist/rules/operators/__tests__/string.test.js +74 -0
  73. package/dist/rules/operators/bool.d.ts +2 -2
  74. package/dist/rules/operators/bool.js +17 -17
  75. package/dist/rules/operators/date.d.ts +2 -2
  76. package/dist/rules/operators/date.js +91 -91
  77. package/dist/rules/operators/hfield.d.ts +2 -2
  78. package/dist/rules/operators/hfield.js +33 -33
  79. package/dist/rules/operators/hschema.d.ts +2 -2
  80. package/dist/rules/operators/hschema.js +21 -21
  81. package/dist/rules/operators/index.d.ts +3 -3
  82. package/dist/rules/operators/index.js +11 -11
  83. package/dist/rules/operators/number.d.ts +2 -2
  84. package/dist/rules/operators/number.js +41 -41
  85. package/dist/rules/operators/string.d.ts +2 -2
  86. package/dist/rules/operators/string.js +58 -58
  87. package/dist/rules/types/config.d.ts +95 -91
  88. package/dist/rules/types/config.js +2 -2
  89. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  90. package/dist/rules/types/dataValueTypes.js +4 -4
  91. package/dist/rules/types/index.d.ts +3 -3
  92. package/dist/rules/types/index.js +19 -19
  93. package/dist/rules/types/internal.d.ts +20 -20
  94. package/dist/rules/types/internal.js +2 -2
  95. package/dist/rules/validate.d.ts +6 -6
  96. package/dist/rules/validate.js +14 -14
  97. package/dist/rules/version.d.ts +1 -1
  98. package/dist/rules/version.js +5 -5
  99. package/dist/schema/index.d.ts +1 -1
  100. package/dist/schema/index.js +17 -17
  101. package/dist/schema/labels.d.ts +2 -2
  102. package/dist/schema/labels.js +20 -20
  103. package/dist/util/canonicalJsonify.d.ts +1 -1
  104. package/dist/util/canonicalJsonify.js +50 -50
  105. package/dist/util/handleResponse.d.ts +1 -1
  106. package/dist/util/handleResponse.js +21 -21
  107. package/dist/util/index.d.ts +2 -2
  108. package/dist/util/index.js +18 -18
  109. package/dist/verifications/cleanInstance.d.ts +9 -9
  110. package/dist/verifications/cleanInstance.js +15 -15
  111. package/dist/verifications/getPOVerification.d.ts +19 -16
  112. package/dist/verifications/getPOVerification.js +105 -94
  113. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  114. package/dist/verifications/getVerifiedBy.js +19 -19
  115. package/dist/verifications/index.d.ts +5 -5
  116. package/dist/verifications/index.js +21 -21
  117. package/dist/verifications/maybeRereference.d.ts +1 -1
  118. package/dist/verifications/maybeRereference.js +10 -10
  119. package/dist/verifications/safeHarbour.d.ts +20 -20
  120. package/dist/verifications/safeHarbour.js +74 -74
  121. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  122. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  123. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  124. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  125. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  126. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
  127. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  128. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
  129. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  130. package/dist/verifications/verifyCheck/index.js +21 -21
  131. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  132. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  133. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  134. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  135. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  136. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  137. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  138. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  139. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  140. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  141. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  142. package/package.json +13 -10
  143. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  144. package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
  145. package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
  146. package/dist/rules/helpers/getValueFromPath.js +0 -35
  147. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
  148. package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
  149. package/dist/rules/isScoreResultValid.d.ts +0 -2
  150. package/dist/rules/isScoreResultValid.js +0 -9
  151. package/dist/rules/operators/array.d.ts +0 -2
  152. package/dist/rules/operators/array.js +0 -74
  153. package/dist/rules/types/operators.d.ts +0 -19
  154. package/dist/rules/types/operators.js +0 -2
  155. package/dist/rules/types/score.d.ts +0 -50
  156. package/dist/rules/types/score.js +0 -2
  157. package/dist/util/conditional.d.ts +0 -7
  158. package/dist/util/conditional.js +0 -15
  159. package/dist/util/hash.js +0 -11
  160. package/dist/verifications/checkSingleVerification.d.ts +0 -9
  161. package/dist/verifications/checkSingleVerification.js +0 -29
  162. package/dist/verifications/checkVerifications.js +0 -16
  163. package/dist/verifications/checkVerificationsNew.js +0 -16
  164. package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
  165. package/dist/verifications/getOwnRealVerifications.js +0 -64
  166. package/dist/verifications/getRealVerifications.d.ts +0 -22
  167. package/dist/verifications/getRealVerifications.js +0 -71
  168. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
  169. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
  170. package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
  171. package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
  172. package/dist/verifications/verifyCheck/util/index.js +0 -14
@@ -1,9 +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>;
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
+ 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,55 +1,60 @@
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;
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 because TS's typeguards aren't great
9
+ const isObjectWithTypeofProp = (x) => typeof x === "object" &&
10
+ !!x &&
11
+ "__typeof__" in x &&
12
+ typeof x.__typeof__ === "symbol";
13
+ /** asserts that the provided `value` meets the constaints of `type` */
14
+ function checkTypeofValue(type, value) {
15
+ switch (type) {
16
+ case "Array":
17
+ return Array.isArray(value);
18
+ case "Bool":
19
+ return typeof value === "boolean";
20
+ case "Date":
21
+ return value instanceof Date;
22
+ case "DateUnit":
23
+ return typeof value === "string" && VALID_DATE_UNITS.includes(value);
24
+ case "FieldVerification":
25
+ return typeof value === "number" && value in types_1.FieldVerification;
26
+ case "HField":
27
+ // this is not fakeable because we use a unique symbol for __typeof__, like
28
+ // what react does with $$typeof. But even if you could construct a fake object,
29
+ // it wouldn't be a concern in this context.
30
+ return isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HFieldSymbol;
31
+ case "HSchema":
32
+ // this is not fakeable because we use a unique symbol for __typeof__, like
33
+ // what react does with $$typeof. But even if you could construct a fake object,
34
+ // it wouldn't be a concern in this context.
35
+ return (isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HSchemaSymbol);
36
+ case "Number":
37
+ return typeof value === "number";
38
+ case "POVerification":
39
+ return typeof value === "number" && value in types_1.POVerification;
40
+ case "RegEx":
41
+ return value instanceof RegExp;
42
+ case "Verifier":
43
+ case "String":
44
+ return typeof value === "string";
45
+ default:
46
+ return false;
47
+ }
48
+ }
49
+ exports.checkTypeofValue = checkTypeofValue;
50
+ /**
51
+ * Some types are effectively equivilant (e.g. n_id and string).
52
+ * Any exceptions defined here should use the same validator in
53
+ * `checkTypeofValue` above.
54
+ */
55
+ function simplifyValueType(type) {
56
+ if (type === "Verifier")
57
+ return "String";
58
+ return type;
59
+ }
60
+ exports.simplifyValueType = simplifyValueType;
@@ -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,21 +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
- 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);
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);
@@ -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,46 @@
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
+ let [lowest, highest] = [Infinity, -Infinity];
26
+ // eslint-disable-next-line fp/no-mutation
27
+ for (let i = 0; i < 2 * rules.length; i += 1) {
28
+ // loop for every possible combination (2*rules.rength), and check that combination
29
+ const product = i
30
+ .toString(2)
31
+ .padStart(rules.length, "0")
32
+ .split("")
33
+ .map((bool, j) => rules[j][bool === "1" ? "trueWeight" : "falseWeight"])
34
+ .reduce((a, b) => a * b, 1);
35
+ if (product > highest)
36
+ highest = product; // eslint-disable-line fp/no-mutation
37
+ if (product < lowest)
38
+ lowest = product; // eslint-disable-line fp/no-mutation
39
+ }
40
+ return [lowest, highest];
41
+ }
42
+ default:
43
+ throw new Error("Invalid combinator");
44
+ }
45
+ }
46
+ exports.getThresholdBoundary = getThresholdBoundary;
@@ -1,7 +1,7 @@
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";
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";
@@ -1,25 +1,25 @@
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
- exports.scoreOperators = void 0;
18
- __exportStar(require("./calculateScore"), exports);
19
- __exportStar(require("./convertInstanceToRuleInput"), exports);
20
- __exportStar(require("./validate"), exports);
21
- __exportStar(require("./types/config"), exports);
22
- __exportStar(require("./helpers/thresholds"), exports);
23
- __exportStar(require("./helpers/addInfiniteThresholdBoundaries"), exports);
24
- var operators_1 = require("./operators");
25
- Object.defineProperty(exports, "scoreOperators", { enumerable: true, get: function () { return operators_1.operators; } });
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
+ exports.scoreOperators = void 0;
18
+ __exportStar(require("./calculateScore"), exports);
19
+ __exportStar(require("./convertInstanceToRuleInput"), exports);
20
+ __exportStar(require("./validate"), exports);
21
+ __exportStar(require("./types/config"), exports);
22
+ __exportStar(require("./helpers/thresholds"), exports);
23
+ __exportStar(require("./helpers/addInfiniteThresholdBoundaries"), exports);
24
+ var operators_1 = require("./operators");
25
+ Object.defineProperty(exports, "scoreOperators", { enumerable: true, get: function () { return operators_1.operators; } });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const bool_1 = require("../bool");
4
+ describe("boolOperators", () => {
5
+ it.each `
6
+ a | b | result
7
+ ${true} | ${true} | ${true}
8
+ ${false} | ${true} | ${false}
9
+ ${false} | ${false} | ${true}
10
+ `("bool_eq $a, $b", ({ a, b, result }) => {
11
+ expect(bool_1.boolOperators.bool_eq.implementation(a, b)).toBe(result);
12
+ });
13
+ it.each `
14
+ a | b | result
15
+ ${true} | ${true} | ${false}
16
+ ${false} | ${true} | ${true}
17
+ ${false} | ${false} | ${false}
18
+ `("bool_neq $a, $b", ({ a, b, result }) => {
19
+ expect(bool_1.boolOperators.bool_neq.implementation(a, b)).toBe(result);
20
+ });
21
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const date_1 = require("../date");
4
+ describe("dateOperators", () => {
5
+ it.each `
6
+ a | b | result
7
+ ${new Date("2001-06-06T01:00:00Z")} | ${new Date("2001-06-06T23:59:59Z")} | ${true}
8
+ ${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${false}
9
+ `("date_eq $a, $b", ({ a, b, result }) => {
10
+ expect(date_1.dateOperators.date_eq.implementation(a, b)).toBe(result);
11
+ });
12
+ it.each `
13
+ a | b | result
14
+ ${new Date("2001-06-06T01:00:00Z")} | ${new Date("2001-06-06T23:59:59Z")} | ${false}
15
+ ${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${true}
16
+ `("date_neq $a, $b", ({ a, b, result }) => {
17
+ expect(date_1.dateOperators.date_neq.implementation(a, b)).toBe(result);
18
+ });
19
+ it.each `
20
+ a | result
21
+ ${new Date("2001-01-01")} | ${true}
22
+ ${new Date("bobs ur uncle")} | ${false}
23
+ `("date_valid $a", ({ a, result }) => {
24
+ expect(date_1.dateOperators.date_valid.implementation(a)).toBe(result);
25
+ });
26
+ it.each `
27
+ a | result
28
+ ${new Date("2001-01-01")} | ${false}
29
+ ${new Date("bobs ur uncle")} | ${true}
30
+ `("date_invalid $a", ({ a, result }) => {
31
+ expect(date_1.dateOperators.date_invalid.implementation(a)).toBe(result);
32
+ });
33
+ it.each `
34
+ a | b | result
35
+ ${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${true}
36
+ ${new Date("2001-01-01")} | ${new Date("1999-01-01")} | ${false}
37
+ `("date_before $a, $b", ({ a, b, result }) => {
38
+ expect(date_1.dateOperators.date_before.implementation(a, b)).toBe(result);
39
+ });
40
+ it.each `
41
+ a | b | result
42
+ ${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${false}
43
+ ${new Date("2001-01-01")} | ${new Date("1999-01-01")} | ${true}
44
+ `("date_after $a, $b", ({ a, b, result }) => {
45
+ expect(date_1.dateOperators.date_after.implementation(a, b)).toBe(result);
46
+ });
47
+ it.each `
48
+ a | b | c | result
49
+ ${new Date("2001")} | ${new Date("2000")} | ${new Date("2002")} | ${true}
50
+ ${new Date("2001")} | ${new Date("2005")} | ${new Date("2000")} | ${false}
51
+ ${new Date("1900")} | ${new Date("1900")} | ${new Date("1900")} | ${true}
52
+ `("date_between $a, $b, $c", ({ a, b, c, result }) => {
53
+ expect(date_1.dateOperators.date_between.implementation(a, b, c)).toBe(result);
54
+ });
55
+ it.each `
56
+ date | num | units | result
57
+ ${new Date("2010")} | ${10} | ${"Y"} | ${true}
58
+ ${new Date("2010")} | ${20} | ${"Y"} | ${false}
59
+ ${new Date("2030")} | ${1} | ${"Y"} | ${false}
60
+ ${new Date()} | ${1} | ${"ms"} | ${true /* reminaing tests are just for 100% coverage */}
61
+ ${new Date()} | ${1} | ${"s"} | ${false}
62
+ ${new Date()} | ${1} | ${"m"} | ${false}
63
+ ${new Date()} | ${1} | ${"h"} | ${false}
64
+ ${new Date()} | ${1} | ${"D"} | ${false}
65
+ ${new Date()} | ${1} | ${"W"} | ${false}
66
+ ${new Date()} | ${1} | ${"M"} | ${false}
67
+ `("date_older_than $date, $num, $units", ({ date, num, units, result }) => {
68
+ expect(date_1.dateOperators.date_older_than.implementation(date, num, units)).toBe(result);
69
+ });
70
+ it("date_older_than (throws an error for an invalid DateUnit)", () => {
71
+ expect(() => date_1.dateOperators.date_older_than.implementation(new Date(), 6, "Quaters")).toThrow(new Error("Invalid date unit: Quaters"));
72
+ });
73
+ it.each `
74
+ date | num | units | result
75
+ ${new Date("2030")} | ${1} | ${"Y"} | ${true}
76
+ ${new Date("2030")} | ${10} | ${"Y"} | ${false}
77
+ ${new Date()} | ${1} | ${"h"} | ${false}
78
+ `("date_newer_than $date, $num, $units", ({ date, num, units, result }) => {
79
+ expect(date_1.dateOperators.date_newer_than.implementation(date, num, units)).toBe(result);
80
+ });
81
+ });
@@ -0,0 +1 @@
1
+ export {};