@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.
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 +6 -9
  11. package/lib/api/Transaction.d.ts.map +1 -1
  12. package/lib/api/Transaction.js +11 -21
  13. package/lib/api/Transaction.js.map +1 -1
  14. package/lib/schema/classes/EntitySchema.d.ts +16 -22
  15. package/lib/schema/classes/EntitySchema.d.ts.map +1 -1
  16. package/lib/schema/classes/EntitySchema.js +17 -25
  17. package/lib/schema/classes/EntitySchema.js.map +1 -1
  18. package/lib/schema/classes/RelationDefinitionSchema.d.ts +8 -10
  19. package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -1
  20. package/lib/schema/classes/RelationDefinitionSchema.js +7 -21
  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 +135 -1
  27. package/lib/schema/classes/Utils.d.ts.map +1 -1
  28. package/lib/schema/classes/Utils.js +165 -3
  29. package/lib/schema/classes/Utils.js.map +1 -1
  30. package/lib/schema/raw/Constraints.d.ts +13 -5
  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 +15 -2
  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 +79 -38
  42. package/src/api/Client.ts +24 -20
  43. package/src/api/Transaction.ts +16 -12
  44. package/src/schema/classes/EntitySchema.ts +35 -41
  45. package/src/schema/classes/RelationDefinitionSchema.ts +10 -25
  46. package/src/schema/classes/Schema.ts +2 -0
  47. package/src/schema/classes/Utils.ts +178 -1
  48. package/src/schema/raw/Constraints.ts +13 -5
  49. package/src/schema/raw/Entities.ts +4 -0
  50. package/src/schema/raw/RelationDefinitions.ts +15 -2
  51. package/src/schema/raw/Schema.ts +2 -0
  52. package/src/schema/raw/Utils.ts +6 -0
@@ -6,7 +6,7 @@ type ConstraintBase<T extends string, V extends Record<string, unknown> | null>
6
6
  value: V;
7
7
  };
8
8
  /**
9
- * THe type of a constraint message when one is present.
9
+ * The type of a constraint message when one is present.
10
10
  */
11
11
  type ConstraintMessage = string | null;
