From 26fcfa878ee068057be27568ede1e62381ea14ad Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Thu, 18 Jul 2019 21:02:52 +0200 Subject: [PATCH] feat(slonik): add types for new API (#36957) * feat: add types for new API (https://github.com/gajus/slonik/compare/v18.1.1...v18.2.0) * feat: update slonik version * fix: lint errors * test(slonik): add tests for createSqlTag API * test(slonik): fix codestyle --- types/slonik/index.d.ts | 10 +++++++++- types/slonik/slonik-tests.ts | 32 +++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/types/slonik/index.d.ts b/types/slonik/index.d.ts index 1db5da53c3..86c17bfba5 100644 --- a/types/slonik/index.d.ts +++ b/types/slonik/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for slonik 16.16 +// Type definitions for slonik 18.2 // Project: https://github.com/gajus/slonik#readme // Definitions by: Sebastian Sebald // Misha Kaletsky @@ -292,6 +292,14 @@ export interface TaggedTemplateLiteralInvocationType string; + +export interface SqlTagConfigurationType { + normalizeIdentifier?: IdentifierNormalizerType; +} + +export function createSqlTag(configuration?: SqlTagConfigurationType): SqlTaggedTemplateType; + export interface SqlTaggedTemplateType { // tslint:disable-next-line no-unnecessary-generics (the sql`select foo` is cleaner in this case than casting with 'as') (template: TemplateStringsArray, ...vals: ValueExpressionType[]): SqlSqlTokenType; diff --git a/types/slonik/slonik-tests.ts b/types/slonik/slonik-tests.ts index 1d17b3361f..0b1dbc9fbc 100644 --- a/types/slonik/slonik-tests.ts +++ b/types/slonik/slonik-tests.ts @@ -1,4 +1,6 @@ import { + createSqlTag, + IdentifierNormalizerType, CheckIntegrityConstraintViolationError, createBenchmarkingInterceptor, createBigintTypeParser, @@ -22,7 +24,8 @@ import { SlonikError, sql, TypeParserType, - UniqueIntegrityConstraintViolationError + UniqueIntegrityConstraintViolationError, + SqlTaggedTemplateType } from 'slonik'; import { ArrayTokenSymbol, TupleListTokenSymbol } from 'slonik/symbols'; @@ -326,6 +329,33 @@ createTimestampWithTimeZoneTypeParser(); `; })(); +// +// createSQLTag +// ---------------------------------------------------------------------- +(() => { + let sql: SqlTaggedTemplateType; + + sql = createSqlTag(); + + sql` + SELECT 1; + `; + + let normalizeIdentifier: IdentifierNormalizerType; + + normalizeIdentifier = (input: string) => + input + .split('') + .reverse() + .join(''); + + sql = createSqlTag({ + normalizeIdentifier, + }); + + sql = createSqlTag({}); +}); + // // ERRORS // ----------------------------------------------------------------------