@arronqzy/blueprint-dsl 1.0.9 → 1.0.11
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 +186 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +173 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -812,6 +812,127 @@ 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
|
+
|
|
926
|
+
// src/app-namespace.ts
|
|
927
|
+
function normalizeAppNameSpace(value) {
|
|
928
|
+
return (value ?? "").trim();
|
|
929
|
+
}
|
|
930
|
+
function appStorageKey(base, nameSpace) {
|
|
931
|
+
const ns = normalizeAppNameSpace(nameSpace);
|
|
932
|
+
if (!ns) return base;
|
|
933
|
+
return `${base}__${ns.slice(0, 120)}`;
|
|
934
|
+
}
|
|
935
|
+
|
|
815
936
|
// src/logic-config.ts
|
|
816
937
|
var DEFAULT_LOGIC_NODE_CONFIG = {
|
|
817
938
|
sourceCode: `function update(input) {
|
|
@@ -1244,6 +1365,7 @@ var DEFAULT_LOGIC_NODE_TYPE = "Logic";
|
|
|
1244
1365
|
var LIFECYCLE_NODE_TYPE = "Lifecycle";
|
|
1245
1366
|
var FETCH_NODE_TYPE = "DataFetch";
|
|
1246
1367
|
var JSON_NODE_TYPE = "JsonNode";
|
|
1368
|
+
var STORAGE_NODE_TYPE = "StorageNode";
|
|
1247
1369
|
var CLOCK_NODE_TYPE = "Clock";
|
|
1248
1370
|
var AND_NODE_TYPE = "AndLogic";
|
|
1249
1371
|
var VIEW_NODE_TYPE = "ViewBind";
|
|
@@ -1278,6 +1400,12 @@ var jsonNodeDefinition = {
|
|
|
1278
1400
|
outputs: [{ name: "out", kind: "data" }],
|
|
1279
1401
|
behavior: { kind: "js", ref: "json-parse-run" }
|
|
1280
1402
|
};
|
|
1403
|
+
var storageNodeDefinition = {
|
|
1404
|
+
type: STORAGE_NODE_TYPE,
|
|
1405
|
+
inputs: [{ name: "in", kind: "data" }],
|
|
1406
|
+
outputs: [{ name: "out", kind: "data" }],
|
|
1407
|
+
behavior: { kind: "js", ref: "storage-run" }
|
|
1408
|
+
};
|
|
1281
1409
|
var clockNodeDefinition = {
|
|
1282
1410
|
type: CLOCK_NODE_TYPE,
|
|
1283
1411
|
inputs: [{ name: "in", kind: "data" }],
|
|
@@ -1311,6 +1439,7 @@ var nodeDefinitionRegistry = {
|
|
|
1311
1439
|
[LIFECYCLE_NODE_TYPE]: lifecycleNodeDefinition,
|
|
1312
1440
|
[FETCH_NODE_TYPE]: fetchNodeDefinition,
|
|
1313
1441
|
[JSON_NODE_TYPE]: jsonNodeDefinition,
|
|
1442
|
+
[STORAGE_NODE_TYPE]: storageNodeDefinition,
|
|
1314
1443
|
[CLOCK_NODE_TYPE]: clockNodeDefinition,
|
|
1315
1444
|
[AND_NODE_TYPE]: andLogicNodeDefinition,
|
|
1316
1445
|
[VIEW_NODE_TYPE]: viewBindNodeDefinition,
|
|
@@ -1497,6 +1626,7 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
|
|
|
1497
1626
|
this.registerBlueprintRefBehavior();
|
|
1498
1627
|
this.registerFetchBehavior();
|
|
1499
1628
|
this.registerJsonBehavior();
|
|
1629
|
+
this.registerStorageBehavior();
|
|
1500
1630
|
this.registerLogicBehavior();
|
|
1501
1631
|
this.registerClockBehavior();
|
|
1502
1632
|
this.registerAndBehavior();
|
|
@@ -2327,6 +2457,48 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
|
|
|
2327
2457
|
io.emitFlow("out");
|
|
2328
2458
|
});
|
|
2329
2459
|
}
|
|
2460
|
+
registerStorageBehavior() {
|
|
2461
|
+
const runner = this;
|
|
2462
|
+
this.behaviors.registerJS("storage-run", async ({ token, io }) => {
|
|
2463
|
+
const node = runner.requireNode(token.nodeId);
|
|
2464
|
+
try {
|
|
2465
|
+
const inputPort = token.inPort || "in";
|
|
2466
|
+
const input = await io.getInput(inputPort);
|
|
2467
|
+
if (isFalseSignal(input)) {
|
|
2468
|
+
io.setOutput("out", input);
|
|
2469
|
+
io.emitFlow("out");
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
if (!isTrueSignal(input)) {
|
|
2473
|
+
io.setOutput(
|
|
2474
|
+
"out",
|
|
2475
|
+
createFalseSignal("\u5B58\u50A8\u8282\u70B9\u9700\u8981\u6536\u5230\u771F\u4FE1\u53F7\u540E\u624D\u4F1A\u8BFB\u5199\u7F13\u5B58")
|
|
2476
|
+
);
|
|
2477
|
+
io.emitFlow("out");
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2480
|
+
const incomingScope = runner.buildFetchIncomingScope(
|
|
2481
|
+
token.nodeId,
|
|
2482
|
+
inputPort,
|
|
2483
|
+
input
|
|
2484
|
+
);
|
|
2485
|
+
const config = normalizeStorageConfig({
|
|
2486
|
+
...DEFAULT_STORAGE_NODE_CONFIG,
|
|
2487
|
+
...node.storageConfig
|
|
2488
|
+
});
|
|
2489
|
+
const value = executeStorageConfig(config, incomingScope);
|
|
2490
|
+
io.setOutput("out", createTrueSignal(value));
|
|
2491
|
+
} catch (error) {
|
|
2492
|
+
io.setOutput(
|
|
2493
|
+
"out",
|
|
2494
|
+
createFalseSignal(
|
|
2495
|
+
error instanceof Error ? error.message : String(error)
|
|
2496
|
+
)
|
|
2497
|
+
);
|
|
2498
|
+
}
|
|
2499
|
+
io.emitFlow("out");
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2330
2502
|
registerClockBehavior() {
|
|
2331
2503
|
const runner = this;
|
|
2332
2504
|
this.behaviors.registerJS("clock-run", async ({ token, io }) => {
|
|
@@ -2595,6 +2767,7 @@ exports.DEFAULT_FETCH_REQUEST_CONFIG = DEFAULT_FETCH_REQUEST_CONFIG;
|
|
|
2595
2767
|
exports.DEFAULT_JSON_NODE_CONFIG = DEFAULT_JSON_NODE_CONFIG;
|
|
2596
2768
|
exports.DEFAULT_LOGIC_NODE_CONFIG = DEFAULT_LOGIC_NODE_CONFIG;
|
|
2597
2769
|
exports.DEFAULT_LOGIC_NODE_TYPE = DEFAULT_LOGIC_NODE_TYPE;
|
|
2770
|
+
exports.DEFAULT_STORAGE_NODE_CONFIG = DEFAULT_STORAGE_NODE_CONFIG;
|
|
2598
2771
|
exports.DEFAULT_VIEW_EVENT_NODE_CONFIG = DEFAULT_VIEW_EVENT_NODE_CONFIG;
|
|
2599
2772
|
exports.EVENT_NODE_TYPE = EVENT_NODE_TYPE;
|
|
2600
2773
|
exports.Executor = Executor;
|
|
@@ -2611,6 +2784,8 @@ exports.LIFECYCLE_NODE_TYPE = LIFECYCLE_NODE_TYPE;
|
|
|
2611
2784
|
exports.LIFECYCLE_SIGNAL_KEY = LIFECYCLE_SIGNAL_KEY;
|
|
2612
2785
|
exports.PAGE_LIFECYCLE_LABELS = PAGE_LIFECYCLE_LABELS;
|
|
2613
2786
|
exports.PAGE_LIFECYCLE_PHASES = PAGE_LIFECYCLE_PHASES;
|
|
2787
|
+
exports.STORAGE_KINDS = STORAGE_KINDS;
|
|
2788
|
+
exports.STORAGE_NODE_TYPE = STORAGE_NODE_TYPE;
|
|
2614
2789
|
exports.UI_EVENT_PAYLOAD_KEY = UI_EVENT_PAYLOAD_KEY;
|
|
2615
2790
|
exports.VIEW_EVENT_SIGNAL_KEY = VIEW_EVENT_SIGNAL_KEY;
|
|
2616
2791
|
exports.VIEW_EVENT_TYPES = VIEW_EVENT_TYPES;
|
|
@@ -2618,6 +2793,7 @@ exports.VIEW_NODE_TYPE = VIEW_NODE_TYPE;
|
|
|
2618
2793
|
exports.abortClockNode = abortClockNode;
|
|
2619
2794
|
exports.abortClockSession = abortClockSession;
|
|
2620
2795
|
exports.andLogicNodeDefinition = andLogicNodeDefinition;
|
|
2796
|
+
exports.appStorageKey = appStorageKey;
|
|
2621
2797
|
exports.applyFetchConfigScope = applyFetchConfigScope;
|
|
2622
2798
|
exports.applyScopeAutocompleteSelection = applyScopeAutocompleteSelection;
|
|
2623
2799
|
exports.assertNoBlueprintReferenceCycle = assertNoBlueprintReferenceCycle;
|
|
@@ -2644,6 +2820,7 @@ exports.createTraceEntryId = createTraceEntryId;
|
|
|
2644
2820
|
exports.createTrueSignal = createTrueSignal;
|
|
2645
2821
|
exports.createViewEventSignal = createViewEventSignal;
|
|
2646
2822
|
exports.defaultLogicNodeDefinition = defaultLogicNodeDefinition;
|
|
2823
|
+
exports.deserializeStorageValue = deserializeStorageValue;
|
|
2647
2824
|
exports.detectBlueprintReferenceCycle = detectBlueprintReferenceCycle;
|
|
2648
2825
|
exports.detectRuntimeBlueprintCycle = detectRuntimeBlueprintCycle;
|
|
2649
2826
|
exports.draftFetchHeadersText = draftFetchHeadersText;
|
|
@@ -2652,6 +2829,7 @@ exports.evaluateScopeTemplate = evaluateScopeTemplate;
|
|
|
2652
2829
|
exports.evaluateScopeTemplateInJson = evaluateScopeTemplateInJson;
|
|
2653
2830
|
exports.executeFetch = executeFetch;
|
|
2654
2831
|
exports.executeLogicConfig = executeLogicConfig;
|
|
2832
|
+
exports.executeStorageConfig = executeStorageConfig;
|
|
2655
2833
|
exports.fetchConfigHasScopeTemplate = fetchConfigHasScopeTemplate;
|
|
2656
2834
|
exports.fetchNodeDefinition = fetchNodeDefinition;
|
|
2657
2835
|
exports.filterEndpointSuggestions = filterEndpointSuggestions;
|
|
@@ -2669,6 +2847,8 @@ exports.isClockNodeActive = isClockNodeActive;
|
|
|
2669
2847
|
exports.isClockScheduleActive = isClockScheduleActive;
|
|
2670
2848
|
exports.isClockSessionAborted = isClockSessionAborted;
|
|
2671
2849
|
exports.isFalseSignal = isFalseSignal;
|
|
2850
|
+
exports.isStorageReadConfigured = isStorageReadConfigured;
|
|
2851
|
+
exports.isStorageSetConfigured = isStorageSetConfigured;
|
|
2672
2852
|
exports.isTrueSignal = isTrueSignal;
|
|
2673
2853
|
exports.isViewEventType = isViewEventType;
|
|
2674
2854
|
exports.isWholeScopeExpression = isWholeScopeExpression;
|
|
@@ -2677,8 +2857,10 @@ exports.latestTraceOutputsByNode = latestTraceOutputsByNode;
|
|
|
2677
2857
|
exports.lifecycleNodeDefinition = lifecycleNodeDefinition;
|
|
2678
2858
|
exports.looksLikeJsonText = looksLikeJsonText;
|
|
2679
2859
|
exports.nodeDefinitionRegistry = nodeDefinitionRegistry;
|
|
2860
|
+
exports.normalizeAppNameSpace = normalizeAppNameSpace;
|
|
2680
2861
|
exports.normalizeClockConfig = normalizeClockConfig;
|
|
2681
2862
|
exports.normalizeFetchRequestConfig = normalizeFetchRequestConfig;
|
|
2863
|
+
exports.normalizeStorageConfig = normalizeStorageConfig;
|
|
2682
2864
|
exports.normalizeViewEventConfig = normalizeViewEventConfig;
|
|
2683
2865
|
exports.parseFetchHeadersJson = parseFetchHeadersJson;
|
|
2684
2866
|
exports.parseJsonConfig = parseJsonConfig;
|
|
@@ -2692,15 +2874,19 @@ exports.resolveFetchHeaders = resolveFetchHeaders;
|
|
|
2692
2874
|
exports.resolveFetchIncomingScope = resolveFetchIncomingScope;
|
|
2693
2875
|
exports.resolveFetchRequestUrl = resolveFetchRequestUrl;
|
|
2694
2876
|
exports.resolveFetchScopeAutocompleteRoot = resolveFetchScopeAutocompleteRoot;
|
|
2877
|
+
exports.resolveStorageWriteValue = resolveStorageWriteValue;
|
|
2695
2878
|
exports.scheduleClockOutputs = scheduleClockOutputs;
|
|
2879
|
+
exports.serializeStorageValue = serializeStorageValue;
|
|
2696
2880
|
exports.serializeTraceValue = serializeTraceValue;
|
|
2697
2881
|
exports.snapshotDomEvent = snapshotDomEvent;
|
|
2698
2882
|
exports.snapshotViewEventNode = snapshotViewEventNode;
|
|
2699
2883
|
exports.startClockSchedule = startClockSchedule;
|
|
2700
2884
|
exports.stopAllClockSchedules = stopAllClockSchedules;
|
|
2701
2885
|
exports.stopClockSchedule = stopClockSchedule;
|
|
2886
|
+
exports.storageNodeDefinition = storageNodeDefinition;
|
|
2702
2887
|
exports.stringifyScopeValue = stringifyScopeValue;
|
|
2703
2888
|
exports.subscribeActiveClockNodes = subscribeActiveClockNodes;
|
|
2889
|
+
exports.uniqueStorageKinds = uniqueStorageKinds;
|
|
2704
2890
|
exports.validateClockScheduleConfig = validateClockScheduleConfig;
|
|
2705
2891
|
exports.validateFetchJsonText = validateFetchJsonText;
|
|
2706
2892
|
exports.validateJsonString = validateJsonString;
|