diff --git a/package.json b/package.json index b7bc5dc9..22eff179 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg-promise", - "version": "10.14.0", + "version": "10.14.1", "description": "PostgreSQL interface for Node.js", "main": "lib/index.js", "typings": "typescript/pg-promise.d.ts", @@ -55,6 +55,6 @@ "JSONStream": "1.3.5", "pg-query-stream": "4.2.4", "tslint": "6.1.3", - "typescript": "4.8.4" + "typescript": "4.9.3" } } diff --git a/test/typescript/tx-mode.ts b/test/typescript/tx-mode.ts index 518ab359..ec0b8173 100644 --- a/test/typescript/tx-mode.ts +++ b/test/typescript/tx-mode.ts @@ -3,9 +3,13 @@ import * as pgPromise from '../../typescript/pg-promise'; const pgp: pgPromise.IMain = pgPromise(); const db: pgPromise.IDatabase<any> = pgp('connection'); -const {TransactionMode} = pgPromise; +const {TransactionMode} = pgPromise.txMode; -const mode = new TransactionMode({deferrable: true, readOnly: true, tiLevel: pgPromise.isolationLevel.readCommitted}); +const mode = new TransactionMode({ + deferrable: true, + readOnly: true, + tiLevel: pgPromise.txMode.isolationLevel.readCommitted +}); db.tx<number>({mode: null}, t => { return 123; diff --git a/test/typescript/types.ts b/test/typescript/types.ts index 85ef17c0..28accf10 100644 --- a/test/typescript/types.ts +++ b/test/typescript/types.ts @@ -28,12 +28,10 @@ import { ITaskContext, IEventContext, errors, - isolationLevel, - TransactionMode, IInitOptions, ILibConfig, IFormatting, - ITXMode, + txMode, IUtils, IHelpers, IGenericPromise, diff --git a/typescript/pg-promise.d.ts b/typescript/pg-promise.d.ts index cf2f5324..bf30428c 100644 --- a/typescript/pg-promise.d.ts +++ b/typescript/pg-promise.d.ts @@ -21,6 +21,26 @@ import * as pg from './pg-subset'; import * as pgMinify from 'pg-minify'; import * as spexLib from 'spex'; +// internal txMode namespace; +declare namespace txModeNamespace { + // Transaction Isolation Level; + // API: http://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel + enum isolationLevel { + none = 0, + serializable = 1, + repeatableRead = 2, + readCommitted = 3 + } + + // TransactionMode class; + // API: http://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html + class TransactionMode { + constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean }) + + begin(cap?: boolean): string + } +} + // Main protocol of the library; // API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html declare namespace pgPromise { @@ -269,7 +289,7 @@ declare namespace pgPromise { constructor(api: IPromiseConfig) } - const txMode: ITXMode; + const txMode: typeof txModeNamespace; const utils: IUtils; const as: IFormatting; @@ -311,7 +331,7 @@ declare namespace pgPromise { readonly spex: spexLib.ISpex readonly errors: typeof errors readonly utils: IUtils - readonly txMode: ITXMode + readonly txMode: typeof txMode readonly helpers: IHelpers readonly as: IFormatting readonly pg: typeof pg @@ -398,7 +418,7 @@ declare namespace pgPromise { tx<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T> - tx<T = any>(options: { tag?: any, mode?: TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T> + tx<T = any>(options: { tag?: any, mode?: txModeNamespace.TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T> // Conditional Transactions; // API: http://vitaly-t.github.io/pg-promise/Database.html#txIf @@ -406,7 +426,7 @@ declare namespace pgPromise { txIf<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T> - txIf<T = any>(options: { tag?: any, mode?: TransactionMode | null, reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean), cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T> + txIf<T = any>(options: { tag?: any, mode?: txModeNamespace.TransactionMode | null, reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean), cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T> } // Database object in connected state; @@ -546,23 +566,6 @@ declare namespace pgPromise { } } - // Transaction Isolation Level; - // API: http://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel - enum isolationLevel { - none = 0, - serializable = 1, - repeatableRead = 2, - readCommitted = 3 - } - - // TransactionMode class; - // API: http://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html - class TransactionMode { - constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean }) - - begin(cap?: boolean): string - } - // Library's Initialization Options // API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html interface IInitOptions<Ext = {}, C extends pg.IClient = pg.IClient> { @@ -641,15 +644,8 @@ declare namespace pgPromise { value(value: any | (() => any)): string } - // Transaction Mode namespace; - // API: http://vitaly-t.github.io/pg-promise/txMode.html - interface ITXMode { - isolationLevel: typeof isolationLevel - TransactionMode: typeof TransactionMode - } - interface ITaskArguments<T> extends IArguments { - options: { tag?: any, cnd?: any, mode?: TransactionMode | null } & T + options: { tag?: any, cnd?: any, mode?: txModeNamespace.TransactionMode | null } & T cb(): any }