@cubicweb/client 1.0.1 → 1.0.3
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/package.json +3 -2
- package/lib/Errors.d.ts +0 -10
- package/lib/Errors.d.ts.map +0 -1
- package/lib/Errors.js +0 -25
- package/lib/Errors.js.map +0 -1
- package/lib/api/Api.d.ts +0 -27
- package/lib/api/Api.d.ts.map +0 -1
- package/lib/api/Api.js +0 -94
- package/lib/api/Api.js.map +0 -1
- package/lib/api/Client.d.ts +0 -11
- package/lib/api/Client.d.ts.map +0 -1
- package/lib/api/Client.js +0 -46
- package/lib/api/Client.js.map +0 -1
- package/lib/api/Transaction.d.ts +0 -15
- package/lib/api/Transaction.d.ts.map +0 -1
- package/lib/api/Transaction.js +0 -60
- package/lib/api/Transaction.js.map +0 -1
- package/lib/index.d.ts +0 -8
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -34
- package/lib/index.js.map +0 -1
- package/lib/schema/Schema.d.ts +0 -169
- package/lib/schema/Schema.d.ts.map +0 -1
- package/lib/schema/Schema.js +0 -269
- package/lib/schema/Schema.js.map +0 -1
- package/lib/schema/SchemaJSON.d.ts +0 -121
- package/lib/schema/SchemaJSON.d.ts.map +0 -1
- package/lib/schema/SchemaJSON.js +0 -3
- package/lib/schema/SchemaJSON.js.map +0 -1
- package/src/__tests__/Schema.specs.ts +0 -347
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { Schema } from "../schema/Schema";
|
|
2
|
-
|
|
3
|
-
describe("Schema", () => {
|
|
4
|
-
describe("From loosely typed schema", () => {
|
|
5
|
-
const looselyTypedSchema = new Schema({
|
|
6
|
-
entities: [
|
|
7
|
-
{
|
|
8
|
-
type: "Person",
|
|
9
|
-
description: "A Person",
|
|
10
|
-
final: false,
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
type: "Task",
|
|
14
|
-
description: "Something that must be done",
|
|
15
|
-
final: false,
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
relations_definitions: [
|
|
19
|
-
{
|
|
20
|
-
type: "has_task",
|
|
21
|
-
description: "Something that the person must do",
|
|
22
|
-
final: false,
|
|
23
|
-
cardinality: "*+",
|
|
24
|
-
subject: "Person",
|
|
25
|
-
object: "Task",
|
|
26
|
-
constraints: null,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
});
|
|
30
|
-
describe("entities", () => {
|
|
31
|
-
it("should be a list of 2 entity schemas", () => {
|
|
32
|
-
expect(looselyTypedSchema.entities).toHaveLength(2);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe("relation_definitions", () => {
|
|
36
|
-
it("should be a list of 1 relation schemas", () => {
|
|
37
|
-
expect(looselyTypedSchema.relationsDefinitions).toHaveLength(1);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe("get", () => {
|
|
41
|
-
it("Get an existing entity", () => {
|
|
42
|
-
expect(looselyTypedSchema.getEntity("Person")?.type).toBe("Person");
|
|
43
|
-
});
|
|
44
|
-
it("Get a non-existing entity", () => {
|
|
45
|
-
expect(looselyTypedSchema.getEntity("Thing")).toBeNull();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("matchRelationDefinitions", () => {
|
|
49
|
-
it("Get a relation by its type", () => {
|
|
50
|
-
const hasTaskMatch = looselyTypedSchema.matchRelationDefinitions({
|
|
51
|
-
type: "has_task",
|
|
52
|
-
});
|
|
53
|
-
expect(hasTaskMatch).toHaveLength(1);
|
|
54
|
-
expect(hasTaskMatch[0].type).toBe("has_task");
|
|
55
|
-
});
|
|
56
|
-
it("Get a relation by its subject", () => {
|
|
57
|
-
const hasTaskMatch = looselyTypedSchema.matchRelationDefinitions({
|
|
58
|
-
subject: "Person",
|
|
59
|
-
});
|
|
60
|
-
expect(hasTaskMatch).toHaveLength(1);
|
|
61
|
-
expect(hasTaskMatch[0].type).toBe("has_task");
|
|
62
|
-
});
|
|
63
|
-
it("Get a non-existing relation", () => {
|
|
64
|
-
const hasTaskMatch = looselyTypedSchema.matchRelationDefinitions({
|
|
65
|
-
subject: "Thing",
|
|
66
|
-
});
|
|
67
|
-
expect(hasTaskMatch).toHaveLength(0);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("EntitySchema", () => {
|
|
72
|
-
describe("subjectRelationDefinitions", () => {
|
|
73
|
-
it("should be a relation with Person as subject", () => {
|
|
74
|
-
expect(
|
|
75
|
-
looselyTypedSchema.getEntity("Person")
|
|
76
|
-
?.subjectRelationDefinitions[0].type
|
|
77
|
-
).toBe("has_task");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe("getSubjectRelationDefinition", () => {
|
|
81
|
-
it("should be the has_task relation", () => {
|
|
82
|
-
expect(
|
|
83
|
-
looselyTypedSchema
|
|
84
|
-
.getEntity("Person")
|
|
85
|
-
?.getSubjectRelationDefinition("has_task").type
|
|
86
|
-
).toBe("has_task");
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe("getObjectRelationDefinition", () => {
|
|
90
|
-
it("should be the has_task relation", () => {
|
|
91
|
-
expect(
|
|
92
|
-
looselyTypedSchema
|
|
93
|
-
.getEntity("Task")
|
|
94
|
-
?.getObjectRelationDefinition("has_task").type
|
|
95
|
-
).toBe("has_task");
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
describe("attributes", () => {
|
|
99
|
-
it("should be an empty array", () => {
|
|
100
|
-
expect(
|
|
101
|
-
looselyTypedSchema.getEntity("Person")?.attributes
|
|
102
|
-
).toHaveLength(0);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
describe("attributes", () => {
|
|
106
|
-
it("should be an empty array", () => {
|
|
107
|
-
expect(
|
|
108
|
-
looselyTypedSchema.getEntity("Person")?.attributes
|
|
109
|
-
).toHaveLength(0);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe("isRelationRequired", () => {
|
|
113
|
-
it("Should not be required", () => {
|
|
114
|
-
expect(
|
|
115
|
-
looselyTypedSchema
|
|
116
|
-
.getEntity("Person")
|
|
117
|
-
?.isRelationRequired("has_task", "subject")
|
|
118
|
-
).toBeFalsy();
|
|
119
|
-
});
|
|
120
|
-
it("Should throw an error", () => {
|
|
121
|
-
expect(() =>
|
|
122
|
-
looselyTypedSchema
|
|
123
|
-
.getEntity("Person")
|
|
124
|
-
?.isRelationRequired("has_task", "object")
|
|
125
|
-
).toThrow();
|
|
126
|
-
});
|
|
127
|
-
it("Should not be required", () => {
|
|
128
|
-
expect(
|
|
129
|
-
looselyTypedSchema
|
|
130
|
-
.getEntity("Task")
|
|
131
|
-
?.isRelationRequired("has_task", "object")
|
|
132
|
-
).toBeTruthy();
|
|
133
|
-
});
|
|
134
|
-
it("Should throw an error", () => {
|
|
135
|
-
expect(() =>
|
|
136
|
-
looselyTypedSchema
|
|
137
|
-
.getEntity("Task")
|
|
138
|
-
?.isRelationRequired("has_task", "subject")
|
|
139
|
-
).toThrow();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("RelationDefinitionSchema", () => {
|
|
145
|
-
describe("subject", () => {
|
|
146
|
-
it("should be a Person entity", () => {
|
|
147
|
-
expect(
|
|
148
|
-
looselyTypedSchema.matchRelationDefinitions({ type: "has_task" })[0]
|
|
149
|
-
.subject.type
|
|
150
|
-
).toBe("Person");
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe("object", () => {
|
|
154
|
-
it("should be a Task entity", () => {
|
|
155
|
-
expect(
|
|
156
|
-
looselyTypedSchema.matchRelationDefinitions({ type: "has_task" })[0]
|
|
157
|
-
.object.type
|
|
158
|
-
).toBe("Task");
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe("From strongly typed schema", () => {
|
|
165
|
-
interface PersonWithATask {
|
|
166
|
-
entities: [
|
|
167
|
-
{
|
|
168
|
-
type: "Person";
|
|
169
|
-
description: "A Person";
|
|
170
|
-
final: false;
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
type: "Task";
|
|
174
|
-
description: "Something that must be done";
|
|
175
|
-
final: false;
|
|
176
|
-
}
|
|
177
|
-
];
|
|
178
|
-
relations_definitions: [
|
|
179
|
-
{
|
|
180
|
-
type: "has_task";
|
|
181
|
-
description: "Something that the person must do";
|
|
182
|
-
final: false;
|
|
183
|
-
cardinality: "*+";
|
|
184
|
-
subject: "Person";
|
|
185
|
-
object: "Task";
|
|
186
|
-
constraints: null;
|
|
187
|
-
}
|
|
188
|
-
];
|
|
189
|
-
}
|
|
190
|
-
const stronglyTypedSchema = new Schema<
|
|
191
|
-
PersonWithATask["entities"],
|
|
192
|
-
PersonWithATask["relations_definitions"]
|
|
193
|
-
>({
|
|
194
|
-
entities: [
|
|
195
|
-
{
|
|
196
|
-
type: "Person",
|
|
197
|
-
description: "A Person",
|
|
198
|
-
final: false,
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
type: "Task",
|
|
202
|
-
description: "Something that must be done",
|
|
203
|
-
final: false,
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
relations_definitions: [
|
|
207
|
-
{
|
|
208
|
-
type: "has_task",
|
|
209
|
-
description: "Something that the person must do",
|
|
210
|
-
final: false,
|
|
211
|
-
cardinality: "*+",
|
|
212
|
-
subject: "Person",
|
|
213
|
-
object: "Task",
|
|
214
|
-
constraints: null,
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
});
|
|
218
|
-
describe("entities", () => {
|
|
219
|
-
it("should be a list of 2 entity schemas", () => {
|
|
220
|
-
expect(stronglyTypedSchema.entities).toHaveLength(2);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
describe("relation_definitions", () => {
|
|
224
|
-
it("should be a list of 1 relation schemas", () => {
|
|
225
|
-
expect(stronglyTypedSchema.relationsDefinitions).toHaveLength(1);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe("get", () => {
|
|
229
|
-
it("Get an existing entity", () => {
|
|
230
|
-
expect(stronglyTypedSchema.getEntity("Person")?.type).toBe("Person");
|
|
231
|
-
});
|
|
232
|
-
it("Get a non-existing entity", () => {
|
|
233
|
-
expect(stronglyTypedSchema.getEntity("Thing")).toBeNull();
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
describe("matchRelationDefinitions", () => {
|
|
237
|
-
it("Get a relation by its type", () => {
|
|
238
|
-
const hasTaskMatch = stronglyTypedSchema.matchRelationDefinitions({
|
|
239
|
-
type: "has_task",
|
|
240
|
-
});
|
|
241
|
-
expect(hasTaskMatch).toHaveLength(1);
|
|
242
|
-
expect(hasTaskMatch[0].type).toBe("has_task");
|
|
243
|
-
});
|
|
244
|
-
it("Get a relation by its subject", () => {
|
|
245
|
-
const hasTaskMatch = stronglyTypedSchema.matchRelationDefinitions({
|
|
246
|
-
subject: "Person",
|
|
247
|
-
});
|
|
248
|
-
expect(hasTaskMatch).toHaveLength(1);
|
|
249
|
-
expect(hasTaskMatch[0].type).toBe("has_task");
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe("EntitySchema", () => {
|
|
254
|
-
describe("subjectRelationDefinitions", () => {
|
|
255
|
-
it("should be a relation with Person as subject", () => {
|
|
256
|
-
expect(
|
|
257
|
-
stronglyTypedSchema.getEntity("Person")
|
|
258
|
-
?.subjectRelationDefinitions[0].type
|
|
259
|
-
).toBe("has_task");
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
describe("getSubjectRelationDefinition", () => {
|
|
263
|
-
it("should be the has_task relation", () => {
|
|
264
|
-
expect(
|
|
265
|
-
stronglyTypedSchema
|
|
266
|
-
.getEntity("Person")
|
|
267
|
-
?.getSubjectRelationDefinition("has_task").type
|
|
268
|
-
).toBe("has_task");
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
describe("getObjectRelationDefinition", () => {
|
|
272
|
-
it("should be the has_task relation", () => {
|
|
273
|
-
expect(
|
|
274
|
-
stronglyTypedSchema
|
|
275
|
-
.getEntity("Task")
|
|
276
|
-
?.getObjectRelationDefinition("has_task").type
|
|
277
|
-
).toBe("has_task");
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
describe("attributes", () => {
|
|
281
|
-
it("should be an empty array", () => {
|
|
282
|
-
expect(
|
|
283
|
-
stronglyTypedSchema.getEntity("Person")?.attributes
|
|
284
|
-
).toHaveLength(0);
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
describe("attributes", () => {
|
|
288
|
-
it("should be an empty array", () => {
|
|
289
|
-
expect(
|
|
290
|
-
stronglyTypedSchema.getEntity("Person")?.attributes
|
|
291
|
-
).toHaveLength(0);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
describe("isRelationRequired", () => {
|
|
295
|
-
it("Should not be required", () => {
|
|
296
|
-
expect(
|
|
297
|
-
stronglyTypedSchema
|
|
298
|
-
.getEntity("Person")
|
|
299
|
-
?.isRelationRequired("has_task", "subject")
|
|
300
|
-
).toBeFalsy();
|
|
301
|
-
});
|
|
302
|
-
it("Should throw an error", () => {
|
|
303
|
-
expect(() =>
|
|
304
|
-
stronglyTypedSchema
|
|
305
|
-
.getEntity("Person")
|
|
306
|
-
?.isRelationRequired("has_task", "object")
|
|
307
|
-
).toThrow();
|
|
308
|
-
});
|
|
309
|
-
it("Should not be required", () => {
|
|
310
|
-
expect(
|
|
311
|
-
stronglyTypedSchema
|
|
312
|
-
.getEntity("Task")
|
|
313
|
-
?.isRelationRequired("has_task", "object")
|
|
314
|
-
).toBeTruthy();
|
|
315
|
-
});
|
|
316
|
-
it("Should throw an error", () => {
|
|
317
|
-
expect(() =>
|
|
318
|
-
stronglyTypedSchema
|
|
319
|
-
.getEntity("Task")
|
|
320
|
-
?.isRelationRequired("has_task", "subject")
|
|
321
|
-
).toThrow();
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
describe("RelationDefinitionSchema", () => {
|
|
327
|
-
describe("subject", () => {
|
|
328
|
-
it("should be a Person entity", () => {
|
|
329
|
-
expect(
|
|
330
|
-
stronglyTypedSchema.matchRelationDefinitions({
|
|
331
|
-
type: "has_task",
|
|
332
|
-
})[0].subject.type
|
|
333
|
-
).toBe("Person");
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
describe("object", () => {
|
|
337
|
-
it("should be a Task entity", () => {
|
|
338
|
-
expect(
|
|
339
|
-
stronglyTypedSchema.matchRelationDefinitions({
|
|
340
|
-
type: "has_task",
|
|
341
|
-
})[0].object.type
|
|
342
|
-
).toBe("Task");
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
});
|