@rljson/rljson 0.0.46 → 0.0.47
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/content/table-cfg.d.ts +7 -0
- package/dist/rljson.js +29 -2
- package/package.json +1 -1
|
@@ -72,6 +72,13 @@ 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
|
+
* Validates the table configuration against the data.
|
|
77
|
+
* @param rows - The rows to validate
|
|
78
|
+
* @param tableCfg - The table configuration to validate against
|
|
79
|
+
* @returns - An array of error messages
|
|
80
|
+
*/
|
|
81
|
+
export declare const validateRljsonAgainstTableCfg: (rows: Json[], tableCfg: TableCfg) => string[];
|
|
75
82
|
/**
|
|
76
83
|
* Add columns to table config
|
|
77
84
|
* @param tableCfg - The table configuration to add columns to
|
package/dist/rljson.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { hip, hsh } from "@rljson/hash";
|
|
5
|
-
import { exampleJsonObject, jsonValueTypes, jsonValueMatchesType } from "@rljson/json";
|
|
5
|
+
import { exampleJsonObject, jsonValueTypes, jsonValueType, jsonValueMatchesType } from "@rljson/json";
|
|
6
6
|
// @license
|
|
7
7
|
const bakeryExample = () => {
|
|
8
8
|
const nutritionalValues = hip({
|
|
@@ -557,6 +557,32 @@ const throwOnInvalidTableCfg = (tableCfg) => {
|
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
};
|
|
560
|
+
const validateRljsonAgainstTableCfg = (rows, tableCfg) => {
|
|
561
|
+
const errors = [];
|
|
562
|
+
const tableKey = tableCfg.key;
|
|
563
|
+
for (let i = 0; i < rows.length; i++) {
|
|
564
|
+
const row = rows[i];
|
|
565
|
+
for (const columnKey in row) {
|
|
566
|
+
const columnCfg = tableCfg.columns.find(
|
|
567
|
+
(column) => column.key === columnKey
|
|
568
|
+
);
|
|
569
|
+
if (!columnCfg) {
|
|
570
|
+
errors.push(
|
|
571
|
+
`Column "${columnKey}" in row ${i} of table "${tableKey}" does not exist.`
|
|
572
|
+
);
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
const expectedType = columnCfg.type;
|
|
576
|
+
const actualType = jsonValueType(row[columnKey]);
|
|
577
|
+
if (expectedType !== actualType) {
|
|
578
|
+
errors.push(
|
|
579
|
+
`Column "${columnKey}" in row ${i} of "${tableKey}" has type "${actualType}", but expected "${expectedType}"`
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return errors;
|
|
585
|
+
};
|
|
560
586
|
const addColumnsToTableCfg = (tableCfg, columns) => {
|
|
561
587
|
const existingKeys = new Set(tableCfg.columns.map((c) => c.key));
|
|
562
588
|
const duplicates = columns.filter((col) => existingKeys.has(col.key));
|
|
@@ -1570,5 +1596,6 @@ export {
|
|
|
1570
1596
|
reservedFieldNames,
|
|
1571
1597
|
reservedTableKeys,
|
|
1572
1598
|
rljsonIndexed,
|
|
1573
|
-
throwOnInvalidTableCfg
|
|
1599
|
+
throwOnInvalidTableCfg,
|
|
1600
|
+
validateRljsonAgainstTableCfg
|
|
1574
1601
|
};
|