@fedify/vocab-runtime 2.2.19 → 2.2.20
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/internal.cjs +6 -0
- package/dist/internal.d.cts +3 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +3 -0
- package/dist/mod.cjs +105 -253
- package/dist/mod.d.cts +5 -28
- package/dist/mod.d.ts +6 -28
- package/dist/mod.js +98 -245
- package/dist/public-fetch-BC-nWJNM.d.ts +143 -0
- package/dist/public-fetch-CFnW7XMn.cjs +821 -0
- package/dist/public-fetch-DBpt3xxf.d.cts +143 -0
- package/dist/public-fetch-Dfmc_Kfy.js +772 -0
- package/dist/tests/{body-BOnyCa1y.mjs → body-B9_hb-GO.mjs} +1 -1
- package/dist/tests/{body-DhbRZ6Ps.cjs → body-pOSG2RFb.cjs} +1 -1
- package/dist/tests/body.test.cjs +1 -1
- package/dist/tests/body.test.mjs +1 -1
- package/dist/tests/decimal.test.cjs +6 -6
- package/dist/tests/decimal.test.mjs +6 -6
- package/dist/tests/{docloader-BjyFsnAA.mjs → docloader-Bdlp7FkK.mjs} +102 -37
- package/dist/tests/{docloader-BhSiTajy.cjs → docloader-Ck3VfY29.cjs} +106 -35
- package/dist/tests/docloader.test.cjs +523 -1273
- package/dist/tests/docloader.test.mjs +469 -1238
- package/dist/tests/esm-CnLt0wAF.mjs +1225 -0
- package/dist/tests/esm-CxbqfkLP.cjs +1208 -0
- package/dist/tests/internal/multicodec.test.cjs +1 -1
- package/dist/tests/internal/multicodec.test.mjs +1 -1
- package/dist/tests/{key-BDIsC6hV.mjs → key-GEdpxA4M.mjs} +2 -2
- package/dist/tests/{key-BarKGLQz.cjs → key-L6ReMuUb.cjs} +2 -2
- package/dist/tests/key.test.cjs +2 -2
- package/dist/tests/key.test.mjs +2 -2
- package/dist/tests/{langstr-BsqFJupv.cjs → langstr-CZpWmpo5.cjs} +1 -1
- package/dist/tests/{langstr-ABdAOKlF.mjs → langstr-DTB4sl0a.mjs} +1 -1
- package/dist/tests/langstr.test.cjs +1 -1
- package/dist/tests/langstr.test.mjs +1 -1
- package/dist/tests/langtag.test.cjs +1 -1
- package/dist/tests/langtag.test.mjs +1 -1
- package/dist/tests/link.test.mjs +1 -1
- package/dist/tests/multibase/multibase.test.cjs +1 -1
- package/dist/tests/multibase/multibase.test.mjs +1 -1
- package/dist/tests/node-C3bjFjL1.mjs +84 -0
- package/dist/tests/node-DWD76vPo.cjs +90 -0
- package/dist/tests/pin-grant-CU-o367k.cjs +70 -0
- package/dist/tests/pin-grant-HW3B6SKv.mjs +53 -0
- package/dist/tests/pin-grant.test.cjs +88 -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 +167 -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 +197 -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-BjE-YJLL.cjs +221 -0
- package/dist/tests/pinners-ZgZDx9y6.mjs +203 -0
- package/dist/tests/public-fetch-Ddjfxbwc.cjs +187 -0
- package/dist/tests/public-fetch-Yi7Vks9s.mjs +170 -0
- package/dist/tests/public-fetch.test.cjs +1074 -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-DGtx5MkG.cjs → request-B3NUKbyk.cjs} +1 -1
- package/dist/tests/{request-yCis9VCB.mjs → request-BSg3IQzf.mjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/support-D5-KVjWZ.cjs +363 -0
- package/dist/tests/support-M5ClN-no.mjs +272 -0
- package/dist/tests/{url-vZTgkIZg.cjs → url-DLuSj57U.cjs} +88 -12
- package/dist/tests/{url-3fyJuqC0.mjs → url-DQWrMGhu.mjs} +65 -13
- package/dist/tests/url.test.cjs +4 -1
- package/dist/tests/url.test.mjs +4 -1
- package/package.json +14 -3
- package/src/docloader.test.ts +700 -32
- package/src/docloader.ts +174 -67
- 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 +12 -3
- /package/dist/tests/{langtag-LDBqlxHv.mjs → langtag-D8FWxjv8.mjs} +0 -0
- /package/dist/tests/{langtag-DgySESmk.cjs → langtag-a2-s9uyi.cjs} +0 -0
- /package/dist/tests/{link-CYszIegt.mjs → link-CHMtH2-k.mjs} +0 -0
- /package/dist/tests/{multibase-8zhYPa7o.cjs → multibase-BmWaK56H.cjs} +0 -0
- /package/dist/tests/{multibase-Ds75BvXs.mjs → multibase-D642Uv3S.mjs} +0 -0
- /package/dist/tests/{multicodec-ByS9XLsw.cjs → multicodec-B-_CSt1M.cjs} +0 -0
- /package/dist/tests/{multicodec-BBPZjRfg.mjs → multicodec-caWdG98t.mjs} +0 -0
|
@@ -1,1238 +1,36 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { t as esm_default } from "./esm-CnLt0wAF.mjs";
|
|
2
|
+
import { t as FetchError } from "./request-BSg3IQzf.mjs";
|
|
3
|
+
import { a as cid_v1_default, i as preloadedContexts, n as getDocumentLoader, r as getRemoteDocument, t as createDocumentLoader } from "./docloader-Bdlp7FkK.mjs";
|
|
4
|
+
import { t as UrlError } from "./url-DQWrMGhu.mjs";
|
|
5
|
+
import { t as createPublicFetch } from "./public-fetch-Yi7Vks9s.mjs";
|
|
4
6
|
import { gzipSync } from "node:zlib";
|
|
5
7
|
import { configure, reset } from "@logtape/logtape";
|
|
6
8
|
import { deepStrictEqual, ok, rejects } from "node:assert";
|
|
7
|
-
import dns from "node:dns/promises";
|
|
8
9
|
import { test } from "@fedify/fixture";
|
|
9
10
|
import { createServer } from "node:http";
|
|
10
11
|
import jsonld from "jsonld/dist/jsonld.esm.js";
|
|
11
|
-
//#region
|
|
12
|
-
var
|
|
13
|
-
var __defProp = Object.defineProperty;
|
|
14
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
17
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
21
|
-
key = keys[i];
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
-
get: ((k) => from[k]).bind(null, key),
|
|
24
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
32
|
-
}) : target, mod));
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region ../../node_modules/.pnpm/regexparam@3.0.0/node_modules/regexparam/dist/index.mjs
|
|
35
|
-
var import_glob_to_regexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
36
|
-
module.exports = function(glob, opts) {
|
|
37
|
-
if (typeof glob !== "string") throw new TypeError("Expected a string");
|
|
38
|
-
var str = String(glob);
|
|
39
|
-
var reStr = "";
|
|
40
|
-
var extended = opts ? !!opts.extended : false;
|
|
41
|
-
var globstar = opts ? !!opts.globstar : false;
|
|
42
|
-
var inGroup = false;
|
|
43
|
-
var flags = opts && typeof opts.flags === "string" ? opts.flags : "";
|
|
44
|
-
var c;
|
|
45
|
-
for (var i = 0, len = str.length; i < len; i++) {
|
|
46
|
-
c = str[i];
|
|
47
|
-
switch (c) {
|
|
48
|
-
case "/":
|
|
49
|
-
case "$":
|
|
50
|
-
case "^":
|
|
51
|
-
case "+":
|
|
52
|
-
case ".":
|
|
53
|
-
case "(":
|
|
54
|
-
case ")":
|
|
55
|
-
case "=":
|
|
56
|
-
case "!":
|
|
57
|
-
case "|":
|
|
58
|
-
reStr += "\\" + c;
|
|
59
|
-
break;
|
|
60
|
-
case "?": if (extended) {
|
|
61
|
-
reStr += ".";
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case "[":
|
|
65
|
-
case "]": if (extended) {
|
|
66
|
-
reStr += c;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case "{": if (extended) {
|
|
70
|
-
inGroup = true;
|
|
71
|
-
reStr += "(";
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case "}": if (extended) {
|
|
75
|
-
inGroup = false;
|
|
76
|
-
reStr += ")";
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case ",":
|
|
80
|
-
if (inGroup) {
|
|
81
|
-
reStr += "|";
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
reStr += "\\" + c;
|
|
85
|
-
break;
|
|
86
|
-
case "*":
|
|
87
|
-
var prevChar = str[i - 1];
|
|
88
|
-
var starCount = 1;
|
|
89
|
-
while (str[i + 1] === "*") {
|
|
90
|
-
starCount++;
|
|
91
|
-
i++;
|
|
92
|
-
}
|
|
93
|
-
var nextChar = str[i + 1];
|
|
94
|
-
if (!globstar) reStr += ".*";
|
|
95
|
-
else if (starCount > 1 && (prevChar === "/" || prevChar === void 0) && (nextChar === "/" || nextChar === void 0)) {
|
|
96
|
-
reStr += "((?:[^/]*(?:/|$))*)";
|
|
97
|
-
i++;
|
|
98
|
-
} else reStr += "([^/]*)";
|
|
99
|
-
break;
|
|
100
|
-
default: reStr += c;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (!flags || !~flags.indexOf("g")) reStr = "^" + reStr + "$";
|
|
104
|
-
return new RegExp(reStr, flags);
|
|
105
|
-
};
|
|
106
|
-
})))(), 1);
|
|
107
|
-
/**
|
|
108
|
-
* @param {string|RegExp} input The route pattern
|
|
109
|
-
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
|
|
110
|
-
*/
|
|
111
|
-
function parse(input, loose) {
|
|
112
|
-
if (input instanceof RegExp) return {
|
|
113
|
-
keys: false,
|
|
114
|
-
pattern: input
|
|
115
|
-
};
|
|
116
|
-
var c, o, tmp, ext, keys = [], pattern = "", arr = input.split("/");
|
|
117
|
-
arr[0] || arr.shift();
|
|
118
|
-
while (tmp = arr.shift()) {
|
|
119
|
-
c = tmp[0];
|
|
120
|
-
if (c === "*") {
|
|
121
|
-
keys.push(c);
|
|
122
|
-
pattern += tmp[1] === "?" ? "(?:/(.*))?" : "/(.*)";
|
|
123
|
-
} else if (c === ":") {
|
|
124
|
-
o = tmp.indexOf("?", 1);
|
|
125
|
-
ext = tmp.indexOf(".", 1);
|
|
126
|
-
keys.push(tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length));
|
|
127
|
-
pattern += !!~o && !~ext ? "(?:/([^/]+?))?" : "/([^/]+?)";
|
|
128
|
-
if (!!~ext) pattern += (!!~o ? "?" : "") + "\\" + tmp.substring(ext);
|
|
129
|
-
} else pattern += "/" + tmp;
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
keys,
|
|
133
|
-
pattern: new RegExp("^" + pattern + (loose ? "(?=$|/)" : "/?$"), "i")
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
//#endregion
|
|
137
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/TypeDescriptor.js
|
|
138
|
-
const valueTypes = new Set([
|
|
139
|
-
"boolean",
|
|
140
|
-
"number",
|
|
141
|
-
"null",
|
|
142
|
-
"string",
|
|
143
|
-
"undefined"
|
|
144
|
-
]);
|
|
145
|
-
const referenceTypes = new Set([
|
|
146
|
-
"array",
|
|
147
|
-
"function",
|
|
148
|
-
"object",
|
|
149
|
-
"symbol"
|
|
150
|
-
]);
|
|
151
|
-
const detectableTypes = new Set([
|
|
152
|
-
"boolean",
|
|
153
|
-
"function",
|
|
154
|
-
"number",
|
|
155
|
-
"string",
|
|
156
|
-
"symbol"
|
|
157
|
-
]);
|
|
158
|
-
const typeConstructors = new Set([
|
|
159
|
-
Boolean,
|
|
160
|
-
Number,
|
|
161
|
-
String
|
|
162
|
-
]);
|
|
163
|
-
var TypeDescriptor = class TypeDescriptor {
|
|
164
|
-
constructor(value) {
|
|
165
|
-
this.name = TypeDescriptor.of(value);
|
|
166
|
-
this.isValueType = TypeDescriptor.isValueType(value);
|
|
167
|
-
this.isReferenceType = TypeDescriptor.isReferenceType(value);
|
|
168
|
-
this.isArray = TypeDescriptor.isArray(value);
|
|
169
|
-
this.isBoolean = TypeDescriptor.isBoolean(value);
|
|
170
|
-
this.isFunction = TypeDescriptor.isFunction(value);
|
|
171
|
-
this.isNull = TypeDescriptor.isNull(value);
|
|
172
|
-
this.isNumber = TypeDescriptor.isNumber(value);
|
|
173
|
-
this.isObject = TypeDescriptor.isObject(value);
|
|
174
|
-
this.isString = TypeDescriptor.isString(value);
|
|
175
|
-
this.isSymbol = TypeDescriptor.isSymbol(value);
|
|
176
|
-
this.isUndefined = TypeDescriptor.isUndefined(value);
|
|
177
|
-
}
|
|
178
|
-
static of(value) {
|
|
179
|
-
if (value === null) return "null";
|
|
180
|
-
if (value === void 0) return "undefined";
|
|
181
|
-
const detectedType = typeof value;
|
|
182
|
-
if (detectableTypes.has(detectedType)) return detectedType;
|
|
183
|
-
if (detectedType === "object") {
|
|
184
|
-
if (Array.isArray(value)) return "array";
|
|
185
|
-
if (typeConstructors.has(value.constructor)) return value.constructor.name.toLowerCase();
|
|
186
|
-
return detectedType;
|
|
187
|
-
}
|
|
188
|
-
throw new Error("Failed due to an unknown type.");
|
|
189
|
-
}
|
|
190
|
-
static from(value) {
|
|
191
|
-
return new TypeDescriptor(value);
|
|
192
|
-
}
|
|
193
|
-
static isValueType(value) {
|
|
194
|
-
return valueTypes.has(TypeDescriptor.of(value));
|
|
195
|
-
}
|
|
196
|
-
static isReferenceType(value) {
|
|
197
|
-
return referenceTypes.has(TypeDescriptor.of(value));
|
|
198
|
-
}
|
|
199
|
-
static isArray(value) {
|
|
200
|
-
return TypeDescriptor.of(value) === "array";
|
|
201
|
-
}
|
|
202
|
-
static isBoolean(value) {
|
|
203
|
-
return TypeDescriptor.of(value) === "boolean";
|
|
204
|
-
}
|
|
205
|
-
static isFunction(value) {
|
|
206
|
-
return TypeDescriptor.of(value) === "function";
|
|
207
|
-
}
|
|
208
|
-
static isNull(value) {
|
|
209
|
-
return TypeDescriptor.of(value) === "null";
|
|
210
|
-
}
|
|
211
|
-
static isNumber(value) {
|
|
212
|
-
return TypeDescriptor.of(value) === "number";
|
|
213
|
-
}
|
|
214
|
-
static isObject(value) {
|
|
215
|
-
return TypeDescriptor.of(value) === "object";
|
|
216
|
-
}
|
|
217
|
-
static isString(value) {
|
|
218
|
-
return TypeDescriptor.of(value) === "string";
|
|
219
|
-
}
|
|
220
|
-
static isSymbol(value) {
|
|
221
|
-
return TypeDescriptor.of(value) === "symbol";
|
|
222
|
-
}
|
|
223
|
-
static isUndefined(value) {
|
|
224
|
-
return TypeDescriptor.of(value) === "undefined";
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
//#endregion
|
|
228
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/IsSubsetOf.js
|
|
229
|
-
const allowedTypes = new Set([
|
|
230
|
-
"array",
|
|
231
|
-
"object",
|
|
232
|
-
"function",
|
|
233
|
-
"null"
|
|
234
|
-
]);
|
|
235
|
-
const isSubsetOf = function(subset, superset, visited = []) {
|
|
236
|
-
const subsetType = TypeDescriptor.of(subset);
|
|
237
|
-
const supersetType = TypeDescriptor.of(superset);
|
|
238
|
-
if (!allowedTypes.has(subsetType)) throw new Error(`Type '${subsetType}' is not supported.`);
|
|
239
|
-
if (!allowedTypes.has(supersetType)) throw new Error(`Type '${supersetType}' is not supported.`);
|
|
240
|
-
if (TypeDescriptor.isFunction(subset)) {
|
|
241
|
-
if (!TypeDescriptor.isFunction(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
242
|
-
return subset.toString() === superset.toString();
|
|
243
|
-
}
|
|
244
|
-
if (TypeDescriptor.isArray(subset)) {
|
|
245
|
-
if (!TypeDescriptor.isArray(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
246
|
-
if (subset.length > superset.length) return false;
|
|
247
|
-
for (const subsetItem of subset) {
|
|
248
|
-
const subsetItemType = TypeDescriptor.of(subsetItem);
|
|
249
|
-
let isItemInSuperset;
|
|
250
|
-
switch (subsetItemType) {
|
|
251
|
-
case "array":
|
|
252
|
-
case "object":
|
|
253
|
-
case "function":
|
|
254
|
-
if (visited.includes(subsetItem)) continue;
|
|
255
|
-
visited.push(subsetItem);
|
|
256
|
-
isItemInSuperset = superset.some((supersetItem) => {
|
|
257
|
-
try {
|
|
258
|
-
return isSubsetOf(subsetItem, supersetItem, visited);
|
|
259
|
-
} catch {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
break;
|
|
264
|
-
default: isItemInSuperset = superset.includes(subsetItem);
|
|
265
|
-
}
|
|
266
|
-
if (!isItemInSuperset) return false;
|
|
267
|
-
}
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
if (TypeDescriptor.isObject(subset)) {
|
|
271
|
-
if (!TypeDescriptor.isObject(superset) || TypeDescriptor.isArray(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
272
|
-
if (Object.keys(subset).length > Object.keys(superset).length) return false;
|
|
273
|
-
for (const [subsetKey, subsetValue] of Object.entries(subset)) {
|
|
274
|
-
const supersetValue = superset[subsetKey];
|
|
275
|
-
switch (TypeDescriptor.of(subsetValue)) {
|
|
276
|
-
case "array":
|
|
277
|
-
case "object":
|
|
278
|
-
case "function":
|
|
279
|
-
if (visited.includes(subsetValue)) continue;
|
|
280
|
-
visited.push(subsetValue);
|
|
281
|
-
try {
|
|
282
|
-
if (!isSubsetOf(subsetValue, supersetValue, visited)) return false;
|
|
283
|
-
} catch {
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
break;
|
|
287
|
-
default: if (subsetValue !== supersetValue) return false;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
if (TypeDescriptor.isNull(subset)) {
|
|
293
|
-
if (!TypeDescriptor.isNull(superset)) throw new Error(`Types '${subsetType}' and '${supersetType}' do not match.`);
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
throw new Error("Invalid operation.");
|
|
297
|
-
};
|
|
298
|
-
isSubsetOf.structural = function(subset, superset, visited = []) {
|
|
299
|
-
if (!TypeDescriptor.isObject(subset)) throw new Error(`Type '${TypeDescriptor.of(subset)}' is not supported.`);
|
|
300
|
-
if (!TypeDescriptor.isObject(superset)) throw new Error(`Type '${TypeDescriptor.of(superset)}' is not supported.`);
|
|
301
|
-
for (const [subsetKey, subsetValue] of Object.entries(subset)) {
|
|
302
|
-
if (superset[subsetKey] === void 0) return false;
|
|
303
|
-
const subsetValueType = TypeDescriptor.of(subsetValue);
|
|
304
|
-
const supersetValue = superset[subsetKey];
|
|
305
|
-
if (subsetValueType === "object") {
|
|
306
|
-
if (visited.includes(subsetValue)) continue;
|
|
307
|
-
visited.push(subsetValue);
|
|
308
|
-
try {
|
|
309
|
-
if (!isSubsetOf.structural(subsetValue, supersetValue, visited)) return false;
|
|
310
|
-
} catch {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return true;
|
|
316
|
-
};
|
|
317
|
-
//#endregion
|
|
318
|
-
//#region ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs
|
|
319
|
-
var has = Object.prototype.hasOwnProperty;
|
|
320
|
-
function find(iter, tar, key) {
|
|
321
|
-
for (key of iter.keys()) if (dequal(key, tar)) return key;
|
|
322
|
-
}
|
|
323
|
-
function dequal(foo, bar) {
|
|
324
|
-
var ctor, len, tmp;
|
|
325
|
-
if (foo === bar) return true;
|
|
326
|
-
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
327
|
-
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
328
|
-
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
329
|
-
if (ctor === Array) {
|
|
330
|
-
if ((len = foo.length) === bar.length) while (len-- && dequal(foo[len], bar[len]));
|
|
331
|
-
return len === -1;
|
|
332
|
-
}
|
|
333
|
-
if (ctor === Set) {
|
|
334
|
-
if (foo.size !== bar.size) return false;
|
|
335
|
-
for (len of foo) {
|
|
336
|
-
tmp = len;
|
|
337
|
-
if (tmp && typeof tmp === "object") {
|
|
338
|
-
tmp = find(bar, tmp);
|
|
339
|
-
if (!tmp) return false;
|
|
340
|
-
}
|
|
341
|
-
if (!bar.has(tmp)) return false;
|
|
342
|
-
}
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
if (ctor === Map) {
|
|
346
|
-
if (foo.size !== bar.size) return false;
|
|
347
|
-
for (len of foo) {
|
|
348
|
-
tmp = len[0];
|
|
349
|
-
if (tmp && typeof tmp === "object") {
|
|
350
|
-
tmp = find(bar, tmp);
|
|
351
|
-
if (!tmp) return false;
|
|
352
|
-
}
|
|
353
|
-
if (!dequal(len[1], bar.get(tmp))) return false;
|
|
354
|
-
}
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
if (ctor === ArrayBuffer) {
|
|
358
|
-
foo = new Uint8Array(foo);
|
|
359
|
-
bar = new Uint8Array(bar);
|
|
360
|
-
} else if (ctor === DataView) {
|
|
361
|
-
if ((len = foo.byteLength) === bar.byteLength) while (len-- && foo.getInt8(len) === bar.getInt8(len));
|
|
362
|
-
return len === -1;
|
|
363
|
-
}
|
|
364
|
-
if (ArrayBuffer.isView(foo)) {
|
|
365
|
-
if ((len = foo.byteLength) === bar.byteLength) while (len-- && foo[len] === bar[len]);
|
|
366
|
-
return len === -1;
|
|
367
|
-
}
|
|
368
|
-
if (!ctor || typeof foo === "object") {
|
|
369
|
-
len = 0;
|
|
370
|
-
for (ctor in foo) {
|
|
371
|
-
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
372
|
-
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
|
373
|
-
}
|
|
374
|
-
return Object.keys(bar).length === len;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return foo !== foo && bar !== bar;
|
|
378
|
-
}
|
|
379
|
-
//#endregion
|
|
380
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/RequestUtils.js
|
|
381
|
-
const absoluteUrlRX = /* @__PURE__ */ new RegExp("^[a-z]+://|^data:", "i");
|
|
382
|
-
const protocolRelativeUrlRX = /* @__PURE__ */ new RegExp("^//", "i");
|
|
383
|
-
function hasCredentialsInUrl(url) {
|
|
384
|
-
const urlObject = new URL(url, !absoluteUrlRX.test(url) ? "http://dummy" : void 0);
|
|
385
|
-
return Boolean(urlObject.username || urlObject.password);
|
|
386
|
-
}
|
|
387
|
-
function normalizeUrl(url, allowRelativeUrls) {
|
|
388
|
-
if (url instanceof URL) return url.href;
|
|
389
|
-
const primitiveUrl = String(url).valueOf();
|
|
390
|
-
if (absoluteUrlRX.test(primitiveUrl)) return new URL(primitiveUrl).href;
|
|
391
|
-
if (protocolRelativeUrlRX.test(primitiveUrl)) return new URL(primitiveUrl, "http://dummy").href.replace(/^[a-z]+:/, "");
|
|
392
|
-
if ("location" in globalThis) if (primitiveUrl.startsWith("/")) return `${globalThis.location.origin}${primitiveUrl}`;
|
|
393
|
-
else return `${globalThis.location.href}/${primitiveUrl}`;
|
|
394
|
-
else if (allowRelativeUrls) {
|
|
395
|
-
const urlInstance = new URL(primitiveUrl, "http://dummy");
|
|
396
|
-
return urlInstance.pathname + urlInstance.search;
|
|
397
|
-
} 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`");
|
|
398
|
-
}
|
|
399
|
-
function createCallLogFromUrlAndOptions(url, options) {
|
|
400
|
-
const pendingPromises = [];
|
|
401
|
-
if (typeof url === "string" || url instanceof String || url instanceof URL) {
|
|
402
|
-
const normalizedUrl = normalizeUrl(url, true);
|
|
403
|
-
const derivedOptions = options ? { ...options } : {};
|
|
404
|
-
if (derivedOptions.headers) derivedOptions.headers = normalizeHeaders(derivedOptions.headers);
|
|
405
|
-
derivedOptions.method = derivedOptions.method ? derivedOptions.method.toLowerCase() : "get";
|
|
406
|
-
return {
|
|
407
|
-
args: [url, options],
|
|
408
|
-
url: normalizedUrl,
|
|
409
|
-
queryParams: new URLSearchParams(getQuery(normalizedUrl)),
|
|
410
|
-
options: derivedOptions,
|
|
411
|
-
signal: derivedOptions.signal,
|
|
412
|
-
pendingPromises
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
if (typeof url === "object") throw new TypeError("fetch-mock: Unrecognised Request object. Read the Config and Installation sections of the docs");
|
|
416
|
-
else throw new TypeError("fetch-mock: Invalid arguments passed to fetch");
|
|
417
|
-
}
|
|
418
|
-
async function createCallLogFromRequest(request, options) {
|
|
419
|
-
const pendingPromises = [];
|
|
420
|
-
const derivedOptions = { method: request.method };
|
|
421
|
-
try {
|
|
422
|
-
try {
|
|
423
|
-
derivedOptions.body = await request.clone().formData();
|
|
424
|
-
} catch {
|
|
425
|
-
derivedOptions.body = await request.clone().text();
|
|
426
|
-
}
|
|
427
|
-
} catch {}
|
|
428
|
-
if (request.headers) derivedOptions.headers = normalizeHeaders(request.headers);
|
|
429
|
-
const url = normalizeUrl(request.url, true);
|
|
430
|
-
return {
|
|
431
|
-
args: [request, options],
|
|
432
|
-
url,
|
|
433
|
-
queryParams: new URLSearchParams(getQuery(url)),
|
|
434
|
-
options: Object.assign(derivedOptions, options || {}),
|
|
435
|
-
request,
|
|
436
|
-
signal: options && options.signal || request.signal,
|
|
437
|
-
pendingPromises
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
function getPath(url) {
|
|
441
|
-
return (absoluteUrlRX.test(url) ? new URL(url) : new URL(url, "http://dummy")).pathname;
|
|
442
|
-
}
|
|
443
|
-
function getHost(url) {
|
|
444
|
-
if (absoluteUrlRX.test(url)) return new URL(url).host;
|
|
445
|
-
else if ("location" in globalThis) return globalThis.location.host;
|
|
446
|
-
return null;
|
|
447
|
-
}
|
|
448
|
-
function getQuery(url) {
|
|
449
|
-
const u = absoluteUrlRX.test(url) ? new URL(url) : new URL(url, "http://dummy");
|
|
450
|
-
return u.search ? u.search.substr(1) : "";
|
|
451
|
-
}
|
|
452
|
-
function normalizeHeaders(headers) {
|
|
453
|
-
let entries;
|
|
454
|
-
if (headers instanceof Headers) entries = [...headers.entries()];
|
|
455
|
-
else if (Array.isArray(headers)) entries = headers;
|
|
456
|
-
else entries = Object.entries(headers);
|
|
457
|
-
return Object.fromEntries(entries.map(([key, val]) => [key.toLowerCase(), String(val).valueOf()]));
|
|
458
|
-
}
|
|
459
|
-
//#endregion
|
|
460
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Matchers.js
|
|
461
|
-
const isUrlMatcher = (matcher) => matcher instanceof RegExp || typeof matcher === "string" || typeof matcher === "object" && "href" in matcher;
|
|
462
|
-
const isFunctionMatcher = (matcher) => typeof matcher === "function";
|
|
463
|
-
const stringMatchers = {
|
|
464
|
-
begin: (targetString) => ({ url }) => url.startsWith(targetString),
|
|
465
|
-
end: (targetString) => ({ url }) => url.endsWith(targetString),
|
|
466
|
-
include: (targetString) => ({ url }) => url.includes(targetString),
|
|
467
|
-
glob: (targetString) => {
|
|
468
|
-
const urlRX = (0, import_glob_to_regexp.default)(targetString);
|
|
469
|
-
return ({ url }) => urlRX.test(url);
|
|
470
|
-
},
|
|
471
|
-
express: (targetString) => {
|
|
472
|
-
const urlRX = parse(targetString);
|
|
473
|
-
return (callLog) => {
|
|
474
|
-
const vals = urlRX.pattern.exec(getPath(callLog.url));
|
|
475
|
-
if (!vals) {
|
|
476
|
-
callLog.expressParams = {};
|
|
477
|
-
return false;
|
|
478
|
-
}
|
|
479
|
-
vals.shift();
|
|
480
|
-
callLog.expressParams = urlRX.keys.reduce((map, paramName, i) => vals[i] ? Object.assign(map, { [paramName]: vals[i] }) : map, {});
|
|
481
|
-
return true;
|
|
482
|
-
};
|
|
483
|
-
},
|
|
484
|
-
path: (targetString) => {
|
|
485
|
-
const dotlessTargetString = getPath(targetString);
|
|
486
|
-
return ({ url }) => {
|
|
487
|
-
const path = getPath(url);
|
|
488
|
-
return path === targetString || path === dotlessTargetString;
|
|
489
|
-
};
|
|
490
|
-
},
|
|
491
|
-
host: (targetString) => {
|
|
492
|
-
return ({ url }) => targetString === getHost(url);
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
const getHeaderMatcher = ({ headers: expectedHeaders }) => {
|
|
496
|
-
if (!expectedHeaders) return;
|
|
497
|
-
const expectation = normalizeHeaders(expectedHeaders);
|
|
498
|
-
return ({ options: { headers = {} } }) => {
|
|
499
|
-
const lowerCaseHeaders = normalizeHeaders(headers);
|
|
500
|
-
return Object.keys(expectation).every((headerName) => lowerCaseHeaders[headerName] === expectation[headerName]);
|
|
501
|
-
};
|
|
502
|
-
};
|
|
503
|
-
const getMissingHeaderMatcher = ({ missingHeaders: expectedMissingHeaders }) => {
|
|
504
|
-
if (!expectedMissingHeaders) return;
|
|
505
|
-
const expectation = expectedMissingHeaders.map((header) => header.toLowerCase());
|
|
506
|
-
return ({ options: { headers = {} } }) => {
|
|
507
|
-
const lowerCaseHeaders = normalizeHeaders(headers);
|
|
508
|
-
return expectation.every((headerName) => !(headerName in lowerCaseHeaders));
|
|
509
|
-
};
|
|
510
|
-
};
|
|
511
|
-
const getMethodMatcher = ({ method: expectedMethod }) => {
|
|
512
|
-
if (!expectedMethod) return;
|
|
513
|
-
return ({ options: { method } = {} }) => {
|
|
514
|
-
return expectedMethod === (method ? method.toLowerCase() : "get");
|
|
515
|
-
};
|
|
516
|
-
};
|
|
517
|
-
const getQueryParamsMatcher = ({ query: passedQuery }) => {
|
|
518
|
-
if (!passedQuery) return;
|
|
519
|
-
const expectedQuery = new URLSearchParams();
|
|
520
|
-
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());
|
|
521
|
-
else expectedQuery.append(key, typeof value === "object" || typeof value === "undefined" ? "" : value.toString());
|
|
522
|
-
const keys = Array.from(expectedQuery.keys());
|
|
523
|
-
return ({ queryParams }) => {
|
|
524
|
-
return keys.every((key) => {
|
|
525
|
-
const expectedValues = expectedQuery.getAll(key).sort();
|
|
526
|
-
const actualValues = queryParams.getAll(key).sort();
|
|
527
|
-
if (expectedValues.length !== actualValues.length) return false;
|
|
528
|
-
if (Array.isArray(passedQuery[key])) return expectedValues.every((expected, index) => expected === actualValues[index]);
|
|
529
|
-
return dequal(actualValues, expectedValues);
|
|
530
|
-
});
|
|
531
|
-
};
|
|
532
|
-
};
|
|
533
|
-
const getExpressParamsMatcher = ({ params: expectedParams, url }) => {
|
|
534
|
-
if (!expectedParams) return;
|
|
535
|
-
if (!(typeof url === "string" && /express:/.test(url))) throw new Error("fetch-mock: matching on params is only possible when using an express: matcher");
|
|
536
|
-
const expectedKeys = Object.keys(expectedParams);
|
|
537
|
-
return ({ expressParams = {} }) => {
|
|
538
|
-
return expectedKeys.every((key) => expressParams[key] === expectedParams[key]);
|
|
539
|
-
};
|
|
540
|
-
};
|
|
541
|
-
const formDataToObject = (formData) => {
|
|
542
|
-
const fields = [...formData];
|
|
543
|
-
const result = {};
|
|
544
|
-
fields.forEach(([key, value]) => {
|
|
545
|
-
result[key] = result[key] || [];
|
|
546
|
-
result[key].push(value);
|
|
547
|
-
});
|
|
548
|
-
return result;
|
|
549
|
-
};
|
|
550
|
-
const getBodyMatcher = (route) => {
|
|
551
|
-
let { body: expectedBody } = route;
|
|
552
|
-
let expectedBodyType = "json";
|
|
553
|
-
if (!expectedBody) return;
|
|
554
|
-
if (expectedBody instanceof FormData) {
|
|
555
|
-
expectedBodyType = "formData";
|
|
556
|
-
expectedBody = formDataToObject(expectedBody);
|
|
557
|
-
}
|
|
558
|
-
return ({ options: { body, method = "get" } }) => {
|
|
559
|
-
if (["get", "head"].includes(method.toLowerCase())) return false;
|
|
560
|
-
let sentBody;
|
|
561
|
-
try {
|
|
562
|
-
if (typeof body === "string") {
|
|
563
|
-
sentBody = JSON.parse(body);
|
|
564
|
-
if (expectedBodyType !== "json") return false;
|
|
565
|
-
}
|
|
566
|
-
} catch {}
|
|
567
|
-
if (body instanceof FormData) {
|
|
568
|
-
if (expectedBodyType !== "formData") return false;
|
|
569
|
-
sentBody = formDataToObject(body);
|
|
570
|
-
}
|
|
571
|
-
return sentBody && (route.matchPartialBody ? isSubsetOf(expectedBody, sentBody) : dequal(expectedBody, sentBody));
|
|
572
|
-
};
|
|
573
|
-
};
|
|
574
|
-
const getFunctionMatcher = ({ matcherFunction }) => matcherFunction;
|
|
575
|
-
const getRegexpMatcher = (regexp) => ({ url }) => regexp.test(url);
|
|
576
|
-
const getFullUrlMatcher = (route, matcherUrl, query) => {
|
|
577
|
-
const expectedUrl = normalizeUrl(matcherUrl, route.allowRelativeUrls);
|
|
578
|
-
if (route.url === matcherUrl) route.url = expectedUrl;
|
|
579
|
-
return ({ url }) => {
|
|
580
|
-
if (query && expectedUrl.indexOf("?")) return getPath(url) === getPath(expectedUrl);
|
|
581
|
-
return normalizeUrl(url, true) === expectedUrl;
|
|
582
|
-
};
|
|
583
|
-
};
|
|
584
|
-
const getUrlMatcher = (route) => {
|
|
585
|
-
const { url: matcherUrl, query } = route;
|
|
586
|
-
if (matcherUrl === "*") return () => true;
|
|
587
|
-
if (matcherUrl instanceof RegExp) return getRegexpMatcher(matcherUrl);
|
|
588
|
-
if (matcherUrl instanceof URL) {
|
|
589
|
-
if (matcherUrl.href) return getFullUrlMatcher(route, matcherUrl.href, query);
|
|
590
|
-
}
|
|
591
|
-
if (typeof matcherUrl === "string") {
|
|
592
|
-
for (const shorthand in stringMatchers) if (matcherUrl.indexOf(`${shorthand}:`) === 0) {
|
|
593
|
-
const urlFragment = matcherUrl.replace(new RegExp(`^${shorthand}:`), "");
|
|
594
|
-
return stringMatchers[shorthand](urlFragment);
|
|
595
|
-
}
|
|
596
|
-
return getFullUrlMatcher(route, matcherUrl, query);
|
|
597
|
-
}
|
|
598
|
-
if (typeof matcherUrl === "object") {
|
|
599
|
-
const matchers = Object.entries(matcherUrl).map(([key, pattern]) => {
|
|
600
|
-
if (key === "regexp") return getRegexpMatcher(pattern);
|
|
601
|
-
else if (key in stringMatchers) return stringMatchers[key](pattern);
|
|
602
|
-
else throw new Error(`unrecognised url matching pattern: ${key}`);
|
|
603
|
-
});
|
|
604
|
-
return (route) => matchers.every((matcher) => matcher(route));
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
const builtInMatchers = [
|
|
608
|
-
{
|
|
609
|
-
name: "url",
|
|
610
|
-
matcher: getUrlMatcher
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
name: "query",
|
|
614
|
-
matcher: getQueryParamsMatcher
|
|
615
|
-
},
|
|
616
|
-
{
|
|
617
|
-
name: "method",
|
|
618
|
-
matcher: getMethodMatcher
|
|
619
|
-
},
|
|
620
|
-
{
|
|
621
|
-
name: "headers",
|
|
622
|
-
matcher: getHeaderMatcher
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
name: "missingHeaders",
|
|
626
|
-
matcher: getMissingHeaderMatcher
|
|
627
|
-
},
|
|
628
|
-
{
|
|
629
|
-
name: "params",
|
|
630
|
-
matcher: getExpressParamsMatcher
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
name: "body",
|
|
634
|
-
matcher: getBodyMatcher,
|
|
635
|
-
usesBody: true
|
|
636
|
-
},
|
|
637
|
-
{
|
|
638
|
-
name: "matcherFunction",
|
|
639
|
-
matcher: getFunctionMatcher
|
|
640
|
-
}
|
|
641
|
-
];
|
|
642
|
-
//#endregion
|
|
643
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/StatusTextMap.js
|
|
644
|
-
const statusTextMap = {
|
|
645
|
-
100: "Continue",
|
|
646
|
-
101: "Switching Protocols",
|
|
647
|
-
102: "Processing",
|
|
648
|
-
200: "OK",
|
|
649
|
-
201: "Created",
|
|
650
|
-
202: "Accepted",
|
|
651
|
-
203: "Non-Authoritative Information",
|
|
652
|
-
204: "No Content",
|
|
653
|
-
205: "Reset Content",
|
|
654
|
-
206: "Partial Content",
|
|
655
|
-
207: "Multi-Status",
|
|
656
|
-
208: "Already Reported",
|
|
657
|
-
226: "IM Used",
|
|
658
|
-
300: "Multiple Choices",
|
|
659
|
-
301: "Moved Permanently",
|
|
660
|
-
302: "Found",
|
|
661
|
-
303: "See Other",
|
|
662
|
-
304: "Not Modified",
|
|
663
|
-
305: "Use Proxy",
|
|
664
|
-
307: "Temporary Redirect",
|
|
665
|
-
308: "Permanent Redirect",
|
|
666
|
-
400: "Bad Request",
|
|
667
|
-
401: "Unauthorized",
|
|
668
|
-
402: "Payment Required",
|
|
669
|
-
403: "Forbidden",
|
|
670
|
-
404: "Not Found",
|
|
671
|
-
405: "Method Not Allowed",
|
|
672
|
-
406: "Not Acceptable",
|
|
673
|
-
407: "Proxy Authentication Required",
|
|
674
|
-
408: "Request Timeout",
|
|
675
|
-
409: "Conflict",
|
|
676
|
-
410: "Gone",
|
|
677
|
-
411: "Length Required",
|
|
678
|
-
412: "Precondition Failed",
|
|
679
|
-
413: "Payload Too Large",
|
|
680
|
-
414: "URI Too Long",
|
|
681
|
-
415: "Unsupported Media Type",
|
|
682
|
-
416: "Range Not Satisfiable",
|
|
683
|
-
417: "Expectation Failed",
|
|
684
|
-
418: "I'm a teapot",
|
|
685
|
-
421: "Misdirected Request",
|
|
686
|
-
422: "Unprocessable Entity",
|
|
687
|
-
423: "Locked",
|
|
688
|
-
424: "Failed Dependency",
|
|
689
|
-
425: "Unordered Collection",
|
|
690
|
-
426: "Upgrade Required",
|
|
691
|
-
428: "Precondition Required",
|
|
692
|
-
429: "Too Many Requests",
|
|
693
|
-
431: "Request Header Fields Too Large",
|
|
694
|
-
451: "Unavailable For Legal Reasons",
|
|
695
|
-
500: "Internal Server Error",
|
|
696
|
-
501: "Not Implemented",
|
|
697
|
-
502: "Bad Gateway",
|
|
698
|
-
503: "Service Unavailable",
|
|
699
|
-
504: "Gateway Timeout",
|
|
700
|
-
505: "HTTP Version Not Supported",
|
|
701
|
-
506: "Variant Also Negotiates",
|
|
702
|
-
507: "Insufficient Storage",
|
|
703
|
-
508: "Loop Detected",
|
|
704
|
-
509: "Bandwidth Limit Exceeded",
|
|
705
|
-
510: "Not Extended",
|
|
706
|
-
511: "Network Authentication Required"
|
|
707
|
-
};
|
|
12
|
+
//#region src/jsonld.ts
|
|
13
|
+
var jsonld_default = jsonld;
|
|
708
14
|
//#endregion
|
|
709
|
-
//#region
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
718
|
-
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");
|
|
719
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
//#region src/docloader.test.ts
|
|
16
|
+
const unpinnedPublicFetch = createPublicFetch({
|
|
17
|
+
pinner: () => Promise.resolve(null),
|
|
18
|
+
lookup: () => Promise.reject(/* @__PURE__ */ new Error("Unexpected default lookup"))
|
|
19
|
+
});
|
|
20
|
+
const PUBLIC_ADDRESS = {
|
|
21
|
+
address: "93.184.215.14",
|
|
22
|
+
family: 4
|
|
720
23
|
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
Object.assign(this, config);
|
|
725
|
-
}
|
|
24
|
+
const PRIVATE_ADDRESS = {
|
|
25
|
+
address: "10.0.0.1",
|
|
26
|
+
family: 4
|
|
726
27
|
};
|
|
727
|
-
function
|
|
728
|
-
return
|
|
28
|
+
function lookupTestAddresses(hostname) {
|
|
29
|
+
return Promise.resolve([hostname === "private.example" ? PRIVATE_ADDRESS : PUBLIC_ADDRESS]);
|
|
729
30
|
}
|
|
730
|
-
function
|
|
731
|
-
|
|
732
|
-
if (!status) return 200;
|
|
733
|
-
if (typeof status === "number" && parseInt(String(status), 10) !== status && status >= 200 || status < 600) return status;
|
|
734
|
-
throw new TypeError(`fetch-mock: Invalid status ${status} passed on response object.
|
|
735
|
-
To respond with a JSON object that has status as a property assign the object to body
|
|
736
|
-
e.g. {"body": {"status: "registered"}}`);
|
|
31
|
+
function openUnpinnedHop(url) {
|
|
32
|
+
return unpinnedPublicFetch.openPublicFetch(url, { lookup: lookupTestAddresses });
|
|
737
33
|
}
|
|
738
|
-
var Route = class {
|
|
739
|
-
constructor(config) {
|
|
740
|
-
_Route_instances.add(this);
|
|
741
|
-
_Route_responseSubscriptions.set(this, void 0);
|
|
742
|
-
this.init(config);
|
|
743
|
-
}
|
|
744
|
-
init(config) {
|
|
745
|
-
this.config = config;
|
|
746
|
-
__classPrivateFieldSet(this, _Route_responseSubscriptions, [], "f");
|
|
747
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_sanitize).call(this);
|
|
748
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_validate).call(this);
|
|
749
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_generateMatcher).call(this);
|
|
750
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_limit).call(this);
|
|
751
|
-
__classPrivateFieldGet(this, _Route_instances, "m", _Route_delayResponse).call(this);
|
|
752
|
-
}
|
|
753
|
-
reset() {}
|
|
754
|
-
waitFor(awaitedRoutes) {
|
|
755
|
-
const { response } = this.config;
|
|
756
|
-
this.config.response = Promise.all(awaitedRoutes.map((awaitedRoute) => new Promise((res) => awaitedRoute.onRespond(() => {
|
|
757
|
-
res(void 0);
|
|
758
|
-
})))).then(() => response);
|
|
759
|
-
}
|
|
760
|
-
onRespond(func) {
|
|
761
|
-
__classPrivateFieldGet(this, _Route_responseSubscriptions, "f").push(func);
|
|
762
|
-
}
|
|
763
|
-
constructResponse(responseInput) {
|
|
764
|
-
const responseOptions = this.constructResponseOptions(responseInput);
|
|
765
|
-
const body = this.constructResponseBody(responseInput, responseOptions);
|
|
766
|
-
const responsePackage = {
|
|
767
|
-
response: new this.config.Response(body, responseOptions),
|
|
768
|
-
responseOptions,
|
|
769
|
-
responseInput
|
|
770
|
-
};
|
|
771
|
-
__classPrivateFieldGet(this, _Route_responseSubscriptions, "f").forEach((func) => func());
|
|
772
|
-
return responsePackage;
|
|
773
|
-
}
|
|
774
|
-
constructResponseOptions(responseInput) {
|
|
775
|
-
const options = responseInput.options || {};
|
|
776
|
-
options.status = sanitizeStatus(responseInput.status);
|
|
777
|
-
options.statusText = statusTextMap[options.status];
|
|
778
|
-
options.headers = new this.config.Headers(responseInput.headers);
|
|
779
|
-
return options;
|
|
780
|
-
}
|
|
781
|
-
constructResponseBody(responseInput, responseOptions) {
|
|
782
|
-
let body = responseInput.body;
|
|
783
|
-
if (!isBodyInit(body)) if (typeof body === "undefined") body = null;
|
|
784
|
-
else if (typeof body === "object") {
|
|
785
|
-
body = JSON.stringify(body);
|
|
786
|
-
if (!responseOptions.headers.has("Content-Type")) responseOptions.headers.set("Content-Type", "application/json");
|
|
787
|
-
} else throw new TypeError("Invalid body provided to construct response");
|
|
788
|
-
if (this.config.includeContentLength && !responseOptions.headers.has("Content-Length") && !(body instanceof ReadableStream) && !(body instanceof FormData)) {
|
|
789
|
-
let length = 0;
|
|
790
|
-
if (body instanceof Blob) length = body.size;
|
|
791
|
-
else if (body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof DataView) length = body.byteLength;
|
|
792
|
-
else if (body instanceof URLSearchParams) length = body.toString().length;
|
|
793
|
-
else if (typeof body === "string" || body instanceof String) length = body.length;
|
|
794
|
-
responseOptions.headers.set("Content-Length", length.toString());
|
|
795
|
-
}
|
|
796
|
-
return body;
|
|
797
|
-
}
|
|
798
|
-
static defineMatcher(matcher) {
|
|
799
|
-
_a.registeredMatchers.push(matcher);
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
_a = Route, _Route_responseSubscriptions = /* @__PURE__ */ new WeakMap(), _Route_instances = /* @__PURE__ */ new WeakSet(), _Route_validate = function _Route_validate() {
|
|
803
|
-
if (["matched", "unmatched"].includes(this.config.name)) throw new Error(`fetch-mock: Routes cannot use the reserved name \`${this.config.name}\``);
|
|
804
|
-
if (!("response" in this.config)) throw new Error("fetch-mock: Each route must define a response");
|
|
805
|
-
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 '*'");
|
|
806
|
-
}, _Route_sanitize = function _Route_sanitize() {
|
|
807
|
-
if (this.config.method) this.config.method = this.config.method.toLowerCase();
|
|
808
|
-
}, _Route_generateMatcher = function _Route_generateMatcher() {
|
|
809
|
-
const activeMatchers = _a.registeredMatchers.filter(({ name }) => name in this.config).map(({ matcher, usesBody }) => ({
|
|
810
|
-
matcher: matcher(this.config),
|
|
811
|
-
usesBody
|
|
812
|
-
}));
|
|
813
|
-
this.config.usesBody = activeMatchers.some(({ usesBody }) => usesBody);
|
|
814
|
-
this.matcher = (normalizedRequest) => activeMatchers.every(({ matcher }) => matcher(normalizedRequest));
|
|
815
|
-
}, _Route_limit = function _Route_limit() {
|
|
816
|
-
if (!this.config.repeat) return;
|
|
817
|
-
const originalMatcher = this.matcher;
|
|
818
|
-
let timesLeft = this.config.repeat;
|
|
819
|
-
this.matcher = (callLog) => {
|
|
820
|
-
if (timesLeft && originalMatcher(callLog)) {
|
|
821
|
-
timesLeft--;
|
|
822
|
-
return true;
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
this.reset = () => {
|
|
826
|
-
timesLeft = this.config.repeat;
|
|
827
|
-
};
|
|
828
|
-
}, _Route_delayResponse = function _Route_delayResponse() {
|
|
829
|
-
if (this.config.delay) {
|
|
830
|
-
const { response } = this.config;
|
|
831
|
-
this.config.response = () => {
|
|
832
|
-
return new Promise((res) => setTimeout(() => res(response), this.config.delay));
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
Route.registeredMatchers = [];
|
|
837
|
-
builtInMatchers.forEach(Route.defineMatcher);
|
|
838
|
-
//#endregion
|
|
839
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/Router.js
|
|
840
|
-
const responseConfigProps = [
|
|
841
|
-
"body",
|
|
842
|
-
"headers",
|
|
843
|
-
"throws",
|
|
844
|
-
"status",
|
|
845
|
-
"redirectUrl"
|
|
846
|
-
];
|
|
847
|
-
function nameToOptions(options) {
|
|
848
|
-
return typeof options === "string" ? { name: options } : options;
|
|
849
|
-
}
|
|
850
|
-
function isPromise(response) {
|
|
851
|
-
return typeof response.then === "function";
|
|
852
|
-
}
|
|
853
|
-
function normalizeResponseInput(responseInput) {
|
|
854
|
-
if (typeof responseInput === "number") return { status: responseInput };
|
|
855
|
-
else if (typeof responseInput === "string" || shouldSendAsObject(responseInput)) return { body: responseInput };
|
|
856
|
-
return responseInput;
|
|
857
|
-
}
|
|
858
|
-
function shouldSendAsObject(responseInput) {
|
|
859
|
-
if (responseConfigProps.some((prop) => prop in responseInput)) {
|
|
860
|
-
if (Object.keys(responseInput).every((key) => responseConfigProps.includes(key))) return false;
|
|
861
|
-
return true;
|
|
862
|
-
}
|
|
863
|
-
return true;
|
|
864
|
-
}
|
|
865
|
-
function throwSpecExceptions({ url, options: { headers, method, body } }) {
|
|
866
|
-
if (headers) Object.entries(headers).forEach(([key]) => {
|
|
867
|
-
if (/\s/.test(key)) throw new TypeError("Invalid name");
|
|
868
|
-
});
|
|
869
|
-
if (hasCredentialsInUrl(url)) throw new TypeError(`Request cannot be constructed from a URL that includes credentials: ${url}`);
|
|
870
|
-
if (["get", "head"].includes(method) && body) throw new TypeError("Request with GET/HEAD method cannot have body.");
|
|
871
|
-
}
|
|
872
|
-
const resolveUntilResponseConfig = async (callLog) => {
|
|
873
|
-
let response = callLog.route.config.response;
|
|
874
|
-
while (true) if (typeof response === "function") response = response(callLog);
|
|
875
|
-
else if (isPromise(response)) response = await response;
|
|
876
|
-
else return response;
|
|
877
|
-
};
|
|
878
|
-
var Router = class {
|
|
879
|
-
constructor(fetchMockConfig, { routes, fallbackRoute } = {}) {
|
|
880
|
-
this.config = fetchMockConfig;
|
|
881
|
-
this.routes = routes || [];
|
|
882
|
-
this.fallbackRoute = fallbackRoute;
|
|
883
|
-
}
|
|
884
|
-
needsToReadBody(request) {
|
|
885
|
-
return Boolean(request && this.routes.some((route) => route.config.usesBody));
|
|
886
|
-
}
|
|
887
|
-
execute(callLog) {
|
|
888
|
-
throwSpecExceptions(callLog);
|
|
889
|
-
return new Promise(async (resolve, reject) => {
|
|
890
|
-
const { url, options, request, pendingPromises } = callLog;
|
|
891
|
-
let eventListenerAbortController;
|
|
892
|
-
if (callLog.signal) {
|
|
893
|
-
const abort = () => {
|
|
894
|
-
const error = new DOMException("The operation was aborted.", "AbortError");
|
|
895
|
-
const requestBody = request?.body || options?.body;
|
|
896
|
-
if (requestBody instanceof ReadableStream) if (requestBody.locked) console.warn("fetch-mock: Locked request body can't be cancelled");
|
|
897
|
-
else requestBody.cancel(error);
|
|
898
|
-
if (callLog?.response?.body) if (callLog.response.body.locked) console.warn("fetch-mock: Locked response body can't be cancelled");
|
|
899
|
-
else callLog.response.body.cancel(error);
|
|
900
|
-
reject(error);
|
|
901
|
-
};
|
|
902
|
-
if (callLog.signal.aborted) abort();
|
|
903
|
-
eventListenerAbortController = new AbortController();
|
|
904
|
-
callLog.signal.addEventListener("abort", abort, {
|
|
905
|
-
once: true,
|
|
906
|
-
signal: eventListenerAbortController.signal
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
if (this.needsToReadBody(request)) options.body = await options.body;
|
|
910
|
-
const route = (this.fallbackRoute ? [...this.routes, this.fallbackRoute] : this.routes).find((route) => route.matcher(callLog));
|
|
911
|
-
if (route) try {
|
|
912
|
-
callLog.route = route;
|
|
913
|
-
const { response, responseOptions, responseInput } = await this.generateResponse(callLog);
|
|
914
|
-
const observableResponse = this.createObservableResponse(response, responseOptions, responseInput, url, pendingPromises);
|
|
915
|
-
callLog.response = response;
|
|
916
|
-
resolve(observableResponse);
|
|
917
|
-
} catch (err) {
|
|
918
|
-
reject(err);
|
|
919
|
-
} finally {
|
|
920
|
-
eventListenerAbortController?.abort();
|
|
921
|
-
}
|
|
922
|
-
else reject(/* @__PURE__ */ new Error(`fetch-mock: No response or fallback rule to cover ${options && options.method || "GET"} to ${url}`));
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
async generateResponse(callLog) {
|
|
926
|
-
const responseInput = await resolveUntilResponseConfig(callLog);
|
|
927
|
-
if (responseInput instanceof Response) return {
|
|
928
|
-
response: responseInput.clone(),
|
|
929
|
-
responseOptions: {},
|
|
930
|
-
responseInput: {}
|
|
931
|
-
};
|
|
932
|
-
const responseConfig = normalizeResponseInput(responseInput);
|
|
933
|
-
if (responseConfig.throws) throw responseConfig.throws;
|
|
934
|
-
return callLog.route.constructResponse(responseConfig);
|
|
935
|
-
}
|
|
936
|
-
createObservableResponse(response, responseConfig, responseInput, responseUrl, pendingPromises) {
|
|
937
|
-
return new Proxy(response, { get: (originalResponse, name) => {
|
|
938
|
-
if (responseInput.redirectUrl) {
|
|
939
|
-
if (name === "url") return responseInput.redirectUrl;
|
|
940
|
-
if (name === "redirected") return true;
|
|
941
|
-
} else {
|
|
942
|
-
if (name === "url") return responseUrl;
|
|
943
|
-
if (name === "redirected") return false;
|
|
944
|
-
}
|
|
945
|
-
if (responseInput.status === 0) {
|
|
946
|
-
if (name === "status") return 0;
|
|
947
|
-
if (name === "statusText") return "";
|
|
948
|
-
}
|
|
949
|
-
if (typeof response[name] === "function") return new Proxy(response[name], { apply: (func, thisArg, args) => {
|
|
950
|
-
const result = func.apply(response, args);
|
|
951
|
-
if (result.then) pendingPromises.push(result.catch(() => void 0));
|
|
952
|
-
return result;
|
|
953
|
-
} });
|
|
954
|
-
return originalResponse[name];
|
|
955
|
-
} });
|
|
956
|
-
}
|
|
957
|
-
addRoute(matcher, response, nameOrOptions) {
|
|
958
|
-
const config = {};
|
|
959
|
-
if (matcher instanceof RouteConfigWrapper) Object.assign(config, matcher);
|
|
960
|
-
if (isUrlMatcher(matcher)) config.url = matcher;
|
|
961
|
-
else if (isFunctionMatcher(matcher)) config.matcherFunction = matcher;
|
|
962
|
-
else Object.assign(config, matcher);
|
|
963
|
-
if (typeof response !== "undefined") config.response = response;
|
|
964
|
-
if (nameOrOptions) Object.assign(config, typeof nameOrOptions === "string" ? nameToOptions(nameOrOptions) : nameOrOptions);
|
|
965
|
-
const route = new Route({
|
|
966
|
-
...this.config,
|
|
967
|
-
...config
|
|
968
|
-
});
|
|
969
|
-
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.");
|
|
970
|
-
if (route.config.waitFor) {
|
|
971
|
-
const routeNamesToWaitFor = Array.isArray(route.config.waitFor) ? route.config.waitFor : [route.config.waitFor];
|
|
972
|
-
const routesToAwait = [];
|
|
973
|
-
routeNamesToWaitFor.forEach((routeName) => {
|
|
974
|
-
const routeToAwait = this.routes.find(({ config: { name: existingName } }) => routeName === existingName);
|
|
975
|
-
if (routeToAwait) routesToAwait.push(routeToAwait);
|
|
976
|
-
else throw new Error(`Cannot wait for route \`${routeName}\`: route of that name does not exist`);
|
|
977
|
-
});
|
|
978
|
-
route.waitFor(routesToAwait);
|
|
979
|
-
}
|
|
980
|
-
this.routes.push(route);
|
|
981
|
-
}
|
|
982
|
-
setFallback(response) {
|
|
983
|
-
if (this.fallbackRoute) console.warn("calling fetchMock.catch() twice - are you sure you want to overwrite the previous fallback response");
|
|
984
|
-
this.fallbackRoute = new Route({
|
|
985
|
-
matcherFunction: () => true,
|
|
986
|
-
response: response || "ok",
|
|
987
|
-
...this.config
|
|
988
|
-
});
|
|
989
|
-
this.fallbackRoute.config.isFallback = true;
|
|
990
|
-
}
|
|
991
|
-
removeRoutes({ names, includeSticky, includeFallback } = {}) {
|
|
992
|
-
includeFallback = includeFallback ?? true;
|
|
993
|
-
this.routes = this.routes.filter(({ config: { sticky, name } }) => {
|
|
994
|
-
if (sticky && !includeSticky) return true;
|
|
995
|
-
if (!names) return false;
|
|
996
|
-
return !names.includes(name);
|
|
997
|
-
});
|
|
998
|
-
if (includeFallback) delete this.fallbackRoute;
|
|
999
|
-
}
|
|
1000
|
-
modifyRoute(routeName, options) {
|
|
1001
|
-
const route = this.routes.find(({ config: { name } }) => name === routeName);
|
|
1002
|
-
if (!route) throw new Error(`Cannot call modifyRoute() on route \`${routeName}\`: route of that name not found`);
|
|
1003
|
-
if (route.config.sticky) throw new Error(`Cannot call modifyRoute() on route \`${routeName}\`: route is sticky and cannot be modified`);
|
|
1004
|
-
if ("name" in options) throw new Error(`Cannot rename the route \`${routeName}\` as \`${options.name}\`: renaming routes is not supported`);
|
|
1005
|
-
if ("sticky" in options) throw new Error(`Altering the stickiness of route \`${routeName}\` is not supported`);
|
|
1006
|
-
const newConfig = {
|
|
1007
|
-
...route.config,
|
|
1008
|
-
...options
|
|
1009
|
-
};
|
|
1010
|
-
Object.entries(options).forEach(([key, value]) => {
|
|
1011
|
-
if (value === null) delete newConfig[key];
|
|
1012
|
-
});
|
|
1013
|
-
route.init(newConfig);
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
//#endregion
|
|
1017
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/CallHistory.js
|
|
1018
|
-
const isName = (filter) => typeof filter === "string" && /^[\da-zA-Z-]+$/.test(filter) && !["matched", "unmatched"].includes(filter);
|
|
1019
|
-
const isMatchedOrUnmatched = (filter) => typeof filter === "boolean" || ["matched", "unmatched"].includes(filter);
|
|
1020
|
-
var CallHistory = class {
|
|
1021
|
-
constructor(config, router) {
|
|
1022
|
-
this.callLogs = [];
|
|
1023
|
-
this.config = config;
|
|
1024
|
-
this.router = router;
|
|
1025
|
-
}
|
|
1026
|
-
recordCall(callLog) {
|
|
1027
|
-
this.callLogs.push(callLog);
|
|
1028
|
-
}
|
|
1029
|
-
clear() {
|
|
1030
|
-
this.callLogs.forEach(({ route }) => {
|
|
1031
|
-
if (route) route.reset();
|
|
1032
|
-
});
|
|
1033
|
-
this.callLogs = [];
|
|
1034
|
-
}
|
|
1035
|
-
async flush(waitForResponseMethods) {
|
|
1036
|
-
const queuedPromises = this.callLogs.flatMap((call) => call.pendingPromises);
|
|
1037
|
-
await Promise.allSettled(queuedPromises);
|
|
1038
|
-
if (waitForResponseMethods) {
|
|
1039
|
-
await Promise.resolve();
|
|
1040
|
-
await this.flush();
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
calls(filter, options) {
|
|
1044
|
-
let calls = [...this.callLogs];
|
|
1045
|
-
if (typeof filter === "undefined" && !options) return calls;
|
|
1046
|
-
if (isMatchedOrUnmatched(filter)) {
|
|
1047
|
-
if ([true, "matched"].includes(filter)) calls = calls.filter(({ route }) => !route?.config || !route.config.isFallback);
|
|
1048
|
-
else if ([false, "unmatched"].includes(filter)) calls = calls.filter(({ route }) => Boolean(route?.config && route.config.isFallback));
|
|
1049
|
-
if (!options) return calls;
|
|
1050
|
-
} else if (isName(filter)) {
|
|
1051
|
-
calls = calls.filter(({ route }) => route?.config?.name === filter);
|
|
1052
|
-
if (!options) return calls;
|
|
1053
|
-
} else if (isUrlMatcher(filter)) options = {
|
|
1054
|
-
url: filter,
|
|
1055
|
-
...options || {}
|
|
1056
|
-
};
|
|
1057
|
-
else options = {
|
|
1058
|
-
...filter,
|
|
1059
|
-
...options || {}
|
|
1060
|
-
};
|
|
1061
|
-
const { matcher } = new Route({
|
|
1062
|
-
response: "ok",
|
|
1063
|
-
...options
|
|
1064
|
-
});
|
|
1065
|
-
calls = calls.filter(({ url, options }) => {
|
|
1066
|
-
return matcher(createCallLogFromUrlAndOptions(url, options));
|
|
1067
|
-
});
|
|
1068
|
-
return calls;
|
|
1069
|
-
}
|
|
1070
|
-
called(filter, options) {
|
|
1071
|
-
return Boolean(this.calls(filter, options).length);
|
|
1072
|
-
}
|
|
1073
|
-
lastCall(filter, options) {
|
|
1074
|
-
return this.calls(filter, options).pop();
|
|
1075
|
-
}
|
|
1076
|
-
done(routeNames) {
|
|
1077
|
-
let routesToCheck = this.router.routes;
|
|
1078
|
-
if (routeNames) {
|
|
1079
|
-
routeNames = Array.isArray(routeNames) ? routeNames : [routeNames];
|
|
1080
|
-
routesToCheck = this.router.routes.filter(({ config: { name } }) => routeNames.includes(name));
|
|
1081
|
-
}
|
|
1082
|
-
return routesToCheck.map((route) => {
|
|
1083
|
-
const calls = this.callLogs.filter(({ route: routeApplied }) => routeApplied === route);
|
|
1084
|
-
if (!calls.length) {
|
|
1085
|
-
console.warn(`Warning: ${route.config.name} not called`);
|
|
1086
|
-
return false;
|
|
1087
|
-
}
|
|
1088
|
-
const expectedTimes = route.config.repeat;
|
|
1089
|
-
if (!expectedTimes) return true;
|
|
1090
|
-
const actualTimes = calls.length;
|
|
1091
|
-
if (expectedTimes > actualTimes) {
|
|
1092
|
-
console.warn(`Warning: ${route.config.name} only called ${actualTimes} times, but ${expectedTimes} expected`);
|
|
1093
|
-
return false;
|
|
1094
|
-
}
|
|
1095
|
-
return true;
|
|
1096
|
-
}).every((isDone) => isDone);
|
|
1097
|
-
}
|
|
1098
|
-
};
|
|
1099
|
-
//#endregion
|
|
1100
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/FetchMock.js
|
|
1101
|
-
const defaultFetchMockConfig = {
|
|
1102
|
-
includeContentLength: true,
|
|
1103
|
-
matchPartialBody: false,
|
|
1104
|
-
Request: globalThis.Request,
|
|
1105
|
-
Response: globalThis.Response,
|
|
1106
|
-
Headers: globalThis.Headers,
|
|
1107
|
-
fetch: globalThis.fetch
|
|
1108
|
-
};
|
|
1109
|
-
const defineShorthand = (shorthandOptions) => {
|
|
1110
|
-
function shorthand(matcher, response, options) {
|
|
1111
|
-
return this.route(matcher, response, Object.assign(options || {}, shorthandOptions));
|
|
1112
|
-
}
|
|
1113
|
-
return shorthand;
|
|
1114
|
-
};
|
|
1115
|
-
const defineGreedyShorthand = (shorthandOptions) => {
|
|
1116
|
-
return function(response, options) {
|
|
1117
|
-
return this.route("*", response, Object.assign(options || {}, shorthandOptions));
|
|
1118
|
-
};
|
|
1119
|
-
};
|
|
1120
|
-
//#endregion
|
|
1121
|
-
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/index.js
|
|
1122
|
-
var esm_default = new class FetchMock {
|
|
1123
|
-
constructor(config, router) {
|
|
1124
|
-
this.sticky = defineShorthand({ sticky: true });
|
|
1125
|
-
this.once = defineShorthand({ repeat: 1 });
|
|
1126
|
-
this.any = defineGreedyShorthand({});
|
|
1127
|
-
this.anyOnce = defineGreedyShorthand({ repeat: 1 });
|
|
1128
|
-
this.get = defineShorthand({ method: "get" });
|
|
1129
|
-
this.getOnce = defineShorthand({
|
|
1130
|
-
method: "get",
|
|
1131
|
-
repeat: 1
|
|
1132
|
-
});
|
|
1133
|
-
this.post = defineShorthand({ method: "post" });
|
|
1134
|
-
this.postOnce = defineShorthand({
|
|
1135
|
-
method: "post",
|
|
1136
|
-
repeat: 1
|
|
1137
|
-
});
|
|
1138
|
-
this.put = defineShorthand({ method: "put" });
|
|
1139
|
-
this.putOnce = defineShorthand({
|
|
1140
|
-
method: "put",
|
|
1141
|
-
repeat: 1
|
|
1142
|
-
});
|
|
1143
|
-
this.delete = defineShorthand({ method: "delete" });
|
|
1144
|
-
this.deleteOnce = defineShorthand({
|
|
1145
|
-
method: "delete",
|
|
1146
|
-
repeat: 1
|
|
1147
|
-
});
|
|
1148
|
-
this.head = defineShorthand({ method: "head" });
|
|
1149
|
-
this.headOnce = defineShorthand({
|
|
1150
|
-
method: "head",
|
|
1151
|
-
repeat: 1
|
|
1152
|
-
});
|
|
1153
|
-
this.patch = defineShorthand({ method: "patch" });
|
|
1154
|
-
this.patchOnce = defineShorthand({
|
|
1155
|
-
method: "patch",
|
|
1156
|
-
repeat: 1
|
|
1157
|
-
});
|
|
1158
|
-
this.config = config;
|
|
1159
|
-
this.router = new Router(this.config, {
|
|
1160
|
-
routes: router ? [...router.routes] : [],
|
|
1161
|
-
fallbackRoute: router ? router.fallbackRoute : null
|
|
1162
|
-
});
|
|
1163
|
-
this.callHistory = new CallHistory(this.config, this.router);
|
|
1164
|
-
this.fetchHandler = this.fetchHandler.bind(this);
|
|
1165
|
-
Object.assign(this.fetchHandler, { fetchMock: this });
|
|
1166
|
-
}
|
|
1167
|
-
createInstance() {
|
|
1168
|
-
return new FetchMock({ ...this.config }, this.router);
|
|
1169
|
-
}
|
|
1170
|
-
async fetchHandler(requestInput, requestInit) {
|
|
1171
|
-
let callLog;
|
|
1172
|
-
if (requestInput instanceof this.config.Request) callLog = await createCallLogFromRequest(requestInput, requestInit);
|
|
1173
|
-
else callLog = createCallLogFromUrlAndOptions(requestInput, requestInit);
|
|
1174
|
-
this.callHistory.recordCall(callLog);
|
|
1175
|
-
const responsePromise = this.router.execute(callLog);
|
|
1176
|
-
callLog.pendingPromises.push(responsePromise);
|
|
1177
|
-
return responsePromise;
|
|
1178
|
-
}
|
|
1179
|
-
route(matcher, response, options) {
|
|
1180
|
-
this.router.addRoute(matcher, response, options);
|
|
1181
|
-
return this;
|
|
1182
|
-
}
|
|
1183
|
-
catch(response) {
|
|
1184
|
-
this.router.setFallback(response);
|
|
1185
|
-
return this;
|
|
1186
|
-
}
|
|
1187
|
-
defineMatcher(matcher) {
|
|
1188
|
-
Route.defineMatcher(matcher);
|
|
1189
|
-
}
|
|
1190
|
-
removeRoutes(options) {
|
|
1191
|
-
this.router.removeRoutes(options);
|
|
1192
|
-
return this;
|
|
1193
|
-
}
|
|
1194
|
-
removeRoute(routeName) {
|
|
1195
|
-
this.router.removeRoutes({ names: [routeName] });
|
|
1196
|
-
return this;
|
|
1197
|
-
}
|
|
1198
|
-
modifyRoute(routeName, options) {
|
|
1199
|
-
this.router.modifyRoute(routeName, options);
|
|
1200
|
-
return this;
|
|
1201
|
-
}
|
|
1202
|
-
clearHistory() {
|
|
1203
|
-
this.callHistory.clear();
|
|
1204
|
-
return this;
|
|
1205
|
-
}
|
|
1206
|
-
mockGlobal() {
|
|
1207
|
-
globalThis.fetch = this.fetchHandler;
|
|
1208
|
-
return this;
|
|
1209
|
-
}
|
|
1210
|
-
unmockGlobal() {
|
|
1211
|
-
globalThis.fetch = this.config.fetch;
|
|
1212
|
-
return this;
|
|
1213
|
-
}
|
|
1214
|
-
hardReset(options) {
|
|
1215
|
-
this.clearHistory();
|
|
1216
|
-
this.removeRoutes(options);
|
|
1217
|
-
this.unmockGlobal();
|
|
1218
|
-
return this;
|
|
1219
|
-
}
|
|
1220
|
-
spy(matcher, name) {
|
|
1221
|
-
const boundFetch = this.config.fetch.bind(globalThis);
|
|
1222
|
-
if (matcher) this.route(matcher, ({ args }) => boundFetch(...args), name);
|
|
1223
|
-
else this.catch(({ args }) => boundFetch(...args));
|
|
1224
|
-
return this;
|
|
1225
|
-
}
|
|
1226
|
-
spyGlobal() {
|
|
1227
|
-
this.mockGlobal();
|
|
1228
|
-
return this.spy();
|
|
1229
|
-
}
|
|
1230
|
-
}({ ...defaultFetchMockConfig });
|
|
1231
|
-
//#endregion
|
|
1232
|
-
//#region src/jsonld.ts
|
|
1233
|
-
var jsonld_default = jsonld;
|
|
1234
|
-
//#endregion
|
|
1235
|
-
//#region src/docloader.test.ts
|
|
1236
34
|
test("new FetchError()", () => {
|
|
1237
35
|
const e = new FetchError("https://example.com/", "An error message.");
|
|
1238
36
|
deepStrictEqual(e.name, "FetchError");
|
|
@@ -1247,7 +45,7 @@ test("new FetchError()", () => {
|
|
|
1247
45
|
deepStrictEqual(e2.response.status, 410);
|
|
1248
46
|
});
|
|
1249
47
|
test("getDocumentLoader()", async (t) => {
|
|
1250
|
-
const fetchDocumentLoader =
|
|
48
|
+
const fetchDocumentLoader = createDocumentLoader({}, { openHop: openUnpinnedHop });
|
|
1251
49
|
esm_default.spyGlobal();
|
|
1252
50
|
esm_default.get("https://example.com/object", { body: {
|
|
1253
51
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
@@ -1662,10 +460,26 @@ test("getDocumentLoader()", async (t) => {
|
|
|
1662
460
|
name: "Fetched object",
|
|
1663
461
|
type: "Object"
|
|
1664
462
|
} });
|
|
463
|
+
esm_default.get("https://example.com/private-redirect", {
|
|
464
|
+
status: 302,
|
|
465
|
+
headers: { Location: "https://private.example/object" }
|
|
466
|
+
});
|
|
467
|
+
esm_default.get("https://private.example/object", { body: {
|
|
468
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
469
|
+
id: "https://private.example/object",
|
|
470
|
+
type: "Object"
|
|
471
|
+
} });
|
|
1665
472
|
await t.step("allowPrivateAddress: false", async () => {
|
|
1666
473
|
await rejects(() => fetchDocumentLoader("https://localhost/object"), UrlError);
|
|
1667
474
|
await rejects(() => fetchDocumentLoader("https://example.com/localhost-redirect"), UrlError);
|
|
1668
475
|
await rejects(() => fetchDocumentLoader("https://example.com/localhost-link"), UrlError);
|
|
476
|
+
await rejects(() => fetchDocumentLoader("https://private.example/object"), UrlError);
|
|
477
|
+
await rejects(() => fetchDocumentLoader("https://example.com/private-redirect"), UrlError);
|
|
478
|
+
deepStrictEqual(esm_default.callHistory.calls("https://private.example/object").length, 0);
|
|
479
|
+
const defaultLoader = getDocumentLoader();
|
|
480
|
+
await rejects(() => defaultLoader("https://localhost/object"), UrlError);
|
|
481
|
+
await rejects(() => defaultLoader("https://127.0.0.1/object"), UrlError);
|
|
482
|
+
deepStrictEqual(esm_default.callHistory.calls("https://localhost/object").length, 0);
|
|
1669
483
|
});
|
|
1670
484
|
const fetchDocumentLoader2 = getDocumentLoader({ allowPrivateAddress: true });
|
|
1671
485
|
await t.step("allowPrivateAddress: true", async () => {
|
|
@@ -1698,7 +512,7 @@ test("getDocumentLoader()", async (t) => {
|
|
|
1698
512
|
});
|
|
1699
513
|
await t.step("custom max redirection", async () => {
|
|
1700
514
|
redirectAttempts = 0;
|
|
1701
|
-
const loader =
|
|
515
|
+
const loader = createDocumentLoader({ maxRedirection: 1 }, { openHop: openUnpinnedHop });
|
|
1702
516
|
await rejects(() => loader("https://example.com/too-many-redirects/0"), FetchError, "Too many redirections");
|
|
1703
517
|
deepStrictEqual(redirectAttempts, 2);
|
|
1704
518
|
});
|
|
@@ -1826,18 +640,14 @@ test("getRemoteDocument() bounds JSON by default", async () => {
|
|
|
1826
640
|
deepStrictEqual(pulls, 257);
|
|
1827
641
|
});
|
|
1828
642
|
test("getDocumentLoader() logs DNS failures as such", async (t) => {
|
|
1829
|
-
if ("Deno" in globalThis && (await Deno.permissions.query({ name: "net" })).state !== "granted") throw new Error("This DNS test requires Deno network permission (--allow-net).");
|
|
1830
|
-
const loader = getDocumentLoader();
|
|
1831
643
|
for (const result of [
|
|
1832
644
|
"throws",
|
|
1833
645
|
"empty",
|
|
1834
|
-
"private"
|
|
646
|
+
"private",
|
|
647
|
+
"default"
|
|
1835
648
|
]) await t.step(result, async () => {
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
address: "127.0.0.1",
|
|
1839
|
-
family: 4
|
|
1840
|
-
}]));
|
|
649
|
+
const lookup = () => result === "throws" ? Promise.reject(/* @__PURE__ */ new Error("Resolver unavailable")) : Promise.resolve(result === "empty" ? [] : [PRIVATE_ADDRESS]);
|
|
650
|
+
const loader = result === "default" ? getDocumentLoader() : createDocumentLoader({}, { openHop: (url) => unpinnedPublicFetch.openPublicFetch(url, { lookup }) });
|
|
1841
651
|
const records = [];
|
|
1842
652
|
await configure({
|
|
1843
653
|
sinks: { buffer: (record) => records.push(record) },
|
|
@@ -1852,19 +662,20 @@ test("getDocumentLoader() logs DNS failures as such", async (t) => {
|
|
|
1852
662
|
reset: true
|
|
1853
663
|
});
|
|
1854
664
|
try {
|
|
1855
|
-
const url = "https://dns-failure.invalid/object";
|
|
665
|
+
const url = result === "default" ? "https://10.0.0.1/object" : "https://dns-failure.invalid/object";
|
|
1856
666
|
let error;
|
|
1857
667
|
await rejects(() => loader(url), (e) => {
|
|
1858
668
|
error = e;
|
|
1859
669
|
return true;
|
|
1860
670
|
});
|
|
1861
671
|
ok(error instanceof UrlError);
|
|
1862
|
-
|
|
672
|
+
const disallowed = result === "private" || result === "default";
|
|
673
|
+
deepStrictEqual(error.reason, disallowed ? "disallowed" : "dns");
|
|
1863
674
|
deepStrictEqual(records.map((r) => [
|
|
1864
675
|
r.level,
|
|
1865
676
|
r.rawMessage,
|
|
1866
677
|
r.properties.url
|
|
1867
|
-
]), [
|
|
678
|
+
]), [disallowed ? [
|
|
1868
679
|
"error",
|
|
1869
680
|
"Disallowed private URL: {url}",
|
|
1870
681
|
url
|
|
@@ -1876,7 +687,6 @@ test("getDocumentLoader() logs DNS failures as such", async (t) => {
|
|
|
1876
687
|
ok(records[0].properties.error === error);
|
|
1877
688
|
} finally {
|
|
1878
689
|
await reset();
|
|
1879
|
-
dns.lookup = originalLookup;
|
|
1880
690
|
}
|
|
1881
691
|
});
|
|
1882
692
|
});
|
|
@@ -2120,5 +930,426 @@ for (const url of unsupportedUrls) {
|
|
|
2120
930
|
});
|
|
2121
931
|
});
|
|
2122
932
|
}
|
|
933
|
+
function createHopRecorder(responder) {
|
|
934
|
+
const events = [];
|
|
935
|
+
const states = /* @__PURE__ */ new Map();
|
|
936
|
+
const violations = [];
|
|
937
|
+
let responses = 0;
|
|
938
|
+
let opens = 0;
|
|
939
|
+
let closes = 0;
|
|
940
|
+
function respond(url) {
|
|
941
|
+
const n = ++responses;
|
|
942
|
+
events.push(`fetch ${url} #${n}`);
|
|
943
|
+
const { status = 200, headers, body = "", failCancel, hangCancel, responseUrl } = responder(url);
|
|
944
|
+
const state = {
|
|
945
|
+
n,
|
|
946
|
+
settled: false
|
|
947
|
+
};
|
|
948
|
+
let sent = false;
|
|
949
|
+
const stream = new ReadableStream({
|
|
950
|
+
pull(controller) {
|
|
951
|
+
if (!sent && body !== "") {
|
|
952
|
+
sent = true;
|
|
953
|
+
controller.enqueue(new TextEncoder().encode(body));
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
controller.close();
|
|
957
|
+
state.settled = true;
|
|
958
|
+
events.push(`consumed #${n}`);
|
|
959
|
+
},
|
|
960
|
+
cancel() {
|
|
961
|
+
state.settled = true;
|
|
962
|
+
events.push(`cancel #${n}`);
|
|
963
|
+
if (failCancel) throw new Error(`Failed to cancel #${n}`);
|
|
964
|
+
if (hangCancel) return new Promise(() => {});
|
|
965
|
+
}
|
|
966
|
+
}, { highWaterMark: 0 });
|
|
967
|
+
const response = new Response(stream, {
|
|
968
|
+
status,
|
|
969
|
+
headers
|
|
970
|
+
});
|
|
971
|
+
if (responseUrl != null) Object.defineProperty(response, "url", { value: responseUrl });
|
|
972
|
+
states.set(response, state);
|
|
973
|
+
return response;
|
|
974
|
+
}
|
|
975
|
+
function record(url, session) {
|
|
976
|
+
opens++;
|
|
977
|
+
events.push(`open ${url}`);
|
|
978
|
+
const fetched = [];
|
|
979
|
+
let closed = false;
|
|
980
|
+
return {
|
|
981
|
+
get url() {
|
|
982
|
+
return session.url;
|
|
983
|
+
},
|
|
984
|
+
async fetch(input, init) {
|
|
985
|
+
const response = await session.fetch(input, init);
|
|
986
|
+
fetched.push(response);
|
|
987
|
+
return response;
|
|
988
|
+
},
|
|
989
|
+
async close() {
|
|
990
|
+
if (closed) return;
|
|
991
|
+
closed = true;
|
|
992
|
+
for (const response of fetched) {
|
|
993
|
+
const state = states.get(response);
|
|
994
|
+
if (state != null && !state.settled) violations.push(`#${state.n} is still open when closing ${url}`);
|
|
995
|
+
}
|
|
996
|
+
closes++;
|
|
997
|
+
events.push(`close ${url}`);
|
|
998
|
+
await session.close();
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
function openHop(url) {
|
|
1003
|
+
const origin = new URL(url).origin;
|
|
1004
|
+
return Promise.resolve(record(url, {
|
|
1005
|
+
url: new URL(url),
|
|
1006
|
+
fetch(input) {
|
|
1007
|
+
const target = input instanceof Request ? input.url : String(input);
|
|
1008
|
+
ok(new URL(target).origin === origin, `${target} is not on ${origin}`);
|
|
1009
|
+
return Promise.resolve(respond(target));
|
|
1010
|
+
},
|
|
1011
|
+
close: () => Promise.resolve()
|
|
1012
|
+
}));
|
|
1013
|
+
}
|
|
1014
|
+
return {
|
|
1015
|
+
events,
|
|
1016
|
+
respond,
|
|
1017
|
+
record,
|
|
1018
|
+
openHop,
|
|
1019
|
+
assertInvariants() {
|
|
1020
|
+
deepStrictEqual(violations, []);
|
|
1021
|
+
deepStrictEqual(opens, closes);
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
const lifecycleDocument = {
|
|
1026
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
1027
|
+
id: "https://b.example/object",
|
|
1028
|
+
type: "Object"
|
|
1029
|
+
};
|
|
1030
|
+
test("getDocumentLoader() closes a redirect hop before the next hop", async () => {
|
|
1031
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1032
|
+
status: 302,
|
|
1033
|
+
headers: { Location: "https://b.example/object" }
|
|
1034
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1035
|
+
deepStrictEqual(await createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start"), {
|
|
1036
|
+
contextUrl: null,
|
|
1037
|
+
documentUrl: "https://b.example/object",
|
|
1038
|
+
document: lifecycleDocument
|
|
1039
|
+
});
|
|
1040
|
+
deepStrictEqual(recorder.events, [
|
|
1041
|
+
"open https://a.example/start",
|
|
1042
|
+
"fetch https://a.example/start #1",
|
|
1043
|
+
"cancel #1",
|
|
1044
|
+
"close https://a.example/start",
|
|
1045
|
+
"open https://b.example/object",
|
|
1046
|
+
"fetch https://b.example/object #2",
|
|
1047
|
+
"consumed #2",
|
|
1048
|
+
"close https://b.example/object"
|
|
1049
|
+
]);
|
|
1050
|
+
recorder.assertInvariants();
|
|
1051
|
+
});
|
|
1052
|
+
test("getDocumentLoader() cancels the body before a Link header alternate", async () => {
|
|
1053
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1054
|
+
headers: {
|
|
1055
|
+
"Content-Type": "text/plain",
|
|
1056
|
+
Link: "<https://b.example/object>; rel=\"alternate\"; type=\"application/activity+json\""
|
|
1057
|
+
},
|
|
1058
|
+
body: "not JSON"
|
|
1059
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1060
|
+
deepStrictEqual((await createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start")).documentUrl, "https://b.example/object");
|
|
1061
|
+
deepStrictEqual(recorder.events, [
|
|
1062
|
+
"open https://a.example/start",
|
|
1063
|
+
"fetch https://a.example/start #1",
|
|
1064
|
+
"cancel #1",
|
|
1065
|
+
"close https://a.example/start",
|
|
1066
|
+
"open https://b.example/object",
|
|
1067
|
+
"fetch https://b.example/object #2",
|
|
1068
|
+
"consumed #2",
|
|
1069
|
+
"close https://b.example/object"
|
|
1070
|
+
]);
|
|
1071
|
+
recorder.assertInvariants();
|
|
1072
|
+
});
|
|
1073
|
+
test("getDocumentLoader() reads the body before an HTML alternate", async () => {
|
|
1074
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1075
|
+
headers: { "Content-Type": "text/html" },
|
|
1076
|
+
body: "<link rel=\"alternate\" type=\"application/activity+json\" href=\"https://b.example/object\">"
|
|
1077
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1078
|
+
deepStrictEqual((await createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start")).documentUrl, "https://b.example/object");
|
|
1079
|
+
deepStrictEqual(recorder.events, [
|
|
1080
|
+
"open https://a.example/start",
|
|
1081
|
+
"fetch https://a.example/start #1",
|
|
1082
|
+
"consumed #1",
|
|
1083
|
+
"close https://a.example/start",
|
|
1084
|
+
"open https://b.example/object",
|
|
1085
|
+
"fetch https://b.example/object #2",
|
|
1086
|
+
"consumed #2",
|
|
1087
|
+
"close https://b.example/object"
|
|
1088
|
+
]);
|
|
1089
|
+
recorder.assertInvariants();
|
|
1090
|
+
});
|
|
1091
|
+
/**
|
|
1092
|
+
* Fails instead of blocking the test if the given promise does not settle
|
|
1093
|
+
* within the given time.
|
|
1094
|
+
*/
|
|
1095
|
+
async function settlesWithin(promise, milliseconds = 1e3) {
|
|
1096
|
+
let timer;
|
|
1097
|
+
try {
|
|
1098
|
+
return await Promise.race([promise, new Promise((_, reject) => {
|
|
1099
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Did not settle in ${milliseconds} ms.`)), milliseconds);
|
|
1100
|
+
})]);
|
|
1101
|
+
} finally {
|
|
1102
|
+
clearTimeout(timer);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Runs the given function while capturing the document loader's logs, and
|
|
1107
|
+
* waits until the rejections of body cancellations started without being
|
|
1108
|
+
* awaited have been logged.
|
|
1109
|
+
*/
|
|
1110
|
+
async function captureDocumentLoaderLogs(fn) {
|
|
1111
|
+
const records = [];
|
|
1112
|
+
await configure({
|
|
1113
|
+
sinks: { buffer: (record) => records.push(record) },
|
|
1114
|
+
loggers: [{
|
|
1115
|
+
category: [
|
|
1116
|
+
"fedify",
|
|
1117
|
+
"runtime",
|
|
1118
|
+
"docloader"
|
|
1119
|
+
],
|
|
1120
|
+
sinks: ["buffer"],
|
|
1121
|
+
lowestLevel: "debug"
|
|
1122
|
+
}, {
|
|
1123
|
+
category: ["logtape", "meta"],
|
|
1124
|
+
sinks: []
|
|
1125
|
+
}],
|
|
1126
|
+
reset: true
|
|
1127
|
+
});
|
|
1128
|
+
try {
|
|
1129
|
+
const result = await fn();
|
|
1130
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1131
|
+
return {
|
|
1132
|
+
result,
|
|
1133
|
+
records
|
|
1134
|
+
};
|
|
1135
|
+
} finally {
|
|
1136
|
+
await reset();
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
function cancelFailureLogs(records) {
|
|
1140
|
+
return records.filter((record) => record.rawMessage === "Failed to cancel the response body from {url}: {error}").map((record) => [
|
|
1141
|
+
record.level,
|
|
1142
|
+
record.properties.url,
|
|
1143
|
+
String(record.properties.error)
|
|
1144
|
+
]);
|
|
1145
|
+
}
|
|
1146
|
+
function linkHeaderAlternate(next) {
|
|
1147
|
+
return {
|
|
1148
|
+
headers: {
|
|
1149
|
+
"Content-Type": "text/plain",
|
|
1150
|
+
Link: `<${next}>; rel="alternate"; type="application/activity+json"`
|
|
1151
|
+
},
|
|
1152
|
+
body: "not JSON"
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
test("getDocumentLoader() continues if an intermediate body fails to cancel", async (t) => {
|
|
1156
|
+
for (const kind of ["redirect", "Link header alternate"]) await t.step(kind, async () => {
|
|
1157
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1158
|
+
...kind === "redirect" ? {
|
|
1159
|
+
status: 302,
|
|
1160
|
+
headers: { Location: "https://b.example/object" }
|
|
1161
|
+
} : linkHeaderAlternate("https://b.example/object"),
|
|
1162
|
+
failCancel: true
|
|
1163
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1164
|
+
const loader = createDocumentLoader({}, { openHop: recorder.openHop });
|
|
1165
|
+
const { result, records } = await captureDocumentLoaderLogs(() => loader("https://a.example/start"));
|
|
1166
|
+
deepStrictEqual(result, {
|
|
1167
|
+
contextUrl: null,
|
|
1168
|
+
documentUrl: "https://b.example/object",
|
|
1169
|
+
document: lifecycleDocument
|
|
1170
|
+
});
|
|
1171
|
+
deepStrictEqual(recorder.events, [
|
|
1172
|
+
"open https://a.example/start",
|
|
1173
|
+
"fetch https://a.example/start #1",
|
|
1174
|
+
"cancel #1",
|
|
1175
|
+
"close https://a.example/start",
|
|
1176
|
+
"open https://b.example/object",
|
|
1177
|
+
"fetch https://b.example/object #2",
|
|
1178
|
+
"consumed #2",
|
|
1179
|
+
"close https://b.example/object"
|
|
1180
|
+
]);
|
|
1181
|
+
recorder.assertInvariants();
|
|
1182
|
+
deepStrictEqual(cancelFailureLogs(records), [[
|
|
1183
|
+
"debug",
|
|
1184
|
+
"https://a.example/start",
|
|
1185
|
+
"Error: Failed to cancel #1"
|
|
1186
|
+
]]);
|
|
1187
|
+
});
|
|
1188
|
+
});
|
|
1189
|
+
test("getDocumentLoader() does not wait for intermediate bodies to be cancelled", async (t) => {
|
|
1190
|
+
for (const kind of ["redirect", "Link header alternate"]) await t.step(kind, async () => {
|
|
1191
|
+
const recorder = createHopRecorder((url) => url === "https://a.example/start" ? {
|
|
1192
|
+
...kind === "redirect" ? {
|
|
1193
|
+
status: 302,
|
|
1194
|
+
headers: { Location: "https://b.example/object" }
|
|
1195
|
+
} : linkHeaderAlternate("https://b.example/object"),
|
|
1196
|
+
hangCancel: true
|
|
1197
|
+
} : { body: JSON.stringify(lifecycleDocument) });
|
|
1198
|
+
deepStrictEqual((await settlesWithin(createDocumentLoader({}, { openHop: recorder.openHop })("https://a.example/start"))).documentUrl, "https://b.example/object");
|
|
1199
|
+
deepStrictEqual(recorder.events, [
|
|
1200
|
+
"open https://a.example/start",
|
|
1201
|
+
"fetch https://a.example/start #1",
|
|
1202
|
+
"cancel #1",
|
|
1203
|
+
"close https://a.example/start",
|
|
1204
|
+
"open https://b.example/object",
|
|
1205
|
+
"fetch https://b.example/object #2",
|
|
1206
|
+
"consumed #2",
|
|
1207
|
+
"close https://b.example/object"
|
|
1208
|
+
]);
|
|
1209
|
+
recorder.assertInvariants();
|
|
1210
|
+
});
|
|
1211
|
+
await t.step("public session with a never-settling cancel", async () => {
|
|
1212
|
+
let cancelled = 0;
|
|
1213
|
+
const pinner = {
|
|
1214
|
+
supports: () => true,
|
|
1215
|
+
fetch: () => Promise.resolve(new Response(new ReadableStream({ cancel() {
|
|
1216
|
+
cancelled++;
|
|
1217
|
+
return new Promise(() => {});
|
|
1218
|
+
} }), { status: 404 })),
|
|
1219
|
+
release() {}
|
|
1220
|
+
};
|
|
1221
|
+
const publicFetch = createPublicFetch({
|
|
1222
|
+
pinner: () => Promise.resolve(pinner),
|
|
1223
|
+
lookup: () => Promise.reject(/* @__PURE__ */ new Error("Unexpected default lookup"))
|
|
1224
|
+
});
|
|
1225
|
+
await settlesWithin(rejects(createDocumentLoader({}, { openHop: (url) => publicFetch.openPublicFetch(url, { lookup: lookupTestAddresses }) })("https://a.example/missing"), (error) => {
|
|
1226
|
+
ok(error instanceof FetchError);
|
|
1227
|
+
error.response?.body?.cancel().catch(() => {});
|
|
1228
|
+
return true;
|
|
1229
|
+
}));
|
|
1230
|
+
deepStrictEqual(cancelled, 1);
|
|
1231
|
+
});
|
|
1232
|
+
});
|
|
1233
|
+
test("getDocumentLoader() completes with tee'd fetch-mock responses", async (t) => {
|
|
1234
|
+
const url = "https://example.com/teed";
|
|
1235
|
+
function stream(text) {
|
|
1236
|
+
return new ReadableStream({ start(controller) {
|
|
1237
|
+
controller.enqueue(new TextEncoder().encode(text));
|
|
1238
|
+
controller.close();
|
|
1239
|
+
} });
|
|
1240
|
+
}
|
|
1241
|
+
const loaders = {
|
|
1242
|
+
unpinned: createDocumentLoader({}, { openHop: openUnpinnedHop }),
|
|
1243
|
+
"private addresses allowed": getDocumentLoader({ allowPrivateAddress: true })
|
|
1244
|
+
};
|
|
1245
|
+
for (const [name, loader] of Object.entries(loaders)) for (const body of ["string", "stream"]) await t.step(`${name}: ${body} bodies`, async () => {
|
|
1246
|
+
const make = (text) => body === "string" ? text : stream(text);
|
|
1247
|
+
esm_default.mockGlobal();
|
|
1248
|
+
try {
|
|
1249
|
+
esm_default.get(`${url}/object`, () => new Response(make(JSON.stringify(lifecycleDocument)), { headers: { "Content-Type": "application/activity+json" } }));
|
|
1250
|
+
esm_default.get(`${url}/redirect`, () => new Response(make("redirect"), {
|
|
1251
|
+
status: 302,
|
|
1252
|
+
headers: { Location: `${url}/object` }
|
|
1253
|
+
}));
|
|
1254
|
+
esm_default.get(`${url}/alternate`, () => new Response(make("not JSON"), { headers: {
|
|
1255
|
+
"Content-Type": "text/plain",
|
|
1256
|
+
Link: `<${url}/object>; rel="alternate"; type="application/activity+json"`
|
|
1257
|
+
} }));
|
|
1258
|
+
esm_default.get(`${url}/missing`, () => new Response(make("not found"), { status: 404 }));
|
|
1259
|
+
for (const path of ["redirect", "alternate"]) deepStrictEqual((await settlesWithin(loader(`${url}/${path}`))).document, lifecycleDocument);
|
|
1260
|
+
await settlesWithin(rejects(loader(`${url}/missing`), FetchError));
|
|
1261
|
+
deepStrictEqual(esm_default.callHistory.calls().map((call) => call.url), [
|
|
1262
|
+
`${url}/redirect`,
|
|
1263
|
+
`${url}/object`,
|
|
1264
|
+
`${url}/alternate`,
|
|
1265
|
+
`${url}/object`,
|
|
1266
|
+
`${url}/missing`
|
|
1267
|
+
]);
|
|
1268
|
+
} finally {
|
|
1269
|
+
esm_default.hardReset();
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1272
|
+
});
|
|
1273
|
+
test("getDocumentLoader() resolves each hop once", async () => {
|
|
1274
|
+
const lookups = [];
|
|
1275
|
+
const recorder = createHopRecorder((url) => {
|
|
1276
|
+
const responseUrl = `https://${PUBLIC_ADDRESS.address}${new URL(url).pathname}`;
|
|
1277
|
+
if (url === "https://a.example/start") return {
|
|
1278
|
+
status: 302,
|
|
1279
|
+
headers: { Location: "https://b.example/next" },
|
|
1280
|
+
responseUrl
|
|
1281
|
+
};
|
|
1282
|
+
else if (url === "https://b.example/next") return {
|
|
1283
|
+
status: 301,
|
|
1284
|
+
headers: { Location: "/object" },
|
|
1285
|
+
responseUrl
|
|
1286
|
+
};
|
|
1287
|
+
return {
|
|
1288
|
+
body: JSON.stringify(lifecycleDocument),
|
|
1289
|
+
responseUrl
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
1292
|
+
const pinner = {
|
|
1293
|
+
supports: () => true,
|
|
1294
|
+
fetch: (_grant, request) => Promise.resolve(recorder.respond(request.url)),
|
|
1295
|
+
release() {}
|
|
1296
|
+
};
|
|
1297
|
+
const publicFetch = createPublicFetch({
|
|
1298
|
+
pinner: () => Promise.resolve(pinner),
|
|
1299
|
+
lookup: () => Promise.reject(/* @__PURE__ */ new Error("Unexpected default lookup"))
|
|
1300
|
+
});
|
|
1301
|
+
deepStrictEqual(await createDocumentLoader({}, { openHop: async (url) => recorder.record(url, await publicFetch.openPublicFetch(url, { lookup(hostname) {
|
|
1302
|
+
lookups.push(hostname);
|
|
1303
|
+
return Promise.resolve([PUBLIC_ADDRESS]);
|
|
1304
|
+
} })) })("https://a.example/start"), {
|
|
1305
|
+
contextUrl: null,
|
|
1306
|
+
documentUrl: "https://b.example/object",
|
|
1307
|
+
document: lifecycleDocument
|
|
1308
|
+
});
|
|
1309
|
+
deepStrictEqual(lookups, [
|
|
1310
|
+
"a.example",
|
|
1311
|
+
"b.example",
|
|
1312
|
+
"b.example"
|
|
1313
|
+
]);
|
|
1314
|
+
deepStrictEqual(recorder.events, [
|
|
1315
|
+
"open https://a.example/start",
|
|
1316
|
+
"fetch https://a.example/start #1",
|
|
1317
|
+
"cancel #1",
|
|
1318
|
+
"close https://a.example/start",
|
|
1319
|
+
"open https://b.example/next",
|
|
1320
|
+
"fetch https://b.example/next #2",
|
|
1321
|
+
"cancel #2",
|
|
1322
|
+
"close https://b.example/next",
|
|
1323
|
+
"open https://b.example/object",
|
|
1324
|
+
"fetch https://b.example/object #3",
|
|
1325
|
+
"consumed #3",
|
|
1326
|
+
"close https://b.example/object"
|
|
1327
|
+
]);
|
|
1328
|
+
recorder.assertInvariants();
|
|
1329
|
+
});
|
|
1330
|
+
test("getRemoteDocument() cancels the body before loading a Link header alternate", async () => {
|
|
1331
|
+
const recorder = createHopRecorder(() => ({
|
|
1332
|
+
headers: {
|
|
1333
|
+
"Content-Type": "text/html",
|
|
1334
|
+
Link: "<https://b.example/object>; rel=\"alternate\"; type=\"application/activity+json\""
|
|
1335
|
+
},
|
|
1336
|
+
body: "<html></html>"
|
|
1337
|
+
}));
|
|
1338
|
+
const response = recorder.respond("https://a.example/start");
|
|
1339
|
+
const placeholder = {
|
|
1340
|
+
contextUrl: null,
|
|
1341
|
+
document: {},
|
|
1342
|
+
documentUrl: "https://b.example/object"
|
|
1343
|
+
};
|
|
1344
|
+
const alternates = [];
|
|
1345
|
+
ok(await getRemoteDocument("https://a.example/start", response, (url) => {
|
|
1346
|
+
alternates.push(url);
|
|
1347
|
+
deepStrictEqual(recorder.events.at(-1), "cancel #1");
|
|
1348
|
+
ok(response.bodyUsed);
|
|
1349
|
+
return Promise.resolve(placeholder);
|
|
1350
|
+
}) === placeholder);
|
|
1351
|
+
deepStrictEqual(alternates, ["https://b.example/object"]);
|
|
1352
|
+
deepStrictEqual(recorder.events, ["fetch https://a.example/start #1", "cancel #1"]);
|
|
1353
|
+
});
|
|
2123
1354
|
//#endregion
|
|
2124
1355
|
export {};
|