first commit

This commit is contained in:
Ichitux
2026-04-05 03:08:53 +02:00
commit 1082d36c12
28015 changed files with 3767672 additions and 0 deletions

View File

@@ -0,0 +1,403 @@
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 & {});
}
export declare type ArgScalarType = 'string' | 'int' | 'bigint' | 'float' | 'decimal' | 'boolean' | 'enum' | 'uuid' | 'json' | 'datetime' | 'bytes' | 'unknown';
export declare type ArgType = {
scalarType: ArgScalarType;
dbType?: string;
arity: Arity;
};
export declare type Arity = 'scalar' | 'list';
export declare const bindAdapter: (adapter: SqlDriverAdapter, errorRegistry?: ErrorRegistryInternal) => ErrorCapturingSqlDriverAdapter;
export declare const bindMigrationAwareSqlAdapterFactory: (adapterFactory: SqlMigrationAwareDriverAdapterFactory) => ErrorCapturingSqlMigrationAwareDriverAdapterFactory;
export declare const bindSqlAdapterFactory: (adapterFactory: SqlDriverAdapterFactory) => ErrorCapturingSqlDriverAdapterFactory;
export declare type ColumnType = (typeof ColumnTypeEnum)[keyof typeof ColumnTypeEnum];
export declare const ColumnTypeEnum: {
readonly Int32: 0;
readonly Int64: 1;
readonly Float: 2;
readonly Double: 3;
readonly Numeric: 4;
readonly Boolean: 5;
readonly Character: 6;
readonly Text: 7;
readonly Date: 8;
readonly Time: 9;
readonly DateTime: 10;
readonly Json: 11;
readonly Enum: 12;
readonly Bytes: 13;
readonly Set: 14;
readonly Uuid: 15;
readonly Int32Array: 64;
readonly Int64Array: 65;
readonly FloatArray: 66;
readonly DoubleArray: 67;
readonly NumericArray: 68;
readonly BooleanArray: 69;
readonly CharacterArray: 70;
readonly TextArray: 71;
readonly DateArray: 72;
readonly TimeArray: 73;
readonly DateTimeArray: 74;
readonly JsonArray: 75;
readonly EnumArray: 76;
readonly BytesArray: 77;
readonly UuidArray: 78;
readonly UnknownNumber: 128;
};
export declare type ConnectionInfo = {
schemaName?: string;
maxBindValues?: number;
supportsRelationJoins: boolean;
};
export { Debug }
export declare class DriverAdapterError extends Error {
name: string;
cause: Error_2;
constructor(payload: Error_2);
}
/**
* A generic driver adapter factory that allows the user to instantiate a
* driver adapter. The query and result types are specific to the adapter.
*/
export declare interface DriverAdapterFactory<Query, Result> extends AdapterInfo {
/**
* Instantiate a driver adapter.
*/
connect(): Promise<Queryable<Query, Result>>;
}
export declare function err<T>(error: Error_2): Result<T>;
declare type Error_2 = MappedError & {
originalCode?: string;
originalMessage?: string;
};
export { Error_2 as Error }
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]>;
};
export declare interface ErrorCapturingSqlDriverAdapter extends ErrorCapturingInterface<SqlDriverAdapter> {
readonly errorRegistry: ErrorRegistry;
}
export declare interface ErrorCapturingSqlDriverAdapterFactory extends ErrorCapturingInterface<SqlDriverAdapterFactory> {
readonly errorRegistry: ErrorRegistry;
}
export declare interface ErrorCapturingSqlMigrationAwareDriverAdapterFactory extends ErrorCapturingInterface<SqlMigrationAwareDriverAdapterFactory> {
readonly errorRegistry: ErrorRegistry;
}
export declare type ErrorCapturingSqlQueryable = ErrorCapturingInterface<SqlQueryable>;
export declare type ErrorCapturingTransaction = ErrorCapturingInterface<Transaction>;
export declare type ErrorRecord = {
error: unknown;
};
export declare interface ErrorRegistry {
consumeError(id: number): ErrorRecord | undefined;
}
declare class ErrorRegistryInternal implements ErrorRegistry {
private registeredErrors;
consumeError(id: number): ErrorRecord | undefined;
registerNewError(error: unknown): number;
}
export declare function isDriverAdapterError(error: any): error is DriverAdapterError;
export declare type IsolationLevel = 'READ UNCOMMITTED' | 'READ COMMITTED' | 'REPEATABLE READ' | 'SNAPSHOT' | 'SERIALIZABLE';
export declare type MappedError = {
kind: 'GenericJs';
id: number;
} | {
kind: 'UnsupportedNativeDataType';
type: string;
} | {
kind: 'InvalidIsolationLevel';
level: string;
} | {
kind: 'LengthMismatch';
column?: string;
} | {
kind: 'UniqueConstraintViolation';
constraint?: {
fields: string[];
} | {
index: string;
} | {
foreignKey: {};
};
} | {
kind: 'NullConstraintViolation';
constraint?: {
fields: string[];
} | {
index: string;
} | {
foreignKey: {};
};
} | {
kind: 'ForeignKeyConstraintViolation';
constraint?: {
fields: string[];
} | {
index: string;
} | {
foreignKey: {};
};
} | {
kind: 'DatabaseNotReachable';
host?: string;
port?: number;
} | {
kind: 'DatabaseDoesNotExist';
db?: string;
} | {
kind: 'DatabaseAlreadyExists';
db?: string;
} | {
kind: 'DatabaseAccessDenied';
db?: string;
} | {
kind: 'ConnectionClosed';
} | {
kind: 'TlsConnectionError';
reason: string;
} | {
kind: 'AuthenticationFailed';
user?: string;
} | {
kind: 'TransactionWriteConflict';
} | {
kind: 'TableDoesNotExist';
table?: string;
} | {
kind: 'ColumnNotFound';
column?: string;
} | {
kind: 'TooManyConnections';
cause: string;
} | {
kind: 'ValueOutOfRange';
cause: string;
} | {
kind: 'InvalidInputValue';
message: string;
} | {
kind: 'MissingFullTextSearchIndex';
} | {
kind: 'SocketTimeout';
} | {
kind: 'InconsistentColumnData';
cause: string;
} | {
kind: 'TransactionAlreadyClosed';
cause: string;
} | {
kind: 'postgres';
code: string;
severity: string;
message: string;
detail: string | undefined;
column: string | undefined;
hint: string | undefined;
} | {
kind: 'mysql';
code: number;
message: string;
state: string;
cause?: string;
} | {
kind: 'sqlite';
/**
* Sqlite extended error code: https://www.sqlite.org/rescode.html
*/
extendedCode: number;
message: string;
} | {
kind: 'mssql';
code: number;
message: string;
};
/**
* Create an adapter stub for testing.
*/
export declare function mockAdapter(provider: 'mysql' | 'sqlite' | 'postgres'): SqlDriverAdapter;
export declare const mockAdapterErrors: {
queryRaw: Error;
executeRaw: Error;
startTransaction: Error;
executeScript: Error;
dispose: Error;
};
/**
* Create an adapter factory stub for testing.
*/
export declare function mockAdapterFactory(provider: 'mysql' | 'sqlite' | 'postgres'): SqlDriverAdapterFactory;
/**
* Create an adapter factory stub for testing.
*/
export declare function mockMigrationAwareAdapterFactory(provider: 'mysql' | 'sqlite' | 'postgres'): SqlMigrationAwareDriverAdapterFactory;
export declare type OfficialDriverAdapterName = (typeof officialPrismaAdapters)[number];
declare const officialPrismaAdapters: readonly ["@prisma/adapter-planetscale", "@prisma/adapter-neon", "@prisma/adapter-libsql", "@prisma/adapter-better-sqlite3", "@prisma/adapter-d1", "@prisma/adapter-pg", "@prisma/adapter-mssql", "@prisma/adapter-mariadb"];
export declare function ok<T>(value: T): Result<T>;
export declare type Provider = 'mysql' | 'postgres' | 'sqlite' | 'sqlserver';
export declare interface Queryable<Query, Result> extends AdapterInfo {
/**
* Execute a query and return its result.
*/
queryRaw(params: Query): Promise<Result>;
/**
* Execute a query and return the number of affected rows.
*/
executeRaw(params: Query): Promise<number>;
}
export declare type Result<T> = {
map<U>(fn: (value: T) => U): Result<U>;
flatMap<U>(fn: (value: T) => Result<U>): Result<U>;
} & ({
readonly ok: true;
readonly value: T;
} | {
readonly ok: false;
readonly error: Error_2;
});
/**
* Represents a value that can be returned for a column from `queryRaw`.
*/
export declare type ResultValue = number | string | boolean | null | ResultValue[] | Uint8Array;
export declare interface SqlDriverAdapter extends SqlQueryable {
/**
* Execute multiple SQL statements separated by semicolon.
*/
executeScript(script: string): Promise<void>;
/**
* Start new transaction.
*/
startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
/**
* Optional method that returns extra connection info
*/
getConnectionInfo?(): ConnectionInfo;
/**
* Dispose of the connection and release any resources.
*/
dispose(): Promise<void>;
}
export declare interface SqlDriverAdapterFactory extends DriverAdapterFactory<SqlQuery, SqlResultSet> {
connect(): Promise<SqlDriverAdapter>;
}
/**
* An SQL migration adapter that is aware of the notion of a shadow database
* and can create a connection to it.
*/
export declare interface SqlMigrationAwareDriverAdapterFactory extends SqlDriverAdapterFactory {
connectToShadowDb(): Promise<SqlDriverAdapter>;
}
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`.
* They are used within the Query Engine to convert values from JS to Quaint values.
*/
columnTypes: Array<ColumnType>;
/**
* List of column names appearing in a database query, in the same order as `columnTypes`.
*/
columnNames: Array<string>;
/**
* List of rows retrieved from a database query.
* Each row is a list of values, whose length matches `columnNames` and `columnTypes`.
*/
rows: Array<Array<unknown>>;
/**
* The last ID of an `INSERT` statement, if any.
* This is required for `AUTO_INCREMENT` columns in databases based on MySQL and SQLite.
*/
lastInsertId?: string;
}
export declare interface Transaction extends AdapterInfo, SqlQueryable {
/**
* Transaction options.
*/
readonly options: TransactionOptions;
/**
* Commit the transaction.
*/
commit(): Promise<void>;
/**
* Roll back the transaction.
*/
rollback(): Promise<void>;
/**
* Creates a savepoint within the currently running transaction.
*/
createSavepoint?(name: string): Promise<void>;
/**
* Rolls back transaction state to a previously created savepoint.
*/
rollbackToSavepoint?(name: string): Promise<void>;
/**
* Releases a previously created savepoint. Optional because not every connector supports this operation.
*/
releaseSavepoint?(name: string): Promise<void>;
}
export declare type TransactionOptions = {
usePhantomQuery: boolean;
};
export { }

View File

@@ -0,0 +1,403 @@
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 & {});
}
export declare type ArgScalarType = 'string' | 'int' | 'bigint' | 'float' | 'decimal' | 'boolean' | 'enum' | 'uuid' | 'json' | 'datetime' | 'bytes' | 'unknown';
export declare type ArgType = {
scalarType: ArgScalarType;
dbType?: string;
arity: Arity;
};
export declare type Arity = 'scalar' | 'list';
export declare const bindAdapter: (adapter: SqlDriverAdapter, errorRegistry?: ErrorRegistryInternal) => ErrorCapturingSqlDriverAdapter;
export declare const bindMigrationAwareSqlAdapterFactory: (adapterFactory: SqlMigrationAwareDriverAdapterFactory) => ErrorCapturingSqlMigrationAwareDriverAdapterFactory;
export declare const bindSqlAdapterFactory: (adapterFactory: SqlDriverAdapterFactory) => ErrorCapturingSqlDriverAdapterFactory;
export declare type ColumnType = (typeof ColumnTypeEnum)[keyof typeof ColumnTypeEnum];
export declare const ColumnTypeEnum: {
readonly Int32: 0;
readonly Int64: 1;
readonly Float: 2;
readonly Double: 3;
readonly Numeric: 4;
readonly Boolean: 5;
readonly Character: 6;
readonly Text: 7;
readonly Date: 8;
readonly Time: 9;
readonly DateTime: 10;
readonly Json: 11;
readonly Enum: 12;
readonly Bytes: 13;
readonly Set: 14;
readonly Uuid: 15;
readonly Int32Array: 64;
readonly Int64Array: 65;
readonly FloatArray: 66;
readonly DoubleArray: 67;
readonly NumericArray: 68;
readonly BooleanArray: 69;
readonly CharacterArray: 70;
readonly TextArray: 71;
readonly DateArray: 72;
readonly TimeArray: 73;
readonly DateTimeArray: 74;
readonly JsonArray: 75;
readonly EnumArray: 76;
readonly BytesArray: 77;
readonly UuidArray: 78;
readonly UnknownNumber: 128;
};
export declare type ConnectionInfo = {
schemaName?: string;
maxBindValues?: number;
supportsRelationJoins: boolean;
};
export { Debug }
export declare class DriverAdapterError extends Error {
name: string;
cause: Error_2;
constructor(payload: Error_2);
}
/**
* A generic driver adapter factory that allows the user to instantiate a
* driver adapter. The query and result types are specific to the adapter.
*/
export declare interface DriverAdapterFactory<Query, Result> extends AdapterInfo {
/**
* Instantiate a driver adapter.
*/
connect(): Promise<Queryable<Query, Result>>;
}
export declare function err<T>(error: Error_2): Result<T>;
declare type Error_2 = MappedError & {
originalCode?: string;
originalMessage?: string;
};
export { Error_2 as Error }
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]>;
};
export declare interface ErrorCapturingSqlDriverAdapter extends ErrorCapturingInterface<SqlDriverAdapter> {
readonly errorRegistry: ErrorRegistry;
}
export declare interface ErrorCapturingSqlDriverAdapterFactory extends ErrorCapturingInterface<SqlDriverAdapterFactory> {
readonly errorRegistry: ErrorRegistry;
}
export declare interface ErrorCapturingSqlMigrationAwareDriverAdapterFactory extends ErrorCapturingInterface<SqlMigrationAwareDriverAdapterFactory> {
readonly errorRegistry: ErrorRegistry;
}
export declare type ErrorCapturingSqlQueryable = ErrorCapturingInterface<SqlQueryable>;
export declare type ErrorCapturingTransaction = ErrorCapturingInterface<Transaction>;
export declare type ErrorRecord = {
error: unknown;
};
export declare interface ErrorRegistry {
consumeError(id: number): ErrorRecord | undefined;
}
declare class ErrorRegistryInternal implements ErrorRegistry {
private registeredErrors;
consumeError(id: number): ErrorRecord | undefined;
registerNewError(error: unknown): number;
}
export declare function isDriverAdapterError(error: any): error is DriverAdapterError;
export declare type IsolationLevel = 'READ UNCOMMITTED' | 'READ COMMITTED' | 'REPEATABLE READ' | 'SNAPSHOT' | 'SERIALIZABLE';
export declare type MappedError = {
kind: 'GenericJs';
id: number;
} | {
kind: 'UnsupportedNativeDataType';
type: string;
} | {
kind: 'InvalidIsolationLevel';
level: string;
} | {
kind: 'LengthMismatch';
column?: string;
} | {
kind: 'UniqueConstraintViolation';
constraint?: {
fields: string[];
} | {
index: string;
} | {
foreignKey: {};
};
} | {
kind: 'NullConstraintViolation';
constraint?: {
fields: string[];
} | {
index: string;
} | {
foreignKey: {};
};
} | {
kind: 'ForeignKeyConstraintViolation';
constraint?: {
fields: string[];
} | {
index: string;
} | {
foreignKey: {};
};
} | {
kind: 'DatabaseNotReachable';
host?: string;
port?: number;
} | {
kind: 'DatabaseDoesNotExist';
db?: string;
} | {
kind: 'DatabaseAlreadyExists';
db?: string;
} | {
kind: 'DatabaseAccessDenied';
db?: string;
} | {
kind: 'ConnectionClosed';
} | {
kind: 'TlsConnectionError';
reason: string;
} | {
kind: 'AuthenticationFailed';
user?: string;
} | {
kind: 'TransactionWriteConflict';
} | {
kind: 'TableDoesNotExist';
table?: string;
} | {
kind: 'ColumnNotFound';
column?: string;
} | {
kind: 'TooManyConnections';
cause: string;
} | {
kind: 'ValueOutOfRange';
cause: string;
} | {
kind: 'InvalidInputValue';
message: string;
} | {
kind: 'MissingFullTextSearchIndex';
} | {
kind: 'SocketTimeout';
} | {
kind: 'InconsistentColumnData';
cause: string;
} | {
kind: 'TransactionAlreadyClosed';
cause: string;
} | {
kind: 'postgres';
code: string;
severity: string;
message: string;
detail: string | undefined;
column: string | undefined;
hint: string | undefined;
} | {
kind: 'mysql';
code: number;
message: string;
state: string;
cause?: string;
} | {
kind: 'sqlite';
/**
* Sqlite extended error code: https://www.sqlite.org/rescode.html
*/
extendedCode: number;
message: string;
} | {
kind: 'mssql';
code: number;
message: string;
};
/**
* Create an adapter stub for testing.
*/
export declare function mockAdapter(provider: 'mysql' | 'sqlite' | 'postgres'): SqlDriverAdapter;
export declare const mockAdapterErrors: {
queryRaw: Error;
executeRaw: Error;
startTransaction: Error;
executeScript: Error;
dispose: Error;
};
/**
* Create an adapter factory stub for testing.
*/
export declare function mockAdapterFactory(provider: 'mysql' | 'sqlite' | 'postgres'): SqlDriverAdapterFactory;
/**
* Create an adapter factory stub for testing.
*/
export declare function mockMigrationAwareAdapterFactory(provider: 'mysql' | 'sqlite' | 'postgres'): SqlMigrationAwareDriverAdapterFactory;
export declare type OfficialDriverAdapterName = (typeof officialPrismaAdapters)[number];
declare const officialPrismaAdapters: readonly ["@prisma/adapter-planetscale", "@prisma/adapter-neon", "@prisma/adapter-libsql", "@prisma/adapter-better-sqlite3", "@prisma/adapter-d1", "@prisma/adapter-pg", "@prisma/adapter-mssql", "@prisma/adapter-mariadb"];
export declare function ok<T>(value: T): Result<T>;
export declare type Provider = 'mysql' | 'postgres' | 'sqlite' | 'sqlserver';
export declare interface Queryable<Query, Result> extends AdapterInfo {
/**
* Execute a query and return its result.
*/
queryRaw(params: Query): Promise<Result>;
/**
* Execute a query and return the number of affected rows.
*/
executeRaw(params: Query): Promise<number>;
}
export declare type Result<T> = {
map<U>(fn: (value: T) => U): Result<U>;
flatMap<U>(fn: (value: T) => Result<U>): Result<U>;
} & ({
readonly ok: true;
readonly value: T;
} | {
readonly ok: false;
readonly error: Error_2;
});
/**
* Represents a value that can be returned for a column from `queryRaw`.
*/
export declare type ResultValue = number | string | boolean | null | ResultValue[] | Uint8Array;
export declare interface SqlDriverAdapter extends SqlQueryable {
/**
* Execute multiple SQL statements separated by semicolon.
*/
executeScript(script: string): Promise<void>;
/**
* Start new transaction.
*/
startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
/**
* Optional method that returns extra connection info
*/
getConnectionInfo?(): ConnectionInfo;
/**
* Dispose of the connection and release any resources.
*/
dispose(): Promise<void>;
}
export declare interface SqlDriverAdapterFactory extends DriverAdapterFactory<SqlQuery, SqlResultSet> {
connect(): Promise<SqlDriverAdapter>;
}
/**
* An SQL migration adapter that is aware of the notion of a shadow database
* and can create a connection to it.
*/
export declare interface SqlMigrationAwareDriverAdapterFactory extends SqlDriverAdapterFactory {
connectToShadowDb(): Promise<SqlDriverAdapter>;
}
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`.
* They are used within the Query Engine to convert values from JS to Quaint values.
*/
columnTypes: Array<ColumnType>;
/**
* List of column names appearing in a database query, in the same order as `columnTypes`.
*/
columnNames: Array<string>;
/**
* List of rows retrieved from a database query.
* Each row is a list of values, whose length matches `columnNames` and `columnTypes`.
*/
rows: Array<Array<unknown>>;
/**
* The last ID of an `INSERT` statement, if any.
* This is required for `AUTO_INCREMENT` columns in databases based on MySQL and SQLite.
*/
lastInsertId?: string;
}
export declare interface Transaction extends AdapterInfo, SqlQueryable {
/**
* Transaction options.
*/
readonly options: TransactionOptions;
/**
* Commit the transaction.
*/
commit(): Promise<void>;
/**
* Roll back the transaction.
*/
rollback(): Promise<void>;
/**
* Creates a savepoint within the currently running transaction.
*/
createSavepoint?(name: string): Promise<void>;
/**
* Rolls back transaction state to a previously created savepoint.
*/
rollbackToSavepoint?(name: string): Promise<void>;
/**
* Releases a previously created savepoint. Optional because not every connector supports this operation.
*/
releaseSavepoint?(name: string): Promise<void>;
}
export declare type TransactionOptions = {
usePhantomQuery: boolean;
};
export { }

