@fedify/testing 2.4.0-dev.2099 → 2.4.0-dev.2108

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
@@ -39,7 +39,7 @@ const noopMeterProvider$1 = { getMeter: () => ({
39
39
  removeBatchObservableCallback: () => void 0
40
40
  }) };
41
41
  function createContext(values) {
42
- const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getPortableObjectUri, getPortableInboxUri, getCollectionUri, getOutboxUri, getMediaUploaderUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject, traverseCollection, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity, enqueueTask, enqueueTaskMany } = values;
42
+ const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getPortableActorUri, getObjectUri, getPortableObjectUri, getPortableInboxUri, getCollectionUri, getOutboxUri, getMediaUploaderUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject, traverseCollection, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity, enqueueTask, enqueueTaskMany } = values;
43
43
  function throwRouterError() {
44
44
  throw new _fedify_fedify_federation.RouterError("Not implemented");
45
45
  }
@@ -60,6 +60,7 @@ function createContext(values) {
60
60
  })),
61
61
  getNodeInfoUri: getNodeInfoUri ?? throwRouterError,
62
62
  getActorUri: getActorUri ?? throwRouterError,
63
+ getPortableActorUri: getPortableActorUri ?? throwRouterError,
63
64
  getObjectUri: getObjectUri ?? throwRouterError,
64
65
  getPortableObjectUri: getPortableObjectUri ?? throwRouterError,
65
66
  getPortableInboxUri: getPortableInboxUri ?? throwRouterError,
@@ -230,6 +231,16 @@ function expandUriTemplate(template, values) {
230
231
  }
231
232
  });
232
233
  }
