diff --git a/src/db/core.ts b/src/db/core.ts index 30b2825..8106379 100644 --- a/src/db/core.ts +++ b/src/db/core.ts @@ -122,7 +122,12 @@ export const toBuffer = strict((ba: ByteArrayString) => Buffer.from(ba.slice(2), * stringified or cast to `json` (again irrespective of the configuration * parameters `castArrayParamsToJson` and `castObjectParamsToJson`). */ -export class Parameter { constructor(public value: T, public cast?: boolean | string) { } } +export class Parameter { + // Make it a nominal type + // @ts-expect-error + private readonly name = 'Parameter'; + constructor(public value: T, public cast?: boolean | string) { } +} /** * Returns a `Parameter` instance, which compiles to a numbered query parameter @@ -145,7 +150,12 @@ export function param(x: T, cast?: boolean | string) { return new Param * Compiles to the wrapped string value, as is, which may enable SQL injection * attacks. */ -export class DangerousRawString { constructor(public value: string) { } } +export class DangerousRawString { + // Make it a nominal type + // @ts-expect-error + private readonly name = 'DangerousRawString'; + constructor(public value: string) { } +} /** * 💥💥💣 **DANGEROUS** 💣💥💥 @@ -164,7 +174,12 @@ export function raw(x: string) { return new DangerousRawString(x); } * list of array values (for use in a `SELECT` query) or object keys (for use * in an `INSERT`, `UPDATE` or `UPSERT` query, alongside `ColumnValues`). */ -export class ColumnNames { constructor(public value: T) { } } +export class ColumnNames { + // Make it a nominal type + // @ts-expect-error + private readonly name = 'ColumnNames'; + constructor(public value: T) { } +} /** * Returns a `ColumnNames` instance, wrapping either an array or an object. * `ColumnNames` compiles to a quoted, comma-separated list of array values (for @@ -177,7 +192,12 @@ export function cols(x: T) { return new ColumnNames(x); } * Compiles to a quoted, comma-separated list of object keys for use in an * `INSERT`, `UPDATE` or `UPSERT` query, alongside `ColumnNames`. */ -export class ColumnValues { constructor(public value: T) { } } +export class ColumnValues { + // Make it a nominal type + // @ts-expect-error + private readonly name = 'ColumnValues'; + constructor(public value: T) { } +} /** * Returns a ColumnValues instance, wrapping an object. ColumnValues compiles to * a quoted, comma-separated list of object keys for use in an INSERT, UPDATE @@ -189,7 +209,12 @@ export function vals(x: T) { return new ColumnValues(x); } * Compiles to the name of the column it wraps in the table of the parent query. * @param value The column name */ -export class ParentColumn { constructor(public value: T) { } } +export class ParentColumn { + // Make it a nominal type + // @ts-expect-error + private readonly name = 'ParentColumn'; + constructor(public value: T) { } +} /** * Returns a `ParentColumn` instance, wrapping a column name, which compiles to * that column name of the table of the parent query. @@ -198,7 +223,7 @@ export function parent(x: T) { return new ParentColum export type GenericSQLExpression = SQLFragment | Parameter | DefaultType | DangerousRawString | SelfType; -export type SQLExpression = Table | ColumnNames | ColumnValues | Whereable | Column | GenericSQLExpression; +export type SQLExpression = Table | ColumnNames | ColumnValues | Whereable | Column | GenericSQLExpression; export type SQL = SQLExpression | SQLExpression[]; export type Queryable = pg.ClientBase | pg.Pool; @@ -223,6 +248,9 @@ export function sql< let preparedNameSeq = 0; export class SQLFragment { + // Make it a nominal type + // @ts-expect-error + private readonly name = 'SQLFragment'; protected constraint?: Constraint; /**