@raytio/core 10.0.1 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +35 -2
- 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 -11
- 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 -7
- package/dist/general/conditional.js +32 -22
- package/dist/general/date.d.ts +2 -0
- package/dist/general/date.js +18 -0
- package/dist/general/index.d.ts +4 -3
- package/dist/general/index.js +20 -19
- 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 +23 -23
- package/dist/rules/calculateScore.js +76 -76
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
- package/dist/rules/convertInstanceToRuleInput.js +139 -139
- package/dist/rules/evaluateScoreCondition.d.ts +2 -2
- package/dist/rules/evaluateScoreCondition.js +45 -45
- 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 +55 -55
- package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
- package/dist/rules/helpers/getLhsTypeofValue.js +1 -0
- package/dist/rules/helpers/getValueFromPath.d.ts +2 -0
- package/dist/rules/helpers/getValueFromPath.js +35 -0
- 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/rebuildInfiniteValues.d.ts +3 -0
- package/dist/rules/helpers/rebuildInfiniteValues.js +6 -0
- 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 +47 -47
- package/dist/rules/index.d.ts +7 -7
- package/dist/rules/index.js +25 -25
- package/dist/rules/isScoreResultValid.d.ts +2 -0
- package/dist/rules/isScoreResultValid.js +9 -0
- package/dist/rules/operators/array.d.ts +2 -0
- package/dist/rules/operators/array.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 +91 -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/types/operators.d.ts +19 -0
- package/dist/rules/types/operators.js +2 -0
- package/dist/rules/types/score.d.ts +50 -0
- package/dist/rules/types/score.js +2 -0
- 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/index.d.ts +1 -1
- package/dist/schema/index.js +17 -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/conditional.d.ts +7 -0
- package/dist/util/conditional.js +15 -0
- package/dist/util/handleResponse.d.ts +1 -1
- package/dist/util/handleResponse.js +21 -21
- package/dist/util/hash.d.ts +1 -0
- package/dist/util/hash.js +11 -0
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.js +18 -18
- package/dist/verifications/checkSingleVerification.d.ts +9 -0
- package/dist/verifications/checkSingleVerification.js +29 -0
- package/dist/verifications/checkVerifications.d.ts +1 -0
- package/dist/verifications/checkVerifications.js +16 -0
- package/dist/verifications/checkVerificationsNew.d.ts +1 -0
- package/dist/verifications/checkVerificationsNew.js +16 -0
- package/dist/verifications/cleanInstance.d.ts +9 -9
- package/dist/verifications/cleanInstance.js +15 -15
- package/dist/verifications/getOwnRealVerifications.d.ts +14 -0
- package/dist/verifications/getOwnRealVerifications.js +64 -0
- package/dist/verifications/getPOVerification.d.ts +16 -16
- package/dist/verifications/getPOVerification.js +94 -94
- package/dist/verifications/getRealVerifications.d.ts +22 -0
- package/dist/verifications/getRealVerifications.js +71 -0
- 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 +74 -74
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +64 -63
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -71
- package/dist/verifications/verifyCheck/index.d.ts +3 -3
- package/dist/verifications/verifyCheck/index.js +21 -21
- 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/dist/verifications/verifyCheck/util/canonicalJsonify.d.ts +1 -0
- package/dist/verifications/verifyCheck/util/canonicalJsonify.js +48 -0
- package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +2 -0
- package/dist/verifications/verifyCheck/util/getValuesForAField.js +9 -0
- package/dist/verifications/verifyCheck/util/index.d.ts +2 -0
- package/dist/verifications/verifyCheck/util/index.js +14 -0
- package/package.json +4 -4
|
@@ -1,76 +1,76 @@
|
|
|
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
|
-
function evaluateRule(rule, data) {
|
|
28
|
-
if (rule.tree.length !== 1) {
|
|
29
|
-
throw new Error("A rule may only have 1 root node");
|
|
30
|
-
}
|
|
31
|
-
const rulePassed = rule.tree.every(n => evaluateASTNode(n, data));
|
|
32
|
-
return {
|
|
33
|
-
passed: rulePassed,
|
|
34
|
-
score: rulePassed ? rule.trueWeight : rule.falseWeight,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* We guarantee that the same configId or ruleId will always produce the same output.
|
|
39
|
-
* This is the closest thing we have to versioning.
|
|
40
|
-
*/
|
|
41
|
-
const jsonId = (json) => (0, general_1.hashPassword)(JSON.stringify(json)).then(hash => hash.slice(0, 10));
|
|
42
|
-
/**
|
|
43
|
-
* the main function to calculate a score and category.
|
|
44
|
-
* Might throw an error.
|
|
45
|
-
*/
|
|
46
|
-
async function calculateScore(ruleConfig, ruleInput) {
|
|
47
|
-
const result = ruleConfig.rules.map(rule => evaluateRule(rule, ruleInput));
|
|
48
|
-
const [addOrMultiply, initialValue] = (0, helpers_1.getCombinator)(ruleConfig.combinator);
|
|
49
|
-
const finalScore = result
|
|
50
|
-
.map(x => x.score)
|
|
51
|
-
.reduce(addOrMultiply, initialValue);
|
|
52
|
-
const matchingCategories = (0, helpers_1.addInfiniteThresholdBoundaries)(ruleConfig.scoreThresholds).filter(threshold => finalScore >= threshold.from && finalScore <= threshold.to);
|
|
53
|
-
if (matchingCategories.length === 0) {
|
|
54
|
-
throw new Error(`No categories match the final score (${finalScore})`);
|
|
55
|
-
}
|
|
56
|
-
if (matchingCategories.length !== 1) {
|
|
57
|
-
throw new Error(`Multiple categories match the final score (${finalScore})`);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
score: finalScore,
|
|
61
|
-
category: matchingCategories[0].name,
|
|
62
|
-
categoryColour: matchingCategories[0].colour,
|
|
63
|
-
diagnostics: {
|
|
64
|
-
version: version_1.SUBMISSION_RULES_VERSION,
|
|
65
|
-
config: {
|
|
66
|
-
id: await jsonId(ruleConfig),
|
|
67
|
-
rules: await Promise.all(result.map(async ({ passed }, i) => {
|
|
68
|
-
const r = ruleConfig.rules[i];
|
|
69
|
-
const ruleId = await jsonId(r);
|
|
70
|
-
return { id: ruleId, name: r.name, passed };
|
|
71
|
-
})),
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
exports.calculateScore = calculateScore;
|
|
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
|
+
function evaluateRule(rule, data) {
|
|
28
|
+
if (rule.tree.length !== 1) {
|
|
29
|
+
throw new Error("A rule may only have 1 root node");
|
|
30
|
+
}
|
|
31
|
+
const rulePassed = rule.tree.every(n => evaluateASTNode(n, data));
|
|
32
|
+
return {
|
|
33
|
+
passed: rulePassed,
|
|
34
|
+
score: rulePassed ? rule.trueWeight : rule.falseWeight,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* We guarantee that the same configId or ruleId will always produce the same output.
|
|
39
|
+
* This is the closest thing we have to versioning.
|
|
40
|
+
*/
|
|
41
|
+
const jsonId = (json) => (0, general_1.hashPassword)(JSON.stringify(json)).then(hash => hash.slice(0, 10));
|
|
42
|
+
/**
|
|
43
|
+
* the main function to calculate a score and category.
|
|
44
|
+
* Might throw an error.
|
|
45
|
+
*/
|
|
46
|
+
async function calculateScore(ruleConfig, ruleInput) {
|
|
47
|
+
const result = ruleConfig.rules.map(rule => evaluateRule(rule, ruleInput));
|
|
48
|
+
const [addOrMultiply, initialValue] = (0, helpers_1.getCombinator)(ruleConfig.combinator);
|
|
49
|
+
const finalScore = result
|
|
50
|
+
.map(x => x.score)
|
|
51
|
+
.reduce(addOrMultiply, initialValue);
|
|
52
|
+
const matchingCategories = (0, helpers_1.addInfiniteThresholdBoundaries)(ruleConfig.scoreThresholds).filter(threshold => finalScore >= threshold.from && finalScore <= threshold.to);
|
|
53
|
+
if (matchingCategories.length === 0) {
|
|
54
|
+
throw new Error(`No categories match the final score (${finalScore})`);
|
|
55
|
+
}
|
|
56
|
+
if (matchingCategories.length !== 1) {
|
|
57
|
+
throw new Error(`Multiple categories match the final score (${finalScore})`);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
score: finalScore,
|
|
61
|
+
category: matchingCategories[0].name,
|
|
62
|
+
categoryColour: matchingCategories[0].colour,
|
|
63
|
+
diagnostics: {
|
|
64
|
+
version: version_1.SUBMISSION_RULES_VERSION,
|
|
65
|
+
config: {
|
|
66
|
+
id: await jsonId(ruleConfig),
|
|
67
|
+
rules: await Promise.all(result.map(async ({ passed }, i) => {
|
|
68
|
+
const r = ruleConfig.rules[i];
|
|
69
|
+
const ruleId = await jsonId(r);
|
|
70
|
+
return { id: ruleId, name: r.name, passed };
|
|
71
|
+
})),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.calculateScore = calculateScore;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Instance, RealVer, Schema } from "@raytio/types";
|
|
2
|
-
import { RuleData } from "./types";
|
|
3
|
-
export declare const convertInstanceToRuleInput: (instance: Instance, realVers: RealVer[], getSchema: (schemaName: string) => Promise<Schema>) => Promise<RuleData>;
|
|
1
|
+
import { Instance, RealVer, Schema } from "@raytio/types";
|
|
2
|
+
import { RuleData } from "./types";
|
|
3
|
+
export declare const convertInstanceToRuleInput: (instance: Instance, realVers: RealVer[], getSchema: (schemaName: string) => Promise<Schema>) => Promise<RuleData>;
|
|
@@ -1,139 +1,139 @@
|
|
|
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 (instance, realVers, getSchema) => {
|
|
30
|
-
const out = {};
|
|
31
|
-
// eslint-disable-next-line fp/no-loops
|
|
32
|
-
for (const PO of instance.profile_objects) {
|
|
33
|
-
const schemaName = (0, schema_1.findSchemaLabel)(PO.labels);
|
|
34
|
-
// eslint-disable-next-line no-continue
|
|
35
|
-
if (schemaName === VERIFICATION_SCHEMA)
|
|
36
|
-
continue;
|
|
37
|
-
const schema = await getSchema(schemaName);
|
|
38
|
-
const verified = (0, verifications_1.getPOVerification)({ PO, schema, realVers });
|
|
39
|
-
// remove anything we can't make rules for (e.g. object), and
|
|
40
|
-
// also remove any fields that aren't defined in the schema.
|
|
41
|
-
const validFields = Object.entries(PO.properties).filter(([fieldName, value]) => getTypeofFieldValue(value) && schema.properties[fieldName]);
|
|
42
|
-
const nonDateProperties = validFields
|
|
43
|
-
.filter(d => !isDateField(schema)(d))
|
|
44
|
-
.map(([fieldName, value]) => {
|
|
45
|
-
var _a;
|
|
46
|
-
const verifiedBy = (0, ramda_1.uniq)((_a = realVers
|
|
47
|
-
.filter(x => x.belongsToNId === PO.n_id &&
|
|
48
|
-
x.fieldName === fieldName &&
|
|
49
|
-
x.provider.verifierNId)) === null || _a === void 0 ? void 0 : _a.map(x => x.provider.verifierNId));
|
|
50
|
-
const field = {
|
|
51
|
-
hField: {
|
|
52
|
-
__typeof__: helpers_1.HFieldSymbol,
|
|
53
|
-
cameFromSchema: schemaName,
|
|
54
|
-
verification: verified.fieldVerifications[fieldName],
|
|
55
|
-
verifiedBy,
|
|
56
|
-
},
|
|
57
|
-
type: getTypeofFieldValue(value),
|
|
58
|
-
value,
|
|
59
|
-
};
|
|
60
|
-
return [fieldName, field];
|
|
61
|
-
});
|
|
62
|
-
const dateFieldByCategorys = (0, ramda_1.groupBy)(([fieldName]) => schema.properties[fieldName].tags.find(tag => tag.startsWith("group:date_picker")), validFields.filter(isDateField(schema)));
|
|
63
|
-
// the three date fields become one pseudo field for the score system
|
|
64
|
-
const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag, members]) => {
|
|
65
|
-
var _a;
|
|
66
|
-
const groupName = groupTag.split(":")[2] || "NO_NAME";
|
|
67
|
-
const memberFieldNames = members.map(x => x[0]);
|
|
68
|
-
const worstVer = (0, ramda_1.sort)((a, b) => b - a, // find the highest enum value (that's the worst)
|
|
69
|
-
memberFieldNames.map(f => verified.fieldVerifications[f]))[0];
|
|
70
|
-
const fieldVers = (0, ramda_1.uniq)((_a = realVers
|
|
71
|
-
.filter(x => x.belongsToNId === PO.n_id &&
|
|
72
|
-
memberFieldNames.includes(x.fieldName) &&
|
|
73
|
-
x.provider.verifierNId)) === null || _a === void 0 ? void 0 : _a.map(v => v.provider.verifierNId).filter((val) => !!val));
|
|
74
|
-
const values = Object.fromEntries(members);
|
|
75
|
-
const dayFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:day"); });
|
|
76
|
-
const monthFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:month"); });
|
|
77
|
-
const yearFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:year"); });
|
|
78
|
-
if (!dayFieldName || !monthFieldName || !yearFieldName) {
|
|
79
|
-
throw new Error("Failed to infer date component field");
|
|
80
|
-
}
|
|
81
|
-
const isoString = [
|
|
82
|
-
values[yearFieldName],
|
|
83
|
-
`${values[monthFieldName]}`.padStart(2, "0"),
|
|
84
|
-
`${values[dayFieldName]}`.padStart(2, "0"),
|
|
85
|
-
].join("-");
|
|
86
|
-
const pseudoField = {
|
|
87
|
-
hField: {
|
|
88
|
-
__typeof__: helpers_1.HFieldSymbol,
|
|
89
|
-
cameFromSchema: schemaName,
|
|
90
|
-
verification: worstVer,
|
|
91
|
-
verifiedBy: fieldVers,
|
|
92
|
-
},
|
|
93
|
-
type: "Date",
|
|
94
|
-
value: new Date(isoString),
|
|
95
|
-
};
|
|
96
|
-
return [`__group_${groupName}`, pseudoField];
|
|
97
|
-
});
|
|
98
|
-
const deepProperties = Object.entries(PO.properties)
|
|
99
|
-
.filter(([fieldName, fieldValue]) => {
|
|
100
|
-
const field = schema.properties[fieldName];
|
|
101
|
-
return (field &&
|
|
102
|
-
field.type === "object" &&
|
|
103
|
-
field.properties &&
|
|
104
|
-
fieldValue &&
|
|
105
|
-
typeof fieldValue === "object");
|
|
106
|
-
})
|
|
107
|
-
.flatMap(([fieldName, fieldValue]) => {
|
|
108
|
-
const subFields = Object.keys(schema.properties[fieldName].properties);
|
|
109
|
-
return subFields.map(subFieldName => {
|
|
110
|
-
const value = fieldValue[subFieldName];
|
|
111
|
-
const hsubfield = {
|
|
112
|
-
hField: null,
|
|
113
|
-
type: getTypeofFieldValue(value),
|
|
114
|
-
value,
|
|
115
|
-
};
|
|
116
|
-
return [`${fieldName}|${subFieldName}`, hsubfield];
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
// eslint-disable-next-line fp/no-mutation
|
|
120
|
-
out[schemaName] || (out[schemaName] = []);
|
|
121
|
-
// eslint-disable-next-line fp/no-mutating-methods
|
|
122
|
-
out[schemaName].push({
|
|
123
|
-
hSchema: {
|
|
124
|
-
__typeof__: helpers_1.HSchemaSymbol,
|
|
125
|
-
verification: verified.status,
|
|
126
|
-
verifiedBy: verified.details.verifiers
|
|
127
|
-
.map(x => x.verifierNId)
|
|
128
|
-
.filter((val) => !!val),
|
|
129
|
-
},
|
|
130
|
-
properties: Object.fromEntries([
|
|
131
|
-
...nonDateProperties,
|
|
132
|
-
...pseudoDateFields,
|
|
133
|
-
...deepProperties,
|
|
134
|
-
]),
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return out;
|
|
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 (instance, realVers, getSchema) => {
|
|
30
|
+
const out = {};
|
|
31
|
+
// eslint-disable-next-line fp/no-loops
|
|
32
|
+
for (const PO of instance.profile_objects) {
|
|
33
|
+
const schemaName = (0, schema_1.findSchemaLabel)(PO.labels);
|
|
34
|
+
// eslint-disable-next-line no-continue
|
|
35
|
+
if (schemaName === VERIFICATION_SCHEMA)
|
|
36
|
+
continue;
|
|
37
|
+
const schema = await getSchema(schemaName);
|
|
38
|
+
const verified = (0, verifications_1.getPOVerification)({ PO, schema, realVers });
|
|
39
|
+
// remove anything we can't make rules for (e.g. object), and
|
|
40
|
+
// also remove any fields that aren't defined in the schema.
|
|
41
|
+
const validFields = Object.entries(PO.properties).filter(([fieldName, value]) => getTypeofFieldValue(value) && schema.properties[fieldName]);
|
|
42
|
+
const nonDateProperties = validFields
|
|
43
|
+
.filter(d => !isDateField(schema)(d))
|
|
44
|
+
.map(([fieldName, value]) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const verifiedBy = (0, ramda_1.uniq)((_a = realVers
|
|
47
|
+
.filter(x => x.belongsToNId === PO.n_id &&
|
|
48
|
+
x.fieldName === fieldName &&
|
|
49
|
+
x.provider.verifierNId)) === null || _a === void 0 ? void 0 : _a.map(x => x.provider.verifierNId));
|
|
50
|
+
const field = {
|
|
51
|
+
hField: {
|
|
52
|
+
__typeof__: helpers_1.HFieldSymbol,
|
|
53
|
+
cameFromSchema: schemaName,
|
|
54
|
+
verification: verified.fieldVerifications[fieldName],
|
|
55
|
+
verifiedBy,
|
|
56
|
+
},
|
|
57
|
+
type: getTypeofFieldValue(value),
|
|
58
|
+
value,
|
|
59
|
+
};
|
|
60
|
+
return [fieldName, field];
|
|
61
|
+
});
|
|
62
|
+
const dateFieldByCategorys = (0, ramda_1.groupBy)(([fieldName]) => schema.properties[fieldName].tags.find(tag => tag.startsWith("group:date_picker")), validFields.filter(isDateField(schema)));
|
|
63
|
+
// the three date fields become one pseudo field for the score system
|
|
64
|
+
const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag, members]) => {
|
|
65
|
+
var _a;
|
|
66
|
+
const groupName = groupTag.split(":")[2] || "NO_NAME";
|
|
67
|
+
const memberFieldNames = members.map(x => x[0]);
|
|
68
|
+
const worstVer = (0, ramda_1.sort)((a, b) => b - a, // find the highest enum value (that's the worst)
|
|
69
|
+
memberFieldNames.map(f => verified.fieldVerifications[f]))[0];
|
|
70
|
+
const fieldVers = (0, ramda_1.uniq)((_a = realVers
|
|
71
|
+
.filter(x => x.belongsToNId === PO.n_id &&
|
|
72
|
+
memberFieldNames.includes(x.fieldName) &&
|
|
73
|
+
x.provider.verifierNId)) === null || _a === void 0 ? void 0 : _a.map(v => v.provider.verifierNId).filter((val) => !!val));
|
|
74
|
+
const values = Object.fromEntries(members);
|
|
75
|
+
const dayFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:day"); });
|
|
76
|
+
const monthFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:month"); });
|
|
77
|
+
const yearFieldName = memberFieldNames.find(f => { var _a; return (_a = schema.properties[f].tags) === null || _a === void 0 ? void 0 : _a.includes("date_component:year"); });
|
|
78
|
+
if (!dayFieldName || !monthFieldName || !yearFieldName) {
|
|
79
|
+
throw new Error("Failed to infer date component field");
|
|
80
|
+
}
|
|
81
|
+
const isoString = [
|
|
82
|
+
values[yearFieldName],
|
|
83
|
+
`${values[monthFieldName]}`.padStart(2, "0"),
|
|
84
|
+
`${values[dayFieldName]}`.padStart(2, "0"),
|
|
85
|
+
].join("-");
|
|
86
|
+
const pseudoField = {
|
|
87
|
+
hField: {
|
|
88
|
+
__typeof__: helpers_1.HFieldSymbol,
|
|
89
|
+
cameFromSchema: schemaName,
|
|
90
|
+
verification: worstVer,
|
|
91
|
+
verifiedBy: fieldVers,
|
|
92
|
+
},
|
|
93
|
+
type: "Date",
|
|
94
|
+
value: new Date(isoString),
|
|
95
|
+
};
|
|
96
|
+
return [`__group_${groupName}`, pseudoField];
|
|
97
|
+
});
|
|
98
|
+
const deepProperties = Object.entries(PO.properties)
|
|
99
|
+
.filter(([fieldName, fieldValue]) => {
|
|
100
|
+
const field = schema.properties[fieldName];
|
|
101
|
+
return (field &&
|
|
102
|
+
field.type === "object" &&
|
|
103
|
+
field.properties &&
|
|
104
|
+
fieldValue &&
|
|
105
|
+
typeof fieldValue === "object");
|
|
106
|
+
})
|
|
107
|
+
.flatMap(([fieldName, fieldValue]) => {
|
|
108
|
+
const subFields = Object.keys(schema.properties[fieldName].properties);
|
|
109
|
+
return subFields.map(subFieldName => {
|
|
110
|
+
const value = fieldValue[subFieldName];
|
|
111
|
+
const hsubfield = {
|
|
112
|
+
hField: null,
|
|
113
|
+
type: getTypeofFieldValue(value),
|
|
114
|
+
value,
|
|
115
|
+
};
|
|
116
|
+
return [`${fieldName}|${subFieldName}`, hsubfield];
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
// eslint-disable-next-line fp/no-mutation
|
|
120
|
+
out[schemaName] || (out[schemaName] = []);
|
|
121
|
+
// eslint-disable-next-line fp/no-mutating-methods
|
|
122
|
+
out[schemaName].push({
|
|
123
|
+
hSchema: {
|
|
124
|
+
__typeof__: helpers_1.HSchemaSymbol,
|
|
125
|
+
verification: verified.status,
|
|
126
|
+
verifiedBy: verified.details.verifiers
|
|
127
|
+
.map(x => x.verifierNId)
|
|
128
|
+
.filter((val) => !!val),
|
|
129
|
+
},
|
|
130
|
+
properties: Object.fromEntries([
|
|
131
|
+
...nonDateProperties,
|
|
132
|
+
...pseudoDateFields,
|
|
133
|
+
...deepProperties,
|
|
134
|
+
]),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
};
|
|
139
|
+
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,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateScoreCondition = void 0;
|
|
4
|
-
/* eslint-disable fp/no-loops */
|
|
5
|
-
const ramda_1 = require("ramda");
|
|
6
|
-
const general_1 = require("../general");
|
|
7
|
-
const operators_1 = require("./operators");
|
|
8
|
-
const helpers_1 = require("./helpers");
|
|
9
|
-
function evaluateScoreCondition(node, data) {
|
|
10
|
-
(0, general_1.assertSafeProperty)(node.operator);
|
|
11
|
-
const op = operators_1.operators[node.operator];
|
|
12
|
-
if (!op) {
|
|
13
|
-
throw new Error(`Operator '${node.operator}' is not known`);
|
|
14
|
-
}
|
|
15
|
-
if (node.values.length !== op.operands.length) {
|
|
16
|
-
throw new Error(`Operator argument length mismatch for '${node.operator}'`);
|
|
17
|
-
}
|
|
18
|
-
const rawValues = node.values
|
|
19
|
-
.map(x => x.value.type === "constant"
|
|
20
|
-
? [x.value.value]
|
|
21
|
-
: (0, helpers_1.getValuesFromPath)(x.value.path, data))
|
|
22
|
-
.map(valuesForArg => valuesForArg.filter(v => typeof v !== "undefined"));
|
|
23
|
-
for (const [i, argType] of op.operands.entries()) {
|
|
24
|
-
if ((0, helpers_1.simplifyValueType)(argType) !== (0, helpers_1.simplifyValueType)(node.values[i].type)) {
|
|
25
|
-
throw new TypeError(`Operator argument ${i} expected ${argType} but got ${node.values[i].type} for '${node.operator}'`);
|
|
26
|
-
}
|
|
27
|
-
const values = rawValues[i];
|
|
28
|
-
if (!values.length) {
|
|
29
|
-
// TODO: if one of the values required for your rule doesn't exist, then what?
|
|
30
|
-
// for now, the rule will return false.
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
// also check if the claimed type of the value matches the actual type of the value
|
|
34
|
-
for (const value of values) {
|
|
35
|
-
if (!(0, helpers_1.checkTypeofValue)(argType, value)) {
|
|
36
|
-
throw new Error(`Operator argument ${i} falsely claimed to be ${argType} for '${node.operator}'`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const options = (0, ramda_1.transpose)(rawValues);
|
|
41
|
-
// everything adds up so far, so we can call the function for each
|
|
42
|
-
// data value. Return true if ANY of the values return true.
|
|
43
|
-
return options.some(args => op.implementation(...args));
|
|
44
|
-
}
|
|
45
|
-
exports.evaluateScoreCondition = evaluateScoreCondition;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateScoreCondition = void 0;
|
|
4
|
+
/* eslint-disable fp/no-loops */
|
|
5
|
+
const ramda_1 = require("ramda");
|
|
6
|
+
const general_1 = require("../general");
|
|
7
|
+
const operators_1 = require("./operators");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
function evaluateScoreCondition(node, data) {
|
|
10
|
+
(0, general_1.assertSafeProperty)(node.operator);
|
|
11
|
+
const op = operators_1.operators[node.operator];
|
|
12
|
+
if (!op) {
|
|
13
|
+
throw new Error(`Operator '${node.operator}' is not known`);
|
|
14
|
+
}
|
|
15
|
+
if (node.values.length !== op.operands.length) {
|
|
16
|
+
throw new Error(`Operator argument length mismatch for '${node.operator}'`);
|
|
17
|
+
}
|
|
18
|
+
const rawValues = node.values
|
|
19
|
+
.map(x => x.value.type === "constant"
|
|
20
|
+
? [x.value.value]
|
|
21
|
+
: (0, helpers_1.getValuesFromPath)(x.value.path, data))
|
|
22
|
+
.map(valuesForArg => valuesForArg.filter(v => typeof v !== "undefined"));
|
|
23
|
+
for (const [i, argType] of op.operands.entries()) {
|
|
24
|
+
if ((0, helpers_1.simplifyValueType)(argType) !== (0, helpers_1.simplifyValueType)(node.values[i].type)) {
|
|
25
|
+
throw new TypeError(`Operator argument ${i} expected ${argType} but got ${node.values[i].type} for '${node.operator}'`);
|
|
26
|
+
}
|
|
27
|
+
const values = rawValues[i];
|
|
28
|
+
if (!values.length) {
|
|
29
|
+
// TODO: if one of the values required for your rule doesn't exist, then what?
|
|
30
|
+
// for now, the rule will return false.
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// also check if the claimed type of the value matches the actual type of the value
|
|
34
|
+
for (const value of values) {
|
|
35
|
+
if (!(0, helpers_1.checkTypeofValue)(argType, value)) {
|
|
36
|
+
throw new Error(`Operator argument ${i} falsely claimed to be ${argType} for '${node.operator}'`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const options = (0, ramda_1.transpose)(rawValues);
|
|
41
|
+
// everything adds up so far, so we can call the function for each
|
|
42
|
+
// data value. Return true if ANY of the values return true.
|
|
43
|
+
return options.some(args => op.implementation(...args));
|
|
44
|
+
}
|
|
45
|
+
exports.evaluateScoreCondition = evaluateScoreCondition;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ScoreThreshold } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* @ignore the first and last threshold boundaries are -Infinity and +Infinity.
|
|
4
|
-
* We override whatever is specified to ensure these boundaries are infinite.
|
|
5
|
-
*
|
|
6
|
-
* This is also needed because json converts non-finite numbers to `null`
|
|
7
|
-
*/
|
|
8
|
-
export declare const addInfiniteThresholdBoundaries: (list: readonly ScoreThreshold[]) => ScoreThreshold[];
|
|
1
|
+
import { ScoreThreshold } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* @ignore the first and last threshold boundaries are -Infinity and +Infinity.
|
|
4
|
+
* We override whatever is specified to ensure these boundaries are infinite.
|
|
5
|
+
*
|
|
6
|
+
* This is also needed because json converts non-finite numbers to `null`
|
|
7
|
+
*/
|
|
8
|
+
export declare const addInfiniteThresholdBoundaries: (list: readonly ScoreThreshold[]) => ScoreThreshold[];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addInfiniteThresholdBoundaries = void 0;
|
|
4
|
-
const ramda_1 = require("ramda");
|
|
5
|
-
/**
|
|
6
|
-
* @ignore the first and last threshold boundaries are -Infinity and +Infinity.
|
|
7
|
-
* We override whatever is specified to ensure these boundaries are infinite.
|
|
8
|
-
*
|
|
9
|
-
* This is also needed because json converts non-finite numbers to `null`
|
|
10
|
-
*/
|
|
11
|
-
exports.addInfiniteThresholdBoundaries = (0, ramda_1.pipe)((0, ramda_1.adjust)(0, v => (Object.assign(Object.assign({}, v), { from: -Infinity }))), (0, ramda_1.adjust)(-1, v => (Object.assign(Object.assign({}, v), { to: Infinity }))));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addInfiniteThresholdBoundaries = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
/**
|
|
6
|
+
* @ignore the first and last threshold boundaries are -Infinity and +Infinity.
|
|
7
|
+
* We override whatever is specified to ensure these boundaries are infinite.
|
|
8
|
+
*
|
|
9
|
+
* This is also needed because json converts non-finite numbers to `null`
|
|
10
|
+
*/
|
|
11
|
+
exports.addInfiniteThresholdBoundaries = (0, ramda_1.pipe)((0, ramda_1.adjust)(0, v => (Object.assign(Object.assign({}, v), { from: -Infinity }))), (0, ramda_1.adjust)(-1, v => (Object.assign(Object.assign({}, v), { to: Infinity }))));
|
|
@@ -1,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;
|