@fedify/vocab 2.1.0 → 2.1.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.
@@ -1,11 +1,9 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- globalThis.addEventListener = () => {};
4
-
5
- import { Collection, Note, Object as Object$1, Person } from "./vocab-dV6QKnk_.js";
6
- import { deno_default, esm_default } from "./deno-zAg2jvCV.js";
7
- import { getTypeId } from "./type-CNuABalk.js";
8
- import { assertInstanceOf } from "./utils-BSWXlrig.js";
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ globalThis.addEventListener = () => {};
3
+ import { f as Note, g as Person, i as Collection, p as Object$1 } from "./vocab-uS-D0TBY.mjs";
4
+ import { n as version, r as esm_default, t as name } from "./deno-Cb1qyeNy.mjs";
5
+ import { t as getTypeId } from "./type-Cf-vxmre.mjs";
6
+ import { t as assertInstanceOf } from "./utils-CE8Dk5hm.mjs";
9
7
  import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
10
8
  import { deepStrictEqual, equal, ok, rejects } from "node:assert/strict";
11
9
  import { lookupWebFinger } from "@fedify/webfinger";
@@ -13,7 +11,6 @@ import { SpanStatusCode, trace } from "@opentelemetry/api";
13
11
  import { getLogger } from "@logtape/logtape";
14
12
  import { getDocumentLoader } from "@fedify/vocab-runtime";
15
13
  import { delay } from "es-toolkit";
16
-
17
14
  //#region src/handle.ts
18
15
  /**
19
16
  * Regular expression to match a fediverse handle in the format `@user@server`
@@ -66,10 +63,8 @@ function parseFediverseHandle(handle) {
66
63
  function toAcctUrl(handle) {
67
64
  const parsed = parseFediverseHandle(handle);
68
65
  if (!parsed) return null;
69
- const identifier = new URL(`acct:${parsed.username}@${parsed.host}`);
70
- return identifier;
66
+ return new URL(`acct:${parsed.username}@${parsed.host}`);
71
67
  }
72
-
73
68
  //#endregion
74
69
  //#region src/lookup.ts
75
70
  const logger = getLogger([
@@ -110,9 +105,7 @@ const logger = getLogger([
110
105
  * @since 0.2.0
111
106
  */
