import type { Static } from '@sinclair/typebox' import type { Thread } from '@wovin/core/thread' import { Type } from '@sinclair/typebox' import { Value } from '@sinclair/typebox/value' import { EntityID } from '@wovin/core/applog' import { withoutDeleted } from '@wovin/core/query' import { rollingFilter } from '@wovin/core/thread' import { Logger } from 'besonders-logger' import stringify from 'safe-stable-stringify' import { getApplogDB } from './ApplogDB' const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line unused-imports/no-unused-vars const Relation = Type.Object({ en: EntityID, block: EntityID, childOf: Type.Union([EntityID, Type.Null()]), isDeleted: Type.Optional(Type.Boolean()), after: Type.Optional(EntityID), }) type Relation = Static // const RelationAttrs = Type.Union(Object.keys(Relation.properties).map((k: keyof Relation) => Type.Literal(k))) const RelationAttrs = Object.keys(Relation.properties) type RelationAttrs = Array export function checkCheck(ds?: Thread) { ds = ds ?? getApplogDB() const validEntityID = Value.Check(EntityID, '656eb60b') const invalidTooShortEntityID = Value.Check(EntityID, '65660b') const invalidTooLongEntityID = Value.Check(EntityID, '65660b5660') const invalidNonHexEntityID = Value.Check(EntityID, '656xx60b') DEBUG({ validEntityID, invalidTooShortEntityID, invalidTooLongEntityID, invalidNonHexEntityID }) // {validEntityID: true, invalidTooShortEntityID: false, invalidTooLongEntityID: false, invalidNonHexEntityID: false} const rollingFilterAttIndex = new Map(RelationAttrs.map( at => [at, rollingFilter(ds, { at: `relation/${at}` })], )) const vl = '6eb99b29' const rollingFilterMapForVM = new Map(RelationAttrs.map( at => [at, rollingFilter(withoutDeleted(ds), { at: `relation/${at}`, vl })], // with or withoutDeleted interesting to consider )) DEBUG({ RelationAttrs, rollingFilterMapForVM, rollingFilterAttIndex, attrs: stringify(RelationAttrs) }) } export interface RelationModelDef { en: EntityID isDeleted?: boolean isExpanded?: boolean /** the ID of "this" block */ block: EntityID /** the ID of the parent of "this" block (in the scope of this relation) */ childOf: EntityID | null /** the ID of the block before this block (in the scope of this parent) */ after?: EntityID }