@fedify/vocab-runtime 2.5.0-dev.2448 → 2.5.0-dev.2494
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/deno.json +5 -2
- package/dist/{docloader-BBnBpbsG.d.cts → docloader-DD6binpN.d.cts} +4 -8
- package/dist/{docloader-BBnBpbsG.d.ts → docloader-DD6binpN.d.ts} +4 -8
- package/dist/internal/jsonld-cache.cjs +1 -1
- package/dist/internal/jsonld-cache.d.cts +1 -1
- package/dist/internal/jsonld-cache.d.ts +1 -1
- package/dist/internal/jsonld-cache.js +1 -1
- package/dist/internal/portable-dereference.cjs +1 -1
- package/dist/internal/portable-dereference.d.cts +2 -2
- package/dist/internal/portable-dereference.d.ts +2 -2
- package/dist/internal/portable-dereference.js +1 -1
- package/dist/internal.cjs +6 -0
- package/dist/internal.d.cts +108 -0
- package/dist/internal.d.ts +108 -0
- package/dist/internal.js +3 -0
- package/dist/mod.cjs +104 -38
- package/dist/mod.d.cts +3 -336
- package/dist/mod.d.ts +4 -336
- package/dist/mod.js +104 -38
- package/dist/{portable-BDydjp5H.d.ts → portable-1VSnSJFj.d.ts} +1 -1
- package/dist/{portable-Dfvcg_Wy.d.cts → portable-Cr7NwZwb.d.cts} +1 -1
- package/dist/public-fetch-Dvfvawei.cjs +527 -0
- package/dist/public-fetch-ziZ39L5I.js +510 -0
- package/dist/tests/{body-DP2u2wUX.cjs → body-0Or8U7lA.cjs} +1 -1
- package/dist/tests/{body-oV99TVdA.mjs → body-DfH6VTh9.mjs} +1 -1
- package/dist/tests/body.test.cjs +1 -1
- package/dist/tests/body.test.mjs +1 -1
- package/dist/tests/decimal.test.cjs +4 -4
- package/dist/tests/decimal.test.mjs +4 -4
- package/dist/tests/{docloader-D3mA7aPJ.mjs → docloader-BZvFOza_.mjs} +106 -40
- package/dist/tests/{docloader-CwxZguqN.cjs → docloader-W_RHEh5W.cjs} +111 -39
- package/dist/tests/docloader.test.cjs +531 -1293
- package/dist/tests/docloader.test.mjs +472 -1252
- package/dist/tests/esm-Ds-eHTfY.mjs +1229 -0
- package/dist/tests/esm-Q2tdh5f3.cjs +1215 -0
- package/dist/tests/internal/portable-dereference.test.cjs +3 -3
- package/dist/tests/internal/portable-dereference.test.mjs +3 -3
- package/dist/tests/{jsonld-cache-BEXiiM-V.cjs → jsonld-cache-DKIWKxEX.cjs} +1 -1
- package/dist/tests/{jsonld-cache-DFnWsLuZ.mjs → jsonld-cache-KH40z9_7.mjs} +1 -1
- package/dist/tests/jsonld-cache.test.cjs +2 -2
- package/dist/tests/jsonld-cache.test.mjs +2 -2
- package/dist/tests/node-CbBR-th-.mjs +84 -0
- package/dist/tests/node-Ch29PDXR.cjs +89 -0
- package/dist/tests/pin-grant-CPrpk1l4.cjs +70 -0
- package/dist/tests/pin-grant-H5XhM1Xs.mjs +53 -0
- package/dist/tests/pin-grant.test.cjs +87 -0
- package/dist/tests/pin-grant.test.d.cts +1 -0
- package/dist/tests/pin-grant.test.d.mts +1 -0
- package/dist/tests/pin-grant.test.mjs +88 -0
- package/dist/tests/pinners/bun.test.cjs +166 -0
- package/dist/tests/pinners/bun.test.d.cts +1 -0
- package/dist/tests/pinners/bun.test.d.mts +1 -0
- package/dist/tests/pinners/bun.test.mjs +167 -0
- package/dist/tests/pinners/node.test.cjs +269 -0
- package/dist/tests/pinners/node.test.d.cts +1 -0
- package/dist/tests/pinners/node.test.d.mts +1 -0
- package/dist/tests/pinners/node.test.mjs +268 -0
- package/dist/tests/pinners/pinners.test.cjs +196 -0
- package/dist/tests/pinners/pinners.test.d.cts +1 -0
- package/dist/tests/pinners/pinners.test.d.mts +1 -0
- package/dist/tests/pinners/pinners.test.mjs +197 -0
- package/dist/tests/pinners/testdata/node-child.cjs +135 -0
- package/dist/tests/pinners/testdata/node-child.d.cts +1 -0
- package/dist/tests/pinners/testdata/node-child.d.mts +1 -0
- package/dist/tests/pinners/testdata/node-child.mjs +134 -0
- package/dist/tests/pinners-DLH_npLf.cjs +220 -0
- package/dist/tests/pinners-tGcl49uF.mjs +203 -0
- package/dist/tests/{portable-dereference-DaTBBvCj.cjs → portable-dereference-BUoDzMxk.cjs} +2 -2
- package/dist/tests/{portable-dereference-sGRs_qdT.mjs → portable-dereference-Du2k3ngE.mjs} +2 -2
- package/dist/tests/{portable-media-B-oCeotd.mjs → portable-media-CqCq3wqj.mjs} +3 -3
- package/dist/tests/{portable-media-D7ClSjFO.cjs → portable-media-Ls_EOkMN.cjs} +3 -3
- package/dist/tests/portable-media.test.cjs +1 -1
- package/dist/tests/portable-media.test.mjs +1 -1
- package/dist/tests/portable-workers.test.cjs +2 -2
- package/dist/tests/portable-workers.test.mjs +2 -2
- package/dist/tests/public-fetch-BGj5pzUD.cjs +186 -0
- package/dist/tests/public-fetch-Cxo3Yzdf.mjs +170 -0
- package/dist/tests/public-fetch.test.cjs +1073 -0
- package/dist/tests/public-fetch.test.d.cts +1 -0
- package/dist/tests/public-fetch.test.d.mts +1 -0
- package/dist/tests/public-fetch.test.mjs +1074 -0
- package/dist/tests/{request-BlLYI4x3.mjs → request-Bo8cJJhV.mjs} +2 -2
- package/dist/tests/{request-B77_oZnk.cjs → request-Cb6h3X72.cjs} +2 -2
- package/dist/tests/request.test.cjs +2 -2
- package/dist/tests/request.test.mjs +2 -2
- package/dist/tests/support-Bj44xlQu.mjs +272 -0
- package/dist/tests/support-BrdlbLJk.cjs +363 -0
- package/dist/tests/{url-BNakuZ8k.cjs → url-Bdj-rTcC.cjs} +88 -12
- package/dist/tests/{url-DMxmp7ZG.mjs → url-COj5Q8mb.mjs} +65 -13
- package/dist/tests/url.test.cjs +4 -1
- package/dist/tests/url.test.mjs +4 -1
- package/dist/url-4EE56sNP.d.cts +352 -0
- package/dist/url-4EE56sNP.d.ts +352 -0
- package/dist/{url-DrGTR8yv.cjs → url-DIKZnaJv.cjs} +88 -12
- package/dist/{url-Dzyp-NsC.js → url-mWveR5GA.js} +65 -13
- package/package.json +14 -3
- package/src/docloader.test.ts +696 -48
- package/src/docloader.ts +186 -75
- package/src/internal.ts +13 -0
- package/src/pin-grant.test.ts +118 -0
- package/src/pin-grant.ts +99 -0
- package/src/pinners/bun.test.ts +278 -0
- package/src/pinners/bun.ts +223 -0
- package/src/pinners/mod.ts +59 -0
- package/src/pinners/node.test.ts +415 -0
- package/src/pinners/node.ts +144 -0
- package/src/pinners/pinners.test.ts +316 -0
- package/src/pinners/testdata/node-child.ts +147 -0
- package/src/pinners/testdata/proxy-child.ts +82 -0
- package/src/pinners/testdata/support.ts +343 -0
- package/src/pinners/testdata/tls-cert.pem +12 -0
- package/src/pinners/testdata/tls-child.ts +88 -0
- package/src/pinners/testdata/tls-key.pem +5 -0
- package/src/pinners/types.ts +48 -0
- package/src/public-fetch.test.ts +1286 -0
- package/src/public-fetch.ts +338 -0
- package/src/testdata/public-fetch-deno-worker.ts +74 -0
- package/src/url.test.ts +11 -0
- package/src/url.ts +113 -22
- package/tsdown.config.ts +7 -2
|
@@ -1,1242 +1,15 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
1
|
+
import { t as esm_default } from "./esm-Ds-eHTfY.mjs";
|
|
2
|
+
import { t as FetchError } from "./request-Bo8cJJhV.mjs";
|
|
3
|
+
import { n as UrlError } from "./url-COj5Q8mb.mjs";
|
|
3
4
|
import { n as cid_v1_default, t as preloadedContexts } from "./contexts-duRA_dDC.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { t as createPublicFetch } from "./public-fetch-Cxo3Yzdf.mjs";
|
|
6
|
+
import { a as withDocumentLoaderTimeout, i as resolveDocumentLoaderTimeout, n as getDocumentLoader, r as getRemoteDocument, t as createDocumentLoader } from "./docloader-BZvFOza_.mjs";
|
|
5
7
|
import { t as jsonld_default } from "./jsonld-DweIJ07b.mjs";
|
|
6
8
|
import { gzipSync } from "node:zlib";
|
|
7
9
|
import { configure, reset } from "@logtape/logtape";
|
|
8
|
-
import dns from "node:dns/promises";
|
|
9
10
|
import { deepStrictEqual, ok, rejects, throws } from "node:assert";
|
|
10
11
|
import { test } from "@fedify/fixture";
|
|
11
12
|
import { createServer } from "node:http";
|
|
12
|
-
//#region \0rolldown/runtime.js
|
|
13
|
-
var __create = Object.create;
|
|
14
|
-
var __defProp = Object.defineProperty;
|
|
15
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
22
|
-
key = keys[i];
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
24
|
-
get: ((k) => from[k]).bind(null, key),
|
|
25
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return to;
|
|
29
|
-
};
|
|
30
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
-
value: mod,
|
|
32
|
-
enumerable: true
|
|
33
|
-
}) : target, mod));
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region ../../node_modules/.pnpm/regexparam@3.0.0/node_modules/regexparam/dist/index.mjs
|
|
36
|
-
var import_glob_to_regexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
37
|
-
module.exports = function(glob, opts) {
|
|
38
|
-
if (typeof glob !== "string") throw new TypeError("Expected a string");
|
|
39
|
-
var str = String(glob);
|
|
40
|
-
var reStr = "";
|
|
41
|
-
var extended = opts ? !!opts.extended : false;
|
|
42
|
-
var globstar = opts ? !!opts.globstar : false;
|
|
43
|
-
var inGroup = false;
|
|
44
|
-
var flags = opts && typeof opts.flags === "string" ? opts.flags : "";
|
|
45
|
-
var c;
|
|
46
|
-
for (var i = 0, len = str.length; i < len; i++) {
|
|
47
|
-
c = str[i];
|
|
48
|
-
switch (c) {
|
|
49
|
-
case "/":
|
|
50
|
-
case "$":
|
|
51
|
-
case "^":
|
|
52
|
-
case "+":
|
|
53
|
-
case ".":
|
|
54
|
-
case "(":
|
|
55
|
-
case ")":
|
|
56
|
-
case "=":
|
|
57
|
-
case "!":
|
|
58
|
-
case "|":
|
|
59
|
-
reStr += "\\" + c;
|
|
60
|
-
break;
|
|
61
|
-
case "?": if (extended) {
|
|
62
|
-
reStr += ".";
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case "[":
|
|
66
|
-
case "]": if (extended) {
|
|
67
|
-
reStr += c;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case "{": if (extended) {
|
|
71
|
-
inGroup = true;
|
|
72
|
-
reStr += "(";
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
case "}": if (extended) {
|
|
76
|
-
inGroup = false;
|
|
77
|
-
reStr += ")";
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case ",":
|
|
81
|
-
if (inGroup) {
|
|
82
|
-
reStr += "|";
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
reStr += "\\" + c;
|
|
86
|
-
break;
|
|
87
|
-
case "*":
|
|
88
|
-
var prevChar = str[i - 1];
|
|
89
|
-
var starCount = 1;
|
|
90
|
-
while (str[i + 1] === "*") {
|
|
91
|
-
starCount++;
|
|
92
|
-
i++;
|
|
93
|
-
}
|
|
94
|
-
var nextChar = str[i + 1];
|
|
95
|
-
if (!globstar) reStr += ".*";
|
|
96
|
-
else if (starCount > 1 && (prevChar === "/" || prevChar === void 0) && (nextChar === "/" || nextChar === void 0)) {
|
|
97
|
-
reStr += "((?:[^/]*(?:/|$))*)";
|
|
98
|
-
i++;
|
|
99
|
-
} else reStr += "([^/]*)";
|
|
100
|
-
break;
|
|
101
|
-
default: reStr += c;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (!flags || !~flags.indexOf("g")) reStr = "^" + reStr + "$";
|
|
105
|
-
return new RegExp(reStr, flags);
|
|
106
|
-
};
|
|
107
|
-
})))(), 1);
|
|
108
|
-
/**
|
|
109
|
-
* @param {string|RegExp} input The route pattern
|
|
110
|
-
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
111
|
-
*/
|
|
112
|
-
function parse(input, loose) {
|
|
113
|
-
if (input instanceof RegExp) return {
|
|
114
|
-
keys: false,
|
|
115
|
-
pattern: input
|
|
116
|
-
};
|
|
117
|
-
var c, o, tmp, ext, keys = [], pattern = "", arr = input.split("/");
|
|
118
|
-
arr[0] || arr.shift();
|
|
119
|
-
while (tmp = arr.shift()) {
|
|
120
|
-
c = tmp[0];
|
|
121
|
-
if (c === "*") {
|
|
122
|
-
keys.push(c);
|
|
123
|
-
pattern += tmp[1] === "?" ? "(?:/(.*))?" : "/(.*)";
|
|
124
|
-
} else if (c === ":") {
|
|
125
|
-
o = tmp.indexOf("?", 1);
|
|
126
|
-
ext = tmp.indexOf(".", 1);
|
|
127
|
-
keys.push(tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length));
|
|
128
|
-
pattern += !!~o && !~ext ? "(?:/([^/]+?))?" : "/([^/]+?)";
|
|
129
|
-
if (!!~ext) pattern += (!!~o ? "?" : "") + "\\" + tmp.substring(ext);
|
|
130
|
-
} else pattern += "/" + tmp;
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
keys,
|
|
134
|
-
pattern: new RegExp("^" + pattern + (loose ? "(?=$|/)" : "/?$"), "i")
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/TypeDescriptor.js
|
|
139
|
-
const valueTypes = /* @__PURE__ */ new Set([
|
|
140
|
-
"boolean",
|
|
141
|
-
"number",
|
|
142
|
-
"null",
|
|
143
|
-
"string",
|
|
144
|
-
"undefined"
|
|
145
|
-
]);
|
|
146
|
-
const referenceTypes = /* @__PURE__ */ new Set([
|
|
147
|
-
"array",
|
|
148
|
-
"function",
|
|
149
|
-
"object",
|
|
150
|
-
"symbol"
|
|
151
|
-
]);
|
|
152
|
-
const detectableTypes = /* @__PURE__ */ new Set([
|
|
153
|
-
"boolean",
|
|
154
|
-
"function",
|
|
155
|
-
"number",
|
|
156
|
-
"string",
|
|
157
|
-
"symbol"
|
|
158
|
-
]);
|
|
159
|
-
const typeConstructors = /* @__PURE__ */ new Set([
|
|
160
|
-
Boolean,
|
|
161
|
-
Number,
|
|
162
|
-
String
|
|
163
|
-
]);
|
|
164
|
-
var TypeDescriptor = class TypeDescriptor {
|
|
165
|
-
constructor(value) {
|
|
166
|
-
this.name = TypeDescriptor.of(value);
|
|
167
|
-
this.isValueType = TypeDescriptor.isValueType(value);
|
|
168
|
-
this.isReferenceType = TypeDescriptor.isReferenceType(value);
|
|
169
|
-
this.isArray = TypeDescriptor.isArray(value);
|
|
170
|
-
this.isBoolean = TypeDescriptor.isBoolean(value);
|
|
171
|
-
this.isFunction = TypeDescriptor.isFunction(value);
|
|
172
|
-
this.isNull = TypeDescriptor.isNull(value);
|
|
173
|
-
this.isNumber = TypeDescriptor.isNumber(value);
|
|
174
|
-
this.isObject = TypeDescriptor.isObject(value);
|
|
175
|
-
this.isString = TypeDescriptor.isString(value);
|
|
176
|
-
this.isSymbol = TypeDescriptor.isSymbol(value);
|
|
177
|
-
this.isUndefined = TypeDescriptor.isUndefined(value);
|
|
178
|
-
}
|
|
179
|
-
static of(value) {
|
|
180
|
-
if (value === null) return "null";
|
|
181
|
-
if (value === void 0) return "undefined";
|
|
182
|
-
const detectedType = typeof value;
|
|
183
|
-
if (detectableTypes.has(detectedType)) return detectedType;
|
|
184
|
-
if (detectedType === "object") {
|
|
185
|
-
if (Array.isArray(value)) return "array";
|
|
186
|
-
if (typeConstructors.has(value.constructor)) return value.constructor.name.toLowerCase();
|
|
187
|
-
return detectedType;
|
|
188
|
-
}
|
|
189
|
-
throw new Error("Failed due to an unknown type.");
|
|
190
|
-
}
|
|
191
|
-
static from(value) {
|
|
192
|
-
return new TypeDescriptor(value);
|
|
193
|
-
}
|
|
194
|
-
static isValueType(value) {
|
|
195
|
-
return valueTypes.has(TypeDescriptor.of(value));
|
|
196
|
-
}
|
|
197
|
-
static isReferenceType(value) {
|
|
198
|
-
return referenceTypes.has(TypeDescriptor.of(value));
|
|
199
|
-
}
|
|
200
|
-
static isArray(value) {
|
|
201
|
-
return TypeDescriptor.of(value) === "array";
|
|
202
|
-
}
|
|
203
|
-
static isBoolean(value) {
|
|
204
|
-
return TypeDescriptor.of(value) === "boolean";
|
|
205
|
-
}
|
|
206
|
-
static isFunction(value) {
|
|
207
|
-
return TypeDescriptor.of(value) === "function";
|
|
208
|
-
}
|
|
209
|
-
static isNull(value) {
|
|
210
|
-
return TypeDescriptor.of(value) === "null";
|
|
211
|
-
}
|
|
212
|
-
static isNumber(value) {
|
|
213
|
-
return TypeDescriptor.of(value) === "number";
|
|
214
|
-
}
|
|
215
|
-
static isObject(value) {
|
|
216
|
-
return TypeDescriptor.of(value) === "object";
|
|
217
|
-
}
|
|
218
|
-
static isString(value) {
|
|
219
|
-
return TypeDescriptor.of(value) === "string";
|
|
220
|
-
}
|
|
221
|
-
static isSymbol(value) {
|
|
222
|
-
return TypeDescriptor.of(value) === "symbol";
|
|
223
|
-
}
|
|
224
|
-
static isUndefined(value) {
|
|
225
|
-
return TypeDescriptor.of(value) === "undefined";
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/IsSubsetOf.js
|
|
230
|
-
const allowedTypes = /* @__PURE__ */ new Set([
|
|
231
|
-
"array",
|
|
232
|
-
"object",
|
|
233
|
-
"function",
|
|
234
|
-
"null"
|
|
235
|
-
]);
|
|
236
|
-
const isSubsetOf = function(subset, superset, visited = []) {
|
|
237
|
-
const subsetType = TypeDescriptor.of(subset);
|
|
238
|
-
const supersetType = TypeDescriptor.of(superset);
|
|
239
|
-
if (!allowedTypes.has(subsetType)) throw new Error(`Type '${subsetType}' is not supported.`);
|
|
240
|
-
if (!allowedTypes.has(supersetType)) throw new Error(`Type '${supersetType}' is not supported.`);
|
|
241
|
-
if (TypeDescriptor.isFunction(subset)) {
|
|
242
|
-
if (!TypeDescriptor.isFunction(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
243
|
-
return subset.toString() === superset.toString();
|
|
244
|
-
}
|
|
245
|
-
if (TypeDescriptor.isArray(subset)) {
|
|
246
|
-
if (!TypeDescriptor.isArray(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
247
|
-
if (subset.length > superset.length) return false;
|
|
248
|
-
for (const subsetItem of subset) {
|
|
249
|
-
const subsetItemType = TypeDescriptor.of(subsetItem);
|
|
250
|
-
let isItemInSuperset;
|
|
251
|
-
switch (subsetItemType) {
|
|
252
|
-
case "array":
|
|
253
|
-
case "object":
|
|
254
|
-
case "function":
|
|
255
|
-
if (visited.includes(subsetItem)) continue;
|
|
256
|
-
visited.push(subsetItem);
|
|
257
|
-
isItemInSuperset = superset.some((supersetItem) => {
|
|
258
|
-
try {
|
|
259
|
-
return isSubsetOf(subsetItem, supersetItem, visited);
|
|
260
|
-
} catch {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
break;
|
|
265
|
-
default: isItemInSuperset = superset.includes(subsetItem);
|
|
266
|
-
}
|
|
267
|
-
if (!isItemInSuperset) return false;
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
if (TypeDescriptor.isObject(subset)) {
|
|
272
|
-
if (!TypeDescriptor.isObject(superset) || TypeDescriptor.isArray(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
273
|
-
if (Object.keys(subset).length > Object.keys(superset).length) return false;
|
|
274
|
-
for (const [subsetKey, subsetValue] of Object.entries(subset)) {
|
|
275
|
-
const supersetValue = superset[subsetKey];
|
|
276
|
-
switch (TypeDescriptor.of(subsetValue)) {
|
|
277
|
-
case "array":
|
|
278
|
-
case "object":
|
|
279
|
-
case "function":
|
|
280
|
-
if (visited.includes(subsetValue)) continue;
|
|
281
|
-
visited.push(subsetValue);
|
|
282
|
-
try {
|
|
283
|
-
if (!isSubsetOf(subsetValue, supersetValue, visited)) return false;
|
|
284
|
-
} catch {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
break;
|
|
288
|
-
default: if (subsetValue !== supersetValue) return false;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
if (TypeDescriptor.isNull(subset)) {
|
|
294
|
-
if (!TypeDescriptor.isNull(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
throw new Error("Invalid operation.");
|
|
298
|
-
};
|
|
299
|
-
isSubsetOf.structural = function(subset, superset, visited = []) {
|
|
300
|
-
if (!TypeDescriptor.isObject(subset)) throw new Error(`Type '${TypeDescriptor.of(subset)}' is not supported.`);
|
|
301
|
-
if (!TypeDescriptor.isObject(superset)) throw new Error(`Type '${TypeDescriptor.of(superset)}' is not supported.`);
|
|
302
|
-
for (const [subsetKey, subsetValue] of Object.entries(subset)) {
|
|
303
|
-
if (superset[subsetKey] === void 0) return false;
|
|
304
|
-
const subsetValueType = TypeDescriptor.of(subsetValue);
|
|
305
|
-
const supersetValue = superset[subsetKey];
|
|
306
|
-
if (subsetValueType === "object") {
|
|
307
|
-
if (visited.includes(subsetValue)) continue;
|
|
308
|
-
visited.push(subsetValue);
|
|
309
|
-
try {
|
|
310
|
-
if (!isSubsetOf.structural(subsetValue, supersetValue, visited)) return false;
|
|
311
|
-
} catch {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return true;
|
|
317
|
-
};
|
|
318
|
-
//#endregion
|
|
319
|
-
//#region ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs
|
|
320
|
-
var has = Object.prototype.hasOwnProperty;
|
|
321
|
-
function find(iter, tar, key) {
|
|
322
|
-
for (key of iter.keys()) if (dequal(key, tar)) return key;
|
|
323
|
-
}
|
|
324
|
-
function dequal(foo, bar) {
|
|
325
|
-
var ctor, len, tmp;
|
|
326
|
-
if (foo === bar) return true;
|
|
327
|
-
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
328
|
-
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
329
|
-
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
330
|
-
if (ctor === Array) {
|
|
331
|
-
if ((len = foo.length) === bar.length) while (len-- && dequal(foo[len], bar[len]));
|
|
332
|
-
return len === -1;
|
|
333
|
-
}
|
|
334
|
-
if (ctor === Set) {
|
|
335
|
-
if (foo.size !== bar.size) return false;
|
|
336
|
-
for (len of foo) {
|
|
337
|
-
tmp = len;
|
|
338
|
-
if (tmp && typeof tmp === "object") {
|
|
339
|
-
tmp = find(bar, tmp);
|
|
340
|
-
if (!tmp) return false;
|
|
341
|
-
}
|
|
342
|
-
if (!bar.has(tmp)) return false;
|
|
343
|
-
}
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
if (ctor === Map) {
|
|
347
|
-
if (foo.size !== bar.size) return false;
|
|
348
|
-
for (len of foo) {
|
|
349
|
-
tmp = len[0];
|
|
350
|
-
if (tmp && typeof tmp === "object") {
|
|
351
|
-
tmp = find(bar, tmp);
|
|
352
|
-
if (!tmp) return false;
|
|
353
|
-
}
|
|
354
|
-
if (!dequal(len[1], bar.get(tmp))) return false;
|
|
355
|
-
}
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
if (ctor === ArrayBuffer) {
|
|
359
|
-
foo = new Uint8Array(foo);
|
|
360
|
-
bar = new Uint8Array(bar);
|
|
361
|
-
} else if (ctor === DataView) {
|
|
362
|
-
if ((len = foo.byteLength) === bar.byteLength) while (len-- && foo.getInt8(len) === bar.getInt8(len));
|
|
363
|
-
return len === -1;
|
|
364
|
-
}
|
|
365
|
-
if (ArrayBuffer.isView(foo)) {
|
|
366
|
-
if ((len = foo.byteLength) === bar.byteLength) while (len-- && foo[len] === bar[len]);
|
|
367
|
-
return len === -1;
|
|
368
|
-
}
|
|
369
|
-
if (!ctor || typeof foo === "object") {
|
|
370
|
-
len = 0;
|
|
371
|
-
for (ctor in foo) {
|
|
372
|
-
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
373
|
-
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
|
374
|
-
}
|
|
375
|
-
return Object.keys(bar).length === len;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return foo !== foo && bar !== bar;
|
|
379
|
-
}
|
|
380
|
-
//#endregion
|
|
381
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/RequestUtils.js
|
|
382
|
-
const absoluteUrlRX = /* @__PURE__ */ new RegExp("^[a-z]+://|^data:", "i");
|
|
383
|
-
const protocolRelativeUrlRX = /* @__PURE__ */ new RegExp("^//", "i");
|
|
384
|
-
function hasCredentialsInUrl(url) {
|
|
385
|
-
const urlObject = new URL(url, !absoluteUrlRX.test(url) ? "http://dummy" : void 0);
|
|
386
|
-
return Boolean(urlObject.username || urlObject.password);
|
|
387
|
-
}
|
|
388
|
-
function normalizeUrl(url, allowRelativeUrls) {
|
|
389
|
-
if (url instanceof URL) return url.href;
|
|
390
|
-
const primitiveUrl = String(url).valueOf();
|
|
391
|
-
if (absoluteUrlRX.test(primitiveUrl)) return new URL(primitiveUrl).href;
|
|
392
|
-
if (protocolRelativeUrlRX.test(primitiveUrl)) return new URL(primitiveUrl, "http://dummy").href.replace(/^[a-z]+:/, "");
|
|
393
|
-
if ("location" in globalThis) if (primitiveUrl.startsWith("/")) return `${globalThis.location.origin}${primitiveUrl}`;
|
|
394
|
-
else return `${globalThis.location.href}/${primitiveUrl}`;
|
|
395
|
-
else if (allowRelativeUrls) {
|
|
396
|
-
const urlInstance = new URL(primitiveUrl, "http://dummy");
|
|
397
|
-
return urlInstance.pathname + urlInstance.search;
|
|
398
|
-
} else throw new Error("Relative urls are not support by default in node.js tests. Either use a utility such as jsdom to define globalThis.location or set `fetchMock.config.allowRelativeUrls = true`");
|
|
399
|
-
}
|
|
400
|
-
function createCallLogFromUrlAndOptions(url, options) {
|
|
401
|
-
const pendingPromises = [];
|
|
402
|
-
if (typeof url === "string" || url instanceof String || url instanceof URL) {
|
|
403
|
-
const normalizedUrl = normalizeUrl(url, true);
|
|
404
|
-
const derivedOptions = options ? { ...options } : {};
|
|
405
|
-
if (derivedOptions.headers) derivedOptions.headers = normalizeHeaders(derivedOptions.headers);
|
|
406
|
-
derivedOptions.method = derivedOptions.method ? derivedOptions.method.toLowerCase() : "get";
|
|
407
|
-
return {
|
|
408
|
-
args: [url, options],
|
|
409
|
-
url: normalizedUrl,
|
|
410
|
-
queryParams: new URLSearchParams(getQuery(normalizedUrl)),
|
|
411
|
-
options: derivedOptions,
|
|
412
|
-
signal: derivedOptions.signal,
|
|
413
|
-
pendingPromises
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
if (typeof url === "object") throw new TypeError("fetch-mock: Unrecognised Request object. Read the Config and Installation sections of the docs");
|
|
417
|
-
else throw new TypeError("fetch-mock: Invalid arguments passed to fetch");
|
|
418
|
-
}
|
|
419
|
-
async function createCallLogFromRequest(request, options) {
|
|
420
|
-
const pendingPromises = [];
|
|
421
|
-
const derivedOptions = { method: request.method };
|
|
422
|
-
try {
|
|
423
|
-
try {
|
|
424
|
-
derivedOptions.body = await request.clone().formData();
|
|
425
|
-
} catch {
|
|
426
|
-
derivedOptions.body = await request.clone().text();
|
|
427
|
-
}
|
|
428
|
-
} catch {}
|
|
429
|
-
if (request.headers) derivedOptions.headers = normalizeHeaders(request.headers);
|
|
430
|
-
const url = normalizeUrl(request.url, true);
|
|
431
|
-
return {
|
|
432
|
-
args: [request, options],
|
|
433
|
-
url,
|
|
434
|
-
queryParams: new URLSearchParams(getQuery(url)),
|
|
435
|
-
options: Object.assign(derivedOptions, options || {}),
|
|
436
|
-
request,
|
|
437
|
-
signal: options && options.signal || request.signal,
|
|
438
|
-
pendingPromises
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
function getPath(url) {
|
|
442
|
-
return (absoluteUrlRX.test(url) ? new URL(url) : new URL(url, "http://dummy")).pathname;
|
|
443
|
-
}
|
|
444
|
-
function getHost(url) {
|
|
445
|
-
if (absoluteUrlRX.test(url)) return new URL(url).host;
|
|
446
|
-
else if ("location" in globalThis) return globalThis.location.host;
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
function getQuery(url) {
|
|
450
|
-
const u = absoluteUrlRX.test(url) ? new URL(url) : new URL(url, "http://dummy");
|
|
451
|
-
return u.search ? u.search.substr(1) : "";
|
|
452
|
-
}
|
|
453
|
-
function normalizeHeaders(headers) {
|
|
454
|
-
let entries;
|
|
455
|
-
if (headers instanceof Headers) entries = [...headers.entries()];
|
|
456
|
-
else if (Array.isArray(headers)) entries = headers;
|
|
457
|
-
else entries = Object.entries(headers);
|
|
458
|
-
return Object.fromEntries(entries.map(([key, val]) => [key.toLowerCase(), String(val).valueOf()]));
|
|
459
|
-
}
|
|
460
|
-
//#endregion
|
|
461
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Matchers.js
|
|
462
|
-
const isUrlMatcher = (matcher) => matcher instanceof RegExp || typeof matcher === "string" || typeof matcher === "object" && "href" in matcher;
|
|
463
|
-
const isFunctionMatcher = (matcher) => typeof matcher === "function";
|
|
464
|
-
const stringMatchers = {
|
|
465
|
-
begin: (targetString) => ({ url }) => url.startsWith(targetString),
|
|
466
|
-
end: (targetString) => ({ url }) => url.endsWith(targetString),
|
|
467
|
-
include: (targetString) => ({ url }) => url.includes(targetString),
|
|
468
|
-
glob: (targetString) => {
|
|
469
|
-
const urlRX = (0, import_glob_to_regexp.default)(targetString);
|
|
470
|
-
return ({ url }) => urlRX.test(url);
|
|
471
|
-
},
|
|
472
|
-
express: (targetString) => {
|
|
473
|
-
const urlRX = parse(targetString);
|
|
474
|
-
return (callLog) => {
|
|
475
|
-
const vals = urlRX.pattern.exec(getPath(callLog.url));
|
|
476
|
-
if (!vals) {
|
|
477
|
-
callLog.expressParams = {};
|
|
478
|
-
return false;
|
|
479
|
-
}
|
|
480
|
-
vals.shift();
|
|
481
|
-
callLog.expressParams = urlRX.keys.reduce((map, paramName, i) => vals[i] ? Object.assign(map, { [paramName]: vals[i] }) : map, {});
|
|
482
|
-
return true;
|
|
483
|
-
};
|
|
484
|
-
},
|
|
485
|
-
path: (targetString) => {
|
|
486
|
-
const dotlessTargetString = getPath(targetString);
|
|
487
|
-
return ({ url }) => {
|
|
488
|
-
const path = getPath(url);
|
|
489
|
-
return path === targetString || path === dotlessTargetString;
|
|
490
|
-
};
|
|
491
|
-
},
|
|
492
|
-
host: (targetString) => {
|
|
493
|
-
return ({ url }) => targetString === getHost(url);
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
const getHeaderMatcher = ({ headers: expectedHeaders }) => {
|
|
497
|
-
if (!expectedHeaders) return;
|
|
498
|
-
const expectation = normalizeHeaders(expectedHeaders);
|
|
499
|
-
return ({ options: { headers = {} } }) => {
|
|
500
|
-
const lowerCaseHeaders = normalizeHeaders(headers);
|
|
501
|
-
return Object.keys(expectation).every((headerName) => lowerCaseHeaders[headerName] === expectation[headerName]);
|
|
502
|
-
};
|
|
503
|
-
};
|
|
504
|
-
const getMissingHeaderMatcher = ({ missingHeaders: expectedMissingHeaders }) => {
|
|
505
|
-
if (!expectedMissingHeaders) return;
|
|
506
|
-
const expectation = expectedMissingHeaders.map((header) => header.toLowerCase());
|
|
507
|
-
return ({ options: { headers = {} } }) => {
|
|
508
|
-
const lowerCaseHeaders = normalizeHeaders(headers);
|
|
509
|
-
return expectation.every((headerName) => !(headerName in lowerCaseHeaders));
|
|
510
|
-
};
|
|
511
|
-
};
|
|
512
|
-
const getMethodMatcher = ({ method: expectedMethod }) => {
|
|
513
|
-
if (!expectedMethod) return;
|
|
514
|
-
return ({ options: { method } = {} }) => {
|
|
515
|
-
return expectedMethod === (method ? method.toLowerCase() : "get");
|
|
516
|
-
};
|
|
517
|
-
};
|
|
518
|
-
const getQueryParamsMatcher = ({ query: passedQuery }) => {
|
|
519
|
-
if (!passedQuery) return;
|
|
520
|
-
const expectedQuery = new URLSearchParams();
|
|
521
|
-
for (const [key, value] of Object.entries(passedQuery)) if (Array.isArray(value)) for (const item of value) expectedQuery.append(key, typeof item === "object" || typeof item === "undefined" ? "" : item.toString());
|
|
522
|
-
else expectedQuery.append(key, typeof value === "object" || typeof value === "undefined" ? "" : value.toString());
|
|
523
|
-
const keys = Array.from(expectedQuery.keys());
|
|
524
|
-
return ({ queryParams }) => {
|
|
525
|
-
return keys.every((key) => {
|
|
526
|
-
const expectedValues = expectedQuery.getAll(key).sort();
|
|
527
|
-
const actualValues = queryParams.getAll(key).sort();
|
|
528
|
-
if (expectedValues.length !== actualValues.length) return false;
|
|
529
|
-
if (Array.isArray(passedQuery[key])) return expectedValues.every((expected, index) => expected === actualValues[index]);
|
|
530
|
-
return dequal(actualValues, expectedValues);
|
|
531
|
-
});
|
|
532
|
-
};
|
|
533
|
-
};
|
|
534
|
-
const getExpressParamsMatcher = ({ params: expectedParams, url }) => {
|
|
535
|
-
if (!expectedParams) return;
|
|
536
|
-
if (!(typeof url === "string" && /express:/.test(url))) throw new Error("fetch-mock: matching on params is only possible when using an express: matcher");
|
|
537
|
-
const expectedKeys = Object.keys(expectedParams);
|
|
538
|
-
return ({ expressParams = {} }) => {
|
|
539
|
-
return expectedKeys.every((key) => expressParams[key] === expectedParams[key]);
|
|
540
|
-
};
|
|
541
|
-
};
|
|
542
|
-
const formDataToObject = (formData) => {
|
|
543
|
-
const fields = [...formData];
|
|
544
|
-
const result = {};
|
|
545
|
-
fields.forEach(([key, value]) => {
|
|
546
|
-
result[key] = result[key] || [];
|
|
547
|
-
result[key].push(value);
|
|
548
|
-
});
|
|
549
|
-
return result;
|
|
550
|
-
};
|
|
551
|
-
const getBodyMatcher = (route) => {
|
|
552
|
-
let { body: expectedBody } = route;
|
|
553
|
-
let expectedBodyType = "json";
|
|
554
|
-
if (!expectedBody) return;
|
|
555
|
-
if (expectedBody instanceof FormData) {
|
|
556
|
-
expectedBodyType = "formData";
|
|
557
|
-
expectedBody = formDataToObject(expectedBody);
|
|
558
|
-
}
|
|
559
|
-
return ({ options: { body, method = "get" } }) => {
|
|
560
|
-
if (["get", "head"].includes(method.toLowerCase())) return false;
|
|
561
|
-
let sentBody;
|
|
562
|
-
try {
|
|
563
|
-
if (typeof body === "string") {
|
|
564
|
-
sentBody = JSON.parse(body);
|
|
565
|
-
if (expectedBodyType !== "json") return false;
|
|
566
|
-
}
|
|
567
|
-
} catch {}
|
|
568
|
-
if (body instanceof FormData) {
|
|
569
|
-
if (expectedBodyType !== "formData") return false;
|
|
570
|
-
sentBody = formDataToObject(body);
|
|
571
|
-
}
|
|
572
|
-
return sentBody && (route.matchPartialBody ? isSubsetOf(expectedBody, sentBody) : dequal(expectedBody, sentBody));
|
|
573
|
-
};
|
|
574
|
-
};
|
|
575
|
-
const getFunctionMatcher = ({ matcherFunction }) => matcherFunction;
|
|
576
|
-
const getRegexpMatcher = (regexp) => ({ url }) => regexp.test(url);
|
|
577
|
-
const getFullUrlMatcher = (route, matcherUrl, query) => {
|
|
578
|
-
const expectedUrl = normalizeUrl(matcherUrl, route.allowRelativeUrls);
|
|
579
|
-
if (route.url === matcherUrl) route.url = expectedUrl;
|
|
580
|
-
return ({ url }) => {
|
|
581
|
-
if (query && expectedUrl.indexOf("?")) return getPath(url) === getPath(expectedUrl);
|
|
582
|
-
return normalizeUrl(url, true) === expectedUrl;
|
|
583
|
-
};
|
|
584
|
-
};
|
|
585
|
-
const getUrlMatcher = (route) => {
|
|
586
|
-
const { url: matcherUrl, query } = route;
|
|
587
|
-
if (matcherUrl === "*") return () => true;
|
|
588
|
-
if (matcherUrl instanceof RegExp) return getRegexpMatcher(matcherUrl);
|
|
589
|
-
if (matcherUrl instanceof URL) {
|
|
590
|
-
if (matcherUrl.href) return getFullUrlMatcher(route, matcherUrl.href, query);
|
|
591
|
-
}
|
|
592
|
-
if (typeof matcherUrl === "string") {
|
|
593
|
-
for (const shorthand in stringMatchers) if (matcherUrl.indexOf(`${shorthand}:`) === 0) {
|
|
594
|
-
const urlFragment = matcherUrl.replace(new RegExp(`^${shorthand}:`), "");
|
|
595
|
-
return stringMatchers[shorthand](urlFragment);
|
|
596
|
-
}
|
|
597
|
-
return getFullUrlMatcher(route, matcherUrl, query);
|
|
598
|
-
}
|
|
599
|
-
if (typeof matcherUrl === "object") {
|
|
600
|
-
const matchers = Object.entries(matcherUrl).map(([key, pattern]) => {
|
|
601
|
-
if (key === "regexp") return getRegexpMatcher(pattern);
|
|
602
|
-
else if (key in stringMatchers) return stringMatchers[key](pattern);
|
|
603
|
-
else throw new Error(`unrecognised url matching pattern: ${key}`);
|
|
604
|
-
});
|
|
605
|
-
return (route) => matchers.every((matcher) => matcher(route));
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
const builtInMatchers = [
|
|
609
|
-
{
|
|
610
|
-
name: "url",
|
|
611
|
-
matcher: getUrlMatcher
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
name: "query",
|
|
615
|
-
matcher: getQueryParamsMatcher
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
name: "method",
|
|
619
|
-
matcher: getMethodMatcher
|
|
620
|
-
},
|
|
621
|
-
{
|
|
622
|
-
name: "headers",
|
|
623
|
-
matcher: getHeaderMatcher
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
name: "missingHeaders",
|
|
627
|
-
matcher: getMissingHeaderMatcher
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
name: "params",
|
|
631
|
-
matcher: getExpressParamsMatcher
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
name: "body",
|
|
635
|
-
matcher: getBodyMatcher,
|
|
636
|
-
usesBody: true
|
|
637
|
-
},
|
|
638
|
-
{
|
|
639
|
-
name: "matcherFunction",
|
|
640
|
-
matcher: getFunctionMatcher
|
|
641
|
-
}
|
|
642
|
-
];
|
|
643
|
-
//#endregion
|
|
644
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/StatusTextMap.js
|
|
645
|
-
const statusTextMap = {
|
|
646
|
-
100: "Continue",
|
|
647
|
-
101: "Switching Protocols",
|
|
648
|
-
102: "Processing",
|
|
649
|
-
200: "OK",
|
|
650
|
-
201: "Created",
|
|
651
|
-
202: "Accepted",
|
|
652
|
-
203: "Non-Authoritative Information",
|
|
653
|
-
204: "No Content",
|
|
654
|
-
205: "Reset Content",
|
|
655
|
-
206: "Partial Content",
|
|
656
|
-
207: "Multi-Status",
|
|
657
|
-
208: "Already Reported",
|
|
658
|
-
226: "IM Used",
|
|
659
|
-
300: "Multiple Choices",
|
|
660
|
-
301: "Moved Permanently",
|
|
661
|
-
302: "Found",
|
|
662
|
-
303: "See Other",
|
|
663
|
-
304: "Not Modified",
|
|
664
|
-
305: "Use Proxy",
|
|
665
|
-
307: "Temporary Redirect",
|
|
666
|
-
308: "Permanent Redirect",
|
|
667
|
-
400: "Bad Request",
|
|
668
|
-
401: "Unauthorized",
|
|
669
|
-
402: "Payment Required",
|
|
670
|
-
403: "Forbidden",
|
|
671
|
-
404: "Not Found",
|
|
672
|
-
405: "Method Not Allowed",
|
|
673
|
-
406: "Not Acceptable",
|
|
674
|
-
407: "Proxy Authentication Required",
|
|
675
|
-
408: "Request Timeout",
|
|
676
|
-
409: "Conflict",
|
|
677
|
-
410: "Gone",
|
|
678
|
-
411: "Length Required",
|
|
679
|
-
412: "Precondition Failed",
|
|
680
|
-
413: "Payload Too Large",
|
|
681
|
-
414: "URI Too Long",
|
|
682
|
-
415: "Unsupported Media Type",
|
|
683
|
-
416: "Range Not Satisfiable",
|
|
684
|
-
417: "Expectation Failed",
|
|
685
|
-
418: "I'm a teapot",
|
|
686
|
-
421: "Misdirected Request",
|
|
687
|
-
422: "Unprocessable Entity",
|
|
688
|
-
423: "Locked",
|
|
689
|
-
424: "Failed Dependency",
|
|
690
|
-
425: "Unordered Collection",
|
|
691
|
-
426: "Upgrade Required",
|
|
692
|
-
428: "Precondition Required",
|
|
693
|
-
429: "Too Many Requests",
|
|
694
|
-
431: "Request Header Fields Too Large",
|
|
695
|
-
451: "Unavailable For Legal Reasons",
|
|
696
|
-
500: "Internal Server Error",
|
|
697
|
-
501: "Not Implemented",
|
|
698
|
-
502: "Bad Gateway",
|
|
699
|
-
503: "Service Unavailable",
|
|
700
|
-
504: "Gateway Timeout",
|
|
701
|
-
505: "HTTP Version Not Supported",
|
|
702
|
-
506: "Variant Also Negotiates",
|
|
703
|
-
507: "Insufficient Storage",
|
|
704
|
-
508: "Loop Detected",
|
|
705
|
-
509: "Bandwidth Limit Exceeded",
|
|
706
|
-
510: "Not Extended",
|
|
707
|
-
511: "Network Authentication Required"
|
|
708
|
-
};
|
|
709
|
-
//#endregion
|
|
710
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Route.js
|
|
711
|
-
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
712
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
713
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
714
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
715
|
-
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
716
|
-
};
|
|
717
|
-
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
718
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
719
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
720
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
721
|
-
};
|
|
722
|
-
var _Route_instances;
|
|
723
|
-
var _a;
|
|
724
|
-
var _Route_responseSubscriptions;
|
|
725
|
-
var _Route_validate;
|
|
726
|
-
var _Route_sanitize;
|
|
727
|
-
var _Route_generateMatcher;
|
|
728
|
-
var _Route_limit;
|
|
729
|
-
var _Route_delayResponse;
|
|
730
|
-
var RouteConfigWrapper = class {
|
|
731
|
-
constructor(config) {
|
|
732
|
-
Object.assign(this, config);
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
function isBodyInit(body) {
|
|
736
|
-
return body instanceof Blob || body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof DataView || body instanceof FormData || body instanceof ReadableStream || body instanceof URLSearchParams || body instanceof String || typeof body === "string" || body === null;
|
|
737
|
-
}
|
|
738
|
-
function sanitizeStatus(status) {
|
|
739
|
-
if (status === 0) return 200;
|
|
740
|
-
if (!status) return 200;
|
|
741
|
-
if (typeof status === "number" && parseInt(String(status), 10) !== status && status >= 200 || status < 600) return status;
|
|
742
|
-
throw new TypeError(`fetch-mock: Invalid status ${status} passed on response object.
|
|
743
|
-
To respond with a JSON object that has status as a property assign the object to body
|
|
744
|
-
e.g. {"body": {"status: "registered"}}`);
|
|
745
|
-
}
|
|
746
|
-
var Route = class {
|
|
747
|
-
constructor(config) {
|
|
748
|
-
_Route_instances.add(this);
|
|
749
|
-
_Route_responseSubscriptions.set(this, void 0);
|
|
750
|
-
this.init(config);
|
|
751
|
-
}
|
|
752
|
-
init(config) {
|
|
753
|
-
this.config = config;
|
|
754
|
-
__classPrivateFieldSet(this, _Route_responseSubscriptions, [], "f");
|
|
755
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_sanitize).call(this);
|
|
756
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_validate).call(this);
|
|
757
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_generateMatcher).call(this);
|
|
758
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_limit).call(this);
|
|
759
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_delayResponse).call(this);
|
|
760
|
-
}
|
|
761
|
-
reset() {}
|
|
762
|
-
waitFor(awaitedRoutes) {
|
|
763
|
-
const { response } = this.config;
|
|
764
|
-
this.config.response = Promise.all(awaitedRoutes.map((awaitedRoute) => new Promise((res) => awaitedRoute.onRespond(() => {
|
|
765
|
-
res(void 0);
|
|
766
|
-
})))).then(() => response);
|
|
767
|
-
}
|
|
768
|
-
onRespond(func) {
|
|
769
|
-
__classPrivateFieldGet(this, _Route_responseSubscriptions, "f").push(func);
|
|
770
|
-
}
|
|
771
|
-
constructResponse(responseInput) {
|
|
772
|
-
const responseOptions = this.constructResponseOptions(responseInput);
|
|
773
|
-
const body = this.constructResponseBody(responseInput, responseOptions);
|
|
774
|
-
const responsePackage = {
|
|
775
|
-
response: new this.config.Response(body, responseOptions),
|
|
776
|
-
responseOptions,
|
|
777
|
-
responseInput
|
|
778
|
-
};
|
|
779
|
-
__classPrivateFieldGet(this, _Route_responseSubscriptions, "f").forEach((func) => func());
|
|
780
|
-
return responsePackage;
|
|
781
|
-
}
|
|
782
|
-
constructResponseOptions(responseInput) {
|
|
783
|
-
const options = responseInput.options || {};
|
|
784
|
-
options.status = sanitizeStatus(responseInput.status);
|
|
785
|
-
options.statusText = statusTextMap[options.status];
|
|
786
|
-
options.headers = new this.config.Headers(responseInput.headers);
|
|
787
|
-
return options;
|
|
788
|
-
}
|
|
789
|
-
constructResponseBody(responseInput, responseOptions) {
|
|
790
|
-
let body = responseInput.body;
|
|
791
|
-
if (!isBodyInit(body)) if (typeof body === "undefined") body = null;
|
|
792
|
-
else if (typeof body === "object") {
|
|
793
|
-
body = JSON.stringify(body);
|
|
794
|
-
if (!responseOptions.headers.has("Content-Type")) responseOptions.headers.set("Content-Type", "application/json");
|
|
795
|
-
} else throw new TypeError("Invalid body provided to construct response");
|
|
796
|
-
if (this.config.includeContentLength && !responseOptions.headers.has("Content-Length") && !(body instanceof ReadableStream) && !(body instanceof FormData)) {
|
|
797
|
-
let length = 0;
|
|
798
|
-
if (body instanceof Blob) length = body.size;
|
|
799
|
-
else if (body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof DataView) length = body.byteLength;
|
|
800
|
-
else if (body instanceof URLSearchParams) length = body.toString().length;
|
|
801
|
-
else if (typeof body === "string" || body instanceof String) length = body.length;
|
|
802
|
-
responseOptions.headers.set("Content-Length", length.toString());
|
|
803
|
-
}
|
|
804
|
-
return body;
|
|
805
|
-
}
|
|
806
|
-
static defineMatcher(matcher) {
|
|
807
|
-
_a.registeredMatchers.push(matcher);
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
_a = Route, _Route_responseSubscriptions = /* @__PURE__ */ new WeakMap(), _Route_instances = /* @__PURE__ */ new WeakSet(), _Route_validate = function _Route_validate() {
|
|
811
|
-
if (["matched", "unmatched"].includes(this.config.name)) throw new Error(`fetch-mock: Routes cannot use the reserved name \`${this.config.name}\``);
|
|
812
|
-
if (!("response" in this.config)) throw new Error("fetch-mock: Each route must define a response");
|
|
813
|
-
if (!_a.registeredMatchers.some(({ name }) => name in this.config)) throw new Error("fetch-mock: Each route must specify some criteria for matching calls to fetch. To match all calls use '*'");
|
|
814
|
-
}, _Route_sanitize = function _Route_sanitize() {
|
|
815
|
-
if (this.config.method) this.config.method = this.config.method.toLowerCase();
|
|
816
|
-
}, _Route_generateMatcher = function _Route_generateMatcher() {
|
|
817
|
-
const activeMatchers = _a.registeredMatchers.filter(({ name }) => name in this.config).map(({ matcher, usesBody }) => ({
|
|
818
|
-
matcher: matcher(this.config),
|
|
819
|
-
usesBody
|
|
820
|
-
}));
|
|
821
|
-
this.config.usesBody = activeMatchers.some(({ usesBody }) => usesBody);
|
|
822
|
-
this.matcher = (normalizedRequest) => activeMatchers.every(({ matcher }) => matcher(normalizedRequest));
|
|
823
|
-
}, _Route_limit = function _Route_limit() {
|
|
824
|
-
if (!this.config.repeat) return;
|
|
825
|
-
const originalMatcher = this.matcher;
|
|
826
|
-
let timesLeft = this.config.repeat;
|
|
827
|
-
this.matcher = (callLog) => {
|
|
828
|
-
if (timesLeft && originalMatcher(callLog)) {
|
|
829
|
-
timesLeft--;
|
|
830
|
-
return true;
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
this.reset = () => {
|
|
834
|
-
timesLeft = this.config.repeat;
|
|
835
|
-
};
|
|
836
|
-
}, _Route_delayResponse = function _Route_delayResponse() {
|
|
837
|
-
if (this.config.delay) {
|
|
838
|
-
const { response } = this.config;
|
|
839
|
-
this.config.response = () => {
|
|
840
|
-
return new Promise((res) => setTimeout(() => res(response), this.config.delay));
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
Route.registeredMatchers = [];
|
|
845
|
-
builtInMatchers.forEach(Route.defineMatcher);
|
|
846
|
-
//#endregion
|
|
847
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Router.js
|
|
848
|
-
const responseConfigProps = [
|
|
849
|
-
"body",
|
|
850
|
-
"headers",
|
|
851
|
-
"throws",
|
|
852
|
-
"status",
|
|
853
|
-
"redirectUrl"
|
|
854
|
-
];
|
|
855
|
-
function nameToOptions(options) {
|
|
856
|
-
return typeof options === "string" ? { name: options } : options;
|
|
857
|
-
}
|
|
858
|
-
function isPromise(response) {
|
|
859
|
-
return typeof response.then === "function";
|
|
860
|
-
}
|
|
861
|
-
function normalizeResponseInput(responseInput) {
|
|
862
|
-
if (typeof responseInput === "number") return { status: responseInput };
|
|
863
|
-
else if (typeof responseInput === "string" || shouldSendAsObject(responseInput)) return { body: responseInput };
|
|
864
|
-
return responseInput;
|
|
865
|
-
}
|
|
866
|
-
function shouldSendAsObject(responseInput) {
|
|
867
|
-
if (responseConfigProps.some((prop) => prop in responseInput)) {
|
|
868
|
-
if (Object.keys(responseInput).every((key) => responseConfigProps.includes(key))) return false;
|
|
869
|
-
return true;
|
|
870
|
-
}
|
|
871
|
-
return true;
|
|
872
|
-
}
|
|
873
|
-
function throwSpecExceptions({ url, options: { headers, method, body } }) {
|
|
874
|
-
if (headers) Object.entries(headers).forEach(([key]) => {
|
|
875
|
-
if (/\s/.test(key)) throw new TypeError("Invalid name");
|
|
876
|
-
});
|
|
877
|
-
if (hasCredentialsInUrl(url)) throw new TypeError(`Request cannot be constructed from a URL that includes credentials: ${url}`);
|
|
878
|
-
if (["get", "head"].includes(method) && body) throw new TypeError("Request with GET/HEAD method cannot have body.");
|
|
879
|
-
}
|
|
880
|
-
const resolveUntilResponseConfig = async (callLog) => {
|
|
881
|
-
let response = callLog.route.config.response;
|
|
882
|
-
while (true) if (typeof response === "function") response = response(callLog);
|
|
883
|
-
else if (isPromise(response)) response = await response;
|
|
884
|
-
else return response;
|
|
885
|
-
};
|
|
886
|
-
var Router = class {
|
|
887
|
-
constructor(fetchMockConfig, { routes, fallbackRoute } = {}) {
|
|
888
|
-
this.config = fetchMockConfig;
|
|
889
|
-
this.routes = routes || [];
|
|
890
|
-
this.fallbackRoute = fallbackRoute;
|
|
891
|
-
}
|
|
892
|
-
needsToReadBody(request) {
|
|
893
|
-
return Boolean(request && this.routes.some((route) => route.config.usesBody));
|
|
894
|
-
}
|
|
895
|
-
execute(callLog) {
|
|
896
|
-
throwSpecExceptions(callLog);
|
|
897
|
-
return new Promise(async (resolve, reject) => {
|
|
898
|
-
const { url, options, request, pendingPromises } = callLog;
|
|
899
|
-
let eventListenerAbortController;
|
|
900
|
-
if (callLog.signal) {
|
|
901
|
-
const abort = () => {
|
|
902
|
-
const error = new DOMException("The operation was aborted.", "AbortError");
|
|
903
|
-
const requestBody = request?.body || options?.body;
|
|
904
|
-
if (requestBody instanceof ReadableStream) if (requestBody.locked) console.warn("fetch-mock: Locked request body can't be cancelled");
|
|
905
|
-
else requestBody.cancel(error);
|
|
906
|
-
if (callLog?.response?.body) if (callLog.response.body.locked) console.warn("fetch-mock: Locked response body can't be cancelled");
|
|
907
|
-
else callLog.response.body.cancel(error);
|
|
908
|
-
reject(error);
|
|
909
|
-
};
|
|
910
|
-
if (callLog.signal.aborted) abort();
|
|
911
|
-
eventListenerAbortController = new AbortController();
|
|
912
|
-
callLog.signal.addEventListener("abort", abort, {
|
|
913
|
-
once: true,
|
|
914
|
-
signal: eventListenerAbortController.signal
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
if (this.needsToReadBody(request)) options.body = await options.body;
|
|
918
|
-
const route = (this.fallbackRoute ? [...this.routes, this.fallbackRoute] : this.routes).find((route) => route.matcher(callLog));
|
|
919
|
-
if (route) try {
|
|
920
|
-
callLog.route = route;
|
|
921
|
-
const { response, responseOptions, responseInput } = await this.generateResponse(callLog);
|
|
922
|
-
const observableResponse = this.createObservableResponse(response, responseOptions, responseInput, url, pendingPromises);
|
|
923
|
-
callLog.response = response;
|
|
924
|
-
resolve(observableResponse);
|
|
925
|
-
} catch (err) {
|
|
926
|
-
reject(err);
|
|
927
|
-
} finally {
|
|
928
|
-
eventListenerAbortController?.abort();
|
|
929
|
-
}
|
|
930
|
-
else reject(/* @__PURE__ */ new Error(`fetch-mock: No response or fallback rule to cover ${options && options.method || "GET"} to ${url}`));
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
async generateResponse(callLog) {
|
|
934
|
-
const responseInput = await resolveUntilResponseConfig(callLog);
|
|
935
|
-
if (responseInput instanceof Response) return {
|
|
936
|
-
response: responseInput.clone(),
|
|
937
|
-
responseOptions: {},
|
|
938
|
-
responseInput: {}
|
|
939
|
-
};
|
|
940
|
-
const responseConfig = normalizeResponseInput(responseInput);
|
|
941
|
-
if (responseConfig.throws) throw responseConfig.throws;
|
|
942
|
-
return callLog.route.constructResponse(responseConfig);
|
|
943
|
-
}
|
|
944
|
-
createObservableResponse(response, responseConfig, responseInput, responseUrl, pendingPromises) {
|
|
945
|
-
return new Proxy(response, { get: (originalResponse, name) => {
|
|
946
|
-
if (responseInput.redirectUrl) {
|
|
947
|
-
if (name === "url") return responseInput.redirectUrl;
|
|
948
|
-
if (name === "redirected") return true;
|
|
949
|
-
} else {
|
|
950
|
-
if (name === "url") return responseUrl;
|
|
951
|
-
if (name === "redirected") return false;
|
|
952
|
-
}
|
|
953
|
-
if (responseInput.status === 0) {
|
|
954
|
-
if (name === "status") return 0;
|
|
955
|
-
if (name === "statusText") return "";
|
|
956
|
-
}
|
|
957
|
-
if (typeof response[name] === "function") return new Proxy(response[name], { apply: (func, thisArg, args) => {
|
|
958
|
-
const result = func.apply(response, args);
|
|
959
|
-
if (result.then) pendingPromises.push(result.catch(() => void 0));
|
|
960
|
-
return result;
|
|
961
|
-
} });
|
|
962
|
-
return originalResponse[name];
|
|
963
|
-
} });
|
|
964
|
-
}
|
|
965
|
-
addRoute(matcher, response, nameOrOptions) {
|
|
966
|
-
const config = {};
|
|
967
|
-
if (matcher instanceof RouteConfigWrapper) Object.assign(config, matcher);
|
|
968
|
-
if (isUrlMatcher(matcher)) config.url = matcher;
|
|
969
|
-
else if (isFunctionMatcher(matcher)) config.matcherFunction = matcher;
|
|
970
|
-
else Object.assign(config, matcher);
|
|
971
|
-
if (typeof response !== "undefined") config.response = response;
|
|
972
|
-
if (nameOrOptions) Object.assign(config, typeof nameOrOptions === "string" ? nameToOptions(nameOrOptions) : nameOrOptions);
|
|
973
|
-
const route = new Route({
|
|
974
|
-
...this.config,
|
|
975
|
-
...config
|
|
976
|
-
});
|
|
977
|
-
if (route.config.name && this.routes.some(({ config: { name: existingName } }) => route.config.name === existingName)) throw new Error("fetch-mock: Adding route with same name as existing route.");
|
|
978
|
-
if (route.config.waitFor) {
|
|
979
|
-
const routeNamesToWaitFor = Array.isArray(route.config.waitFor) ? route.config.waitFor : [route.config.waitFor];
|
|
980
|
-
const routesToAwait = [];
|
|
981
|
-
routeNamesToWaitFor.forEach((routeName) => {
|
|
982
|
-
const routeToAwait = this.routes.find(({ config: { name: existingName } }) => routeName === existingName);
|
|
983
|
-
if (routeToAwait) routesToAwait.push(routeToAwait);
|
|
984
|
-
else throw new Error(`Cannot wait for route \`${routeName}\`: route of that name does not exist`);
|
|
985
|
-
});
|
|
986
|
-
route.waitFor(routesToAwait);
|
|
987
|
-
}
|
|
988
|
-
this.routes.push(route);
|
|
989
|
-
}
|
|
990
|
-
setFallback(response) {
|
|
991
|
-
if (this.fallbackRoute) console.warn("calling fetchMock.catch() twice - are you sure you want to overwrite the previous fallback response");
|
|
992
|
-
this.fallbackRoute = new Route({
|
|
993
|
-
matcherFunction: () => true,
|
|
994
|
-
response: response || "ok",
|
|
995
|
-
...this.config
|
|
996
|
-
});
|
|
997
|
-
this.fallbackRoute.config.isFallback = true;
|
|
998
|
-
}
|
|
999
|
-
removeRoutes({ names, includeSticky, includeFallback } = {}) {
|
|
1000
|
-
includeFallback = includeFallback ?? true;
|
|
1001
|
-
this.routes = this.routes.filter(({ config: { sticky, name } }) => {
|
|
1002
|
-
if (sticky && !includeSticky) return true;
|
|
1003
|
-
if (!names) return false;
|
|
1004
|
-
return !names.includes(name);
|
|
1005
|
-
});
|
|
1006
|
-
if (includeFallback) delete this.fallbackRoute;
|
|
1007
|
-
}
|
|
1008
|
-
modifyRoute(routeName, options) {
|
|
1009
|
-
const route = this.routes.find(({ config: { name } }) => name === routeName);
|
|
1010
|
-
if (!route) throw new Error(`Cannot call modifyRoute() on route \`${routeName}\`: route of that name not found`);
|
|
1011
|
-
if (route.config.sticky) throw new Error(`Cannot call modifyRoute() on route \`${routeName}\`: route is sticky and cannot be modified`);
|
|
1012
|
-
if ("name" in options) throw new Error(`Cannot rename the route \`${routeName}\` as \`${options.name}\`: renaming routes is not supported`);
|
|
1013
|
-
if ("sticky" in options) throw new Error(`Altering the stickiness of route \`${routeName}\` is not supported`);
|
|
1014
|
-
const newConfig = {
|
|
1015
|
-
...route.config,
|
|
1016
|
-
...options
|
|
1017
|
-
};
|
|
1018
|
-
Object.entries(options).forEach(([key, value]) => {
|
|
1019
|
-
if (value === null) delete newConfig[key];
|
|
1020
|
-
});
|
|
1021
|
-
route.init(newConfig);
|
|
1022
|
-
}
|
|
1023
|
-
};
|
|
1024
|
-
//#endregion
|
|
1025
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/CallHistory.js
|
|
1026
|
-
const isName = (filter) => typeof filter === "string" && /^[\da-zA-Z-]+$/.test(filter) && !["matched", "unmatched"].includes(filter);
|
|
1027
|
-
const isMatchedOrUnmatched = (filter) => typeof filter === "boolean" || ["matched", "unmatched"].includes(filter);
|
|
1028
|
-
var CallHistory = class {
|
|
1029
|
-
constructor(config, router) {
|
|
1030
|
-
this.callLogs = [];
|
|
1031
|
-
this.config = config;
|
|
1032
|
-
this.router = router;
|
|
1033
|
-
}
|
|
1034
|
-
recordCall(callLog) {
|
|
1035
|
-
this.callLogs.push(callLog);
|
|
1036
|
-
}
|
|
1037
|
-
clear() {
|
|
1038
|
-
this.callLogs.forEach(({ route }) => {
|
|
1039
|
-
if (route) route.reset();
|
|
1040
|
-
});
|
|
1041
|
-
this.callLogs = [];
|
|
1042
|
-
}
|
|
1043
|
-
async flush(waitForResponseMethods) {
|
|
1044
|
-
const queuedPromises = this.callLogs.flatMap((call) => call.pendingPromises);
|
|
1045
|
-
await Promise.allSettled(queuedPromises);
|
|
1046
|
-
if (waitForResponseMethods) {
|
|
1047
|
-
await Promise.resolve();
|
|
1048
|
-
await this.flush();
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
calls(filter, options) {
|
|
1052
|
-
let calls = [...this.callLogs];
|
|
1053
|
-
if (typeof filter === "undefined" && !options) return calls;
|
|
1054
|
-
if (isMatchedOrUnmatched(filter)) {
|
|
1055
|
-
if ([true, "matched"].includes(filter)) calls = calls.filter(({ route }) => !route?.config || !route.config.isFallback);
|
|
1056
|
-
else if ([false, "unmatched"].includes(filter)) calls = calls.filter(({ route }) => Boolean(route?.config && route.config.isFallback));
|
|
1057
|
-
if (!options) return calls;
|
|
1058
|
-
} else if (isName(filter)) {
|
|
1059
|
-
calls = calls.filter(({ route }) => route?.config?.name === filter);
|
|
1060
|
-
if (!options) return calls;
|
|
1061
|
-
} else if (isUrlMatcher(filter)) options = {
|
|
1062
|
-
url: filter,
|
|
1063
|
-
...options || {}
|
|
1064
|
-
};
|
|
1065
|
-
else options = {
|
|
1066
|
-
...filter,
|
|
1067
|
-
...options || {}
|
|
1068
|
-
};
|
|
1069
|
-
const { matcher } = new Route({
|
|
1070
|
-
response: "ok",
|
|
1071
|
-
...options
|
|
1072
|
-
});
|
|
1073
|
-
calls = calls.filter(({ url, options }) => {
|
|
1074
|
-
return matcher(createCallLogFromUrlAndOptions(url, options));
|
|
1075
|
-
});
|
|
1076
|
-
return calls;
|
|
1077
|
-
}
|
|
1078
|
-
called(filter, options) {
|
|
1079
|
-
return Boolean(this.calls(filter, options).length);
|
|
1080
|
-
}
|
|
1081
|
-
lastCall(filter, options) {
|
|
1082
|
-
return this.calls(filter, options).pop();
|
|
1083
|
-
}
|
|
1084
|
-
done(routeNames) {
|
|
1085
|
-
let routesToCheck = this.router.routes;
|
|
1086
|
-
if (routeNames) {
|
|
1087
|
-
routeNames = Array.isArray(routeNames) ? routeNames : [routeNames];
|
|
1088
|
-
routesToCheck = this.router.routes.filter(({ config: { name } }) => routeNames.includes(name));
|
|
1089
|
-
}
|
|
1090
|
-
return routesToCheck.map((route) => {
|
|
1091
|
-
const calls = this.callLogs.filter(({ route: routeApplied }) => routeApplied === route);
|
|
1092
|
-
if (!calls.length) {
|
|
1093
|
-
console.warn(`Warning: ${route.config.name} not called`);
|
|
1094
|
-
return false;
|
|
1095
|
-
}
|
|
1096
|
-
const expectedTimes = route.config.repeat;
|
|
1097
|
-
if (!expectedTimes) return true;
|
|
1098
|
-
const actualTimes = calls.length;
|
|
1099
|
-
if (expectedTimes > actualTimes) {
|
|
1100
|
-
console.warn(`Warning: ${route.config.name} only called ${actualTimes} times, but ${expectedTimes} expected`);
|
|
1101
|
-
return false;
|
|
1102
|
-
}
|
|
1103
|
-
return true;
|
|
1104
|
-
}).every((isDone) => isDone);
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
//#endregion
|
|
1108
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/FetchMock.js
|
|
1109
|
-
const defaultFetchMockConfig = {
|
|
1110
|
-
includeContentLength: true,
|
|
1111
|
-
matchPartialBody: false,
|
|
1112
|
-
Request: globalThis.Request,
|
|
1113
|
-
Response: globalThis.Response,
|
|
1114
|
-
Headers: globalThis.Headers,
|
|
1115
|
-
fetch: globalThis.fetch
|
|
1116
|
-
};
|
|
1117
|
-
const defineShorthand = (shorthandOptions) => {
|
|
1118
|
-
function shorthand(matcher, response, options) {
|
|
1119
|
-
return this.route(matcher, response, Object.assign(options || {}, shorthandOptions));
|
|
1120
|
-
}
|
|
1121
|
-
return shorthand;
|
|
1122
|
-
};
|
|
1123
|
-
const defineGreedyShorthand = (shorthandOptions) => {
|
|
1124
|
-
return function(response, options) {
|
|
1125
|
-
return this.route("*", response, Object.assign(options || {}, shorthandOptions));
|
|
1126
|
-
};
|
|
1127
|
-
};
|
|
1128
|
-
//#endregion
|
|
1129
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/index.js
|
|
1130
|
-
var esm_default = new class FetchMock {
|
|
1131
|
-
constructor(config, router) {
|
|
1132
|
-
this.sticky = defineShorthand({ sticky: true });
|
|
1133
|
-
this.once = defineShorthand({ repeat: 1 });
|
|
1134
|
-
this.any = defineGreedyShorthand({});
|
|
1135
|
-
this.anyOnce = defineGreedyShorthand({ repeat: 1 });
|
|
1136
|
-
this.get = defineShorthand({ method: "get" });
|
|
1137
|
-
this.getOnce = defineShorthand({
|
|
1138
|
-
method: "get",
|
|
1139
|
-
repeat: 1
|
|
1140
|
-
});
|
|
1141
|
-
this.post = defineShorthand({ method: "post" });
|
|
1142
|
-
this.postOnce = defineShorthand({
|
|
1143
|
-
method: "post",
|
|
1144
|
-
repeat: 1
|
|
1145
|
-
});
|
|
1146
|
-
this.put = defineShorthand({ method: "put" });
|
|
1147
|
-
this.putOnce = defineShorthand({
|
|
1148
|
-
method: "put",
|
|
1149
|
-
repeat: 1
|
|
1150
|
-
});
|
|
1151
|
-
this.delete = defineShorthand({ method: "delete" });
|
|
1152
|
-
this.deleteOnce = defineShorthand({
|
|
1153
|
-
method: "delete",
|
|
1154
|
-
repeat: 1
|
|
1155
|
-
});
|
|
1156
|
-
this.head = defineShorthand({ method: "head" });
|
|
1157
|
-
this.headOnce = defineShorthand({
|
|
1158
|
-
method: "head",
|
|
1159
|
-
repeat: 1
|
|
1160
|
-
});
|
|
1161
|
-
this.patch = defineShorthand({ method: "patch" });
|
|
1162
|
-
this.patchOnce = defineShorthand({
|
|
1163
|
-
method: "patch",
|
|
1164
|
-
repeat: 1
|
|
1165
|
-
});
|
|
1166
|
-
this.config = config;
|
|
1167
|
-
this.router = new Router(this.config, {
|
|
1168
|
-
routes: router ? [...router.routes] : [],
|
|
1169
|
-
fallbackRoute: router ? router.fallbackRoute : null
|
|
1170
|
-
});
|
|
1171
|
-
this.callHistory = new CallHistory(this.config, this.router);
|
|
1172
|
-
this.fetchHandler = this.fetchHandler.bind(this);
|
|
1173
|
-
Object.assign(this.fetchHandler, { fetchMock: this });
|
|
1174
|
-
}
|
|
1175
|
-
createInstance() {
|
|
1176
|
-
return new FetchMock({ ...this.config }, this.router);
|
|
1177
|
-
}
|
|
1178
|
-
async fetchHandler(requestInput, requestInit) {
|
|
1179
|
-
let callLog;
|
|
1180
|
-
if (requestInput instanceof this.config.Request) callLog = await createCallLogFromRequest(requestInput, requestInit);
|
|
1181
|
-
else callLog = createCallLogFromUrlAndOptions(requestInput, requestInit);
|
|
1182
|
-
this.callHistory.recordCall(callLog);
|
|
1183
|
-
const responsePromise = this.router.execute(callLog);
|
|
1184
|
-
callLog.pendingPromises.push(responsePromise);
|
|
1185
|
-
return responsePromise;
|
|
1186
|
-
}
|
|
1187
|
-
route(matcher, response, options) {
|
|
1188
|
-
this.router.addRoute(matcher, response, options);
|
|
1189
|
-
return this;
|
|
1190
|
-
}
|
|
1191
|
-
catch(response) {
|
|
1192
|
-
this.router.setFallback(response);
|
|
1193
|
-
return this;
|
|
1194
|
-
}
|
|
1195
|
-
defineMatcher(matcher) {
|
|
1196
|
-
Route.defineMatcher(matcher);
|
|
1197
|
-
}
|
|
1198
|
-
removeRoutes(options) {
|
|
1199
|
-
this.router.removeRoutes(options);
|
|
1200
|
-
return this;
|
|
1201
|
-
}
|
|
1202
|
-
removeRoute(routeName) {
|
|
1203
|
-
this.router.removeRoutes({ names: [routeName] });
|
|
1204
|
-
return this;
|
|
1205
|
-
}
|
|
1206
|
-
modifyRoute(routeName, options) {
|
|
1207
|
-
this.router.modifyRoute(routeName, options);
|
|
1208
|
-
return this;
|
|
1209
|
-
}
|
|
1210
|
-
clearHistory() {
|
|
1211
|
-
this.callHistory.clear();
|
|
1212
|
-
return this;
|
|
1213
|
-
}
|
|
1214
|
-
mockGlobal() {
|
|
1215
|
-
globalThis.fetch = this.fetchHandler;
|
|
1216
|
-
return this;
|
|
1217
|
-
}
|
|
1218
|
-
unmockGlobal() {
|
|
1219
|
-
globalThis.fetch = this.config.fetch;
|
|
1220
|
-
return this;
|
|
1221
|
-
}
|
|
1222
|
-
hardReset(options) {
|
|
1223
|
-
this.clearHistory();
|
|
1224
|
-
this.removeRoutes(options);
|
|
1225
|
-
this.unmockGlobal();
|
|
1226
|
-
return this;
|
|
1227
|
-
}
|
|
1228
|
-
spy(matcher, name) {
|
|
1229
|
-
const boundFetch = this.config.fetch.bind(globalThis);
|
|
1230
|
-
if (matcher) this.route(matcher, ({ args }) => boundFetch(...args), name);
|
|
1231
|
-
else this.catch(({ args }) => boundFetch(...args));
|
|
1232
|
-
return this;
|
|
1233
|
-
}
|
|
1234
|
-
spyGlobal() {
|
|
1235
|
-
this.mockGlobal();
|
|
1236
|
-
return this.spy();
|
|
1237
|
-
}
|
|
1238
|
-
}({ ...defaultFetchMockConfig });
|
|
1239
|
-
//#endregion
|
|
1240
13
|
//#region src/docloader.test.ts
|
|
1241
14
|
test("getRemoteDocument() forwards options to alternate documents", async () => {
|
|
1242
15
|
const records = [];
|
|
@@ -1284,6 +57,24 @@ test("getRemoteDocument() forwards options to alternate documents", async () =>
|
|
|
1284
57
|
await reset();
|
|
1285
58
|
}
|
|
1286
59
|
});
|
|
60
|
+
const unpinnedPublicFetch = createPublicFetch({
|
|
61
|
+
pinner: () => Promise.resolve(null),
|
|
62
|
+
lookup: () => Promise.reject(/* @__PURE__ */ new Error("Unexpected default lookup"))
|
|
63
|
+
});
|
|
64
|
+
const PUBLIC_ADDRESS = {
|
|
65
|
+
address: "93.184.215.14",
|
|
66
|
+
family: 4
|
|
67
|
+
};
|
|
68
|
+
const PRIVATE_ADDRESS = {
|
|
69
|
+
address: "10.0.0.1",
|
|
70
|
+
family: 4
|
|
71
|
+
};
|
|
72
|
+
function lookupTestAddresses(hostname) {
|
|
73
|
+
return Promise.resolve([hostname === "private.example" ? PRIVATE_ADDRESS : PUBLIC_ADDRESS]);
|
|
74
|
+
}
|
|
75
|
+
function openUnpinnedHop(url) {
|
|
76
|
+
return unpinnedPublicFetch.openPublicFetch(url, { lookup: lookupTestAddresses });
|
|
77
|
+
}
|
|
1287
78
|
test("new FetchError()", () => {
|
|
1288
79
|
const e = new FetchError("https://example.com/", "An error message.");
|
|
1289
80
|
deepStrictEqual(e.name, "FetchError");
|
|
@@ -1298,7 +89,7 @@ test("new FetchError()", () => {
|
|
|
1298
89
|
deepStrictEqual(e2.response.status, 410);
|
|
1299
90
|
});
|
|
1300
91
|
test("getDocumentLoader()", async (t) => {
|
|
1301
|
-
const fetchDocumentLoader =
|
|
92
|
+
const fetchDocumentLoader = createDocumentLoader({}, { openHop: openUnpinnedHop });
|
|
1302
93
|
esm_default.spyGlobal();
|
|
1303
94
|
esm_default.get("https://example.com/object", { body: {
|
|
1304
95
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
@@ -1765,10 +556,26 @@ test("getDocumentLoader()", async (t) => {
|
|
|
1765
556
|
name: "Fetched object",
|
|
1766
557
|
type: "Object"
|
|
1767
558
|
} });
|
|
559
|
+
esm_default.get("https://example.com/private-redirect", {
|
|
560
|
+
status: 302,
|
|
561
|
+
headers: { Location: "https://private.example/object" }
|
|
562
|
+
});
|
|
563
|
+
esm_default.get("https://private.example/object", { body: {
|
|
564
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
565
|
+
id: "https://private.example/object",
|
|
566
|
+
type: "Object"
|
|
567
|
+
} });
|
|
1768
568
|
await t.step("allowPrivateAddress: false", async () => {
|
|
1769
569
|
await rejects(() => fetchDocumentLoader("https://localhost/object"), UrlError);
|
|
1770
570
|
await rejects(() => fetchDocumentLoader("https://example.com/localhost-redirect"), UrlError);
|
|
1771
571
|
await rejects(() => fetchDocumentLoader("https://example.com/localhost-link"), UrlError);
|
|
572
|
+
await rejects(() => fetchDocumentLoader("https://private.example/object"), UrlError);
|
|
573
|
+
await rejects(() => fetchDocumentLoader("https://example.com/private-redirect"), UrlError);
|
|
574
|
+
deepStrictEqual(esm_default.callHistory.calls("https://private.example/object").length, 0);
|
|
575
|
+
const defaultLoader = getDocumentLoader();
|
|
576
|
+
await rejects(() => defaultLoader("https://localhost/object"), UrlError);
|
|
577
|
+
await rejects(() => defaultLoader("https://127.0.0.1/object"), UrlError);
|
|
578
|
+
deepStrictEqual(esm_default.callHistory.calls("https://localhost/object").length, 0);
|
|
1772
579
|
});
|
|
1773
580
|
const fetchDocumentLoader2 = getDocumentLoader({ allowPrivateAddress: true });
|
|
1774
581
|
await t.step("allowPrivateAddress: true", async () => {
|
|
@@ -1801,7 +608,7 @@ test("getDocumentLoader()", async (t) => {
|
|
|
1801
608
|
});
|
|
1802
609
|
await t.step("custom max redirection", async () => {
|
|
1803
610
|
redirectAttempts = 0;
|
|
1804
|
-
const loader =
|
|
611
|
+
const loader = createDocumentLoader({ maxRedirection: 1 }, { openHop: openUnpinnedHop });
|
|
1805
612
|
await rejects(() => loader("https://example.com/too-many-redirects/0"), FetchError, "Too many redirections");
|
|
1806
613
|
deepStrictEqual(redirectAttempts, 2);
|
|
1807
614
|
});
|
|
@@ -1929,18 +736,14 @@ test("getRemoteDocument() bounds JSON by default", async () => {
|
|
|
1929
736
|
deepStrictEqual(pulls, 257);
|
|
1930
737
|
});
|
|
1931
738
|
test("getDocumentLoader() logs DNS failures as such", async (t) => {
|
|
1932
|
-
if ("Deno" in globalThis && (await Deno.permissions.query({ name: "net" })).state !== "granted") throw new Error("This DNS test requires Deno network permission (--allow-net).");
|
|
1933
|
-
const loader = getDocumentLoader();
|
|
1934
739
|
for (const result of [
|
|
1935
740
|
"throws",
|
|
1936
741
|
"empty",
|
|
1937
|
-
"private"
|
|
742
|
+
"private",
|
|
743
|
+
"default"
|
|
1938
744
|
]) await t.step(result, async () => {
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
address: "127.0.0.1",
|
|
1942
|
-
family: 4
|
|
1943
|
-
}]));
|
|
745
|
+
const lookup = () => result === "throws" ? Promise.reject(/* @__PURE__ */ new Error("Resolver unavailable")) : Promise.resolve(result === "empty" ? [] : [PRIVATE_ADDRESS]);
|
|
746
|
+
const loader = result === "default" ? getDocumentLoader() : createDocumentLoader({}, { openHop: (url) => unpinnedPublicFetch.openPublicFetch(url, { lookup }) });
|
|
1944
747
|
const records = [];
|
|
1945
748
|
await configure({
|
|
1946
749
|
sinks: { buffer: (record) => records.push(record) },
|
|
@@ -1955,19 +758,20 @@ test("getDocumentLoader() logs DNS failures as such", async (t) => {
|
|
|
1955
758
|
reset: true
|
|
1956
759
|
});
|
|
1957
760
|
try {
|
|
1958
|
-
const url = "https://dns-failure.invalid/object";
|
|
761
|
+
const url = result === "default" ? "https://10.0.0.1/object" : "https://dns-failure.invalid/object";
|
|
1959
762
|
let error;
|
|
1960
763
|
await rejects(() => loader(url), (e) => {
|
|
1961
764
|
error = e;
|
|
1962
765
|
return true;
|
|
1963
766
|
});
|
|
1964
767
|
ok(error instanceof UrlError);
|
|
1965
|
-
|
|
768
|
+
const disallowed = result === "private" || result === "default";
|
|
769
|
+
deepStrictEqual(error.reason, disallowed ? "disallowed" : "dns");
|
|
1966
770
|
deepStrictEqual(records.map((r) => [
|
|
1967
771
|
r.level,
|
|
1968
772
|
r.rawMessage,
|
|
1969
773
|
r.properties.url
|
|
1970
|
-
]), [
|
|
774
|
+
]), [disallowed ? [
|
|
1971
775
|
"error",
|
|
1972
776
|
"Disallowed private URL: {url}",
|
|
1973
777
|
url
|
|
@@ -1979,7 +783,6 @@ test("getDocumentLoader() logs DNS failures as such", async (t) => {
|
|
|
1979
783
|
ok(records[0].properties.error === error);
|
|
1980
784
|
} finally {
|
|
1981
785
|
await reset();
|
|
1982
|
-
dns.lookup = originalLookup;
|
|
1983
786
|
}
|
|
1984
787
|
});
|
|
1985
788
|
});
|
|
@@ -2277,7 +1080,6 @@ test("getDocumentLoader() lets the caller's signal abort a request", async () =>
|
|
|
2277
1080
|
});
|
|
2278
1081
|
});
|
|
2279
1082
|
test("getDocumentLoader() bounds DNS lookups that ignore the timeout", async () => {
|
|
2280
|
-
if ("Deno" in globalThis && (await Deno.permissions.query({ name: "net" })).state !== "granted") throw new Error("This DNS test requires Deno network permission (--allow-net).");
|
|
2281
1083
|
esm_default.mockGlobal();
|
|
2282
1084
|
let requests = 0;
|
|
2283
1085
|
const url = "https://slow-dns.example/object";
|
|
@@ -2285,23 +1087,21 @@ test("getDocumentLoader() bounds DNS lookups that ignore the timeout", async ()
|
|
|
2285
1087
|
requests++;
|
|
2286
1088
|
return Response.json({ id: url });
|
|
2287
1089
|
});
|
|
2288
|
-
const originalLookup = dns.lookup;
|
|
2289
1090
|
let resolveLookup = () => {};
|
|
2290
1091
|
const lookedUp = new Promise((resolve) => resolveLookup = resolve);
|
|
2291
|
-
|
|
1092
|
+
const lookup = () => new Promise((resolve) => setTimeout(() => {
|
|
2292
1093
|
resolve([{
|
|
2293
1094
|
address: "93.184.215.14",
|
|
2294
1095
|
family: 4
|
|
2295
1096
|
}]);
|
|
2296
1097
|
resolveLookup();
|
|
2297
|
-
}, 200))
|
|
1098
|
+
}, 200));
|
|
2298
1099
|
try {
|
|
2299
|
-
await rejects(
|
|
1100
|
+
await rejects(createDocumentLoader({ timeout: 50 }, { openHop: (url) => unpinnedPublicFetch.openPublicFetch(url, { lookup }) })(url), (e) => isTimeoutFetchError(e, url));
|
|
2300
1101
|
await lookedUp;
|
|
2301
1102
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
2302
1103
|
deepStrictEqual(requests, 0);
|
|
2303
1104
|
} finally {
|
|
2304
|
-
dns.lookup = originalLookup;
|
|
2305
1105
|
esm_default.hardReset();
|
|
2306
1106
|
}
|
|
2307
1107
|
});
|
|
@@ -2483,5 +1283,425 @@ for (const url of unsupportedUrls) {
|
|
|
2483
1283
|
});
|
|
2484
1284
|
});
|
|
2485
1285
|
}
|
|
1286
|
+
function createHopRecorder(responder) {
|
|
1287
|
+
const events = [];
|
|
1288
|
+
const states = /* @__PURE__ */ new Map();
|
|
1289
|
+
const violations = [];
|
|
1290
|
+
let responses = 0;
|
|
1291
|
+
let opens = 0;
|
|
1292
|
+
let closes = 0;
|
|
1293
|
+
function respond(url) {
|
|
1294
|
+
const n = ++responses;
|
|
1295
|
+
events.push(`fetch ${url} #${n}`);
|
|
1296
|
+
const { status = 200, headers, body = "", failCancel, hangCancel, responseUrl } = responder(url);
|
|
1297
|
+
const state = {
|
|
1298
|
+
n,
|
|
1299
|
+
settled: false
|
|
1300
|
+
};
|
|
1301
|
+
let sent = false;
|
|
1302
|
+
const stream = new ReadableStream({
|
|
1303
|
+
pull(controller) {
|
|
1304
|
+
if (!sent && body !== "") {
|
|
1305
|
+
sent = true;
|
|
1306
|
+
controller.enqueue(new TextEncoder().encode(body));
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
controller.close();
|
|
1310
|
+
state.settled = true;
|
|
1311
|
+
events.push(`consumed #${n}`);
|
|
1312
|
+
},
|
|
1313
|
+
cancel() {
|
|
1314
|
+
state.settled = true;
|
|
1315
|
+
events.push(`cancel #${n}`);
|
|
1316
|
+
if (failCancel) throw new Error(`Failed to cancel #${n}`);
|
|
1317
|
+
if (hangCancel) return new Promise(() => {});
|
|
1318
|
+
}
|
|
1319
|
+
}, { highWaterMark: 0 });
|
|
1320
|
+
const response = new Response(stream, {
|
|
1321
|
+
status,
|
|
1322
|
+
headers
|
|
1323
|
+
});
|
|
1324
|
+
if (responseUrl != null) Object.defineProperty(response, "url", { value: responseUrl });
|
|
1325
|
+
states.set(response, state);
|
|
1326
|
+
return response;
|
|
1327
|
+
}
|
|
1328
|
+
function record(url, session) {
|
|
1329
|
+
opens++;
|
|
1330
|
+
events.push(`open ${url}`);
|
|
1331
|
+
const fetched = [];
|
|
1332
|
+
let closed = false;
|
|
1333
|
+
return {
|
|
1334
|
+
get url() {
|
|
1335
|
+
return session.url;
|
|
1336
|
+
},
|
|
1337
|
+
async fetch(input, init) {
|
|
1338
|
+
const response = await session.fetch(input, init);
|
|
1339
|
+
fetched.push(response);
|
|
1340
|
+
return response;
|
|
1341
|
+
},
|
|
1342
|
+
async close() {
|
|
1343
|
+
if (closed) return;
|
|
1344
|
+
closed = true;
|
|
1345
|
+
for (const response of fetched) {
|
|
1346
|
+
const state = states.get(response);
|
|
1347
|
+
if (state != null && !state.settled) violations.push(`#${state.n} is still open when closing ${url}`);
|
|
1348
|
+
}
|
|
1349
|
+
closes++;
|
|
1350
|
+
events.push(`close ${url}`);
|
|
1351
|
+
await session.close();
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
function openHop(url) {
|
|
1356
|
+
const origin = new URL(url).origin;
|
|
1357
|
+
return Promise.resolve(record(url, {
|
|
1358
|
+
url: new URL(url),
|
|
1359
|
+
fetch(input) {
|
|
1360
|
+
const target = input instanceof Request ? input.url : String(input);
|
|
1361
|
+
ok(new URL(target).origin === origin, `${target} is not on ${origin}`);
|
|
1362
|
+
return Promise.resolve(respond(target));
|
|
1363
|
+
},
|
|
1364
|
+
close: () => Promise.resolve()
|
|
1365
|
+
}));
|
|
1366
|
+
}
|
|
1367
|
+
return {
|
|
1368
|
+
events,
|
|
1369
|
+
respond,
|
|
1370
|
+
record,
|
|
1371
|
+
openHop,
|
|
1372
|
+
assertInvariants() {
|
|
1373
|
+
deepStrictEqual(violations, []);
|
|
1374
|
+
deepStrictEqual(opens, closes);
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
const lifecycleDocument = {
|
|
1379
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
1380
|
+
id: "https://b.example/object",
|
|
1381
|
+
type: "Object"
|
|
1382
|
+
};
|
|
1383
|
+
test("getDocumentLoader() closes a redirect hop before the next hop", async () => {
|
|
1384
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1385
|
+
status: 302,
|
|
1386
|
+
headers: { Location: "https://b.example/object" }
|
|
1387
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1388
|
+
deepStrictEqual(await createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start"), {
|
|
1389
|
+
contextUrl: null,
|
|
1390
|
+
documentUrl: "https://b.example/object",
|
|
1391
|
+
document: lifecycleDocument
|
|
1392
|
+
});
|
|
1393
|
+
deepStrictEqual(recorder.events, [
|
|
1394
|
+
"open https://a.example/start",
|
|
1395
|
+
"fetch https://a.example/start #1",
|
|
1396
|
+
"cancel #1",
|
|
1397
|
+
"close https://a.example/start",
|
|
1398
|
+
"open https://b.example/object",
|
|
1399
|
+
"fetch https://b.example/object #2",
|
|
1400
|
+
"consumed #2",
|
|
1401
|
+
"close https://b.example/object"
|
|
1402
|
+
]);
|
|
1403
|
+
recorder.assertInvariants();
|
|
1404
|
+
});
|
|
1405
|
+
test("getDocumentLoader() cancels the body before a Link header alternate", async () => {
|
|
1406
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1407
|
+
headers: {
|
|
1408
|
+
"Content-Type": "text/plain",
|
|
1409
|
+
Link: "<https://b.example/object>; rel=\"alternate\"; type=\"application/activity+json\""
|
|
1410
|
+
},
|
|
1411
|
+
body: "not JSON"
|
|
1412
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1413
|
+
deepStrictEqual((await createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start")).documentUrl, "https://b.example/object");
|
|
1414
|
+
deepStrictEqual(recorder.events, [
|
|
1415
|
+
"open https://a.example/start",
|
|
1416
|
+
"fetch https://a.example/start #1",
|
|
1417
|
+
"cancel #1",
|
|
1418
|
+
"close https://a.example/start",
|
|
1419
|
+
"open https://b.example/object",
|
|
1420
|
+
"fetch https://b.example/object #2",
|
|
1421
|
+
"consumed #2",
|
|
1422
|
+
"close https://b.example/object"
|
|
1423
|
+
]);
|
|
1424
|
+
recorder.assertInvariants();
|
|
1425
|
+
});
|
|
1426
|
+
test("getDocumentLoader() reads the body before an HTML alternate", async () => {
|
|
1427
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1428
|
+
headers: { "Content-Type": "text/html" },
|
|
1429
|
+
body: "<link rel=\"alternate\" type=\"application/activity+json\" href=\"https://b.example/object\">"
|
|
1430
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1431
|
+
deepStrictEqual((await createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start")).documentUrl, "https://b.example/object");
|
|
1432
|
+
deepStrictEqual(recorder.events, [
|
|
1433
|
+
"open https://a.example/start",
|
|
1434
|
+
"fetch https://a.example/start #1",
|
|
1435
|
+
"consumed #1",
|
|
1436
|
+
"close https://a.example/start",
|
|
1437
|
+
"open https://b.example/object",
|
|
1438
|
+
"fetch https://b.example/object #2",
|
|
1439
|
+
"consumed #2",
|
|
1440
|
+
"close https://b.example/object"
|
|
1441
|
+
]);
|
|
1442
|
+
recorder.assertInvariants();
|
|
1443
|
+
});
|
|
1444
|
+
/**
|
|
1445
|
+
* Fails instead of blocking the test if the given promise does not settle
|
|
1446
|
+
* within the given time.
|
|
1447
|
+
*/
|
|
1448
|
+
async function settlesWithin(promise, milliseconds = 1e3) {
|
|
1449
|
+
let timer;
|
|
1450
|
+
try {
|
|
1451
|
+
return await Promise.race([promise, new Promise((_, reject) => {
|
|
1452
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Did not settle in ${milliseconds} ms.`)), milliseconds);
|
|
1453
|
+
})]);
|
|
1454
|
+
} finally {
|
|
1455
|
+
clearTimeout(timer);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Runs the given function while capturing the document loader's logs, and
|
|
1460
|
+
* waits until the rejections of body cancellations started without being
|
|
1461
|
+
* awaited have been logged.
|
|
1462
|
+
*/
|
|
1463
|
+
async function captureDocumentLoaderLogs(fn) {
|
|
1464
|
+
const records = [];
|
|
1465
|
+
await configure({
|
|
1466
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
1467
|
+
loggers: [{
|
|
1468
|
+
category: [
|
|
1469
|
+
"fedify",
|
|
1470
|
+
"runtime",
|
|
1471
|
+
"docloader"
|
|
1472
|
+
],
|
|
1473
|
+
sinks: ["buffer"],
|
|
1474
|
+
lowestLevel: "debug"
|
|
1475
|
+
}, {
|
|
1476
|
+
category: ["logtape", "meta"],
|
|
1477
|
+
sinks: []
|
|
1478
|
+
}],
|
|
1479
|
+
reset: true
|
|
1480
|
+
});
|
|
1481
|
+
try {
|
|
1482
|
+
const result = await fn();
|
|
1483
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1484
|
+
return {
|
|
1485
|
+
result,
|
|
1486
|
+
records
|
|
1487
|
+
};
|
|
1488
|
+
} finally {
|
|
1489
|
+
await reset();
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function cancelFailureLogs(records) {
|
|
1493
|
+
return records.filter((record) => record.rawMessage === "Failed to cancel the response body from {url}: {error}").map((record) => [
|
|
1494
|
+
record.level,
|
|
1495
|
+
record.properties.url,
|
|
1496
|
+
String(record.properties.error)
|
|
1497
|
+
]);
|
|
1498
|
+
}
|
|
1499
|
+
function linkHeaderAlternate(next) {
|
|
1500
|
+
return {
|
|
1501
|
+
headers: {
|
|
1502
|
+
"Content-Type": "text/plain",
|
|
1503
|
+
Link: `<${next}>; rel="alternate"; type="application/activity+json"`
|
|
1504
|
+
},
|
|
1505
|
+
body: "not JSON"
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
test("getDocumentLoader() continues if an intermediate body fails to cancel", async (t) => {
|
|
1509
|
+
for (const kind of ["redirect", "Link header alternate"]) await t.step(kind, async () => {
|
|
1510
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1511
|
+
...kind === "redirect" ? {
|
|
1512
|
+
status: 302,
|
|
1513
|
+
headers: { Location: "https://b.example/object" }
|
|
1514
|
+
} : linkHeaderAlternate("https://b.example/object"),
|
|
1515
|
+
failCancel: true
|
|
1516
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1517
|
+
const loader = createDocumentLoader({}, { openHop: recorder.openHop });
|
|
1518
|
+
const { result, records } = await captureDocumentLoaderLogs(() => loader("https://a.example/start"));
|
|
1519
|
+
deepStrictEqual(result, {
|
|
1520
|
+
contextUrl: null,
|
|
1521
|
+
documentUrl: "https://b.example/object",
|
|
1522
|
+
document: lifecycleDocument
|
|
1523
|
+
});
|
|
1524
|
+
deepStrictEqual(recorder.events, [
|
|
1525
|
+
"open https://a.example/start",
|
|
1526
|
+
"fetch https://a.example/start #1",
|
|
1527
|
+
"cancel #1",
|
|
1528
|
+
"close https://a.example/start",
|
|
1529
|
+
"open https://b.example/object",
|
|
1530
|
+
"fetch https://b.example/object #2",
|
|
1531
|
+
"consumed #2",
|
|
1532
|
+
"close https://b.example/object"
|
|
1533
|
+
]);
|
|
1534
|
+
recorder.assertInvariants();
|
|
1535
|
+
deepStrictEqual(cancelFailureLogs(records), [[
|
|
1536
|
+
"debug",
|
|
1537
|
+
"https://a.example/start",
|
|
1538
|
+
"Error: Failed to cancel #1"
|
|
1539
|
+
]]);
|
|
1540
|
+
});
|
|
1541
|
+
});
|
|
1542
|
+
test("getDocumentLoader() does not wait for intermediate bodies to be cancelled", async (t) => {
|
|
1543
|
+
for (const kind of ["redirect", "Link header alternate"]) await t.step(kind, async () => {
|
|
1544
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1545
|
+
...kind === "redirect" ? {
|
|
1546
|
+
status: 302,
|
|
1547
|
+
headers: { Location: "https://b.example/object" }
|
|
1548
|
+
} : linkHeaderAlternate("https://b.example/object"),
|
|
1549
|
+
hangCancel: true
|
|
1550
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1551
|
+
deepStrictEqual((await settlesWithin(createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start"))).documentUrl, "https://b.example/object");
|
|
1552
|
+
deepStrictEqual(recorder.events, [
|
|
1553
|
+
"open https://a.example/start",
|
|
1554
|
+
"fetch https://a.example/start #1",
|
|
1555
|
+
"cancel #1",
|
|
1556
|
+
"close https://a.example/start",
|
|
1557
|
+
"open https://b.example/object",
|
|
1558
|
+
"fetch https://b.example/object #2",
|
|
1559
|
+
"consumed #2",
|
|
1560
|
+
"close https://b.example/object"
|
|
1561
|
+
]);
|
|
1562
|
+
recorder.assertInvariants();
|
|
1563
|
+
});
|
|
1564
|
+
await t.step("public session with a never-settling cancel", async () => {
|
|
1565
|
+
let cancelled = 0;
|
|
1566
|
+
const pinner = {
|
|
1567
|
+
supports: () => true,
|
|
1568
|
+
fetch: () => Promise.resolve(new Response(new ReadableStream({ cancel() {
|
|
1569
|
+
cancelled++;
|
|
1570
|
+
return new Promise(() => {});
|
|
1571
|
+
} }), {
|
|
1572
|
+
status: 302,
|
|
1573
|
+
headers: { Location: "file:///private-document" }
|
|
1574
|
+
})),
|
|
1575
|
+
release() {}
|
|
1576
|
+
};
|
|
1577
|
+
const publicFetch = createPublicFetch({
|
|
1578
|
+
pinner: () => Promise.resolve(pinner),
|
|
1579
|
+
lookup: () => Promise.reject(/* @__PURE__ */ new Error("Unexpected default lookup"))
|
|
1580
|
+
});
|
|
1581
|
+
await settlesWithin(rejects(createDocumentLoader({}, { openHop: (url) => publicFetch.openPublicFetch(url, { lookup: lookupTestAddresses }) })("https://a.example/redirect"), UrlError));
|
|
1582
|
+
deepStrictEqual(cancelled, 1);
|
|
1583
|
+
});
|
|
1584
|
+
});
|
|
1585
|
+
test("getDocumentLoader() completes with tee'd fetch-mock responses", async (t) => {
|
|
1586
|
+
const url = "https://example.com/teed";
|
|
1587
|
+
function stream(text) {
|
|
1588
|
+
return new ReadableStream({ start(controller) {
|
|
1589
|
+
controller.enqueue(new TextEncoder().encode(text));
|
|
1590
|
+
controller.close();
|
|
1591
|
+
} });
|
|
1592
|
+
}
|
|
1593
|
+
const loaders = {
|
|
1594
|
+
unpinned: createDocumentLoader({}, { openHop: openUnpinnedHop }),
|
|
1595
|
+
"private addresses allowed": getDocumentLoader({ allowPrivateAddress: true })
|
|
1596
|
+
};
|
|
1597
|
+
for (const [name, loader] of Object.entries(loaders)) for (const body of ["string", "stream"]) await t.step(`${name}: ${body} bodies`, async () => {
|
|
1598
|
+
const make = (text) => body === "string" ? text : stream(text);
|
|
1599
|
+
esm_default.mockGlobal();
|
|
1600
|
+
try {
|
|
1601
|
+
esm_default.get(`${url}/object`, () => new Response(make(JSON.stringify(lifecycleDocument)), { headers: { "Content-Type": "application/activity+json" } }));
|
|
1602
|
+
esm_default.get(`${url}/redirect`, () => new Response(make("redirect"), {
|
|
1603
|
+
status: 302,
|
|
1604
|
+
headers: { Location: `${url}/object` }
|
|
1605
|
+
}));
|
|
1606
|
+
esm_default.get(`${url}/alternate`, () => new Response(make("not JSON"), { headers: {
|
|
1607
|
+
"Content-Type": "text/plain",
|
|
1608
|
+
Link: `<${url}/object>; rel="alternate"; type="application/activity+json"`
|
|
1609
|
+
} }));
|
|
1610
|
+
esm_default.get(`${url}/missing`, () => new Response(make("not found"), { status: 404 }));
|
|
1611
|
+
for (const path of ["redirect", "alternate"]) deepStrictEqual((await settlesWithin(loader(`${url}/${path}`))).document, lifecycleDocument);
|
|
1612
|
+
await settlesWithin(rejects(loader(`${url}/missing`), FetchError));
|
|
1613
|
+
deepStrictEqual(esm_default.callHistory.calls().map((call) => call.url), [
|
|
1614
|
+
`${url}/redirect`,
|
|
1615
|
+
`${url}/object`,
|
|
1616
|
+
`${url}/alternate`,
|
|
1617
|
+
`${url}/object`,
|
|
1618
|
+
`${url}/missing`
|
|
1619
|
+
]);
|
|
1620
|
+
} finally {
|
|
1621
|
+
esm_default.hardReset();
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
});
|
|
1625
|
+
test("getDocumentLoader() resolves each hop once", async () => {
|
|
1626
|
+
const lookups = [];
|
|
1627
|
+
const recorder = createHopRecorder((url) => {
|
|
1628
|
+
const responseUrl = `https://${PUBLIC_ADDRESS.address}${new URL(url).pathname}`;
|
|
1629
|
+
if (url === "https://a.example/start") return {
|
|
1630
|
+
status: 302,
|
|
1631
|
+
headers: { Location: "https://b.example/next" },
|
|
1632
|
+
responseUrl
|
|
1633
|
+
};
|
|
1634
|
+
else if (url === "https://b.example/next") return {
|
|
1635
|
+
status: 301,
|
|
1636
|
+
headers: { Location: "/object" },
|
|
1637
|
+
responseUrl
|
|
1638
|
+
};
|
|
1639
|
+
return {
|
|
1640
|
+
body: JSON.stringify(lifecycleDocument),
|
|
1641
|
+
responseUrl
|
|
1642
|
+
};
|
|
1643
|
+
});
|
|
1644
|
+
const pinner = {
|
|
1645
|
+
supports: () => true,
|
|
1646
|
+
fetch: (_grant, request) => Promise.resolve(recorder.respond(request.url)),
|
|
1647
|
+
release() {}
|
|
1648
|
+
};
|
|
1649
|
+
const publicFetch = createPublicFetch({
|
|
1650
|
+
pinner: () => Promise.resolve(pinner),
|
|
1651
|
+
lookup: () => Promise.reject(/* @__PURE__ */ new Error("Unexpected default lookup"))
|
|
1652
|
+
});
|
|
1653
|
+
deepStrictEqual(await createDocumentLoader({}, { openHop: async (url) => recorder.record(url, await publicFetch.openPublicFetch(url, { lookup(hostname) {
|
|
1654
|
+
lookups.push(hostname);
|
|
1655
|
+
return Promise.resolve([PUBLIC_ADDRESS]);
|
|
1656
|
+
} })) })("https://a.example/start"), {
|
|
1657
|
+
contextUrl: null,
|
|
1658
|
+
documentUrl: "https://b.example/object",
|
|
1659
|
+
document: lifecycleDocument
|
|
1660
|
+
});
|
|
1661
|
+
deepStrictEqual(lookups, [
|
|
1662
|
+
"a.example",
|
|
1663
|
+
"b.example",
|
|
1664
|
+
"b.example"
|
|
1665
|
+
]);
|
|
1666
|
+
deepStrictEqual(recorder.events, [
|
|
1667
|
+
"open https://a.example/start",
|
|
1668
|
+
"fetch https://a.example/start #1",
|
|
1669
|
+
"cancel #1",
|
|
1670
|
+
"close https://a.example/start",
|
|
1671
|
+
"open https://b.example/next",
|
|
1672
|
+
"fetch https://b.example/next #2",
|
|
1673
|
+
"cancel #2",
|
|
1674
|
+
"close https://b.example/next",
|
|
1675
|
+
"open https://b.example/object",
|
|
1676
|
+
"fetch https://b.example/object #3",
|
|
1677
|
+
"consumed #3",
|
|
1678
|
+
"close https://b.example/object"
|
|
1679
|
+
]);
|
|
1680
|
+
recorder.assertInvariants();
|
|
1681
|
+
});
|
|
1682
|
+
test("getRemoteDocument() cancels the body before loading a Link header alternate", async () => {
|
|
1683
|
+
const recorder = createHopRecorder(() => ({
|
|
1684
|
+
headers: {
|
|
1685
|
+
"Content-Type": "text/html",
|
|
1686
|
+
Link: "<https://b.example/object>; rel=\"alternate\"; type=\"application/activity+json\""
|
|
1687
|
+
},
|
|
1688
|
+
body: "<html></html>"
|
|
1689
|
+
}));
|
|
1690
|
+
const response = recorder.respond("https://a.example/start");
|
|
1691
|
+
const placeholder = {
|
|
1692
|
+
contextUrl: null,
|
|
1693
|
+
document: {},
|
|
1694
|
+
documentUrl: "https://b.example/object"
|
|
1695
|
+
};
|
|
1696
|
+
const alternates = [];
|
|
1697
|
+
ok(await getRemoteDocument("https://a.example/start", response, (url) => {
|
|
1698
|
+
alternates.push(url);
|
|
1699
|
+
deepStrictEqual(recorder.events.at(-1), "cancel #1");
|
|
1700
|
+
ok(response.bodyUsed);
|
|
1701
|
+
return Promise.resolve(placeholder);
|
|
1702
|
+
}) === placeholder);
|
|
1703
|
+
deepStrictEqual(alternates, ["https://b.example/object"]);
|
|
1704
|
+
deepStrictEqual(recorder.events, ["fetch https://a.example/start #1", "cancel #1"]);
|
|
1705
|
+
});
|
|
2486
1706
|
//#endregion
|
|
2487
1707
|
export {};
|