@fedify/fedify 1.8.1-pr.334.1193 → 1.8.1-pr.339.1221
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/dist/{actor-CeBMq8qR.js → actor-C_fB23SK.js} +1 -1
- package/dist/{actor-BxYrc06V.js → actor-D-gppdfb.js} +179 -179
- package/dist/{authdocloader-mGQvrIQ2.js → authdocloader-B2hkRlHV.js} +3 -3
- package/dist/{authdocloader-D64rqKxU.js → authdocloader-C4tzFZqI.js} +3 -3
- package/dist/{builder-BMWyrhEH.js → builder-D8tC_vfI.js} +74 -4
- package/dist/{client-CTC5x_Sz.js → client-Bk-YQuxz.js} +1 -1
- package/dist/compat/mod.d.ts +3 -3
- package/dist/compat/transformers.test.js +16 -16
- package/dist/{context-B6mUZhs_.d.ts → context-Csbv_Ssv.d.ts} +215 -2
- package/dist/{docloader-BU0Mbf3M.js → docloader-CN5x_D5w.js} +1 -1
- package/dist/{esm-LMB9p-G5.js → esm-B-Jb47LY.js} +1 -1
- package/dist/federation/builder.test.js +25 -6
- package/dist/federation/collection.test.js +3 -3
- package/dist/federation/handler.test.js +327 -17
- package/dist/federation/inbox.test.js +4 -4
- package/dist/federation/keycache.test.js +4 -4
- package/dist/federation/kv.test.js +3 -3
- package/dist/federation/middleware.test.js +49 -18
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +10 -10
- package/dist/federation/mq.test.js +3 -3
- package/dist/federation/retry.test.js +3 -3
- package/dist/federation/router.test.js +3 -3
- package/dist/federation/send.test.js +10 -10
- package/dist/{http-D1uoUH4N.d.ts → http-BL6S1G0j.d.ts} +1 -1
- package/dist/{http-D3g0NXG1.js → http-BN-AfxHv.js} +2 -2
- package/dist/{http-CYR3mIVn.js → http-CX9EBYil.js} +3 -3
- package/dist/{inbox-CKssCQNk.js → inbox-B-guAC2t.js} +1 -1
- package/dist/{key-CuNvhgVd.js → key-BsFs0hRJ.js} +4 -4
- package/dist/{key-BBZcKCrH.js → key-CDER1nPf.js} +2 -2
- package/dist/{key-CmOXs0Mq.js → key-DBpUT6eL.js} +3 -3
- package/dist/{key-YOEsvep6.js → key-wEgiBcf4.js} +2 -2
- package/dist/{keycache-DGObidvq.js → keycache-CzNY9D-R.js} +1 -1
- package/dist/{keys-CPhbsrsX.js → keys-DyrWvTVk.js} +1 -1
- package/dist/{ld-D8ugSU-x.js → ld-Bij-eGOh.js} +2 -2
- package/dist/{lookup-rBByGTyy.js → lookup-BnVbBDao.js} +1 -1
- package/dist/{lookup-B0_qPExk.js → lookup-Dvnw2uak.js} +1 -1
- package/dist/{middleware-B_To0NZ3.js → middleware-BdCHqVyf.js} +615 -10
- package/dist/middleware-BylQejY9.js +17 -0
- package/dist/{middleware-u2WBeCjB.js → middleware-CRHRYKzd.js} +549 -14
- package/dist/middleware-Cruz4Ju6.js +26 -0
- package/dist/{mod-0L5jhGYM.d.ts → mod-D8-liXFY.d.ts} +1 -1
- package/dist/{mod-D9qE4iHP.d.ts → mod-Dc_fDCtK.d.ts} +1 -1
- package/dist/{mod-BCl7t-Ka.d.ts → mod-j0OCtlRW.d.ts} +1 -1
- package/dist/mod.d.ts +6 -6
- package/dist/mod.js +10 -10
- package/dist/nodeinfo/client.test.js +5 -5
- package/dist/nodeinfo/handler.test.js +16 -16
- package/dist/nodeinfo/mod.js +2 -2
- package/dist/nodeinfo/semver.test.js +3 -3
- package/dist/nodeinfo/types.test.js +3 -3
- package/dist/{owner-D1TBvEbO.js → owner-DaDx2G2T.js} +2 -2
- package/dist/{proof-CUsFh6B-.js → proof-B7EUMoa_.js} +3 -3
- package/dist/{proof-CyWfFsKS.js → proof-BY0M6tMI.js} +2 -2
- package/dist/runtime/authdocloader.test.js +9 -9
- package/dist/runtime/docloader.test.js +4 -4
- package/dist/runtime/key.test.js +5 -5
- package/dist/runtime/langstr.test.js +3 -3
- package/dist/runtime/mod.d.ts +2 -2
- package/dist/runtime/mod.js +6 -6
- package/dist/runtime/multibase/multibase.test.js +3 -3
- package/dist/runtime/url.test.js +3 -3
- package/dist/{send-CrjrTnXW.js → send-DfVJ7u7H.js} +2 -2
- package/dist/sig/http.test.js +8 -8
- package/dist/sig/key.test.js +6 -6
- package/dist/sig/ld.test.js +7 -7
- package/dist/sig/mod.d.ts +2 -2
- package/dist/sig/mod.js +6 -6
- package/dist/sig/owner.test.js +7 -7
- package/dist/sig/proof.test.js +7 -7
- package/dist/testing/docloader.test.js +3 -3
- package/dist/testing/mod.d.ts +212 -0
- package/dist/testing/mod.js +3 -3
- package/dist/{testing-CROcCUCq.js → testing-CxPA9ooV.js} +4 -3
- package/dist/{type-DGlR8Urb.js → type-BclCS6EM.js} +179 -179
- package/dist/{types-DZdBK266.js → types-aPGcTfd2.js} +1 -1
- package/dist/vocab/actor.test.js +5 -5
- package/dist/vocab/lookup.test.js +4 -4
- package/dist/vocab/mod.js +4 -4
- package/dist/vocab/type.test.js +3 -3
- package/dist/vocab/vocab.test.js +4 -4
- package/dist/{vocab-BLQ-_oLb.js → vocab-BgH1bkzj.js} +3 -3
- package/dist/webfinger/handler.test.js +16 -16
- package/dist/webfinger/lookup.test.js +4 -4
- package/dist/webfinger/mod.js +2 -2
- package/dist/x/cfworkers.test.js +3 -3
- package/dist/x/hono.d.ts +2 -2
- package/dist/x/sveltekit.d.ts +2 -2
- package/package.json +1 -1
- package/dist/middleware-DbDzHrt7.js +0 -17
- package/dist/middleware-JUbAKlS5.js +0 -26
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
|
|
5
|
-
import { UrlError, createRequest, getRemoteDocument, logRequest, validatePublicUrl } from "./docloader-
|
|
6
|
-
import { validateCryptoKey } from "./key-
|
|
7
|
-
import { doubleKnock } from "./http-
|
|
5
|
+
import { UrlError, createRequest, getRemoteDocument, logRequest, validatePublicUrl } from "./docloader-CN5x_D5w.js";
|
|
6
|
+
import { validateCryptoKey } from "./key-CDER1nPf.js";
|
|
7
|
+
import { doubleKnock } from "./http-CX9EBYil.js";
|
|
8
8
|
import { getLogger } from "@logtape/logtape";
|
|
9
9
|
|
|
10
10
|
//#region runtime/authdocloader.ts
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { UrlError, createRequest, getRemoteDocument, logRequest, validatePublicUrl } from "./type-
|
|
7
|
-
import { validateCryptoKey } from "./key-
|
|
8
|
-
import { doubleKnock } from "./http-
|
|
6
|
+
import { UrlError, createRequest, getRemoteDocument, logRequest, validatePublicUrl } from "./type-BclCS6EM.js";
|
|
7
|
+
import { validateCryptoKey } from "./key-wEgiBcf4.js";
|
|
8
|
+
import { doubleKnock } from "./http-BN-AfxHv.js";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
10
10
|
|
|
11
11
|
//#region runtime/authdocloader.ts
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { deno_default, getTypeId } from "./type-
|
|
7
|
-
import { Router, RouterError } from "./lookup-
|
|
8
|
-
import { InboxListenerSet } from "./inbox-
|
|
6
|
+
import { deno_default, getTypeId } from "./type-BclCS6EM.js";
|
|
7
|
+
import { Router, RouterError } from "./lookup-Dvnw2uak.js";
|
|
8
|
+
import { InboxListenerSet } from "./inbox-B-guAC2t.js";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
10
10
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
11
11
|
|
|
@@ -27,13 +27,21 @@ var FederationBuilderImpl = class {
|
|
|
27
27
|
inboxListeners;
|
|
28
28
|
inboxErrorHandler;
|
|
29
29
|
sharedInboxKeyDispatcher;
|
|
30
|
+
collectionTypeIds;
|
|
31
|
+
collectionCallbacks;
|
|
32
|
+
/**
|
|
33
|
+
* Symbol registry for unique identification of unnamed symbols.
|
|
34
|
+
*/
|
|
35
|
+
#symbolRegistry = /* @__PURE__ */ new Map();
|
|
30
36
|
constructor() {
|
|
31
37
|
this.router = new Router();
|
|
32
38
|
this.objectCallbacks = {};
|
|
33
39
|
this.objectTypeIds = {};
|
|
40
|
+
this.collectionCallbacks = {};
|
|
41
|
+
this.collectionTypeIds = {};
|
|
34
42
|
}
|
|
35
43
|
async build(options) {
|
|
36
|
-
const { FederationImpl } = await import("./middleware-
|
|
44
|
+
const { FederationImpl } = await import("./middleware-Cruz4Ju6.js");
|
|
37
45
|
const f = new FederationImpl(options);
|
|
38
46
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
39
47
|
f.router = this.router.clone();
|
|
@@ -477,6 +485,68 @@ var FederationBuilderImpl = class {
|
|
|
477
485
|
};
|
|
478
486
|
return setters;
|
|
479
487
|
}
|
|
488
|
+
setCollectionDispatcher(name, ...args) {
|
|
489
|
+
return this.#setCustomCollectionDispatcher(name, "collection", ...args);
|
|
490
|
+
}
|
|
491
|
+
setOrderedCollectionDispatcher(name, ...args) {
|
|
492
|
+
return this.#setCustomCollectionDispatcher(name, "orderedCollection", ...args);
|
|
493
|
+
}
|
|
494
|
+
#setCustomCollectionDispatcher(name, collectionType, itemType, path, dispatcher) {
|
|
495
|
+
const strName = String(name);
|
|
496
|
+
const routeName = `${collectionType}:${this.#uniqueCollectionId(name)}`;
|
|
497
|
+
if (this.router.has(routeName)) throw new RouterError(`Collection dispatcher for ${strName} already set.`);
|
|
498
|
+
if (this.collectionCallbacks[name] != null) throw new RouterError(`Collection dispatcher for ${strName} already set.`);
|
|
499
|
+
const variables = this.router.add(path, routeName);
|
|
500
|
+
if (variables.size < 1) throw new RouterError("Path for collection dispatcher must have at least one variable.");
|
|
501
|
+
const callbacks = { dispatcher };
|
|
502
|
+
this.collectionCallbacks[name] = callbacks;
|
|
503
|
+
this.collectionTypeIds[name] = itemType;
|
|
504
|
+
const setters = {
|
|
505
|
+
setCounter(counter) {
|
|
506
|
+
callbacks.counter = counter;
|
|
507
|
+
return setters;
|
|
508
|
+
},
|
|
509
|
+
setFirstCursor(cursor) {
|
|
510
|
+
callbacks.firstCursor = cursor;
|
|
511
|
+
return setters;
|
|
512
|
+
},
|
|
513
|
+
setLastCursor(cursor) {
|
|
514
|
+
callbacks.lastCursor = cursor;
|
|
515
|
+
return setters;
|
|
516
|
+
},
|
|
517
|
+
authorize(predicate) {
|
|
518
|
+
callbacks.authorizePredicate = predicate;
|
|
519
|
+
return setters;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
return setters;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Get the URL path for a custom collection.
|
|
526
|
+
* If the collection is not registered, returns null.
|
|
527
|
+
* @typeParam TParam The parameter names of the requested URL.
|
|
528
|
+
* @param {string | symbol} name The name of the custom collection.
|
|
529
|
+
* @param {TParam} values The values to fill in the URL parameters.
|
|
530
|
+
* @returns {string | null} The URL path for the custom collection, or null if not registered.
|
|
531
|
+
*/
|
|
532
|
+
getCollectionPath(name, values) {
|
|
533
|
+
if (!(name in this.collectionCallbacks)) return null;
|
|
534
|
+
const routeName = this.#uniqueCollectionId(name);
|
|
535
|
+
const path = this.router.build(`collection:${routeName}`, values) ?? this.router.build(`orderedCollection:${routeName}`, values);
|
|
536
|
+
return path;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Converts a name (string or symbol) to a unique string identifier.
|
|
540
|
+
* For symbols, generates and caches a UUID if not already present.
|
|
541
|
+
* For strings, returns the string as-is.
|
|
542
|
+
* @param name The name to convert to a unique identifier
|
|
543
|
+
* @returns A unique string identifier
|
|
544
|
+
*/
|
|
545
|
+
#uniqueCollectionId(name) {
|
|
546
|
+
if (typeof name === "string") return name;
|
|
547
|
+
if (!this.#symbolRegistry.has(name)) this.#symbolRegistry.set(name, crypto.randomUUID());
|
|
548
|
+
return this.#symbolRegistry.get(name);
|
|
549
|
+
}
|
|
480
550
|
};
|
|
481
551
|
/**
|
|
482
552
|
* Creates a new {@link FederationBuilder} instance.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { getUserAgent } from "./type-
|
|
6
|
+
import { getUserAgent } from "./type-BclCS6EM.js";
|
|
7
7
|
import { parseSemVer } from "./semver-DCqorrj5.js";
|
|
8
8
|
import { getLogger } from "@logtape/logtape";
|
|
9
9
|
|
package/dist/compat/mod.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ import "../docloader-BeCtcTOJ.js";
|
|
|
5
5
|
import "../client-BQ4AQGKo.js";
|
|
6
6
|
import "../vocab-By6mpzr-.js";
|
|
7
7
|
import "../actor-B4TBtqRP.js";
|
|
8
|
-
import "../http-
|
|
8
|
+
import "../http-BL6S1G0j.js";
|
|
9
9
|
import "../owner-CEv_PfyK.js";
|
|
10
10
|
import "../mod-BFwgZ7_K.js";
|
|
11
11
|
import "../lookup-J_m4YZg0.js";
|
|
12
|
-
import { ActivityTransformer } from "../context-
|
|
12
|
+
import { ActivityTransformer } from "../context-Csbv_Ssv.js";
|
|
13
13
|
import "../mq-DYKDDJmp.js";
|
|
14
|
-
import { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers } from "../mod-
|
|
14
|
+
import { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers } from "../mod-Dc_fDCtK.js";
|
|
15
15
|
export { ActivityTransformer, actorDehydrator, autoIdAssigner, getDefaultActivityTransformers };
|
|
@@ -3,30 +3,30 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { Follow, Person } from "../type-
|
|
6
|
+
import { Follow, Person } from "../type-BclCS6EM.js";
|
|
7
7
|
import { assertEquals } from "../assert_equals-C5gKCm6A.js";
|
|
8
8
|
import { assert } from "../assert-DwEa6glZ.js";
|
|
9
9
|
import { assertInstanceOf } from "../assert_instance_of-C9QtN-X9.js";
|
|
10
10
|
import { MemoryKvStore } from "../kv-D7Yt6pnB.js";
|
|
11
|
-
import { FederationImpl, actorDehydrator, autoIdAssigner } from "../middleware-
|
|
11
|
+
import { FederationImpl, actorDehydrator, autoIdAssigner } from "../middleware-CRHRYKzd.js";
|
|
12
12
|
import "../semver-DCqorrj5.js";
|
|
13
|
-
import "../client-
|
|
14
|
-
import "../lookup-
|
|
13
|
+
import "../client-Bk-YQuxz.js";
|
|
14
|
+
import "../lookup-Dvnw2uak.js";
|
|
15
15
|
import "../types-n7HI7VFr.js";
|
|
16
|
-
import "../actor-
|
|
17
|
-
import "../key-
|
|
18
|
-
import "../http-
|
|
19
|
-
import "../authdocloader-
|
|
20
|
-
import "../ld-
|
|
21
|
-
import "../owner-
|
|
22
|
-
import "../proof-
|
|
23
|
-
import "../inbox-
|
|
24
|
-
import "../builder-
|
|
16
|
+
import "../actor-C_fB23SK.js";
|
|
17
|
+
import "../key-wEgiBcf4.js";
|
|
18
|
+
import "../http-BN-AfxHv.js";
|
|
19
|
+
import "../authdocloader-C4tzFZqI.js";
|
|
20
|
+
import "../ld-Bij-eGOh.js";
|
|
21
|
+
import "../owner-DaDx2G2T.js";
|
|
22
|
+
import "../proof-BY0M6tMI.js";
|
|
23
|
+
import "../inbox-B-guAC2t.js";
|
|
24
|
+
import "../builder-D8tC_vfI.js";
|
|
25
25
|
import "../collection-D5V3UzU3.js";
|
|
26
|
-
import "../keycache-
|
|
26
|
+
import "../keycache-CzNY9D-R.js";
|
|
27
27
|
import "../retry-BnpVRGFC.js";
|
|
28
|
-
import "../send-
|
|
29
|
-
import { test } from "../testing-
|
|
28
|
+
import "../send-DfVJ7u7H.js";
|
|
29
|
+
import { test } from "../testing-CxPA9ooV.js";
|
|
30
30
|
|
|
31
31
|
//#region compat/transformers.test.ts
|
|
32
32
|
const federation = new FederationImpl({ kv: new MemoryKvStore() });
|
|
@@ -5,7 +5,7 @@ import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFacto
|
|
|
5
5
|
import { GetNodeInfoOptions, JsonValue, NodeInfo } from "./client-BQ4AQGKo.js";
|
|
6
6
|
import { Activity, Collection, CryptographicKey, Hashtag, Link, Multikey, Object as Object$1 } from "./vocab-By6mpzr-.js";
|
|
7
7
|
import { Actor, Recipient } from "./actor-B4TBtqRP.js";
|
|
8
|
-
import { HttpMessageSignaturesSpec } from "./http-
|
|
8
|
+
import { HttpMessageSignaturesSpec } from "./http-BL6S1G0j.js";
|
|
9
9
|
import { GetKeyOwnerOptions } from "./owner-CEv_PfyK.js";
|
|
10
10
|
import { LookupObjectOptions, TraverseCollectionOptions } from "./mod-BFwgZ7_K.js";
|
|
11
11
|
import { LookupWebFingerOptions, ResourceDescriptor } from "./lookup-J_m4YZg0.js";
|
|
@@ -260,8 +260,48 @@ type AuthorizePredicate<TContextData> = (context: RequestContext<TContextData>,
|
|
|
260
260
|
* @since 0.7.0
|
|
261
261
|
*/
|
|
262
262
|
type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>, signedKey: CryptographicKey | null, signedKeyOwner: Actor | null) => boolean | Promise<boolean>;
|
|
263
|
+
/**
|
|
264
|
+
* A callback that dispatches a custom collection.
|
|
265
|
+
*
|
|
266
|
+
* @typeParam TItem The type of items in the collection.
|
|
267
|
+
* @typeParam TParams The parameter names of the requested URL.
|
|
268
|
+
* @typeParam TContext The type of the context. {@link Context} or
|
|
269
|
+
* {@link RequestContext}.
|
|
270
|
+
* @typeParam TContextData The context data to pass to the `TContext`.
|
|
271
|
+
* @typeParam TFilter The type of the filter, if any.
|
|
272
|
+
* @param context The context.
|
|
273
|
+
* @param values The parameters of the requested URL.
|
|
274
|
+
* @param cursor The cursor to start the collection from, or `null` to dispatch
|
|
275
|
+
* the entire collection without pagination.
|
|
276
|
+
* @since 1.8.0
|
|
277
|
+
*/
|
|
278
|
+
type CustomCollectionDispatcher<TItem, TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: TParams, cursor: string | null) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
|
|
279
|
+
/**
|
|
280
|
+
* A callback that counts the number of items in a custom collection.
|
|
281
|
+
*
|
|
282
|
+
* @typeParam TParams The parameter names of the requested URL.
|
|
283
|
+
* @typeParam TContextData The context data to pass to the {@link Context}.
|
|
284
|
+
* @param context The context.
|
|
285
|
+
* @param values The parameters of the requested URL.
|
|
286
|
+
* @since 1.8.0
|
|
287
|
+
*/
|
|
288
|
+
type CustomCollectionCounter<TParams extends Record<string, string>, TContextData> = (context: RequestContext<TContextData>, values: TParams) => number | bigint | null | Promise<number | bigint | null>;
|
|
289
|
+
/**
|
|
290
|
+
* A callback that returns a cursor for a custom collection.
|
|
291
|
+
*
|
|
292
|
+
* @typeParam TParams The parameter names of the requested URL.
|
|
293
|
+
* @typeParam TContext The type of the context. {@link Context} or
|
|
294
|
+
* {@link RequestContext}.
|
|
295
|
+
* @typeParam TContextData The context data to pass to the {@link Context}.
|
|
296
|
+
* @typeParam TFilter The type of the filter, if any.
|
|
297
|
+
* @param context The context.
|
|
298
|
+
* @param values The parameters of the requested URL.
|
|
299
|
+
* @since 1.8.0
|
|
300
|
+
*/
|
|
301
|
+
type CustomCollectionCursor<TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: TParams) => string | null | Promise<string | null>;
|
|
263
302
|
//#endregion
|
|
264
303
|
//#region federation/handler.d.ts
|
|
304
|
+
|
|
265
305
|
/**
|
|
266
306
|
* Options for the {@link respondWithObject} and
|
|
267
307
|
* {@link respondWithObjectIfAcceptable} functions.
|
|
@@ -874,6 +914,36 @@ interface Federatable<TContextData> {
|
|
|
874
914
|
* @throws {RouteError} Thrown if the path pattern is invalid.
|
|
875
915
|
*/
|
|
876
916
|
setInboxListeners(inboxPath: `${string}{identifier}${string}` | `${string}{handle}${string}`, sharedInboxPath?: string): InboxListenerSetters<TContextData>;
|
|
917
|
+
/**
|
|
918
|
+
* Registers a collection of objects dispatcher.
|
|
919
|
+
*
|
|
920
|
+
* @typeParam TContextData The context data to pass to the {@link Context}.
|
|
921
|
+
* @typeParam TObject The type of objects to dispatch.
|
|
922
|
+
* @typeParam TParam The parameter names of the requested URL.
|
|
923
|
+
* @param name A unique name for the collection dispatcher.
|
|
924
|
+
* @param itemType The Activity Vocabulary class of the object to dispatch.
|
|
925
|
+
* @param path The URI path pattern for the collection dispatcher.
|
|
926
|
+
* The syntax is based on URI Template
|
|
927
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
|
928
|
+
* The path must have one or more variables.
|
|
929
|
+
* @param dispatcher A collection dispatcher callback to register.
|
|
930
|
+
*/
|
|
931
|
+
setCollectionDispatcher<TObject extends Object$1, TParams extends Record<string, string>>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: ParamsKeyPath<TParams>, dispatcher: CustomCollectionDispatcher<TObject, TParams, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParams, RequestContext<TContextData>, TContextData>;
|
|
932
|
+
/**
|
|
933
|
+
* Registers an ordered collection of objects dispatcher.
|
|
934
|
+
*
|
|
935
|
+
* @typeParam TContextData The context data to pass to the {@link Context}.
|
|
936
|
+
* @typeParam TObject The type of objects to dispatch.
|
|
937
|
+
* @typeParam TParam The parameter names of the requested URL.
|
|
938
|
+
* @param name A unique name for the collection dispatcher.
|
|
939
|
+
* @param itemType The Activity Vocabulary class of the object to dispatch.
|
|
940
|
+
* @param path The URI path pattern for the collection dispatcher.
|
|
941
|
+
* The syntax is based on URI Template
|
|
942
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
|
943
|
+
* The path must have one or more variables.
|
|
944
|
+
* @param dispatcher A collection dispatcher callback to register.
|
|
945
|
+
*/
|
|
946
|
+
setOrderedCollectionDispatcher<TObject extends Object$1, TParams extends Record<string, string>>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: ParamsKeyPath<TParams>, dispatcher: CustomCollectionDispatcher<TObject, TParams, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParams, RequestContext<TContextData>, TContextData>;
|
|
877
947
|
}
|
|
878
948
|
/**
|
|
879
949
|
* An object that registers federation-related business logic and dispatches
|
|
@@ -1294,6 +1364,119 @@ interface FederationFetchOptions<TContextData> {
|
|
|
1294
1364
|
*/
|
|
1295
1365
|
onUnauthorized?: (request: Request) => Response | Promise<Response>;
|
|
1296
1366
|
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Additional settings for a custom collection dispatcher.
|
|
1369
|
+
*
|
|
1370
|
+
* @typeParam TParams The type of the parameters in the URL path.
|
|
1371
|
+
* @typeParam TContext The type of the context. {@link Context} or
|
|
1372
|
+
* {@link RequestContext}.
|
|
1373
|
+
* @typeParam TContextData The context data to pass to the {@link Context}.
|
|
1374
|
+
* @typeParam TFilter The type of filter for the collection.
|
|
1375
|
+
*/
|
|
1376
|
+
interface CustomCollectionCallbackSetters<TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> {
|
|
1377
|
+
/**
|
|
1378
|
+
* Sets the counter for the custom collection.
|
|
1379
|
+
* @param counter A callback that returns the number of items in the custom collection.
|
|
1380
|
+
* @returns The setters object so that settings can be chained.
|
|
1381
|
+
*/
|
|
1382
|
+
setCounter(counter: CustomCollectionCounter<TParams, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Sets the first cursor for the custom collection.
|
|
1385
|
+
* @param cursor The cursor for the first item in the custom collection.
|
|
1386
|
+
* @returns The setters object so that settings can be chained.
|
|
1387
|
+
*/
|
|
1388
|
+
setFirstCursor(cursor: CustomCollectionCursor<TParams, TContext, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
|
1389
|
+
/**
|
|
1390
|
+
* Sets the last cursor for the custom collection.
|
|
1391
|
+
* @param cursor The cursor for the last item in the custom collection.
|
|
1392
|
+
* @returns The setters object so that settings can be chained.
|
|
1393
|
+
*/
|
|
1394
|
+
setLastCursor(cursor: CustomCollectionCursor<TParams, TContext, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
|
1395
|
+
/**
|
|
1396
|
+
* Specifies the conditions under which requests are authorized.
|
|
1397
|
+
* @param predicate A callback that returns whether a request is authorized.
|
|
1398
|
+
* @returns The setters object so that settings can be chained.
|
|
1399
|
+
* @since 0.7.0
|
|
1400
|
+
*/
|
|
1401
|
+
authorize(predicate: ObjectAuthorizePredicate<TContextData, string>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Represents an object with a type ID, which is either a constructor or an
|
|
1405
|
+
* instance of the object.
|
|
1406
|
+
*
|
|
1407
|
+
* @typeParam TObject The type of the object.
|
|
1408
|
+
*/
|
|
1409
|
+
type ConstructorWithTypeId<TObject extends Object$1> = (new (...args: any[]) => TObject) & {
|
|
1410
|
+
typeId: URL;
|
|
1411
|
+
};
|
|
1412
|
+
/**
|
|
1413
|
+
* Represents a path from the key of parameter objects.
|
|
1414
|
+
* @param Params - A record of parameters where keys are parameter names and
|
|
1415
|
+
* values are their string representations.
|
|
1416
|
+
* @returns A string representing the path with all parameters.
|
|
1417
|
+
* @example
|
|
1418
|
+
* ```ts
|
|
1419
|
+
* type UserPostPath = ParamsKeyPath<{ userId: string; postId: string }>;
|
|
1420
|
+
* let userPostPath: UserPostPath;
|
|
1421
|
+
* // userPostPath = "/posts/{postId}"; // invalid - does not contain `{userId}`
|
|
1422
|
+
* // userPostPath = "/users/{userId}"; // invalid - does not contain `{postId}`
|
|
1423
|
+
* userPostPath = "/users/{userId}/posts/{postId}"; // valid
|
|
1424
|
+
* userPostPath = "/posts/{postId}/users/{userId}"; // valid
|
|
1425
|
+
* ```
|
|
1426
|
+
*/
|
|
1427
|
+
type ParamsKeyPath<Params extends Record<string, string>> = ParamsPath<Extract<keyof Params, string>> & string;
|
|
1428
|
+
/**
|
|
1429
|
+
* Represents a path with multiple parameters.
|
|
1430
|
+
* All permutations of the parameters are included in the union type.
|
|
1431
|
+
* The path must have all parameters in the form of `{paramName}`.
|
|
1432
|
+
* @param Params - A union of parameter names.
|
|
1433
|
+
* @returns A string representing the path with all parameters.
|
|
1434
|
+
* @example
|
|
1435
|
+
* ```ts
|
|
1436
|
+
* type UserPostPath = ParamsPath<"userId" | "postId">;
|
|
1437
|
+
* // = `${string}{userId}${string}` & `${string}{postId}${string}`
|
|
1438
|
+
* // =
|
|
1439
|
+
* // | `${string}{userId}${string}{postId}${string}`
|
|
1440
|
+
* // | `${string}{postId}${string}{userId}${string}`
|
|
1441
|
+
* let userPostPath: UserPostPath;
|
|
1442
|
+
* userPostPath = "/users/posts"; // ❌ invalid
|
|
1443
|
+
* userPostPath = "/users/{userId}"; // ❌ invalid
|
|
1444
|
+
* userPostPath = "/posts/{postId}"; // ❌ invalid
|
|
1445
|
+
* userPostPath = "/users/{userId}/posts/{postId}"; // ✅ valid
|
|
1446
|
+
* userPostPath = "/posts/{postId}/users/{userId}"; // ✅ valid
|
|
1447
|
+
*/
|
|
1448
|
+
type ParamsPath<Params extends string> = UnionToIntersection<ParamPath<Params>>;
|
|
1449
|
+
/**
|
|
1450
|
+
* Represents a path with a single parameter.
|
|
1451
|
+
* The path must have at least one of the parameters in the form of `{paramName}`.
|
|
1452
|
+
* @param Param - The name of the parameter.
|
|
1453
|
+
* @returns A string representing the path with the parameter.
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```ts
|
|
1456
|
+
* type UserPostPath = ParamPath<"userId" | "postId">;
|
|
1457
|
+
* // = `${string}{userId}${string}` | `${string}{postId}${string}`
|
|
1458
|
+
* let userPostPath: UserPostPath;
|
|
1459
|
+
* userPostPath = "/users/posts"; // ❌ invalid
|
|
1460
|
+
* userPostPath = "/users/{userId}"; // ✅ valid
|
|
1461
|
+
* userPostPath = "/posts/{postId}"; // ✅ valid
|
|
1462
|
+
* userPostPath = "/users/{userId}/posts/{postId}"; // ✅ valid
|
|
1463
|
+
* userPostPath = "/posts/{postId}/users/{userId}"; // ✅ valid
|
|
1464
|
+
*/
|
|
1465
|
+
type ParamPath<Param extends string> = `${string}{${Param}}${string}`;
|
|
1466
|
+
/**
|
|
1467
|
+
* Converts union types to intersection types.
|
|
1468
|
+
*
|
|
1469
|
+
* @typeParam U - The union type to convert.
|
|
1470
|
+
* @returns The intersection type of the union.
|
|
1471
|
+
* @example
|
|
1472
|
+
* ```ts
|
|
1473
|
+
* type A = { a: string };
|
|
1474
|
+
* type B = { b: number };
|
|
1475
|
+
* type AorB = A | B;
|
|
1476
|
+
* type AandB = UnionToIntersection<AorB>;
|
|
1477
|
+
* // AandB = { a: string; b: number }
|
|
1478
|
+
*/
|
|
1479
|
+
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
1297
1480
|
//#endregion
|
|
1298
1481
|
//#region federation/context.d.ts
|
|
1299
1482
|
/**
|
|
@@ -1648,6 +1831,16 @@ interface Context<TContextData> {
|
|
|
1648
1831
|
* @since 1.3.0
|
|
1649
1832
|
*/
|
|
1650
1833
|
routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
|
|
1834
|
+
/**
|
|
1835
|
+
* Builds the URI of a collection of objects with the given name and values.
|
|
1836
|
+
* @param name The name of the collection, which can be a string or a symbol.
|
|
1837
|
+
* @param values The values of the URI parameters.
|
|
1838
|
+
* @return The URI of the collection.
|
|
1839
|
+
* @throws {RouteError} If no object dispatcher is available for the name.
|
|
1840
|
+
* @throws {TypeError} If values are invalid.
|
|
1841
|
+
* @since 1.8.0
|
|
1842
|
+
*/
|
|
1843
|
+
getCollectionUri<TParam extends Record<string, string>>(name: string | symbol, values: TParam): URL;
|
|
1651
1844
|
}
|
|
1652
1845
|
/**
|
|
1653
1846
|
* A context for a request.
|
|
@@ -1898,6 +2091,26 @@ type ParseUriResult =
|
|
|
1898
2091
|
readonly type: "featuredTags";
|
|
1899
2092
|
readonly identifier: string;
|
|
1900
2093
|
readonly handle: string;
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* The case of a custom collection URI.
|
|
2097
|
+
* @since 1.8.0
|
|
2098
|
+
*/ | {
|
|
2099
|
+
readonly type: "collection";
|
|
2100
|
+
readonly name: string | symbol;
|
|
2101
|
+
readonly class: ConstructorWithTypeId<Object$1>;
|
|
2102
|
+
readonly typeId: URL;
|
|
2103
|
+
readonly values: Record<string, string>;
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* The case of a custom ordered collection URI.
|
|
2107
|
+
* @since 1.8.0
|
|
2108
|
+
*/ | {
|
|
2109
|
+
readonly type: "orderedCollection";
|
|
2110
|
+
readonly name: string | symbol;
|
|
2111
|
+
readonly class: ConstructorWithTypeId<Object$1>;
|
|
2112
|
+
readonly typeId: URL;
|
|
2113
|
+
readonly values: Record<string, string>;
|
|
1901
2114
|
};
|
|
1902
2115
|
/**
|
|
1903
2116
|
* Options for {@link Context.sendActivity} method.
|
|
@@ -2034,4 +2247,4 @@ interface ActorKeyPair extends CryptoKeyPair {
|
|
|
2034
2247
|
multikey: Multikey;
|
|
2035
2248
|
}
|
|
2036
2249
|
//#endregion
|
|
2037
|
-
export { ActivityTransformer, ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, Context, CreateExponentialBackoffPolicyOptions, CreateFederationOptions, Federatable, Federation, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetSignedKeyOptions, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, Message, NodeInfoDispatcher, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxErrorHandler, PageItems, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, respondWithObject, respondWithObjectIfAcceptable };
|
|
2250
|
+
export { ActivityTransformer, ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CreateFederationOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetSignedKeyOptions, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, Message, NodeInfoDispatcher, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxErrorHandler, PageItems, ParamsKeyPath, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, respondWithObject, respondWithObjectIfAcceptable };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { __commonJS, __toESM } from "./type-
|
|
6
|
+
import { __commonJS, __toESM } from "./type-BclCS6EM.js";
|
|
7
7
|
|
|
8
8
|
//#region ../node_modules/.pnpm/glob-to-regexp@0.4.1/node_modules/glob-to-regexp/index.js
|
|
9
9
|
var require_glob_to_regexp = __commonJS({ "../node_modules/.pnpm/glob-to-regexp@0.4.1/node_modules/glob-to-regexp/index.js"(exports, module) {
|
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import { Activity, Note, Person } from "../type-
|
|
6
|
+
import { Activity, Note, Person } from "../type-BclCS6EM.js";
|
|
7
7
|
import { assertEquals } from "../assert_equals-C5gKCm6A.js";
|
|
8
8
|
import "../assert-DwEa6glZ.js";
|
|
9
9
|
import "../assert_instance_of-C9QtN-X9.js";
|
|
10
10
|
import { MemoryKvStore } from "../kv-D7Yt6pnB.js";
|
|
11
11
|
import { parseSemVer } from "../semver-DCqorrj5.js";
|
|
12
|
-
import "../lookup-
|
|
13
|
-
import "../inbox-
|
|
14
|
-
import { createFederationBuilder } from "../builder-
|
|
15
|
-
import { test } from "../testing-
|
|
12
|
+
import "../lookup-Dvnw2uak.js";
|
|
13
|
+
import "../inbox-B-guAC2t.js";
|
|
14
|
+
import { createFederationBuilder } from "../builder-D8tC_vfI.js";
|
|
15
|
+
import { test } from "../testing-CxPA9ooV.js";
|
|
16
16
|
import { assertExists } from "../std__assert-BQdmxyzF.js";
|
|
17
17
|
import "../assert_rejects-AjlKk-Vo.js";
|
|
18
18
|
import "../assert_is_error-CeVBLPsZ.js";
|
|
19
19
|
import "../assert_not_equals-D2R2nl5h.js";
|
|
20
|
-
import "../assert_throws-CqMKbTh_.js";
|
|
20
|
+
import { assertThrows } from "../assert_throws-CqMKbTh_.js";
|
|
21
21
|
|
|
22
22
|
//#region federation/builder.test.ts
|
|
23
23
|
test("FederationBuilder", async (t) => {
|
|
@@ -150,6 +150,25 @@ test("FederationBuilder", async (t) => {
|
|
|
150
150
|
assertEquals(personRoute?.name, `object:${Person.typeId.href}`);
|
|
151
151
|
assertEquals(personRoute?.values.id, "abc");
|
|
152
152
|
});
|
|
153
|
+
await t.step("should handle symbol names uniquely in custom collection dispatchers", () => {
|
|
154
|
+
const builder = createFederationBuilder();
|
|
155
|
+
const unnamedSymbol1 = Symbol();
|
|
156
|
+
const unnamedSymbol2 = Symbol();
|
|
157
|
+
const namedSymbol1 = Symbol.for("");
|
|
158
|
+
const namedSymbol2 = Symbol.for("");
|
|
159
|
+
const strId = String(unnamedSymbol1);
|
|
160
|
+
const dispatcher = (_ctx, _params) => ({ items: [] });
|
|
161
|
+
builder.setCollectionDispatcher(unnamedSymbol1, Note, "/unnamed-symbol1/{id}", dispatcher);
|
|
162
|
+
assertThrows(() => {
|
|
163
|
+
builder.setCollectionDispatcher(unnamedSymbol1, Note, "/unnamed-symbol1-duplicate/{id}", dispatcher);
|
|
164
|
+
}, Error, "Collection dispatcher for Symbol() already set.");
|
|
165
|
+
builder.setCollectionDispatcher(unnamedSymbol2, Note, "/unnamed-symbol2/{id}", dispatcher);
|
|
166
|
+
builder.setCollectionDispatcher(namedSymbol1, Note, "/named-symbol/{id}", dispatcher);
|
|
167
|
+
assertThrows(() => {
|
|
168
|
+
builder.setCollectionDispatcher(namedSymbol2, Note, "/named-symbol/{id}", dispatcher);
|
|
169
|
+
});
|
|
170
|
+
builder.setCollectionDispatcher(strId, Note, "/string-id/{id}", dispatcher);
|
|
171
|
+
});
|
|
153
172
|
});
|
|
154
173
|
|
|
155
174
|
//#endregion
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
|
4
4
|
globalThis.addEventListener = () => {};
|
|
5
5
|
|
|
6
|
-
import "../type-
|
|
6
|
+
import "../type-BclCS6EM.js";
|
|
7
7
|
import { assertEquals } from "../assert_equals-C5gKCm6A.js";
|
|
8
8
|
import "../assert-DwEa6glZ.js";
|
|
9
9
|
import "../assert_instance_of-C9QtN-X9.js";
|
|
10
|
-
import "../lookup-
|
|
10
|
+
import "../lookup-Dvnw2uak.js";
|
|
11
11
|
import { buildCollectionSynchronizationHeader, digest } from "../collection-D5V3UzU3.js";
|
|
12
|
-
import { test } from "../testing-
|
|
12
|
+
import { test } from "../testing-CxPA9ooV.js";
|
|
13
13
|
import "../std__assert-BQdmxyzF.js";
|
|
14
14
|
import "../assert_rejects-AjlKk-Vo.js";
|
|
15
15
|
import "../assert_is_error-CeVBLPsZ.js";
|