@cubicweb/client 2.1.1 → 3.0.0-alpha.11

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 (64) hide show
  1. package/README.md +28 -16
  2. package/lib/Errors.js +3 -9
  3. package/lib/Errors.js.map +1 -1
  4. package/lib/api/Api.d.ts +35 -15
  5. package/lib/api/Api.d.ts.map +1 -1
  6. package/lib/api/Api.js +152 -133
  7. package/lib/api/Api.js.map +1 -1
  8. package/lib/api/Client.d.ts +20 -9
  9. package/lib/api/Client.d.ts.map +1 -1
  10. package/lib/api/Client.js +40 -49
  11. package/lib/api/Client.js.map +1 -1
  12. package/lib/api/Transaction.d.ts +33 -20
  13. package/lib/api/Transaction.d.ts.map +1 -1
  14. package/lib/api/Transaction.js +50 -46
  15. package/lib/api/Transaction.js.map +1 -1
  16. package/lib/index.d.ts +13 -13
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +12 -33
  19. package/lib/index.js.map +1 -1
  20. package/lib/schema/classes/EntitySchema.d.ts +21 -27
  21. package/lib/schema/classes/EntitySchema.d.ts.map +1 -1
  22. package/lib/schema/classes/EntitySchema.js +20 -30
  23. package/lib/schema/classes/EntitySchema.js.map +1 -1
  24. package/lib/schema/classes/RelationDefinitionSchema.d.ts +13 -15
  25. package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -1
  26. package/lib/schema/classes/RelationDefinitionSchema.js +14 -30
  27. package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -1
  28. package/lib/schema/classes/Schema.d.ts +9 -7
  29. package/lib/schema/classes/Schema.d.ts.map +1 -1
  30. package/lib/schema/classes/Schema.js +10 -11
  31. package/lib/schema/classes/Schema.js.map +1 -1
  32. package/lib/schema/classes/Utils.d.ts +139 -5
  33. package/lib/schema/classes/Utils.d.ts.map +1 -1
  34. package/lib/schema/classes/Utils.js +157 -11
  35. package/lib/schema/classes/Utils.js.map +1 -1
  36. package/lib/schema/raw/Constraints.d.ts +17 -9
  37. package/lib/schema/raw/Constraints.d.ts.map +1 -1
  38. package/lib/schema/raw/Constraints.js +1 -2
  39. package/lib/schema/raw/Entities.d.ts +4 -0
  40. package/lib/schema/raw/Entities.d.ts.map +1 -1
  41. package/lib/schema/raw/Entities.js +1 -2
  42. package/lib/schema/raw/RelationDefinitions.d.ts +17 -4
  43. package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
  44. package/lib/schema/raw/RelationDefinitions.js +1 -2
  45. package/lib/schema/raw/Schema.d.ts +4 -2
  46. package/lib/schema/raw/Schema.d.ts.map +1 -1
  47. package/lib/schema/raw/Schema.js +1 -2
  48. package/lib/schema/raw/Utils.d.ts +7 -1
  49. package/lib/schema/raw/Utils.d.ts.map +1 -1
  50. package/lib/schema/raw/Utils.js +1 -2
  51. package/package.json +6 -9
  52. package/src/api/Api.ts +110 -57
  53. package/src/api/Client.ts +36 -19
  54. package/src/api/Transaction.ts +56 -37
  55. package/src/index.ts +13 -13
  56. package/src/schema/classes/EntitySchema.ts +43 -46
  57. package/src/schema/classes/RelationDefinitionSchema.ts +16 -31
  58. package/src/schema/classes/Schema.ts +12 -7
  59. package/src/schema/classes/Utils.ts +182 -5
  60. package/src/schema/raw/Constraints.ts +20 -8
  61. package/src/schema/raw/Entities.ts +4 -0
  62. package/src/schema/raw/RelationDefinitions.ts +17 -4
  63. package/src/schema/raw/Schema.ts +4 -2
  64. package/src/schema/raw/Utils.ts +7 -1
