@prisma/adapter-neon 7.10.1 → 7.11.0-dev.10
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 +67 -10
- package/dist/index.mjs +67 -10
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ var ArrayColumnType = {
|
|
|
69
69
|
TEXT_ARRAY: 1009,
|
|
70
70
|
TIMESTAMP_ARRAY: 1115,
|
|
71
71
|
TIMESTAMPTZ_ARRAY: 1185,
|
|
72
|
+
TIMETZ_ARRAY: 1270,
|
|
72
73
|
TIME_ARRAY: 1183,
|
|
73
74
|
UUID_ARRAY: 2951,
|
|
74
75
|
VARBIT_ARRAY: 1563,
|
|
@@ -266,6 +267,7 @@ function fieldToColumnType(fieldTypeId) {
|
|
|
266
267
|
case ArrayColumnType.DATE_ARRAY:
|
|
267
268
|
return import_driver_adapter_utils.ColumnTypeEnum.DateArray;
|
|
268
269
|
case ArrayColumnType.TIME_ARRAY:
|
|
270
|
+
case ArrayColumnType.TIMETZ_ARRAY:
|
|
269
271
|
return import_driver_adapter_utils.ColumnTypeEnum.TimeArray;
|
|
270
272
|
case ArrayColumnType.TIMESTAMP_ARRAY:
|
|
271
273
|
return import_driver_adapter_utils.ColumnTypeEnum.DateTimeArray;
|
|
@@ -292,23 +294,41 @@ function normalize_array(element_normalizer) {
|
|
|
292
294
|
function normalize_numeric(numeric) {
|
|
293
295
|
return numeric;
|
|
294
296
|
}
|
|
297
|
+
function expandYear(value) {
|
|
298
|
+
return value.replace(/^(\d{5,})(?=-)/, (_, year) => `+${year.padStart(6, "0")}`);
|
|
299
|
+
}
|
|
295
300
|
function normalize_date(date) {
|
|
296
|
-
return date;
|
|
301
|
+
return expandYear(date);
|
|
297
302
|
}
|
|
298
303
|
function normalize_timestamp(time) {
|
|
299
|
-
return `${time.replace(" ", "T")}+00:00
|
|
304
|
+
return expandYear(`${time.replace(" ", "T")}+00:00`);
|
|
300
305
|
}
|
|
301
306
|
function normalize_timestamptz(time) {
|
|
302
|
-
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
307
|
+
return expandYear(time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00"));
|
|
303
308
|
}
|
|
304
309
|
function normalize_time(time) {
|
|
305
310
|
return time;
|
|
306
311
|
}
|
|
307
312
|
function normalize_timez(time) {
|
|
308
|
-
|
|
313
|
+
const match = time.match(/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?([+-])(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
|
|
314
|
+
if (!match) return time;
|
|
315
|
+
const [, h, m, s, fraction = "", sign, oh, om = "0", os = "0"] = match;
|
|
316
|
+
const offset = (sign === "+" ? 1 : -1) * (Number(oh) * 3600 + Number(om) * 60 + Number(os));
|
|
317
|
+
if (offset === 0) return `${h}:${m}:${s}${fraction}`;
|
|
318
|
+
const seconds = ((Number(h) * 3600 + Number(m) * 60 + Number(s) - offset) % 86400 + 86400) % 86400;
|
|
319
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
320
|
+
return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
|
|
309
321
|
}
|
|
322
|
+
var SUPPORTED_MONEY_FORMAT = /^(?:(-)[\p{L}\p{Sc}]+|[\p{L}\p{Sc}]+(-)?)(\d{1,3}(?:,\d{3})*)(\.(?!\d{3}$)\d+)?$/u;
|
|
310
323
|
function normalize_money(money) {
|
|
311
|
-
|
|
324
|
+
const match = SUPPORTED_MONEY_FORMAT.exec(money);
|
|
325
|
+
if (match === null) {
|
|
326
|
+
throw new Error(
|
|
327
|
+
`Unsupported money format "${money}": expected a currency symbol directly followed by an amount with "," thousands separators and a "." decimal point, such as -\xA31,234.50`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
const [, signBeforeSymbol = "", signAfterSymbol = "", integer, fraction = ""] = match;
|
|
331
|
+
return `${signBeforeSymbol}${signAfterSymbol}${integer.replaceAll(",", "")}${fraction}`;
|
|
312
332
|
}
|
|
313
333
|
function normalize_xml(xml) {
|
|
314
334
|
return xml;
|
|
@@ -330,6 +350,7 @@ var customParsers = {
|
|
|
330
350
|
[ScalarColumnType.TIME]: normalize_time,
|
|
331
351
|
[ArrayColumnType.TIME_ARRAY]: normalize_array(normalize_time),
|
|
332
352
|
[ScalarColumnType.TIMETZ]: normalize_timez,
|
|
353
|
+
[ArrayColumnType.TIMETZ_ARRAY]: normalize_array(normalize_timez),
|
|
333
354
|
[ScalarColumnType.DATE]: normalize_date,
|
|
334
355
|
[ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
|
|
335
356
|
[ScalarColumnType.TIMESTAMP]: normalize_timestamp,
|
|
@@ -361,8 +382,9 @@ function mapArg(arg, argType) {
|
|
|
361
382
|
if (arg instanceof Date) {
|
|
362
383
|
switch (argType.dbType) {
|
|
363
384
|
case "TIME":
|
|
364
|
-
case "TIMETZ":
|
|
365
385
|
return formatTime(arg);
|
|
386
|
+
case "TIMETZ":
|
|
387
|
+
return formatTime(arg) + "+00";
|
|
366
388
|
case "DATE":
|
|
367
389
|
return formatDate(arg);
|
|
368
390
|
default:
|
|
@@ -608,15 +630,50 @@ var NeonTransaction = class extends NeonWsQueryable {
|
|
|
608
630
|
this.options = options;
|
|
609
631
|
this.cleanup = cleanup;
|
|
610
632
|
}
|
|
633
|
+
closed = false;
|
|
634
|
+
runningStatements = 0;
|
|
635
|
+
async performIO(query) {
|
|
636
|
+
if (this.closed) {
|
|
637
|
+
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
638
|
+
kind: "TransactionAlreadyClosed",
|
|
639
|
+
cause: "The transaction has already been committed or rolled back"
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
this.runningStatements++;
|
|
643
|
+
try {
|
|
644
|
+
return await super.performIO(query);
|
|
645
|
+
} finally {
|
|
646
|
+
this.runningStatements--;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Closes the transaction at most once. Once the pool has lent the client to
|
|
651
|
+
* a new owner, a second `release()` would corrupt the pool's bookkeeping, so
|
|
652
|
+
* it is skipped. A client with a statement still running is released with an
|
|
653
|
+
* error so the pool destroys it instead of lending out a busy connection.
|
|
654
|
+
*/
|
|
655
|
+
close() {
|
|
656
|
+
if (this.closed) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
this.closed = true;
|
|
660
|
+
try {
|
|
661
|
+
this.cleanup?.();
|
|
662
|
+
} finally {
|
|
663
|
+
if (this.runningStatements > 0) {
|
|
664
|
+
this.client.release(new Error("Transaction closed with a statement still running"));
|
|
665
|
+
} else {
|
|
666
|
+
this.client.release();
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
611
670
|
async commit() {
|
|
612
671
|
debug(`[js::commit]`);
|
|
613
|
-
this.
|
|
614
|
-
this.client.release();
|
|
672
|
+
this.close();
|
|
615
673
|
}
|
|
616
674
|
async rollback() {
|
|
617
675
|
debug(`[js::rollback]`);
|
|
618
|
-
this.
|
|
619
|
-
this.client.release();
|
|
676
|
+
this.close();
|
|
620
677
|
}
|
|
621
678
|
async createSavepoint(name2) {
|
|
622
679
|
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
|
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,7 @@ var ArrayColumnType = {
|
|
|
32
32
|
TEXT_ARRAY: 1009,
|
|
33
33
|
TIMESTAMP_ARRAY: 1115,
|
|
34
34
|
TIMESTAMPTZ_ARRAY: 1185,
|
|
35
|
+
TIMETZ_ARRAY: 1270,
|
|
35
36
|
TIME_ARRAY: 1183,
|
|
36
37
|
UUID_ARRAY: 2951,
|
|
37
38
|
VARBIT_ARRAY: 1563,
|
|
@@ -229,6 +230,7 @@ function fieldToColumnType(fieldTypeId) {
|
|
|
229
230
|
case ArrayColumnType.DATE_ARRAY:
|
|
230
231
|
return ColumnTypeEnum.DateArray;
|
|
231
232
|
case ArrayColumnType.TIME_ARRAY:
|
|
233
|
+
case ArrayColumnType.TIMETZ_ARRAY:
|
|
232
234
|
return ColumnTypeEnum.TimeArray;
|
|
233
235
|
case ArrayColumnType.TIMESTAMP_ARRAY:
|
|
234
236
|
return ColumnTypeEnum.DateTimeArray;
|
|
@@ -255,23 +257,41 @@ function normalize_array(element_normalizer) {
|
|
|
255
257
|
function normalize_numeric(numeric) {
|
|
256
258
|
return numeric;
|
|
257
259
|
}
|
|
260
|
+
function expandYear(value) {
|
|
261
|
+
return value.replace(/^(\d{5,})(?=-)/, (_, year) => `+${year.padStart(6, "0")}`);
|
|
262
|
+
}
|
|
258
263
|
function normalize_date(date) {
|
|
259
|
-
return date;
|
|
264
|
+
return expandYear(date);
|
|
260
265
|
}
|
|
261
266
|
function normalize_timestamp(time) {
|
|
262
|
-
return `${time.replace(" ", "T")}+00:00
|
|
267
|
+
return expandYear(`${time.replace(" ", "T")}+00:00`);
|
|
263
268
|
}
|
|
264
269
|
function normalize_timestamptz(time) {
|
|
265
|
-
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
270
|
+
return expandYear(time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00"));
|
|
266
271
|
}
|
|
267
272
|
function normalize_time(time) {
|
|
268
273
|
return time;
|
|
269
274
|
}
|
|
270
275
|
function normalize_timez(time) {
|
|
271
|
-
|
|
276
|
+
const match = time.match(/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?([+-])(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
|
|
277
|
+
if (!match) return time;
|
|
278
|
+
const [, h, m, s, fraction = "", sign, oh, om = "0", os = "0"] = match;
|
|
279
|
+
const offset = (sign === "+" ? 1 : -1) * (Number(oh) * 3600 + Number(om) * 60 + Number(os));
|
|
280
|
+
if (offset === 0) return `${h}:${m}:${s}${fraction}`;
|
|
281
|
+
const seconds = ((Number(h) * 3600 + Number(m) * 60 + Number(s) - offset) % 86400 + 86400) % 86400;
|
|
282
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
283
|
+
return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
|
|
272
284
|
}
|
|
285
|
+
var SUPPORTED_MONEY_FORMAT = /^(?:(-)[\p{L}\p{Sc}]+|[\p{L}\p{Sc}]+(-)?)(\d{1,3}(?:,\d{3})*)(\.(?!\d{3}$)\d+)?$/u;
|
|
273
286
|
function normalize_money(money) {
|
|
274
|
-
|
|
287
|
+
const match = SUPPORTED_MONEY_FORMAT.exec(money);
|
|
288
|
+
if (match === null) {
|
|
289
|
+
throw new Error(
|
|
290
|
+
`Unsupported money format "${money}": expected a currency symbol directly followed by an amount with "," thousands separators and a "." decimal point, such as -\xA31,234.50`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
const [, signBeforeSymbol = "", signAfterSymbol = "", integer, fraction = ""] = match;
|
|
294
|
+
return `${signBeforeSymbol}${signAfterSymbol}${integer.replaceAll(",", "")}${fraction}`;
|
|
275
295
|
}
|
|
276
296
|
function normalize_xml(xml) {
|
|
277
297
|
return xml;
|
|
@@ -293,6 +313,7 @@ var customParsers = {
|
|
|
293
313
|
[ScalarColumnType.TIME]: normalize_time,
|
|
294
314
|
[ArrayColumnType.TIME_ARRAY]: normalize_array(normalize_time),
|
|
295
315
|
[ScalarColumnType.TIMETZ]: normalize_timez,
|
|
316
|
+
[ArrayColumnType.TIMETZ_ARRAY]: normalize_array(normalize_timez),
|
|
296
317
|
[ScalarColumnType.DATE]: normalize_date,
|
|
297
318
|
[ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
|
|
298
319
|
[ScalarColumnType.TIMESTAMP]: normalize_timestamp,
|
|
@@ -324,8 +345,9 @@ function mapArg(arg, argType) {
|
|
|
324
345
|
if (arg instanceof Date) {
|
|
325
346
|
switch (argType.dbType) {
|
|
326
347
|
case "TIME":
|
|
327
|
-
case "TIMETZ":
|
|
328
348
|
return formatTime(arg);
|
|
349
|
+
case "TIMETZ":
|
|
350
|
+
return formatTime(arg) + "+00";
|
|
329
351
|
case "DATE":
|
|
330
352
|
return formatDate(arg);
|
|
331
353
|
default:
|
|
@@ -571,15 +593,50 @@ var NeonTransaction = class extends NeonWsQueryable {
|
|
|
571
593
|
this.options = options;
|
|
572
594
|
this.cleanup = cleanup;
|
|
573
595
|
}
|
|
596
|
+
closed = false;
|
|
597
|
+
runningStatements = 0;
|
|
598
|
+
async performIO(query) {
|
|
599
|
+
if (this.closed) {
|
|
600
|
+
throw new DriverAdapterError({
|
|
601
|
+
kind: "TransactionAlreadyClosed",
|
|
602
|
+
cause: "The transaction has already been committed or rolled back"
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
this.runningStatements++;
|
|
606
|
+
try {
|
|
607
|
+
return await super.performIO(query);
|
|
608
|
+
} finally {
|
|
609
|
+
this.runningStatements--;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Closes the transaction at most once. Once the pool has lent the client to
|
|
614
|
+
* a new owner, a second `release()` would corrupt the pool's bookkeeping, so
|
|
615
|
+
* it is skipped. A client with a statement still running is released with an
|
|
616
|
+
* error so the pool destroys it instead of lending out a busy connection.
|
|
617
|
+
*/
|
|
618
|
+
close() {
|
|
619
|
+
if (this.closed) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
this.closed = true;
|
|
623
|
+
try {
|
|
624
|
+
this.cleanup?.();
|
|
625
|
+
} finally {
|
|
626
|
+
if (this.runningStatements > 0) {
|
|
627
|
+
this.client.release(new Error("Transaction closed with a statement still running"));
|
|
628
|
+
} else {
|
|
629
|
+
this.client.release();
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
574
633
|
async commit() {
|
|
575
634
|
debug(`[js::commit]`);
|
|
576
|
-
this.
|
|
577
|
-
this.client.release();
|
|
635
|
+
this.close();
|
|
578
636
|
}
|
|
579
637
|
async rollback() {
|
|
580
638
|
debug(`[js::rollback]`);
|
|
581
|
-
this.
|
|
582
|
-
this.client.release();
|
|
639
|
+
this.close();
|
|
583
640
|
}
|
|
584
641
|
async createSavepoint(name2) {
|
|
585
642
|
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-neon",
|
|
3
|
-
"version": "7.10
|
|
3
|
+
"version": "7.11.0-dev.10",
|
|
4
4
|
"description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,14 +33,13 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"postgres-array": "3.0.4",
|
|
35
35
|
"@neondatabase/serverless": ">0.6.0 <2",
|
|
36
|
-
"@prisma/driver-adapter-utils": "7.10
|
|
36
|
+
"@prisma/driver-adapter-utils": "7.11.0-dev.10"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@prisma/debug": "7.10
|
|
39
|
+
"@prisma/debug": "7.11.0-dev.10"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
43
|
-
"build": "tsx helpers/build.ts"
|
|
44
|
-
"test": "vitest run"
|
|
43
|
+
"build": "tsx helpers/build.ts"
|
|
45
44
|
}
|
|
46
45
|
}
|