@rljson/rljson 0.0.23 → 0.0.25
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/buffet.d.ts +2 -2
- package/dist/content/cake.d.ts +2 -2
- package/dist/content/collection.d.ts +2 -2
- package/dist/content/table-cfg.d.ts +10 -6
- package/dist/example.d.ts +1 -1
- package/dist/rljson-indexed.d.ts +1 -1
- package/dist/rljson.d.ts +4 -4
- package/dist/rljson.js +99 -99
- package/dist/src/example.ts +10 -11
- package/dist/typedefs.d.ts +7 -2
- package/dist/validate/base-validator.d.ts +4 -4
- package/package.json +1 -1
package/dist/content/buffet.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Json } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
|
-
import { ItemId, Ref,
|
|
3
|
+
import { ItemId, Ref, TableKey } from '../typedefs.ts';
|
|
4
4
|
/**
|
|
5
5
|
* A buffet id is a name or id of a buffet
|
|
6
6
|
*/
|
|
@@ -17,7 +17,7 @@ export interface Buffet extends Json {
|
|
|
17
17
|
/**
|
|
18
18
|
* The table the item is taken from
|
|
19
19
|
*/
|
|
20
|
-
table:
|
|
20
|
+
table: TableKey;
|
|
21
21
|
/**
|
|
22
22
|
* The hash of the item in the able
|
|
23
23
|
*/
|
package/dist/content/cake.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Json } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
|
-
import { ItemId,
|
|
3
|
+
import { ItemId, TableKey } from '../typedefs.ts';
|
|
4
4
|
import { CollectionRef } from './collection.ts';
|
|
5
5
|
import { IdSetRef } from './id-set.ts';
|
|
6
6
|
/**
|
|
@@ -22,7 +22,7 @@ export interface Cake extends Json {
|
|
|
22
22
|
/**
|
|
23
23
|
* The table containing the item collections defining the layers
|
|
24
24
|
*/
|
|
25
|
-
collections:
|
|
25
|
+
collections: TableKey;
|
|
26
26
|
/**
|
|
27
27
|
* Assigns a collection to each layer of the cake.
|
|
28
28
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Json } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
|
-
import { ItemId, Ref,
|
|
3
|
+
import { ItemId, Ref, TableKey } from '../typedefs.ts';
|
|
4
4
|
import { IdSetRef } from './id-set.ts';
|
|
5
5
|
import { PropertiesRef } from './properties.ts';
|
|
6
6
|
/**
|
|
@@ -24,7 +24,7 @@ export interface Collection extends Json {
|
|
|
24
24
|
* The table containing the properties that are assigned to the items
|
|
25
25
|
* with the assign property below
|
|
26
26
|
*/
|
|
27
|
-
properties:
|
|
27
|
+
properties: TableKey;
|
|
28
28
|
/**
|
|
29
29
|
* Assign properties to each item of the collection.
|
|
30
30
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Json,
|
|
1
|
+
import { Json, JsonValueType } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
|
-
import { ContentType, Ref } from '../typedefs.ts';
|
|
3
|
+
import { ColumnKey, ContentType, Ref, TableKey } from '../typedefs.ts';
|
|
4
4
|
/**
|
|
5
5
|
* A ColumnsRef is a hash pointing to columns metadata
|
|
6
6
|
*/
|
|
@@ -10,9 +10,9 @@ export type TableCfgRef = Ref;
|
|
|
10
10
|
*/
|
|
11
11
|
export interface ColumnCfg extends Json {
|
|
12
12
|
/**
|
|
13
|
-
* The
|
|
13
|
+
* The key of the column used in data
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
key: ColumnKey;
|
|
16
16
|
/**
|
|
17
17
|
* The type of the column
|
|
18
18
|
*/
|
|
@@ -25,15 +25,19 @@ export interface TableCfg extends Json {
|
|
|
25
25
|
/**
|
|
26
26
|
* Technical lower camel case json identifier of the table
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
key: TableKey;
|
|
29
29
|
/**
|
|
30
30
|
* A short description of the table
|
|
31
31
|
*/
|
|
32
|
-
columns: Record<
|
|
32
|
+
columns: Record<ColumnKey, ColumnCfg>;
|
|
33
33
|
/**
|
|
34
34
|
* The content type of the table
|
|
35
35
|
*/
|
|
36
36
|
type: ContentType;
|
|
37
|
+
/**
|
|
38
|
+
* The previous version of the table
|
|
39
|
+
*/
|
|
40
|
+
previous?: TableCfgRef;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* A table containing columns
|
package/dist/example.d.ts
CHANGED
package/dist/rljson-indexed.d.ts
CHANGED
package/dist/rljson.d.ts
CHANGED
|
@@ -5,16 +5,16 @@ import { CollectionsTable } from './content/collection.ts';
|
|
|
5
5
|
import { IdSetsTable } from './content/id-set.ts';
|
|
6
6
|
import { PropertiesTable } from './content/properties.ts';
|
|
7
7
|
import { TableCfgRef, TablesCfgTable } from './content/table-cfg.ts';
|
|
8
|
-
import { ContentType, Ref,
|
|
8
|
+
import { ContentType, Ref, TableKey } from './typedefs.ts';
|
|
9
9
|
export declare const reservedFieldNames: string[];
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const reservedTableKeys: string[];
|
|
11
11
|
/**
|
|
12
12
|
* One of the supported Rljson table types
|
|
13
13
|
*/
|
|
14
14
|
export type TableType = BuffetsTable | PropertiesTable<any> | CollectionsTable | IdSetsTable | CakesTable;
|
|
15
15
|
/** The rljson data format */
|
|
16
16
|
export interface Rljson extends Json {
|
|
17
|
-
[tableId:
|
|
17
|
+
[tableId: TableKey]: TableType;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Rljson set with private fields
|
|
@@ -58,4 +58,4 @@ export interface RljsonTable<Data extends Json, Type extends ContentType> extend
|
|
|
58
58
|
* @param rljson - The Rljson object to iterate
|
|
59
59
|
* @param callback - The callback to call for each table
|
|
60
60
|
*/
|
|
61
|
-
export declare const iterateTables: (rljson: Rljson, callback: (
|
|
61
|
+
export declare const iterateTables: (rljson: Rljson, callback: (tableKey: string, table: TableType) => void) => void;
|
package/dist/rljson.js
CHANGED
|
@@ -163,39 +163,39 @@ __publicField(_Example, "ok", {
|
|
|
163
163
|
_data: [
|
|
164
164
|
{
|
|
165
165
|
_hash: "",
|
|
166
|
-
|
|
166
|
+
key: "table",
|
|
167
167
|
type: "properties",
|
|
168
168
|
columns: {
|
|
169
169
|
int: {
|
|
170
|
-
|
|
170
|
+
key: "int",
|
|
171
171
|
type: "number"
|
|
172
172
|
},
|
|
173
173
|
double: {
|
|
174
|
-
|
|
174
|
+
key: "double",
|
|
175
175
|
type: "number"
|
|
176
176
|
},
|
|
177
177
|
string: {
|
|
178
|
-
|
|
178
|
+
key: "string",
|
|
179
179
|
type: "string"
|
|
180
180
|
},
|
|
181
181
|
boolean: {
|
|
182
|
-
|
|
182
|
+
key: "boolean",
|
|
183
183
|
type: "boolean"
|
|
184
184
|
},
|
|
185
185
|
null: {
|
|
186
|
-
|
|
186
|
+
key: "null",
|
|
187
187
|
type: "null"
|
|
188
188
|
},
|
|
189
189
|
jsonArray: {
|
|
190
|
-
|
|
190
|
+
key: "jsonArray",
|
|
191
191
|
type: "jsonArray"
|
|
192
192
|
},
|
|
193
193
|
json: {
|
|
194
|
-
|
|
194
|
+
key: "json",
|
|
195
195
|
type: "json"
|
|
196
196
|
},
|
|
197
197
|
jsonValue: {
|
|
198
|
-
|
|
198
|
+
key: "jsonValue",
|
|
199
199
|
type: "jsonValue"
|
|
200
200
|
}
|
|
201
201
|
}
|
|
@@ -341,7 +341,7 @@ __publicField(_Example, "ok", {
|
|
|
341
341
|
});
|
|
342
342
|
__publicField(_Example, "broken", {
|
|
343
343
|
base: {
|
|
344
|
-
|
|
344
|
+
brokenTableKey: () => {
|
|
345
345
|
return {
|
|
346
346
|
brok$en: {
|
|
347
347
|
_type: "properties",
|
|
@@ -502,15 +502,15 @@ const rljsonIndexed = (rljson) => {
|
|
|
502
502
|
};
|
|
503
503
|
// @license
|
|
504
504
|
const reservedFieldNames = ["_type", "_data"];
|
|
505
|
-
const
|
|
505
|
+
const reservedTableKeys = ["_hash", "idSets", "tableCfgs"];
|
|
506
506
|
const exampleRljson = () => Example.ok.singleRow();
|
|
507
507
|
const iterateTables = (rljson, callback) => {
|
|
508
|
-
for (const
|
|
509
|
-
const value = rljson[
|
|
508
|
+
for (const tableKey in rljson) {
|
|
509
|
+
const value = rljson[tableKey];
|
|
510
510
|
if (typeof value !== "object" || !Array.isArray(value._data)) {
|
|
511
511
|
continue;
|
|
512
512
|
}
|
|
513
|
-
callback(
|
|
513
|
+
callback(tableKey, rljson[tableKey]);
|
|
514
514
|
}
|
|
515
515
|
};
|
|
516
516
|
// @license
|
|
@@ -525,7 +525,7 @@ const exampleTypedefs = () => {
|
|
|
525
525
|
return {
|
|
526
526
|
ref: "ref",
|
|
527
527
|
itemId: "itemId",
|
|
528
|
-
|
|
528
|
+
tableKey: "tableKey",
|
|
529
529
|
contentType: "collections"
|
|
530
530
|
};
|
|
531
531
|
};
|
|
@@ -550,10 +550,10 @@ class _BaseValidator {
|
|
|
550
550
|
// ######################
|
|
551
551
|
// Private
|
|
552
552
|
// ######################
|
|
553
|
-
__publicField(this, "
|
|
553
|
+
__publicField(this, "tableKeys");
|
|
554
554
|
__publicField(this, "rljsonIndexed");
|
|
555
555
|
this.rljson = rljson;
|
|
556
|
-
this.
|
|
556
|
+
this.tableKeys = Object.keys(this.rljson).filter(
|
|
557
557
|
(table) => !table.startsWith("_")
|
|
558
558
|
);
|
|
559
559
|
this.rljsonIndexed = rljsonIndexed(rljson);
|
|
@@ -565,14 +565,14 @@ class _BaseValidator {
|
|
|
565
565
|
const steps = [
|
|
566
566
|
// Base checks
|
|
567
567
|
() => this._writeAndValidHashes(),
|
|
568
|
-
() => this.
|
|
569
|
-
() => this.
|
|
568
|
+
() => this._tableKeysNotLowerCamelCase(),
|
|
569
|
+
() => this._tableKeysDoNotEndWithRef(),
|
|
570
570
|
() => this._columnNamesNotLowerCamelCase(),
|
|
571
571
|
() => this._dataNotFound(),
|
|
572
572
|
() => this._dataHasWrongType(),
|
|
573
573
|
() => this._invalidTableTypes(),
|
|
574
574
|
// Check table cfg
|
|
575
|
-
() => this.
|
|
575
|
+
() => this._tableCfgsReferencedTableKeyNotFound(),
|
|
576
576
|
() => this._tableCfgsHaveWrongType(),
|
|
577
577
|
() => this._tableCfgNotFound(),
|
|
578
578
|
() => this._missingColumnConfigs(),
|
|
@@ -599,32 +599,32 @@ class _BaseValidator {
|
|
|
599
599
|
this.errors.hasErrors = this.hasErrors;
|
|
600
600
|
return this.errors;
|
|
601
601
|
}
|
|
602
|
-
|
|
603
|
-
const
|
|
604
|
-
for (const
|
|
605
|
-
if (!BaseValidator.isValidFieldName(
|
|
606
|
-
|
|
602
|
+
_tableKeysNotLowerCamelCase() {
|
|
603
|
+
const invalidTableKeys = [];
|
|
604
|
+
for (const tableKey of this.tableKeys) {
|
|
605
|
+
if (!BaseValidator.isValidFieldName(tableKey)) {
|
|
606
|
+
invalidTableKeys.push(tableKey);
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
|
-
if (
|
|
610
|
-
this.errors.
|
|
609
|
+
if (invalidTableKeys.length > 0) {
|
|
610
|
+
this.errors.tableKeysNotLowerCamelCase = {
|
|
611
611
|
error: "Table names must be lower camel case",
|
|
612
|
-
|
|
612
|
+
invalidTableKeys
|
|
613
613
|
};
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
616
|
// ...........................................................................
|
|
617
|
-
|
|
618
|
-
const
|
|
619
|
-
for (const
|
|
620
|
-
if (
|
|
621
|
-
|
|
617
|
+
_tableKeysDoNotEndWithRef() {
|
|
618
|
+
const invalidTableKeys = [];
|
|
619
|
+
for (const tableKey of this.tableKeys) {
|
|
620
|
+
if (tableKey.endsWith("Ref")) {
|
|
621
|
+
invalidTableKeys.push(tableKey);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
if (
|
|
625
|
-
this.errors.
|
|
624
|
+
if (invalidTableKeys.length > 0) {
|
|
625
|
+
this.errors.tableKeysDoNotEndWithRef = {
|
|
626
626
|
error: 'Table names must not end with "Ref"',
|
|
627
|
-
|
|
627
|
+
invalidTableKeys
|
|
628
628
|
};
|
|
629
629
|
}
|
|
630
630
|
}
|
|
@@ -632,8 +632,8 @@ class _BaseValidator {
|
|
|
632
632
|
_columnNamesNotLowerCamelCase() {
|
|
633
633
|
const invalidColumnNames = {};
|
|
634
634
|
let hadErrors = false;
|
|
635
|
-
for (const
|
|
636
|
-
const table = this.rljson[
|
|
635
|
+
for (const tableKey of this.tableKeys) {
|
|
636
|
+
const table = this.rljson[tableKey];
|
|
637
637
|
if (!table._data || !Array.isArray(table._data)) {
|
|
638
638
|
continue;
|
|
639
639
|
}
|
|
@@ -643,8 +643,8 @@ class _BaseValidator {
|
|
|
643
643
|
continue;
|
|
644
644
|
}
|
|
645
645
|
if (!BaseValidator.isValidFieldName(columnName)) {
|
|
646
|
-
invalidColumnNames[
|
|
647
|
-
invalidColumnNames[
|
|
646
|
+
invalidColumnNames[tableKey] ?? (invalidColumnNames[tableKey] = []);
|
|
647
|
+
invalidColumnNames[tableKey].push(columnName);
|
|
648
648
|
hadErrors = true;
|
|
649
649
|
}
|
|
650
650
|
}
|
|
@@ -682,7 +682,7 @@ class _BaseValidator {
|
|
|
682
682
|
_dataNotFound() {
|
|
683
683
|
const rljson = this.rljson;
|
|
684
684
|
const tablesWithMissingData = [];
|
|
685
|
-
for (const table of this.
|
|
685
|
+
for (const table of this.tableKeys) {
|
|
686
686
|
const tableData = rljson[table];
|
|
687
687
|
const items = tableData["_data"];
|
|
688
688
|
if (items == null) {
|
|
@@ -697,23 +697,23 @@ class _BaseValidator {
|
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
// ...........................................................................
|
|
700
|
-
|
|
700
|
+
_tableCfgsReferencedTableKeyNotFound() {
|
|
701
701
|
const tableCfgs = this.rljson.tableCfgs;
|
|
702
702
|
if (!tableCfgs) {
|
|
703
703
|
return;
|
|
704
704
|
}
|
|
705
705
|
const brokenCfgs = [];
|
|
706
706
|
for (const item of tableCfgs._data) {
|
|
707
|
-
const table = this.rljson[item.
|
|
707
|
+
const table = this.rljson[item.key];
|
|
708
708
|
if (!table) {
|
|
709
709
|
brokenCfgs.push({
|
|
710
710
|
brokenTableCfg: item._hash,
|
|
711
|
-
|
|
711
|
+
tableKeyNotFound: item.key
|
|
712
712
|
});
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
715
|
if (brokenCfgs.length > 0) {
|
|
716
|
-
this.errors.
|
|
716
|
+
this.errors.tableCfgsReferencedTableKeyNotFound = {
|
|
717
717
|
error: "Tables referenced in tableCfgs not found",
|
|
718
718
|
brokenCfgs
|
|
719
719
|
};
|
|
@@ -752,7 +752,7 @@ class _BaseValidator {
|
|
|
752
752
|
_tableCfgNotFound() {
|
|
753
753
|
const tableCfgs = this.rljsonIndexed.tableCfgs;
|
|
754
754
|
const tableCfgNotFound = [];
|
|
755
|
-
iterateTables(this.rljson, (
|
|
755
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
756
756
|
const tableCfgRef = table._tableCfg;
|
|
757
757
|
if (!tableCfgRef) {
|
|
758
758
|
return;
|
|
@@ -760,7 +760,7 @@ class _BaseValidator {
|
|
|
760
760
|
const tableCfgData = tableCfgs._data[tableCfgRef];
|
|
761
761
|
if (!tableCfgData) {
|
|
762
762
|
tableCfgNotFound.push({
|
|
763
|
-
tableWithBrokenTableCfgRef:
|
|
763
|
+
tableWithBrokenTableCfgRef: tableKey,
|
|
764
764
|
brokenTableCfgRef: tableCfgRef
|
|
765
765
|
});
|
|
766
766
|
return;
|
|
@@ -777,7 +777,7 @@ class _BaseValidator {
|
|
|
777
777
|
_missingColumnConfigs() {
|
|
778
778
|
const tableCfgs = this.rljsonIndexed.tableCfgs;
|
|
779
779
|
const missingColumnConfigs = [];
|
|
780
|
-
iterateTables(this.rljson, (
|
|
780
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
781
781
|
const tableCfgRef = table._tableCfg;
|
|
782
782
|
if (!tableCfgRef) {
|
|
783
783
|
return;
|
|
@@ -798,7 +798,7 @@ class _BaseValidator {
|
|
|
798
798
|
tableCfg: tableCfgRef,
|
|
799
799
|
row: row._hash,
|
|
800
800
|
column: columnKey,
|
|
801
|
-
table:
|
|
801
|
+
table: tableKey
|
|
802
802
|
});
|
|
803
803
|
}
|
|
804
804
|
processedColumnKeys.push(columnKey);
|
|
@@ -816,7 +816,7 @@ class _BaseValidator {
|
|
|
816
816
|
_dataDoesNotMatchColumnConfig() {
|
|
817
817
|
const tableCfgs = this.rljsonIndexed.tableCfgs;
|
|
818
818
|
const brokenValues = [];
|
|
819
|
-
iterateTables(this.rljson, (
|
|
819
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
820
820
|
const tableCfgRef = table._tableCfg;
|
|
821
821
|
if (!tableCfgRef) {
|
|
822
822
|
return;
|
|
@@ -836,7 +836,7 @@ class _BaseValidator {
|
|
|
836
836
|
const typeShould = columnConfig.type;
|
|
837
837
|
if (!jsonValueMatchesType(value, typeShould)) {
|
|
838
838
|
brokenValues.push({
|
|
839
|
-
table:
|
|
839
|
+
table: tableKey,
|
|
840
840
|
row: row._hash,
|
|
841
841
|
column: columnKey,
|
|
842
842
|
tableCfg: tableCfgRef
|
|
@@ -856,8 +856,8 @@ class _BaseValidator {
|
|
|
856
856
|
_tableTypesDoNotMatch() {
|
|
857
857
|
const rljson = this.rljson;
|
|
858
858
|
const tablesWithTypeMissmatch = [];
|
|
859
|
-
for (const
|
|
860
|
-
const table = rljson[
|
|
859
|
+
for (const tableKey of this.tableKeys) {
|
|
860
|
+
const table = rljson[tableKey];
|
|
861
861
|
const cfgRef = table._tableCfg;
|
|
862
862
|
if (!cfgRef) {
|
|
863
863
|
continue;
|
|
@@ -867,7 +867,7 @@ class _BaseValidator {
|
|
|
867
867
|
const typeIs = table._type;
|
|
868
868
|
if (typeShould !== typeIs) {
|
|
869
869
|
tablesWithTypeMissmatch.push({
|
|
870
|
-
table:
|
|
870
|
+
table: tableKey,
|
|
871
871
|
typeInTable: typeIs,
|
|
872
872
|
typeInConfig: typeShould,
|
|
873
873
|
tableCfg: cfgRef
|
|
@@ -885,11 +885,11 @@ class _BaseValidator {
|
|
|
885
885
|
_dataHasWrongType() {
|
|
886
886
|
const rljson = this.rljson;
|
|
887
887
|
const tablesWithWrongType = [];
|
|
888
|
-
for (const
|
|
889
|
-
const tableData = rljson[
|
|
888
|
+
for (const tableKey of this.tableKeys) {
|
|
889
|
+
const tableData = rljson[tableKey];
|
|
890
890
|
const items = tableData["_data"];
|
|
891
891
|
if (!Array.isArray(items)) {
|
|
892
|
-
tablesWithWrongType.push(
|
|
892
|
+
tablesWithWrongType.push(tableKey);
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
895
|
if (tablesWithWrongType.length > 0) {
|
|
@@ -903,12 +903,12 @@ class _BaseValidator {
|
|
|
903
903
|
_invalidTableTypes() {
|
|
904
904
|
const rljson = this.rljson;
|
|
905
905
|
const tablesWithWrongType = [];
|
|
906
|
-
for (const
|
|
907
|
-
const table = rljson[
|
|
906
|
+
for (const tableKey of this.tableKeys) {
|
|
907
|
+
const table = rljson[tableKey];
|
|
908
908
|
const type = table._type;
|
|
909
909
|
if (contentTypes.indexOf(type) === -1) {
|
|
910
910
|
tablesWithWrongType.push({
|
|
911
|
-
table:
|
|
911
|
+
table: tableKey,
|
|
912
912
|
type,
|
|
913
913
|
allowedTypes: contentTypes.join(" | ")
|
|
914
914
|
});
|
|
@@ -923,35 +923,35 @@ class _BaseValidator {
|
|
|
923
923
|
}
|
|
924
924
|
_refsNotFound() {
|
|
925
925
|
const missingRefs = [];
|
|
926
|
-
iterateTables(this.rljson, (
|
|
926
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
927
927
|
const tableData = table._data;
|
|
928
928
|
for (const item of tableData) {
|
|
929
929
|
for (const key of Object.keys(item)) {
|
|
930
930
|
if (key.endsWith("Ref")) {
|
|
931
931
|
const targetItemHash = item[key];
|
|
932
|
-
const
|
|
932
|
+
const targetTableKey = key.substring(0, key.length - 3);
|
|
933
933
|
const itemHash = item._hash;
|
|
934
|
-
if (this.
|
|
934
|
+
if (this.tableKeys.indexOf(targetTableKey) === -1) {
|
|
935
935
|
missingRefs.push({
|
|
936
|
-
error: `Target table "${
|
|
937
|
-
sourceTable:
|
|
936
|
+
error: `Target table "${targetTableKey}" not found.`,
|
|
937
|
+
sourceTable: tableKey,
|
|
938
938
|
sourceKey: key,
|
|
939
939
|
sourceItemHash: itemHash,
|
|
940
940
|
targetItemHash,
|
|
941
|
-
targetTable:
|
|
941
|
+
targetTable: targetTableKey
|
|
942
942
|
});
|
|
943
943
|
continue;
|
|
944
944
|
}
|
|
945
|
-
const targetTableIndexed = this.rljsonIndexed[
|
|
945
|
+
const targetTableIndexed = this.rljsonIndexed[targetTableKey];
|
|
946
946
|
const referencedItem = targetTableIndexed._data[targetItemHash];
|
|
947
947
|
if (referencedItem === void 0) {
|
|
948
948
|
missingRefs.push({
|
|
949
|
-
sourceTable:
|
|
949
|
+
sourceTable: tableKey,
|
|
950
950
|
sourceItemHash: itemHash,
|
|
951
951
|
sourceKey: key,
|
|
952
952
|
targetItemHash,
|
|
953
|
-
targetTable:
|
|
954
|
-
error: `Table "${
|
|
953
|
+
targetTable: targetTableKey,
|
|
954
|
+
error: `Table "${targetTableKey}" has no item with hash "${targetItemHash}"`
|
|
955
955
|
});
|
|
956
956
|
}
|
|
957
957
|
}
|
|
@@ -967,11 +967,11 @@ class _BaseValidator {
|
|
|
967
967
|
}
|
|
968
968
|
_collectionBasesNotFound() {
|
|
969
969
|
const brokenCollections = [];
|
|
970
|
-
iterateTables(this.rljson, (
|
|
970
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
971
971
|
if (table._type !== "collections") {
|
|
972
972
|
return;
|
|
973
973
|
}
|
|
974
|
-
const collectionsIndexed = this.rljsonIndexed[
|
|
974
|
+
const collectionsIndexed = this.rljsonIndexed[tableKey];
|
|
975
975
|
const collectionsTable = table;
|
|
976
976
|
for (const collection of collectionsTable._data) {
|
|
977
977
|
const baseRef = collection.base;
|
|
@@ -981,7 +981,7 @@ class _BaseValidator {
|
|
|
981
981
|
const baseCollection = collectionsIndexed._data[baseRef];
|
|
982
982
|
if (!baseCollection) {
|
|
983
983
|
brokenCollections.push({
|
|
984
|
-
collectionsTable:
|
|
984
|
+
collectionsTable: tableKey,
|
|
985
985
|
brokenCollection: collection._hash,
|
|
986
986
|
missingBaseCollection: baseRef
|
|
987
987
|
});
|
|
@@ -997,7 +997,7 @@ class _BaseValidator {
|
|
|
997
997
|
}
|
|
998
998
|
_collectionIdSetsExist() {
|
|
999
999
|
const brokenCollections = [];
|
|
1000
|
-
iterateTables(this.rljson, (
|
|
1000
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
1001
1001
|
if (table._type !== "collections") {
|
|
1002
1002
|
return;
|
|
1003
1003
|
}
|
|
@@ -1011,7 +1011,7 @@ class _BaseValidator {
|
|
|
1011
1011
|
const idSet = idSets._data[idSetRef];
|
|
1012
1012
|
if (!idSet) {
|
|
1013
1013
|
brokenCollections.push({
|
|
1014
|
-
collectionsTable:
|
|
1014
|
+
collectionsTable: tableKey,
|
|
1015
1015
|
collectionHash: collection._hash,
|
|
1016
1016
|
missingIdSet: idSetRef
|
|
1017
1017
|
});
|
|
@@ -1028,19 +1028,19 @@ class _BaseValidator {
|
|
|
1028
1028
|
_collectionPropertyAssignmentsNotFound() {
|
|
1029
1029
|
const missingPropertyTables = [];
|
|
1030
1030
|
const brokenAssignments = [];
|
|
1031
|
-
iterateTables(this.rljson, (
|
|
1031
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
1032
1032
|
if (table._type !== "collections") {
|
|
1033
1033
|
return;
|
|
1034
1034
|
}
|
|
1035
1035
|
const collectionsTable = table;
|
|
1036
1036
|
for (const collection of collectionsTable._data) {
|
|
1037
|
-
const
|
|
1038
|
-
const propertiesTable = this.rljsonIndexed[
|
|
1037
|
+
const propertyTableKey = collection.properties;
|
|
1038
|
+
const propertiesTable = this.rljsonIndexed[propertyTableKey];
|
|
1039
1039
|
if (!propertiesTable) {
|
|
1040
1040
|
missingPropertyTables.push({
|
|
1041
1041
|
brokenCollection: collection._hash,
|
|
1042
|
-
collectionsTable:
|
|
1043
|
-
missingPropertyTable:
|
|
1042
|
+
collectionsTable: tableKey,
|
|
1043
|
+
missingPropertyTable: propertyTableKey
|
|
1044
1044
|
});
|
|
1045
1045
|
continue;
|
|
1046
1046
|
}
|
|
@@ -1052,9 +1052,9 @@ class _BaseValidator {
|
|
|
1052
1052
|
const propertyHash = assignments[itemId];
|
|
1053
1053
|
if (!propertiesTable._data[propertyHash]) {
|
|
1054
1054
|
brokenAssignments.push({
|
|
1055
|
-
collectionsTable:
|
|
1055
|
+
collectionsTable: tableKey,
|
|
1056
1056
|
brokenCollection: collection._hash,
|
|
1057
|
-
referencedPropertyTable:
|
|
1057
|
+
referencedPropertyTable: propertyTableKey,
|
|
1058
1058
|
brokenAssignment: itemId,
|
|
1059
1059
|
missingProperty: propertyHash
|
|
1060
1060
|
});
|
|
@@ -1077,7 +1077,7 @@ class _BaseValidator {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
_cakeIdSetsNotFound() {
|
|
1079
1079
|
const brokenCakes = [];
|
|
1080
|
-
iterateTables(this.rljson, (
|
|
1080
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
1081
1081
|
if (table._type !== "cakes") {
|
|
1082
1082
|
return;
|
|
1083
1083
|
}
|
|
@@ -1091,7 +1091,7 @@ class _BaseValidator {
|
|
|
1091
1091
|
const idSet = idSets._data[idSetRef];
|
|
1092
1092
|
if (!idSet) {
|
|
1093
1093
|
brokenCakes.push({
|
|
1094
|
-
cakeTable:
|
|
1094
|
+
cakeTable: tableKey,
|
|
1095
1095
|
brokenCake: cake._hash,
|
|
1096
1096
|
missingIdSet: idSetRef
|
|
1097
1097
|
});
|
|
@@ -1108,19 +1108,19 @@ class _BaseValidator {
|
|
|
1108
1108
|
_cakeCollectionTablesNotFound() {
|
|
1109
1109
|
const missingCollectionTables = [];
|
|
1110
1110
|
const missingLayerCollections = [];
|
|
1111
|
-
iterateTables(this.rljson, (
|
|
1111
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
1112
1112
|
if (table._type !== "cakes") {
|
|
1113
1113
|
return;
|
|
1114
1114
|
}
|
|
1115
1115
|
const cakesTable = table;
|
|
1116
1116
|
for (const cake of cakesTable._data) {
|
|
1117
|
-
const
|
|
1118
|
-
const collectionsTable = this.rljsonIndexed[
|
|
1117
|
+
const collectionsTableKey = cake.collections;
|
|
1118
|
+
const collectionsTable = this.rljsonIndexed[collectionsTableKey];
|
|
1119
1119
|
if (!collectionsTable) {
|
|
1120
1120
|
missingCollectionTables.push({
|
|
1121
|
-
cakeTable:
|
|
1121
|
+
cakeTable: tableKey,
|
|
1122
1122
|
brokenCake: cake._hash,
|
|
1123
|
-
missingCollectionsTable:
|
|
1123
|
+
missingCollectionsTable: collectionsTableKey
|
|
1124
1124
|
});
|
|
1125
1125
|
continue;
|
|
1126
1126
|
}
|
|
@@ -1132,10 +1132,10 @@ class _BaseValidator {
|
|
|
1132
1132
|
const collection = collectionsTable._data[collectionRef];
|
|
1133
1133
|
if (!collection) {
|
|
1134
1134
|
missingLayerCollections.push({
|
|
1135
|
-
cakeTable:
|
|
1135
|
+
cakeTable: tableKey,
|
|
1136
1136
|
brokenCake: cake._hash,
|
|
1137
1137
|
brokenLayerName: layer,
|
|
1138
|
-
collectionsTable:
|
|
1138
|
+
collectionsTable: collectionsTableKey,
|
|
1139
1139
|
missingCollection: collectionRef
|
|
1140
1140
|
});
|
|
1141
1141
|
}
|
|
@@ -1158,20 +1158,20 @@ class _BaseValidator {
|
|
|
1158
1158
|
_buffetReferencedTableNotFound() {
|
|
1159
1159
|
const missingTables = [];
|
|
1160
1160
|
const missingItems = [];
|
|
1161
|
-
iterateTables(this.rljson, (
|
|
1161
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
1162
1162
|
if (table._type !== "buffets") {
|
|
1163
1163
|
return;
|
|
1164
1164
|
}
|
|
1165
1165
|
const buffetsTable = table;
|
|
1166
1166
|
for (const buffet of buffetsTable._data) {
|
|
1167
1167
|
for (const item of buffet.items) {
|
|
1168
|
-
const
|
|
1169
|
-
const itemTable = this.rljsonIndexed[
|
|
1168
|
+
const itemTableKey = item.table;
|
|
1169
|
+
const itemTable = this.rljsonIndexed[itemTableKey];
|
|
1170
1170
|
if (!itemTable) {
|
|
1171
1171
|
missingTables.push({
|
|
1172
|
-
buffetTable:
|
|
1172
|
+
buffetTable: tableKey,
|
|
1173
1173
|
brokenBuffet: buffet._hash,
|
|
1174
|
-
missingItemTable:
|
|
1174
|
+
missingItemTable: itemTableKey
|
|
1175
1175
|
});
|
|
1176
1176
|
continue;
|
|
1177
1177
|
}
|
|
@@ -1179,9 +1179,9 @@ class _BaseValidator {
|
|
|
1179
1179
|
const referencedItem = itemTable._data[ref];
|
|
1180
1180
|
if (!referencedItem) {
|
|
1181
1181
|
missingItems.push({
|
|
1182
|
-
buffetTable:
|
|
1182
|
+
buffetTable: tableKey,
|
|
1183
1183
|
brokenBuffet: buffet._hash,
|
|
1184
|
-
itemTable:
|
|
1184
|
+
itemTable: itemTableKey,
|
|
1185
1185
|
missingItem: ref
|
|
1186
1186
|
});
|
|
1187
1187
|
}
|
|
@@ -1257,6 +1257,6 @@ export {
|
|
|
1257
1257
|
isValidFieldName,
|
|
1258
1258
|
iterateTables,
|
|
1259
1259
|
reservedFieldNames,
|
|
1260
|
-
|
|
1260
|
+
reservedTableKeys,
|
|
1261
1261
|
rljsonIndexed
|
|
1262
1262
|
};
|
package/dist/src/example.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { TablesCfgTable } from './content/table-cfg.ts';
|
|
|
11
11
|
import { bakeryExample } from './example/bakery-example.ts';
|
|
12
12
|
import { Rljson } from './rljson.ts';
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
export class Example {
|
|
16
15
|
static readonly ok = {
|
|
17
16
|
bakery: (): Rljson => bakeryExample(),
|
|
@@ -41,39 +40,39 @@ export class Example {
|
|
|
41
40
|
_data: [
|
|
42
41
|
{
|
|
43
42
|
_hash: '',
|
|
44
|
-
|
|
43
|
+
key: 'table',
|
|
45
44
|
type: 'properties',
|
|
46
45
|
columns: {
|
|
47
46
|
int: {
|
|
48
|
-
|
|
47
|
+
key: 'int',
|
|
49
48
|
type: 'number',
|
|
50
49
|
},
|
|
51
50
|
double: {
|
|
52
|
-
|
|
51
|
+
key: 'double',
|
|
53
52
|
type: 'number',
|
|
54
53
|
},
|
|
55
54
|
string: {
|
|
56
|
-
|
|
55
|
+
key: 'string',
|
|
57
56
|
type: 'string',
|
|
58
57
|
},
|
|
59
58
|
boolean: {
|
|
60
|
-
|
|
59
|
+
key: 'boolean',
|
|
61
60
|
type: 'boolean',
|
|
62
61
|
},
|
|
63
62
|
null: {
|
|
64
|
-
|
|
63
|
+
key: 'null',
|
|
65
64
|
type: 'null',
|
|
66
65
|
},
|
|
67
66
|
jsonArray: {
|
|
68
|
-
|
|
67
|
+
key: 'jsonArray',
|
|
69
68
|
type: 'jsonArray',
|
|
70
69
|
},
|
|
71
70
|
json: {
|
|
72
|
-
|
|
71
|
+
key: 'json',
|
|
73
72
|
type: 'json',
|
|
74
73
|
},
|
|
75
74
|
jsonValue: {
|
|
76
|
-
|
|
75
|
+
key: 'jsonValue',
|
|
77
76
|
type: 'jsonValue',
|
|
78
77
|
},
|
|
79
78
|
},
|
|
@@ -230,7 +229,7 @@ export class Example {
|
|
|
230
229
|
|
|
231
230
|
static readonly broken = {
|
|
232
231
|
base: {
|
|
233
|
-
|
|
232
|
+
brokenTableKey: () => {
|
|
234
233
|
return {
|
|
235
234
|
brok$en: {
|
|
236
235
|
_type: 'properties',
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonKey } from '@rljson/json';
|
|
1
2
|
/**
|
|
2
3
|
* A ref is a hash that references to another element
|
|
3
4
|
*/
|
|
@@ -11,7 +12,11 @@ export type ItemId = string;
|
|
|
11
12
|
* A table id reference to a table. The table ids are used as keys in the top
|
|
12
13
|
* level structure of an Rljson data object.
|
|
13
14
|
*/
|
|
14
|
-
export type
|
|
15
|
+
export type TableKey = JsonKey;
|
|
16
|
+
/**
|
|
17
|
+
* A column key is a key that references a column in a table
|
|
18
|
+
*/
|
|
19
|
+
export type ColumnKey = JsonKey;
|
|
15
20
|
/**
|
|
16
21
|
* Types of tables that can be stored in an Rljson object
|
|
17
22
|
*
|
|
@@ -29,6 +34,6 @@ export type ContentType = (typeof contentTypes)[number];
|
|
|
29
34
|
export declare const exampleTypedefs: () => {
|
|
30
35
|
ref: Ref;
|
|
31
36
|
itemId: ItemId;
|
|
32
|
-
|
|
37
|
+
tableKey: TableKey;
|
|
33
38
|
contentType: ContentType;
|
|
34
39
|
};
|
|
@@ -2,15 +2,15 @@ import { Json } from '@rljson/json';
|
|
|
2
2
|
import { Rljson } from '../rljson.ts';
|
|
3
3
|
import { Errors, Validator } from './validate.ts';
|
|
4
4
|
export interface BaseErrors extends Errors {
|
|
5
|
-
|
|
5
|
+
tableKeysNotLowerCamelCase?: Json;
|
|
6
6
|
columnNamesNotLowerCamelCase?: Json;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
tableKeysDoNotStartWithANumber?: Json;
|
|
8
|
+
tableKeysDoNotEndWithRef?: Json;
|
|
9
9
|
hashesNotValid?: Json;
|
|
10
10
|
dataNotFound?: Json;
|
|
11
11
|
dataHasWrongType?: Json;
|
|
12
12
|
invalidTableTypes?: Json;
|
|
13
|
-
|
|
13
|
+
tableCfgsReferencedTableKeyNotFound?: Json;
|
|
14
14
|
columnsHaveWrongType?: Json;
|
|
15
15
|
tableCfgReferencedNotFound?: Json;
|
|
16
16
|
columnConfigNotFound?: Json;
|