@raytio/core 8.1.0 → 9.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/README.md +460 -1
- package/dist/accessApplication/createAA.js +0 -1
- package/dist/crypto/decryptKeys.js +0 -2
- package/dist/crypto/decryptSharedData.js +7 -4
- package/dist/crypto/helpers.d.ts +1 -1
- package/dist/general/index.d.ts +1 -0
- package/dist/general/index.js +1 -0
- package/dist/general/types.d.ts +6 -0
- package/dist/general/types.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/rules/calculateScore.d.ts +11 -0
- package/dist/rules/calculateScore.js +52 -0
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -0
- package/dist/rules/convertInstanceToRuleInput.js +140 -0
- package/dist/rules/evaluateScoreCondition.d.ts +2 -0
- package/dist/rules/evaluateScoreCondition.js +45 -0
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -0
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -0
- package/dist/rules/helpers/checkTypeofValue.d.ts +3 -0
- package/dist/rules/helpers/checkTypeofValue.js +43 -0
- package/dist/rules/helpers/getValuesFromPath.d.ts +3 -0
- package/dist/rules/helpers/getValuesFromPath.js +50 -0
- package/dist/rules/helpers/index.d.ts +5 -0
- package/dist/rules/helpers/index.js +17 -0
- package/dist/rules/helpers/symbols.d.ts +2 -0
- package/dist/rules/helpers/symbols.js +5 -0
- package/dist/rules/helpers/thresholds.d.ts +5 -0
- package/dist/rules/helpers/thresholds.js +47 -0
- package/dist/rules/index.d.ts +6 -0
- package/dist/rules/index.js +20 -0
- package/dist/rules/operators/bool.d.ts +2 -0
- package/dist/rules/operators/bool.js +17 -0
- package/dist/rules/operators/date.d.ts +2 -0
- package/dist/rules/operators/date.js +91 -0
- package/dist/rules/operators/hfield.d.ts +2 -0
- package/dist/rules/operators/hfield.js +33 -0
- package/dist/rules/operators/hschema.d.ts +2 -0
- package/dist/rules/operators/hschema.js +21 -0
- package/dist/rules/operators/index.d.ts +3 -0
- package/dist/rules/operators/index.js +11 -0
- package/dist/rules/operators/number.d.ts +2 -0
- package/dist/rules/operators/number.js +41 -0
- package/dist/rules/operators/string.d.ts +2 -0
- package/dist/rules/operators/string.js +58 -0
- package/dist/rules/types/config.d.ts +86 -0
- package/dist/rules/types/config.js +2 -0
- package/dist/rules/types/dataValueTypes.d.ts +19 -0
- package/dist/rules/types/dataValueTypes.js +4 -0
- package/dist/rules/types/index.d.ts +3 -0
- package/dist/rules/types/index.js +15 -0
- package/dist/rules/types/internal.d.ts +20 -0
- package/dist/rules/types/internal.js +2 -0
- package/dist/{verifications/checkVerifications.d.ts → util/canonicalJsonify.d.ts} +0 -0
- package/dist/util/canonicalJsonify.js +48 -0
- package/dist/util/handleResponse.js +0 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/verifications/cleanInstance.d.ts +9 -0
- package/dist/verifications/cleanInstance.js +15 -0
- package/dist/verifications/getPOVerification.d.ts +5 -2
- package/dist/verifications/getPOVerification.js +3 -4
- package/dist/verifications/index.d.ts +2 -1
- package/dist/verifications/index.js +2 -1
- package/dist/verifications/safeHarbour.d.ts +2 -3
- package/dist/verifications/safeHarbour.js +2 -2
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -0
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +63 -0
- package/dist/verifications/{getRealVerifications.d.ts → verifyCheck/getSomeoneElsesRealVerifications.d.ts} +6 -2
- package/dist/verifications/{getRealVerifications.js → verifyCheck/getSomeoneElsesRealVerifications.js} +26 -16
- package/dist/verifications/verifyCheck/index.d.ts +2 -0
- package/dist/verifications/verifyCheck/index.js +14 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +9 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +31 -0
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -0
- package/dist/verifications/{checkVerifications.js → verifyCheck/operations/checkSomeoneElsesVerifications.js} +4 -4
- package/dist/verifications/verifyCheck/operations/index.d.ts +2 -0
- package/dist/verifications/verifyCheck/operations/index.js +14 -0
- package/package.json +8 -8
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
// TODO: better system
|
|
76
|
+
const dayFieldName = memberFieldNames.find(f => f.includes("day"));
|
|
77
|
+
const monthFieldName = memberFieldNames.find(f => f.includes("month"));
|
|
78
|
+
const yearFieldName = memberFieldNames.find(f => f.includes("year"));
|
|
79
|
+
if (!dayFieldName || !monthFieldName || !yearFieldName) {
|
|
80
|
+
throw new Error("Failed to infer date component field");
|
|
81
|
+
}
|
|
82
|
+
const isoString = [
|
|
83
|
+
values[yearFieldName],
|
|
84
|
+
`${values[monthFieldName]}`.padStart(2, "0"),
|
|
85
|
+
`${values[dayFieldName]}`.padStart(2, "0"),
|
|
86
|
+
].join("-");
|
|
87
|
+
const pseudoField = {
|
|
88
|
+
hField: {
|
|
89
|
+
__typeof__: helpers_1.HFieldSymbol,
|
|
90
|
+
cameFromSchema: schemaName,
|
|
91
|
+
verification: worstVer,
|
|
92
|
+
verifiedBy: fieldVers,
|
|
93
|
+
},
|
|
94
|
+
type: "Date",
|
|
95
|
+
value: new Date(isoString),
|
|
96
|
+
};
|
|
97
|
+
return [`__group_${groupName}`, pseudoField];
|
|
98
|
+
});
|
|
99
|
+
const deepProperties = Object.entries(PO.properties)
|
|
100
|
+
.filter(([fieldName, fieldValue]) => {
|
|
101
|
+
const field = schema.properties[fieldName];
|
|
102
|
+
return (field &&
|
|
103
|
+
field.type === "object" &&
|
|
104
|
+
field.properties &&
|
|
105
|
+
fieldValue &&
|
|
106
|
+
typeof fieldValue === "object");
|
|
107
|
+
})
|
|
108
|
+
.flatMap(([fieldName, fieldValue]) => {
|
|
109
|
+
const subFields = Object.keys(schema.properties[fieldName].properties);
|
|
110
|
+
return subFields.map(subFieldName => {
|
|
111
|
+
const value = fieldValue[subFieldName];
|
|
112
|
+
const hsubfield = {
|
|
113
|
+
hField: null,
|
|
114
|
+
type: getTypeofFieldValue(value),
|
|
115
|
+
value,
|
|
116
|
+
};
|
|
117
|
+
return [`${fieldName}|${subFieldName}`, hsubfield];
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
// eslint-disable-next-line fp/no-mutation
|
|
121
|
+
out[schemaName] || (out[schemaName] = []);
|
|
122
|
+
// eslint-disable-next-line fp/no-mutating-methods
|
|
123
|
+
out[schemaName].push({
|
|
124
|
+
hSchema: {
|
|
125
|
+
__typeof__: helpers_1.HSchemaSymbol,
|
|
126
|
+
verification: verified.status,
|
|
127
|
+
verifiedBy: verified.details.verifiers
|
|
128
|
+
.map(x => x.verifierNId)
|
|
129
|
+
.filter((val) => !!val),
|
|
130
|
+
},
|
|
131
|
+
properties: Object.fromEntries([
|
|
132
|
+
...nonDateProperties,
|
|
133
|
+
...pseudoDateFields,
|
|
134
|
+
...deepProperties,
|
|
135
|
+
]),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
};
|
|
140
|
+
exports.convertInstanceToRuleInput = convertInstanceToRuleInput;
|
|
@@ -0,0 +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 (argType !== 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 value
|
|
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;
|
|
@@ -0,0 +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[];
|
|
@@ -0,0 +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 }))));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkTypeofValue = void 0;
|
|
4
|
+
const types_1 = require("@raytio/types");
|
|
5
|
+
const symbols_1 = require("./symbols");
|
|
6
|
+
const types_2 = require("../types");
|
|
7
|
+
const VALID_DATE_UNITS = types_2.DATE_UNITS;
|
|
8
|
+
// we need this function beacuse TS's typeguards aren't great
|
|
9
|
+
const isObjectWithTypeofProp = (x) => typeof x === "object" && !!x && "__typeof__" in x;
|
|
10
|
+
/** asserts that the provided `value` meets the constaints of `type` */
|
|
11
|
+
function checkTypeofValue(type, value) {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case "Array":
|
|
14
|
+
return Array.isArray(value);
|
|
15
|
+
case "Bool":
|
|
16
|
+
return typeof value === "boolean";
|
|
17
|
+
case "Date":
|
|
18
|
+
return value instanceof Date;
|
|
19
|
+
case "DateUnit":
|
|
20
|
+
return typeof value === "string" && VALID_DATE_UNITS.includes(value);
|
|
21
|
+
case "FieldVerification":
|
|
22
|
+
return typeof value === "number" && value in types_1.FieldVerification;
|
|
23
|
+
case "HField":
|
|
24
|
+
// this is fakeable (you could make a constant object with these props),
|
|
25
|
+
// but that's not a concern in this context.
|
|
26
|
+
return isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HFieldSymbol;
|
|
27
|
+
case "HSchema":
|
|
28
|
+
// this is fakeable (you could make a constant object with these props),
|
|
29
|
+
// but that's not a concern in this context.
|
|
30
|
+
return (isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HSchemaSymbol);
|
|
31
|
+
case "Number":
|
|
32
|
+
return typeof value === "number";
|
|
33
|
+
case "POVerification":
|
|
34
|
+
return typeof value === "number" && value in types_1.POVerification;
|
|
35
|
+
case "RegEx":
|
|
36
|
+
return value instanceof RegExp;
|
|
37
|
+
case "String":
|
|
38
|
+
return typeof value === "string";
|
|
39
|
+
default:
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.checkTypeofValue = checkTypeofValue;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValuesFromPath = void 0;
|
|
4
|
+
const general_1 = require("../../general");
|
|
5
|
+
/** this returns an array because there might be multiple of the same schema shared */
|
|
6
|
+
function getValuesFromPath(path, data) {
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
|
+
const type = path[0];
|
|
9
|
+
switch (type) {
|
|
10
|
+
case "field": {
|
|
11
|
+
const [, schemaName, fieldName, attr] = path;
|
|
12
|
+
(0, general_1.assertSafeProperty)(schemaName);
|
|
13
|
+
(0, general_1.assertSafeProperty)(fieldName);
|
|
14
|
+
(0, general_1.assertSafeProperty)(attr);
|
|
15
|
+
if (attr === "meta") {
|
|
16
|
+
return (((_a = data[schemaName]) === null || _a === void 0 ? void 0 : _a.map(x => { var _a; return (_a = x.properties[fieldName]) === null || _a === void 0 ? void 0 : _a.hField; })) || []);
|
|
17
|
+
}
|
|
18
|
+
const values = ((_b = data[schemaName]) === null || _b === void 0 ? void 0 : _b.map(x => { var _a; return (_a = x.properties[fieldName]) === null || _a === void 0 ? void 0 : _a.value; })) || [];
|
|
19
|
+
if (attr === "value")
|
|
20
|
+
return values;
|
|
21
|
+
if (attr === "valueLength") {
|
|
22
|
+
return values.map(v => {
|
|
23
|
+
if (typeof v === "string" || Array.isArray(v))
|
|
24
|
+
return v.length;
|
|
25
|
+
throw new Error("valueLength may only be used on arrays and strings");
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (attr === null || attr === void 0 ? void 0 : attr.startsWith("subField|")) {
|
|
29
|
+
const subFieldName = attr.slice(9);
|
|
30
|
+
(0, general_1.assertSafeProperty)(subFieldName);
|
|
31
|
+
const key = `${fieldName}|${subFieldName}`;
|
|
32
|
+
const subValueList = ((_c = data[schemaName]) === null || _c === void 0 ? void 0 : _c.map(x => { var _a; return (_a = x.properties[key]) === null || _a === void 0 ? void 0 : _a.value; })) || [];
|
|
33
|
+
return subValueList;
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Invalid ValuePath[3] for field (${attr})`);
|
|
36
|
+
}
|
|
37
|
+
case "schema": {
|
|
38
|
+
const [, schemaName, attr] = path;
|
|
39
|
+
(0, general_1.assertSafeProperty)(schemaName);
|
|
40
|
+
(0, general_1.assertSafeProperty)(attr);
|
|
41
|
+
if (attr === "meta") {
|
|
42
|
+
return ((_d = data[schemaName]) === null || _d === void 0 ? void 0 : _d.map(x => x.hSchema)) || [];
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Invalid ValuePath[2] for schema (${attr})`);
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Invalid ValuePath[0] (${type})`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.getValuesFromPath = getValuesFromPath;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./addInfiniteThresholdBoundaries"), exports);
|
|
14
|
+
__exportStar(require("./checkTypeofValue"), exports);
|
|
15
|
+
__exportStar(require("./getValuesFromPath"), exports);
|
|
16
|
+
__exportStar(require("./symbols"), exports);
|
|
17
|
+
__exportStar(require("./thresholds"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Combinator, ScoreRule } from "../types";
|
|
2
|
+
/** @ignore */
|
|
3
|
+
export declare function getCombinator(combinator: Combinator): [func: (a: number, b: number) => number, initialValue: number];
|
|
4
|
+
/** @ignore */
|
|
5
|
+
export declare function getThresholdBoundary(combinator: Combinator, rules: ScoreRule[]): [lowest: number, highest: number];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getThresholdBoundary = exports.getCombinator = void 0;
|
|
4
|
+
/** @ignore */
|
|
5
|
+
function getCombinator(combinator) {
|
|
6
|
+
switch (combinator) {
|
|
7
|
+
case "+":
|
|
8
|
+
return [(a, b) => a + b, 0];
|
|
9
|
+
case "*":
|
|
10
|
+
return [(a, b) => a * b, 1];
|
|
11
|
+
default:
|
|
12
|
+
throw new Error("Invalid combinator");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.getCombinator = getCombinator;
|
|
16
|
+
/** @ignore */
|
|
17
|
+
function getThresholdBoundary(combinator, rules) {
|
|
18
|
+
switch (combinator) {
|
|
19
|
+
case "+": {
|
|
20
|
+
const lowest = rules.reduce((ac, r) => ac + Math.min(r.falseWeight, r.trueWeight), 0);
|
|
21
|
+
const highest = rules.reduce((ac, r) => ac + Math.max(r.falseWeight, r.trueWeight), 0);
|
|
22
|
+
return [lowest, highest];
|
|
23
|
+
}
|
|
24
|
+
case "*": {
|
|
25
|
+
// eslint-disable-next-line fp/no-let
|
|
26
|
+
let [lowest, highest] = [Infinity, -Infinity];
|
|
27
|
+
// eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation
|
|
28
|
+
for (let i = 0; i < 2 * rules.length; i += 1) {
|
|
29
|
+
// loop for every possible combination (2*rules.rength), and check that combination
|
|
30
|
+
const product = i
|
|
31
|
+
.toString(2)
|
|
32
|
+
.padStart(rules.length, "0")
|
|
33
|
+
.split("")
|
|
34
|
+
.map((bool, j) => rules[j][bool === "1" ? "trueWeight" : "falseWeight"])
|
|
35
|
+
.reduce((a, b) => a * b, 1);
|
|
36
|
+
if (product > highest)
|
|
37
|
+
highest = product; // eslint-disable-line fp/no-mutation
|
|
38
|
+
if (product < lowest)
|
|
39
|
+
lowest = product; // eslint-disable-line fp/no-mutation
|
|
40
|
+
}
|
|
41
|
+
return [lowest, highest];
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
throw new Error("Invalid combinator");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.getThresholdBoundary = getThresholdBoundary;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./calculateScore";
|
|
2
|
+
export * from "./convertInstanceToRuleInput";
|
|
3
|
+
export * from "./types/config";
|
|
4
|
+
export * from "./helpers/thresholds";
|
|
5
|
+
export * from "./helpers/addInfiniteThresholdBoundaries";
|
|
6
|
+
export { operators as scoreOperators } from "./operators";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.scoreOperators = void 0;
|
|
14
|
+
__exportStar(require("./calculateScore"), exports);
|
|
15
|
+
__exportStar(require("./convertInstanceToRuleInput"), exports);
|
|
16
|
+
__exportStar(require("./types/config"), exports);
|
|
17
|
+
__exportStar(require("./helpers/thresholds"), exports);
|
|
18
|
+
__exportStar(require("./helpers/addInfiniteThresholdBoundaries"), exports);
|
|
19
|
+
var operators_1 = require("./operators");
|
|
20
|
+
Object.defineProperty(exports, "scoreOperators", { enumerable: true, get: function () { return operators_1.operators; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.boolOperators = void 0;
|
|
4
|
+
exports.boolOperators = {
|
|
5
|
+
bool_eq: {
|
|
6
|
+
operands: ["Bool", "Bool"],
|
|
7
|
+
implementation(b1, b2) {
|
|
8
|
+
return b1 === b2;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
bool_neq: {
|
|
12
|
+
operands: ["Bool", "Bool"],
|
|
13
|
+
implementation(b1, b2) {
|
|
14
|
+
return b1 !== b2;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateOperators = void 0;
|
|
4
|
+
function getDateInXUnits(offset, unit) {
|
|
5
|
+
const d = new Date();
|
|
6
|
+
switch (unit) {
|
|
7
|
+
case "ms":
|
|
8
|
+
d.setMilliseconds(d.getMilliseconds() + offset);
|
|
9
|
+
break;
|
|
10
|
+
case "s":
|
|
11
|
+
d.setSeconds(d.getSeconds() + offset);
|
|
12
|
+
break;
|
|
13
|
+
case "m":
|
|
14
|
+
d.setMinutes(d.getMinutes() + offset);
|
|
15
|
+
break;
|
|
16
|
+
case "h":
|
|
17
|
+
d.setHours(d.getHours() + offset);
|
|
18
|
+
break;
|
|
19
|
+
case "D":
|
|
20
|
+
d.setDate(d.getDate() + offset);
|
|
21
|
+
break;
|
|
22
|
+
case "M":
|
|
23
|
+
d.setMonth(d.getMonth() + offset);
|
|
24
|
+
break;
|
|
25
|
+
case "W":
|
|
26
|
+
d.setDate(d.getDate() + 7 * offset);
|
|
27
|
+
break;
|
|
28
|
+
case "Y":
|
|
29
|
+
d.setFullYear(d.getFullYear() + offset);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`Invalid date unit: ${unit}`);
|
|
33
|
+
}
|
|
34
|
+
return d;
|
|
35
|
+
}
|
|
36
|
+
exports.dateOperators = {
|
|
37
|
+
date_eq: {
|
|
38
|
+
operands: ["Date", "Date"],
|
|
39
|
+
implementation(d1, d2) {
|
|
40
|
+
// only comaparing dates (not times), and in the UTC timezone.
|
|
41
|
+
const isoDate1 = d1.toISOString().split("T")[0];
|
|
42
|
+
const isoDate2 = d2.toISOString().split("T")[0];
|
|
43
|
+
return isoDate1 === isoDate2;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
date_neq: {
|
|
47
|
+
operands: ["Date", "Date"],
|
|
48
|
+
implementation(d1, d2) {
|
|
49
|
+
// only comaparing dates (not times), and in the UTC timezone.
|
|
50
|
+
const isoDate1 = d1.toISOString().split("T")[0];
|
|
51
|
+
const isoDate2 = d2.toISOString().split("T")[0];
|
|
52
|
+
return isoDate1 !== isoDate2;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
date_valid: {
|
|
56
|
+
operands: ["Date"],
|
|
57
|
+
implementation: (d) => !Number.isNaN(+d),
|
|
58
|
+
},
|
|
59
|
+
date_invalid: {
|
|
60
|
+
operands: ["Date"],
|
|
61
|
+
implementation: (d) => Number.isNaN(+d),
|
|
62
|
+
},
|
|
63
|
+
date_before: {
|
|
64
|
+
operands: ["Date", "Date"],
|
|
65
|
+
implementation: (d1, d2) => d1 < d2,
|
|
66
|
+
},
|
|
67
|
+
date_after: {
|
|
68
|
+
operands: ["Date", "Date"],
|
|
69
|
+
implementation: (d1, d2) => d1 > d2,
|
|
70
|
+
},
|
|
71
|
+
date_between: {
|
|
72
|
+
operands: ["Date", "Date", "Date"],
|
|
73
|
+
implementation(lhs, lower, upper) {
|
|
74
|
+
return lhs >= lower && lhs <= upper;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
date_older_than: {
|
|
78
|
+
operands: ["Date", "Number", "DateUnit"],
|
|
79
|
+
implementation(date, num, unit) {
|
|
80
|
+
const XUnitsAgo = getDateInXUnits(-num, unit);
|
|
81
|
+
return date < XUnitsAgo;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
date_newer_than: {
|
|
85
|
+
operands: ["Date", "Number", "DateUnit"],
|
|
86
|
+
implementation(date, num, unit) {
|
|
87
|
+
const inXUnits = getDateInXUnits(num, unit);
|
|
88
|
+
return date > inXUnits;
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fieldOperators = void 0;
|
|
4
|
+
exports.fieldOperators = {
|
|
5
|
+
field_verifiedBy: {
|
|
6
|
+
operands: ["HField", "String"],
|
|
7
|
+
implementation(field, verifiedBy) {
|
|
8
|
+
return field.verifiedBy.includes(verifiedBy);
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
field_shared: {
|
|
12
|
+
operands: ["HField"],
|
|
13
|
+
implementation: () => true, // we can return true, because if the field didn't exist, this would never be called
|
|
14
|
+
},
|
|
15
|
+
field_hasVerStatus: {
|
|
16
|
+
operands: ["HField", "FieldVerification"],
|
|
17
|
+
implementation(field, status) {
|
|
18
|
+
return field.verification === status;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
field_cameFromSchema: {
|
|
22
|
+
operands: ["HField", "String"],
|
|
23
|
+
implementation(field, schemaName) {
|
|
24
|
+
return field.cameFromSchema === schemaName;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
field_ncameFromSchema: {
|
|
28
|
+
operands: ["HField", "String"],
|
|
29
|
+
implementation(field, schemaName) {
|
|
30
|
+
return field.cameFromSchema !== schemaName;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaOperators = void 0;
|
|
4
|
+
exports.schemaOperators = {
|
|
5
|
+
schema_verifiedBy: {
|
|
6
|
+
operands: ["HSchema", "String"],
|
|
7
|
+
implementation(schema, verifiedBy) {
|
|
8
|
+
return schema === null || schema === void 0 ? void 0 : schema.verifiedBy.includes(verifiedBy);
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
schema_shared: {
|
|
12
|
+
operands: ["HSchema"],
|
|
13
|
+
implementation: () => true, // we can return true, because if the schema didn't exist, this would never be called
|
|
14
|
+
},
|
|
15
|
+
schema_hasVerStatus: {
|
|
16
|
+
operands: ["HSchema", "POVerification"],
|
|
17
|
+
implementation(schema, status) {
|
|
18
|
+
return (schema === null || schema === void 0 ? void 0 : schema.verification) === status;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.operators = void 0;
|
|
4
|
+
const bool_1 = require("./bool");
|
|
5
|
+
const date_1 = require("./date");
|
|
6
|
+
const hfield_1 = require("./hfield");
|
|
7
|
+
const hschema_1 = require("./hschema");
|
|
8
|
+
const number_1 = require("./number");
|
|
9
|
+
const string_1 = require("./string");
|
|
10
|
+
/** @ignore */
|
|
11
|
+
exports.operators = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, bool_1.boolOperators), date_1.dateOperators), hfield_1.fieldOperators), hschema_1.schemaOperators), number_1.numberOperators), string_1.stringOperators);
|