@lionweb/validation 0.7.2 → 0.8.0-beta.1

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/validators/LionWebReferenceValidator.d.ts +19 -1
  3. package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
  4. package/dist/validators/LionWebReferenceValidator.js +20 -2
  5. package/dist/validators/LionWebReferenceValidator.js.map +1 -1
  6. package/dist/validators/LionWebSyntaxValidator.d.ts +0 -3
  7. package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -1
  8. package/dist/validators/LionWebSyntaxValidator.js +10 -3
  9. package/dist/validators/LionWebSyntaxValidator.js.map +1 -1
  10. package/dist/validators/ValidationFunctions.d.ts +1 -1
  11. package/dist/validators/ValidationFunctions.d.ts.map +1 -1
  12. package/dist/validators/definitions/ChunksDefinitions.d.ts +3 -0
  13. package/dist/validators/definitions/ChunksDefinitions.d.ts.map +1 -0
  14. package/dist/validators/definitions/ChunksDefinitions.js +251 -0
  15. package/dist/validators/definitions/ChunksDefinitions.js.map +1 -0
  16. package/dist/validators/definitions/CommandDefinitions.d.ts +3 -0
  17. package/dist/validators/definitions/CommandDefinitions.d.ts.map +1 -0
  18. package/dist/validators/definitions/CommandDefinitions.js +2138 -0
  19. package/dist/validators/definitions/CommandDefinitions.js.map +1 -0
  20. package/dist/validators/definitions/DeltaTypesDefinitions.d.ts +3 -0
  21. package/dist/validators/definitions/DeltaTypesDefinitions.d.ts.map +1 -0
  22. package/dist/validators/definitions/DeltaTypesDefinitions.js +116 -0
  23. package/dist/validators/definitions/DeltaTypesDefinitions.js.map +1 -0
  24. package/dist/validators/definitions/EventDefinitions.d.ts +3 -0
  25. package/dist/validators/definitions/EventDefinitions.d.ts.map +1 -0
  26. package/dist/validators/definitions/EventDefinitions.js +2806 -0
  27. package/dist/validators/definitions/EventDefinitions.js.map +1 -0
  28. package/dist/validators/definitions/QueryDefinitions.d.ts +3 -0
  29. package/dist/validators/definitions/QueryDefinitions.d.ts.map +1 -0
  30. package/dist/validators/definitions/QueryDefinitions.js +145 -0
  31. package/dist/validators/definitions/QueryDefinitions.js.map +1 -0
  32. package/dist/validators/definitions/RequestDefinitions.d.ts +3 -0
  33. package/dist/validators/definitions/RequestDefinitions.d.ts.map +1 -0
  34. package/dist/validators/definitions/RequestDefinitions.js +315 -0
  35. package/dist/validators/definitions/RequestDefinitions.js.map +1 -0
  36. package/dist/validators/definitions/ResponseDefinitions.d.ts +3 -0
  37. package/dist/validators/definitions/ResponseDefinitions.d.ts.map +1 -0
  38. package/dist/validators/definitions/ResponseDefinitions.js +273 -0
  39. package/dist/validators/definitions/ResponseDefinitions.js.map +1 -0
  40. package/dist/validators/definitions/index.d.ts +8 -0
  41. package/dist/validators/definitions/index.d.ts.map +1 -0
  42. package/dist/validators/definitions/index.js +8 -0
  43. package/dist/validators/definitions/index.js.map +1 -0
  44. package/dist/validators/generic/SyntaxValidator.d.ts +7 -6
  45. package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -1
  46. package/dist/validators/generic/SyntaxValidator.js +53 -21
  47. package/dist/validators/generic/SyntaxValidator.js.map +1 -1
  48. package/dist/validators/generic/schema/SyntaxDefinition.d.ts +45 -0
  49. package/dist/validators/generic/schema/SyntaxDefinition.d.ts.map +1 -0
  50. package/dist/validators/generic/schema/SyntaxDefinition.js +39 -0
  51. package/dist/validators/generic/schema/SyntaxDefinition.js.map +1 -0
  52. package/dist/validators/generic/schema/index.d.ts +1 -2
  53. package/dist/validators/generic/schema/index.d.ts.map +1 -1
  54. package/dist/validators/generic/schema/index.js +1 -2
  55. package/dist/validators/generic/schema/index.js.map +1 -1
  56. package/dist/validators/index.d.ts +1 -1
  57. package/dist/validators/index.d.ts.map +1 -1
  58. package/dist/validators/index.js +1 -1
  59. package/dist/validators/index.js.map +1 -1
  60. package/package.json +4 -4
  61. package/src/validators/LionWebReferenceValidator.ts +20 -2
  62. package/src/validators/LionWebSyntaxValidator.ts +10 -3
  63. package/src/validators/ValidationFunctions.ts +1 -1
  64. package/src/validators/definitions/ChunksDefinitions.ts +252 -0
  65. package/src/validators/definitions/CommandDefinitions.ts +2139 -0
  66. package/src/validators/definitions/DeltaTypesDefinitions.ts +117 -0
  67. package/src/validators/definitions/EventDefinitions.ts +2807 -0
  68. package/src/validators/definitions/QueryDefinitions.ts +146 -0
  69. package/src/validators/definitions/README.md +17 -0
  70. package/src/validators/definitions/RequestDefinitions.ts +316 -0
  71. package/src/validators/definitions/ResponseDefinitions.ts +274 -0
  72. package/src/validators/definitions/index.ts +7 -0
  73. package/src/validators/generic/SyntaxValidator.ts +60 -29
  74. package/src/validators/generic/index.ts +1 -0
  75. package/src/validators/generic/schema/SyntaxDefinition.ts +83 -0
  76. package/src/validators/generic/schema/index.ts +1 -2
  77. package/src/validators/index.ts +1 -1
  78. package/dist/validators/LionWebChunkDefinitions.d.ts +0 -9
  79. package/dist/validators/LionWebChunkDefinitions.d.ts.map +0 -1
  80. package/dist/validators/LionWebChunkDefinitions.js +0 -100
  81. package/dist/validators/LionWebChunkDefinitions.js.map +0 -1
  82. package/dist/validators/generic/schema/DefinitionSchema.d.ts +0 -23
  83. package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +0 -1
  84. package/dist/validators/generic/schema/DefinitionSchema.js +0 -43
  85. package/dist/validators/generic/schema/DefinitionSchema.js.map +0 -1
  86. package/dist/validators/generic/schema/ValidationTypes.d.ts +0 -101
  87. package/dist/validators/generic/schema/ValidationTypes.d.ts.map +0 -1
  88. package/dist/validators/generic/schema/ValidationTypes.js +0 -43
  89. package/dist/validators/generic/schema/ValidationTypes.js.map +0 -1
  90. package/src/validators/LionWebChunkDefinitions.ts +0 -104
  91. package/src/validators/generic/schema/DefinitionSchema.ts +0 -52
  92. package/src/validators/generic/schema/ValidationTypes.ts +0 -134
