@raytio/core 10.1.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +100 -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/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/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 +74 -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,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 {};
|
|
@@ -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 }))));
|