Skip to content

Commit

Permalink
feat: expose name property on RuntimeType
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Sep 22, 2022
1 parent 5aa2ae5 commit 0ccf7f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/postgres/array.ts
@@ -1,10 +1,10 @@
import { kTypeArrayId, kTypeName } from './symbols'
import { kTypeArrayId } from './symbols'
import { defineType, RuntimeType, Type } from './type'

export const array = ((type: RuntimeType) => {
const id = type[kTypeArrayId]
if (id !== undefined) {
return defineType(id, type[kTypeName] + '[]', id)
return defineType(id, type.name + '[]', id)
}
throw Error('Cannot define array type for type without array ID')
}) as {
Expand Down
1 change: 0 additions & 1 deletion src/postgres/symbols.ts
Expand Up @@ -23,5 +23,4 @@ export const kTableName = Symbol.for('table.name')
export const kTableRef = Symbol.for('table.ref')
export const kTypeArrayId = Symbol.for('type.arrayId')
export const kTypeId = Symbol.for('type.id')
export const kTypeName = Symbol.for('type.name')
export const kTypeTokenizer = Symbol.for('type.tokenizer')
10 changes: 5 additions & 5 deletions src/postgres/type.ts
Expand Up @@ -12,12 +12,12 @@ import {
kTableName,
kTypeArrayId,
kTypeId,
kTypeName,
kTypeTokenizer,
} from './symbols'
import type { TableRef } from './table'
import { t } from './type-builtin'

const kTypeName = Symbol()
const kClientType = Symbol()
const kColumnInput = Symbol()

Expand All @@ -38,9 +38,9 @@ export abstract class Type<
* that describe the type of an expression.
*/
export declare class RuntimeType<T extends Type = any> {
readonly name: string
protected [kTypeId]: number
protected [kTypeArrayId]: number | undefined
protected [kTypeName]: string
protected [kTypeTokenizer]: ValueTokenizer | undefined
/** Exists for type inference */
protected declare compilerType: T
Expand All @@ -55,9 +55,9 @@ export const defineType = <T extends Type>(
tokenizer?: ValueTokenizer
): RuntimeType<T> =>
({
name,
[kTypeId]: id,
[kTypeArrayId]: arrayId,
[kTypeName]: name,
[kTypeTokenizer]: tokenizer,
} as any)

Expand Down Expand Up @@ -114,7 +114,7 @@ export function isExpressionType(val: any): val is ExpressionType {

export function isBoolExpression(val: any): val is Expression<t.bool> {
const exprType = isExpression(val) && val[kRuntimeType]
return !!exprType && exprType[kTypeName] == 'bool'
return !!exprType && exprType.name == 'bool'
}

export function isCallExpression(
Expand All @@ -126,5 +126,5 @@ export function isCallExpression(
}

export function isArrayType(val: any): val is Type {
return kTypeName in val && val[kTypeName].endsWith('[]')
return kTypeId in val && val.name.endsWith('[]')
}

0 comments on commit 0ccf7f7

Please sign in to comment.