@payloadcms/drizzle 4.0.0-internal.c7d5de4 → 4.0.0-internal.cc18726
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/createTableName.d.ts.map +1 -1
- package/dist/createTableName.js +2 -7
- package/dist/createTableName.js.map +1 -1
- package/dist/exports/postgres.d.ts +2 -0
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +2 -0
- package/dist/exports/postgres.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +35 -13
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts +2 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +12 -2
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +21 -7
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts +2 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +14 -3
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts +2 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +12 -2
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.d.ts +2 -1
- package/dist/migrateStatus.d.ts.map +1 -1
- package/dist/migrateStatus.js +11 -6
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +6 -0
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts +15 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts.map +1 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js +25 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js.map +1 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.spec.js +91 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.spec.js.map +1 -0
- package/dist/postgres/query/postgresUnaccent.d.ts +13 -0
- package/dist/postgres/query/postgresUnaccent.d.ts.map +1 -0
- package/dist/postgres/query/postgresUnaccent.js +40 -0
- package/dist/postgres/query/postgresUnaccent.js.map +1 -0
- package/dist/postgres/query/postgresUnaccent.spec.js +71 -0
- package/dist/postgres/query/postgresUnaccent.spec.js.map +1 -0
- package/dist/postgres/types.d.ts +13 -2
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/buildOperatorConstraint.d.ts +22 -0
- package/dist/queries/buildOperatorConstraint.d.ts.map +1 -0
- package/dist/queries/buildOperatorConstraint.js +63 -0
- package/dist/queries/buildOperatorConstraint.js.map +1 -0
- package/dist/queries/buildOperatorConstraint.spec.js +348 -0
- package/dist/queries/buildOperatorConstraint.spec.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.d.ts +12 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +50 -27
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +7 -3
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +203 -8
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/resolveRelationshipPath.d.ts +36 -0
- package/dist/queries/resolveRelationshipPath.d.ts.map +1 -0
- package/dist/queries/resolveRelationshipPath.js +66 -0
- package/dist/queries/resolveRelationshipPath.js.map +1 -0
- package/dist/queries/validateOperatorHandlers.d.ts +8 -0
- package/dist/queries/validateOperatorHandlers.d.ts.map +1 -0
- package/dist/queries/validateOperatorHandlers.js +30 -0
- package/dist/queries/validateOperatorHandlers.js.map +1 -0
- package/dist/queries/validateOperatorHandlers.spec.js +142 -0
- package/dist/queries/validateOperatorHandlers.spec.js.map +1 -0
- package/dist/schema/buildRawSchema.spec.js +290 -0
- package/dist/schema/buildRawSchema.spec.js.map +1 -0
- package/dist/schema/traverseFields.js +5 -5
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/types.d.ts +50 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +37 -0
- package/dist/updateJobs.js.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.js +12 -8
- package/dist/utilities/buildCreateMigration.js.map +1 -1
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.js +3 -2
- package/dist/utilities/buildForeignKeyName.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.js +3 -2
- package/dist/utilities/buildIndexName.js.map +1 -1
- package/dist/utilities/checkTruncatedIdentifiers.d.ts +13 -0
- package/dist/utilities/checkTruncatedIdentifiers.d.ts.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.js +56 -0
- package/dist/utilities/checkTruncatedIdentifiers.js.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.spec.js +301 -0
- package/dist/utilities/checkTruncatedIdentifiers.spec.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +3 -0
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +1 -5
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
- package/dist/utilities/validateIdentifierLength.d.ts +12 -0
- package/dist/utilities/validateIdentifierLength.d.ts.map +1 -0
- package/dist/utilities/validateIdentifierLength.js +18 -0
- package/dist/utilities/validateIdentifierLength.js.map +1 -0
- package/dist/utilities/validateIdentifierLength.spec.js +19 -0
- package/dist/utilities/validateIdentifierLength.spec.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
const isReplacementHandler = (handler)=>typeof handler.build === 'function';
|
|
3
|
+
const fieldTypesOverlap = (a, b)=>!a.fieldTypes || !b.fieldTypes || a.fieldTypes.some((fieldType)=>b.fieldTypes.includes(fieldType));
|
|
4
|
+
/**
|
|
5
|
+
* Validates operator-handler configuration before any request runs: rejects a handler that
|
|
6
|
+
* defines both `build` and `transformOperands`, and rejects two replacement handlers whose
|
|
7
|
+
* `operators` and `fieldTypes` both overlap for the same resolved operator.
|
|
8
|
+
*/ export const validateOperatorHandlers = (operatorHandlers)=>{
|
|
9
|
+
for (const handler of operatorHandlers){
|
|
10
|
+
if (typeof handler.build === 'function' && typeof handler.transformOperands === 'function') {
|
|
11
|
+
throw new APIError(`Operator handler "${handler.name}" cannot define both "build" and "transformOperands". Use "transformOperands" to adjust operands, or "build" to replace the comparison entirely.`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const replacementHandlers = operatorHandlers.filter(isReplacementHandler);
|
|
15
|
+
for(let i = 0; i < replacementHandlers.length; i++){
|
|
16
|
+
for(let j = i + 1; j < replacementHandlers.length; j++){
|
|
17
|
+
const handlerA = replacementHandlers[i];
|
|
18
|
+
const handlerB = replacementHandlers[j];
|
|
19
|
+
const sharedOperators = handlerA.operators.filter((operator)=>handlerB.operators.includes(operator));
|
|
20
|
+
if (!sharedOperators.length) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (fieldTypesOverlap(handlerA, handlerB)) {
|
|
24
|
+
throw new APIError(`Operator handlers "${handlerA.name}" and "${handlerB.name}" both replace the "${sharedOperators.join('", "')}" operator for overlapping field types. Only one replacement handler may match a given resolved operator and field type.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=validateOperatorHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/validateOperatorHandlers.ts"],"sourcesContent":["import { APIError } from 'payload'\n\nimport type { DrizzleOperatorHandler, DrizzleOperatorReplacementHandler } from '../types.js'\n\nconst isReplacementHandler = (\n handler: DrizzleOperatorHandler,\n): handler is DrizzleOperatorReplacementHandler => typeof handler.build === 'function'\n\nconst fieldTypesOverlap = (\n a: DrizzleOperatorReplacementHandler,\n b: DrizzleOperatorReplacementHandler,\n): boolean =>\n !a.fieldTypes ||\n !b.fieldTypes ||\n a.fieldTypes.some((fieldType) => b.fieldTypes.includes(fieldType))\n\n/**\n * Validates operator-handler configuration before any request runs: rejects a handler that\n * defines both `build` and `transformOperands`, and rejects two replacement handlers whose\n * `operators` and `fieldTypes` both overlap for the same resolved operator.\n */\nexport const validateOperatorHandlers = (operatorHandlers: DrizzleOperatorHandler[]): void => {\n for (const handler of operatorHandlers) {\n if (typeof handler.build === 'function' && typeof handler.transformOperands === 'function') {\n throw new APIError(\n `Operator handler \"${handler.name}\" cannot define both \"build\" and \"transformOperands\". Use \"transformOperands\" to adjust operands, or \"build\" to replace the comparison entirely.`,\n )\n }\n }\n\n const replacementHandlers = operatorHandlers.filter(isReplacementHandler)\n\n for (let i = 0; i < replacementHandlers.length; i++) {\n for (let j = i + 1; j < replacementHandlers.length; j++) {\n const handlerA = replacementHandlers[i]\n const handlerB = replacementHandlers[j]\n\n const sharedOperators = handlerA.operators.filter((operator) =>\n handlerB.operators.includes(operator),\n )\n\n if (!sharedOperators.length) {\n continue\n }\n\n if (fieldTypesOverlap(handlerA, handlerB)) {\n throw new APIError(\n `Operator handlers \"${handlerA.name}\" and \"${handlerB.name}\" both replace the \"${sharedOperators.join('\", \"')}\" operator for overlapping field types. Only one replacement handler may match a given resolved operator and field type.`,\n )\n }\n }\n }\n}\n"],"names":["APIError","isReplacementHandler","handler","build","fieldTypesOverlap","a","b","fieldTypes","some","fieldType","includes","validateOperatorHandlers","operatorHandlers","transformOperands","name","replacementHandlers","filter","i","length","j","handlerA","handlerB","sharedOperators","operators","operator","join"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,MAAMC,uBAAuB,CAC3BC,UACiD,OAAOA,QAAQC,KAAK,KAAK;AAE5E,MAAMC,oBAAoB,CACxBC,GACAC,IAEA,CAACD,EAAEE,UAAU,IACb,CAACD,EAAEC,UAAU,IACbF,EAAEE,UAAU,CAACC,IAAI,CAAC,CAACC,YAAcH,EAAEC,UAAU,CAACG,QAAQ,CAACD;AAEzD;;;;CAIC,GACD,OAAO,MAAME,2BAA2B,CAACC;IACvC,KAAK,MAAMV,WAAWU,iBAAkB;QACtC,IAAI,OAAOV,QAAQC,KAAK,KAAK,cAAc,OAAOD,QAAQW,iBAAiB,KAAK,YAAY;YAC1F,MAAM,IAAIb,SACR,CAAC,kBAAkB,EAAEE,QAAQY,IAAI,CAAC,gJAAgJ,CAAC;QAEvL;IACF;IAEA,MAAMC,sBAAsBH,iBAAiBI,MAAM,CAACf;IAEpD,IAAK,IAAIgB,IAAI,GAAGA,IAAIF,oBAAoBG,MAAM,EAAED,IAAK;QACnD,IAAK,IAAIE,IAAIF,IAAI,GAAGE,IAAIJ,oBAAoBG,MAAM,EAAEC,IAAK;YACvD,MAAMC,WAAWL,mBAAmB,CAACE,EAAE;YACvC,MAAMI,WAAWN,mBAAmB,CAACI,EAAE;YAEvC,MAAMG,kBAAkBF,SAASG,SAAS,CAACP,MAAM,CAAC,CAACQ,WACjDH,SAASE,SAAS,CAACb,QAAQ,CAACc;YAG9B,IAAI,CAACF,gBAAgBJ,MAAM,EAAE;gBAC3B;YACF;YAEA,IAAId,kBAAkBgB,UAAUC,WAAW;gBACzC,MAAM,IAAIrB,SACR,CAAC,mBAAmB,EAAEoB,SAASN,IAAI,CAAC,OAAO,EAAEO,SAASP,IAAI,CAAC,oBAAoB,EAAEQ,gBAAgBG,IAAI,CAAC,QAAQ,wHAAwH,CAAC;YAE3O;QACF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { validateOperatorHandlers } from './validateOperatorHandlers.js';
|
|
3
|
+
const transformHandler = (overrides = {})=>({
|
|
4
|
+
name: 'transform',
|
|
5
|
+
operators: [
|
|
6
|
+
'contains'
|
|
7
|
+
],
|
|
8
|
+
transformOperands: ({ column, value })=>({
|
|
9
|
+
column,
|
|
10
|
+
value
|
|
11
|
+
}),
|
|
12
|
+
...overrides
|
|
13
|
+
});
|
|
14
|
+
const replacementHandler = (overrides = {})=>({
|
|
15
|
+
name: 'replace',
|
|
16
|
+
operators: [
|
|
17
|
+
'contains'
|
|
18
|
+
],
|
|
19
|
+
build: ()=>null,
|
|
20
|
+
...overrides
|
|
21
|
+
});
|
|
22
|
+
describe('validateOperatorHandlers', ()=>{
|
|
23
|
+
it('does not throw when zero handlers are configured', ()=>{
|
|
24
|
+
expect(()=>validateOperatorHandlers([])).not.toThrow();
|
|
25
|
+
});
|
|
26
|
+
it('does not throw for any number of non-conflicting operand-transform handlers', ()=>{
|
|
27
|
+
expect(()=>validateOperatorHandlers([
|
|
28
|
+
transformHandler({
|
|
29
|
+
name: 'a'
|
|
30
|
+
}),
|
|
31
|
+
transformHandler({
|
|
32
|
+
name: 'b'
|
|
33
|
+
}),
|
|
34
|
+
transformHandler({
|
|
35
|
+
name: 'c'
|
|
36
|
+
})
|
|
37
|
+
])).not.toThrow();
|
|
38
|
+
});
|
|
39
|
+
it('throws when two build handlers list the same resolved operator, naming both handlers and the operator', ()=>{
|
|
40
|
+
expect(()=>validateOperatorHandlers([
|
|
41
|
+
replacementHandler({
|
|
42
|
+
name: 'handler-a',
|
|
43
|
+
operators: [
|
|
44
|
+
'contains'
|
|
45
|
+
]
|
|
46
|
+
}),
|
|
47
|
+
replacementHandler({
|
|
48
|
+
name: 'handler-b',
|
|
49
|
+
operators: [
|
|
50
|
+
'contains'
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
])).toThrow(/handler-a/);
|
|
54
|
+
expect(()=>validateOperatorHandlers([
|
|
55
|
+
replacementHandler({
|
|
56
|
+
name: 'handler-a',
|
|
57
|
+
operators: [
|
|
58
|
+
'contains'
|
|
59
|
+
]
|
|
60
|
+
}),
|
|
61
|
+
replacementHandler({
|
|
62
|
+
name: 'handler-b',
|
|
63
|
+
operators: [
|
|
64
|
+
'contains'
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
])).toThrow(/handler-b/);
|
|
68
|
+
expect(()=>validateOperatorHandlers([
|
|
69
|
+
replacementHandler({
|
|
70
|
+
name: 'handler-a',
|
|
71
|
+
operators: [
|
|
72
|
+
'contains'
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
replacementHandler({
|
|
76
|
+
name: 'handler-b',
|
|
77
|
+
operators: [
|
|
78
|
+
'contains'
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
])).toThrow(/contains/);
|
|
82
|
+
});
|
|
83
|
+
it('does not throw when two build handlers target the same operator but declare disjoint fieldTypes', ()=>{
|
|
84
|
+
expect(()=>validateOperatorHandlers([
|
|
85
|
+
replacementHandler({
|
|
86
|
+
name: 'text',
|
|
87
|
+
operators: [
|
|
88
|
+
'contains'
|
|
89
|
+
],
|
|
90
|
+
fieldTypes: [
|
|
91
|
+
'text'
|
|
92
|
+
]
|
|
93
|
+
}),
|
|
94
|
+
replacementHandler({
|
|
95
|
+
name: 'number',
|
|
96
|
+
operators: [
|
|
97
|
+
'contains'
|
|
98
|
+
],
|
|
99
|
+
fieldTypes: [
|
|
100
|
+
'number'
|
|
101
|
+
]
|
|
102
|
+
})
|
|
103
|
+
])).not.toThrow();
|
|
104
|
+
});
|
|
105
|
+
it('throws when two build handlers target the same operator and at least one declares no fieldTypes', ()=>{
|
|
106
|
+
expect(()=>validateOperatorHandlers([
|
|
107
|
+
replacementHandler({
|
|
108
|
+
name: 'unrestricted',
|
|
109
|
+
operators: [
|
|
110
|
+
'contains'
|
|
111
|
+
]
|
|
112
|
+
}),
|
|
113
|
+
replacementHandler({
|
|
114
|
+
name: 'text',
|
|
115
|
+
operators: [
|
|
116
|
+
'contains'
|
|
117
|
+
],
|
|
118
|
+
fieldTypes: [
|
|
119
|
+
'text'
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
])).toThrow();
|
|
123
|
+
});
|
|
124
|
+
it('throws when a handler object defines both build and transformOperands', ()=>{
|
|
125
|
+
const malformed = {
|
|
126
|
+
name: 'malformed',
|
|
127
|
+
operators: [
|
|
128
|
+
'contains'
|
|
129
|
+
],
|
|
130
|
+
build: ()=>null,
|
|
131
|
+
transformOperands: ({ column, value })=>({
|
|
132
|
+
column,
|
|
133
|
+
value
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
expect(()=>validateOperatorHandlers([
|
|
137
|
+
malformed
|
|
138
|
+
])).toThrow(/malformed/);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=validateOperatorHandlers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/validateOperatorHandlers.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport type { DrizzleOperatorHandler } from '../types.js'\n\nimport { validateOperatorHandlers } from './validateOperatorHandlers.js'\n\nconst transformHandler = (\n overrides: Partial<DrizzleOperatorHandler> = {},\n): DrizzleOperatorHandler =>\n ({\n name: 'transform',\n operators: ['contains'],\n transformOperands: ({ column, value }) => ({ column, value }),\n ...overrides,\n }) as DrizzleOperatorHandler\n\nconst replacementHandler = (\n overrides: Partial<DrizzleOperatorHandler> = {},\n): DrizzleOperatorHandler =>\n ({\n name: 'replace',\n operators: ['contains'],\n build: () => null as any,\n ...overrides,\n }) as DrizzleOperatorHandler\n\ndescribe('validateOperatorHandlers', () => {\n it('does not throw when zero handlers are configured', () => {\n expect(() => validateOperatorHandlers([])).not.toThrow()\n })\n\n it('does not throw for any number of non-conflicting operand-transform handlers', () => {\n expect(() =>\n validateOperatorHandlers([\n transformHandler({ name: 'a' }),\n transformHandler({ name: 'b' }),\n transformHandler({ name: 'c' }),\n ]),\n ).not.toThrow()\n })\n\n it('throws when two build handlers list the same resolved operator, naming both handlers and the operator', () => {\n expect(() =>\n validateOperatorHandlers([\n replacementHandler({ name: 'handler-a', operators: ['contains'] }),\n replacementHandler({ name: 'handler-b', operators: ['contains'] }),\n ]),\n ).toThrow(/handler-a/)\n\n expect(() =>\n validateOperatorHandlers([\n replacementHandler({ name: 'handler-a', operators: ['contains'] }),\n replacementHandler({ name: 'handler-b', operators: ['contains'] }),\n ]),\n ).toThrow(/handler-b/)\n\n expect(() =>\n validateOperatorHandlers([\n replacementHandler({ name: 'handler-a', operators: ['contains'] }),\n replacementHandler({ name: 'handler-b', operators: ['contains'] }),\n ]),\n ).toThrow(/contains/)\n })\n\n it('does not throw when two build handlers target the same operator but declare disjoint fieldTypes', () => {\n expect(() =>\n validateOperatorHandlers([\n replacementHandler({ name: 'text', operators: ['contains'], fieldTypes: ['text'] }),\n replacementHandler({ name: 'number', operators: ['contains'], fieldTypes: ['number'] }),\n ]),\n ).not.toThrow()\n })\n\n it('throws when two build handlers target the same operator and at least one declares no fieldTypes', () => {\n expect(() =>\n validateOperatorHandlers([\n replacementHandler({ name: 'unrestricted', operators: ['contains'] }),\n replacementHandler({ name: 'text', operators: ['contains'], fieldTypes: ['text'] }),\n ]),\n ).toThrow()\n })\n\n it('throws when a handler object defines both build and transformOperands', () => {\n const malformed = {\n name: 'malformed',\n operators: ['contains'],\n build: () => null as any,\n transformOperands: ({ column, value }: any) => ({ column, value }),\n } as unknown as DrizzleOperatorHandler\n\n expect(() => validateOperatorHandlers([malformed])).toThrow(/malformed/)\n })\n})\n"],"names":["describe","expect","it","validateOperatorHandlers","transformHandler","overrides","name","operators","transformOperands","column","value","replacementHandler","build","not","toThrow","fieldTypes","malformed"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAI7C,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,MAAMC,mBAAmB,CACvBC,YAA6C,CAAC,CAAC,GAE9C,CAAA;QACCC,MAAM;QACNC,WAAW;YAAC;SAAW;QACvBC,mBAAmB,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAM,CAAA;gBAAED;gBAAQC;YAAM,CAAA;QAC3D,GAAGL,SAAS;IACd,CAAA;AAEF,MAAMM,qBAAqB,CACzBN,YAA6C,CAAC,CAAC,GAE9C,CAAA;QACCC,MAAM;QACNC,WAAW;YAAC;SAAW;QACvBK,OAAO,IAAM;QACb,GAAGP,SAAS;IACd,CAAA;AAEFL,SAAS,4BAA4B;IACnCE,GAAG,oDAAoD;QACrDD,OAAO,IAAME,yBAAyB,EAAE,GAAGU,GAAG,CAACC,OAAO;IACxD;IAEAZ,GAAG,+EAA+E;QAChFD,OAAO,IACLE,yBAAyB;gBACvBC,iBAAiB;oBAAEE,MAAM;gBAAI;gBAC7BF,iBAAiB;oBAAEE,MAAM;gBAAI;gBAC7BF,iBAAiB;oBAAEE,MAAM;gBAAI;aAC9B,GACDO,GAAG,CAACC,OAAO;IACf;IAEAZ,GAAG,yGAAyG;QAC1GD,OAAO,IACLE,yBAAyB;gBACvBQ,mBAAmB;oBAAEL,MAAM;oBAAaC,WAAW;wBAAC;qBAAW;gBAAC;gBAChEI,mBAAmB;oBAAEL,MAAM;oBAAaC,WAAW;wBAAC;qBAAW;gBAAC;aACjE,GACDO,OAAO,CAAC;QAEVb,OAAO,IACLE,yBAAyB;gBACvBQ,mBA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vitest';
|
|
3
|
+
import { setColumnID } from '../postgres/schema/setColumnID.js';
|
|
4
|
+
import { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js';
|
|
5
|
+
import { buildRawSchema } from './buildRawSchema.js';
|
|
6
|
+
const headlineBlock = {
|
|
7
|
+
slug: 'headline',
|
|
8
|
+
fields: [
|
|
9
|
+
{
|
|
10
|
+
name: 'title',
|
|
11
|
+
type: 'text'
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
const createContainerBlock = (slug)=>({
|
|
16
|
+
slug,
|
|
17
|
+
fields: [
|
|
18
|
+
{
|
|
19
|
+
name: 'content',
|
|
20
|
+
type: 'blocks',
|
|
21
|
+
blocks: [
|
|
22
|
+
'headline'
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
});
|
|
27
|
+
const createAdapter = (config, warn = ()=>{})=>({
|
|
28
|
+
blocksAsJSON: false,
|
|
29
|
+
fieldConstraints: {},
|
|
30
|
+
idType: 'serial',
|
|
31
|
+
localesSuffix: '_locales',
|
|
32
|
+
payload: {
|
|
33
|
+
blocks: Object.fromEntries(config.blocks.map((block)=>[
|
|
34
|
+
block.slug,
|
|
35
|
+
block
|
|
36
|
+
])),
|
|
37
|
+
collections: Object.fromEntries(config.collections.map((collection)=>[
|
|
38
|
+
collection.slug,
|
|
39
|
+
{
|
|
40
|
+
config: collection,
|
|
41
|
+
customIDType: undefined
|
|
42
|
+
}
|
|
43
|
+
])),
|
|
44
|
+
config,
|
|
45
|
+
logger: {
|
|
46
|
+
warn
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
rawRelations: {},
|
|
50
|
+
rawTables: {},
|
|
51
|
+
tableNameMap: new Map(),
|
|
52
|
+
versionsSuffix: '_versions'
|
|
53
|
+
});
|
|
54
|
+
describe('buildRawSchema', ()=>{
|
|
55
|
+
it('should create suffixed block tables for different schemas with the same slug', async ()=>{
|
|
56
|
+
const config = sanitizeConfig({
|
|
57
|
+
collections: [
|
|
58
|
+
{
|
|
59
|
+
slug: 'pages',
|
|
60
|
+
fields: [
|
|
61
|
+
{
|
|
62
|
+
name: 'primaryContent',
|
|
63
|
+
type: 'blocks',
|
|
64
|
+
localized: true,
|
|
65
|
+
blocks: [
|
|
66
|
+
{
|
|
67
|
+
slug: 'content',
|
|
68
|
+
fields: [
|
|
69
|
+
{
|
|
70
|
+
name: 'title',
|
|
71
|
+
type: 'text'
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'secondaryContent',
|
|
79
|
+
type: 'blocks',
|
|
80
|
+
localized: true,
|
|
81
|
+
blocks: [
|
|
82
|
+
{
|
|
83
|
+
slug: 'content',
|
|
84
|
+
fields: [
|
|
85
|
+
{
|
|
86
|
+
name: 'description',
|
|
87
|
+
type: 'textarea'
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
localization: {
|
|
97
|
+
defaultLocale: 'en',
|
|
98
|
+
locales: [
|
|
99
|
+
'en',
|
|
100
|
+
'de'
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
const adapter = createAdapter(config);
|
|
105
|
+
buildRawSchema({
|
|
106
|
+
adapter,
|
|
107
|
+
setColumnID
|
|
108
|
+
});
|
|
109
|
+
expect(adapter.rawTables.pages_blocks_content.columns.title).toBeDefined();
|
|
110
|
+
expect(adapter.rawTables.pages_blocks_content.columns._locale).toBeDefined();
|
|
111
|
+
expect(adapter.rawTables.pages_blocks_content_2.columns.description).toBeDefined();
|
|
112
|
+
expect(adapter.rawTables.pages_blocks_content_2.columns._locale).toBeDefined();
|
|
113
|
+
});
|
|
114
|
+
it('should not create duplicate suffixed block tables for identical reused blocks under localized ancestors', async ()=>{
|
|
115
|
+
const layoutBlocks = [
|
|
116
|
+
createContainerBlock('container'),
|
|
117
|
+
createContainerBlock('container50')
|
|
118
|
+
];
|
|
119
|
+
const config = sanitizeConfig({
|
|
120
|
+
blocks: [
|
|
121
|
+
headlineBlock
|
|
122
|
+
],
|
|
123
|
+
collections: [
|
|
124
|
+
{
|
|
125
|
+
slug: 'pages',
|
|
126
|
+
fields: [
|
|
127
|
+
{
|
|
128
|
+
name: 'layout',
|
|
129
|
+
type: 'blocks',
|
|
130
|
+
localized: true,
|
|
131
|
+
blocks: layoutBlocks
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
slug: 'posts',
|
|
137
|
+
fields: [
|
|
138
|
+
{
|
|
139
|
+
name: 'layout',
|
|
140
|
+
type: 'blocks',
|
|
141
|
+
localized: true,
|
|
142
|
+
blocks: layoutBlocks
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
localization: {
|
|
148
|
+
defaultLocale: 'en',
|
|
149
|
+
locales: [
|
|
150
|
+
'en',
|
|
151
|
+
'de'
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const adapter = createAdapter(config);
|
|
156
|
+
buildRawSchema({
|
|
157
|
+
adapter,
|
|
158
|
+
setColumnID
|
|
159
|
+
});
|
|
160
|
+
expect(adapter.rawTables.pages_blocks_headline).toBeDefined();
|
|
161
|
+
expect(adapter.rawTables.pages_blocks_headline.columns._locale).toBeDefined();
|
|
162
|
+
expect(adapter.rawTables.pages_blocks_headline_2).toBeUndefined();
|
|
163
|
+
expect(adapter.rawTables.pages_blocks_headline_2_locales).toBeUndefined();
|
|
164
|
+
expect(adapter.rawTables.posts_blocks_headline).toBeDefined();
|
|
165
|
+
expect(adapter.rawTables.posts_blocks_headline.columns._locale).toBeDefined();
|
|
166
|
+
expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined();
|
|
167
|
+
expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined();
|
|
168
|
+
});
|
|
169
|
+
it('should warn when a localized field pushes the _locales companion table past 63 chars', async ()=>{
|
|
170
|
+
// Base table name (61 chars) is under the limit, but `${base}_locales` (69) overflows it.
|
|
171
|
+
const longSlug = `localized_collection_${'x'.repeat(40)}`;
|
|
172
|
+
const config = sanitizeConfig({
|
|
173
|
+
collections: [
|
|
174
|
+
{
|
|
175
|
+
slug: longSlug,
|
|
176
|
+
fields: [
|
|
177
|
+
{
|
|
178
|
+
name: 'title',
|
|
179
|
+
type: 'text',
|
|
180
|
+
localized: true
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
timestamps: false,
|
|
184
|
+
versions: false
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
localization: {
|
|
188
|
+
defaultLocale: 'en',
|
|
189
|
+
locales: [
|
|
190
|
+
'en',
|
|
191
|
+
'de'
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
const warn = vi.fn();
|
|
196
|
+
const adapter = createAdapter(config, warn);
|
|
197
|
+
buildRawSchema({
|
|
198
|
+
adapter,
|
|
199
|
+
setColumnID
|
|
200
|
+
});
|
|
201
|
+
expect(adapter.rawTables[`${longSlug}_locales`]).toBeDefined();
|
|
202
|
+
expect(()=>checkTruncatedIdentifiers({
|
|
203
|
+
adapter,
|
|
204
|
+
logWarnings: true
|
|
205
|
+
})).not.toThrow();
|
|
206
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
207
|
+
expect(warn.mock.calls[0][0]).toContain(`${longSlug}_locales`);
|
|
208
|
+
});
|
|
209
|
+
it('should not warn when the _locales companion table fits within 63 chars', async ()=>{
|
|
210
|
+
const config = sanitizeConfig({
|
|
211
|
+
collections: [
|
|
212
|
+
{
|
|
213
|
+
slug: 'short_localized',
|
|
214
|
+
fields: [
|
|
215
|
+
{
|
|
216
|
+
name: 'title',
|
|
217
|
+
type: 'text',
|
|
218
|
+
localized: true
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
timestamps: false,
|
|
222
|
+
versions: false
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
localization: {
|
|
226
|
+
defaultLocale: 'en',
|
|
227
|
+
locales: [
|
|
228
|
+
'en',
|
|
229
|
+
'de'
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
const warn = vi.fn();
|
|
234
|
+
const adapter = createAdapter(config, warn);
|
|
235
|
+
buildRawSchema({
|
|
236
|
+
adapter,
|
|
237
|
+
setColumnID
|
|
238
|
+
});
|
|
239
|
+
expect(adapter.rawTables.short_localized_locales).toBeDefined();
|
|
240
|
+
checkTruncatedIdentifiers({
|
|
241
|
+
adapter,
|
|
242
|
+
logWarnings: true
|
|
243
|
+
});
|
|
244
|
+
expect(warn).not.toHaveBeenCalled();
|
|
245
|
+
});
|
|
246
|
+
it('should warn about raw inline sub-table index and foreign key names that exceed 63 chars', async ()=>{
|
|
247
|
+
// Array sub-tables assign structural index/FK names inline (not via buildIndexName/
|
|
248
|
+
// buildForeignKeyName), so a long-but-valid array table name still overflows them.
|
|
249
|
+
const arrayFieldName = 'a'.repeat(58);
|
|
250
|
+
const config = sanitizeConfig({
|
|
251
|
+
collections: [
|
|
252
|
+
{
|
|
253
|
+
slug: 'p',
|
|
254
|
+
fields: [
|
|
255
|
+
{
|
|
256
|
+
name: arrayFieldName,
|
|
257
|
+
type: 'array',
|
|
258
|
+
fields: [
|
|
259
|
+
{
|
|
260
|
+
name: 'title',
|
|
261
|
+
type: 'text'
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
],
|
|
266
|
+
timestamps: false,
|
|
267
|
+
versions: false
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
const warn = vi.fn();
|
|
272
|
+
const adapter = createAdapter(config, warn);
|
|
273
|
+
buildRawSchema({
|
|
274
|
+
adapter,
|
|
275
|
+
setColumnID
|
|
276
|
+
});
|
|
277
|
+
const arrayTable = `p_${arrayFieldName}`;
|
|
278
|
+
checkTruncatedIdentifiers({
|
|
279
|
+
adapter,
|
|
280
|
+
logWarnings: true
|
|
281
|
+
});
|
|
282
|
+
expect(arrayTable.length).toBeLessThanOrEqual(63);
|
|
283
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
284
|
+
const message = warn.mock.calls[0][0];
|
|
285
|
+
expect(message).toContain(`${arrayTable}_order_idx`);
|
|
286
|
+
expect(message).toContain(`${arrayTable}_parent_id_fk`);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
//# sourceMappingURL=buildRawSchema.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema/buildRawSchema.spec.ts"],"sourcesContent":["import type { Block, Config, SanitizedConfig } from 'payload'\nimport { sanitizeConfig } from 'payload'\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { setColumnID } from '../postgres/schema/setColumnID.js'\nimport type { DrizzleAdapter } from '../types.js'\nimport { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js'\nimport { buildRawSchema } from './buildRawSchema.js'\n\nconst headlineBlock: Block = {\n slug: 'headline',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n}\n\nconst createContainerBlock = (slug: string): Block => ({\n slug,\n fields: [\n {\n name: 'content',\n type: 'blocks',\n blocks: ['headline'],\n },\n ],\n})\n\nconst createAdapter = (\n config: SanitizedConfig,\n warn: (...args: any[]) => void = () => {},\n): DrizzleAdapter =>\n ({\n blocksAsJSON: false,\n fieldConstraints: {},\n idType: 'serial',\n localesSuffix: '_locales',\n payload: {\n blocks: Object.fromEntries(config.blocks.map((block) => [block.slug, block])),\n collections: Object.fromEntries(\n config.collections.map((collection) => [\n collection.slug,\n {\n config: collection,\n customIDType: undefined,\n },\n ]),\n ),\n config,\n logger: { warn },\n },\n rawRelations: {},\n rawTables: {},\n tableNameMap: new Map(),\n versionsSuffix: '_versions',\n }) as unknown as DrizzleAdapter\n\ndescribe('buildRawSchema', () => {\n it('should create suffixed block tables for different schemas with the same slug', async () => {\n const config = sanitizeConfig({\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'primaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n },\n ],\n },\n {\n name: 'secondaryContent',\n type: 'blocks',\n localized: true,\n blocks: [\n {\n slug: 'content',\n fields: [\n {\n name: 'description',\n type: 'textarea',\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_content.columns.title).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns.description).toBeDefined()\n expect(adapter.rawTables.pages_blocks_content_2.columns._locale).toBeDefined()\n })\n\n it('should not create duplicate suffixed block tables for identical reused blocks under localized ancestors', async () => {\n const layoutBlocks = [createContainerBlock('container'), createContainerBlock('container50')]\n\n const config = sanitizeConfig({\n blocks: [headlineBlock],\n collections: [\n {\n slug: 'pages',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n {\n slug: 'posts',\n fields: [\n {\n name: 'layout',\n type: 'blocks',\n localized: true,\n blocks: layoutBlocks,\n },\n ],\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const adapter = createAdapter(config)\n\n buildRawSchema({\n adapter,\n setColumnID,\n })\n\n expect(adapter.rawTables.pages_blocks_headline).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.pages_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.pages_blocks_headline_2_locales).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline.columns._locale).toBeDefined()\n expect(adapter.rawTables.posts_blocks_headline_2).toBeUndefined()\n expect(adapter.rawTables.posts_blocks_headline_2_locales).toBeUndefined()\n })\n\n it('should warn when a localized field pushes the _locales companion table past 63 chars', async () => {\n // Base table name (61 chars) is under the limit, but `${base}_locales` (69) overflows it.\n const longSlug = `localized_collection_${'x'.repeat(40)}`\n\n const config = sanitizeConfig({\n collections: [\n {\n slug: longSlug,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const warn = vi.fn()\n const adapter = createAdapter(config, warn)\n\n buildRawSchema({ adapter, setColumnID })\n\n expect(adapter.rawTables[`${longSlug}_locales`]).toBeDefined()\n\n expect(() => checkTruncatedIdentifiers({ adapter, logWarnings: true })).not.toThrow()\n expect(warn).toHaveBeenCalledTimes(1)\n expect(warn.mock.calls[0][0]).toContain(`${longSlug}_locales`)\n })\n\n it('should not warn when the _locales companion table fits within 63 chars', async () => {\n const config = sanitizeConfig({\n collections: [\n {\n slug: 'short_localized',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n localization: {\n defaultLocale: 'en',\n locales: ['en', 'de'],\n },\n } as Config)\n\n const warn = vi.fn()\n const adapter = createAdapter(config, warn)\n\n buildRawSchema({ adapter, setColumnID })\n\n expect(adapter.rawTables.short_localized_locales).toBeDefined()\n\n checkTruncatedIdentifiers({ adapter, logWarnings: true })\n\n expect(warn).not.toHaveBeenCalled()\n })\n\n it('should warn about raw inline sub-table index and foreign key names that exceed 63 chars', async () => {\n // Array sub-tables assign structural index/FK names inline (not via buildIndexName/\n // buildForeignKeyName), so a long-but-valid array table name still overflows them.\n const arrayFieldName = 'a'.repeat(58)\n\n const config = sanitizeConfig({\n collections: [\n {\n slug: 'p',\n fields: [\n {\n name: arrayFieldName,\n type: 'array',\n fields: [{ name: 'title', type: 'text' }],\n },\n ],\n timestamps: false,\n versions: false,\n },\n ],\n } as Config)\n\n const warn = vi.fn()\n const adapter = createAdapter(config, warn)\n\n buildRawSchema({ adapter, setColumnID })\n\n const arrayTable = `p_${arrayFieldName}`\n\n checkTruncatedIdentifiers({ adapter, logWarnings: true })\n\n expect(arrayTable.length).toBeLessThanOrEqual(63)\n expect(warn).toHaveBeenCalledTimes(1)\n\n const message: string = warn.mock.calls[0][0]\n\n expect(message).toContain(`${arrayTable}_order_idx`)\n expect(message).toContain(`${arrayTable}_parent_id_fk`)\n })\n})\n"],"names":["sanitizeConfig","describe","expect","it","vi","setColumnID","checkTruncatedIdentifiers","buildRawSchema","headlineBlock","slug","fields","name","type","createContainerBlock","blocks","createAdapter","config","warn","blocksAsJSON","fieldConstraints","idType","localesSuffix","payload","Object","fromEntries","map","block","collections","collection","customIDType","undefined","logger","rawRelations","rawTables","tableNameMap","Map","versionsSuffix","localized","localization","defaultLocale","locales","adapter","pages_blocks_content","columns","title","toBeDefined","_locale","pages_blocks_content_2","description","layoutBlocks","pages_blocks_headline","pages_blocks_headline_2","toBeUndefined","pages_blocks_headline_2_locales","posts_blocks_headline","posts_blocks_headline_2","posts_blocks_headline_2_locales","longSlug","repeat","timestamps","versions","fn","logWarnings","not","toThrow","toHaveBeenCalledTimes","mock","calls","toContain","short_localized_locales","toHaveBeenCalled","arrayFieldName","arrayTable","length","toBeLessThanOrEqual","message"],"mappings":"AACA,SAASA,cAAc,QAAQ,UAAS;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,WAAW,QAAQ,oCAAmC;AAE/D,SAASC,yBAAyB,QAAQ,4CAA2C;AACrF,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,MA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({ adapter, blocksTableNameMap, columnPrefix, colu
|
|
|
269
269
|
throwValidationError,
|
|
270
270
|
versionsCustomName: versions
|
|
271
271
|
});
|
|
272
|
+
const isLocalizedBlockTable = Boolean(isFieldLocalized && adapter.payload.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
272
273
|
if (typeof blocksTableNameMap[blockTableName] === 'undefined') {
|
|
273
274
|
blocksTableNameMap[blockTableName] = 1;
|
|
274
275
|
} else if (!adapter.rawTables[blockTableName] || !validateExistingBlockIsIdentical({
|
|
275
276
|
block,
|
|
276
|
-
localized:
|
|
277
|
-
|
|
277
|
+
localized: isLocalizedBlockTable,
|
|
278
|
+
parentIsLocalized,
|
|
278
279
|
table: adapter.rawTables[blockTableName],
|
|
279
280
|
tableLocales: adapter.rawTables[`${blockTableName}${adapter.localesSuffix}`]
|
|
280
281
|
})) {
|
|
@@ -335,8 +336,7 @@ export const traverseFields = ({ adapter, blocksTableNameMap, columnPrefix, colu
|
|
|
335
336
|
onDelete: 'cascade'
|
|
336
337
|
}
|
|
337
338
|
};
|
|
338
|
-
|
|
339
|
-
if (isLocalized) {
|
|
339
|
+
if (isLocalizedBlockTable) {
|
|
340
340
|
baseColumns._locale = {
|
|
341
341
|
name: '_locale',
|
|
342
342
|
type: 'enum',
|
|
@@ -367,7 +367,7 @@ export const traverseFields = ({ adapter, blocksTableNameMap, columnPrefix, colu
|
|
|
367
367
|
setColumnID,
|
|
368
368
|
tableName: blockTableName,
|
|
369
369
|
versions,
|
|
370
|
-
withinLocalizedArrayOrBlock:
|
|
370
|
+
withinLocalizedArrayOrBlock: isLocalizedBlockTable
|
|
371
371
|
});
|
|
372
372
|
if (subHasLocalizedManyNumberField) {
|
|
373
373
|
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|