@payloadcms/drizzle 3.71.0-internal-debug.80dab4c → 3.71.0-internal.727c7a4
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/create.d.ts.map +1 -1
- package/dist/create.js +0 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +0 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +0 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +1 -8
- package/dist/createVersion.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +0 -4
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +0 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +0 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +0 -2
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +0 -1
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +0 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +0 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +145 -102
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/types.d.ts +0 -8
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/package.json +3 -3
- package/dist/upsertRow/handleUpsertError.d.ts +0 -19
- package/dist/upsertRow/handleUpsertError.d.ts.map +0 -1
- package/dist/upsertRow/handleUpsertError.js +0 -65
- package/dist/upsertRow/handleUpsertError.js.map +0 -1
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from 'payload';
|
|
2
|
-
/**
|
|
3
|
-
* Handles unique constraint violation errors from PostgreSQL and SQLite,
|
|
4
|
-
* converting them to Payload ValidationErrors.
|
|
5
|
-
* Re-throws non-constraint errors unchanged.
|
|
6
|
-
*/ export const handleUpsertError = ({ id, adapter, collectionSlug, error: caughtError, globalSlug, req, tableName })=>{
|
|
7
|
-
let error = caughtError;
|
|
8
|
-
if (typeof caughtError === 'object' && caughtError !== null && 'cause' in caughtError) {
|
|
9
|
-
error = caughtError.cause;
|
|
10
|
-
}
|
|
11
|
-
// PostgreSQL: 23505, SQLite: SQLITE_CONSTRAINT_UNIQUE
|
|
12
|
-
if (error?.code === '23505' || error?.code === 'SQLITE_CONSTRAINT_UNIQUE') {
|
|
13
|
-
let fieldName = null;
|
|
14
|
-
if (error.code === '23505') {
|
|
15
|
-
// PostgreSQL - extract field name from constraint
|
|
16
|
-
if (adapter.fieldConstraints?.[tableName]?.[error.constraint]) {
|
|
17
|
-
fieldName = adapter.fieldConstraints[tableName][error.constraint];
|
|
18
|
-
} else {
|
|
19
|
-
const replacement = `${tableName}_`;
|
|
20
|
-
if (error.constraint?.includes(replacement)) {
|
|
21
|
-
const replacedConstraint = error.constraint.replace(replacement, '');
|
|
22
|
-
if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint]) {
|
|
23
|
-
fieldName = adapter.fieldConstraints[tableName][replacedConstraint];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!fieldName && error.detail) {
|
|
28
|
-
// Extract from detail: "Key (field)=(value) already exists."
|
|
29
|
-
const regex = /Key \(([^)]+)\)=\(([^)]+)\)/;
|
|
30
|
-
const match = error.detail.match(regex);
|
|
31
|
-
if (match && match[1]) {
|
|
32
|
-
fieldName = match[1];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} else if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {
|
|
36
|
-
// SQLite - extract from message: "UNIQUE constraint failed: table.field"
|
|
37
|
-
const regex = /UNIQUE constraint failed: ([^.]+)\.([^.]+)/;
|
|
38
|
-
const match = error.message?.match(regex);
|
|
39
|
-
if (match && match[2]) {
|
|
40
|
-
if (adapter.fieldConstraints[tableName]) {
|
|
41
|
-
fieldName = adapter.fieldConstraints[tableName][`${match[2]}_idx`];
|
|
42
|
-
}
|
|
43
|
-
if (!fieldName) {
|
|
44
|
-
fieldName = match[2];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
throw new ValidationError({
|
|
49
|
-
id,
|
|
50
|
-
collection: collectionSlug,
|
|
51
|
-
errors: [
|
|
52
|
-
{
|
|
53
|
-
message: req?.t ? req.t('error:valueMustBeUnique') : 'Value must be unique',
|
|
54
|
-
path: fieldName
|
|
55
|
-
}
|
|
56
|
-
],
|
|
57
|
-
global: globalSlug,
|
|
58
|
-
req
|
|
59
|
-
}, req?.t);
|
|
60
|
-
}
|
|
61
|
-
// Re-throw non-constraint errors
|
|
62
|
-
throw caughtError;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//# sourceMappingURL=handleUpsertError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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: ([^.]+)\\.([^.]+)/\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,gBAAgB,YAAYA,gBAAgB,QAAQ,WAAWA,aAAa;QACrFD,QAAQC,YAAYI,KAAK;IAC3B;IAEA,sDAAsD;IACtD,IAAIL,OAAOM,SAAS,WAAWN,OAAOM,SAAS,4BAA4B;QACzE,IAAIC,YAA2B;QAE/B,IAAIP,MAAMM,IAAI,KAAK,SAAS;YAC1B,kDAAkD;YAClD,IAAIR,QAAQU,gBAAgB,EAAE,CAACJ,UAAU,EAAE,CAACJ,MAAMS,UAAU,CAAC,EAAE;gBAC7DF,YAAYT,QAAQU,gBAAgB,CAACJ,UAAU,CAACJ,MAAMS,UAAU,CAAC;YACnE,OAAO;gBACL,MAAMC,cAAc,GAAGN,UAAU,CAAC,CAAC;gBACnC,IAAIJ,MAAMS,UAAU,EAAEE,SAASD,cAAc;oBAC3C,MAAME,qBAAqBZ,MAAMS,UAAU,CAACI,OAAO,CAACH,aAAa;oBACjE,IAAIE,sBAAsBd,QAAQU,gBAAgB,CAACJ,UAAU,EAAE,CAACQ,mBAAmB,EAAE;wBACnFL,YAAYT,QAAQU,gBAAgB,CAACJ,UAAU,CAACQ,mBAAmB;oBACrE;gBACF;YACF;YAEA,IAAI,CAACL,aAAaP,MAAMc,MAAM,EAAE;gBAC9B,6DAA6D;gBAC7D,MAAMC,QAAQ;gBACd,MAAMC,QAAkBhB,MAAMc,M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