@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.
Files changed (75) hide show
  1. package/lib/api/Api.d.ts +87 -3
  2. package/lib/api/Api.d.ts.map +1 -1
  3. package/lib/api/Api.js +99 -10
  4. package/lib/api/Api.js.map +1 -1
  5. package/lib/api/Client.d.ts +39 -1
  6. package/lib/api/Client.d.ts.map +1 -1
  7. package/lib/api/Client.js +41 -1
  8. package/lib/api/Client.js.map +1 -1
  9. package/lib/api/Transaction.d.ts +42 -0
  10. package/lib/api/Transaction.d.ts.map +1 -1
  11. package/lib/api/Transaction.js +42 -0
  12. package/lib/api/Transaction.js.map +1 -1
  13. package/lib/index.d.ts +9 -3
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +13 -9
  16. package/lib/index.js.map +1 -1
  17. package/lib/schema/classes/EntitySchema.d.ts +71 -0
  18. package/lib/schema/classes/EntitySchema.d.ts.map +1 -0
  19. package/lib/schema/classes/EntitySchema.js +83 -0
  20. package/lib/schema/classes/EntitySchema.js.map +1 -0
  21. package/lib/schema/classes/RelationDefinitionSchema.d.ts +87 -0
  22. package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -0
  23. package/lib/schema/classes/RelationDefinitionSchema.js +128 -0
  24. package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -0
  25. package/lib/schema/classes/Schema.d.ts +54 -0
  26. package/lib/schema/classes/Schema.d.ts.map +1 -0
  27. package/lib/schema/classes/Schema.js +75 -0
  28. package/lib/schema/classes/Schema.js.map +1 -0
  29. package/lib/schema/classes/Utils.d.ts +30 -0
  30. package/lib/schema/classes/Utils.d.ts.map +1 -0
  31. package/lib/schema/classes/Utils.js +25 -0
  32. package/lib/schema/classes/Utils.js.map +1 -0
  33. package/lib/schema/raw/Constraints.d.ts +58 -0
  34. package/lib/schema/raw/Constraints.d.ts.map +1 -0
  35. package/lib/schema/raw/Constraints.js +3 -0
  36. package/lib/schema/raw/Constraints.js.map +1 -0
  37. package/lib/schema/raw/Entities.d.ts +13 -0
  38. package/lib/schema/raw/Entities.d.ts.map +1 -0
  39. package/lib/schema/{SchemaJSON.js → raw/Entities.js} +1 -1
  40. package/lib/schema/raw/Entities.js.map +1 -0
  41. package/lib/schema/raw/RelationDefinitions.d.ts +113 -0
  42. package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -0
  43. package/lib/schema/raw/RelationDefinitions.js +3 -0
  44. package/lib/schema/raw/RelationDefinitions.js.map +1 -0
  45. package/lib/schema/raw/Schema.d.ts +13 -0
  46. package/lib/schema/raw/Schema.d.ts.map +1 -0
  47. package/lib/schema/raw/Schema.js +3 -0
  48. package/lib/schema/raw/Schema.js.map +1 -0
  49. package/lib/schema/raw/Utils.d.ts +22 -0
  50. package/lib/schema/raw/Utils.d.ts.map +1 -0
  51. package/lib/schema/raw/Utils.js +3 -0
  52. package/lib/schema/raw/Utils.js.map +1 -0
  53. package/package.json +1 -1
  54. package/src/api/Api.ts +128 -15
  55. package/src/api/Client.ts +42 -1
  56. package/src/api/Transaction.ts +42 -0
  57. package/src/index.ts +15 -8
  58. package/src/schema/classes/EntitySchema.ts +125 -0
  59. package/src/schema/classes/RelationDefinitionSchema.ts +156 -0
  60. package/src/schema/classes/Schema.ts +122 -0
  61. package/src/schema/classes/Utils.ts +52 -0
  62. package/src/schema/raw/Constraints.ts +77 -0
  63. package/src/schema/raw/Entities.ts +13 -0
  64. package/src/schema/raw/RelationDefinitions.ts +157 -0
  65. package/src/schema/raw/Schema.ts +16 -0
  66. package/src/schema/raw/Utils.ts +33 -0
  67. package/lib/schema/Schema.d.ts +0 -147
  68. package/lib/schema/Schema.d.ts.map +0 -1
  69. package/lib/schema/Schema.js +0 -240
  70. package/lib/schema/Schema.js.map +0 -1
  71. package/lib/schema/SchemaJSON.d.ts +0 -121
  72. package/lib/schema/SchemaJSON.d.ts.map +0 -1
  73. package/lib/schema/SchemaJSON.js.map +0 -1
  74. package/src/schema/Schema.ts +0 -352
  75. package/src/schema/SchemaJSON.ts +0 -195
