@cubicweb/client 1.4.0 → 1.5.0

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 (74) hide show
  1. package/lib/api/Api.d.ts +87 -3
  2. package/lib/api/Api.d.ts.map +1 -1
  3. package/lib/api/Api.js +99 -10
  4. package/lib/api/Api.js.map +1 -1
  5. package/lib/api/Client.d.ts +39 -1
  6. package/lib/api/Client.d.ts.map +1 -1
  7. package/lib/api/Client.js +41 -1
  8. package/lib/api/Client.js.map +1 -1
  9. package/lib/api/Transaction.d.ts +42 -0
  10. package/lib/api/Transaction.d.ts.map +1 -1
  11. package/lib/api/Transaction.js +42 -0
  12. package/lib/api/Transaction.js.map +1 -1
  13. package/lib/index.d.ts +9 -3
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +13 -9
  16. package/lib/index.js.map +1 -1
  17. package/lib/schema/classes/EntitySchema.d.ts +71 -0
  18. package/lib/schema/classes/EntitySchema.d.ts.map +1 -0
  19. package/lib/schema/classes/EntitySchema.js +83 -0
  20. package/lib/schema/classes/EntitySchema.js.map +1 -0
  21. package/lib/schema/classes/RelationDefinitionSchema.d.ts +87 -0
  22. package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -0
  23. package/lib/schema/classes/RelationDefinitionSchema.js +128 -0
  24. package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -0
  25. package/lib/schema/classes/Schema.d.ts +54 -0
  26. package/lib/schema/classes/Schema.d.ts.map +1 -0
  27. package/lib/schema/classes/Schema.js +75 -0
  28. package/lib/schema/classes/Schema.js.map +1 -0
  29. package/lib/schema/classes/Utils.d.ts +30 -0
  30. package/lib/schema/classes/Utils.d.ts.map +1 -0
  31. package/lib/schema/classes/Utils.js +25 -0
  32. package/lib/schema/classes/Utils.js.map +1 -0
  33. package/lib/schema/raw/Constraints.d.ts +58 -0
  34. package/lib/schema/raw/Constraints.d.ts.map +1 -0
  35. package/lib/schema/raw/Constraints.js +3 -0
  36. package/lib/schema/raw/Constraints.js.map +1 -0
  37. package/lib/schema/raw/Entities.d.ts +13 -0
  38. package/lib/schema/raw/Entities.d.ts.map +1 -0
  39. package/lib/schema/{SchemaJSON.js → raw/Entities.js} +1 -1
  40. package/lib/schema/raw/Entities.js.map +1 -0
  41. package/lib/schema/raw/RelationDefinitions.d.ts +113 -0
  42. package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -0
  43. package/lib/schema/raw/RelationDefinitions.js +3 -0
  44. package/lib/schema/raw/RelationDefinitions.js.map +1 -0
  45. package/lib/schema/raw/Schema.d.ts +13 -0
  46. package/lib/schema/raw/Schema.d.ts.map +1 -0
  47. package/lib/schema/raw/Schema.js +3 -0
  48. package/lib/schema/raw/Schema.js.map +1 -0
  49. package/lib/schema/raw/Utils.d.ts +22 -0
  50. package/lib/schema/raw/Utils.d.ts.map +1 -0
  51. package/lib/schema/raw/Utils.js +3 -0
  52. package/lib/schema/raw/Utils.js.map +1 -0
  53. package/package.json +1 -1
  54. package/src/api/Api.ts +128 -15
  55. package/src/api/Client.ts +42 -1
  56. package/src/api/Transaction.ts +42 -0
  57. package/src/index.ts +15 -8
  58. package/src/schema/classes/EntitySchema.ts +125 -0
  59. package/src/schema/classes/RelationDefinitionSchema.ts +156 -0
  60. package/src/schema/classes/Schema.ts +122 -0
  61. package/src/schema/classes/Utils.ts +52 -0
  62. package/src/schema/raw/Constraints.ts +77 -0
  63. package/src/schema/raw/Entities.ts +13 -0
  64. package/src/schema/{SchemaJSON.ts → raw/RelationDefinitions.ts} +36 -101
  65. package/src/schema/raw/Schema.ts +16 -0
  66. package/src/schema/raw/Utils.ts +33 -0
  67. package/lib/schema/Schema.d.ts +0 -156
  68. package/lib/schema/Schema.d.ts.map +0 -1
  69. package/lib/schema/Schema.js +0 -246
  70. package/lib/schema/Schema.js.map +0 -1
  71. package/lib/schema/SchemaJSON.d.ts +0 -140
  72. package/lib/schema/SchemaJSON.d.ts.map +0 -1
  73. package/lib/schema/SchemaJSON.js.map +0 -1
  74. package/src/schema/Schema.ts +0 -371
