@rljson/rljson 0.0.16 → 0.0.18
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 +31 -0
- package/dist/content/cake.d.ts +40 -0
- package/dist/content/collection.d.ts +40 -0
- package/dist/content/id-set.d.ts +33 -0
- package/dist/content/properties.d.ts +16 -0
- package/dist/content/table-cfg.d.ts +48 -0
- package/dist/example/bakery-example.d.ts +35 -0
- package/dist/rljson.js +2 -2
- package/dist/validate/base-validator.d.ts +39 -0
- package/dist/validate/validate.d.ts +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { RljsonTable } from '../rljson.ts';
|
|
3
|
+
import { ItemId, Ref, TableName } from '../typedefs.ts';
|
|
4
|
+
/**
|
|
5
|
+
* A buffet id is a name or id of a buffet
|
|
6
|
+
*/
|
|
7
|
+
export type BuffetId = ItemId;
|
|
8
|
+
/**
|
|
9
|
+
* A buffet is a collection of arbitrary but related items, e.g. cakes,
|
|
10
|
+
* collections, or items.
|
|
11
|
+
*/
|
|
12
|
+
export interface Buffet extends Json {
|
|
13
|
+
/**
|
|
14
|
+
* The items of the buffet
|
|
15
|
+
*/
|
|
16
|
+
items: Array<{
|
|
17
|
+
/**
|
|
18
|
+
* The table the item is taken from
|
|
19
|
+
*/
|
|
20
|
+
table: TableName;
|
|
21
|
+
/**
|
|
22
|
+
* The hash of the item in the able
|
|
23
|
+
*/
|
|
24
|
+
ref: Ref;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A table containing buffets
|
|
29
|
+
*/
|
|
30
|
+
export type BuffetsTable = RljsonTable<Buffet, 'buffets'>;
|
|
31
|
+
export declare const exampleBuffetsTable: () => BuffetsTable;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { RljsonTable } from '../rljson.ts';
|
|
3
|
+
import { ItemId, TableName } from '../typedefs.ts';
|
|
4
|
+
import { CollectionRef } from './collection.ts';
|
|
5
|
+
import { IdSetRef } from './id-set.ts';
|
|
6
|
+
/**
|
|
7
|
+
* A `CakeLayerId` assigns an id or name to a cake layer
|
|
8
|
+
*/
|
|
9
|
+
export type CakeLayerId = ItemId;
|
|
10
|
+
/**
|
|
11
|
+
* A cake is a collection of layers.
|
|
12
|
+
*
|
|
13
|
+
* A layer is a collection of items.
|
|
14
|
+
* All layers of a cake refer to the same items.
|
|
15
|
+
*/
|
|
16
|
+
export interface Cake extends Json {
|
|
17
|
+
/**
|
|
18
|
+
* The item ids of the collection. If present, the item ids in the layers
|
|
19
|
+
* must match these ids. The item id sets can be found in the _idSets table.
|
|
20
|
+
*/
|
|
21
|
+
idSet?: IdSetRef;
|
|
22
|
+
/**
|
|
23
|
+
* The table containing the item collections defining the layers
|
|
24
|
+
*/
|
|
25
|
+
collections: TableName;
|
|
26
|
+
/**
|
|
27
|
+
* Assigns a collection to each layer of the cake.
|
|
28
|
+
*/
|
|
29
|
+
layers: {
|
|
30
|
+
[layerId: CakeLayerId]: CollectionRef;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A table containing cakes
|
|
35
|
+
*/
|
|
36
|
+
export type CakesTable = RljsonTable<Cake, 'cakes'>;
|
|
37
|
+
/**
|
|
38
|
+
* Provides an example collectionsTable for test purposes
|
|
39
|
+
*/
|
|
40
|
+
export declare const exampleCakesTable: () => CakesTable;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { RljsonTable } from '../rljson.ts';
|
|
3
|
+
import { ItemId, Ref, TableName } from '../typedefs.ts';
|
|
4
|
+
import { IdSetRef } from './id-set.ts';
|
|
5
|
+
import { PropertiesRef } from './properties.ts';
|
|
6
|
+
/**
|
|
7
|
+
* A CollectionRef is a hash pointing to a collection
|
|
8
|
+
*/
|
|
9
|
+
export type CollectionRef = Ref;
|
|
10
|
+
/**
|
|
11
|
+
* A collection assigns properties to item ids
|
|
12
|
+
*/
|
|
13
|
+
export interface Collection extends Json {
|
|
14
|
+
/**
|
|
15
|
+
* `base` an optional base collection that is extended by this collection
|
|
16
|
+
*/
|
|
17
|
+
base?: CollectionRef;
|
|
18
|
+
/**
|
|
19
|
+
* The item ids of the collection. If presnet, the item ids in `assign`
|
|
20
|
+
* must match these ids. The item id sets can be found in the _idSets table.
|
|
21
|
+
*/
|
|
22
|
+
idSet?: IdSetRef;
|
|
23
|
+
/**
|
|
24
|
+
* The table containing the properties that are assigned to the items
|
|
25
|
+
* with the assign property below
|
|
26
|
+
*/
|
|
27
|
+
properties: TableName;
|
|
28
|
+
/**
|
|
29
|
+
* Assign properties to each item of the collection.
|
|
30
|
+
*/
|
|
31
|
+
assign: Record<ItemId, PropertiesRef>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A table containing collections
|
|
35
|
+
*/
|
|
36
|
+
export type CollectionsTable = RljsonTable<Collection, 'collections'>;
|
|
37
|
+
/**
|
|
38
|
+
* Provides an example collectionsTable for test purposes
|
|
39
|
+
*/
|
|
40
|
+
export declare const exampleCollectionsTable: () => CollectionsTable;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { RljsonTable } from '../rljson.ts';
|
|
3
|
+
import { ItemId, Ref } from '../typedefs.ts';
|
|
4
|
+
/**
|
|
5
|
+
* An IdSetRef is a hash pointing to an Ids
|
|
6
|
+
*/
|
|
7
|
+
export type IdSetRef = Ref;
|
|
8
|
+
/**
|
|
9
|
+
* An Ids manages list of item ids
|
|
10
|
+
*/
|
|
11
|
+
export interface IdSet extends Json {
|
|
12
|
+
/**
|
|
13
|
+
* The hash of another item id list which is extended by this one.
|
|
14
|
+
* Must be empty or null, when the list is the root.
|
|
15
|
+
*/
|
|
16
|
+
base?: IdSetRef;
|
|
17
|
+
/**
|
|
18
|
+
* The item ids added to base
|
|
19
|
+
*/
|
|
20
|
+
add: ItemId[];
|
|
21
|
+
/**
|
|
22
|
+
* The item ids removed from base
|
|
23
|
+
*/
|
|
24
|
+
remove?: ItemId[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A table containing item ids
|
|
28
|
+
*/
|
|
29
|
+
export type IdSetsTable = RljsonTable<IdSet, 'idSets'>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns one of the layers of the example cake
|
|
32
|
+
*/
|
|
33
|
+
export declare const exampleIdSetsTable: () => IdSetsTable;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { NutritiveValues } from '../example/bakery-example.ts';
|
|
3
|
+
import { RljsonTable } from '../rljson.ts';
|
|
4
|
+
import { Ref } from '../typedefs.ts';
|
|
5
|
+
/**
|
|
6
|
+
* A reference to a properties row in a properties table
|
|
7
|
+
*/
|
|
8
|
+
export type PropertiesRef = Ref;
|
|
9
|
+
/**
|
|
10
|
+
* A table containing item properties
|
|
11
|
+
*/
|
|
12
|
+
export type PropertiesTable<T extends Json> = RljsonTable<T, 'properties'>;
|
|
13
|
+
/**
|
|
14
|
+
* Provides an example collectionsTable for test purposes
|
|
15
|
+
*/
|
|
16
|
+
export declare const examplePropertiesTable: () => PropertiesTable<NutritiveValues>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Json, JsonKey, JsonValueType } from '@rljson/json';
|
|
2
|
+
import { RljsonTable } from '../rljson.ts';
|
|
3
|
+
import { Ref } from '../typedefs.ts';
|
|
4
|
+
/**
|
|
5
|
+
* A ColumnsRef is a hash pointing to columns metadata
|
|
6
|
+
*/
|
|
7
|
+
export type TableCfgRef = Ref;
|
|
8
|
+
/**
|
|
9
|
+
* A column configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface ColumnCfg extends Json {
|
|
12
|
+
/**
|
|
13
|
+
* The jsonKey of the column used in data
|
|
14
|
+
*/
|
|
15
|
+
jsonKey: JsonKey;
|
|
16
|
+
/**
|
|
17
|
+
* A short name of the column to be shown in the table header
|
|
18
|
+
*/
|
|
19
|
+
nameShort: string;
|
|
20
|
+
/**
|
|
21
|
+
* A unshorted name to be shown in the tool tip
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* Average number of characters in the column
|
|
26
|
+
*/
|
|
27
|
+
avgChars?: number;
|
|
28
|
+
/**
|
|
29
|
+
* The type of the column
|
|
30
|
+
*/
|
|
31
|
+
type: JsonValueType;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Describes the configuration of a table, i.e. table metadata and columns
|
|
35
|
+
*/
|
|
36
|
+
export interface TableCfg extends Json {
|
|
37
|
+
name: string;
|
|
38
|
+
jsonKey: JsonKey;
|
|
39
|
+
columns: Record<JsonKey, ColumnCfg>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A table containing columns
|
|
43
|
+
*/
|
|
44
|
+
export type TablesCfgTable = RljsonTable<TableCfg, 'properties'>;
|
|
45
|
+
/**
|
|
46
|
+
* Example matching allTypesRow
|
|
47
|
+
*/
|
|
48
|
+
export declare const exampleTableCfgTable: () => TablesCfgTable;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { BuffetsTable } from '../content/buffet.ts';
|
|
3
|
+
import { CakesTable } from '../content/cake.ts';
|
|
4
|
+
import { CollectionsTable } from '../content/collection.ts';
|
|
5
|
+
import { IdSetsTable } from '../content/id-set.ts';
|
|
6
|
+
import { PropertiesTable } from '../content/properties.ts';
|
|
7
|
+
import { Rljson } from '../rljson.ts';
|
|
8
|
+
import { Ref } from '../typedefs.ts';
|
|
9
|
+
export interface Ingredient extends Json {
|
|
10
|
+
name: string;
|
|
11
|
+
amountUnit: 'g' | 'ml';
|
|
12
|
+
nutritiveValuesRef: Ref;
|
|
13
|
+
}
|
|
14
|
+
export interface RecipeIngredient extends Json {
|
|
15
|
+
ingredientsRef: string;
|
|
16
|
+
quantity: number;
|
|
17
|
+
}
|
|
18
|
+
export type IngredientsTypeTable = PropertiesTable<Ingredient>;
|
|
19
|
+
export interface NutritiveValues extends Json {
|
|
20
|
+
energy: number;
|
|
21
|
+
fat: number;
|
|
22
|
+
protein: number;
|
|
23
|
+
carbohydrates: number;
|
|
24
|
+
}
|
|
25
|
+
export interface Bakery extends Rljson {
|
|
26
|
+
buffets: BuffetsTable;
|
|
27
|
+
cakes: CakesTable;
|
|
28
|
+
slices: IdSetsTable;
|
|
29
|
+
layers: CollectionsTable;
|
|
30
|
+
recipes: CollectionsTable;
|
|
31
|
+
recipeIngredients: PropertiesTable<RecipeIngredient>;
|
|
32
|
+
ingredients: PropertiesTable<Ingredient>;
|
|
33
|
+
nutritiveValues: PropertiesTable<NutritiveValues>;
|
|
34
|
+
}
|
|
35
|
+
export declare const bakeryExample: () => Bakery;
|
package/dist/rljson.js
CHANGED
|
@@ -532,7 +532,7 @@ const exampleTypedefs = () => {
|
|
|
532
532
|
// @license
|
|
533
533
|
class BaseValidator {
|
|
534
534
|
constructor() {
|
|
535
|
-
__publicField(this, "name", "
|
|
535
|
+
__publicField(this, "name", "base");
|
|
536
536
|
}
|
|
537
537
|
async validate(rljson) {
|
|
538
538
|
return this.validateSync(rljson);
|
|
@@ -1172,7 +1172,7 @@ class Validate {
|
|
|
1172
1172
|
return result.reduce((acc, errors) => {
|
|
1173
1173
|
let hasErrors = false;
|
|
1174
1174
|
for (const key of Object.keys(errors)) {
|
|
1175
|
-
const e = Object.keys(errors[key]);
|
|
1175
|
+
const e = Object.keys(errors[key]).filter((k) => k !== "hasErrors");
|
|
1176
1176
|
if (e.length > 0) {
|
|
1177
1177
|
hasErrors = true;
|
|
1178
1178
|
break;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { Rljson } from '../rljson.ts';
|
|
3
|
+
import { Errors, Validator } from './validate.ts';
|
|
4
|
+
export interface BaseErrors extends Errors {
|
|
5
|
+
tableNamesNotLowerCamelCase?: Json;
|
|
6
|
+
columnNamesNotLowerCamelCase?: Json;
|
|
7
|
+
tableNamesDoNotStartWithANumber?: Json;
|
|
8
|
+
tableNamesDoNotEndWithRef?: Json;
|
|
9
|
+
hashesNotValid?: Json;
|
|
10
|
+
dataNotFound?: Json;
|
|
11
|
+
dataHasWrongType?: Json;
|
|
12
|
+
tableCfgsReferencedTableNameNotFound?: Json;
|
|
13
|
+
tableCfgsHaveWrongTypes?: Json;
|
|
14
|
+
tableCfgReferencedNotFound?: Json;
|
|
15
|
+
columnConfigNotFound?: Json;
|
|
16
|
+
dataDoesNotMatchColumnConfig?: Json;
|
|
17
|
+
refsNotFound?: Json;
|
|
18
|
+
collectionBasesNotFound?: Json;
|
|
19
|
+
collectionIdSetsNotFound?: Json;
|
|
20
|
+
collectionPropertyTablesNotFound?: Json;
|
|
21
|
+
collectionPropertyAssignmentsNotFound?: Json;
|
|
22
|
+
cakeIdSetsNotFound?: Json;
|
|
23
|
+
cakeCollectionTablesNotFound?: Json;
|
|
24
|
+
cakeLayerCollectionsNotFound?: Json;
|
|
25
|
+
buffetReferencedTablesNotFound?: Json;
|
|
26
|
+
buffetReferencedItemsNotFound?: Json;
|
|
27
|
+
}
|
|
28
|
+
export declare class BaseValidator implements Validator {
|
|
29
|
+
name: string;
|
|
30
|
+
validate(rljson: Rljson): Promise<Errors>;
|
|
31
|
+
validateSync(rljson: Rljson): BaseErrors;
|
|
32
|
+
static isValidFieldName(fieldName: string): boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates an field name
|
|
36
|
+
* @param fieldName - The field name to validate
|
|
37
|
+
* @returns true if the field name is valid, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare const isValidFieldName: (fieldName: string) => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Json } from '@rljson/json';
|
|
2
|
+
import { Rljson } from '../rljson.ts';
|
|
3
|
+
export type Errors = Json & {
|
|
4
|
+
hasErrors: boolean;
|
|
5
|
+
};
|
|
6
|
+
export interface ValidationResult {
|
|
7
|
+
[group: string]: Errors;
|
|
8
|
+
}
|
|
9
|
+
export interface Validator {
|
|
10
|
+
name: string;
|
|
11
|
+
validate(rljson: Rljson): Promise<Errors>;
|
|
12
|
+
}
|
|
13
|
+
export declare class Validate {
|
|
14
|
+
addValidator(validator: Validator): void;
|
|
15
|
+
run(rljson: Rljson): Promise<{
|
|
16
|
+
[group: string]: Errors;
|
|
17
|
+
}>;
|
|
18
|
+
private _validators;
|
|
19
|
+
}
|