package/lib/index.js CHANGED
@@ -17,18 +17,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Transaction = exports.Api = exports.Client = exports.RelationDefinitionSchema = exports.EntitySchema = exports.Schema = exports.getLooseSchema = void 0;
21
- var Schema_1 = require("./schema/Schema");
22
- Object.defineProperty(exports, "getLooseSchema", { enumerable: true, get: function () { return Schema_1.getLooseSchema; } });
23
- Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return Schema_1.Schema; } });
24
- Object.defineProperty(exports, "EntitySchema", { enumerable: true, get: function () { return Schema_1.EntitySchema; } });
25
- Object.defineProperty(exports, "RelationDefinitionSchema", { enumerable: true, get: function () { return Schema_1.RelationDefinitionSchema; } });
26
- __exportStar(require("./schema/SchemaJSON"), exports);
20
+ exports.Transaction = exports.Client = void 0;
21
+ // Raw Schema
22
+ __exportStar(require("./schema/raw/Constraints"), exports);
23
+ __exportStar(require("./schema/raw/Entities"), exports);
24
+ __exportStar(require("./schema/raw/RelationDefinitions"), exports);
25
+ __exportStar(require("./schema/raw/Schema"), exports);
26
+ __exportStar(require("./schema/raw/Utils"), exports);
27
+ // Schema Abstraction class
28
+ __exportStar(require("./schema/classes/EntitySchema"), exports);
29
+ __exportStar(require("./schema/classes/RelationDefinitionSchema"), exports);
30
+ __exportStar(require("./schema/classes/Schema"), exports);
31
+ __exportStar(require("./schema/classes/Utils"), exports);
27
32
  __exportStar(require("./Errors"), exports);
33
+ // API
28
34
  var Client_1 = require("./api/Client");
29
35
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return __importDefault(Client_1).default; } });
30
- var Api_1 = require("./api/Api");
31
- Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return __importDefault(Api_1).default; } });
32
36
  var Transaction_1 = require("./api/Transaction");
33
37
  Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return __importDefault(Transaction_1).default; } });
