@payloadcms/drizzle 3.84.0-internal.d5d6e43 → 3.84.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.
|
@@ -33,8 +33,8 @@ import { ValidationError } from 'payload';
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
} else if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {
|
|
36
|
-
// SQLite - extract from message: "UNIQUE constraint failed: table.field"
|
|
37
|
-
const regex = /UNIQUE constraint failed: ([^.]+)\.([
|
|
36
|
+
// SQLite - extract from message: "UNIQUE constraint failed: table.field[, table.field2, ...]"
|
|
37
|
+
const regex = /UNIQUE constraint failed: ([^.]+)\.([^.,]+)/;
|
|
38
38
|
const match = error.message?.match(regex);
|
|
39
39
|
if (match && match[2]) {
|
|
40
40
|
if (adapter.fieldConstraints[tableName]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/upsertRow/handleUpsertError.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { ValidationError } from 'payload'\n\nimport type { DrizzleAdapter } from '../types.js'\n\ntype HandleUpsertErrorArgs = {\n adapter: DrizzleAdapter\n collectionSlug?: string\n error: unknown\n globalSlug?: string\n id?: number | string\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\n/**\n * Handles unique constraint violation errors from PostgreSQL and SQLite,\n * converting them to Payload ValidationErrors.\n * Re-throws non-constraint errors unchanged.\n */\nexport const handleUpsertError = ({\n id,\n adapter,\n collectionSlug,\n error: caughtError,\n globalSlug,\n req,\n tableName,\n}: HandleUpsertErrorArgs): never => {\n let error: any = caughtError\n if (typeof caughtError === 'object' && caughtError !== null && 'cause' in caughtError) {\n error = caughtError.cause\n }\n\n // PostgreSQL: 23505, SQLite: SQLITE_CONSTRAINT_UNIQUE\n if (error?.code === '23505' || error?.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n let fieldName: null | string = null\n\n if (error.code === '23505') {\n // PostgreSQL - extract field name from constraint\n if (adapter.fieldConstraints?.[tableName]?.[error.constraint]) {\n fieldName = adapter.fieldConstraints[tableName][error.constraint]\n } else {\n const replacement = `${tableName}_`\n if (error.constraint?.includes(replacement)) {\n const replacedConstraint = error.constraint.replace(replacement, '')\n if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint]) {\n fieldName = adapter.fieldConstraints[tableName][replacedConstraint]\n }\n }\n }\n\n if (!fieldName && error.detail) {\n // Extract from detail: \"Key (field)=(value) already exists.\"\n const regex = /Key \\(([^)]+)\\)=\\(([^)]+)\\)/\n const match: string[] = error.detail.match(regex)\n if (match && match[1]) {\n fieldName = match[1]\n }\n }\n } else if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n // SQLite - extract from message: \"UNIQUE constraint failed: table.field\"\n const regex = /UNIQUE constraint failed: ([^.]+)\\.([
|
|
1
|
+
{"version":3,"sources":["../../src/upsertRow/handleUpsertError.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { ValidationError } from 'payload'\n\nimport type { DrizzleAdapter } from '../types.js'\n\ntype HandleUpsertErrorArgs = {\n adapter: DrizzleAdapter\n collectionSlug?: string\n error: unknown\n globalSlug?: string\n id?: number | string\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\n/**\n * Handles unique constraint violation errors from PostgreSQL and SQLite,\n * converting them to Payload ValidationErrors.\n * Re-throws non-constraint errors unchanged.\n */\nexport const handleUpsertError = ({\n id,\n adapter,\n collectionSlug,\n error: caughtError,\n globalSlug,\n req,\n tableName,\n}: HandleUpsertErrorArgs): never => {\n let error: any = caughtError\n if (typeof caughtError === 'object' && caughtError !== null && 'cause' in caughtError) {\n error = caughtError.cause\n }\n\n // PostgreSQL: 23505, SQLite: SQLITE_CONSTRAINT_UNIQUE\n if (error?.code === '23505' || error?.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n let fieldName: null | string = null\n\n if (error.code === '23505') {\n // PostgreSQL - extract field name from constraint\n if (adapter.fieldConstraints?.[tableName]?.[error.constraint]) {\n fieldName = adapter.fieldConstraints[tableName][error.constraint]\n } else {\n const replacement = `${tableName}_`\n if (error.constraint?.includes(replacement)) {\n const replacedConstraint = error.constraint.replace(replacement, '')\n if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint]) {\n fieldName = adapter.fieldConstraints[tableName][replacedConstraint]\n }\n }\n }\n\n if (!fieldName && error.detail) {\n // Extract from detail: \"Key (field)=(value) already exists.\"\n const regex = /Key \\(([^)]+)\\)=\\(([^)]+)\\)/\n const match: string[] = error.detail.match(regex)\n if (match && match[1]) {\n fieldName = match[1]\n }\n }\n } else if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n // SQLite - extract from message: \"UNIQUE constraint failed: table.field[, table.field2, ...]\"\n const regex = /UNIQUE constraint failed: ([^.]+)\\.([^.,]+)/\n const match: string[] = error.message?.match(regex)\n if (match && match[2]) {\n if (adapter.fieldConstraints[tableName]) {\n fieldName = adapter.fieldConstraints[tableName][`${match[2]}_idx`]\n }\n if (!fieldName) {\n fieldName = match[2]\n }\n }\n }\n\n throw new ValidationError(\n {\n id,\n collection: collectionSlug,\n errors: [\n {\n message: req?.t ? req.t('error:valueMustBeUnique') : 'Value must be unique',\n path: fieldName,\n },\n ],\n global: globalSlug,\n req,\n },\n req?.t,\n )\n }\n\n // Re-throw non-constraint errors\n throw caughtError\n}\n"],"names":["ValidationError","handleUpsertError","id","adapter","collectionSlug","error","caughtError","globalSlug","req","tableName","cause","code","fieldName","fieldConstraints","constraint","replacement","includes","replacedConstraint","replace","detail","regex","match","message","collection","errors","t","path","global"],"mappings":"AAEA,SAASA,eAAe,QAAQ,UAAS;AAczC;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,EAAE,EACFC,OAAO,EACPC,cAAc,EACdC,OAAOC,WAAW,EAClBC,UAAU,EACVC,GAAG,EACHC,SAAS,EACa;IACtB,IAAIJ,QAAaC;IACjB,IAAI,OAAOA,gB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C,EAAE,CAAC,IAAI,CAAC,CAAC;gBACpE;gBACA,IAAI,CAACT,WAAW;oBACdA,YAAYS,KAAK,CAAC,EAAE;gBACtB;YACF;QACF;QAEA,MAAM,IAAIrB,gBACR;YACEE;YACAqB,YAAYnB;YACZoB,QAAQ;gBACN;oBACEF,SAASd,KAAKiB,IAAIjB,IAAIiB,CAAC,CAAC,6BAA6B;oBACrDC,MAAMd;gBACR;aACD;YACDe,QAAQpB;YACRC;QACF,GACAA,KAAKiB;IAET;IAEA,iCAAiC;IACjC,MAAMnB;AACR,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.84.
|
|
3
|
+
"version": "3.84.1",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@types/pg": "8.20.0",
|
|
61
61
|
"@types/to-snake-case": "1.0.0",
|
|
62
62
|
"@payloadcms/eslint-config": "3.28.0",
|
|
63
|
-
"payload": "3.84.
|
|
63
|
+
"payload": "3.84.1"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"payload": "3.84.
|
|
66
|
+
"payload": "3.84.1"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build": "pnpm build:swc && pnpm build:types",
|