112
107
  async function lookupObject(identifier, options = {}) {
113
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
114
- const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
115
- return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => {
108
+ return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("activitypub.lookup_object", async (span) => {
116
109
  try {
117
110
  const result = await lookupObjectInternal(identifier, options);
118
111
  if (result == null) span.setStatus({ code: SpanStatusCode.ERROR });
@@ -225,7 +218,6 @@ async function* traverseCollection(collection, options = {}) {
225
218
  page = await page.getNext(options);
226
219
  }
227
220
  }
228
-
229
221
  //#endregion
230
222
  //#region src/lookup.test.ts
231
223
  test("lookupObject()", {
@@ -262,10 +254,8 @@ test("lookupObject()", {
262
254
  assertInstanceOf(person, Person);
263
255
  deepStrictEqual(person.id, new URL("https://example.com/person"));
264
256
  equal(person.name, "John Doe");
265
- const person2 = await lookupObject("johndoe@example.com", options);
266
- deepStrictEqual(person2, person);
267
- const person3 = await lookupObject("acct:johndoe@example.com", options);
268
- deepStrictEqual(person3, person);
257
+ deepStrictEqual(await lookupObject("johndoe@example.com", options), person);
258
+ deepStrictEqual(await lookupObject("acct:johndoe@example.com", options), person);
269
259
  });
270
260
  await t.step("object", async () => {
271
261
  const object = await lookupObject("https://example.com/object", options);
@@ -350,11 +340,10 @@ test("lookupObject()", {
350
340
  await t.step("cancellation with immediate abort", async () => {
351
341
  const controller = new AbortController();
352
342
  controller.abort();
353
- const result = await lookupObject("johndoe@example.com", {
343
+ deepStrictEqual(await lookupObject("johndoe@example.com", {
354
344
  ...options,
355
345
  signal: controller.signal
356
- });
357
- deepStrictEqual(result, null);
346
+ }), null);
358
347
  });
359
348
  esm_default.removeRoutes();
360
349
  esm_default.get("https://example.com/slow-object", () => new Promise((resolve) => {
@@ -434,11 +423,10 @@ test("FEP-fe34: lookupObject() cross-origin security", {
434
423
  };
435
424
  throw new Error(`Unexpected URL: ${url}`);
436
425
  };
437
- const result = await lookupObject("https://example.com/note", {
426
+ deepStrictEqual(await lookupObject("https://example.com/note", {
438
427
  documentLoader: crossOriginDocumentLoader,
439
428
  contextLoader: mockDocumentLoader
440
- });
441
- deepStrictEqual(result, null);
429
+ }), null);
442
430
  });
443
431
  await t.step("crossOrigin: throw - throws error for cross-origin objects", async () => {
444
432
  const crossOriginDocumentLoader = async (url) => {
@@ -549,11 +537,10 @@ test("FEP-fe34: lookupObject() cross-origin security", {
549
537
  };
550
538
  throw new Error(`Unexpected URL: ${url}`);
551
539
  };
552
- const result1 = await lookupObject("@user@example.com", {
540
+ deepStrictEqual(await lookupObject("@user@example.com", {
553
541
  documentLoader: webfingerDocumentLoader,
554
542
  contextLoader: mockDocumentLoader
555
- });
556
- deepStrictEqual(result1, null);
543
+ }), null);
557
544
  await rejects(() => lookupObject("@user@example.com", {
558
545
  documentLoader: webfingerDocumentLoader,
559
546
  contextLoader: mockDocumentLoader,
@@ -583,11 +570,10 @@ test("FEP-fe34: lookupObject() cross-origin security", {
583
570
  };
584
571
  throw new Error(`Unexpected URL: ${url}`);
585
572
  };
586
- const result = await lookupObject("https://api.example.com/note", {
573
+ deepStrictEqual(await lookupObject("https://api.example.com/note", {
587
574
  documentLoader: subdomainDocumentLoader,
588
575
  contextLoader: mockDocumentLoader
589
- });
590
- deepStrictEqual(result, null);
576
+ }), null);
591
577
  });
592
578
  await t.step("different port same-origin check", async () => {
593
579
  const differentPortDocumentLoader = async (url) => {
@@ -603,11 +589,10 @@ test("FEP-fe34: lookupObject() cross-origin security", {
603
589
  };
604
590
  throw new Error(`Unexpected URL: ${url}`);
605
591
  };
606
- const result = await lookupObject("https://example.com:8080/note", {
592
+ deepStrictEqual(await lookupObject("https://example.com:8080/note", {
607
593
  documentLoader: differentPortDocumentLoader,
608
594
  contextLoader: mockDocumentLoader
609
- });
610
- deepStrictEqual(result, null);
595
+ }), null);
611
596
  });
612
597
  await t.step("protocol difference same-origin check", async () => {
613
598
  const differentProtocolDocumentLoader = async (url) => {
@@ -623,22 +608,20 @@ test("FEP-fe34: lookupObject() cross-origin security", {
623
608
  };
624
609
  throw new Error(`Unexpected URL: ${url}`);
625
610
  };
626
- const result = await lookupObject("https://example.com/note", {
611
+ deepStrictEqual(await lookupObject("https://example.com/note", {
627
612
  documentLoader: differentProtocolDocumentLoader,
628
613
  contextLoader: mockDocumentLoader
629
- });
630
- deepStrictEqual(result, null);
614
+ }), null);
631
615
  });
632
616
  await t.step("error handling with crossOrigin throw option", async () => {
633
617
  const errorDocumentLoader = async (_url) => {
634
618
  throw new Error("Network error");
635
619
  };
636
- const result = await lookupObject("https://example.com/note", {
620
+ deepStrictEqual(await lookupObject("https://example.com/note", {
637
621
  documentLoader: errorDocumentLoader,
638
622
  contextLoader: mockDocumentLoader,
639
623
  crossOrigin: "throw"
640
- });
641
- deepStrictEqual(result, null);
624
+ }), null);
642
625
  });
643
626
  await t.step("malformed JSON handling with cross-origin policy", async () => {
644
627
  const malformedJsonDocumentLoader = async (url) => {
@@ -668,12 +651,11 @@ test("FEP-fe34: lookupObject() cross-origin security", {
668
651
  });
669
652
  test("lookupObject() records OpenTelemetry span events", async () => {
670
653
  const [tracerProvider, exporter] = createTestTracerProvider();
671
- const object = await lookupObject("https://example.com/object", {
654
+ assertInstanceOf(await lookupObject("https://example.com/object", {
672
655
  documentLoader: mockDocumentLoader,
673
656
  contextLoader: mockDocumentLoader,
674
657
  tracerProvider
675
- });
676
- assertInstanceOf(object, Object$1);
658
+ }), Object$1);
677
659
  const spans = exporter.getSpans("activitypub.lookup_object");
678
660
  deepStrictEqual(spans.length, 1);
679
661
  const span = spans[0];
@@ -684,8 +666,7 @@ test("lookupObject() records OpenTelemetry span events", async () => {
684
666
  ok(event.attributes != null);
685
667
  ok(typeof event.attributes["activitypub.object.type"] === "string");
686
668
  ok(typeof event.attributes["activitypub.object.json"] === "string");
687
- const recordedObject = JSON.parse(event.attributes["activitypub.object.json"]);
688
- deepStrictEqual(recordedObject.id, "https://example.com/object");
669
+ deepStrictEqual(JSON.parse(event.attributes["activitypub.object.json"]).id, "https://example.com/object");
689
670
  });
690
-
691
- //#endregion
671
+ //#endregion
672
+ export {};
@@ -0,0 +1,9 @@
1
+ import "@js-temporal/polyfill";
2
+ globalThis.addEventListener = () => {};
3
+ //#region src/type.ts
4
+ function getTypeId(object) {
5
+ if (object == null) return object;
6
+ return object.constructor.typeId;
7
+ }
8
+ //#endregion
9
+ export { getTypeId as t };
@@ -0,0 +1,16 @@
1
+ import "@js-temporal/polyfill";
2
+ globalThis.addEventListener = () => {};
3
+ import { g as Person } from "./vocab-uS-D0TBY.mjs";
4
+ import { t as getTypeId } from "./type-Cf-vxmre.mjs";
5
+ import { test } from "@fedify/fixture";
6
+ import { deepStrictEqual } from "node:assert/strict";
7
+ //#region src/type.test.ts
8
+ test("getTypeId()", () => {
9
+ deepStrictEqual(getTypeId(new Person({})), new URL("https://www.w3.org/ns/activitystreams#Person"));
10
+ deepStrictEqual(getTypeId(null), null);
11
+ deepStrictEqual(getTypeId(void 0), void 0);
12
+ deepStrictEqual(getTypeId(null), null);
13
+ deepStrictEqual(getTypeId(void 0), void 0);
14
+ });
15
+ //#endregion
16
+ export {};
@@ -1,13 +1,9 @@
1
-
2
- import { Temporal } from "@js-temporal/polyfill";
3
- globalThis.addEventListener = () => {};
4
-
1
+ import "@js-temporal/polyfill";
2
+ globalThis.addEventListener = () => {};
5
3
  import { ok } from "node:assert";
6
-
7
4
  //#region src/utils.ts
8
5
  function assertInstanceOf(value, constructor) {
9
6
  ok(value instanceof constructor);
10
7
  }
11
-
12
8
  //#endregion
13
- export { assertInstanceOf };
9
+ export { assertInstanceOf as t };