@prisma/adapter-neon 6.18.0-dev.2 → 6.18.0-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +20 -10
- package/dist/index.mjs +20 -10
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -68,6 +68,7 @@ var ArrayColumnType = {
|
|
|
68
68
|
OID_ARRAY: 1028,
|
|
69
69
|
TEXT_ARRAY: 1009,
|
|
70
70
|
TIMESTAMP_ARRAY: 1115,
|
|
71
|
+
TIMESTAMPTZ_ARRAY: 1185,
|
|
71
72
|
TIME_ARRAY: 1183,
|
|
72
73
|
UUID_ARRAY: 2951,
|
|
73
74
|
VARBIT_ARRAY: 1563,
|
|
@@ -295,10 +296,10 @@ function normalize_date(date) {
|
|
|
295
296
|
return date;
|
|
296
297
|
}
|
|
297
298
|
function normalize_timestamp(time) {
|
|
298
|
-
return
|
|
299
|
+
return `${time.replace(" ", "T")}+00:00`;
|
|
299
300
|
}
|
|
300
|
-
function
|
|
301
|
-
return
|
|
301
|
+
function normalize_timestamptz(time) {
|
|
302
|
+
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
302
303
|
}
|
|
303
304
|
function normalize_time(time) {
|
|
304
305
|
return time;
|
|
@@ -341,7 +342,8 @@ var customParsers = {
|
|
|
341
342
|
[ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
|
|
342
343
|
[ScalarColumnType.TIMESTAMP]: normalize_timestamp,
|
|
343
344
|
[ArrayColumnType.TIMESTAMP_ARRAY]: normalize_array(normalize_timestamp),
|
|
344
|
-
[ScalarColumnType.TIMESTAMPTZ]:
|
|
345
|
+
[ScalarColumnType.TIMESTAMPTZ]: normalize_timestamptz,
|
|
346
|
+
[ArrayColumnType.TIMESTAMPTZ_ARRAY]: normalize_array(normalize_timestamptz),
|
|
345
347
|
[ScalarColumnType.MONEY]: normalize_money,
|
|
346
348
|
[ArrayColumnType.MONEY_ARRAY]: normalize_array(normalize_money),
|
|
347
349
|
[ScalarColumnType.JSON]: toJson,
|
|
@@ -389,11 +391,11 @@ function mapArg(arg, argType) {
|
|
|
389
391
|
function formatDateTime(date) {
|
|
390
392
|
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
391
393
|
const ms = date.getUTCMilliseconds();
|
|
392
|
-
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
394
|
+
return pad(date.getUTCFullYear(), 4) + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
393
395
|
}
|
|
394
396
|
function formatDate(date) {
|
|
395
397
|
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
396
|
-
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
398
|
+
return pad(date.getUTCFullYear(), 4) + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
397
399
|
}
|
|
398
400
|
function formatTime(date) {
|
|
399
401
|
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
@@ -593,16 +595,19 @@ var NeonWsQueryable = class extends NeonQueryable {
|
|
|
593
595
|
}
|
|
594
596
|
};
|
|
595
597
|
var NeonTransaction = class extends NeonWsQueryable {
|
|
596
|
-
constructor(client, options) {
|
|
598
|
+
constructor(client, options, cleanup) {
|
|
597
599
|
super(client);
|
|
598
600
|
this.options = options;
|
|
601
|
+
this.cleanup = cleanup;
|
|
599
602
|
}
|
|
600
603
|
async commit() {
|
|
601
604
|
debug(`[js::commit]`);
|
|
605
|
+
this.cleanup?.();
|
|
602
606
|
this.client.release();
|
|
603
607
|
}
|
|
604
608
|
async rollback() {
|
|
605
609
|
debug(`[js::rollback]`);
|
|
610
|
+
this.cleanup?.();
|
|
606
611
|
this.client.release();
|
|
607
612
|
}
|
|
608
613
|
};
|
|
@@ -622,12 +627,16 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
|
|
|
622
627
|
const tag = "[js::startTransaction]";
|
|
623
628
|
debug("%s options: %O", tag, options);
|
|
624
629
|
const conn = await this.client.connect().catch((error) => this.onError(error));
|
|
625
|
-
|
|
630
|
+
const onError = (err) => {
|
|
626
631
|
debug(`Error from pool connection: ${err.message} %O`, err);
|
|
627
632
|
this.options?.onConnectionError?.(err);
|
|
628
|
-
}
|
|
633
|
+
};
|
|
634
|
+
conn.on("error", onError);
|
|
635
|
+
const cleanup = () => {
|
|
636
|
+
conn.removeListener("error", onError);
|
|
637
|
+
};
|
|
629
638
|
try {
|
|
630
|
-
const tx = new NeonTransaction(conn, options);
|
|
639
|
+
const tx = new NeonTransaction(conn, options, cleanup);
|
|
631
640
|
await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
|
|
632
641
|
if (isolationLevel) {
|
|
633
642
|
await tx.executeRaw({
|
|
@@ -638,6 +647,7 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
|
|
|
638
647
|
}
|
|
639
648
|
return tx;
|
|
640
649
|
} catch (error) {
|
|
650
|
+
cleanup();
|
|
641
651
|
conn.release(error);
|
|
642
652
|
this.onError(error);
|
|
643
653
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -31,6 +31,7 @@ var ArrayColumnType = {
|
|
|
31
31
|
OID_ARRAY: 1028,
|
|
32
32
|
TEXT_ARRAY: 1009,
|
|
33
33
|
TIMESTAMP_ARRAY: 1115,
|
|
34
|
+
TIMESTAMPTZ_ARRAY: 1185,
|
|
34
35
|
TIME_ARRAY: 1183,
|
|
35
36
|
UUID_ARRAY: 2951,
|
|
36
37
|
VARBIT_ARRAY: 1563,
|
|
@@ -258,10 +259,10 @@ function normalize_date(date) {
|
|
|
258
259
|
return date;
|
|
259
260
|
}
|
|
260
261
|
function normalize_timestamp(time) {
|
|
261
|
-
return
|
|
262
|
+
return `${time.replace(" ", "T")}+00:00`;
|
|
262
263
|
}
|
|
263
|
-
function
|
|
264
|
-
return
|
|
264
|
+
function normalize_timestamptz(time) {
|
|
265
|
+
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
265
266
|
}
|
|
266
267
|
function normalize_time(time) {
|
|
267
268
|
return time;
|
|
@@ -304,7 +305,8 @@ var customParsers = {
|
|
|
304
305
|
[ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
|
|
305
306
|
[ScalarColumnType.TIMESTAMP]: normalize_timestamp,
|
|
306
307
|
[ArrayColumnType.TIMESTAMP_ARRAY]: normalize_array(normalize_timestamp),
|
|
307
|
-
[ScalarColumnType.TIMESTAMPTZ]:
|
|
308
|
+
[ScalarColumnType.TIMESTAMPTZ]: normalize_timestamptz,
|
|
309
|
+
[ArrayColumnType.TIMESTAMPTZ_ARRAY]: normalize_array(normalize_timestamptz),
|
|
308
310
|
[ScalarColumnType.MONEY]: normalize_money,
|
|
309
311
|
[ArrayColumnType.MONEY_ARRAY]: normalize_array(normalize_money),
|
|
310
312
|
[ScalarColumnType.JSON]: toJson,
|
|
@@ -352,11 +354,11 @@ function mapArg(arg, argType) {
|
|
|
352
354
|
function formatDateTime(date) {
|
|
353
355
|
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
354
356
|
const ms = date.getUTCMilliseconds();
|
|
355
|
-
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
357
|
+
return pad(date.getUTCFullYear(), 4) + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
356
358
|
}
|
|
357
359
|
function formatDate(date) {
|
|
358
360
|
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
359
|
-
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
361
|
+
return pad(date.getUTCFullYear(), 4) + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
360
362
|
}
|
|
361
363
|
function formatTime(date) {
|
|
362
364
|
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
@@ -556,16 +558,19 @@ var NeonWsQueryable = class extends NeonQueryable {
|
|
|
556
558
|
}
|
|
557
559
|
};
|
|
558
560
|
var NeonTransaction = class extends NeonWsQueryable {
|
|
559
|
-
constructor(client, options) {
|
|
561
|
+
constructor(client, options, cleanup) {
|
|
560
562
|
super(client);
|
|
561
563
|
this.options = options;
|
|
564
|
+
this.cleanup = cleanup;
|
|
562
565
|
}
|
|
563
566
|
async commit() {
|
|
564
567
|
debug(`[js::commit]`);
|
|
568
|
+
this.cleanup?.();
|
|
565
569
|
this.client.release();
|
|
566
570
|
}
|
|
567
571
|
async rollback() {
|
|
568
572
|
debug(`[js::rollback]`);
|
|
573
|
+
this.cleanup?.();
|
|
569
574
|
this.client.release();
|
|
570
575
|
}
|
|
571
576
|
};
|
|
@@ -585,12 +590,16 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
|
|
|
585
590
|
const tag = "[js::startTransaction]";
|
|
586
591
|
debug("%s options: %O", tag, options);
|
|
587
592
|
const conn = await this.client.connect().catch((error) => this.onError(error));
|
|
588
|
-
|
|
593
|
+
const onError = (err) => {
|
|
589
594
|
debug(`Error from pool connection: ${err.message} %O`, err);
|
|
590
595
|
this.options?.onConnectionError?.(err);
|
|
591
|
-
}
|
|
596
|
+
};
|
|
597
|
+
conn.on("error", onError);
|
|
598
|
+
const cleanup = () => {
|
|
599
|
+
conn.removeListener("error", onError);
|
|
600
|
+
};
|
|
592
601
|
try {
|
|
593
|
-
const tx = new NeonTransaction(conn, options);
|
|
602
|
+
const tx = new NeonTransaction(conn, options, cleanup);
|
|
594
603
|
await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
|
|
595
604
|
if (isolationLevel) {
|
|
596
605
|
await tx.executeRaw({
|
|
@@ -601,6 +610,7 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
|
|
|
601
610
|
}
|
|
602
611
|
return tx;
|
|
603
612
|
} catch (error) {
|
|
613
|
+
cleanup();
|
|
604
614
|
conn.release(error);
|
|
605
615
|
this.onError(error);
|
|
606
616
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-neon",
|
|
3
|
-
"version": "6.18.0-dev.
|
|
3
|
+
"version": "6.18.0-dev.20",
|
|
4
4
|
"description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,10 +33,14 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"postgres-array": "3.0.4",
|
|
35
35
|
"@neondatabase/serverless": ">0.6.0 <2",
|
|
36
|
-
"@prisma/driver-adapter-utils": "6.18.0-dev.
|
|
36
|
+
"@prisma/driver-adapter-utils": "6.18.0-dev.20"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@prisma/debug": "6.18.0-dev.20"
|
|
37
40
|
},
|
|
38
41
|
"scripts": {
|
|
39
42
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
40
|
-
"build": "tsx helpers/build.ts"
|
|
43
|
+
"build": "tsx helpers/build.ts",
|
|
44
|
+
"test": "vitest run"
|
|
41
45
|
}
|
|
42
46
|
}
|