package/src/api/Api.ts CHANGED
@@ -1,36 +1,48 @@
1
- import { ValidationError } from "../Errors";
2
- import { RawSchema } from "../schema/raw/Schema";
1
+ import { ValidationError } from "../Errors.js";
2
+ import { RawSchema } from "../schema/raw/Schema.js";
3
3
  import {
4
4
  TransactionResult,
5
5
  Transaction,
6
- isTransactionQueryRef,
7
- } from "./Transaction";
6
+ TransactionQueryScalarRef,
7
+ TransactionQueryBinaryRef,
8
+ } from "./Transaction.js";
8
9
 
9
10
  /**
10
11
  * Type representing an RQL request and its associated parameters.
12
+ *
13
+ * @category Api
11
14
  */
12
15
  export type RQLQuery = [string, RQLParams];
13
16
 
14
17
  export type RQLParamValue = string | number | boolean | null;
15
18
  /**
16
19
  * Type representing RQL parameters to send along a request.
20
+ *
21
+ * @category Api
17
22
  */
18
- export interface RQLParams {
19
- [key: string]: RQLParamValue;
20
- }
23
+ export type RQLParams = Record<
24
+ string,
25
+ RQLParamValue | TransactionQueryScalarRef | TransactionQueryBinaryRef
26
+ >;
21
27
 
22
28
  /**
23
29
  * Type representing a row returned in a result set.
30
+ *
31
+ * @category Api
24
32
  */
25
33
  export type RqlRow = Array<string | number | boolean | null>;
26
34
 
27
35
  /**
28
36
  * Type representing a RQL request result.
37
+ *
38
+ * @category Api
29
39
  */
30
40
  export type ResultSet = Array<RqlRow>;
31
41
 
32
42
  /**
33
43
  * Type representing the currently logged user's data
44
+ *
45
+ * @category Api
34
46
  */
