import type { Static } from '@sinclair/typebox' import type { EntityID } from '@wovin/core/applog' import type { Thread } from '@wovin/core/thread' import { TypeMap } from './TypeMap' export type TypeMapKeys = keyof typeMap export type TypeMapValueTB = typeof TypeMap[VM] export type VMstatic = Static> export type EntityNames = `${TypeMapKeys}` export const KnownAttrs = {} as { [EachEntity in EntityNames]: Array['properties']> } Object.entries(TypeMap).forEach( ([EachEntity, eachTypeBox]) => KnownAttrs[`${EachEntity}`] = Object.keys(eachTypeBox.properties), ) export type TypeAttrOptionsAll = { [EachEntity in EntityNames]: keyof TypeMapValueTB['properties'] } export type TypeAttrOptions = keyof TypeMapValueTB['properties'] export type TypeAttrTB = TypeMapValueTB[`properties`] export type KnownAtMap = { [K in TypeMapKeys]: { [P in keyof TypeAttrTB as Extract]: `${Uncapitalize}/${P}` } } export const knownAtMap: KnownAtMap = {} as KnownAtMap Object.entries(TypeMap).forEach(([entityName, typeBox]) => { const entityMapping: Record = {} for (const key in typeBox.properties) { entityMapping[/* snakeCase( */ key /* ).toUpperCase() */] = `${entityName[0].toLowerCase() + entityName.slice(1)}/${key}` // TODO: wovinprefix? } ;(knownAtMap as any)[entityName] = entityMapping }) export const KnownFullAttrs = {} as { [EachEntity in EntityNames]: Array } Object.entries(knownAtMap).forEach( ([EachEntity, atMapping]) => KnownFullAttrs[EachEntity as EntityNames] = Object.values(atMapping), ) export type VMap = Map< VM, Map > export const UniVMaps = new Map< Thread, VMap >() // from: https://stackoverflow.com/a/65642944 type CamelToSnakeCase = S extends `${infer T}${infer U}` ? `${T extends Capitalize ? '_' : ''}${Lowercase}${CamelToSnakeCase}` : S