From 6cf8596c3a0d456c3718798bb601f21f799de63c Mon Sep 17 00:00:00 2001 From: Haydn Paterson Date: Sat, 9 Nov 2024 23:09:10 +0900 Subject: [PATCH] Revision 0.33.22 (#1065) * Remove Parse from Top Level Import * Rename Parse submodule to Syntax * Export Parse Inference Types * ChangeLog * Version --- changelog/0.33.0.md | 2 ++ example/index.ts | 5 ++-- package-lock.json | 4 +-- package.json | 2 +- src/index.ts | 5 +--- src/{parse => syntax}/index.ts | 2 +- src/{parse => syntax}/parse.ts | 27 ++++++++++++------- src/{parse => syntax}/parsebox/index.ts | 0 .../parsebox/runtime/guard.ts | 0 .../parsebox/runtime/index.ts | 0 .../parsebox/runtime/module.ts | 0 .../parsebox/runtime/parse.ts | 0 .../parsebox/runtime/token.ts | 0 .../parsebox/runtime/types.ts | 0 .../parsebox/static/index.ts | 0 .../parsebox/static/parse.ts | 0 .../parsebox/static/token.ts | 0 .../parsebox/static/types.ts | 0 src/{parse => syntax}/runtime.ts | 2 +- src/{parse => syntax}/static.ts | 2 +- src/tsconfig.json | 2 +- task/build/package/build.ts | 2 +- test/runtime/index.ts | 2 +- test/runtime/parse/index.ts | 1 - test/runtime/syntax/index.ts | 1 + .../{parse/parse.ts => syntax/syntax.ts} | 3 ++- tsconfig.json | 2 +- 27 files changed, 36 insertions(+), 28 deletions(-) rename src/{parse => syntax}/index.ts (98%) rename src/{parse => syntax}/parse.ts (59%) rename src/{parse => syntax}/parsebox/index.ts (100%) rename src/{parse => syntax}/parsebox/runtime/guard.ts (100%) rename src/{parse => syntax}/parsebox/runtime/index.ts (100%) rename src/{parse => syntax}/parsebox/runtime/module.ts (100%) rename src/{parse => syntax}/parsebox/runtime/parse.ts (100%) rename src/{parse => syntax}/parsebox/runtime/token.ts (100%) rename src/{parse => syntax}/parsebox/runtime/types.ts (100%) rename src/{parse => syntax}/parsebox/static/index.ts (100%) rename src/{parse => syntax}/parsebox/static/parse.ts (100%) rename src/{parse => syntax}/parsebox/static/token.ts (100%) rename src/{parse => syntax}/parsebox/static/types.ts (100%) rename src/{parse => syntax}/runtime.ts (99%) rename src/{parse => syntax}/static.ts (99%) delete mode 100644 test/runtime/parse/index.ts create mode 100644 test/runtime/syntax/index.ts rename test/runtime/{parse/parse.ts => syntax/syntax.ts} (99%) diff --git a/changelog/0.33.0.md b/changelog/0.33.0.md index f42f59f..31140de 100644 --- a/changelog/0.33.0.md +++ b/changelog/0.33.0.md @@ -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) diff --git a/example/index.ts b/example/index.ts index 711d7d0..9d22868 100644 --- a/example/index.ts +++ b/example/index.ts @@ -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`) +const S = Parse({ T }, `{ x: T, y: T, z: T }`) type S = Static diff --git a/package-lock.json b/package-lock.json index f9c7d94..262945a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 4dbbc3e..1a8dff9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 9f0429d..6a99799 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 // ------------------------------------------------------------------ diff --git a/src/parse/index.ts b/src/syntax/index.ts similarity index 98% rename from src/parse/index.ts rename to src/syntax/index.ts index d0a1a96..ae2cee7 100644 --- a/src/parse/index.ts +++ b/src/syntax/index.ts @@ -1,6 +1,6 @@ /*-------------------------------------------------------------------------- -@sinclair/typebox +@sinclair/typebox/syntax The MIT License (MIT) diff --git a/src/parse/parse.ts b/src/syntax/parse.ts similarity index 59% rename from src/parse/parse.ts rename to src/syntax/parse.ts index ef9928f..4605b9c 100644 --- a/src/parse/parse.ts +++ b/src/syntax/parse.ts @@ -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 = {}>(context: Context, code: Code, options?: SchemaOptions): Static.Parse[0] -/** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */ -export function Parse(code: Code, options?: SchemaOptions): Static.Parse[0] -/** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */ +/** `[Experimental]` Infers a TypeBox type from TypeScript syntax. */ +export type StaticParseAsSchema, Code extends string> = Static.Parse[0] + +/** `[Experimental]` Infers a TypeScript type from TypeScript syntax. */ +export type StaticParseAsType, Code extends string> = StaticParseAsSchema extends infer Type extends TSchema ? StaticDecode : undefined + +/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */ +export function Parse, Code extends string>(context: Context, code: Code, options?: SchemaOptions): StaticParseAsSchema +/** `[Experimental]` Parses a TypeBox type from TypeScript syntax. */ +export function Parse(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 = {}>(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, Code extends string>(context: Context, code: Code, options?: SchemaOptions): TSchema | undefined +/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax */ export function ParseOnly(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] || {}] diff --git a/src/parse/parsebox/index.ts b/src/syntax/parsebox/index.ts similarity index 100% rename from src/parse/parsebox/index.ts rename to src/syntax/parsebox/index.ts diff --git a/src/parse/parsebox/runtime/guard.ts b/src/syntax/parsebox/runtime/guard.ts similarity index 100% rename from src/parse/parsebox/runtime/guard.ts rename to src/syntax/parsebox/runtime/guard.ts diff --git a/src/parse/parsebox/runtime/index.ts b/src/syntax/parsebox/runtime/index.ts similarity index 100% rename from src/parse/parsebox/runtime/index.ts rename to src/syntax/parsebox/runtime/index.ts diff --git a/src/parse/parsebox/runtime/module.ts b/src/syntax/parsebox/runtime/module.ts similarity index 100% rename from src/parse/parsebox/runtime/module.ts rename to src/syntax/parsebox/runtime/module.ts diff --git a/src/parse/parsebox/runtime/parse.ts b/src/syntax/parsebox/runtime/parse.ts similarity index 100% rename from src/parse/parsebox/runtime/parse.ts rename to src/syntax/parsebox/runtime/parse.ts diff --git a/src/parse/parsebox/runtime/token.ts b/src/syntax/parsebox/runtime/token.ts similarity index 100% rename from src/parse/parsebox/runtime/token.ts rename to src/syntax/parsebox/runtime/token.ts diff --git a/src/parse/parsebox/runtime/types.ts b/src/syntax/parsebox/runtime/types.ts similarity index 100% rename from src/parse/parsebox/runtime/types.ts rename to src/syntax/parsebox/runtime/types.ts diff --git a/src/parse/parsebox/static/index.ts b/src/syntax/parsebox/static/index.ts similarity index 100% rename from src/parse/parsebox/static/index.ts rename to src/syntax/parsebox/static/index.ts diff --git a/src/parse/parsebox/static/parse.ts b/src/syntax/parsebox/static/parse.ts similarity index 100% rename from src/parse/parsebox/static/parse.ts rename to src/syntax/parsebox/static/parse.ts diff --git a/src/parse/parsebox/static/token.ts b/src/syntax/parsebox/static/token.ts similarity index 100% rename from src/parse/parsebox/static/token.ts rename to src/syntax/parsebox/static/token.ts diff --git a/src/parse/parsebox/static/types.ts b/src/syntax/parsebox/static/types.ts similarity index 100% rename from src/parse/parsebox/static/types.ts rename to src/syntax/parsebox/static/types.ts diff --git a/src/parse/runtime.ts b/src/syntax/runtime.ts similarity index 99% rename from src/parse/runtime.ts rename to src/syntax/runtime.ts index 933f938..0d28dbb 100644 --- a/src/parse/runtime.ts +++ b/src/syntax/runtime.ts @@ -1,6 +1,6 @@ /*-------------------------------------------------------------------------- -@sinclair/typebox +@sinclair/typebox/syntax The MIT License (MIT) diff --git a/src/parse/static.ts b/src/syntax/static.ts similarity index 99% rename from src/parse/static.ts rename to src/syntax/static.ts index 90bec8e..ff75dca 100644 --- a/src/parse/static.ts +++ b/src/syntax/static.ts @@ -1,6 +1,6 @@ /*-------------------------------------------------------------------------- -@sinclair/typebox +@sinclair/typebox/syntax The MIT License (MIT) diff --git a/src/tsconfig.json b/src/tsconfig.json index e53e3eb..89a62a8 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -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"] } diff --git a/task/build/package/build.ts b/task/build/package/build.ts index a7fc92f..0e05ede 100644 --- a/task/build/package/build.ts +++ b/task/build/package/build.ts @@ -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) } diff --git a/test/runtime/index.ts b/test/runtime/index.ts index 56b6a34..ec19724 100644 --- a/test/runtime/index.ts +++ b/test/runtime/index.ts @@ -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' diff --git a/test/runtime/parse/index.ts b/test/runtime/parse/index.ts deleted file mode 100644 index 09cc871..0000000 --- a/test/runtime/parse/index.ts +++ /dev/null @@ -1 +0,0 @@ -import './parse' diff --git a/test/runtime/syntax/index.ts b/test/runtime/syntax/index.ts new file mode 100644 index 0000000..8d81ae4 --- /dev/null +++ b/test/runtime/syntax/index.ts @@ -0,0 +1 @@ +import './syntax' diff --git a/test/runtime/parse/parse.ts b/test/runtime/syntax/syntax.ts similarity index 99% rename from test/runtime/parse/parse.ts rename to test/runtime/syntax/syntax.ts index 1ac85df..11e2829 100644 --- a/test/runtime/parse/parse.ts +++ b/test/runtime/syntax/syntax.ts @@ -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 diff --git a/tsconfig.json b/tsconfig.json index 811eedc..34a4b8f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"],