@cubicweb/client 1.5.0 → 1.7.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.
@@ -1,58 +1,65 @@
1
1
  /**
2
2
  * Base type used to describe a constraint.
3
3
  */
4
- declare type ConstraintBase<T extends string, V extends Record<string, unknown> | null> = {
4
+ type ConstraintBase<T extends string, V extends Record<string, unknown> | null> = {
5
5
  type: T;
6
6
  value: V;
7
7
  };
8
8
  /**
9
9
  * All the possible operators inside a constraint.
10
10
  */
11
- export declare type ConstraintOperator = ">" | ">=" | "<" | "<=";
11
+ export type ConstraintOperator = ">" | ">=" | "<" | "<=";
12
12
  /**
13
13
  * THe type of a constraint message when one is present.
14
14
  */
15
- declare type ConstraintMessage = string | null;
16
- export declare type UniqueConstraint = ConstraintBase<"UniqueConstraint", null>;
17
- export declare type SizeConstraint = ConstraintBase<"SizeConstraint", {
15
+ type ConstraintMessage = string | null;
16
+ export type UniqueConstraint = ConstraintBase<"UniqueConstraint", {
17
+ msg: ConstraintMessage;
18
+ }>;
19
+ export type SizeConstraint = ConstraintBase<"SizeConstraint", {
18
20
  min: number | null;
19
21
  max: number | null;
20
22
  msg: ConstraintMessage;
21
23
  }>;
22
- export declare type RegexpConstraint = ConstraintBase<"RegexpConstraint", {
24
+ export type RegexpConstraint = ConstraintBase<"RegexpConstraint", {
23
25
  regexp: string;
24
26
  flags: number;
25
27
  msg: ConstraintMessage;
26
28
  }>;
27
- export declare type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
29
+ export type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
28
30
  boundary: number | null;
29
31
  op: ConstraintOperator;
30
32
  msg: ConstraintMessage;
31
33
  }>;
32
- export declare type IntervalBoundConstraint = ConstraintBase<"IntervalBoundConstraint", {
34
+ export type IntervalBoundConstraint = ConstraintBase<"IntervalBoundConstraint", {
33
35
  minvalue: number | null;
34
36
  maxvalue: number | null;
35
37
  msg: ConstraintMessage;
36
38
  }>;
37
- export declare type StaticVocabularyConstraint = ConstraintBase<"StaticVocabularyConstraint", {
39
+ export type StaticVocabularyConstraint = ConstraintBase<"StaticVocabularyConstraint", {
38
40
  values: string[];
39
41
  msg: ConstraintMessage;
40
42
  }>;
41
- export declare type FormatConstraint = ConstraintBase<"FormatConstraint", {
43
+ export type FormatConstraint = ConstraintBase<"FormatConstraint", {
42
44
  values: ["text/rest", "text/markdown", "text/html", "text/plain"];
43
45
  msg: ConstraintMessage;
44
46
  }>;
45
- export declare type RQLVocabularyConstraint = ConstraintBase<"RQLVocabularyConstraint", {
47
+ export type RQLVocabularyConstraint = ConstraintBase<"RQLVocabularyConstraint", {
48
+ expression: string;
49
+ mainvars: string[];
50
+ }>;
51
+ export type RQLConstraint = ConstraintBase<"RQLConstraint", {
46
52
  expression: string;
47
53
  mainvars: string[];
54
+ msg: ConstraintMessage;
48
55
  }>;
49
56
  /**
50
57
  * Type representing all possible constraints for attributes.
51
58
  */
52
- export declare type AttributeConstraint = Readonly<UniqueConstraint | SizeConstraint | RegexpConstraint | BoundaryConstraint | IntervalBoundConstraint | StaticVocabularyConstraint | FormatConstraint>;
59
+ export type AttributeConstraint = Readonly<UniqueConstraint | SizeConstraint | RegexpConstraint | BoundaryConstraint | IntervalBoundConstraint | StaticVocabularyConstraint | FormatConstraint | RQLConstraint>;
53
60
  /**
54
61
  * Type representing all possible constraints for relations.
55
62
  */
56
- export declare type RelationConstraint = Readonly<RQLVocabularyConstraint>;
63
+ export type RelationConstraint = Readonly<RQLVocabularyConstraint | RQLConstraint>;
57
64
  export {};
58
65
  //# sourceMappingURL=Constraints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Constraints.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Constraints.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,aAAK,cAAc,CACjB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,IACtC;I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AAmB,GAAG,QAAQ,CACtC,gBAAgB,GAChB,cAAc,GACd,gBAAgB,GAChB,kBAAkB,GAClB,uBAAuB,GACvB,0BAA0B,GAC1B,gBAAgB,GAChB,aAAa,CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CACvC,uBAAuB,GAAG,aAAa,CACxC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Type representing an entity schema.
3
3
  */
4
- export declare type EntityRawSchema = {
4
+ export type EntityRawSchema = {
5
5
  type: string;
6
6
  final: boolean;
7
7
  description: string;
@@ -9,5 +9,5 @@ export declare type EntityRawSchema = {
9
9
  /**
10
10
  * Type representing a list of entity schemas.
11
11
  */
12
- export declare type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
12
+ export type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
13
13
  //# sourceMappingURL=Entities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Entities.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,oBAAY,oBAAoB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC"}
1
+ {"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Entities.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC"}
@@ -3,17 +3,17 @@ import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
3
3
  /**
4
4
  * Type representing all the possible cardinalities in CubicWeb.
5
5
  */
6
- export declare type Cardinality = "*" | "1" | "?" | "+";
6
+ export type Cardinality = "*" | "1" | "?" | "+";
7
7
  /**
8
8
  * Type representing a cardinality pair as used in relation definitions.
9
9
  */
10
- export declare type CardinalityPair = `${Cardinality}${Cardinality}`;
10
+ export type CardinalityPair = `${Cardinality}${Cardinality}`;
11
11
  /**
12
12
  * Type used as a base to build final relation definitions with primitive types (Int, String, ...).
13
13
  *
14
14
  * @internal
15
15
  */
16
- declare type BuildObjBase<T extends string> = {
16
+ type BuildObjBase<T extends string> = {
17
17
  object: T;
18
18
  final: true;
19
19
  required?: boolean;
@@ -60,17 +60,21 @@ interface TZDatetimeBuildObj extends BuildObjBase<"TZDatetime"> {
60
60
  interface IntervalBuildObj extends BuildObjBase<"Interval"> {
61
61
  default: unknown;
62
62
  }
63
+ interface CustomBuildObj<T extends string> extends BuildObjBase<T> {
64
+ type: T;
65
+ default: unknown;
66
+ }
63
67
  /**
64
68
  * Type allowing to link the type of an object to the type of their default values in a
65
69
  * relation definition. It only works for final relations using primitive types.
66
70
  *
67
71
  * @internal
68
72
  */
69
- export declare type BuildObj = Readonly<StringBuildObj | PasswordBuildObj | BytesBuildObj | IntBuildObj | BigIntBuildObj | FloatBuildObj | BooleanBuildObj | DecimalBuildObj | DateBuildObj | TimeBuildObj | DatetimeBuildObj | TZTimeBuildObj | TZDatetimeBuildObj | IntervalBuildObj>;
73
+ export type BuildObj = Readonly<StringBuildObj | PasswordBuildObj | BytesBuildObj | IntBuildObj | BigIntBuildObj | FloatBuildObj | BooleanBuildObj | DecimalBuildObj | DateBuildObj | TimeBuildObj | DatetimeBuildObj | TZTimeBuildObj | TZDatetimeBuildObj | IntervalBuildObj | CustomBuildObj<string>>;
70
74
  /**
71
75
  * Type representing the possible options for an attribute.
72
76
  */
73
- export declare type AttributeOptions = {
77
+ export type AttributeOptions = {
74
78
  indexed?: boolean;
75
79
  fulltextindexed?: boolean;
76
80
  internationalizable?: boolean;
@@ -78,7 +82,7 @@ export declare type AttributeOptions = {
78
82
  /**
79
83
  * Type representing the possible options for a relation definition.
80
84
  */
81
- export declare type RelationOptions = {
85
+ export type RelationOptions = {
82
86
  symmetric?: boolean;
83
87
  inlined?: boolean;
84
88
  fulltext_container?: "subject" | "object";
@@ -90,7 +94,7 @@ export declare type RelationOptions = {
90
94
  *
91
95
  * It can infer default values type depending on the object type if the relation is final.
92
96
  */
93
- export declare type RelationDefinitionRawSchema<ESchemas extends EntityRawSchemaArray, Final extends boolean = boolean> = Readonly<{
97
+ export type RelationDefinitionRawSchema<ESchemas extends EntityRawSchemaArray, Final extends boolean = boolean> = Readonly<{
94
98
  type: string;
95
99
  description: string;
96
100
  cardinality: CardinalityPair;
@@ -108,6 +112,6 @@ export declare type RelationDefinitionRawSchema<ESchemas extends EntityRawSchema
108
112
  /**
109
113
  * Type representing a list of relation definitions.
110
114
  */
111
- export declare type RelationDefinitionRawSchemaArray<ESchemas extends EntityRawSchemaArray> = ReadonlyArray<RelationDefinitionRawSchema<ESchemas, boolean>>;
115
+ export type RelationDefinitionRawSchemaArray<ESchemas extends EntityRawSchemaArray> = ReadonlyArray<RelationDefinitionRawSchema<ESchemas, boolean>>;
112
116
  export {};
113
117
  //# sourceMappingURL=RelationDefinitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RelationDefinitions.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/RelationDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,oBAAY,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEhD;;GAEG;AACH,oBAAY,eAAe,GAAG,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AAE7D;;;;GA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AAC,CACP,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,CAC1C,QAAQ,SAAS,oBAAoB,IACnC,aAAa,CAAC,2BAA2B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC"}
@@ -6,7 +6,7 @@ import { RelationDefinitionRawSchemaArray } from "./RelationDefinitions";
6
6
  *
7
7
  * `cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>`
8
8
  */
9
- export declare type RawSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> = {
9
+ export type RawSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> = {
10
10
  entities: E;
11
11
  relations_definitions: R;
12
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAEzE;;;;;GAKG;AACH,oBAAY,SAAS,CACnB,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EACrD,CAAC,SAAS,gCAAgC,CAAC,CAAC,CAAC,GAAG,gCAAgC,CAAC,CAAC,CAAC,IACjF;IACF,QAAQ,EAAE,CAAC,CAAC;IACZ,qBAAqB,EAAE,CAAC,CAAC;CAC1B,CAAC"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,MAAM,SAAS,CACnB,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EACrD,CAAC,SAAS,gCAAgC,CAAC,CAAC,CAAC,GAAG,gCAAgC,CAAC,CAAC,CAAC,IACjF;IACF,QAAQ,EAAE,CAAC,CAAC;IACZ,qBAAqB,EAAE,CAAC,CAAC;CAC1B,CAAC"}
@@ -6,17 +6,17 @@ import { EntityRawSchemaArray } from "./Entities";
6
6
  * In the given EntityRawSchemaArray, if the entities type is a string, the schema is loosely typed.
7
7
  * If the schema is strongly typed, the entities type would be a word (which is stricter than string).
8
8
  */
9
- export declare type IsLooseSchema<E extends EntityRawSchemaArray> = string extends E[number]["type"] ? true : false;
9
+ export type IsLooseSchema<E extends EntityRawSchemaArray> = string extends E[number]["type"] ? true : false;
10
10
  /**
11
11
  * Checks if the given entity type is present in the EntityRawSchemaArray.
12
12
  * Use this to create conditional types.
13
13
  */
14
- export declare type IsETypeInStrictSchema<E extends EntityRawSchemaArray, EType extends string> = EType extends E[number]["type"] ? true : false;
14
+ export type IsETypeInStrictSchema<E extends EntityRawSchemaArray, EType extends string> = EType extends E[number]["type"] ? true : false;
15
15
  /**
16
16
  * Type representing the entity's raw schema matching this type.
17
17
  * This type only works for EntityRawSchemaArray with literals as "type" property.
18
18
  */
19
- export declare type EntityRawSchemaByType<E extends EntityRawSchemaArray, T extends string> = E[number] extends infer ESchema ? ESchema extends {
19
+ export type EntityRawSchemaByType<E extends EntityRawSchemaArray, T extends string> = E[number] extends infer ESchema ? ESchema extends {
20
20
  type: T;
21
21
  } ? ESchema : never : never;
22
22
  //# sourceMappingURL=Utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,oBAAY,aAAa,CAAC,CAAC,SAAS,oBAAoB,IACtD,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAElD;;;GAGG;AACH,oBAAY,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,KAAK,SAAS,MAAM,IAClB,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAEnD;;;GAGG;AACH,oBAAY,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,MAAM,IACd,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,OAAO,GAC/B,OAAO,SAAS;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GACzB,OAAO,GACP,KAAK,GACP,KAAK,CAAC"}
1
+ {"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,oBAAoB,IACtD,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,KAAK,SAAS,MAAM,IAClB,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,MAAM,IACd,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,OAAO,GAC/B,OAAO,SAAS;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GACzB,OAAO,GACP,KAAK,GACP,KAAK,CAAC"}
package/package.json CHANGED
@@ -2,12 +2,13 @@
2
2
  "name": "@cubicweb/client",
3
3
  "description": "Official JS client for CubicWeb API",
4
4
  "author": "Logilab",
5
- "version": "1.5.0",
5
+ "version": "1.7.0",
6
6
  "license": "LGPL-3.0-or-later",
7
7
  "main": "lib/index.js",
8
8
  "types": "lib/index.d.ts",
9
9
  "scripts": {
10
- "build": "tsc --project tsconfig.build.json"
10
+ "build": "tsc --project tsconfig.build.json",
11
+ "docs": "typedoc"
11
12
  },
12
13
  "repository": {
13
14
  "type": "hg",
@@ -22,5 +23,9 @@
22
23
  "lib/**",
23
24
  "src/**",
24
25
  "!**/__tests__/**"
25
- ]
26
- }
26
+ ],
27
+ "devDependencies": {
28
+ "typedoc": "^0.23.24",
29
+ "typescript": "^4.9.4"
30
+ }
31
+ }
package/src/Errors.ts CHANGED
@@ -5,6 +5,13 @@ export class InconsistentSchemaError extends Error {
5
5
  }
6
6
  }
7
7
 
8
+ export class ValidationError extends Error {
9
+ constructor(message: string) {
10
+ super(message);
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+ }
13
+ }
14
+
8
15
  export class TransactionClosedError extends Error {
9
16
  constructor() {
10
17
  super("Trying to use a closed transaction");
package/src/api/Api.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ValidationError } from "../Errors";
1
2
  import { RawSchema } from "../schema/raw/Schema";
2
3
 
3
4
  /**
@@ -97,11 +98,15 @@ export default class Api {
97
98
  * @returns A promise with the request's result set
98
99
  */
99
100
  async execute(query: string, params: RQLParams): Promise<ResultSet> {
100
- return nonNullFetchApi<ResultSet>(this._rqlApiUrl, {
101
- method: "POST",
102
- body: JSON.stringify({ query, params }),
103
- credentials: "include", // FIXME is it secure?
104
- });
101
+ try {
102
+ return await nonNullFetchApi<ResultSet>(this._rqlApiUrl, {
103
+ method: "POST",
104
+ body: JSON.stringify({ query, params }),
105
+ credentials: "include", // FIXME is it secure?
106
+ });
107
+ } catch (e) {
108
+ this.handleUserErrors(e);
109
+ }
105
110
  }
106
111
 
107
112
  /**
@@ -124,16 +129,19 @@ export default class Api {
124
129
  * @returns A promise returning true if the login was successful, false otherwise
125
130
  */
126
131
  async login(login: string, password: string): Promise<boolean> {
127
- return fetchApi<null>(this._loginApiUrl, {
128
- method: "POST",
129
- body: JSON.stringify({
130
- login,
131
- password,
132
- }),
133
- credentials: "include",
134
- })
135
- .then(() => true)
136
- .catch(() => false);
132
+ try {
133
+ await fetchApi<null>(this._loginApiUrl, {
134
+ method: "POST",
135
+ body: JSON.stringify({
136
+ login,
137
+ password,
138
+ }),
139
+ credentials: "include",
140
+ });
141
+ return true;
142
+ } catch (_error) {
143
+ return false;
144
+ }
137
145
  }
138
146
 
139
147
  /**
@@ -161,11 +169,15 @@ export default class Api {
161
169
  query: string,
162
170
  params: RQLParams
163
171
  ): Promise<ResultSet | null> {
164
- return fetchApi<ResultSet>(this._transactionApiUrl.execute, {
165
- method: "POST",
166
- body: JSON.stringify({ uuid, query, params }),
167
- credentials: "include",
168
- });
172
+ try {
173
+ return await fetchApi<ResultSet>(this._transactionApiUrl.execute, {
174
+ method: "POST",
175
+ body: JSON.stringify({ uuid, query, params }),
176
+ credentials: "include",
177
+ });
178
+ } catch (e) {
179
+ this.handleUserErrors(e);
180
+ }
169
181
  }
170
182
 
171
183
  /**
@@ -174,11 +186,15 @@ export default class Api {
174
186
  * @param uuid The transaction's uuid
175
187
  */
176
188
  async transactionCommit(uuid: string): Promise<null> {
177
- return fetchApi<null>(this._transactionApiUrl.commit, {
178
- method: "POST",
179
- body: JSON.stringify({ uuid }),
180
- credentials: "include",
181
- });
189
+ try {
190
+ return await fetchApi<null>(this._transactionApiUrl.commit, {
191
+ method: "POST",
192
+ body: JSON.stringify({ uuid }),
193
+ credentials: "include",
194
+ });
195
+ } catch (e) {
196
+ this.handleUserErrors(e);
197
+ }
182
198
  }
183
199
 
184
200
  /**
@@ -193,6 +209,23 @@ export default class Api {
193
209
  credentials: "include",
194
210
  });
195
211
  }
212
+
213
+ private handleUserErrors(error: unknown): never {
214
+ if (
215
+ typeof error === "object" &&
216
+ error !== null &&
217
+ "title" in error &&
218
+ typeof error.title === "string" &&
219
+ "message" in error &&
220
+ typeof error.message === "string"
221
+ ) {
222
+ if (error.title === "ValidationError") {
223
+ throw new ValidationError(error.message);
224
+ }
225
+ throw error;
226
+ }
227
+ throw error;
228
+ }
196
229
  }
197
230
 
198
231
  /**
@@ -204,28 +237,21 @@ export default class Api {
204
237
  * @param init Additional request parameters
205
238
  * @returns A promise with the non-null fetched result
206
239
  */
207
- const nonNullFetchApi = <R = unknown>(
240
+ async function nonNullFetchApi<R = unknown>(
208
241
  input: RequestInfo,
209
242
  init?: RequestInit
210
- ) => {
211
- return new Promise(
212
- (resolve: (value: R) => void, reject: (reason: ApiErrorResponse) => void) =>
213
- fetchApi<R>(input, init)
214
- .then((v) => {
215
- if (v == null) {
216
- const error: ApiErrorResponse = {
217
- status: 500,
218
- title: "Unexpected null response",
219
- message: "Response was null but a value was expected",
220
- };
221
- reject(error);
222
- } else {
223
- resolve(v);
224
- }
225
- })
226
- .catch(reject)
227
- );
228
- };
243
+ ) {
244
+ const result = await fetchApi<R>(input, init);
245
+ if (result == null) {
246
+ const error: ApiErrorResponse = {
247
+ status: 500,
248
+ title: "Unexpected null response",
249
+ message: "Response was null but a value was expected",
250
+ };
251
+ throw error;
252
+ }
253
+ return result;
254
+ }
229
255
 
230
256
  /**
231
257
  * Sends a request to the given API route with the `Content-Type` header set and waits for a response.
@@ -236,7 +262,10 @@ const nonNullFetchApi = <R = unknown>(
236
262
  * @param init Additional request parameters
237
263
  * @returns A promise with the fetched result
238
264
  */
239
- const fetchApi = <R = unknown>(input: RequestInfo, init?: RequestInit) => {
265
+ async function fetchApi<R = unknown>(
266
+ input: RequestInfo,
267
+ init?: RequestInit
268
+ ): Promise<R | null> {
240
269
  let headers = init?.headers;
241
270
  if (init?.method && init.method !== "GET" && init.method !== "DELETE") {
242
271
  headers = {
@@ -244,42 +273,30 @@ const fetchApi = <R = unknown>(input: RequestInfo, init?: RequestInit) => {
244
273
  ...init?.headers,
245
274
  };
246
275
  }
247
- return new Promise(
248
- (
249
- resolve: (value: R | null) => void,
250
- reject: (reason: ApiErrorResponse) => void
251
- ) =>
252
- fetch(input, {
253
- ...init,
254
- headers,
255
- }).then((response) => {
256
- const status = response.status;
257
- if (status >= 200 && status < 300) {
258
- if (status === 204) {
259
- resolve(null);
260
- } else {
261
- response
262
- .json()
263
- .then(resolve)
264
- .catch((e) => {
265
- console.error(e);
266
- resolve(null);
267
- });
268
- }
269
- } else {
270
- response
271
- .json()
272
- .then((data: ApiError) => {
273
- reject({
274
- status,
275
- ...data,
276
- });
277
- })
278
- .catch((e) => {
279
- console.error(e);
280
- reject({ status, title: "Error", message: "" });
281
- });
282
- }
283
- })
284
- );
285
- };
276
+
277
+ const response = await fetch(input, {
278
+ ...init,
279
+ headers,
280
+ });
281
+ const status = response.status;
282
+ if (status >= 200 && status < 300) {
283
+ if (status === 204) {
284
+ return null;
285
+ }
286
+ try {
287
+ return await response.json();
288
+ } catch (e) {
289
+ console.error(e);
290
+ return null;
291
+ }
292
+ } else {
293
+ let json;
294
+ try {
295
+ json = await response.json();
296
+ } catch (e) {
297
+ console.error(e);
298
+ throw { status, title: "Error", message: "" };
299
+ }
300
+ throw { status, ...json };
301
+ }
302
+ }
package/src/api/Client.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "../schema/classes/Schema";
2
- import Api, { RQLParams } from "./Api";
2
+ import Api, { RQLParams, ResultSet } from "./Api";
3
3
  import Transaction from "./Transaction";
4
4
 
5
5
  /**
@@ -30,7 +30,7 @@ export default class Client {
30
30
  * @param params The additional parameters for the request
31
31
  * @returns A promise with the request's result set
32
32
  */
33
- async execute(query: string, params: RQLParams = {}) {
33
+ async execute(query: string, params: RQLParams = {}): Promise<ResultSet> {
34
34
  return await this.api.execute(query, params);
35
35
  }
36
36
 
@@ -59,6 +59,8 @@ export default class Client {
59
59
  * Creates a new transaction and exposes the Transaction object in the given callback.
60
60
  * Use this callback to execute RQL requests as part of the transaction.
61
61
  * Once the callback's end is reached, the transaction is automatically committed.
62
+ * Note that any exception thrown by the callback will lead to the
63
+ * transaction being rolled back.
62
64
  *
63
65
  * @param callback Function to execute transaction requests in.
64
66
  * @returns The promise returned by the callback
@@ -66,7 +68,16 @@ export default class Client {
66
68
  async transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T> {
67
69
  const transaction = new Transaction(this.api);
68
70
  await transaction.begin();
69
- const result = await callback(transaction);
71
+
72
+ let result: T;
73
+ try {
74
+ result = await callback(transaction);
75
+ } catch (error) {
76
+ if (!transaction.isClosed()) {
77
+ await transaction.rollback();
78
+ }
79
+ throw error;
80
+ }
70
81
  if (!transaction.isClosed()) {
71
82
  await transaction.commit();
72
83
  }
@@ -19,7 +19,10 @@ export type ConstraintOperator = ">" | ">=" | "<" | "<=";
19
19
  */
20
20
  type ConstraintMessage = string | null;
21
21
 
22
- export type UniqueConstraint = ConstraintBase<"UniqueConstraint", null>;
22
+ export type UniqueConstraint = ConstraintBase<
23
+ "UniqueConstraint",
24
+ { msg: ConstraintMessage }
25
+ >;
23
26
 
24
27
  export type SizeConstraint = ConstraintBase<
25
28
  "SizeConstraint",
@@ -58,6 +61,11 @@ export type RQLVocabularyConstraint = ConstraintBase<
58
61
  { expression: string; mainvars: string[] }
59
62
  >;
60
63
 
64
+ export type RQLConstraint = ConstraintBase<
65
+ "RQLConstraint",
66
+ { expression: string; mainvars: string[]; msg: ConstraintMessage }
67
+ >;
68
+
61
69
  /**
62
70
  * Type representing all possible constraints for attributes.
63
71
  */
@@ -69,9 +77,12 @@ export type AttributeConstraint = Readonly<
69
77
  | IntervalBoundConstraint
70
78
  | StaticVocabularyConstraint
71
79
  | FormatConstraint
80
+ | RQLConstraint
72
81
  >;
73
82
 
74
83
  /**
75
84
  * Type representing all possible constraints for relations.
76
85
  */
77
- export type RelationConstraint = Readonly<RQLVocabularyConstraint>;
86
+ export type RelationConstraint = Readonly<
87
+ RQLVocabularyConstraint | RQLConstraint
88
+ >;
@@ -78,6 +78,11 @@ interface IntervalBuildObj extends BuildObjBase<"Interval"> {
78
78
  default: unknown;
79
79
  }
80
80
 
81
+ interface CustomBuildObj<T extends string> extends BuildObjBase<T> {
82
+ type: T;
83
+ default: unknown;
84
+ }
85
+
81
86
  /**
82
87
  * Type allowing to link the type of an object to the type of their default values in a
83
88
  * relation definition. It only works for final relations using primitive types.
@@ -99,6 +104,7 @@ export type BuildObj = Readonly<
99
104
  | TZTimeBuildObj
100
105
  | TZDatetimeBuildObj
101
106
  | IntervalBuildObj
107
+ | CustomBuildObj<string>
102
108
  >;
103
109
 
104
110
  /**