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

201
node_modules/@prisma/adapter-libsql/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

46
node_modules/@prisma/adapter-libsql/README.md generated vendored Normal file
View File

@@ -0,0 +1,46 @@
# Prisma driver adapter for libSQL
Prisma driver adapter for Turso and libSQL. Refer to the [announcement blog post](https://prisma.io/turso) and our [docs](https://www.prisma.io/docs/guides/database/turso) for more details.
> **Note**: Support for Turso is available in [Early Access](https://www.prisma.io/docs/about/prisma/releases#early-access) from Prisma versions [5.4.2](https://github.com/prisma/prisma/releases/tag/5.4.2) and later.
## Getting started
To get started, install the libSQL database client and Prisma driver adapter for libSQL packages:
```sh
npm install @prisma/adapter-libsql
npm install @libsql/client
```
Update your Prisma Client instance to use the libSQL database Client:
```ts
// Import needed packages
import { PrismaClient } from '@prisma/client'
import { PrismaLibSql } from '@prisma/adapter-libsql'
// You can alternatively use the web version of the client if you're running in
// a constrained environment where the standard libsql client doesn't work:
// import { PrismaLibSql } from '@prisma/adapter-libsql/web'
// Setup
const connectionString = `${process.env.TURSO_DATABASE_URL}`
const authToken = `${process.env.TURSO_AUTH_TOKEN}`
// Init prisma client
const adapter = new PrismaLibSql({
url: connectionString,
authToken,
})
const prisma = new PrismaClient({ adapter })
```
The above setup uses a **single** remote Turso database. You can take this a step further by setting up [remote replicas](https://docs.turso.tech/concepts#replica) and [embedded replicas](https://blog.turso.tech/introducing-embedded-replicas-deploy-turso-anywhere-2085aa0dc242) with Turso.
Refer to our [docs](https://www.prisma.io/docs/guides/database/turso#how-to-manage-schema-changes) to learn how to manage schema changes when using Prisma and Turso.
## Feedback
We encourage you to create an issue if you find something missing or run into a bug.
If you have any feedback, leave a comment in [this GitHub discussion](https://github.com/prisma/prisma/discussions/21345).

View File

@@ -0,0 +1,26 @@
import { Client } from '@libsql/client';
import { Config } from '@libsql/client';
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
export declare class PrismaLibSql extends PrismaLibSqlAdapterFactoryBase {
createClient(config: Config): Client;
}
declare abstract class PrismaLibSqlAdapterFactoryBase implements SqlMigrationAwareDriverAdapterFactory {
#private;
readonly provider = "sqlite";
readonly adapterName: string;
constructor(config: Config, options?: PrismaLibSqlOptions);
connect(): Promise<SqlDriverAdapter>;
connectToShadowDb(): Promise<SqlDriverAdapter>;
abstract createClient(config: Config): StdClient;
}
declare type PrismaLibSqlOptions = {
timestampFormat?: 'iso8601' | 'unixepoch-ms';
};
declare type StdClient = Client;
export { }

View File

@@ -0,0 +1,26 @@
import { Client } from '@libsql/client';
import { Config } from '@libsql/client';
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
export declare class PrismaLibSql extends PrismaLibSqlAdapterFactoryBase {
createClient(config: Config): Client;
}
declare abstract class PrismaLibSqlAdapterFactoryBase implements SqlMigrationAwareDriverAdapterFactory {
#private;
readonly provider = "sqlite";
readonly adapterName: string;
constructor(config: Config, options?: PrismaLibSqlOptions);
connect(): Promise<SqlDriverAdapter>;
connectToShadowDb(): Promise<SqlDriverAdapter>;
abstract createClient(config: Config): StdClient;
}
declare type PrismaLibSqlOptions = {
timestampFormat?: 'iso8601' | 'unixepoch-ms';
};
declare type StdClient = Client;
export { }

435
node_modules/@prisma/adapter-libsql/dist/index-node.js generated vendored Normal file
View File

@@ -0,0 +1,435 @@
"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 name2 in all)
__defProp(target, name2, { get: all[name2], 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-node.ts
var index_node_exports = {};
__export(index_node_exports, {
PrismaLibSql: () => PrismaLibSqlAdapterFactory
});
module.exports = __toCommonJS(index_node_exports);
// src/libsql-node.ts
var import_client = require("@libsql/client");
// src/libsql.ts
var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
var import_async_mutex = require("async-mutex");
// package.json
var name = "@prisma/adapter-libsql";
// src/conversion.ts
var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
var debug = (0, import_driver_adapter_utils.Debug)("prisma:driver-adapter:libsql:conversion");
function mapDeclType(declType) {
switch (declType.toUpperCase()) {
case "":
return null;
case "DECIMAL":
return import_driver_adapter_utils.ColumnTypeEnum.Numeric;
case "FLOAT":
return import_driver_adapter_utils.ColumnTypeEnum.Float;
case "DOUBLE":
case "DOUBLE PRECISION":
case "NUMERIC":
case "REAL":
return import_driver_adapter_utils.ColumnTypeEnum.Double;
case "TINYINT":
case "SMALLINT":
case "MEDIUMINT":
case "INT":
case "INTEGER":
case "SERIAL":
case "INT2":
return import_driver_adapter_utils.ColumnTypeEnum.Int32;
case "BIGINT":
case "UNSIGNED BIG INT":
case "INT8":
return import_driver_adapter_utils.ColumnTypeEnum.Int64;
case "DATETIME":
case "TIMESTAMP":
return import_driver_adapter_utils.ColumnTypeEnum.DateTime;
case "TIME":
return import_driver_adapter_utils.ColumnTypeEnum.Time;
case "DATE":
return import_driver_adapter_utils.ColumnTypeEnum.Date;
case "TEXT":
case "CLOB":
case "CHARACTER":
case "VARCHAR":
case "VARYING CHARACTER":
case "NCHAR":
case "NATIVE CHARACTER":
case "NVARCHAR":
return import_driver_adapter_utils.ColumnTypeEnum.Text;
case "BLOB":
return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
case "BOOLEAN":
return import_driver_adapter_utils.ColumnTypeEnum.Boolean;
case "JSONB":
return import_driver_adapter_utils.ColumnTypeEnum.Json;
default:
debug("unknown decltype:", declType);
return null;
}
}
function mapDeclaredColumnTypes(columnTypes) {
const emptyIndices = /* @__PURE__ */ new Set();
const result = columnTypes.map((typeName, index) => {
const mappedType = mapDeclType(typeName);
if (mappedType === null) {
emptyIndices.add(index);
}
return mappedType;
});
return [result, emptyIndices];
}
function getColumnTypes(declaredTypes, rows) {
const [columnTypes, emptyIndices] = mapDeclaredColumnTypes(declaredTypes);
if (emptyIndices.size === 0) {
return columnTypes;
}
columnLoop: for (const columnIndex of emptyIndices) {
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
const candidateValue = rows[rowIndex][columnIndex];
if (candidateValue !== null) {
columnTypes[columnIndex] = inferColumnType(candidateValue);
continue columnLoop;
}
}
columnTypes[columnIndex] = import_driver_adapter_utils.ColumnTypeEnum.Int32;
}
return columnTypes;
}
function inferColumnType(value) {
switch (typeof value) {
case "string":
return import_driver_adapter_utils.ColumnTypeEnum.Text;
case "bigint":
return import_driver_adapter_utils.ColumnTypeEnum.Int64;
case "boolean":
return import_driver_adapter_utils.ColumnTypeEnum.Boolean;
case "number":
return import_driver_adapter_utils.ColumnTypeEnum.UnknownNumber;
case "object":
return inferObjectType(value);
default:
throw new UnexpectedTypeError(value);
}
}
function inferObjectType(value) {
if (value instanceof ArrayBuffer) {
return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
}
throw new UnexpectedTypeError(value);
}
var UnexpectedTypeError = class extends Error {
name = "UnexpectedTypeError";
constructor(value) {
const type = typeof value;
const repr = type === "object" ? JSON.stringify(value) : String(value);
super(`unexpected value of type ${type}: ${repr}`);
}
};
function mapRow(row, columnTypes) {
const result = [];
for (let i = 0; i < row.length; i++) {
const value = row[i];
if (value instanceof ArrayBuffer) {
result[i] = new Uint8Array(value);
continue;
}
if (typeof value === "number" && (columnTypes[i] === import_driver_adapter_utils.ColumnTypeEnum.Int32 || columnTypes[i] === import_driver_adapter_utils.ColumnTypeEnum.Int64) && !Number.isInteger(value)) {
result[i] = Math.trunc(value);
continue;
}
if (["number", "bigint"].includes(typeof value) && columnTypes[i] === import_driver_adapter_utils.ColumnTypeEnum.DateTime) {
result[i] = new Date(Number(value)).toISOString();
continue;
}
if (typeof value === "bigint") {
result[i] = value.toString();
continue;
}
result[i] = value;
}
return result;
}
function mapArg(arg, argType, options) {
if (arg === null) {
return null;
}
if (typeof arg === "string" && argType.scalarType === "bigint") {
return BigInt(arg);
}
if (typeof arg === "string" && argType.scalarType === "decimal") {
return Number.parseFloat(arg);
}
if (typeof arg === "string" && argType.scalarType === "datetime") {
arg = new Date(arg);
}
if (arg instanceof Date) {
const format = options?.timestampFormat ?? "iso8601";
switch (format) {
case "unixepoch-ms":
return arg.getTime();
case "iso8601":
return arg.toISOString().replace("Z", "+00:00");
default:
throw new Error(`Unknown timestamp format: ${format}`);
}
}
if (typeof arg === "string" && argType.scalarType === "bytes") {
return Buffer.from(arg, "base64");
}
return arg;
}
// src/errors.ts
var SQLITE_BUSY = 5;
var PRIMARY_ERROR_CODE_MASK = 255;
function convertDriverError(error) {
if (isDriverError(error)) {
return {
originalCode: error.rawCode?.toString(),
originalMessage: error.message,
...mapDriverError(error)
};
}
throw error;
}
function mapDriverError(error) {
const rawCode = error.rawCode ?? error.cause?.["rawCode"] ?? 1;
switch (rawCode) {
case 2067:
case 1555: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "UniqueConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 1299: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "NullConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 787:
case 1811:
return {
kind: "ForeignKeyConstraintViolation",
constraint: { foreignKey: {} }
};
default:
if (rawCode && (rawCode & PRIMARY_ERROR_CODE_MASK) === SQLITE_BUSY) {
return {
kind: "SocketTimeout"
};
} else if (error.message.startsWith("no such table")) {
return {
kind: "TableDoesNotExist",
table: error.message.split(": ").at(1)
};
} else if (error.message.startsWith("no such column")) {
return {
kind: "ColumnNotFound",
column: error.message.split(": ").at(1)
};
} else if (error.message.includes("has no column named ")) {
return {
kind: "ColumnNotFound",
column: error.message.split("has no column named ").at(1)
};
}
return {
kind: "sqlite",
extendedCode: rawCode,
message: error.message
};
}
}
function isDriverError(error) {
return typeof error.code === "string" && typeof error.message === "string" && (typeof error.rawCode === "number" || error.rawCode === void 0);
}
// src/libsql.ts
var debug2 = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:libsql");
var LOCK_TAG = Symbol();
var LibSqlQueryable = class {
constructor(client, adapterOptions) {
this.client = client;
this.adapterOptions = adapterOptions;
}
provider = "sqlite";
adapterName = name;
[LOCK_TAG] = new import_async_mutex.Mutex();
/**
* Execute a query given as SQL, interpolating the given parameters.
*/
async queryRaw(query) {
const tag = "[js::query_raw]";
debug2(`${tag} %O`, query);
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
return {
columnNames: columns,
columnTypes,
rows: rows.map((row) => mapRow(row, columnTypes))
};
}
/**
* Execute a query given as SQL, interpolating the given parameters and
* returning the number of affected rows.
* Note: Queryable expects a u64, but napi.rs only supports u32.
*/
async executeRaw(query) {
const tag = "[js::execute_raw]";
debug2(`${tag} %O`, query);
return (await this.performIO(query)).rowsAffected ?? 0;
}
/**
* Run a query against the database, returning the result set.
* Should the query fail due to a connection error, the connection is
* marked as unhealthy.
*/
async performIO(query) {
const release = await this[LOCK_TAG].acquire();
try {
const result = await this.client.execute({
sql: query.sql,
args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions))
});
return result;
} catch (e) {
this.onError(e);
} finally {
release();
}
}
onError(error) {
debug2("Error in performIO: %O", error);
throw new import_driver_adapter_utils2.DriverAdapterError(convertDriverError(error));
}
};
var LibSqlTransaction = class extends LibSqlQueryable {
constructor(client, options, adapterOptions, unlockParent) {
super(client, adapterOptions);
this.options = options;
this.#unlockParent = unlockParent;
}
#unlockParent;
async commit() {
debug2(`[js::commit]`);
try {
await this.client.commit();
} finally {
this.#unlockParent();
}
}
async rollback() {
debug2(`[js::rollback]`);
try {
await this.client.rollback();
} catch (error) {
debug2("error in rollback:", error);
} finally {
this.#unlockParent();
}
}
async createSavepoint(name2) {
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
async rollbackToSavepoint(name2) {
await this.executeRaw({ sql: `ROLLBACK TO ${name2}`, args: [], argTypes: [] });
}
async releaseSavepoint(name2) {
await this.executeRaw({ sql: `RELEASE SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
};
var PrismaLibSqlAdapter = class extends LibSqlQueryable {
constructor(client, adapterOptions) {
super(client, adapterOptions);
}
async executeScript(script) {
const release = await this[LOCK_TAG].acquire();
try {
await this.client.executeMultiple(script);
} catch (e) {
this.onError(e);
} finally {
release();
}
}
async startTransaction(isolationLevel) {
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
throw new import_driver_adapter_utils2.DriverAdapterError({
kind: "InvalidIsolationLevel",
level: isolationLevel
});
}
const options = {
usePhantomQuery: true
};
const tag = "[js::startTransaction]";
debug2("%s options: %O", tag, options);
const release = await this[LOCK_TAG].acquire();
try {
const tx = await this.client.transaction("deferred");
return new LibSqlTransaction(tx, options, this.adapterOptions, release);
} catch (e) {
release();
this.onError(e);
}
}
dispose() {
this.client.close();
return Promise.resolve();
}
};
var PrismaLibSqlAdapterFactoryBase = class {
provider = "sqlite";
adapterName = name;
#config;
#options;
constructor(config, options) {
this.#config = config;
this.#options = options;
}
connect() {
return Promise.resolve(new PrismaLibSqlAdapter(this.createClient(this.#config), this.#options));
}
connectToShadowDb() {
return Promise.resolve(
new PrismaLibSqlAdapter(this.createClient({ ...this.#config, url: ":memory:" }), this.#options)
);
}
};
// src/libsql-node.ts
var PrismaLibSqlAdapterFactory = class extends PrismaLibSqlAdapterFactoryBase {
createClient(config) {
return (0, import_client.createClient)(config);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PrismaLibSql
});

408
node_modules/@prisma/adapter-libsql/dist/index-node.mjs generated vendored Normal file
View File

@@ -0,0 +1,408 @@
// src/libsql-node.ts
import { createClient } from "@libsql/client";
// src/libsql.ts
import { Debug as Debug2, DriverAdapterError } from "@prisma/driver-adapter-utils";
import { Mutex } from "async-mutex";
// package.json
var name = "@prisma/adapter-libsql";
// src/conversion.ts
import { ColumnTypeEnum, Debug } from "@prisma/driver-adapter-utils";
var debug = Debug("prisma:driver-adapter:libsql:conversion");
function mapDeclType(declType) {
switch (declType.toUpperCase()) {
case "":
return null;
case "DECIMAL":
return ColumnTypeEnum.Numeric;
case "FLOAT":
return ColumnTypeEnum.Float;
case "DOUBLE":
case "DOUBLE PRECISION":
case "NUMERIC":
case "REAL":
return ColumnTypeEnum.Double;
case "TINYINT":
case "SMALLINT":
case "MEDIUMINT":
case "INT":
case "INTEGER":
case "SERIAL":
case "INT2":
return ColumnTypeEnum.Int32;
case "BIGINT":
case "UNSIGNED BIG INT":
case "INT8":
return ColumnTypeEnum.Int64;
case "DATETIME":
case "TIMESTAMP":
return ColumnTypeEnum.DateTime;
case "TIME":
return ColumnTypeEnum.Time;
case "DATE":
return ColumnTypeEnum.Date;
case "TEXT":
case "CLOB":
case "CHARACTER":
case "VARCHAR":
case "VARYING CHARACTER":
case "NCHAR":
case "NATIVE CHARACTER":
case "NVARCHAR":
return ColumnTypeEnum.Text;
case "BLOB":
return ColumnTypeEnum.Bytes;
case "BOOLEAN":
return ColumnTypeEnum.Boolean;
case "JSONB":
return ColumnTypeEnum.Json;
default:
debug("unknown decltype:", declType);
return null;
}
}
function mapDeclaredColumnTypes(columnTypes) {
const emptyIndices = /* @__PURE__ */ new Set();
const result = columnTypes.map((typeName, index) => {
const mappedType = mapDeclType(typeName);
if (mappedType === null) {
emptyIndices.add(index);
}
return mappedType;
});
return [result, emptyIndices];
}
function getColumnTypes(declaredTypes, rows) {
const [columnTypes, emptyIndices] = mapDeclaredColumnTypes(declaredTypes);
if (emptyIndices.size === 0) {
return columnTypes;
}
columnLoop: for (const columnIndex of emptyIndices) {
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
const candidateValue = rows[rowIndex][columnIndex];
if (candidateValue !== null) {
columnTypes[columnIndex] = inferColumnType(candidateValue);
continue columnLoop;
}
}
columnTypes[columnIndex] = ColumnTypeEnum.Int32;
}
return columnTypes;
}
function inferColumnType(value) {
switch (typeof value) {
case "string":
return ColumnTypeEnum.Text;
case "bigint":
return ColumnTypeEnum.Int64;
case "boolean":
return ColumnTypeEnum.Boolean;
case "number":
return ColumnTypeEnum.UnknownNumber;
case "object":
return inferObjectType(value);
default:
throw new UnexpectedTypeError(value);
}
}
function inferObjectType(value) {
if (value instanceof ArrayBuffer) {
return ColumnTypeEnum.Bytes;
}
throw new UnexpectedTypeError(value);
}
var UnexpectedTypeError = class extends Error {
name = "UnexpectedTypeError";
constructor(value) {
const type = typeof value;
const repr = type === "object" ? JSON.stringify(value) : String(value);
super(`unexpected value of type ${type}: ${repr}`);
}
};
function mapRow(row, columnTypes) {
const result = [];
for (let i = 0; i < row.length; i++) {
const value = row[i];
if (value instanceof ArrayBuffer) {
result[i] = new Uint8Array(value);
continue;
}
if (typeof value === "number" && (columnTypes[i] === ColumnTypeEnum.Int32 || columnTypes[i] === ColumnTypeEnum.Int64) && !Number.isInteger(value)) {
result[i] = Math.trunc(value);
continue;
}
if (["number", "bigint"].includes(typeof value) && columnTypes[i] === ColumnTypeEnum.DateTime) {
result[i] = new Date(Number(value)).toISOString();
continue;
}
if (typeof value === "bigint") {
result[i] = value.toString();
continue;
}
result[i] = value;
}
return result;
}
function mapArg(arg, argType, options) {
if (arg === null) {
return null;
}
if (typeof arg === "string" && argType.scalarType === "bigint") {
return BigInt(arg);
}
if (typeof arg === "string" && argType.scalarType === "decimal") {
return Number.parseFloat(arg);
}
if (typeof arg === "string" && argType.scalarType === "datetime") {
arg = new Date(arg);
}
if (arg instanceof Date) {
const format = options?.timestampFormat ?? "iso8601";
switch (format) {
case "unixepoch-ms":
return arg.getTime();
case "iso8601":
return arg.toISOString().replace("Z", "+00:00");
default:
throw new Error(`Unknown timestamp format: ${format}`);
}
}
if (typeof arg === "string" && argType.scalarType === "bytes") {
return Buffer.from(arg, "base64");
}
return arg;
}
// src/errors.ts
var SQLITE_BUSY = 5;
var PRIMARY_ERROR_CODE_MASK = 255;
function convertDriverError(error) {
if (isDriverError(error)) {
return {
originalCode: error.rawCode?.toString(),
originalMessage: error.message,
...mapDriverError(error)
};
}
throw error;
}
function mapDriverError(error) {
const rawCode = error.rawCode ?? error.cause?.["rawCode"] ?? 1;
switch (rawCode) {
case 2067:
case 1555: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "UniqueConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 1299: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "NullConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 787:
case 1811:
return {
kind: "ForeignKeyConstraintViolation",
constraint: { foreignKey: {} }
};
default:
if (rawCode && (rawCode & PRIMARY_ERROR_CODE_MASK) === SQLITE_BUSY) {
return {
kind: "SocketTimeout"
};
} else if (error.message.startsWith("no such table")) {
return {
kind: "TableDoesNotExist",
table: error.message.split(": ").at(1)
};
} else if (error.message.startsWith("no such column")) {
return {
kind: "ColumnNotFound",
column: error.message.split(": ").at(1)
};
} else if (error.message.includes("has no column named ")) {
return {
kind: "ColumnNotFound",
column: error.message.split("has no column named ").at(1)
};
}
return {
kind: "sqlite",
extendedCode: rawCode,
message: error.message
};
}
}
function isDriverError(error) {
return typeof error.code === "string" && typeof error.message === "string" && (typeof error.rawCode === "number" || error.rawCode === void 0);
}
// src/libsql.ts
var debug2 = Debug2("prisma:driver-adapter:libsql");
var LOCK_TAG = Symbol();
var LibSqlQueryable = class {
constructor(client, adapterOptions) {
this.client = client;
this.adapterOptions = adapterOptions;
}
provider = "sqlite";
adapterName = name;
[LOCK_TAG] = new Mutex();
/**
* Execute a query given as SQL, interpolating the given parameters.
*/
async queryRaw(query) {
const tag = "[js::query_raw]";
debug2(`${tag} %O`, query);
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
return {
columnNames: columns,
columnTypes,
rows: rows.map((row) => mapRow(row, columnTypes))
};
}
/**
* Execute a query given as SQL, interpolating the given parameters and
* returning the number of affected rows.
* Note: Queryable expects a u64, but napi.rs only supports u32.
*/
async executeRaw(query) {
const tag = "[js::execute_raw]";
debug2(`${tag} %O`, query);
return (await this.performIO(query)).rowsAffected ?? 0;
}
/**
* Run a query against the database, returning the result set.
* Should the query fail due to a connection error, the connection is
* marked as unhealthy.
*/
async performIO(query) {
const release = await this[LOCK_TAG].acquire();
try {
const result = await this.client.execute({
sql: query.sql,
args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions))
});
return result;
} catch (e) {
this.onError(e);
} finally {
release();
}
}
onError(error) {
debug2("Error in performIO: %O", error);
throw new DriverAdapterError(convertDriverError(error));
}
};
var LibSqlTransaction = class extends LibSqlQueryable {
constructor(client, options, adapterOptions, unlockParent) {
super(client, adapterOptions);
this.options = options;
this.#unlockParent = unlockParent;
}
#unlockParent;
async commit() {
debug2(`[js::commit]`);
try {
await this.client.commit();
} finally {
this.#unlockParent();
}
}
async rollback() {
debug2(`[js::rollback]`);
try {
await this.client.rollback();
} catch (error) {
debug2("error in rollback:", error);
} finally {
this.#unlockParent();
}
}
async createSavepoint(name2) {
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
async rollbackToSavepoint(name2) {
await this.executeRaw({ sql: `ROLLBACK TO ${name2}`, args: [], argTypes: [] });
}
async releaseSavepoint(name2) {
await this.executeRaw({ sql: `RELEASE SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
};
var PrismaLibSqlAdapter = class extends LibSqlQueryable {
constructor(client, adapterOptions) {
super(client, adapterOptions);
}
async executeScript(script) {
const release = await this[LOCK_TAG].acquire();
try {
await this.client.executeMultiple(script);
} catch (e) {
this.onError(e);
} finally {
release();
}
}
async startTransaction(isolationLevel) {
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
throw new DriverAdapterError({
kind: "InvalidIsolationLevel",
level: isolationLevel
});
}
const options = {
usePhantomQuery: true
};
const tag = "[js::startTransaction]";
debug2("%s options: %O", tag, options);
const release = await this[LOCK_TAG].acquire();
try {
const tx = await this.client.transaction("deferred");
return new LibSqlTransaction(tx, options, this.adapterOptions, release);
} catch (e) {
release();
this.onError(e);
}
}
dispose() {
this.client.close();
return Promise.resolve();
}
};
var PrismaLibSqlAdapterFactoryBase = class {
provider = "sqlite";
adapterName = name;
#config;
#options;
constructor(config, options) {
this.#config = config;
this.#options = options;
}
connect() {
return Promise.resolve(new PrismaLibSqlAdapter(this.createClient(this.#config), this.#options));
}
connectToShadowDb() {
return Promise.resolve(
new PrismaLibSqlAdapter(this.createClient({ ...this.#config, url: ":memory:" }), this.#options)
);
}
};
// src/libsql-node.ts
var PrismaLibSqlAdapterFactory = class extends PrismaLibSqlAdapterFactoryBase {
createClient(config) {
return createClient(config);
}
};
export {
PrismaLibSqlAdapterFactory as PrismaLibSql
};

View File

@@ -0,0 +1,28 @@
import type { Client } from '@libsql/client';
import { Client as Client_2 } from '@libsql/client/web';
import type { Config } from '@libsql/client';
import { Config as Config_2 } from '@libsql/client/web';
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
export declare class PrismaLibSql extends PrismaLibSqlAdapterFactoryBase {
createClient(config: Config_2): Client_2;
}
declare abstract class PrismaLibSqlAdapterFactoryBase implements SqlMigrationAwareDriverAdapterFactory {
#private;
readonly provider = "sqlite";
readonly adapterName: string;
constructor(config: Config, options?: PrismaLibSqlOptions);
connect(): Promise<SqlDriverAdapter>;
connectToShadowDb(): Promise<SqlDriverAdapter>;
abstract createClient(config: Config): StdClient;
}
declare type PrismaLibSqlOptions = {
timestampFormat?: 'iso8601' | 'unixepoch-ms';
};
declare type StdClient = Client;
export { }

View File

@@ -0,0 +1,28 @@
import type { Client } from '@libsql/client';
import { Client as Client_2 } from '@libsql/client/web';
import type { Config } from '@libsql/client';
import { Config as Config_2 } from '@libsql/client/web';
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
export declare class PrismaLibSql extends PrismaLibSqlAdapterFactoryBase {
createClient(config: Config_2): Client_2;
}
declare abstract class PrismaLibSqlAdapterFactoryBase implements SqlMigrationAwareDriverAdapterFactory {
#private;
readonly provider = "sqlite";
readonly adapterName: string;
constructor(config: Config, options?: PrismaLibSqlOptions);
connect(): Promise<SqlDriverAdapter>;
connectToShadowDb(): Promise<SqlDriverAdapter>;
abstract createClient(config: Config): StdClient;
}
declare type PrismaLibSqlOptions = {
timestampFormat?: 'iso8601' | 'unixepoch-ms';
};
declare type StdClient = Client;
export { }

435
node_modules/@prisma/adapter-libsql/dist/index-web.js generated vendored Normal file
View File

@@ -0,0 +1,435 @@
"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 name2 in all)
__defProp(target, name2, { get: all[name2], 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-web.ts
var index_web_exports = {};
__export(index_web_exports, {
PrismaLibSql: () => PrismaLibSqlWebAdapterFactory
});
module.exports = __toCommonJS(index_web_exports);
// src/libsql-web.ts
var import_web = require("@libsql/client/web");
// src/libsql.ts
var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
var import_async_mutex = require("async-mutex");
// package.json
var name = "@prisma/adapter-libsql";
// src/conversion.ts
var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
var debug = (0, import_driver_adapter_utils.Debug)("prisma:driver-adapter:libsql:conversion");
function mapDeclType(declType) {
switch (declType.toUpperCase()) {
case "":
return null;
case "DECIMAL":
return import_driver_adapter_utils.ColumnTypeEnum.Numeric;
case "FLOAT":
return import_driver_adapter_utils.ColumnTypeEnum.Float;
case "DOUBLE":
case "DOUBLE PRECISION":
case "NUMERIC":
case "REAL":
return import_driver_adapter_utils.ColumnTypeEnum.Double;
case "TINYINT":
case "SMALLINT":
case "MEDIUMINT":
case "INT":
case "INTEGER":
case "SERIAL":
case "INT2":
return import_driver_adapter_utils.ColumnTypeEnum.Int32;
case "BIGINT":
case "UNSIGNED BIG INT":
case "INT8":
return import_driver_adapter_utils.ColumnTypeEnum.Int64;
case "DATETIME":
case "TIMESTAMP":
return import_driver_adapter_utils.ColumnTypeEnum.DateTime;
case "TIME":
return import_driver_adapter_utils.ColumnTypeEnum.Time;
case "DATE":
return import_driver_adapter_utils.ColumnTypeEnum.Date;
case "TEXT":
case "CLOB":
case "CHARACTER":
case "VARCHAR":
case "VARYING CHARACTER":
case "NCHAR":
case "NATIVE CHARACTER":
case "NVARCHAR":
return import_driver_adapter_utils.ColumnTypeEnum.Text;
case "BLOB":
return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
case "BOOLEAN":
return import_driver_adapter_utils.ColumnTypeEnum.Boolean;
case "JSONB":
return import_driver_adapter_utils.ColumnTypeEnum.Json;
default:
debug("unknown decltype:", declType);
return null;
}
}
function mapDeclaredColumnTypes(columnTypes) {
const emptyIndices = /* @__PURE__ */ new Set();
const result = columnTypes.map((typeName, index) => {
const mappedType = mapDeclType(typeName);
if (mappedType === null) {
emptyIndices.add(index);
}
return mappedType;
});
return [result, emptyIndices];
}
function getColumnTypes(declaredTypes, rows) {
const [columnTypes, emptyIndices] = mapDeclaredColumnTypes(declaredTypes);
if (emptyIndices.size === 0) {
return columnTypes;
}
columnLoop: for (const columnIndex of emptyIndices) {
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
const candidateValue = rows[rowIndex][columnIndex];
if (candidateValue !== null) {
columnTypes[columnIndex] = inferColumnType(candidateValue);
continue columnLoop;
}
}
columnTypes[columnIndex] = import_driver_adapter_utils.ColumnTypeEnum.Int32;
}
return columnTypes;
}
function inferColumnType(value) {
switch (typeof value) {
case "string":
return import_driver_adapter_utils.ColumnTypeEnum.Text;
case "bigint":
return import_driver_adapter_utils.ColumnTypeEnum.Int64;
case "boolean":
return import_driver_adapter_utils.ColumnTypeEnum.Boolean;
case "number":
return import_driver_adapter_utils.ColumnTypeEnum.UnknownNumber;
case "object":
return inferObjectType(value);
default:
throw new UnexpectedTypeError(value);
}
}
function inferObjectType(value) {
if (value instanceof ArrayBuffer) {
return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
}
throw new UnexpectedTypeError(value);
}
var UnexpectedTypeError = class extends Error {
name = "UnexpectedTypeError";
constructor(value) {
const type = typeof value;
const repr = type === "object" ? JSON.stringify(value) : String(value);
super(`unexpected value of type ${type}: ${repr}`);
}
};
function mapRow(row, columnTypes) {
const result = [];
for (let i = 0; i < row.length; i++) {
const value = row[i];
if (value instanceof ArrayBuffer) {
result[i] = new Uint8Array(value);
continue;
}
if (typeof value === "number" && (columnTypes[i] === import_driver_adapter_utils.ColumnTypeEnum.Int32 || columnTypes[i] === import_driver_adapter_utils.ColumnTypeEnum.Int64) && !Number.isInteger(value)) {
result[i] = Math.trunc(value);
continue;
}
if (["number", "bigint"].includes(typeof value) && columnTypes[i] === import_driver_adapter_utils.ColumnTypeEnum.DateTime) {
result[i] = new Date(Number(value)).toISOString();
continue;
}
if (typeof value === "bigint") {
result[i] = value.toString();
continue;
}
result[i] = value;
}
return result;
}
function mapArg(arg, argType, options) {
if (arg === null) {
return null;
}
if (typeof arg === "string" && argType.scalarType === "bigint") {
return BigInt(arg);
}
if (typeof arg === "string" && argType.scalarType === "decimal") {
return Number.parseFloat(arg);
}
if (typeof arg === "string" && argType.scalarType === "datetime") {
arg = new Date(arg);
}
if (arg instanceof Date) {
const format = options?.timestampFormat ?? "iso8601";
switch (format) {
case "unixepoch-ms":
return arg.getTime();
case "iso8601":
return arg.toISOString().replace("Z", "+00:00");
default:
throw new Error(`Unknown timestamp format: ${format}`);
}
}
if (typeof arg === "string" && argType.scalarType === "bytes") {
return Buffer.from(arg, "base64");
}
return arg;
}
// src/errors.ts
var SQLITE_BUSY = 5;
var PRIMARY_ERROR_CODE_MASK = 255;
function convertDriverError(error) {
if (isDriverError(error)) {
return {
originalCode: error.rawCode?.toString(),
originalMessage: error.message,
...mapDriverError(error)
};
}
throw error;
}
function mapDriverError(error) {
const rawCode = error.rawCode ?? error.cause?.["rawCode"] ?? 1;
switch (rawCode) {
case 2067:
case 1555: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "UniqueConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 1299: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "NullConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 787:
case 1811:
return {
kind: "ForeignKeyConstraintViolation",
constraint: { foreignKey: {} }
};
default:
if (rawCode && (rawCode & PRIMARY_ERROR_CODE_MASK) === SQLITE_BUSY) {
return {
kind: "SocketTimeout"
};
} else if (error.message.startsWith("no such table")) {
return {
kind: "TableDoesNotExist",
table: error.message.split(": ").at(1)
};
} else if (error.message.startsWith("no such column")) {
return {
kind: "ColumnNotFound",
column: error.message.split(": ").at(1)
};
} else if (error.message.includes("has no column named ")) {
return {
kind: "ColumnNotFound",
column: error.message.split("has no column named ").at(1)
};
}
return {
kind: "sqlite",
extendedCode: rawCode,
message: error.message
};
}
}
function isDriverError(error) {
return typeof error.code === "string" && typeof error.message === "string" && (typeof error.rawCode === "number" || error.rawCode === void 0);
}
// src/libsql.ts
var debug2 = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:libsql");
var LOCK_TAG = Symbol();
var LibSqlQueryable = class {
constructor(client, adapterOptions) {
this.client = client;
this.adapterOptions = adapterOptions;
}
provider = "sqlite";
adapterName = name;
[LOCK_TAG] = new import_async_mutex.Mutex();
/**
* Execute a query given as SQL, interpolating the given parameters.
*/
async queryRaw(query) {
const tag = "[js::query_raw]";
debug2(`${tag} %O`, query);
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
return {
columnNames: columns,
columnTypes,
rows: rows.map((row) => mapRow(row, columnTypes))
};
}
/**
* Execute a query given as SQL, interpolating the given parameters and
* returning the number of affected rows.
* Note: Queryable expects a u64, but napi.rs only supports u32.
*/
async executeRaw(query) {
const tag = "[js::execute_raw]";
debug2(`${tag} %O`, query);
return (await this.performIO(query)).rowsAffected ?? 0;
}
/**
* Run a query against the database, returning the result set.
* Should the query fail due to a connection error, the connection is
* marked as unhealthy.
*/
async performIO(query) {
const release = await this[LOCK_TAG].acquire();
try {
const result = await this.client.execute({
sql: query.sql,
args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions))
});
return result;
} catch (e) {
this.onError(e);
} finally {
release();
}
}
onError(error) {
debug2("Error in performIO: %O", error);
throw new import_driver_adapter_utils2.DriverAdapterError(convertDriverError(error));
}
};
var LibSqlTransaction = class extends LibSqlQueryable {
constructor(client, options, adapterOptions, unlockParent) {
super(client, adapterOptions);
this.options = options;
this.#unlockParent = unlockParent;
}
#unlockParent;
async commit() {
debug2(`[js::commit]`);
try {
await this.client.commit();
} finally {
this.#unlockParent();
}
}
async rollback() {
debug2(`[js::rollback]`);
try {
await this.client.rollback();
} catch (error) {
debug2("error in rollback:", error);
} finally {
this.#unlockParent();
}
}
async createSavepoint(name2) {
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
async rollbackToSavepoint(name2) {
await this.executeRaw({ sql: `ROLLBACK TO ${name2}`, args: [], argTypes: [] });
}
async releaseSavepoint(name2) {
await this.executeRaw({ sql: `RELEASE SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
};
var PrismaLibSqlAdapter = class extends LibSqlQueryable {
constructor(client, adapterOptions) {
super(client, adapterOptions);
}
async executeScript(script) {
const release = await this[LOCK_TAG].acquire();
try {
await this.client.executeMultiple(script);
} catch (e) {
this.onError(e);
} finally {
release();
}
}
async startTransaction(isolationLevel) {
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
throw new import_driver_adapter_utils2.DriverAdapterError({
kind: "InvalidIsolationLevel",
level: isolationLevel
});
}
const options = {
usePhantomQuery: true
};
const tag = "[js::startTransaction]";
debug2("%s options: %O", tag, options);
const release = await this[LOCK_TAG].acquire();
try {
const tx = await this.client.transaction("deferred");
return new LibSqlTransaction(tx, options, this.adapterOptions, release);
} catch (e) {
release();
this.onError(e);
}
}
dispose() {
this.client.close();
return Promise.resolve();
}
};
var PrismaLibSqlAdapterFactoryBase = class {
provider = "sqlite";
adapterName = name;
#config;
#options;
constructor(config, options) {
this.#config = config;
this.#options = options;
}
connect() {
return Promise.resolve(new PrismaLibSqlAdapter(this.createClient(this.#config), this.#options));
}
connectToShadowDb() {
return Promise.resolve(
new PrismaLibSqlAdapter(this.createClient({ ...this.#config, url: ":memory:" }), this.#options)
);
}
};
// src/libsql-web.ts
var PrismaLibSqlWebAdapterFactory = class extends PrismaLibSqlAdapterFactoryBase {
createClient(config) {
return (0, import_web.createClient)(config);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PrismaLibSql
});

408
node_modules/@prisma/adapter-libsql/dist/index-web.mjs generated vendored Normal file
View File

@@ -0,0 +1,408 @@
// src/libsql-web.ts
import { createClient } from "@libsql/client/web";
// src/libsql.ts
import { Debug as Debug2, DriverAdapterError } from "@prisma/driver-adapter-utils";
import { Mutex } from "async-mutex";
// package.json
var name = "@prisma/adapter-libsql";
// src/conversion.ts
import { ColumnTypeEnum, Debug } from "@prisma/driver-adapter-utils";
var debug = Debug("prisma:driver-adapter:libsql:conversion");
function mapDeclType(declType) {
switch (declType.toUpperCase()) {
case "":
return null;
case "DECIMAL":
return ColumnTypeEnum.Numeric;
case "FLOAT":
return ColumnTypeEnum.Float;
case "DOUBLE":
case "DOUBLE PRECISION":
case "NUMERIC":
case "REAL":
return ColumnTypeEnum.Double;
case "TINYINT":
case "SMALLINT":
case "MEDIUMINT":
case "INT":
case "INTEGER":
case "SERIAL":
case "INT2":
return ColumnTypeEnum.Int32;
case "BIGINT":
case "UNSIGNED BIG INT":
case "INT8":
return ColumnTypeEnum.Int64;
case "DATETIME":
case "TIMESTAMP":
return ColumnTypeEnum.DateTime;
case "TIME":
return ColumnTypeEnum.Time;
case "DATE":
return ColumnTypeEnum.Date;
case "TEXT":
case "CLOB":
case "CHARACTER":
case "VARCHAR":
case "VARYING CHARACTER":
case "NCHAR":
case "NATIVE CHARACTER":
case "NVARCHAR":
return ColumnTypeEnum.Text;
case "BLOB":
return ColumnTypeEnum.Bytes;
case "BOOLEAN":
return ColumnTypeEnum.Boolean;
case "JSONB":
return ColumnTypeEnum.Json;
default:
debug("unknown decltype:", declType);
return null;
}
}
function mapDeclaredColumnTypes(columnTypes) {
const emptyIndices = /* @__PURE__ */ new Set();
const result = columnTypes.map((typeName, index) => {
const mappedType = mapDeclType(typeName);
if (mappedType === null) {
emptyIndices.add(index);
}
return mappedType;
});
return [result, emptyIndices];
}
function getColumnTypes(declaredTypes, rows) {
const [columnTypes, emptyIndices] = mapDeclaredColumnTypes(declaredTypes);
if (emptyIndices.size === 0) {
return columnTypes;
}
columnLoop: for (const columnIndex of emptyIndices) {
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
const candidateValue = rows[rowIndex][columnIndex];
if (candidateValue !== null) {
columnTypes[columnIndex] = inferColumnType(candidateValue);
continue columnLoop;
}
}
columnTypes[columnIndex] = ColumnTypeEnum.Int32;
}
return columnTypes;
}
function inferColumnType(value) {
switch (typeof value) {
case "string":
return ColumnTypeEnum.Text;
case "bigint":
return ColumnTypeEnum.Int64;
case "boolean":
return ColumnTypeEnum.Boolean;
case "number":
return ColumnTypeEnum.UnknownNumber;
case "object":
return inferObjectType(value);
default:
throw new UnexpectedTypeError(value);
}
}
function inferObjectType(value) {
if (value instanceof ArrayBuffer) {
return ColumnTypeEnum.Bytes;
}
throw new UnexpectedTypeError(value);
}
var UnexpectedTypeError = class extends Error {
name = "UnexpectedTypeError";
constructor(value) {
const type = typeof value;
const repr = type === "object" ? JSON.stringify(value) : String(value);
super(`unexpected value of type ${type}: ${repr}`);
}
};
function mapRow(row, columnTypes) {
const result = [];
for (let i = 0; i < row.length; i++) {
const value = row[i];
if (value instanceof ArrayBuffer) {
result[i] = new Uint8Array(value);
continue;
}
if (typeof value === "number" && (columnTypes[i] === ColumnTypeEnum.Int32 || columnTypes[i] === ColumnTypeEnum.Int64) && !Number.isInteger(value)) {
result[i] = Math.trunc(value);
continue;
}
if (["number", "bigint"].includes(typeof value) && columnTypes[i] === ColumnTypeEnum.DateTime) {
result[i] = new Date(Number(value)).toISOString();
continue;
}
if (typeof value === "bigint") {
result[i] = value.toString();
continue;
}
result[i] = value;
}
return result;
}
function mapArg(arg, argType, options) {
if (arg === null) {
return null;
}
if (typeof arg === "string" && argType.scalarType === "bigint") {
return BigInt(arg);
}
if (typeof arg === "string" && argType.scalarType === "decimal") {
return Number.parseFloat(arg);
}
if (typeof arg === "string" && argType.scalarType === "datetime") {
arg = new Date(arg);
}
if (arg instanceof Date) {
const format = options?.timestampFormat ?? "iso8601";
switch (format) {
case "unixepoch-ms":
return arg.getTime();
case "iso8601":
return arg.toISOString().replace("Z", "+00:00");
default:
throw new Error(`Unknown timestamp format: ${format}`);
}
}
if (typeof arg === "string" && argType.scalarType === "bytes") {
return Buffer.from(arg, "base64");
}
return arg;
}
// src/errors.ts
var SQLITE_BUSY = 5;
var PRIMARY_ERROR_CODE_MASK = 255;
function convertDriverError(error) {
if (isDriverError(error)) {
return {
originalCode: error.rawCode?.toString(),
originalMessage: error.message,
...mapDriverError(error)
};
}
throw error;
}
function mapDriverError(error) {
const rawCode = error.rawCode ?? error.cause?.["rawCode"] ?? 1;
switch (rawCode) {
case 2067:
case 1555: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "UniqueConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 1299: {
const fields = error.message.split("constraint failed: ").at(1)?.split(", ").map((field) => field.split(".").pop());
return {
kind: "NullConstraintViolation",
constraint: fields !== void 0 ? { fields } : void 0
};
}
case 787:
case 1811:
return {
kind: "ForeignKeyConstraintViolation",
constraint: { foreignKey: {} }
};
default:
if (rawCode && (rawCode & PRIMARY_ERROR_CODE_MASK) === SQLITE_BUSY) {
return {
kind: "SocketTimeout"
};
} else if (error.message.startsWith("no such table")) {
return {
kind: "TableDoesNotExist",
table: error.message.split(": ").at(1)
};
} else if (error.message.startsWith("no such column")) {
return {
kind: "ColumnNotFound",
column: error.message.split(": ").at(1)
};
} else if (error.message.includes("has no column named ")) {
return {
kind: "ColumnNotFound",
column: error.message.split("has no column named ").at(1)
};
}
return {
kind: "sqlite",
extendedCode: rawCode,
message: error.message
};
}
}
function isDriverError(error) {
return typeof error.code === "string" && typeof error.message === "string" && (typeof error.rawCode === "number" || error.rawCode === void 0);
}
// src/libsql.ts
var debug2 = Debug2("prisma:driver-adapter:libsql");
var LOCK_TAG = Symbol();
var LibSqlQueryable = class {
constructor(client, adapterOptions) {
this.client = client;
this.adapterOptions = adapterOptions;
}
provider = "sqlite";
adapterName = name;
[LOCK_TAG] = new Mutex();
/**
* Execute a query given as SQL, interpolating the given parameters.
*/
async queryRaw(query) {
const tag = "[js::query_raw]";
debug2(`${tag} %O`, query);
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
return {
columnNames: columns,
columnTypes,
rows: rows.map((row) => mapRow(row, columnTypes))
};
}
/**
* Execute a query given as SQL, interpolating the given parameters and
* returning the number of affected rows.
* Note: Queryable expects a u64, but napi.rs only supports u32.
*/
async executeRaw(query) {
const tag = "[js::execute_raw]";
debug2(`${tag} %O`, query);
return (await this.performIO(query)).rowsAffected ?? 0;
}
/**
* Run a query against the database, returning the result set.
* Should the query fail due to a connection error, the connection is
* marked as unhealthy.
*/
async performIO(query) {
const release = await this[LOCK_TAG].acquire();
try {
const result = await this.client.execute({
sql: query.sql,
args: query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions))
});
return result;
} catch (e) {
this.onError(e);
} finally {
release();
}
}
onError(error) {
debug2("Error in performIO: %O", error);
throw new DriverAdapterError(convertDriverError(error));
}
};
var LibSqlTransaction = class extends LibSqlQueryable {
constructor(client, options, adapterOptions, unlockParent) {
super(client, adapterOptions);
this.options = options;
this.#unlockParent = unlockParent;
}
#unlockParent;
async commit() {
debug2(`[js::commit]`);
try {
await this.client.commit();
} finally {
this.#unlockParent();
}
}
async rollback() {
debug2(`[js::rollback]`);
try {
await this.client.rollback();
} catch (error) {
debug2("error in rollback:", error);
} finally {
this.#unlockParent();
}
}
async createSavepoint(name2) {
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
async rollbackToSavepoint(name2) {
await this.executeRaw({ sql: `ROLLBACK TO ${name2}`, args: [], argTypes: [] });
}
async releaseSavepoint(name2) {
await this.executeRaw({ sql: `RELEASE SAVEPOINT ${name2}`, args: [], argTypes: [] });
}
};
var PrismaLibSqlAdapter = class extends LibSqlQueryable {
constructor(client, adapterOptions) {
super(client, adapterOptions);
}
async executeScript(script) {
const release = await this[LOCK_TAG].acquire();
try {
await this.client.executeMultiple(script);
} catch (e) {
this.onError(e);
} finally {
release();
}
}
async startTransaction(isolationLevel) {
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
throw new DriverAdapterError({
kind: "InvalidIsolationLevel",
level: isolationLevel
});
}
const options = {
usePhantomQuery: true
};
const tag = "[js::startTransaction]";
debug2("%s options: %O", tag, options);
const release = await this[LOCK_TAG].acquire();
try {
const tx = await this.client.transaction("deferred");
return new LibSqlTransaction(tx, options, this.adapterOptions, release);
} catch (e) {
release();
this.onError(e);
}
}
dispose() {
this.client.close();
return Promise.resolve();
}
};
var PrismaLibSqlAdapterFactoryBase = class {
provider = "sqlite";
adapterName = name;
#config;
#options;
constructor(config, options) {
this.#config = config;
this.#options = options;
}
connect() {
return Promise.resolve(new PrismaLibSqlAdapter(this.createClient(this.#config), this.#options));
}
connectToShadowDb() {
return Promise.resolve(
new PrismaLibSqlAdapter(this.createClient({ ...this.#config, url: ":memory:" }), this.#options)
);
}
};
// src/libsql-web.ts
var PrismaLibSqlWebAdapterFactory = class extends PrismaLibSqlAdapterFactoryBase {
createClient(config) {
return createClient(config);
}
};
export {
PrismaLibSqlWebAdapterFactory as PrismaLibSql
};

53
node_modules/@prisma/adapter-libsql/package.json generated vendored Normal file
View File

@@ -0,0 +1,53 @@
{
"name": "@prisma/adapter-libsql",
"version": "7.6.0",
"description": "Prisma's driver adapter for libSQL and Turso",
"main": "dist/index-node.js",
"module": "dist/index-node.mjs",
"types": "dist/index-node.d.ts",
"exports": {
".": {
"require": {
"types": "./dist/index-node.d.ts",
"default": "./dist/index-node.js"
},
"import": {
"types": "./dist/index-node.d.mts",
"default": "./dist/index-node.mjs"
}
},
"./web": {
"require": {
"types": "./dist/index-web.d.ts",
"default": "./dist/index-web.js"
},
"import": {
"types": "./dist/index-web.d.mts",
"default": "./dist/index-web.mjs"
}
}
},
"repository": {
"type": "git",
"url": "https://github.com/prisma/prisma.git",
"directory": "packages/adapter-libsql"
},
"files": [
"dist",
"README.md"
],
"keywords": [],
"author": "Alexey Orlenko <orlenko@prisma.io>",
"license": "Apache-2.0",
"sideEffects": false,
"dependencies": {
"@libsql/client": "^0.17.0",
"async-mutex": "0.5.0",
"@prisma/driver-adapter-utils": "7.6.0"
},
"scripts": {
"dev": "DEV=true tsx helpers/build.ts",
"build": "tsx helpers/build.ts",
"test": "vitest run"
}
}