@cubicweb/client 2.1.1 → 3.0.0-alpha.5
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/README.md +28 -16
- package/lib/api/Api.d.ts +25 -10
- package/lib/api/Api.d.ts.map +1 -1
- package/lib/api/Api.js +69 -43
- package/lib/api/Api.js.map +1 -1
- package/lib/api/Client.d.ts +11 -6
- package/lib/api/Client.d.ts.map +1 -1
- package/lib/api/Client.js +20 -11
- package/lib/api/Client.js.map +1 -1
- package/lib/api/Transaction.d.ts +6 -9
- package/lib/api/Transaction.d.ts.map +1 -1
- package/lib/api/Transaction.js +11 -21
- package/lib/api/Transaction.js.map +1 -1
- package/lib/schema/classes/EntitySchema.d.ts +16 -22
- package/lib/schema/classes/EntitySchema.d.ts.map +1 -1
- package/lib/schema/classes/EntitySchema.js +17 -25
- package/lib/schema/classes/EntitySchema.js.map +1 -1
- package/lib/schema/classes/RelationDefinitionSchema.d.ts +8 -10
- package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -1
- package/lib/schema/classes/RelationDefinitionSchema.js +7 -21
- package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -1
- package/lib/schema/classes/Schema.d.ts +2 -0
- package/lib/schema/classes/Schema.d.ts.map +1 -1
- package/lib/schema/classes/Schema.js +2 -0
- package/lib/schema/classes/Schema.js.map +1 -1
- package/lib/schema/classes/Utils.d.ts +135 -1
- package/lib/schema/classes/Utils.d.ts.map +1 -1
- package/lib/schema/classes/Utils.js +165 -3
- package/lib/schema/classes/Utils.js.map +1 -1
- package/lib/schema/raw/Constraints.d.ts +13 -5
- package/lib/schema/raw/Constraints.d.ts.map +1 -1
- package/lib/schema/raw/Entities.d.ts +4 -0
- package/lib/schema/raw/Entities.d.ts.map +1 -1
- package/lib/schema/raw/RelationDefinitions.d.ts +15 -2
- package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
- package/lib/schema/raw/Schema.d.ts +2 -0
- package/lib/schema/raw/Schema.d.ts.map +1 -1
- package/lib/schema/raw/Utils.d.ts +6 -0
- package/lib/schema/raw/Utils.d.ts.map +1 -1
- package/package.json +4 -8
- package/src/api/Api.ts +79 -38
- package/src/api/Client.ts +24 -20
- package/src/api/Transaction.ts +16 -12
- package/src/schema/classes/EntitySchema.ts +35 -41
- package/src/schema/classes/RelationDefinitionSchema.ts +10 -25
- package/src/schema/classes/Schema.ts +2 -0
- package/src/schema/classes/Utils.ts +178 -1
- package/src/schema/raw/Constraints.ts +13 -5
- package/src/schema/raw/Entities.ts +4 -0
- package/src/schema/raw/RelationDefinitions.ts +15 -2
- package/src/schema/raw/Schema.ts +2 -0
- package/src/schema/raw/Utils.ts +6 -0
|
@@ -8,6 +8,8 @@ import { MatchedRelationDefinition, RelationDefinitionMatcher } from "./Utils";
|
|
|
8
8
|
* Wrapper around raw entity schemas from the Schema.
|
|
9
9
|
* You should never have to create this object yourself.
|
|
10
10
|
* Instead, retrieve these objects from the methods in the `Schema` class.
|
|
11
|
+
*
|
|
12
|
+
* @category Schema
|
|
11
13
|
*/
|
|
12
14
|
export class EntitySchema<
|
|
13
15
|
E extends EntityRawSchemaArray = EntityRawSchemaArray,
|
|
@@ -49,43 +51,54 @@ export class EntitySchema<
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
|
-
* Gets the list of relation
|
|
53
|
-
*
|
|
54
|
-
* there will be dupicates when used along with `objectRelationsDefinitions`.
|
|
54
|
+
* Gets the list of attribute schemas (relation definition schemas with final at false)
|
|
55
|
+
* for this entity schema.
|
|
55
56
|
*/
|
|
56
|
-
get
|
|
57
|
+
get attributes(): RelationDefinitionSchema<
|
|
57
58
|
E,
|
|
58
59
|
R,
|
|
59
60
|
MatchedRelationDefinition<
|
|
60
61
|
E,
|
|
61
62
|
R,
|
|
62
|
-
{ subject: ERawSchema["type"]; final:
|
|
63
|
+
{ subject: ERawSchema["type"]; final: true }
|
|
63
64
|
>
|
|
64
65
|
>[] {
|
|
65
66
|
return this.schema.matchRelationDefinitions({
|
|
67
|
+
final: true,
|
|
66
68
|
subject: this.type,
|
|
67
|
-
final: false,
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* In case a relation definition schema has this entity as both object and subject,
|
|
74
|
-
* there will be dupicates when used along with `subjectRelationDefinitions`.
|
|
75
|
-
*/
|
|
76
|
-
get objectRelationsDefinitions(): RelationDefinitionSchema<
|
|
77
|
-
E,
|
|
78
|
-
R,
|
|
79
|
-
MatchedRelationDefinition<
|
|
72
|
+
get relationDefinitions(): {
|
|
73
|
+
subject: RelationDefinitionSchema<
|
|
80
74
|
E,
|
|
81
75
|
R,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
MatchedRelationDefinition<
|
|
77
|
+
E,
|
|
78
|
+
R,
|
|
79
|
+
{ subject: ERawSchema["type"]; final: false }
|
|
80
|
+
>
|
|
81
|
+
>[];
|
|
82
|
+
object: RelationDefinitionSchema<
|
|
83
|
+
E,
|
|
84
|
+
R,
|
|
85
|
+
MatchedRelationDefinition<
|
|
86
|
+
E,
|
|
87
|
+
R,
|
|
88
|
+
{ object: ERawSchema["type"]; final: false }
|
|
89
|
+
>
|
|
90
|
+
>[];
|
|
91
|
+
} {
|
|
92
|
+
return {
|
|
93
|
+
subject: this.schema.matchRelationDefinitions({
|
|
94
|
+
subject: this.type,
|
|
95
|
+
final: false,
|
|
96
|
+
}),
|
|
97
|
+
object: this.schema.matchRelationDefinitions({
|
|
98
|
+
object: this.type,
|
|
99
|
+
final: false,
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
89
102
|
}
|
|
90
103
|
|
|
91
104
|
/**
|
|
@@ -103,23 +116,4 @@ export class EntitySchema<
|
|
|
103
116
|
>[] {
|
|
104
117
|
return this.schema.matchRelationDefinitions(matcher);
|
|
105
118
|
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Gets the list of attribute schemas (relation definition schemas with final at false)
|
|
109
|
-
* for this entity schema.
|
|
110
|
-
*/
|
|
111
|
-
get attributes(): RelationDefinitionSchema<
|
|
112
|
-
E,
|
|
113
|
-
R,
|
|
114
|
-
MatchedRelationDefinition<
|
|
115
|
-
E,
|
|
116
|
-
R,
|
|
117
|
-
{ subject: ERawSchema["type"]; final: true }
|
|
118
|
-
>
|
|
119
|
-
>[] {
|
|
120
|
-
return this.schema.matchRelationDefinitions({
|
|
121
|
-
final: true,
|
|
122
|
-
subject: this.type,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
119
|
}
|
|
@@ -7,12 +7,14 @@ import {
|
|
|
7
7
|
import { IsLooseSchema, EntityRawSchemaByType } from "../raw/Utils";
|
|
8
8
|
import { EntitySchema } from "./EntitySchema";
|
|
9
9
|
import { Schema } from "./Schema";
|
|
10
|
-
import {
|
|
10
|
+
import { EntityRole, isCardinalityRequired } from "./Utils";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Wrapper around raw relation definition schemas from the Schema.
|
|
14
14
|
* You should never have to create this object yourself.
|
|
15
15
|
* Instead, retrieve these objects from the methods in the `Schema` class.
|
|
16
|
+
*
|
|
17
|
+
* @category Schema
|
|
16
18
|
*/
|
|
17
19
|
export class RelationDefinitionSchema<
|
|
18
20
|
E extends EntityRawSchemaArray = EntityRawSchemaArray,
|
|
@@ -84,22 +86,11 @@ export class RelationDefinitionSchema<
|
|
|
84
86
|
/**
|
|
85
87
|
* The cardinality of this relation definition schema.
|
|
86
88
|
*/
|
|
87
|
-
get cardinality():
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* The cardinality of this relation definition schema's subject.
|
|
93
|
-
*/
|
|
94
|
-
get subjectCardinality(): Cardinality {
|
|
95
|
-
return this.relDef.cardinality[0] as Cardinality;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* The cardinality of this relation definition schema's object.
|
|
100
|
-
*/
|
|
101
|
-
get objectCardinality(): Cardinality {
|
|
102
|
-
return this.relDef.cardinality[1] as Cardinality;
|
|
89
|
+
get cardinality(): { subject: Cardinality; object: Cardinality } {
|
|
90
|
+
return {
|
|
91
|
+
subject: this.relDef.cardinality[0] as Cardinality,
|
|
92
|
+
object: this.relDef.cardinality[1] as Cardinality,
|
|
93
|
+
};
|
|
103
94
|
}
|
|
104
95
|
|
|
105
96
|
/**
|
|
@@ -144,13 +135,7 @@ export class RelationDefinitionSchema<
|
|
|
144
135
|
* @param role The point of view to use
|
|
145
136
|
* @returns
|
|
146
137
|
*/
|
|
147
|
-
isRequired(role:
|
|
148
|
-
|
|
149
|
-
if (role === "subject") {
|
|
150
|
-
cardinality = this.subjectCardinality;
|
|
151
|
-
} else {
|
|
152
|
-
cardinality = this.objectCardinality;
|
|
153
|
-
}
|
|
154
|
-
return cardinalityRequired(cardinality);
|
|
138
|
+
isRequired(role: EntityRole) {
|
|
139
|
+
return isCardinalityRequired(this.cardinality[role]);
|
|
155
140
|
}
|
|
156
141
|
}
|
|
@@ -19,6 +19,8 @@ const rawSchemaKey: unique symbol = Symbol("Indexer of the rawSchema");
|
|
|
19
19
|
* Wrapper around the raw JSON Schema.
|
|
20
20
|
* It is recommended to use this class instead of the raw JSON Schema
|
|
21
21
|
* as it is more robust to schema changes and provides utility functions.
|
|
22
|
+
*
|
|
23
|
+
* @category Schema
|
|
22
24
|
*/
|
|
23
25
|
export class Schema<
|
|
24
26
|
E extends EntityRawSchemaArray = EntityRawSchemaArray,
|
|
@@ -7,12 +7,26 @@ import {
|
|
|
7
7
|
import { Schema } from "./Schema";
|
|
8
8
|
import { EntitySchema } from "./EntitySchema";
|
|
9
9
|
|
|
10
|
+
// This prefix is often applied to relation types as convention
|
|
11
|
+
// indicating a relation is viewed from the object's point of view
|
|
12
|
+
// We do not export it and instead encourage users to use the utility functions
|
|
13
|
+
const REVERSE_INDICATOR = "reverse_";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An entity role in a relation.
|
|
17
|
+
*
|
|
18
|
+
* @category Utils
|
|
19
|
+
*/
|
|
20
|
+
export type EntityRole = "subject" | "object";
|
|
21
|
+
|
|
10
22
|
/**
|
|
11
23
|
* Returns the given schema using loose typing.
|
|
12
24
|
* Can be useful when working with generic schemas
|
|
13
25
|
*
|
|
14
26
|
* @param schema The schema to create a loose type for
|
|
15
27
|
* @returns A loosely typed schema
|
|
28
|
+
*
|
|
29
|
+
* @category Utils
|
|
16
30
|
*/
|
|
17
31
|
export const getLooseSchema = <
|
|
18
32
|
E extends EntityRawSchemaArray = EntityRawSchemaArray,
|
|
@@ -28,13 +42,174 @@ export const getLooseSchema = <
|
|
|
28
42
|
*
|
|
29
43
|
* @param cardinality The cardinality to check
|
|
30
44
|
* @returns True if the cardinality is 1 or +
|
|
45
|
+
*
|
|
46
|
+
* @category Utils
|
|
31
47
|
*/
|
|
32
|
-
export function
|
|
48
|
+
export function isCardinalityRequired(cardinality: Cardinality): boolean {
|
|
33
49
|
return cardinality === "1" || cardinality === "+";
|
|
34
50
|
}
|
|
35
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the cardinality allows multiple entities to be present
|
|
54
|
+
*
|
|
55
|
+
* @param cardinality The cardinility to check
|
|
56
|
+
* @returns True if the cardinality is `*` or `+`
|
|
57
|
+
*
|
|
58
|
+
* @category Utils
|
|
59
|
+
*/
|
|
60
|
+
export const isCardinalityMultiple = (cardinality: Cardinality): boolean => {
|
|
61
|
+
return cardinality === "*" || cardinality === "+";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Checks if the cardinality allows entities to be absent
|
|
66
|
+
*
|
|
67
|
+
* @param cardinality The cardinility to check
|
|
68
|
+
* @returns True if the cardinality is `?` or `*`
|
|
69
|
+
*
|
|
70
|
+
* @category Utils
|
|
71
|
+
*/
|
|
72
|
+
export const isCardinalityOptional = (cardinality: Cardinality): boolean => {
|
|
73
|
+
return cardinality === "?" || cardinality === "*";
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Reverses the given role name
|
|
78
|
+
*
|
|
79
|
+
* @param role The role to reverse
|
|
80
|
+
* @returns "object" if the given role was "subject", "subject" otherwise
|
|
81
|
+
*
|
|
82
|
+
* @category Utils
|
|
83
|
+
*/
|
|
84
|
+
export function getOppositeRelationRole(role: EntityRole): EntityRole {
|
|
85
|
+
return role === "subject" ? "object" : "subject";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the given relation type is reversed.
|
|
90
|
+
*
|
|
91
|
+
* A reversed relation means the relation is considered from the object entity
|
|
92
|
+
* point of view.
|
|
93
|
+
* The reverse indicator is a prefix added as a convention in CubicWeb.
|
|
94
|
+
*
|
|
95
|
+
* @param relationType The relation type to check
|
|
96
|
+
* @returns True if the relation type starts with the reverse indicator
|
|
97
|
+
*
|
|
98
|
+
* @category Utils
|
|
99
|
+
*/
|
|
100
|
+
export const isRelationTypeReversed = (relationType: string): boolean => {
|
|
101
|
+
return relationType.startsWith(REVERSE_INDICATOR);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Gets the entity role in the given relation type by
|
|
106
|
+
* checking for the reverse indicator
|
|
107
|
+
*
|
|
108
|
+
* A reversed relation means the relation is considered from the object entity
|
|
109
|
+
* point of view.
|
|
110
|
+
* The reverse indicator is a prefix added as a convention in CubicWeb.
|
|
111
|
+
*
|
|
112
|
+
* @param relationType The relation type to check
|
|
113
|
+
* @returns "subject" if the relation is not reversed, "object" otherwise
|
|
114
|
+
*
|
|
115
|
+
* @category Utils
|
|
116
|
+
*/
|
|
117
|
+
export const getRoleFromRelationType = (relationType: string): EntityRole => {
|
|
118
|
+
return isRelationTypeReversed(relationType) ? "object" : "subject";
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Adds the reverse indicator from the relation type if it is not already present.
|
|
123
|
+
*
|
|
124
|
+
* A reversed relation means the relation is considered from the object entity
|
|
125
|
+
* point of view.
|
|
126
|
+
* The reverse indicator is a prefix added as a convention in CubicWeb.
|
|
127
|
+
*
|
|
128
|
+
* @param relationType The relation type to transform
|
|
129
|
+
* @returns The relation type with the reverse indicator added or removed
|
|
130
|
+
*
|
|
131
|
+
* @category Utils
|
|
132
|
+
*/
|
|
133
|
+
export const getReverseRelationType = (relationType: string): string => {
|
|
134
|
+
if (!isRelationTypeReversed(relationType)) {
|
|
135
|
+
return `${REVERSE_INDICATOR}${relationType}`;
|
|
136
|
+
} else {
|
|
137
|
+
return relationType;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Clears the reverse indicator from the relation type if it is present.
|
|
143
|
+
*
|
|
144
|
+
* A reversed relation means the relation is considered from the object entity
|
|
145
|
+
* point of view.
|
|
146
|
+
* The reverse indicator is a prefix added as a convention in CubicWeb.
|
|
147
|
+
*
|
|
148
|
+
* @param relationType The relation type to transform
|
|
149
|
+
* @returns The relation type with the reverse indicator added or removed
|
|
150
|
+
*
|
|
151
|
+
* @category Utils
|
|
152
|
+
*/
|
|
153
|
+
export const getRawRelationType = (relationType: string): string => {
|
|
154
|
+
if (isRelationTypeReversed(relationType)) {
|
|
155
|
+
return relationType.replace(REVERSE_INDICATOR, "");
|
|
156
|
+
} else {
|
|
157
|
+
return relationType;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Returns the relation type with the reverse indicator added if necessary.
|
|
163
|
+
*
|
|
164
|
+
* A reversed relation means the relation is considered from the object entity
|
|
165
|
+
* point of view.
|
|
166
|
+
* The reverse indicator is a prefix added as a convention in CubicWeb.
|
|
167
|
+
*
|
|
168
|
+
* @param relationType The relation type to transform
|
|
169
|
+
* @param role The entity role in the relation
|
|
170
|
+
* @returns A relation type with the reverse indicator if necessary
|
|
171
|
+
*
|
|
172
|
+
* @category Utils
|
|
173
|
+
*/
|
|
174
|
+
export const getRelationType = (relationType: string, role: EntityRole) => {
|
|
175
|
+
return role === "subject"
|
|
176
|
+
? relationType
|
|
177
|
+
: getReverseRelationType(relationType);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Finds the relation matching the provided source, relation typ and target
|
|
182
|
+
*
|
|
183
|
+
* @param entitySchema The entity schema the relation is from
|
|
184
|
+
* @param sourceType The entity type acting as source for the relation
|
|
185
|
+
* @param relationType The type of the relation to use. Can have the reverse indicator to decide the role of the source/target entities
|
|
186
|
+
* @param targetType The entity type acting as target for the relation
|
|
187
|
+
* @returns The relation definition matching the triplet source relation target
|
|
188
|
+
*
|
|
189
|
+
* @category Utils
|
|
190
|
+
*/
|
|
191
|
+
export const getRelationDefinition = (
|
|
192
|
+
entitySchema: EntitySchema,
|
|
193
|
+
sourceType: string,
|
|
194
|
+
relationType: string,
|
|
195
|
+
targetType: string
|
|
196
|
+
) => {
|
|
197
|
+
const role = getRoleFromRelationType(relationType);
|
|
198
|
+
const match = entitySchema.matchRelationDefinitions({
|
|
199
|
+
[role]: sourceType,
|
|
200
|
+
type: getRawRelationType(relationType),
|
|
201
|
+
[getOppositeRelationRole(role)]: targetType,
|
|
202
|
+
});
|
|
203
|
+
if (match.length > 0) {
|
|
204
|
+
return match[0];
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
};
|
|
208
|
+
|
|
36
209
|
/**
|
|
37
210
|
* Partial raw relation definition schema type.
|
|
211
|
+
*
|
|
212
|
+
* @category Utils
|
|
38
213
|
*/
|
|
39
214
|
export type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<
|
|
40
215
|
RelationDefinitionRawSchema<E>
|
|
@@ -45,6 +220,8 @@ export type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<
|
|
|
45
220
|
* If it finds a relation definition matching the partial one given, it will return its type.
|
|
46
221
|
* If it cannot find any relation definition matching, it will return the `never` type
|
|
47
222
|
* and TypeScript will give compile errors.
|
|
223
|
+
*
|
|
224
|
+
* @category Utils
|
|
48
225
|
*/
|
|
49
226
|
export type MatchedRelationDefinition<
|
|
50
227
|
E extends EntityRawSchemaArray,
|
|
@@ -10,7 +10,7 @@ type ConstraintBase<
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* The type of a constraint message when one is present.
|
|
14
14
|
*/
|
|
15
15
|
type ConstraintMessage = string | null;
|
|
16
16
|
|
|
@@ -33,6 +33,8 @@ export type RegexpConstraint = ConstraintBase<
|
|
|
33
33
|
* Reference to an attribute used in constraints.
|
|
34
34
|
*
|
|
35
35
|
* @property \_\_attribute\_\_ name of the attribute in the same entity
|
|
36
|
+
*
|
|
37
|
+
* @category Schema
|
|
36
38
|
*/
|
|
37
39
|
export interface Attribute {
|
|
38
40
|
__attribute__: string;
|
|
@@ -50,6 +52,8 @@ export interface TimeDelta {
|
|
|
50
52
|
* @property \_\_today\_\_ always true
|
|
51
53
|
* @property offset delta to current date at the time of the check
|
|
52
54
|
* @property type name of the Python class used to do the comparison
|
|
55
|
+
*
|
|
56
|
+
* @category Schema
|
|
53
57
|
*/
|
|
54
58
|
export interface Today {
|
|
55
59
|
__today__: true;
|
|
@@ -62,6 +66,8 @@ export interface Today {
|
|
|
62
66
|
*
|
|
63
67
|
* @property \_\_now\_\_ always true
|
|
64
68
|
* @property offset delta to current date at the time of the check
|
|
69
|
+
*
|
|
70
|
+
* @category Schema
|
|
65
71
|
*/
|
|
66
72
|
export interface Now {
|
|
67
73
|
__now__: true;
|
|
@@ -70,13 +76,11 @@ export interface Now {
|
|
|
70
76
|
|
|
71
77
|
/**
|
|
72
78
|
* All the possible operators inside a constraint.
|
|
79
|
+
*
|
|
80
|
+
* @category Schema
|
|
73
81
|
*/
|
|
74
82
|
export type ConstraintOperator = ">" | ">=" | "<" | "<=";
|
|
75
83
|
|
|
76
|
-
/**
|
|
77
|
-
* @property value.boundary boudary value to compare the attribut
|
|
78
|
-
*
|
|
79
|
-
*/
|
|
80
84
|
export type BoundaryConstraint = ConstraintBase<
|
|
81
85
|
"BoundaryConstraint",
|
|
82
86
|
{
|
|
@@ -115,6 +119,8 @@ export type RQLConstraint = ConstraintBase<
|
|
|
115
119
|
|
|
116
120
|
/**
|
|
117
121
|
* Type representing all possible constraints for attributes.
|
|
122
|
+
*
|
|
123
|
+
* @category Schema
|
|
118
124
|
*/
|
|
119
125
|
export type AttributeConstraint = Readonly<
|
|
120
126
|
| UniqueConstraint
|
|
@@ -129,6 +135,8 @@ export type AttributeConstraint = Readonly<
|
|
|
129
135
|
|
|
130
136
|
/**
|
|
131
137
|
* Type representing all possible constraints for relations.
|
|
138
|
+
*
|
|
139
|
+
* @category Schema
|
|
132
140
|
*/
|
|
133
141
|
export type RelationConstraint = Readonly<
|
|
134
142
|
RQLVocabularyConstraint | RQLConstraint
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type representing an entity schema.
|
|
3
|
+
*
|
|
4
|
+
* @category Schema
|
|
3
5
|
*/
|
|
4
6
|
export type EntityRawSchema = {
|
|
5
7
|
type: string;
|
|
@@ -9,5 +11,7 @@ export type EntityRawSchema = {
|
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Type representing a list of entity schemas.
|
|
14
|
+
*
|
|
15
|
+
* @category Schema
|
|
12
16
|
*/
|
|
13
17
|
export type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { EntityRole } from "../classes/Utils";
|
|
1
2
|
import { AttributeConstraint, RelationConstraint } from "./Constraints";
|
|
2
3
|
import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Type representing all the possible cardinalities in CubicWeb.
|
|
7
|
+
*
|
|
8
|
+
* @category Schema
|
|
6
9
|
*/
|
|
7
10
|
export type Cardinality = "*" | "1" | "?" | "+";
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Type representing a cardinality pair as used in relation definitions.
|
|
14
|
+
*
|
|
15
|
+
* @category Schema
|
|
11
16
|
*/
|
|
12
17
|
export type CardinalityPair = `${Cardinality}${Cardinality}`;
|
|
13
18
|
|
|
@@ -109,6 +114,8 @@ export type BuildObj = Readonly<
|
|
|
109
114
|
|
|
110
115
|
/**
|
|
111
116
|
* Type representing the possible options for an attribute.
|
|
117
|
+
*
|
|
118
|
+
* @category Schema
|
|
112
119
|
*/
|
|
113
120
|
export type AttributeOptions = {
|
|
114
121
|
indexed?: boolean;
|
|
@@ -118,12 +125,14 @@ export type AttributeOptions = {
|
|
|
118
125
|
|
|
119
126
|
/**
|
|
120
127
|
* Type representing the possible options for a relation definition.
|
|
128
|
+
*
|
|
129
|
+
* @category Schema
|
|
121
130
|
*/
|
|
122
131
|
export type RelationOptions = {
|
|
123
132
|
symmetric?: boolean;
|
|
124
133
|
inlined?: boolean;
|
|
125
|
-
fulltext_container?:
|
|
126
|
-
composite?:
|
|
134
|
+
fulltext_container?: EntityRole;
|
|
135
|
+
composite?: EntityRole;
|
|
127
136
|
};
|
|
128
137
|
|
|
129
138
|
/**
|
|
@@ -131,6 +140,8 @@ export type RelationOptions = {
|
|
|
131
140
|
* It can represent both attributes and relations depending on the value of Final.
|
|
132
141
|
*
|
|
133
142
|
* It can infer default values type depending on the object type if the relation is final.
|
|
143
|
+
*
|
|
144
|
+
* @category Schema
|
|
134
145
|
*/
|
|
135
146
|
export type RelationDefinitionRawSchema<
|
|
136
147
|
ESchemas extends EntityRawSchemaArray,
|
|
@@ -157,6 +168,8 @@ export type RelationDefinitionRawSchema<
|
|
|
157
168
|
|
|
158
169
|
/**
|
|
159
170
|
* Type representing a list of relation definitions.
|
|
171
|
+
*
|
|
172
|
+
* @category Schema
|
|
160
173
|
*/
|
|
161
174
|
export type RelationDefinitionRawSchemaArray<
|
|
162
175
|
ESchemas extends EntityRawSchemaArray
|
package/src/schema/raw/Schema.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { RelationDefinitionRawSchemaArray } from "./RelationDefinitions";
|
|
|
6
6
|
* You can export this schema from your CubicWeb instance using the command:
|
|
7
7
|
*
|
|
8
8
|
* `cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>`
|
|
9
|
+
*
|
|
10
|
+
* @category Schema
|
|
9
11
|
*/
|
|
10
12
|
export type RawSchema<
|
|
11
13
|
E extends EntityRawSchemaArray = EntityRawSchemaArray,
|
package/src/schema/raw/Utils.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { EntityRawSchemaArray } from "./Entities";
|
|
|
6
6
|
*
|
|
7
7
|
* In the given EntityRawSchemaArray, if the entities type is a string, the schema is loosely typed.
|
|
8
8
|
* If the schema is strongly typed, the entities type would be a word (which is stricter than string).
|
|
9
|
+
*
|
|
10
|
+
* @category Schema
|
|
9
11
|
*/
|
|
10
12
|
export type IsLooseSchema<E extends EntityRawSchemaArray> =
|
|
11
13
|
string extends E[number]["type"] ? true : false;
|
|
@@ -13,6 +15,8 @@ export type IsLooseSchema<E extends EntityRawSchemaArray> =
|
|
|
13
15
|
/**
|
|
14
16
|
* Checks if the given entity type is present in the EntityRawSchemaArray.
|
|
15
17
|
* Use this to create conditional types.
|
|
18
|
+
*
|
|
19
|
+
* @category Schema
|
|
16
20
|
*/
|
|
17
21
|
export type IsETypeInStrictSchema<
|
|
18
22
|
E extends EntityRawSchemaArray,
|
|
@@ -22,6 +26,8 @@ export type IsETypeInStrictSchema<
|
|
|
22
26
|
/**
|
|
23
27
|
* Type representing the entity's raw schema matching this type.
|
|
24
28
|
* This type only works for EntityRawSchemaArray with literals as "type" property.
|
|
29
|
+
*
|
|
30
|
+
* @category Schema
|
|
25
31
|
*/
|
|
26
32
|
export type EntityRawSchemaByType<
|
|
27
33
|
E extends EntityRawSchemaArray,
|