@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
|
@@ -1,76 +1,82 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateScore = void 0;
|
|
4
|
-
const evaluateScoreCondition_1 = require("./evaluateScoreCondition");
|
|
5
|
-
const helpers_1 = require("./helpers");
|
|
6
|
-
const general_1 = require("../general");
|
|
7
|
-
const version_1 = require("./version");
|
|
8
|
-
function evaluateASTNode(node, data) {
|
|
9
|
-
if (node.type === "LanguageOperator") {
|
|
10
|
-
if (!node.children.length) {
|
|
11
|
-
// we allow a single child because why not.
|
|
12
|
-
throw new Error("LanguageOperator has no children");
|
|
13
|
-
}
|
|
14
|
-
if (node.operator === "AND") {
|
|
15
|
-
return node.children.every(n => evaluateASTNode(n, data));
|
|
16
|
-
}
|
|
17
|
-
if (node.operator === "OR") {
|
|
18
|
-
return node.children.some(n => evaluateASTNode(n, data));
|
|
19
|
-
}
|
|
20
|
-
throw new Error(`LanguageOperator node has invalid operator '${node.operator}'`);
|
|
21
|
-
}
|
|
22
|
-
if (node.type === "ScoreCondition") {
|
|
23
|
-
return (0, evaluateScoreCondition_1.evaluateScoreCondition)(node, data);
|
|
24
|
-
}
|
|
25
|
-
throw new Error("ASTNode has invalid type");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
score
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateScore = exports.evaluateRule = void 0;
|
|
4
|
+
const evaluateScoreCondition_1 = require("./evaluateScoreCondition");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const general_1 = require("../general");
|
|
7
|
+
const version_1 = require("./version");
|
|
8
|
+
function evaluateASTNode(node, data) {
|
|
9
|
+
if (node.type === "LanguageOperator") {
|
|
10
|
+
if (!node.children.length) {
|
|
11
|
+
// we allow a single child because why not.
|
|
12
|
+
throw new Error("LanguageOperator has no children");
|
|
13
|
+
}
|
|
14
|
+
if (node.operator === "AND") {
|
|
15
|
+
return node.children.every(n => evaluateASTNode(n, data));
|
|
16
|
+
}
|
|
17
|
+
if (node.operator === "OR") {
|
|
18
|
+
return node.children.some(n => evaluateASTNode(n, data));
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`LanguageOperator node has invalid operator '${node.operator}'`);
|
|
21
|
+
}
|
|
22
|
+
if (node.type === "ScoreCondition") {
|
|
23
|
+
return (0, evaluateScoreCondition_1.evaluateScoreCondition)(node, data);
|
|
24
|
+
}
|
|
25
|
+
throw new Error("ASTNode has invalid type");
|
|
26
|
+
}
|
|
27
|
+
/** evaluates an individual rule, normally you should use {@link calculateScore} */
|
|
28
|
+
function evaluateRule(rule, data) {
|
|
29
|
+
if (rule.tree.length !== 1) {
|
|
30
|
+
throw new Error("A rule may only have 1 root node");
|
|
31
|
+
}
|
|
32
|
+
const rulePassed = rule.tree.every(n => evaluateASTNode(n, data));
|
|
33
|
+
return {
|
|
34
|
+
passed: rulePassed,
|
|
35
|
+
score: rulePassed ? rule.trueWeight : rule.falseWeight,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.evaluateRule = evaluateRule;
|
|
39
|
+
/**
|
|
40
|
+
* We guarantee that the same configId or ruleId will always produce the same output.
|
|
41
|
+
* This is the closest thing we have to versioning.
|
|
42
|
+
*/
|
|
43
|
+
const jsonId = (json) => (0, general_1.hashPassword)(JSON.stringify(json)).then(hash => hash.slice(0, 10));
|
|
44
|
+
/**
|
|
45
|
+
* the main function to calculate a score and category.
|
|
46
|
+
* Might throw an error.
|
|
47
|
+
*/
|
|
48
|
+
async function calculateScore(ruleConfig, ruleInput) {
|
|
49
|
+
const activeRules = ruleConfig.rules.filter(rule => rule.enabled !== false);
|
|
50
|
+
if (!activeRules.length) {
|
|
51
|
+
throw new Error("There are no enabled rules");
|
|
52
|
+
}
|
|
53
|
+
const result = activeRules.map(rule => evaluateRule(rule, ruleInput));
|
|
54
|
+
const [addOrMultiply, initialValue] = (0, helpers_1.getCombinator)(ruleConfig.combinator);
|
|
55
|
+
const finalScore = result
|
|
56
|
+
.map(x => x.score)
|
|
57
|
+
.reduce(addOrMultiply, initialValue);
|
|
58
|
+
const matchingCategories = (0, helpers_1.addInfiniteThresholdBoundaries)(ruleConfig.scoreThresholds).filter(threshold => finalScore >= threshold.from && finalScore <= threshold.to);
|
|
59
|
+
if (matchingCategories.length === 0) {
|
|
60
|
+
throw new Error(`No categories match the final score (${finalScore})`);
|
|
61
|
+
}
|
|
62
|
+
if (matchingCategories.length !== 1) {
|
|
63
|
+
throw new Error(`Multiple categories match the final score (${finalScore})`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
score: finalScore,
|
|
67
|
+
category: matchingCategories[0].name,
|
|
68
|
+
categoryColour: matchingCategories[0].colour,
|
|
69
|
+
diagnostics: {
|
|
70
|
+
version: version_1.SUBMISSION_RULES_VERSION,
|
|
71
|
+
config: {
|
|
72
|
+
id: await jsonId(ruleConfig),
|
|
73
|
+
rules: await Promise.all(result.map(async ({ passed }, i) => {
|
|
74
|
+
const r = ruleConfig.rules[i];
|
|
75
|
+
const ruleId = await jsonId(r);
|
|
76
|
+
return { id: ruleId, name: r.name, passed };
|
|
77
|
+
})),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
exports.calculateScore = calculateScore;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RuleData } from "./types";
|
|
3
|
-
export declare const convertInstanceToRuleInput: (
|
|
1
|
+
import { ProfileObject, RealVer, Schema } from "@raytio/types";
|
|
2
|
+
import { RuleData } from "./types";
|
|
3
|
+
export declare const convertInstanceToRuleInput: (POs: ProfileObject[], realVers: RealVer[], getSchema: (schemaName: string) => Promise<Schema>) => Promise<RuleData>;
|
|
@@ -1,139 +1,138 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertInstanceToRuleInput = void 0;
|
|
4
|
-
const ramda_1 = require("ramda");
|
|
5
|
-
const verifications_1 = require("../verifications");
|
|
6
|
-
const schema_1 = require("../schema");
|
|
7
|
-
const helpers_1 = require("./helpers");
|
|
8
|
-
// has to be hardcodede since we're in @raytio/core
|
|
9
|
-
const VERIFICATION_SCHEMA = "ss_Verification";
|
|
10
|
-
/**
|
|
11
|
-
* this is only called for field values, so we can easily work out the type
|
|
12
|
-
* There are no complications like POVerification or DateUnits
|
|
13
|
-
*/
|
|
14
|
-
function getTypeofFieldValue(value) {
|
|
15
|
-
if (Array.isArray(value))
|
|
16
|
-
return "Array";
|
|
17
|
-
if (typeof value === "boolean")
|
|
18
|
-
return "Bool";
|
|
19
|
-
if (typeof value === "number")
|
|
20
|
-
return "Number";
|
|
21
|
-
if (typeof value === "string")
|
|
22
|
-
return "String";
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
const isDateField = (schema) => ([fieldName]) => {
|
|
26
|
-
var _a;
|
|
27
|
-
return (_a = schema.properties[fieldName].tags) === null || _a === void 0 ? void 0 : _a.some(tag => tag.startsWith("group:date_picker"));
|
|
28
|
-
};
|
|
29
|
-
const convertInstanceToRuleInput = async (
|
|
30
|
-
const out = {};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
// remove
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
x.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
values[
|
|
83
|
-
`${values[
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
field.
|
|
103
|
-
|
|
104
|
-
fieldValue
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
...
|
|
132
|
-
...
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
exports.convertInstanceToRuleInput = convertInstanceToRuleInput;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertInstanceToRuleInput = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
const verifications_1 = require("../verifications");
|
|
6
|
+
const schema_1 = require("../schema");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
// has to be hardcodede since we're in @raytio/core
|
|
9
|
+
const VERIFICATION_SCHEMA = "ss_Verification";
|
|
10
|
+
/**
|
|
11
|
+
* this is only called for field values, so we can easily work out the type
|
|
12
|
+
* There are no complications like POVerification or DateUnits
|
|
13
|
+
*/
|
|
14
|
+
function getTypeofFieldValue(value) {
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return "Array";
|
|
17
|
+
if (typeof value === "boolean")
|
|
18
|
+
return "Bool";
|
|
19
|
+
if (typeof value === "number")
|
|
20
|
+
return "Number";
|
|
21
|
+
if (typeof value === "string")
|
|
22
|
+
return "String";
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const isDateField = (schema) => ([fieldName]) => {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = schema.properties[fieldName].tags) === null || _a === void 0 ? void 0 : _a.some(tag => tag.startsWith("group:date_picker"));
|
|
28
|
+
};
|
|
29
|
+
const convertInstanceToRuleInput = async (POs, realVers, getSchema) => {
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const PO of POs) {
|
|
32
|
+
const schemaName = (0, schema_1.findSchemaLabel)(PO.labels);
|
|
33
|
+
// eslint-disable-next-line no-continue
|
|
34
|
+
if (schemaName === VERIFICATION_SCHEMA)
|
|
35
|
+
continue;
|
|
36
|
+
const schema = await getSchema(schemaName);
|
|
37
|
+
const verified = (0, verifications_1.getPOVerification)({ PO, schema, realVers });
|
|
38
|
+
// remove anything we can't make rules for (e.g. object), and
|
|
39
|
+
// also remove any fields that aren't defined in the schema.
|
|
40
|
+
const validFields = Object.entries(PO.properties).filter(([fieldName, value]) => getTypeofFieldValue(value) && schema.properties[fieldName]);
|
|
41
|
+
const nonDateProperties = validFields
|
|
42
|
+
.filter(d => !isDateField(schema)(d))
|
|
43
|
+
.map(([fieldName, value]) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const verifiedBy = (0, ramda_1.uniq)((_a = realVers
|
|
46
|
+
.filter(x => x.belongsToNId === PO.n_id &&
|
|
47
|
+
x.fieldName === fieldName &&
|
|
48
|
+
x.provider.verifierNId)) === null || _a === void 0 ? void 0 : _a.map(x => x.provider.verifierNId));
|
|
49
|
+
const field = {
|
|
50
|
+
hField: {
|
|
51
|
+
__typeof__: helpers_1.HFieldSymbol,
|
|
52
|
+
cameFromSchema: schemaName,
|
|
53
|
+
verification: verified.fieldVerifications[fieldName],
|
|
54
|
+
verifiedBy,
|
|
55
|
+
},
|
|
56
|
+
type: getTypeofFieldValue(value),
|
|
57
|
+
value,
|
|
58
|
+
};
|
|
59
|
+
return [fieldName, field];
|
|
60
|
+
});
|
|
61
|
+
const dateFieldByCategorys = (0, ramda_1.groupBy)(([fieldName]) => schema.properties[fieldName].tags.find(tag => tag.startsWith("group:date_picker")), validFields.filter(isDateField(schema)));
|
|
62
|
+
// the three date fields become one pseudo field for the score system
|
|
63
|
+
const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag, members]) => {
|
|
64
|
+
var _a;
|
|
65
|
+
const groupName = groupTag.split(":")[2] || "NO_NAME";
|
|
66
|
+
const memberFieldNames = members.map(x => x[0]);
|
|
67
|
+
const worstVer = (0, ramda_1.sort)((a, b) => b - a, // find the highest enum value (that's the worst)
|
|
68
|
+
memberFieldNames.map(f => verified.fieldVerifications[f]))[0];
|
|
69
|
+
const fieldVers = (0, ramda_1.uniq)((_a = realVers
|
|
70
|
+
.filter(x => x.belongsToNId === PO.n_id &&
|
|
71
|
+
memberFieldNames.includes(x.fieldName) &&
|
|
72
|
+
x.provider.verifierNId)) === null || _a === void 0 ? void 0 : _a.map(v => v.provider.verifierNId).filter((val) => !!val));
|
|
73
|
+
const values = Object.fromEntries(members);
|
|
74
|
+
const dayFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:day"); });
|
|
75
|
+
const monthFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:month"); });
|
|
76
|
+
const yearFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:year"); });
|
|
77
|
+
if (!dayFieldName || !monthFieldName || !yearFieldName) {
|
|
78
|
+
throw new Error("Failed to infer date component field");
|
|
79
|
+
}
|
|
80
|
+
const isoString = [
|
|
81
|
+
values[yearFieldName],
|
|
82
|
+
`${values[monthFieldName]}`.padStart(2, "0"),
|
|
83
|
+
`${values[dayFieldName]}`.padStart(2, "0"),
|
|
84
|
+
].join("-");
|
|
85
|
+
const pseudoField = {
|
|
86
|
+
hField: {
|
|
87
|
+
__typeof__: helpers_1.HFieldSymbol,
|
|
88
|
+
cameFromSchema: schemaName,
|
|
89
|
+
verification: worstVer,
|
|
90
|
+
verifiedBy: fieldVers,
|
|
91
|
+
},
|
|
92
|
+
type: "Date",
|
|
93
|
+
value: new Date(isoString),
|
|
94
|
+
};
|
|
95
|
+
return [`__group_${groupName}`, pseudoField];
|
|
96
|
+
});
|
|
97
|
+
const deepProperties = Object.entries(PO.properties)
|
|
98
|
+
.filter(([fieldName, fieldValue]) => {
|
|
99
|
+
const field = schema.properties[fieldName];
|
|
100
|
+
return (field &&
|
|
101
|
+
field.type === "object" &&
|
|
102
|
+
field.properties &&
|
|
103
|
+
fieldValue &&
|
|
104
|
+
typeof fieldValue === "object");
|
|
105
|
+
})
|
|
106
|
+
.flatMap(([fieldName, fieldValue]) => {
|
|
107
|
+
const subFields = Object.keys(schema.properties[fieldName].properties);
|
|
108
|
+
return subFields.map(subFieldName => {
|
|
109
|
+
const value = fieldValue[subFieldName];
|
|
110
|
+
const hsubfield = {
|
|
111
|
+
hField: null,
|
|
112
|
+
type: getTypeofFieldValue(value),
|
|
113
|
+
value,
|
|
114
|
+
};
|
|
115
|
+
return [`${fieldName}|${subFieldName}`, hsubfield];
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
// eslint-disable-next-line fp/no-mutation
|
|
119
|
+
out[schemaName] || (out[schemaName] = []);
|
|
120
|
+
// eslint-disable-next-line fp/no-mutating-methods
|
|
121
|
+
out[schemaName].push({
|
|
122
|
+
hSchema: {
|
|
123
|
+
__typeof__: helpers_1.HSchemaSymbol,
|
|
124
|
+
verification: verified.status,
|
|
125
|
+
verifiedBy: verified.details.verifiers
|
|
126
|
+
.map(x => x.verifierNId)
|
|
127
|
+
.filter((val) => !!val),
|
|
128
|
+
},
|
|
129
|
+
properties: Object.fromEntries([
|
|
130
|
+
...nonDateProperties,
|
|
131
|
+
...pseudoDateFields,
|
|
132
|
+
...deepProperties,
|
|
133
|
+
]),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
138
|
+
exports.convertInstanceToRuleInput = convertInstanceToRuleInput;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ASTScoreConditionNode, RuleData } from "./types";
|
|
2
|
-
export declare function evaluateScoreCondition(node: ASTScoreConditionNode, data: RuleData): boolean;
|
|
1
|
+
import { ASTScoreConditionNode, RuleData } from "./types";
|
|
2
|
+
export declare function evaluateScoreCondition(node: ASTScoreConditionNode, data: RuleData): boolean;
|
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateScoreCondition = void 0;
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
exports.evaluateScoreCondition = evaluateScoreCondition;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateScoreCondition = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
const general_1 = require("../general");
|
|
6
|
+
const operators_1 = require("./operators");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
function evaluateScoreCondition(node, data) {
|
|
9
|
+
(0, general_1.assertSafeProperty)(node.operator);
|
|
10
|
+
const op = operators_1.operators[node.operator];
|
|
11
|
+
if (!op) {
|
|
12
|
+
throw new Error(`Operator '${node.operator}' is not known`);
|
|
13
|
+
}
|
|
14
|
+
if (node.values.length !== op.operands.length) {
|
|
15
|
+
throw new Error(`Operator argument length mismatch for '${node.operator}'`);
|
|
16
|
+
}
|
|
17
|
+
const rawValues = node.values
|
|
18
|
+
.map(x => x.value.type === "constant"
|
|
19
|
+
? [x.value.value]
|
|
20
|
+
: (0, helpers_1.getValuesFromPath)(x.value.path, data))
|
|
21
|
+
.map(valuesForArg => valuesForArg.filter(v => typeof v !== "undefined"));
|
|
22
|
+
for (const [i, argType] of op.operands.entries()) {
|
|
23
|
+
if ((0, helpers_1.simplifyValueType)(argType) !== (0, helpers_1.simplifyValueType)(node.values[i].type)) {
|
|
24
|
+
throw new TypeError(`Operator argument ${i} expected ${argType} but got ${node.values[i].type} for '${node.operator}'`);
|
|
25
|
+
}
|
|
26
|
+
const values = rawValues[i];
|
|
27
|
+
if (!values.length) {
|
|
28
|
+
// TODO: if one of the values required for your rule doesn't exist, then what?
|
|
29
|
+
// for now, the rule will return false.
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
// also check if the claimed type of the value matches the actual type of the value
|
|
33
|
+
for (const value of values) {
|
|
34
|
+
if (!(0, helpers_1.checkTypeofValue)(argType, value)) {
|
|
35
|
+
throw new Error(`Operator argument ${i} falsely claimed to be ${argType} for '${node.operator}'`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const options = (0, ramda_1.transpose)(rawValues);
|
|
40
|
+
// everything adds up so far, so we can call the function for each
|
|
41
|
+
// data value. Return true if ANY of the values return true.
|
|
42
|
+
return options.some(args => op.implementation(...args));
|
|
43
|
+
}
|
|
44
|
+
exports.evaluateScoreCondition = evaluateScoreCondition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const addInfiniteThresholdBoundaries_1 = require("../addInfiniteThresholdBoundaries");
|
|
4
|
+
describe("addInfiniteThresholdBoundaries", () => {
|
|
5
|
+
it("correctly re-adds Infinity to the first and last boundary", () => {
|
|
6
|
+
expect((0, addInfiniteThresholdBoundaries_1.addInfiniteThresholdBoundaries)([
|
|
7
|
+
{ colour: "", from: null, to: 1, name: "❤️" },
|
|
8
|
+
{ colour: "", from: 2, to: 50, name: "💛" },
|
|
9
|
+
{ colour: "", from: 51, to: null, name: "💚" },
|
|
10
|
+
])).toStrictEqual([
|
|
11
|
+
{ colour: "", from: -Infinity, to: 1, name: "❤️" },
|
|
12
|
+
{ colour: "", from: 2, to: 50, name: "💛" },
|
|
13
|
+
{ colour: "", from: 51, to: Infinity, name: "💚" },
|
|
14
|
+
]);
|
|
15
|
+
expect((0, addInfiniteThresholdBoundaries_1.addInfiniteThresholdBoundaries)([])).toStrictEqual([]);
|
|
16
|
+
expect((0, addInfiniteThresholdBoundaries_1.addInfiniteThresholdBoundaries)([
|
|
17
|
+
{ colour: "", from: 1, to: 10, name: "my useless single category" },
|
|
18
|
+
])).toStrictEqual([
|
|
19
|
+
{
|
|
20
|
+
colour: "",
|
|
21
|
+
from: -Infinity,
|
|
22
|
+
to: Infinity,
|
|
23
|
+
name: "my useless single category",
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|