/** * MIT License * * Copyright (c) 2025 Chris M. Perez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import { Schema } from 'effect'; import { EFFUSE_NODE } from '../constants.js'; import { ElementPropsSchema } from './dom.js'; const BaseNodeSchema = Schema.Struct({ [EFFUSE_NODE]: Schema.Literal(true), key: Schema.optional(Schema.Union(Schema.String, Schema.Number)), }); export const EffuseChildSchema: Schema.Schema = Schema.suspend(() => Schema.Union( EffuseNodeSchema, Schema.String, Schema.Number, Schema.Boolean, Schema.Null, Schema.Undefined, Schema.Array(EffuseChildSchema), Schema.Object ) ) as unknown as Schema.Schema; export const PortalFnSchema = Schema.Unknown; export const PortalsSchema = Schema.Record({ key: Schema.String, value: PortalFnSchema, }); export const ElementNodeSchema = BaseNodeSchema.pipe( Schema.extend( Schema.Struct({ _tag: Schema.Literal('Element'), tag: Schema.String, props: Schema.Union(ElementPropsSchema, Schema.Null), children: Schema.Array(EffuseChildSchema), }) ) ); export const TextNodeSchema = BaseNodeSchema.pipe( Schema.extend( Schema.Struct({ _tag: Schema.Literal('Text'), text: Schema.String, }) ) ); export const FragmentNodeSchema = BaseNodeSchema.pipe( Schema.extend( Schema.Struct({ _tag: Schema.Literal('Fragment'), children: Schema.Array(EffuseChildSchema), }) ) ); export const BlueprintContextSchema = Schema.Struct({ props: Schema.Record({ key: Schema.String, value: Schema.Unknown }), state: Schema.Record({ key: Schema.String, value: Schema.Object }), portals: PortalsSchema, }); export const BlueprintDefSchema = Schema.Struct({ _tag: Schema.Literal('Blueprint'), name: Schema.optional(Schema.String), props: Schema.optional( Schema.Record({ key: Schema.String, value: Schema.Unknown }) ), state: Schema.optional(Schema.Unknown), view: Schema.Unknown, error: Schema.optional(Schema.Unknown), loading: Schema.optional(Schema.Unknown), }); export const BlueprintNodeSchema = BaseNodeSchema.pipe( Schema.extend( Schema.Struct({ _tag: Schema.Literal('Blueprint'), blueprint: BlueprintDefSchema, props: Schema.Record({ key: Schema.String, value: Schema.Unknown }), portals: Schema.Union(PortalsSchema, Schema.Null), }) ) ); export const ListNodeSchema = BaseNodeSchema.pipe( Schema.extend( Schema.Struct({ _tag: Schema.Literal('List'), children: Schema.Array(EffuseChildSchema), }) ) ); export const EffuseNodeSchema = Schema.Union( ElementNodeSchema, TextNodeSchema, FragmentNodeSchema, BlueprintNodeSchema, ListNodeSchema ); export type PortalFn = Schema.Schema.Type; export type Portals = Schema.Schema.Type; export type ElementNode = Schema.Schema.Type; export type TextNode = Schema.Schema.Type; export type FragmentNode = Schema.Schema.Type; export type BlueprintNode = Schema.Schema.Type; export type ListNode = Schema.Schema.Type; export type EffuseNode = Schema.Schema.Type; export type EffuseChild = Schema.Schema.Type; export type BlueprintContext = Schema.Schema.Type< typeof BlueprintContextSchema >; export type BlueprintDef = Schema.Schema.Type;