@rljson/rljson 0.0.21 → 0.0.23
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 +5 -9
- package/dist/rljson.js +80 -35
- package/dist/src/example.ts +6 -21
- package/dist/typedefs.d.ts +2 -1
- package/dist/validate/base-validator.d.ts +3 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Json, JsonKey, JsonValueType } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
|
-
import { Ref } from '../typedefs.ts';
|
|
3
|
+
import { ContentType, Ref } from '../typedefs.ts';
|
|
4
4
|
/**
|
|
5
5
|
* A ColumnsRef is a hash pointing to columns metadata
|
|
6
6
|
*/
|
|
@@ -13,14 +13,6 @@ export interface ColumnCfg extends Json {
|
|
|
13
13
|
* The jsonKey of the column used in data
|
|
14
14
|
*/
|
|
15
15
|
jsonKey: JsonKey;
|
|
16
|
-
/**
|
|
17
|
-
* Average number of characters in the column
|
|
18
|
-
*/
|
|
19
|
-
avgChars?: number;
|
|
20
|
-
/**
|
|
21
|
-
* Maximum number of characters in the column
|
|
22
|
-
*/
|
|
23
|
-
maxChars?: number;
|
|
24
16
|
/**
|
|
25
17
|
* The type of the column
|
|
26
18
|
*/
|
|
@@ -38,6 +30,10 @@ export interface TableCfg extends Json {
|
|
|
38
30
|
* A short description of the table
|
|
39
31
|
*/
|
|
40
32
|
columns: Record<JsonKey, ColumnCfg>;
|
|
33
|
+
/**
|
|
34
|
+
* The content type of the table
|
|
35
|
+
*/
|
|
36
|
+
type: ContentType;
|
|
41
37
|
}
|
|
42
38
|
/**
|
|
43
39
|
* A table containing columns
|
package/dist/rljson.js
CHANGED
|
@@ -157,72 +157,56 @@ __publicField(_Example, "ok", {
|
|
|
157
157
|
};
|
|
158
158
|
},
|
|
159
159
|
singleRow: () => {
|
|
160
|
-
const tableCfgs = {
|
|
160
|
+
const tableCfgs = hip({
|
|
161
161
|
_hash: "",
|
|
162
162
|
_type: "properties",
|
|
163
163
|
_data: [
|
|
164
164
|
{
|
|
165
|
-
_hash: "
|
|
166
|
-
name: "Single Row Table",
|
|
165
|
+
_hash: "",
|
|
167
166
|
jsonKey: "table",
|
|
167
|
+
type: "properties",
|
|
168
168
|
columns: {
|
|
169
169
|
int: {
|
|
170
170
|
jsonKey: "int",
|
|
171
|
-
type: "number"
|
|
172
|
-
name: "Integer",
|
|
173
|
-
nameShort: "Int"
|
|
171
|
+
type: "number"
|
|
174
172
|
},
|
|
175
173
|
double: {
|
|
176
174
|
jsonKey: "double",
|
|
177
|
-
type: "number"
|
|
178
|
-
name: "Double",
|
|
179
|
-
nameShort: "Dbl"
|
|
175
|
+
type: "number"
|
|
180
176
|
},
|
|
181
177
|
string: {
|
|
182
178
|
jsonKey: "string",
|
|
183
|
-
type: "string"
|
|
184
|
-
name: "String",
|
|
185
|
-
nameShort: "Str"
|
|
179
|
+
type: "string"
|
|
186
180
|
},
|
|
187
181
|
boolean: {
|
|
188
182
|
jsonKey: "boolean",
|
|
189
|
-
type: "boolean"
|
|
190
|
-
name: "Boolean",
|
|
191
|
-
nameShort: "Bool"
|
|
183
|
+
type: "boolean"
|
|
192
184
|
},
|
|
193
185
|
null: {
|
|
194
186
|
jsonKey: "null",
|
|
195
|
-
type: "null"
|
|
196
|
-
name: "null",
|
|
197
|
-
nameShort: "null"
|
|
187
|
+
type: "null"
|
|
198
188
|
},
|
|
199
189
|
jsonArray: {
|
|
200
190
|
jsonKey: "jsonArray",
|
|
201
|
-
type: "jsonArray"
|
|
202
|
-
name: "Json Array",
|
|
203
|
-
nameShort: "Jarray"
|
|
191
|
+
type: "jsonArray"
|
|
204
192
|
},
|
|
205
193
|
json: {
|
|
206
194
|
jsonKey: "json",
|
|
207
|
-
type: "json"
|
|
208
|
-
name: "Json",
|
|
209
|
-
nameShort: "Json"
|
|
195
|
+
type: "json"
|
|
210
196
|
},
|
|
211
197
|
jsonValue: {
|
|
212
198
|
jsonKey: "jsonValue",
|
|
213
|
-
type: "jsonValue"
|
|
214
|
-
name: "Json Value",
|
|
215
|
-
nameShort: "Jval"
|
|
199
|
+
type: "jsonValue"
|
|
216
200
|
}
|
|
217
201
|
}
|
|
218
202
|
}
|
|
219
203
|
]
|
|
220
|
-
};
|
|
204
|
+
});
|
|
221
205
|
const result = {
|
|
222
206
|
tableCfgs,
|
|
223
207
|
table: {
|
|
224
208
|
_type: "properties",
|
|
225
|
-
_tableCfg:
|
|
209
|
+
_tableCfg: tableCfgs._data[0]._hash,
|
|
226
210
|
_data: [exampleJsonObject()],
|
|
227
211
|
_hash: ""
|
|
228
212
|
}
|
|
@@ -518,7 +502,7 @@ const rljsonIndexed = (rljson) => {
|
|
|
518
502
|
};
|
|
519
503
|
// @license
|
|
520
504
|
const reservedFieldNames = ["_type", "_data"];
|
|
521
|
-
const reservedTableNames = ["_hash", "
|
|
505
|
+
const reservedTableNames = ["_hash", "idSets", "tableCfgs"];
|
|
522
506
|
const exampleRljson = () => Example.ok.singleRow();
|
|
523
507
|
const iterateTables = (rljson, callback) => {
|
|
524
508
|
for (const tableName in rljson) {
|
|
@@ -530,6 +514,13 @@ const iterateTables = (rljson, callback) => {
|
|
|
530
514
|
}
|
|
531
515
|
};
|
|
532
516
|
// @license
|
|
517
|
+
const contentTypes = [
|
|
518
|
+
"buffets",
|
|
519
|
+
"cakes",
|
|
520
|
+
"collections",
|
|
521
|
+
"idSets",
|
|
522
|
+
"properties"
|
|
523
|
+
];
|
|
533
524
|
const exampleTypedefs = () => {
|
|
534
525
|
return {
|
|
535
526
|
ref: "ref",
|
|
@@ -579,12 +570,14 @@ class _BaseValidator {
|
|
|
579
570
|
() => this._columnNamesNotLowerCamelCase(),
|
|
580
571
|
() => this._dataNotFound(),
|
|
581
572
|
() => this._dataHasWrongType(),
|
|
573
|
+
() => this._invalidTableTypes(),
|
|
582
574
|
// Check table cfg
|
|
583
|
-
() => this.
|
|
584
|
-
() => this.
|
|
575
|
+
() => this._tableCfgsReferencedTableNameNotFound(),
|
|
576
|
+
() => this._tableCfgsHaveWrongType(),
|
|
585
577
|
() => this._tableCfgNotFound(),
|
|
586
578
|
() => this._missingColumnConfigs(),
|
|
587
579
|
() => this._dataDoesNotMatchColumnConfig(),
|
|
580
|
+
() => this._tableTypesDoNotMatch(),
|
|
588
581
|
// Check references
|
|
589
582
|
() => this._refsNotFound(),
|
|
590
583
|
// Check collections
|
|
@@ -704,7 +697,7 @@ class _BaseValidator {
|
|
|
704
697
|
}
|
|
705
698
|
}
|
|
706
699
|
// ...........................................................................
|
|
707
|
-
|
|
700
|
+
_tableCfgsReferencedTableNameNotFound() {
|
|
708
701
|
const tableCfgs = this.rljson.tableCfgs;
|
|
709
702
|
if (!tableCfgs) {
|
|
710
703
|
return;
|
|
@@ -727,7 +720,7 @@ class _BaseValidator {
|
|
|
727
720
|
}
|
|
728
721
|
}
|
|
729
722
|
// ...........................................................................
|
|
730
|
-
|
|
723
|
+
_tableCfgsHaveWrongType() {
|
|
731
724
|
const tableCfgs = this.rljson.tableCfgs;
|
|
732
725
|
if (!tableCfgs) {
|
|
733
726
|
return;
|
|
@@ -749,7 +742,7 @@ class _BaseValidator {
|
|
|
749
742
|
}
|
|
750
743
|
}
|
|
751
744
|
if (brokenCfgs.length > 0) {
|
|
752
|
-
this.errors.
|
|
745
|
+
this.errors.columnsHaveWrongType = {
|
|
753
746
|
error: "Some of the columns have invalid types. Valid types are: " + jsonValueTypes.join(", "),
|
|
754
747
|
brokenCfgs
|
|
755
748
|
};
|
|
@@ -860,6 +853,35 @@ class _BaseValidator {
|
|
|
860
853
|
}
|
|
861
854
|
}
|
|
862
855
|
// ...........................................................................
|
|
856
|
+
_tableTypesDoNotMatch() {
|
|
857
|
+
const rljson = this.rljson;
|
|
858
|
+
const tablesWithTypeMissmatch = [];
|
|
859
|
+
for (const tableName of this.tableNames) {
|
|
860
|
+
const table = rljson[tableName];
|
|
861
|
+
const cfgRef = table._tableCfg;
|
|
862
|
+
if (!cfgRef) {
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
const cfg = this.rljsonIndexed.tableCfgs._data[cfgRef];
|
|
866
|
+
const typeShould = cfg.type;
|
|
867
|
+
const typeIs = table._type;
|
|
868
|
+
if (typeShould !== typeIs) {
|
|
869
|
+
tablesWithTypeMissmatch.push({
|
|
870
|
+
table: tableName,
|
|
871
|
+
typeInTable: typeIs,
|
|
872
|
+
typeInConfig: typeShould,
|
|
873
|
+
tableCfg: cfgRef
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (tablesWithTypeMissmatch.length > 0) {
|
|
878
|
+
this.errors.tableTypesDoNotMatch = {
|
|
879
|
+
error: "Table types do not match table config",
|
|
880
|
+
tables: tablesWithTypeMissmatch
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
// ...........................................................................
|
|
863
885
|
_dataHasWrongType() {
|
|
864
886
|
const rljson = this.rljson;
|
|
865
887
|
const tablesWithWrongType = [];
|
|
@@ -877,6 +899,28 @@ class _BaseValidator {
|
|
|
877
899
|
};
|
|
878
900
|
}
|
|
879
901
|
}
|
|
902
|
+
// ...........................................................................
|
|
903
|
+
_invalidTableTypes() {
|
|
904
|
+
const rljson = this.rljson;
|
|
905
|
+
const tablesWithWrongType = [];
|
|
906
|
+
for (const tableName of this.tableNames) {
|
|
907
|
+
const table = rljson[tableName];
|
|
908
|
+
const type = table._type;
|
|
909
|
+
if (contentTypes.indexOf(type) === -1) {
|
|
910
|
+
tablesWithWrongType.push({
|
|
911
|
+
table: tableName,
|
|
912
|
+
type,
|
|
913
|
+
allowedTypes: contentTypes.join(" | ")
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (tablesWithWrongType.length > 0) {
|
|
918
|
+
this.errors.invalidTableTypes = {
|
|
919
|
+
error: "Tables with invalid types",
|
|
920
|
+
tables: tablesWithWrongType
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
}
|
|
880
924
|
_refsNotFound() {
|
|
881
925
|
const missingRefs = [];
|
|
882
926
|
iterateTables(this.rljson, (tableName, table) => {
|
|
@@ -1201,6 +1245,7 @@ export {
|
|
|
1201
1245
|
Example,
|
|
1202
1246
|
Validate,
|
|
1203
1247
|
bakeryExample,
|
|
1248
|
+
contentTypes,
|
|
1204
1249
|
exampleBuffetsTable,
|
|
1205
1250
|
exampleCakesTable,
|
|
1206
1251
|
exampleCollectionsTable,
|
package/dist/src/example.ts
CHANGED
|
@@ -11,6 +11,7 @@ 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
|
+
|
|
14
15
|
export class Example {
|
|
15
16
|
static readonly ok = {
|
|
16
17
|
bakery: (): Rljson => bakeryExample(),
|
|
@@ -34,73 +35,57 @@ export class Example {
|
|
|
34
35
|
},
|
|
35
36
|
|
|
36
37
|
singleRow: (): Rljson => {
|
|
37
|
-
const tableCfgs: TablesCfgTable = {
|
|
38
|
+
const tableCfgs: TablesCfgTable = hip({
|
|
38
39
|
_hash: '',
|
|
39
40
|
_type: 'properties',
|
|
40
41
|
_data: [
|
|
41
42
|
{
|
|
42
|
-
_hash: '
|
|
43
|
-
name: 'Single Row Table',
|
|
43
|
+
_hash: '',
|
|
44
44
|
jsonKey: 'table',
|
|
45
|
+
type: 'properties',
|
|
45
46
|
columns: {
|
|
46
47
|
int: {
|
|
47
48
|
jsonKey: 'int',
|
|
48
49
|
type: 'number',
|
|
49
|
-
name: 'Integer',
|
|
50
|
-
nameShort: 'Int',
|
|
51
50
|
},
|
|
52
51
|
double: {
|
|
53
52
|
jsonKey: 'double',
|
|
54
53
|
type: 'number',
|
|
55
|
-
name: 'Double',
|
|
56
|
-
nameShort: 'Dbl',
|
|
57
54
|
},
|
|
58
55
|
string: {
|
|
59
56
|
jsonKey: 'string',
|
|
60
57
|
type: 'string',
|
|
61
|
-
name: 'String',
|
|
62
|
-
nameShort: 'Str',
|
|
63
58
|
},
|
|
64
59
|
boolean: {
|
|
65
60
|
jsonKey: 'boolean',
|
|
66
61
|
type: 'boolean',
|
|
67
|
-
name: 'Boolean',
|
|
68
|
-
nameShort: 'Bool',
|
|
69
62
|
},
|
|
70
63
|
null: {
|
|
71
64
|
jsonKey: 'null',
|
|
72
65
|
type: 'null',
|
|
73
|
-
name: 'null',
|
|
74
|
-
nameShort: 'null',
|
|
75
66
|
},
|
|
76
67
|
jsonArray: {
|
|
77
68
|
jsonKey: 'jsonArray',
|
|
78
69
|
type: 'jsonArray',
|
|
79
|
-
name: 'Json Array',
|
|
80
|
-
nameShort: 'Jarray',
|
|
81
70
|
},
|
|
82
71
|
json: {
|
|
83
72
|
jsonKey: 'json',
|
|
84
73
|
type: 'json',
|
|
85
|
-
name: 'Json',
|
|
86
|
-
nameShort: 'Json',
|
|
87
74
|
},
|
|
88
75
|
jsonValue: {
|
|
89
76
|
jsonKey: 'jsonValue',
|
|
90
77
|
type: 'jsonValue',
|
|
91
|
-
name: 'Json Value',
|
|
92
|
-
nameShort: 'Jval',
|
|
93
78
|
},
|
|
94
79
|
},
|
|
95
80
|
},
|
|
96
81
|
],
|
|
97
|
-
};
|
|
82
|
+
});
|
|
98
83
|
|
|
99
84
|
const result: Rljson = {
|
|
100
85
|
tableCfgs: tableCfgs,
|
|
101
86
|
table: {
|
|
102
87
|
_type: 'properties',
|
|
103
|
-
_tableCfg:
|
|
88
|
+
_tableCfg: tableCfgs._data[0]._hash as string,
|
|
104
89
|
_data: [exampleJsonObject()],
|
|
105
90
|
_hash: '',
|
|
106
91
|
},
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export type TableName = ItemId;
|
|
|
21
21
|
* - `ids` Tables containing item ids
|
|
22
22
|
* - `properties` Tables containing item properties
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
24
|
+
export declare const contentTypes: readonly ["buffets", "cakes", "collections", "idSets", "properties"];
|
|
25
|
+
export type ContentType = (typeof contentTypes)[number];
|
|
25
26
|
/**
|
|
26
27
|
* An example object using the typedefs
|
|
27
28
|
*/
|
|
@@ -9,11 +9,13 @@ export interface BaseErrors extends Errors {
|
|
|
9
9
|
hashesNotValid?: Json;
|
|
10
10
|
dataNotFound?: Json;
|
|
11
11
|
dataHasWrongType?: Json;
|
|
12
|
+
invalidTableTypes?: Json;
|
|
12
13
|
tableCfgsReferencedTableNameNotFound?: Json;
|
|
13
|
-
|
|
14
|
+
columnsHaveWrongType?: Json;
|
|
14
15
|
tableCfgReferencedNotFound?: Json;
|
|
15
16
|
columnConfigNotFound?: Json;
|
|
16
17
|
dataDoesNotMatchColumnConfig?: Json;
|
|
18
|
+
tableTypesDoNotMatch?: Json;
|
|
17
19
|
refsNotFound?: Json;
|
|
18
20
|
collectionBasesNotFound?: Json;
|
|
19
21
|
collectionIdSetsNotFound?: Json;
|