@cubicweb/client 3.0.0-alpha.4 → 3.0.0-alpha.6

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 (52) hide show
  1. package/README.md +28 -16
  2. package/lib/api/Api.d.ts +25 -10
  3. package/lib/api/Api.d.ts.map +1 -1
  4. package/lib/api/Api.js +69 -43
  5. package/lib/api/Api.js.map +1 -1
  6. package/lib/api/Client.d.ts +11 -6
  7. package/lib/api/Client.d.ts.map +1 -1
  8. package/lib/api/Client.js +20 -11
  9. package/lib/api/Client.js.map +1 -1
  10. package/lib/api/Transaction.d.ts +30 -21
  11. package/lib/api/Transaction.d.ts.map +1 -1
  12. package/lib/api/Transaction.js +44 -36
  13. package/lib/api/Transaction.js.map +1 -1
  14. package/lib/schema/classes/EntitySchema.d.ts +2 -0
  15. package/lib/schema/classes/EntitySchema.d.ts.map +1 -1
  16. package/lib/schema/classes/EntitySchema.js +2 -0
  17. package/lib/schema/classes/EntitySchema.js.map +1 -1
  18. package/lib/schema/classes/RelationDefinitionSchema.d.ts +2 -0
  19. package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -1
  20. package/lib/schema/classes/RelationDefinitionSchema.js +2 -0
  21. package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -1
  22. package/lib/schema/classes/Schema.d.ts +2 -0
  23. package/lib/schema/classes/Schema.d.ts.map +1 -1
  24. package/lib/schema/classes/Schema.js +2 -0
  25. package/lib/schema/classes/Schema.js.map +1 -1
  26. package/lib/schema/classes/Utils.d.ts +28 -0
  27. package/lib/schema/classes/Utils.d.ts.map +1 -1
  28. package/lib/schema/classes/Utils.js +22 -0
  29. package/lib/schema/classes/Utils.js.map +1 -1
  30. package/lib/schema/raw/Constraints.d.ts +17 -9
  31. package/lib/schema/raw/Constraints.d.ts.map +1 -1
  32. package/lib/schema/raw/Entities.d.ts +4 -0
  33. package/lib/schema/raw/Entities.d.ts.map +1 -1
  34. package/lib/schema/raw/RelationDefinitions.d.ts +12 -0
  35. package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
  36. package/lib/schema/raw/Schema.d.ts +2 -0
  37. package/lib/schema/raw/Schema.d.ts.map +1 -1
  38. package/lib/schema/raw/Utils.d.ts +6 -0
  39. package/lib/schema/raw/Utils.d.ts.map +1 -1
  40. package/package.json +4 -8
  41. package/src/api/Api.ts +81 -40
  42. package/src/api/Client.ts +24 -20
  43. package/src/api/Transaction.ts +57 -31
  44. package/src/schema/classes/EntitySchema.ts +2 -0
  45. package/src/schema/classes/RelationDefinitionSchema.ts +2 -0
  46. package/src/schema/classes/Schema.ts +2 -0
  47. package/src/schema/classes/Utils.ts +28 -0
  48. package/src/schema/raw/Constraints.ts +20 -8
  49. package/src/schema/raw/Entities.ts +4 -0
  50. package/src/schema/raw/RelationDefinitions.ts +12 -0
  51. package/src/schema/raw/Schema.ts +2 -0
  52. package/src/schema/raw/Utils.ts +6 -0
@@ -14,6 +14,8 @@ const REVERSE_INDICATOR = "reverse_";
14
14
 
15
15
  /**
16
16
  * An entity role in a relation.
17
+ *
18
+ * @category Utils
17
19
  */
18
20
  export type EntityRole = "subject" | "object";
19
21
 
@@ -23,6 +25,8 @@ export type EntityRole = "subject" | "object";
23
25
  *
24
26
  * @param schema The schema to create a loose type for
25
27
  * @returns A loosely typed schema
28
+ *
29
+ * @category Utils
26
30
  */
27
31
  export const getLooseSchema = <
28
32
  E extends EntityRawSchemaArray = EntityRawSchemaArray,
@@ -38,6 +42,8 @@ export const getLooseSchema = <
38
42
  *
39
43
  * @param cardinality The cardinality to check
40
44
  * @returns True if the cardinality is 1 or +