@@ -1,65 +1,21 @@
1
- type ConstraintBase<
2
- T extends string,
3
- V extends Record<string, unknown> | null
4
- > = {
5
- type: T;
6
- value: V;
7
- };
8
-
9
- export type ConstraintOperator = ">" | ">=" | "<" | "<=";
10
- type ConstraintMessage = string | null;
11
-
12
- export type UniqueConstraint = ConstraintBase<"UniqueConstraint", null>;
13
-
14
- export type SizeConstraint = ConstraintBase<
15
- "SizeConstraint",
16
- { min: number | null; max: number | null; msg: ConstraintMessage }
17
- >;
18
-
19
- export type RegexpConstraint = ConstraintBase<
20
- "RegexpConstraint",
21
- { regexp: string; flags: number; msg: ConstraintMessage }
22
- >;
23
-
24
- export type BoundaryConstraint = ConstraintBase<
25
- "BoundaryConstraint",
26
- { boundary: number | null; op: ConstraintOperator; msg: ConstraintMessage }
27
- >;
28
- export type IntervalBoundConstraint = ConstraintBase<
29
- "IntervalBoundConstraint",
30
- { minvalue: number | null; maxvalue: number | null; msg: ConstraintMessage }
31
- >;
32
-
33
- export type StaticVocabularyConstraint = ConstraintBase<
34
- "StaticVocabularyConstraint",
35
- { values: string[]; msg: ConstraintMessage }
36
- >;
1
+ import { AttributeConstraint, RelationConstraint } from "./Constraints";
2
+ import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
37
3
 
38
- export type FormatConstraint = ConstraintBase<
39
- "FormatConstraint",
40
- {
41
- values: ["text/rest", "text/markdown", "text/html", "text/plain"];
42
- msg: ConstraintMessage;
43
- }
44
- >;
45
-
46
- export type RQLVocabularyConstraint = ConstraintBase<
47
- "RQLVocabularyConstraint",
48
- { expression: string; mainvars: string[] }
49
- >;
50
-
51
- export type AttributeConstraint = Readonly<
52
- | UniqueConstraint
53
- | SizeConstraint
54
- | RegexpConstraint
55
- | BoundaryConstraint
56
- | IntervalBoundConstraint
57
- | StaticVocabularyConstraint
58
- | FormatConstraint
59
- >;
4
+ /**
5
+ * Type representing all the possible cardinalities in CubicWeb.
6
+ */
7
+ export type Cardinality = "*" | "1" | "?" | "+";
60
8
 
61
- export type RelationConstraint = Readonly<RQLVocabularyConstraint>;
9
+ /**
10
+ * Type representing a cardinality pair as used in relation definitions.
11
+ */
12
+ export type CardinalityPair = `${Cardinality}${Cardinality}`;
62
13
 
