import type { ObjectOptions, TAnySchema } from '@sinclair/typebox' import { Type } from '@sinclair/typebox' // HACK: @see https://github.com/elysiajs/elysia/issues/75 const EntityID = Type.String() // HACK how to configure ID format? const URL = Type.String({ format: 'URL' }) export const TiptapContentT = Type.Object({ content: Type.Optional(Type.Any()), type: Type.Optional(Type.String()), }) export type TiptapContent = Record export const Entity = Type.Object({ isDeleted: Type.Optional(Type.Boolean()), }) export function wovinAtName(atToUse, TypeBoxDef: TAnySchema) { TypeBoxDef.wovinAtName = atToUse return TypeBoxDef } interface WovinSchemaOptions { wovinPrefix?: string } export function T(typeBoxObjectDef: ObjectOptions, wovinOptions: WovinSchemaOptions = {}) { const TypeBoxDef = Type.Object(typeBoxObjectDef) Object.assign(TypeBoxDef, wovinOptions) return TypeBoxDef } // only the props that belong in the wovin Applogs belong here // all other props needed for rendering belong on the VMs as _privates or getters export const TypeMap = { Entity, 'Relation': T({ // en: EntityID, block: EntityID, childOf: EntityID, isExpanded: Type.Optional(Type.Boolean()), isReply: Type.Optional(Type.Boolean()), after: Type.Optional(EntityID), }), 'Block': T({ // en: EntityID, content: TiptapContentT, mirrors: Type.Optional(Type.String()), pullUrl: Type.Optional(URL), }), 'Wovin/provider': T({ // en: EntityID, type: Type.Optional(Type.String()), url: wovinAtName('url', Type.Optional(Type.String())), }, { wovinPrefix: 'wovin/provider', }), 'Provider': Type.Object({ type: Type.Optional(Type.String()), url: wovinAtName('url', Type.Optional(Type.String())), }), 'Publication': T({ // en: EntityID, name: Type.String(), // TODO ... }), 'Subscription': T({ // en: EntityID, name: Type.String(), // TODO ... }), } as const // export const AutoVMs = wovinMakeAutoVMs(TypeMap) // const wovinMakeAutoVMs = Object.fromEntries( // Object.entries(TypeMap) // .map(([eachEntityName, eachDef]) => [`${eachEntityName}VM`, makeAutoVM(eachEntityName, eachDef)]), // ) const TypeMapEntries = Object.entries(TypeMap) const _archive = { Provider: Type.Composite([ Entity, Type.Object({ 'wovin/provider/type': Type.String(), 'url': Type.String(), }), ]), // 'Provider2': AttributePrefix( // 'wovin/provider', // recursive prefix // Type.Object({ // type: Type.String(), // url: AttributeRename('url', Type.String(/* { rename: 'url' } as StringOptions*/) ), // // url: AttributeRename('foo/url', Type.String()), // AttributeRename will remove parent prefixs ? how to make obvious // }/* , { // // Theoretically possible, but far uglier and meant for other shenanigans // additionalProperties: { // '[Kind]': 'prefix', // params: [], // prefix: 'wovin/provider', // static: false, // }, // } */), // ), }