-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
106 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
import { DataType } from "./types.ts"; | ||
import type { Field, FieldImpl } from "./types.ts"; | ||
import { DataType, FieldImpl } from "./types.ts"; | ||
|
||
export const testFieldImpl = (field: FieldImpl | null, ...types: DataType[]): boolean => | ||
field === null || types.includes(field.type); | ||
field === null || field?.type === DataType._Unknown || types.includes(field.type); | ||
|
||
export const getFieldName = (field: string | FieldImpl): string => { | ||
return typeof field === "string" ? field : field.name; | ||
}; | ||
export class FieldObject<T extends DataType> { | ||
readonly name: string; | ||
readonly type: T; | ||
|
||
constructor(name: string, type: T) { | ||
this.name = name; | ||
this.type = type; | ||
} | ||
|
||
toString(): string { | ||
return this.name; | ||
} | ||
} | ||
|
||
function Field(name: string): FieldObject<DataType._Unknown>; | ||
function Field<T extends DataType>(name: string, type: T): FieldObject<T>; | ||
function Field<T extends DataType>(name: string, type?: T): FieldObject<T | DataType._Unknown> { | ||
return new FieldObject(name, type ?? DataType._Unknown); | ||
} | ||
|
||
export { Field }; | ||
|
||
export const SystemFields: { | ||
Id: Field<DataType.RowIdentifier>; | ||
CreatedAt: Field<DataType.FixedTimestamp>; | ||
UpdatedAt: Field<DataType.FixedTimestamp>; | ||
Id: FieldObject<DataType.RowIdentifier>; | ||
CreatedAt: FieldObject<DataType.FixedTimestamp>; | ||
UpdatedAt: FieldObject<DataType.FixedTimestamp>; | ||
} = { | ||
/** System field: **:id**, Only works in 2.1 */ | ||
Id: { | ||
name: ":id", | ||
type: DataType.RowIdentifier, | ||
}, | ||
Id: Field(":id", DataType.RowIdentifier), | ||
/** System field: **:created_at**, Only works in 2.1 */ | ||
CreatedAt: { | ||
name: ":created_at", | ||
type: DataType.FixedTimestamp, | ||
}, | ||
CreatedAt: Field(":created_at", DataType.FixedTimestamp), | ||
/** System field: **:updated_at**, Only works in 2.1 */ | ||
UpdatedAt: { | ||
name: ":updated_at", | ||
type: DataType.FixedTimestamp, | ||
}, | ||
UpdatedAt: Field(":updated_at", DataType.FixedTimestamp), | ||
}; |
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