@fedify/vocab 2.0.35 → 2.0.36-dev.2551

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,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  globalThis.addEventListener = () => {};
3
- import { S as vocab_exports, _ as Place, a as Collection, c as Follow, d as Link, f as Note, g as Person, m as OrderedCollectionPage, n as Activity, o as Create, p as Object$1, r as Announce, s as CryptographicKey, t as Accept, u as Hashtag, v as PropertyValue, x as Source, y as Question } from "./vocab-4POt9BSw.mjs";
3
+ import { S as vocab_exports, _ as Place, a as Collection, c as Follow, d as Link, f as Note, g as Person, m as OrderedCollectionPage, n as Activity, o as Create, p as Object$1, r as Announce, s as CryptographicKey, t as Accept, u as Hashtag, v as PropertyValue, x as Source, y as Question } from "./vocab-ZYaaH8Qo.mjs";
4
4
  import { t as assertInstanceOf } from "./utils-CE8Dk5hm.mjs";
5
5
  import { mockDocumentLoader, test } from "@fedify/fixture";
6
6
  import { deepStrictEqual, notDeepStrictEqual, ok, rejects, strictEqual, throws } from "node:assert/strict";
@@ -1681,5 +1681,49 @@ for (const typeUri in types) {
1681
1681
  deepStrictEqual(cls.typeId, new URL(type.uri));
1682
1682
  });
1683
1683
  }
1684
+ test("Note.fromJsonLd() accepts date-times without seconds", async () => {
1685
+ for (const [published, expected] of [
1686
+ ["2024-01-01T10:00Z", "2024-01-01T10:00:00Z"],
1687
+ ["2024-01-01T10:00+09:00", "2024-01-01T01:00:00Z"],
1688
+ ["2024-01-01T10:00-05:00", "2024-01-01T15:00:00Z"],
1689
+ ["2024-01-01T10:00", "2024-01-01T10:00:00Z"],
1690
+ ["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"],
1691
+ ["2024-01-01T10:00.5+09:00", "2024-01-01T01:00:00.5Z"],
1692
+ ["2024-01-01T10:00.5-05:00", "2024-01-01T15:00:00.5Z"],
1693
+ ["2024-01-01T10:00.5", "2024-01-01T10:00:00.5Z"]
1694
+ ]) strictEqual((await Note.fromJsonLd({
1695
+ "@context": "https://www.w3.org/ns/activitystreams",
1696
+ type: "Note",
1697
+ published
1698
+ }, {
1699
+ documentLoader: mockDocumentLoader,
1700
+ contextLoader: mockDocumentLoader
1701
+ })).published?.toString(), Temporal.Instant.from(expected).toString());
1702
+ });
1703
+ test("Question.fromJsonLd() decodes closed values without seconds", async () => {
1704
+ const parse = (closed) => Question.fromJsonLd({
1705
+ "@context": "https://www.w3.org/ns/activitystreams",
1706
+ type: "Question",
1707
+ closed
1708
+ }, {
1709
+ documentLoader: mockDocumentLoader,
1710
+ contextLoader: mockDocumentLoader
1711
+ });
1712
+ for (const [closed, expected] of [["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"], ["2024-01-01T10:00.5+09:00", "2024-01-01T01:00:00.5Z"]]) strictEqual((await parse(closed)).closed?.toString(), Temporal.Instant.from(expected).toString());
1713
+ await rejects(() => parse("2024-02-31T10:00.5Z"), RangeError);
1714
+ await rejects(() => parse("Sat, 01 Jan 2024 10:00:00 GMT"), RangeError);
1715
+ strictEqual((await parse(true)).closed, true);
1716
+ strictEqual((await parse("not a date")).closed, null);
1717
+ });
1718
+ test("Note.fromJsonLd() rejects date-times that Temporal cannot parse", async () => {
1719
+ await rejects(() => Note.fromJsonLd({
1720
+ "@context": "https://www.w3.org/ns/activitystreams",
1721
+ type: "Note",
1722
+ published: "Sat, 01 Jan 2024 10:00:00 GMT"
1723
+ }, {
1724
+ documentLoader: mockDocumentLoader,
1725
+ contextLoader: mockDocumentLoader
1726
+ }), RangeError);
1727
+ });
1684
1728
  //#endregion
1685
1729
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab",
3
- "version": "2.0.35",
3
+ "version": "2.0.36-dev.2551+8b012df4",
4
4
  "homepage": "https://fedify.dev/",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,9 +46,9 @@