35
47
  export interface CurrentUser {
36
48
  login: string;
@@ -40,6 +52,8 @@ export interface CurrentUser {
40
52
 
41
53
  /**
42
54
  * Type representing the body of an error sent by CubicWeb's API.
55
+ *
56
+ * @category Api
43
57
  */
44
58
  type ApiError = {
45
59
  title: string;
@@ -49,6 +63,8 @@ type ApiError = {
49
63
 
50
64
  /**
51
65
  * Type representing the error data sent to clients when retrieving an API error.
66
+ *
67
+ * @category Api
52
68
  */
53
69
  export type ApiErrorResponse = {
54
70
  status: number;
@@ -68,8 +84,9 @@ export default class Api {
68
84
  private _rqlApiUrl: string;
69
85
  private _schemaApiUrl: string;
70
86
  private _loginApiUrl: string;
87
+ private _logoutApiUrl: string;
71
88
  private _currentUserApiUrl: string;
72
- private _transactionApiUrl: string;
89
+ private _binaryApiUrl: string;
73
90
 
74
91
  /**
75
92
  * Class used to handle requests to the CubicWeb API.
@@ -86,8 +103,9 @@ export default class Api {
86
103
  this._rqlApiUrl = this.getApiRoute("rql");
87
104
  this._schemaApiUrl = this.getApiRoute("schema");
88
105
  this._loginApiUrl = this.getApiRoute("login");
106
+ this._logoutApiUrl = this.getApiRoute("logout");
89
107
  this._currentUserApiUrl = this.getApiRoute("current-user");
90
- this._transactionApiUrl = this.getApiRoute("transaction");
108
+ this._binaryApiUrl = this.getApiRoute("binary");
91
109
  }
92
110
 
93
111
  get apiUrl() {
@@ -98,25 +116,6 @@ export default class Api {
98
116
  return `${this._apiUrl}/${this._version}/${route}`;
99
117
  }
100
118
 
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
119
  /**
121
120
  * Retrieves the CubicWeb instance's JSON schema.
122
121
  *
@@ -152,6 +151,18 @@ export default class Api {
152
151
  }
153
152
  }
154
153
 
154
+ /**
155
+ * Logs out the current user. Will invalidate any authentication cookie active.
156
+ *
157
+ * @returns A promise which will resolve when the user is properly logged out
158
+ */
159
+ async logout(): Promise<void> {
160
+ await fetchApi<null>(this._logoutApiUrl, {
161
+ method: "POST",
162
+ credentials: "include",
163
+ });
164
+ }
165
+
155
166
  /**
156
167
  * Get the current user associated to this client
157
168
  *
@@ -164,39 +175,72 @@ export default class Api {
164
175
  });
165
176
  }
166
177
 
167
- async executeTransaction(
168
- transaction: Transaction
169
- ): Promise<TransactionResult> {
170
- const data = transaction.queries.map((transactionQuery) => ({
171
- query: transactionQuery.query,
172
- params: Object.fromEntries(
173
- Object.entries(transactionQuery.params).map(([key, value]) => [
174
- key,
175
- isTransactionQueryRef(value)
176
- ? {
177
- queryIndex: value.queryIndex,
178
- row: value.row,
179
- column: value.column,
180
- }
181
- : value,
182
- ])
183
- ),
184
- }));
178
+ /**
179
+ * Get the binary for the given entity attribute
180
+ *
181
+ * @returns A promise resolving to the binary
182
+ */
183
+ async binary(eid: number, attribute: string): Promise<Blob> {
184
+ const params = new URLSearchParams({
185
+ eid: eid.toString(),
186
+ attribute,
187
+ });
188
+ return await nonNullFetchApi<Blob>(this._binaryApiUrl + params, {
189
+ method: "GET",
190
+ credentials: "include",
191
+ });
192
+ }
193
+
194
+ async rql(transaction: Transaction): Promise<TransactionResult> {
185
195
  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);
196
+ if (Object.keys(transaction.binaries).length > 0) {
197
+ return await this.multipartTransaction(transaction);
198
+ } else {
199
+ return await this.jsonTransaction(transaction);
200
+ }
195
201
  } catch (e) {
196
202
  this.handleUserErrors(e);
197
203
  }
198
204
  }
199
205
 
206
+ private getTransactionParams(transaction: Transaction) {
207
+ return transaction.queries.map((transactionQuery) => ({
208
+ query: transactionQuery.query,
209
+ params: transactionQuery.params,
210
+ }));
211
+ }
212
+
213
+ private async multipartTransaction(transaction: Transaction) {
214
+ const jsonParams = this.getTransactionParams(transaction);
215
+ const formData = new FormData();
216
+ formData.append("queries", JSON.stringify(jsonParams));
217
+ Object.entries(transaction.binaries).forEach(([key, value]) => {
218
+ formData.append(key, value);
219
+ });
220
+
221
+ const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
222
+ this._rqlApiUrl,
223
+ {
224
+ method: "POST",
225
+ credentials: "include",
226
+ body: formData,
227
+ }
228
+ );
229
+ return new TransactionResult(resultSets);
230
+ }
231
+
232
+ private async jsonTransaction(transaction: Transaction) {
233
+ const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
234
+ this._rqlApiUrl,
235
+ {
236
+ method: "POST",
237
+ credentials: "include",
238
+ body: JSON.stringify(this.getTransactionParams(transaction)),
239
+ }
240
+ );
241
+ return new TransactionResult(resultSets);
242
+ }
243
+
200
244
  private handleUserErrors(error: unknown): never {
201
245
  if (
202
246
  typeof error === "object" &&
@@ -254,9 +298,18 @@ async function fetchApi<R = unknown>(
254
298
  init?: RequestInit
255
299
  ): Promise<R | null> {
256
300
  let headers = init?.headers;
257
- if (init?.method && init.method !== "GET" && init.method !== "DELETE") {
301
+ if (init?.method && init.method !== "GET") {
302
+ headers = {
303
+ // CSRF custom header necessary for POST requests
304
+ "X-Client-Name": "XMLHttpRequest",
305
+ };
306
+ // Browsers will automatically set the multipart content type
307
+ // with the right boundary if the body is FormData
308
+ if (!(init.body instanceof FormData)) {
309
+ headers["Content-Type"] = "application/json;charset=UTF-8";
310
+ }
258
311
  headers = {
259
- "Content-Type": "application/json;charset=UTF-8",
312
+ ...headers,
260
313
  ...init?.headers,
261
314
  };
262
315
  }
package/src/api/Client.ts CHANGED
@@ -1,18 +1,18 @@
1
- import { Schema } from "../schema/classes/Schema";
2
- import Api, { RQLParams, ResultSet, CurrentUser } from "./Api";
1
+ import { Schema } from "../schema/classes/Schema.js";
2
+ import Api, { RQLParams, ResultSet, CurrentUser } from "./Api.js";
3
3
  import {
4
- NativeTransactionBackend,
4
+ BinariesParam,
5
5
  Transaction,
6
- TransactionBackend,
7
6
  TransactionResult,
8
- } from "./Transaction";
7
+ } from "./Transaction.js";
9
8
 
10
9
  /**
11
10
  * Class used to communicate with a CubicWeb instance's API.
11
+ *
12
+ * @category Api
12
13
  */
13
14
  export default class Client {
14
15
  private api: Api;
15
- private transactionBackend: TransactionBackend;
16
16
 
17
17
  /**
18
18
  * Class used to communicate with a CubicWeb instance's API.
@@ -21,17 +21,8 @@ export default class Client {
21
21
  * Example: if you can retrieve the schema with https://example.com/api/v1/schema,
22
22
  * use https://example.com/api as `apiUrl`.
23
23
  */
24
- constructor(
25
- apiUrl: string,
26
- options: { transactionBackend?: TransactionBackend } = {}
27
- ) {
24
+ constructor(apiUrl: string) {
28
25
  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
26
  }
36
27
 
37
28
  get apiUrl() {
@@ -45,8 +36,16 @@ export default class Client {
45
36
  * @param params The additional parameters for the request
46
37
  * @returns A promise with the request's result set
47
38
  */
48
- async execute(query: string, params: RQLParams = {}): Promise<ResultSet> {
49
- return await this.api.execute(query, params);
39
+ async execute(
40
+ query: string,
41
+ params: RQLParams = {},
42
+ binaries?: BinariesParam
43
+ ): Promise<ResultSet> {
44
+ const transaction = new Transaction();
45
+ const transactionQuery = transaction.push(query, params);
46
+ transaction.setBinaries(binaries);
47
+ const result = await this.executeTransaction(transaction);
48
+ return result.resolveQuery(transactionQuery.ref());
50
49
  }
51
50
 
52
51
  /**
@@ -70,6 +69,15 @@ export default class Client {
70
69
  return await this.api.login(login, password);
71
70
  }
72
71
 
72
+ /**
73
+ * Logs out the current user. Will invalidate any authentication cookie active.
74
+ *
75
+ * @returns A promise which will resolve when the user is properly logged out
76
+ */
77
+ async logout() {
78
+ return await this.api.logout();
79
+ }
80
+
73
81
  /**
74
82
  * Get the user associated to this client
75
83
  *
@@ -86,6 +94,15 @@ export default class Client {
86
94
  async executeTransaction(
87
95
  transaction: Transaction
88
96
  ): Promise<TransactionResult> {
89
- return await this.transactionBackend.execute(transaction);
97
+ return await this.api.rql(transaction);
98
+ }
99
+
100
+ /**
101
+ * Get the binary for the given entity attribute
102
+ *
103
+ * @returns A promise resolving to the binary
104
+ */
105
+ async getBinary(eid: number, attribute: string) {
106
+ return await this.api.binary(eid, attribute);
90
107
  }
91
108
  }
@@ -1,12 +1,12 @@
1
- import Api, { ResultSet, RQLParamValue } from "./Api";
1
+ import { RQLParams, ResultSet } from "./Api.js";
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
- push(
7
- query: string,
8
- params: Record<string, RQLParamValue | TransactionQueryRef>
9
- ): TransactionQuery {
9
+ push(query: string, params: RQLParams): TransactionQuery {
10
10
  const stackedQuery = new TransactionQuery(
11
11
  query,
12
12
  params,
@@ -16,60 +16,79 @@ export class Transaction {
16
16
  return stackedQuery;
17
17
  }
18
18
 
19
+ setBinaries(binaries?: BinariesParam) {
20
+ this._binaries = binaries ?? {};
21
+ }
22
+
23
+ get binaries(): BinariesParam {
24
+ return this._binaries;
25
+ }
26
+
19
27
  get queries(): ReadonlyArray<TransactionQuery> {
20
28
  return this._queries;
21
29
  }
22
30
  }
23
31
 
32
+ export class TransactionQuery {
33
+ constructor(
34
+ public readonly query: string,
35
+ public readonly params: RQLParams,
36
+ public readonly index: number
37
+ ) {}
38
+
39
+ ref(): TransactionQueryRef {
40
+ return new TransactionQueryRef(this.index);
41
+ }
42
+ }
43
+
24
44
  export class TransactionResult {
25
45
  constructor(private resultSets: ReadonlyArray<ResultSet>) {}
26
46
 
27
- resolve(ref: TransactionQueryRef) {
47
+ resolveQuery(ref: TransactionQueryRef) {
48
+ return this.resultSets[ref.queryIndex];
49
+ }
50
+
51
+ resolveRow(ref: TransactionQueryRowRef) {
52
+ return this.resultSets[ref.queryIndex][ref.row];
53
+ }
54
+
55
+ resolveScalar(ref: TransactionQueryScalarRef) {
28
56
  return this.resultSets[ref.queryIndex][ref.row][ref.column];
29
57
  }
30
58
  }
31
59
 
32
- export interface TransactionQueryRef {
33
- queryIndex: number;
34
- row: number;
35
- column: number;
60
+ export class TransactionQueryRef {
61
+ constructor(public readonly queryIndex: number) {}
62
+
63
+ row(r: number): TransactionQueryRowRef {
64
+ return new TransactionQueryRowRef(this.queryIndex, r);
65
+ }
36
66
  }
37
67
 
38
- export class TransactionQuery {
68
+ export class TransactionQueryRowRef {
39
69
  constructor(
40
- public readonly query: string,
41
- public readonly params: Record<string, RQLParamValue | TransactionQueryRef>,
42
- public readonly index: number
70
+ public readonly queryIndex: number,
71
+ public readonly row: number
43
72
  ) {}
44
73
 
45
- ref(row = 0, column = 0): TransactionQueryRef {
74
+ column(c: number): TransactionQueryScalarRef {
46
75
  return {
47
- queryIndex: this.index,
48
- row,
49
- column,
76
+ type: "query_reference",
77
+ queryIndex: this.queryIndex,
78
+ row: this.row,
79
+ column: c,
50
80
  };
51
81
  }
52
82
  }
53
83
 
54
- export function isTransactionQueryRef(
55
- value: RQLParamValue | TransactionQueryRef
56
- ): value is TransactionQueryRef {
57
- return (
58
- typeof value === "object" &&
59
- value !== null &&
60
- ["queryIndex", "row", "column"].every((key) =>
61
- Object.keys(value).includes(key)
62
- )
63
- );
84
+ export interface TransactionQueryScalarRef {
85
+ readonly queryIndex: number;
86
+ readonly row: number;
87
+ readonly column: number;
88
+ readonly type: "query_reference";
64
89
  }
65
90
 
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
- }
91
+ export interface TransactionQueryBinaryRef {
92
+ readonly ref: string;
93
+ readonly type: "binary_reference";
75
94
  }
package/src/index.ts CHANGED
@@ -1,25 +1,25 @@
1
1
  // Raw Schema
2
- export * from "./schema/raw/Constraints";
3
- export * from "./schema/raw/Entities";
4
- export * from "./schema/raw/RelationDefinitions";
5
- export * from "./schema/raw/Schema";
6
- export * from "./schema/raw/Utils";
2
+ export * from "./schema/raw/Constraints.js";
3
+ export * from "./schema/raw/Entities.js";
4
+ export * from "./schema/raw/RelationDefinitions.js";
5
+ export * from "./schema/raw/Schema.js";
6
+ export * from "./schema/raw/Utils.js";
7
7
 
8
8
  // Schema Abstraction class
9
- export * from "./schema/classes/EntitySchema";
10
- export * from "./schema/classes/RelationDefinitionSchema";
11
- export * from "./schema/classes/Schema";
12
- export * from "./schema/classes/Utils";
9
+ export * from "./schema/classes/EntitySchema.js";
10
+ export * from "./schema/classes/RelationDefinitionSchema.js";
11
+ export * from "./schema/classes/Schema.js";
12
+ export * from "./schema/classes/Utils.js";
13
13
 
14
- export * from "./Errors";
14
+ export * from "./Errors.js";
15
15
 
16
16
  // API
17
- export { default as Client } from "./api/Client";
18
- export * from "./api/Transaction";
17
+ export { default as Client } from "./api/Client.js";
18
+ export * from "./api/Transaction.js";
19
19
  export {
20
20
  RQLQuery,
21
21
  RQLParams,
22
22
  RqlRow,
23
23
  ResultSet,
24
24
  ApiErrorResponse,
25
- } from "./api/Api";
25
+ } from "./api/Api.js";
@@ -1,13 +1,18 @@
1
- import { EntityRawSchemaArray } from "../raw/Entities";
2
- import { RelationDefinitionRawSchemaArray } from "../raw/RelationDefinitions";
3
- import { RelationDefinitionSchema } from "./RelationDefinitionSchema";
4
- import { Schema } from "./Schema";
5
- import { MatchedRelationDefinition, RelationDefinitionMatcher } from "./Utils";
1
+ import { EntityRawSchemaArray } from "../raw/Entities.js";
2
+ import { RelationDefinitionRawSchemaArray } from "../raw/RelationDefinitions.js";
3
+ import { RelationDefinitionSchema } from "./RelationDefinitionSchema.js";
4
+ import { Schema } from "./Schema.js";
5
+ import {
6
+ MatchedRelationDefinition,
7
+ RelationDefinitionMatcher,
8
+ } from "./Utils.js";
6
9
 
7
10
  /**
8
11
  * Wrapper around raw entity schemas from the Schema.
9
12
  * You should never have to create this object yourself.
10
13
  * Instead, retrieve these objects from the methods in the `Schema` class.
14
+ *
15
+ * @category Schema
11
16
  */
12
17
  export class EntitySchema<
13
18
  E extends EntityRawSchemaArray = EntityRawSchemaArray,
@@ -49,43 +54,54 @@ export class EntitySchema<
49
54
  }
50
55
 
51
56
  /**
52
- * Gets the list of relation definitions schemas with this entity as subject.
53
- * In case a relation definition schema has this entity as both object and subject,
54
- * there will be dupicates when used along with `objectRelationsDefinitions`.
57
+ * Gets the list of attribute schemas (relation definition schemas with final at false)
58
+ * for this entity schema.
55
59
  */
56
- get subjectRelationDefinitions(): RelationDefinitionSchema<
60
+ get attributes(): RelationDefinitionSchema<
57
61
  E,
58
62
  R,
59
63
  MatchedRelationDefinition<
60
64
  E,
61
65
  R,
62
- { subject: ERawSchema["type"]; final: false }
66
+ { subject: ERawSchema["type"]; final: true }
63
67
  >
64
68
  >[] {
65
69
  return this.schema.matchRelationDefinitions({
70
+ final: true,
66
71
  subject: this.type,
67
- final: false,
68
72
  });
69
73
  }
70
74
 
71
- /**
72
- * Gets the list of relation definitions schemas with this entity as object.
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<
75
+ get relationDefinitions(): {
76
+ subject: RelationDefinitionSchema<
80
77
  E,
81
78
  R,
82
- { object: ERawSchema["type"]; final: false }
83
- >
84
- >[] {
85
- return this.schema.matchRelationDefinitions({
86
- object: this.type,
87
- final: false,
88
- });
79
+ MatchedRelationDefinition<
80
+ E,
81
+ R,
82
+ { subject: ERawSchema["type"]; final: false }
83
+ >
84
+ >[];
85
+ object: RelationDefinitionSchema<
86
+ E,
87
+ R,
88
+ MatchedRelationDefinition<
89
+ E,
90
+ R,
91
+ { object: ERawSchema["type"]; final: false }
92
+ >
93
+ >[];
94
+ } {
95
+ return {
96
+ subject: this.schema.matchRelationDefinitions({
97
+ subject: this.type,
98
+ final: false,
99
+ }),
100
+ object: this.schema.matchRelationDefinitions({
101
+ object: this.type,
102
+ final: false,
103
+ }),
104
+ };
89
105
  }
90
106
 
91
107
  /**
@@ -103,23 +119,4 @@ export class EntitySchema<
103
119
  >[] {
104
120
  return this.schema.matchRelationDefinitions(matcher);
105
121
  }
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
122
  }