Skip to content

Commit

Permalink
Remove Constant Type, Misc. Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Nov 25, 2024
1 parent 180acde commit 12d548b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 87 deletions.
3 changes: 1 addition & 2 deletions types/Ty.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assertEquals } from "@std/assert"
import { assertTySnapshot } from "test_util"
import { SubschemaFactory } from "./schema.ts"
import { Ty } from "./Ty.ts"
import { SubschemaFactory, Ty } from "./Ty.ts"

export const any = Ty<unknown, never, true>(() => ({
type: ["string", "number", "object", "array", "boolean", "null"],
Expand Down
23 changes: 20 additions & 3 deletions types/Ty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Schema, type Subschema, SubschemaFactory } from "./schema.ts"
import { recombine } from "../util/recombine.ts"

export interface Ty<T = any, P extends keyof any = keyof any, R extends boolean = boolean> {
<P2 extends Array<keyof any>>(
Expand Down Expand Up @@ -66,9 +66,26 @@ export function Ty<T, P extends keyof any, R extends boolean, I = T>(
)
}

export interface Context {
export type Subschema = (subschema: SubschemaFactory) => Schema

export type SubschemaFactory = (ty: Ty) => Schema
export function SubschemaFactory(applied: Applied): SubschemaFactory {
return (ty) => {
applied = { ...applied, ...ty[""].applied }
const description = ty[""].context
.map(({ template, placeheld }) => recombine(template, placeheld.map((k) => applied[k]!)))
.join(" ")
return {
...ty[""].subschema(SubschemaFactory(applied)),
...description ? { description } : {},
}
}
}

interface Context {
template: TemplateStringsArray
placeheld: Array<keyof any>
}
type Applied = Record<keyof any, number | string>

export type Applied = Record<keyof any, number | string>
export type Schema = Record<string, unknown>
41 changes: 0 additions & 41 deletions types/__snapshots__/constant.test.ts.snap

This file was deleted.

10 changes: 0 additions & 10 deletions types/constant.test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions types/constant.ts

This file was deleted.

2 changes: 0 additions & 2 deletions types/mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export * from "./array.ts"
export * from "./constant.ts"
export * from "./constantUnion.ts"
export * from "./object.ts"
export * from "./primitives.ts"
export * from "./schema.ts"
export * from "./std/mod.ts"
export * from "./taggedUnion.ts"
export * from "./transform.ts"
Expand Down
20 changes: 0 additions & 20 deletions types/schema.ts

This file was deleted.

3 changes: 1 addition & 2 deletions types/taggedUnion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Schema } from "./schema.ts"
import { Ty } from "./Ty.ts"
import { type Schema, Ty } from "./Ty.ts"

export function taggedUnion<M extends Record<string, Ty>>(members: M): Ty<
{
Expand Down

0 comments on commit 12d548b

Please sign in to comment.