@rljson/rljson 0.0.37 → 0.0.38

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/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 {
@@ -568,15 +576,36 @@ const reservedTableKeys = [
568
576
  "revisions"
569
577
  ];
570
578
  const exampleRljson = () => Example.ok.singleRow();
571
- const iterateTables = (rljson, callback) => {
579
+ const _isTable = (value) => {
580
+ return !(typeof value !== "object" || !Array.isArray(value._data));
581
+ };
582
+ const iterateTablesSync = (rljson, callback) => {
572
583
  for (const tableKey in rljson) {
573
584
  const value = rljson[tableKey];
574
- if (typeof value !== "object" || !Array.isArray(value._data)) {
585
+ if (!_isTable(value)) {
575
586
  continue;
576
587
  }
577
588
  callback(tableKey, rljson[tableKey]);
578
589
  }
579
590
  };
591
+ const iterateTables = async (rljson, callback) => {
592
+ const array = [];
593
+ const errors = [];
594
+ for (const tableKey in rljson) {
595
+ const value = rljson[tableKey];
596
+ if (!_isTable(value)) {
597
+ continue;
598
+ }
599
+ const promise = callback(tableKey, rljson[tableKey]).catch((error) => {
600
+ errors.push({ tableKey, error });
601
+ });
602
+ array.push(promise);
603
+ }
604
+ await Promise.all(array);
605
+ if (errors.length) {
606
+ throw errors;
607
+ }
608
+ };
580
609
  // @license
581
610
  const contentTypes = [
582
611
  "buffets",
@@ -821,7 +850,7 @@ class _BaseValidator {
821
850
  _tableCfgNotFound() {
822
851
  const tableCfgs = this.rljsonIndexed.tableCfgs;
823
852
  const tableCfgNotFound = [];
824
- iterateTables(this.rljson, (tableKey, table) => {
853
+ iterateTablesSync(this.rljson, (tableKey, table) => {
825
854
  const tableCfgRef = table._tableCfg;
826
855
  if (!tableCfgRef) {
827
856
  return;
@@ -846,7 +875,7 @@ class _BaseValidator {
846
875
  _missingColumnConfigs() {
847
876
  const tableCfgs = this.rljsonIndexed.tableCfgs;
848
877
  const missingColumnConfigs = [];
849
- iterateTables(this.rljson, (tableKey, table) => {
878
+ iterateTablesSync(this.rljson, (tableKey, table) => {
850
879
  const tableCfgRef = table._tableCfg;
851
880
  if (!tableCfgRef) {
852
881
  return;
@@ -885,7 +914,7 @@ class _BaseValidator {
885
914
  _dataDoesNotMatchColumnConfig() {
886
915
  const tableCfgs = this.rljsonIndexed.tableCfgs;
887
916
  const brokenValues = [];
888
- iterateTables(this.rljson, (tableKey, table) => {
917
+ iterateTablesSync(this.rljson, (tableKey, table) => {
889
918
  const tableCfgRef = table._tableCfg;
890
919
  if (!tableCfgRef) {
891
920
  return;
@@ -1062,7 +1091,7 @@ class _BaseValidator {
1062
1091
  }
1063
1092
  _refsNotFound() {
1064
1093
  const missingRefs = [];
1065
- iterateTables(this.rljson, (tableKey, table) => {
1094
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1066
1095
  const tableData = table._data;
1067
1096
  for (const item of tableData) {
1068
1097
  for (const key of Object.keys(item)) {
@@ -1106,7 +1135,7 @@ class _BaseValidator {
1106
1135
  }
1107
1136
  _layerBasesNotFound() {
1108
1137
  const brokenLayers = [];
1109
- iterateTables(this.rljson, (tableKey, table) => {
1138
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1110
1139
  if (table._type !== "layers") {
1111
1140
  return;
1112
1141
  }
@@ -1136,7 +1165,7 @@ class _BaseValidator {
1136
1165
  }
1137
1166
  _layerSliceIdsTableNotFound() {
1138
1167
  const brokenLayers = [];
1139
- iterateTables(this.rljson, (tableKey, table) => {
1168
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1140
1169
  if (table._type !== "layers") {
1141
1170
  return;
1142
1171
  }
@@ -1161,7 +1190,7 @@ class _BaseValidator {
1161
1190
  }
1162
1191
  _layerSliceIdsRowNotFound() {
1163
1192
  const brokenLayers = [];
1164
- iterateTables(this.rljson, (tableKey, table) => {
1193
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1165
1194
  if (table._type !== "layers") {
1166
1195
  return;
1167
1196
  }
@@ -1189,7 +1218,7 @@ class _BaseValidator {
1189
1218
  _layerIngredientAssignmentsNotFound() {
1190
1219
  const missingIngredientTables = [];
1191
1220
  const brokenAssignments = [];
1192
- iterateTables(this.rljson, (tableKey, table) => {
1221
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1193
1222
  if (table._type !== "layers") {
1194
1223
  return;
1195
1224
  }
@@ -1238,7 +1267,7 @@ class _BaseValidator {
1238
1267
  }
1239
1268
  _layerAssignmentsDoNotMatchSliceIds() {
1240
1269
  const layersWithMissingAssignments = [];
1241
- iterateTables(this.rljson, (tableKey, table) => {
1270
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1242
1271
  if (table._type !== "layers") {
1243
1272
  return;
1244
1273
  }
@@ -1273,7 +1302,7 @@ class _BaseValidator {
1273
1302
  }
1274
1303
  _cakeSliceIdsTableNotFound() {
1275
1304
  const brokenCakes = [];
1276
- iterateTables(this.rljson, (tableKey, table) => {
1305
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1277
1306
  if (table._type !== "cakes") {
1278
1307
  return;
1279
1308
  }
@@ -1298,7 +1327,7 @@ class _BaseValidator {
1298
1327
  }
1299
1328
  _cakeSliceIdsNotFound() {
1300
1329
  const brokenCakes = [];
1301
- iterateTables(this.rljson, (tableKey, table) => {
1330
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1302
1331
  if (table._type !== "cakes") {
1303
1332
  return;
1304
1333
  }
@@ -1326,7 +1355,7 @@ class _BaseValidator {
1326
1355
  _cakeLayerTablesNotFound() {
1327
1356
  const missingLayerTables = [];
1328
1357
  const missingCakeLayers = [];
1329
- iterateTables(this.rljson, (tableKey, table) => {
1358
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1330
1359
  if (table._type !== "cakes") {
1331
1360
  return;
1332
1361
  }
@@ -1376,7 +1405,7 @@ class _BaseValidator {
1376
1405
  _buffetReferencedTableNotFound() {
1377
1406
  const missingTables = [];
1378
1407
  const missingItems = [];
1379
- iterateTables(this.rljson, (tableKey, table) => {
1408
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1380
1409
  if (table._type !== "buffets") {
1381
1410
  return;
1382
1411
  }
@@ -1468,6 +1497,7 @@ export {
1468
1497
  exampleCakesTable,
1469
1498
  exampleIngredientsTable,
1470
1499
  exampleLayersTable,
1500
+ exampleRevision,
1471
1501
  exampleRljson,
1472
1502
  exampleSliceIdsTable,
1473
1503
  exampleTableCfg,
@@ -1475,6 +1505,7 @@ export {
1475
1505
  exampleTypedefs,
1476
1506
  isValidFieldName,
1477
1507
  iterateTables,
1508
+ iterateTablesSync,
1478
1509
  reservedFieldNames,
1479
1510
  reservedTableKeys,
1480
1511
  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.38",
4
4
  "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",