@coffer-org/sdk 2.1.2 → 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 CHANGED
@@ -400,6 +400,7 @@ export declare function json(o: JsonOpts & {
400
400
  }): FieldMeta;
401
401
  export interface CheckOpts extends FieldCoreOpts {
402
402
  slots?: string[];
403
+ fields?: FieldItem[];
403
404
  }
404
405
  export declare function check(o: CheckOpts & {
405
406
  key: string;
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 = slots.map((label, i) => boolean({ key: `check${i}`, label: label || 'core.fields.check' }));
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 = { text: z.string() };
518
- const columns = { text: 'text' };
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: { slots },
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffer-org/sdk",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"