@prisma/adapter-d1 7.2.0 → 7.3.0-integration-prisma6-fix-cloudflare-engine.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,696 +0,0 @@
1
- // package.json
2
- var name = "@prisma/adapter-d1";
3
-
4
- // src/d1-http.ts
5
- import {
6
- Debug,
7
- DriverAdapterError
8
- } from "@prisma/driver-adapter-utils";
9
-
10
- // ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs
11
- var FORCE_COLOR;
12
- var NODE_DISABLE_COLORS;
13
- var NO_COLOR;
14
- var TERM;
15
- var isTTY = true;
16
- if (typeof process !== "undefined") {
17
- ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
18
- isTTY = process.stdout && process.stdout.isTTY;
19
- }
20
- var $ = {
21
- enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY)
22
- };
23
- function init(x, y) {
24
- let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
25
- let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
26
- return function(txt) {
27
- if (!$.enabled || txt == null) return txt;
28
- return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
29
- };
30
- }
31
- var reset = init(0, 0);
32
- var bold = init(1, 22);
33
- var dim = init(2, 22);
34
- var italic = init(3, 23);
35
- var underline = init(4, 24);
36
- var inverse = init(7, 27);
37
- var hidden = init(8, 28);
38
- var strikethrough = init(9, 29);
39
- var black = init(30, 39);
40
- var red = init(31, 39);
41
- var green = init(32, 39);
42
- var yellow = init(33, 39);
43
- var blue = init(34, 39);
44
- var magenta = init(35, 39);
45
- var cyan = init(36, 39);
46
- var white = init(37, 39);
47
- var gray = init(90, 39);
48
- var grey = init(90, 39);
49
- var bgBlack = init(40, 49);
50
- var bgRed = init(41, 49);
51
- var bgGreen = init(42, 49);
52
- var bgYellow = init(43, 49);
53
- var bgBlue = init(44, 49);
54
- var bgMagenta = init(45, 49);
55
- var bgCyan = init(46, 49);
56
- var bgWhite = init(47, 49);
57
-
58
- // src/d1-http.ts
59
- import ky from "ky";
60
-
61
- // src/constants.ts
62
- var MAX_BIND_VALUES = 98;
63
- var GENERIC_SQLITE_ERROR = 1;
64
-
65
- // src/conversion.ts
66
- import { ColumnTypeEnum } from "@prisma/driver-adapter-utils";
67
- function getColumnTypes(columnNames, rows) {
68
- const columnTypes = [];
69
- columnLoop: for (let columnIndex = 0; columnIndex < columnNames.length; columnIndex++) {
70
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
71
- const candidateValue = rows[rowIndex][columnIndex];
72
- if (candidateValue !== null) {
73
- const inferred = inferColumnType(candidateValue);
74
- if (columnTypes[columnIndex] === void 0 || inferred === ColumnTypeEnum.Text) {
75
- columnTypes[columnIndex] = inferred;
76
- }
77
- if (inferred !== ColumnTypeEnum.UnknownNumber) {
78
- continue columnLoop;
79
- }
80
- }
81
- }
82
- if (columnTypes[columnIndex] === void 0) {
83
- columnTypes[columnIndex] = ColumnTypeEnum.Int32;
84
- }
85
- }
86
- return columnTypes;
87
- }
88
- function inferColumnType(value) {
89
- switch (typeof value) {
90
- case "string":
91
- return inferStringType(value);
92
- case "number":
93
- return inferNumberType(value);
94
- case "object":
95
- return inferObjectType(value);
96
- default:
97
- throw new UnexpectedTypeError(value);
98
- }
99
- }
100
- var isoDateRegex = new RegExp(
101
- /^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))$|^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$|^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$/
102
- );
103
- var sqliteDateRegex = /^\d{4}-[0-1]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d$/;
104
- function isISODate(str) {
105
- return isoDateRegex.test(str) || sqliteDateRegex.test(str);
106
- }
107
- function inferStringType(value) {
108
- if (isISODate(value)) {
109
- return ColumnTypeEnum.DateTime;
110
- }
111
- return ColumnTypeEnum.Text;
112
- }
113
- function inferNumberType(_) {
114
- return ColumnTypeEnum.UnknownNumber;
115
- }
116
- function inferObjectType(value) {
117
- if (value instanceof Array) {
118
- return ColumnTypeEnum.Bytes;
119
- }
120
- throw new UnexpectedTypeError(value);
121
- }
122
- var UnexpectedTypeError = class extends Error {
123
- name = "UnexpectedTypeError";
124
- constructor(value) {
125
- const type = typeof value;
126
- const repr = type === "object" ? JSON.stringify(value) : String(value);
127
- super(`unexpected value of type ${type}: ${repr}`);
128
- }
129
- };
130
- function mapRow(result, columnTypes) {
131
- for (let i = 0; i < result.length; i++) {
132
- const value = result[i];
133
- if (value instanceof ArrayBuffer) {
134
- result[i] = new Uint8Array(value);
135
- continue;
136
- }
137
- if (typeof value === "number" && (columnTypes[i] === ColumnTypeEnum.Int32 || columnTypes[i] === ColumnTypeEnum.Int64) && !Number.isInteger(value)) {
138
- result[i] = Math.trunc(value);
139
- continue;
140
- }
141
- if (typeof value === "number" && columnTypes[i] === ColumnTypeEnum.Text) {
142
- result[i] = value.toString();
143
- continue;
144
- }
145
- if (typeof value === "bigint") {
146
- result[i] = value.toString();
147
- continue;
148
- }
149
- if (columnTypes[i] === ColumnTypeEnum.Boolean) {
150
- result[i] = JSON.parse(value);
151
- }
152
- }
153
- return result;
154
- }
155
- function mapArg(arg, argType) {
156
- if (arg === null) {
157
- return null;
158
- }
159
- if (typeof arg === "bigint" || argType.scalarType === "bigint") {
160
- const asInt56 = Number.parseInt(`${arg}`);
161
- if (!Number.isSafeInteger(asInt56)) {
162
- throw new Error(`Invalid Int64-encoded value received: ${arg}`);
163
- }
164
- return asInt56;
165
- }
166
- if (typeof arg === "string" && argType.scalarType === "int") {
167
- return Number.parseInt(arg);
168
- }
169
- if (typeof arg === "string" && argType.scalarType === "float") {
170
- return Number.parseFloat(arg);
171
- }
172
- if (typeof arg === "string" && argType.scalarType === "decimal") {
173
- return Number.parseFloat(arg);
174
- }
175
- if (arg === true) {
176
- return 1;
177
- }
178
- if (arg === false) {
179
- return 0;
180
- }
181
- if (typeof arg === "string" && argType.scalarType === "datetime") {
182
- arg = new Date(arg);
183
- }
184
- if (arg instanceof Date) {
185
- return arg.toISOString().replace("Z", "+00:00");
186
- }
187
- if (typeof arg === "string" && argType.scalarType === "bytes") {
188
- return Array.from(Buffer.from(arg, "base64"));
189
- }
190
- if (arg instanceof Uint8Array) {
191
- return Array.from(arg);
192
- }
193
- return arg;
194
- }
195
-
196
- // src/errors.ts
197
- function convertDriverError(error) {
198
- if (isDriverError(error)) {
199
- return {
200
- originalMessage: error.message,
201
- ...mapDriverError(error)
202
- };
203
- }
204
- throw error;
205
- }
206
- function mapDriverError(error) {
207
- let stripped = error.message.split("D1_ERROR: ").at(1) ?? error.message;
208
- stripped = stripped.split("SqliteError: ").at(1) ?? stripped;
209
- if (stripped.startsWith("UNIQUE constraint failed") || stripped.startsWith("PRIMARY KEY constraint failed")) {
210
- const fields = stripped.split(": ").at(1)?.split(", ").map((field) => field.split(".").pop());
211
- return {
212
- kind: "UniqueConstraintViolation",
213
- constraint: fields !== void 0 ? { fields } : void 0
214
- };
215
- } else if (stripped.startsWith("NOT NULL constraint failed")) {
216
- const fields = stripped.split(": ").at(1)?.split(", ").map((field) => field.split(".").pop());
217
- return {
218
- kind: "NullConstraintViolation",
219
- constraint: fields !== void 0 ? { fields } : void 0
220
- };
221
- } else if (stripped.startsWith("FOREIGN KEY constraint failed") || stripped.startsWith("CHECK constraint failed")) {
222
- return {
223
- kind: "ForeignKeyConstraintViolation",
224
- constraint: { foreignKey: {} }
225
- };
226
- } else if (stripped.startsWith("no such table")) {
227
- return {
228
- kind: "TableDoesNotExist",
229
- table: stripped.split(": ").at(1)
230
- };
231
- } else if (stripped.startsWith("no such column")) {
232
- return {
233
- kind: "ColumnNotFound",
234
- column: stripped.split(": ").at(1)
235
- };
236
- } else if (stripped.includes("has no column named ")) {
237
- return {
238
- kind: "ColumnNotFound",
239
- column: stripped.split("has no column named ").at(1)
240
- };
241
- }
242
- return {
243
- kind: "sqlite",
244
- extendedCode: error["code"] ?? error["cause"]?.["code"] ?? 1,
245
- message: error.message
246
- };
247
- }
248
- function isDriverError(error) {
249
- return typeof error["message"] === "string";
250
- }
251
-
252
- // src/d1-http.ts
253
- var debug = Debug("prisma:driver-adapter:d1-http");
254
- function onUnsuccessfulD1HttpResponse({ errors }) {
255
- debug("D1 HTTP Errors: %O", errors);
256
- const error = errors.at(0) ?? { message: "Unknown error", code: GENERIC_SQLITE_ERROR };
257
- throw new DriverAdapterError(convertDriverError(error));
258
- }
259
- function onGenericD1HttpError(error) {
260
- debug("HTTP Error: %O", error);
261
- throw new DriverAdapterError(convertDriverError(error));
262
- }
263
- function onError(error) {
264
- console.error("Error in performIO: %O", error);
265
- throw new DriverAdapterError(convertDriverError(error));
266
- }
267
- async function performRawQuery(client, options) {
268
- try {
269
- const response = await client.post("raw", options).json();
270
- const tag = "[js::performRawQuery]";
271
- debug(`${tag} %O`, {
272
- success: response.success,
273
- errors: response.errors,
274
- messages: response.messages,
275
- result: response.result
276
- });
277
- if (!response.success) {
278
- onUnsuccessfulD1HttpResponse(response);
279
- }
280
- return response.result;
281
- } catch (e) {
282
- onGenericD1HttpError(e);
283
- }
284
- }
285
- function isD1HttpParams(params) {
286
- return typeof params === "object" && params !== null && "CLOUDFLARE_D1_TOKEN" in params && "CLOUDFLARE_ACCOUNT_ID" in params && "CLOUDFLARE_DATABASE_ID" in params;
287
- }
288
- var D1HttpQueryable = class {
289
- constructor(client) {
290
- this.client = client;
291
- }
292
- provider = "sqlite";
293
- adapterName = `${name}-http`;
294
- /**
295
- * Execute a query given as SQL, interpolating the given parameters.
296
- */
297
- async queryRaw(query) {
298
- const tag = "[js::query_raw]";
299
- debug(`${tag} %O`, query);
300
- const data = await this.performIO(query);
301
- const convertedData = this.convertData(data);
302
- return convertedData;
303
- }
304
- convertData({ columnNames, rows: results }) {
305
- if (results.length === 0) {
306
- return {
307
- columnNames: [],
308
- columnTypes: [],
309
- rows: []
310
- };
311
- }
312
- const columnTypes = getColumnTypes(columnNames, results);
313
- const rows = results.map((value) => mapRow(value, columnTypes));
314
- return {
315
- columnNames,
316
- columnTypes,
317
- rows
318
- };
319
- }
320
- /**
321
- * Execute a query given as SQL, interpolating the given parameters and
322
- * returning the number of affected rows.
323
- * Note: Queryable expects a u64, but napi.rs only supports u32.
324
- */
325
- async executeRaw(query) {
326
- const tag = "[js::execute_raw]";
327
- debug(`${tag} %O`, query);
328
- const result = await this.performIO(query);
329
- return result.affectedRows ?? 0;
330
- }
331
- async performIO(query) {
332
- try {
333
- const body = {
334
- json: {
335
- sql: query.sql,
336
- params: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
337
- }
338
- };
339
- const tag = "[js::perform_io]";
340
- debug(`${tag} %O`, body);
341
- const results = await performRawQuery(this.client, body);
342
- if (results.length !== 1) {
343
- throw new Error("Expected exactly one result");
344
- }
345
- const result = results[0];
346
- const { columns: columnNames = [], rows = [] } = result.results ?? {};
347
- const affectedRows = result.meta?.changes;
348
- return { rows, columnNames, affectedRows };
349
- } catch (e) {
350
- onError(e);
351
- }
352
- }
353
- };
354
- var D1HttpTransaction = class extends D1HttpQueryable {
355
- constructor(client, options) {
356
- super(client);
357
- this.options = options;
358
- }
359
- async commit() {
360
- debug(`[js::commit]`);
361
- }
362
- async rollback() {
363
- debug(`[js::rollback]`);
364
- }
365
- };
366
- var PrismaD1HttpAdapter = class extends D1HttpQueryable {
367
- constructor(params, release) {
368
- const D1_API_BASE_URL = `https://api.cloudflare.com/client/v4/accounts/${params.CLOUDFLARE_ACCOUNT_ID}/d1/database/${params.CLOUDFLARE_DATABASE_ID}`;
369
- const client = ky.create({
370
- prefixUrl: D1_API_BASE_URL,
371
- headers: {
372
- Authorization: `Bearer ${params.CLOUDFLARE_D1_TOKEN}`
373
- },
374
- // Don't automatically throw on non-2xx status codes
375
- throwHttpErrors: false
376
- });
377
- super(client);
378
- this.release = release;
379
- }
380
- tags = {
381
- error: red("prisma:error"),
382
- warn: yellow("prisma:warn"),
383
- info: cyan("prisma:info"),
384
- query: blue("prisma:query")
385
- };
386
- alreadyWarned = /* @__PURE__ */ new Set();
387
- /**
388
- * This will warn once per transaction
389
- * e.g. the following two explicit transactions
390
- * will only trigger _two_ warnings
391
- *
392
- * ```ts
393
- * await prisma.$transaction([ ...queries ])
394
- * await prisma.$transaction([ ...moreQueries ])
395
- * ```
396
- */
397
- warnOnce = (key, message, ...args) => {
398
- if (!this.alreadyWarned.has(key)) {
399
- this.alreadyWarned.add(key);
400
- console.info(`${this.tags.warn} ${message}`, ...args);
401
- }
402
- };
403
- async executeScript(script) {
404
- try {
405
- await performRawQuery(this.client, {
406
- json: {
407
- sql: script
408
- }
409
- });
410
- } catch (error) {
411
- onError(error);
412
- }
413
- }
414
- getConnectionInfo() {
415
- return {
416
- maxBindValues: MAX_BIND_VALUES,
417
- supportsRelationJoins: false
418
- };
419
- }
420
- async startTransaction(isolationLevel) {
421
- if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
422
- throw new DriverAdapterError({
423
- kind: "InvalidIsolationLevel",
424
- level: isolationLevel
425
- });
426
- }
427
- this.warnOnce(
428
- "D1 Transaction",
429
- "Cloudflare D1 does not support transactions yet. When using Prisma's D1 adapter, implicit & explicit transactions will be ignored and run as individual queries, which breaks the guarantees of the ACID properties of transactions. For more details see https://pris.ly/d/d1-transactions"
430
- );
431
- const options = {
432
- usePhantomQuery: true
433
- };
434
- const tag = "[js::startTransaction]";
435
- debug("%s options: %O", tag, options);
436
- return new D1HttpTransaction(this.client, options);
437
- }
438
- async dispose() {
439
- await this.release?.();
440
- }
441
- };
442
- var PrismaD1HttpAdapterFactory = class {
443
- constructor(params) {
444
- this.params = params;
445
- }
446
- provider = "sqlite";
447
- adapterName = `${name}-http`;
448
- async connect() {
449
- return new PrismaD1HttpAdapter(this.params, async () => {
450
- });
451
- }
452
- async connectToShadowDb() {
453
- const D1_API_BASE_URL = `https://api.cloudflare.com/client/v4/accounts/${this.params.CLOUDFLARE_ACCOUNT_ID}/d1/database`;
454
- const client = ky.create({
455
- headers: {
456
- Authorization: `Bearer ${this.params.CLOUDFLARE_D1_TOKEN}`
457
- },
458
- // Don't throw on non-2xx status codes
459
- throwHttpErrors: false
460
- });
461
- const createShadowDatabase = async () => {
462
- const tag = "[js::connectToShadowDb::createShadowDatabase]";
463
- const SHADOW_DATABASE_PREFIX = "_prisma_shadow_";
464
- const CLOUDFLARE_SHADOW_DATABASE_NAME = `${SHADOW_DATABASE_PREFIX}${globalThis.crypto.randomUUID()}`;
465
- debug(`${tag} creating database %s`, CLOUDFLARE_SHADOW_DATABASE_NAME);
466
- try {
467
- const response = await client.post(D1_API_BASE_URL, {
468
- json: {
469
- name: CLOUDFLARE_SHADOW_DATABASE_NAME
470
- }
471
- }).json();
472
- debug(`${tag} %O`, response);
473
- if (!response.success) {
474
- onUnsuccessfulD1HttpResponse(response);
475
- }
476
- const { uuid: CLOUDFLARE_SHADOW_DATABASE_ID2 } = response.result;
477
- debug(`${tag} created database %s with ID %s`, CLOUDFLARE_SHADOW_DATABASE_NAME, CLOUDFLARE_SHADOW_DATABASE_ID2);
478
- return CLOUDFLARE_SHADOW_DATABASE_ID2;
479
- } catch (e) {
480
- onGenericD1HttpError(e);
481
- }
482
- };
483
- const CLOUDFLARE_SHADOW_DATABASE_ID = this.params.CLOUDFLARE_SHADOW_DATABASE_ID ?? await createShadowDatabase();
484
- const dispose = async () => {
485
- const tag = "[js::connectToShadowDb::dispose]";
486
- try {
487
- debug(`${tag} deleting database %s`, CLOUDFLARE_SHADOW_DATABASE_ID);
488
- const response = await client.delete(`${D1_API_BASE_URL}/${CLOUDFLARE_SHADOW_DATABASE_ID}`).json();
489
- debug(`${tag} %O`, response);
490
- if (!response.success) {
491
- onUnsuccessfulD1HttpResponse(response);
492
- }
493
- } catch (e) {
494
- onGenericD1HttpError(e);
495
- }
496
- };
497
- return new PrismaD1HttpAdapter(this.params, dispose);
498
- }
499
- };
500
-
501
- // src/d1-worker.ts
502
- import {
503
- Debug as Debug2,
504
- DriverAdapterError as DriverAdapterError2
505
- } from "@prisma/driver-adapter-utils";
506
- var debug2 = Debug2("prisma:driver-adapter:d1");
507
- var D1WorkerQueryable = class {
508
- constructor(client) {
509
- this.client = client;
510
- }
511
- provider = "sqlite";
512
- adapterName = name;
513
- /**
514
- * Execute a query given as SQL, interpolating the given parameters.
515
- */
516
- async queryRaw(query) {
517
- const tag = "[js::query_raw]";
518
- debug2(`${tag} %O`, query);
519
- const data = await this.performIO(query);
520
- const convertedData = this.convertData(data);
521
- return convertedData;
522
- }
523
- convertData(ioResult) {
524
- const columnNames = ioResult[0];
525
- const results = ioResult[1];
526
- if (results.length === 0) {
527
- return {
528
- columnNames: [],
529
- columnTypes: [],
530
- rows: []
531
- };
532
- }
533
- const columnTypes = Object.values(getColumnTypes(columnNames, results));
534
- const rows = results.map((value) => mapRow(value, columnTypes));
535
- return {
536
- columnNames,
537
- // * Note: without Object.values the array looks like
538
- // * columnTypes: [ id: 128 ],
539
- // * and errors with:
540
- // * ✘ [ERROR] A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.
541
- columnTypes,
542
- rows
543
- };
544
- }
545
- /**
546
- * Execute a query given as SQL, interpolating the given parameters and
547
- * returning the number of affected rows.
548
- * Note: Queryable expects a u64, but napi.rs only supports u32.
549
- */
550
- async executeRaw(query) {
551
- const tag = "[js::execute_raw]";
552
- debug2(`${tag} %O`, query);
553
- const result = await this.performIO(query, true);
554
- return result.meta.changes ?? 0;
555
- }
556
- async performIO(query, executeRaw = false) {
557
- try {
558
- const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
559
- const stmt = this.client.prepare(query.sql).bind(...args);
560
- if (executeRaw) {
561
- return await stmt.run();
562
- } else {
563
- const [columnNames, ...rows] = await stmt.raw({ columnNames: true });
564
- return [columnNames, rows];
565
- }
566
- } catch (e) {
567
- onError2(e);
568
- }
569
- }
570
- };
571
- var D1WorkerTransaction = class extends D1WorkerQueryable {
572
- constructor(client, options) {
573
- super(client);
574
- this.options = options;
575
- }
576
- async commit() {
577
- debug2(`[js::commit]`);
578
- }
579
- async rollback() {
580
- debug2(`[js::rollback]`);
581
- }
582
- };
583
- var PrismaD1WorkerAdapter = class extends D1WorkerQueryable {
584
- constructor(client, release) {
585
- super(client);
586
- this.release = release;
587
- }
588
- tags = {
589
- error: red("prisma:error"),
590
- warn: yellow("prisma:warn"),
591
- info: cyan("prisma:info"),
592
- query: blue("prisma:query")
593
- };
594
- alreadyWarned = /* @__PURE__ */ new Set();
595
- /**
596
- * This will warn once per transaction
597
- * e.g. the following two explicit transactions
598
- * will only trigger _two_ warnings
599
- *
600
- * ```ts
601
- * await prisma.$transaction([ ...queries ])
602
- * await prisma.$transaction([ ...moreQueries ])
603
- * ```
604
- */
605
- warnOnce = (key, message, ...args) => {
606
- if (!this.alreadyWarned.has(key)) {
607
- this.alreadyWarned.add(key);
608
- console.info(`${this.tags.warn} ${message}`, ...args);
609
- }
610
- };
611
- async executeScript(script) {
612
- try {
613
- await this.client.exec(script);
614
- } catch (error) {
615
- onError2(error);
616
- }
617
- }
618
- getConnectionInfo() {
619
- return {
620
- maxBindValues: MAX_BIND_VALUES,
621
- supportsRelationJoins: false
622
- };
623
- }
624
- async startTransaction(isolationLevel) {
625
- if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
626
- throw new DriverAdapterError2({
627
- kind: "InvalidIsolationLevel",
628
- level: isolationLevel
629
- });
630
- }
631
- this.warnOnce(
632
- "D1 Transaction",
633
- "Cloudflare D1 does not support transactions yet. When using Prisma's D1 adapter, implicit & explicit transactions will be ignored and run as individual queries, which breaks the guarantees of the ACID properties of transactions. For more details see https://pris.ly/d/d1-transactions"
634
- );
635
- const options = {
636
- usePhantomQuery: true
637
- };
638
- const tag = "[js::startTransaction]";
639
- debug2("%s options: %O", tag, options);
640
- return new D1WorkerTransaction(this.client, options);
641
- }
642
- async dispose() {
643
- await this.release?.();
644
- }
645
- };
646
- var PrismaD1WorkerAdapterFactory = class {
647
- constructor(client) {
648
- this.client = client;
649
- }
650
- provider = "sqlite";
651
- adapterName = name;
652
- async connect() {
653
- return new PrismaD1WorkerAdapter(this.client, async () => {
654
- });
655
- }
656
- };
657
- function onError2(error) {
658
- console.error("Error in performIO: %O", error);
659
- throw new DriverAdapterError2(convertDriverError(error));
660
- }
661
-
662
- // src/d1.ts
663
- var PrismaD1 = class {
664
- provider = "sqlite";
665
- adapterName = name;
666
- connect;
667
- connectToShadowDb;
668
- constructor(params) {
669
- if (isD1HttpParams(params)) {
670
- const factory = new PrismaD1HttpAdapterFactory(params);
671
- const self = this;
672
- self.connect = factory.connect.bind(factory);
673
- self.connectToShadowDb = factory.connectToShadowDb.bind(factory);
674
- } else {
675
- const factory = new PrismaD1WorkerAdapterFactory(params);
676
- const self = this;
677
- self.connect = factory.connect.bind(factory);
678
- }
679
- }
680
- };
681
-
682
- // src/node/list-local-databases.ts
683
- import fs from "node:fs";
684
- import path from "node:path";
685
- var localD1DatabasePath = path.join(".wrangler", "state", "v3", "d1", "miniflare-D1DatabaseObject");
686
- function listLocalDatabases() {
687
- const cwd = process.cwd();
688
- const d1DirPath = path.join(cwd, localD1DatabasePath);
689
- const files = fs.readdirSync(d1DirPath);
690
- return files.filter((file) => file.endsWith(".sqlite")).map((file) => path.join(d1DirPath, file));
691
- }
692
- export {
693
- PrismaD1,
694
- PrismaD1HttpAdapterFactory as PrismaD1Http,
695
- listLocalDatabases
696
- };