Skip to content

Commit

Permalink
fix: add map to the ts definitions file (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-clarson authored Jul 4, 2023
1 parent 4d07023 commit 9e54b38
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions SQL.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ declare class SqlStatement implements StatementLike {
*/
static glue(pieces: StatementLike[], separator: string): SqlStatement

/**
* A function that accepts an array of objects and a mapper function
* It returns a clean SQL format using the object properties defined in the mapper function
* @param array the items to be mapped over
* @param mapFunc a function to transform the items in `array` before being added to the SqlStatement
* @example
* SQL`SELECT ${SQL.map([1,2,3])}`
* @example
* SQL`SELECT ${SQL.map([1,2,3], x => x ** 2)}`
*/
map<T>(array: T[], mapFunc?: (item: T) => unknown): SqlStatement

/**
* A function that accepts an array of objects and a mapper function
* It returns a clean SQL format using the object properties defined in the mapper function
* @param array the items to be mapped over
* @param mapFunc a function to transform the items in `array` before being added to the SqlStatement
* @example
* SQL`SELECT ${SQL.map([1,2,3])}`
* @example
* SQL`SELECT ${SQL.map([1,2,3], x => x ** 2)}`
*/
static map<T>(array: T[], mapFunc?: (item: T) => unknown): SqlStatement

/** Returns a formatted but unsafe statement of strings and values, useful for debugging */
get debug(): string

Expand Down Expand Up @@ -85,6 +109,18 @@ declare namespace SQL {
*/
export function glue(pieces: StatementLike[], separator: string): SqlStatement

/**
* A function that accepts an array of objects and a mapper function
* It returns a clean SQL format using the object properties defined in the mapper function
* @param array the items to be mapped over
* @param mapFunc a function to transform the items in `array` before being added to the SqlStatement
* @example
* SQL`SELECT ${SQL.map([1,2,3])}`
* @example
* SQL`SELECT ${SQL.map([1,2,3], x => x ** 2)}`
*/
export function map<T>(array: T[], mapFunc?: (item: T) => unknown): SqlStatement

export function unsafe<T>(value: T): { value: T }
export function quoteIdent(value: string): { value: string }
}
Expand Down
6 changes: 5 additions & 1 deletion SQL.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SQL from '.'
import { glue, SqlStatement } from '.'
import { glue, map, SqlStatement } from '.'
import { expectType, expectError } from 'tsd'

expectType<SqlStatement>(SQL`SELECT 1`)
Expand All @@ -8,6 +8,10 @@ expectType<SqlStatement>(SQL`SELECT `.append(SQL`1`))
expectType<SQL.SqlStatement>(SQL`SELECT `.append(SQL`1`))
expectType<SqlStatement>(glue([SQL`SELECT`, SQL`1`], ' '))
expectType<SQL.SqlStatement>(SQL.glue([SQL`SELECT`, SQL`1`], ' '))
expectType<SQL.SqlStatement>(SQL.map([1,2,3]))
expectType<SQL.SqlStatement>(SQL.map([1,2,3], x => x**2))
expectType<SQL.SqlStatement>(map([1,2,3]))
expectType<SQL.SqlStatement>(map([1,2,3], x => x**2))
expectType<string>(SQL`SELECT 1`.debug)
expectType<string>(SQL`SELECT 1`.sql)
expectType<string>(SQL`SELECT 1`.text)
Expand Down

0 comments on commit 9e54b38

Please sign in to comment.