@degenerate/rules 0.6.0 → 0.7.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/dist/evaluation/evaluate-rules-via-sandbox.d.ts +27 -0
- package/dist/evaluation/evaluate-rules-via-sandbox.d.ts.map +1 -0
- package/dist/evaluation/evaluate-rules-via-sandbox.js +56 -0
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/index.d.ts.map +1 -1
- package/dist/evaluation/index.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IShareData, IShareRuleApplied, IShareRulesEvaluationResult, RuleEvaluator } from '@degenerate/generic';
|
|
2
|
+
/** Default per-rule gas ceiling when the caller does not pin one. */
|
|
3
|
+
export declare const DEFAULT_RULE_GAS_LIMIT = 600;
|
|
4
|
+
export interface EvaluateRulesViaSandboxOptions {
|
|
5
|
+
ruleEvaluator?: RuleEvaluator;
|
|
6
|
+
gasLimit?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface RulesViaSandboxResult {
|
|
9
|
+
isValidProposal: boolean;
|
|
10
|
+
rulesResults: IShareRulesEvaluationResult[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Routing-preserving, sandboxed rule evaluation — the runtime counterpart of
|
|
14
|
+
* `startRuleEvaluation`'s rule phase. The TRUSTED per-property routing runs
|
|
15
|
+
* in-process exactly as the engine does (`getRootPropertyDifferences`, OR within
|
|
16
|
+
* a property, AND across changed properties via `checkIfProposalIsValid`); each
|
|
17
|
+
* individual rule's verdict is computed by running its compiled predicate in the
|
|
18
|
+
* (untrusted) sandbox.
|
|
19
|
+
*
|
|
20
|
+
* Because `compileRuleToSource` is faithfulness-proven (a rule's compiled verdict
|
|
21
|
+
* equals the engine's `currentResult && proposedResult`) and the routing is
|
|
22
|
+
* reused verbatim, `isValidProposal` matches `startRuleEvaluation`. Assumes the
|
|
23
|
+
* data has changed — the apply path enforces that separately, exactly as the
|
|
24
|
+
* engine's `determineIfDataHasChanged` guard does.
|
|
25
|
+
*/
|
|
26
|
+
export declare const evaluateRulesViaSandbox: (appliedRules: IShareRuleApplied[], shareDataCurrent: IShareData, shareDataProposed: IShareData, options?: EvaluateRulesViaSandboxOptions) => Promise<RulesViaSandboxResult>;
|
|
27
|
+
//# sourceMappingURL=evaluate-rules-via-sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-rules-via-sandbox.d.ts","sourceRoot":"","sources":["../../src/evaluation/evaluate-rules-via-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,aAAa,EAChB,MAAM,qBAAqB,CAAC;AAI7B,qEAAqE;AACrE,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,MAAM,WAAW,8BAA8B;IAC3C,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IAClC,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,2BAA2B,EAAE,CAAC;CAC/C;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,GAChC,cAAc,iBAAiB,EAAE,EACjC,kBAAkB,UAAU,EAC5B,mBAAmB,UAAU,EAC7B,UAAS,8BAAmC,KAC7C,OAAO,CAAC,qBAAqB,CAkC/B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateRulesViaSandbox = exports.DEFAULT_RULE_GAS_LIMIT = void 0;
|
|
4
|
+
const generic_1 = require("@degenerate/generic");
|
|
5
|
+
const check_if_proposal_is_valid_1 = require("./check-if-proposal-is-valid");
|
|
6
|
+
const get_data_changed_information_1 = require("./get-data-changed-information");
|
|
7
|
+
/** Default per-rule gas ceiling when the caller does not pin one. */
|
|
8
|
+
exports.DEFAULT_RULE_GAS_LIMIT = 600;
|
|
9
|
+
/**
|
|
10
|
+
* Routing-preserving, sandboxed rule evaluation — the runtime counterpart of
|
|
11
|
+
* `startRuleEvaluation`'s rule phase. The TRUSTED per-property routing runs
|
|
12
|
+
* in-process exactly as the engine does (`getRootPropertyDifferences`, OR within
|
|
13
|
+
* a property, AND across changed properties via `checkIfProposalIsValid`); each
|
|
14
|
+
* individual rule's verdict is computed by running its compiled predicate in the
|
|
15
|
+
* (untrusted) sandbox.
|
|
16
|
+
*
|
|
17
|
+
* Because `compileRuleToSource` is faithfulness-proven (a rule's compiled verdict
|
|
18
|
+
* equals the engine's `currentResult && proposedResult`) and the routing is
|
|
19
|
+
* reused verbatim, `isValidProposal` matches `startRuleEvaluation`. Assumes the
|
|
20
|
+
* data has changed — the apply path enforces that separately, exactly as the
|
|
21
|
+
* engine's `determineIfDataHasChanged` guard does.
|
|
22
|
+
*/
|
|
23
|
+
const evaluateRulesViaSandbox = async (appliedRules, shareDataCurrent, shareDataProposed, options = {}) => {
|
|
24
|
+
const evaluator = options.ruleEvaluator ?? (0, generic_1.createInProcessRuleEvaluator)();
|
|
25
|
+
const gasLimit = options.gasLimit ?? exports.DEFAULT_RULE_GAS_LIMIT;
|
|
26
|
+
const differentRootProperties = (0, get_data_changed_information_1.getRootPropertyDifferences)(shareDataCurrent, shareDataProposed);
|
|
27
|
+
const rulesResults = [];
|
|
28
|
+
for (const rootParam of differentRootProperties) {
|
|
29
|
+
const rulesForProperty = appliedRules.filter((rule) => rule.targettedProperty === rootParam);
|
|
30
|
+
const result = {
|
|
31
|
+
rootParam,
|
|
32
|
+
shareRuleEvalutionResults: [],
|
|
33
|
+
passedRuleCheck: false,
|
|
34
|
+
passedRuleId: '',
|
|
35
|
+
};
|
|
36
|
+
// OR within a property: the first passing rule wins (matches the engine).
|
|
37
|
+
for (const rule of rulesForProperty) {
|
|
38
|
+
const verdict = await evaluator.evaluate({
|
|
39
|
+
source: (0, generic_1.compileRuleToSource)(rule),
|
|
40
|
+
current: shareDataCurrent,
|
|
41
|
+
proposed: shareDataProposed,
|
|
42
|
+
gasLimit,
|
|
43
|
+
});
|
|
44
|
+
if (verdict.passed === true) {
|
|
45
|
+
result.passedRuleCheck = true;
|
|
46
|
+
result.passedRuleId = rule.ruleId;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
rulesResults.push(result);
|
|
51
|
+
}
|
|
52
|
+
// AND across changed properties: every changed property needs a passing rule.
|
|
53
|
+
const isValidProposal = (0, check_if_proposal_is_valid_1.checkIfProposalIsValid)(differentRootProperties.length, rulesResults);
|
|
54
|
+
return { isValidProposal, rulesResults };
|
|
55
|
+
};
|
|
56
|
+
exports.evaluateRulesViaSandbox = evaluateRulesViaSandbox;
|
|
@@ -13,6 +13,7 @@ export * from './determine-if-data-has-changed';
|
|
|
13
13
|
export * from './evaluate-rule';
|
|
14
14
|
export * from './evaluate-rule-conditions';
|
|
15
15
|
export * from './evaluate-rules';
|
|
16
|
+
export * from './evaluate-rules-via-sandbox';
|
|
16
17
|
export * from './get-data-changed-information';
|
|
17
18
|
export * from './get-root-property-results';
|
|
18
19
|
export * from './start-rule-evaluation';
|
|
@@ -1 +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,gCAAgC,CAAC;AAI/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC"}
|
|
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,gCAAgC,CAAC;AAI/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC"}
|
package/dist/evaluation/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./determine-if-data-has-changed"), exports);
|
|
|
31
31
|
__exportStar(require("./evaluate-rule"), exports);
|
|
32
32
|
__exportStar(require("./evaluate-rule-conditions"), exports);
|
|
33
33
|
__exportStar(require("./evaluate-rules"), exports);
|
|
34
|
+
__exportStar(require("./evaluate-rules-via-sandbox"), exports);
|
|
34
35
|
__exportStar(require("./get-data-changed-information"), exports);
|
|
35
36
|
__exportStar(require("./get-root-property-results"), exports);
|
|
36
37
|
__exportStar(require("./start-rule-evaluation"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/rules",
|
|
3
3
|
"description": "This contains the rules information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"homepage": "https://github.com/syncrude/safe#readme",
|
|
45
45
|
"author": "Degenerate Inc.",
|
|
46
46
|
"license": "ISC",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1f747e160c9022863c7b2d7b8a6a157f204be95b",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@degenerate/generic": "^0.
|
|
49
|
+
"@degenerate/generic": "^0.7.0",
|
|
50
50
|
"zod": "^4.4.3"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|