@rljson/rljson 0.0.40 → 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
@@ -210,7 +210,7 @@ __publicField(_Example, "ok", {
210
210
  },
211
211
  {
212
212
  key: "null",
213
- type: "null"
213
+ type: "string"
214
214
  },
215
215
  {
216
216
  key: "jsonArray",
@@ -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"
@@ -945,6 +973,7 @@ class _BaseValidator {
945
973
  }
946
974
  const typeShould = columnConfig.type;
947
975
  if (!jsonValueMatchesType(value, typeShould)) {
976
+ jsonValueMatchesType(value, typeShould);
948
977
  brokenValues.push({
949
978
  table: tableKey,
950
979
  row: row._hash,
@@ -1520,5 +1549,6 @@ export {
1520
1549
  iterateTablesSync,
1521
1550
  reservedFieldNames,
1522
1551
  reservedTableKeys,
1523
- rljsonIndexed
1552
+ rljsonIndexed,
1553
+ throwOnInvalidTableCfg
1524
1554
  };
@@ -71,7 +71,7 @@ export class Example {
71
71
  },
72
72
  {
73
73
  key: 'null',
74
- type: 'null',
74
+ type: 'string',
75
75
  },
76
76
  {
77
77
  key: 'jsonArray',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.40",
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",
@@ -50,8 +50,8 @@
50
50
  "vitest-dom": "^0.1.1"
51
51
  },
52
52
  "dependencies": {
53
- "@rljson/hash": "^0.0.13",
54
- "@rljson/json": "^0.0.18"
53
+ "@rljson/hash": "^0.0.15",
54
+ "@rljson/json": "^0.0.21"
55
55
  },
56
56
  "pnpm": {
57
57
  "onlyBuiltDependencies": [