@wcstack/state 2.2.0 → 2.4.0

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.
@@ -1079,6 +1079,8 @@ const STATE_EVENT_TOKENS_NAME = "$eventTokens";
1079
1079
  const STATE_ON_NAME = "$on";
1080
1080
  const STATE_STREAMS_NAME = "$streams";
1081
1081
  const STATE_WATCH_NAME = "$watch";
1082
+ const STATE_SCAN_NAME = "$scan";
1083
+ const STATE_RECURSION_NAME = "$recursion";
1082
1084
  const STATE_LIST_KEYS_NAME = "$listKeys";
1083
1085
  const STATE_STREAM_STATUS_NAMESPACE_NAME = "$streamStatus";
1084
1086
  const STATE_STREAM_ERROR_NAMESPACE_NAME = "$streamError";
@@ -1156,7 +1158,9 @@ function getWcsManifest() {
1156
1158
  STATE_ON_NAME,
1157
1159
  STATE_STREAMS_NAME,
1158
1160
  STATE_WATCH_NAME,
1161
+ STATE_SCAN_NAME,
1159
1162
  STATE_LIST_KEYS_NAME,
1163
+ STATE_RECURSION_NAME,
1160
1164
  STATE_STREAM_STATUS_NAMESPACE_NAME,
1161
1165
  STATE_STREAM_ERROR_NAMESPACE_NAME,
1162
1166
  ],
@@ -33,6 +33,17 @@ for (let i = 0; i < MAX_WILDCARD_DEPTH; i++) {
33
33
  tmpIndexByIndexName[`${INDEX_PARAM_PREFIX}${i + 1}`] = i;
34
34
  }
35
35
  Object.freeze(tmpIndexByIndexName);
36
+ /**
37
+ * 再帰ワイルドカード。オーサリング層($recursion 宣言・getter キー・API 引数)にだけ
38
+ * 現れ、PathInfo には決して降ろさない — wildcardCount が不定になると ListIndex 連鎖長・
39
+ * $1..$n・$resolve の厳密一致・走査の段数が同時に壊れる
40
+ * (docs/state-recursive-path-design.md §2-1)。
41
+ */
42
+ const RECURSION_WILDCARD = "**";
43
+
44
+ function raiseError(message) {
45
+ throw new Error(`[@wcstack/state] ${message}`);
46
+ }
36
47
 
37
48
  const _cache = new Map();
38
49
  /**
@@ -51,6 +62,16 @@ function getPathInfo(path) {
51
62
  if (typeof pathInfo !== "undefined") {
52
63
  return pathInfo;
53
64
  }
65
+ // 再帰ワイルドカードはオーサリング層の記号で、ここへ降りてきてはならない
66
+ // (降ろすと wildcardCount が不定になり ListIndex 連鎖長・$1..$n・$resolve の
67
+ // 厳密一致・走査の段数が同時に壊れる。設計書 D2)。到達したということは、
68
+ // `**` を解釈しない消費者に `**` パスが渡ったということ。通常のパスはこの検査を
69
+ // 初回 intern のときにしか払わない(`**` パスは intern されないので読むたびに落ちる)。
70
+ if (path.indexOf(RECURSION_WILDCARD) !== -1) {
71
+ raiseError(`[wcs/recursion-unsupported] "${path}" uses "${RECURSION_WILDCARD}", which is not accepted here. ` +
72
+ `It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path ` +
73
+ `argument of $getAll / $setAll — and only when the state declares a $recursion anchor.`);
74
+ }
54
75
  pathInfo = Object.freeze(new PathInfo(path));
55
76
  _cache.set(path, pathInfo);
56
77
  return pathInfo;
@@ -219,10 +240,6 @@ function didYouMean(input, candidates) {
219
240
  */
220
241
  const LINT_HINT = " Validate statically: npx @wcstack/lint <file>.";
221
242
 
222
- function raiseError(message) {
223
- throw new Error(`[@wcstack/state] ${message}`);
224
- }
225
-
226
243
  const STRUCTURAL_BINDING_TYPE_SET = new Set([
227
244
  "if",
228
245
  "elseif",
@@ -642,7 +642,9 @@
642
642
  "$on",
643
643
  "$streams",
644
644
  "$watch",
645
+ "$scan",
645
646
  "$listKeys",
647
+ "$recursion",
646
648
  "$streamStatus",
647
649
  "$streamError"
648
650
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/state",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Reactive state management with declarative data binding for Web Components. Zero dependencies, buildless.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",