From c03fb39a3bb07adb2377567c12706d5f76c4172c Mon Sep 17 00:00:00 2001 From: sinclairzx81 Date: Sat, 1 Feb 2025 04:19:06 +0900 Subject: [PATCH] Revision 0.8.9 (#19) * String Projection | Formatting * Version --- package-lock.json | 4 ++-- package.json | 2 +- src/syntax/syntax-from-typebox.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c2fc949..d0b15f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sinclair/typemap", - "version": "0.8.8", + "version": "0.8.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sinclair/typemap", - "version": "0.8.8", + "version": "0.8.9", "license": "MIT", "devDependencies": { "@arethetypeswrong/cli": "^0.17.2", diff --git a/package.json b/package.json index e20fce7..6f702ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sinclair/typemap", - "version": "0.8.8", + "version": "0.8.9", "description": "Syntax, Compiler and Translation System for Runtime Types", "author": "sinclairzx81", "license": "MIT", diff --git a/src/syntax/syntax-from-typebox.ts b/src/syntax/syntax-from-typebox.ts index 9a02379..f8087e8 100644 --- a/src/syntax/syntax-from-typebox.ts +++ b/src/syntax/syntax-from-typebox.ts @@ -171,7 +171,7 @@ type TFromObject `arg${index}: ${FromType(parameter)}`) - return `(${FromDelimited(result, Comma)})` + return `(${FromDelimited(result, `${Comma} `)})` } // ------------------------------------------------------------------ // Property @@ -241,6 +241,13 @@ function FromProperties(propertyKeys: PropertyKey[], properties: t.TProperties): }, [] as string[]) } // ------------------------------------------------------------------ +// Promise +// ------------------------------------------------------------------ +type TFromPromise}>`> = Result +function FromPromise(type: t.TSchema): string { + return `Promise<${FromType(type)}>` +} +// ------------------------------------------------------------------ // String // ------------------------------------------------------------------ type TFromString<_Type extends t.TString> = 'string' @@ -318,6 +325,7 @@ type TFromType = ( Type extends t.TNumber ? TFromNumber : Type extends t.TNull ? TFromNull : Type extends t.TObject ? TFromObject : + Type extends t.TPromise ? TFromPromise : Type extends t.TString ? TFromString : Type extends t.TSymbol ? TFromSymbol : Type extends t.TTuple ? TFromTuple : @@ -342,6 +350,7 @@ function FromType(type: Type): TFromType { t.KindGuard.IsNumber(type) ? FromNumber(type) : t.KindGuard.IsNull(type) ? FromNull(type) : t.KindGuard.IsObject(type) ? FromObject(type.properties) : + t.KindGuard.IsPromise(type) ? FromPromise(type.item) : t.KindGuard.IsString(type) ? FromString(type) : t.KindGuard.IsSymbol(type) ? FromSymbol(type) : t.KindGuard.IsTuple(type) ? FromTuple(type.items || []) :