@fedify/vocab-runtime 2.4.0-dev.1508 → 2.4.0-dev.1528

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.
Files changed (38) hide show
  1. package/deno.json +2 -1
  2. package/dist/docloader-DnUMWHaJ.d.cts +202 -0
  3. package/dist/docloader-xRGn1azD.d.ts +202 -0
  4. package/dist/internal/jsonld-cache.cjs +279 -0
  5. package/dist/internal/jsonld-cache.d.cts +48 -0
  6. package/dist/internal/jsonld-cache.d.ts +48 -0
  7. package/dist/internal/jsonld-cache.js +275 -0
  8. package/dist/mod.cjs +13 -183
  9. package/dist/mod.d.cts +18 -200
  10. package/dist/mod.d.ts +18 -200
  11. package/dist/mod.js +3 -177
  12. package/dist/tests/decimal.test.cjs +2 -2
  13. package/dist/tests/decimal.test.mjs +2 -2
  14. package/dist/tests/{docloader-0m6FCm4u.mjs → docloader-9JRkIgYh.mjs} +2 -2
  15. package/dist/tests/{docloader-60uMNsd3.cjs → docloader-yxXccHZv.cjs} +2 -2
  16. package/dist/tests/docloader.test.cjs +3 -3
  17. package/dist/tests/docloader.test.mjs +3 -3
  18. package/dist/tests/jsonld-cache.test.cjs +652 -0
  19. package/dist/tests/jsonld-cache.test.d.cts +1 -0
  20. package/dist/tests/jsonld-cache.test.d.mts +1 -0
  21. package/dist/tests/jsonld-cache.test.mjs +651 -0
  22. package/dist/tests/{request-CO5esooK.mjs → request-4-bNhrbG.mjs} +1 -1
  23. package/dist/tests/{request-CcBmdgDa.cjs → request-_LWX0dnv.cjs} +1 -1
  24. package/dist/tests/request.test.cjs +1 -1
  25. package/dist/tests/request.test.mjs +1 -1
  26. package/dist/tests/{url-C20FhC7p.cjs → url-2XwVbUS_.cjs} +108 -0
  27. package/dist/tests/{url-m9Qzxy-Y.mjs → url-YWJbnRlf.mjs} +85 -1
  28. package/dist/tests/url.test.cjs +104 -1
  29. package/dist/tests/url.test.mjs +105 -2
  30. package/dist/url-BAdyyqAa.cjs +315 -0
  31. package/dist/url-BuxPHxK2.js +261 -0
  32. package/package.json +11 -1
  33. package/src/internal/jsonld-cache.ts +538 -0
  34. package/src/jsonld-cache.test.ts +554 -0
  35. package/src/mod.ts +4 -0
  36. package/src/url.test.ts +252 -1
  37. package/src/url.ts +141 -0
  38. package/tsdown.config.ts +6 -1
@@ -8,6 +8,90 @@ var UrlError = class extends Error {
8
8
  this.name = "UrlError";
9
9
  }
10
10
  };
