@rljson/rljson 0.0.44 → 0.0.46

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.
@@ -72,6 +72,14 @@ export type TablesCfgTable = RljsonTable<TableCfg, 'ingredients'>;
72
72
  * @param tableCfg - The table configuration to check
73
73
  */
74
74
  export declare const throwOnInvalidTableCfg: (tableCfg: TableCfg) => void;
75
+ /**
76
+ * Add columns to table config
77
+ * @param tableCfg - The table configuration to add columns to
78
+ * @param columns - The columns to add
79
+ * @returns The updated table configuration
80
+ * @throws Error if the columns already exist in the table configuration
81
+ */
82
+ export declare const addColumnsToTableCfg: (tableCfg: TableCfg, columns: ColumnCfg[]) => TableCfg;
75
83
  /**
76
84
  * Example matching allTypesRow
77
85
  */
package/dist/rljson.js CHANGED
@@ -557,6 +557,26 @@ const throwOnInvalidTableCfg = (tableCfg) => {
557
557
  }
558
558
  }
559
559
  };
560
+ const addColumnsToTableCfg = (tableCfg, columns) => {
561
+ const existingKeys = new Set(tableCfg.columns.map((c) => c.key));
562
+ const duplicates = columns.filter((col) => existingKeys.has(col.key));
563
+ if (duplicates.length > 0) {
564
+ const keys = duplicates.map((d) => d.key).join(", ");
565
+ throw new Error(
566
+ `The following columns already exist in the table "${tableCfg.key}": ${keys}`
567
+ );
568
+ }
569
+ return hsh(
570
+ {
571
+ ...tableCfg,
572
+ columns: [...tableCfg.columns, ...columns]
573
+ },
574
+ {
575
+ updateExistingHashes: true,
576
+ throwOnWrongHashes: false
577
+ }
578
+ );
579
+ };
560
580
  const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
561
581
  const exampleTableCfg = (tableCfg = void 0) => {
562
582
  return {
@@ -1531,6 +1551,7 @@ export {
1531
1551
  BaseValidator,
1532
1552
  Example,
1533
1553
  Validate,
1554
+ addColumnsToTableCfg,
1534
1555
  bakeryExample,
1535
1556
  contentTypes,
1536
1557
  exampleBuffetsTable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",