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: 5 additions & 1 deletion changelog/1.2.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 1.2.0

Advancing Programmable Runtime Types
---

### Version Updates
- [Revision 1.2.1](https://github.com/sinclairzx81/typebox/pull/1605)
- Fix: Escape Decimal Separator in `NumberPattern`

<a name="overview"></a>

Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Build
// --------------------------------------------------------------
"tasksmith": "https://raw.githubusercontent.com/sinclairzx81/tasksmith/0.9.13/src/index.ts",
"parsebox": "https://raw.githubusercontent.com/sinclairzx81/parsebox/0.11.4/src/index.ts",
"parsebox": "https://raw.githubusercontent.com/sinclairzx81/parsebox/0.11.5/src/index.ts",
// --------------------------------------------------------------
// Test
// --------------------------------------------------------------
Expand Down
151 changes: 84 additions & 67 deletions deno.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/type/script/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,12 +1356,12 @@ export function PatternStringMapping(input: '.*'): unknown {
return T.String()
}
// -------------------------------------------------------------------
// PatternNumber: '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?'
// PatternNumber: '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?'
// -------------------------------------------------------------------
export type TPatternNumberMapping<Input extends '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?'> = (
export type TPatternNumberMapping<Input extends '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?'> = (
T.TNumber
)
export function PatternNumberMapping(input: '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?'): unknown {
export function PatternNumberMapping(input: '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?'): unknown {
return T.Number()
}
// -------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/type/script/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ export type TJsonArray<Input extends string> = (Token.TConst<'[', Input> extends
export type TJson<Input extends string> = (TJsonNumber<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TJsonBoolean<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TJsonString<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TJsonNull<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TJsonObject<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TJsonArray<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [S.TJsonMapping<_0>, Input] : []
export type TPatternBigInt<Input extends string> = Token.TConst<'-?(?:0|[1-9][0-9]*)n', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)n', infer Input extends string] ? [S.TPatternBigIntMapping<_0>, Input] : []
export type TPatternString<Input extends string> = Token.TConst<'.*', Input> extends [infer _0 extends '.*', infer Input extends string] ? [S.TPatternStringMapping<_0>, Input] : []
export type TPatternNumber<Input extends string> = Token.TConst<'-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?', infer Input extends string] ? [S.TPatternNumberMapping<_0>, Input] : []
export type TPatternNumber<Input extends string> = Token.TConst<'-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', infer Input extends string] ? [S.TPatternNumberMapping<_0>, Input] : []
export type TPatternInteger<Input extends string> = Token.TConst<'-?(?:0|[1-9][0-9]*)', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)', infer Input extends string] ? [S.TPatternIntegerMapping<_0>, Input] : []
export type TPatternNever<Input extends string> = Token.TConst<'(?!)', Input> extends [infer _0 extends '(?!)', infer Input extends string] ? [S.TPatternNeverMapping<_0>, Input] : []
export type TPatternText<Input extends string> = Token.TUntil_1<['-?(?:0|[1-9][0-9]*)n', '.*', '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?', '-?(?:0|[1-9][0-9]*)', '(?!)', '(', ')', '$', '|'], Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPatternTextMapping<_0>, Input] : []
export type TPatternText<Input extends string> = Token.TUntil_1<['-?(?:0|[1-9][0-9]*)n', '.*', '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', '-?(?:0|[1-9][0-9]*)', '(?!)', '(', ')', '$', '|'], Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPatternTextMapping<_0>, Input] : []
export type TPatternBase<Input extends string> = (TPatternBigInt<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternString<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternNumber<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternInteger<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternNever<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternGroup<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternText<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [S.TPatternBaseMapping<_0>, Input] : []
export type TPatternGroup<Input extends string> = (Token.TConst<'(', Input> extends [infer _0, infer Input extends string] ? (TPatternBody<Input> extends [infer _1, infer Input extends string] ? (Token.TConst<')', Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown], infer Input extends string] ? [S.TPatternGroupMapping<_0>, Input] : []
export type TPatternUnion<Input extends string> = ((TPatternTerm<Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'|', Input> extends [infer _1, infer Input extends string] ? (TPatternUnion<Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (TPatternTerm<Input> extends [infer _0, infer Input extends string] ? [[_0], Input] : []) extends [infer _0, infer Input extends string] ? [_0, Input] : [[], Input] extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends [unknown, unknown, unknown] | [unknown] | [], infer Input extends string] ? [S.TPatternUnionMapping<_0>, Input] : []
Expand Down Expand Up @@ -271,10 +271,10 @@ export const JsonArray = (input: string): [unknown, string] | [] => If(If(Token.
export const Json = (input: string): [unknown, string] | [] => If(If(JsonNumber(input), ([_0, input]) => [_0, input], () => If(JsonBoolean(input), ([_0, input]) => [_0, input], () => If(JsonString(input), ([_0, input]) => [_0, input], () => If(JsonNull(input), ([_0, input]) => [_0, input], () => If(JsonObject(input), ([_0, input]) => [_0, input], () => If(JsonArray(input), ([_0, input]) => [_0, input], () => [])))))), ([_0, input]) => [S.JsonMapping(_0 as unknown), input])
export const PatternBigInt = (input: string): [unknown, string] | [] => If(Token.Const('-?(?:0|[1-9][0-9]*)n', input), ([_0, input]) => [S.PatternBigIntMapping(_0 as '-?(?:0|[1-9][0-9]*)n'), input])
export const PatternString = (input: string): [unknown, string] | [] => If(Token.Const('.*', input), ([_0, input]) => [S.PatternStringMapping(_0 as '.*'), input])
export const PatternNumber = (input: string): [unknown, string] | [] => If(Token.Const('-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?', input), ([_0, input]) => [S.PatternNumberMapping(_0 as '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?'), input])
export const PatternNumber = (input: string): [unknown, string] | [] => If(Token.Const('-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', input), ([_0, input]) => [S.PatternNumberMapping(_0 as '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?'), input])
export const PatternInteger = (input: string): [unknown, string] | [] => If(Token.Const('-?(?:0|[1-9][0-9]*)', input), ([_0, input]) => [S.PatternIntegerMapping(_0 as '-?(?:0|[1-9][0-9]*)'), input])
export const PatternNever = (input: string): [unknown, string] | [] => If(Token.Const('(?!)', input), ([_0, input]) => [S.PatternNeverMapping(_0 as '(?!)'), input])
export const PatternText = (input: string): [unknown, string] | [] => If(Token.Until_1(['-?(?:0|[1-9][0-9]*)n', '.*', '-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?', '-?(?:0|[1-9][0-9]*)', '(?!)', '(', ')', '$', '|'], input), ([_0, input]) => [S.PatternTextMapping(_0 as string), input])
export const PatternText = (input: string): [unknown, string] | [] => If(Token.Until_1(['-?(?:0|[1-9][0-9]*)n', '.*', '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', '-?(?:0|[1-9][0-9]*)', '(?!)', '(', ')', '$', '|'], input), ([_0, input]) => [S.PatternTextMapping(_0 as string), input])
export const PatternBase = (input: string): [unknown, string] | [] => If(If(PatternBigInt(input), ([_0, input]) => [_0, input], () => If(PatternString(input), ([_0, input]) => [_0, input], () => If(PatternNumber(input), ([_0, input]) => [_0, input], () => If(PatternInteger(input), ([_0, input]) => [_0, input], () => If(PatternNever(input), ([_0, input]) => [_0, input], () => If(PatternGroup(input), ([_0, input]) => [_0, input], () => If(PatternText(input), ([_0, input]) => [_0, input], () => []))))))), ([_0, input]) => [S.PatternBaseMapping(_0 as unknown), input])
export const PatternGroup = (input: string): [unknown, string] | [] => If(If(Token.Const('(', input), ([_0, input]) => If(PatternBody(input), ([_1, input]) => If(Token.Const(')', input), ([_2, input]) => [[_0, _1, _2], input]))), ([_0, input]) => [S.PatternGroupMapping(_0 as [unknown, unknown, unknown]), input])
export const PatternUnion = (input: string): [unknown, string] | [] => If(If(If(PatternTerm(input), ([_0, input]) => If(Token.Const('|', input), ([_1, input]) => If(PatternUnion(input), ([_2, input]) => [[_0, _1, _2], input]))), ([_0, input]) => [_0, input], () => If(If(PatternTerm(input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => []))), ([_0, input]) => [S.PatternUnionMapping(_0 as [unknown, unknown, unknown] | [unknown] | []), input])
Expand Down
2 changes: 1 addition & 1 deletion src/type/types/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { type TSchema, type TNumberOptions, IsKind } from './schema.ts'
// ------------------------------------------------------------------
// Pattern
// ------------------------------------------------------------------
export const NumberPattern = '-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?'
export const NumberPattern = '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?'
// ------------------------------------------------------------------
// Static
// ------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Metrics } from './task/metrics/index.ts'
import { Spec } from './task/spec/index.ts'
import { Task } from 'tasksmith'

const Version = '1.2.0'
const Version = '1.2.1'

// ------------------------------------------------------------------
// Build
Expand Down
8 changes: 4 additions & 4 deletions test/typebox/runtime/type/engine/action/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Test('Should Record 4', () => {
Assert.IsTrue(Type.IsInteger(Type.RecordKey(T)))
})
Test('Should Record 5', () => {
const T: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$', Type.TNull> = Type.Record(Type.Number(), Type.Null())
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$')
const T: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$', Type.TNull> = Type.Record(Type.Number(), Type.Null())
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$')
Assert.IsTrue(Type.IsNumber(Type.RecordKey(T)))
})
Test('Should Record 6', () => {
Expand Down Expand Up @@ -189,8 +189,8 @@ Test('Should Record 20', () => {
// Key: Number
// ------------------------------------------------------------------
Test('Should Record 21', () => {
const T: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$', Type.TNull> = Type.Record(Type.Number(), Type.Null())
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$')
const T: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$', Type.TNull> = Type.Record(Type.Number(), Type.Null())
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$')

Assert.IsTrue(Type.IsRecord(T))
Assert.IsTrue(Type.IsNumber(Type.RecordKey(T)))
Expand Down
2 changes: 1 addition & 1 deletion test/typebox/runtime/type/engine/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Test('Should Instantiate 34', () => {
Assert.IsEqual(A.properties.y.$ref, 'B')
})
Test('Should Instantiate 35', () => {
const A: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$', Type.TRef<'B'>> = Type.Instantiate({ A: Type.Number() }, Type.Record(Type.Ref('A'), Type.Ref('B')))
const A: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$', Type.TRef<'B'>> = Type.Instantiate({ A: Type.Number() }, Type.Record(Type.Ref('A'), Type.Ref('B')))
Assert.IsTrue(Type.IsRecord(A))
Assert.IsTrue(Type.IsNumber(Type.RecordKey(A)))
Assert.IsTrue(Type.IsRef(Type.RecordValue(A)))
Expand Down
4 changes: 2 additions & 2 deletions test/typebox/runtime/type/script/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ Test('Should Record 15', () => {
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)$')
})
Test('Should Record 16', () => {
const T: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$', Type.TString> = Type.Script('Record<`${number}`, string>')
const T: Type.TRecord<'^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$', Type.TString> = Type.Script('Record<`${number}`, string>')
Assert.IsTrue(Type.IsRecord(T))
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$')
Assert.IsEqual(Type.RecordPattern(T), '^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$')
})
Test('Should Record 17', () => {
const T: Type.TRecord<'^(?!)$', Type.TString> = Type.Script('Record<`${never}`, string>')
Expand Down
4 changes: 2 additions & 2 deletions test/typebox/runtime/type/script/template_literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Test('Should TemplateLiteral 7', () => {
// Embedded Infinite
// ------------------------------------------------------------------
Test('Should TemplateLiteral 8', () => {
const T: Type.TTemplateLiteral<'^hello -?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$'> = Type.Script('`hello ${number}`')
const T: Type.TTemplateLiteral<'^hello -?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$'> = Type.Script('`hello ${number}`')
Assert.IsTrue(Type.IsTemplateLiteral(T))
Assert.IsEqual(T.pattern, '^hello -?(?:0|[1-9][0-9]*)(?:.[0-9]+)?$')
Assert.IsEqual(T.pattern, '^hello -?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$')
})
Test('Should TemplateLiteral 9', () => {
const T: Type.TTemplateLiteral<'^hello .*$'> = Type.Script('`hello ${string}`')
Expand Down
Loading
Loading