11
+ const PORTABLE_IRI_PATTERN = /^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
12
+ const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/;
13
+ const DID_SCHEME_PATTERN = /^did:/i;
14
+ const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i;
15
+ /**
16
+ * Parses a JSON-LD `@id` value as an IRI.
17
+ */
18
+ function parseJsonLdId(id, base) {
19
+ if (id == null || id.startsWith("_:")) return void 0;
20
+ try {
21
+ return parseIri(id, base);
22
+ } catch {
23
+ throw new TypeError("Invalid @id: " + id);
24
+ }
25
+ }
26
+ /**
27
+ * Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs.
28
+ */
29
+ function parseIri(iri, base) {
30
+ if (iri instanceof URL) return normalizePortableUrl(iri) ?? new URL(iri.href);
31
+ const portable = parsePortableIri(iri);
32
+ if (portable != null) return portable;
33
+ base = normalizeBaseIri(base);
34
+ if (!URL.canParse(iri, base) && iri.startsWith("at://")) return parseAtUri(iri);
35
+ const parsed = new URL(iri, base);
36
+ return normalizePortableUrl(parsed) ?? parsed;
37
+ }
38
+ /**
39
+ * Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs.
40
+ */
41
+ function formatIri(iri) {
42
+ const parsed = parsePortableIri(iri instanceof URL ? iri.href : iri);
43
+ if (parsed == null) return iri instanceof URL ? iri.href : URL.canParse(iri) ? new URL(iri).href : iri;
44
+ return `ap+ef61://${decodePortableAuthority(parsed.host)}${parsed.pathname}${parsed.search}${parsed.hash}`;
45
+ }
46
+ /**
47
+ * Checks whether two IRIs have the same origin.
48
+ */
49
+ function haveSameIriOrigin(left, right) {
50
+ return getComparableIriOrigin(left) === getComparableIriOrigin(right);
51
+ }
52
+ function getComparableIriOrigin(iri) {
53
+ iri = normalizePortableUrl(iri) ?? iri;
54
+ if (iri.origin !== "null") return iri.origin;
55
+ if (iri.host !== "") {
56
+ const host = iri.protocol === "ap+ef61:" ? encodeURIComponent(decodePortableAuthority(iri.host).replace(DID_SCHEME_PATTERN, "did:")) : iri.host;
57
+ return `${iri.protocol}//${host}`;
58
+ }
59
+ return iri.href;
60
+ }
61
+ function parsePortableIri(iri) {
62
+ const match = iri.match(PORTABLE_IRI_PATTERN);
63
+ if (match == null) return null;
64
+ const authority = decodePortableAuthority(match[2]);
65
+ if (!DID_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
66
+ if (match[3] === "") throw new TypeError("Invalid portable ActivityPub IRI path.");
67
+ return new URL(`ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${match[5] ?? ""}`);
68
+ }
69
+ function normalizePortableUrl(iri) {
70
+ if (iri.protocol !== "ap:" && iri.protocol !== "ap+ef61:") return null;
71
+ return parsePortableIri(`ap+ef61://${iri.host}${iri.pathname}${iri.search}${iri.hash}`);
72
+ }
73
+ function normalizeBaseIri(base) {
74
+ if (base == null) return void 0;
75
+ if (base instanceof URL) return normalizePortableUrl(base) ?? base;
76
+ return parsePortableIri(base) ?? (base.startsWith("at://") && !URL.canParse(".", base) ? parseAtUri(base) : base);
77
+ }
78
+ function decodePortableAuthority(authority) {
79
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
80
+ if (DID_SCHEME_PATTERN.test(authority)) {
81
+ const decoded = authority.replace(/%25/gi, "%");
82
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
83
+ return decoded;
84
+ }
85
+ const decoded = authority.replace(/%(25|3A)/gi, (match) => match.toLowerCase() === "%3a" ? ":" : "%");
86
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
87
+ return decoded;
88
+ }
89
+ function parseAtUri(uri) {
90
+ const index = uri.indexOf("/", 5);
91
+ const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5);
92
+ const path = index >= 0 ? uri.slice(index) : "";
93
+ return new URL("at://" + encodeURIComponent(authority) + path);
94
+ }
11
95
  /**
12
96
  * Validates a URL to prevent SSRF attacks.
13
97
  */
@@ -186,6 +270,18 @@ Object.defineProperty(exports, "expandIPv6Address", {
186
270
  return expandIPv6Address;
187
271
  }
188
272
  });
