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