@wcstack/fetch 4.4.0 → 4.6.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/README.ja.md +7 -3
- package/README.md +7 -3
- package/dist/auto.d.ts +2 -0
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +35 -19
- package/dist/index.esm.js +62 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -274,6 +274,8 @@ declare class Fetch extends HTMLElement {
|
|
|
274
274
|
private _autoPending;
|
|
275
275
|
private _connectResolve;
|
|
276
276
|
private _lastFetchedUrl;
|
|
277
|
+
private _toldTriggerWithoutUrl;
|
|
278
|
+
private _toldUndefinedHelper;
|
|
277
279
|
private _internals;
|
|
278
280
|
constructor();
|
|
279
281
|
get debugStates(): string[];
|
|
@@ -339,6 +341,20 @@ declare class Fetch extends HTMLElement {
|
|
|
339
341
|
* sent an empty POST on every navigation after the first post, without a word
|
|
340
342
|
* (docs/seam-apps.md, ssr-news; docs/mistake-catalogue.md).
|
|
341
343
|
*/
|
|
344
|
+
/**
|
|
345
|
+
* A `trigger` written while `url` is empty does nothing (timing-and-firing-contract §1.5),
|
|
346
|
+
* and said nothing: a `trigger` before `url` in one `data-wcs` (bindings apply in the
|
|
347
|
+
* order written), a url that state has not computed yet. Said once per element
|
|
348
|
+
* (docs/v4-direction-2026-10.md §5.1, the I/O command policy).
|
|
349
|
+
*/
|
|
350
|
+
private _warnTriggerWithoutUrl;
|
|
351
|
+
/**
|
|
352
|
+
* A `<wcs-fetch-header>` / `<wcs-fetch-body>` whose definition never loaded is a plain element, and its
|
|
353
|
+
* header or body was left out of the request without a word: a page that defines the tags itself (an
|
|
354
|
+
* autoloader's wrapper module, a scoped registry) defined `<wcs-fetch>` only (docs/seam-apps.md,
|
|
355
|
+
* fw-inventory). Said once per element.
|
|
356
|
+
*/
|
|
357
|
+
private _warnUndefinedHelper;
|
|
342
358
|
private _warnUnsafeAutoFetch;
|
|
343
359
|
fetch(): Promise<any>;
|
|
344
360
|
attributeChangedCallback(name: string, _oldValue: string | null, _newValue: string | null): void;
|
|
@@ -372,24 +388,6 @@ declare class InfiniteScroll extends HTMLElement {
|
|
|
372
388
|
private _triggerFetch;
|
|
373
389
|
}
|
|
374
390
|
|
|
375
|
-
/**
|
|
376
|
-
* fetchCapabilities.ts
|
|
377
|
-
*
|
|
378
|
-
* fetch node 固有の capability registry と error code。汎用の assess 機構・型は
|
|
379
|
-
* `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から
|
|
380
|
-
* import する。node 固有の宣言はこのハンドライトファイルに置き、生成コピーとは分離する。
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
/** 安定した fetch error code(taxonomy)。値は公開キーとして固定。 */
|
|
384
|
-
declare const WCS_FETCH_ERROR_CODE: {
|
|
385
|
-
readonly CapabilityMissing: "capability-missing";
|
|
386
|
-
readonly InvalidArgument: "invalid-argument";
|
|
387
|
-
readonly Network: "network";
|
|
388
|
-
readonly HttpError: "http-error";
|
|
389
|
-
readonly Timeout: "timeout";
|
|
390
|
-
readonly Aborted: "aborted";
|
|
391
|
-
};
|
|
392
|
-
|
|
393
391
|
/**
|
|
394
392
|
* `<wcs-fetch-header name value>`: one request header of the `<wcs-fetch>` it sits in, read when a
|
|
395
393
|
* request starts. `name` / `value` are properties too, reflected to the attributes (`null` removes
|
|
@@ -418,6 +416,24 @@ declare class FetchBody extends HTMLElement {
|
|
|
418
416
|
get bodyContent(): string;
|
|
419
417
|
}
|
|
420
418
|
|
|
419
|
+
/**
|
|
420
|
+
* fetchCapabilities.ts
|
|
421
|
+
*
|
|
422
|
+
* fetch node 固有の capability registry と error code。汎用の assess 機構・型は
|
|
423
|
+
* `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から
|
|
424
|
+
* import する。node 固有の宣言はこのハンドライトファイルに置き、生成コピーとは分離する。
|
|
425
|
+
*/
|
|
426
|
+
|
|
427
|
+
/** 安定した fetch error code(taxonomy)。値は公開キーとして固定。 */
|
|
428
|
+
declare const WCS_FETCH_ERROR_CODE: {
|
|
429
|
+
readonly CapabilityMissing: "capability-missing";
|
|
430
|
+
readonly InvalidArgument: "invalid-argument";
|
|
431
|
+
readonly Network: "network";
|
|
432
|
+
readonly HttpError: "http-error";
|
|
433
|
+
readonly Timeout: "timeout";
|
|
434
|
+
readonly Aborted: "aborted";
|
|
435
|
+
};
|
|
436
|
+
|
|
421
437
|
declare global {
|
|
422
438
|
interface HTMLElementTagNameMap {
|
|
423
439
|
"wcs-fetch": Fetch;
|
|
@@ -427,5 +443,5 @@ declare global {
|
|
|
427
443
|
}
|
|
428
444
|
}
|
|
429
445
|
|
|
430
|
-
export { FetchCore, TRUSTED_TYPES_POLICY_SLOT, WCS_FETCH_ERROR_CODE, Fetch as WcsFetch, InfiniteScroll as WcsInfiniteScroll, bootstrapFetch, getConfig, getTrustedTypesPolicy, setTrustedTypesPolicy };
|
|
446
|
+
export { FetchCore, TRUSTED_TYPES_POLICY_SLOT, WCS_FETCH_ERROR_CODE, Fetch as WcsFetch, FetchBody as WcsFetchBody, FetchHeader as WcsFetchHeader, InfiniteScroll as WcsInfiniteScroll, bootstrapFetch, getConfig, getTrustedTypesPolicy, setTrustedTypesPolicy };
|
|
431
447
|
export type { FetchRequestOptions, IWcsTrustedTypesPolicy, IWritableConfig, IWritableTagNames, WcsFetchCoreValues, WcsFetchHttpError, WcsFetchValues, WcsIoErrorInfo, WcsIoErrorPhase };
|
package/dist/index.esm.js
CHANGED
|
@@ -935,6 +935,21 @@ function hasAccessorOnPrototype(target, name) {
|
|
|
935
935
|
}
|
|
936
936
|
return false;
|
|
937
937
|
}
|
|
938
|
+
// 属性になってしまったオブジェクトの入力(`files="[object File]"`)を、要素ごとに 1 回だけ言う。
|
|
939
|
+
// React 19 は定義前の要素にプロパティが無いのでオブジェクトを属性に書き、Vue の `.attr` も
|
|
940
|
+
// 書く。要素はその入力をプロパティでしか読まないので、何も受け取らず、何も言わなかった
|
|
941
|
+
// (docs/seam-apps.md、fw-inventory)。
|
|
942
|
+
const toldObjectAttribute = new WeakSet();
|
|
943
|
+
function warnObjectAttribute(element, name, value) {
|
|
944
|
+
if (toldObjectAttribute.has(element))
|
|
945
|
+
return;
|
|
946
|
+
toldObjectAttribute.add(element);
|
|
947
|
+
const tag = element.localName ?? "element";
|
|
948
|
+
console.warn(`[wcs/input-as-attribute] <${tag}> has the attribute ${name}="${value}": an object was written as an ` +
|
|
949
|
+
`attribute, so the element did not receive it. A framework does that when the property is set before the ` +
|
|
950
|
+
`element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, ` +
|
|
951
|
+
`or assign the property through a ref (Vue: .prop). (Said once per element.)`, element);
|
|
952
|
+
}
|
|
938
953
|
/**
|
|
939
954
|
* `connectedCallback` の先頭で呼ぶ。宣言済み input のうち upgrade 前の代入で
|
|
940
955
|
* accessor をシャドウしている own プロパティを、delete → 再代入で setter に通し直す。
|
|
@@ -942,14 +957,19 @@ function hasAccessorOnPrototype(target, name) {
|
|
|
942
957
|
* - 冪等: 再代入は accessor を通るので own プロパティは残らず、2 回目以降は no-op。
|
|
943
958
|
* - 宣言に `inputs` が無い要素、`wcBindable` を持たない要素では何もしない。
|
|
944
959
|
* - 値の意味は変えない。今まで捨てられていた代入が届くようになる一方向の変化。
|
|
960
|
+
* - 値が `[object …]` の属性(属性に書かれてしまったオブジェクトの入力)は、要素ごとに 1 回警告する。
|
|
945
961
|
*/
|
|
946
962
|
function upgradeProperties(element) {
|
|
947
963
|
const declaration = element.constructor?.wcBindable;
|
|
948
964
|
const inputs = declaration?.inputs;
|
|
949
965
|
if (inputs === undefined)
|
|
950
966
|
return;
|
|
967
|
+
const getAttribute = element.getAttribute;
|
|
951
968
|
for (const input of inputs) {
|
|
952
969
|
const name = input.name;
|
|
970
|
+
const attribute = typeof getAttribute === "function" ? getAttribute.call(element, name.toLowerCase()) : null;
|
|
971
|
+
if (attribute !== null && attribute.startsWith("[object "))
|
|
972
|
+
warnObjectAttribute(element, name, attribute);
|
|
953
973
|
if (!Object.prototype.hasOwnProperty.call(element, name))
|
|
954
974
|
continue;
|
|
955
975
|
if (!hasAccessorOnPrototype(element, name))
|
|
@@ -1158,6 +1178,8 @@ class Fetch extends HTMLElement {
|
|
|
1158
1178
|
_autoPending = false;
|
|
1159
1179
|
_connectResolve = null;
|
|
1160
1180
|
_lastFetchedUrl = null;
|
|
1181
|
+
_toldTriggerWithoutUrl = false;
|
|
1182
|
+
_toldUndefinedHelper = false;
|
|
1161
1183
|
_internals = null;
|
|
1162
1184
|
constructor() {
|
|
1163
1185
|
super();
|
|
@@ -1320,8 +1342,10 @@ class Fetch extends HTMLElement {
|
|
|
1320
1342
|
// surfacing a `wcs-fetch:trigger-changed` "completion" would lie to observers.
|
|
1321
1343
|
// Keeping the flag false also avoids stalling — once url is provided, writing
|
|
1322
1344
|
// `true` again is a real false→true transition that triggers the fetch.
|
|
1323
|
-
if (!this.url)
|
|
1345
|
+
if (!this.url) {
|
|
1346
|
+
this._warnTriggerWithoutUrl();
|
|
1324
1347
|
return;
|
|
1348
|
+
}
|
|
1325
1349
|
this._trigger = true;
|
|
1326
1350
|
this.fetch().finally(() => {
|
|
1327
1351
|
this._trigger = false;
|
|
@@ -1336,6 +1360,10 @@ class Fetch extends HTMLElement {
|
|
|
1336
1360
|
const headers = {};
|
|
1337
1361
|
const headerElements = this.querySelectorAll(config.tagNames.fetchHeader);
|
|
1338
1362
|
for (const el of headerElements) {
|
|
1363
|
+
if (typeof el.hasHeader !== "boolean") {
|
|
1364
|
+
this._warnUndefinedHelper(config.tagNames.fetchHeader, "header");
|
|
1365
|
+
continue;
|
|
1366
|
+
}
|
|
1339
1367
|
// a header without a value attribute is not sent (FetchHeader)
|
|
1340
1368
|
if (el.hasHeader) {
|
|
1341
1369
|
headers[el.headerName] = el.headerValue;
|
|
@@ -1372,7 +1400,10 @@ class Fetch extends HTMLElement {
|
|
|
1372
1400
|
}
|
|
1373
1401
|
// サブタグからbodyを取得
|
|
1374
1402
|
const bodyElement = this.querySelector(config.tagNames.fetchBody);
|
|
1375
|
-
if (bodyElement) {
|
|
1403
|
+
if (bodyElement && typeof bodyElement.bodyContent !== "string") {
|
|
1404
|
+
this._warnUndefinedHelper(config.tagNames.fetchBody, "body");
|
|
1405
|
+
}
|
|
1406
|
+
else if (bodyElement) {
|
|
1376
1407
|
return {
|
|
1377
1408
|
body: bodyElement.bodyContent || null,
|
|
1378
1409
|
contentType: bodyElement.contentType,
|
|
@@ -1445,6 +1476,34 @@ class Fetch extends HTMLElement {
|
|
|
1445
1476
|
* sent an empty POST on every navigation after the first post, without a word
|
|
1446
1477
|
* (docs/seam-apps.md, ssr-news; docs/mistake-catalogue.md).
|
|
1447
1478
|
*/
|
|
1479
|
+
/**
|
|
1480
|
+
* A `trigger` written while `url` is empty does nothing (timing-and-firing-contract §1.5),
|
|
1481
|
+
* and said nothing: a `trigger` before `url` in one `data-wcs` (bindings apply in the
|
|
1482
|
+
* order written), a url that state has not computed yet. Said once per element
|
|
1483
|
+
* (docs/v4-direction-2026-10.md §5.1, the I/O command policy).
|
|
1484
|
+
*/
|
|
1485
|
+
_warnTriggerWithoutUrl() {
|
|
1486
|
+
if (this._toldTriggerWithoutUrl)
|
|
1487
|
+
return;
|
|
1488
|
+
this._toldTriggerWithoutUrl = true;
|
|
1489
|
+
console.warn("[@wcstack/fetch] [wcs/command-not-ready] trigger was refused: there is no url, so nothing is fetched. " +
|
|
1490
|
+
"Write url before trigger (bindings apply in the order written), and write trigger again once there is one. " +
|
|
1491
|
+
"(Said once per element.)", this);
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* A `<wcs-fetch-header>` / `<wcs-fetch-body>` whose definition never loaded is a plain element, and its
|
|
1495
|
+
* header or body was left out of the request without a word: a page that defines the tags itself (an
|
|
1496
|
+
* autoloader's wrapper module, a scoped registry) defined `<wcs-fetch>` only (docs/seam-apps.md,
|
|
1497
|
+
* fw-inventory). Said once per element.
|
|
1498
|
+
*/
|
|
1499
|
+
_warnUndefinedHelper(tag, what) {
|
|
1500
|
+
if (this._toldUndefinedHelper)
|
|
1501
|
+
return;
|
|
1502
|
+
this._toldUndefinedHelper = true;
|
|
1503
|
+
console.warn(`[@wcstack/fetch] [wcs/fetch-helper-undefined] <${tag}> inside this <${config.tagNames.fetch}> is not ` +
|
|
1504
|
+
`defined, so its ${what} is not sent. Load @wcstack/fetch/auto, or define WcsFetchHeader and WcsFetchBody ` +
|
|
1505
|
+
"with WcsFetch when the page defines the tags itself. (Said once per element.)", this);
|
|
1506
|
+
}
|
|
1448
1507
|
_warnUnsafeAutoFetch() {
|
|
1449
1508
|
const method = this.method;
|
|
1450
1509
|
if (method === "GET" || method === "HEAD" || method === "OPTIONS")
|
|
@@ -1760,5 +1819,5 @@ function bootstrapFetch(userConfig, registry) {
|
|
|
1760
1819
|
registerComponents(registry);
|
|
1761
1820
|
}
|
|
1762
1821
|
|
|
1763
|
-
export { FetchCore, TRUSTED_TYPES_POLICY_SLOT, WCS_FETCH_ERROR_CODE, Fetch as WcsFetch, InfiniteScroll as WcsInfiniteScroll, bootstrapFetch, getConfig, getTrustedTypesPolicy, setTrustedTypesPolicy };
|
|
1822
|
+
export { FetchCore, TRUSTED_TYPES_POLICY_SLOT, WCS_FETCH_ERROR_CODE, Fetch as WcsFetch, FetchBody as WcsFetchBody, FetchHeader as WcsFetchHeader, InfiniteScroll as WcsInfiniteScroll, bootstrapFetch, getConfig, getTrustedTypesPolicy, setTrustedTypesPolicy };
|
|
1764
1823
|
//# sourceMappingURL=index.esm.js.map
|