@fedify/fedify 1.8.1-pr.328.1154 → 1.8.1-pr.328.1165

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 (102) hide show
  1. package/README.md +4 -1
  2. package/dist/{actor-Br-ZQ9iE.js → actor-6WfgEEM7.js} +1 -4
  3. package/dist/{actor-DqpnNLrD.js → actor-BvUN9QgD.js} +179 -179
  4. package/dist/{assert_rejects-DceVjUlD.js → assert_rejects-AjlKk-Vo.js} +1 -1
  5. package/dist/{assert_throws-DTDC_gwN.js → assert_throws-CqMKbTh_.js} +1 -1
  6. package/dist/{authdocloader-q9_ikBNG.js → authdocloader-BxpW2l0x.js} +3 -3
  7. package/dist/{authdocloader-BMRGaiFE.js → authdocloader-DlQKiAuj.js} +3 -4
  8. package/dist/{builder-mgHwYg4-.js → builder-Bql0U6IX.js} +4 -5
  9. package/dist/{client-DdMIIvjf.js → client-CI4TcEtW.js} +2 -2
  10. package/dist/compat/transformers.test.js +20 -27
  11. package/dist/{docloader-Ddsh58Kf.js → docloader-B6dtEu0e.js} +2 -1
  12. package/dist/{esm-d-9EVGaP.js → esm-80CEOYyg.js} +1 -1
  13. package/dist/federation/builder.test.js +11 -16
  14. package/dist/federation/collection.test.js +9 -7
  15. package/dist/federation/handler.test.js +26 -35
  16. package/dist/federation/inbox.test.js +6 -10
  17. package/dist/federation/keycache.test.js +4 -7
  18. package/dist/federation/kv.test.js +8 -6
  19. package/dist/federation/middleware.test.js +27 -35
  20. package/dist/federation/mod.js +10 -10
  21. package/dist/federation/mq.test.js +10 -8
  22. package/dist/federation/retry.test.js +5 -3
  23. package/dist/federation/router.test.js +8 -7
  24. package/dist/federation/send.test.js +15 -21
  25. package/dist/{http-69zRGYEG.js → http-Cdm4poZb.js} +2 -3
  26. package/dist/{http-IMAUyNbl.js → http-epXQkoos.js} +3 -3
  27. package/dist/{inbox-B4MZPH6B.js → inbox-ClBcgVPg.js} +1 -3
  28. package/dist/{key-ZtnqTDUN.js → key-B2Vg4tVB.js} +4 -4
  29. package/dist/key-CE5RdobB.js +10 -0
  30. package/dist/{key-D48qsYqC.js → key-Cl_Xlkrv.js} +2 -2
  31. package/dist/{key-BpF6CgxV.js → key-D2T-GDYd.js} +2 -3
  32. package/dist/{keycache-UKudzeG7.js → keycache-M-zWLLCU.js} +1 -1
  33. package/dist/{keys-CUTBJXE-.js → keys-qx88le-G.js} +1 -1
  34. package/dist/{ld-DroIpWgz.js → ld-ZkyR7ab4.js} +2 -4
  35. package/dist/{lookup-CusFqkXP.js → lookup-BH2SgpoS.js} +113 -6
  36. package/dist/{lookup-X3OcU2u3.js → lookup-BlMMBOS2.js} +1 -1
  37. package/dist/{middleware-BHKH0CVi.js → middleware-0TQ_tx1T.js} +17 -21
  38. package/dist/{middleware-ClYMTxST.js → middleware-Cye6GERQ.js} +11 -11
  39. package/dist/middleware-DPQqiqLu.js +26 -0
  40. package/dist/middleware-Dh8xaPyd.js +17 -0
  41. package/dist/mod.js +10 -10
  42. package/dist/nodeinfo/client.test.js +11 -11
  43. package/dist/nodeinfo/handler.test.js +25 -34
  44. package/dist/nodeinfo/mod.js +2 -2
  45. package/dist/nodeinfo/semver.test.js +9 -7
  46. package/dist/nodeinfo/types.test.js +10 -8
  47. package/dist/{owner-B4cJX8FD.js → owner-C_vL0hRG.js} +2 -3
  48. package/dist/{proof-BfKmsXPq.js → proof-CiYpiavN.js} +3 -3
  49. package/dist/{proof-CVedLBo3.js → proof-Dz3Yq7kI.js} +2 -4
  50. package/dist/runtime/authdocloader.test.js +14 -20
  51. package/dist/runtime/docloader.test.js +9 -10
  52. package/dist/runtime/key.test.js +10 -15
  53. package/dist/runtime/langstr.test.js +8 -7
  54. package/dist/runtime/mod.js +6 -6
  55. package/dist/runtime/multibase/multibase.test.js +8 -7
  56. package/dist/runtime/url.test.js +5 -4
  57. package/dist/{send-mEdMj0kU.js → send-CDQXxlmm.js} +2 -2
  58. package/dist/sig/http.test.js +13 -19
  59. package/dist/sig/key.test.js +11 -17
  60. package/dist/sig/ld.test.js +10 -16
  61. package/dist/sig/mod.js +6 -6
  62. package/dist/sig/owner.test.js +12 -19
  63. package/dist/sig/proof.test.js +12 -18
  64. package/dist/testing/docloader.test.js +8 -7
  65. package/dist/testing/mod.d.ts +8387 -1
  66. package/dist/testing/mod.js +4 -2
  67. package/dist/testing-COl4JbdC.js +301 -0
  68. package/dist/{vocab-Bvny-jeR.js → type-BvQGw6hv.js} +5255 -183
  69. package/dist/{types-91gV1mrn.js → types-E0EOd3en.js} +1 -1
  70. package/dist/{types-C7C_l-jz.js → types-n7HI7VFr.js} +1 -1
  71. package/dist/vocab/actor.test.js +10 -16
  72. package/dist/vocab/lookup.test.js +9 -16
  73. package/dist/vocab/mod.js +4 -4
  74. package/dist/vocab/type.test.js +3 -7
  75. package/dist/vocab/vocab.test.js +9 -13
  76. package/dist/{vocab-DUbTHmAQ.js → vocab-fVvi4e5m.js} +3 -3
  77. package/dist/webfinger/handler.test.js +25 -34
  78. package/dist/webfinger/lookup.test.js +9 -10
  79. package/dist/webfinger/mod.js +2 -2
  80. package/dist/x/cfworkers.test.js +8 -6
  81. package/package.json +1 -1
  82. package/dist/chunk-HsBuZ-b2.js +0 -41
  83. package/dist/context-DOdppD2M.js +0 -108
  84. package/dist/docloader-09nVWLAZ.js +0 -68
  85. package/dist/docloader-DqhzoWgx.js +0 -4526
  86. package/dist/key-DsQ07psn.js +0 -16
  87. package/dist/langstr-DbWheeIS.js +0 -33
  88. package/dist/lookup-CrmOp-xC.js +0 -132
  89. package/dist/middleware-BloPP8sC.js +0 -33
  90. package/dist/middleware-CYQ3reF_.js +0 -17
  91. package/dist/multibase-DeCHcK8L.js +0 -316
  92. package/dist/router-D3UybECj.js +0 -118
  93. package/dist/testing-BZ0dJ4qn.js +0 -143
  94. package/dist/type-D2s5lmbZ.js +0 -14
  95. package/dist/url-kTAI6_KP.js +0 -68
  96. /package/dist/{assert_is_error-DQdKoRgb.js → assert_is_error-CeVBLPsZ.js} +0 -0
  97. /package/dist/{assert_not_equals-7pyUM3Ib.js → assert_not_equals-D2R2nl5h.js} +0 -0
  98. /package/dist/{collection-Dfb0TPno.js → collection-D5V3UzU3.js} +0 -0
  99. /package/dist/{denokv-QWKsIqML.js → denokv-DK9P5Jq7.js} +0 -0
  100. /package/dist/{retry-BiIhZWgD.js → retry-BnpVRGFC.js} +0 -0
  101. /package/dist/{semver-DWClQt_5.js → semver-DCqorrj5.js} +0 -0
  102. /package/dist/{std__assert-B3iAixc-.js → std__assert-BQdmxyzF.js} +0 -0