14
+ /**
15
+ * Type used as a base to build final relation definitions with primitive types (Int, String, ...).
16
+ *
17
+ * @internal
18
+ */
63
19
  type BuildObjBase<T extends string> = {
64
20
  object: T;
65
21
  final: true;
@@ -122,6 +78,12 @@ interface IntervalBuildObj extends BuildObjBase<"Interval"> {
122
78
  default: unknown;
123
79
  }
124
80
 
81
+ /**
82
+ * Type allowing to link the type of an object to the type of their default values in a
83
+ * relation definition. It only works for final relations using primitive types.
84
+ *
85
+ * @internal
86
+ */
125
87
  export type BuildObj = Readonly<
126
88
  | StringBuildObj
127
89
  | PasswordBuildObj
@@ -139,24 +101,18 @@ export type BuildObj = Readonly<
139
101
  | IntervalBuildObj
140
102
  >;
141
103
 
142
- export type Cardinality = "*" | "1" | "?" | "+";
143
-
144
- export type CardinalityPair = `${Cardinality}${Cardinality}`;
145
-
146
- export type EntityRawSchema = {
147
- type: string;
148
- final: boolean;
149
- description: string;
150
- };
151
-
152
- export type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
153
-
104
+ /**
105
+ * Type representing the possible options for an attribute.
106
+ */
154
107
  export type AttributeOptions = {
155
108
  indexed?: boolean;
156
109
  fulltextindexed?: boolean;
157
110
  internationalizable?: boolean;
158
111
  };
159
112
 
113
+ /**
114
+ * Type representing the possible options for a relation definition.
115
+ */
160
116
  export type RelationOptions = {
161
117
  symmetric?: boolean;
162
118
  inlined?: boolean;
@@ -164,6 +120,12 @@ export type RelationOptions = {
164
120
  composite?: "subject" | "object";
165
121
  };
166
122
 
123
+ /**
124
+ * Type representing a relation definition schema.
125
+ * It can represent both attributes and relations depending on the value of Final.
126
+ *
127
+ * It can infer default values type depending on the object type if the relation is final.
128
+ */
167
129
  export type RelationDefinitionRawSchema<
168
130
  ESchemas extends EntityRawSchemaArray,
169
131
  Final extends boolean = boolean
@@ -187,36 +149,9 @@ export type RelationDefinitionRawSchema<
187
149
  })
188
150
  >;
189
151
 
152
+ /**
153
+ * Type representing a list of relation definitions.
154
+ */
190
155
  export type RelationDefinitionRawSchemaArray<
191
156
  ESchemas extends EntityRawSchemaArray
192
157
  > = ReadonlyArray<RelationDefinitionRawSchema<ESchemas, boolean>>;
