@coffer-org/sdk 2.1.1 → 2.1.3
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/fields.d.ts +1 -0
- package/dist/fields.js +25 -5
- package/package.json +1 -1
package/dist/fields.d.ts
CHANGED
package/dist/fields.js
CHANGED
|
@@ -509,13 +509,30 @@ export function check(raw) {
|
|
|
509
509
|
const required = o.required ?? false;
|
|
510
510
|
const multiple = o.multiple ?? false;
|
|
511
511
|
const slots = o.slots && o.slots.length > 0 ? o.slots : [''];
|
|
512
|
+
const contentFields = o.fields?.length
|
|
513
|
+
? o.fields
|
|
514
|
+
: [string({ key: 'text', label: 'core.fields.text' })];
|
|
515
|
+
const contentKeys = new Set();
|
|
516
|
+
for (const f of contentFields) {
|
|
517
|
+
if (contentKeys.has(f.key))
|
|
518
|
+
throw new Error(`[field.check] duplicate content field '${f.key}'`);
|
|
519
|
+
if (/^check\d+$/.test(f.key))
|
|
520
|
+
throw new Error(`[field.check] content field '${f.key}' is reserved for checkbox slots`);
|
|
521
|
+
if (!multiple && (f.type.virtual || f.type.columns))
|
|
522
|
+
throw new Error(`[field.check] single content field '${f.key}' must be a scalar stored field`);
|
|
523
|
+
contentKeys.add(f.key);
|
|
524
|
+
}
|
|
525
|
+
const checkFields = slots.map((label, i) => boolean({ key: `check${i}`, label: label || 'core.fields.check' }));
|
|
512
526
|
if (multiple) {
|
|
513
|
-
const fields =
|
|
514
|
-
fields.push(string({ key: 'text', label: 'core.fields.text' }));
|
|
527
|
+
const fields = [...checkFields, ...contentFields];
|
|
515
528
|
return group({ key: o.key, label: o.label ?? o.key, multiple: true, required: required, fields, view: { kind: 'checklist' } });
|
|
516
529
|
}
|
|
517
|
-
const shape = {
|
|
518
|
-
const columns = {
|
|
530
|
+
const shape = {};
|
|
531
|
+
const columns = {};
|
|
532
|
+
for (const f of contentFields) {
|
|
533
|
+
shape[f.key] = f.type.zod;
|
|
534
|
+
columns[f.key] = f.type.column;
|
|
535
|
+
}
|
|
519
536
|
slots.forEach((_, i) => {
|
|
520
537
|
shape[`check${i}`] = z.boolean();
|
|
521
538
|
columns[`check${i}`] = 'boolean';
|
|
@@ -536,7 +553,10 @@ export function check(raw) {
|
|
|
536
553
|
required,
|
|
537
554
|
prim: 'check',
|
|
538
555
|
column: 'text',
|
|
539
|
-
hints: {
|
|
556
|
+
hints: {
|
|
557
|
+
slots,
|
|
558
|
+
fields: contentFields.map((f) => ({ key: f.key, ...toClient(f.type) })),
|
|
559
|
+
},
|
|
540
560
|
columns,
|
|
541
561
|
zod: optionalize(s, required),
|
|
542
562
|
};
|