@prisma/adapter-neon 7.10.1 → 7.11.0-dev.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.
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;
@@ -305,10 +307,22 @@ function normalize_time(time) {
305
307
  return time;
306
308
  }
307
309
  function normalize_timez(time) {
308
- return time.replace(/[+-]\d{2}(:\d{2})?$/, "");
310
+ const match = time.match(/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?([+-])(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
311
+ if (!match) return time;
312
+ const [, h, m, s, fraction = "", sign, oh, om = "0", os = "0"] = match;
313
+ const offset = (sign === "+" ? 1 : -1) * (Number(oh) * 3600 + Number(om) * 60 + Number(os));
314
+ if (offset === 0) return `${h}:${m}:${s}${fraction}`;
315
+ const seconds = ((Number(h) * 3600 + Number(m) * 60 + Number(s) - offset) % 86400 + 86400) % 86400;
316
+ const pad = (n) => String(n).padStart(2, "0");
317
+ return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
309
318
  }
310
319
  function normalize_money(money) {
311
- return money.slice(1);
320
+ if (!/^-?\$\d{1,3}(,\d{3})*\.\d{2}$/.test(money)) {
321
+ throw new Error(
322
+ `Unsupported money format "${money}": only the default lc_monetary format, such as -$1,234.50, is supported`
323
+ );
324
+ }
325
+ return money.replace(/[^\d.-]/g, "");
312
326
  }
313
327
  function normalize_xml(xml) {
314
328
  return xml;
@@ -330,6 +344,7 @@ var customParsers = {
330
344
  [ScalarColumnType.TIME]: normalize_time,
331
345
  [ArrayColumnType.TIME_ARRAY]: normalize_array(normalize_time),
332
346
  [ScalarColumnType.TIMETZ]: normalize_timez,
347
+ [ArrayColumnType.TIMETZ_ARRAY]: normalize_array(normalize_timez),
333
348
  [ScalarColumnType.DATE]: normalize_date,
334
349
  [ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
335
350
  [ScalarColumnType.TIMESTAMP]: normalize_timestamp,
@@ -361,8 +376,9 @@ function mapArg(arg, argType) {
361
376
  if (arg instanceof Date) {
362
377
  switch (argType.dbType) {
363
378
  case "TIME":
364
- case "TIMETZ":
365
379
  return formatTime(arg);
380
+ case "TIMETZ":
381
+ return formatTime(arg) + "+00";
366
382
  case "DATE":
367
383
  return formatDate(arg);
368
384
  default:
@@ -608,15 +624,50 @@ var NeonTransaction = class extends NeonWsQueryable {
608
624
  this.options = options;
609
625
  this.cleanup = cleanup;
610
626
  }
627
+ closed = false;
628
+ runningStatements = 0;
629
+ async performIO(query) {
630
+ if (this.closed) {
631
+ throw new import_driver_adapter_utils2.DriverAdapterError({
632
+ kind: "TransactionAlreadyClosed",
633
+ cause: "The transaction has already been committed or rolled back"
634
+ });
635
+ }
636
+ this.runningStatements++;
637
+ try {
638
+ return await super.performIO(query);
639
+ } finally {
640
+ this.runningStatements--;
641
+ }
642
+ }
643
+ /**
644
+ * Closes the transaction at most once. Once the pool has lent the client to
645
+ * a new owner, a second `release()` would corrupt the pool's bookkeeping, so
646
+ * it is skipped. A client with a statement still running is released with an
647
+ * error so the pool destroys it instead of lending out a busy connection.
648
+ */
649
+ close() {
650
+ if (this.closed) {
651
+ return;
652
+ }
653
+ this.closed = true;
654
+ try {
655
+ this.cleanup?.();
656
+ } finally {
657
+ if (this.runningStatements > 0) {
658
+ this.client.release(new Error("Transaction closed with a statement still running"));
659
+ } else {
660
+ this.client.release();
661
+ }
662
+ }
663
+ }
611
664
  async commit() {
612
665
  debug(`[js::commit]`);
613
- this.cleanup?.();
614
- this.client.release();
666
+ this.close();
615
667
  }
616
668
  async rollback() {
617
669
  debug(`[js::rollback]`);
618
- this.cleanup?.();
619
- this.client.release();
670
+ this.close();
620
671
  }
621
672
  async createSavepoint(name2) {
622
673
  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;
@@ -268,10 +270,22 @@ function normalize_time(time) {
268
270
  return time;
269
271
  }
270
272
  function normalize_timez(time) {
271
- return time.replace(/[+-]\d{2}(:\d{2})?$/, "");
273
+ const match = time.match(/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?([+-])(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
274
+ if (!match) return time;
275
+ const [, h, m, s, fraction = "", sign, oh, om = "0", os = "0"] = match;
276
+ const offset = (sign === "+" ? 1 : -1) * (Number(oh) * 3600 + Number(om) * 60 + Number(os));
277
+ if (offset === 0) return `${h}:${m}:${s}${fraction}`;
278
+ const seconds = ((Number(h) * 3600 + Number(m) * 60 + Number(s) - offset) % 86400 + 86400) % 86400;
279
+ const pad = (n) => String(n).padStart(2, "0");
280
+ return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
272
281
  }
273
282
  function normalize_money(money) {
274
- return money.slice(1);
283
+ if (!/^-?\$\d{1,3}(,\d{3})*\.\d{2}$/.test(money)) {
284
+ throw new Error(
285
+ `Unsupported money format "${money}": only the default lc_monetary format, such as -$1,234.50, is supported`
286
+ );
287
+ }
288
+ return money.replace(/[^\d.-]/g, "");
275
289
  }
276
290
  function normalize_xml(xml) {
277
291
  return xml;
@@ -293,6 +307,7 @@ var customParsers = {
293
307
  [ScalarColumnType.TIME]: normalize_time,
294
308
  [ArrayColumnType.TIME_ARRAY]: normalize_array(normalize_time),
295
309
  [ScalarColumnType.TIMETZ]: normalize_timez,
310
+ [ArrayColumnType.TIMETZ_ARRAY]: normalize_array(normalize_timez),
296
311
  [ScalarColumnType.DATE]: normalize_date,
297
312
  [ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
298
313
  [ScalarColumnType.TIMESTAMP]: normalize_timestamp,
@@ -324,8 +339,9 @@ function mapArg(arg, argType) {
324
339
  if (arg instanceof Date) {
325
340
  switch (argType.dbType) {
326
341
  case "TIME":
327
- case "TIMETZ":
328
342
  return formatTime(arg);
343
+ case "TIMETZ":
344
+ return formatTime(arg) + "+00";
329
345
  case "DATE":
330
346
  return formatDate(arg);
331
347
  default:
@@ -571,15 +587,50 @@ var NeonTransaction = class extends NeonWsQueryable {
571
587
  this.options = options;
572
588
  this.cleanup = cleanup;
573
589
  }
590
+ closed = false;
591
+ runningStatements = 0;
592
+ async performIO(query) {
593
+ if (this.closed) {
594
+ throw new DriverAdapterError({
595
+ kind: "TransactionAlreadyClosed",
596
+ cause: "The transaction has already been committed or rolled back"
597
+ });
598
+ }
599
+ this.runningStatements++;
600
+ try {
601
+ return await super.performIO(query);
602
+ } finally {
603
+ this.runningStatements--;
604
+ }
605
+ }
606
+ /**
607
+ * Closes the transaction at most once. Once the pool has lent the client to
608
+ * a new owner, a second `release()` would corrupt the pool's bookkeeping, so
609
+ * it is skipped. A client with a statement still running is released with an
610
+ * error so the pool destroys it instead of lending out a busy connection.
611
+ */
612
+ close() {
613
+ if (this.closed) {
614
+ return;
615
+ }
616
+ this.closed = true;
617
+ try {
618
+ this.cleanup?.();
619
+ } finally {
620
+ if (this.runningStatements > 0) {
621
+ this.client.release(new Error("Transaction closed with a statement still running"));
622
+ } else {
623
+ this.client.release();
624
+ }
625
+ }
626
+ }
574
627
  async commit() {
575
628
  debug(`[js::commit]`);
576
- this.cleanup?.();
577
- this.client.release();
629
+ this.close();
578
630
  }
579
631
  async rollback() {
580
632
  debug(`[js::rollback]`);
581
- this.cleanup?.();
582
- this.client.release();
633
+ this.close();
583
634
  }
584
635
  async createSavepoint(name2) {
585
636
  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.1",
3
+ "version": "7.11.0-dev.1",
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.1"
36
+ "@prisma/driver-adapter-utils": "7.11.0-dev.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@prisma/debug": "7.10.1"
39
+ "@prisma/debug": "7.11.0-dev.1"
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
  }