-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature compelete & cleanup * fix * fix
- Loading branch information
1 parent
fe39b2d
commit eaccab5
Showing
18 changed files
with
111 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
import { type ClickhouseSchema } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type ChDataType, type MapChSchemaTypes } from '@clickhouse-schema-data-types/index' | ||
import { type ChArray } from '@clickhouse-schema-data-types/ch_array' | ||
import { type ChJSON } from '@clickhouse-schema-data-types/ch_json' | ||
import { type ExtractInnerType, type ExtractOuterType } from '@clickhouse-schema-utils/type_inference' | ||
import { type ChEnum } from '@clickhouse-schema-data-types/ch_enum' | ||
import { type ClickhouseSchema, type ChSchemaDefinition } from '@clickhouse-schema-core/clickhouse_schema' | ||
import { type ChDataType } from '@clickhouse-schema-data-types/index' | ||
import { type InferArray, type InferEnum, type InferJSON, type InferNullable, type InferTypeFromMap } from '@clickhouse-schema-utils/util' | ||
|
||
/** InferSchemaClickhouseSchemaType is a type that takes a ClickhouseSchema and returns the typescript that it represents */ | ||
export type InferClickhouseSchemaType<T extends ClickhouseSchema<any>> = { [K in keyof T['schema']]: InferType<T['schema'][K]['type']> } | ||
|
||
/** InferTypeFromMap is a type that takes a string and returns the typescript that it represents */ | ||
type InferTypeFromMap<T extends string> = ExtractInnerType<T> extends keyof MapChSchemaTypes | ||
? MapChSchemaTypes[ExtractInnerType<T>] | ||
: ExtractOuterType<T> extends keyof MapChSchemaTypes ? | ||
MapChSchemaTypes[ExtractOuterType<T>] | ||
: unknown | ||
export type InferClickhouseSchemaType<T extends ClickhouseSchema<ChSchemaDefinition>> = { [K in keyof T['schema']]: InferType<T['schema'][K]['type']> } | ||
|
||
/** InferType is a type that takes a ChDataType and returns the typescript that it represents */ | ||
type InferType<T extends ChDataType> = | ||
T extends ChArray<infer ArrayType> | ||
? Array<InferType<ArrayType>> | ||
: T extends ChEnum<infer EnumType> | ||
? keyof EnumType | ||
: T extends ChJSON<infer Schema> | ||
? { [K in keyof T['dataType']]: InferType<Schema[K]['type']> } | ||
: T extends ChDataType | ||
? InferTypeFromMap<T['typeStr']> | ||
: unknown | ||
type InferType<T extends ChDataType> = T['dataTypeMarker'] extends 'Array' ? InferArray<T> : T['dataTypeMarker'] extends 'Enum' ? InferEnum<T> : T['dataTypeMarker'] extends 'JSON' ? InferJSON<T> : T['dataTypeMarker'] extends 'Nullable' ? InferNullable<T> : InferTypeFromMap<T['typeStr']> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import { type ChDataType } from '@clickhouse-schema-data-types/index' | ||
|
||
export class ChArray<T extends ChDataType | ChArray<ChDataType>> implements ChDataType { | ||
readonly dataType: T | ||
readonly innerType: T | ||
readonly typeStr: string | ||
readonly dataTypeMarker = 'Array' as const | ||
|
||
constructor (t: T) { | ||
if (t instanceof ChArray) { | ||
this.dataType = new ChArray(t.dataType) as T | ||
this.innerType = new ChArray(t.innerType) as T | ||
} else { | ||
this.dataType = t | ||
this.innerType = t | ||
} | ||
this.typeStr = this.toString() | ||
} | ||
|
||
toString (): string { | ||
if (this.dataType instanceof ChArray) return `Array(${this.dataType.toString()})` | ||
return `Array(${this.dataType})` | ||
if (this.innerType instanceof ChArray) return `Array(${this.innerType.toString()})` | ||
return `Array(${this.innerType})` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type ChPrimitiveType, type ChDataType } from '@clickhouse-schema-data-types/index' | ||
|
||
export class ChNullable<T extends ChPrimitiveType> implements ChDataType { | ||
readonly typeStr | ||
readonly innerType: T | ||
readonly dataTypeMarker = 'Nullable' as const | ||
|
||
constructor (t: T) { | ||
this.innerType = t | ||
this.typeStr = `Nullable(${this.innerType})` | ||
} | ||
|
||
toString (): string { | ||
return this.typeStr | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type ChArray } from '@clickhouse-schema-data-types/ch_array' | ||
import { type ChEnum } from '@clickhouse-schema-data-types/ch_enum' | ||
import { type ChJSON } from '@clickhouse-schema-data-types/ch_json' | ||
import { type ChNullable } from '@clickhouse-schema-data-types/ch_nullable' | ||
import { type MapChSchemaTypes, type ChDataType } from '@clickhouse-schema-data-types/index' | ||
|
||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
export type ExtractInnerType<T extends string> = T extends `${infer _BeforeBracket}(${infer Rest})` | ||
? ExtractInnerType<Rest> | ||
: T | ||
export type ExtractOuterType<T extends string> = T extends `${infer BeforeBracket}(${infer _Rest})` | ||
? BeforeBracket | ||
: T | ||
|
||
/** InferTypeFromMap is a type that takes a string and returns the typescript that it represents */ | ||
export type InferTypeFromMap<T extends string> = ExtractInnerType<T> extends keyof MapChSchemaTypes | ||
? MapChSchemaTypes[ExtractInnerType<T>] | ||
: ExtractOuterType<T> extends keyof MapChSchemaTypes ? | ||
MapChSchemaTypes[ExtractOuterType<T>] | ||
: unknown | ||
|
||
export type InferArray<T extends ChDataType> = T extends ChArray<infer ArrayType> ? Array<InferArray<ArrayType>> : InferTypeFromMap<T['typeStr']> | ||
|
||
export type InferEnum<T extends ChDataType> = T extends ChEnum<infer EnumType> ? keyof EnumType : InferTypeFromMap<T['typeStr']> | ||
|
||
export type InferJSON<T extends ChDataType> = T extends ChJSON<infer Schema> ? { [K in keyof T['innerType']]: InferJSON<Schema[K]['type']> } : InferTypeFromMap<T['typeStr']> | ||
|
||
export type InferNullable<T extends ChDataType> = T extends ChNullable<infer NullableType> ? InferTypeFromMap<NullableType['typeStr']> | null : InferTypeFromMap<T['typeStr']> |
eaccab5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
20 tests passing in 2 suites.
Report generated by 🧪jest coverage report action from eaccab5