@fedify/testing 1.10.0 → 1.10.2

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/mod.cjs CHANGED
@@ -21,8 +21,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
- const __fedify_fedify_federation = __toESM(require("@fedify/fedify/federation"));
25
24
  const __fedify_fedify_vocab = __toESM(require("@fedify/fedify/vocab"));
25
+ const __fedify_fedify_federation = __toESM(require("@fedify/fedify/federation"));
26
26
 
27
27
  //#region src/docloader.ts
28
28
  const mockDocumentLoader = async (url) => ({
@@ -205,6 +205,7 @@ var MockFederation = class {
205
205
  nodeInfoDispatcher;
206
206
  webFingerDispatcher;
207
207
  actorDispatchers = /* @__PURE__ */ new Map();
208
+ actorKeyPairsDispatcher;
208
209
  actorPath;
209
210
  inboxPath;
210
211
  outboxPath;
@@ -242,7 +243,10 @@ var MockFederation = class {
242
243
  this.actorDispatchers.set(path, dispatcher);
243
244
  this.actorPath = path;
244
245
  return {
245
- setKeyPairsDispatcher: () => this,
246
+ setKeyPairsDispatcher: (keyPairsDispatcher) => {
247
+ this.actorKeyPairsDispatcher = keyPairsDispatcher;
248
+ return this;
249
+ },
246
250
  mapHandle: () => this,
247
251
  mapAlias: () => this,
248
252
  authorize: () => this
@@ -531,11 +535,22 @@ var MockContext = class MockContext {
531
535
  this.contextLoader = options.contextLoader ?? this.documentLoader;
532
536
  this.tracerProvider = options.tracerProvider ?? noopTracerProvider;
533
537
  }
534
- getActor(_handle) {
535
- return Promise.resolve(null);
538
+ async getActor(handle) {
539
+ if (this.federation instanceof MockFederation && this.federation.actorPath) {
540
+ const dispatcher = this.federation.actorDispatchers.get(this.federation.actorPath);
541
+ if (dispatcher) return await dispatcher(this, handle);
542
+ }
543
+ return null;
536
544
  }
537
- getObject(_cls, _values) {
538
- return Promise.resolve(null);
545
+ async getObject(cls, values) {
546
+ if (this.federation instanceof MockFederation) {
547
+ const path = this.federation.objectPaths.get(cls.typeId.href);
548
+ if (path) {
549
+ const dispatcher = this.federation.objectDispatchers.get(path);
550
+ if (dispatcher) return await dispatcher(this, values);
551
+ }
552
+ }
553
+ return null;
539
554
  }
540
555
  getSignedKey() {
541
556
  return Promise.resolve(null);
@@ -667,8 +682,25 @@ var MockContext = class MockContext {
667
682
  }
668
683
  return null;
669
684
  }
670
- getActorKeyPairs(_identifier) {
671
- return Promise.resolve([]);
685
+ async getActorKeyPairs(identifier) {
686
+ if (this.federation instanceof MockFederation && this.federation.actorKeyPairsDispatcher) {
687
+ const keyPairs = await this.federation.actorKeyPairsDispatcher(this, identifier);
688
+ const owner = this.getActorUri(identifier);
689
+ return keyPairs.map((kp) => ({
690
+ ...kp,
691
+ cryptographicKey: new __fedify_fedify_vocab.CryptographicKey({
692
+ id: kp.keyId,
693
+ owner,
694
+ publicKey: kp.publicKey
695
+ }),
696
+ multikey: new __fedify_fedify_vocab.Multikey({
697
+ id: kp.keyId,
698
+ controller: owner,
699
+ publicKey: kp.publicKey
700
+ })
701
+ }));
702
+ }
703
+ return [];
672
704
  }
673
705
  getDocumentLoader(params) {
674
706
  if ("keyId" in params) return this.documentLoader;
package/dist/mod.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Context, Federation, InboxContext, RequestContext } from "@fedify/fedify/federation";
2
1
  import { Activity } from "@fedify/fedify/vocab";
2
+ import { Context, Federation, InboxContext, RequestContext } from "@fedify/fedify/federation";
3
3
 
4
4
  //#region src/context.d.ts
5
5
  declare function createContext<TContextData>(values: Partial<Context<TContextData>> & {
package/dist/mod.js CHANGED
@@ -1,5 +1,5 @@
1
+ import { CryptographicKey, Multikey, lookupObject, traverseCollection } from "@fedify/fedify/vocab";
1
2
  import { RouterError } from "@fedify/fedify/federation";
2
- import { lookupObject, traverseCollection } from "@fedify/fedify/vocab";
3
3
 
4
4
  //#region src/docloader.ts
5
5
  const mockDocumentLoader = async (url) => ({
@@ -182,6 +182,7 @@ var MockFederation = class {
182
182
  nodeInfoDispatcher;
183
183
  webFingerDispatcher;
184
184
  actorDispatchers = /* @__PURE__ */ new Map();
185
+ actorKeyPairsDispatcher;
185
186
  actorPath;
186
187
  inboxPath;
187
188
  outboxPath;
@@ -219,7 +220,10 @@ var MockFederation = class {
219
220
  this.actorDispatchers.set(path, dispatcher);
220
221
  this.actorPath = path;
221
222
  return {
222
- setKeyPairsDispatcher: () => this,
223
+ setKeyPairsDispatcher: (keyPairsDispatcher) => {
224
+ this.actorKeyPairsDispatcher = keyPairsDispatcher;
225
+ return this;
226
+ },
223
227
  mapHandle: () => this,
224
228
  mapAlias: () => this,
225
229
  authorize: () => this
@@ -508,11 +512,22 @@ var MockContext = class MockContext {
508
512
  this.contextLoader = options.contextLoader ?? this.documentLoader;
509
513
  this.tracerProvider = options.tracerProvider ?? noopTracerProvider;
510
514
  }
511
- getActor(_handle) {
512
- return Promise.resolve(null);
515
+ async getActor(handle) {
516
+ if (this.federation instanceof MockFederation && this.federation.actorPath) {
517
+ const dispatcher = this.federation.actorDispatchers.get(this.federation.actorPath);
518
+ if (dispatcher) return await dispatcher(this, handle);
519
+ }
520
+ return null;
513
521
  }
514
- getObject(_cls, _values) {
515
- return Promise.resolve(null);
522
+ async getObject(cls, values) {
523
+ if (this.federation instanceof MockFederation) {
524
+ const path = this.federation.objectPaths.get(cls.typeId.href);
525
+ if (path) {
526
+ const dispatcher = this.federation.objectDispatchers.get(path);
527
+ if (dispatcher) return await dispatcher(this, values);
528
+ }
529
+ }
530
+ return null;
516
531
  }
517
532
  getSignedKey() {
518
533
  return Promise.resolve(null);
@@ -644,8 +659,25 @@ var MockContext = class MockContext {
644
659
  }
645
660
  return null;
646
661
  }
647
- getActorKeyPairs(_identifier) {
648
- return Promise.resolve([]);
662
+ async getActorKeyPairs(identifier) {
663
+ if (this.federation instanceof MockFederation && this.federation.actorKeyPairsDispatcher) {
664
+ const keyPairs = await this.federation.actorKeyPairsDispatcher(this, identifier);
665
+ const owner = this.getActorUri(identifier);
666
+ return keyPairs.map((kp) => ({
667
+ ...kp,
668
+ cryptographicKey: new CryptographicKey({
669
+ id: kp.keyId,
670
+ owner,
671
+ publicKey: kp.publicKey
672
+ }),
673
+ multikey: new Multikey({
674
+ id: kp.keyId,
675
+ controller: owner,
676
+ publicKey: kp.publicKey
677
+ })
678
+ }));
679
+ }
680
+ return [];
649
681
  }
650
682
  getDocumentLoader(params) {
651
683
  if ("keyId" in params) return this.documentLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/testing",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "description": "Testing utilities for Fedify applications",
5
5
  "keywords": [
6
6
  "fedify",
@@ -50,7 +50,7 @@
50
50
  "package.json"
51
51
  ],
52
52
  "peerDependencies": {
53
- "@fedify/fedify": "^1.10.0"
53
+ "@fedify/fedify": "^1.10.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@js-temporal/polyfill": "^0.5.1",