nextjs-cms 0.7.9 → 0.7.11
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/cli/lib/update-sections.d.ts.map +1 -1
- package/dist/cli/lib/update-sections.js +45 -11
- package/dist/cli/utils/schema-generator.d.ts +20 -4
- package/dist/cli/utils/schema-generator.d.ts.map +1 -1
- package/dist/cli/utils/schema-generator.js +27 -24
- package/dist/core/factories/FieldFactory.d.ts.map +1 -1
- package/dist/core/factories/FieldFactory.js +40 -15
- package/dist/core/submit/ItemEditSubmit.d.ts.map +1 -1
- package/dist/core/submit/ItemEditSubmit.js +33 -8
- package/package.json +3 -3
|
@@ -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":"AAolCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAoBrD"}
|
|
@@ -11,7 +11,7 @@ import { FileField } from '../../core/fields/index.js';
|
|
|
11
11
|
import chalk from 'chalk';
|
|
12
12
|
import { intro, select, spinner, log } from '@clack/prompts';
|
|
13
13
|
import { MysqlTableChecker } from '../../core/db/index.js';
|
|
14
|
-
import { generateDrizzleSchema } from '../utils/schema-generator.js';
|
|
14
|
+
import { generateDrizzleSchema, resolveCaseStyleFns } from '../utils/schema-generator.js';
|
|
15
15
|
import { addTableKeys } from '../utils/add-table-keys.js';
|
|
16
16
|
function generateFieldSQL(input) {
|
|
17
17
|
let fieldSQL = `\`${input.name}\` `;
|
|
@@ -525,8 +525,9 @@ const main = async (s) => {
|
|
|
525
525
|
else {
|
|
526
526
|
console.log(chalk.yellow(`Schema generation is disabled. Skipping Drizzle schema generation.`));
|
|
527
527
|
}
|
|
528
|
+
const caseStyleFns = resolveCaseStyleFns(cmsConfig.schemaGeneration.drizzle.naming);
|
|
528
529
|
const drizzleTableSchemas = [];
|
|
529
|
-
const
|
|
530
|
+
const drizzleImports = new Set(['mysqlTable']);
|
|
530
531
|
let sections = [];
|
|
531
532
|
const desiredTables = [];
|
|
532
533
|
let existingTables = [];
|
|
@@ -556,17 +557,13 @@ const main = async (s) => {
|
|
|
556
557
|
/**
|
|
557
558
|
* Generate the Drizzle schema for the table
|
|
558
559
|
*/
|
|
559
|
-
const drizzleSchema =
|
|
560
|
+
const drizzleSchema = generateDrizzleSchema({
|
|
560
561
|
name: s.db.table,
|
|
561
562
|
fields: s.fieldConfigs,
|
|
562
563
|
identifier: s.db.identifier,
|
|
563
|
-
});
|
|
564
|
+
}, caseStyleFns);
|
|
564
565
|
drizzleTableSchemas.push(drizzleSchema.schema);
|
|
565
|
-
drizzleSchema.
|
|
566
|
-
if (!drizzleColumnTypes.includes(type)) {
|
|
567
|
-
drizzleColumnTypes.push(type);
|
|
568
|
-
}
|
|
569
|
-
});
|
|
566
|
+
drizzleSchema.drizzleImports.forEach((type) => drizzleImports.add(type));
|
|
570
567
|
desiredTables.push({
|
|
571
568
|
name: s.db.table,
|
|
572
569
|
fields: s.fields,
|
|
@@ -614,6 +611,17 @@ const main = async (s) => {
|
|
|
614
611
|
*/
|
|
615
612
|
primaryKey: [referenceIdFieldConfig, selectIdFieldConfig],
|
|
616
613
|
});
|
|
614
|
+
const destDbFields = [
|
|
615
|
+
{ name: field.destinationDb.itemIdentifier, type: 'text', required: true },
|
|
616
|
+
{ name: field.destinationDb.selectIdentifier, type: 'text', required: true },
|
|
617
|
+
];
|
|
618
|
+
const destDbSchema = generateDrizzleSchema({
|
|
619
|
+
name: field.destinationDb.table,
|
|
620
|
+
fields: destDbFields,
|
|
621
|
+
compositePrimaryKey: destDbFields,
|
|
622
|
+
}, caseStyleFns);
|
|
623
|
+
drizzleTableSchemas.push(destDbSchema.schema);
|
|
624
|
+
destDbSchema.drizzleImports.forEach((type) => drizzleImports.add(type));
|
|
617
625
|
}
|
|
618
626
|
}
|
|
619
627
|
/**
|
|
@@ -654,6 +662,32 @@ const main = async (s) => {
|
|
|
654
662
|
identifier: photoField,
|
|
655
663
|
primaryKey: [photoField],
|
|
656
664
|
});
|
|
665
|
+
const gallerySchema = generateDrizzleSchema({
|
|
666
|
+
name: gallery.db.tableName,
|
|
667
|
+
fields: [
|
|
668
|
+
{
|
|
669
|
+
name: gallery.db.referenceIdentifierField || 'reference_id',
|
|
670
|
+
type: 'text',
|
|
671
|
+
required: true,
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
name: gallery.db.photoNameField || 'photo',
|
|
675
|
+
type: 'text',
|
|
676
|
+
required: true,
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
name: gallery.db.metaField || 'meta',
|
|
680
|
+
type: 'textarea',
|
|
681
|
+
required: false,
|
|
682
|
+
},
|
|
683
|
+
],
|
|
684
|
+
identifier: {
|
|
685
|
+
name: gallery.db.photoNameField || 'photo',
|
|
686
|
+
type: 'text',
|
|
687
|
+
},
|
|
688
|
+
}, caseStyleFns);
|
|
689
|
+
drizzleTableSchemas.push(gallerySchema.schema);
|
|
690
|
+
gallerySchema.drizzleImports.forEach((type) => drizzleImports.add(type));
|
|
657
691
|
}
|
|
658
692
|
}
|
|
659
693
|
/**
|
|
@@ -667,9 +701,9 @@ const main = async (s) => {
|
|
|
667
701
|
fs.mkdirSync(schemaOutDir, { recursive: true });
|
|
668
702
|
}
|
|
669
703
|
/**
|
|
670
|
-
* Append the Drizzle
|
|
704
|
+
* Append the Drizzle imports to the schema file
|
|
671
705
|
*/
|
|
672
|
-
fs.appendFileSync(schemaFilePath, 'import {' +
|
|
706
|
+
fs.appendFileSync(schemaFilePath, 'import {' + [...drizzleImports].join(',') + "} from 'drizzle-orm/mysql-core'\n\n");
|
|
673
707
|
/**
|
|
674
708
|
* Append the Drizzle table schemas to the schema file
|
|
675
709
|
*/
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import type { FieldConfig } from '../../core/fields/index.js';
|
|
2
|
+
export interface CaseStyleFns {
|
|
3
|
+
tableCaseStyleFn: (str: string) => string;
|
|
4
|
+
columnCaseStyleFn: (str: string) => string;
|
|
5
|
+
}
|
|
6
|
+
export interface NamingConfig {
|
|
7
|
+
tables: 'camelCase' | 'snakeCase' | 'pascalCase';
|
|
8
|
+
columns: 'camelCase' | 'snakeCase' | 'pascalCase';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves case-style functions from the naming configuration.
|
|
12
|
+
* Centralises the switch logic that was previously duplicated across generators.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveCaseStyleFns(naming: NamingConfig): CaseStyleFns;
|
|
2
15
|
export declare function generateDrizzleSchema(table: {
|
|
3
16
|
name: string;
|
|
4
17
|
fields: FieldConfig[];
|
|
5
|
-
identifier
|
|
6
|
-
|
|
18
|
+
identifier?: FieldConfig;
|
|
19
|
+
compositePrimaryKey?: {
|
|
20
|
+
name: string;
|
|
21
|
+
}[];
|
|
22
|
+
}, caseStyleFns: CaseStyleFns): {
|
|
7
23
|
schema: string;
|
|
8
|
-
|
|
9
|
-
}
|
|
24
|
+
drizzleImports: string[];
|
|
25
|
+
};
|
|
10
26
|
//# sourceMappingURL=schema-generator.d.ts.map
|
|
@@ -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,
|
|
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,CA8BtE;AAED,wBAAgB,qBAAqB,CACjC,KAAK,EAAE;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,UAAU,CAAC,EAAE,WAAW,CAAA;IACxB,mBAAmB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC3C,EACD,YAAY,EAAE,YAAY,GAC3B;IACC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,EAAE,CAAA;CAC3B,CAwIA"}
|
|
@@ -13,12 +13,13 @@ function toSnakeCase(str) {
|
|
|
13
13
|
.replace(/^_/, '') // Remove leading underscore if any
|
|
14
14
|
.toLowerCase();
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Resolves case-style functions from the naming configuration.
|
|
18
|
+
* Centralises the switch logic that was previously duplicated across generators.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveCaseStyleFns(naming) {
|
|
18
21
|
let tableCaseStyleFn;
|
|
19
|
-
|
|
20
|
-
const lzConfig = await getCMSConfig();
|
|
21
|
-
switch (lzConfig.schemaGeneration.drizzle.naming.tables) {
|
|
22
|
+
switch (naming.tables) {
|
|
22
23
|
case 'snakeCase':
|
|
23
24
|
tableCaseStyleFn = toSnakeCase;
|
|
24
25
|
break;
|
|
@@ -30,7 +31,8 @@ export async function generateDrizzleSchema(table) {
|
|
|
30
31
|
tableCaseStyleFn = toPascalCase;
|
|
31
32
|
break;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
let columnCaseStyleFn;
|
|
35
|
+
switch (naming.columns) {
|
|
34
36
|
case 'snakeCase':
|
|
35
37
|
columnCaseStyleFn = toSnakeCase;
|
|
36
38
|
break;
|
|
@@ -42,12 +44,11 @@ export async function generateDrizzleSchema(table) {
|
|
|
42
44
|
columnCaseStyleFn = toCamelCase;
|
|
43
45
|
break;
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const drizzleColumnTypes = [];
|
|
47
|
+
return { tableCaseStyleFn, columnCaseStyleFn };
|
|
48
|
+
}
|
|
49
|
+
export function generateDrizzleSchema(table, caseStyleFns) {
|
|
50
|
+
const { tableCaseStyleFn, columnCaseStyleFn } = caseStyleFns;
|
|
51
|
+
const drizzleImports = [];
|
|
51
52
|
let schema = '';
|
|
52
53
|
const schemaName = tableCaseStyleFn(`${table.name}_table`);
|
|
53
54
|
schema += `export const ${schemaName} = mysqlTable('${table.name}', {\n`;
|
|
@@ -58,7 +59,6 @@ export async function generateDrizzleSchema(table) {
|
|
|
58
59
|
continue;
|
|
59
60
|
let columnType;
|
|
60
61
|
let drizzleColumnType;
|
|
61
|
-
// let columnOptions = ''
|
|
62
62
|
switch (input.type) {
|
|
63
63
|
case 'text':
|
|
64
64
|
columnType = `varchar('${input.name}', { length: ${input.maxLength ?? 255} })`;
|
|
@@ -145,27 +145,30 @@ export async function generateDrizzleSchema(table) {
|
|
|
145
145
|
if (input.required) {
|
|
146
146
|
columnType += `.notNull()`;
|
|
147
147
|
}
|
|
148
|
-
if (input === table.identifier) {
|
|
148
|
+
if (table.identifier && input === table.identifier) {
|
|
149
149
|
columnType += `.primaryKey()`;
|
|
150
150
|
}
|
|
151
151
|
/*if (input.type === 'date') {
|
|
152
152
|
columnType += `.defaultNow()`
|
|
153
153
|
}*/
|
|
154
154
|
schema += ` ${columnCaseStyleFn(input.name)}: ${columnType},\n`;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*/
|
|
158
|
-
if (drizzleColumnType && !drizzleColumnTypes.includes(drizzleColumnType)) {
|
|
159
|
-
/**
|
|
160
|
-
* If it's not, add it to the array
|
|
161
|
-
*/
|
|
162
|
-
drizzleColumnTypes.push(drizzleColumnType);
|
|
155
|
+
if (drizzleColumnType && !drizzleImports.includes(drizzleColumnType)) {
|
|
156
|
+
drizzleImports.push(drizzleColumnType);
|
|
163
157
|
}
|
|
164
158
|
}
|
|
165
159
|
schema = schema.slice(0, -2); // Remove the last comma and newline
|
|
166
|
-
|
|
160
|
+
if (table.compositePrimaryKey && table.compositePrimaryKey.length > 1) {
|
|
161
|
+
const pkCols = table.compositePrimaryKey.map((f) => `table.${columnCaseStyleFn(f.name)}`).join(', ');
|
|
162
|
+
schema += `\n}, (table) => [primaryKey({ columns: [${pkCols}] })]);\n\n`;
|
|
163
|
+
if (!drizzleImports.includes('primaryKey')) {
|
|
164
|
+
drizzleImports.push('primaryKey');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
schema += `\n});\n\n`;
|
|
169
|
+
}
|
|
167
170
|
return {
|
|
168
171
|
schema: schema,
|
|
169
|
-
|
|
172
|
+
drizzleImports,
|
|
170
173
|
};
|
|
171
174
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldFactory.d.ts","sourceRoot":"","sources":["../../../src/core/factories/FieldFactory.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAGnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAQlD,KAAK,eAAe,GACd;IACI,IAAI,EAAE,KAAK,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,KAAK,CAAA;CACjB,GACD;IACI,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAA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yC;IACvD,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,aAAa,CAAa;IAClC,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAAA;IAC9B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAA;IAC7B,OAAO,CAAC,YAAY,CAA4B;IAGhD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAY;IAEjD;;OAEG;gBACS,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,eAAe;IASnE;;OAEG;IACU,UAAU;YAUT,aAAa;YASb,qBAAqB;IAuHnC;;;;OAIG;YACW,qBAAqB;IAoDnC;;;;OAIG;YACW,cAAc;IAuB5B;;;;;OAKG;YACW,YAAY;IAiB1B,OAAO,CAAC,kBAAkB;IAa1B;;OAEG;IACU,cAAc;IAqB3B;;;OAGG;IACH,OAAO,CAAC,UAAU;IA4ElB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;;OAGG;IACU,gBAAgB;;;;;;;;;;;;;;;IAmF7B,IAAI,WAAW,IAAI,OAAO,GAAG,SAAS,CAErC;IACD,IAAI,YAAY,IAAI,MAAM,CAEzB;IACD,IAAI,KAAK,IAAI,OAAO,CAEnB;CACJ"}
|
|
@@ -79,26 +79,51 @@ export class FieldFactory {
|
|
|
79
79
|
*/
|
|
80
80
|
for (const field of this._sectionInfo.fields) {
|
|
81
81
|
if (field.destinationDb && (is(field, SelectMultipleField) || is(field, SelectField))) {
|
|
82
|
-
|
|
83
|
-
sql `select * from ${sql.raw(field.destinationDb.table)} a JOIN ${sql.raw(field.db.table)} b ON a.${sql.raw(field.destinationDb.selectIdentifier)} = b.${sql.raw(field.db.identifier)} where ${sql.raw(field.destinationDb.itemIdentifier)} = ${this.itemId}`,
|
|
84
|
-
];
|
|
85
|
-
if (is(field, SelectField) && field.hasDepth()) {
|
|
82
|
+
if (field.db) {
|
|
86
83
|
/**
|
|
87
|
-
*
|
|
84
|
+
* field.db is available (db or section options) — JOIN the options table
|
|
85
|
+
* to retrieve both the stored value and its label
|
|
88
86
|
*/
|
|
89
|
-
sqlChunks
|
|
87
|
+
const sqlChunks = [
|
|
88
|
+
sql `select * from ${sql.raw(field.destinationDb.table)} a JOIN ${sql.raw(field.db.table)} b ON a.${sql.raw(field.destinationDb.selectIdentifier)} = b.${sql.raw(field.db.identifier)} where ${sql.raw(field.destinationDb.itemIdentifier)} = ${this.itemId}`,
|
|
89
|
+
];
|
|
90
|
+
if (is(field, SelectField) && field.hasDepth()) {
|
|
91
|
+
/**
|
|
92
|
+
* Add the where clause to the select statement
|
|
93
|
+
*/
|
|
94
|
+
sqlChunks.push(sql ` ORDER BY b.level ASC`);
|
|
95
|
+
}
|
|
96
|
+
const [_rows, _fields] = await db.execute(sql.join(sqlChunks));
|
|
97
|
+
const values = [];
|
|
98
|
+
if (Array.isArray(_rows)) {
|
|
99
|
+
for (const row of _rows) {
|
|
100
|
+
values.push({
|
|
101
|
+
value: row[field.destinationDb.selectIdentifier],
|
|
102
|
+
label: row[field.db.label],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this._values[field.name] = values;
|
|
90
107
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
108
|
+
else {
|
|
109
|
+
/**
|
|
110
|
+
* field.db is null (static options) — query only the destinationDb table
|
|
111
|
+
* and resolve labels from the field's static options array
|
|
112
|
+
*/
|
|
113
|
+
const [_rows] = await db.execute(sql `SELECT * FROM ${sql.raw(field.destinationDb.table)} WHERE ${sql.raw(field.destinationDb.itemIdentifier)} = ${this.itemId}`);
|
|
114
|
+
const values = [];
|
|
115
|
+
if (Array.isArray(_rows)) {
|
|
116
|
+
for (const row of _rows) {
|
|
117
|
+
const storedValue = row[field.destinationDb.selectIdentifier];
|
|
118
|
+
const matchingOption = field.options?.find((opt) => opt.value.toString() === storedValue?.toString());
|
|
119
|
+
values.push({
|
|
120
|
+
value: storedValue,
|
|
121
|
+
label: matchingOption?.label ?? '',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
99
124
|
}
|
|
125
|
+
this._values[field.name] = values;
|
|
100
126
|
}
|
|
101
|
-
this._values[field.name] = values;
|
|
102
127
|
}
|
|
103
128
|
/**
|
|
104
129
|
* Handle TagsField with destinationDb
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemEditSubmit.d.ts","sourceRoot":"","sources":["../../../src/core/submit/ItemEditSubmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAItC,OAAO,KAAK,EAAuB,KAAK,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,UAAU,EAAM,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAO3E,KAAK,eAAe,GAAG;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,eAAe,CAAC,EAAE,eAAe,CAAA;CACpC,CAAA;AAED,qBAAa,UAAW,SAAQ,MAAM;IAClC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAe;IAC5D,mBAA4B,OAAO,EAAE,MAAM,CAAA;IAC3C,SAAS,CAAC,OAAO,EAAE,MAAM,CA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IAC3C,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAK;cAExB,eAAe,IAAI,YAAY;IAIlD;;;OAGG;cACsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3D;;;OAGG;cACsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5D;;OAEG;gBACS,MAAM,EAAE,eAAe;IAKnC;;;OAGG;IACmB,UAAU;IASV,MAAM;YAQd,qBAAqB;cAuBhB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;cAIjD,gBAAgB,IAAI,MAAM,EAAE;IAO/C,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,iBAAiB;IAczB;;;OAGG;YACW,aAAa;YAQb,sBAAsB;IAmDpC;;;;;OAKG;cACsB,kBAAkB;IAI3C;;;;;OAKG;cACsB,cAAc;YAUzB,oBAAoB;IAoBlC;;;OAGG;cACgB,aAAa,IAAI,GAAG,GAAG,SAAS;IAmBnD;;;;OAIG;IACM,aAAa,CAAC,KAAK,EAAE,KAAK;IAmBnC;;;;OAIG;IACY,WAAW,CAAC,KAAK,EAAE,KAAK;IAQvC;;OAEG;IACM,iBAAiB;IAI1B;;;;OAIG;cACgB,iBAAiB,IAAI,MAAM;IAI9C;;;;OAIG;IACM,aAAa,CAAC,KAAK,EAAE,KAAK;CAgBtC"}
|
|
@@ -131,15 +131,40 @@ export class EditSubmit extends Submit {
|
|
|
131
131
|
async getSelectMultipleValue(field) {
|
|
132
132
|
if (!field.destinationDb)
|
|
133
133
|
return this._values[field.name] ?? undefined;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
if (field.db) {
|
|
135
|
+
/**
|
|
136
|
+
* field.db is available (db or section options) — JOIN the options table
|
|
137
|
+
* to retrieve both the stored value and its label
|
|
138
|
+
*/
|
|
139
|
+
const [_rows, _fields] = await db.execute(sql `select * from ${sql.raw(field.destinationDb.table)} a JOIN ${sql.raw(field.db.table)} b ON a.${sql.raw(field.destinationDb.selectIdentifier)} = b.${sql.raw(field.db.identifier)} where ${sql.raw(field.destinationDb.itemIdentifier)} = ${this._itemId}`);
|
|
140
|
+
const values = [];
|
|
141
|
+
for (const row of _rows) {
|
|
142
|
+
values.push({
|
|
143
|
+
value: row[field.destinationDb.selectIdentifier],
|
|
144
|
+
label: row[field.db.label],
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return values;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
/**
|
|
151
|
+
* field.db is null (static options) — query only the destinationDb table
|
|
152
|
+
* and resolve labels from the field's static options array
|
|
153
|
+
*/
|
|
154
|
+
const [_rows] = await db.execute(sql `SELECT * FROM ${sql.raw(field.destinationDb.table)} WHERE ${sql.raw(field.destinationDb.itemIdentifier)} = ${this._itemId}`);
|
|
155
|
+
const values = [];
|
|
156
|
+
if (Array.isArray(_rows)) {
|
|
157
|
+
for (const row of _rows) {
|
|
158
|
+
const storedValue = row[field.destinationDb.selectIdentifier];
|
|
159
|
+
const matchingOption = field.options?.find((opt) => opt.value.toString() === storedValue?.toString());
|
|
160
|
+
values.push({
|
|
161
|
+
value: storedValue,
|
|
162
|
+
label: matchingOption?.label ?? '',
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return values;
|
|
141
167
|
}
|
|
142
|
-
return values;
|
|
143
168
|
}
|
|
144
169
|
/**
|
|
145
170
|
* Rollback post submit operations
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-cms",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.11",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -200,9 +200,9 @@
|
|
|
200
200
|
"prettier": "^3.3.3",
|
|
201
201
|
"tsx": "^4.20.6",
|
|
202
202
|
"typescript": "^5.9.2",
|
|
203
|
-
"@lzcms/
|
|
203
|
+
"@lzcms/eslint-config": "0.3.0",
|
|
204
204
|
"@lzcms/prettier-config": "0.1.0",
|
|
205
|
-
"@lzcms/
|
|
205
|
+
"@lzcms/tsconfig": "0.1.0"
|
|
206
206
|
},
|
|
207
207
|
"license": "MIT",
|
|
208
208
|
"keywords": [
|