@tonyclaw/llm-inspector 1.9.6 → 1.9.7
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/.output/nitro.json +1 -1
- package/.output/public/assets/index-Cc1oV0hF.css +1 -0
- package/.output/public/assets/index-DTjsqi6U.js +11 -0
- package/.output/public/assets/index-DrYcBTSK.js +122 -0
- package/.output/server/_chunks/ssr-renderer.mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +1 -1
- package/.output/server/_libs/ajv-formats.mjs +18 -18
- package/.output/server/_libs/ajv.mjs +196 -196
- package/.output/server/_libs/cookie-es.mjs +7 -21
- package/.output/server/_libs/h3-v2.mjs +18 -7
- package/.output/server/_libs/h3.mjs +24 -16
- package/.output/server/_libs/jszip.mjs +28 -28
- package/.output/server/_libs/pako.mjs +13 -13
- package/.output/server/_libs/radix-ui__react-collection.mjs +1 -1
- package/.output/server/_libs/radix-ui__react-id.mjs +1 -1
- package/.output/server/_libs/react-dom.mjs +5 -5
- package/.output/server/_libs/react.mjs +43 -43
- package/.output/server/_libs/readable-stream.mjs +15 -15
- package/.output/server/_libs/safe-buffer.mjs +3 -3
- package/.output/server/_libs/semver.mjs +10 -10
- package/.output/server/_libs/seroval-plugins.mjs +5 -5
- package/.output/server/_libs/seroval.mjs +606 -596
- package/.output/server/_libs/srvx.mjs +110 -46
- package/.output/server/_libs/swr.mjs +1 -1
- package/.output/server/_libs/tanstack__history.mjs +31 -44
- package/.output/server/_libs/tanstack__react-router.mjs +781 -1090
- package/.output/server/_libs/tanstack__router-core.mjs +2223 -2328
- package/.output/server/_libs/tslib.mjs +5 -5
- package/.output/server/_libs/use-sync-external-store.mjs +1 -1
- package/.output/server/_libs/zod.mjs +503 -205
- package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +6 -0
- package/.output/server/_ssr/{index--OdB29Fv.mjs → index-Lxfn0bBE.mjs} +31 -13
- package/.output/server/_ssr/index.mjs +1100 -777
- package/.output/server/_ssr/{router-CY_hgLPo.mjs → router-CXva8nm-.mjs} +26 -7
- package/.output/server/_tanstack-start-manifest_v-Cb2CDJtB.mjs +4 -0
- package/.output/server/index.mjs +26 -25
- package/README.md +50 -11
- package/package.json +1 -1
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +35 -2
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +25 -11
- package/src/proxy/formats/openai/schemas.ts +6 -0
- package/src/proxy/formats/openai/stream.ts +8 -0
- package/src/proxy/handler.ts +6 -2
- package/.output/public/assets/index-Bjuk3Pry.css +0 -1
- package/.output/public/assets/index-DtK6Ymig.js +0 -97
- package/.output/public/assets/main-ClWp6y0D.js +0 -17
- package/.output/server/_libs/tiny-invariant.mjs +0 -12
- package/.output/server/_libs/tiny-warning.mjs +0 -5
- package/.output/server/_tanstack-start-manifest_v-bpFJzmyh.mjs +0 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import nodeHTTP from "node:http";
|
|
2
2
|
import { Readable, PassThrough } from "node:stream";
|
|
3
|
+
import { pipeline } from "node:stream/promises";
|
|
3
4
|
import nodeHTTPS from "node:https";
|
|
4
5
|
import nodeHTTP2 from "node:http2";
|
|
5
6
|
function lazyInherit(target, source, sourceKey) {
|
|
@@ -29,6 +30,7 @@ function lazyInherit(target, source, sourceKey) {
|
|
|
29
30
|
if (modified) Object.defineProperty(target, key, desc);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
33
|
+
const _needsNormRE = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^\x80-\uffff]/i;
|
|
32
34
|
const FastURL = /* @__PURE__ */ (() => {
|
|
33
35
|
const NativeURL = globalThis.URL;
|
|
34
36
|
const FastURL2 = class URL {
|
|
@@ -41,7 +43,9 @@ const FastURL = /* @__PURE__ */ (() => {
|
|
|
41
43
|
#searchParams;
|
|
42
44
|
#pos;
|
|
43
45
|
constructor(url) {
|
|
44
|
-
if (typeof url === "string") this.#href = url;
|
|
46
|
+
if (typeof url === "string") if (url[0] === "/") this.#href = url;
|
|
47
|
+
else this.#url = new NativeURL(url);
|
|
48
|
+
else if (_needsNormRE.test(url.pathname)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
|
|
45
49
|
else {
|
|
46
50
|
this.#protocol = url.protocol;
|
|
47
51
|
this.#host = url.host;
|
|
@@ -74,10 +78,11 @@ const FastURL = /* @__PURE__ */ (() => {
|
|
|
74
78
|
const url = this.href;
|
|
75
79
|
const protoIndex = url.indexOf("://");
|
|
76
80
|
const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
|
|
81
|
+
const qIndex = pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex);
|
|
77
82
|
this.#pos = [
|
|
78
83
|
protoIndex,
|
|
79
84
|
pathnameIndex,
|
|
80
|
-
|
|
85
|
+
qIndex
|
|
81
86
|
];
|
|
82
87
|
}
|
|
83
88
|
return this.#pos;
|
|
@@ -111,7 +116,8 @@ const FastURL = /* @__PURE__ */ (() => {
|
|
|
111
116
|
if (this.#protocol === void 0) {
|
|
112
117
|
const [protocolIndex] = this.#getPos();
|
|
113
118
|
if (protocolIndex === -1) return this._url.protocol;
|
|
114
|
-
|
|
119
|
+
const url = this.href;
|
|
120
|
+
this.#protocol = url.slice(0, protocolIndex + 1);
|
|
115
121
|
}
|
|
116
122
|
return this.#protocol;
|
|
117
123
|
}
|
|
@@ -268,15 +274,14 @@ async function sendNodeResponse(nodeRes, webRes) {
|
|
|
268
274
|
}
|
|
269
275
|
if (webRes._toNodeResponse) {
|
|
270
276
|
const res = webRes._toNodeResponse();
|
|
271
|
-
writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
272
277
|
if (res.body) {
|
|
273
|
-
if (res.body instanceof ReadableStream)
|
|
274
|
-
|
|
275
|
-
res.body
|
|
276
|
-
|
|
277
|
-
|
|
278
|
+
if (res.body instanceof ReadableStream) {
|
|
279
|
+
writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
280
|
+
return streamBody(res.body, nodeRes);
|
|
281
|
+
} else if (typeof res.body?.pipe === "function") return pipeBody(res.body, nodeRes, res.status, res.statusText, res.headers);
|
|
282
|
+
writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
278
283
|
nodeRes.write(res.body);
|
|
279
|
-
}
|
|
284
|
+
} else writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
280
285
|
return endNodeResponse(nodeRes);
|
|
281
286
|
}
|
|
282
287
|
const rawHeaders = [...webRes.headers];
|
|
@@ -284,13 +289,48 @@ async function sendNodeResponse(nodeRes, webRes) {
|
|
|
284
289
|
return webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes);
|
|
285
290
|
}
|
|
286
291
|
function writeHead(nodeRes, status, statusText, rawHeaders) {
|
|
287
|
-
const writeHeaders =
|
|
292
|
+
const writeHeaders = rawHeaders.flat();
|
|
288
293
|
if (!nodeRes.headersSent) if (nodeRes.req?.httpVersion === "2.0") nodeRes.writeHead(status, writeHeaders);
|
|
289
294
|
else nodeRes.writeHead(status, statusText, writeHeaders);
|
|
290
295
|
}
|
|
291
296
|
function endNodeResponse(nodeRes) {
|
|
292
297
|
return new Promise((resolve) => nodeRes.end(resolve));
|
|
293
298
|
}
|
|
299
|
+
function pipeBody(stream, nodeRes, status, statusText, headers) {
|
|
300
|
+
if (nodeRes.destroyed) {
|
|
301
|
+
stream.destroy?.();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (typeof stream.on !== "function" || typeof stream.destroy !== "function") {
|
|
305
|
+
writeHead(nodeRes, status, statusText, headers);
|
|
306
|
+
stream.pipe(nodeRes);
|
|
307
|
+
return new Promise((resolve) => nodeRes.on("close", resolve));
|
|
308
|
+
}
|
|
309
|
+
if (stream.destroyed) {
|
|
310
|
+
writeHead(nodeRes, 500, "Internal Server Error", []);
|
|
311
|
+
return endNodeResponse(nodeRes);
|
|
312
|
+
}
|
|
313
|
+
return new Promise((resolve) => {
|
|
314
|
+
function onEarlyError() {
|
|
315
|
+
stream.off("readable", onReadable);
|
|
316
|
+
stream.destroy();
|
|
317
|
+
writeHead(nodeRes, 500, "Internal Server Error", []);
|
|
318
|
+
endNodeResponse(nodeRes).then(resolve);
|
|
319
|
+
}
|
|
320
|
+
function onReadable() {
|
|
321
|
+
stream.off("error", onEarlyError);
|
|
322
|
+
if (nodeRes.destroyed) {
|
|
323
|
+
stream.destroy();
|
|
324
|
+
return resolve();
|
|
325
|
+
}
|
|
326
|
+
writeHead(nodeRes, status, statusText, headers);
|
|
327
|
+
pipeline(stream, nodeRes).catch(() => {
|
|
328
|
+
}).then(() => resolve());
|
|
329
|
+
}
|
|
330
|
+
stream.once("error", onEarlyError);
|
|
331
|
+
stream.once("readable", onReadable);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
294
334
|
function streamBody(stream, nodeRes) {
|
|
295
335
|
if (nodeRes.destroyed) {
|
|
296
336
|
stream.cancel();
|
|
@@ -319,23 +359,31 @@ function streamBody(stream, nodeRes) {
|
|
|
319
359
|
nodeRes.off("error", streamCancel);
|
|
320
360
|
});
|
|
321
361
|
}
|
|
362
|
+
const HOST_RE = /^(\[(?:[A-Fa-f0-9:.]+)\]|(?:[A-Za-z0-9_-]+\.)*[A-Za-z0-9_-]+|(?:\d{1,3}\.){3}\d{1,3})(:\d{1,5})?$/;
|
|
322
363
|
var NodeRequestURL = class extends FastURL {
|
|
323
364
|
#req;
|
|
324
365
|
constructor({ req }) {
|
|
325
366
|
const path = req.url || "/";
|
|
367
|
+
let host = req.headers.host || req.headers[":authority"];
|
|
368
|
+
if (host && !HOST_RE.test(host)) host = "_invalid_";
|
|
369
|
+
else if (!host) if (req.socket) host = `${req.socket.localFamily === "IPv6" ? "[" + req.socket.localAddress + "]" : req.socket.localAddress}:${req.socket?.localPort || "80"}`;
|
|
370
|
+
else host = "localhost";
|
|
371
|
+
const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" || req.headers[":scheme"] === "https" ? "https:" : "http:";
|
|
326
372
|
if (path[0] === "/") {
|
|
327
373
|
const qIndex = path.indexOf("?");
|
|
328
|
-
const pathname = qIndex === -1 ? path : path?.slice(0, qIndex) || "/";
|
|
329
|
-
const search = qIndex === -1 ? "" : path?.slice(qIndex) || "";
|
|
330
|
-
const host = req.headers.host || req.headers[":authority"] || `${req.socket.localFamily === "IPv6" ? "[" + req.socket.localAddress + "]" : req.socket.localAddress}:${req.socket?.localPort || "80"}`;
|
|
331
|
-
const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" || req.headers[":scheme"] === "https" ? "https:" : "http:";
|
|
332
374
|
super({
|
|
333
375
|
protocol,
|
|
334
376
|
host,
|
|
335
|
-
pathname,
|
|
336
|
-
search
|
|
377
|
+
pathname: qIndex === -1 ? path : path.slice(0, qIndex) || "/",
|
|
378
|
+
search: qIndex === -1 ? "" : path.slice(qIndex) || ""
|
|
337
379
|
});
|
|
338
|
-
} else
|
|
380
|
+
} else if (path === "*") super({
|
|
381
|
+
protocol,
|
|
382
|
+
host,
|
|
383
|
+
pathname: "/*",
|
|
384
|
+
search: ""
|
|
385
|
+
});
|
|
386
|
+
else super(path);
|
|
339
387
|
this.#req = req;
|
|
340
388
|
}
|
|
341
389
|
get pathname() {
|
|
@@ -386,17 +434,8 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
|
|
|
386
434
|
const value = this.#req.headers["set-cookie"];
|
|
387
435
|
return Array.isArray(value) ? value : value ? [value] : [];
|
|
388
436
|
}
|
|
389
|
-
*_entries() {
|
|
390
|
-
const rawHeaders = this.#req.rawHeaders;
|
|
391
|
-
const len = rawHeaders.length;
|
|
392
|
-
for (let i = 0; i < len; i += 2) {
|
|
393
|
-
const key = rawHeaders[i];
|
|
394
|
-
if (key.charCodeAt(0) === 58) continue;
|
|
395
|
-
yield [key.toLowerCase(), rawHeaders[i + 1]];
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
437
|
entries() {
|
|
399
|
-
return this
|
|
438
|
+
return this._headers.entries();
|
|
400
439
|
}
|
|
401
440
|
[Symbol.iterator]() {
|
|
402
441
|
return this.entries();
|
|
@@ -472,7 +511,8 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
472
511
|
if (this.#request) return this.#request.body;
|
|
473
512
|
if (this.#bodyStream === void 0) {
|
|
474
513
|
const method = this.method;
|
|
475
|
-
|
|
514
|
+
const hasBody = !(method === "GET" || method === "HEAD");
|
|
515
|
+
this.#bodyStream = hasBody ? Readable.toWeb(this.#req) : null;
|
|
476
516
|
}
|
|
477
517
|
return this.#bodyStream;
|
|
478
518
|
}
|
|
@@ -643,6 +683,7 @@ var NodeServer = class {
|
|
|
643
683
|
waitUntil;
|
|
644
684
|
#isSecure;
|
|
645
685
|
#listeningPromise;
|
|
686
|
+
#listenError;
|
|
646
687
|
#wait;
|
|
647
688
|
constructor(options) {
|
|
648
689
|
this.options = {
|
|
@@ -652,15 +693,13 @@ var NodeServer = class {
|
|
|
652
693
|
for (const plugin of options.plugins || []) plugin(this);
|
|
653
694
|
errorPlugin(this);
|
|
654
695
|
const fetchHandler = this.fetch = wrapFetch(this);
|
|
655
|
-
const loader = globalThis.__srvxLoader__;
|
|
656
|
-
if (loader) {
|
|
657
|
-
loader(fetchHandler);
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
gracefulShutdownPlugin(this);
|
|
661
|
-
this.#wait = createWaitUntil();
|
|
662
|
-
this.waitUntil = this.#wait.waitUntil;
|
|
663
696
|
const handler = (nodeReq, nodeRes) => {
|
|
697
|
+
const reqUrl = nodeReq.url;
|
|
698
|
+
if (reqUrl && reqUrl[0] !== "/" && reqUrl !== "*" && !URL.canParse(reqUrl)) {
|
|
699
|
+
nodeRes.statusCode = 400;
|
|
700
|
+
nodeRes.end();
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
664
703
|
const request = new NodeRequest({
|
|
665
704
|
req: nodeReq,
|
|
666
705
|
res: nodeRes
|
|
@@ -669,6 +708,18 @@ var NodeServer = class {
|
|
|
669
708
|
const res = fetchHandler(request);
|
|
670
709
|
return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
|
|
671
710
|
};
|
|
711
|
+
this.node = {
|
|
712
|
+
handler,
|
|
713
|
+
server: void 0
|
|
714
|
+
};
|
|
715
|
+
const loader = globalThis.__srvxLoader__;
|
|
716
|
+
if (loader) {
|
|
717
|
+
loader({ server: this });
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
gracefulShutdownPlugin(this);
|
|
721
|
+
this.#wait = createWaitUntil();
|
|
722
|
+
this.waitUntil = this.#wait.waitUntil;
|
|
672
723
|
const tls = resolveTLSOptions(this.options);
|
|
673
724
|
const { port, hostname: host } = resolvePortAndHost(this.options);
|
|
674
725
|
this.serveOptions = {
|
|
@@ -691,20 +742,32 @@ var NodeServer = class {
|
|
|
691
742
|
else throw new Error("node.http2 option requires tls certificate!");
|
|
692
743
|
else if (this.#isSecure) server = nodeHTTPS.createServer(this.serveOptions, handler);
|
|
693
744
|
else server = nodeHTTP.createServer(this.serveOptions, handler);
|
|
694
|
-
this.node =
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
};
|
|
698
|
-
if (!options.manual) this.serve();
|
|
745
|
+
this.node.server = server;
|
|
746
|
+
if (!options.manual) this.serve().catch(() => {
|
|
747
|
+
});
|
|
699
748
|
}
|
|
700
749
|
serve() {
|
|
701
|
-
if (this.#listeningPromise) return
|
|
702
|
-
|
|
703
|
-
|
|
750
|
+
if (this.#listeningPromise) return this.#listeningPromise.then(() => this);
|
|
751
|
+
const server = this.node?.server;
|
|
752
|
+
if (!server) return Promise.reject(/* @__PURE__ */ new Error("Server not initialized"));
|
|
753
|
+
this.#listenError = void 0;
|
|
754
|
+
this.#listeningPromise = new Promise((resolve, reject) => {
|
|
755
|
+
const onError = (error) => {
|
|
756
|
+
server.off("listening", onListening);
|
|
757
|
+
this.#listenError = error;
|
|
758
|
+
this.#listeningPromise = void 0;
|
|
759
|
+
reject(error);
|
|
760
|
+
};
|
|
761
|
+
const onListening = () => {
|
|
762
|
+
server.off("error", onError);
|
|
704
763
|
printListening(this.options, this.url);
|
|
705
764
|
resolve();
|
|
706
|
-
}
|
|
765
|
+
};
|
|
766
|
+
server.once("error", onError);
|
|
767
|
+
server.once("listening", onListening);
|
|
768
|
+
server.listen(this.serveOptions);
|
|
707
769
|
});
|
|
770
|
+
return this.#listeningPromise.then(() => this);
|
|
708
771
|
}
|
|
709
772
|
get url() {
|
|
710
773
|
const addr = this.node?.server?.address();
|
|
@@ -712,6 +775,7 @@ var NodeServer = class {
|
|
|
712
775
|
return typeof addr === "string" ? addr : fmtURL(addr.address, addr.port, this.#isSecure);
|
|
713
776
|
}
|
|
714
777
|
ready() {
|
|
778
|
+
if (this.#listenError) return Promise.reject(this.#listenError);
|
|
715
779
|
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
716
780
|
}
|
|
717
781
|
async close(closeAll) {
|
|
@@ -1,39 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
var stateIndexKey = "__TSR_index";
|
|
2
2
|
function createHistory(opts) {
|
|
3
3
|
let location = opts.getLocation();
|
|
4
4
|
const subscribers = /* @__PURE__ */ new Set();
|
|
5
5
|
const notify = (action) => {
|
|
6
6
|
location = opts.getLocation();
|
|
7
|
-
subscribers.forEach((subscriber) => subscriber({
|
|
7
|
+
subscribers.forEach((subscriber) => subscriber({
|
|
8
|
+
location,
|
|
9
|
+
action
|
|
10
|
+
}));
|
|
8
11
|
};
|
|
9
12
|
const handleIndexChange = (action) => {
|
|
10
13
|
if (opts.notifyOnIndexChange ?? true) notify(action);
|
|
11
14
|
else location = opts.getLocation();
|
|
12
15
|
};
|
|
13
|
-
const tryNavigation = async ({
|
|
14
|
-
|
|
15
|
-
navigateOpts,
|
|
16
|
-
...actionInfo
|
|
17
|
-
}) => {
|
|
18
|
-
const ignoreBlocker = navigateOpts?.ignoreBlocker ?? false;
|
|
19
|
-
if (ignoreBlocker) {
|
|
16
|
+
const tryNavigation = async ({ task, navigateOpts, ...actionInfo }) => {
|
|
17
|
+
if (navigateOpts?.ignoreBlocker ?? false) {
|
|
20
18
|
task();
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
21
|
const blockers = opts.getBlockers?.() ?? [];
|
|
24
22
|
const isPushOrReplace = actionInfo.type === "PUSH" || actionInfo.type === "REPLACE";
|
|
25
|
-
if (typeof document !== "undefined" && blockers.length && isPushOrReplace) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
opts.onBlocked?.();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
23
|
+
if (typeof document !== "undefined" && blockers.length && isPushOrReplace) for (const blocker of blockers) {
|
|
24
|
+
const nextLocation = parseHref(actionInfo.path, actionInfo.state);
|
|
25
|
+
if (await blocker.blockerFn({
|
|
26
|
+
currentLocation: location,
|
|
27
|
+
nextLocation,
|
|
28
|
+
action: actionInfo.type
|
|
29
|
+
})) {
|
|
30
|
+
opts.onBlocked?.();
|
|
31
|
+
return;
|
|
37
32
|
}
|
|
38
33
|
}
|
|
39
34
|
task();
|
|
@@ -84,7 +79,10 @@ function createHistory(opts) {
|
|
|
84
79
|
tryNavigation({
|
|
85
80
|
task: () => {
|
|
86
81
|
opts.go(index);
|
|
87
|
-
handleIndexChange({
|
|
82
|
+
handleIndexChange({
|
|
83
|
+
type: "GO",
|
|
84
|
+
index
|
|
85
|
+
});
|
|
88
86
|
},
|
|
89
87
|
navigateOpts,
|
|
90
88
|
type: "GO"
|
|
@@ -128,26 +126,19 @@ function createHistory(opts) {
|
|
|
128
126
|
};
|
|
129
127
|
}
|
|
130
128
|
function assignKeyAndIndex(index, state) {
|
|
131
|
-
if (!state) {
|
|
132
|
-
state = {};
|
|
133
|
-
}
|
|
129
|
+
if (!state) state = {};
|
|
134
130
|
const key = createRandomKey();
|
|
135
131
|
return {
|
|
136
132
|
...state,
|
|
137
133
|
key,
|
|
138
|
-
// TODO: Remove in v2 - use __TSR_key instead
|
|
139
134
|
__TSR_key: key,
|
|
140
135
|
[stateIndexKey]: index
|
|
141
136
|
};
|
|
142
137
|
}
|
|
143
|
-
function createMemoryHistory(opts = {
|
|
144
|
-
initialEntries: ["/"]
|
|
145
|
-
}) {
|
|
138
|
+
function createMemoryHistory(opts = { initialEntries: ["/"] }) {
|
|
146
139
|
const entries = opts.initialEntries;
|
|
147
140
|
let index = opts.initialIndex ? Math.min(Math.max(opts.initialIndex, 0), entries.length - 1) : entries.length - 1;
|
|
148
|
-
const states = entries.map(
|
|
149
|
-
(_entry, index2) => assignKeyAndIndex(index2, void 0)
|
|
150
|
-
);
|
|
141
|
+
const states = entries.map((_entry, index2) => assignKeyAndIndex(index2, void 0));
|
|
151
142
|
const getLocation = () => parseHref(entries[index], states[index]);
|
|
152
143
|
let blockers = [];
|
|
153
144
|
const _getBlockers = () => blockers;
|
|
@@ -184,9 +175,7 @@ function createMemoryHistory(opts = {
|
|
|
184
175
|
}
|
|
185
176
|
function sanitizePath(path) {
|
|
186
177
|
let sanitized = path.replace(/[\x00-\x1f\x7f]/g, "");
|
|
187
|
-
if (sanitized.startsWith("//"))
|
|
188
|
-
sanitized = "/" + sanitized.replace(/^\/+/, "");
|
|
189
|
-
}
|
|
178
|
+
if (sanitized.startsWith("//")) sanitized = "/" + sanitized.replace(/^\/+/, "");
|
|
190
179
|
return sanitized;
|
|
191
180
|
}
|
|
192
181
|
function parseHref(href, state) {
|
|
@@ -196,16 +185,14 @@ function parseHref(href, state) {
|
|
|
196
185
|
const addedKey = createRandomKey();
|
|
197
186
|
return {
|
|
198
187
|
href: sanitizedHref,
|
|
199
|
-
pathname: sanitizedHref.substring(
|
|
200
|
-
0,
|
|
201
|
-
hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : sanitizedHref.length
|
|
202
|
-
),
|
|
188
|
+
pathname: sanitizedHref.substring(0, hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : sanitizedHref.length),
|
|
203
189
|
hash: hashIndex > -1 ? sanitizedHref.substring(hashIndex) : "",
|
|
204
|
-
search: searchIndex > -1 ? sanitizedHref.slice(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
190
|
+
search: searchIndex > -1 ? sanitizedHref.slice(searchIndex, hashIndex === -1 ? void 0 : hashIndex) : "",
|
|
191
|
+
state: state || {
|
|
192
|
+
[stateIndexKey]: 0,
|
|
193
|
+
key: addedKey,
|
|
194
|
+
__TSR_key: addedKey
|
|
195
|
+
}
|
|
209
196
|
};
|
|
210
197
|
}
|
|
211
198
|
function createRandomKey() {
|