294
node_modules/@prisma/driver-adapter-utils/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,294 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
ColumnTypeEnum: () => ColumnTypeEnum,
Debug: () => import_debug.Debug,
DriverAdapterError: () => DriverAdapterError,
bindAdapter: () => bindAdapter,
bindMigrationAwareSqlAdapterFactory: () => bindMigrationAwareSqlAdapterFactory,
bindSqlAdapterFactory: () => bindSqlAdapterFactory,
err: () => err,
isDriverAdapterError: () => isDriverAdapterError,
mockAdapter: () => mockAdapter,
mockAdapterErrors: () => mockAdapterErrors,
mockAdapterFactory: () => mockAdapterFactory,
mockMigrationAwareAdapterFactory: () => mockMigrationAwareAdapterFactory,
ok: () => ok
});
module.exports = __toCommonJS(index_exports);
// src/debug.ts
var import_debug = require("@prisma/debug");
// src/error.ts
var DriverAdapterError = class extends Error {
name = "DriverAdapterError";
cause;
constructor(payload) {
super(typeof payload["message"] === "string" ? payload["message"] : payload.kind);
this.cause = payload;
}
};
function isDriverAdapterError(error) {
return error["name"] === "DriverAdapterError" && typeof error["cause"] === "object";
}
// src/result.ts
function ok(value) {
return {
ok: true,
value,
map(fn) {
return ok(fn(value));
},
flatMap(fn) {
return fn(value);
}
};
}
function err(error) {
return {
ok: false,
error,
map() {
return err(error);
},
flatMap() {
return err(error);
}
};
}
// src/binder.ts
var debug = (0, import_debug.Debug)("driver-adapter-utils");
var ErrorRegistryInternal = class {
registeredErrors = [];
consumeError(id) {
return this.registeredErrors[id];
}
registerNewError(error) {
let i = 0;
while (this.registeredErrors[i] !== void 0) {
i++;
}
this.registeredErrors[i] = { error };
return i;
}
};
function copySymbolsFromSource(source, target) {
const symbols = Object.getOwnPropertySymbols(source);
const symbolObject = Object.fromEntries(symbols.map((symbol) => [symbol, true]));
Object.assign(target, symbolObject);
}
var bindMigrationAwareSqlAdapterFactory = (adapterFactory) => {
const errorRegistry = new ErrorRegistryInternal();
const boundFactory = {
adapterName: adapterFactory.adapterName,
provider: adapterFactory.provider,
errorRegistry,
connect: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapterFactory.connect.bind(adapterFactory))(...args);
return ctx.map((ctx2) => bindAdapter(ctx2, errorRegistry));
},
connectToShadowDb: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapterFactory.connectToShadowDb.bind(adapterFactory))(...args);
return ctx.map((ctx2) => bindAdapter(ctx2, errorRegistry));
}
};
copySymbolsFromSource(adapterFactory, boundFactory);
return boundFactory;
};
var bindSqlAdapterFactory = (adapterFactory) => {
const errorRegistry = new ErrorRegistryInternal();
const boundFactory = {
adapterName: adapterFactory.adapterName,
provider: adapterFactory.provider,
errorRegistry,
connect: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapterFactory.connect.bind(adapterFactory))(...args);
return ctx.map((ctx2) => bindAdapter(ctx2, errorRegistry));
}
};
copySymbolsFromSource(adapterFactory, boundFactory);
return boundFactory;
};
var bindAdapter = (adapter, errorRegistry = new ErrorRegistryInternal()) => {
const boundAdapter = {
adapterName: adapter.adapterName,
errorRegistry,
queryRaw: wrapAsync(errorRegistry, adapter.queryRaw.bind(adapter)),
executeRaw: wrapAsync(errorRegistry, adapter.executeRaw.bind(adapter)),
executeScript: wrapAsync(errorRegistry, adapter.executeScript.bind(adapter)),
dispose: wrapAsync(errorRegistry, adapter.dispose.bind(adapter)),
provider: adapter.provider,
startTransaction: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapter.startTransaction.bind(adapter))(...args);
return ctx.map((ctx2) => bindTransaction(errorRegistry, ctx2));
}
};
if (adapter.getConnectionInfo) {
boundAdapter.getConnectionInfo = wrapSync(errorRegistry, adapter.getConnectionInfo.bind(adapter));
}
return boundAdapter;
};
var bindTransaction = (errorRegistry, transaction) => {
const boundTransaction = {
adapterName: transaction.adapterName,
provider: transaction.provider,
options: transaction.options,
queryRaw: wrapAsync(errorRegistry, transaction.queryRaw.bind(transaction)),
executeRaw: wrapAsync(errorRegistry, transaction.executeRaw.bind(transaction)),
commit: wrapAsync(errorRegistry, transaction.commit.bind(transaction)),
rollback: wrapAsync(errorRegistry, transaction.rollback.bind(transaction))
};
if (transaction.createSavepoint) {
boundTransaction.createSavepoint = wrapAsync(errorRegistry, transaction.createSavepoint.bind(transaction));
}
if (transaction.rollbackToSavepoint) {
boundTransaction.rollbackToSavepoint = wrapAsync(errorRegistry, transaction.rollbackToSavepoint.bind(transaction));
}
if (transaction.releaseSavepoint) {
boundTransaction.releaseSavepoint = wrapAsync(errorRegistry, transaction.releaseSavepoint.bind(transaction));
}
return boundTransaction;
};
function wrapAsync(registry, fn) {
return async (...args) => {
try {
return ok(await fn(...args));
} catch (error) {
debug("[error@wrapAsync]", error);
if (isDriverAdapterError(error)) {
return err(error.cause);
}
const id = registry.registerNewError(error);
return err({ kind: "GenericJs", id });
}
};
}
function wrapSync(registry, fn) {
return (...args) => {
try {
return ok(fn(...args));
} catch (error) {
debug("[error@wrapSync]", error);
if (isDriverAdapterError(error)) {
return err(error.cause);
}
const id = registry.registerNewError(error);
return err({ kind: "GenericJs", id });
}
};
}
// src/const.ts
var ColumnTypeEnum = {
// Scalars
Int32: 0,
Int64: 1,
Float: 2,
Double: 3,
Numeric: 4,
Boolean: 5,
Character: 6,
Text: 7,
Date: 8,
Time: 9,
DateTime: 10,
Json: 11,
Enum: 12,
Bytes: 13,
Set: 14,
Uuid: 15,
// Arrays
Int32Array: 64,
Int64Array: 65,
FloatArray: 66,
DoubleArray: 67,
NumericArray: 68,
BooleanArray: 69,
CharacterArray: 70,
TextArray: 71,
DateArray: 72,
TimeArray: 73,
DateTimeArray: 74,
JsonArray: 75,
EnumArray: 76,
BytesArray: 77,
UuidArray: 78,
// Custom
UnknownNumber: 128
};
// src/mock.ts
var mockAdapterErrors = {
queryRaw: new Error("Not implemented: queryRaw"),
executeRaw: new Error("Not implemented: executeRaw"),
startTransaction: new Error("Not implemented: startTransaction"),
executeScript: new Error("Not implemented: executeScript"),
dispose: new Error("Not implemented: dispose")
};
function mockAdapter(provider) {
return {
provider,
adapterName: "@prisma/adapter-mock",
queryRaw: () => Promise.reject(mockAdapterErrors.queryRaw),
executeRaw: () => Promise.reject(mockAdapterErrors.executeRaw),
startTransaction: () => Promise.reject(mockAdapterErrors.startTransaction),
executeScript: () => Promise.reject(mockAdapterErrors.executeScript),
dispose: () => Promise.reject(mockAdapterErrors.dispose),
[Symbol.for("adapter.mockAdapter")]: true
};
}
function mockAdapterFactory(provider) {
return {
provider,
adapterName: "@prisma/adapter-mock",
connect: () => Promise.resolve(mockAdapter(provider)),
[Symbol.for("adapter.mockAdapterFactory")]: true
};
}
function mockMigrationAwareAdapterFactory(provider) {
return {
provider,
adapterName: "@prisma/adapter-mock",
connect: () => Promise.resolve(mockAdapter(provider)),
connectToShadowDb: () => Promise.resolve(mockAdapter(provider)),
[Symbol.for("adapter.mockMigrationAwareAdapterFactory")]: true
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ColumnTypeEnum,
Debug,
DriverAdapterError,
bindAdapter,
bindMigrationAwareSqlAdapterFactory,
bindSqlAdapterFactory,
err,
isDriverAdapterError,
mockAdapter,
mockAdapterErrors,
mockAdapterFactory,
mockMigrationAwareAdapterFactory,
ok
});

