Skip to main content
This release is 23 versions behind 1.4.9 — the latest version of @fedify/fedify. Jump to latest

Built and signed on GitHub Actions

An ActivityPub/fediverse server framework

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
94%
Published
3 months ago (1.3.3)
import { encodeBase58 } from "jsr:/@std/encoding@^1.0.5/base58"; import type { PropertySchema, TypeSchema } from "./schema.ts"; import { areAllScalarTypes, getTypeNames } from "./type.ts"; export async function getFieldName( propertyUri: string, prefix = "#", ): Promise<string> { const hashedUri = await crypto.subtle.digest( "SHA-1", new TextEncoder().encode(propertyUri), ); const match = propertyUri.match(/#([A-Za-z0-9_]+)$/); const suffix = match == null ? "" : `_${match[1]}`; return `${prefix}_${encodeBase58(hashedUri)}${suffix}`; } export async function generateField( property: PropertySchema, types: Record<string, TypeSchema>, prefix = "#", ): Promise<string> { const fieldName = await getFieldName(property.uri, prefix); if (areAllScalarTypes(property.range, types)) { return `${fieldName}: (${ getTypeNames(property.range, types, true) })[] = [];\n`; } else { return `${fieldName}: (${ getTypeNames(property.range, types) } | URL)[] = [];\n`; } } export async function* generateFields( typeUri: string, types: Record<string, TypeSchema>, ): AsyncIterable<string> { const type = types[typeUri]; for (const property of type.properties) { yield await generateField(property, types); } }