12
12
  export type UniqueConstraint = ConstraintBase<"UniqueConstraint", {
@@ -26,6 +26,8 @@ export type RegexpConstraint = ConstraintBase<"RegexpConstraint", {
26
26
  * Reference to an attribute used in constraints.
27
27
  *
28
28
  * @property \_\_attribute\_\_ name of the attribute in the same entity
29
+ *
30
+ * @category Schema
29
31
  */
30
32
  export interface Attribute {
31
33
  __attribute__: string;
@@ -41,6 +43,8 @@ export interface TimeDelta {
41
43
  * @property \_\_today\_\_ always true
42
44
  * @property offset delta to current date at the time of the check
43
45
  * @property type name of the Python class used to do the comparison
46
+ *
47
+ * @category Schema
44
48
  */
45
49
  export interface Today {
46
50
  __today__: true;
@@ -52,6 +56,8 @@ export interface Today {
52
56
  *
53
57
  * @property \_\_now\_\_ always true
54
58
  * @property offset delta to current date at the time of the check
59
+ *
60
+ * @category Schema
55
61
  */
56
62
  export interface Now {
57
63
  __now__: true;
@@ -59,12 +65,10 @@ export interface Now {
59
65
  }
60
66
  /**
61
67
  * All the possible operators inside a constraint.
62
- */
63
- export type ConstraintOperator = ">" | ">=" | "<" | "<=";
64
- /**
65
- * @property value.boundary boudary value to compare the attribut
66
68
  *
69
+ * @category Schema
67
70
  */
71
+ export type ConstraintOperator = ">" | ">=" | "<" | "<=";
68
72
  export type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
69
73
  boundary: Attribute | Today | Now | number | null;
70
74
  op: ConstraintOperator;
@@ -94,10 +98,14 @@ export type RQLConstraint = ConstraintBase<"RQLConstraint", {
94
98
  }>;
95
99
  /**
96
100
  * Type representing all possible constraints for attributes.
101
+ *
102
+ * @category Schema
97
103
  */
98
104
  export type AttributeConstraint = Readonly<UniqueConstraint | SizeConstraint | RegexpConstraint | BoundaryConstraint | IntervalBoundConstraint | StaticVocabularyConstraint | FormatConstraint | RQLConstraint>;
99
105
  /**
100
106
  * Type representing all possible constraints for relations.
107
+ *
108
+ * @category Schema
101
109
  */
102
110
  export type RelationConstraint = Readonly<RQLVocabularyConstraint | RQLConstraint>;
103
111
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Constraints.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Constraints.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,cAAc,CACjB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,IACtC;IACF,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,KAAK,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAAC;AAEvC,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAC3C,kBAAkB,EAClB;IAAE,GAAG,EAAE,iBAAiB,CAAA;CAAE,CAC3B,CAAC;AAEF,MAAM,MA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B,GAAG,QAAQ,CACvC,uBAAuB,GAAG,aAAa,CACxC,CAAC"}
@@ -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;
@@ -8,6 +10,8 @@ export type EntityRawSchema = {
8
10
  };
9
11
  /**
10
12
  * Type representing a list of entity schemas.
13
+ *
14
+ * @category Schema
11
15
  */
12
16
  export type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
13
17
  //# 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,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"}
1
+ {"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Entities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC"}
@@ -1,11 +1,16 @@
1
+ import { EntityRole } from "../classes/Utils";
1
2
  import { AttributeConstraint, RelationConstraint } from "./Constraints";
2
3
  import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
3
4
  /**
4
5
  * Type representing all the possible cardinalities in CubicWeb.
6
+ *
7
+ * @category Schema
5
8
  */
6
9
  export type Cardinality = "*" | "1" | "?" | "+";
7
10
  /**
8
11
  * Type representing a cardinality pair as used in relation definitions.
12
+ *
13
+ * @category Schema
9
14
  */
10
15
  export type CardinalityPair = `${Cardinality}${Cardinality}`;
11
16
  /**
@@ -73,6 +78,8 @@ interface CustomBuildObj<T extends string> extends BuildObjBase<T> {
73
78
  export type BuildObj = Readonly<StringBuildObj | PasswordBuildObj | BytesBuildObj | IntBuildObj | BigIntBuildObj | FloatBuildObj | BooleanBuildObj | DecimalBuildObj | DateBuildObj | TimeBuildObj | DatetimeBuildObj | TZTimeBuildObj | TZDatetimeBuildObj | IntervalBuildObj | CustomBuildObj<string>>;
74
79
  /**
75
80
  * Type representing the possible options for an attribute.
81
+ *
82
+ * @category Schema
76
83
  */
77
84
  export type AttributeOptions = {
78
85
  indexed?: boolean;
@@ -81,18 +88,22 @@ export type AttributeOptions = {
81
88
  };
82
89
  /**
83
90
  * Type representing the possible options for a relation definition.
91
+ *
92
+ * @category Schema
84
93
  */
85
94
  export type RelationOptions = {
86
95
  symmetric?: boolean;
87
96
  inlined?: boolean;
88
- fulltext_container?: "subject" | "object";
89
- composite?: "subject" | "object";
97
+ fulltext_container?: EntityRole;
98
+ composite?: EntityRole;
90
99
  };
91
100
  /**
92
101
  * Type representing a relation definition schema.
93
102
  * It can represent both attributes and relations depending on the value of Final.
94
103
  *
95
104
  * It can infer default values type depending on the object type if the relation is final.
105
+ *
106
+ * @category Schema
96
107
  */
97
108
  export type RelationDefinitionRawSchema<ESchemas extends EntityRawSchemaArray, Final extends boolean = boolean> = Readonly<{
98
109
  type: string;
@@ -111,6 +122,8 @@ export type RelationDefinitionRawSchema<ESchemas extends EntityRawSchemaArray, F
111
122
  })>;
112
123
  /**
113
124
  * Type representing a list of relation definitions.
125
+ *
126
+ * @category Schema
114
127
  */
115
128
  export type RelationDefinitionRawSchemaArray<ESchemas extends EntityRawSchemaArray> = ReadonlyArray<RelationDefinitionRawSchema<ESchemas, boolean>>;
116
129
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"RelationDefinitions.d.ts","sourceRoot":"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;;GAOG;AACH,MAAM,MAAM,2BAA2B,CACrC,QAAQ,SAAS,oBAAoB,EACrC,KAAK,SAAS,OAAO,GAAG,OAAO,IAC7B,QAAQ,CACV;IACE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,eAAe,CAAC;IAC7B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;CACnC,GAAG,CAAC,KAAK,SAAS,IAAI,GACnB,QAAQ,GAAG;IACT,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,EAAE,mBAAmB,EAAE,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC;CAC3B,GACD;IACE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAClC,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC,CACP,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gCAAgC,CAC1C,QAAQ,SAAS,oBAAoB,IACnC,aAAa,CAAC,2BAA2B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC"}
@@ -5,6 +5,8 @@ import { RelationDefinitionRawSchemaArray } from "./RelationDefinitions";
5
5
  * You can export this schema from your CubicWeb instance using the command:
6
6
  *
7
7
  * `cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>`
8
+ *
9
+ * @category Schema
8
10
  */
9
11
  export type RawSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> = {
10
12
  entities: E;
@@ -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,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"}
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;;;;;;;GAOG;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"}
@@ -5,16 +5,22 @@ import { EntityRawSchemaArray } from "./Entities";
5
5
  *
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
+ *
9
+ * @category Schema
8
10
  */
9
11
  export type IsLooseSchema<E extends EntityRawSchemaArray> = string extends E[number]["type"] ? true : false;
10
12
  /**
11
13
  * Checks if the given entity type is present in the EntityRawSchemaArray.
12
14
  * Use this to create conditional types.
15
+ *
16
+ * @category Schema
13
17
  */
14
18
  export type IsETypeInStrictSchema<E extends EntityRawSchemaArray, EType extends string> = EType extends E[number]["type"] ? true : false;
15
19
  /**
16
20
  * Type representing the entity's raw schema matching this type.
17
21
  * This type only works for EntityRawSchemaArray with literals as "type" property.
22
+ *
23
+ * @category Schema
18
24
  */
19
25
  export type EntityRawSchemaByType<E extends EntityRawSchemaArray, T extends string> = E[number] extends infer ESchema ? ESchema extends {
20
26
  type: T;
@@ -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,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"}
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;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,oBAAoB,IACtD,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAElD;;;;;GAKG;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;;;;;GAKG;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,13 +2,13 @@
2
2
  "name": "@cubicweb/client",
3
3
  "description": "Official JS client for CubicWeb API",
4
4
  "author": "Logilab",
5
- "version": "2.1.1",
5
+ "version": "3.0.0-alpha.5",
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",
11
- "docs": "typedoc"
10
+ "build": "run -T tsc --project tsconfig.build.json",
11
+ "docs": "run -T typedoc"
12
12
  },
13
13
  "repository": {
14
14
  "type": "hg",
@@ -23,9 +23,5 @@
23
23
  "lib/**",
24
24
  "src/**",
25
25
  "!**/__tests__/**"
26
- ],
27
- "devDependencies": {
28
- "typedoc": "^0.23.24",
29
- "typescript": "^4.9.4"
30
- }
26
+ ]
31
27
  }
package/src/api/Api.ts CHANGED
@@ -8,12 +8,16 @@ import {
8
8
 
9
9
  /**
10
10
  * Type representing an RQL request and its associated parameters.
11
+ *
12
+ * @category Api
11
13
  */
12
14
  export type RQLQuery = [string, RQLParams];
13
15
 
14
16
  export type RQLParamValue = string | number | boolean | null;
15
17
  /**
16
18
  * Type representing RQL parameters to send along a request.
19
+ *
20
+ * @category Api
17
21
  */
18
22
  export interface RQLParams {
19
23
  [key: string]: RQLParamValue;
@@ -21,16 +25,22 @@ export interface RQLParams {
21
25
 
22
26
  /**
23
27
  * Type representing a row returned in a result set.
28
+ *
29
+ * @category Api
24
30
  */
25
31
  export type RqlRow = Array<string | number | boolean | null>;
26
32
 
27
33
  /**
28
34
  * Type representing a RQL request result.
35
+ *
36
+ * @category Api
29
37
  */
30
38
  export type ResultSet = Array<RqlRow>;
31
39
 
32
40
  /**
33
41
  * Type representing the currently logged user's data
42
+ *
43
+ * @category Api
34
44
  */
35
45
  export interface CurrentUser {
36
46
  login: string;
@@ -40,6 +50,8 @@ export interface CurrentUser {
40
50
 
41
51
  /**
42
52
  * Type representing the body of an error sent by CubicWeb's API.
53
+ *
54
+ * @category Api
43
55
  */
44
56
  type ApiError = {
45
57
  title: string;
@@ -49,6 +61,8 @@ type ApiError = {
49
61
 
50
62
  /**
51
63
  * Type representing the error data sent to clients when retrieving an API error.
64
+ *
65
+ * @category Api
52
66
  */
53
67
  export type ApiErrorResponse = {
54
68
  status: number;
@@ -69,7 +83,7 @@ export default class Api {
69
83
  private _schemaApiUrl: string;
70
84
  private _loginApiUrl: string;
71
85
  private _currentUserApiUrl: string;
72
- private _transactionApiUrl: string;
86
+ private _binaryApiUrl: string;
73
87
 
74
88
  /**
75
89
  * Class used to handle requests to the CubicWeb API.
@@ -87,7 +101,7 @@ export default class Api {
87
101
  this._schemaApiUrl = this.getApiRoute("schema");
88
102
  this._loginApiUrl = this.getApiRoute("login");
89
103
  this._currentUserApiUrl = this.getApiRoute("current-user");
90
- this._transactionApiUrl = this.getApiRoute("transaction");
104
+ this._binaryApiUrl = this.getApiRoute("binary");
91
105
  }
92
106
 
93
107
  get apiUrl() {
@@ -98,25 +112,6 @@ export default class Api {
98
112
  return `${this._apiUrl}/${this._version}/${route}`;
99
113
  }
100
114
 
101
- /**
102
- * Executes the given query and waits for the response.
103
- *
104
- * @param query The RQL query to send
105
- * @param params The additional parameters for the request
106
- * @returns A promise with the request's result set
107
- */
108
- async execute(query: string, params: RQLParams): Promise<ResultSet> {
109
- try {
110
- return await nonNullFetchApi<ResultSet>(this._rqlApiUrl, {
111
- method: "POST",
112
- body: JSON.stringify({ query, params }),
113
- credentials: "include", // FIXME is it secure?
114
- });
115
- } catch (e) {
116
- this.handleUserErrors(e);
117
- }
118
- }
119
-
120
115
  /**
121
116
  * Retrieves the CubicWeb instance's JSON schema.
122
117
  *
@@ -164,10 +159,36 @@ export default class Api {
164
159
  });
165
160
  }
166
161
 
167
- async executeTransaction(
168
- transaction: Transaction
169
- ): Promise<TransactionResult> {
170
- const data = transaction.queries.map((transactionQuery) => ({
162
+ /**
163
+ * Get the binary for the given entity attribute
164
+ *
165
+ * @returns A promise resolving to the binary
166
+ */
167
+ async binary(eid: number, attribute: string): Promise<Blob> {
168
+ const params = new URLSearchParams({
169
+ eid: eid.toString(),
170
+ attribute,
171
+ });
172
+ return await nonNullFetchApi<Blob>(this._binaryApiUrl + params, {
173
+ method: "GET",
174
+ credentials: "include",
175
+ });
176
+ }
177
+
178
+ async rql(transaction: Transaction): Promise<TransactionResult> {
179
+ try {
180
+ if (Object.keys(transaction.binaries).length > 0) {
181
+ return await this.multipartTransaction(transaction);
182
+ } else {
183
+ return await this.jsonTransaction(transaction);
184
+ }
185
+ } catch (e) {
186
+ this.handleUserErrors(e);
187
+ }
188
+ }
189
+
190
+ private getTransactionParams(transaction: Transaction) {
191
+ return transaction.queries.map((transactionQuery) => ({
171
192
  query: transactionQuery.query,
172
193
  params: Object.fromEntries(
173
194
  Object.entries(transactionQuery.params).map(([key, value]) => [
@@ -182,19 +203,37 @@ export default class Api {
182
203
  ])
183
204
  ),
184
205
  }));
185
- try {
186
- const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
187
- this._transactionApiUrl,
188
- {
189
- method: "POST",
190
- credentials: "include",
191
- body: JSON.stringify(data),
192
- }
193
- );
194
- return new TransactionResult(resultSets);
195
- } catch (e) {
196
- this.handleUserErrors(e);
197
- }
206
+ }
207
+
208
+ private async multipartTransaction(transaction: Transaction) {
209
+ const jsonParams = this.getTransactionParams(transaction);
210
+ const formData = new FormData();
211
+ formData.append("queries", JSON.stringify(jsonParams));
212
+ Object.entries(transaction.binaries).forEach(([key, value]) => {
213
+ formData.append(key, value);
214
+ });
215
+
216
+ const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
217
+ this._rqlApiUrl,
218
+ {
219
+ method: "POST",
220
+ credentials: "include",
221
+ body: formData,
222
+ }
223
+ );
224
+ return new TransactionResult(resultSets);
225
+ }
226
+
227
+ private async jsonTransaction(transaction: Transaction) {
228
+ const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
229
+ this._rqlApiUrl,
230
+ {
231
+ method: "POST",
232
+ credentials: "include",
233
+ body: JSON.stringify(this.getTransactionParams(transaction)),
234
+ }
235
+ );
236
+ return new TransactionResult(resultSets);
198
237
  }
199
238
 
200
239
  private handleUserErrors(error: unknown): never {
@@ -257,6 +296,8 @@ async function fetchApi<R = unknown>(
257
296
  if (init?.method && init.method !== "GET" && init.method !== "DELETE") {
258
297
  headers = {
259
298
  "Content-Type": "application/json;charset=UTF-8",
299
+ // CSRF custom header necessary for POST requests
300
+ "X-Requested-With": "XMLHttpRequest",
260
301
  ...init?.headers,
261
302
  };
262
303
  }
package/src/api/Client.ts CHANGED
@@ -1,18 +1,14 @@
1
1
  import { Schema } from "../schema/classes/Schema";
2
2
  import Api, { RQLParams, ResultSet, CurrentUser } from "./Api";
3
- import {
4
- NativeTransactionBackend,
5
- Transaction,
6
- TransactionBackend,
7
- TransactionResult,
8
- } from "./Transaction";
3
+ import { BinariesParam, Transaction, TransactionResult } from "./Transaction";
9
4
 
10
5
  /**
11
6
  * Class used to communicate with a CubicWeb instance's API.
7
+ *
8
+ * @category Api
12
9
  */
13
10
  export default class Client {
14
11
  private api: Api;
15
- private transactionBackend: TransactionBackend;
16
12
 
17
13
  /**
18
14
  * Class used to communicate with a CubicWeb instance's API.
@@ -21,17 +17,8 @@ export default class Client {
21
17
  * Example: if you can retrieve the schema with https://example.com/api/v1/schema,
22
18
  * use https://example.com/api as `apiUrl`.
23
19
  */
24
- constructor(
25
- apiUrl: string,
26
- options: { transactionBackend?: TransactionBackend } = {}
27
- ) {
20
+ constructor(apiUrl: string) {
28
21
  this.api = new Api(apiUrl);
29
- const { transactionBackend } = options;
30
- if (transactionBackend === undefined) {
31
- this.transactionBackend = new NativeTransactionBackend(this.api);
32
- } else {
33
- this.transactionBackend = transactionBackend;
34
- }
35
22
  }
36
23
 
37
24
  get apiUrl() {
@@ -45,8 +32,16 @@ export default class Client {
45
32
  * @param params The additional parameters for the request
46
33
  * @returns A promise with the request's result set
47
34
  */
48
- async execute(query: string, params: RQLParams = {}): Promise<ResultSet> {
49
- return await this.api.execute(query, params);
35
+ async execute(
36
+ query: string,
37
+ params: RQLParams = {},
38
+ binaries?: BinariesParam
39
+ ): Promise<ResultSet> {
40
+ const transaction = new Transaction();
41
+ transaction.push(query, params);
42
+ transaction.setBinaries(binaries);
43
+ const result = await this.executeTransaction(transaction);
44
+ return result.get(0);
50
45
  }
51
46
 
52
47
  /**
@@ -86,6 +81,15 @@ export default class Client {
86
81
  async executeTransaction(
87
82
  transaction: Transaction
88
83
  ): Promise<TransactionResult> {
89
- return await this.transactionBackend.execute(transaction);
84
+ return await this.api.rql(transaction);
85
+ }
86
+
87
+ /**
88
+ * Get the binary for the given entity attribute
89
+ *
90
+ * @returns A promise resolving to the binary
91
+ */
92
+ async getBinary(eid: number, attribute: string) {
93
+ return await this.api.binary(eid, attribute);
90
94
  }
91
95
  }
@@ -1,7 +1,10 @@
1
- import Api, { ResultSet, RQLParamValue } from "./Api";
1
+ import { ResultSet, RQLParamValue } from "./Api";
2
+
3
+ export type BinariesParam = Record<string, Blob>;
2
4
 
3
5
  export class Transaction {
4
6
  private _queries: Array<TransactionQuery> = [];
7
+ private _binaries: BinariesParam = {};
5
8
 
6
9
  push(
7
10
  query: string,
@@ -16,6 +19,14 @@ export class Transaction {
16
19
  return stackedQuery;
17
20
  }
18
21
 
22
+ setBinaries(binaries?: BinariesParam) {
23
+ this._binaries = binaries ?? {};
24
+ }
25
+
26
+ get binaries(): BinariesParam {
27
+ return this._binaries;
28
+ }
29
+
19
30
  get queries(): ReadonlyArray<TransactionQuery> {
20
31
  return this._queries;
21
32
  }
@@ -24,6 +35,10 @@ export class Transaction {
24
35
  export class TransactionResult {
25
36
  constructor(private resultSets: ReadonlyArray<ResultSet>) {}
26
37
 
38
+ get(queryIndex: number): ResultSet {
39
+ return this.resultSets[queryIndex];
40
+ }
41
+
27
42
  resolve(ref: TransactionQueryRef) {
28
43
  return this.resultSets[ref.queryIndex][ref.row][ref.column];
29
44
  }
@@ -62,14 +77,3 @@ export function isTransactionQueryRef(
62
77
  )
63
78
  );
64
79
  }
65
-
66
- export interface TransactionBackend {
67
- execute(transaction: Transaction): Promise<TransactionResult>;
68
- }
69
-
70
- export class NativeTransactionBackend implements TransactionBackend {
71
- constructor(private _api: Api) {}
72
- async execute(transaction: Transaction): Promise<TransactionResult> {
73
- return this._api.executeTransaction(transaction);
74
- }
75
- }