@cubicweb/client 1.2.2 → 1.5.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/lib/api/Api.d.ts +87 -3
- package/lib/api/Api.d.ts.map +1 -1
- package/lib/api/Api.js +99 -10
- package/lib/api/Api.js.map +1 -1
- package/lib/api/Client.d.ts +39 -1
- package/lib/api/Client.d.ts.map +1 -1
- package/lib/api/Client.js +41 -1
- package/lib/api/Client.js.map +1 -1
- package/lib/api/Transaction.d.ts +42 -0
- package/lib/api/Transaction.d.ts.map +1 -1
- package/lib/api/Transaction.js +42 -0
- package/lib/api/Transaction.js.map +1 -1
- package/lib/index.d.ts +9 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -9
- package/lib/index.js.map +1 -1
- package/lib/schema/classes/EntitySchema.d.ts +71 -0
- package/lib/schema/classes/EntitySchema.d.ts.map +1 -0
- package/lib/schema/classes/EntitySchema.js +83 -0
- package/lib/schema/classes/EntitySchema.js.map +1 -0
- package/lib/schema/classes/RelationDefinitionSchema.d.ts +87 -0
- package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -0
- package/lib/schema/classes/RelationDefinitionSchema.js +128 -0
- package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -0
- package/lib/schema/classes/Schema.d.ts +54 -0
- package/lib/schema/classes/Schema.d.ts.map +1 -0
- package/lib/schema/classes/Schema.js +75 -0
- package/lib/schema/classes/Schema.js.map +1 -0
- package/lib/schema/classes/Utils.d.ts +30 -0
- package/lib/schema/classes/Utils.d.ts.map +1 -0
- package/lib/schema/classes/Utils.js +25 -0
- package/lib/schema/classes/Utils.js.map +1 -0
- package/lib/schema/raw/Constraints.d.ts +58 -0
- package/lib/schema/raw/Constraints.d.ts.map +1 -0
- package/lib/schema/raw/Constraints.js +3 -0
- package/lib/schema/raw/Constraints.js.map +1 -0
- package/lib/schema/raw/Entities.d.ts +13 -0
- package/lib/schema/raw/Entities.d.ts.map +1 -0
- package/lib/schema/{SchemaJSON.js → raw/Entities.js} +1 -1
- package/lib/schema/raw/Entities.js.map +1 -0
- package/lib/schema/raw/RelationDefinitions.d.ts +113 -0
- package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -0
- package/lib/schema/raw/RelationDefinitions.js +3 -0
- package/lib/schema/raw/RelationDefinitions.js.map +1 -0
- package/lib/schema/raw/Schema.d.ts +13 -0
- package/lib/schema/raw/Schema.d.ts.map +1 -0
- package/lib/schema/raw/Schema.js +3 -0
- package/lib/schema/raw/Schema.js.map +1 -0
- package/lib/schema/raw/Utils.d.ts +22 -0
- package/lib/schema/raw/Utils.d.ts.map +1 -0
- package/lib/schema/raw/Utils.js +3 -0
- package/lib/schema/raw/Utils.js.map +1 -0
- package/package.json +1 -1
- package/src/api/Api.ts +128 -15
- package/src/api/Client.ts +42 -1
- package/src/api/Transaction.ts +42 -0
- package/src/index.ts +15 -8
- package/src/schema/classes/EntitySchema.ts +125 -0
- package/src/schema/classes/RelationDefinitionSchema.ts +156 -0
- package/src/schema/classes/Schema.ts +122 -0
- package/src/schema/classes/Utils.ts +52 -0
- package/src/schema/raw/Constraints.ts +77 -0
- package/src/schema/raw/Entities.ts +13 -0
- package/src/schema/raw/RelationDefinitions.ts +157 -0
- package/src/schema/raw/Schema.ts +16 -0
- package/src/schema/raw/Utils.ts +33 -0
- package/lib/schema/Schema.d.ts +0 -147
- package/lib/schema/Schema.d.ts.map +0 -1
- package/lib/schema/Schema.js +0 -240
- 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.map +0 -1
- package/src/schema/Schema.ts +0 -352
- package/src/schema/SchemaJSON.ts +0 -195
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base type used to describe a constraint.
|
|
3
|
+
*/
|
|
4
|
+
declare type ConstraintBase<T extends string, V extends Record<string, unknown> | null> = {
|
|
5
|
+
type: T;
|
|
6
|
+
value: V;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* All the possible operators inside a constraint.
|
|
10
|
+
*/
|
|
11
|
+
export declare type ConstraintOperator = ">" | ">=" | "<" | "<=";
|
|
12
|
+
/**
|
|
13
|
+
* THe type of a constraint message when one is present.
|
|
14
|
+
*/
|
|
15
|
+
declare type ConstraintMessage = string | null;
|
|
16
|
+
export declare type UniqueConstraint = ConstraintBase<"UniqueConstraint", null>;
|
|
17
|
+
export declare type SizeConstraint = ConstraintBase<"SizeConstraint", {
|
|
18
|
+
min: number | null;
|
|
19
|
+
max: number | null;
|
|
20
|
+
msg: ConstraintMessage;
|
|
21
|
+
}>;
|
|
22
|
+
export declare type RegexpConstraint = ConstraintBase<"RegexpConstraint", {
|
|
23
|
+
regexp: string;
|
|
24
|
+
flags: number;
|
|
25
|
+
msg: ConstraintMessage;
|
|
26
|
+
}>;
|
|
27
|
+
export declare type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
|
|
28
|
+
boundary: number | null;
|
|
29
|
+
op: ConstraintOperator;
|
|
30
|
+
msg: ConstraintMessage;
|
|
31
|
+
}>;
|
|
32
|
+
export declare type IntervalBoundConstraint = ConstraintBase<"IntervalBoundConstraint", {
|
|
33
|
+
minvalue: number | null;
|
|
34
|
+
maxvalue: number | null;
|
|
35
|
+
msg: ConstraintMessage;
|
|
36
|
+
}>;
|
|
37
|
+
export declare type StaticVocabularyConstraint = ConstraintBase<"StaticVocabularyConstraint", {
|
|
38
|
+
values: string[];
|
|
39
|
+
msg: ConstraintMessage;
|
|
40
|
+
}>;
|
|
41
|
+
export declare type FormatConstraint = ConstraintBase<"FormatConstraint", {
|
|
42
|
+
values: ["text/rest", "text/markdown", "text/html", "text/plain"];
|
|
43
|
+
msg: ConstraintMessage;
|
|
44
|
+
}>;
|
|
45
|
+
export declare type RQLVocabularyConstraint = ConstraintBase<"RQLVocabularyConstraint", {
|
|
46
|
+
expression: string;
|
|
47
|
+
mainvars: string[];
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Type representing all possible constraints for attributes.
|
|
51
|
+
*/
|
|
52
|
+
export declare type AttributeConstraint = Readonly<UniqueConstraint | SizeConstraint | RegexpConstraint | BoundaryConstraint | IntervalBoundConstraint | StaticVocabularyConstraint | FormatConstraint>;
|
|
53
|
+
/**
|
|
54
|
+
* Type representing all possible constraints for relations.
|
|
55
|
+
*/
|
|
56
|
+
export declare type RelationConstraint = Readonly<RQLVocabularyConstraint>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=Constraints.d.ts.map
|
|
@@ -0,0 +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;IACF,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,oBAAY,kBAAkB,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;AAEzD;;GAEG;AACH,aAAK,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAAC;AAEvC,oBAAY,gBAAgB,GAAG,cAAc,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;AAExE,oBAAY,cAAc,GAAG,cAAc,CACzC,gBAAgB,EAChB;IAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,iBAAiB,CAAA;CAAE,CACnE,CAAC;AAEF,oBAAY,gBAAgB,GAAG,cAAc,CAC3C,kBAAkB,EAClB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC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|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type representing an entity schema.
|
|
3
|
+
*/
|
|
4
|
+
export declare type EntityRawSchema = {
|
|
5
|
+
type: string;
|
|
6
|
+
final: boolean;
|
|
7
|
+
description: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Type representing a list of entity schemas.
|
|
11
|
+
*/
|
|
12
|
+
export declare type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
|
|
13
|
+
//# sourceMappingURL=Entities.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Entities.js","sourceRoot":"","sources":["../../../src/schema/raw/Entities.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { AttributeConstraint, RelationConstraint } from "./Constraints";
|
|
2
|
+
import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
|
|
3
|
+
/**
|
|
4
|
+
* Type representing all the possible cardinalities in CubicWeb.
|
|
5
|
+
*/
|
|
6
|
+
export declare type Cardinality = "*" | "1" | "?" | "+";
|
|
7
|
+
/**
|
|
8
|
+
* Type representing a cardinality pair as used in relation definitions.
|
|
9
|
+
*/
|
|
10
|
+
export declare type CardinalityPair = `${Cardinality}${Cardinality}`;
|
|
11
|
+
/**
|
|
12
|
+
* Type used as a base to build final relation definitions with primitive types (Int, String, ...).
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
declare type BuildObjBase<T extends string> = {
|
|
17
|
+
object: T;
|
|
18
|
+
final: true;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
};
|
|
21
|
+
interface StringBuildObj extends BuildObjBase<"String"> {
|
|
22
|
+
default: string | null;
|
|
23
|
+
}
|
|
24
|
+
interface PasswordBuildObj extends BuildObjBase<"Password"> {
|
|
25
|
+
default: string | null;
|
|
26
|
+
}
|
|
27
|
+
interface BytesBuildObj extends BuildObjBase<"Bytes"> {
|
|
28
|
+
default: string | null;
|
|
29
|
+
}
|
|
30
|
+
interface IntBuildObj extends BuildObjBase<"Int"> {
|
|
31
|
+
default: number | null;
|
|
32
|
+
}
|
|
33
|
+
interface BigIntBuildObj extends BuildObjBase<"BigInt"> {
|
|
34
|
+
default: number | null;
|
|
35
|
+
}
|
|
36
|
+
interface FloatBuildObj extends BuildObjBase<"Float"> {
|
|
37
|
+
default: number | null;
|
|
38
|
+
}
|
|
39
|
+
interface BooleanBuildObj extends BuildObjBase<"Boolean"> {
|
|
40
|
+
default: boolean | null;
|
|
41
|
+
}
|
|
42
|
+
interface DecimalBuildObj extends BuildObjBase<"Decimal"> {
|
|
43
|
+
default: number | null;
|
|
44
|
+
}
|
|
45
|
+
interface DateBuildObj extends BuildObjBase<"Date"> {
|
|
46
|
+
default: unknown;
|
|
47
|
+
}
|
|
48
|
+
interface TimeBuildObj extends BuildObjBase<"Time"> {
|
|
49
|
+
default: unknown;
|
|
50
|
+
}
|
|
51
|
+
interface DatetimeBuildObj extends BuildObjBase<"Datetime"> {
|
|
52
|
+
default: Date | "NOW" | "TODAY" | null;
|
|
53
|
+
}
|
|
54
|
+
interface TZTimeBuildObj extends BuildObjBase<"TZTime"> {
|
|
55
|
+
default: unknown;
|
|
56
|
+
}
|
|
57
|
+
interface TZDatetimeBuildObj extends BuildObjBase<"TZDatetime"> {
|
|
58
|
+
default: unknown;
|
|
59
|
+
}
|
|
60
|
+
interface IntervalBuildObj extends BuildObjBase<"Interval"> {
|
|
61
|
+
default: unknown;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Type allowing to link the type of an object to the type of their default values in a
|
|
65
|
+
* relation definition. It only works for final relations using primitive types.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export declare type BuildObj = Readonly<StringBuildObj | PasswordBuildObj | BytesBuildObj | IntBuildObj | BigIntBuildObj | FloatBuildObj | BooleanBuildObj | DecimalBuildObj | DateBuildObj | TimeBuildObj | DatetimeBuildObj | TZTimeBuildObj | TZDatetimeBuildObj | IntervalBuildObj>;
|
|
70
|
+
/**
|
|
71
|
+
* Type representing the possible options for an attribute.
|
|
72
|
+
*/
|
|
73
|
+
export declare type AttributeOptions = {
|
|
74
|
+
indexed?: boolean;
|
|
75
|
+
fulltextindexed?: boolean;
|
|
76
|
+
internationalizable?: boolean;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Type representing the possible options for a relation definition.
|
|
80
|
+
*/
|
|
81
|
+
export declare type RelationOptions = {
|
|
82
|
+
symmetric?: boolean;
|
|
83
|
+
inlined?: boolean;
|
|
84
|
+
fulltext_container?: "subject" | "object";
|
|
85
|
+
composite?: "subject" | "object";
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Type representing a relation definition schema.
|
|
89
|
+
* It can represent both attributes and relations depending on the value of Final.
|
|
90
|
+
*
|
|
91
|
+
* It can infer default values type depending on the object type if the relation is final.
|
|
92
|
+
*/
|
|
93
|
+
export declare type RelationDefinitionRawSchema<ESchemas extends EntityRawSchemaArray, Final extends boolean = boolean> = Readonly<{
|
|
94
|
+
type: string;
|
|
95
|
+
description: string;
|
|
96
|
+
cardinality: CardinalityPair;
|
|
97
|
+
subject: ESchemas[number]["type"];
|
|
98
|
+
} & (Final extends true ? BuildObj & {
|
|
99
|
+
final: true;
|
|
100
|
+
constraints: AttributeConstraint[];
|
|
101
|
+
options: AttributeOptions;
|
|
102
|
+
} : {
|
|
103
|
+
object: EntityRawSchema["type"];
|
|
104
|
+
final: false;
|
|
105
|
+
constraints: RelationConstraint[];
|
|
106
|
+
options: RelationOptions;
|
|
107
|
+
})>;
|
|
108
|
+
/**
|
|
109
|
+
* Type representing a list of relation definitions.
|
|
110
|
+
*/
|
|
111
|
+
export declare type RelationDefinitionRawSchemaArray<ESchemas extends EntityRawSchemaArray> = ReadonlyArray<RelationDefinitionRawSchema<ESchemas, boolean>>;
|
|
112
|
+
export {};
|
|
113
|
+
//# sourceMappingURL=RelationDefinitions.d.ts.map
|
|
@@ -0,0 +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;;;;GAIG;AACH,aAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI;IACpC,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,UAAU,cAAe,SAAQ,YAAY,CAAC,QAAQ,CAAC;IACrD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,gBAAiB,SAAQ,YAAY,CAAC,UAAU,CAAC;IACzD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,aAAc,SAAQ,YAAY,CAAC,OAAO,CAAC;IACnD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,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"","sources":["../../../src/schema/raw/RelationDefinitions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EntityRawSchemaArray } from "./Entities";
|
|
2
|
+
import { RelationDefinitionRawSchemaArray } from "./RelationDefinitions";
|
|
3
|
+
/**
|
|
4
|
+
* The full raw JSON schema type as returned by the API.
|
|
5
|
+
* You can export this schema from your CubicWeb instance using the command:
|
|
6
|
+
*
|
|
7
|
+
* `cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>`
|
|
8
|
+
*/
|
|
9
|
+
export declare type RawSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> = {
|
|
10
|
+
entities: E;
|
|
11
|
+
relations_definitions: R;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../../src/schema/raw/Schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EntityRawSchemaArray } from "./Entities";
|
|
2
|
+
/**
|
|
3
|
+
* Type used to check if a schema is loosely typed.
|
|
4
|
+
* Use this to create conditional types.
|
|
5
|
+
*
|
|
6
|
+
* In the given EntityRawSchemaArray, if the entities type is a string, the schema is loosely typed.
|
|
7
|
+
* If the schema is strongly typed, the entities type would be a word (which is stricter than string).
|
|
8
|
+
*/
|
|
9
|
+
export declare type IsLooseSchema<E extends EntityRawSchemaArray> = string extends E[number]["type"] ? true : false;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the given entity type is present in the EntityRawSchemaArray.
|
|
12
|
+
* Use this to create conditional types.
|
|
13
|
+
*/
|
|
14
|
+
export declare type IsETypeInStrictSchema<E extends EntityRawSchemaArray, EType extends string> = EType extends E[number]["type"] ? true : false;
|
|
15
|
+
/**
|
|
16
|
+
* Type representing the entity's raw schema matching this type.
|
|
17
|
+
* This type only works for EntityRawSchemaArray with literals as "type" property.
|
|
18
|
+
*/
|
|
19
|
+
export declare type EntityRawSchemaByType<E extends EntityRawSchemaArray, T extends string> = E[number] extends infer ESchema ? ESchema extends {
|
|
20
|
+
type: T;
|
|
21
|
+
} ? ESchema : never : never;
|
|
22
|
+
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/schema/raw/Utils.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/api/Api.ts
CHANGED
|
@@ -1,58 +1,130 @@
|
|
|
1
|
-
import { RawSchema } from "../schema/
|
|
1
|
+
import { RawSchema } from "../schema/raw/Schema";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Type representing an RQL request and its associated parameters.
|
|
5
|
+
*/
|
|
3
6
|
export type RQLQuery = [string, RQLParams];
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Type representing RQL parameters to send along a request.
|
|
10
|
+
*/
|
|
5
11
|
export interface RQLParams {
|
|
6
12
|
[key: string]: string | number;
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Type representing a row returned in a result set.
|
|
17
|
+
*/
|
|
9
18
|
export type RqlRow = Array<string | number | boolean | null>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Type representing a RQL request result.
|
|
22
|
+
*/
|
|
10
23
|
export type ResultSet = Array<RqlRow>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Type representing the body of an error sent by CubicWeb's API.
|
|
27
|
+
*/
|
|
11
28
|
type ApiError = {
|
|
12
29
|
title: string;
|
|
13
30
|
message: string;
|
|
14
31
|
data?: Record<string, unknown>;
|
|
15
32
|
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Type representing the error data sent to clients when retrieving an API error.
|
|
36
|
+
*/
|
|
16
37
|
export type ApiErrorResponse = {
|
|
17
38
|
status: number;
|
|
18
39
|
} & ApiError;
|
|
19
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Class used to handle requests to the CubicWeb API.
|
|
43
|
+
*
|
|
44
|
+
* You should never have to create this object yourself.
|
|
45
|
+
* Instead, retrieve this object from the methods in the `Client` class.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
20
49
|
export default class Api {
|
|
21
|
-
private
|
|
22
|
-
private
|
|
50
|
+
private _apiUrl: string;
|
|
51
|
+
private _version = "v1";
|
|
52
|
+
private _rqlApiUrl: string;
|
|
53
|
+
private _schemaApiUrl: string;
|
|
54
|
+
private _loginApiUrl: string;
|
|
55
|
+
private _transactionApiUrl = {
|
|
23
56
|
begin: "",
|
|
24
57
|
execute: "",
|
|
25
58
|
commit: "",
|
|
26
59
|
rollback: "",
|
|
27
60
|
};
|
|
28
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Class used to handle requests to the CubicWeb API.
|
|
64
|
+
*
|
|
65
|
+
* You should never have to create this object yourself.
|
|
66
|
+
* Instead, retrieve this object from the methods in the `Client` class.
|
|
67
|
+
*
|
|
68
|
+
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
69
|
+
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
70
|
+
* use https://example.com/api as `apiUrl`.
|
|
71
|
+
*/
|
|
29
72
|
constructor(apiUrl: string) {
|
|
30
|
-
this.
|
|
31
|
-
|
|
73
|
+
this._apiUrl = apiUrl;
|
|
74
|
+
this._rqlApiUrl = this.getApiRoute("rql");
|
|
75
|
+
this._schemaApiUrl = this.getApiRoute("schema");
|
|
76
|
+
this._loginApiUrl = this.getApiRoute("login");
|
|
77
|
+
Object.keys(this._transactionApiUrl).forEach(
|
|
32
78
|
(k) =>
|
|
33
|
-
(this.
|
|
34
|
-
|
|
35
|
-
] = `${this.apiUrl}/transaction/${k}`)
|
|
79
|
+
(this._transactionApiUrl[k as keyof typeof this._transactionApiUrl] =
|
|
80
|
+
this.getApiRoute(`transaction/${k}`))
|
|
36
81
|
);
|
|
37
82
|
}
|
|
38
83
|
|
|
84
|
+
get apiUrl() {
|
|
85
|
+
return this._apiUrl;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private getApiRoute(route: string) {
|
|
89
|
+
return `${this._apiUrl}/${this._version}/${route}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Executes the given query and waits for the response.
|
|
94
|
+
*
|
|
95
|
+
* @param query The RQL query to send
|
|
96
|
+
* @param params The additional parameters for the request
|
|
97
|
+
* @returns A promise with the request's result set
|
|
98
|
+
*/
|
|
39
99
|
async execute(query: string, params: RQLParams): Promise<ResultSet> {
|
|
40
|
-
return nonNullFetchApi<ResultSet>(
|
|
100
|
+
return nonNullFetchApi<ResultSet>(this._rqlApiUrl, {
|
|
41
101
|
method: "POST",
|
|
42
102
|
body: JSON.stringify({ query, params }),
|
|
43
103
|
credentials: "include", // FIXME is it secure?
|
|
44
104
|
});
|
|
45
105
|
}
|
|
46
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves the CubicWeb instance's JSON schema.
|
|
109
|
+
*
|
|
110
|
+
* @returns The CubicWeb instance's JSON schema.
|
|
111
|
+
*/
|
|
47
112
|
async schema(): Promise<RawSchema> {
|
|
48
|
-
return nonNullFetchApi<RawSchema>(
|
|
113
|
+
return nonNullFetchApi<RawSchema>(this._schemaApiUrl, {
|
|
49
114
|
method: "GET",
|
|
50
115
|
credentials: "include",
|
|
51
116
|
});
|
|
52
117
|
}
|
|
53
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
121
|
+
*
|
|
122
|
+
* @param login The user login
|
|
123
|
+
* @param password THe user password
|
|
124
|
+
* @returns A promise returning true if the login was successful, false otherwise
|
|
125
|
+
*/
|
|
54
126
|
async login(login: string, password: string): Promise<boolean> {
|
|
55
|
-
return fetchApi<null>(
|
|
127
|
+
return fetchApi<null>(this._loginApiUrl, {
|
|
56
128
|
method: "POST",
|
|
57
129
|
body: JSON.stringify({
|
|
58
130
|
login,
|
|
@@ -64,35 +136,58 @@ export default class Api {
|
|
|
64
136
|
.catch(() => false);
|
|
65
137
|
}
|
|
66
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Starts a new transaction.
|
|
141
|
+
*
|
|
142
|
+
* @returns A promise with the transaction uuid
|
|
143
|
+
*/
|
|
67
144
|
async transactionBegin(): Promise<string> {
|
|
68
|
-
return nonNullFetchApi<string>(this.
|
|
145
|
+
return nonNullFetchApi<string>(this._transactionApiUrl.begin, {
|
|
69
146
|
method: "POST",
|
|
70
147
|
credentials: "include",
|
|
71
148
|
});
|
|
72
149
|
}
|
|
73
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Executes a RQL request as part of a transaction identified by the given uuid.
|
|
153
|
+
*
|
|
154
|
+
* @param uuid The transaction's uuid
|
|
155
|
+
* @param query The RQL query to send
|
|
156
|
+
* @param params The additional parameters for the request
|
|
157
|
+
* @returns A promise with the request's result set
|
|
158
|
+
*/
|
|
74
159
|
async transactionExecute(
|
|
75
160
|
uuid: string,
|
|
76
161
|
query: string,
|
|
77
162
|
params: RQLParams
|
|
78
163
|
): Promise<ResultSet | null> {
|
|
79
|
-
return fetchApi<ResultSet>(this.
|
|
164
|
+
return fetchApi<ResultSet>(this._transactionApiUrl.execute, {
|
|
80
165
|
method: "POST",
|
|
81
166
|
body: JSON.stringify({ uuid, query, params }),
|
|
82
167
|
credentials: "include",
|
|
83
168
|
});
|
|
84
169
|
}
|
|
85
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Commits the transaction identified by the given uuid.
|
|
173
|
+
*
|
|
174
|
+
* @param uuid The transaction's uuid
|
|
175
|
+
*/
|
|
86
176
|
async transactionCommit(uuid: string): Promise<null> {
|
|
87
|
-
return fetchApi<null>(this.
|
|
177
|
+
return fetchApi<null>(this._transactionApiUrl.commit, {
|
|
88
178
|
method: "POST",
|
|
89
179
|
body: JSON.stringify({ uuid }),
|
|
90
180
|
credentials: "include",
|
|
91
181
|
});
|
|
92
182
|
}
|
|
93
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Rollbacks the transaction identified by the given uuid.
|
|
186
|
+
*
|
|
187
|
+
* @param uuid The transaction's uuid
|
|
188
|
+
*/
|
|
94
189
|
async transactionRollback(uuid: string): Promise<null> {
|
|
95
|
-
return fetchApi<null>(this.
|
|
190
|
+
return fetchApi<null>(this._transactionApiUrl.rollback, {
|
|
96
191
|
method: "POST",
|
|
97
192
|
body: JSON.stringify({ uuid }),
|
|
98
193
|
credentials: "include",
|
|
@@ -100,6 +195,15 @@ export default class Api {
|
|
|
100
195
|
}
|
|
101
196
|
}
|
|
102
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Behaves the same as `fetchAPI` but forbids null responses.
|
|
200
|
+
* If this function detects a null response from the API,
|
|
201
|
+
* the promise will be rejected with a 500 error code.
|
|
202
|
+
*
|
|
203
|
+
* @param input The API route to use
|
|
204
|
+
* @param init Additional request parameters
|
|
205
|
+
* @returns A promise with the non-null fetched result
|
|
206
|
+
*/
|
|
103
207
|
const nonNullFetchApi = <R = unknown>(
|
|
104
208
|
input: RequestInfo,
|
|
105
209
|
init?: RequestInit
|
|
@@ -123,6 +227,15 @@ const nonNullFetchApi = <R = unknown>(
|
|
|
123
227
|
);
|
|
124
228
|
};
|
|
125
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Sends a request to the given API route with the `Content-Type` header set and waits for a response.
|
|
232
|
+
* The returned promise will be rejected if the API returns HTTP error codes.
|
|
233
|
+
* The rejected promise will contain an `ApiErrorResponse` object.
|
|
234
|
+
*
|
|
235
|
+
* @param input The API route to use
|
|
236
|
+
* @param init Additional request parameters
|
|
237
|
+
* @returns A promise with the fetched result
|
|
238
|
+
*/
|
|
126
239
|
const fetchApi = <R = unknown>(input: RequestInfo, init?: RequestInit) => {
|
|
127
240
|
let headers = init?.headers;
|
|
128
241
|
if (init?.method && init.method !== "GET" && init.method !== "DELETE") {
|
package/src/api/Client.ts
CHANGED
|
@@ -1,27 +1,68 @@
|
|
|
1
|
-
import { Schema } from "../schema/Schema";
|
|
1
|
+
import { Schema } from "../schema/classes/Schema";
|
|
2
2
|
import Api, { RQLParams } from "./Api";
|
|
3
3
|
import Transaction from "./Transaction";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Class used to communicate with a CubicWeb instance's API.
|
|
7
|
+
*/
|
|
5
8
|
export default class Client {
|
|
6
9
|
private api: Api;
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Class used to communicate with a CubicWeb instance's API.
|
|
13
|
+
*
|
|
14
|
+
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
15
|
+
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
16
|
+
* use https://example.com/api as `apiUrl`.
|
|
17
|
+
*/
|
|
8
18
|
constructor(apiUrl: string) {
|
|
9
19
|
this.api = new Api(apiUrl);
|
|
10
20
|
}
|
|
11
21
|
|
|
22
|
+
get apiUrl() {
|
|
23
|
+
return this.api.apiUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Executes the given query and waits for the response.
|
|
28
|
+
*
|
|
29
|
+
* @param query The RQL query to send
|
|
30
|
+
* @param params The additional parameters for the request
|
|
31
|
+
* @returns A promise with the request's result set
|
|
32
|
+
*/
|
|
12
33
|
async execute(query: string, params: RQLParams = {}) {
|
|
13
34
|
return await this.api.execute(query, params);
|
|
14
35
|
}
|
|
15
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the CubicWeb instance's JSON schema.
|
|
39
|
+
*
|
|
40
|
+
* @returns The CubicWeb instance's JSON schema.
|
|
41
|
+
*/
|
|
16
42
|
async schema() {
|
|
17
43
|
const schema = await this.api.schema();
|
|
18
44
|
return new Schema(schema);
|
|
19
45
|
}
|
|
20
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
49
|
+
*
|
|
50
|
+
* @param login The user login
|
|
51
|
+
* @param password THe user password
|
|
52
|
+
* @returns A promise returning true if the login was successful, false otherwise
|
|
53
|
+
*/
|
|
21
54
|
async login(login: string, password: string) {
|
|
22
55
|
return await this.api.login(login, password);
|
|
23
56
|
}
|
|
24
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
60
|
+
* Use this callback to execute RQL requests as part of the transaction.
|
|
61
|
+
* Once the callback's end is reached, the transaction is automatically committed.
|
|
62
|
+
*
|
|
63
|
+
* @param callback Function to execute transaction requests in.
|
|
64
|
+
* @returns The promise returned by the callback
|
|
65
|
+
*/
|
|
25
66
|
async transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T> {
|
|
26
67
|
const transaction = new Transaction(this.api);
|
|
27
68
|
await transaction.begin();
|