@prisma/adapter-neon 6.15.0-dev.3 → 6.15.0-dev.5

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.d.mts CHANGED
@@ -77,6 +77,8 @@ export declare class PrismaNeonHTTP implements SqlDriverAdapterFactory {
77
77
 
78
78
  declare type PrismaNeonOptions = {
79
79
  schema?: string;
80
+ onPoolError?: (err: Error) => void;
81
+ onConnectionError?: (err: Error) => void;
80
82
  };
81
83
 
82
84
  export { }
package/dist/index.d.ts CHANGED
@@ -77,6 +77,8 @@ export declare class PrismaNeonHTTP implements SqlDriverAdapterFactory {
77
77
 
78
78
  declare type PrismaNeonOptions = {
79
79
  schema?: string;
80
+ onPoolError?: (err: Error) => void;
81
+ onConnectionError?: (err: Error) => void;
80
82
  };
81
83
 
82
84
  export { }
package/dist/index.js CHANGED
@@ -354,20 +354,35 @@ var customParsers = {
354
354
  [ArrayColumnType.VARBIT_ARRAY]: normalize_array(normalizeBit),
355
355
  [ArrayColumnType.XML_ARRAY]: normalize_array(normalize_xml)
356
356
  };
357
- function fixArrayBufferValues(values) {
358
- for (let i = 0; i < values.length; i++) {
359
- const list = values[i];
360
- if (!Array.isArray(list)) {
361
- continue;
362
- }
363
- for (let j = 0; j < list.length; j++) {
364
- const listItem = list[j];
365
- if (ArrayBuffer.isView(listItem)) {
366
- list[j] = Buffer.from(listItem.buffer, listItem.byteOffset, listItem.byteLength);
367
- }
357
+ function mapArg(arg, argType) {
358
+ if (arg === null) {
359
+ return null;
360
+ }
361
+ if (Array.isArray(arg) && argType.arity === "list") {
362
+ return arg.map((value) => mapArg(value, argType));
363
+ }
364
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
365
+ arg = new Date(arg);
366
+ }
367
+ if (arg instanceof Date) {
368
+ switch (argType.dbType) {
369
+ case "TIME":
370
+ case "TIMETZ":
371
+ return arg.toISOString().split("T")[1];
372
+ default:
373
+ return arg.toISOString();
368
374
  }
369
375
  }
370
- return values;
376
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
377
+ return Buffer.from(arg, "base64");
378
+ }
379
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
380
+ return Buffer.from(arg);
381
+ }
382
+ if (ArrayBuffer.isView(arg)) {
383
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
384
+ }
385
+ return arg;
371
386
  }
372
387
 
373
388
  // src/errors.ts
@@ -522,12 +537,11 @@ var NeonWsQueryable = class extends NeonQueryable {
522
537
  this.client = client;
523
538
  }
524
539
  async performIO(query) {
525
- const { sql, args: values } = query;
540
+ const { sql, args } = query;
526
541
  try {
527
542
  const result = await this.client.query(
528
543
  {
529
544
  text: sql,
530
- values: fixArrayBufferValues(values),
531
545
  rowMode: "array",
532
546
  types: {
533
547
  // This is the error expected:
@@ -550,7 +564,7 @@ var NeonWsQueryable = class extends NeonQueryable {
550
564
  }
551
565
  }
552
566
  },
553
- fixArrayBufferValues(values)
567
+ args.map((arg, i) => mapArg(arg, query.argTypes[i]))
554
568
  );
555
569
  return result;
556
570
  } catch (e) {
@@ -592,6 +606,10 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
592
606
  const tag = "[js::startTransaction]";
593
607
  debug("%s options: %O", tag, options);
594
608
  const conn = await this.client.connect().catch((error) => this.onError(error));
609
+ conn.on("error", (err) => {
610
+ debug(`Error from pool connection: ${err.message} %O`, err);
611
+ this.options?.onConnectionError?.(err);
612
+ });
595
613
  try {
596
614
  const tx = new NeonTransaction(conn, options);
597
615
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
@@ -632,7 +650,12 @@ var PrismaNeonAdapterFactory = class {
632
650
  provider = "postgres";
633
651
  adapterName = name;
634
652
  async connect() {
635
- return new PrismaNeonAdapter(new neon.Pool(this.config), this.options);
653
+ const pool = new neon.Pool(this.config);
654
+ pool.on("error", (err) => {
655
+ debug(`Error from pool client: ${err.message} %O`, err);
656
+ this.options?.onPoolError?.(err);
657
+ });
658
+ return new PrismaNeonAdapter(pool, this.options);
636
659
  }
637
660
  };
638
661
  var PrismaNeonHTTPAdapter = class extends NeonQueryable {
package/dist/index.mjs CHANGED
@@ -317,20 +317,35 @@ var customParsers = {
317
317
  [ArrayColumnType.VARBIT_ARRAY]: normalize_array(normalizeBit),
318
318
  [ArrayColumnType.XML_ARRAY]: normalize_array(normalize_xml)
319
319
  };
320
- function fixArrayBufferValues(values) {
321
- for (let i = 0; i < values.length; i++) {
322
- const list = values[i];
323
- if (!Array.isArray(list)) {
324
- continue;
325
- }
326
- for (let j = 0; j < list.length; j++) {
327
- const listItem = list[j];
328
- if (ArrayBuffer.isView(listItem)) {
329
- list[j] = Buffer.from(listItem.buffer, listItem.byteOffset, listItem.byteLength);
330
- }
320
+ function mapArg(arg, argType) {
321
+ if (arg === null) {
322
+ return null;
323
+ }
324
+ if (Array.isArray(arg) && argType.arity === "list") {
325
+ return arg.map((value) => mapArg(value, argType));
326
+ }
327
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
328
+ arg = new Date(arg);
329
+ }
330
+ if (arg instanceof Date) {
331
+ switch (argType.dbType) {
332
+ case "TIME":
333
+ case "TIMETZ":
334
+ return arg.toISOString().split("T")[1];
335
+ default:
336
+ return arg.toISOString();
331
337
  }
332
338
  }
333
- return values;
339
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
340
+ return Buffer.from(arg, "base64");
341
+ }
342
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
343
+ return Buffer.from(arg);
344
+ }
345
+ if (ArrayBuffer.isView(arg)) {
346
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
347
+ }
348
+ return arg;
334
349
  }
335
350
 
336
351
  // src/errors.ts
@@ -485,12 +500,11 @@ var NeonWsQueryable = class extends NeonQueryable {
485
500
  this.client = client;
486
501
  }
487
502
  async performIO(query) {
488
- const { sql, args: values } = query;
503
+ const { sql, args } = query;
489
504
  try {
490
505
  const result = await this.client.query(
491
506
  {
492
507
  text: sql,
493
- values: fixArrayBufferValues(values),
494
508
  rowMode: "array",
495
509
  types: {
496
510
  // This is the error expected:
@@ -513,7 +527,7 @@ var NeonWsQueryable = class extends NeonQueryable {
513
527
  }
514
528
  }
515
529
  },
516
- fixArrayBufferValues(values)
530
+ args.map((arg, i) => mapArg(arg, query.argTypes[i]))
517
531
  );
518
532
  return result;
519
533
  } catch (e) {
@@ -555,6 +569,10 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
555
569
  const tag = "[js::startTransaction]";
556
570
  debug("%s options: %O", tag, options);
557
571
  const conn = await this.client.connect().catch((error) => this.onError(error));
572
+ conn.on("error", (err) => {
573
+ debug(`Error from pool connection: ${err.message} %O`, err);
574
+ this.options?.onConnectionError?.(err);
575
+ });
558
576
  try {
559
577
  const tx = new NeonTransaction(conn, options);
560
578
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
@@ -595,7 +613,12 @@ var PrismaNeonAdapterFactory = class {
595
613
  provider = "postgres";
596
614
  adapterName = name;
597
615
  async connect() {
598
- return new PrismaNeonAdapter(new neon.Pool(this.config), this.options);
616
+ const pool = new neon.Pool(this.config);
617
+ pool.on("error", (err) => {
618
+ debug(`Error from pool client: ${err.message} %O`, err);
619
+ this.options?.onPoolError?.(err);
620
+ });
621
+ return new PrismaNeonAdapter(pool, this.options);
599
622
  }
600
623
  };
601
624
  var PrismaNeonHTTPAdapter = class extends NeonQueryable {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-neon",
3
- "version": "6.15.0-dev.3",
3
+ "version": "6.15.0-dev.5",
4
4
  "description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "postgres-array": "3.0.4",
35
35
  "@neondatabase/serverless": ">0.6.0 <2",
36
- "@prisma/driver-adapter-utils": "6.15.0-dev.3"
36
+ "@prisma/driver-adapter-utils": "6.15.0-dev.5"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@swc/core": "1.11.5",