knex 3.2.10 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/index.d.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  import type { EventEmitter } from 'events';
10
10
  import type { Duplex, PassThrough, Stream } from 'stream';
11
11
  import type { Pool } from 'tarn';
12
+ import type { PoolOptions } from 'tarn/dist/Pool';
12
13
  import type { ConnectionOptions } from 'tls';
13
14
 
14
15
  import type { Registry } from './result';
@@ -482,6 +483,10 @@ declare namespace knex {
482
483
 
483
484
  export class KnexTimeoutError extends Error {}
484
485
 
486
+ export class KnexPool<T = any> extends Pool<T> {
487
+ constructor(config: PoolOptions<T>);
488
+ }
489
+
485
490
  export const Client: typeof Knex.Client;
486
491
  }
487
492
 
@@ -1704,7 +1709,10 @@ declare namespace Knex {
1704
1709
  TResult
1705
1710
  >;
1706
1711
 
1707
- (object: Readonly<Record<string, any>>): QueryBuilder<TRecord, TResult>;
1712
+ // note: `Object` is intentional here: its mapped members preserve excess-property
1713
+ // checking so `.where({ unknownColumn })` stays a compile error, while still
1714
+ // accepting pre-typed dynamic objects, see #6452
1715
+ (object: Readonly<Object>): QueryBuilder<TRecord, TResult>;
1708
1716
 
1709
1717
  <T extends keyof ResolveTableType<TRecord>>(
1710
1718
  columnName: T,
@@ -2757,6 +2765,14 @@ declare namespace Knex {
2757
2765
  jsonbSupport?: boolean;
2758
2766
  version?: string;
2759
2767
  connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
2768
+ /**
2769
+ * An external pool to use instead of knex creating its own.
2770
+ * Accepts a KnexPool, tarn Pool, or a native driver pool (pg.Pool,
2771
+ * mysql.createPool(), oracledb.createPool()).
2772
+ * Mutually exclusive with `connection` — knex does not own the pool
2773
+ * lifecycle; call pool.end() / pool.close() yourself when done.
2774
+ */
2775
+ connectionPool?: ConnectionPool;
2760
2776
  pool?: PoolConfig;
2761
2777
  migrations?: MigratorConfig;
2762
2778
  postProcessResponse?: (result: any, queryContext: any) => any;
@@ -2817,7 +2833,8 @@ declare namespace Knex {
2817
2833
  | 'azure-active-directory-access-token'
2818
2834
  | 'azure-active-directory-msi-vm'
2819
2835
  | 'azure-active-directory-msi-app-service'
2820
- | 'azure-active-directory-service-principal-secret';
2836
+ | 'azure-active-directory-service-principal-secret'
2837
+ | 'token-credential';
2821
2838
 
2822
2839
  interface MsSqlDefaultAuthenticationConfig extends MsSqlConnectionConfigBase {
2823
2840
  type?: 'default' | never;
@@ -2895,6 +2912,19 @@ declare namespace Knex {
2895
2912
  tenantId: string;
2896
2913
  }
2897
2914
 
2915
+ interface MsSqlTokenCredential {
2916
+ getToken(
2917
+ scopes: string | string[],
2918
+ options?: unknown
2919
+ ): Promise<{ token: string; expiresOnTimestamp: number } | null>;
2920
+ }
2921
+
2922
+ interface MsSqlTokenCredentialAuthenticationConfig
2923
+ extends MsSqlConnectionConfigBase {
2924
+ type: 'token-credential';
2925
+ credential: MsSqlTokenCredential;
2926
+ }
2927
+
2898
2928
  interface MsSqlNtlmAuthenticationConfig extends MsSqlConnectionConfigBase {
2899
2929
  type: 'ntlm';
2900
2930
  /**
@@ -2914,7 +2944,8 @@ declare namespace Knex {
2914
2944
  | MsSqlAzureActiveDirectoryMsiAppServiceAuthenticationConfig
2915
2945
  | MsSqlAzureActiveDirectoryMsiVmAuthenticationConfig
2916
2946
  | MsSqlAzureActiveDirectoryPasswordAuthenticationConfig
2917
- | MsSqlAzureActiveDirectoryServicePrincipalSecretConfig;
2947
+ | MsSqlAzureActiveDirectoryServicePrincipalSecretConfig
2948
+ | MsSqlTokenCredentialAuthenticationConfig;
2918
2949
 
2919
2950
  // Config object for tedious: see http://tediousjs.github.io/tedious/api-connection.html
2920
2951
  interface MsSqlConnectionConfigBase {
@@ -3124,6 +3155,46 @@ declare namespace Knex {
3124
3155
  expirationChecker?(): boolean;
3125
3156
  }
3126
3157
 
3158
+ // Pool-like interfaces matching the shapes of native driver pools.
3159
+ // These allow `connectionPool` to accept pools from pg, mysql/mysql2,
3160
+ // oracledb, or any tarn-compatible pool without importing driver types.
3161
+
3162
+ /** Matches the pg.Pool interface */
3163
+ interface PgPoolLike {
3164
+ connect(): Promise<any>;
3165
+ end(): Promise<void>;
3166
+ totalCount: number;
3167
+ idleCount: number;
3168
+ waitingCount: number;
3169
+ }
3170
+
3171
+ /** Matches the mysql / mysql2 pool interface */
3172
+ interface MySQLPoolLike {
3173
+ getConnection(cb: (err: Error | null, connection: any) => void): void;
3174
+ end(cb?: (err?: Error) => void): void;
3175
+ }
3176
+
3177
+ /** Matches the oracledb pool interface */
3178
+ interface OraclePoolLike {
3179
+ getConnection(): Promise<any>;
3180
+ close(drainTime?: number): Promise<void>;
3181
+ }
3182
+
3183
+ /** Any tarn-compatible pool (including KnexPool) */
3184
+ interface TarnPoolLike {
3185
+ acquire(): { promise: Promise<any> };
3186
+ release(resource: any): boolean;
3187
+ destroy(): Promise<void>;
3188
+ }
3189
+
3190
+ /** Types accepted by the `connectionPool` config option */
3191
+ type ConnectionPool =
3192
+ | Pool<any>
3193
+ | TarnPoolLike
3194
+ | PgPoolLike
3195
+ | MySQLPoolLike
3196
+ | OraclePoolLike;
3197
+
3127
3198
  interface PoolConfig {
3128
3199
  name?: string;
3129
3200
  afterCreate?: Function;
@@ -3209,6 +3280,8 @@ declare namespace Knex {
3209
3280
  list(config?: MigratorConfig): Promise<any>;
3210
3281
  up(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
3211
3282
  down(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
3283
+ to(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
3284
+ before(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
3212
3285
  forceFreeMigrationsLock(config?: MigratorConfig): Promise<any>;
3213
3286
  }
3214
3287
 
@@ -3310,7 +3383,8 @@ declare namespace Knex {
3310
3383
  };
3311
3384
  getPoolSettings(poolConfig: any): any;
3312
3385
  initializePool(config?: {}): void;
3313
- pool: Pool<any> | undefined;
3386
+ initializeExternalPool(externalPool: ConnectionPool): void;
3387
+ pool: Pool<any> | TarnPoolLike | undefined;
3314
3388
  acquireConnection(): any;
3315
3389
  releaseConnection(connection: any): any;
3316
3390
  destroy(callback: any): any;