@wcstack/fetch 4.25.0 → 4.27.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
@@ -288,6 +288,7 @@ declare class Fetch extends HTMLElement {
288
288
  private _lastFetchedUrl;
289
289
  private _toldTriggerWithoutUrl;
290
290
  private _toldUndefinedHelper;
291
+ private _toldUrlArgument;
291
292
  private _sentBody;
292
293
  private _toldBodyGone;
293
294
  private _auto;
@@ -382,6 +383,14 @@ declare class Fetch extends HTMLElement {
382
383
  * change starts, which `[wcs/fetch-auto-unsafe]` reports.
383
384
  */
384
385
  private _warnBodyGone;
386
+ /**
387
+ * A value in `fetch()`'s `url` place that is neither a url nor one of the values it ignores on purpose (none, an
388
+ * empty string, the event an `on…: $command.x` binding emits first): a number, a plain object. The element fetched
389
+ * its own url instead — with no url, nothing — and said nothing: a page emitted the id of the row to cancel
390
+ * (`this.$command.cancelReq.emit(id)`) where the command takes a url (docs/seam-apps.md, lending-desk). Said once
391
+ * per element for each kind of value.
392
+ */
393
+ private _warnUrlArgument;
385
394
  /**
386
395
  * Runs a request. With no argument it is the element's: its `url`, `method`, headers and `body`.
387
396
  *
@@ -390,8 +399,9 @@ declare class Fetch extends HTMLElement {
390
399
  * a command runs before the bindings of its update, so a `url` written in the same handler has not reached the
391
400
  * element yet, and the request went to the one before (docs/seam-apps.md, town-archive). `init` takes `method`,
392
401
  * `headers` (added to the `<wcs-fetch-header>` ones, replacing a same name) and `body` (in place of the
393
- * element's, which is then kept for the next request). Anything that is not a string in `url`'s place — the
394
- * event an `on…: $command.x` binding emits first — is ignored, and `init` with it.
402
+ * element's, which is then kept for the next request). `url` is a non-empty string or a `URL`. Anything else in
403
+ * its place is not this request's url, and `init` is ignored with it: the event an `on…: $command.x` binding
404
+ * emits first (and none, an empty string) silently, any other value with `[wcs/fetch-url-argument]`.
395
405
  */
396
406
  fetch(url?: unknown, init?: unknown): Promise<any>;
397
407
  attributeChangedCallback(name: string, _oldValue: string | null, _newValue: string | null): void;
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.25.0"};
71
+ var pkg = {"name":"@wcstack/fetch","version":"4.27.0"};
72
72
 
73
73
  // ===========================================================================
74
74
  // AUTO-GENERATED FILE - DO NOT EDIT.
@@ -751,8 +751,10 @@ class FetchCore extends EventTarget {
751
751
  // CommitGuard's epoch/CAS check and writes nothing, even if the body still
752
752
  // resolved. HEAD carries no body by spec.
753
753
  let value = null;
754
- if (method === "HEAD") {
755
- // HEAD responses carry no body — reading it would throw a parse error.
754
+ if (method === "HEAD" || response.status === 204 || response.status === 205) {
755
+ // HEAD responses, 204 No Content and 205 Reset Content carry no body: reading one as JSON would throw,
756
+ // and a success was reported as a network failure (status 0) — a server that labels its empty 204
757
+ // `Content-Type: application/json`, under the default "auto" (docs/seam-apps.md, stamp-rally).
756
758
  }
757
759
  else if (!response.ok) {
758
760
  // HTTP error: read the body text for the error envelope. Handled below.
@@ -1169,6 +1171,8 @@ class Fetch extends HTMLElement {
1169
1171
  _lastFetchedUrl = null;
1170
1172
  _toldTriggerWithoutUrl = false;
1171
1173
  _toldUndefinedHelper = false;
1174
+ // fetch() の url の位置に来た値のうち、言った種類("number"・"object" など。要素ごと・種類ごとに 1 回)
1175
+ _toldUrlArgument = null;
1172
1176
  // 本文を運んだ要求を出したことがある(body の入力か <wcs-fetch-body> から)
1173
1177
  _sentBody = false;
1174
1178
  _toldBodyGone = false;
@@ -1529,6 +1533,37 @@ class Fetch extends HTMLElement {
1529
1533
  "it wrote last, so the same string on a retry never arrives: write a new object each time " +
1530
1534
  "(this.payload = { ...entry }), or null between two sends. (Said once until a body is sent again.)", this);
1531
1535
  }
1536
+ /**
1537
+ * A value in `fetch()`'s `url` place that is neither a url nor one of the values it ignores on purpose (none, an
1538
+ * empty string, the event an `on…: $command.x` binding emits first): a number, a plain object. The element fetched
1539
+ * its own url instead — with no url, nothing — and said nothing: a page emitted the id of the row to cancel
1540
+ * (`this.$command.cancelReq.emit(id)`) where the command takes a url (docs/seam-apps.md, lending-desk). Said once
1541
+ * per element for each kind of value.
1542
+ */
1543
+ _warnUrlArgument(url) {
1544
+ if (url === undefined || url === null || url === "" || url instanceof Event)
1545
+ return;
1546
+ const kind = Array.isArray(url) ? "array" : typeof url;
1547
+ const told = (this._toldUrlArgument ??= new Set());
1548
+ if (told.has(kind))
1549
+ return;
1550
+ told.add(kind);
1551
+ let given;
1552
+ if (kind === "object") {
1553
+ const tag = Object.prototype.toString.call(url).slice(8, -1);
1554
+ given = tag === "Object" ? "an object" : `a ${tag} object`;
1555
+ }
1556
+ else if (kind === "array")
1557
+ given = "an array";
1558
+ else if (kind === "symbol" || kind === "function")
1559
+ given = `a ${kind}`;
1560
+ else
1561
+ given = `${String(url)} (a ${kind})`;
1562
+ console.warn(`[@wcstack/fetch] [wcs/fetch-url-argument] fetch() was given ${given} in the url's place, which takes a url ` +
1563
+ `(a string or a URL), so this <${config.tagNames.fetch}> fetched its own url instead${this.url ? "" : " — it has none, so nothing"}. ` +
1564
+ "A command token passes what emit() was given: emit the url (this.$command.load.emit(\"/api/items/\" + id)), " +
1565
+ "or nothing for the element's own request. (Said once per element for each kind of value.)", this);
1566
+ }
1532
1567
  /**
1533
1568
  * Runs a request. With no argument it is the element's: its `url`, `method`, headers and `body`.
1534
1569
  *
@@ -1537,12 +1572,15 @@ class Fetch extends HTMLElement {
1537
1572
  * a command runs before the bindings of its update, so a `url` written in the same handler has not reached the
1538
1573
  * element yet, and the request went to the one before (docs/seam-apps.md, town-archive). `init` takes `method`,
1539
1574
  * `headers` (added to the `<wcs-fetch-header>` ones, replacing a same name) and `body` (in place of the
1540
- * element's, which is then kept for the next request). Anything that is not a string in `url`'s place — the
1541
- * event an `on…: $command.x` binding emits first — is ignored, and `init` with it.
1575
+ * element's, which is then kept for the next request). `url` is a non-empty string or a `URL`. Anything else in
1576
+ * its place is not this request's url, and `init` is ignored with it: the event an `on…: $command.x` binding
1577
+ * emits first (and none, an empty string) silently, any other value with `[wcs/fetch-url-argument]`.
1542
1578
  */
1543
1579
  async fetch(url, init) {
1544
- const given = typeof url === "string" && url !== "";
1545
- const requestUrl = given ? url : this.url;
1580
+ const given = typeof url === "string" ? url !== "" : url instanceof URL;
1581
+ if (!given)
1582
+ this._warnUrlArgument(url);
1583
+ const requestUrl = given ? String(url) : this.url;
1546
1584
  const options = (given && init !== null && typeof init === "object" ? init : {});
1547
1585
  // Record the url for the auto-fetch same-value guard. Every fetch (explicit
1548
1586
  // included) updates it so a later auto-write of the same url is treated as a