@prisma/adapter-neon 6.7.0-dev.1 → 6.7.0-dev.3

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
@@ -368,6 +368,94 @@ function fixArrayBufferValues(values) {
368
368
  return values;
369
369
  }
370
370
 
371
+ // src/errors.ts
372
+ function convertDriverError(error) {
373
+ if (!isDbError(error)) {
374
+ throw error;
375
+ }
376
+ switch (error.code) {
377
+ case "22001":
378
+ return {
379
+ kind: "LengthMismatch",
380
+ column: error.column
381
+ };
382
+ case "23505":
383
+ return {
384
+ kind: "UniqueConstraintViolation",
385
+ fields: error.detail?.match(/Key \(([^)]+)\)/)?.at(1)?.split(", ") ?? []
386
+ };
387
+ case "23502":
388
+ return {
389
+ kind: "NullConstraintViolation",
390
+ fields: error.detail?.match(/Key \(([^)]+)\)/)?.at(1)?.split(", ") ?? []
391
+ };
392
+ case "23503": {
393
+ let constraint;
394
+ if (error.column) {
395
+ constraint = { fields: [error.column] };
396
+ } else if (error.constraint) {
397
+ constraint = { index: error.constraint };
398
+ }
399
+ return {
400
+ kind: "ForeignKeyConstraintViolation",
401
+ constraint
402
+ };
403
+ }
404
+ case "3D000":
405
+ return {
406
+ kind: "DatabaseDoesNotExist",
407
+ db: error.message.split(" ").at(1)?.split('"').at(1)
408
+ };
409
+ case "28000":
410
+ return {
411
+ kind: "DatabaseAccessDenied",
412
+ db: error.message.split(" ").at(5)?.split('"').at(1)
413
+ };
414
+ case "28P01":
415
+ return {
416
+ kind: "AuthenticationFailed",
417
+ user: error.message.split(" ").pop()?.split('"').at(1)
418
+ };
419
+ case "40001":
420
+ return {
421
+ kind: "TransactionWriteConflict"
422
+ };
423
+ case "42P01":
424
+ return {
425
+ kind: "TableDoesNotExist",
426
+ table: error.message.split(" ").at(1)?.split('"').at(1)
427
+ };
428
+ case "42703":
429
+ return {
430
+ kind: "ColumnNotFound",
431
+ column: error.message.split(" ").at(1)?.split('"').at(1)
432
+ };
433
+ case "42P04":
434
+ return {
435
+ kind: "DatabaseAlreadyExists",
436
+ db: error.message.split(" ").at(1)?.split('"').at(1)
437
+ };
438
+ case "53300":
439
+ return {
440
+ kind: "TooManyConnections",
441
+ cause: error.message
442
+ };
443
+ default:
444
+ return {
445
+ kind: "postgres",
446
+ code: error.code ?? "N/A",
447
+ severity: error.severity ?? "N/A",
448
+ message: error.message,
449
+ detail: error.detail,
450
+ column: error.column,
451
+ hint: error.hint
452
+ };
453
+ }
454
+ }
455
+ function isDbError(error) {
456
+ return typeof error.code === "string" && typeof error.message === "string" && typeof error.severity === "string" && (typeof error.detail === "string" || error.detail === void 0) && (typeof error.column === "string" || error.column === void 0) && (typeof error.hint === "string" || error.hint === void 0);
457
+ }
458
+
371
459
  // src/neon.ts
372
460
  var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:neon");
373
461
  var NeonQueryable = class {
@@ -453,18 +541,7 @@ var NeonWsQueryable = class extends NeonQueryable {
453
541
  }
454
542
  onError(e) {
455
543
  debug("Error in onError: %O", e);
456
- if (e && typeof e.code === "string" && typeof e.severity === "string" && typeof e.message === "string") {
457
- throw new import_driver_adapter_utils2.DriverAdapterError({
458
- kind: "postgres",
459
- code: e.code,
460
- severity: e.severity,
461
- message: e.message,
462
- detail: e.detail,
463
- column: e.column,
464
- hint: e.hint
465
- });
466
- }
467
- throw e;
544
+ throw new import_driver_adapter_utils2.DriverAdapterError(convertDriverError(e));
468
545
  }
469
546
  };
470
547
  var NeonTransaction = class extends NeonWsQueryable {
@@ -496,9 +573,9 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
496
573
  };
497
574
  const tag = "[js::startTransaction]";
498
575
  debug("%s options: %O", tag, options);
