nextjs-cms 0.9.40 → 0.9.42
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/api/actions/pages.d.ts +4 -3
- package/dist/api/actions/pages.d.ts.map +1 -1
- package/dist/api/actions/pages.js +11 -4
- package/dist/api/trpc/root.d.ts +4 -3
- package/dist/api/trpc/root.d.ts.map +1 -1
- package/dist/api/trpc/routers/config.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.d.ts +1 -0
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/trpc/routers/navigation.d.ts +3 -3
- package/dist/api/trpc/server.d.ts +12 -9
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/cli/lib/update-sections.d.ts.map +1 -1
- package/dist/cli/lib/update-sections.js +43 -2
- package/dist/cli/utils/add-table-keys.d.ts.map +1 -1
- package/dist/cli/utils/add-table-keys.js +42 -6
- package/dist/cli/utils/schema-generator.d.ts +41 -0
- package/dist/cli/utils/schema-generator.d.ts.map +1 -1
- package/dist/cli/utils/schema-generator.js +41 -1
- package/dist/core/config/config-loader.d.ts +25 -6
- package/dist/core/config/config-loader.d.ts.map +1 -1
- package/dist/core/config/config-loader.js +9 -13
- package/dist/core/fields/photo.d.ts +86 -14
- package/dist/core/fields/photo.d.ts.map +1 -1
- package/dist/core/fields/photo.js +120 -23
- package/dist/core/fields/richText.d.ts +8 -8
- package/dist/core/fields/select.d.ts +1 -1
- package/dist/core/fields/select.d.ts.map +1 -1
- package/dist/core/fields/select.js +18 -2
- package/dist/core/fields/selectMultiple.d.ts.map +1 -1
- package/dist/core/fields/selectMultiple.js +9 -0
- package/dist/core/helpers/index.d.ts +2 -0
- package/dist/core/helpers/index.d.ts.map +1 -1
- package/dist/core/helpers/index.js +1 -0
- package/dist/core/helpers/watermark.d.ts +96 -0
- package/dist/core/helpers/watermark.d.ts.map +1 -0
- package/dist/core/helpers/watermark.js +61 -0
- package/dist/core/sections/category.d.ts +80 -44
- package/dist/core/sections/category.d.ts.map +1 -1
- package/dist/core/sections/hasItems.d.ts +140 -56
- package/dist/core/sections/hasItems.d.ts.map +1 -1
- package/dist/core/sections/section.d.ts +63 -26
- package/dist/core/sections/section.d.ts.map +1 -1
- package/dist/core/sections/section.js +2 -2
- package/dist/core/sections/simple.d.ts +44 -8
- package/dist/core/sections/simple.d.ts.map +1 -1
- package/dist/core/submit/gallery-order.d.ts +34 -0
- package/dist/core/submit/gallery-order.d.ts.map +1 -0
- package/dist/core/submit/gallery-order.js +50 -0
- package/dist/core/submit/submit.d.ts +8 -0
- package/dist/core/submit/submit.d.ts.map +1 -1
- package/dist/core/submit/submit.js +63 -3
- package/dist/core/types/index.d.ts +1 -0
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/translations/client.d.ts +4 -4
- package/dist/translations/server.d.ts +4 -4
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/api/trpc/server.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAUjE,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEvF,MAAM,WAAW,uBAAuB,CAAC,KAAK,SAAS,YAAY;IAC/D,OAAO,CAAC,EAAE,0BAA0B,CAAC,KAAK,CAAC,CAAA;IAC3C,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;CACjE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,KAAK,SAAS,YAAY,GAAG,EAAE,EAAE,IAAI,GAAE,uBAA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AAC;EAqFvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/update-sections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/update-sections.ts"],"names":[],"mappings":"AA+pFA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAoBrD"}
|
|
@@ -11,7 +11,7 @@ import { is } from '../../core/helpers/index.js';
|
|
|
11
11
|
import { db } from '../../db/client.js';
|
|
12
12
|
import { NextJsCmsTablesTable } from '../../db/schema.js';
|
|
13
13
|
import { addTableKeys } from '../utils/add-table-keys.js';
|
|
14
|
-
import { generateDrizzleSchema, generateLocalesTableSchema, resolveCaseStyleFns } from '../utils/schema-generator.js';
|
|
14
|
+
import { generateDrizzleSchema, generateLocalesTableSchema, getLocalizedLocalesConstraints, resolveCaseStyleFns, } from '../utils/schema-generator.js';
|
|
15
15
|
/**
|
|
16
16
|
* Returns all DB column names a field owns.
|
|
17
17
|
* Most fields own a single column (field.name), but rarely some fields own two,
|
|
@@ -1426,6 +1426,19 @@ const main = async (spinnerObject) => {
|
|
|
1426
1426
|
required: true,
|
|
1427
1427
|
order: 0,
|
|
1428
1428
|
});
|
|
1429
|
+
/**
|
|
1430
|
+
* Gallery photos are orderable. No minValue/maxValue is declared on
|
|
1431
|
+
* purpose: generateFieldSQL picks the smallest integer type that fits
|
|
1432
|
+
* the declared bounds, so `minValue: 0` would yield TINYINT UNSIGNED
|
|
1433
|
+
* and cap galleries at 255 photos. Unbounded resolves to INT(11).
|
|
1434
|
+
*/
|
|
1435
|
+
const sortOrderField = numberField({
|
|
1436
|
+
name: 'sort_order',
|
|
1437
|
+
label: 'Sort Order',
|
|
1438
|
+
required: true,
|
|
1439
|
+
defaultValue: 0,
|
|
1440
|
+
order: 0,
|
|
1441
|
+
});
|
|
1429
1442
|
const localeFieldConfig = isLocalizedGallery ? buildLocaleFieldConfig() : undefined;
|
|
1430
1443
|
const galleryFields = [
|
|
1431
1444
|
galleryRefField.build(),
|
|
@@ -1436,6 +1449,7 @@ const main = async (spinnerObject) => {
|
|
|
1436
1449
|
required: false,
|
|
1437
1450
|
order: 0,
|
|
1438
1451
|
}).build(),
|
|
1452
|
+
sortOrderField.build(),
|
|
1439
1453
|
...(localeFieldConfig ? [localeFieldConfig.build()] : []),
|
|
1440
1454
|
];
|
|
1441
1455
|
const galleryPrimaryKey = localeFieldConfig ? [photoField, localeFieldConfig] : [photoField];
|
|
@@ -1473,6 +1487,11 @@ const main = async (spinnerObject) => {
|
|
|
1473
1487
|
type: 'textarea',
|
|
1474
1488
|
required: false,
|
|
1475
1489
|
},
|
|
1490
|
+
{
|
|
1491
|
+
name: 'sort_order',
|
|
1492
|
+
type: 'number',
|
|
1493
|
+
required: true,
|
|
1494
|
+
},
|
|
1476
1495
|
...(isLocalizedGallery
|
|
1477
1496
|
? [
|
|
1478
1497
|
{
|
|
@@ -1535,6 +1554,23 @@ const main = async (spinnerObject) => {
|
|
|
1535
1554
|
order: 0,
|
|
1536
1555
|
});
|
|
1537
1556
|
const localizedFieldInstances = s.fields.filter((f) => f.localized);
|
|
1557
|
+
/**
|
|
1558
|
+
* Propagate the section's own `unique` / `index` / `fulltext` constraints to the
|
|
1559
|
+
* `_locales` table, but only those whose columns are all localized (mirrors
|
|
1560
|
+
* `LocaleSubmit.checkUniqueConstraint`). Unique constraints get `locale` appended so
|
|
1561
|
+
* uniqueness is enforced per locale; indexes/fulltext keep their columns unchanged.
|
|
1562
|
+
*/
|
|
1563
|
+
const localizedFieldNames = new Set(localizedFieldInstances.map((f) => f.name));
|
|
1564
|
+
const localizedConstraints = getLocalizedLocalesConstraints({
|
|
1565
|
+
localesTableName,
|
|
1566
|
+
localizedFieldNames,
|
|
1567
|
+
unique: s.db.unique,
|
|
1568
|
+
index: s.db.index,
|
|
1569
|
+
fulltext: s.db.fulltext,
|
|
1570
|
+
});
|
|
1571
|
+
const localizedUniqueColumns = localizedConstraints.unique;
|
|
1572
|
+
const localizedIndexColumns = localizedConstraints.index;
|
|
1573
|
+
const localizedFulltextColumns = localizedConstraints.fulltext;
|
|
1538
1574
|
desiredTables.push({
|
|
1539
1575
|
name: localesTableName,
|
|
1540
1576
|
fields: [
|
|
@@ -1547,7 +1583,9 @@ const main = async (spinnerObject) => {
|
|
|
1547
1583
|
sectionType: 'locales',
|
|
1548
1584
|
identifier: idFieldConfig,
|
|
1549
1585
|
primaryKey: [idFieldConfig],
|
|
1550
|
-
unique: [{ columns: [parentIdFieldConfig, localeFieldConfig] }],
|
|
1586
|
+
unique: [{ columns: [parentIdFieldConfig, localeFieldConfig] }, ...localizedUniqueColumns],
|
|
1587
|
+
index: localizedIndexColumns.length > 0 ? localizedIndexColumns : undefined,
|
|
1588
|
+
fulltext: localizedFulltextColumns.length > 0 ? localizedFulltextColumns : undefined,
|
|
1551
1589
|
});
|
|
1552
1590
|
const localizedFieldConfigs = s.fieldConfigs.filter((f) => 'localized' in f && f.localized === true);
|
|
1553
1591
|
const localesSchema = generateLocalesTableSchema({
|
|
@@ -1555,6 +1593,9 @@ const main = async (spinnerObject) => {
|
|
|
1555
1593
|
parentIdentifier: s.db.identifier,
|
|
1556
1594
|
localizedFields: localizedFieldConfigs,
|
|
1557
1595
|
caseStyleFns,
|
|
1596
|
+
localizedUnique: localizedConstraints.unique,
|
|
1597
|
+
localizedIndex: localizedConstraints.index,
|
|
1598
|
+
localizedFulltext: localizedConstraints.fulltext,
|
|
1558
1599
|
});
|
|
1559
1600
|
drizzleTableSchemas.push(localesSchema.schema);
|
|
1560
1601
|
localesSchema.drizzleImports.forEach((type) => drizzleImports.add(type));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-table-keys.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/add-table-keys.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add-table-keys.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/add-table-keys.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,wBAAsB,YAAY,CAC9B,KAAK,EAAE;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,WAAW,EAAE,CAAA;IACzB,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,EAAE,CAAA;IACnD,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,EAAE,CAAA;IACpD,QAAQ,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,EAAE,CAAA;CACzD,EACD,YAAY,CAAC,EAAE;IACX,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IACjD,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IAChD,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;CACtD,mBA6SJ"}
|
|
@@ -88,7 +88,13 @@ export async function addTableKeys(table, existingKeys) {
|
|
|
88
88
|
*/
|
|
89
89
|
if (!matchingUnique) {
|
|
90
90
|
console.log(chalk.gray(` - Adding unique key with columns [${requestedUnique.columns.map((col) => col.name).join(', ')}] to '${table.name}'`));
|
|
91
|
-
|
|
91
|
+
try {
|
|
92
|
+
await db.execute(`ALTER TABLE \`${table.name}\` ADD UNIQUE ${requestedUnique.name ?? ''}(${uniqueColumns})`);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
sqlErrors++;
|
|
96
|
+
console.error(chalk.red(` - Error adding unique key [${requestedUnique.columns.map((col) => col.name).join(', ')}] to '${table.name}':`, error));
|
|
97
|
+
}
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
/**
|
|
@@ -100,7 +106,13 @@ export async function addTableKeys(table, existingKeys) {
|
|
|
100
106
|
unique.columns.every((col) => existingUnique.columns.includes(col.name)));
|
|
101
107
|
})) {
|
|
102
108
|
console.log(chalk.gray(` - Dropping unique key with columns [${existingUnique.columns.join(', ')}] from '${table.name}'`));
|
|
103
|
-
|
|
109
|
+
try {
|
|
110
|
+
await db.execute(`ALTER TABLE \`${table.name}\` DROP INDEX \`${existingUnique.name}\``);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
sqlErrors++;
|
|
114
|
+
console.error(chalk.red(` - Error dropping unique key '${existingUnique.name}' from '${table.name}':`, error));
|
|
115
|
+
}
|
|
104
116
|
}
|
|
105
117
|
}
|
|
106
118
|
}
|
|
@@ -118,7 +130,13 @@ export async function addTableKeys(table, existingKeys) {
|
|
|
118
130
|
if (!matchingIndex) {
|
|
119
131
|
// Add index
|
|
120
132
|
console.log(chalk.gray(` - Adding index with columns [${index.columns.map((col) => col.name).join(', ')}] to '${table.name}'`));
|
|
121
|
-
|
|
133
|
+
try {
|
|
134
|
+
await db.execute(`ALTER TABLE \`${table.name}\` ADD INDEX ${index.name ?? ''}(${indexColumns})`);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
sqlErrors++;
|
|
138
|
+
console.error(chalk.red(` - Error adding index [${index.columns.map((col) => col.name).join(', ')}] to '${table.name}':`, error));
|
|
139
|
+
}
|
|
122
140
|
}
|
|
123
141
|
}
|
|
124
142
|
/**
|
|
@@ -130,7 +148,13 @@ export async function addTableKeys(table, existingKeys) {
|
|
|
130
148
|
index.columns.every((col) => existingIndex.columns.includes(col.name)));
|
|
131
149
|
})) {
|
|
132
150
|
console.log(chalk.gray(` - Dropping index with columns [${existingIndex.columns.join(', ')}] from '${table.name}'`));
|
|
133
|
-
|
|
151
|
+
try {
|
|
152
|
+
await db.execute(`ALTER TABLE \`${table.name}\` DROP INDEX \`${existingIndex.name}\``);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
sqlErrors++;
|
|
156
|
+
console.error(chalk.red(` - Error dropping index '${existingIndex.name}' from '${table.name}':`, error));
|
|
157
|
+
}
|
|
134
158
|
}
|
|
135
159
|
}
|
|
136
160
|
}
|
|
@@ -151,7 +175,13 @@ export async function addTableKeys(table, existingKeys) {
|
|
|
151
175
|
if (!matchingFulltext) {
|
|
152
176
|
// Add fulltext index
|
|
153
177
|
console.log(chalk.gray(` - Adding fulltext index with columns [${requestedFullTextIndex.columns.map((col) => col.name).join(', ')}] to '${table.name}'`));
|
|
154
|
-
|
|
178
|
+
try {
|
|
179
|
+
await db.execute(`ALTER TABLE \`${table.name}\` ADD FULLTEXT ${requestedFullTextIndex.name ?? ''}(${fulltextColumns})`);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
sqlErrors++;
|
|
183
|
+
console.error(chalk.red(` - Error adding fulltext index [${requestedFullTextIndex.columns.map((col) => col.name).join(', ')}] to '${table.name}':`, error));
|
|
184
|
+
}
|
|
155
185
|
}
|
|
156
186
|
}
|
|
157
187
|
/**
|
|
@@ -163,7 +193,13 @@ export async function addTableKeys(table, existingKeys) {
|
|
|
163
193
|
fulltext.columns.every((col) => existingFulltext.columns.includes(col.name)));
|
|
164
194
|
})) {
|
|
165
195
|
console.log(chalk.gray(` - Dropping fulltext index with columns [${existingFulltext.columns.join(', ')}] from '${table.name}'`));
|
|
166
|
-
|
|
196
|
+
try {
|
|
197
|
+
await db.execute(`ALTER TABLE \`${table.name}\` DROP INDEX \`${existingFulltext.name}\``);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
sqlErrors++;
|
|
201
|
+
console.error(chalk.red(` - Error dropping fulltext index '${existingFulltext.name}' from '${table.name}':`, error));
|
|
202
|
+
}
|
|
167
203
|
}
|
|
168
204
|
}
|
|
169
205
|
}
|
|
@@ -41,6 +41,42 @@ export declare function generateDrizzleSchema(table: {
|
|
|
41
41
|
schema: string;
|
|
42
42
|
drizzleImports: string[];
|
|
43
43
|
};
|
|
44
|
+
/** A constraint definition referencing columns by name (index / unique / fulltext). */
|
|
45
|
+
export type ConstraintDefinition = {
|
|
46
|
+
columns: {
|
|
47
|
+
name: string;
|
|
48
|
+
}[];
|
|
49
|
+
name?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Computes the `unique` / `index` / `fulltext` constraints a section's `_locales`
|
|
53
|
+
* table should carry, derived from the section's own constraints.
|
|
54
|
+
*
|
|
55
|
+
* Only constraints whose columns are ALL localized fields apply — a constraint that
|
|
56
|
+
* touches a non-localized column belongs to the base table (that column does not
|
|
57
|
+
* exist in the `_locales` table). This mirrors `LocaleSubmit.checkUniqueConstraint`,
|
|
58
|
+
* which only enforces constraints whose columns are all localized.
|
|
59
|
+
*
|
|
60
|
+
* Translation rules:
|
|
61
|
+
* - unique → append `locale` so uniqueness is scoped per locale (matches the
|
|
62
|
+
* app-level check that adds `locale = <current locale>`).
|
|
63
|
+
* - index → columns unchanged.
|
|
64
|
+
* - fulltext → columns unchanged.
|
|
65
|
+
*
|
|
66
|
+
* Names are always `_locales`-scoped so they don't collide with the base table's
|
|
67
|
+
* constraint names in the generated schema.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getLocalizedLocalesConstraints(params: {
|
|
70
|
+
localesTableName: string;
|
|
71
|
+
localizedFieldNames: Set<string>;
|
|
72
|
+
unique?: ConstraintDefinition[];
|
|
73
|
+
index?: ConstraintDefinition[];
|
|
74
|
+
fulltext?: ConstraintDefinition[];
|
|
75
|
+
}): {
|
|
76
|
+
unique: ConstraintDefinition[];
|
|
77
|
+
index: ConstraintDefinition[];
|
|
78
|
+
fulltext: ConstraintDefinition[];
|
|
79
|
+
};
|
|
44
80
|
/**
|
|
45
81
|
* Generates a Drizzle schema for a `_locales` table that stores per-locale
|
|
46
82
|
* translations of fields marked `localized: true`.
|
|
@@ -51,12 +87,17 @@ export declare function generateDrizzleSchema(table: {
|
|
|
51
87
|
* - `locale` – locale code (e.g. "en", "ar")
|
|
52
88
|
* - one column per localized field
|
|
53
89
|
* - a unique constraint on `(parent_id, locale)`
|
|
90
|
+
* - any localized `unique` / `index` / `fulltext` constraints derived from the
|
|
91
|
+
* section (see `getLocalizedLocalesConstraints`)
|
|
54
92
|
*/
|
|
55
93
|
export declare function generateLocalesTableSchema(params: {
|
|
56
94
|
parentTableName: string;
|
|
57
95
|
parentIdentifier: FieldConfig;
|
|
58
96
|
localizedFields: FieldConfig[];
|
|
59
97
|
caseStyleFns: CaseStyleFns;
|
|
98
|
+
localizedUnique?: ConstraintDefinition[];
|
|
99
|
+
localizedIndex?: ConstraintDefinition[];
|
|
100
|
+
localizedFulltext?: ConstraintDefinition[];
|
|
60
101
|
}): {
|
|
61
102
|
schema: string;
|
|
62
103
|
drizzleImports: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-generator.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/schema-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAoB7D,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACzC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CAC7C;AAED,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAA;IAChD,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAA;CACpD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CA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,CAAA;IAC9B,QAAQ,CAAC,EAAE,oBAAoB,EAAE,CAAA;CACpC,GAAG;IACA,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,KAAK,EAAE,oBAAoB,EAAE,CAAA;IAC7B,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CACnC,CAwBA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IAC/C,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,WAAW,CAAA;IAC7B,eAAe,EAAE,WAAW,EAAE,CAAA;IAC9B,YAAY,EAAE,YAAY,CAAA;IAC1B,eAAe,CAAC,EAAE,oBAAoB,EAAE,CAAA;IACxC,cAAc,CAAC,EAAE,oBAAoB,EAAE,CAAA;IACvC,iBAAiB,CAAC,EAAE,oBAAoB,EAAE,CAAA;CAC7C,GAAG;IACA,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,EAAE,CAAA;CAC3B,CAiDA"}
|
|
@@ -239,6 +239,42 @@ export function generateDrizzleSchema(table, caseStyleFns) {
|
|
|
239
239
|
drizzleImports,
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Computes the `unique` / `index` / `fulltext` constraints a section's `_locales`
|
|
244
|
+
* table should carry, derived from the section's own constraints.
|
|
245
|
+
*
|
|
246
|
+
* Only constraints whose columns are ALL localized fields apply — a constraint that
|
|
247
|
+
* touches a non-localized column belongs to the base table (that column does not
|
|
248
|
+
* exist in the `_locales` table). This mirrors `LocaleSubmit.checkUniqueConstraint`,
|
|
249
|
+
* which only enforces constraints whose columns are all localized.
|
|
250
|
+
*
|
|
251
|
+
* Translation rules:
|
|
252
|
+
* - unique → append `locale` so uniqueness is scoped per locale (matches the
|
|
253
|
+
* app-level check that adds `locale = <current locale>`).
|
|
254
|
+
* - index → columns unchanged.
|
|
255
|
+
* - fulltext → columns unchanged.
|
|
256
|
+
*
|
|
257
|
+
* Names are always `_locales`-scoped so they don't collide with the base table's
|
|
258
|
+
* constraint names in the generated schema.
|
|
259
|
+
*/
|
|
260
|
+
export function getLocalizedLocalesConstraints(params) {
|
|
261
|
+
const { localesTableName, localizedFieldNames } = params;
|
|
262
|
+
const allLocalized = (constraint) => constraint.columns.every((column) => localizedFieldNames.has(column.name));
|
|
263
|
+
const columnSlug = (constraint) => constraint.columns.map((column) => column.name).join('_');
|
|
264
|
+
const unique = (params.unique ?? []).filter(allLocalized).map((constraint) => ({
|
|
265
|
+
columns: [...constraint.columns, { name: 'locale' }],
|
|
266
|
+
name: `${localesTableName}_${columnSlug(constraint)}_locale_unique`,
|
|
267
|
+
}));
|
|
268
|
+
const index = (params.index ?? []).filter(allLocalized).map((constraint) => ({
|
|
269
|
+
columns: constraint.columns,
|
|
270
|
+
name: `${localesTableName}_${columnSlug(constraint)}_index`,
|
|
271
|
+
}));
|
|
272
|
+
const fulltext = (params.fulltext ?? []).filter(allLocalized).map((constraint) => ({
|
|
273
|
+
columns: constraint.columns,
|
|
274
|
+
name: `${localesTableName}_${columnSlug(constraint)}_fulltext`,
|
|
275
|
+
}));
|
|
276
|
+
return { unique, index, fulltext };
|
|
277
|
+
}
|
|
242
278
|
/**
|
|
243
279
|
* Generates a Drizzle schema for a `_locales` table that stores per-locale
|
|
244
280
|
* translations of fields marked `localized: true`.
|
|
@@ -249,6 +285,8 @@ export function generateDrizzleSchema(table, caseStyleFns) {
|
|
|
249
285
|
* - `locale` – locale code (e.g. "en", "ar")
|
|
250
286
|
* - one column per localized field
|
|
251
287
|
* - a unique constraint on `(parent_id, locale)`
|
|
288
|
+
* - any localized `unique` / `index` / `fulltext` constraints derived from the
|
|
289
|
+
* section (see `getLocalizedLocalesConstraints`)
|
|
252
290
|
*/
|
|
253
291
|
export function generateLocalesTableSchema(params) {
|
|
254
292
|
const tableName = `${params.parentTableName}_locales`;
|
|
@@ -286,6 +324,8 @@ export function generateLocalesTableSchema(params) {
|
|
|
286
324
|
name: tableName,
|
|
287
325
|
fields: allFields,
|
|
288
326
|
identifier: idField,
|
|
289
|
-
unique: [{ columns: [{ name: 'parent_id' }, { name: 'locale' }] }],
|
|
327
|
+
unique: [{ columns: [{ name: 'parent_id' }, { name: 'locale' }] }, ...(params.localizedUnique ?? [])],
|
|
328
|
+
index: params.localizedIndex,
|
|
329
|
+
fulltext: params.localizedFulltext,
|
|
290
330
|
}, params.caseStyleFns);
|
|
291
331
|
}
|