Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into refine
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Apr 29, 2024
2 parents cbea73a + 93a32b0 commit 70c2946
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions hammer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export async function build(target = 'target/build') {
await test()
await clean()
await Promise.all([
Build.Import.build(target),
Build.Require.build(target),
Build.Redirect.build(target)
Build.Package.build(target),
Build.Esm.build(target),
Build.Cjs.build(target),
])
await folder(target).add('readme.md')
await folder(target).add('license')
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.32.25",
"version": "0.32.27",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type T = Static<typeof T> // type T = {
TypeBox is a runtime type builder that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript and runtime asserted using standard Json Schema validation.
This library is designed to allow Json Schema to compose with the same flexibility as TypeScript's programmable type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
This library is designed to allow Json Schema to compose similar to how types compose within TypeScript's type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
License MIT
Expand Down Expand Up @@ -897,9 +897,9 @@ const K = Type.TemplateLiteral('prop${A|B|C}') // const K: TTemplateLitera
// ]>

const R = Type.Record(K, Type.String()) // const R: TObject<{
// hello1: TString,
// hello2: TString,
// hello3: TString,
// propA: TString,
// propB: TString,
// propC: TString,
// }>
```
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export namespace Policy {
: `(typeof ${value} === 'object' && ${value} !== null && !(${value} instanceof Date) && !(${value} instanceof Uint8Array))`
}
export function IsNumberLike(value: string): string {
return !TypeSystemPolicy.AllowNaN ? `(typeof ${value} === 'number' && Number.isFinite(${value}))` : `typeof ${value} === 'number'`
return TypeSystemPolicy.AllowNaN ? `typeof ${value} === 'number'` : `Number.isFinite(${value})`
}
export function IsVoidLike(value: string): string {
return TypeSystemPolicy.AllowNullVoid ? `(${value} === undefined || ${value} === null)` : `${value} === undefined`
Expand Down Expand Up @@ -290,7 +290,7 @@ export namespace TypeCompiler {
yield `(typeof ${value} === 'function')`
}
function* FromInteger(schema: TInteger, references: TSchema[], value: string): IterableIterator<string> {
yield `(typeof ${value} === 'number' && Number.isInteger(${value}))`
yield `Number.isInteger(${value})`
if (IsNumber(schema.exclusiveMaximum)) yield `${value} < ${schema.exclusiveMaximum}`
if (IsNumber(schema.exclusiveMinimum)) yield `${value} > ${schema.exclusiveMinimum}`
if (IsNumber(schema.maximum)) yield `${value} <= ${schema.maximum}`
Expand Down
3 changes: 1 addition & 2 deletions src/system/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export namespace TypeSystemPolicy {
}
/** Asserts this value using the AllowNaN policy */
export function IsNumberLike(value: unknown): value is number {
const isNumber = IsNumber(value)
return AllowNaN ? isNumber : isNumber && Number.isFinite(value)
return AllowNaN ? IsNumber(value) : Number.isFinite(value)
}
/** Asserts this value using the AllowVoidNull policy */
export function IsVoidLike(value: unknown): value is void {
Expand Down
2 changes: 1 addition & 1 deletion src/type/guard/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import * as ValueGuard from './value'
import { Kind, Hint, RefineKind, TransformKind, ReadonlyKind, OptionalKind } from '../symbols/index'
import { TypeBoxError } from '../error/index'
import { TransformOptions } from '../transform/index'
import { TTemplateLiteral, TTemplateLiteralKind } from '../template-literal/index'
import { TTemplateLiteral } from '../template-literal/index'
import { TArray } from '../array/index'
import { TBoolean } from '../boolean/index'
import type { TRecord } from '../record/index'
Expand Down
2 changes: 1 addition & 1 deletion src/value/guard/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function IsNumber(value: unknown): value is number {
}
/** Returns true if this value is an integer */
export function IsInteger(value: unknown): value is number {
return IsNumber(value) && Number.isInteger(value)
return Number.isInteger(value)
}
/** Returns true if this value is bigint */
export function IsBigInt(value: unknown): value is bigint {
Expand Down
6 changes: 3 additions & 3 deletions task/build/require/build.ts → task/build/cjs/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { removeNotices } from '../common/remove-notices'
import { removeNotices } from '../notices/remove-notices'
import { compile } from './compile'

/** Builds the CommonJS version of this package */
export async function build(target: string) {
console.log('building...require')
const buildTarget = `${target}/build/require`
console.log('building...cjs')
const buildTarget = `${target}/build/cjs`
await compile(buildTarget)
await removeNotices(buildTarget)
}
File renamed without changes.
6 changes: 3 additions & 3 deletions task/build/import/build.ts → task/build/esm/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { removeNotices } from '../common/remove-notices'
import { removeNotices } from '../notices/remove-notices'
import { convertToEsm } from './convert-to-esm'
import { compile } from './compile'

/** Builds the ESM version of this package */
export async function build(target: string) {
console.log('building...import')
const buildTarget = `${target}/build/import`
console.log('building...esm')
const buildTarget = `${target}/build/esm`
await compile(buildTarget)
await convertToEsm(buildTarget)
await removeNotices(buildTarget)
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions task/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

export * as Import from './import/build'
export * as Require from './require/build'
export * as Redirect from './redirect/build'
export * as Package from './package/build'
export * as Esm from './esm/build'
export * as Cjs from './cjs/build'
File renamed without changes.
6 changes: 3 additions & 3 deletions task/build/redirect/build.ts → task/build/package/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { createPackageJsonRedirect } from './create-package-json-redirect'
import { createPackageJson } from './create-package-json'
import { createRedirectPaths } from './create-redirect-paths'

/** Builds package.json and redirect directories */
export async function build(target: string) {
console.log('building...redirect')
console.log('building...package.json')
const submodules = ['compiler', 'errors', 'system', 'type', 'value']
await createPackageJsonRedirect(target, submodules)
await createPackageJson(target, submodules)
await createRedirectPaths(target, submodules)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ THE SOFTWARE.

import * as Fs from 'node:fs'

// prettier-ignore
function writeRedirect(target: string, submodule: string) {
Fs.mkdirSync(`${target}/${submodule}`, { recursive: true })
Fs.writeFileSync(`${target}/${submodule}/package.json`,JSON.stringify({
main: `../build/cjs/${submodule}/index.js`,
types: `../build/cjs/${submodule}/index.d.ts`,
}, null, 2))
}
// --------------------------------------------------------------------------------------------------------------------------
// Builds redirect directories for earlier versions of Node. Note that TypeScript will use these directories to
// resolve types when tsconfig.json is configured for `moduleResolution: 'node'`. This approach is referred to as
Expand All @@ -37,15 +45,6 @@ import * as Fs from 'node:fs'
// --------------------------------------------------------------------------------------------------------------------------

// prettier-ignore
export function createRedirectPaths(target: string, submodules: string[]) {
export function createPackageJsonRedirect(target: string, submodules: string[]) {
submodules.forEach((submodule) => writeRedirect(target, submodule))
}

// prettier-ignore
function writeRedirect(target: string, submodule: string) {
Fs.mkdirSync(`${target}/${submodule}`, { recursive: true })
Fs.writeFileSync(`${target}/${submodule}/package.json`,JSON.stringify({
main: `../build/require/${submodule}/index.js`,
types: `../build/require/${submodule}/index.d.ts`,
}, null, 2))
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ function resolvePackageJson(submodules: string[]) {
function resolveSubmoduleExports(submodule: string) {
return {
require: {
types: `./build/require/${submodule}/index.d.ts`,
default: `./build/require/${submodule}/index.js`,
types: `./build/cjs/${submodule}/index.d.ts`,
default: `./build/cjs/${submodule}/index.js`,
},
import: {
types: `./build/import/${submodule}/index.d.mts`,
default: `./build/import/${submodule}/index.mjs`,

types: `./build/esm/${submodule}/index.d.mts`,
default: `./build/esm/${submodule}/index.mjs`,
}
}
}
Expand All @@ -66,13 +65,13 @@ function resolveExports(submodules: string[]) {
// ... and root module
".": {
"require": {
"types": "./build/require/index.d.ts",
"default": "./build/require/index.js",
"types": "./build/cjs/index.d.ts",
"default": "./build/cjs/index.js",

},
"import": {
"types": "./build/import/index.d.mts",
"default": "./build/import/index.mjs",
"types": "./build/esm/index.d.mts",
"default": "./build/esm/index.mjs",
}
}
})
Expand All @@ -90,9 +89,12 @@ function resolveMetadata() {
author: packageJson.author,
license: packageJson.license,
repository: packageJson.repository,
scripts: { test: 'echo test' }, // flagged by socket.dev
types: "./build/require/index.d.ts",
main: "./build/require/index.js",
module: "./build/import/index.mjs",
// flagged by socket.dev if not present
scripts: { test: 'echo test' },
// disable auto bundle strategy: see https://github.com/esm-dev/esm.sh#bundling-strategy
'esm.sh': { 'bundle': false },
types: "./build/cjs/index.d.ts",
main: "./build/cjs/index.js",
module: "./build/esm/index.mjs"
}
}

0 comments on commit 70c2946

Please sign in to comment.