234
+ /**
235
+ * Builds an FEP-ef61 portable ID from a DID authority and a path, validating
236
+ * the authority the same way as `@fedify/fedify` does.
237
+ */
238
+ function buildPortableUri(authority, path) {
239
+ if (typeof authority !== "string" || !/^did:[a-z0-9]+:[^/?#]+$/i.test(authority)) throw new TypeError("The authority of a portable ID must be a DID without a path, query, or fragment.");
240
+ const did = (0, _fedify_vocab_runtime.getFe34Origin)(authority);
241
+ if (did.startsWith("did:key:") && !/^z[1-9A-HJ-NP-Za-km-z]+$/.test(did.slice(8))) throw new TypeError("The did:key authority of a portable ID must be encoded in base58-btc, i.e., start with z.");
242
+ return (0, _fedify_vocab_runtime.parseIri)(`ap+ef61://${did}${path}`);
243
+ }
233
244
  function validateOutboxListenerPath(path, dispatcherPath) {
234
245
  if (!path.startsWith("/")) throw new TypeError("Path must start with a slash.");
235
246
  if (dispatcherPath != null && dispatcherPath !== path) throw new TypeError("Outbox listener path and outbox dispatcher path must match.");
@@ -768,12 +779,16 @@ var MockContext = class MockContext {
768
779
  }
769
780
  return null;
770
781
  }
771
- async getObject(cls, values) {
782
+ async getObject(cls, values, options) {
772
783
  if (this.federation instanceof MockFederation) {
773
784
  const path = this.federation.objectPaths.get(cls.typeId.href);
774
785
  if (path) {
775
786
  const dispatcher = this.federation.objectDispatchers.get(path);
776
- if (dispatcher) return await dispatcher(this, values);
787
+ if (dispatcher) {
788
+ const object = await dispatcher(this, values);
789
+ if (object instanceof _fedify_vocab.Tombstone && !(object instanceof cls) && options?.tombstone !== "passthrough") return null;
790
+ return object;
791
+ }
777
792
  }
778
793
  }
779
794
  return null;
@@ -837,15 +852,17 @@ var MockContext = class MockContext {
837
852
  const path = globalThis.Object.entries(values).map(([key, value]) => `${key}/${value}`).join("/");
838
853
  return new URL(`/objects/${cls.name.toLowerCase()}/${path}`, this.origin);
839
854
  }
855
+ getPortableActorUri(identifier, authority) {
856
+ const { pathname } = this.getActorUri(identifier);
857
+ return buildPortableUri(authority, pathname);
858
+ }
840
859
  getPortableObjectUri(cls, values, authority) {
841
- if (!/^did:[a-z0-9]+:[^/?#]+$/i.test(authority)) throw new TypeError("The authority of a portable ID must be a DID without a path, query, or fragment.");
842
860
  const { pathname } = this.getObjectUri(cls, values);
843
- return (0, _fedify_vocab_runtime.parseIri)(`ap+ef61://${authority}${pathname}`);
861
+ return buildPortableUri(authority, pathname);
844
862
  }
845
863
  getPortableInboxUri(identifier, authority) {
846
- if (!/^did:[a-z0-9]+:[^/?#]+$/i.test(authority)) throw new TypeError("The authority of a portable ID must be a DID without a path, query, or fragment.");
847
864
  const { pathname } = this.getInboxUri(identifier);
848
- return (0, _fedify_vocab_runtime.parseIri)(`ap+ef61://${authority}${pathname}`);
865
+ return buildPortableUri(authority, pathname);
849
866
  }
850
867
  getOutboxUri(identifier) {
851
868
  if (this.federation instanceof MockFederation && this.federation.outboxPath) {
package/dist/mod.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { hasProofLike, hasSignatureLike } from "@fedify/fedify/sig";
3
- import { Activity, CryptographicKey, Multikey, lookupObject, traverseCollection } from "@fedify/vocab";
4
- import { parseIri } from "@fedify/vocab-runtime";
3
+ import { Activity, CryptographicKey, Multikey, Tombstone, lookupObject, traverseCollection } from "@fedify/vocab";
4
+ import { getFe34Origin, parseIri } from "@fedify/vocab-runtime";
5
5
  import { RouterError } from "@fedify/fedify/federation";
6
6
  import { delay } from "es-toolkit";
7
7
  import { deepStrictEqual, ok, strictEqual } from "node:assert/strict";
@@ -38,7 +38,7 @@ const noopMeterProvider$1 = { getMeter: () => ({
38
38
  removeBatchObservableCallback: () => void 0
39
39
  }) };
40
40
  function createContext(values) {
41
- const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getPortableObjectUri, getPortableInboxUri, getCollectionUri, getOutboxUri, getMediaUploaderUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject: lookupObject$1, traverseCollection: traverseCollection$1, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity, enqueueTask, enqueueTaskMany } = values;
41
+ const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getPortableActorUri, getObjectUri, getPortableObjectUri, getPortableInboxUri, getCollectionUri, getOutboxUri, getMediaUploaderUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject: lookupObject$1, traverseCollection: traverseCollection$1, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity, enqueueTask, enqueueTaskMany } = values;
42
42
  function throwRouterError() {
43
43
  throw new RouterError("Not implemented");
44
44
  }
@@ -59,6 +59,7 @@ function createContext(values) {
59
59
  })),
60
60
  getNodeInfoUri: getNodeInfoUri ?? throwRouterError,
61
61
  getActorUri: getActorUri ?? throwRouterError,
62
+ getPortableActorUri: getPortableActorUri ?? throwRouterError,
62
63
  getObjectUri: getObjectUri ?? throwRouterError,
63
64
  getPortableObjectUri: getPortableObjectUri ?? throwRouterError,
64
65
  getPortableInboxUri: getPortableInboxUri ?? throwRouterError,
@@ -229,6 +230,16 @@ function expandUriTemplate(template, values) {
229
230
  }
230
231
  });
231
232
  }
233
+ /**
234
+ * Builds an FEP-ef61 portable ID from a DID authority and a path, validating
235
+ * the authority the same way as `@fedify/fedify` does.
236
+ */
237
+ function buildPortableUri(authority, path) {
238
+ if (typeof authority !== "string" || !/^did:[a-z0-9]+:[^/?#]+$/i.test(authority)) throw new TypeError("The authority of a portable ID must be a DID without a path, query, or fragment.");
239
+ const did = getFe34Origin(authority);
240
+ if (did.startsWith("did:key:") && !/^z[1-9A-HJ-NP-Za-km-z]+$/.test(did.slice(8))) throw new TypeError("The did:key authority of a portable ID must be encoded in base58-btc, i.e., start with z.");
241
+ return parseIri(`ap+ef61://${did}${path}`);
242
+ }
232
243
  function validateOutboxListenerPath(path, dispatcherPath) {
233
244
  if (!path.startsWith("/")) throw new TypeError("Path must start with a slash.");
234
245
  if (dispatcherPath != null && dispatcherPath !== path) throw new TypeError("Outbox listener path and outbox dispatcher path must match.");
@@ -767,12 +778,16 @@ var MockContext = class MockContext {
767
778
  }
768
779
  return null;
769
780
  }
770
- async getObject(cls, values) {
781
+ async getObject(cls, values, options) {
771
782
  if (this.federation instanceof MockFederation) {
772
783
  const path = this.federation.objectPaths.get(cls.typeId.href);
773
784
  if (path) {
774
785
  const dispatcher = this.federation.objectDispatchers.get(path);
775
- if (dispatcher) return await dispatcher(this, values);
786
+ if (dispatcher) {
787
+ const object = await dispatcher(this, values);
788
+ if (object instanceof Tombstone && !(object instanceof cls) && options?.tombstone !== "passthrough") return null;
789
+ return object;
790
+ }
776
791
  }
777
792
  }
778
793
  return null;
@@ -836,15 +851,17 @@ var MockContext = class MockContext {
836
851
  const path = globalThis.Object.entries(values).map(([key, value]) => `${key}/${value}`).join("/");
837
852
  return new URL(`/objects/${cls.name.toLowerCase()}/${path}`, this.origin);
838
853
  }
854
+ getPortableActorUri(identifier, authority) {
855
+ const { pathname } = this.getActorUri(identifier);
856
+ return buildPortableUri(authority, pathname);
857
+ }
839
858
  getPortableObjectUri(cls, values, authority) {
840
- if (!/^did:[a-z0-9]+:[^/?#]+$/i.test(authority)) throw new TypeError("The authority of a portable ID must be a DID without a path, query, or fragment.");
841
859
  const { pathname } = this.getObjectUri(cls, values);
842
- return parseIri(`ap+ef61://${authority}${pathname}`);
860
+ return buildPortableUri(authority, pathname);
843
861
  }
844
862
  getPortableInboxUri(identifier, authority) {
845
- if (!/^did:[a-z0-9]+:[^/?#]+$/i.test(authority)) throw new TypeError("The authority of a portable ID must be a DID without a path, query, or fragment.");
846
863
  const { pathname } = this.getInboxUri(identifier);
847
- return parseIri(`ap+ef61://${authority}${pathname}`);
864
+ return buildPortableUri(authority, pathname);
848
865
  }
849
866
  getOutboxUri(identifier) {
850
867
  if (this.federation instanceof MockFederation && this.federation.outboxPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/testing",
3
- "version": "2.4.0-dev.2099+cd074fe2",
3
+ "version": "2.4.0-dev.2108+159ea471",
4
4
  "description": "Testing utilities for Fedify applications",
5
5
  "keywords": [
6
6
  "fedify",
@@ -47,13 +47,13 @@
47
47
  "package.json"
48
48
  ],
49
49
  "peerDependencies": {
50
- "@fedify/fedify": "^2.4.0-dev.2099+cd074fe2"
50
+ "@fedify/fedify": "^2.4.0-dev.2108+159ea471"
51
51
  },
52
52
  "dependencies": {
53
53
  "es-toolkit": "1.46.1",
54
54
  "temporal-polyfill": "^1.0.1",
55
- "@fedify/vocab": "2.4.0-dev.2099+cd074fe2",
56
- "@fedify/vocab-runtime": "^2.4.0-dev.2099+cd074fe2"
55
+ "@fedify/vocab": "2.4.0-dev.2108+159ea471",
56
+ "@fedify/vocab-runtime": "^2.4.0-dev.2108+159ea471"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@standard-schema/spec": "^1.1.0",