import type { Distill, LastInUnion, MergeTrees, ReduceTrees, Tree, TreeMap, TreeMapExhaustive, } from "../src/treetrunks.ts" import { optional, required } from "../src/treetrunks.ts" describe(`experiments`, () => { test(`web routes`, () => { const myWebRoutes = optional({ documents: null, }) satisfies Tree type HttpInterface = { query: Record; response: string } type HttpSignalMethod = `DELETE` | `GET` type HttpVectorMethod = `GET` | `PATCH` | `POST` | `PUT` type HttpMethod = HttpSignalMethod | HttpVectorMethod type WebIO = M extends HttpSignalMethod ? HttpInterface : HttpInterface & { body: string } type WebApiRouteDescriptor = Partial<{ [M in HttpMethod]: WebIO }> type WebApi = TreeMap const none: Readonly> = {} const _WEB_ROUTES = { "": { GET: { query: none, response: `Hello World`, }, }, documents: {}, } satisfies WebApi }) test(`render tree`, () => { const _myRenderTree = required({ body: required({ header: required({ nav: required({ ul: required({ li: required({ a: required({}), }), }), }), }), main: required({ section: null, }), }), }) satisfies Tree type VNode = { render(): string; tree?: T } type ComponentFn> = ( ...params: any[] ) => N | string | null type TreeFromVNode | string | null> = N extends VNode ? T : null type TreesFromComponentFn> = F extends ComponentFn ? TreeFromVNode : never function div | string | null>( _: N, ): { render(): string tree?: [ `required`, { div: TreeFromVNode }, ] } { return { render: () => `` } } function span | string | null>( _: N, ): { render(): string tree?: [ `required`, { span: TreeFromVNode }, ] } { return { render: () => `` } } function myComponent() { if (Math.random() > 0.5) { return span(`hi`) } return div(span(`hi`)) } const treeA = optional({ a: required({ b: null, }), }) const treeB = optional({ a: required({ c: null, d: optional({ e: null, }), }), z: null, }) type _MergedTree = MergeTrees type _Z = LastInUnion<1 | 2> type _ZZ = Distill<1 | 2 | 3> type ComponentTree> = Distill> extends Tree[] ? ReduceTrees>> extends Tree ? ReduceTrees>> : never : never type _ComponentTrees = Distill> type ComponentTrees2 = ComponentTree type CSSProperties = Record type _StylesForComponent = Omit< TreeMapExhaustive, CSSProperties, ` > `>, `` > type TreeLedger = { [K in keyof T[1] as `${P}${K & string}`]: null } type _ZZZ = TreeLedger `> }) })