34
38
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AAJvB,wGAAA,cAAc,OAAA;AACd,gGAAA,MAAM,OAAA;AACN,sGAAA,YAAY,OAAA;AACZ,kHAAA,wBAAwB,OAAA;AAE1B,sDAAoC;AACpC,2CAAyB;AACzB,uCAAiD;AAAxC,iHAAA,OAAO,OAAU;AAC1B,iCAA2C;AAAlC,2GAAA,OAAO,OAAO;AACvB,iDAA2D;AAAlD,2HAAA,OAAO,OAAe"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,2DAAyC;AACzC,wDAAsC;AACtC,mEAAiD;AACjD,sDAAoC;AACpC,qDAAmC;AAEnC,2BAA2B;AAC3B,gEAA8C;AAC9C,4EAA0D;AAC1D,0DAAwC;AACxC,yDAAuC;AAEvC,2CAAyB;AAEzB,MAAM;AACN,uCAAiD;AAAxC,iHAAA,OAAO,OAAU;AAC1B,iDAA2D;AAAlD,2HAAA,OAAO,OAAe"}
@@ -0,0 +1,71 @@
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";
6
+ /**
7
+ * Wrapper around raw entity schemas from the Schema.
8
+ * You should never have to create this object yourself.
9
+ * Instead, retrieve these objects from the methods in the `Schema` class.
10
+ */
11
+ export declare class EntitySchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>, ERawSchema extends E[number] = E[number]> {
12
+ private schema;
13
+ private entityRawSchema;
14
+ /**
15
+ * Wrapper around raw entity schemas from the Schema.
16
+ * You should never have to create this object yourself.
17
+ * Instead, retrieve these objects from the methods in the `Schema` class.
18
+ *
19
+ * @param schema The Schema abstraction class used to create this object
20
+ * @param entityRawSchema The raw entity schema
21
+ */
22
+ constructor(schema: Schema<E, R>, entityRawSchema: ERawSchema);
23
+ /**
24
+ * The type of the entity schema. This can also be referred to as the entity schema's name.
25
+ */
26
+ get type(): ERawSchema["type"];
27
+ /**
28
+ * A short description which can be used as documentation for the entity schema.
29
+ */
30
+ get description(): ERawSchema["description"];
31
+ /**
32
+ * True if the current entity schema is a primitive type such as string or int
33
+ */
34
+ get final(): ERawSchema["final"];
35
+ /**
36
+ * Gets the list of relation definitions schemas with this entity as subject.
37
+ * In case a relation definition schema has this entity as both object and subject,
38
+ * there will be dupicates when used along with `objectRelationsDefinitions`.
39
+ */
40
+ get subjectRelationDefinitions(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
41
+ subject: ERawSchema["type"];
42
+ final: false;
43
+ }>>[];
44
+ /**
45
+ * Gets the list of relation definitions schemas with this entity as object.
46
+ * In case a relation definition schema has this entity as both object and subject,
47
+ * there will be dupicates when used along with `subjectRelationDefinitions`.
48
+ */
49
+ get objectRelationsDefinitions(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
50
+ object: ERawSchema["type"];
51
+ final: false;
52
+ }>>[];
53
+ /**
54
+ * Finds relations in the Schema matching the partial relation given.
55
+ *
56
+ * @param matcher Partial relation definition to match against
57
+ * @returns Matched relation schema classes
58
+ */
59
+ matchRelationDefinitions<M extends RelationDefinitionMatcher<E>>(matcher: M): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
60
+ subject: ERawSchema["type"];
61
+ }>>[];
62
+ /**
63
+ * Gets the list of attribute schemas (relation definition schemas with final at false)
64
+ * for this entity schema.
65
+ */
66
+ get attributes(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
67
+ subject: ERawSchema["type"];
68
+ final: true;
69
+ }>>[];
70
+ }
71
+ //# sourceMappingURL=EntitySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntitySchema.d.ts","sourceRoot":"","sources":["../../../src/schema/classes/EntitySchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAE/E;;;;GAIG;AACH,qBAAa,YAAY,CACvB,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EACrD,CAAC,SAAS,gCAAgC,CAAC,CAAC,CAAC,GAAG,gCAAgC,CAAC,CAAC,CAAC,EACnF,UAAU,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAWtC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,eAAe;IAVzB;;;;;;;OAOG;gBAEO,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,eAAe,EAAE,UAAU;IAGrC;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,CAE7B;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,UAAU,CAAC,aAAa,CAAC,CAE3C;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,UAAU,CAAC,OAAO,CAAC,CAE/B;IAED;;;;OAIG;IACH,IAAI,0BAA0B,IAAI,wBAAwB,CACxD,CAAC,EACD,CAAC,EACD,yBAAyB,CACvB,CAAC,EACD,CAAC,EACD;QAAE,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAC9C,CACF,EAAE,CAKF;IAED;;;;OAIG;IACH,IAAI,0BAA0B,IAAI,wBAAwB,CACxD,CAAC,EACD,CAAC,EACD,yBAAyB,CACvB,CAAC,EACD,CAAC,EACD;QAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAC7C,CACF,EAAE,CAKF;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,CAAC,SAAS,yBAAyB,CAAC,CAAC,CAAC,EAC7D,OAAO,EAAE,CAAC,GACT,wBAAwB,CACzB,CAAC,EACD,CAAC,EACD,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE;QAAE,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CACjE,EAAE;IAIH;;;OAGG;IACH,IAAI,UAAU,IAAI,wBAAwB,CACxC,CAAC,EACD,CAAC,EACD,yBAAyB,CACvB,CAAC,EACD,CAAC,EACD;QAAE,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAE,CAC7C,CACF,EAAE,CAKF;CACF"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntitySchema = void 0;
4
+ /**
5
+ * Wrapper around raw entity schemas from the Schema.
6
+ * You should never have to create this object yourself.
7
+ * Instead, retrieve these objects from the methods in the `Schema` class.
8
+ */
9
+ class EntitySchema {
10
+ /**
11
+ * Wrapper around raw entity schemas from the Schema.
12
+ * You should never have to create this object yourself.
13
+ * Instead, retrieve these objects from the methods in the `Schema` class.
14
+ *
15
+ * @param schema The Schema abstraction class used to create this object
16
+ * @param entityRawSchema The raw entity schema
17
+ */
18
+ constructor(schema, entityRawSchema) {
19
+ this.schema = schema;
20
+ this.entityRawSchema = entityRawSchema;
21
+ }
22
+ /**
23
+ * The type of the entity schema. This can also be referred to as the entity schema's name.
24
+ */
25
+ get type() {
26
+ return this.entityRawSchema.type;
27
+ }
28
+ /**
29
+ * A short description which can be used as documentation for the entity schema.
30
+ */
31
+ get description() {
32
+ return this.entityRawSchema.description;
33
+ }
34
+ /**
35
+ * True if the current entity schema is a primitive type such as string or int
36
+ */
37
+ get final() {
38
+ return this.entityRawSchema.final;
39
+ }
40
+ /**
41
+ * Gets the list of relation definitions schemas with this entity as subject.
42
+ * In case a relation definition schema has this entity as both object and subject,
43
+ * there will be dupicates when used along with `objectRelationsDefinitions`.
44
+ */
45
+ get subjectRelationDefinitions() {
46
+ return this.schema.matchRelationDefinitions({
47
+ subject: this.type,
48
+ final: false,
49
+ });
50
+ }
51
+ /**
52
+ * Gets the list of relation definitions schemas with this entity as object.
53
+ * In case a relation definition schema has this entity as both object and subject,
54
+ * there will be dupicates when used along with `subjectRelationDefinitions`.
55
+ */
56
+ get objectRelationsDefinitions() {
57
+ return this.schema.matchRelationDefinitions({
58
+ object: this.type,
59
+ final: false,
60
+ });
61
+ }
62
+ /**
63
+ * Finds relations in the Schema matching the partial relation given.
64
+ *
65
+ * @param matcher Partial relation definition to match against
66
+ * @returns Matched relation schema classes
67
+ */
68
+ matchRelationDefinitions(matcher) {
69
+ return this.schema.matchRelationDefinitions(matcher);
70
+ }
71
+ /**
72
+ * Gets the list of attribute schemas (relation definition schemas with final at false)
73
+ * for this entity schema.
74
+ */
75
+ get attributes() {
76
+ return this.schema.matchRelationDefinitions({
77
+ final: true,
78
+ subject: this.type,
79
+ });
80
+ }
81
+ }
82
+ exports.EntitySchema = EntitySchema;
83
+ //# sourceMappingURL=EntitySchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntitySchema.js","sourceRoot":"","sources":["../../../src/schema/classes/EntitySchema.ts"],"names":[],"mappings":";;;AAMA;;;;GAIG;AACH,MAAa,YAAY;IAKvB;;;;;;;OAOG;IACH,YACU,MAAoB,EACpB,eAA2B;QAD3B,WAAM,GAAN,MAAM,CAAc;QACpB,oBAAe,GAAf,eAAe,CAAY;IAClC,CAAC;IAEJ;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,IAAI,0BAA0B;QAS5B,OAAO,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;YAC1C,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,IAAI,0BAA0B;QAS5B,OAAO,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;YAC1C,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,wBAAwB,CACtB,OAAU;QAMV,OAAO,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;OAGG;IACH,IAAI,UAAU;QASZ,OAAO,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;YAC1C,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,IAAI,CAAC,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;CACF;AAjHD,oCAiHC"}
@@ -0,0 +1,87 @@
1
+ import { EntityRawSchemaArray } from "../raw/Entities";
2
+ import { RelationDefinitionRawSchemaArray, Cardinality } from "../raw/RelationDefinitions";
3
+ import { IsLooseSchema, EntityRawSchemaByType } from "../raw/Utils";
4
+ import { EntitySchema } from "./EntitySchema";
5
+ import { Schema } from "./Schema";
6
+ /**
7
+ * Wrapper around raw relation definition schemas from the Schema.
8
+ * You should never have to create this object yourself.
9
+ * Instead, retrieve these objects from the methods in the `Schema` class.
10
+ */
11
+ export declare class RelationDefinitionSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>, RDef extends R[number] = R[number]> {
12
+ private schema;
13
+ private relDef;
14
+ /**
15
+ * Wrapper around raw relation definition schemas from the Schema.
16
+ * You should never have to create this object yourself.
17
+ * Instead, retrieve these objects from the methods in the `Schema` class.
18
+ *
19
+ * @param schema The Schema abstractin class used to create this object
20
+ * @param relDef The raw relation definition schema
21
+ */
22
+ constructor(schema: Schema<E, R>, relDef: RDef);
23
+ /**
24
+ * The type of the relation definition. This can also be referred to as the relation definition's name.
25
+ */
26
+ get type(): RDef["type"];
27
+ /**
28
+ * A short description which can be used as documentation for the relation definition schema.
29
+ */
30
+ get description(): RDef["description"];
31
+ /**
32
+ * True if the object of the relation definition schema is a primitive type.
33
+ * In this case the relation is called an "attribute".
34
+ */
35
+ get final(): RDef["final"];
36
+ /**
37
+ * The list of options set for this relation definition schema.
38
+ * The returned type will change if this relationd definition schema
39
+ * describes an attribute or a relation.
40
+ */
41
+ get options(): RDef["options"];
42
+ /**
43
+ * The list of constraints set for this relation definition schema.
44
+ * The returned type will change if this relationd definition schema
45
+ * describes an attribute or a relation.
46
+ */
47
+ get constraints(): RDef["constraints"];
48
+ /**
49
+ * The default value for this relation.
50
+ * It can be used when creating new relations if the user did not enter a value (even if required).
51
+ */
52
+ get default(): RDef extends {
53
+ default: infer V;
54
+ } ? V : undefined;
55
+ /**
56
+ * The cardinality of this relation definition schema.
57
+ */
58
+ get cardinality(): RDef["cardinality"];
59
+ /**
60
+ * The cardinality of this relation definition schema's subject.
61
+ */
62
+ get subjectCardinality(): Cardinality;
63
+ /**
64
+ * The cardinality of this relation definition schema's object.
65
+ */
66
+ get objectCardinality(): Cardinality;
67
+ /**
68
+ * Gets the entity associated to this relation definition schema's subject.
69
+ *
70
+ * @throws InconsistentSchemaError if the relation definition schema's subject is not a valid entity
71
+ */
72
+ get subject(): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> : EntitySchema<E, R, EntityRawSchemaByType<E, RDef["subject"]>>;
73
+ /**
74
+ * Gets the entity associated to this relation definition schema's object.
75
+ *
76
+ * @throws InconsistentSchemaError if the relation definition schema's object is not a valid entity
77
+ */
78
+ get object(): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> : EntitySchema<E, R, EntityRawSchemaByType<E, RDef["object"]>>;
79
+ /**
80
+ * Checks if the relation is required when using the subject or object point of view.
81
+ *
82
+ * @param role The point of view to use
83
+ * @returns
84
+ */
85
+ isRequired(role: "subject" | "object"): boolean;
86
+ }
87
+ //# sourceMappingURL=RelationDefinitionSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationDefinitionSchema.d.ts","sourceRoot":"","sources":["../../../src/schema/classes/RelationDefinitionSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,gCAAgC,EAChC,WAAW,EACZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC;;;;GAIG;AACH,qBAAa,wBAAwB,CACnC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EACrD,CAAC,SAAS,gCAAgC,CAAC,CAAC,CAAC,GAAG,gCAAgC,CAAC,CAAC,CAAC,EACnF,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAUtB,OAAO,CAAC,MAAM;IAAgB,OAAO,CAAC,MAAM;IARxD;;;;;;;OAOG;gBACiB,MAAM,EAAE,MAAM,CAAC,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E,SAAS,GAAG,QAAQ;CAStC"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelationDefinitionSchema = void 0;
4
+ const Errors_1 = require("../../Errors");
5
+ const Utils_1 = require("./Utils");
6
+ /**
7
+ * Wrapper around raw relation definition schemas from the Schema.
8
+ * You should never have to create this object yourself.
9
+ * Instead, retrieve these objects from the methods in the `Schema` class.
10
+ */
11
+ class RelationDefinitionSchema {
12
+ /**
13
+ * Wrapper around raw relation definition schemas from the Schema.
14
+ * You should never have to create this object yourself.
15
+ * Instead, retrieve these objects from the methods in the `Schema` class.
16
+ *
17
+ * @param schema The Schema abstractin class used to create this object
18
+ * @param relDef The raw relation definition schema
19
+ */
20
+ constructor(schema, relDef) {
21
+ this.schema = schema;
22
+ this.relDef = relDef;
23
+ }
24
+ /**
25
+ * The type of the relation definition. This can also be referred to as the relation definition's name.
26
+ */
27
+ get type() {
28
+ return this.relDef.type;
29
+ }
30
+ /**
31
+ * A short description which can be used as documentation for the relation definition schema.
32
+ */
33
+ get description() {
34
+ return this.relDef.description;
35
+ }
36
+ /**
37
+ * True if the object of the relation definition schema is a primitive type.
38
+ * In this case the relation is called an "attribute".
39
+ */
40
+ get final() {
41
+ return this.relDef.final;
42
+ }
43
+ /**
44
+ * The list of options set for this relation definition schema.
45
+ * The returned type will change if this relationd definition schema
46
+ * describes an attribute or a relation.
47
+ */
48
+ get options() {
49
+ return this.relDef.options;
50
+ }
51
+ /**
52
+ * The list of constraints set for this relation definition schema.
53
+ * The returned type will change if this relationd definition schema
54
+ * describes an attribute or a relation.
55
+ */
56
+ get constraints() {
57
+ return this.relDef.constraints;
58
+ }
59
+ /**
60
+ * The default value for this relation.
61
+ * It can be used when creating new relations if the user did not enter a value (even if required).
62
+ */
63
+ get default() {
64
+ return ("default" in this.relDef ? this.relDef.default : undefined);
65
+ }
66
+ /**
67
+ * The cardinality of this relation definition schema.
68
+ */
69
+ get cardinality() {
70
+ return this.relDef.cardinality;
71
+ }
72
+ /**
73
+ * The cardinality of this relation definition schema's subject.
74
+ */
75
+ get subjectCardinality() {
76
+ return this.relDef.cardinality[0];
77
+ }
78
+ /**
79
+ * The cardinality of this relation definition schema's object.
80
+ */
81
+ get objectCardinality() {
82
+ return this.relDef.cardinality[1];
83
+ }
84
+ /**
85
+ * Gets the entity associated to this relation definition schema's subject.
86
+ *
87
+ * @throws InconsistentSchemaError if the relation definition schema's subject is not a valid entity
88
+ */
89
+ get subject() {
90
+ const subjectSchema = this.schema.getEntity(this.relDef.subject);
91
+ if (subjectSchema === null) {
92
+ throw new Errors_1.InconsistentSchemaError(`entity type ${this.relDef.subject} used as subject of relation ${this.type} is not declared`);
93
+ }
94
+ // @ts-ignore: Cannot be null as we checked for this above
95
+ return subjectSchema;
96
+ }
97
+ /**
98
+ * Gets the entity associated to this relation definition schema's object.
99
+ *
100
+ * @throws InconsistentSchemaError if the relation definition schema's object is not a valid entity
101
+ */
102
+ get object() {
103
+ const objectSchema = this.schema.getEntity(this.relDef.object);
104
+ if (objectSchema === null) {
105
+ throw new Errors_1.InconsistentSchemaError(`entity type ${this.relDef.object} used as object of relation ${this.type} is not declared`);
106
+ }
107
+ // @ts-ignore: Cannot be null as we checked for this above
108
+ return objectSchema;
109
+ }
110
+ /**
111
+ * Checks if the relation is required when using the subject or object point of view.
112
+ *
113
+ * @param role The point of view to use
114
+ * @returns
115
+ */
116
+ isRequired(role) {
117
+ let cardinality;
118
+ if (role === "subject") {
119
+ cardinality = this.subjectCardinality;
120
+ }
121
+ else {
122
+ cardinality = this.objectCardinality;
123
+ }
124
+ return (0, Utils_1.cardinalityRequired)(cardinality);
125
+ }
126
+ }
127
+ exports.RelationDefinitionSchema = RelationDefinitionSchema;
128
+ //# sourceMappingURL=RelationDefinitionSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationDefinitionSchema.js","sourceRoot":"","sources":["../../../src/schema/classes/RelationDefinitionSchema.ts"],"names":[],"mapp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AAM,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,aAAa,KAAK,IAAI,EAAE;YAC1B,MAAM,IAAI,gCAAuB,CAC/B,eAAe,IAAI,CAAC,MAAM,CAAC,OAAO,gCAAgC,IAAI,CAAC,IAAI,kBAAkB,CAC9F,CAAC;SACH;QACD,0DAA0D;QAC1D,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QAGR,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,YAAY,KAAK,IAAI,EAAE;YACzB,MAAM,IAAI,gCAAuB,CAC/B,eAAe,IAAI,CAAC,MAAM,CAAC,MAAM,+BAA+B,IAAI,CAAC,IAAI,kBAAkB,CAC5F,CAAC;SACH;QACD,0DAA0D;QAC1D,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,IAA0B;QACnC,IAAI,WAAwB,CAAC;QAC7B,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC;SACvC;aAAM;YACL,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC;SACtC;QACD,OAAO,IAAA,2BAAmB,EAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;CACF;AA3ID,4DA2IC"}
@@ -0,0 +1,54 @@
1
+ import { EntityRawSchemaArray } from "../raw/Entities";
2
+ import { RelationDefinitionRawSchemaArray } from "../raw/RelationDefinitions";
3
+ import { RawSchema } from "../raw/Schema";
4
+ import { EntityRawSchemaByType, IsETypeInStrictSchema, IsLooseSchema } from "../raw/Utils";
5
+ import { EntitySchema } from "./EntitySchema";
6
+ import { RelationDefinitionSchema } from "./RelationDefinitionSchema";
7
+ import { RelationDefinitionMatcher, MatchedRelationDefinition } from "./Utils";
8
+ declare const rawSchemaKey: unique symbol;
9
+ /**
10
+ * Wrapper around the raw JSON Schema.
11
+ * It is recommended to use this class instead of the raw JSON Schema
12
+ * as it is more robust to schema changes and provides utility functions.
13
+ */
14
+ export declare class Schema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> {
15
+ [rawSchemaKey]: RawSchema<E, R>;
16
+ /**
17
+ * Wrapper around the raw JSON Schema.
18
+ * It is recommended to use this class instead of the raw JSON Schema
19
+ * as it is more robust to schema changes and provides utility functions.
20
+ *
21
+ * @param rawSchema The raw JSON schema to create the wrapper from.
22
+ */
23
+ constructor(rawSchema: RawSchema<E, R>);
24
+ /**
25
+ * Returns the list of entity schemas in the schema using the EntitySchema abstraction class.
26
+ */
27
+ get entities(): EntitySchema<E, R, E[number]>[];
28
+ /**
29
+ * Returns the list of relation definitions schemas in the schema
30
+ * using the RelationDefinitionSchema abstraction class.
31
+ */
32
+ get relationsDefinitions(): RelationDefinitionSchema<E, R, R[number]>[];
33
+ /**
34
+ * Returns the entity schema for the given entity type if it exists.
35
+ * When using TypeScript, this method can detect if the given type does not exist
36
+ * in the schema.
37
+ *
38
+ * @param entityType The entity type string
39
+ * @returns A new EntitySchema or null if the type does not exist
40
+ */
41
+ getEntity<EType extends string>(entityType: EType): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> | null : IsETypeInStrictSchema<E, EType> extends true ? EntitySchema<E, R, EntityRawSchemaByType<E, EType>> : null;
42
+ /**
43
+ * Finds relations definition schemas in the Schema matching the
44
+ * raw partial relation definition schema given.
45
+ *
46
+ * @param matcher Partial raw relation definition schema to match against
47
+ * @returns Array of matched relation definition schema classes
48
+ */
49
+ matchRelationDefinitions<M extends RelationDefinitionMatcher<E>>(matcher: M): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
50
+ subject: E[number]["type"];
51
+ }>>[];
52
+ }
53
+ export {};
54
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sch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,CAAC,GAAG,IAAI,GACpC,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,IAAI,GAC5C,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GACnD,IAAI;IAiBR;;;;;;OAMG;IACH,wBAAwB,CAAC,CAAC,SAAS,yBAAyB,CAAC,CAAC,CAAC,EAC7D,OAAO,EAAE,CAAC,GACT,wBAAwB,CACzB,CAAC,EACD,CAAC,EACD,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAChE,EAAE;CAmBJ"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Schema = void 0;
4
+ const EntitySchema_1 = require("./EntitySchema");
5
+ const RelationDefinitionSchema_1 = require("./RelationDefinitionSchema");
6
+ const rawSchemaKey = Symbol("Indexer of the rawSchema");
7
+ /**
8
+ * Wrapper around the raw JSON Schema.
9
+ * It is recommended to use this class instead of the raw JSON Schema
10
+ * as it is more robust to schema changes and provides utility functions.
11
+ */
12
+ class Schema {
13
+ /**
14
+ * Wrapper around the raw JSON Schema.
15
+ * It is recommended to use this class instead of the raw JSON Schema
16
+ * as it is more robust to schema changes and provides utility functions.
17
+ *
18
+ * @param rawSchema The raw JSON schema to create the wrapper from.
19
+ */
20
+ constructor(rawSchema) {
21
+ this[rawSchemaKey] = rawSchema;
22
+ }
23
+ /**
24
+ * Returns the list of entity schemas in the schema using the EntitySchema abstraction class.
25
+ */
26
+ get entities() {
27
+ return this[rawSchemaKey].entities.map((eSchema) => new EntitySchema_1.EntitySchema(this, eSchema));
28
+ }
29
+ /**
30
+ * Returns the list of relation definitions schemas in the schema
31
+ * using the RelationDefinitionSchema abstraction class.
32
+ */
33
+ get relationsDefinitions() {
34
+ return this[rawSchemaKey].relations_definitions.map((rdefSchema) => new RelationDefinitionSchema_1.RelationDefinitionSchema(this, rdefSchema));
35
+ }
36
+ /**
37
+ * Returns the entity schema for the given entity type if it exists.
38
+ * When using TypeScript, this method can detect if the given type does not exist
39
+ * in the schema.
40
+ *
41
+ * @param entityType The entity type string
42
+ * @returns A new EntitySchema or null if the type does not exist
43
+ */
44
+ getEntity(entityType) {
45
+ const entityRawSchema = this[rawSchemaKey].entities.filter((eSchema) => eSchema.type === entityType)[0];
46
+ if (!entityRawSchema) {
47
+ // @ts-ignore: Is only null when the given type is not in the schema.
48
+ // Thus the return type will be (EntitySchema | null)
49
+ // but TypeScript does not understand this
50
+ return null;
51
+ }
52
+ // @ts-ignore: see above
53
+ return new EntitySchema_1.EntitySchema(this, entityRawSchema);
54
+ }
55
+ /**
56
+ * Finds relations definition schemas in the Schema matching the
57
+ * raw partial relation definition schema given.
58
+ *
59
+ * @param matcher Partial raw relation definition schema to match against
60
+ * @returns Array of matched relation definition schema classes
61
+ */
62
+ matchRelationDefinitions(matcher) {
63
+ const matchArray = this[rawSchemaKey].relations_definitions.filter((relDef) => {
64
+ for (const key of Object.keys(matcher)) {
65
+ if (matcher[key] !== relDef[key]) {
66
+ return false;
67
+ }
68
+ }
69
+ return true;
70
+ });
71
+ return matchArray.map((m) => new RelationDefinitionSchema_1.RelationDefinitionSchema(this, m));
72
+ }
73
+ }
74
+ exports.Schema = Schema;
75
+ //# sourceMappingURL=Schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../../src/schema/classes/Schema.ts"],"names":[],"mappings":";;;AAWA,iDAA8C;AAC9C,yEAAsE;AAGtE,MAAM,YAAY,GAAkB,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAa,MAAM;IAMjB;;;;;;OAMG;IACH,YAAY,SAA0B;QACpC,IAAI,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IA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B,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;CACF;AAnGD,wBAmGC"}
@@ -0,0 +1,30 @@
1
+ import { EntityRawSchemaArray } from "../raw/Entities";
2
+ import { Cardinality, RelationDefinitionRawSchema, RelationDefinitionRawSchemaArray } from "../raw/RelationDefinitions";
3
+ import { Schema } from "./Schema";
4
+ /**
5
+ * Returns the given schema using loose typing.
6
+ * Can be useful when working with generic schemas
7
+ *
8
+ * @param schema The schema to create a loose type for
9
+ * @returns A loosely typed schema
10
+ */
11
+ export declare const getLooseSchema: <E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>>(schema: Schema<E, R>) => Schema<EntityRawSchemaArray, RelationDefinitionRawSchemaArray<EntityRawSchemaArray>>;
12
+ /**
13
+ * Checks if the given cardinality requires at least one entity to be present
14
+ *
15
+ * @param cardinality The cardinality to check
16
+ * @returns True if the cardinality is 1 or +
17
+ */
18
+ export declare function cardinalityRequired(cardinality: Cardinality): boolean;
19
+ /**
20
+ * Partial raw relation definition schema type.
21
+ */
22
+ export declare type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<RelationDefinitionRawSchema<E>>;
23
+ /**
24
+ * Type representing a raw relation definition matched from a partial raw relation definition schema.
25
+ * If it finds a relation definition matching the partial one given, it will return its type.
26
+ * If it cannot find any relation definition matching, it will return the `never` type
27
+ * and TypeScript will give compile errors.
28
+ */
29
+ export declare type MatchedRelationDefinition<E extends EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<EntityRawSchemaArray>, M extends RelationDefinitionMatcher<E>> = R[number] extends infer RDef ? (RDef extends M ? RDef : never) : never;
30
+ //# sourceMappingURL=Utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/classes/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,gCAAgC,EACjC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,4PAO1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAErE;AAED;;GAEG;AACH,oBAAY,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,IAAI,OAAO,CAC7E,2BAA2B,CAAC,CAAC,CAAC,CAC/B,CAAC;AAEF;;;;;GAKG;AACH,oBAAY,yBAAyB,CACnC,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,gCAAgC,CAAC,oBAAoB,CAAC,EAChE,CAAC,SAAS,yBAAyB,CAAC,CAAC,CAAC,IACpC,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cardinalityRequired = exports.getLooseSchema = void 0;
4
+ /**
5
+ * Returns the given schema using loose typing.
6
+ * Can be useful when working with generic schemas
7
+ *
8
+ * @param schema The schema to create a loose type for
9
+ * @returns A loosely typed schema
10
+ */
11
+ const getLooseSchema = (schema) => {
12
+ return schema;
13
+ };
14
+ exports.getLooseSchema = getLooseSchema;
15
+ /**
16
+ * Checks if the given cardinality requires at least one entity to be present
17
+ *
18
+ * @param cardinality The cardinality to check
19
+ * @returns True if the cardinality is 1 or +
20
+ */
21
+ function cardinalityRequired(cardinality) {
22
+ return cardinality === "1" || cardinality === "+";
23
+ }
24
+ exports.cardinalityRequired = cardinalityRequired;
25
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/schema/classes/Utils.ts"],"names":[],"mappings":";;;AAQA;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAI5B,MAAoB,EACpB,EAAE;IACF,OAAO,MAA2B,CAAC;AACrC,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB;AAEF;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,WAAwB;IAC1D,OAAO,WAAW,KAAK,GAAG,IAAI,WAAW,KAAK,GAAG,CAAC;AACpD,CAAC;AAFD,kDAEC"}