Unverified Commit aac953a3 authored by Hong Minhee's avatar Hong Minhee
Browse files

Add Mastodon extensions to Actor types

parent e1518729
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -27,8 +27,10 @@
  "cSpell.words": [
    "bccs",
    "btos",
    "cfworker",
    "codegen",
    "Deno",
    "discoverability",
    "docloader",
    "fedify",
    "fediverse",
+745 −15

File changed.

Preview size limit exceeded, changes collapsed.

+14 −10
Original line number Diff line number Diff line
import { join } from "jsr:@std/path@^0.218.2";
import * as url from "jsr:@std/url@^0.218.2";
import { parse } from "jsr:@std/yaml@^0.218.2";
import { Schema as JsonSchema } from "https://deno.land/x/jema@v1.1.9/schema.js";
import {
  Schema as JsonSchema,
  Validator,
} from "npm:@cfworker/json-schema@1.12.8";
import { readDirRecursive } from "./fs.ts";

/**
@@ -172,27 +175,28 @@ export class SchemaError extends Error {
  }
}

async function loadSchemaSchema(): Promise<JsonSchema> {
async function loadSchemaValidator(): Promise<Validator> {
  const thisFile = new URL(import.meta.url);
  const response = await fetch(url.join(url.dirname(thisFile), "schema.yaml"));
  const content = await response.text();
  const schemaObject = parse(content);
  const schema = new JsonSchema(schemaObject as object);
  await schema.deref();
  return schema;
  return new Validator(schemaObject as JsonSchema);
}

const schemaSchema: JsonSchema = await loadSchemaSchema();
const schemaValidator: Validator = await loadSchemaValidator();

async function loadSchema(path: string): Promise<TypeSchema> {
  const content = await Deno.readTextFile(path);
  const schema = parse(content);
  const result = schemaValidator.validate(schema);
  const errors: SchemaError[] = [];
  for (const e of schemaSchema.errors(schema)) {
    errors.push(new SchemaError(path, `${path}: ${e.message}`));
  if (result.valid) return schema as TypeSchema;
  for (const e of result.errors) {
    errors.push(
      new SchemaError(path, `${path}:${e.instanceLocation}: ${e.error}`),
    );
  }
  if (errors.length > 0) throw new AggregateError(errors);
  return schema as TypeSchema;
  throw new AggregateError(errors);
}

/**
+5 −1
Original line number Diff line number Diff line
@@ -49,8 +49,12 @@ federation.setActorDispatcher("/users/{handle}", async (ctx, handle, key) => {
    name: blog.title,
    summary: blog.description,
    preferredUsername: handle,
    url: new URL("/", ctx.request.url),
    url: new URL("/", ctx.url),
    published: blog.published,
    discoverable: true,
    suspended: false,
    indexable: true,
    memorial: false,
    // A `Context<TContextData>` object has several purposes, and one of
    // them is to provide a way to generate URIs for the dispatchers and
    // the collections:
+75 −15
Original line number Diff line number Diff line
@@ -733,7 +733,11 @@ snapshot[`Deno.inspect(Application) [auto] 1`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -789,7 +793,11 @@ snapshot[`Deno.inspect(Application) [auto] 2`] = `
  followers: URL "https://example.com/",
  linked: URL "https://example.com/",
  streams: [ URL "https://example.com/" ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -857,7 +865,11 @@ snapshot[`Deno.inspect(Application) [auto] 3`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {}, Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -3051,7 +3063,11 @@ snapshot[`Deno.inspect(Group) [auto] 1`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -3107,7 +3123,11 @@ snapshot[`Deno.inspect(Group) [auto] 2`] = `
  followers: URL "https://example.com/",
  linked: URL "https://example.com/",
  streams: [ URL "https://example.com/" ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -3175,7 +3195,11 @@ snapshot[`Deno.inspect(Group) [auto] 3`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {}, Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -4688,7 +4712,11 @@ snapshot[`Deno.inspect(Organization) [auto] 1`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -4744,7 +4772,11 @@ snapshot[`Deno.inspect(Organization) [auto] 2`] = `
  followers: URL "https://example.com/",
  linked: URL "https://example.com/",
  streams: [ URL "https://example.com/" ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -4812,7 +4844,11 @@ snapshot[`Deno.inspect(Organization) [auto] 3`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {}, Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -5020,7 +5056,11 @@ snapshot[`Deno.inspect(Person) [auto] 1`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -5076,7 +5116,11 @@ snapshot[`Deno.inspect(Person) [auto] 2`] = `
  followers: URL "https://example.com/",
  linked: URL "https://example.com/",
  streams: [ URL "https://example.com/" ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -5144,7 +5188,11 @@ snapshot[`Deno.inspect(Person) [auto] 3`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {}, Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -5998,7 +6046,11 @@ snapshot[`Deno.inspect(Service) [auto] 1`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -6054,7 +6106,11 @@ snapshot[`Deno.inspect(Service) [auto] 2`] = `
  followers: URL "https://example.com/",
  linked: URL "https://example.com/",
  streams: [ URL "https://example.com/" ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

@@ -6122,7 +6178,11 @@ snapshot[`Deno.inspect(Service) [auto] 3`] = `
  followers: Collection {},
  linked: Collection {},
  streams: [ Collection {}, Collection {} ],
  endpoints: Endpoints {}
  endpoints: Endpoints {},
  discoverable: true,
  suspended: true,
  memorial: true,
  indexable: true
}'
`;

Loading