@degenerate/rules 0.0.1

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.
Files changed (188) hide show
  1. package/README.md +3 -0
  2. package/dist/generic/src/_settings/cryptography-settings.d.ts +27 -0
  3. package/dist/generic/src/_settings/cryptography-settings.d.ts.map +1 -0
  4. package/dist/generic/src/_settings/cryptography-settings.js +27 -0
  5. package/dist/generic/src/crypto/calculate-combined-hash.d.ts +13 -0
  6. package/dist/generic/src/crypto/calculate-combined-hash.d.ts.map +1 -0
  7. package/dist/generic/src/crypto/calculate-combined-hash.js +44 -0
  8. package/dist/generic/src/crypto/calculate-hash.d.ts +7 -0
  9. package/dist/generic/src/crypto/calculate-hash.d.ts.map +1 -0
  10. package/dist/generic/src/crypto/calculate-hash.js +37 -0
  11. package/dist/generic/src/crypto/index.d.ts +13 -0
  12. package/dist/generic/src/crypto/index.d.ts.map +1 -0
  13. package/dist/generic/src/crypto/index.js +34 -0
  14. package/dist/generic/src/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts +12 -0
  15. package/dist/generic/src/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts.map +1 -0
  16. package/dist/generic/src/crypto/private-public-keys/create-key-pair-from-mnemonic.js +44 -0
  17. package/dist/generic/src/crypto/private-public-keys/create-key-pair-from-private-key.d.ts +11 -0
  18. package/dist/generic/src/crypto/private-public-keys/create-key-pair-from-private-key.d.ts.map +1 -0
  19. package/dist/generic/src/crypto/private-public-keys/create-key-pair-from-private-key.js +40 -0
  20. package/dist/generic/src/crypto/private-public-keys/generation/create-256-private-key-from-mnemonic.d.ts +11 -0
  21. package/dist/generic/src/crypto/private-public-keys/generation/create-256-private-key-from-mnemonic.d.ts.map +1 -0
  22. package/dist/generic/src/crypto/private-public-keys/generation/create-256-private-key-from-mnemonic.js +45 -0
  23. package/dist/generic/src/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts +10 -0
  24. package/dist/generic/src/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map +1 -0
  25. package/dist/generic/src/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.js +40 -0
  26. package/dist/generic/src/crypto/private-public-keys/generation/create-random-256-private-key.d.ts +8 -0
  27. package/dist/generic/src/crypto/private-public-keys/generation/create-random-256-private-key.d.ts.map +1 -0
  28. package/dist/generic/src/crypto/private-public-keys/generation/create-random-256-private-key.js +41 -0
  29. package/dist/generic/src/crypto/private-public-keys/generation/generate-key-pair.d.ts +11 -0
  30. package/dist/generic/src/crypto/private-public-keys/generation/generate-key-pair.d.ts.map +1 -0
  31. package/dist/generic/src/crypto/private-public-keys/generation/generate-key-pair.js +39 -0
  32. package/dist/generic/src/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts +15 -0
  33. package/dist/generic/src/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts.map +1 -0
  34. package/dist/generic/src/crypto/private-public-keys/generation/get-private-public-key-from-keypair.js +21 -0
  35. package/dist/generic/src/crypto/signature/create-crypto-signature.d.ts +9 -0
  36. package/dist/generic/src/crypto/signature/create-crypto-signature.d.ts.map +1 -0
  37. package/dist/generic/src/crypto/signature/create-crypto-signature.js +13 -0
  38. package/dist/generic/src/crypto/signature/verify-crypto-signature-by-data.d.ts +13 -0
  39. package/dist/generic/src/crypto/signature/verify-crypto-signature-by-data.d.ts.map +1 -0
  40. package/dist/generic/src/crypto/signature/verify-crypto-signature-by-data.js +45 -0
  41. package/dist/generic/src/crypto/signature/verify-crypto-signature-by-hash.d.ts +13 -0
  42. package/dist/generic/src/crypto/signature/verify-crypto-signature-by-hash.d.ts.map +1 -0
  43. package/dist/generic/src/crypto/signature/verify-crypto-signature-by-hash.js +42 -0
  44. package/dist/generic/src/errors/base-error.d.ts +23 -0
  45. package/dist/generic/src/errors/base-error.d.ts.map +1 -0
  46. package/dist/generic/src/errors/base-error.js +34 -0
  47. package/dist/generic/src/errors/generic/generic-errors.d.ts +35 -0
  48. package/dist/generic/src/errors/generic/generic-errors.d.ts.map +1 -0
  49. package/dist/generic/src/errors/generic/generic-errors.js +47 -0
  50. package/dist/generic/src/errors/index.d.ts +7 -0
  51. package/dist/generic/src/errors/index.d.ts.map +1 -0
  52. package/dist/generic/src/errors/index.js +22 -0
  53. package/dist/generic/src/errors/request/request-errors.d.ts +89 -0
  54. package/dist/generic/src/errors/request/request-errors.d.ts.map +1 -0
  55. package/dist/generic/src/errors/request/request-errors.js +120 -0
  56. package/dist/generic/src/errors/safe/safe-rules-errors.d.ts +11 -0
  57. package/dist/generic/src/errors/safe/safe-rules-errors.d.ts.map +1 -0
  58. package/dist/generic/src/errors/safe/safe-rules-errors.js +17 -0
  59. package/dist/generic/src/errors/scheduler/scheduler-errors.d.ts +8 -0
  60. package/dist/generic/src/errors/scheduler/scheduler-errors.d.ts.map +1 -0
  61. package/dist/generic/src/errors/scheduler/scheduler-errors.js +14 -0
  62. package/dist/generic/src/errors/share-data/share-data-errors.d.ts +49 -0
  63. package/dist/generic/src/errors/share-data/share-data-errors.d.ts.map +1 -0
  64. package/dist/generic/src/errors/share-data/share-data-errors.js +66 -0
  65. package/dist/generic/src/helpers/array/array-helpers.d.ts +8 -0
  66. package/dist/generic/src/helpers/array/array-helpers.d.ts.map +1 -0
  67. package/dist/generic/src/helpers/array/array-helpers.js +14 -0
  68. package/dist/generic/src/helpers/data/data-helpers.d.ts +46 -0
  69. package/dist/generic/src/helpers/data/data-helpers.d.ts.map +1 -0
  70. package/dist/generic/src/helpers/data/data-helpers.js +106 -0
  71. package/dist/generic/src/helpers/file/file-helpers.d.ts +12 -0
  72. package/dist/generic/src/helpers/file/file-helpers.d.ts.map +1 -0
  73. package/dist/generic/src/helpers/file/file-helpers.js +39 -0
  74. package/dist/generic/src/helpers/id-helpers.d.ts +8 -0
  75. package/dist/generic/src/helpers/id-helpers.d.ts.map +1 -0
  76. package/dist/generic/src/helpers/id-helpers.js +19 -0
  77. package/dist/generic/src/helpers/index.d.ts +11 -0
  78. package/dist/generic/src/helpers/index.d.ts.map +1 -0
  79. package/dist/generic/src/helpers/index.js +31 -0
  80. package/dist/generic/src/helpers/lodash/lodash-helpers.d.ts +14 -0
  81. package/dist/generic/src/helpers/lodash/lodash-helpers.d.ts.map +1 -0
  82. package/dist/generic/src/helpers/lodash/lodash-helpers.js +28 -0
  83. package/dist/generic/src/helpers/object-helpers.d.ts +23 -0
  84. package/dist/generic/src/helpers/object-helpers.d.ts.map +1 -0
  85. package/dist/generic/src/helpers/object-helpers.js +54 -0
  86. package/dist/generic/src/helpers/object-validation-helpers.d.ts +59 -0
  87. package/dist/generic/src/helpers/object-validation-helpers.d.ts.map +1 -0
  88. package/dist/generic/src/helpers/object-validation-helpers.js +233 -0
  89. package/dist/generic/src/helpers/request/params-object-helpers.d.ts +38 -0
  90. package/dist/generic/src/helpers/request/params-object-helpers.d.ts.map +1 -0
  91. package/dist/generic/src/helpers/request/params-object-helpers.js +54 -0
  92. package/dist/generic/src/helpers/request/query-object-helpers.d.ts +12 -0
  93. package/dist/generic/src/helpers/request/query-object-helpers.d.ts.map +1 -0
  94. package/dist/generic/src/helpers/request/query-object-helpers.js +25 -0
  95. package/dist/generic/src/helpers/request/request-object-helpers.d.ts +19 -0
  96. package/dist/generic/src/helpers/request/request-object-helpers.d.ts.map +1 -0
  97. package/dist/generic/src/helpers/request/request-object-helpers.js +28 -0
  98. package/dist/generic/src/index.d.ts +6 -0
  99. package/dist/generic/src/index.d.ts.map +1 -0
  100. package/dist/generic/src/index.js +23 -0
  101. package/dist/generic/src/models/data/data-models.d.ts +24 -0
  102. package/dist/generic/src/models/data/data-models.d.ts.map +1 -0
  103. package/dist/generic/src/models/data/data-models.js +3 -0
  104. package/dist/generic/src/models/dynamic-execution/dynamic-execution-models.d.ts +9 -0
  105. package/dist/generic/src/models/dynamic-execution/dynamic-execution-models.d.ts.map +1 -0
  106. package/dist/generic/src/models/dynamic-execution/dynamic-execution-models.js +2 -0
  107. package/dist/generic/src/models/events/share-event-models.d.ts +65 -0
  108. package/dist/generic/src/models/events/share-event-models.d.ts.map +1 -0
  109. package/dist/generic/src/models/events/share-event-models.js +70 -0
  110. package/dist/generic/src/models/functions/share-data-function-models.d.ts +86 -0
  111. package/dist/generic/src/models/functions/share-data-function-models.d.ts.map +1 -0
  112. package/dist/generic/src/models/functions/share-data-function-models.js +17 -0
  113. package/dist/generic/src/models/generic/request-response-models.d.ts +8 -0
  114. package/dist/generic/src/models/generic/request-response-models.d.ts.map +1 -0
  115. package/dist/generic/src/models/generic/request-response-models.js +2 -0
  116. package/dist/generic/src/models/index.d.ts +8 -0
  117. package/dist/generic/src/models/index.d.ts.map +1 -0
  118. package/dist/generic/src/models/index.js +24 -0
  119. package/dist/generic/src/models/rules/share-rule-models.d.ts +277 -0
  120. package/dist/generic/src/models/rules/share-rule-models.d.ts.map +1 -0
  121. package/dist/generic/src/models/rules/share-rule-models.js +107 -0
  122. package/dist/generic/src/models/share-data/share-data.d.ts +55 -0
  123. package/dist/generic/src/models/share-data/share-data.d.ts.map +1 -0
  124. package/dist/generic/src/models/share-data/share-data.js +19 -0
  125. package/dist/rules/jest.config.d.ts +8 -0
  126. package/dist/rules/jest.config.d.ts.map +1 -0
  127. package/dist/rules/jest.config.js +44 -0
  128. package/dist/rules/src/evaluation/check-function-integrity.d.ts +7 -0
  129. package/dist/rules/src/evaluation/check-function-integrity.d.ts.map +1 -0
  130. package/dist/rules/src/evaluation/check-function-integrity.js +14 -0
  131. package/dist/rules/src/evaluation/check-if-proposal-is-valid.d.ts +11 -0
  132. package/dist/rules/src/evaluation/check-if-proposal-is-valid.d.ts.map +1 -0
  133. package/dist/rules/src/evaluation/check-if-proposal-is-valid.js +15 -0
  134. package/dist/rules/src/evaluation/conditions/boolean-conditions.d.ts +15 -0
  135. package/dist/rules/src/evaluation/conditions/boolean-conditions.d.ts.map +1 -0
  136. package/dist/rules/src/evaluation/conditions/boolean-conditions.js +29 -0
  137. package/dist/rules/src/evaluation/conditions/contains-conditions.d.ts +16 -0
  138. package/dist/rules/src/evaluation/conditions/contains-conditions.d.ts.map +1 -0
  139. package/dist/rules/src/evaluation/conditions/contains-conditions.js +27 -0
  140. package/dist/rules/src/evaluation/conditions/empty-conditions.d.ts +15 -0
  141. package/dist/rules/src/evaluation/conditions/empty-conditions.d.ts.map +1 -0
  142. package/dist/rules/src/evaluation/conditions/empty-conditions.js +50 -0
  143. package/dist/rules/src/evaluation/conditions/equality-conditions.d.ts +15 -0
  144. package/dist/rules/src/evaluation/conditions/equality-conditions.d.ts.map +1 -0
  145. package/dist/rules/src/evaluation/conditions/equality-conditions.js +24 -0
  146. package/dist/rules/src/evaluation/conditions/null-conditions.d.ts +15 -0
  147. package/dist/rules/src/evaluation/conditions/null-conditions.d.ts.map +1 -0
  148. package/dist/rules/src/evaluation/conditions/null-conditions.js +24 -0
  149. package/dist/rules/src/evaluation/conditions/range-conditions.d.ts +15 -0
  150. package/dist/rules/src/evaluation/conditions/range-conditions.d.ts.map +1 -0
  151. package/dist/rules/src/evaluation/conditions/range-conditions.js +28 -0
  152. package/dist/rules/src/evaluation/conditions/special-conditions.d.ts +15 -0
  153. package/dist/rules/src/evaluation/conditions/special-conditions.d.ts.map +1 -0
  154. package/dist/rules/src/evaluation/conditions/special-conditions.js +47 -0
  155. package/dist/rules/src/evaluation/conditions/starts-end-with-conditions.d.ts +16 -0
  156. package/dist/rules/src/evaluation/conditions/starts-end-with-conditions.d.ts.map +1 -0
  157. package/dist/rules/src/evaluation/conditions/starts-end-with-conditions.js +25 -0
  158. package/dist/rules/src/evaluation/conditions/typeof-rule-conditions.d.ts +16 -0
  159. package/dist/rules/src/evaluation/conditions/typeof-rule-conditions.d.ts.map +1 -0
  160. package/dist/rules/src/evaluation/conditions/typeof-rule-conditions.js +56 -0
  161. package/dist/rules/src/evaluation/determine-if-data-has-changed.d.ts +11 -0
  162. package/dist/rules/src/evaluation/determine-if-data-has-changed.d.ts.map +1 -0
  163. package/dist/rules/src/evaluation/determine-if-data-has-changed.js +14 -0
  164. package/dist/rules/src/evaluation/evaluate-rule-conditions.d.ts +10 -0
  165. package/dist/rules/src/evaluation/evaluate-rule-conditions.d.ts.map +1 -0
  166. package/dist/rules/src/evaluation/evaluate-rule-conditions.js +66 -0
  167. package/dist/rules/src/evaluation/evaluate-rule.d.ts +13 -0
  168. package/dist/rules/src/evaluation/evaluate-rule.d.ts.map +1 -0
  169. package/dist/rules/src/evaluation/evaluate-rule.js +50 -0
  170. package/dist/rules/src/evaluation/evaluate-rules.d.ts +12 -0
  171. package/dist/rules/src/evaluation/evaluate-rules.d.ts.map +1 -0
  172. package/dist/rules/src/evaluation/evaluate-rules.js +50 -0
  173. package/dist/rules/src/evaluation/get-data-changed-information.d.ts +11 -0
  174. package/dist/rules/src/evaluation/get-data-changed-information.d.ts.map +1 -0
  175. package/dist/rules/src/evaluation/get-data-changed-information.js +31 -0
  176. package/dist/rules/src/evaluation/get-root-property-results.d.ts +14 -0
  177. package/dist/rules/src/evaluation/get-root-property-results.d.ts.map +1 -0
  178. package/dist/rules/src/evaluation/get-root-property-results.js +27 -0
  179. package/dist/rules/src/evaluation/index.d.ts +10 -0
  180. package/dist/rules/src/evaluation/index.d.ts.map +1 -0
  181. package/dist/rules/src/evaluation/index.js +27 -0
  182. package/dist/rules/src/evaluation/start-rule-evaluation.d.ts +13 -0
  183. package/dist/rules/src/evaluation/start-rule-evaluation.d.ts.map +1 -0
  184. package/dist/rules/src/evaluation/start-rule-evaluation.js +42 -0
  185. package/dist/rules/src/index.d.ts +2 -0
  186. package/dist/rules/src/index.d.ts.map +1 -0
  187. package/dist/rules/src/index.js +17 -0
  188. package/package.json +38 -0