46
46
  "es-toolkit": "1.43.0",
47
47
  "jsonld": "^9.0.0",
48
48
  "pkijs": "^3.3.3",
49
- "@fedify/vocab-tools": "2.0.35",
50
- "@fedify/webfinger": "2.0.35",
51
- "@fedify/vocab-runtime": "2.0.35"
49
+ "@fedify/vocab-tools": "2.0.36-dev.2551+8b012df4",
50
+ "@fedify/webfinger": "2.0.36-dev.2551+8b012df4",
51
+ "@fedify/vocab-runtime": "2.0.36-dev.2551+8b012df4"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "^22.17.0",
package/src/vocab.test.ts CHANGED
@@ -2599,3 +2599,73 @@ for (const typeUri in types) {
2599
2599
  deepStrictEqual(cls.typeId, new URL(type.uri));
2600
2600
  });
2601
2601
  }
2602
+
2603
+ test("Note.fromJsonLd() accepts date-times without seconds", async () => {
2604
+ const cases: readonly (readonly [string, string])[] = [
2605
+ ["2024-01-01T10:00Z", "2024-01-01T10:00:00Z"],
2606
+ ["2024-01-01T10:00+09:00", "2024-01-01T01:00:00Z"],
2607
+ ["2024-01-01T10:00-05:00", "2024-01-01T15:00:00Z"],
2608
+ ["2024-01-01T10:00", "2024-01-01T10:00:00Z"],
2609
+ ["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"],
2610
+ ["2024-01-01T10:00.5+09:00", "2024-01-01T01:00:00.5Z"],
2611
+ ["2024-01-01T10:00.5-05:00", "2024-01-01T15:00:00.5Z"],
2612
+ ["2024-01-01T10:00.5", "2024-01-01T10:00:00.5Z"],
2613
+ ];
2614
+ for (const [published, expected] of cases) {
2615
+ const note = await Note.fromJsonLd({
2616
+ "@context": "https://www.w3.org/ns/activitystreams",
2617
+ type: "Note",
2618
+ published,
2619
+ }, {
2620
+ documentLoader: mockDocumentLoader,
2621
+ contextLoader: mockDocumentLoader,
2622
+ });
2623
+ // deepStrictEqual() cannot tell Temporal.Instant values apart.
2624
+ strictEqual(
2625
+ note.published?.toString(),
2626
+ Temporal.Instant.from(expected).toString(),
2627
+ );
2628
+ }
2629
+ });
2630
+
2631
+ test("Question.fromJsonLd() decodes closed values without seconds", async () => {
2632
+ const parse = (closed: string | boolean) =>
2633
+ Question.fromJsonLd({
2634
+ "@context": "https://www.w3.org/ns/activitystreams",
2635
+ type: "Question",
2636
+ closed,
2637
+ }, {
2638
+ documentLoader: mockDocumentLoader,
2639
+ contextLoader: mockDocumentLoader,
2640
+ });
2641
+ const cases: readonly (readonly [string, string])[] = [
2642
+ ["2024-01-01T10:00.5Z", "2024-01-01T10:00:00.5Z"],
2643
+ ["2024-01-01T10:00.5+09:00", "2024-01-01T01:00:00.5Z"],
2644
+ ];
2645
+ for (const [closed, expected] of cases) {
2646
+ const question = await parse(closed);
2647
+ strictEqual(
2648
+ question.closed?.toString(),
2649
+ Temporal.Instant.from(expected).toString(),
2650
+ );
2651
+ }
2652
+ await rejects(() => parse("2024-02-31T10:00.5Z"), RangeError);
2653
+ await rejects(() => parse("Sat, 01 Jan 2024 10:00:00 GMT"), RangeError);
2654
+ strictEqual((await parse(true)).closed, true);
2655
+ strictEqual((await parse("not a date")).closed, null);
2656
+ });
2657
+
2658
+ test("Note.fromJsonLd() rejects date-times that Temporal cannot parse", async () => {
2659
+ await rejects(
2660
+ () =>
2661
+ Note.fromJsonLd({
2662
+ "@context": "https://www.w3.org/ns/activitystreams",
2663
+ type: "Note",
2664
+ published: "Sat, 01 Jan 2024 10:00:00 GMT",
2665
+ }, {
2666
+ documentLoader: mockDocumentLoader,
2667
+ contextLoader: mockDocumentLoader,
2668
+ }),
2669
+ RangeError,
2670
+ );
2671
+ });