@@ -1,16 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import "./docloader-DqhzoWgx.js";
7
- import "./url-kTAI6_KP.js";
8
- import "./multibase-DeCHcK8L.js";
9
- import "./vocab-Bvny-jeR.js";
10
- import "./langstr-DbWheeIS.js";
11
- import "./lookup-CrmOp-xC.js";
12
- import "./type-D2s5lmbZ.js";
13
- import "./actor-Br-ZQ9iE.js";
14
- import { exportJwk, fetchKey, generateCryptoKeyPair, importJwk, validateCryptoKey } from "./key-BpF6CgxV.js";
15
-
16
- export { validateCryptoKey };
@@ -1,33 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { parseLanguageTag } from "@phensley/language-tag";
7
-
8
- //#region runtime/langstr.ts
9
- /**
10
- * A language-tagged string which corresponds to the `rdf:langString` type.
11
- */
12
- var LanguageString = class extends String {
13
- language;
14
- /**
15
- * Constructs a new `LanguageString`.
16
- * @param value A string value written in the given language.
17
- * @param language The language of the string. If a string is given, it will
18
- * be parsed as a `LanguageTag`.
19
- */
20
- constructor(value, language) {
21
- super(value);
22
- this.language = typeof language === "string" ? parseLanguageTag(language) : language;
23
- }
24
- [Symbol.for("Deno.customInspect")](inspect, options) {
25
- return `<${this.language.compact()}> ${inspect(this.toString(), options)}`;
26
- }
27
- [Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) {
28
- return `<${this.language.compact()}> ${inspect(this.toString(), options)}`;
29
- }
30
- };
31
-
32
- //#endregion
33
- export { LanguageString };
@@ -1,132 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { deno_default, getUserAgent } from "./docloader-DqhzoWgx.js";
7
- import { UrlError, validatePublicUrl } from "./url-kTAI6_KP.js";
8
- import { getLogger } from "@logtape/logtape";
9
- import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
10
-
11
- //#region webfinger/lookup.ts
12
- const logger = getLogger([
13
- "fedify",
14
- "webfinger",
15
- "lookup"
16
- ]);
17
- const DEFAULT_MAX_REDIRECTION = 5;
18
- /**
19
- * Looks up a WebFinger resource.
20
- * @param resource The resource URL to look up.
21
- * @param options Extra options for looking up the resource.
22
- * @returns The resource descriptor, or `null` if not found.
23
- * @since 0.2.0
24
- */
25
- async function lookupWebFinger(resource, options = {}) {
26
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
27
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
28
- return await tracer.startActiveSpan("webfinger.lookup", {
29
- kind: SpanKind.CLIENT,
30
- attributes: {
31
- "webfinger.resource": resource.toString(),
32
- "webfinger.resource.scheme": typeof resource === "string" ? resource.replace(/:.*$/, "") : resource.protocol.replace(/:$/, "")
33
- }
34
- }, async (span) => {
35
- try {
36
- const result = await lookupWebFingerInternal(resource, options);
37
- span.setStatus({ code: result === null ? SpanStatusCode.ERROR : SpanStatusCode.OK });
38
- return result;
39
- } catch (error) {
40
- span.setStatus({
41
- code: SpanStatusCode.ERROR,
42
- message: String(error)
43
- });
44
- throw error;
45
- } finally {
46
- span.end();
47
- }
48
- });
49
- }
50
- async function lookupWebFingerInternal(resource, options = {}) {
51
- if (typeof resource === "string") resource = new URL(resource);
52
- let protocol = "https:";
53
- let server;
54
- if (resource.protocol === "acct:") {
55
- const atPos = resource.pathname.lastIndexOf("@");
56
- if (atPos < 0) return null;
57
- server = resource.pathname.substring(atPos + 1);
58
- if (server === "") return null;
59
- } else {
60
- protocol = resource.protocol;
61
- server = resource.host;
62
- }
63
- let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
64
- url.searchParams.set("resource", resource.href);
65
- let redirected = 0;
66
- while (true) {
67
- logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
68
- let response;
69
- if (options.allowPrivateAddress !== true) try {
70
- await validatePublicUrl(url.href);
71
- } catch (e) {
72
- if (e instanceof UrlError) {
73
- logger.error("Invalid URL for WebFinger resource descriptor: {error}", { error: e });
74
- return null;
75
- }
76
- throw e;
77
- }
78
- try {
79
- response = await fetch(url, {
80
- headers: {
81
- Accept: "application/jrd+json",
82
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
83
- },
84
- redirect: "manual"
85
- });
86
- } catch (error) {
87
- logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
88
- url: url.href,
89
- error
90
- });
91
- return null;
92
- }
93
- if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
94
- redirected++;
95
- const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
96
- if (redirected >= maxRedirection) {
97
- logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
98
- return null;
99
- }
100
- const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
101
- if (redirectedUrl.protocol !== url.protocol) {
102
- logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
103
- protocol: url.protocol,
104
- redirectedProtocol: redirectedUrl.protocol
105
- });
106
- return null;
107
- }
108
- url = redirectedUrl;
109
- continue;
110
- }
111
- if (!response.ok) {
112
- logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
113
- url: url.href,
114
- status: response.status,
115
- statusText: response.statusText
116
- });
117
- return null;
118
- }
119
- try {
120
- return await response.json();
121
- } catch (e) {
122
- if (e instanceof SyntaxError) {
123
- logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
124
- return null;
125
- }
126
- throw e;
127
- }
128
- }
129
- }
130
-
131
- //#endregion
132
- export { lookupWebFinger };
@@ -1,33 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-BHKH0CVi.js";
7
- import "./docloader-DqhzoWgx.js";
8
- import "./url-kTAI6_KP.js";
9
- import "./semver-DWClQt_5.js";
10
- import "./client-DdMIIvjf.js";
11
- import "./router-D3UybECj.js";
12
- import "./types-C7C_l-jz.js";
13
- import "./multibase-DeCHcK8L.js";
14
- import "./vocab-Bvny-jeR.js";
15
- import "./langstr-DbWheeIS.js";
16
- import "./lookup-CrmOp-xC.js";
17
- import "./type-D2s5lmbZ.js";
18
- import "./actor-Br-ZQ9iE.js";
19
- import "./key-BpF6CgxV.js";
20
- import "./http-69zRGYEG.js";
21
- import "./authdocloader-BMRGaiFE.js";
22
- import "./ld-DroIpWgz.js";
23
- import "./owner-B4cJX8FD.js";
24
- import "./proof-CVedLBo3.js";
25
- import "./lookup-CusFqkXP.js";
26
- import "./inbox-B4MZPH6B.js";
27
- import "./builder-mgHwYg4-.js";
28
- import "./collection-Dfb0TPno.js";
29
- import "./keycache-UKudzeG7.js";
30
- import "./retry-BiIhZWgD.js";
31
- import "./send-mEdMj0kU.js";
32
-
33
- export { FederationImpl };
@@ -1,17 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
-
5
- import "./transformers-ghwJuzGY.js";
6
- import "./docloader-Ddsh58Kf.js";
7
- import "./actor-DqpnNLrD.js";
8
- import { ContextImpl, FederationImpl, InboxContextImpl, KvSpecDeterminer, createFederation } from "./middleware-ClYMTxST.js";
9
- import "./lookup-X3OcU2u3.js";
10
- import "./key-D48qsYqC.js";
11
- import "./http-IMAUyNbl.js";
12
- import "./proof-BfKmsXPq.js";
13
- import "./types-91gV1mrn.js";
14
- import "./authdocloader-q9_ikBNG.js";
15
- import "./vocab-DUbTHmAQ.js";
16
-
17
- export { FederationImpl };
@@ -1,316 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import baseX from "@multiformats/base-x";
7
-
8
- //#region runtime/multibase/util.ts
9
- const textDecoder = new TextDecoder();
10
- const decodeText = (bytes) => textDecoder.decode(bytes);
11
- const textEncoder = new TextEncoder();
12
- const encodeText = (text) => textEncoder.encode(text);
13
- function concat(arrs, length) {
14
- const output = new Uint8Array(length);
15
- let offset = 0;
16
- for (const arr of arrs) {
17
- output.set(arr, offset);
18
- offset += arr.length;
19
- }
20
- return output;
21
- }
22
-
23
- //#endregion
24
- //#region runtime/multibase/base.ts
25
- /**
26
- * Class to encode/decode in the supported Bases
27
- */
28
- var Base = class {
29
- codeBuf;
30
- codec;
31
- constructor(name, code, factory, alphabet) {
32
- this.name = name;
33
- this.code = code;
34
- this.alphabet = alphabet;
35
- this.codeBuf = encodeText(this.code);
36
- this.alphabet = alphabet;
37
- this.codec = factory(alphabet);
38
- }
39
- encode(buf) {
40
- return this.codec.encode(buf);
41
- }
42
- decode(string) {
43
- for (const char of string) if (this.alphabet && this.alphabet.indexOf(char) < 0) throw new Error(`invalid character '${char}' in '${string}'`);
44
- return this.codec.decode(string);
45
- }
46
- };
47
-
48
- //#endregion
49
- //#region runtime/multibase/rfc4648.ts
50
- const decode$1 = (string, alphabet, bitsPerChar) => {
51
- const codes$1 = {};
52
- for (let i = 0; i < alphabet.length; ++i) codes$1[alphabet[i]] = i;
53
- let end = string.length;
54
- while (string[end - 1] === "=") --end;
55
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
56
- let bits = 0;
57
- let buffer = 0;
58
- let written = 0;
59
- for (let i = 0; i < end; ++i) {
60
- const value = codes$1[string[i]];
61
- if (value === void 0) throw new SyntaxError("Invalid character " + string[i]);
62
- buffer = buffer << bitsPerChar | value;
63
- bits += bitsPerChar;
64
- if (bits >= 8) {
65
- bits -= 8;
66
- out[written++] = 255 & buffer >> bits;
67
- }
68
- }
69
- if (bits >= bitsPerChar || 255 & buffer << 8 - bits) throw new SyntaxError("Unexpected end of data");
70
- return out;
71
- };
72
- const encode$1 = (data, alphabet, bitsPerChar) => {
73
- const pad = alphabet[alphabet.length - 1] === "=";
74
- const mask = (1 << bitsPerChar) - 1;
75
- let out = "";
76
- let bits = 0;
77
- let buffer = 0;
78
- for (let i = 0; i < data.length; ++i) {
79
- buffer = buffer << 8 | data[i];
80
- bits += 8;
81
- while (bits > bitsPerChar) {
82
- bits -= bitsPerChar;
83
- out += alphabet[mask & buffer >> bits];
84
- }
85
- }
86
- if (bits) out += alphabet[mask & buffer << bitsPerChar - bits];
87
- if (pad) while (out.length * bitsPerChar & 7) out += "=";
88
- return out;
89
- };
90
- /**
91
- * RFC4648 Factory
92
- */
93
- const rfc4648 = (bitsPerChar) => (alphabet) => {
94
- return {
95
- encode(input) {
96
- return encode$1(input, alphabet, bitsPerChar);
97
- },
98
- decode(input) {
99
- return decode$1(input, alphabet, bitsPerChar);
100
- }
101
- };
102
- };
103
-
104
- //#endregion
105
- //#region runtime/multibase/constants.ts
106
- const identity = () => {
107
- return {
108
- encode: decodeText,
109
- decode: encodeText
110
- };
111
- };
112
- /**
113
- * name, code, implementation, alphabet
114
- *
115
- * @type {Array<[BaseName, BaseCode, CodecFactory, string]>}
116
- */
117
- const constants = [
118
- [
119
- "identity",
120
- "\0",
121
- identity,
122
- ""
123
- ],
124
- [
125
- "base2",
126
- "0",
127
- rfc4648(1),
128
- "01"
129
- ],
130
- [
131
- "base8",
132
- "7",
133
- rfc4648(3),
134
- "01234567"
135
- ],
136
- [
137
- "base10",
138
- "9",
139
- baseX,
140
- "0123456789"
141
- ],
142
- [
143
- "base16",
144
- "f",
145
- rfc4648(4),
146
- "0123456789abcdef"
147
- ],
148
- [
149
- "base16upper",
150
- "F",
151
- rfc4648(4),
152
- "0123456789ABCDEF"
153
- ],
154
- [
155
- "base32hex",
156
- "v",
157
- rfc4648(5),
158
- "0123456789abcdefghijklmnopqrstuv"
159
- ],
160
- [
161
- "base32hexupper",
162
- "V",
163
- rfc4648(5),
164
- "0123456789ABCDEFGHIJKLMNOPQRSTUV"
165
- ],
166
- [
167
- "base32hexpad",
168
- "t",
169
- rfc4648(5),
170
- "0123456789abcdefghijklmnopqrstuv="
171
- ],
172
- [
173
- "base32hexpadupper",
174
- "T",
175
- rfc4648(5),
176
- "0123456789ABCDEFGHIJKLMNOPQRSTUV="
177
- ],
178
- [
179
- "base32",
180
- "b",
181
- rfc4648(5),
182
- "abcdefghijklmnopqrstuvwxyz234567"
183
- ],
184
- [
185
- "base32upper",
186
- "B",
187
- rfc4648(5),
188
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
189
- ],
190
- [
191
- "base32pad",
192
- "c",
193
- rfc4648(5),
194
- "abcdefghijklmnopqrstuvwxyz234567="
195
- ],
196
- [
197
- "base32padupper",
198
- "C",
199
- rfc4648(5),
200
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="
201
- ],
202
- [
203
- "base32z",
204
- "h",
205
- rfc4648(5),
206
- "ybndrfg8ejkmcpqxot1uwisza345h769"
207
- ],
208
- [
209
- "base36",
210
- "k",
211
- baseX,
212
- "0123456789abcdefghijklmnopqrstuvwxyz"
213
- ],
214
- [
215
- "base36upper",
216
- "K",
217
- baseX,
218
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
219
- ],
220
- [
221
- "base58btc",
222
- "z",
223
- baseX,
224
- "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
225
- ],
226
- [
227
- "base58flickr",
228
- "Z",
229
- baseX,
230
- "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
231
- ],
232
- [
233
- "base64",
234
- "m",
235
- rfc4648(6),
236
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
237
- ],
238
- [
239
- "base64pad",
240
- "M",
241
- rfc4648(6),
242
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
243
- ],
244
- [
245
- "base64url",
246
- "u",
247
- rfc4648(6),
248
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
249
- ],
250
- [
251
- "base64urlpad",
252
- "U",
253
- rfc4648(6),
254
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="
255
- ]
256
- ];
257
- const names = constants.reduce((prev, tupple) => {
258
- prev[tupple[0]] = new Base(tupple[0], tupple[1], tupple[2], tupple[3]);
259
- return prev;
260
- }, {});
261
- const codes = constants.reduce((prev, tupple) => {
262
- prev[tupple[1]] = names[tupple[0]];
263
- return prev;
264
- }, {});
265
-
266
- //#endregion
267
- //#region runtime/multibase/index.ts
268
- /**
269
- * Encode data with the specified base and add the multibase prefix.
270
- *
271
- * @throws {Error} Will throw if the encoding is not supported
272
- */
273
- function encode(nameOrCode, buf) {
274
- const enc = encoding(nameOrCode);
275
- const data = encodeText(enc.encode(buf));
276
- return concat([enc.codeBuf, data], enc.codeBuf.length + data.length);
277
- }
278
- /**
279
- * Takes a Uint8Array or string encoded with multibase header, decodes it and
280
- * returns the decoded buffer
281
- *
282
- * @throws {Error} Will throw if the encoding is not supported
283
- */
284
- function decode(data) {
285
- if (data instanceof Uint8Array) data = decodeText(data);
286
- const prefix = data[0];
287
- if ([
288
- "f",
289
- "F",
290
- "v",
291
- "V",
292
- "t",
293
- "T",
294
- "b",
295
- "B",
296
- "c",
297
- "C",
298
- "h",
299
- "k",
300
- "K"
301
- ].includes(prefix)) data = data.toLowerCase();
302
- const enc = encoding(data[0]);
303
- return enc.decode(data.substring(1));
304
- }
305
- /**
306
- * Get the encoding by name or code
307
- * @throws {Error} Will throw if the encoding is not supported
308
- */
309
- function encoding(nameOrCode) {
310
- if (Object.prototype.hasOwnProperty.call(names, nameOrCode)) return names[nameOrCode];
311
- else if (Object.prototype.hasOwnProperty.call(codes, nameOrCode)) return codes[nameOrCode];
312
- else throw new Error(`Unsupported encoding: ${nameOrCode}`);
313
- }
314
-
315
- //#endregion
316
- export { codes, decode, decodeText, encode, encodeText, names };
@@ -1,118 +0,0 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- import { URLPattern } from "urlpattern-polyfill";
4
- globalThis.addEventListener = () => {};
5
-
6
- import { cloneDeep } from "es-toolkit";
7
- import { Router } from "uri-template-router";
8
- import { parseTemplate } from "url-template";
9
-
10
- //#region federation/router.ts
11
- function cloneInnerRouter(router) {
12
- const clone = new Router();
13
- clone.nid = router.nid;
14
- clone.fsm = cloneDeep(router.fsm);
15
- clone.routeSet = new Set(router.routeSet);
16
- clone.templateRouteMap = new Map(router.templateRouteMap);
17
- clone.valueRouteMap = new Map(router.valueRouteMap);
18
- clone.hierarchy = cloneDeep(router.hierarchy);
19
- return clone;
20
- }
21
- /**
22
- * URL router and constructor based on URI Template
23
- * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
24
- */
25
- var Router$1 = class Router$1 {
26
- #router;
27
- #templates;
28
- #templateStrings;
29
- /**
30
- * Whether to ignore trailing slashes when matching paths.
31
- * @since 1.6.0
32
- */
33
- trailingSlashInsensitive;
34
- /**
35
- * Create a new {@link Router}.
36
- * @param options Options for the router.
37
- */
38
- constructor(options = {}) {
39
- this.#router = new Router();
40
- this.#templates = {};
41
- this.#templateStrings = {};
42
- this.trailingSlashInsensitive = options.trailingSlashInsensitive ?? false;
43
- }
44
- clone() {
45
- const clone = new Router$1({ trailingSlashInsensitive: this.trailingSlashInsensitive });
46
- clone.#router = cloneInnerRouter(this.#router);
47
- clone.#templates = { ...this.#templates };
48
- clone.#templateStrings = { ...this.#templateStrings };
49
- return clone;
50
- }
51
- /**
52
- * Checks if a path name exists in the router.
53
- * @param name The name of the path.
54
- * @returns `true` if the path name exists, otherwise `false`.
55
- */
56
- has(name) {
57
- return name in this.#templates;
58
- }
59
- /**
60
- * Adds a new path rule to the router.
61
- * @param template The path pattern.
62
- * @param name The name of the path.
63
- * @returns The names of the variables in the path pattern.
64
- */
65
- add(template, name) {
66
- if (!template.startsWith("/")) throw new RouterError("Path must start with a slash.");
67
- const rule = this.#router.addTemplate(template, {}, name);
68
- this.#templates[name] = parseTemplate(template);
69
- this.#templateStrings[name] = template;
70
- return new Set(rule.variables.map((v) => v.varname));
71
- }
72
- /**
73
- * Resolves a path name and values from a URL, if any match.
74
- * @param url The URL to resolve.
75
- * @returns The name of the path and its values, if any match. Otherwise,
76
- * `null`.
77
- */
78
- route(url) {
79
- let match = this.#router.resolveURI(url);
80
- if (match == null) {
81
- if (!this.trailingSlashInsensitive) return null;
82
- url = url.endsWith("/") ? url.replace(/\/+$/, "") : `${url}/`;
83
- match = this.#router.resolveURI(url);
84
- if (match == null) return null;
85
- }
86
- return {
87
- name: match.matchValue,
88
- template: this.#templateStrings[match.matchValue],
89
- values: match.params
90
- };
91
- }
92
- /**
93
- * Constructs a URL/path from a path name and values.
94
- * @param name The name of the path.
95
- * @param values The values to expand the path with.
96
- * @returns The URL/path, if the name exists. Otherwise, `null`.
97
- */
98
- build(name, values) {
99
- if (name in this.#templates) return this.#templates[name].expand(values);
100
- return null;
101
- }
102
- };
103
- /**
104
- * An error thrown by the {@link Router}.
105
- */
106
- var RouterError = class extends Error {
107
- /**
108
- * Create a new {@link RouterError}.
109
- * @param message The error message.
110
- */
111
- constructor(message) {
112
- super(message);
113
- this.name = "RouterError";
114
- }
115
- };
116
-
117
- //#endregion
118
- export { Router$1 as Router, RouterError };