Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.34.10 #1107

Merged
merged 8 commits into from
Dec 4, 2024
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
5 changes: 5 additions & 0 deletions changelog/0.34.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
### 0.34.0
- [Revision 0.34.10](https://github.com/sinclairzx81/typebox/pull/1107)
- Fix Declaration Emit for Index and Mapped Types
- Fix Record Inference Presentation when Embedded in Modules
- Fix Record Mapping when using TImport as Key
- Add Encode to Parse Operation List
- [Revision 0.34.9](https://github.com/sinclairzx81/typebox/pull/1101)
- User Defined Parse Pipelines
- Access to Schema and References on TypeCheck
Expand Down
25 changes: 25 additions & 0 deletions hammer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export async function clean() {
await folder('node_modules/typebox').delete()
await folder('target').delete()
}

// -------------------------------------------------------------------------------
// Format
// -------------------------------------------------------------------------------
export async function format() {
await shell('prettier --no-semi --single-quote --print-width 240 --trailing-comma all --write src test task example/index.ts')
}

// -------------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------------
Expand All @@ -28,6 +30,7 @@ export async function benchmark() {
await Benchmark.compression()
await Benchmark.measurement()
}

// -------------------------------------------------------------------------------
// Test
// -------------------------------------------------------------------------------
Expand All @@ -49,6 +52,7 @@ export async function test(filter = '') {
await test_static()
await test_runtime(filter)
}

// -------------------------------------------------------------------------------
// Build
// -------------------------------------------------------------------------------
Expand All @@ -69,6 +73,25 @@ export async function build(target = 'target/build') {
await shell(`cd ${target} && npm pack`)
await build_check(target)
}

// -------------------------------------------------------------------------------
// Build To
// -------------------------------------------------------------------------------
export async function build_to(remote = 'target/remote', target = 'target/build') {
await clean()
await Promise.all([
Build.Package.build(target),
Build.Esm.build(target),
Build.Cjs.build(target),
])
await folder(target).add('readme.md')
await folder(target).add('license')
await shell(`cd ${target} && npm pack`)
const { version } = JSON.parse(Fs.readFileSync('package.json', 'utf8'))
const filename = `${target}/sinclair-typebox-${version}.tgz`
await folder(remote).add(filename)
}

// -------------------------------------------------------------------------------
// Install
// -------------------------------------------------------------------------------
Expand All @@ -77,6 +100,7 @@ export async function install_local() {
await build('target/typebox')
await folder('node_modules').add('target/typebox')
}

// -------------------------------------------------------------
// Publish
// -------------------------------------------------------------
Expand All @@ -87,6 +111,7 @@ export async function publish(otp, target = 'target/build') {
await shell(`git tag ${version}`)
await shell(`git push origin ${version}`)
}

// -------------------------------------------------------------
// Publish-Dev
// -------------------------------------------------------------
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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.34.9",
"version": "0.34.10",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand All @@ -20,6 +20,7 @@
"test:runtime": "hammer task test_runtime",
"install:local": "hammer task install_local",
"benchmark": "hammer task benchmark",
"build:to": "hammer task build_to",
"build": "hammer task build",
"test": "hammer task test",
"clean": "hammer task clean",
Expand Down
11 changes: 7 additions & 4 deletions src/type/indexed/indexed-from-mapped-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type TMappedIndexPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
[_ in Key]: TIndex<Type, [Key]>
}
// prettier-ignore
function MappedIndexPropertyKey<Type extends TSchema, Key extends PropertyKey
>(type: Type, key: Key, options?: SchemaOptions): TMappedIndexPropertyKey<Type, Key> {
function MappedIndexPropertyKey<Type extends TSchema, Key extends PropertyKey>(type: Type, key: Key, options?: SchemaOptions): TMappedIndexPropertyKey<Type, Key> {
return { [key]: Index(type, [key], Clone(options)) } as never
}
// ------------------------------------------------------------------
Expand All @@ -55,7 +54,10 @@ type TMappedIndexPropertyKeys<Type extends TSchema, PropertyKeys extends Propert
: Result
)
// prettier-ignore
function MappedIndexPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys], options?: SchemaOptions): TMappedIndexPropertyKeys<Type, PropertyKeys> {
function MappedIndexPropertyKeys<
Type extends TSchema,
PropertyKeys extends PropertyKey[]
>(type: Type, propertyKeys: [...PropertyKeys], options?: SchemaOptions): TMappedIndexPropertyKeys<Type, PropertyKeys> {
return propertyKeys.reduce((result, left) => {
return { ...result, ...MappedIndexPropertyKey(type, left, options) }
}, {} as TProperties) as never
Expand All @@ -68,7 +70,8 @@ type TMappedIndexProperties<Type extends TSchema, MappedKey extends TMappedKey>
TMappedIndexPropertyKeys<Type, MappedKey['keys']>
>
// prettier-ignore
function MappedIndexProperties<Type extends TSchema, MappedKey extends TMappedKey>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TMappedIndexProperties<Type, MappedKey> {
function MappedIndexProperties<Type extends TSchema, MappedKey extends TMappedKey
>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TMappedIndexProperties<Type, MappedKey> {
return MappedIndexPropertyKeys(type, mappedKey.keys, options) as never
}
// ------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions src/type/indexed/indexed-from-mapped-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ type TFromProperties<Type extends TSchema, Properties extends TProperties> = (
function FromProperties<Type extends TSchema, Properties extends TProperties>(type: Type, properties: Properties, options?: SchemaOptions): TFromProperties<Type, Properties> {
const result = {} as Record<PropertyKey, TSchema>
for(const K2 of Object.getOwnPropertyNames(properties)) {
const keys = IndexPropertyKeys(properties[K2])
result[K2] = Index(type, keys, options) as never
result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options)
}
return result as never
}
Expand Down
26 changes: 12 additions & 14 deletions src/type/indexed/indexed-property-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ import { IsTemplateLiteral, IsUnion, IsLiteral, IsNumber, IsInteger } from '../g
// FromTemplateLiteral
// ------------------------------------------------------------------
// prettier-ignore
type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral,
Result extends string[] = TTemplateLiteralGenerate<TemplateLiteral>
> = Result
type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Keys extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = (Keys)
// prettier-ignore
function FromTemplateLiteral<TemplateLiteral extends TTemplateLiteral>(templateLiteral: TemplateLiteral): TFromTemplateLiteral<TemplateLiteral> {
const result = TemplateLiteralGenerate(templateLiteral) as string[]
return result.map(S => S.toString()) as never
const keys = TemplateLiteralGenerate(templateLiteral) as string[]
return keys.map(key => key.toString()) as never
}
// ------------------------------------------------------------------
// FromUnion
Expand All @@ -59,9 +57,9 @@ type TFromUnion<Types extends TSchema[], Result extends string[] = []> = (
: Result
)
// prettier-ignore
function FromUnion<Type extends TSchema[]>(type: Type): TFromUnion<Type> {
function FromUnion<Types extends TSchema[]>(types: Types): TFromUnion<Types> {
const result = [] as string[]
for(const left of type) result.push(...IndexPropertyKeys(left))
for(const type of types) result.push(...IndexPropertyKeys(type))
return result as never
}
// ------------------------------------------------------------------
Expand All @@ -74,23 +72,23 @@ type TFromLiteral<LiteralValue extends TLiteralValue> = (
: []
)
// prettier-ignore
function FromLiteral<LiteralValue extends TLiteralValue>(T: LiteralValue): TFromLiteral<LiteralValue> {
function FromLiteral<LiteralValue extends TLiteralValue>(literalValue: LiteralValue): TFromLiteral<LiteralValue> {
return (
[(T as string).toString()] // TS 5.4 observes TLiteralValue as not having a toString()
[(literalValue as string).toString()] // TS 5.4 observes TLiteralValue as not having a toString()
) as never
}
// ------------------------------------------------------------------
// IndexedKeyResolve
// IndexPropertyKeys
// ------------------------------------------------------------------
// prettier-ignore
export type TIndexPropertyKeys<Type extends TSchema, Result extends PropertyKey[] = (
Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> :
export type TIndexPropertyKeys<Type extends TSchema> = (
Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> :
Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> :
Type extends TLiteral<infer LiteralValue extends TLiteralValue> ? TFromLiteral<LiteralValue> :
Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral<Value> :
Type extends TNumber ? ['[number]'] :
Type extends TInteger ? ['[number]'] :
[]
)> = Result
)
/** Returns a tuple of PropertyKeys derived from the given TSchema */
// prettier-ignore
export function IndexPropertyKeys<Type extends TSchema>(type: Type): TIndexPropertyKeys<Type> {
Expand Down
Loading
Loading