@wcstack/fetch 4.21.0 → 4.23.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
@@ -276,6 +276,9 @@ declare class Fetch extends HTMLElement {
276
276
  private _lastFetchedUrl;
277
277
  private _toldTriggerWithoutUrl;
278
278
  private _toldUndefinedHelper;
279
+ private _sentBody;
280
+ private _toldBodyGone;
281
+ private _auto;
279
282
  private _internals;
280
283
  constructor();
281
284
  get debugStates(): string[];
@@ -358,9 +361,19 @@ declare class Fetch extends HTMLElement {
358
361
  */
359
362
  private _warnUndefinedHelper;
360
363
  private _warnUnsafeAutoFetch;
364
+ /**
365
+ * `body` is a one-shot input: sent with one request, then gone. A request that changes data (POST, PUT,
366
+ * PATCH) going out with no body after one that carried a body is a second send whose body was not written
367
+ * again: a binding does not write a value equal to the one it wrote last, so the same JSON string on a
368
+ * retry never reaches the element, and the server got an empty request without a word
369
+ * (docs/seam-apps.md, ekiden-entry). Said once until a body is sent again. Not for the request a url
370
+ * change starts, which `[wcs/fetch-auto-unsafe]` reports.
371
+ */
372
+ private _warnBodyGone;
361
373
  fetch(): Promise<any>;
362
374
  attributeChangedCallback(name: string, _oldValue: string | null, _newValue: string | null): void;
363
375
  connectedCallback(): void;
376
+ connectedMoveCallback(): void;
364
377
  disconnectedCallback(): void;
365
378
  }
366
379
 
package/dist/index.esm.js CHANGED
@@ -68,7 +68,7 @@ function setConfig(partialConfig) {
68
68
  frozenConfig = null;
69
69
  }
70
70
 
71
- var pkg = {"name":"@wcstack/fetch","version":"4.21.0"};
71
+ var pkg = {"name":"@wcstack/fetch","version":"4.23.0"};
72
72
 
73
73
  // ===========================================================================
74
74
  // AUTO-GENERATED FILE - DO NOT EDIT.
@@ -1169,6 +1169,11 @@ class Fetch extends HTMLElement {
1169
1169
  _lastFetchedUrl = null;
1170
1170
  _toldTriggerWithoutUrl = false;
1171
1171
  _toldUndefinedHelper = false;
1172
+ // 本文を運んだ要求を出したことがある(body の入力か <wcs-fetch-body> から)
1173
+ _sentBody = false;
1174
+ _toldBodyGone = false;
1175
+ // 次に始まる要求は url が始めるもの(auto-fetch)で、コマンドや trigger のものではない
1176
+ _auto = false;
1172
1177
  _internals = null;
1173
1178
  constructor() {
1174
1179
  super();
@@ -1449,6 +1454,7 @@ class Fetch extends HTMLElement {
1449
1454
  // (not the request the element starts as it connects with a url: a POST that is meant)
1450
1455
  if (resolveConnect === null)
1451
1456
  this._warnUnsafeAutoFetch();
1457
+ this._auto = true;
1452
1458
  // fetch() cannot reject here: FetchCore swallows network/HTTP errors and
1453
1459
  // only rejects on an empty url, which the `url` guard above rules out.
1454
1460
  this.fetch().finally(() => resolveConnect?.());
@@ -1505,6 +1511,24 @@ class Fetch extends HTMLElement {
1505
1511
  `${method} with no body (its method stays ${method}; a body is sent once). Give loading and each change ` +
1506
1512
  `its own <wcs-fetch>, or set \`manual\` on the one that changes data.`);
1507
1513
  }
1514
+ /**
1515
+ * `body` is a one-shot input: sent with one request, then gone. A request that changes data (POST, PUT,
1516
+ * PATCH) going out with no body after one that carried a body is a second send whose body was not written
1517
+ * again: a binding does not write a value equal to the one it wrote last, so the same JSON string on a
1518
+ * retry never reaches the element, and the server got an empty request without a word
1519
+ * (docs/seam-apps.md, ekiden-entry). Said once until a body is sent again. Not for the request a url
1520
+ * change starts, which `[wcs/fetch-auto-unsafe]` reports.
1521
+ */
1522
+ _warnBodyGone() {
1523
+ const method = this.method;
1524
+ if (!this._sentBody || this._toldBodyGone || (method !== "POST" && method !== "PUT" && method !== "PATCH"))
1525
+ return;
1526
+ this._toldBodyGone = true;
1527
+ console.warn(`[@wcstack/fetch] [wcs/fetch-body-gone] This <${config.tagNames.fetch}> sent a ${method} with no body: a body is ` +
1528
+ "sent once, and none was written since the last request. A binding does not write a value equal to the one " +
1529
+ "it wrote last, so the same string on a retry never arrives: write a new object each time " +
1530
+ "(this.payload = { ...entry }), or null between two sends. (Said once until a body is sent again.)", this);
1531
+ }
1508
1532
  async fetch() {
1509
1533
  // Record the url for the auto-fetch same-value guard. Every fetch (explicit
1510
1534
  // included) updates it so a later auto-write of the same url is treated as a
@@ -1520,6 +1544,15 @@ class Fetch extends HTMLElement {
1520
1544
  const bodySnapshot = this._body;
1521
1545
  this._body = null;
1522
1546
  const { body, contentType } = this._collectBody(bodySnapshot);
1547
+ const auto = this._auto;
1548
+ this._auto = false;
1549
+ if (body !== null) {
1550
+ this._sentBody = true;
1551
+ this._toldBodyGone = false;
1552
+ }
1553
+ else if (!auto) {
1554
+ this._warnBodyGone();
1555
+ }
1523
1556
  // FormData に手動で Content-Type を付けると、ブラウザが付与するはずの multipart
1524
1557
  // boundary が失われてサーバー側でパースできなくなる。ヘッダはユーザー指定を
1525
1558
  // 尊重して素通しするが、この典型的な誤設定は警告する。
@@ -1588,6 +1621,10 @@ class Fetch extends HTMLElement {
1588
1621
  }
1589
1622
  this._scheduleAutoFetch();
1590
1623
  }
1624
+ // moveBefore() で動かされたとき(並べ替えで動くリストの行): この要素のすることは置かれた場所に
1625
+ // よらないので、何も止めず、何も始め直さない。connectedMoveCallback が無いと、ブラウザは代わりに
1626
+ // disconnectedCallback と connectedCallback を呼ぶ(docs/timing-and-firing-contract.md §25)
1627
+ connectedMoveCallback() { }
1591
1628
  disconnectedCallback() {
1592
1629
  this.abort();
1593
1630
  // Reset the same-value guard so a remount (reconnect with the same url)