Skip to content

Commit

Permalink
fixing typescript declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 16, 2022
1 parent e0d5b3f commit 8e96d6b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
8 changes: 6 additions & 2 deletions test/typescript/tx-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions test/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import {
ITaskContext,
IEventContext,
errors,
isolationLevel,
TransactionMode,
IInitOptions,
ILibConfig,
IFormatting,
ITXMode,
txMode,
IUtils,
IHelpers,
IGenericPromise,
Expand Down
54 changes: 25 additions & 29 deletions typescript/pg-promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -269,7 +289,7 @@ declare namespace pgPromise {
constructor(api: IPromiseConfig)
}

const txMode: ITXMode;
const txMode: typeof txModeNamespace;
const utils: IUtils;
const as: IFormatting;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -398,15 +418,15 @@ 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
txIf<T = any>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>

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;
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8e96d6b

Please sign in to comment.