View File

@@ -0,0 +1,255 @@
// src/debug.ts
import { Debug } from "@prisma/debug";
// src/error.ts
var DriverAdapterError = class extends Error {
name = "DriverAdapterError";
cause;
constructor(payload) {
super(typeof payload["message"] === "string" ? payload["message"] : payload.kind);
this.cause = payload;
}
};
function isDriverAdapterError(error) {
return error["name"] === "DriverAdapterError" && typeof error["cause"] === "object";
}
// src/result.ts
function ok(value) {
return {
ok: true,
value,
map(fn) {
return ok(fn(value));
},
flatMap(fn) {
return fn(value);
}
};
}
function err(error) {
return {
ok: false,
error,
map() {
return err(error);
},
flatMap() {
return err(error);
}
};
}
// src/binder.ts
var debug = Debug("driver-adapter-utils");
var ErrorRegistryInternal = class {
registeredErrors = [];
consumeError(id) {
return this.registeredErrors[id];
}
registerNewError(error) {
let i = 0;
while (this.registeredErrors[i] !== void 0) {
i++;
}
this.registeredErrors[i] = { error };
return i;
}
};
function copySymbolsFromSource(source, target) {
const symbols = Object.getOwnPropertySymbols(source);
const symbolObject = Object.fromEntries(symbols.map((symbol) => [symbol, true]));
Object.assign(target, symbolObject);
}
var bindMigrationAwareSqlAdapterFactory = (adapterFactory) => {
const errorRegistry = new ErrorRegistryInternal();
const boundFactory = {
adapterName: adapterFactory.adapterName,
provider: adapterFactory.provider,
errorRegistry,
connect: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapterFactory.connect.bind(adapterFactory))(...args);
return ctx.map((ctx2) => bindAdapter(ctx2, errorRegistry));
},
connectToShadowDb: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapterFactory.connectToShadowDb.bind(adapterFactory))(...args);
return ctx.map((ctx2) => bindAdapter(ctx2, errorRegistry));
}
};
copySymbolsFromSource(adapterFactory, boundFactory);
return boundFactory;
};
var bindSqlAdapterFactory = (adapterFactory) => {
const errorRegistry = new ErrorRegistryInternal();
const boundFactory = {
adapterName: adapterFactory.adapterName,
provider: adapterFactory.provider,
errorRegistry,
connect: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapterFactory.connect.bind(adapterFactory))(...args);
return ctx.map((ctx2) => bindAdapter(ctx2, errorRegistry));
}
};
copySymbolsFromSource(adapterFactory, boundFactory);
return boundFactory;
};
var bindAdapter = (adapter, errorRegistry = new ErrorRegistryInternal()) => {
const boundAdapter = {
adapterName: adapter.adapterName,
errorRegistry,
queryRaw: wrapAsync(errorRegistry, adapter.queryRaw.bind(adapter)),
executeRaw: wrapAsync(errorRegistry, adapter.executeRaw.bind(adapter)),
executeScript: wrapAsync(errorRegistry, adapter.executeScript.bind(adapter)),
dispose: wrapAsync(errorRegistry, adapter.dispose.bind(adapter)),
provider: adapter.provider,
startTransaction: async (...args) => {
const ctx = await wrapAsync(errorRegistry, adapter.startTransaction.bind(adapter))(...args);
return ctx.map((ctx2) => bindTransaction(errorRegistry, ctx2));
}
};
if (adapter.getConnectionInfo) {
boundAdapter.getConnectionInfo = wrapSync(errorRegistry, adapter.getConnectionInfo.bind(adapter));
}
return boundAdapter;
};
var bindTransaction = (errorRegistry, transaction) => {
const boundTransaction = {
adapterName: transaction.adapterName,
provider: transaction.provider,
options: transaction.options,
queryRaw: wrapAsync(errorRegistry, transaction.queryRaw.bind(transaction)),
executeRaw: wrapAsync(errorRegistry, transaction.executeRaw.bind(transaction)),
commit: wrapAsync(errorRegistry, transaction.commit.bind(transaction)),
rollback: wrapAsync(errorRegistry, transaction.rollback.bind(transaction))
};
if (transaction.createSavepoint) {
boundTransaction.createSavepoint = wrapAsync(errorRegistry, transaction.createSavepoint.bind(transaction));
}
if (transaction.rollbackToSavepoint) {
boundTransaction.rollbackToSavepoint = wrapAsync(errorRegistry, transaction.rollbackToSavepoint.bind(transaction));
}
if (transaction.releaseSavepoint) {
boundTransaction.releaseSavepoint = wrapAsync(errorRegistry, transaction.releaseSavepoint.bind(transaction));
}
return boundTransaction;
};
function wrapAsync(registry, fn) {
return async (...args) => {
try {
return ok(await fn(...args));
} catch (error) {
debug("[error@wrapAsync]", error);
if (isDriverAdapterError(error)) {
return err(error.cause);
}
const id = registry.registerNewError(error);
return err({ kind: "GenericJs", id });
}
};
}
function wrapSync(registry, fn) {
return (...args) => {
try {
return ok(fn(...args));
} catch (error) {
debug("[error@wrapSync]", error);
if (isDriverAdapterError(error)) {
return err(error.cause);
}
const id = registry.registerNewError(error);
return err({ kind: "GenericJs", id });
}
};
}
// src/const.ts
var ColumnTypeEnum = {
// Scalars
Int32: 0,
Int64: 1,
Float: 2,
Double: 3,
Numeric: 4,
Boolean: 5,
Character: 6,
Text: 7,
Date: 8,
Time: 9,
DateTime: 10,
Json: 11,
Enum: 12,
Bytes: 13,
Set: 14,
Uuid: 15,
// Arrays
Int32Array: 64,
Int64Array: 65,
FloatArray: 66,
DoubleArray: 67,
NumericArray: 68,
BooleanArray: 69,
CharacterArray: 70,
TextArray: 71,
DateArray: 72,
TimeArray: 73,
DateTimeArray: 74,
JsonArray: 75,
EnumArray: 76,
BytesArray: 77,
UuidArray: 78,
// Custom
UnknownNumber: 128
};
// src/mock.ts
var mockAdapterErrors = {
queryRaw: new Error("Not implemented: queryRaw"),
executeRaw: new Error("Not implemented: executeRaw"),
startTransaction: new Error("Not implemented: startTransaction"),
executeScript: new Error("Not implemented: executeScript"),
dispose: new Error("Not implemented: dispose")
};
function mockAdapter(provider) {
return {
provider,
adapterName: "@prisma/adapter-mock",
queryRaw: () => Promise.reject(mockAdapterErrors.queryRaw),
executeRaw: () => Promise.reject(mockAdapterErrors.executeRaw),
startTransaction: () => Promise.reject(mockAdapterErrors.startTransaction),
executeScript: () => Promise.reject(mockAdapterErrors.executeScript),
dispose: () => Promise.reject(mockAdapterErrors.dispose),
[Symbol.for("adapter.mockAdapter")]: true
};
}
function mockAdapterFactory(provider) {
return {
provider,
adapterName: "@prisma/adapter-mock",
connect: () => Promise.resolve(mockAdapter(provider)),
[Symbol.for("adapter.mockAdapterFactory")]: true
};
}
function mockMigrationAwareAdapterFactory(provider) {
return {
provider,
adapterName: "@prisma/adapter-mock",
connect: () => Promise.resolve(mockAdapter(provider)),
connectToShadowDb: () => Promise.resolve(mockAdapter(provider)),
[Symbol.for("adapter.mockMigrationAwareAdapterFactory")]: true
};
}
export {
ColumnTypeEnum,
Debug,
DriverAdapterError,
bindAdapter,
bindMigrationAwareSqlAdapterFactory,
bindSqlAdapterFactory,
err,
isDriverAdapterError,
mockAdapter,
mockAdapterErrors,
mockAdapterFactory,
mockMigrationAwareAdapterFactory,
ok
};