-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mastodon extensions to Actor types
- Loading branch information
Showing
10 changed files
with
1,036 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
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/[email protected]/schema.js"; | ||
import { | ||
Schema as JsonSchema, | ||
Validator, | ||
} from "npm:@cfworker/[email protected]"; | ||
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); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.