@prisma/adapter-pg 6.7.0-dev.2 → 6.7.0-dev.4

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/pg.ts
372
460
  var types2 = import_pg2.default.types;
373
461
  var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:pg");
@@ -456,18 +544,7 @@ var PgQueryable = class {
456
544
  }
457
545
  onError(error) {
458
546
  debug("Error in performIO: %O", error);
459
- if (error && typeof error.code === "string" && typeof error.severity === "string" && typeof error.message === "string") {
460
- throw new import_driver_adapter_utils2.DriverAdapterError({
461
- kind: "postgres",
462
- code: error.code,
463
- severity: error.severity,
464
- message: error.message,
465
- detail: error.detail,
466
- column: error.column,
467
- hint: error.hint
468
- });
469
- }
470
- throw error;
547
+ throw new import_driver_adapter_utils2.DriverAdapterError(convertDriverError(error));
471
548
  }
472
549
  };
473
550
  var PgTransaction = class extends PgQueryable {
@@ -496,9 +573,9 @@ var PrismaPgAdapter = class extends PgQueryable {
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 PgTransaction(conn, options);
576
+ const conn = await this.client.connect().catch((error) => this.onError(error));
501
577
  try {
578
+ const tx = new PgTransaction(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 PrismaPgAdapter = class extends PgQueryable {
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
  async executeScript(script) {
package/dist/index.mjs CHANGED
@@ -332,6 +332,94 @@ function fixArrayBufferValues(values) {
332
332
  return values;
333
333
  }
334
334
 
335
+ // src/errors.ts
336
+ function convertDriverError(error) {
337
+ if (!isDbError(error)) {
338
+ throw error;
339
+ }
340
+ switch (error.code) {
341
+ case "22001":
342
+ return {
343
+ kind: "LengthMismatch",
344
+ column: error.column
345
+ };
346
+ case "23505":
347
+ return {
348
+ kind: "UniqueConstraintViolation",
349
+ fields: error.detail?.match(/Key \(([^)]+)\)/)?.at(1)?.split(", ") ?? []
350
+ };
351
+ case "23502":
352
+ return {
353
+ kind: "NullConstraintViolation",
354
+ fields: error.detail?.match(/Key \(([^)]+)\)/)?.at(1)?.split(", ") ?? []
355
+ };
356
+ case "23503": {
357
+ let constraint;
358
+ if (error.column) {
359
+ constraint = { fields: [error.column] };
360
+ } else if (error.constraint) {
361
+ constraint = { index: error.constraint };
362
+ }
363
+ return {
364
+ kind: "ForeignKeyConstraintViolation",
365
+ constraint
366
+ };
367
+ }
368
+ case "3D000":
369
+ return {
370
+ kind: "DatabaseDoesNotExist",
371
+ db: error.message.split(" ").at(1)?.split('"').at(1)
372
+ };
373
+ case "28000":
374
+ return {
375
+ kind: "DatabaseAccessDenied",
376
+ db: error.message.split(" ").at(5)?.split('"').at(1)
377
+ };
378
+ case "28P01":
379
+ return {
380
+ kind: "AuthenticationFailed",
381
+ user: error.message.split(" ").pop()?.split('"').at(1)
382
+ };
383
+ case "40001":
384
+ return {
385
+ kind: "TransactionWriteConflict"
386
+ };
387
+ case "42P01":
388
+ return {
389
+ kind: "TableDoesNotExist",
390
+ table: error.message.split(" ").at(1)?.split('"').at(1)
391
+ };
392
+ case "42703":
393
+ return {
394
+ kind: "ColumnNotFound",
395
+ column: error.message.split(" ").at(1)?.split('"').at(1)
396
+ };
397
+ case "42P04":
398
+ return {
399
+ kind: "DatabaseAlreadyExists",
400
+ db: error.message.split(" ").at(1)?.split('"').at(1)
401
+ };
402
+ case "53300":
403
+ return {
404
+ kind: "TooManyConnections",
405
+ cause: error.message
406
+ };
407
+ default:
408
+ return {
409
+ kind: "postgres",
410
+ code: error.code ?? "N/A",
411
+ severity: error.severity ?? "N/A",
412
+ message: error.message,
413
+ detail: error.detail,
414
+ column: error.column,
415
+ hint: error.hint
416
+ };
417
+ }
418
+ }
419
+ function isDbError(error) {
420
+ 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);
421
+ }
422
+
335
423
  // src/pg.ts
336
424
  var types2 = pg2.types;
337
425
  var debug = Debug("prisma:driver-adapter:pg");
@@ -420,18 +508,7 @@ var PgQueryable = class {
420
508
  }
421
509
  onError(error) {
422
510
  debug("Error in performIO: %O", error);
423
- if (error && typeof error.code === "string" && typeof error.severity === "string" && typeof error.message === "string") {
424
- throw new DriverAdapterError({
425
- kind: "postgres",
426
- code: error.code,
427
- severity: error.severity,
428
- message: error.message,
429
- detail: error.detail,
430
- column: error.column,
431
- hint: error.hint
432
- });
433
- }
434
- throw error;
511
+ throw new DriverAdapterError(convertDriverError(error));
435
512
  }
436
513
  };
437
514
  var PgTransaction = class extends PgQueryable {
@@ -460,9 +537,9 @@ var PrismaPgAdapter = class extends PgQueryable {
460
537
  };
461
538
  const tag = "[js::startTransaction]";
462
539
  debug("%s options: %O", tag, options);
463
- const conn = await this.client.connect();
464
- const tx = new PgTransaction(conn, options);
540
+ const conn = await this.client.connect().catch((error) => this.onError(error));
465
541
  try {
542
+ const tx = new PgTransaction(conn, options);
466
543
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
467
544
  if (isolationLevel) {
468
545
  await tx.executeRaw({
@@ -474,7 +551,7 @@ var PrismaPgAdapter = class extends PgQueryable {
474
551
  return tx;
475
552
  } catch (error) {
476
553
  conn.release(error);
477
- throw error;
554
+ this.onError(error);
478
555
  }
479
556
  }
480
557
  async executeScript(script) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "6.7.0-dev.2",
3
+ "version": "6.7.0-dev.4",
4
4
  "description": "Prisma's driver adapter for \"pg\"",
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.2"
35
+ "@prisma/driver-adapter-utils": "6.7.0-dev.4"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@swc/core": "1.11.5",