@contember/schema
Advanced tools
Comparing version
@@ -19,3 +19,2 @@ import Input from './input'; | ||
type AnyColumn = Column<ColumnType>; | ||
type AnyColumnDefinition = UuidColumnDefinition | StringColumnDefinition | IntColumnDefinition | DoubleColumnDefinition | BoolColumnDefinition | EnumColumnDefinition | DateTimeColumnDefinition | DateColumnDefinition; | ||
enum ColumnType { | ||
@@ -29,10 +28,10 @@ Uuid = "Uuid", | ||
DateTime = "DateTime", | ||
Date = "Date" | ||
Date = "Date", | ||
Json = "Json" | ||
} | ||
type Column<T extends ColumnType> = Field<T> & ColumnDefinitionByType<T> & { | ||
type Column<T extends ColumnType> = ColumnTypeDefinition & { | ||
name: string; | ||
columnName: string; | ||
}; | ||
interface ColumnTypeDefinition<T extends ColumnType = ColumnType> { | ||
type: T; | ||
interface ColumnTypeDefinition extends Field<ColumnType> { | ||
columnType: string; | ||
@@ -42,41 +41,2 @@ nullable: boolean; | ||
} | ||
type ColumnByType<T extends ColumnType, A = AnyColumn> = A extends { | ||
type: T; | ||
} ? A : never; | ||
type ColumnDefinitionByType<T extends ColumnType, A = AnyColumnDefinition> = A extends { | ||
type: T; | ||
} ? A : never; | ||
interface UuidColumnDefinition extends ColumnTypeDefinition<ColumnType.Uuid> { | ||
columnType: 'uuid'; | ||
default?: undefined; | ||
} | ||
interface StringColumnDefinition extends ColumnTypeDefinition<ColumnType.String> { | ||
columnType: 'text'; | ||
default?: string; | ||
} | ||
interface IntColumnDefinition extends ColumnTypeDefinition<ColumnType.Int> { | ||
columnType: 'integer'; | ||
default?: number; | ||
} | ||
interface DoubleColumnDefinition extends ColumnTypeDefinition<ColumnType.Double> { | ||
columnType: 'double precision'; | ||
default?: number; | ||
} | ||
interface BoolColumnDefinition extends ColumnTypeDefinition<ColumnType.Bool> { | ||
columnType: 'boolean'; | ||
default?: boolean; | ||
} | ||
interface EnumColumnDefinition extends ColumnTypeDefinition<ColumnType.Enum> { | ||
columnType: string; | ||
enumName: string; | ||
default?: string; | ||
} | ||
interface DateTimeColumnDefinition extends ColumnTypeDefinition<ColumnType.DateTime> { | ||
columnType: 'timestamptz'; | ||
default?: 'now'; | ||
} | ||
interface DateColumnDefinition extends ColumnTypeDefinition<ColumnType.Date> { | ||
columnType: 'date'; | ||
default?: 'now'; | ||
} | ||
interface ColumnVisitor<T> { | ||
@@ -83,0 +43,0 @@ visitColumn(entity: Entity, column: AnyColumn): T; |
@@ -16,2 +16,3 @@ "use strict"; | ||
ColumnType["Date"] = "Date"; | ||
ColumnType["Json"] = "Json"; | ||
})(ColumnType = Model.ColumnType || (Model.ColumnType = {})); | ||
@@ -18,0 +19,0 @@ let RelationType; |
{ | ||
"name": "@contember/schema", | ||
"version": "0.10.0-alpha.7", | ||
"version": "0.10.0-alpha.8", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -20,11 +20,2 @@ import Input from './input' | ||
export type AnyColumn = Column<ColumnType> | ||
export type AnyColumnDefinition = | ||
| UuidColumnDefinition | ||
| StringColumnDefinition | ||
| IntColumnDefinition | ||
| DoubleColumnDefinition | ||
| BoolColumnDefinition | ||
| EnumColumnDefinition | ||
| DateTimeColumnDefinition | ||
| DateColumnDefinition | ||
@@ -40,12 +31,11 @@ export enum ColumnType { | ||
Date = 'Date', | ||
Json = 'Json', | ||
} | ||
export type Column<T extends ColumnType> = Field<T> & | ||
ColumnDefinitionByType<T> & { | ||
name: string | ||
columnName: string | ||
} | ||
export type Column<T extends ColumnType> = ColumnTypeDefinition & { | ||
name: string | ||
columnName: string | ||
} | ||
export interface ColumnTypeDefinition<T extends ColumnType = ColumnType> { | ||
type: T | ||
export interface ColumnTypeDefinition extends Field<ColumnType> { | ||
columnType: string | ||
@@ -56,46 +46,2 @@ nullable: boolean | ||
export type ColumnByType<T extends ColumnType, A = AnyColumn> = A extends { type: T } ? A : never | ||
export type ColumnDefinitionByType<T extends ColumnType, A = AnyColumnDefinition> = A extends { type: T } ? A : never | ||
export interface UuidColumnDefinition extends ColumnTypeDefinition<ColumnType.Uuid> { | ||
columnType: 'uuid' | ||
default?: undefined | ||
} | ||
export interface StringColumnDefinition extends ColumnTypeDefinition<ColumnType.String> { | ||
columnType: 'text' | ||
default?: string | ||
} | ||
export interface IntColumnDefinition extends ColumnTypeDefinition<ColumnType.Int> { | ||
columnType: 'integer' | ||
default?: number | ||
} | ||
export interface DoubleColumnDefinition extends ColumnTypeDefinition<ColumnType.Double> { | ||
columnType: 'double precision' | ||
default?: number | ||
} | ||
export interface BoolColumnDefinition extends ColumnTypeDefinition<ColumnType.Bool> { | ||
columnType: 'boolean' | ||
default?: boolean | ||
} | ||
export interface EnumColumnDefinition extends ColumnTypeDefinition<ColumnType.Enum> { | ||
columnType: string | ||
enumName: string | ||
default?: string | ||
} | ||
export interface DateTimeColumnDefinition extends ColumnTypeDefinition<ColumnType.DateTime> { | ||
columnType: 'timestamptz' | ||
default?: 'now' | ||
} | ||
export interface DateColumnDefinition extends ColumnTypeDefinition<ColumnType.Date> { | ||
columnType: 'date' | ||
default?: 'now' | ||
} | ||
export interface ColumnVisitor<T> { | ||
@@ -102,0 +48,0 @@ visitColumn(entity: Entity, column: AnyColumn): T |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
272057
-1.68%1264
-6.23%