499
- const conn = await this.client.connect();
500
- const tx = new NeonTransaction(conn, options);
576
+ const conn = await this.client.connect().catch((error) => this.onError(error));
501
577
  try {
578
+ const tx = new NeonTransaction(conn, options);
502
579
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
503
580
  if (isolationLevel) {
504
581
  await tx.executeRaw({
@@ -510,7 +587,7 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
510
587
  return tx;
511
588
  } catch (error) {
512
589
  conn.release(error);
513
- throw error;
590
+ this.onError(error);
514
591
  }
515
592
  }
516
593
  getConnectionInfo() {
package/dist/index.mjs CHANGED
@@ -331,6 +331,94 @@ function fixArrayBufferValues(values) {
331
331
  return values;
332
332
  }
333
333
 
334
+ // src/errors.ts
335
+ function convertDriverError(error) {
336
+ if (!isDbError(error)) {
337
+ throw error;
338
+ }
339
+ switch (error.code) {
340
+ case "22001":
341
+ return {
342
+ kind: "LengthMismatch",
343
+ column: error.column
344
+ };
345
+ case "23505":
346
+ return {
347
+ kind: "UniqueConstraintViolation",
348
+ fields: error.detail?.match(/Key \(([^)]+)\)/)?.at(1)?.split(", ") ?? []
349
+ };
350
+ case "23502":
351
+ return {
352
+ kind: "NullConstraintViolation",
353
+ fields: error.detail?.match(/Key \(([^)]+)\)/)?.at(1)?.split(", ") ?? []
354
+ };
355
+ case "23503": {
356
+ let constraint;
357
+ if (error.column) {
358
+ constraint = { fields: [error.column] };
359
+ } else if (error.constraint) {
360
+ constraint = { index: error.constraint };
361
+ }
362
+ return {
363
+ kind: "ForeignKeyConstraintViolation",
364
+ constraint
365
+ };
366
+ }
367
+ case "3D000":
368
+ return {
369
+ kind: "DatabaseDoesNotExist",
370
+ db: error.message.split(" ").at(1)?.split('"').at(1)
371
+ };
372
+ case "28000":
373
+ return {
374
+ kind: "DatabaseAccessDenied",
375
+ db: error.message.split(" ").at(5)?.split('"').at(1)
376
+ };
377
+ case "28P01":
378
+ return {
379
+ kind: "AuthenticationFailed",
380
+ user: error.message.split(" ").pop()?.split('"').at(1)
381
+ };
382
+ case "40001":
383
+ return {
384
+ kind: "TransactionWriteConflict"
385
+ };
386
+ case "42P01":
387
+ return {
388
+ kind: "TableDoesNotExist",
389
+ table: error.message.split(" ").at(1)?.split('"').at(1)
390
+ };
391
+ case "42703":
392
+ return {
393
+ kind: "ColumnNotFound",
394
+ column: error.message.split(" ").at(1)?.split('"').at(1)
395
+ };
396
+ case "42P04":
397
+ return {
398
+ kind: "DatabaseAlreadyExists",
399
+ db: error.message.split(" ").at(1)?.split('"').at(1)
400
+ };
401
+ case "53300":
402
+ return {
403
+ kind: "TooManyConnections",
404
+ cause: error.message
405
+ };
406
+ default:
407
+ return {
408
+ kind: "postgres",
409
+ code: error.code ?? "N/A",
410
+ severity: error.severity ?? "N/A",
411
+ message: error.message,
412
+ detail: error.detail,
413
+ column: error.column,
414
+ hint: error.hint
415
+ };
416
+ }
417
+ }
418
+ function isDbError(error) {
419
+ return typeof error.code === "string" && typeof error.message === "string" && typeof error.severity === "string" && (typeof error.detail === "string" || error.detail === void 0) && (typeof error.column === "string" || error.column === void 0) && (typeof error.hint === "string" || error.hint === void 0);
420
+ }
421
+
334
422
  // src/neon.ts
335
423
  var debug = Debug("prisma:driver-adapter:neon");
336
424
  var NeonQueryable = class {
@@ -416,18 +504,7 @@ var NeonWsQueryable = class extends NeonQueryable {
416
504
  }
417
505
  onError(e) {
418
506
  debug("Error in onError: %O", e);
419
- if (e && typeof e.code === "string" && typeof e.severity === "string" && typeof e.message === "string") {
420
- throw new DriverAdapterError({
421
- kind: "postgres",
422
- code: e.code,
423
- severity: e.severity,
424
- message: e.message,
425
- detail: e.detail,
426
- column: e.column,
427
- hint: e.hint
428
- });
429
- }
430
- throw e;
507
+ throw new DriverAdapterError(convertDriverError(e));
431
508
  }
432
509
  };
433
510
  var NeonTransaction = class extends NeonWsQueryable {
@@ -459,9 +536,9 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
459
536
  };
460
537
  const tag = "[js::startTransaction]";
461
538
  debug("%s options: %O", tag, options);
462
- const conn = await this.client.connect();
463
- const tx = new NeonTransaction(conn, options);
539
+ const conn = await this.client.connect().catch((error) => this.onError(error));
464
540
  try {
541
+ const tx = new NeonTransaction(conn, options);
465
542
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
466
543
  if (isolationLevel) {
467
544
  await tx.executeRaw({
@@ -473,7 +550,7 @@ var PrismaNeonAdapter = class extends NeonWsQueryable {
473
550
  return tx;
474
551
  } catch (error) {
475
552
  conn.release(error);
476
- throw error;
553
+ this.onError(error);
477
554
  }
478
555
  }
479
556
  getConnectionInfo() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-neon",
3
- "version": "6.7.0-dev.1",
3
+ "version": "6.7.0-dev.3",
4
4
  "description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -32,7 +32,7 @@
32
32
  "sideEffects": false,
33
33
  "dependencies": {
34
34
  "postgres-array": "3.0.4",
35
- "@prisma/driver-adapter-utils": "6.7.0-dev.1"
35
+ "@prisma/driver-adapter-utils": "6.7.0-dev.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@neondatabase/serverless": "0.10.2",