@arronqzy/blueprint-dsl 1.0.9 → 1.0.10
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 +174 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.js +163 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -812,6 +812,117 @@ function parseJsonConfig(config) {
|
|
|
812
812
|
return result.value;
|
|
813
813
|
}
|
|
814
814
|
|
|
815
|
+
// src/storage-config.ts
|
|
816
|
+
var STORAGE_KINDS = ["session", "local"];
|
|
817
|
+
var DEFAULT_STORAGE_NODE_CONFIG = {
|
|
818
|
+
read: { storage: "local", key: "" },
|
|
819
|
+
set: { storages: [], key: "", value: "" }
|
|
820
|
+
};
|
|
821
|
+
function isStorageKind(value) {
|
|
822
|
+
return value === "session" || value === "local";
|
|
823
|
+
}
|
|
824
|
+
function uniqueStorageKinds(kinds) {
|
|
825
|
+
const next = /* @__PURE__ */ new Set();
|
|
826
|
+
for (const kind of kinds ?? []) {
|
|
827
|
+
if (isStorageKind(kind)) next.add(kind);
|
|
828
|
+
}
|
|
829
|
+
return STORAGE_KINDS.filter((kind) => next.has(kind));
|
|
830
|
+
}
|
|
831
|
+
function normalizeStorageConfig(config) {
|
|
832
|
+
const read = config?.read;
|
|
833
|
+
const set = config?.set;
|
|
834
|
+
return {
|
|
835
|
+
read: {
|
|
836
|
+
storage: read?.storage === "session" ? "session" : "local",
|
|
837
|
+
key: typeof read?.key === "string" ? read.key : ""
|
|
838
|
+
},
|
|
839
|
+
set: {
|
|
840
|
+
storages: uniqueStorageKinds(set?.storages),
|
|
841
|
+
key: typeof set?.key === "string" ? set.key : "",
|
|
842
|
+
value: typeof set?.value === "string" ? set.value : ""
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function isStorageReadConfigured(config) {
|
|
847
|
+
return Boolean(config.read?.key?.trim());
|
|
848
|
+
}
|
|
849
|
+
function isStorageSetConfigured(config) {
|
|
850
|
+
return Boolean(config.set?.key?.trim()) && (config.set?.storages?.length ?? 0) > 0;
|
|
851
|
+
}
|
|
852
|
+
function resolveStorageWriteValue(template, scope) {
|
|
853
|
+
const raw = template ?? "";
|
|
854
|
+
const trimmed = raw.trim();
|
|
855
|
+
if (!trimmed) return "";
|
|
856
|
+
if (isWholeScopeExpression(trimmed)) {
|
|
857
|
+
const value = evaluateScopeExpression(trimmed.slice(1, -1), scope);
|
|
858
|
+
return value === void 0 ? "" : value;
|
|
859
|
+
}
|
|
860
|
+
if (hasScopeTemplate(raw)) {
|
|
861
|
+
return evaluateScopeTemplate(raw, scope);
|
|
862
|
+
}
|
|
863
|
+
return raw;
|
|
864
|
+
}
|
|
865
|
+
function serializeStorageValue(value) {
|
|
866
|
+
if (value === void 0 || value === null) return "";
|
|
867
|
+
if (typeof value === "string") return value;
|
|
868
|
+
try {
|
|
869
|
+
return JSON.stringify(value);
|
|
870
|
+
} catch {
|
|
871
|
+
return String(value);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
function deserializeStorageValue(raw) {
|
|
875
|
+
if (raw === null) return null;
|
|
876
|
+
const trimmed = raw.trim();
|
|
877
|
+
if (!trimmed) return raw;
|
|
878
|
+
if (!looksLikeJsonText(trimmed)) return raw;
|
|
879
|
+
try {
|
|
880
|
+
return JSON.parse(trimmed);
|
|
881
|
+
} catch {
|
|
882
|
+
return raw;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
function getDefaultStorageAccessors() {
|
|
886
|
+
if (typeof window === "undefined") return null;
|
|
887
|
+
try {
|
|
888
|
+
return {
|
|
889
|
+
session: window.sessionStorage,
|
|
890
|
+
local: window.localStorage
|
|
891
|
+
};
|
|
892
|
+
} catch {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function requireStorage(accessors, kind) {
|
|
897
|
+
const target = kind === "session" ? accessors?.session : accessors?.local;
|
|
898
|
+
if (!target) {
|
|
899
|
+
throw new Error(
|
|
900
|
+
kind === "session" ? "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 sessionStorage" : "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 localStorage"
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
return target;
|
|
904
|
+
}
|
|
905
|
+
function executeStorageConfig(config, incomingScope, accessors) {
|
|
906
|
+
const normalized = normalizeStorageConfig(config);
|
|
907
|
+
const store = accessors === void 0 ? getDefaultStorageAccessors() : accessors;
|
|
908
|
+
if (isStorageSetConfigured(normalized)) {
|
|
909
|
+
const value = resolveStorageWriteValue(normalized.set.value, incomingScope);
|
|
910
|
+
const serialized = serializeStorageValue(value);
|
|
911
|
+
const key = normalized.set.key.trim();
|
|
912
|
+
for (const kind of normalized.set.storages) {
|
|
913
|
+
requireStorage(store, kind).setItem(key, serialized);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (!isStorageReadConfigured(normalized)) {
|
|
917
|
+
return null;
|
|
918
|
+
}
|
|
919
|
+
return deserializeStorageValue(
|
|
920
|
+
requireStorage(store, normalized.read.storage).getItem(
|
|
921
|
+
normalized.read.key.trim()
|
|
922
|
+
)
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
|
|
815
926
|
// src/logic-config.ts
|
|
816
927
|
var DEFAULT_LOGIC_NODE_CONFIG = {
|
|
817
928
|
sourceCode: `function update(input) {
|
|
@@ -1244,6 +1355,7 @@ var DEFAULT_LOGIC_NODE_TYPE = "Logic";
|
|
|
1244
1355
|
var LIFECYCLE_NODE_TYPE = "Lifecycle";
|
|
1245
1356
|
var FETCH_NODE_TYPE = "DataFetch";
|
|
1246
1357
|
var JSON_NODE_TYPE = "JsonNode";
|
|
1358
|
+
var STORAGE_NODE_TYPE = "StorageNode";
|
|
1247
1359
|
var CLOCK_NODE_TYPE = "Clock";
|
|
1248
1360
|
var AND_NODE_TYPE = "AndLogic";
|
|
1249
1361
|
var VIEW_NODE_TYPE = "ViewBind";
|
|
@@ -1278,6 +1390,12 @@ var jsonNodeDefinition = {
|
|
|
1278
1390
|
outputs: [{ name: "out", kind: "data" }],
|
|
1279
1391
|
behavior: { kind: "js", ref: "json-parse-run" }
|
|
1280
1392
|
};
|
|
1393
|
+
var storageNodeDefinition = {
|
|
1394
|
+
type: STORAGE_NODE_TYPE,
|
|
1395
|
+
inputs: [{ name: "in", kind: "data" }],
|
|
1396
|
+
outputs: [{ name: "out", kind: "data" }],
|
|
1397
|
+
behavior: { kind: "js", ref: "storage-run" }
|
|
1398
|
+
};
|
|
1281
1399
|
var clockNodeDefinition = {
|
|
1282
1400
|
type: CLOCK_NODE_TYPE,
|
|
1283
1401
|
inputs: [{ name: "in", kind: "data" }],
|
|
@@ -1311,6 +1429,7 @@ var nodeDefinitionRegistry = {
|
|
|
1311
1429
|
[LIFECYCLE_NODE_TYPE]: lifecycleNodeDefinition,
|
|
1312
1430
|
[FETCH_NODE_TYPE]: fetchNodeDefinition,
|
|
1313
1431
|
[JSON_NODE_TYPE]: jsonNodeDefinition,
|
|
1432
|
+
[STORAGE_NODE_TYPE]: storageNodeDefinition,
|
|
1314
1433
|
[CLOCK_NODE_TYPE]: clockNodeDefinition,
|
|
1315
1434
|
[AND_NODE_TYPE]: andLogicNodeDefinition,
|
|
1316
1435
|
[VIEW_NODE_TYPE]: viewBindNodeDefinition,
|
|
@@ -1497,6 +1616,7 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
|
|
|
1497
1616
|
this.registerBlueprintRefBehavior();
|
|
1498
1617
|
this.registerFetchBehavior();
|
|
1499
1618
|
this.registerJsonBehavior();
|
|
1619
|
+
this.registerStorageBehavior();
|
|
1500
1620
|
this.registerLogicBehavior();
|
|
1501
1621
|
this.registerClockBehavior();
|
|
1502
1622
|
this.registerAndBehavior();
|
|
@@ -2327,6 +2447,48 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
|
|
|
2327
2447
|
io.emitFlow("out");
|
|
2328
2448
|
});
|
|
2329
2449
|
}
|
|
2450
|
+
registerStorageBehavior() {
|
|
2451
|
+
const runner = this;
|
|
2452
|
+
this.behaviors.registerJS("storage-run", async ({ token, io }) => {
|
|
2453
|
+
const node = runner.requireNode(token.nodeId);
|
|
2454
|
+
try {
|
|
2455
|
+
const inputPort = token.inPort || "in";
|
|
2456
|
+
const input = await io.getInput(inputPort);
|
|
2457
|
+
if (isFalseSignal(input)) {
|
|
2458
|
+
io.setOutput("out", input);
|
|
2459
|
+
io.emitFlow("out");
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2462
|
+
if (!isTrueSignal(input)) {
|
|
2463
|
+
io.setOutput(
|
|
2464
|
+
"out",
|
|
2465
|
+
createFalseSignal("\u5B58\u50A8\u8282\u70B9\u9700\u8981\u6536\u5230\u771F\u4FE1\u53F7\u540E\u624D\u4F1A\u8BFB\u5199\u7F13\u5B58")
|
|
2466
|
+
);
|
|
2467
|
+
io.emitFlow("out");
|
|
2468
|
+
return;
|
|
2469
|
+
}
|
|
2470
|
+
const incomingScope = runner.buildFetchIncomingScope(
|
|
2471
|
+
token.nodeId,
|
|
2472
|
+
inputPort,
|
|
2473
|
+
input
|
|
2474
|
+
);
|
|
2475
|
+
const config = normalizeStorageConfig({
|
|
2476
|
+
...DEFAULT_STORAGE_NODE_CONFIG,
|
|
2477
|
+
...node.storageConfig
|
|
2478
|
+
});
|
|
2479
|
+
const value = executeStorageConfig(config, incomingScope);
|
|
2480
|
+
io.setOutput("out", createTrueSignal(value));
|
|
2481
|
+
} catch (error) {
|
|
2482
|
+
io.setOutput(
|
|
2483
|
+
"out",
|
|
2484
|
+
createFalseSignal(
|
|
2485
|
+
error instanceof Error ? error.message : String(error)
|
|
2486
|
+
)
|
|
2487
|
+
);
|
|
2488
|
+
}
|
|
2489
|
+
io.emitFlow("out");
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2330
2492
|
registerClockBehavior() {
|
|
2331
2493
|
const runner = this;
|
|
2332
2494
|
this.behaviors.registerJS("clock-run", async ({ token, io }) => {
|
|
@@ -2595,6 +2757,7 @@ exports.DEFAULT_FETCH_REQUEST_CONFIG = DEFAULT_FETCH_REQUEST_CONFIG;
|
|
|
2595
2757
|
exports.DEFAULT_JSON_NODE_CONFIG = DEFAULT_JSON_NODE_CONFIG;
|
|
2596
2758
|
exports.DEFAULT_LOGIC_NODE_CONFIG = DEFAULT_LOGIC_NODE_CONFIG;
|
|
2597
2759
|
exports.DEFAULT_LOGIC_NODE_TYPE = DEFAULT_LOGIC_NODE_TYPE;
|
|
2760
|
+
exports.DEFAULT_STORAGE_NODE_CONFIG = DEFAULT_STORAGE_NODE_CONFIG;
|
|
2598
2761
|
exports.DEFAULT_VIEW_EVENT_NODE_CONFIG = DEFAULT_VIEW_EVENT_NODE_CONFIG;
|
|
2599
2762
|
exports.EVENT_NODE_TYPE = EVENT_NODE_TYPE;
|
|
2600
2763
|
exports.Executor = Executor;
|
|
@@ -2611,6 +2774,8 @@ exports.LIFECYCLE_NODE_TYPE = LIFECYCLE_NODE_TYPE;
|
|
|
2611
2774
|
exports.LIFECYCLE_SIGNAL_KEY = LIFECYCLE_SIGNAL_KEY;
|
|
2612
2775
|
exports.PAGE_LIFECYCLE_LABELS = PAGE_LIFECYCLE_LABELS;
|
|
2613
2776
|
exports.PAGE_LIFECYCLE_PHASES = PAGE_LIFECYCLE_PHASES;
|
|
2777
|
+
exports.STORAGE_KINDS = STORAGE_KINDS;
|
|
2778
|
+
exports.STORAGE_NODE_TYPE = STORAGE_NODE_TYPE;
|
|
2614
2779
|
exports.UI_EVENT_PAYLOAD_KEY = UI_EVENT_PAYLOAD_KEY;
|
|
2615
2780
|
exports.VIEW_EVENT_SIGNAL_KEY = VIEW_EVENT_SIGNAL_KEY;
|
|
2616
2781
|
exports.VIEW_EVENT_TYPES = VIEW_EVENT_TYPES;
|
|
@@ -2644,6 +2809,7 @@ exports.createTraceEntryId = createTraceEntryId;
|
|
|
2644
2809
|
exports.createTrueSignal = createTrueSignal;
|
|
2645
2810
|
exports.createViewEventSignal = createViewEventSignal;
|
|
2646
2811
|
exports.defaultLogicNodeDefinition = defaultLogicNodeDefinition;
|
|
2812
|
+
exports.deserializeStorageValue = deserializeStorageValue;
|
|
2647
2813
|
exports.detectBlueprintReferenceCycle = detectBlueprintReferenceCycle;
|
|
2648
2814
|
exports.detectRuntimeBlueprintCycle = detectRuntimeBlueprintCycle;
|
|
2649
2815
|
exports.draftFetchHeadersText = draftFetchHeadersText;
|
|
@@ -2652,6 +2818,7 @@ exports.evaluateScopeTemplate = evaluateScopeTemplate;
|
|
|
2652
2818
|
exports.evaluateScopeTemplateInJson = evaluateScopeTemplateInJson;
|
|
2653
2819
|
exports.executeFetch = executeFetch;
|
|
2654
2820
|
exports.executeLogicConfig = executeLogicConfig;
|
|
2821
|
+
exports.executeStorageConfig = executeStorageConfig;
|
|
2655
2822
|
exports.fetchConfigHasScopeTemplate = fetchConfigHasScopeTemplate;
|
|
2656
2823
|
exports.fetchNodeDefinition = fetchNodeDefinition;
|
|
2657
2824
|
exports.filterEndpointSuggestions = filterEndpointSuggestions;
|
|
@@ -2669,6 +2836,8 @@ exports.isClockNodeActive = isClockNodeActive;
|
|
|
2669
2836
|
exports.isClockScheduleActive = isClockScheduleActive;
|
|
2670
2837
|
exports.isClockSessionAborted = isClockSessionAborted;
|
|
2671
2838
|
exports.isFalseSignal = isFalseSignal;
|
|
2839
|
+
exports.isStorageReadConfigured = isStorageReadConfigured;
|
|
2840
|
+
exports.isStorageSetConfigured = isStorageSetConfigured;
|
|
2672
2841
|
exports.isTrueSignal = isTrueSignal;
|
|
2673
2842
|
exports.isViewEventType = isViewEventType;
|
|
2674
2843
|
exports.isWholeScopeExpression = isWholeScopeExpression;
|
|
@@ -2679,6 +2848,7 @@ exports.looksLikeJsonText = looksLikeJsonText;
|
|
|
2679
2848
|
exports.nodeDefinitionRegistry = nodeDefinitionRegistry;
|
|
2680
2849
|
exports.normalizeClockConfig = normalizeClockConfig;
|
|
2681
2850
|
exports.normalizeFetchRequestConfig = normalizeFetchRequestConfig;
|
|
2851
|
+
exports.normalizeStorageConfig = normalizeStorageConfig;
|
|
2682
2852
|
exports.normalizeViewEventConfig = normalizeViewEventConfig;
|
|
2683
2853
|
exports.parseFetchHeadersJson = parseFetchHeadersJson;
|
|
2684
2854
|
exports.parseJsonConfig = parseJsonConfig;
|
|
@@ -2692,15 +2862,19 @@ exports.resolveFetchHeaders = resolveFetchHeaders;
|
|
|
2692
2862
|
exports.resolveFetchIncomingScope = resolveFetchIncomingScope;
|
|
2693
2863
|
exports.resolveFetchRequestUrl = resolveFetchRequestUrl;
|
|
2694
2864
|
exports.resolveFetchScopeAutocompleteRoot = resolveFetchScopeAutocompleteRoot;
|
|
2865
|
+
exports.resolveStorageWriteValue = resolveStorageWriteValue;
|
|
2695
2866
|
exports.scheduleClockOutputs = scheduleClockOutputs;
|
|
2867
|
+
exports.serializeStorageValue = serializeStorageValue;
|
|
2696
2868
|
exports.serializeTraceValue = serializeTraceValue;
|
|
2697
2869
|
exports.snapshotDomEvent = snapshotDomEvent;
|
|
2698
2870
|
exports.snapshotViewEventNode = snapshotViewEventNode;
|
|
2699
2871
|
exports.startClockSchedule = startClockSchedule;
|
|
2700
2872
|
exports.stopAllClockSchedules = stopAllClockSchedules;
|
|
2701
2873
|
exports.stopClockSchedule = stopClockSchedule;
|
|
2874
|
+
exports.storageNodeDefinition = storageNodeDefinition;
|
|
2702
2875
|
exports.stringifyScopeValue = stringifyScopeValue;
|
|
2703
2876
|
exports.subscribeActiveClockNodes = subscribeActiveClockNodes;
|
|
2877
|
+
exports.uniqueStorageKinds = uniqueStorageKinds;
|
|
2704
2878
|
exports.validateClockScheduleConfig = validateClockScheduleConfig;
|
|
2705
2879
|
exports.validateFetchJsonText = validateFetchJsonText;
|
|
2706
2880
|
exports.validateJsonString = validateJsonString;
|