@rkmodules/rules 0.0.171 → 0.0.173
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/index.cjs.js +85 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +85 -22
- package/dist/index.esm.mjs.map +1 -1
- package/dist/lib/Engine/cache.d.ts +8 -1
- package/package.json +1 -1
- package/readme.md +15 -7
package/dist/index.cjs.js
CHANGED
|
@@ -753,6 +753,50 @@ function sameRecord(a, b) {
|
|
|
753
753
|
var otherKeys = Object.keys(b);
|
|
754
754
|
return keys.length === otherKeys.length && keys.every(function (key, i) { return key === otherKeys[i] && Object.is(a[key], b[key]); });
|
|
755
755
|
}
|
|
756
|
+
/** Compare immutable graph configuration, never runtime dependency trees.
|
|
757
|
+
* Preserve key order (interpolation observes it); opaque objects retain identity
|
|
758
|
+
* semantics. Cyclic configurations conservatively miss instead of recursing forever.
|
|
759
|
+
*/
|
|
760
|
+
function sameConfiguration(a, b, ancestors) {
|
|
761
|
+
if (Object.is(a, b))
|
|
762
|
+
return true;
|
|
763
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object")
|
|
764
|
+
return false;
|
|
765
|
+
var prototype = Object.getPrototypeOf(a);
|
|
766
|
+
if (prototype !== Object.getPrototypeOf(b))
|
|
767
|
+
return false;
|
|
768
|
+
if (Array.isArray(a)) {
|
|
769
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
else if (prototype !== Object.prototype && prototype !== null)
|
|
773
|
+
return false;
|
|
774
|
+
if ((ancestors === null || ancestors === void 0 ? void 0 : ancestors.has(a)) || (ancestors === null || ancestors === void 0 ? void 0 : ancestors.has(b)))
|
|
775
|
+
return false;
|
|
776
|
+
var keys = Reflect.ownKeys(a);
|
|
777
|
+
var otherKeys = Reflect.ownKeys(b);
|
|
778
|
+
if (keys.length !== otherKeys.length)
|
|
779
|
+
return false;
|
|
780
|
+
ancestors = ancestors || new Set();
|
|
781
|
+
ancestors.add(a);
|
|
782
|
+
ancestors.add(b);
|
|
783
|
+
try {
|
|
784
|
+
return keys.every(function (key, i) {
|
|
785
|
+
if (key !== otherKeys[i])
|
|
786
|
+
return false;
|
|
787
|
+
var left = Object.getOwnPropertyDescriptor(a, key);
|
|
788
|
+
var right = Object.getOwnPropertyDescriptor(b, key);
|
|
789
|
+
// Accessors may read external state; do not invoke them for comparison.
|
|
790
|
+
return "value" in left && "value" in right &&
|
|
791
|
+
left.enumerable === right.enumerable &&
|
|
792
|
+
sameConfiguration(left.value, right.value, ancestors);
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
finally {
|
|
796
|
+
ancestors.delete(a);
|
|
797
|
+
ancestors.delete(b);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
756
800
|
function put(map, key, value) {
|
|
757
801
|
map.delete(key);
|
|
758
802
|
map.set(key, value);
|
|
@@ -850,7 +894,8 @@ var ExecutionCache = /** @class */ (function () {
|
|
|
850
894
|
finally { if (e_2) throw e_2.error; }
|
|
851
895
|
}
|
|
852
896
|
};
|
|
853
|
-
ExecutionCache.prototype.interpolate = function (run, path, raw, scope) {
|
|
897
|
+
ExecutionCache.prototype.interpolate = function (run, path, raw, scope, configuration) {
|
|
898
|
+
if (configuration === void 0) { configuration = false; }
|
|
854
899
|
var key = cachePath(path);
|
|
855
900
|
run.visited.add(key);
|
|
856
901
|
if (!this.current(run))
|
|
@@ -862,13 +907,16 @@ var ExecutionCache = /** @class */ (function () {
|
|
|
862
907
|
// Deep references depend on the base tree's identity. Unrelated scope
|
|
863
908
|
// entries never invalidate this port; a fresh execution context is fine.
|
|
864
909
|
var old = previous === null || previous === void 0 ? void 0 : previous.ports.get(name);
|
|
865
|
-
var
|
|
910
|
+
var sameRaw = old && (configuration
|
|
911
|
+
? sameConfiguration(old.raw, value) : Object.is(old.raw, value));
|
|
912
|
+
var paths = sameRaw ? old.paths :
|
|
866
913
|
getReferencePaths(value).map(function (path) { return path.split(".").slice(0, 2).join("."); });
|
|
867
914
|
var dependencies = paths.map(function (path) { return getValue$1(scope, path); });
|
|
868
|
-
var same =
|
|
915
|
+
var same = sameRaw &&
|
|
869
916
|
old.dependencies.length === dependencies.length &&
|
|
870
917
|
dependencies.every(function (value, i) { return Object.is(value, old.dependencies[i]); });
|
|
871
|
-
|
|
918
|
+
// Remember the latest raw reference so subsequent runs take the fast path.
|
|
919
|
+
var port = same ? __assign(__assign({}, old), { raw: value }) : {
|
|
872
920
|
raw: value,
|
|
873
921
|
paths: paths,
|
|
874
922
|
dependencies: dependencies,
|
|
@@ -893,8 +941,10 @@ var ExecutionCache = /** @class */ (function () {
|
|
|
893
941
|
return;
|
|
894
942
|
var entry = run.scope[kind].get(key);
|
|
895
943
|
if (entry && entry.definition === fn && entry.impl === fn.impl &&
|
|
896
|
-
|
|
897
|
-
|
|
944
|
+
sameConfiguration(entry.metadata, this.key(call)) && sameRecord(entry.inputs, inputs) &&
|
|
945
|
+
sameConfiguration(entry.params, params)) {
|
|
946
|
+
entry.metadata = this.key(call);
|
|
947
|
+
entry.params = __assign({}, params);
|
|
898
948
|
put(run.scope[kind], key, entry);
|
|
899
949
|
return entry;
|
|
900
950
|
}
|
|
@@ -3530,10 +3580,11 @@ var Engine = /** @class */ (function () {
|
|
|
3530
3580
|
};
|
|
3531
3581
|
Engine.prototype.executeCall = function (fn_1, call_1, inputs_1, params_1, context_1, name_1, executionId_1, run_1, path_1) {
|
|
3532
3582
|
return __awaiter(this, arguments, void 0, function (fn, call, inputs, params, context, name, executionId, run, path, root) {
|
|
3533
|
-
var graphRunner, kind, hit, startTime, start, result, createdAt,
|
|
3583
|
+
var graphRunner, kind, hit, startTime, start, result, createdAt, started_1, activate, impl, endTime, event;
|
|
3584
|
+
var _this = this;
|
|
3534
3585
|
if (root === void 0) { root = false; }
|
|
3535
|
-
return __generator(this, function (
|
|
3536
|
-
switch (
|
|
3586
|
+
return __generator(this, function (_a) {
|
|
3587
|
+
switch (_a.label) {
|
|
3537
3588
|
case 0:
|
|
3538
3589
|
this.cache.visit(run, path);
|
|
3539
3590
|
graphRunner = this.graphRunners.get(fn);
|
|
@@ -3562,24 +3613,36 @@ var Engine = /** @class */ (function () {
|
|
|
3562
3613
|
createdAt = hit.info.createdAt;
|
|
3563
3614
|
return [3 /*break*/, 8];
|
|
3564
3615
|
case 1:
|
|
3565
|
-
context.activations[name] =
|
|
3616
|
+
context.activations[name] = false;
|
|
3617
|
+
started_1 = false;
|
|
3618
|
+
activate = function () {
|
|
3619
|
+
var _a;
|
|
3620
|
+
if (started_1)
|
|
3621
|
+
return;
|
|
3622
|
+
started_1 = true;
|
|
3623
|
+
(_a = run.onPrimitiveExecution) === null || _a === void 0 ? void 0 : _a.call(run);
|
|
3624
|
+
context.activations[name] = true;
|
|
3625
|
+
_this.fireEvent("functionCall", start);
|
|
3626
|
+
};
|
|
3566
3627
|
impl = fn.impl;
|
|
3567
|
-
|
|
3568
|
-
_b.label = 2;
|
|
3628
|
+
_a.label = 2;
|
|
3569
3629
|
case 2:
|
|
3570
|
-
|
|
3571
|
-
this.fireEvent("functionCall", start);
|
|
3630
|
+
_a.trys.push([2, , 7, 8]);
|
|
3572
3631
|
if (!graphRunner) return [3 /*break*/, 4];
|
|
3573
|
-
return [4 /*yield*/, graphRunner(inputs, params, run, path)];
|
|
3632
|
+
return [4 /*yield*/, graphRunner(inputs, params, __assign(__assign({}, run), { onPrimitiveExecution: activate }), path)];
|
|
3574
3633
|
case 3:
|
|
3575
|
-
|
|
3634
|
+
// Traversal alone is not activity. Defer this graph's call
|
|
3635
|
+
// event until the first cache miss, including in nested graphs.
|
|
3636
|
+
result = (_a.sent()).result;
|
|
3576
3637
|
return [3 /*break*/, 6];
|
|
3577
|
-
case 4:
|
|
3638
|
+
case 4:
|
|
3639
|
+
activate();
|
|
3640
|
+
console.log("Executing function call: ".concat(name));
|
|
3641
|
+
return [4 /*yield*/, impl.call(fn, inputs, params, this, root ? null : context, name)];
|
|
3578
3642
|
case 5:
|
|
3579
|
-
|
|
3580
|
-
|
|
3643
|
+
result = _a.sent();
|
|
3644
|
+
_a.label = 6;
|
|
3581
3645
|
case 6:
|
|
3582
|
-
result = _a;
|
|
3583
3646
|
createdAt = Date.now();
|
|
3584
3647
|
if (kind)
|
|
3585
3648
|
this.cache.set(run, path, kind, fn, call, inputs, params, result, impl, createdAt);
|
|
@@ -3644,7 +3707,7 @@ var Engine = /** @class */ (function () {
|
|
|
3644
3707
|
if (!fn)
|
|
3645
3708
|
throw new Error("function ".concat(fnCall.name, " not found in index"));
|
|
3646
3709
|
callPath = __spreadArray(__spreadArray([], __read(path), false), [name_1], false);
|
|
3647
|
-
inputs_1 = this.cache.interpolate(run, __spreadArray(__spreadArray([], __read(callPath), false), ["$inputs"], false), fnCall.inputs || {}, context.scope);
|
|
3710
|
+
inputs_1 = this.cache.interpolate(run, __spreadArray(__spreadArray([], __read(callPath), false), ["$inputs"], false), fnCall.inputs || {}, context.scope, true);
|
|
3648
3711
|
params_1 = fnCall.params || {};
|
|
3649
3712
|
context.calls[name_1] = fnCall;
|
|
3650
3713
|
context.inputs[name_1] = inputs_1;
|
|
@@ -3668,7 +3731,7 @@ var Engine = /** @class */ (function () {
|
|
|
3668
3731
|
finally { if (e_1) throw e_1.error; }
|
|
3669
3732
|
return [7 /*endfinally*/];
|
|
3670
3733
|
case 8:
|
|
3671
|
-
result = this.cache.interpolate(run, __spreadArray(__spreadArray([], __read(path), false), ["$outputs"], false), node.outputs || {}, context.scope);
|
|
3734
|
+
result = this.cache.interpolate(run, __spreadArray(__spreadArray([], __read(path), false), ["$outputs"], false), node.outputs || {}, context.scope, true);
|
|
3672
3735
|
endTime = performance.now();
|
|
3673
3736
|
response = {
|
|
3674
3737
|
name: node.name,
|