45
+ *
46
+ * @category Utils
41
47
  */
42
48
  export function isCardinalityRequired(cardinality: Cardinality): boolean {
43
49
  return cardinality === "1" || cardinality === "+";
@@ -48,6 +54,8 @@ export function isCardinalityRequired(cardinality: Cardinality): boolean {
48
54
  *
49
55
  * @param cardinality The cardinility to check
50
56
  * @returns True if the cardinality is `*` or `+`
57
+ *
58
+ * @category Utils
51
59
  */
52
60
  export const isCardinalityMultiple = (cardinality: Cardinality): boolean => {
53
61
  return cardinality === "*" || cardinality === "+";
@@ -58,6 +66,8 @@ export const isCardinalityMultiple = (cardinality: Cardinality): boolean => {
58
66
  *
59
67
  * @param cardinality The cardinility to check
60
68
  * @returns True if the cardinality is `?` or `*`
69
+ *
70
+ * @category Utils
61
71
  */
62
72
  export const isCardinalityOptional = (cardinality: Cardinality): boolean => {
63
73
  return cardinality === "?" || cardinality === "*";
@@ -68,6 +78,8 @@ export const isCardinalityOptional = (cardinality: Cardinality): boolean => {
68
78
  *
69
79
  * @param role The role to reverse
70
80
  * @returns "object" if the given role was "subject", "subject" otherwise
81
+ *
82
+ * @category Utils
71
83
  */
72
84
  export function getOppositeRelationRole(role: EntityRole): EntityRole {
73
85
  return role === "subject" ? "object" : "subject";
@@ -82,6 +94,8 @@ export function getOppositeRelationRole(role: EntityRole): EntityRole {
82
94
  *
83
95
  * @param relationType The relation type to check
84
96
  * @returns True if the relation type starts with the reverse indicator
97
+ *
98
+ * @category Utils
85
99
  */
86
100
  export const isRelationTypeReversed = (relationType: string): boolean => {
87
101
  return relationType.startsWith(REVERSE_INDICATOR);
@@ -97,6 +111,8 @@ export const isRelationTypeReversed = (relationType: string): boolean => {
97
111
  *
98
112
  * @param relationType The relation type to check
99
113
  * @returns "subject" if the relation is not reversed, "object" otherwise
114
+ *
115
+ * @category Utils
100
116
  */
101
117
  export const getRoleFromRelationType = (relationType: string): EntityRole => {
102
118
  return isRelationTypeReversed(relationType) ? "object" : "subject";
@@ -111,6 +127,8 @@ export const getRoleFromRelationType = (relationType: string): EntityRole => {
111
127
  *
112
128
  * @param relationType The relation type to transform
113
129
  * @returns The relation type with the reverse indicator added or removed
130
+ *
131
+ * @category Utils
114
132
  */
115
133
  export const getReverseRelationType = (relationType: string): string => {
116
134
  if (!isRelationTypeReversed(relationType)) {
@@ -129,6 +147,8 @@ export const getReverseRelationType = (relationType: string): string => {
129
147
  *
130
148
  * @param relationType The relation type to transform
131
149
  * @returns The relation type with the reverse indicator added or removed
150
+ *
151
+ * @category Utils
132
152
  */
133
153
  export const getRawRelationType = (relationType: string): string => {
134
154
  if (isRelationTypeReversed(relationType)) {
@@ -148,6 +168,8 @@ export const getRawRelationType = (relationType: string): string => {
148
168
  * @param relationType The relation type to transform
149
169
  * @param role The entity role in the relation
150
170
  * @returns A relation type with the reverse indicator if necessary
171
+ *
172
+ * @category Utils
151
173
  */
152
174
  export const getRelationType = (relationType: string, role: EntityRole) => {
153
175
  return role === "subject"
@@ -163,6 +185,8 @@ export const getRelationType = (relationType: string, role: EntityRole) => {
163
185
  * @param relationType The type of the relation to use. Can have the reverse indicator to decide the role of the source/target entities
164
186
  * @param targetType The entity type acting as target for the relation
165
187
  * @returns The relation definition matching the triplet source relation target
188
+ *
189
+ * @category Utils
166
190
  */
167
191
  export const getRelationDefinition = (
168
192
  entitySchema: EntitySchema,
@@ -184,6 +208,8 @@ export const getRelationDefinition = (
184
208
 
185
209
  /**
186
210
  * Partial raw relation definition schema type.
211
+ *
212
+ * @category Utils
187
213
  */
188
214
  export type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<
189
215
  RelationDefinitionRawSchema<E>
@@ -194,6 +220,8 @@ export type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<
194
220
  * If it finds a relation definition matching the partial one given, it will return its type.
195
221
  * If it cannot find any relation definition matching, it will return the `never` type
196
222
  * and TypeScript will give compile errors.
223
+ *
224
+ * @category Utils
197
225
  */
198
226
  export type MatchedRelationDefinition<
199
227
  E extends EntityRawSchemaArray,
@@ -10,7 +10,7 @@ type ConstraintBase<
10
10
  };
11
11
 
12
12
  /**
13
- * THe type of a constraint message when one is present.
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,32 +66,36 @@ 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;
68
- offset: TimeDelta;
74
+ offset: TimeDelta | null;
69
75
  }
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
  {
83
- boundary: Attribute | Today | Now | number | null;
87
+ boundary: Attribute | Today | Now | number | string | null;
84
88
  op: ConstraintOperator;
85
89
  msg: ConstraintMessage;
86
90
  }
87
91
  >;
88
92
  export type IntervalBoundConstraint = ConstraintBase<
89
93
  "IntervalBoundConstraint",
90
- { minvalue: number | null; maxvalue: number | null; msg: ConstraintMessage }
94
+ {
95
+ minvalue: number | string | null;
96
+ maxvalue: number | string | null;
97
+ msg: ConstraintMessage;
98
+ }
91
99
  >;
92
100
 
93
101
  export type StaticVocabularyConstraint = ConstraintBase<
@@ -115,6 +123,8 @@ export type RQLConstraint = ConstraintBase<
115
123
 
116
124
  /**
117
125
  * Type representing all possible constraints for attributes.
126
+ *
127
+ * @category Schema
118
128
  */
119
129
  export type AttributeConstraint = Readonly<
120
130
  | UniqueConstraint
@@ -129,6 +139,8 @@ export type AttributeConstraint = Readonly<
129
139
 
130
140
  /**
131
141
  * Type representing all possible constraints for relations.
142
+ *
143
+ * @category Schema
132
144
  */
133
145
  export type RelationConstraint = Readonly<
134
146
  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>;
@@ -4,11 +4,15 @@ import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
4
4
 
5
5
  /**
6
6
  * Type representing all the possible cardinalities in CubicWeb.
7
+ *
8
+ * @category Schema
7
9
  */
8
10
  export type Cardinality = "*" | "1" | "?" | "+";
9
11
 
10
12
  /**
11
13
  * Type representing a cardinality pair as used in relation definitions.
14
+ *
15
+ * @category Schema
12
16
  */
13
17
  export type CardinalityPair = `${Cardinality}${Cardinality}`;
14
18
 
@@ -110,6 +114,8 @@ export type BuildObj = Readonly<
110
114
 
111
115
  /**
112
116
  * Type representing the possible options for an attribute.
117
+ *
118
+ * @category Schema
113
119
  */
114
120
  export type AttributeOptions = {
115
121
  indexed?: boolean;
@@ -119,6 +125,8 @@ export type AttributeOptions = {
119
125
 
120
126
  /**
121
127
  * Type representing the possible options for a relation definition.
128
+ *
129
+ * @category Schema
122
130
  */
123
131
  export type RelationOptions = {
124
132
  symmetric?: boolean;
@@ -132,6 +140,8 @@ export type RelationOptions = {
132
140
  * It can represent both attributes and relations depending on the value of Final.
133
141
  *
134
142
  * It can infer default values type depending on the object type if the relation is final.
143
+ *
144
+ * @category Schema
135
145
  */
136
146
  export type RelationDefinitionRawSchema<
137
147
  ESchemas extends EntityRawSchemaArray,
@@ -158,6 +168,8 @@ export type RelationDefinitionRawSchema<
158
168
 
159
169
  /**
160
170
  * Type representing a list of relation definitions.
171
+ *
172
+ * @category Schema
161
173
  */
162
174
  export type RelationDefinitionRawSchemaArray<
163
175
  ESchemas extends EntityRawSchemaArray
@@ -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,
@@ -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,