import { assertEquals } from "@std/assert"; import "@commonfabric/api/schema"; import type { Default, FactoryInput, HandlerFactory, JSONSchema, OpaqueRef, PatternFactory, PatternFunction, SELF, StripCell, WishFunction, WishParams, WishState, Writable, } from "@commonfabric/api"; import type { Schema, SchemaWithoutCell } from "@commonfabric/api/schema"; type MustBeTrue = T; type AssertAssignable = [T] extends [U] ? true : never; type AssertNotAssignable = [T] extends [U] ? never : true; interface Ship { name: string; } interface PlayerData { name: string; ships: Ship[]; } type PlayerCell = Writable>; type ReactivePlayerData = { name: FactoryInput; ships: Array>; }; interface HandlerState { name: string; player1: PlayerCell; } interface RoomInput { player1: PlayerCell; } type HandlerBinding = { name: FactoryInput; player1: Writable; }; type RoomBinding = { player1: Writable; }; type WrongRoomBinding = { player1: Writable< { name: FactoryInput; ships: Array>; } | null >; }; const _handlerBinding: MustBeTrue< AssertAssignable>> > = true; const _roomBinding: MustBeTrue< AssertAssignable>> > = true; const _handlerFactory: MustBeTrue< AssertAssignable< HandlerFactory, (inputs: HandlerBinding) => unknown > > = true; const _patternFactory: MustBeTrue< AssertAssignable< PatternFactory, unknown>, (inputs: RoomBinding) => unknown > > = true; const _wrongRoomBinding: MustBeTrue< AssertNotAssignable>> > = true; type SchemaPatternOverloadAcceptsFactoryInput = PatternFunction extends { ( fn: ( input: OpaqueRef> & { [SELF]: OpaqueRef> }, ) => FactoryInput>, argumentSchema: IS, resultSchema: OS, ): PatternFactory, Schema>; } ? true : never; type SchemaWishOverloadAcceptsFactoryInput = WishFunction extends { ( target: FactoryInput, schema: S, ): OpaqueRef>>; } ? true : never; const _schemaPatternOverload: MustBeTrue< SchemaPatternOverloadAcceptsFactoryInput > = true; const _schemaWishOverload: MustBeTrue< SchemaWishOverloadAcceptsFactoryInput > = true; Deno.test("FactoryInput accepts reactive cell handles in factory bindings", async () => { const schemaModule = await import("@commonfabric/api/schema"); assertEquals( [ typeof schemaModule, _handlerBinding, _roomBinding, _handlerFactory, _patternFactory, _wrongRoomBinding, _schemaPatternOverload, _schemaWishOverload, ], ["object", true, true, true, true, true, true, true], ); });