@arronqzy/blueprint-dsl 1.0.14 → 1.0.15

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 CHANGED
@@ -804,8 +804,20 @@ function validateJsonString(jsonString) {
804
804
  };
805
805
  }
806
806
  }
807
- function parseJsonConfig(config) {
808
- const result = validateJsonString(config.jsonString ?? "");
807
+ function validateJsonStringAllowingScope(jsonString) {
808
+ if (hasScopeTemplate(jsonString ?? "")) {
809
+ return { ok: true, deferred: true };
810
+ }
811
+ const result = validateJsonString(jsonString);
812
+ if (!result.ok) return result;
813
+ return { ok: true, value: result.value };
814
+ }
815
+ function parseJsonConfig(config, scope) {
816
+ let raw = config.jsonString ?? "";
817
+ if (scope !== void 0 && hasScopeTemplate(raw)) {
818
+ raw = evaluateScopeTemplateInJson(raw, scope);
819
+ }
820
+ const result = validateJsonString(raw);
809
821
  if (!result.ok) {
810
822
  throw new Error(result.error);
811
823
  }
@@ -862,6 +874,20 @@ function resolveStorageWriteValue(template, scope) {
862
874
  }
863
875
  return raw;
864
876
  }
877
+ function resolveStorageKey(key, scope) {
878
+ const raw = key ?? "";
879
+ const trimmed = raw.trim();
880
+ if (!trimmed) return "";
881
+ if (isWholeScopeExpression(trimmed)) {
882
+ return stringifyScopeValue(
883
+ evaluateScopeExpression(trimmed.slice(1, -1), scope)
884
+ );
885
+ }
886
+ if (hasScopeTemplate(raw)) {
887
+ return evaluateScopeTemplate(raw, scope).trim();
888
+ }
889
+ return trimmed;
890
+ }
865
891
  function serializeStorageValue(value) {
866
892
  if (value === void 0 || value === null) return "";
867
893
  if (typeof value === "string") return value;
@@ -893,6 +919,35 @@ function getDefaultStorageAccessors() {
893
919
  return null;
894
920
  }
895
921
  }
922
+ function readBrowserStorageBucket(kind) {
923
+ if (typeof window === "undefined") return null;
924
+ try {
925
+ return kind === "session" ? window.sessionStorage : window.localStorage;
926
+ } catch {
927
+ return null;
928
+ }
929
+ }
930
+ function listBrowserStorageKeys(kind) {
931
+ const kinds = uniqueStorageKinds(Array.isArray(kind) ? kind : [kind]);
932
+ const keys = /* @__PURE__ */ new Set();
933
+ for (const next of kinds) {
934
+ const storage = readBrowserStorageBucket(next);
935
+ if (!storage) continue;
936
+ try {
937
+ for (let i = 0; i < storage.length; i += 1) {
938
+ const key = storage.key(i);
939
+ if (typeof key === "string" && key) keys.add(key);
940
+ }
941
+ } catch {
942
+ }
943
+ }
944
+ return [...keys].sort((a, b) => a.localeCompare(b));
945
+ }
946
+ function filterStorageKeySuggestions(keys, query) {
947
+ const q = query.trim().toLowerCase();
948
+ if (!q) return [...keys];
949
+ return keys.filter((key) => key.toLowerCase().includes(q));
950
+ }
896
951
  function requireStorage(accessors, kind) {
897
952
  const target = kind === "session" ? accessors?.session : accessors?.local;
898
953
  if (!target) {
@@ -908,7 +963,10 @@ function executeStorageConfig(config, incomingScope, accessors) {
908
963
  if (isStorageSetConfigured(normalized)) {
909
964
  const value = resolveStorageWriteValue(normalized.set.value, incomingScope);
910
965
  const serialized = serializeStorageValue(value);
911
- const key = normalized.set.key.trim();
966
+ const key = resolveStorageKey(normalized.set.key, incomingScope);
967
+ if (!key) {
968
+ throw new Error("\u5B58\u50A8\u5199\u5165 key \u89E3\u6790\u4E3A\u7A7A");
969
+ }
912
970
  for (const kind of normalized.set.storages) {
913
971
  requireStorage(store, kind).setItem(key, serialized);
914
972
  }
@@ -916,10 +974,12 @@ function executeStorageConfig(config, incomingScope, accessors) {
916
974
  if (!isStorageReadConfigured(normalized)) {
917
975
  return null;
918
976
  }
977
+ const readKey = resolveStorageKey(normalized.read.key, incomingScope);
978
+ if (!readKey) {
979
+ return null;
980
+ }
919
981
  return deserializeStorageValue(
920
- requireStorage(store, normalized.read.storage).getItem(
921
- normalized.read.key.trim()
922
- )
982
+ requireStorage(store, normalized.read.storage).getItem(readKey)
923
983
  );
924
984
  }
925
985
 
@@ -2444,7 +2504,12 @@ var BlueprintGraphRunner = class _BlueprintGraphRunner {
2444
2504
  ...DEFAULT_JSON_NODE_CONFIG,
2445
2505
  ...node.jsonConfig
2446
2506
  };
2447
- const value = parseJsonConfig(config);
2507
+ const incomingScope = runner.buildFetchIncomingScope(
2508
+ token.nodeId,
2509
+ "in",
2510
+ input
2511
+ );
2512
+ const value = parseJsonConfig(config, incomingScope);
2448
2513
  io.setOutput("out", createTrueSignal(value));
2449
2514
  } catch (error) {
2450
2515
  io.setOutput(
@@ -2833,6 +2898,7 @@ exports.executeStorageConfig = executeStorageConfig;
2833
2898
  exports.fetchConfigHasScopeTemplate = fetchConfigHasScopeTemplate;
2834
2899
  exports.fetchNodeDefinition = fetchNodeDefinition;
2835
2900
  exports.filterEndpointSuggestions = filterEndpointSuggestions;
2901
+ exports.filterStorageKeySuggestions = filterStorageKeySuggestions;
2836
2902
  exports.formatBlueprintCycleMessage = formatBlueprintCycleMessage;
2837
2903
  exports.formatClockTime = formatClockTime;
2838
2904
  exports.getActiveClockNodeIds = getActiveClockNodeIds;
@@ -2855,6 +2921,7 @@ exports.isWholeScopeExpression = isWholeScopeExpression;
2855
2921
  exports.jsonNodeDefinition = jsonNodeDefinition;
2856
2922
  exports.latestTraceOutputsByNode = latestTraceOutputsByNode;
2857
2923
  exports.lifecycleNodeDefinition = lifecycleNodeDefinition;
2924
+ exports.listBrowserStorageKeys = listBrowserStorageKeys;
2858
2925
  exports.looksLikeJsonText = looksLikeJsonText;
2859
2926
  exports.nodeDefinitionRegistry = nodeDefinitionRegistry;
2860
2927
  exports.normalizeAppNameSpace = normalizeAppNameSpace;
@@ -2874,6 +2941,7 @@ exports.resolveFetchHeaders = resolveFetchHeaders;
2874
2941
  exports.resolveFetchIncomingScope = resolveFetchIncomingScope;
2875
2942
  exports.resolveFetchRequestUrl = resolveFetchRequestUrl;
2876
2943
  exports.resolveFetchScopeAutocompleteRoot = resolveFetchScopeAutocompleteRoot;
2944
+ exports.resolveStorageKey = resolveStorageKey;
2877
2945
  exports.resolveStorageWriteValue = resolveStorageWriteValue;
2878
2946
  exports.scheduleClockOutputs = scheduleClockOutputs;
2879
2947
  exports.serializeStorageValue = serializeStorageValue;
@@ -2890,6 +2958,7 @@ exports.uniqueStorageKinds = uniqueStorageKinds;
2890
2958
  exports.validateClockScheduleConfig = validateClockScheduleConfig;
2891
2959
  exports.validateFetchJsonText = validateFetchJsonText;
2892
2960
  exports.validateJsonString = validateJsonString;
2961
+ exports.validateJsonStringAllowingScope = validateJsonStringAllowingScope;
2893
2962
  exports.validateLogicSourceCode = validateLogicSourceCode;
2894
2963
  exports.viewBindNodeDefinition = viewBindNodeDefinition;
2895
2964
  exports.viewEventNodeDefinition = viewEventNodeDefinition;