Revision 0.33.22 (#1065)

* Remove Parse from Top Level Import

* Rename Parse submodule to Syntax

* Export Parse Inference Types

* ChangeLog

* Version
This commit is contained in:
Haydn Paterson
2024-11-09 23:09:10 +09:00
committed by GitHub
parent 52ceab98c5
commit 6cf8596c3a
27 changed files with 36 additions and 28 deletions

View File

@@ -1,4 +1,6 @@
### 0.33.0
- [Revision 0.33.22](https://github.com/sinclairzx81/typebox/pull/1065)
- Rename TypeScript parsing infrastructure from `/parse` to `/syntax`. Remove Parse API from top level import.
- [Revision 0.33.21](https://github.com/sinclairzx81/typebox/pull/1064)
- [1063](https://github.com/sinclairzx81/typebox/issues/1063) Hotfix to resolve variable shadowing on Object (Parser Runtime)
- [Revision 0.33.20](https://github.com/sinclairzx81/typebox/pull/1062)

View File

@@ -1,7 +1,8 @@
import { TypeSystem } from '@sinclair/typebox/system'
import { TypeCompiler } from '@sinclair/typebox/compiler'
import { Value, ValuePointer } from '@sinclair/typebox/value'
import { Type, Parse, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox'
import { Parse, StaticParseAsType } from '@sinclair/typebox/syntax'
import { Type, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox'
// -----------------------------------------------------------
// Create: Type
@@ -21,7 +22,7 @@ console.log(T)
// Parse: Type
// -----------------------------------------------------------
const S = Parse({ T }, `Partial<T>`)
const S = Parse({ T }, `{ x: T, y: T, z: T }`)
type S = Static<typeof S>

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@sinclair/typebox",
"version": "0.33.21",
"version": "0.33.22",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@sinclair/typebox",
"version": "0.33.21",
"version": "0.33.22",
"license": "MIT",
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.2",

View File

@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.33.21",
"version": "0.33.22",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",

View File

@@ -38,10 +38,7 @@ export * from './type/patterns/index'
export * from './type/registry/index'
export * from './type/sets/index'
export * from './type/symbols/index'
// ------------------------------------------------------------------
// Parse
// ------------------------------------------------------------------
export * from './parse/index'
// ------------------------------------------------------------------
// Types
// ------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------------
@sinclair/typebox
@sinclair/typebox/syntax
The MIT License (MIT)

View File

@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------------
@sinclair/typebox
@sinclair/typebox/syntax
The MIT License (MIT)
@@ -29,23 +29,30 @@ THE SOFTWARE.
import { Static } from './parsebox/index'
import { CreateType } from '../type/create/type'
import { TSchema, SchemaOptions } from '../type/schema/index'
import { StaticDecode } from '../type/static/index'
import { Module } from './runtime'
import { Type } from './static'
/** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
export function Parse<Code extends string, Context extends Record<PropertyKey, TSchema> = {}>(context: Context, code: Code, options?: SchemaOptions): Static.Parse<Type, Code, Context>[0]
/** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
export function Parse<Code extends string>(code: Code, options?: SchemaOptions): Static.Parse<Type, Code, {}>[0]
/** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
/** `[Experimental]` Infers a TypeBox type from TypeScript syntax. */
export type StaticParseAsSchema<Context extends Record<PropertyKey, TSchema>, Code extends string> = Static.Parse<Type, Code, Context>[0]
/** `[Experimental]` Infers a TypeScript type from TypeScript syntax. */
export type StaticParseAsType<Context extends Record<PropertyKey, TSchema>, Code extends string> = StaticParseAsSchema<Context, Code> extends infer Type extends TSchema ? StaticDecode<Type> : undefined
/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */
export function Parse<Context extends Record<PropertyKey, TSchema>, Code extends string>(context: Context, code: Code, options?: SchemaOptions): StaticParseAsSchema<Context, Code>
/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */
export function Parse<Code extends string>(code: Code, options?: SchemaOptions): StaticParseAsSchema<{}, Code>
/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */
export function Parse(...args: any[]): never {
return ParseOnly.apply(null, args as never) as never
}
/** `[Experimental]` Parses a TypeScript type annotation as TSchema */
export function ParseOnly<Code extends string, Context extends Record<PropertyKey, TSchema> = {}>(context: Context, code: Code, options?: SchemaOptions): TSchema | undefined
/** `[Experimental]` Parses a TypeScript type annotation as TSchema */
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */
export function ParseOnly<Context extends Record<PropertyKey, TSchema>, Code extends string>(context: Context, code: Code, options?: SchemaOptions): TSchema | undefined
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax */
export function ParseOnly<Code extends string>(code: Code, options?: SchemaOptions): TSchema | undefined
/** `[Experimental]` Parses a TypeScript type annotation as TSchema */
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */
export function ParseOnly(...args: any[]): TSchema | undefined {
const withContext = typeof args[0] === 'string' ? false : true
const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}]

View File

@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------------
@sinclair/typebox
@sinclair/typebox/syntax
The MIT License (MIT)

View File

@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------------
@sinclair/typebox
@sinclair/typebox/syntax
The MIT License (MIT)

View File

@@ -1,4 +1,4 @@
{
"extends": "../tsconfig.json",
"files": ["compiler/index.ts", "errors/index.ts", "system/index.ts", "type/index.ts", "value/index.ts", "index.ts"]
"files": ["compiler/index.ts", "errors/index.ts", "syntax/index.ts", "system/index.ts", "type/index.ts", "value/index.ts", "index.ts"]
}

View File

@@ -32,7 +32,7 @@ import { createPackageJson } from './create-package-json'
/** Builds package.json and redirect directories */
export async function build(target: string) {
console.log('building...package.json')
const submodules = ['compiler', 'errors', 'parse', 'system', 'type', 'value']
const submodules = ['compiler', 'errors', 'syntax', 'system', 'type', 'value']
await createPackageJsonRedirect(target, submodules)
await createPackageJson(target, submodules)
}

View File

@@ -8,7 +8,7 @@ TypeSystemPolicy.InstanceMode = 'freeze'
import './compiler/index'
import './compiler-ajv/index'
import './errors/index'
import './parse/index'
import './syntax/index'
import './system/index'
import './type/index'
import './value/index'

View File

@@ -1 +0,0 @@
import './parse'

View File

@@ -0,0 +1 @@
import './syntax'

View File

@@ -1,5 +1,6 @@
import { TypeGuard } from '@sinclair/typebox'
import { Type, Parse } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { Parse } from '@sinclair/typebox/syntax'
import { Assert } from '../assert/index'
// prettier-ignore

View File

@@ -8,7 +8,7 @@
"paths": {
"@sinclair/typebox/compiler": ["src/compiler/index.ts"],
"@sinclair/typebox/errors": ["src/errors/index.ts"],
"@sinclair/typebox/parse": ["src/parse/index.ts"],
"@sinclair/typebox/syntax": ["src/syntax/index.ts"],
"@sinclair/typebox/system": ["src/system/index.ts"],
"@sinclair/typebox/type": ["src/type/index.ts"],
"@sinclair/typebox/value": ["src/value/index.ts"],