@scalar/oas-utils 0.3.2 → 0.4.1
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/CHANGELOG.md +22 -0
- package/dist/entities/spec/collection.d.ts +6 -12
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +1 -1
- package/dist/entities/spec/collection.js.map +2 -2
- package/dist/helpers/http-methods.js +9 -9
- package/dist/helpers/http-methods.js.map +1 -1
- package/dist/helpers/pretty-print-json.d.ts.map +1 -1
- package/dist/helpers/pretty-print-json.js.map +2 -2
- package/dist/transforms/import-spec.d.ts +8 -3
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +30 -9
- package/dist/transforms/import-spec.js.map +2 -2
- package/package.json +5 -5
- package/dist/entities/spec/operation.test.js +0 -43
- package/dist/entities/spec/operation.test.js.map +0 -7
- package/dist/entities/spec/parameters.test.js +0 -80
- package/dist/entities/spec/parameters.test.js.map +0 -7
- package/dist/entities/spec/request-example.test.js +0 -633
- package/dist/entities/spec/request-example.test.js.map +0 -7
- package/dist/entities/spec/server.test.js +0 -120
- package/dist/entities/spec/server.test.js.map +0 -7
- package/dist/entities/spec/spec-objects.test.js +0 -205
- package/dist/entities/spec/spec-objects.test.js.map +0 -7
- package/dist/entities/spec/x-scalar-environments.test.js +0 -11
- package/dist/entities/spec/x-scalar-environments.test.js.map +0 -7
- package/dist/entities/spec/x-scalar-secrets.test.js +0 -11
- package/dist/entities/spec/x-scalar-secrets.test.js.map +0 -7
- package/dist/helpers/ensure-protocol.test.js +0 -70
- package/dist/helpers/ensure-protocol.test.js.map +0 -7
- package/dist/helpers/fetch-document.test.js +0 -63
- package/dist/helpers/fetch-document.test.js.map +0 -7
- package/dist/helpers/find-variables.test.js +0 -20
- package/dist/helpers/find-variables.test.js.map +0 -7
- package/dist/helpers/is-defined.test.js +0 -37
- package/dist/helpers/is-defined.test.js.map +0 -7
- package/dist/helpers/is-local-url.test.js +0 -40
- package/dist/helpers/is-local-url.test.js.map +0 -7
- package/dist/helpers/is-valid-url.test.js +0 -17
- package/dist/helpers/is-valid-url.test.js.map +0 -7
- package/dist/helpers/json2xml.test.js +0 -19
- package/dist/helpers/json2xml.test.js.map +0 -7
- package/dist/helpers/make-url-absolute.test.js +0 -61
- package/dist/helpers/make-url-absolute.test.js.map +0 -7
- package/dist/helpers/merge-urls.test.js +0 -339
- package/dist/helpers/merge-urls.test.js.map +0 -7
- package/dist/helpers/normalize-mime-type-object.test.js +0 -53
- package/dist/helpers/normalize-mime-type-object.test.js.map +0 -7
- package/dist/helpers/normalize-mime-type.test.js +0 -33
- package/dist/helpers/normalize-mime-type.test.js.map +0 -7
- package/dist/helpers/omit-undefined-values.test.js +0 -89
- package/dist/helpers/omit-undefined-values.test.js.map +0 -7
- package/dist/helpers/parse.test.js +0 -45
- package/dist/helpers/parse.test.js.map +0 -7
- package/dist/helpers/pretty-print-json.test.js +0 -28
- package/dist/helpers/pretty-print-json.test.js.map +0 -7
- package/dist/helpers/redirect-to-proxy.test.js +0 -54
- package/dist/helpers/redirect-to-proxy.test.js.map +0 -7
- package/dist/helpers/regex-helpers.test.js +0 -154
- package/dist/helpers/regex-helpers.test.js.map +0 -7
- package/dist/helpers/replace-variables.test.js +0 -30
- package/dist/helpers/replace-variables.test.js.map +0 -7
- package/dist/helpers/security/get-schemes.test.js +0 -71
- package/dist/helpers/security/get-schemes.test.js.map +0 -7
- package/dist/helpers/security/has-token.test.js +0 -157
- package/dist/helpers/security/has-token.test.js.map +0 -7
- package/dist/migrations/semver.test.js +0 -21
- package/dist/migrations/semver.test.js.map +0 -7
- package/dist/migrations/v-2.4.0/migration.test.js +0 -90
- package/dist/migrations/v-2.4.0/migration.test.js.map +0 -7
- package/dist/migrations/v-2.5.0/migration.test.js +0 -108
- package/dist/migrations/v-2.5.0/migration.test.js.map +0 -7
- package/dist/spec-getters/get-example-from-schema.test.js +0 -1092
- package/dist/spec-getters/get-example-from-schema.test.js.map +0 -7
- package/dist/spec-getters/get-parameters-from-operation.test.js +0 -178
- package/dist/spec-getters/get-parameters-from-operation.test.js.map +0 -7
- package/dist/spec-getters/get-request-body-from-operation.test.js +0 -289
- package/dist/spec-getters/get-request-body-from-operation.test.js.map +0 -7
- package/dist/transforms/import-spec.test.js +0 -1124
- package/dist/transforms/import-spec.test.js.map +0 -7
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/fetch-document.test.ts"],
|
|
4
|
-
"sourcesContent": ["// @vitest-environment jsdom\nimport { beforeAll, describe, expect, it, vi } from 'vitest'\n\nimport { fetchDocument } from './fetch-document'\n\nconst PROXY_PORT = 5051\n\nbeforeAll(async () => {\n // Check whether the proxy-server is running\n try {\n const result = await fetch(`http://127.0.0.1:${PROXY_PORT}`)\n\n if (result.ok) {\n return\n }\n } catch (_error) {\n throw new Error(`\n\n[sendRequest.test.ts] Looks like you\u2019re not running @scalar/proxy-server on <http://127.0.0.1:${PROXY_PORT}>, but it\u2019s required for this test file.\n\nTry to run it like this:\n\n$ pnpm dev:proxy-server\n`)\n }\n})\n\ndescribe('fetchDocument', () => {\n it('fetches specifications (without a proxy)', async () => {\n const spec = await fetchDocument('https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml')\n\n expect(typeof spec).toEqual('string')\n expect(spec.length).toBeGreaterThan(100)\n })\n\n it('fetches specifications (through proxy.scalar.com)', async () => {\n const spec = await fetchDocument(\n 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',\n 'https://proxy.scalar.com',\n )\n\n expect(typeof spec).toEqual('string')\n expect(spec.length).toBeGreaterThan(100)\n })\n\n it(`fetches specifications (through 127.0.0.1:${PROXY_PORT})`, async () => {\n const spec = await fetchDocument(\n 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',\n `http://127.0.0.1:${PROXY_PORT}`,\n )\n\n expect(typeof spec).toEqual('string')\n expect(spec.length).toBeGreaterThan(100)\n })\n\n it('fetches specifications from localhost without proxy', async () => {\n const originalFetch = globalThis.fetch\n // mock fetch\n // @ts-expect-error TODO not properly typed\n globalThis.fetch = vi.fn(() =>\n Promise.resolve({\n ok: true,\n status: 200,\n text: () => Promise.resolve(''),\n }),\n )\n\n const spec = await fetchDocument(`http://127.0.0.1:${PROXY_PORT}/test`)\n\n expect(typeof spec).toEqual('string')\n\n // restore fetch\n globalThis.fetch = originalFetch\n })\n\n it('throws error for invalid URLs', async () => {\n await expect(fetchDocument('not-a-valid-url')).rejects.toThrow()\n })\n\n it('throws error when fetch fails', async () => {\n await expect(fetchDocument('https://does-not-exist.scalar.com/spec.yaml')).rejects.toThrow('fetch failed')\n })\n})\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,WAAW,UAAU,QAAQ,IAAI,UAAU;AAEpD,SAAS,qBAAqB;AAE9B,MAAM,aAAa;AAEnB,UAAU,YAAY;AAEpB,MAAI;AACF,UAAM,SAAS,MAAM,MAAM,oBAAoB,UAAU,EAAE;AAE3D,QAAI,OAAO,IAAI;AACb;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AACf,UAAM,IAAI,MAAM;AAAA;AAAA,qGAE4E,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,CAKzG;AAAA,EACC;AACF,CAAC;AAED,SAAS,iBAAiB,MAAM;AAC9B,KAAG,4CAA4C,YAAY;AACzD,UAAM,OAAO,MAAM,cAAc,8DAA8D;AAE/F,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AACpC,WAAO,KAAK,MAAM,EAAE,gBAAgB,GAAG;AAAA,EACzC,CAAC;AAED,KAAG,qDAAqD,YAAY;AAClE,UAAM,OAAO,MAAM;AAAA,MACjB;AAAA,MACA;AAAA,IACF;AAEA,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AACpC,WAAO,KAAK,MAAM,EAAE,gBAAgB,GAAG;AAAA,EACzC,CAAC;AAED,KAAG,6CAA6C,UAAU,KAAK,YAAY;AACzE,UAAM,OAAO,MAAM;AAAA,MACjB;AAAA,MACA,oBAAoB,UAAU;AAAA,IAChC;AAEA,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AACpC,WAAO,KAAK,MAAM,EAAE,gBAAgB,GAAG;AAAA,EACzC,CAAC;AAED,KAAG,uDAAuD,YAAY;AACpE,UAAM,gBAAgB,WAAW;AAGjC,eAAW,QAAQ,GAAG;AAAA,MAAG,MACvB,QAAQ,QAAQ;AAAA,QACd,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,MAAM,MAAM,QAAQ,QAAQ,EAAE;AAAA,MAChC,CAAC;AAAA,IACH;AAEA,UAAM,OAAO,MAAM,cAAc,oBAAoB,UAAU,OAAO;AAEtE,WAAO,OAAO,IAAI,EAAE,QAAQ,QAAQ;AAGpC,eAAW,QAAQ;AAAA,EACrB,CAAC;AAED,KAAG,iCAAiC,YAAY;AAC9C,UAAM,OAAO,cAAc,iBAAiB,CAAC,EAAE,QAAQ,QAAQ;AAAA,EACjE,CAAC;AAED,KAAG,iCAAiC,YAAY;AAC9C,UAAM,OAAO,cAAc,6CAA6C,CAAC,EAAE,QAAQ,QAAQ,cAAc;AAAA,EAC3G,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { findVariables } from "./find-variables.js";
|
|
3
|
-
describe("findVariables", () => {
|
|
4
|
-
it("finds variables", async () => {
|
|
5
|
-
expect(findVariables("http://{baseUrl}/foobar")).toEqual(["baseUrl"]);
|
|
6
|
-
});
|
|
7
|
-
it("finds variables with double curly braces", async () => {
|
|
8
|
-
expect(findVariables("http://{{baseUrl}}/foobar")).toEqual(["baseUrl"]);
|
|
9
|
-
});
|
|
10
|
-
it("ignores whitespace", async () => {
|
|
11
|
-
expect(findVariables("http://{ baseUrl }/foobar")).toEqual(["baseUrl"]);
|
|
12
|
-
});
|
|
13
|
-
it("works with special characters", async () => {
|
|
14
|
-
expect(findVariables("http://{Example123_}/foobar")).toEqual(["Example123_"]);
|
|
15
|
-
});
|
|
16
|
-
it("returns an empty array if there\u2019s no variable", async () => {
|
|
17
|
-
expect(findVariables("http://example.com/foobar")).toEqual([]);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
//# sourceMappingURL=find-variables.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/find-variables.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { findVariables } from './find-variables'\n\ndescribe('findVariables', () => {\n it('finds variables', async () => {\n expect(findVariables('http://{baseUrl}/foobar')).toEqual(['baseUrl'])\n })\n\n it('finds variables with double curly braces', async () => {\n expect(findVariables('http://{{baseUrl}}/foobar')).toEqual(['baseUrl'])\n })\n\n it('ignores whitespace', async () => {\n expect(findVariables('http://{ baseUrl }/foobar')).toEqual(['baseUrl'])\n })\n\n it('works with special characters', async () => {\n expect(findVariables('http://{Example123_}/foobar')).toEqual(['Example123_'])\n })\n\n it('returns an empty array if there\u2019s no variable', async () => {\n expect(findVariables('http://example.com/foobar')).toEqual([])\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB,MAAM;AAC9B,KAAG,mBAAmB,YAAY;AAChC,WAAO,cAAc,yBAAyB,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;AAAA,EACtE,CAAC;AAED,KAAG,4CAA4C,YAAY;AACzD,WAAO,cAAc,2BAA2B,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;AAAA,EACxE,CAAC;AAED,KAAG,sBAAsB,YAAY;AACnC,WAAO,cAAc,2BAA2B,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;AAAA,EACxE,CAAC;AAED,KAAG,iCAAiC,YAAY;AAC9C,WAAO,cAAc,6BAA6B,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC;AAAA,EAC9E,CAAC;AAED,KAAG,sDAAiD,YAAY;AAC9D,WAAO,cAAc,2BAA2B,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EAC/D,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
2
|
-
import { isDefined } from "./is-defined.js";
|
|
3
|
-
describe("isDefined type", () => {
|
|
4
|
-
it("should narrow type when filtering arrays", () => {
|
|
5
|
-
const array = [1, null, 2, void 0, 3];
|
|
6
|
-
const filtered = array.filter(isDefined);
|
|
7
|
-
expectTypeOf(filtered).toMatchTypeOf();
|
|
8
|
-
});
|
|
9
|
-
it("should work with complex types", () => {
|
|
10
|
-
const array = [{ foo: "a", bar: 1 }, null, { foo: "b", bar: 2 }, void 0];
|
|
11
|
-
const filtered = array.filter(isDefined);
|
|
12
|
-
expectTypeOf(filtered).toMatchTypeOf();
|
|
13
|
-
});
|
|
14
|
-
it("should work with union types", () => {
|
|
15
|
-
const array = ["a", 1, null, true, void 0];
|
|
16
|
-
const filtered = array.filter(isDefined);
|
|
17
|
-
expectTypeOf(filtered).toMatchTypeOf();
|
|
18
|
-
});
|
|
19
|
-
it("should preserve literal types", () => {
|
|
20
|
-
const array = ["foo", null, "bar", void 0];
|
|
21
|
-
const filtered = array.filter(isDefined);
|
|
22
|
-
expectTypeOf(filtered).toEqualTypeOf();
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe("isDefined runtime", () => {
|
|
26
|
-
it("should filter out null and undefined values", () => {
|
|
27
|
-
const array = [1, null, 2, void 0, 3];
|
|
28
|
-
const filtered = array.filter(isDefined);
|
|
29
|
-
expect(filtered).toEqual([1, 2, 3]);
|
|
30
|
-
});
|
|
31
|
-
it("should keep falsy values that are not null or undefined", () => {
|
|
32
|
-
const array = [0, "", false, null, void 0];
|
|
33
|
-
const filtered = array.filter(isDefined);
|
|
34
|
-
expect(filtered).toEqual([0, "", false]);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=is-defined.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/is-defined.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, expectTypeOf, it } from 'vitest'\n\nimport { isDefined } from './is-defined'\n\ndescribe('isDefined type', () => {\n it('should narrow type when filtering arrays', () => {\n const array = [1, null, 2, undefined, 3] as const\n const filtered = array.filter(isDefined)\n\n // Should be number[], not (number | null | undefined)[]\n expectTypeOf(filtered).toMatchTypeOf<number[]>()\n })\n\n it('should work with complex types', () => {\n const array = [{ foo: 'a', bar: 1 }, null, { foo: 'b', bar: 2 }, undefined] as const\n\n const filtered = array.filter(isDefined)\n\n // Should be Complex[], not (Complex | null | undefined)[]\n expectTypeOf(filtered).toMatchTypeOf<{ foo: string; bar: number }[]>()\n })\n\n it('should work with union types', () => {\n const array = ['a', 1, null, true, undefined] as const\n const filtered = array.filter(isDefined)\n\n // Should be (string | number | boolean)[], not (string | number | boolean | null | undefined)[]\n expectTypeOf(filtered).toMatchTypeOf<(string | number | boolean)[]>()\n })\n\n it('should preserve literal types', () => {\n const array = ['foo' as const, null, 'bar' as const, undefined] as const\n const filtered = array.filter(isDefined)\n\n // Should be ('foo' | 'bar')[], not string[]\n expectTypeOf(filtered).toEqualTypeOf<('foo' | 'bar')[]>()\n })\n})\n\ndescribe('isDefined runtime', () => {\n it('should filter out null and undefined values', () => {\n const array = [1, null, 2, undefined, 3]\n const filtered = array.filter(isDefined)\n expect(filtered).toEqual([1, 2, 3])\n })\n\n it('should keep falsy values that are not null or undefined', () => {\n const array = [0, '', false, null, undefined]\n const filtered = array.filter(isDefined)\n expect(filtered).toEqual([0, '', false])\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,cAAc,UAAU;AAEnD,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB,MAAM;AAC/B,KAAG,4CAA4C,MAAM;AACnD,UAAM,QAAQ,CAAC,GAAG,MAAM,GAAG,QAAW,CAAC;AACvC,UAAM,WAAW,MAAM,OAAO,SAAS;AAGvC,iBAAa,QAAQ,EAAE,cAAwB;AAAA,EACjD,CAAC;AAED,KAAG,kCAAkC,MAAM;AACzC,UAAM,QAAQ,CAAC,EAAE,KAAK,KAAK,KAAK,EAAE,GAAG,MAAM,EAAE,KAAK,KAAK,KAAK,EAAE,GAAG,MAAS;AAE1E,UAAM,WAAW,MAAM,OAAO,SAAS;AAGvC,iBAAa,QAAQ,EAAE,cAA8C;AAAA,EACvE,CAAC;AAED,KAAG,gCAAgC,MAAM;AACvC,UAAM,QAAQ,CAAC,KAAK,GAAG,MAAM,MAAM,MAAS;AAC5C,UAAM,WAAW,MAAM,OAAO,SAAS;AAGvC,iBAAa,QAAQ,EAAE,cAA6C;AAAA,EACtE,CAAC;AAED,KAAG,iCAAiC,MAAM;AACxC,UAAM,QAAQ,CAAC,OAAgB,MAAM,OAAgB,MAAS;AAC9D,UAAM,WAAW,MAAM,OAAO,SAAS;AAGvC,iBAAa,QAAQ,EAAE,cAAiC;AAAA,EAC1D,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,MAAM;AAClC,KAAG,+CAA+C,MAAM;AACtD,UAAM,QAAQ,CAAC,GAAG,MAAM,GAAG,QAAW,CAAC;AACvC,UAAM,WAAW,MAAM,OAAO,SAAS;AACvC,WAAO,QAAQ,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC;AAAA,EACpC,CAAC;AAED,KAAG,2DAA2D,MAAM;AAClE,UAAM,QAAQ,CAAC,GAAG,IAAI,OAAO,MAAM,MAAS;AAC5C,UAAM,WAAW,MAAM,OAAO,SAAS;AACvC,WAAO,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAI,KAAK,CAAC;AAAA,EACzC,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { isLocalUrl } from "./is-local-url.js";
|
|
3
|
-
describe("isLocalUrl ", () => {
|
|
4
|
-
it("returns true for localhost", () => {
|
|
5
|
-
expect(isLocalUrl("http://localhost")).toBe(true);
|
|
6
|
-
expect(isLocalUrl("https://localhost")).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
it("returns true for 127.0.0.1", () => {
|
|
9
|
-
expect(isLocalUrl("http://127.0.0.1")).toBe(true);
|
|
10
|
-
expect(isLocalUrl("https://127.0.0.1")).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
it("returns true for [::1]", () => {
|
|
13
|
-
expect(isLocalUrl("http://[::1]")).toBe(true);
|
|
14
|
-
expect(isLocalUrl("https://[::1]")).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
it("returns true for 0.0.0.0", () => {
|
|
17
|
-
expect(isLocalUrl("http://0.0.0.0")).toBe(true);
|
|
18
|
-
expect(isLocalUrl("https://0.0.0.0")).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
it("returns false for non-local URLs", () => {
|
|
21
|
-
expect(isLocalUrl("http://example.com")).toBe(false);
|
|
22
|
-
expect(isLocalUrl("https://google.com")).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
it("returns false for IP addresses that are not in the local list", () => {
|
|
25
|
-
expect(isLocalUrl("http://192.168.1.1")).toBe(false);
|
|
26
|
-
expect(isLocalUrl("https://10.0.0.1")).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
it("handles URLs with ports", () => {
|
|
29
|
-
expect(isLocalUrl("http://localhost:3000")).toBe(true);
|
|
30
|
-
expect(isLocalUrl("https://127.0.0.1:8080")).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
it("handles URLs with paths and query parameters", () => {
|
|
33
|
-
expect(isLocalUrl("http://localhost/api/data")).toBe(true);
|
|
34
|
-
expect(isLocalUrl("https://127.0.0.1/search?q=test")).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it("returns true for relative file paths", () => {
|
|
37
|
-
expect(isLocalUrl("openapi.json")).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
//# sourceMappingURL=is-local-url.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/is-local-url.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { isLocalUrl } from './is-local-url'\n\ndescribe('isLocalUrl ', () => {\n it('returns true for localhost', () => {\n expect(isLocalUrl('http://localhost')).toBe(true)\n expect(isLocalUrl('https://localhost')).toBe(true)\n })\n\n it('returns true for 127.0.0.1', () => {\n expect(isLocalUrl('http://127.0.0.1')).toBe(true)\n expect(isLocalUrl('https://127.0.0.1')).toBe(true)\n })\n\n it('returns true for [::1]', () => {\n expect(isLocalUrl('http://[::1]')).toBe(true)\n expect(isLocalUrl('https://[::1]')).toBe(true)\n })\n\n it('returns true for 0.0.0.0', () => {\n expect(isLocalUrl('http://0.0.0.0')).toBe(true)\n expect(isLocalUrl('https://0.0.0.0')).toBe(true)\n })\n\n it('returns false for non-local URLs', () => {\n expect(isLocalUrl('http://example.com')).toBe(false)\n expect(isLocalUrl('https://google.com')).toBe(false)\n })\n\n it('returns false for IP addresses that are not in the local list', () => {\n expect(isLocalUrl('http://192.168.1.1')).toBe(false)\n expect(isLocalUrl('https://10.0.0.1')).toBe(false)\n })\n\n it('handles URLs with ports', () => {\n expect(isLocalUrl('http://localhost:3000')).toBe(true)\n expect(isLocalUrl('https://127.0.0.1:8080')).toBe(true)\n })\n\n it('handles URLs with paths and query parameters', () => {\n expect(isLocalUrl('http://localhost/api/data')).toBe(true)\n expect(isLocalUrl('https://127.0.0.1/search?q=test')).toBe(true)\n })\n\n it('returns true for relative file paths', () => {\n expect(isLocalUrl('openapi.json')).toBe(true)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,kBAAkB;AAE3B,SAAS,eAAe,MAAM;AAC5B,KAAG,8BAA8B,MAAM;AACrC,WAAO,WAAW,kBAAkB,CAAC,EAAE,KAAK,IAAI;AAChD,WAAO,WAAW,mBAAmB,CAAC,EAAE,KAAK,IAAI;AAAA,EACnD,CAAC;AAED,KAAG,8BAA8B,MAAM;AACrC,WAAO,WAAW,kBAAkB,CAAC,EAAE,KAAK,IAAI;AAChD,WAAO,WAAW,mBAAmB,CAAC,EAAE,KAAK,IAAI;AAAA,EACnD,CAAC;AAED,KAAG,0BAA0B,MAAM;AACjC,WAAO,WAAW,cAAc,CAAC,EAAE,KAAK,IAAI;AAC5C,WAAO,WAAW,eAAe,CAAC,EAAE,KAAK,IAAI;AAAA,EAC/C,CAAC;AAED,KAAG,4BAA4B,MAAM;AACnC,WAAO,WAAW,gBAAgB,CAAC,EAAE,KAAK,IAAI;AAC9C,WAAO,WAAW,iBAAiB,CAAC,EAAE,KAAK,IAAI;AAAA,EACjD,CAAC;AAED,KAAG,oCAAoC,MAAM;AAC3C,WAAO,WAAW,oBAAoB,CAAC,EAAE,KAAK,KAAK;AACnD,WAAO,WAAW,oBAAoB,CAAC,EAAE,KAAK,KAAK;AAAA,EACrD,CAAC;AAED,KAAG,iEAAiE,MAAM;AACxE,WAAO,WAAW,oBAAoB,CAAC,EAAE,KAAK,KAAK;AACnD,WAAO,WAAW,kBAAkB,CAAC,EAAE,KAAK,KAAK;AAAA,EACnD,CAAC;AAED,KAAG,2BAA2B,MAAM;AAClC,WAAO,WAAW,uBAAuB,CAAC,EAAE,KAAK,IAAI;AACrD,WAAO,WAAW,wBAAwB,CAAC,EAAE,KAAK,IAAI;AAAA,EACxD,CAAC;AAED,KAAG,gDAAgD,MAAM;AACvD,WAAO,WAAW,2BAA2B,CAAC,EAAE,KAAK,IAAI;AACzD,WAAO,WAAW,iCAAiC,CAAC,EAAE,KAAK,IAAI;AAAA,EACjE,CAAC;AAED,KAAG,wCAAwC,MAAM;AAC/C,WAAO,WAAW,cAAc,CAAC,EAAE,KAAK,IAAI;AAAA,EAC9C,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { isValidUrl } from "./is-valid-url.js";
|
|
3
|
-
describe("isValidUrl ", () => {
|
|
4
|
-
it("says false for empty string", () => {
|
|
5
|
-
expect(isValidUrl("")).toBe(false);
|
|
6
|
-
});
|
|
7
|
-
it("says false for a path", () => {
|
|
8
|
-
expect(isValidUrl("/some-path")).toBe(false);
|
|
9
|
-
});
|
|
10
|
-
it("says false for a origin without a protocol", () => {
|
|
11
|
-
expect(isValidUrl("google.com")).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
it("says true for a protocol, origin, host, path and query parameters", () => {
|
|
14
|
-
expect(isValidUrl("https://google.com/maps?some=thing")).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=is-valid-url.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/is-valid-url.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { isValidUrl } from './is-valid-url'\n\ndescribe('isValidUrl ', () => {\n it('says false for empty string', () => {\n expect(isValidUrl('')).toBe(false)\n })\n\n it('says false for a path', () => {\n expect(isValidUrl('/some-path')).toBe(false)\n })\n\n it('says false for a origin without a protocol', () => {\n expect(isValidUrl('google.com')).toBe(false)\n })\n\n it('says true for a protocol, origin, host, path and query parameters', () => {\n expect(isValidUrl('https://google.com/maps?some=thing')).toBe(true)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,kBAAkB;AAE3B,SAAS,eAAe,MAAM;AAC5B,KAAG,+BAA+B,MAAM;AACtC,WAAO,WAAW,EAAE,CAAC,EAAE,KAAK,KAAK;AAAA,EACnC,CAAC;AAED,KAAG,yBAAyB,MAAM;AAChC,WAAO,WAAW,YAAY,CAAC,EAAE,KAAK,KAAK;AAAA,EAC7C,CAAC;AAED,KAAG,8CAA8C,MAAM;AACrD,WAAO,WAAW,YAAY,CAAC,EAAE,KAAK,KAAK;AAAA,EAC7C,CAAC;AAED,KAAG,qEAAqE,MAAM;AAC5E,WAAO,WAAW,oCAAoC,CAAC,EAAE,KAAK,IAAI;AAAA,EACpE,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { json2xml } from "./json2xml.js";
|
|
3
|
-
describe("getUrlFromServerState", () => {
|
|
4
|
-
it("transforms JSON to xml", () => {
|
|
5
|
-
const xml = json2xml({
|
|
6
|
-
foo: "bar"
|
|
7
|
-
});
|
|
8
|
-
expect(xml).toMatchObject("<foo>bar</foo>");
|
|
9
|
-
});
|
|
10
|
-
it("wraps array items", () => {
|
|
11
|
-
const xml = json2xml({
|
|
12
|
-
urls: {
|
|
13
|
-
url: ["https://example.com", "https://example.com"]
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
expect(xml).toMatchObject("<urls><url>https://example.com</url><url>https://example.com</url></urls>");
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
//# sourceMappingURL=json2xml.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/json2xml.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { json2xml } from './json2xml'\n\ndescribe('getUrlFromServerState', () => {\n it('transforms JSON to xml', () => {\n const xml = json2xml({\n foo: 'bar',\n })\n\n expect(xml).toMatchObject('<foo>bar</foo>')\n })\n\n it('wraps array items', () => {\n const xml = json2xml({\n urls: {\n url: ['https://example.com', 'https://example.com'],\n },\n })\n\n expect(xml).toMatchObject('<urls><url>https://example.com</url><url>https://example.com</url></urls>')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,gBAAgB;AAEzB,SAAS,yBAAyB,MAAM;AACtC,KAAG,0BAA0B,MAAM;AACjC,UAAM,MAAM,SAAS;AAAA,MACnB,KAAK;AAAA,IACP,CAAC;AAED,WAAO,GAAG,EAAE,cAAc,gBAAgB;AAAA,EAC5C,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,UAAM,MAAM,SAAS;AAAA,MACnB,MAAM;AAAA,QACJ,KAAK,CAAC,uBAAuB,qBAAqB;AAAA,MACpD;AAAA,IACF,CAAC;AAED,WAAO,GAAG,EAAE,cAAc,2EAA2E;AAAA,EACvG,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { makeUrlAbsolute } from "./make-url-absolute.js";
|
|
3
|
-
describe("makeUrlAbsolute", () => {
|
|
4
|
-
it("returns undefined for undefined input", () => {
|
|
5
|
-
expect(makeUrlAbsolute(void 0)).toBeUndefined();
|
|
6
|
-
});
|
|
7
|
-
it("returns the same URL for absolute URLs", () => {
|
|
8
|
-
expect(makeUrlAbsolute("http://example.com")).toBe("http://example.com");
|
|
9
|
-
expect(makeUrlAbsolute("https://example.com")).toBe("https://example.com");
|
|
10
|
-
});
|
|
11
|
-
it("converts relative URLs to absolute URLs", () => {
|
|
12
|
-
const originalHref = window.location.href;
|
|
13
|
-
Object.defineProperty(window, "location", {
|
|
14
|
-
value: { href: "http://example.com/path/" },
|
|
15
|
-
writable: true
|
|
16
|
-
});
|
|
17
|
-
expect(makeUrlAbsolute("relative")).toBe("http://example.com/path/relative");
|
|
18
|
-
expect(makeUrlAbsolute("/absolute-path")).toBe("http://example.com/absolute-path");
|
|
19
|
-
Object.defineProperty(window, "location", {
|
|
20
|
-
value: { href: originalHref },
|
|
21
|
-
writable: true
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
it("handles base URLs without trailing slash", () => {
|
|
25
|
-
const originalHref = window.location.href;
|
|
26
|
-
Object.defineProperty(window, "location", {
|
|
27
|
-
value: { href: "http://example.com/path" },
|
|
28
|
-
writable: true
|
|
29
|
-
});
|
|
30
|
-
expect(makeUrlAbsolute("relative")).toBe("http://example.com/relative");
|
|
31
|
-
Object.defineProperty(window, "location", {
|
|
32
|
-
value: { href: originalHref },
|
|
33
|
-
writable: true
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it("ignores query parameters and hash in base URL", () => {
|
|
37
|
-
const originalHref = window.location.href;
|
|
38
|
-
Object.defineProperty(window, "location", {
|
|
39
|
-
value: { href: "http://example.com/path?query=1#hash" },
|
|
40
|
-
writable: true
|
|
41
|
-
});
|
|
42
|
-
expect(makeUrlAbsolute("relative")).toBe("http://example.com/relative");
|
|
43
|
-
Object.defineProperty(window, "location", {
|
|
44
|
-
value: { href: originalHref },
|
|
45
|
-
writable: true
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("handles parent directory paths", () => {
|
|
49
|
-
const originalHref = window.location.href;
|
|
50
|
-
Object.defineProperty(window, "location", {
|
|
51
|
-
value: { href: "http://example.com/path/to/current/" },
|
|
52
|
-
writable: true
|
|
53
|
-
});
|
|
54
|
-
expect(makeUrlAbsolute("../openapi.json")).toBe("http://example.com/path/to/openapi.json");
|
|
55
|
-
Object.defineProperty(window, "location", {
|
|
56
|
-
value: { href: originalHref },
|
|
57
|
-
writable: true
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
//# sourceMappingURL=make-url-absolute.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/make-url-absolute.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { makeUrlAbsolute } from './make-url-absolute'\n\n/**\n * @vitest-environment jsdom\n */\ndescribe('makeUrlAbsolute', () => {\n it('returns undefined for undefined input', () => {\n expect(makeUrlAbsolute(undefined)).toBeUndefined()\n })\n\n it('returns the same URL for absolute URLs', () => {\n expect(makeUrlAbsolute('http://example.com')).toBe('http://example.com')\n expect(makeUrlAbsolute('https://example.com')).toBe('https://example.com')\n })\n\n it('converts relative URLs to absolute URLs', () => {\n // Mock window.location.href\n const originalHref = window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: 'http://example.com/path/' },\n writable: true,\n })\n\n expect(makeUrlAbsolute('relative')).toBe('http://example.com/path/relative')\n expect(makeUrlAbsolute('/absolute-path')).toBe('http://example.com/absolute-path')\n\n // Restore original window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: originalHref },\n writable: true,\n })\n })\n\n it('handles base URLs without trailing slash', () => {\n // Mock window.location.href\n const originalHref = window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: 'http://example.com/path' },\n writable: true,\n })\n\n expect(makeUrlAbsolute('relative')).toBe('http://example.com/relative')\n\n // Restore original window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: originalHref },\n writable: true,\n })\n })\n\n it('ignores query parameters and hash in base URL', () => {\n // Mock window.location.href\n const originalHref = window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: 'http://example.com/path?query=1#hash' },\n writable: true,\n })\n\n expect(makeUrlAbsolute('relative')).toBe('http://example.com/relative')\n\n // Restore original window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: originalHref },\n writable: true,\n })\n })\n\n it('handles parent directory paths', () => {\n // Mock window.location.href\n const originalHref = window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: 'http://example.com/path/to/current/' },\n writable: true,\n })\n\n expect(makeUrlAbsolute('../openapi.json')).toBe('http://example.com/path/to/openapi.json')\n\n // Restore original window.location.href\n Object.defineProperty(window, 'location', {\n value: { href: originalHref },\n writable: true,\n })\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,uBAAuB;AAKhC,SAAS,mBAAmB,MAAM;AAChC,KAAG,yCAAyC,MAAM;AAChD,WAAO,gBAAgB,MAAS,CAAC,EAAE,cAAc;AAAA,EACnD,CAAC;AAED,KAAG,0CAA0C,MAAM;AACjD,WAAO,gBAAgB,oBAAoB,CAAC,EAAE,KAAK,oBAAoB;AACvE,WAAO,gBAAgB,qBAAqB,CAAC,EAAE,KAAK,qBAAqB;AAAA,EAC3E,CAAC;AAED,KAAG,2CAA2C,MAAM;AAElD,UAAM,eAAe,OAAO,SAAS;AACrC,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,2BAA2B;AAAA,MAC1C,UAAU;AAAA,IACZ,CAAC;AAED,WAAO,gBAAgB,UAAU,CAAC,EAAE,KAAK,kCAAkC;AAC3E,WAAO,gBAAgB,gBAAgB,CAAC,EAAE,KAAK,kCAAkC;AAGjF,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,aAAa;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,CAAC;AAED,KAAG,4CAA4C,MAAM;AAEnD,UAAM,eAAe,OAAO,SAAS;AACrC,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,0BAA0B;AAAA,MACzC,UAAU;AAAA,IACZ,CAAC;AAED,WAAO,gBAAgB,UAAU,CAAC,EAAE,KAAK,6BAA6B;AAGtE,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,aAAa;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,CAAC;AAED,KAAG,iDAAiD,MAAM;AAExD,UAAM,eAAe,OAAO,SAAS;AACrC,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,uCAAuC;AAAA,MACtD,UAAU;AAAA,IACZ,CAAC;AAED,WAAO,gBAAgB,UAAU,CAAC,EAAE,KAAK,6BAA6B;AAGtE,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,aAAa;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,CAAC;AAED,KAAG,kCAAkC,MAAM;AAEzC,UAAM,eAAe,OAAO,SAAS;AACrC,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,sCAAsC;AAAA,MACrD,UAAU;AAAA,IACZ,CAAC;AAED,WAAO,gBAAgB,iBAAiB,CAAC,EAAE,KAAK,yCAAyC;AAGzF,WAAO,eAAe,QAAQ,YAAY;AAAA,MACxC,OAAO,EAAE,MAAM,aAAa;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { combineUrlAndPath, mergeSearchParams, mergeUrls } from "./merge-urls.js";
|
|
3
|
-
describe("mergeSearchParams", () => {
|
|
4
|
-
it("merges basic params from different sources", () => {
|
|
5
|
-
const base = new URLSearchParams("a=1&b=2");
|
|
6
|
-
const path = new URLSearchParams("c=3");
|
|
7
|
-
const url = new URLSearchParams("d=4");
|
|
8
|
-
const result = mergeSearchParams(base, path, url);
|
|
9
|
-
expect(result.toString()).toBe("a=1&b=2&c=3&d=4");
|
|
10
|
-
});
|
|
11
|
-
it("later sources overwrite earlier ones completely", () => {
|
|
12
|
-
const base = new URLSearchParams("a=1&b=2");
|
|
13
|
-
const path = new URLSearchParams("b=3");
|
|
14
|
-
const url = new URLSearchParams("b=4");
|
|
15
|
-
const result = mergeSearchParams(base, path, url);
|
|
16
|
-
expect(result.toString()).toBe("a=1&b=4");
|
|
17
|
-
});
|
|
18
|
-
it("preserves multiple values from the same source", () => {
|
|
19
|
-
const base = new URLSearchParams("a=1&a=2");
|
|
20
|
-
const path = new URLSearchParams("b=3&b=4");
|
|
21
|
-
const url = new URLSearchParams("c=5&c=6");
|
|
22
|
-
const result = mergeSearchParams(base, path, url);
|
|
23
|
-
expect(result.toString()).toBe("a=1&a=2&b=3&b=4&c=5&c=6");
|
|
24
|
-
});
|
|
25
|
-
it("overwrites multiple values from earlier sources", () => {
|
|
26
|
-
const base = new URLSearchParams("a=1&a=2");
|
|
27
|
-
const path = new URLSearchParams("a=3&a=4");
|
|
28
|
-
const url = new URLSearchParams();
|
|
29
|
-
const result = mergeSearchParams(base, path, url);
|
|
30
|
-
expect(result.toString()).toBe("a=3&a=4");
|
|
31
|
-
});
|
|
32
|
-
it("handles empty params", () => {
|
|
33
|
-
const base = new URLSearchParams();
|
|
34
|
-
const path = new URLSearchParams("a=1");
|
|
35
|
-
const url = new URLSearchParams();
|
|
36
|
-
const result = mergeSearchParams(base, path, url);
|
|
37
|
-
expect(result.toString()).toBe("a=1");
|
|
38
|
-
});
|
|
39
|
-
it("handles special characters correctly", () => {
|
|
40
|
-
const base = new URLSearchParams("q=hello world");
|
|
41
|
-
const path = new URLSearchParams("filter=type:123");
|
|
42
|
-
const url = new URLSearchParams("special=@#$%");
|
|
43
|
-
const result = mergeSearchParams(base, path, url);
|
|
44
|
-
expect(decodeURIComponent(result.toString())).toBe("q=hello+world&filter=type:123&special=@#$%");
|
|
45
|
-
});
|
|
46
|
-
it("handles complex overwriting scenarios", () => {
|
|
47
|
-
const base = new URLSearchParams("a=1&a=2&b=1&c=1");
|
|
48
|
-
const path = new URLSearchParams("b=2&b=3&c=2");
|
|
49
|
-
const url = new URLSearchParams("c=3&c=4");
|
|
50
|
-
const result = mergeSearchParams(base, path, url);
|
|
51
|
-
expect(result.toString()).toBe("a=1&a=2&b=2&b=3&c=3&c=4");
|
|
52
|
-
});
|
|
53
|
-
it("maintains order of parameters", () => {
|
|
54
|
-
const base = new URLSearchParams("first=1&second=2");
|
|
55
|
-
const path = new URLSearchParams("third=3");
|
|
56
|
-
const url = new URLSearchParams("fourth=4");
|
|
57
|
-
const result = mergeSearchParams(base, path, url);
|
|
58
|
-
expect(result.toString()).toBe("first=1&second=2&third=3&fourth=4");
|
|
59
|
-
});
|
|
60
|
-
it("handles boolean and numeric values", () => {
|
|
61
|
-
const base = new URLSearchParams("bool=true&num=123");
|
|
62
|
-
const path = new URLSearchParams("bool=false");
|
|
63
|
-
const url = new URLSearchParams("num=456");
|
|
64
|
-
const result = mergeSearchParams(base, path, url);
|
|
65
|
-
expect(result.toString()).toBe("bool=false&num=456");
|
|
66
|
-
});
|
|
67
|
-
it("handles null and undefined values", () => {
|
|
68
|
-
const base = new URLSearchParams("a=null&b=undefined");
|
|
69
|
-
const path = new URLSearchParams("a=value");
|
|
70
|
-
const url = new URLSearchParams();
|
|
71
|
-
const result = mergeSearchParams(base, path, url);
|
|
72
|
-
expect(result.toString()).toBe("a=value&b=undefined");
|
|
73
|
-
});
|
|
74
|
-
it("handles empty string values", () => {
|
|
75
|
-
const base = new URLSearchParams("a=&b=value");
|
|
76
|
-
const path = new URLSearchParams("b=");
|
|
77
|
-
const url = new URLSearchParams();
|
|
78
|
-
const result = mergeSearchParams(base, path, url);
|
|
79
|
-
expect(result.toString()).toBe("a=&b=");
|
|
80
|
-
});
|
|
81
|
-
describe("edge cases", () => {
|
|
82
|
-
it("handles all empty params", () => {
|
|
83
|
-
const result = mergeSearchParams(new URLSearchParams(), new URLSearchParams(), new URLSearchParams());
|
|
84
|
-
expect(result.toString()).toBe("");
|
|
85
|
-
});
|
|
86
|
-
it("handles repeated overwrites", () => {
|
|
87
|
-
const base = new URLSearchParams("a=1&a=2");
|
|
88
|
-
const path = new URLSearchParams("a=3");
|
|
89
|
-
const url = new URLSearchParams("a=4&a=5");
|
|
90
|
-
const result = mergeSearchParams(base, path, url);
|
|
91
|
-
expect(result.toString()).toBe("a=4&a=5");
|
|
92
|
-
});
|
|
93
|
-
it("preserves plus signs in values", () => {
|
|
94
|
-
const base = new URLSearchParams("q=c++");
|
|
95
|
-
const result = mergeSearchParams(base, new URLSearchParams(), new URLSearchParams());
|
|
96
|
-
expect(result.toString()).toBe("q=c++");
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("mergeUrls", () => {
|
|
101
|
-
it("combines simple URL and path", () => {
|
|
102
|
-
const result = mergeUrls("https://api.example.com", "/users");
|
|
103
|
-
expect(result).toBe("https://api.example.com/users");
|
|
104
|
-
});
|
|
105
|
-
it("handles query parameters from base URL", () => {
|
|
106
|
-
const result = mergeUrls("https://api.example.com?version=1", "/users");
|
|
107
|
-
expect(result).toBe("https://api.example.com/users?version=1");
|
|
108
|
-
});
|
|
109
|
-
it("handles query parameters from path", () => {
|
|
110
|
-
const result = mergeUrls("https://api.example.com", "/users?role=admin");
|
|
111
|
-
expect(result).toBe("https://api.example.com/users?role=admin");
|
|
112
|
-
});
|
|
113
|
-
it("handles query parameters from urlParams", () => {
|
|
114
|
-
const params = new URLSearchParams("token=123");
|
|
115
|
-
const result = mergeUrls("https://api.example.com", "/users", params);
|
|
116
|
-
expect(result).toBe("https://api.example.com/users?token=123");
|
|
117
|
-
});
|
|
118
|
-
it("merges query parameters from all sources", () => {
|
|
119
|
-
const params = new URLSearchParams("token=123");
|
|
120
|
-
const result = mergeUrls("https://api.example.com?version=1", "/users?role=admin", params);
|
|
121
|
-
expect(result).toBe("https://api.example.com/users?version=1&role=admin&token=123");
|
|
122
|
-
});
|
|
123
|
-
it("handles multiple values for same parameter", () => {
|
|
124
|
-
const params = new URLSearchParams([
|
|
125
|
-
["filter", "active"],
|
|
126
|
-
["filter", "verified"]
|
|
127
|
-
]);
|
|
128
|
-
const result = mergeUrls("https://api.example.com", "/users", params);
|
|
129
|
-
expect(result).toBe("https://api.example.com/users?filter=active&filter=verified");
|
|
130
|
-
});
|
|
131
|
-
it("later sources overwrite earlier ones", () => {
|
|
132
|
-
const params = new URLSearchParams("version=3");
|
|
133
|
-
const result = mergeUrls("https://api.example.com?version=1", "/users?version=2", params);
|
|
134
|
-
expect(result).toBe("https://api.example.com/users?version=3");
|
|
135
|
-
});
|
|
136
|
-
it("handles URLs with template variables", () => {
|
|
137
|
-
const result = mergeUrls("{protocol}://api.example.com", "/users");
|
|
138
|
-
expect(result).toBe("http://localhost:3000/{protocol}://api.example.com/users");
|
|
139
|
-
});
|
|
140
|
-
it("handles URLs with template variables and disableOriginPrefix", () => {
|
|
141
|
-
const result = mergeUrls("{protocol}://api.example.com", "/users", void 0, true);
|
|
142
|
-
expect(result).toBe("{protocol}://api.example.com/users");
|
|
143
|
-
});
|
|
144
|
-
it("handles relative URLs", () => {
|
|
145
|
-
const result = mergeUrls("/api", "/users");
|
|
146
|
-
expect(result).toBe("http://localhost:3000/api/users");
|
|
147
|
-
});
|
|
148
|
-
it("handles relative URLs with disableOriginPrefix", () => {
|
|
149
|
-
const result = mergeUrls("/api", "/users", void 0, true);
|
|
150
|
-
expect(result).toBe("/api/users");
|
|
151
|
-
});
|
|
152
|
-
describe("path handling", () => {
|
|
153
|
-
it("handles trailing slashes in base URL", () => {
|
|
154
|
-
const result = mergeUrls("https://api.example.com/", "/users");
|
|
155
|
-
expect(result).toBe("https://api.example.com/users");
|
|
156
|
-
});
|
|
157
|
-
it("handles leading slashes in path", () => {
|
|
158
|
-
const result = mergeUrls("https://api.example.com", "users");
|
|
159
|
-
expect(result).toBe("https://api.example.com/users");
|
|
160
|
-
});
|
|
161
|
-
it("handles both trailing and leading slashes", () => {
|
|
162
|
-
const result = mergeUrls("https://api.example.com/", "/users/");
|
|
163
|
-
expect(result).toBe("https://api.example.com/users/");
|
|
164
|
-
});
|
|
165
|
-
it("handles empty path", () => {
|
|
166
|
-
const result = mergeUrls("https://api.example.com", "");
|
|
167
|
-
expect(result).toBe("https://api.example.com");
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
describe("query parameter handling", () => {
|
|
171
|
-
it("preserves parameter order", () => {
|
|
172
|
-
const params = new URLSearchParams([
|
|
173
|
-
["c", "3"],
|
|
174
|
-
["d", "4"]
|
|
175
|
-
]);
|
|
176
|
-
const result = mergeUrls("https://api.example.com?a=1", "/users?b=2", params);
|
|
177
|
-
expect(result).toBe("https://api.example.com/users?a=1&b=2&c=3&d=4");
|
|
178
|
-
});
|
|
179
|
-
it("handles special characters in parameters", () => {
|
|
180
|
-
const params = new URLSearchParams([["q", "hello world&special=true"]]);
|
|
181
|
-
const result = mergeUrls("https://api.example.com", "/search", params);
|
|
182
|
-
expect(result).toBe("https://api.example.com/search?q=hello+world%26special%3Dtrue");
|
|
183
|
-
});
|
|
184
|
-
it("handles empty parameters", () => {
|
|
185
|
-
const params = new URLSearchParams("empty=");
|
|
186
|
-
const result = mergeUrls("https://api.example.com", "/users", params);
|
|
187
|
-
expect(result).toBe("https://api.example.com/users?empty=");
|
|
188
|
-
});
|
|
189
|
-
it("handles null or undefined parameters", () => {
|
|
190
|
-
const params = new URLSearchParams([
|
|
191
|
-
["null", "null"],
|
|
192
|
-
["undefined", "undefined"]
|
|
193
|
-
]);
|
|
194
|
-
const result = mergeUrls("https://api.example.com", "/users", params);
|
|
195
|
-
expect(result).toBe("https://api.example.com/users?null=null&undefined=undefined");
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe("edge cases", () => {
|
|
199
|
-
it("handles invalid URLs gracefully", () => {
|
|
200
|
-
const result = mergeUrls("not-a-url", "/path");
|
|
201
|
-
expect(result).toBe("http://localhost:3000/not-a-url/path");
|
|
202
|
-
});
|
|
203
|
-
it("handles invalid URLs with disableOriginPrefix", () => {
|
|
204
|
-
const result = mergeUrls("not-a-url", "/path", void 0, true);
|
|
205
|
-
expect(result).toBe("not-a-url/path");
|
|
206
|
-
});
|
|
207
|
-
it("handles URLs with authentication", () => {
|
|
208
|
-
const result = mergeUrls("https://user:pass@api.example.com", "/users");
|
|
209
|
-
expect(result).toBe("https://user:pass@api.example.com/users");
|
|
210
|
-
});
|
|
211
|
-
it("handles URLs with ports", () => {
|
|
212
|
-
const result = mergeUrls("https://api.example.com:8080", "/users");
|
|
213
|
-
expect(result).toBe("https://api.example.com:8080/users");
|
|
214
|
-
});
|
|
215
|
-
it("handles complex URLs", () => {
|
|
216
|
-
const params = new URLSearchParams("token=123");
|
|
217
|
-
const result = mergeUrls("https://user:pass@api.example.com:8080?version=1", "/users?role=admin", params);
|
|
218
|
-
expect(result).toBe("https://user:pass@api.example.com:8080/users?version=1&role=admin&token=123");
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
describe("error handling", () => {
|
|
222
|
-
it("handles empty base url", () => {
|
|
223
|
-
const result = mergeUrls("", "/users");
|
|
224
|
-
expect(result).toBe("/users");
|
|
225
|
-
});
|
|
226
|
-
it("handles undefined urlParams", () => {
|
|
227
|
-
const result = mergeUrls("https://api.example.com", "/users", void 0);
|
|
228
|
-
expect(result).toBe("https://api.example.com/users");
|
|
229
|
-
});
|
|
230
|
-
it("handles malformed URLs gracefully", () => {
|
|
231
|
-
const result = mergeUrls("http://{bad-url}", "/users");
|
|
232
|
-
expect(result).toBe("http://{bad-url}/users");
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
describe("combineUrlAndPath", () => {
|
|
237
|
-
describe("basic path joining", () => {
|
|
238
|
-
it("combines base and path with single slash", () => {
|
|
239
|
-
expect(combineUrlAndPath("http://example.com", "api")).toBe("http://example.com/api");
|
|
240
|
-
});
|
|
241
|
-
it("returns base when paths are identical", () => {
|
|
242
|
-
expect(combineUrlAndPath("http://example.com", "http://example.com")).toBe("http://example.com");
|
|
243
|
-
});
|
|
244
|
-
it("returns base when path is empty", () => {
|
|
245
|
-
expect(combineUrlAndPath("http://example.com", "")).toBe("http://example.com");
|
|
246
|
-
});
|
|
247
|
-
it("returns base when path is undefined", () => {
|
|
248
|
-
expect(combineUrlAndPath("http://example.com", void 0)).toBe("http://example.com");
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
describe("slash handling", () => {
|
|
252
|
-
it("removes trailing slash from base", () => {
|
|
253
|
-
expect(combineUrlAndPath("http://example.com/", "api")).toBe("http://example.com/api");
|
|
254
|
-
});
|
|
255
|
-
it("removes leading slash from path", () => {
|
|
256
|
-
expect(combineUrlAndPath("http://example.com", "/api")).toBe("http://example.com/api");
|
|
257
|
-
});
|
|
258
|
-
it("handles both trailing and leading slashes", () => {
|
|
259
|
-
expect(combineUrlAndPath("http://example.com/", "/api")).toBe("http://example.com/api");
|
|
260
|
-
});
|
|
261
|
-
it("removes multiple trailing slashes", () => {
|
|
262
|
-
expect(combineUrlAndPath("http://example.com///", "api")).toBe("http://example.com/api");
|
|
263
|
-
});
|
|
264
|
-
it("removes multiple leading slashes", () => {
|
|
265
|
-
expect(combineUrlAndPath("http://example.com", "///api")).toBe("http://example.com/api");
|
|
266
|
-
});
|
|
267
|
-
it("handles multiple slashes in both base and path", () => {
|
|
268
|
-
expect(combineUrlAndPath("http://example.com///", "///api")).toBe("http://example.com/api");
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
describe("path segments", () => {
|
|
272
|
-
it("preserves multiple path segments", () => {
|
|
273
|
-
expect(combineUrlAndPath("http://example.com", "api/v1/users")).toBe("http://example.com/api/v1/users");
|
|
274
|
-
});
|
|
275
|
-
it("preserves query parameters in base", () => {
|
|
276
|
-
expect(combineUrlAndPath("http://example.com?version=1", "api")).toBe("http://example.com?version=1/api");
|
|
277
|
-
});
|
|
278
|
-
it("preserves query parameters in path", () => {
|
|
279
|
-
expect(combineUrlAndPath("http://example.com", "api?version=1")).toBe("http://example.com/api?version=1");
|
|
280
|
-
});
|
|
281
|
-
it("preserves hash fragments", () => {
|
|
282
|
-
expect(combineUrlAndPath("http://example.com#section", "api")).toBe("http://example.com#section/api");
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
describe("special cases", () => {
|
|
286
|
-
it("handles relative base paths", () => {
|
|
287
|
-
expect(combineUrlAndPath("./base", "api")).toBe("./base/api");
|
|
288
|
-
});
|
|
289
|
-
it("handles parent directory references", () => {
|
|
290
|
-
expect(combineUrlAndPath("../base", "api")).toBe("../base/api");
|
|
291
|
-
});
|
|
292
|
-
it("handles absolute paths", () => {
|
|
293
|
-
expect(combineUrlAndPath("/base", "api")).toBe("/base/api");
|
|
294
|
-
});
|
|
295
|
-
it("removes extra spaces", () => {
|
|
296
|
-
expect(combineUrlAndPath("http://example.com ", " api ")).toBe("http://example.com/api");
|
|
297
|
-
});
|
|
298
|
-
it("handles URLs with ports", () => {
|
|
299
|
-
expect(combineUrlAndPath("http://example.com:8080", "api")).toBe("http://example.com:8080/api");
|
|
300
|
-
});
|
|
301
|
-
it("handles URLs with authentication", () => {
|
|
302
|
-
expect(combineUrlAndPath("http://user:pass@example.com", "api")).toBe("http://user:pass@example.com/api");
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
describe("template variables", () => {
|
|
306
|
-
it("preserves variables in base", () => {
|
|
307
|
-
expect(combineUrlAndPath("{protocol}://example.com", "api")).toBe("{protocol}://example.com/api");
|
|
308
|
-
});
|
|
309
|
-
it("preserves variables in path", () => {
|
|
310
|
-
expect(combineUrlAndPath("http://example.com", "{version}/api")).toBe("http://example.com/{version}/api");
|
|
311
|
-
});
|
|
312
|
-
it("preserves variables in both", () => {
|
|
313
|
-
expect(combineUrlAndPath("{host}/base", "{version}/api")).toBe("{host}/base/{version}/api");
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
describe("edge cases", () => {
|
|
317
|
-
it("handles empty base", () => {
|
|
318
|
-
expect(combineUrlAndPath("", "api")).toBe("api");
|
|
319
|
-
});
|
|
320
|
-
it("handles no base url", () => {
|
|
321
|
-
expect(combineUrlAndPath("", "https://example.com/api")).toBe("https://example.com/api");
|
|
322
|
-
});
|
|
323
|
-
it("handles both empty strings", () => {
|
|
324
|
-
expect(combineUrlAndPath("", "")).toBe("");
|
|
325
|
-
});
|
|
326
|
-
it("handles root paths", () => {
|
|
327
|
-
expect(combineUrlAndPath("http://example.com", "/")).toBe("http://example.com/");
|
|
328
|
-
});
|
|
329
|
-
it("handles special characters in paths", () => {
|
|
330
|
-
expect(combineUrlAndPath("http://example.com", "path with spaces")).toBe("http://example.com/path with spaces");
|
|
331
|
-
});
|
|
332
|
-
it("preserves URL encoded characters", () => {
|
|
333
|
-
expect(combineUrlAndPath("http://example.com", "path%20with%20spaces")).toBe(
|
|
334
|
-
"http://example.com/path%20with%20spaces"
|
|
335
|
-
);
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
//# sourceMappingURL=merge-urls.test.js.map
|