273
+ Object.defineProperty(exports, "formatIri", {
274
+ enumerable: true,
275
+ get: function() {
276
+ return formatIri;
277
+ }
278
+ });
279
+ Object.defineProperty(exports, "haveSameIriOrigin", {
280
+ enumerable: true,
281
+ get: function() {
282
+ return haveSameIriOrigin;
283
+ }
284
+ });
189
285
  Object.defineProperty(exports, "isValidPublicIPv4Address", {
190
286
  enumerable: true,
191
287
  get: function() {
@@ -198,6 +294,18 @@ Object.defineProperty(exports, "isValidPublicIPv6Address", {
198
294
  return isValidPublicIPv6Address;
199
295
  }
200
296
  });
297
+ Object.defineProperty(exports, "parseIri", {
298
+ enumerable: true,
299
+ get: function() {
300
+ return parseIri;
301
+ }
302
+ });
303
+ Object.defineProperty(exports, "parseJsonLdId", {
304
+ enumerable: true,
305
+ get: function() {
306
+ return parseJsonLdId;
307
+ }
308
+ });
201
309
  Object.defineProperty(exports, "validatePublicUrl", {
202
310
  enumerable: true,
203
311
  get: function() {
@@ -7,6 +7,90 @@ var UrlError = class extends Error {
7
7
  this.name = "UrlError";
8
8
  }
9
9
  };
10
+ const PORTABLE_IRI_PATTERN = /^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
11
+ const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/;
12
+ const DID_SCHEME_PATTERN = /^did:/i;
13
+ const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i;
14
+ /**
15
+ * Parses a JSON-LD `@id` value as an IRI.
16
+ */
17
+ function parseJsonLdId(id, base) {
18
+ if (id == null || id.startsWith("_:")) return void 0;
19
+ try {
20
+ return parseIri(id, base);
21
+ } catch {
22
+ throw new TypeError("Invalid @id: " + id);
23
+ }
24
+ }
25
+ /**
26
+ * Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs.
27
+ */
28
+ function parseIri(iri, base) {
29
+ if (iri instanceof URL) return normalizePortableUrl(iri) ?? new URL(iri.href);
30
+ const portable = parsePortableIri(iri);
31
+ if (portable != null) return portable;
32
+ base = normalizeBaseIri(base);
33
+ if (!URL.canParse(iri, base) && iri.startsWith("at://")) return parseAtUri(iri);
34
+ const parsed = new URL(iri, base);
35
+ return normalizePortableUrl(parsed) ?? parsed;
36
+ }
37
+ /**
38
+ * Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs.
39
+ */
40
+ function formatIri(iri) {
41
+ const parsed = parsePortableIri(iri instanceof URL ? iri.href : iri);
42
+ if (parsed == null) return iri instanceof URL ? iri.href : URL.canParse(iri) ? new URL(iri).href : iri;
43
+ return `ap+ef61://${decodePortableAuthority(parsed.host)}${parsed.pathname}${parsed.search}${parsed.hash}`;
44
+ }
45
+ /**
46
+ * Checks whether two IRIs have the same origin.
47
+ */
48
+ function haveSameIriOrigin(left, right) {
49
+ return getComparableIriOrigin(left) === getComparableIriOrigin(right);
50
+ }
51
+ function getComparableIriOrigin(iri) {
52
+ iri = normalizePortableUrl(iri) ?? iri;
53
+ if (iri.origin !== "null") return iri.origin;
54
+ if (iri.host !== "") {
55
+ const host = iri.protocol === "ap+ef61:" ? encodeURIComponent(decodePortableAuthority(iri.host).replace(DID_SCHEME_PATTERN, "did:")) : iri.host;
56
+ return `${iri.protocol}//${host}`;
57
+ }
58
+ return iri.href;
59
+ }
60
+ function parsePortableIri(iri) {
61
+ const match = iri.match(PORTABLE_IRI_PATTERN);
62
+ if (match == null) return null;
63
+ const authority = decodePortableAuthority(match[2]);
64
+ if (!DID_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
65
+ if (match[3] === "") throw new TypeError("Invalid portable ActivityPub IRI path.");
66
+ return new URL(`ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${match[5] ?? ""}`);
67
+ }
68
+ function normalizePortableUrl(iri) {
69
+ if (iri.protocol !== "ap:" && iri.protocol !== "ap+ef61:") return null;
70
+ return parsePortableIri(`ap+ef61://${iri.host}${iri.pathname}${iri.search}${iri.hash}`);
71
+ }
72
+ function normalizeBaseIri(base) {
73
+ if (base == null) return void 0;
74
+ if (base instanceof URL) return normalizePortableUrl(base) ?? base;
75
+ return parsePortableIri(base) ?? (base.startsWith("at://") && !URL.canParse(".", base) ? parseAtUri(base) : base);
76
+ }
77
+ function decodePortableAuthority(authority) {
78
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
79
+ if (DID_SCHEME_PATTERN.test(authority)) {
80
+ const decoded = authority.replace(/%25/gi, "%");
81
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
82
+ return decoded;
83
+ }
84
+ const decoded = authority.replace(/%(25|3A)/gi, (match) => match.toLowerCase() === "%3a" ? ":" : "%");
85
+ if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
86
+ return decoded;
87
+ }
88
+ function parseAtUri(uri) {
89
+ const index = uri.indexOf("/", 5);
90
+ const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5);
91
+ const path = index >= 0 ? uri.slice(index) : "";
92
+ return new URL("at://" + encodeURIComponent(authority) + path);
93
+ }
10
94
  /**
11
95
  * Validates a URL to prevent SSRF attacks.
12
96
  */
@@ -173,4 +257,4 @@ function matchesIPv6Prefix(address, prefixWords, prefixLength) {
173
257
  return true;
174
258
  }
175
259
  //#endregion
176
- export { validatePublicUrl as a, isValidPublicIPv6Address as i, expandIPv6Address as n, isValidPublicIPv4Address as r, UrlError as t };
260
+ export { isValidPublicIPv4Address as a, parseJsonLdId as c, haveSameIriOrigin as i, validatePublicUrl as l, expandIPv6Address as n, isValidPublicIPv6Address as o, formatIri as r, parseIri as s, UrlError as t };
@@ -1,8 +1,111 @@
1
1
  require("./chunk-C2EiDwsr.cjs");
2
- const require_url = require("./url-C20FhC7p.cjs");
2
+ const require_url = require("./url-2XwVbUS_.cjs");
3
3
  let node_assert = require("node:assert");
4
4
  let node_test = require("node:test");
5
5
  //#region src/url.test.ts
6
+ (0, node_test.test)("parseIri() accepts portable ActivityPub URI schemes", () => {
7
+ for (const iri of [
8
+ "ap://did:key:z6Mkabc/actor",
9
+ "ap://did%3Akey%3Az6Mkabc/actor",
10
+ "ap+ef61://did:key:z6Mkabc/actor",
11
+ "ap+ef61://did%3Akey%3Az6Mkabc/actor",
12
+ "AP+EF61://did:key:z6Mkabc/actor"
13
+ ]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
14
+ });
15
+ (0, node_test.test)("parseIri() accepts DID schemes case-insensitively", () => {
16
+ for (const iri of ["ap://DID:key:z6Mkabc/actor", "ap://DID%3Akey%3Az6Mkabc/actor"]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"));
17
+ });
18
+ (0, node_test.test)("parseIri() accepts DID method names that start with digits", () => {
19
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("ap://did:3:abc/actor"), new URL("ap+ef61://did%3A3%3Aabc/actor"));
20
+ });
21
+ (0, node_test.test)("parseIri() accepts hyphens in DID method-specific IDs", () => {
22
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("ap+ef61://did:web:foo-bar.example/actor"), new URL("ap+ef61://did%3Aweb%3Afoo-bar.example/actor"));
23
+ });
24
+ (0, node_test.test)("parseIri() preserves existing URL parsing behavior", () => {
25
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
26
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("at://did:plc:example/record"), new URL("at://did%3Aplc%3Aexample/record"));
27
+ (0, node_assert.throws)(() => require_url.parseIri("ap://not-a-did/actor"), TypeError);
28
+ });
29
+ (0, node_test.test)("parseJsonLdId() parses JSON-LD ids", () => {
30
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId(void 0), void 0);
31
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId("_:blank"), void 0);
32
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
33
+ (0, node_assert.deepStrictEqual)(require_url.parseJsonLdId("ap://did:key:z6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
34
+ (0, node_assert.throws)(() => require_url.parseJsonLdId("/actor"), {
35
+ name: "TypeError",
36
+ message: "Invalid @id: /actor"
37
+ });
38
+ });
39
+ (0, node_test.test)("parseIri() resolves relative IRIs against portable string bases", () => {
40
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("/actor", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
41
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"));
42
+ (0, node_assert.throws)(() => require_url.parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), TypeError);
43
+ });
44
+ (0, node_test.test)("parseIri() resolves relative IRIs against at:// string bases", () => {
45
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("/record", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/record"));
46
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("reply", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
47
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("reply", "at://did%3Aplc%3Aexample/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
48
+ });
49
+ (0, node_test.test)("parseIri() rejects portable IRIs without paths", () => {
50
+ (0, node_assert.throws)(() => require_url.parseIri("ap://did:key:z6Mkabc"), TypeError);
51
+ (0, node_assert.throws)(() => require_url.parseIri("ap://did:key:z6Mkabc?gateways=https%3A%2F%2Fserver.example"), TypeError);
52
+ (0, node_assert.throws)(() => require_url.parseIri("ap://did:key:z6Mkabc#actor"), TypeError);
53
+ });
54
+ (0, node_test.test)("parseIri() rejects malformed portable DID authorities", () => {
55
+ for (const iri of [
56
+ "ap://did:/actor",
57
+ "ap://did:key/actor",
58
+ "ap://did%3Akey%3Aabc%25zz/actor",
59
+ "ap://did:key:abc%25zz/actor"
60
+ ]) (0, node_assert.throws)(() => require_url.parseIri(iri), TypeError);
61
+ });
62
+ (0, node_test.test)("haveSameIriOrigin() compares portable IRI authorities", () => {
63
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkabc/outbox")));
64
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
65
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(require_url.parseIri("ap://DID:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkabc/outbox")));
66
+ (0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
67
+ (0, node_assert.ok)(!require_url.haveSameIriOrigin(require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/actor")));
68
+ });
69
+ (0, node_test.test)("parseIri() normalizes portable URL instances", () => {
70
+ (0, node_assert.deepStrictEqual)(require_url.parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
71
+ (0, node_assert.throws)(() => require_url.parseIri("ap+ef61://not-a-did/actor"), TypeError);
72
+ });
73
+ (0, node_test.test)("formatIri() emits canonical portable ActivityPub URI syntax", () => {
74
+ const cases = [new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")];
75
+ for (const iri of cases) (0, node_assert.deepStrictEqual)(require_url.formatIri(iri), "ap+ef61://did:key:z6Mkabc/actor");
76
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(new URL("https://example.com/actor")), "https://example.com/actor");
77
+ (0, node_assert.deepStrictEqual)(require_url.formatIri("/actor"), "/actor");
78
+ });
79
+ (0, node_test.test)("formatIri() preserves DID authority pct-encoded delimiters", () => {
80
+ const parsed = require_url.parseIri("ap://did:example:abc%2Fdef/actor");
81
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
82
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:example:abc%2Fdef/actor");
83
+ (0, node_assert.deepStrictEqual)(require_url.parseIri(require_url.formatIri(parsed)), parsed);
84
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), "ap+ef61://did:example:abc%2Fdef/actor");
85
+ });
86
+ (0, node_test.test)("parseIri() normalizes equivalent encoded DID authorities", () => {
87
+ (0, node_assert.deepStrictEqual)(require_url.parseIri("ap://did:example:abc%252Fdef/actor"), require_url.parseIri("ap://did%3Aexample%3Aabc%252Fdef/actor"));
88
+ });
89
+ (0, node_test.test)("formatIri() preserves DID-internal pct-encoded authority characters", () => {
90
+ const parsed = require_url.parseIri("ap://did:web:example.com%3A3000/actor");
91
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/actor"));
92
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/actor");
93
+ });
94
+ (0, node_test.test)("parseIri() accepts portable DID URLs with encoded DID delimiters", () => {
95
+ const parsed = require_url.parseIri("ap://did:web:example.com%3A3000/u/1");
96
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
97
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
98
+ });
99
+ (0, node_test.test)("parseIri() decodes pct-encoded DID delimiters in order", () => {
100
+ const parsed = require_url.parseIri("ap://did%3Aweb%3Aexample.com%253A3000/u/1");
101
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
102
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
103
+ });
104
+ (0, node_test.test)("parseIri() preserves encoded percent signs while decoding delimiters", () => {
105
+ const parsed = require_url.parseIri("ap://did%3Aweb%3Aexample.com%2500/u/1");
106
+ (0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"));
107
+ (0, node_assert.deepStrictEqual)(require_url.formatIri(parsed), "ap+ef61://did:web:example.com%00/u/1");
108
+ });
6
109
  (0, node_test.test)("validatePublicUrl()", async () => {
7
110
  await (0, node_assert.rejects)(() => require_url.validatePublicUrl("ftp://localhost"), require_url.UrlError);
8
111
  await (0, node_assert.rejects)(() => require_url.validatePublicUrl("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="), require_url.UrlError);
@@ -1,7 +1,110 @@
1
- import { a as validatePublicUrl, i as isValidPublicIPv6Address, n as expandIPv6Address, r as isValidPublicIPv4Address, t as UrlError } from "./url-m9Qzxy-Y.mjs";
2
- import { deepStrictEqual, ok, rejects } from "node:assert";
1
+ import { a as isValidPublicIPv4Address, c as parseJsonLdId, i as haveSameIriOrigin, l as validatePublicUrl, n as expandIPv6Address, o as isValidPublicIPv6Address, r as formatIri, s as parseIri, t as UrlError } from "./url-YWJbnRlf.mjs";
2
+ import { deepStrictEqual, ok, rejects, throws } from "node:assert";
3
3
  import { test } from "node:test";
4
4
  //#region src/url.test.ts
5
+ test("parseIri() accepts portable ActivityPub URI schemes", () => {
6
+ for (const iri of [
7
+ "ap://did:key:z6Mkabc/actor",
8
+ "ap://did%3Akey%3Az6Mkabc/actor",
9
+ "ap+ef61://did:key:z6Mkabc/actor",
10
+ "ap+ef61://did%3Akey%3Az6Mkabc/actor",
11
+ "AP+EF61://did:key:z6Mkabc/actor"
12
+ ]) deepStrictEqual(parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
13
+ });
14
+ test("parseIri() accepts DID schemes case-insensitively", () => {
15
+ for (const iri of ["ap://DID:key:z6Mkabc/actor", "ap://DID%3Akey%3Az6Mkabc/actor"]) deepStrictEqual(parseIri(iri), new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"));
16
+ });
17
+ test("parseIri() accepts DID method names that start with digits", () => {
18
+ deepStrictEqual(parseIri("ap://did:3:abc/actor"), new URL("ap+ef61://did%3A3%3Aabc/actor"));
19
+ });
20
+ test("parseIri() accepts hyphens in DID method-specific IDs", () => {
21
+ deepStrictEqual(parseIri("ap+ef61://did:web:foo-bar.example/actor"), new URL("ap+ef61://did%3Aweb%3Afoo-bar.example/actor"));
22
+ });
23
+ test("parseIri() preserves existing URL parsing behavior", () => {
24
+ deepStrictEqual(parseIri("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
25
+ deepStrictEqual(parseIri("at://did:plc:example/record"), new URL("at://did%3Aplc%3Aexample/record"));
26
+ throws(() => parseIri("ap://not-a-did/actor"), TypeError);
27
+ });
28
+ test("parseJsonLdId() parses JSON-LD ids", () => {
29
+ deepStrictEqual(parseJsonLdId(void 0), void 0);
30
+ deepStrictEqual(parseJsonLdId("_:blank"), void 0);
31
+ deepStrictEqual(parseJsonLdId("/actor", new URL("https://example.com/users/alice")), new URL("https://example.com/actor"));
32
+ deepStrictEqual(parseJsonLdId("ap://did:key:z6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
33
+ throws(() => parseJsonLdId("/actor"), {
34
+ name: "TypeError",
35
+ message: "Invalid @id: /actor"
36
+ });
37
+ });
38
+ test("parseIri() resolves relative IRIs against portable string bases", () => {
39
+ deepStrictEqual(parseIri("/actor", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
40
+ deepStrictEqual(parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"));
41
+ throws(() => parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), TypeError);
42
+ });
43
+ test("parseIri() resolves relative IRIs against at:// string bases", () => {
44
+ deepStrictEqual(parseIri("/record", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/record"));
45
+ deepStrictEqual(parseIri("reply", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
46
+ deepStrictEqual(parseIri("reply", "at://did%3Aplc%3Aexample/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
47
+ });
48
+ test("parseIri() rejects portable IRIs without paths", () => {
49
+ throws(() => parseIri("ap://did:key:z6Mkabc"), TypeError);
50
+ throws(() => parseIri("ap://did:key:z6Mkabc?gateways=https%3A%2F%2Fserver.example"), TypeError);
51
+ throws(() => parseIri("ap://did:key:z6Mkabc#actor"), TypeError);
52
+ });
53
+ test("parseIri() rejects malformed portable DID authorities", () => {
54
+ for (const iri of [
55
+ "ap://did:/actor",
56
+ "ap://did:key/actor",
57
+ "ap://did%3Akey%3Aabc%25zz/actor",
58
+ "ap://did:key:abc%25zz/actor"
59
+ ]) throws(() => parseIri(iri), TypeError);
60
+ });
61
+ test("haveSameIriOrigin() compares portable IRI authorities", () => {
62
+ ok(haveSameIriOrigin(parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkabc/outbox")));
63
+ ok(haveSameIriOrigin(new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
64
+ ok(haveSameIriOrigin(parseIri("ap://DID:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkabc/outbox")));
65
+ ok(haveSameIriOrigin(new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
66
+ ok(!haveSameIriOrigin(parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkdef/actor")));
67
+ });
68
+ test("parseIri() normalizes portable URL instances", () => {
69
+ deepStrictEqual(parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
70
+ throws(() => parseIri("ap+ef61://not-a-did/actor"), TypeError);
71
+ });
72
+ test("formatIri() emits canonical portable ActivityPub URI syntax", () => {
73
+ const cases = [new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")];
74
+ for (const iri of cases) deepStrictEqual(formatIri(iri), "ap+ef61://did:key:z6Mkabc/actor");
75
+ deepStrictEqual(formatIri(new URL("https://example.com/actor")), "https://example.com/actor");
76
+ deepStrictEqual(formatIri("/actor"), "/actor");
77
+ });
78
+ test("formatIri() preserves DID authority pct-encoded delimiters", () => {
79
+ const parsed = parseIri("ap://did:example:abc%2Fdef/actor");
80
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
81
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:example:abc%2Fdef/actor");
82
+ deepStrictEqual(parseIri(formatIri(parsed)), parsed);
83
+ deepStrictEqual(formatIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), "ap+ef61://did:example:abc%2Fdef/actor");
84
+ });
85
+ test("parseIri() normalizes equivalent encoded DID authorities", () => {
86
+ deepStrictEqual(parseIri("ap://did:example:abc%252Fdef/actor"), parseIri("ap://did%3Aexample%3Aabc%252Fdef/actor"));
87
+ });
88
+ test("formatIri() preserves DID-internal pct-encoded authority characters", () => {
89
+ const parsed = parseIri("ap://did:web:example.com%3A3000/actor");
90
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/actor"));
91
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/actor");
92
+ });
93
+ test("parseIri() accepts portable DID URLs with encoded DID delimiters", () => {
94
+ const parsed = parseIri("ap://did:web:example.com%3A3000/u/1");
95
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
96
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
97
+ });
98
+ test("parseIri() decodes pct-encoded DID delimiters in order", () => {
99
+ const parsed = parseIri("ap://did%3Aweb%3Aexample.com%253A3000/u/1");
100
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"));
101
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%3A3000/u/1");
102
+ });
103
+ test("parseIri() preserves encoded percent signs while decoding delimiters", () => {
104
+ const parsed = parseIri("ap://did%3Aweb%3Aexample.com%2500/u/1");
105
+ deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"));
106
+ deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%00/u/1");
107
+ });
5
108
  test("validatePublicUrl()", async () => {
6
109
  await rejects(() => validatePublicUrl("ftp://localhost"), UrlError);
7
110
  await rejects(() => validatePublicUrl("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="), UrlError);