@@ -1 +0,0 @@
1
- {"version":3,"file":"LionWebChunkDefinitions.js","sourceRoot":"","sources":["../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E,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACpF,YAAY,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC3F,YAAY,CAAC,EAAE,IAAI,EAAE,mCAAmC,EAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,kCAAkC,EAAE,CAAC;IACjI,YAAY,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;IAC3D,YAAY,CAAC,EAAE,IAAI,EAAE,UAAU,EAAC,aAAa,EAAE,QAAQ,EAAE,CAAC;CAC7D,CAAC,CAAA"}
@@ -1,23 +0,0 @@
1
- import { Definition, PrimitiveDefinition, TaggedUnionDefinition } from "./ValidationTypes.js";
2
- /**
3
- * A collection of object and primitive definitions describing JSON objects.
4
- * Used to
5
- * - validate an incoming JSON object
6
- * - generate the corresponding TypeScript type definitions
7
- * - generate handlers for the JSOn objects (in @lionweb/server)
8
- */
9
- export declare class DefinitionSchema {
10
- unionDefinition: TaggedUnionDefinition | undefined;
11
- /**
12
- * Mapping from extenden object type name to list of extending Object Definitions
13
- */
14
- definitionsMap: Map<string, Definition>;
15
- constructor(definitions: Definition[], taggedUnion?: TaggedUnionDefinition);
16
- getDefinition(name: string): Definition | undefined;
17
- add(definitions: Definition[] | Definition): void;
18
- isTagProperty(propertyName: string): boolean;
19
- definitions(): Definition[];
20
- isUnionDiscriminator(propDef: PrimitiveDefinition): boolean;
21
- joinDefinitions(...schema: DefinitionSchema[]): void;
22
- }
23
- //# sourceMappingURL=DefinitionSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DefinitionSchema.d.ts","sourceRoot":"","sources":["../../../../src/validators/generic/schema/DefinitionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAE7F;;;;;;GAMG;AACH,qBAAa,gBAAgB;IACzB,eAAe,EAAE,qBAAqB,GAAG,SAAS,CAAA;IAClD;;OAEG;IACH,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAgC;gBAE3D,WAAW,EAAE,UAAU,EAAE,EAAE,WAAW,CAAC,EAAE,qBAAqB;IAK1E,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAInD,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU;IAS1C,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAI5C,WAAW,IAAI,UAAU,EAAE;IAI3B,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO;IAI3D,eAAe,CAAC,GAAG,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI;CAKvD"}
@@ -1,43 +0,0 @@
1
- /**
2
- * A collection of object and primitive definitions describing JSON objects.
3
- * Used to
4
- * - validate an incoming JSON object
5
- * - generate the corresponding TypeScript type definitions
6
- * - generate handlers for the JSOn objects (in @lionweb/server)
7
- */
8
- export class DefinitionSchema {
9
- constructor(definitions, taggedUnion) {
10
- /**
11
- * Mapping from extenden object type name to list of extending Object Definitions
12
- */
13
- this.definitionsMap = new Map();
14
- this.add(definitions);
15
- this.unionDefinition = taggedUnion;
16
- }
17
- getDefinition(name) {
18
- return this.definitionsMap.get(name);
19
- }
20
- add(definitions) {
21
- if (!Array.isArray(definitions)) {
22
- definitions = [definitions];
23
- }
24
- for (const def of definitions) {
25
- this.definitionsMap.set(def.name, def);
26
- }
27
- }
28
- isTagProperty(propertyName) {
29
- return this.unionDefinition?.unionProperty === propertyName;
30
- }
31
- definitions() {
32
- return Array.from(this.definitionsMap.values());
33
- }
34
- isUnionDiscriminator(propDef) {
35
- return this.unionDefinition?.unionDiscriminator === propDef.name;
36
- }
37
- joinDefinitions(...schema) {
38
- schema.forEach(sch => {
39
- this.add(sch.definitions());
40
- });
41
- }
42
- }
43
- //# sourceMappingURL=DefinitionSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DefinitionSchema.js","sourceRoot":"","sources":["../../../../src/validators/generic/schema/DefinitionSchema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAOzB,YAAY,WAAyB,EAAE,WAAmC;QAL1E;;WAEG;QACH,mBAAc,GAA4B,IAAI,GAAG,EAAsB,CAAA;QAGnE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACrB,IAAI,CAAC,eAAe,GAAG,WAAW,CAAA;IACtC,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAED,GAAG,CAAC,WAAsC;QACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9B,WAAW,GAAG,CAAC,WAAW,CAAC,CAAA;QAC/B,CAAC;QACD,KAAI,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC3B,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAC1C,CAAC;IACL,CAAC;IAED,aAAa,CAAC,YAAoB;QAC9B,OAAO,IAAI,CAAC,eAAe,EAAE,aAAa,KAAK,YAAY,CAAA;IAC/D,CAAC;IAED,WAAW;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAA;IACnD,CAAC;IAED,oBAAoB,CAAC,OAA4B;QAC7C,OAAO,IAAI,CAAC,eAAe,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAA;IACpE,CAAC;IAED,eAAe,CAAC,GAAG,MAA0B;QACzC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;QAC/B,CAAC,CAAC,CAAA;IACN,CAAC;CACJ"}
@@ -1,101 +0,0 @@
1
- import { JsonContext } from "@lionweb/json-utils";
2
- import { ValidationResult } from "../ValidationResult.js";
3
- export type UnknownObjectType = {
4
- [key: string]: unknown;
5
- };
6
- /**
7
- * Definition of a property, used by the SyntaxValidator to validate objects.
8
- *
9
- * **Note** that some of the properties are defined as optional.
10
- * They should not be empty ever!! But being optional allows to leave them out in the `PropertyDef` function.
11
- * The `PropertyDef` function sets default values for all optional fields.
12
- * You should **always** use the `PropertyDef` function to create a `PropertyDefinition`.
13
- */
14
- export type PropertyDefinition = {
15
- /**
16
- * The property name
17
- */
18
- name: string;
19
- /**
20
- * The expected type of the property value
21
- */
22
- type: string;
23
- /**
24
- * Whether the property value is allowed to be null
25
- */
26
- mayBeNull?: boolean;
27
- /**
28
- * IS this a list property?
29
- */
30
- isList?: boolean;
31
- /**
32
- * Is this property optional?
33
- */
34
- isOptional?: boolean;
35
- /**
36
- * Additional validation function
37
- */
38
- validate?: ValidatorFunction;
39
- };
40
- export type ValidatorFunction = <T>(obj: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition) => void;
41
- export declare function emptyValidation<T>(object: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition): void;
42
- export declare const MAY_BE_NULL = true;
43
- /**
44
- * Definition of a primitive type.
45
- */
46
- export type PrimitiveDefinition = {
47
- name: string;
48
- /**
49
- * The expected type of the property value
50
- */
51
- primitiveType: string;
52
- /**
53
- * Additional validation function
54
- */
55
- validate?: ValidatorFunction;
56
- };
57
- /**
58
- * Definition of an object type.
59
- */
60
- export type ObjectDefinition = {
61
- name: string;
62
- properties: PropertyDefinition[];
63
- /**
64
- * The name of the tagged union that this type belongs to
65
- */
66
- taggedUnionType?: string;
67
- };
68
- export type Definition = ObjectDefinition | PrimitiveDefinition;
69
- /**
70
- * Defionition of tagged union.
71
- */
72
- export type TaggedUnionDefinition = {
73
- /**
74
- * The tagged union "super" type
75
- */
76
- unionType: string;
77
- /**
78
- * The primitive property type that is the discriminator or tag
79
- */
80
- unionDiscriminator: string;
81
- /**
82
- * The name of the property in an object that contains the discriminator value
83
- */
84
- unionProperty: string;
85
- };
86
- /**
87
- * Easy way to create a PrimitiveDefinition typed object with default values.
88
- * @param propDef
89
- * @constructor
90
- */
91
- export declare function PrimitiveDef(propDef: PrimitiveDefinition): PrimitiveDefinition;
92
- /**
93
- * Easy way to create a PropertyDefinition typed object with default values.
94
- * @param propDef
95
- * @constructor
96
- */
97
- export declare function PropertyDef(propDef: PropertyDefinition): PropertyDefinition;
98
- export declare function isObjectDefinition(def: Definition | undefined): def is ObjectDefinition;
99
- export declare function isPrimitiveDefinition(def: Definition | undefined): def is PrimitiveDefinition;
100
- export declare function isJavaScriptPrimitive(type: string): boolean;
101
- //# sourceMappingURL=ValidationTypes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ValidationTypes.d.ts","sourceRoot":"","sources":["../../../../src/validators/generic/schema/ValidationTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,MAAM,iBAAiB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAA;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAC/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ED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,GAAG,GAAG,IAAI,mBAAmB,CAE7F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
@@ -1,43 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- export function emptyValidation(object, result, ctx, pdef) { }
3
- // Make boolean argument more readable.
4
- export const MAY_BE_NULL = true;
5
- /**
6
- * Easy way to create a PrimitiveDefinition typed object with default values.
7
- * @param propDef
8
- * @constructor
9
- */
10
- export function PrimitiveDef(propDef) {
11
- const { name, primitiveType, validate = emptyValidation } = propDef;
12
- return {
13
- name: name,
14
- primitiveType: primitiveType,
15
- validate: validate
16
- };
17
- }
18
- /**
19
- * Easy way to create a PropertyDefinition typed object with default values.
20
- * @param propDef
21
- * @constructor
22
- */
23
- export function PropertyDef(propDef) {
24
- const { name, type, mayBeNull = false, isList = false, isOptional = false, validate = emptyValidation } = propDef;
25
- return {
26
- name: name,
27
- type: type,
28
- isList: isList,
29
- mayBeNull: mayBeNull,
30
- isOptional: isOptional,
31
- validate: validate
32
- };
33
- }
34
- export function isObjectDefinition(def) {
35
- return (def !== undefined) && Array.isArray(def?.properties);
36
- }
37
- export function isPrimitiveDefinition(def) {
38
- return (def !== undefined) && def?.primitiveType !== undefined;
39
- }
40
- export function isJavaScriptPrimitive(type) {
41
- return ["number", "string", "boolean"].includes(type);
42
- }
43
- //# sourceMappingURL=ValidationTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ValidationTypes.js","sourceRoot":"","sources":["../../../../src/validators/generic/schema/ValidationTypes.ts"],"names":[],"mappings":"AAyCA,6DAA6D;AAC7D,MAAM,UAAU,eAAe,CAAI,MAAS,EAAE,MAAwB,EAAE,GAAgB,EAAE,IAAyB,IAAS,CAAC;AAE7H,uCAAuC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAA;AA+C/B;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B;IACrD,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,OAAO,CAAA;IACnE,OAAO;QACH,IAAI,EAAE,IAAI;QACV,aAAa,EAAE,aAAa;QAC5B,QAAQ,EAAE,QAAQ;KACrB,CAAA;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B;IACnD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,OAAO,CAAA;IACjH,OAAO;QACH,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,QAAQ;KACrB,CAAA;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAA2B;IAC1D,OAAQ,CAAC,GAAG,KAAK,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,CAAE,GAAwB,EAAE,UAAU,CAAC,CAAA;AACvF,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,GAA2B;IAC7D,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,IAAK,GAA2B,EAAE,aAAa,KAAK,SAAS,CAAA;AAC3F,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAC9C,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AACzD,CAAC"}
@@ -1,104 +0,0 @@
1
- import { DefinitionSchema, MAY_BE_NULL, PropertyDef, PrimitiveDef } from "./generic/index.js"
2
- import { validateId, validateKey, validateSerializationFormatVersion, validateVersion } from "./ValidationFunctions.js"
3
-
4
- /**
5
- * The structure below defines the structure of a LionWeb Chunk by defining all the properties.
6
- * It can
7
- * - be used by the SyntaxValidator to validate an object sat runtime.
8
- * - used to generate all the TypeScript types for a LionWebChunk.
9
- */
10
- export const LionWebSchema: DefinitionSchema = new DefinitionSchema([
11
- {
12
- name: "LionWebJsonMetaPointer",
13
- properties: [
14
- PropertyDef({ name: "key", type: "LionWebKey" }),
15
- PropertyDef({ name: "version", type: "LionWebVersion" }),
16
- PropertyDef({ name: "language", type: "LionWebKey" })
17
- ]
18
- },
19
- {
20
- name: "LionWebJsonMetaPointer",
21
- properties: [
22
- PropertyDef({ name: "key", type: "LionWebKey" }),
23
- PropertyDef({ name: "version", type: "LionWebVersion" }),
24
- PropertyDef({ name: "language", type: "LionWebKey" }),
25
- ]
26
- },
27
- {
28
- name: "ResponseMessage",
29
- properties: [
30
- PropertyDef({ name: "kind", type: "JSstring" }),
31
- PropertyDef({ name: "message", type: "JSstring" }),
32
- PropertyDef({ name: "data", type: "JSobject", mayBeNull: true, isOptional: true })
33
- ]
34
- },
35
- {
36
- name: "LionWebJsonChunk",
37
- properties: [
38
- PropertyDef({ name: "serializationFormatVersion", type: "LionWebSerializationFormatVersion" }),
39
- PropertyDef({ name: "languages", type: "LionWebJsonUsedLanguage", isList: true }),
40
- PropertyDef({ name: "nodes", type: "LionWebJsonNode", isList: true })
41
- ]
42
- },
43
- {
44
- name: "LionWebJsonUsedLanguage",
45
- properties: [
46
- PropertyDef({ name: "key", type: "LionWebKey" }),
47
- PropertyDef({ name: "version", type: "LionWebVersion" })
48
- ]
49
- },
50
- {
51
- name: "LionWebJsonNode",
52
- properties: [
53
- PropertyDef({ name: "id", type: "LionWebId" }),
54
- PropertyDef({ name: "classifier", type: "LionWebJsonMetaPointer" }),
55
- PropertyDef({ name: "properties", type: "LionWebJsonProperty", isList: true }),
56
- PropertyDef({ name: "containments", type: "LionWebJsonContainment", isList: true }),
57
- PropertyDef({ name: "references", type: "LionWebJsonReference", isList: true }),
58
- PropertyDef({ name: "annotations", type: "LionWebId", isList: true }),
59
- PropertyDef({ name: "parent", type: "LionWebId", mayBeNull: MAY_BE_NULL }),
60
- ]
61
- },
62
- {
63
- name: "LionWebJsonProperty",
64
- properties: [
65
- PropertyDef({ name: "property", type: "LionWebJsonMetaPointer" }),
66
- PropertyDef({ name: "value", type: "JSstring", mayBeNull: MAY_BE_NULL }),
67
- ]
68
- },
69
- {
70
- name: "LionWebJsonContainment",
71
- properties: [
72
- PropertyDef({ name: "containment", type: "LionWebJsonMetaPointer" }),
73
- PropertyDef({ name: "children", type: "LionWebId", isList: true }),
74
- ]
75
- },
76
- {
77
- name: "LionWebJsonReference",
78
- properties: [
79
- PropertyDef({ name: "reference", type: "LionWebJsonMetaPointer"}),
80
- PropertyDef({ name: "targets", type: "LionWebJsonReferenceTarget", isList: true}),
81
- ]
82
- },
83
- {
84
- name: "LionWebJsonReferenceTarget",
85
- properties: [
86
- PropertyDef({ name: "resolveInfo", type: "JSstring", mayBeNull: MAY_BE_NULL }),
87
- PropertyDef({ name: "reference", type: "LionWebId", mayBeNull: MAY_BE_NULL }),
88
- ]
89
- },
90
- /**
91
- * Elements without properties are assumed to be JSON/JS primitive values, and tested using `typeof`
92
- * and the (optional) validate function.
93
- */
94
- PrimitiveDef({ name: "LionWebId", primitiveType: "string", validate: validateId }),
95
- PrimitiveDef({ name: "LionWebKey", primitiveType: "string", validate: validateKey }),
96
- PrimitiveDef({ name: "LionWebVersion",primitiveType: "string", validate: validateVersion }),
97
- PrimitiveDef({ name: "LionWebSerializationFormatVersion",primitiveType: "string", validate: validateSerializationFormatVersion }),
98
- PrimitiveDef({ name: "JSstring", primitiveType: "string" }),
99
- PrimitiveDef({ name: "JSobject",primitiveType: "object" }),
100
- ])
101
-
102
-
103
-
104
-
@@ -1,52 +0,0 @@
1
- import { Definition, PrimitiveDefinition, TaggedUnionDefinition } from "./ValidationTypes.js"
2
-
3
- /**
4
- * A collection of object and primitive definitions describing JSON objects.
5
- * Used to
6
- * - validate an incoming JSON object
7
- * - generate the corresponding TypeScript type definitions
8
- * - generate handlers for the JSOn objects (in @lionweb/server)
9
- */
10
- export class DefinitionSchema {
11
- unionDefinition: TaggedUnionDefinition | undefined
12
- /**
13
- * Mapping from extenden object type name to list of extending Object Definitions
14
- */
15
- definitionsMap: Map<string, Definition> = new Map<string, Definition>()
16
-
17
- constructor(definitions: Definition[], taggedUnion?: TaggedUnionDefinition) {
18
- this.add(definitions)
19
- this.unionDefinition = taggedUnion
20
- }
21
-
22
- getDefinition(name: string): Definition | undefined {
23
- return this.definitionsMap.get(name)
24
- }
25
-
26
- add(definitions :Definition[] | Definition) {
27
- if (!Array.isArray(definitions)) {
28
- definitions = [definitions]
29
- }
30
- for(const def of definitions) {
31
- this.definitionsMap.set(def.name, def)
32
- }
33
- }
34
-
35
- isTagProperty(propertyName: string): boolean {
36
- return this.unionDefinition?.unionProperty === propertyName
37
- }
38
-
39
- definitions(): Definition[] {
40
- return Array.from(this.definitionsMap.values())
41
- }
42
-
43
- isUnionDiscriminator(propDef: PrimitiveDefinition): boolean {
44
- return this.unionDefinition?.unionDiscriminator === propDef.name
45
- }
46
-
47
- joinDefinitions(...schema: DefinitionSchema[]): void {
48
- schema.forEach(sch => {
49
- this.add(sch.definitions())
50
- })
51
- }
52
- }
@@ -1,134 +0,0 @@
1
- import { JsonContext } from "@lionweb/json-utils"
2
- import { ValidationResult } from "../ValidationResult.js"
3
-
4
- export type UnknownObjectType = { [key: string]: unknown }
5
-
6
- /**
7
- * Definition of a property, used by the SyntaxValidator to validate objects.
8
- *
9
- * **Note** that some of the properties are defined as optional.
10
- * They should not be empty ever!! But being optional allows to leave them out in the `PropertyDef` function.
11
- * The `PropertyDef` function sets default values for all optional fields.
12
- * You should **always** use the `PropertyDef` function to create a `PropertyDefinition`.
13
- */
14
- export type PropertyDefinition = {
15
- /**
16
- * The property name
17
- */
18
- name: string
19
- /**
20
- * The expected type of the property value
21
- */
22
- type: string
23
- /**
24
- * Whether the property value is allowed to be null
25
- */
26
- mayBeNull?: boolean
27
- /**
28
- * IS this a list property?
29
- */
30
- isList?: boolean,
31
- /**
32
- * Is this property optional?
33
- */
34
- isOptional?: boolean,
35
- /**
36
- * Additional validation function
37
- */
38
- validate?: ValidatorFunction
39
- }
40
-
41
- export type ValidatorFunction = <T>(obj: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition) => void
42
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
- export function emptyValidation<T>(object: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition): void {}
44
-
45
- // Make boolean argument more readable.
46
- export const MAY_BE_NULL = true
47
-
48
- /**
49
- * Definition of a primitive type.
50
- */
51
- export type PrimitiveDefinition = {
52
- name: string,
53
- /**
54
- * The expected type of the property value
55
- */
56
- primitiveType: string
57
- /**
58
- * Additional validation function
59
- */
60
- validate?: ValidatorFunction
61
- }
62
-
63
- /**
64
- * Definition of an object type.
65
- */
66
- export type ObjectDefinition = {
67
- name: string,
68
- properties: PropertyDefinition[],
69
- /**
70
- * The name of the tagged union that this type belongs to
71
- */
72
- taggedUnionType?: string
73
- }
74
-
75
- export type Definition = ObjectDefinition | PrimitiveDefinition
76
- /**
77
- * Defionition of tagged union.
78
- */
79
- export type TaggedUnionDefinition = {
80
- /**
81
- * The tagged union "super" type
82
- */
83
- unionType: string,
84
- /**
85
- * The primitive property type that is the discriminator or tag
86
- */
87
- unionDiscriminator: string,
88
- /**
89
- * The name of the property in an object that contains the discriminator value
90
- */
91
- unionProperty: string
92
- }
93
- /**
94
- * Easy way to create a PrimitiveDefinition typed object with default values.
95
- * @param propDef
96
- * @constructor
97
- */
98
- export function PrimitiveDef(propDef: PrimitiveDefinition): PrimitiveDefinition {
99
- const { name, primitiveType, validate = emptyValidation } = propDef
100
- return {
101
- name: name,
102
- primitiveType: primitiveType,
103
- validate: validate
104
- }
105
- }
106
-
107
- /**
108
- * Easy way to create a PropertyDefinition typed object with default values.
109
- * @param propDef
110
- * @constructor
111
- */
112
- export function PropertyDef(propDef: PropertyDefinition): PropertyDefinition {
113
- const { name, type, mayBeNull = false, isList = false, isOptional = false, validate = emptyValidation } = propDef
114
- return {
115
- name: name,
116
- type: type,
117
- isList: isList,
118
- mayBeNull: mayBeNull,
119
- isOptional: isOptional,
120
- validate: validate
121
- }
122
- }
123
-
124
- export function isObjectDefinition(def: Definition | undefined): def is ObjectDefinition {
125
- return (def !== undefined) && Array.isArray((def as ObjectDefinition)?.properties)
126
- }
127
-
128
- export function isPrimitiveDefinition(def: Definition | undefined): def is PrimitiveDefinition {
129
- return (def !== undefined) && (def as PrimitiveDefinition)?.primitiveType !== undefined
130
- }
131
-
132
- export function isJavaScriptPrimitive(type: string): boolean {
133
- return ["number", "string", "boolean"].includes(type)
134
- }