Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fluffy-mirrors-open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@traversable/schema-zod-adapter": patch
"@traversable/schema": patch
---

chore(schema,zod): prep work for breaking out `schema-core`
1 change: 1 addition & 0 deletions packages/schema-zod-adapter/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {
fromConstantToSchemaString,
toString,
} from './functor.js'
export * as Print from './print.js'
34 changes: 1 addition & 33 deletions packages/schema-zod-adapter/src/functor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod'
import type * as T from '@traversable/registry'
import { fn, has, parseKey } from '@traversable/registry'
import { Json } from '@traversable/json'
import * as Print from './print.js'

export {
toString,
Expand Down Expand Up @@ -393,39 +394,6 @@ const DepthFunctor: T.IndexedFunctor<number, Json.Free> = {
}
}

declare namespace Print {
export interface Options {
indent?: number
separator?: string
}
}

namespace Print {
export const defaults = {
indent: 0,
separator: "",
} as const satisfies Required<Options>

export const pad = ({ indent = defaults.indent }: Options) => " ".repeat(indent)
export const tab = ({ indent = defaults.indent }: Options) => " ".repeat(indent + 2)
export const newline = ({ indent = defaults.indent }: Options, count = 0) => "\n" + " ".repeat(indent + (2 * (count + 1)))

export function lines($?: Options):
<L extends string, const Body extends string[], R extends string>(left: L, ...body: [...Body, R])
=> `${L}${string}${R}`
export function lines($: Options = defaults) {
return (...args: [string, ...string[], string]) => {
const [left, body, right] = [args.at(0), args.slice(1, -1), args.at(-1)]
return ""
+ left
+ [body.map((_) => newline($) + _).join(",")].join("," + newline($, -1))
+ newline($, -1)
+ right
}
}

}

namespace Algebra {
export const toString: T.Functor.Algebra<Z.Free, string> = (x) => {
switch (true) {
Expand Down
27 changes: 27 additions & 0 deletions packages/schema-zod-adapter/src/print.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface Options {
indent?: number
separator?: string
}

export const defaults = {
indent: 0,
separator: "",
} as const satisfies Required<Options>

export const pad = ({ indent = defaults.indent }: Options) => " ".repeat(indent)
export const tab = ({ indent = defaults.indent }: Options) => " ".repeat(indent + 2)
export const newline = ({ indent = defaults.indent }: Options, count = 0) => "\n" + " ".repeat(indent + (2 * (count + 1)))

export function lines($?: Options):
<L extends string, const Body extends string[], R extends string>(left: L, ...body: [...Body, R])
=> `${L}${string}${R}`
export function lines($: Options = defaults) {
return (...args: [string, ...string[], string]) => {
const [left, body, right] = [args.at(0), args.slice(1, -1), args.at(-1)]
return ""
+ left
+ [body.map((_) => newline($) + _).join(",")].join("," + newline($, -1))
+ newline($, -1)
+ right
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/schema/src/ast.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as AST from './_internal.js'
export * as AST from './_ast.js'
2 changes: 1 addition & 1 deletion packages/schema/src/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Predicate } from './types.js'
import type { Force, Intersect } from '@traversable/registry'
import { symbol as Symbol, URI } from '@traversable/registry'
import type * as AST from './_internal.js'
import type * as AST from './_ast.js'
import type { SchemaOptions } from './options.js'

export {
Expand Down