@rljson/rljson 0.0.37 → 0.0.39

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.
@@ -68,6 +68,17 @@ export interface TableCfg extends Json {
68
68
  * A table containing columns
69
69
  */
70
70
  export type TablesCfgTable = RljsonTable<TableCfg, 'ingredients'>;
71
+ /**
72
+ * Offers tools for working with table configurations
73
+ */
74
+ export declare class TableCfgTools {
75
+ readonly tableCfg: TableCfg;
76
+ constructor(tableCfg: TableCfg);
77
+ /**
78
+ * Returns all column keys
79
+ */
80
+ get columnKeys(): ColumnKey[];
81
+ }
71
82
  /**
72
83
  * Example matching allTypesRow
73
84
  */
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './content/buffet.ts';
2
2
  export * from './content/cake.ts';
3
3
  export * from './content/ingredients.ts';
4
4
  export * from './content/layer.ts';
5
+ export * from './content/revision.ts';
5
6
  export * from './content/slice-ids.ts';
6
7
  export * from './content/table-cfg.ts';
7
8
  export * from './example.ts';
package/dist/rljson.d.ts CHANGED
@@ -59,4 +59,13 @@ export interface RljsonTable<Data extends Json, Type extends ContentType> extend
59
59
  * @param rljson - The Rljson object to iterate
60
60
  * @param callback - The callback to call for each table
61
61
  */
62
- export declare const iterateTables: (rljson: Rljson, callback: (tableKey: string, table: TableType) => void) => void;
62
+ export declare const iterateTablesSync: (rljson: Rljson, callback: (tableKey: string, table: TableType) => void) => void;
63
+ /**
64
+ * Iterates over all tables of an Rljson object.
65
+ * Skips private members starting with _
66
+ * @param rljson - The Rljson object to iterate
67
+ * @param callback - The callback to call for each table
68
+ *
69
+ * Note: The callbacks are executed in parallel.
70
+ */
71
+ export declare const iterateTables: (rljson: Rljson, callback: (tableKey: string, table: TableType) => Promise<void>) => Promise<void>;
package/dist/rljson.js CHANGED
@@ -148,6 +148,14 @@ const exampleIngredientsTable = () => bakeryExample().nutritionalValues;
148
148
  // @license
149
149
  const exampleLayersTable = () => bakeryExample().layers;
150
150
  // @license
151
+ const exampleRevision = () => ({
152
+ table: "nutritionalValues",
153
+ id: "flour",
154
+ predecessor: "gZXFSlrl5QAs5hOVsq5sWB",
155
+ successor: "IqeoWJjZQNlr-NVk2QT15B",
156
+ timestamp: 1743558427
157
+ });
158
+ // @license
151
159
  const exampleSliceIdsTable = () => bakeryExample().slices;
152
160
  // @license
153
161
  const _Example = class _Example {
@@ -516,6 +524,20 @@ __publicField(_Example, "broken", {
516
524
  });
517
525
  let Example = _Example;
518
526
  // @license
527
+ class TableCfgTools {
528
+ constructor(tableCfg) {
529
+ this.tableCfg = tableCfg;
530
+ }
531
+ /**
532
+ * Returns all column keys
533
+ */
534
+ get columnKeys() {
535
+ const columnNames = Object.keys(this.tableCfg.columns).filter(
536
+ (e) => !e.startsWith("_")
537
+ );
538
+ return columnNames;
539
+ }
540
+ }
519
541
  const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
520
542
  const exampleTableCfg = (tableCfg = void 0) => {
521
543
  return {
@@ -568,15 +590,36 @@ const reservedTableKeys = [
568
590
  "revisions"
569
591
  ];
570
592
  const exampleRljson = () => Example.ok.singleRow();
571
- const iterateTables = (rljson, callback) => {
593
+ const _isTable = (value) => {
594
+ return !(typeof value !== "object" || !Array.isArray(value._data));
595
+ };
596
+ const iterateTablesSync = (rljson, callback) => {
572
597
  for (const tableKey in rljson) {
573
598
  const value = rljson[tableKey];
574
- if (typeof value !== "object" || !Array.isArray(value._data)) {
599
+ if (!_isTable(value)) {
575
600
  continue;
576
601
  }
577
602
  callback(tableKey, rljson[tableKey]);
578
603
  }
579
604
  };
605
+ const iterateTables = async (rljson, callback) => {
606
+ const array = [];
607
+ const errors = [];
608
+ for (const tableKey in rljson) {
609
+ const value = rljson[tableKey];
610
+ if (!_isTable(value)) {
611
+ continue;
612
+ }
613
+ const promise = callback(tableKey, rljson[tableKey]).catch((error) => {
614
+ errors.push({ tableKey, error });
615
+ });
616
+ array.push(promise);
617
+ }
618
+ await Promise.all(array);
619
+ if (errors.length) {
620
+ throw errors;
621
+ }
622
+ };
580
623
  // @license
581
624
  const contentTypes = [
582
625
  "buffets",
@@ -821,7 +864,7 @@ class _BaseValidator {
821
864
  _tableCfgNotFound() {
822
865
  const tableCfgs = this.rljsonIndexed.tableCfgs;
823
866
  const tableCfgNotFound = [];
824
- iterateTables(this.rljson, (tableKey, table) => {
867
+ iterateTablesSync(this.rljson, (tableKey, table) => {
825
868
  const tableCfgRef = table._tableCfg;
826
869
  if (!tableCfgRef) {
827
870
  return;
@@ -846,7 +889,7 @@ class _BaseValidator {
846
889
  _missingColumnConfigs() {
847
890
  const tableCfgs = this.rljsonIndexed.tableCfgs;
848
891
  const missingColumnConfigs = [];
849
- iterateTables(this.rljson, (tableKey, table) => {
892
+ iterateTablesSync(this.rljson, (tableKey, table) => {
850
893
  const tableCfgRef = table._tableCfg;
851
894
  if (!tableCfgRef) {
852
895
  return;
@@ -885,7 +928,7 @@ class _BaseValidator {
885
928
  _dataDoesNotMatchColumnConfig() {
886
929
  const tableCfgs = this.rljsonIndexed.tableCfgs;
887
930
  const brokenValues = [];
888
- iterateTables(this.rljson, (tableKey, table) => {
931
+ iterateTablesSync(this.rljson, (tableKey, table) => {
889
932
  const tableCfgRef = table._tableCfg;
890
933
  if (!tableCfgRef) {
891
934
  return;
@@ -1062,7 +1105,7 @@ class _BaseValidator {
1062
1105
  }
1063
1106
  _refsNotFound() {
1064
1107
  const missingRefs = [];
1065
- iterateTables(this.rljson, (tableKey, table) => {
1108
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1066
1109
  const tableData = table._data;
1067
1110
  for (const item of tableData) {
1068
1111
  for (const key of Object.keys(item)) {
@@ -1106,7 +1149,7 @@ class _BaseValidator {
1106
1149
  }
1107
1150
  _layerBasesNotFound() {
1108
1151
  const brokenLayers = [];
1109
- iterateTables(this.rljson, (tableKey, table) => {
1152
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1110
1153
  if (table._type !== "layers") {
1111
1154
  return;
1112
1155
  }
@@ -1136,7 +1179,7 @@ class _BaseValidator {
1136
1179
  }
1137
1180
  _layerSliceIdsTableNotFound() {
1138
1181
  const brokenLayers = [];
1139
- iterateTables(this.rljson, (tableKey, table) => {
1182
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1140
1183
  if (table._type !== "layers") {
1141
1184
  return;
1142
1185
  }
@@ -1161,7 +1204,7 @@ class _BaseValidator {
1161
1204
  }
1162
1205
  _layerSliceIdsRowNotFound() {
1163
1206
  const brokenLayers = [];
1164
- iterateTables(this.rljson, (tableKey, table) => {
1207
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1165
1208
  if (table._type !== "layers") {
1166
1209
  return;
1167
1210
  }
@@ -1189,7 +1232,7 @@ class _BaseValidator {
1189
1232
  _layerIngredientAssignmentsNotFound() {
1190
1233
  const missingIngredientTables = [];
1191
1234
  const brokenAssignments = [];
1192
- iterateTables(this.rljson, (tableKey, table) => {
1235
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1193
1236
  if (table._type !== "layers") {
1194
1237
  return;
1195
1238
  }
@@ -1238,7 +1281,7 @@ class _BaseValidator {
1238
1281
  }
1239
1282
  _layerAssignmentsDoNotMatchSliceIds() {
1240
1283
  const layersWithMissingAssignments = [];
1241
- iterateTables(this.rljson, (tableKey, table) => {
1284
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1242
1285
  if (table._type !== "layers") {
1243
1286
  return;
1244
1287
  }
@@ -1273,7 +1316,7 @@ class _BaseValidator {
1273
1316
  }
1274
1317
  _cakeSliceIdsTableNotFound() {
1275
1318
  const brokenCakes = [];
1276
- iterateTables(this.rljson, (tableKey, table) => {
1319
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1277
1320
  if (table._type !== "cakes") {
1278
1321
  return;
1279
1322
  }
@@ -1298,7 +1341,7 @@ class _BaseValidator {
1298
1341
  }
1299
1342
  _cakeSliceIdsNotFound() {
1300
1343
  const brokenCakes = [];
1301
- iterateTables(this.rljson, (tableKey, table) => {
1344
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1302
1345
  if (table._type !== "cakes") {
1303
1346
  return;
1304
1347
  }
@@ -1326,7 +1369,7 @@ class _BaseValidator {
1326
1369
  _cakeLayerTablesNotFound() {
1327
1370
  const missingLayerTables = [];
1328
1371
  const missingCakeLayers = [];
1329
- iterateTables(this.rljson, (tableKey, table) => {
1372
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1330
1373
  if (table._type !== "cakes") {
1331
1374
  return;
1332
1375
  }
@@ -1376,7 +1419,7 @@ class _BaseValidator {
1376
1419
  _buffetReferencedTableNotFound() {
1377
1420
  const missingTables = [];
1378
1421
  const missingItems = [];
1379
- iterateTables(this.rljson, (tableKey, table) => {
1422
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1380
1423
  if (table._type !== "buffets") {
1381
1424
  return;
1382
1425
  }
@@ -1461,6 +1504,7 @@ class Validate {
1461
1504
  export {
1462
1505
  BaseValidator,
1463
1506
  Example,
1507
+ TableCfgTools,
1464
1508
  Validate,
1465
1509
  bakeryExample,
1466
1510
  contentTypes,
@@ -1468,6 +1512,7 @@ export {
1468
1512
  exampleCakesTable,
1469
1513
  exampleIngredientsTable,
1470
1514
  exampleLayersTable,
1515
+ exampleRevision,
1471
1516
  exampleRljson,
1472
1517
  exampleSliceIdsTable,
1473
1518
  exampleTableCfg,
@@ -1475,6 +1520,7 @@ export {
1475
1520
  exampleTypedefs,
1476
1521
  isValidFieldName,
1477
1522
  iterateTables,
1523
+ iterateTablesSync,
1478
1524
  reservedFieldNames,
1479
1525
  reservedTableKeys,
1480
1526
  rljsonIndexed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",
@@ -29,20 +29,20 @@
29
29
  "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/node": "^22.13.17",
33
- "@typescript-eslint/eslint-plugin": "^8.29.0",
34
- "@typescript-eslint/parser": "^8.29.0",
32
+ "@types/node": "^22.14.1",
33
+ "@typescript-eslint/eslint-plugin": "^8.30.1",
34
+ "@typescript-eslint/parser": "^8.30.1",
35
35
  "@vitest/coverage-v8": "^3.1.1",
36
36
  "cross-env": "^7.0.3",
37
- "eslint": "^9.23.0",
37
+ "eslint": "^9.25.0",
38
38
  "eslint-plugin-jsdoc": "^50.6.9",
39
39
  "eslint-plugin-tsdoc": "^0.4.0",
40
40
  "globals": "^16.0.0",
41
41
  "jsdoc": "^4.0.4",
42
42
  "read-pkg": "^9.0.1",
43
- "typescript": "~5.8.2",
44
- "typescript-eslint": "^8.29.0",
45
- "vite": "^6.2.4",
43
+ "typescript": "~5.8.3",
44
+ "typescript-eslint": "^8.30.1",
45
+ "vite": "^6.3.2",
46
46
  "vite-node": "^3.1.1",
47
47
  "vite-plugin-dts": "^4.5.3",
48
48
  "vite-tsconfig-paths": "^5.1.4",