@@ -0,0 +1,10 @@
1
+ import { ICondition, ITargetObject } from '../../../generic/src';
2
+ /**
3
+ * This evaluates the conditions for the rule.
4
+ *
5
+ * @param targetObject the full object to check
6
+ * @param condition the condition to check
7
+ */
8
+ declare const evaluateRuleConditions: (targetObject: ITargetObject, condition: ICondition) => boolean;
9
+ export { evaluateRuleConditions };
10
+ //# sourceMappingURL=evaluate-rule-conditions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate-rule-conditions.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/evaluate-rule-conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAUH,UAAU,EACV,aAAa,EAChB,MAAM,sBAAsB,CAAC;AAW9B;;;;;GAKG;AACH,QAAA,MAAM,sBAAsB,iBAAkB,aAAa,aAAa,UAAU,KAAG,OAkCpF,CAAC;AAGF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateRuleConditions = void 0;
4
+ const src_1 = require("../../../generic/src");
5
+ const boolean_conditions_1 = require("./conditions/boolean-conditions");
6
+ const contains_conditions_1 = require("./conditions/contains-conditions");
7
+ const empty_conditions_1 = require("./conditions/empty-conditions");
8
+ const equality_conditions_1 = require("./conditions/equality-conditions");
9
+ const null_conditions_1 = require("./conditions/null-conditions");
10
+ const range_conditions_1 = require("./conditions/range-conditions");
11
+ const special_conditions_1 = require("./conditions/special-conditions");
12
+ const starts_end_with_conditions_1 = require("./conditions/starts-end-with-conditions");
13
+ const typeof_rule_conditions_1 = require("./conditions/typeof-rule-conditions");
14
+ /**
15
+ * This evaluates the conditions for the rule.
16
+ *
17
+ * @param targetObject the full object to check
18
+ * @param condition the condition to check
19
+ */
20
+ const evaluateRuleConditions = (targetObject, condition) => {
21
+ const splitProperties = condition.targettedProperty.split('.');
22
+ const targetValue = getNestedProperty(targetObject, splitProperties);
23
+ switch (condition.conditionType) {
24
+ case src_1.ConditionTypeTypeOf.IS_TYPEOF:
25
+ case src_1.ConditionTypeTypeOf.IS_NOT_TYPEOF:
26
+ return (0, typeof_rule_conditions_1.isValidTypeOfValue)(targetValue, condition.conditionValue, condition.conditionType);
27
+ case src_1.ConditionTypeEquality.EQUAL:
28
+ case src_1.ConditionTypeEquality.NOT_EQUAL:
29
+ return (0, equality_conditions_1.isValidEqualityValue)(targetValue, condition.conditionValue, condition.conditionType);
30
+ case src_1.ConditionTypeRange.GREATER_THAN:
31
+ case src_1.ConditionTypeRange.LESS_THAN:
32
+ case src_1.ConditionTypeRange.GREATER_THAN_OR_EQUAL:
33
+ case src_1.ConditionTypeRange.LESS_THAN_OR_EQUAL:
34
+ return (0, range_conditions_1.isValidRangeValue)(targetValue, condition.conditionValue, condition.conditionType);
35
+ case src_1.ConditionTypeContains.CONTAINS:
36
+ case src_1.ConditionTypeContains.NOT_CONTAINS:
37
+ return (0, contains_conditions_1.isValidContainsValue)(targetValue, condition.conditionValue, condition.conditionType);
38
+ case src_1.ConditionTypeStartsEndsWith.STARTS_WITH:
39
+ case src_1.ConditionTypeStartsEndsWith.ENDS_WITH:
40
+ return (0, starts_end_with_conditions_1.isValidStartEndWithValue)(targetValue, condition.conditionValue, condition.conditionType);
41
+ case src_1.ConditionTypeNull.IS_NULL:
42
+ case src_1.ConditionTypeNull.IS_NOT_NULL:
43
+ return (0, null_conditions_1.isValidNullValue)(targetValue, condition.conditionType);
44
+ case src_1.ConditionTypeBoolean.IS_TRUE:
45
+ case src_1.ConditionTypeBoolean.IS_FALSE:
46
+ return (0, boolean_conditions_1.isValidBooleanValue)(targetValue, condition.conditionType);
47
+ case src_1.ConditionTypeEmpty.IS_EMPTY:
48
+ case src_1.ConditionTypeEmpty.IS_NOT_EMPTY:
49
+ return (0, empty_conditions_1.isValidEmptyValue)(targetValue, condition.conditionType);
50
+ case src_1.ConditionTypeSpecial.PATTERN:
51
+ return (0, special_conditions_1.isValidSpecialValue)(targetObject, condition.conditionValue, condition.conditionType);
52
+ }
53
+ // return false;
54
+ };
55
+ exports.evaluateRuleConditions = evaluateRuleConditions;
56
+ /**
57
+ * Accesses a nested property in an object dynamically.
58
+ *
59
+ * @param obj The object to access.
60
+ * @param path The path to the property as an array of strings.
61
+ * @returns The value of the nested property, or undefined if the property does not exist.
62
+ */
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ const getNestedProperty = (obj, path) => {
65
+ return path.reduce((acc, key) => (acc && acc[key] !== undefined) ? acc[key] : undefined, obj);
66
+ };
@@ -0,0 +1,13 @@
1
+ import { IShareRuleApplied, IShareData, IShareRuleEvalutionResult } from '../../../generic/src';
2
+ /**
3
+ * This function evaluates a rule and returns the Id of the rule and whether it is valid.
4
+ *
5
+ * @param rule the rule to evaluate
6
+ * @param shareDataCurrent the current share data
7
+ * @param shareDataProposed the proposed share data
8
+ * @param logInfo whether to log the information (optional) default is false
9
+ * @returns
10
+ */
11
+ declare const evaluateRule: (rule: IShareRuleApplied, shareDataCurrent: IShareData, shareDataProposed: IShareData, logInfo?: boolean) => IShareRuleEvalutionResult;
12
+ export { evaluateRule };
13
+ //# sourceMappingURL=evaluate-rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate-rule.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/evaluate-rule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAGhG;;;;;;;;GAQG;AACH,QAAA,MAAM,YAAY,SACR,iBAAiB,oBACL,UAAU,qBACT,UAAU,wBAE9B,yBAmCF,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateRule = void 0;
4
+ const evaluate_rule_conditions_1 = require("./evaluate-rule-conditions");
5
+ /**
6
+ * This function evaluates a rule and returns the Id of the rule and whether it is valid.
7
+ *
8
+ * @param rule the rule to evaluate
9
+ * @param shareDataCurrent the current share data
10
+ * @param shareDataProposed the proposed share data
11
+ * @param logInfo whether to log the information (optional) default is false
12
+ * @returns
13
+ */
14
+ const evaluateRule = (rule, shareDataCurrent, shareDataProposed, logInfo = false) => {
15
+ const ruleEvaluationResult = {
16
+ ruleId: rule.ruleId,
17
+ currentConditionFailure: [],
18
+ currentResult: true,
19
+ proposedConditionFailure: [],
20
+ proposedResult: true,
21
+ };
22
+ // make sure that both before and after data conditions are present
23
+ if (rule.currentDataConditions.length === 0 || rule.proposedDataConditions.length === 0) {
24
+ ruleEvaluationResult.currentResult = (rule.currentDataConditions.length !== 0);
25
+ ruleEvaluationResult.proposedResult = (rule.proposedDataConditions.length !== 0);
26
+ return ruleEvaluationResult;
27
+ }
28
+ // check the current conditions
29
+ for (const condition of rule.currentDataConditions) {
30
+ const conditionEvaluationOutcome = (0, evaluate_rule_conditions_1.evaluateRuleConditions)(shareDataCurrent, condition);
31
+ if (!conditionEvaluationOutcome) {
32
+ ruleEvaluationResult.currentResult = false;
33
+ ruleEvaluationResult.currentConditionFailure.push(condition);
34
+ if (!logInfo)
35
+ break;
36
+ }
37
+ }
38
+ // check the proposed conditions
39
+ for (const condition of rule.proposedDataConditions) {
40
+ const conditionEvaluationOutcome = (0, evaluate_rule_conditions_1.evaluateRuleConditions)(shareDataProposed, condition);
41
+ if (!conditionEvaluationOutcome) {
42
+ ruleEvaluationResult.proposedResult = false;
43
+ ruleEvaluationResult.proposedConditionFailure.push(condition);
44
+ if (!logInfo)
45
+ break;
46
+ }
47
+ }
48
+ return ruleEvaluationResult;
49
+ };
50
+ exports.evaluateRule = evaluateRule;
@@ -0,0 +1,12 @@
1
+ import { IShareRuleApplied, IShareData, IShareRulesEvaluationResult } from '../../../generic/src';
2
+ /**
3
+ * This function evaluates all rules to check if at least one rule is valid.
4
+ * @param rootParam the root parameter that all the rules are providing a allow / deny for
5
+ * @param appliedRules the rules to check for validation
6
+ * @param shareDataCurrent the current share data
7
+ * @param shareDataProposed the proposed share data
8
+ * @param logInfo whether to log the information (optional) default is false
9
+ */
10
+ declare const evaluateRules: (rootParam: string, appliedRules: IShareRuleApplied[], shareDataCurrent: IShareData, shareDataProposed: IShareData, logInfo?: boolean) => IShareRulesEvaluationResult;
11
+ export { evaluateRules };
12
+ //# sourceMappingURL=evaluate-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate-rules.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/evaluate-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,2BAA2B,EAA6B,MAAM,sBAAsB,CAAC;AAG7H;;;;;;;GAOG;AACH,QAAA,MAAM,aAAa,cACJ,MAAM,gBACH,iBAAiB,EAAE,oBACf,UAAU,qBACT,UAAU,wBAE9B,2BA2BF,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateRules = void 0;
4
+ const evaluate_rule_1 = require("./evaluate-rule");
5
+ /**
6
+ * This function evaluates all rules to check if at least one rule is valid.
7
+ * @param rootParam the root parameter that all the rules are providing a allow / deny for
8
+ * @param appliedRules the rules to check for validation
9
+ * @param shareDataCurrent the current share data
10
+ * @param shareDataProposed the proposed share data
11
+ * @param logInfo whether to log the information (optional) default is false
12
+ */
13
+ const evaluateRules = (rootParam, appliedRules, shareDataCurrent, shareDataProposed, logInfo = false) => {
14
+ // create the evaluation object.
15
+ const shareRulesEvaluationResults = {
16
+ rootParam,
17
+ shareRuleEvalutionResults: [],
18
+ passedRuleCheck: false,
19
+ passedRuleId: '',
20
+ };
21
+ // check each rule
22
+ for (const rule of appliedRules) {
23
+ // evaluate the rule
24
+ const ruleEvaluationResult = (0, evaluate_rule_1.evaluateRule)(rule, shareDataCurrent, shareDataProposed, logInfo);
25
+ // check if the rule passed
26
+ const passedRuleCheck = checkIfPassedRules(ruleEvaluationResult);
27
+ if (passedRuleCheck) {
28
+ shareRulesEvaluationResults.passedRuleCheck = true;
29
+ shareRulesEvaluationResults.passedRuleId = rule.ruleId;
30
+ if (!logInfo)
31
+ break;
32
+ }
33
+ else {
34
+ if (logInfo) {
35
+ shareRulesEvaluationResults.shareRuleEvalutionResults.push(ruleEvaluationResult);
36
+ }
37
+ }
38
+ }
39
+ return shareRulesEvaluationResults;
40
+ };
41
+ exports.evaluateRules = evaluateRules;
42
+ /**
43
+ * This functions returns whether or not the rule passed for the evaluation.
44
+ *
45
+ * @param shareRulesEvaluationResults the evaluation results
46
+ * @returns
47
+ */
48
+ const checkIfPassedRules = (shareRulesEvaluationResults) => {
49
+ return (shareRulesEvaluationResults.currentResult && shareRulesEvaluationResults.proposedResult);
50
+ };
@@ -0,0 +1,11 @@
1
+ import { IShareData } from '../../../generic/src';
2
+ /**
3
+ * This gets a list of the root properties that are different between the two share data objects.
4
+ *
5
+ * @param shareDataCurrent The current share data
6
+ * @param shareDataProposed the proposed share data
7
+ * @returns
8
+ */
9
+ declare const getRootPropertyDifferences: (shareDataCurrent: IShareData, shareDataProposed: IShareData) => string[];
10
+ export { getRootPropertyDifferences };
11
+ //# sourceMappingURL=get-data-changed-information.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-data-changed-information.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/get-data-changed-information.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD;;;;;;GAMG;AACH,QAAA,MAAM,0BAA0B,qBAAsB,UAAU,qBACzC,UAAU,KAAG,MAAM,EAsBzC,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRootPropertyDifferences = void 0;
4
+ const determine_if_data_has_changed_1 = require("./determine-if-data-has-changed");
5
+ /**
6
+ * This gets a list of the root properties that are different between the two share data objects.
7
+ *
8
+ * @param shareDataCurrent The current share data
9
+ * @param shareDataProposed the proposed share data
10
+ * @returns
11
+ */
12
+ const getRootPropertyDifferences = (shareDataCurrent, shareDataProposed) => {
13
+ // create an array of root properties to check
14
+ const currentRootProperties = Object.keys(shareDataCurrent);
15
+ const proposedRootProperties = Object.keys(shareDataProposed);
16
+ // check if the root properties are the same, if not return the differences
17
+ const differences = currentRootProperties.filter((x) => !proposedRootProperties.includes(x));
18
+ const differences2 = proposedRootProperties.filter((x) => !currentRootProperties.includes(x));
19
+ // combine the differences
20
+ const allDifferences = [...differences, ...differences2];
21
+ // get the items that are the same
22
+ const sameItems = currentRootProperties.filter((x) => proposedRootProperties.includes(x));
23
+ // loop each item and check if the data is the same or different between them
24
+ for (const item of sameItems) {
25
+ if ((0, determine_if_data_has_changed_1.determineIfDataHasChanged)(shareDataCurrent[item], shareDataProposed[item])) {
26
+ allDifferences.push(item);
27
+ }
28
+ }
29
+ return allDifferences;
30
+ };
31
+ exports.getRootPropertyDifferences = getRootPropertyDifferences;
@@ -0,0 +1,14 @@
1
+ import { IShareRuleApplied, IShareData, IShareRulesEvaluationResult } from '../../../generic/src';
2
+ /**
3
+ * This function gets the root property results.
4
+ *
5
+ * @param differentRootProperties the different root properties
6
+ * @param appliedRules the rules to check
7
+ * @param shareDataCurrent the current share data
8
+ * @param shareDataProposed the proposed share data
9
+ * @param logInfo the detailed log information (optional) default is false
10
+ * @returns
11
+ */
12
+ declare const getRootPropertyResults: (differentRootProperties: string[], appliedRules: IShareRuleApplied[], shareDataCurrent: IShareData, shareDataProposed: IShareData, logInfo?: boolean) => IShareRulesEvaluationResult[];
13
+ export { getRootPropertyResults };
14
+ //# sourceMappingURL=get-root-property-results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-root-property-results.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/get-root-property-results.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGlG;;;;;;;;;GASG;AACH,QAAA,MAAM,sBAAsB,4BACC,MAAM,EAAE,gBACnB,iBAAiB,EAAE,oBACf,UAAU,qBACT,UAAU,wBAE9B,2BAA2B,EAa7B,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRootPropertyResults = void 0;
4
+ const evaluate_rules_1 = require("./evaluate-rules");
5
+ /**
6
+ * This function gets the root property results.
7
+ *
8
+ * @param differentRootProperties the different root properties
9
+ * @param appliedRules the rules to check
10
+ * @param shareDataCurrent the current share data
11
+ * @param shareDataProposed the proposed share data
12
+ * @param logInfo the detailed log information (optional) default is false
13
+ * @returns
14
+ */
15
+ const getRootPropertyResults = (differentRootProperties, appliedRules, shareDataCurrent, shareDataProposed, logInfo = false) => {
16
+ const rulesResults = [];
17
+ // loop each root property and check their rules.
18
+ for (const rootProperty of differentRootProperties) {
19
+ // get the rules for the root property
20
+ const rulesForRootProperty = appliedRules.filter((x) => x.targettedProperty === rootProperty);
21
+ // evaluate the rules
22
+ const ruleEvaluationResult = (0, evaluate_rules_1.evaluateRules)(rootProperty, rulesForRootProperty, shareDataCurrent, shareDataProposed, logInfo);
23
+ rulesResults.push(ruleEvaluationResult);
24
+ }
25
+ return rulesResults;
26
+ };
27
+ exports.getRootPropertyResults = getRootPropertyResults;
@@ -0,0 +1,10 @@
1
+ export * from './conditions/boolean-conditions';
2
+ export * from './conditions/contains-conditions';
3
+ export * from './conditions/empty-conditions';
4
+ export * from './conditions/equality-conditions';
5
+ export * from './conditions/null-conditions';
6
+ export * from './conditions/range-conditions';
7
+ export * from './conditions/special-conditions';
8
+ export * from './conditions/starts-end-with-conditions';
9
+ export * from './conditions/typeof-rule-conditions';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/index.ts"],"names":[],"mappings":"AAEA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ //#region Conditional Functions
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./conditions/boolean-conditions"), exports);
19
+ __exportStar(require("./conditions/contains-conditions"), exports);
20
+ __exportStar(require("./conditions/empty-conditions"), exports);
21
+ __exportStar(require("./conditions/equality-conditions"), exports);
22
+ __exportStar(require("./conditions/null-conditions"), exports);
23
+ __exportStar(require("./conditions/range-conditions"), exports);
24
+ __exportStar(require("./conditions/special-conditions"), exports);
25
+ __exportStar(require("./conditions/starts-end-with-conditions"), exports);
26
+ __exportStar(require("./conditions/typeof-rule-conditions"), exports);
27
+ //#endregion Conditional Functions
@@ -0,0 +1,13 @@
1
+ import { IShareFunction, IShareRuleApplied, IShareData, IRuleEvaluationResults } from '../../../generic/src';
2
+ /**
3
+ * This function starts the rule evaluation for the share data.
4
+ *
5
+ * @param shareDataId the share data id
6
+ * @param appliedRules all rules in the share data
7
+ * @param shareDataCurrent the current share data
8
+ * @param shareDataProposed the proposed share data
9
+ * @param logInfo whether detailed information should be logged (optional) default is false
10
+ */
11
+ declare const startRuleEvaluation: (shareDataId: string, shareDataFunction: IShareFunction<any, (...args: any[]) => any, any>, shareDataFunctions: IShareFunction<any, (...args: any[]) => any, any>[], appliedRules: IShareRuleApplied[], shareDataCurrent: IShareData, shareDataProposed: IShareData, logInfo?: boolean) => IRuleEvaluationResults;
12
+ export { startRuleEvaluation };
13
+ //# sourceMappingURL=start-rule-evaluation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-rule-evaluation.d.ts","sourceRoot":"","sources":["../../../../src/evaluation/start-rule-evaluation.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EAGzB,MAAM,sBAAsB,CAAC;AAO9B;;;;;;;;GAQG;AACH,QAAA,MAAM,mBAAmB,gBACR,MAAM,qBACA,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,sBAChD,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,EAAE,gBACzD,iBAAiB,EAAE,oBACf,UAAU,qBACT,UAAU,wBAE9B,sBA4BF,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.startRuleEvaluation = void 0;
5
+ const src_1 = require("../../../generic/src");
6
+ const check_function_integrity_1 = require("./check-function-integrity");
7
+ const check_if_proposal_is_valid_1 = require("./check-if-proposal-is-valid");
8
+ const determine_if_data_has_changed_1 = require("./determine-if-data-has-changed");
9
+ const get_data_changed_information_1 = require("./get-data-changed-information");
10
+ const get_root_property_results_1 = require("./get-root-property-results");
11
+ /**
12
+ * This function starts the rule evaluation for the share data.
13
+ *
14
+ * @param shareDataId the share data id
15
+ * @param appliedRules all rules in the share data
16
+ * @param shareDataCurrent the current share data
17
+ * @param shareDataProposed the proposed share data
18
+ * @param logInfo whether detailed information should be logged (optional) default is false
19
+ */
20
+ const startRuleEvaluation = (shareDataId, shareDataFunction, shareDataFunctions, appliedRules, shareDataCurrent, shareDataProposed, logInfo = false) => {
21
+ // create the return data
22
+ const rulesEvaluationsFull = {
23
+ shareDataId,
24
+ rulesResults: [],
25
+ isValidProposal: false,
26
+ };
27
+ // check data integrity
28
+ if (!(0, check_function_integrity_1.checkFunctionIntegrity)(shareDataFunction, shareDataFunctions)) {
29
+ throw new src_1.ShareDataIntegrityError(shareDataId);
30
+ }
31
+ // check if the data has changed.
32
+ if (!(0, determine_if_data_has_changed_1.determineIfDataHasChanged)(shareDataCurrent, shareDataProposed)) {
33
+ throw new src_1.ShareDataCurrentAndProposalDataMatchesError(shareDataId);
34
+ }
35
+ // get all root properties that are different
36
+ const differentRootProperties = (0, get_data_changed_information_1.getRootPropertyDifferences)(shareDataCurrent, shareDataProposed);
37
+ const totalRulesToBeValid = differentRootProperties.length;
38
+ rulesEvaluationsFull.rulesResults = (0, get_root_property_results_1.getRootPropertyResults)(differentRootProperties, appliedRules, shareDataCurrent, shareDataProposed, logInfo);
39
+ rulesEvaluationsFull.isValidProposal = (0, check_if_proposal_is_valid_1.checkIfProposalIsValid)(totalRulesToBeValid, rulesEvaluationsFull.rulesResults);
40
+ return rulesEvaluationsFull;
41
+ };
42
+ exports.startRuleEvaluation = startRuleEvaluation;
@@ -0,0 +1,2 @@
1
+ export * from './evaluation';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -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
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./evaluation"), exports);
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@degenerate/rules",
3
+ "description": "This contains the rules information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network.",
4
+ "version": "0.0.1",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "devDependencies": {
8
+ "@types/jest": "^29.5.13",
9
+ "@types/node": "^22.7.7",
10
+ "jest": "^29.7.0",
11
+ "ts-jest": "^29.2.5",
12
+ "typescript": "^5.6.3"
13
+ },
14
+ "scripts": {
15
+ "build": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
16
+ "compile": "rm -rf dist/* && tsc -p tsconfig.pkg.json",
17
+ "test": "jest --forceExit --detectOpenHandles --verbose --silent=false --env node --config tsconfig.pkg.json",
18
+ "test:coverage": "jest --forceExit --coverage --detectOpenHandles --verbose --silent=false --env node --config tsconfig.pkg.json",
19
+ "test:clearCache": "jest --clearCache"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/syncrude/safe.git"
24
+ },
25
+ "keywords": [
26
+ "ShareData Adaptive Framework Ecosystem",
27
+ "SAFE",
28
+ "SAFE Rules",
29
+ "ShareData",
30
+ "ShareBlock"
31
+ ],
32
+ "bugs": {
33
+ "url": "https://github.com/syncrude/safe/issues"
34
+ },
35
+ "homepage": "https://github.com/syncrude/safe#readme",
36
+ "author": "Degenerate Inc.",
37
+ "license": "ISC"
38
+ }