@cubicweb/client 1.5.0 → 1.6.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.
- package/README.md +207 -0
- package/lib/schema/raw/Constraints.d.ts +10 -3
- package/lib/schema/raw/Constraints.d.ts.map +1 -1
- package/lib/schema/raw/RelationDefinitions.d.ts +5 -1
- package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
- package/package.json +9 -4
- package/src/schema/raw/Constraints.ts +13 -2
- package/src/schema/raw/RelationDefinitions.ts +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# @cubicweb/client
|
|
2
|
+
|
|
3
|
+
This library is the [CubicWeb](https://cubicweb.org/) JavaScript client
|
|
4
|
+
used to communicate with instances running with the
|
|
5
|
+
[API cube](https://forge.extranet.logilab.fr/cubicweb/cubes/api).
|
|
6
|
+
It replaces the [cwclientlibjs](https://forge.extranet.logilab.fr/open-source/cwclientlibjs)
|
|
7
|
+
library.
|
|
8
|
+
|
|
9
|
+
The full documentation is available [here](https://cubicweb.pages.logilab.fr/cubicwebjs/client).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
@cubicweb/client is avalaible from NPM:
|
|
14
|
+
```bash
|
|
15
|
+
# With NPM
|
|
16
|
+
npm i @cubicweb/client
|
|
17
|
+
# Or with Yarn
|
|
18
|
+
yarn add @cubicweb/client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then make sure you have a CubicWeb instance running with the
|
|
22
|
+
[API cube](https://forge.extranet.logilab.fr/cubicweb/cubes/api).
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
This library exposes a `Client` class used to send requests to the API.
|
|
27
|
+
This class requires the URL to your CubicWeb instance API endpoint
|
|
28
|
+
(eg: `https://example.com/api`).
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const client = new Client("https://example.com/api")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**⚠️ Real API routes include the API version in the URL (eg: `v1`),
|
|
35
|
+
but it must not appear here. The API version number will be automatically set by the client.**
|
|
36
|
+
|
|
37
|
+
For example, if you used `https://example.com/api/v1/schema` to retrieve your instance schema,
|
|
38
|
+
simply pass `https://example.com/api` to the client,
|
|
39
|
+
it will automatically add `/v1` on each request.
|
|
40
|
+
|
|
41
|
+
Your client object can then be used to send requests to the API.
|
|
42
|
+
|
|
43
|
+
See the [Client documentation](https://cubicweb.pages.logilab.fr/cubicwebjs/client/classes/Client.html) for more information.
|
|
44
|
+
|
|
45
|
+
### Example
|
|
46
|
+
|
|
47
|
+
The following example tries to log in a user then performs some operations on the instance.
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
client
|
|
51
|
+
.login("login", "password")
|
|
52
|
+
// Login was successful
|
|
53
|
+
.then(() => {
|
|
54
|
+
// Retrieve the instance's schema
|
|
55
|
+
client
|
|
56
|
+
.schema()
|
|
57
|
+
.then((schema) => {
|
|
58
|
+
console.log("Found the instance's schema:");
|
|
59
|
+
console.log(schema);
|
|
60
|
+
})
|
|
61
|
+
.catch((e) => {
|
|
62
|
+
console.error("There was an error while fetching the schema:");
|
|
63
|
+
console.error(e);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Execute an RQL query
|
|
67
|
+
client
|
|
68
|
+
.execute("Any X Where X eid 5")
|
|
69
|
+
.then((resultSet) => {
|
|
70
|
+
console.log("RQL request was successul and returned:");
|
|
71
|
+
console.log(resultSet);
|
|
72
|
+
})
|
|
73
|
+
.catch((e) => {
|
|
74
|
+
console.error("There was an error processing the RQL request:");
|
|
75
|
+
console.error(e);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Execute a series of request in a transaction
|
|
79
|
+
client
|
|
80
|
+
.transaction(async (tr) => {
|
|
81
|
+
const insertResult = await tr.execute(
|
|
82
|
+
`INSERT Person X: X name "test"`
|
|
83
|
+
);
|
|
84
|
+
const insertedEid = insertResult?.[0]?.[0];
|
|
85
|
+
if (insertedEid != null) {
|
|
86
|
+
return tr.execute(`Any X Where X eid %(created_eid)s`, {
|
|
87
|
+
created_eid: insertedEid,
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error("Error inserting Person");
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
.then((callbackResult) => {
|
|
94
|
+
console.log("Transaction was successul and the callback returned:");
|
|
95
|
+
console.log(callbackResult);
|
|
96
|
+
})
|
|
97
|
+
.catch((e) => {
|
|
98
|
+
console.error("There was an error processing the transaction:");
|
|
99
|
+
console.error(e);
|
|
100
|
+
});
|
|
101
|
+
})
|
|
102
|
+
// Login failed
|
|
103
|
+
.catch((e) => {
|
|
104
|
+
console.error("There was an error while loggin in the user:");
|
|
105
|
+
console.log(e);
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## CORS handling
|
|
110
|
+
|
|
111
|
+
> Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server
|
|
112
|
+
> to indicate any origins (domain, scheme, or port) other than its own from which a browser
|
|
113
|
+
> should permit loading resources. -
|
|
114
|
+
> [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
|
|
115
|
+
|
|
116
|
+
If the client is running on a different server from your CubicWeb instance,
|
|
117
|
+
you must authorize the URL the client is running on as well as the `Content-Type` header in your
|
|
118
|
+
[CubicWeb instance's configuration](https://cubicweb.readthedocs.io/en/latest/book/admin/instance-config#cross-origin-resource-sharing).
|
|
119
|
+
|
|
120
|
+
## Authentication
|
|
121
|
+
|
|
122
|
+
The API cube uses cookie authentication using [JWT](https://jwt.io).
|
|
123
|
+
A `CW_JWT` [HTTP Only](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security) cookie
|
|
124
|
+
will be automatically created by the browser when executing the login request.
|
|
125
|
+
This cookie cannot be accessed by the JavaScript so you will have to implement your own
|
|
126
|
+
logic to save the login state.
|
|
127
|
+
|
|
128
|
+
If the client is running on a different server from your CubicWeb instance,
|
|
129
|
+
make sure you setup CORS as described above.
|
|
130
|
+
For the login to work, you may also need to modify the cookie sent by the API cube to set
|
|
131
|
+
[`SameSite`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#samesite_attribute)
|
|
132
|
+
to `None`.
|
|
133
|
+
|
|
134
|
+
## Using the Schema
|
|
135
|
+
|
|
136
|
+
This library provides CubicWeb [schema abstraction classes](packages/client/src/schema/Schema.ts). Three classes are available:
|
|
137
|
+
* `Schema` - Global handling of the schema.
|
|
138
|
+
Can be used to query entities and relations.
|
|
139
|
+
* `EntitySchema` - Handling of a single entity type.
|
|
140
|
+
Can be used to query relations and metadata about the entity.
|
|
141
|
+
* `RelationDefinitionSchema` - Handling of a single relation.
|
|
142
|
+
Can be used to retrieve associated entities and metadata the relation.
|
|
143
|
+
|
|
144
|
+
The `Schema` class is created from the JSON schema returned by the API.
|
|
145
|
+
The `Client.schema()` method takes care of this for you.
|
|
146
|
+
If your schema does not change often, it is recommended to export it using the following command
|
|
147
|
+
(replace `<YOUR_INSTANCE_NAME>` by the name of your instance):
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
cubicweb-ctl export-schema -f json <YOUR_INSTANCE_NAME>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You can then manually create the Schema object by passing your JSON schema to its constructor.
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
// Making the request with the client
|
|
157
|
+
const schema = client.schema();
|
|
158
|
+
// Using a local json schema
|
|
159
|
+
const schema = new Schema(your_raw_json_schema);
|
|
160
|
+
```
|
|
161
|
+
`EntitySchema` and `RelationDefinitionSchema` objects should not be created manually.
|
|
162
|
+
These are returned when querying a `Schema` object.
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
// Retrieving an entity
|
|
166
|
+
const entitySchema = schema.getEntity("YourEntityType");
|
|
167
|
+
// Retrieving a relation
|
|
168
|
+
const relationDefinitionSchema = schema.matchRelationDefinitions({
|
|
169
|
+
subject: "YourEntityType",
|
|
170
|
+
type: "YourRelationType"',
|
|
171
|
+
object: "YourEntityType2"
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
See the [documentation](https://cubicweb.pages.logilab.fr/cubicwebjs/client/modules.html) for more information.
|
|
176
|
+
|
|
177
|
+
## TypeScript support
|
|
178
|
+
|
|
179
|
+
Both the client and the schema abstraction classes expose TypeScript types.
|
|
180
|
+
|
|
181
|
+
You can type the Schema class using the TypeScript representation of your instance schema
|
|
182
|
+
to benefit from the strong type inference. You can generate this representation using the command
|
|
183
|
+
(replace `<YOUR_INSTANCE_NAME>` by the name of your instance):
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This command will generate a file `schema.ts` containing the typings.
|
|
190
|
+
You can then include it in your project. When using this generated type,
|
|
191
|
+
the TS engine will be able to detect invalid entity types and relations.
|
|
192
|
+
|
|
193
|
+
**⚠️ You cannot type the schema when using the `client.schema()` method.
|
|
194
|
+
This is intended to prevent errors if the JSON schema changes and not the TS schema.**
|
|
195
|
+
You must export both the JSON schema and TypeScript schema to use the typings.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
// Type the schema when creating from a local JSON schema
|
|
199
|
+
const schema = new Schema<InstanceSchema["entities"], InstanceSchema["relations_definitions"]>(your_raw_json_schema);
|
|
200
|
+
|
|
201
|
+
// TS will complain it cannot assign type 'never'. This means your entity does not exist.
|
|
202
|
+
const entity = schema.getEntity("InvalidEntityType");
|
|
203
|
+
// TS will be happy and your entity will have the type 'ValidEntityType'.
|
|
204
|
+
const entity = schema.getEntity("ValidEntityType");
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
|
|
@@ -13,7 +13,9 @@ export declare type ConstraintOperator = ">" | ">=" | "<" | "<=";
|
|
|
13
13
|
* THe type of a constraint message when one is present.
|
|
14
14
|
*/
|
|
15
15
|
declare type ConstraintMessage = string | null;
|
|
16
|
-
export declare type UniqueConstraint = ConstraintBase<"UniqueConstraint",
|
|
16
|
+
export declare type UniqueConstraint = ConstraintBase<"UniqueConstraint", {
|
|
17
|
+
msg: ConstraintMessage;
|
|
18
|
+
}>;
|
|
17
19
|
export declare type SizeConstraint = ConstraintBase<"SizeConstraint", {
|
|
18
20
|
min: number | null;
|
|
19
21
|
max: number | null;
|
|
@@ -46,13 +48,18 @@ export declare type RQLVocabularyConstraint = ConstraintBase<"RQLVocabularyConst
|
|
|
46
48
|
expression: string;
|
|
47
49
|
mainvars: string[];
|
|
48
50
|
}>;
|
|
51
|
+
export declare type RQLConstraint = ConstraintBase<"RQLConstraint", {
|
|
52
|
+
expression: string;
|
|
53
|
+
mainvars: string[];
|
|
54
|
+
msg: ConstraintMessage;
|
|
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 declare 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 declare 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,c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GAAG,QAAQ,CACvC,uBAAuB,GAAG,aAAa,CACxC,CAAC"}
|
|
@@ -60,13 +60,17 @@ 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 declare 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
|
*/
|
|
@@ -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,GAA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AC3B,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;;GAEG;AACH,oBAAY,gCAAgC,CAC1C,QAAQ,SAAS,oBAAoB,IACnC,aAAa,CAAC,2BAA2B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,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
|
+
"version": "1.6.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.18",
|
|
29
|
+
"typescript": "^4.8.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -19,7 +19,10 @@ export type ConstraintOperator = ">" | ">=" | "<" | "<=";
|
|
|
19
19
|
*/
|
|
20
20
|
type ConstraintMessage = string | null;
|
|
21
21
|
|
|
22
|
-
export type UniqueConstraint = ConstraintBase<
|
|
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<
|
|
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
|
/**
|