193
-
194
- export type RawSchema<
195
- E extends EntityRawSchemaArray = EntityRawSchemaArray,
196
- R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>
197
- > = {
198
- entities: E;
199
- relations_definitions: R;
200
- };
201
-
202
- export type IsLooseSchema<E extends EntityRawSchemaArray> =
203
- string extends E[number]["type"] ? true : false;
204
-
205
- export type IsETypeInStrictSchema<
206
- E extends EntityRawSchemaArray,
207
- EType extends string
208
- > = EType extends E[number]["type"] ? true : false;
209
-
210
- /**
211
- * Type representing the entity's raw schema matching this type.
212
- * This type only works for EntityRawSchemaArray with literals as "type" property.
213
- *
214
- **/
215
- export type EntityRawSchemaByType<
216
- E extends EntityRawSchemaArray,
217
- T extends string
218
- > = E[number] extends infer ESchema
219
- ? ESchema extends { type: T }
220
- ? ESchema
221
- : never
222
- : never; // Will never happen E[number] always has a type
@@ -0,0 +1,16 @@
1
+ import { EntityRawSchemaArray } from "./Entities";
2
+ import { RelationDefinitionRawSchemaArray } from "./RelationDefinitions";
3
+
4
+ /**
5
+ * The full raw JSON schema type as returned by the API.
6
+ * You can export this schema from your CubicWeb instance using the command:
7
+ *
8
+ * `cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>`
9
+ */
10
+ export type RawSchema<
11
+ E extends EntityRawSchemaArray = EntityRawSchemaArray,
12
+ R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>
13
+ > = {
14
+ entities: E;
15
+ relations_definitions: R;
16
+ };
@@ -0,0 +1,33 @@
1
+ import { EntityRawSchemaArray } from "./Entities";
2
+
3
+ /**
4
+ * Type used to check if a schema is loosely typed.
5
+ * Use this to create conditional types.
6
+ *
7
+ * In the given EntityRawSchemaArray, if the entities type is a string, the schema is loosely typed.
8
+ * If the schema is strongly typed, the entities type would be a word (which is stricter than string).
9
+ */
10
+ export type IsLooseSchema<E extends EntityRawSchemaArray> =
11
+ string extends E[number]["type"] ? true : false;
12
+
13
+ /**
14
+ * Checks if the given entity type is present in the EntityRawSchemaArray.
15
+ * Use this to create conditional types.
16
+ */
17
+ export type IsETypeInStrictSchema<
18
+ E extends EntityRawSchemaArray,
19
+ EType extends string
20
+ > = EType extends E[number]["type"] ? true : false;
21
+
22
+ /**
23
+ * Type representing the entity's raw schema matching this type.
24
+ * This type only works for EntityRawSchemaArray with literals as "type" property.
25
+ */
26
+ export type EntityRawSchemaByType<
27
+ E extends EntityRawSchemaArray,
28
+ T extends string
29
+ > = E[number] extends infer ESchema
30
+ ? ESchema extends { type: T }
31
+ ? ESchema
32
+ : never
33
+ : never; // Will never happen E[number] always has a type
@@ -1,156 +0,0 @@
1
- import { Cardinality } from "..";
2
- import { RawSchema, RelationDefinitionRawSchema, RelationDefinitionRawSchemaArray, EntityRawSchemaArray, EntityRawSchemaByType, IsLooseSchema, IsETypeInStrictSchema } from "./SchemaJSON";
3
- declare const rawSchemaKey: unique symbol;
4
- /**
5
- * Returns the given schema using loose typing.
6
- * Can be useful when working for generic schemas
7
- *
8
- * @param schema The schema to create a loose type for
9
- * @returns
10
- */
11
- export declare const getLooseSchema: <E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>>(schema: Schema<E, R>) => Schema<EntityRawSchemaArray, RelationDefinitionRawSchemaArray<EntityRawSchemaArray>>;
12
- /**
13
- * Wrapper around the raw JSON Schema
14
- */
15
- export declare class Schema<E extends EntityRawSchemaArray = EntityRawSchemaArray, // List of all entities
16
- R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> {
17
- [rawSchemaKey]: RawSchema<E, R>;
18
- constructor(rawSchema: RawSchema<E, R>);
19
- get entities(): EntitySchema<E, R, E[number]>[];
20
- get relationsDefinitions(): RelationDefinitionSchema<E, R, R[number]>[];
21
- /**
22
- * Returns the entity schema for the given entity type if it exists.
23
- * When using TypeScript, this method can detect if the given type does not exist
24
- * in the schema.
25
- *
26
- * @param entityType The entity type string
27
- * @returns A new EntitySchema or null if the type does not exist
28
- */
29
- getEntity<EType extends string>(entityType: EType): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> | null : IsETypeInStrictSchema<E, EType> extends true ? EntitySchema<E, R, EntityRawSchemaByType<E, EType>> : null;
30
- /**
31
- * Finds relations in the Schema matching the partial relation given
32
- *
33
- * @param matcher Partial relation definition to match against
34
- * @returns Matched relation schema classes
35
- */
36
- matchRelationDefinitions<M extends RelationDefinitionMatcher<E>>(matcher: M): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
37
- subject: E[number]["type"];
38
- }>>[];
39
- }
40
- /**
41
- * Wrapper around raw entities from the Schema
42
- */
43
- export declare class EntitySchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, // List of all entities
44
- R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>, // List of all relation defintions
45
- ERawSchema extends E[number] = E[number]> {
46
- private schema;
47
- private entityRawSchema;
48
- constructor(schema: Schema<E, R>, entityRawSchema: ERawSchema);
49
- /**
50
- * The type of the entity. This can also be referred to as the entity' name.
51
- */
52
- get type(): ERawSchema["type"];
53
- /**
54
- * A short description which can be used as documentation for the entity.
55
- */
56
- get description(): ERawSchema["description"];
57
- /**
58
- * True if the current entity is a primitive type such as string or int
59
- */
60
- get final(): ERawSchema["final"];
61
- /**
62
- * Gets the list of relation definitions with this entity as subject
63
- */
64
- get subjectRelationDefinitions(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
65
- subject: ERawSchema["type"];
66
- final: false;
67
- }>>[];
68
- /**
69
- * Gets the list of relation definitions with this entity as object
70
- */
71
- get objectRelationsDefinitions(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
72
- object: ERawSchema["type"];
73
- final: false;
74
- }>>[];
75
- /**
76
- * Finds relations in the Schema matching the partial relation given
77
- *
78
- * @param matcher Partial relation definition to match against
79
- * @returns Matched relation schema classes
80
- */
81
- matchRelationDefinitions<M extends RelationDefinitionMatcher<E>>(matcher: M): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
82
- subject: ERawSchema["type"];
83
- }>>[];
84
- /**
85
- * Gets the list of attributes names for this entity
86
- */
87
- get attributes(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
88
- subject: ERawSchema["type"];
89
- final: true;
90
- }>>[];
91
- }
92
- /**
93
- * Wrapper around raw relation definitions from the Schema
94
- */
95
- export declare class RelationDefinitionSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, // List of all entities
96
- R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>, // List of all relation defintions
97
- RDef extends R[number] = R[number]> {
98
- private schema;
99
- private relDef;
100
- constructor(schema: Schema<E, R>, relDef: RDef);
101
- /**
102
- * The type of the relation. This can also be referred to as the relation's name.
103
- */
104
- get type(): RDef["type"];
105
- /**
106
- * A short description which can be used as documentation for the relation.
107
- */
108
- get description(): RDef["description"];
109
- /**
110
- * True if the object of the relation is a primitive type.
111
- * In this case the relation iscalled an "attribute"
112
- */
113
- get final(): RDef["final"];
114
- /**
115
- * The list of options set for this relation
116
- */
117
- get options(): RDef["options"];
118
- /**
119
- * The list of constraints if any. Only attributes (relations with final = true) have constraints.
120
- * In other cases this returns null.
121
- */
122
- get constraints(): RDef["constraints"];
123
- /**
124
- * The default value for this relation.
125
- * It can be used when creating new relations if user did not enter a value (even if required).
126
- */
127
- get default(): RDef extends {
128
- default: infer V;
129
- } ? V : undefined;
130
- get cardinality(): RDef["cardinality"];
131
- get subjectCardinality(): Cardinality;
132
- get objectCardinality(): Cardinality;
133
- /**
134
- * Gets the entity associated to this relation's subject
135
- *
136
- * @throws InconsistentSchemaError if the relation's subject is not a valid entity
137
- */
138
- get subject(): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> : EntitySchema<E, R, EntityRawSchemaByType<E, RDef["subject"]>>;
139
- /**
140
- * Gets the entity associated to this relation's object
141
- *
142
- * @throws InconsistentSchemaError if the relation's object is not a valid entity
143
- */
144
- get object(): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> : EntitySchema<E, R, EntityRawSchemaByType<E, RDef["object"]>>;
145
- /**
146
- * Checks if the relation is required when using the subject or object pointof view
147
- *
148
- * @param role The point of view to use
149
- * @returns
150
- */
151
- isRequired(role: "subject" | "object"): boolean;
152
- }
153
- export declare type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<RelationDefinitionRawSchema<E>>;
154
- export declare type MatchedRelationDefinition<E extends EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<EntityRawSchemaArray>, M extends RelationDefinitionMatcher<E>> = R[number] extends infer RDef ? (RDef extends M ? RDef : never) : never;
155
- export {};
156
- //# sourceMappingURL=Schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/schema/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAEjC,OAAO,EACL,SAAS,EACT,2BAA2B,EAC3B,gCAAgC,EAChC,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAEtB,QAAA,MAAM,YAAY,EAAE,OAAO,MAA2C,CAAC;AAEvE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,4PAO1B,CAAC;AAEF;;GAEG;AACH,qBAAa,MAAM,CACjB,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,uBAAuB;AAC9E,CAAC,SAAS,gCAAg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EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAUhE;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,SAAS,IAAI,GACvC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAC7B,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAU/D;IAED;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ;CAStC;AAYD,oBAAY,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,IAAI,OAAO,CAC7E,2BAA2B,CAAC,CAAC,CAAC,CAC/B,CAAC;AAEF,oBAAY,yBAAyB,CACnC,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,gCAAgC,CAAC,oBAAoB,CAAC,EAChE,CAAC,SAAS,yBAAyB,CAAC,CAAC,CAAC,IACpC,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC"}
@@ -1,246 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RelationDefinitionSchema = exports.EntitySchema = exports.Schema = exports.getLooseSchema = void 0;
4
- const Errors_1 = require("../Errors");
5
- const rawSchemaKey = Symbol("Indexer of the rawSchema");
6
- /**
7
- * Returns the given schema using loose typing.
8
- * Can be useful when working for generic schemas
9
- *
10
- * @param schema The schema to create a loose type for
11
- * @returns
12
- */
13
- const getLooseSchema = (schema) => {
14
- return schema;
15
- };
16
- exports.getLooseSchema = getLooseSchema;
17
- /**
18
- * Wrapper around the raw JSON Schema
19
- */
20
- class Schema {
21
- constructor(rawSchema) {
22
- this[rawSchemaKey] = rawSchema;
23
- }
24
- get entities() {
25
- return this[rawSchemaKey].entities.map((eSchema) => new EntitySchema(this, eSchema));
26
- }
27
- get relationsDefinitions() {
28
- return this[rawSchemaKey].relations_definitions.map((rdefSchema) => new RelationDefinitionSchema(this, rdefSchema));
29
- }
30
- /**
31
- * Returns the entity schema for the given entity type if it exists.
32
- * When using TypeScript, this method can detect if the given type does not exist
33
- * in the schema.
34
- *
35
- * @param entityType The entity type string
36
- * @returns A new EntitySchema or null if the type does not exist
37
- */
38
- getEntity(entityType) {
39
- const entityRawSchema = this[rawSchemaKey].entities.filter((eSchema) => eSchema.type === entityType)[0];
40
- if (!entityRawSchema) {
41
- // Is only null when the given type is not in the schema.
42
- // Thus the return type will be (EntitySchema | null)
43
- // but TypeScript does not understand this
44
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
- // @ts-ignore
46
- return null;
47
- }
48
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
49
- // @ts-ignore
50
- return new EntitySchema(this, entityRawSchema);
51
- }
52
- /**
53
- * Finds relations in the Schema matching the partial relation given
54
- *
55
- * @param matcher Partial relation definition to match against
56
- * @returns Matched relation schema classes
57
- */
58
- matchRelationDefinitions(matcher) {
59
- const matchArray = this[rawSchemaKey].relations_definitions.filter((relDef) => {
60
- for (const key of Object.keys(matcher)) {
61
- if (matcher[key] !== relDef[key]) {
62
- return false;
63
- }
64
- }
65
- return true;
66
- });
67
- return matchArray.map((m) => new RelationDefinitionSchema(this, m));
68
- }
69
- }
70
- exports.Schema = Schema;
71
- /**
72
- * Wrapper around raw entities from the Schema
73
- */
74
- class EntitySchema {
75
- constructor(schema, entityRawSchema) {
76
- this.schema = schema;
77
- this.entityRawSchema = entityRawSchema;
78
- }
79
- /**
80
- * The type of the entity. This can also be referred to as the entity' name.
81
- */
82
- get type() {
83
- return this.entityRawSchema.type;
84
- }
85
- /**
86
- * A short description which can be used as documentation for the entity.
87
- */
88
- get description() {
89
- return this.entityRawSchema.description;
90
- }
91
- /**
92
- * True if the current entity is a primitive type such as string or int
93
- */
94
- get final() {
95
- return this.entityRawSchema.final;
96
- }
97
- /**
98
- * Gets the list of relation definitions with this entity as subject
99
- */
100
- get subjectRelationDefinitions() {
101
- return this.schema.matchRelationDefinitions({
102
- subject: this.type,
103
- final: false,
104
- });
105
- }
106
- /**
107
- * Gets the list of relation definitions with this entity as object
108
- */
109
- get objectRelationsDefinitions() {
110
- return this.schema.matchRelationDefinitions({
111
- object: this.type,
112
- final: false,
113
- });
114
- }
115
- /**
116
- * Finds relations in the Schema matching the partial relation given
117
- *
118
- * @param matcher Partial relation definition to match against
119
- * @returns Matched relation schema classes
120
- */
121
- matchRelationDefinitions(matcher) {
122
- return this.schema.matchRelationDefinitions(matcher);
123
- }
124
- /**
125
- * Gets the list of attributes names for this entity
126
- */
127
- get attributes() {
128
- return this.schema.matchRelationDefinitions({
129
- final: true,
130
- subject: this.type,
131
- });
132
- }
133
- }
134
- exports.EntitySchema = EntitySchema;
135
- /**
136
- * Wrapper around raw relation definitions from the Schema
137
- */
138
- class RelationDefinitionSchema {
139
- constructor(schema, relDef) {
140
- this.schema = schema;
141
- this.relDef = relDef;
142
- }
143
- /**
144
- * The type of the relation. This can also be referred to as the relation's name.
145
- */
146
- get type() {
147
- return this.relDef.type;
148
- }
149
- /**
150
- * A short description which can be used as documentation for the relation.
151
- */
152
- get description() {
153
- return this.relDef.description;
154
- }
155
- /**
156
- * True if the object of the relation is a primitive type.
157
- * In this case the relation iscalled an "attribute"
158
- */
159
- get final() {
160
- return this.relDef.final;
161
- }
162
- /**
163
- * The list of options set for this relation
164
- */
165
- get options() {
166
- return this.relDef.options;
167
- }
168
- /**
169
- * The list of constraints if any. Only attributes (relations with final = true) have constraints.
170
- * In other cases this returns null.
171
- */
172
- get constraints() {
173
- return this.relDef.constraints;
174
- }
175
- /**
176
- * The default value for this relation.
177
- * It can be used when creating new relations if user did not enter a value (even if required).
178
- */
179
- get default() {
180
- return ("default" in this.relDef ? this.relDef.default : undefined);
181
- }
182
- get cardinality() {
183
- return this.relDef.cardinality;
184
- }
185
- get subjectCardinality() {
186
- return this.relDef.cardinality[0];
187
- }
188
- get objectCardinality() {
189
- return this.relDef.cardinality[1];
190
- }
191
- /**
192
- * Gets the entity associated to this relation's subject
193
- *
194
- * @throws InconsistentSchemaError if the relation's subject is not a valid entity
195
- */
196
- get subject() {
197
- const subjectSchema = this.schema.getEntity(this.relDef.subject);
198
- if (subjectSchema === null) {
199
- throw new Errors_1.InconsistentSchemaError(`entity type ${this.relDef.subject} used as subject of relation ${this.type} is not declared`);
200
- }
201
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
202
- // @ts-ignore
203
- return subjectSchema;
204
- }
205
- /**
206
- * Gets the entity associated to this relation's object
207
- *
208
- * @throws InconsistentSchemaError if the relation's object is not a valid entity
209
- */
210
- get object() {
211
- const objectSchema = this.schema.getEntity(this.relDef.object);
212
- if (objectSchema === null) {
213
- throw new Errors_1.InconsistentSchemaError(`entity type ${this.relDef.object} used as object of relation ${this.type} is not declared`);
214
- }
215
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
216
- // @ts-ignore
217
- return objectSchema;
218
- }
219
- /**
220
- * Checks if the relation is required when using the subject or object pointof view
221
- *
222
- * @param role The point of view to use
223
- * @returns
224
- */
225
- isRequired(role) {
226
- let cardinality;
227
- if (role === "subject") {
228
- cardinality = this.cardinality[0];
229
- }
230
- else {
231
- cardinality = this.cardinality[1];
232
- }
233
- return cardinalityRequired(cardinality);
234
- }
235
- }
236
- exports.RelationDefinitionSchema = RelationDefinitionSchema;
237
- /**
238
- * Checks if the given cardinality requires at least one entity to be present
239
- *
240
- * @param cardinality The cardinality to check
241
- * @returns
242
- */
243
- function cardinalityRequired(cardinality) {
244
- return cardinality === "1" || cardinality === "+";
245
- }
246
- //# sourceMappingURL=Schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/schema/Schema.ts"],"names":[],"mappings":";;;AACA,sCAAoD;AAWpD,MAAM,YAAY,GAAkB,MAAM,CAAC,0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