@raytio/core 10.1.0 → 11.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.
- package/CHANGELOG.md +10 -0
- package/README.md +198 -59
- package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
- package/dist/__tests__/docs.test.js +24 -0
- package/dist/accessApplication/createAA.d.ts +17 -17
- package/dist/accessApplication/createAA.js +71 -71
- package/dist/accessApplication/index.d.ts +1 -1
- package/dist/accessApplication/index.js +17 -17
- package/dist/crypto/cognitoAttributes.d.ts +15 -15
- package/dist/crypto/cognitoAttributes.js +33 -33
- package/dist/crypto/decryptKeys.d.ts +1 -1
- package/dist/crypto/decryptKeys.js +33 -33
- package/dist/crypto/decryptSharedData.d.ts +26 -26
- package/dist/crypto/decryptSharedData.js +38 -38
- package/dist/crypto/getAADecryptor.d.ts +16 -16
- package/dist/crypto/getAADecryptor.js +20 -20
- package/dist/crypto/helpers.d.ts +18 -18
- package/dist/crypto/helpers.js +26 -26
- package/dist/crypto/index.d.ts +4 -4
- package/dist/crypto/index.js +21 -21
- package/dist/general/conditional.d.ts +17 -17
- package/dist/general/conditional.js +32 -32
- package/dist/general/date.d.ts +2 -2
- package/dist/general/date.js +18 -18
- package/dist/general/index.d.ts +4 -4
- package/dist/general/index.js +20 -20
- package/dist/general/password.d.ts +10 -10
- package/dist/general/password.js +31 -31
- package/dist/general/types.d.ts +6 -6
- package/dist/general/types.js +13 -13
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/dist/rules/calculateScore.d.ts +28 -23
- package/dist/rules/calculateScore.js +82 -76
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
- package/dist/rules/convertInstanceToRuleInput.js +138 -139
- package/dist/rules/evaluateScoreCondition.d.ts +2 -2
- package/dist/rules/evaluateScoreCondition.js +44 -45
- package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
- package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
- package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
- package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
- package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
- package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
- package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
- package/dist/rules/helpers/checkTypeofValue.js +60 -55
- package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
- package/dist/rules/helpers/getValuesFromPath.js +50 -50
- package/dist/rules/helpers/index.d.ts +5 -5
- package/dist/rules/helpers/index.js +21 -21
- package/dist/rules/helpers/symbols.d.ts +2 -2
- package/dist/rules/helpers/symbols.js +5 -5
- package/dist/rules/helpers/thresholds.d.ts +5 -5
- package/dist/rules/helpers/thresholds.js +46 -47
- package/dist/rules/index.d.ts +7 -7
- package/dist/rules/index.js +25 -25
- package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/bool.test.js +21 -0
- package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/date.test.js +81 -0
- package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/hfield.test.js +38 -0
- package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/hschema.test.js +24 -0
- package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/number.test.js +53 -0
- package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/string.test.js +74 -0
- package/dist/rules/operators/bool.d.ts +2 -2
- package/dist/rules/operators/bool.js +17 -17
- package/dist/rules/operators/date.d.ts +2 -2
- package/dist/rules/operators/date.js +91 -91
- package/dist/rules/operators/hfield.d.ts +2 -2
- package/dist/rules/operators/hfield.js +33 -33
- package/dist/rules/operators/hschema.d.ts +2 -2
- package/dist/rules/operators/hschema.js +21 -21
- package/dist/rules/operators/index.d.ts +3 -3
- package/dist/rules/operators/index.js +11 -11
- package/dist/rules/operators/number.d.ts +2 -2
- package/dist/rules/operators/number.js +41 -41
- package/dist/rules/operators/string.d.ts +2 -2
- package/dist/rules/operators/string.js +58 -58
- package/dist/rules/types/config.d.ts +95 -91
- package/dist/rules/types/config.js +2 -2
- package/dist/rules/types/dataValueTypes.d.ts +19 -19
- package/dist/rules/types/dataValueTypes.js +4 -4
- package/dist/rules/types/index.d.ts +3 -3
- package/dist/rules/types/index.js +19 -19
- package/dist/rules/types/internal.d.ts +20 -20
- package/dist/rules/types/internal.js +2 -2
- package/dist/rules/validate.d.ts +6 -6
- package/dist/rules/validate.js +14 -14
- package/dist/rules/version.d.ts +1 -1
- package/dist/rules/version.js +5 -5
- package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
- package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/expandSchema.test.js +95 -0
- package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
- package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
- package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
- package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
- package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
- package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
- package/dist/schema/expandSchema/constants.d.ts +2 -0
- package/dist/schema/expandSchema/constants.js +11 -0
- package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
- package/dist/schema/expandSchema/expandSchema.js +19 -0
- package/dist/schema/expandSchema/i18n.d.ts +5 -0
- package/dist/schema/expandSchema/i18n.js +20 -0
- package/dist/schema/expandSchema/index.d.ts +3 -0
- package/dist/schema/expandSchema/index.js +21 -0
- package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
- package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
- package/dist/schema/expandSchema/processSchema.d.ts +4 -0
- package/dist/schema/expandSchema/processSchema.js +94 -0
- package/dist/schema/expandSchema/removePrivateFields.d.ts +119 -0
- package/dist/schema/expandSchema/removePrivateFields.js +15 -0
- package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
- package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
- package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
- package/dist/schema/expandSchema/unwrapSchema.js +7 -0
- package/dist/schema/expandSchema/util.d.ts +6 -0
- package/dist/schema/expandSchema/util.js +15 -0
- package/dist/schema/index.d.ts +2 -1
- package/dist/schema/index.js +18 -17
- package/dist/schema/labels.d.ts +2 -2
- package/dist/schema/labels.js +20 -20
- package/dist/util/canonicalJsonify.d.ts +1 -1
- package/dist/util/canonicalJsonify.js +50 -50
- package/dist/util/handleResponse.d.ts +1 -1
- package/dist/util/handleResponse.js +21 -21
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.js +18 -18
- package/dist/verifications/cleanInstance.d.ts +9 -9
- package/dist/verifications/cleanInstance.js +15 -15
- package/dist/verifications/getPOVerification.d.ts +19 -16
- package/dist/verifications/getPOVerification.js +105 -94
- package/dist/verifications/getVerifiedBy.d.ts +1 -1
- package/dist/verifications/getVerifiedBy.js +19 -19
- package/dist/verifications/index.d.ts +5 -5
- package/dist/verifications/index.js +21 -21
- package/dist/verifications/maybeRereference.d.ts +1 -1
- package/dist/verifications/maybeRereference.js +10 -10
- package/dist/verifications/safeHarbour.d.ts +20 -20
- package/dist/verifications/safeHarbour.js +67 -74
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
- package/dist/verifications/verifyCheck/index.d.ts +3 -3
- package/dist/verifications/verifyCheck/index.js +21 -21
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
- package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
- package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
- package/dist/verifications/verifyCheck/operations/index.js +18 -18
- package/package.json +13 -10
- package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
- package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
- package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
- package/dist/rules/helpers/getValueFromPath.js +0 -35
- package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
- package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
- package/dist/rules/isScoreResultValid.d.ts +0 -2
- package/dist/rules/isScoreResultValid.js +0 -9
- package/dist/rules/operators/array.d.ts +0 -2
- package/dist/rules/operators/array.js +0 -74
- package/dist/rules/types/operators.d.ts +0 -19
- package/dist/rules/types/operators.js +0 -2
- package/dist/rules/types/score.d.ts +0 -50
- package/dist/rules/types/score.js +0 -2
- package/dist/util/conditional.d.ts +0 -7
- package/dist/util/conditional.js +0 -15
- package/dist/util/hash.js +0 -11
- package/dist/verifications/checkSingleVerification.d.ts +0 -9
- package/dist/verifications/checkSingleVerification.js +0 -29
- package/dist/verifications/checkVerifications.js +0 -16
- package/dist/verifications/checkVerificationsNew.js +0 -16
- package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
- package/dist/verifications/getOwnRealVerifications.js +0 -64
- package/dist/verifications/getRealVerifications.d.ts +0 -22
- package/dist/verifications/getRealVerifications.js +0 -71
- package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
- package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
- package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
- package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
- package/dist/verifications/verifyCheck/util/index.js +0 -14
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@raytio/types");
|
|
4
|
+
const checkTypeofValue_1 = require("../checkTypeofValue");
|
|
5
|
+
const symbols_1 = require("../symbols");
|
|
6
|
+
const hField = { __typeof__: symbols_1.HFieldSymbol };
|
|
7
|
+
const hSchema = { __typeof__: symbols_1.HSchemaSymbol };
|
|
8
|
+
describe("checkTypeofValue", () => {
|
|
9
|
+
it.each `
|
|
10
|
+
val | type | isValid
|
|
11
|
+
${[]} | ${"Array"} | ${true}
|
|
12
|
+
${[]} | ${"Number"} | ${false}
|
|
13
|
+
${false} | ${"Bool"} | ${true}
|
|
14
|
+
${undefined} | ${"Bool"} | ${false}
|
|
15
|
+
${new Date()} | ${"Date"} | ${true}
|
|
16
|
+
${2020} | ${"Date"} | ${false}
|
|
17
|
+
${"Y"} | ${"DateUnit"} | ${true}
|
|
18
|
+
${"y"} | ${"DateUnit"} | ${false}
|
|
19
|
+
${types_1.FieldVerification.Expired} | ${"FieldVerification"} | ${true}
|
|
20
|
+
${12345} | ${"FieldVerification"} | ${false}
|
|
21
|
+
${hField} | ${"HField"} | ${true}
|
|
22
|
+
${{}} | ${"HField"} | ${false}
|
|
23
|
+
${hSchema} | ${"HSchema"} | ${true}
|
|
24
|
+
${{}} | ${"HSchema"} | ${false}
|
|
25
|
+
${123} | ${"Number"} | ${true}
|
|
26
|
+
${types_1.FieldVerification.Expired} | ${"Number"} | ${true}
|
|
27
|
+
${"123"} | ${"Number"} | ${false}
|
|
28
|
+
${types_1.POVerification.Expired} | ${"POVerification"} | ${true}
|
|
29
|
+
${12345} | ${"POVerification"} | ${false}
|
|
30
|
+
${/a/} | ${"RegEx"} | ${true}
|
|
31
|
+
${"/a/"} | ${"RegEx"} | ${false}
|
|
32
|
+
${""} | ${"String"} | ${true}
|
|
33
|
+
${1} | ${"String"} | ${false}
|
|
34
|
+
${""} | ${"Verifier"} | ${true}
|
|
35
|
+
${1} | ${"Verifier"} | ${false}
|
|
36
|
+
${0} | ${"invalidddd"} | ${false}
|
|
37
|
+
`("asserts that $val is/isNot $type ($isValid)", ({ val, type, isValid }) => {
|
|
38
|
+
expect((0, checkTypeofValue_1.checkTypeofValue)(type, val)).toBe(isValid);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("simplifyValueType", () => {
|
|
42
|
+
it.each `
|
|
43
|
+
input | output
|
|
44
|
+
${"Verifier"} | ${"String"}
|
|
45
|
+
${"some other value"} | ${"some other value"}
|
|
46
|
+
`("can simplify functionally equivalent types ($input -> $output)", ({ input, output }) => {
|
|
47
|
+
expect((0, checkTypeofValue_1.simplifyValueType)(input)).toStrictEqual(output);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@raytio/types");
|
|
4
|
+
const getValuesFromPath_1 = require("../getValuesFromPath");
|
|
5
|
+
const symbols_1 = require("../symbols");
|
|
6
|
+
const hSchema = {
|
|
7
|
+
__typeof__: symbols_1.HSchemaSymbol,
|
|
8
|
+
verification: types_1.POVerification.PartiallyVerified,
|
|
9
|
+
verifiedBy: ["Waka Kotahi"],
|
|
10
|
+
};
|
|
11
|
+
const hField = {
|
|
12
|
+
__typeof__: symbols_1.HFieldSymbol,
|
|
13
|
+
cameFromSchema: "ss_NZ_DL",
|
|
14
|
+
verification: types_1.FieldVerification.Verified,
|
|
15
|
+
verifiedBy: ["Waka Kotahi"],
|
|
16
|
+
};
|
|
17
|
+
const data = {
|
|
18
|
+
ss_NZ_DL: [
|
|
19
|
+
{
|
|
20
|
+
hSchema,
|
|
21
|
+
properties: {
|
|
22
|
+
fName: { type: "String", value: "Wolfgang", hField },
|
|
23
|
+
age: { type: "Number", value: 19.25, hField },
|
|
24
|
+
"address|housenumber": {
|
|
25
|
+
type: "Number",
|
|
26
|
+
value: 31,
|
|
27
|
+
hField: null,
|
|
28
|
+
},
|
|
29
|
+
"address|street": {
|
|
30
|
+
type: "String",
|
|
31
|
+
value: "Circular Quay",
|
|
32
|
+
hField: null,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
describe("getValuesFromPath", () => {
|
|
39
|
+
it.each `
|
|
40
|
+
path | out
|
|
41
|
+
${["field", "ss_NZ_DL", "fName", "value"]} | ${["Wolfgang"]}
|
|
42
|
+
${["field", "ss_NZ_DL", "fName", "valueLength"]} | ${[8]}
|
|
43
|
+
${["field", "ss_NZ_DL", "fName", "meta"]} | ${[hField]}
|
|
44
|
+
${["schema", "ss_NZ_DL", "meta"]} | ${[hSchema]}
|
|
45
|
+
${["field", "ss_NZ_DL", "fakeeee", "value"]} | ${[undefined]}
|
|
46
|
+
${["schema", "fakeeee", "meta"]} | ${[]}
|
|
47
|
+
${["field", "ss_NZ_DL", "address", "subField|street"]} | ${["Circular Quay"]}
|
|
48
|
+
${["field", "ss_NZ_DL", "address", "subField|fakeee"]} | ${[undefined]}
|
|
49
|
+
${["field", "ss_NZ_DL", "address", "subField|"]} | ${[undefined]}
|
|
50
|
+
`("can get a value from a valid path ($path)", ({ path, out }) => {
|
|
51
|
+
expect((0, getValuesFromPath_1.getValuesFromPath)(path, data)).toStrictEqual(out);
|
|
52
|
+
});
|
|
53
|
+
it.each `
|
|
54
|
+
path | error
|
|
55
|
+
${["jkhsfjkdf"]} | ${"Invalid ValuePath[0] (jkhsfjkdf)"}
|
|
56
|
+
${["schema", "constructor", "meta"]} | ${"Unacceptable object property"}
|
|
57
|
+
${["schema", "ss_NZ_DL", "fakeeee"]} | ${"Invalid ValuePath[2] for schema (fakeeee)"}
|
|
58
|
+
${["schema", "ss_NZ_DL", "constructor", "meta"]} | ${"Unacceptable object property"}
|
|
59
|
+
${["field", "ss_NZ_DL", "fName", "fakeeee"]} | ${"Invalid ValuePath[3] for field (fakeeee)"}
|
|
60
|
+
${["field"]} | ${"Invalid ValuePath[3] for field (undefined)"}
|
|
61
|
+
${["schema"]} | ${"Invalid ValuePath[2] for schema (undefined)"}
|
|
62
|
+
${""} | ${"Invalid ValuePath[0] (undefined)"}
|
|
63
|
+
${["field", "ss_NZ_DL", "age", "valueLength"]} | ${"valueLength may only be used on arrays and strings"}
|
|
64
|
+
`("throws an error for invalid paths ($path)", ({ path, error }) => {
|
|
65
|
+
expect(() => (0, getValuesFromPath_1.getValuesFromPath)(path, data)).toThrow(new Error(error));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const thresholds_1 = require("../thresholds");
|
|
4
|
+
describe("getThresholdBoundary", () => {
|
|
5
|
+
it("gets the min and max for plus", () => {
|
|
6
|
+
expect((0, thresholds_1.getThresholdBoundary)("+", [
|
|
7
|
+
{ trueWeight: 3, falseWeight: 5 },
|
|
8
|
+
{ trueWeight: -20, falseWeight: -10 },
|
|
9
|
+
])).toStrictEqual([-17, -5]);
|
|
10
|
+
expect((0, thresholds_1.getThresholdBoundary)("+", [
|
|
11
|
+
{ trueWeight: -7, falseWeight: -8 },
|
|
12
|
+
])).toStrictEqual([-8, -7]);
|
|
13
|
+
});
|
|
14
|
+
it("gets the min and max for multiply", () => {
|
|
15
|
+
expect((0, thresholds_1.getThresholdBoundary)("*", [
|
|
16
|
+
{ trueWeight: 7, falseWeight: -2 },
|
|
17
|
+
{ trueWeight: -1, falseWeight: 2 },
|
|
18
|
+
{ trueWeight: -5, falseWeight: 4 },
|
|
19
|
+
])).toStrictEqual([-70, 56]);
|
|
20
|
+
expect((0, thresholds_1.getThresholdBoundary)("*", [
|
|
21
|
+
{ trueWeight: 7, falseWeight: -2 },
|
|
22
|
+
])).toStrictEqual([-2, 7]);
|
|
23
|
+
});
|
|
24
|
+
it("works for empty arrays", () => {
|
|
25
|
+
expect((0, thresholds_1.getThresholdBoundary)("+", [])).toStrictEqual([0, 0]);
|
|
26
|
+
expect((0, thresholds_1.getThresholdBoundary)("*", [])).toStrictEqual([Infinity, -Infinity]);
|
|
27
|
+
});
|
|
28
|
+
it("throws an error for invalid combinators", () => {
|
|
29
|
+
// @ts-expect-error testing invalid input
|
|
30
|
+
expect(() => (0, thresholds_1.getThresholdBoundary)("^", [])).toThrow(new Error("Invalid combinator"));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -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,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
|
|
9
|
-
const isObjectWithTypeofProp = (x) => typeof x === "object" &&
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
return
|
|
31
|
-
case "
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
case "
|
|
39
|
-
return typeof value === "
|
|
40
|
-
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
.
|
|
33
|
-
.
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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;
|