@prisma/driver-adapter-utils
Advanced tools
Comparing version 6.5.0-integration-fix-e2e-prisma-config-2.9 to 6.5.0-integration-fix-improve-global-omit-api-performance.1
import { Debug } from '@prisma/debug'; | ||
/** | ||
* An interface that exposes some basic information about the | ||
* adapter like its name and provider type. | ||
*/ | ||
declare interface AdapterInfo { | ||
readonly provider: Provider; | ||
readonly adapterName: (typeof officialPrismaAdapters)[number] | (string & {}); | ||
} | ||
/** | ||
* Original `quaint::ValueType` enum tag from Prisma's `quaint`. | ||
@@ -10,3 +19,3 @@ * Query arguments marked with this type are sanitized before being sent to the database. | ||
export declare const bindAdapter: (adapter: DriverAdapter) => ErrorCapturingDriverAdapter; | ||
export declare const bindAdapter: (adapter: SqlConnection) => ErrorCapturingSqlConnection; | ||
@@ -57,13 +66,19 @@ export declare type ColumnType = (typeof ColumnTypeEnum)[keyof typeof ColumnTypeEnum]; | ||
export declare interface DriverAdapter extends Queryable { | ||
/** | ||
* A generic driver adapter that allows the user to connect to a | ||
* database. The query and result types are specific to the adapter. | ||
*/ | ||
declare interface DriverAdapter_2<Query, Result> extends AdapterInfo { | ||
/** | ||
* Starts new transaction. | ||
* Connect to the database. | ||
*/ | ||
transactionContext(): Promise<Result<TransactionContext>>; | ||
/** | ||
* Optional method that returns extra connection info | ||
*/ | ||
getConnectionInfo?(): Result<ConnectionInfo>; | ||
connect(): Promise<Queryable<Query, Result>>; | ||
} | ||
export declare class DriverAdapterError extends Error { | ||
name: string; | ||
cause: Error_2; | ||
constructor(payload: Error_2); | ||
} | ||
export declare function err<T>(error: Error_2): Result<T>; | ||
@@ -100,6 +115,20 @@ | ||
export declare interface ErrorCapturingDriverAdapter extends DriverAdapter { | ||
declare type ErrorCapturingFunction<T> = T extends (...args: infer A) => Promise<infer R> ? (...args: A) => Promise<Result<ErrorCapturingInterface<R>>> : T extends (...args: infer A) => infer R ? (...args: A) => Result<ErrorCapturingInterface<R>> : T; | ||
declare type ErrorCapturingInterface<T> = { | ||
[K in keyof T]: ErrorCapturingFunction<T[K]>; | ||
}; | ||
declare interface ErrorCapturingSqlConnection extends ErrorCapturingInterface<SqlConnection> { | ||
readonly errorRegistry: ErrorRegistry; | ||
} | ||
export { ErrorCapturingSqlConnection as ErrorCapturingDriverAdapter } | ||
export { ErrorCapturingSqlConnection } | ||
export declare type ErrorCapturingSqlQueryable = ErrorCapturingInterface<SqlQueryable>; | ||
export declare type ErrorCapturingTransaction = ErrorCapturingInterface<Transaction>; | ||
export declare type ErrorCapturingTransactionContext = ErrorCapturingInterface<TransactionContext>; | ||
export declare type ErrorRecord = { | ||
@@ -119,26 +148,11 @@ error: unknown; | ||
export declare type Query = { | ||
sql: string; | ||
args: Array<unknown>; | ||
argTypes: Array<ArgType>; | ||
}; | ||
export declare interface Queryable { | ||
readonly provider: Provider; | ||
readonly adapterName: (typeof officialPrismaAdapters)[number] | (string & {}); | ||
declare interface Queryable<Query, Result> extends AdapterInfo { | ||
/** | ||
* Execute a query given as SQL, interpolating the given parameters, | ||
* and returning the type-aware result set of the query. | ||
* | ||
* This is the preferred way of executing `SELECT` queries. | ||
* Execute a query and return its result. | ||
*/ | ||
queryRaw(params: Query): Promise<Result<ResultSet>>; | ||
queryRaw(params: Query): Promise<Result>; | ||
/** | ||
* Execute a query given as SQL, interpolating the given parameters, | ||
* and returning the number of affected rows. | ||
* | ||
* This is the preferred way of executing `INSERT`, `UPDATE`, `DELETE` queries, | ||
* as well as transactional queries. | ||
* Execute a query and return the number of affected rows. | ||
*/ | ||
executeRaw(params: Query): Promise<Result<number>>; | ||
executeRaw(params: Query): Promise<number>; | ||
} | ||
@@ -157,4 +171,46 @@ | ||
export declare interface ResultSet { | ||
declare interface SqlConnection extends SqlQueryable { | ||
/** | ||
* Execute multiple SQL statements separated by semicolon. | ||
*/ | ||
executeScript(script: string): Promise<void>; | ||
/** | ||
* Start new transaction. | ||
*/ | ||
transactionContext(): Promise<TransactionContext>; | ||
/** | ||
* Optional method that returns extra connection info | ||
*/ | ||
getConnectionInfo?(): ConnectionInfo; | ||
/** | ||
* Dispose of the connection and release any resources. | ||
*/ | ||
dispose(): Promise<void>; | ||
} | ||
export { SqlConnection as DriverAdapter } | ||
export { SqlConnection } | ||
declare interface SqlDriverAdapter extends DriverAdapter_2<SqlQuery, SqlResultSet> { | ||
connect(): Promise<SqlConnection>; | ||
} | ||
/** | ||
* An SQL migration adapter that is aware of the notion of a shadow database | ||
* and can create a connection to it. | ||
*/ | ||
export declare interface SqlMigrationAwareDriverAdapter extends SqlDriverAdapter { | ||
connectToShadowDb(): Promise<SqlConnection>; | ||
} | ||
export declare type SqlQuery = { | ||
sql: string; | ||
args: Array<unknown>; | ||
argTypes: Array<ArgType>; | ||
}; | ||
export declare interface SqlQueryable extends Queryable<SqlQuery, SqlResultSet> { | ||
} | ||
export declare interface SqlResultSet { | ||
/** | ||
* List of column types appearing in a database query, in the same order as `columnNames`. | ||
@@ -180,3 +236,3 @@ * They are used within the Query Engine to convert values from JS to Quaint values. | ||
export declare interface Transaction extends Queryable { | ||
export declare interface Transaction extends AdapterInfo, SqlQueryable { | ||
/** | ||
@@ -189,14 +245,14 @@ * Transaction options. | ||
*/ | ||
commit(): Promise<Result<void>>; | ||
commit(): Promise<void>; | ||
/** | ||
* Rolls back the transaction. | ||
* Roll back the transaction. | ||
*/ | ||
rollback(): Promise<Result<void>>; | ||
rollback(): Promise<void>; | ||
} | ||
export declare interface TransactionContext extends Queryable { | ||
export declare interface TransactionContext extends AdapterInfo, SqlQueryable { | ||
/** | ||
* Starts new transaction. | ||
* Start new transaction. | ||
*/ | ||
startTransaction(): Promise<Result<Transaction>>; | ||
startTransaction(): Promise<Transaction>; | ||
} | ||
@@ -203,0 +259,0 @@ |
@@ -25,2 +25,3 @@ "use strict"; | ||
Debug: () => import_debug.Debug, | ||
DriverAdapterError: () => DriverAdapterError, | ||
bindAdapter: () => bindAdapter, | ||
@@ -32,2 +33,14 @@ err: () => err, | ||
// src/error.ts | ||
var DriverAdapterError = class extends Error { | ||
constructor(payload) { | ||
super(typeof payload["message"] === "string" ? payload["message"] : payload.kind); | ||
this.name = "DriverAdapterError"; | ||
this.cause = payload; | ||
} | ||
}; | ||
function isDriverAdapterError(error) { | ||
return error["name"] === "DriverAdapterError" && typeof error["cause"] === "object"; | ||
} | ||
// src/result.ts | ||
@@ -84,6 +97,8 @@ function ok(value) { | ||
executeRaw: wrapAsync(errorRegistry, adapter.executeRaw.bind(adapter)), | ||
executeScript: wrapAsync(errorRegistry, adapter.executeScript.bind(adapter)), | ||
dispose: wrapAsync(errorRegistry, adapter.dispose.bind(adapter)), | ||
provider: adapter.provider, | ||
transactionContext: async (...args) => { | ||
const ctx = await createTransactionContext(...args); | ||
return ctx.map((tx) => bindTransactionContext(errorRegistry, tx)); | ||
return ctx.map((ctx2) => bindTransactionContext(errorRegistry, ctx2)); | ||
} | ||
@@ -123,4 +138,7 @@ }; | ||
try { | ||
return await fn(...args); | ||
return ok(await fn(...args)); | ||
} catch (error) { | ||
if (isDriverAdapterError(error)) { | ||
return err(error.cause); | ||
} | ||
const id = registry.registerNewError(error); | ||
@@ -134,4 +152,7 @@ return err({ kind: "GenericJs", id }); | ||
try { | ||
return fn(...args); | ||
return ok(fn(...args)); | ||
} catch (error) { | ||
if (isDriverAdapterError(error)) { | ||
return err(error.cause); | ||
} | ||
const id = registry.registerNewError(error); | ||
@@ -188,2 +209,3 @@ return err({ kind: "GenericJs", id }); | ||
Debug, | ||
DriverAdapterError, | ||
bindAdapter, | ||
@@ -190,0 +212,0 @@ err, |
{ | ||
"name": "@prisma/driver-adapter-utils", | ||
"version": "6.5.0-integration-fix-e2e-prisma-config-2.9", | ||
"version": "6.5.0-integration-fix-improve-global-omit-api-performance.1", | ||
"description": "Internal set of utilities and types for Prisma's driver adapters.", | ||
@@ -34,3 +34,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@prisma/debug": "6.5.0-integration-fix-e2e-prisma-config-2.9" | ||
"@prisma/debug": "6.5.0-integration-fix-improve-global-omit-api-performance.1" | ||
}, | ||
@@ -37,0 +37,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
38003
597