Unverified Commit 6069656f authored by Hong Minhee's avatar Hong Minhee
Browse files

Merge tag '0.14.5' into 0.15-maintenance

Fedify 0.14.5
parents 8e62e4f9 fcd31225
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ Version 0.15.2

To be released.

 -  Fixed a bug of `Object.toJsonLd()` method where it had not fall back to
    the proper compact form when the heuristic compact form was not available.


Version 0.15.1
--------------
@@ -82,6 +85,15 @@ Released on September 11, 2024.
    object.


Version 0.14.5
--------------

Released on September 26, 2024.

 -  Fixed a bug of `Object.toJsonLd()` method where it had not fall back to
    the proper compact form when the heuristic compact form was not available.


Version 0.14.4
--------------

+441 −309

File changed.

Preview size limit exceeded, changes collapsed.

+17 −15
Original line number Diff line number Diff line
@@ -47,21 +47,7 @@ export async function* generateEncoder(
  `;
  if (isCompactableType(typeUri, types)) {
    yield `
    if (
      options.format == null
    `;
    for (const property of type.properties) {
      if (!property.range.every((r) => isCompactableType(r, types))) {
        yield `
        && (
          this.${await getFieldName(property.uri)} == null ||
          this.${await getFieldName(property.uri)}.length < 1
        )
        `;
      }
    }
    yield `
    ) {
    if (options.format == null && this.isCompactable()) {
    `;
    if (type.extends == null) {
      yield "const result: Record<string, unknown> = {};";
@@ -253,6 +239,22 @@ export async function* generateEncoder(
    }
    return compacted;
  }

  protected isCompactable(): boolean {
`;
  for (const property of type.properties) {
    if (!property.range.every((r) => isCompactableType(r, types))) {
      yield `
      if (
        this.${await getFieldName(property.uri)} != null &&
        this.${await getFieldName(property.uri)}.length > 0
      ) return false;
      `;
    }
  }
  yield `
    return ${type.extends == null ? "true" : "super.isCompactable()"};
  }
  `;
}

+3 −0
Original line number Diff line number Diff line
@@ -442,6 +442,9 @@ export function isCompactableType(
  } else if (typeUri in types) {
    const type = types[typeUri];
    if (type.compactName == null) return false;
    else if (type.extends != null && !isCompactableType(type.extends, types)) {
      return false;
    }
    const defaultContext = type.defaultContext;
    return defaultContext != null &&
        HEURISTICS_CONTEXTS.includes(defaultContext as string) ||
+52 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import {
  CryptographicKey,
  type DataIntegrityProof,
  Follow,
  Hashtag,
  Note,
  Object,
  Person,
@@ -235,6 +236,57 @@ test("Object.toJsonLd()", async () => {
  });
});

test("Note.toJsonLd()", async () => {
  const note = new Note({
    tags: [
      new Hashtag({
        name: "#Fedify",
        href: new URL("https://fedify.dev/"),
      }),
    ],
  });
  assertEquals(await note.toJsonLd({ contextLoader: mockDocumentLoader }), {
    "@context": [
      "https://www.w3.org/ns/activitystreams",
      "https://w3id.org/security/data-integrity/v1",
      {
        Emoji: "toot:Emoji",
        Hashtag: "as:Hashtag",
        _misskey_quote: "misskey:_misskey_quote",
        fedibird: "http://fedibird.com/ns#",
        misskey: "https://misskey-hub.net/ns#",
        quoteUri: "fedibird:quoteUri",
        quoteUrl: "as:quoteUrl",
        sensitive: "as:sensitive",
        toot: "http://joinmastodon.org/ns#",
      },
    ],
    tag: {
      "@context": [
        "https://www.w3.org/ns/activitystreams",
        {
          Hashtag: "as:Hashtag",
        },
      ],
      href: "https://fedify.dev/",
      name: "#Fedify",
      type: "Hashtag",
    },
    type: "Note",
  });

  const noteWithName = note.clone({
    name: "Test",
  });
  assertEquals(
    await noteWithName.toJsonLd({ contextLoader: mockDocumentLoader }),
    await noteWithName.toJsonLd({
      contextLoader: mockDocumentLoader,
      format: "compact",
    }),
  );
});

test("Activity.fromJsonLd()", async () => {
  const follow = await Activity.fromJsonLd(
    {