@rljson/rljson 0.0.42 → 0.0.43

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,11 @@ export interface TableCfg extends Json {
72
72
  * A table containing columns
73
73
  */
74
74
  export type TablesCfgTable = RljsonTable<TableCfg, 'ingredients'>;
75
+ /**
76
+ * Throws an error if the table configuration is not valid.
77
+ * @param tableCfg - The table configuration to check
78
+ */
79
+ export declare const throwOnInvalidTableCfg: (tableCfg: TableCfg) => void;
75
80
  /**
76
81
  * Example matching allTypesRow
77
82
  */
package/dist/rljson.js CHANGED
@@ -533,12 +533,40 @@ __publicField(_Example, "broken", {
533
533
  });
534
534
  let Example = _Example;
535
535
  // @license
536
+ const throwOnInvalidTableCfg = (tableCfg) => {
537
+ if (tableCfg.columns.length < 2) {
538
+ throw new Error(
539
+ `Invalid table configuration: Table "${tableCfg.key}" must have at least a _hash and a second column`
540
+ );
541
+ }
542
+ if (tableCfg.columns[0].key !== "_hash") {
543
+ throw new Error(
544
+ `Invalid table configuration: The first column of table "${tableCfg.key}" must be "_hash"`
545
+ );
546
+ }
547
+ if (tableCfg.columns[0].type !== "string") {
548
+ throw new Error(
549
+ `Invalid table configuration: The first _hash column of table "${tableCfg.key}" must be of type "string"`
550
+ );
551
+ }
552
+ for (const column of tableCfg.columns) {
553
+ if (!jsonValueTypes.includes(column.type)) {
554
+ throw new Error(
555
+ `Invalid table configuration: Column "${column.key}" of table "${tableCfg.key}" has an unsupported type "${column.type}"`
556
+ );
557
+ }
558
+ }
559
+ };
536
560
  const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
537
561
  const exampleTableCfg = (tableCfg = void 0) => {
538
562
  return {
539
563
  key: (tableCfg == null ? void 0 : tableCfg.key) ?? "table",
540
564
  version: 1,
541
565
  columns: (tableCfg == null ? void 0 : tableCfg.columns) ?? [
566
+ {
567
+ key: "_hash",
568
+ type: "string"
569
+ },
542
570
  {
543
571
  key: "a",
544
572
  type: "string"
@@ -1521,5 +1549,6 @@ export {
1521
1549
  iterateTablesSync,
1522
1550
  reservedFieldNames,
1523
1551
  reservedTableKeys,
1524
- rljsonIndexed
1552
+ rljsonIndexed,
1553
+ throwOnInvalidTableCfg
1525
1554
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",