@wcstack/fetch 1.23.0 → 1.24.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.
package/dist/index.d.ts CHANGED
@@ -51,10 +51,27 @@ interface PlatformAssessment {
51
51
  readonly lastError?: WcsIoErrorInfo;
52
52
  }
53
53
 
54
+ /**
55
+ * Observation semantics of a `properties` entry.
56
+ *
57
+ * "state" — current value. A snapshot may cache it, and equality-based dedupe is safe.
58
+ * "event" — occurrence. Repeated identical payloads are distinct occurrences; never dedupe.
59
+ * "handle" — live / opaque resource with its own lifecycle (e.g. MediaStream). Not
60
+ * snapshot-safe and not necessarily serializable; consumers need an explicit
61
+ * ref / callback surface rather than a value slot.
62
+ */
63
+ type WcBindableSemantics = "state" | "event" | "handle";
54
64
  interface IWcBindableProperty {
55
65
  readonly name: string;
56
66
  readonly event: string;
57
67
  readonly getter?: (event: Event) => any;
68
+ /**
69
+ * Optional, additive, forward-compatible. An absent value means **unspecified**, NOT
70
+ * "state": a reader that finds no `semantics` MUST keep the behavior it had before this
71
+ * field existed (deliver the update as-is; do not start deduping, caching or serializing
72
+ * on assumption). Only an explicit value licenses a reader to change its handling.
73
+ */
74
+ readonly semantics?: WcBindableSemantics;
58
75
  }
59
76
  interface IWcBindableInput {
60
77
  readonly name: string;
package/dist/index.esm.js CHANGED
@@ -434,19 +434,19 @@ class FetchCore extends EventTarget {
434
434
  protocol: "wc-bindable",
435
435
  version: 1,
436
436
  properties: [
437
- { name: "value", event: "wcs-fetch:response", getter: (e) => e.detail.value },
438
- { name: "loading", event: "wcs-fetch:loading-changed" },
439
- { name: "error", event: "wcs-fetch:error" },
440
- { name: "status", event: "wcs-fetch:response", getter: (e) => e.detail.status },
437
+ { name: "value", event: "wcs-fetch:response", semantics: "state", getter: (e) => e.detail.value },
438
+ { name: "loading", event: "wcs-fetch:loading-changed", semantics: "state" },
439
+ { name: "error", event: "wcs-fetch:error", semantics: "state" },
440
+ { name: "status", event: "wcs-fetch:response", semantics: "state", getter: (e) => e.detail.status },
441
441
  // Managed object URL for a `responseType: "blob"` response (null otherwise).
442
442
  // The Core revokes the previous URL on each new response and on dispose, so
443
443
  // a consumer can bind it straight into <img src> without lifecycle glue.
444
- { name: "objectURL", event: "wcs-fetch:response", getter: (e) => e.detail.objectURL },
444
+ { name: "objectURL", event: "wcs-fetch:response", semantics: "state", getter: (e) => e.detail.objectURL },
445
445
  // Serializable failure taxonomy (stable code / phase / recoverable), or null.
446
446
  // Additive bindable output — the existing `error` property/event are unchanged.
447
447
  // Fires on its own `wcs-fetch:error-info-changed` event; no getter, so the
448
448
  // bound value is the event detail (mirrors `error` / `loading`).
449
- { name: "errorInfo", event: "wcs-fetch:error-info-changed" },
449
+ { name: "errorInfo", event: "wcs-fetch:error-info-changed", semantics: "state" },
450
450
  ],
451
451
  inputs: [
452
452
  { name: "url" },
@@ -878,13 +878,55 @@ function registerAutoTrigger() {
878
878
  document.addEventListener("click", handleClick);
879
879
  }
880
880
 
881
+ // ===========================================================================
882
+ // AUTO-GENERATED FILE - DO NOT EDIT.
883
+ // Generated from /protocol/upgrade-properties.ts by scripts/sync-protocol-types.mjs.
884
+ // Run `node scripts/sync-protocol-types.mjs` after editing the source.
885
+ // ===========================================================================
886
+ function hasAccessorOnPrototype(target, name) {
887
+ let proto = Object.getPrototypeOf(target);
888
+ while (proto !== null) {
889
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
890
+ if (descriptor !== undefined) {
891
+ return typeof descriptor.get === "function" || typeof descriptor.set === "function";
892
+ }
893
+ proto = Object.getPrototypeOf(proto);
894
+ }
895
+ return false;
896
+ }
897
+ /**
898
+ * `connectedCallback` の先頭で呼ぶ。宣言済み input のうち upgrade 前の代入で
899
+ * accessor をシャドウしている own プロパティを、delete → 再代入で setter に通し直す。
900
+ *
901
+ * - 冪等: 再代入は accessor を通るので own プロパティは残らず、2 回目以降は no-op。
902
+ * - 宣言に `inputs` が無い要素、`wcBindable` を持たない要素では何もしない。
903
+ * - 値の意味は変えない。今まで捨てられていた代入が届くようになる一方向の変化。
904
+ */
905
+ function upgradeProperties(element) {
906
+ const declaration = element.constructor?.wcBindable;
907
+ const inputs = declaration?.inputs;
908
+ if (inputs === undefined)
909
+ return;
910
+ for (const input of inputs) {
911
+ const name = input.name;
912
+ if (!Object.prototype.hasOwnProperty.call(element, name))
913
+ continue;
914
+ if (!hasAccessorOnPrototype(element, name))
915
+ continue;
916
+ const record = element;
917
+ const value = record[name];
918
+ delete record[name];
919
+ record[name] = value;
920
+ }
921
+ }
922
+
881
923
  class Fetch extends HTMLElement {
882
924
  static hasConnectedCallbackPromise = true;
883
925
  static wcBindable = {
884
926
  ...FetchCore.wcBindable,
885
927
  properties: [
886
928
  ...FetchCore.wcBindable.properties,
887
- { name: "trigger", event: "wcs-fetch:trigger-changed" },
929
+ { name: "trigger", event: "wcs-fetch:trigger-changed", semantics: "state" },
888
930
  ],
889
931
  // Shell-level input surface. The Core declares only the portable `url` / `method`;
890
932
  // the Shell adds the DOM-driven settable surface. No `attribute` hints are given:
@@ -1250,6 +1292,8 @@ class Fetch extends HTMLElement {
1250
1292
  }
1251
1293
  }
1252
1294
  connectedCallback() {
1295
+ // upgrade 前に代入された input を取り込み直す(doc 13 §1.2 / Phase A1)
1296
+ upgradeProperties(this);
1253
1297
  this.style.display = "none";
1254
1298
  if (config.autoTrigger) {
1255
1299
  registerAutoTrigger();