@coasys/ad4m 0.8.0-fix → 0.8.1

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 (161) hide show
  1. package/README.md +229 -229
  2. package/jest.config.js +5 -5
  3. package/jsdoc.json +27 -27
  4. package/lib/index.cjs +4522 -4571
  5. package/lib/index.js +4522 -4571
  6. package/lib/shims/type-graphql.d.ts +32 -32
  7. package/lib/shims/type-graphql.js +70 -70
  8. package/lib/src/Ad4mClient.d.ts +26 -26
  9. package/lib/src/Ad4mClient.js +66 -66
  10. package/lib/src/Address.d.ts +1 -1
  11. package/lib/src/Address.js +1 -1
  12. package/lib/src/DID.d.ts +1 -1
  13. package/lib/src/DID.js +1 -1
  14. package/lib/src/Exception.d.ts +6 -6
  15. package/lib/src/Exception.js +7 -7
  16. package/lib/src/Literal.d.ts +7 -7
  17. package/lib/src/Literal.js +76 -76
  18. package/lib/src/PubSub.d.ts +14 -14
  19. package/lib/src/PubSub.js +14 -14
  20. package/lib/src/SmartLiteral.d.ts +12 -12
  21. package/lib/src/SmartLiteral.js +74 -74
  22. package/lib/src/agent/Agent.d.ts +104 -104
  23. package/lib/src/agent/Agent.js +337 -337
  24. package/lib/src/agent/AgentClient.d.ts +57 -57
  25. package/lib/src/agent/AgentClient.js +431 -431
  26. package/lib/src/agent/AgentResolver.d.ts +30 -30
  27. package/lib/src/agent/AgentResolver.js +325 -325
  28. package/lib/src/agent/AgentStatus.d.ts +8 -8
  29. package/lib/src/agent/AgentStatus.js +61 -61
  30. package/lib/src/buildSchema.d.ts +1 -1
  31. package/lib/src/buildSchema.js +36 -36
  32. package/lib/src/expression/Expression.d.ts +28 -28
  33. package/lib/src/expression/Expression.js +143 -143
  34. package/lib/src/expression/ExpressionClient.d.ts +13 -13
  35. package/lib/src/expression/ExpressionClient.js +102 -102
  36. package/lib/src/expression/ExpressionRef.d.ts +9 -9
  37. package/lib/src/expression/ExpressionRef.js +67 -67
  38. package/lib/src/expression/ExpressionResolver.d.ts +10 -10
  39. package/lib/src/expression/ExpressionResolver.js +106 -106
  40. package/lib/src/index.d.ts +30 -30
  41. package/lib/src/index.js +30 -30
  42. package/lib/src/jestSetup.d.ts +1 -1
  43. package/lib/src/jestSetup.js +1 -1
  44. package/lib/src/language/Icon.d.ts +4 -4
  45. package/lib/src/language/Icon.js +24 -24
  46. package/lib/src/language/Language.d.ts +195 -195
  47. package/lib/src/language/Language.js +79 -79
  48. package/lib/src/language/LanguageClient.d.ts +17 -17
  49. package/lib/src/language/LanguageClient.js +137 -137
  50. package/lib/src/language/LanguageContext.d.ts +37 -37
  51. package/lib/src/language/LanguageContext.js +2 -2
  52. package/lib/src/language/LanguageHandle.d.ts +9 -9
  53. package/lib/src/language/LanguageHandle.js +41 -41
  54. package/lib/src/language/LanguageMeta.d.ts +35 -35
  55. package/lib/src/language/LanguageMeta.js +89 -89
  56. package/lib/src/language/LanguageRef.d.ts +6 -6
  57. package/lib/src/language/LanguageRef.js +30 -30
  58. package/lib/src/language/LanguageResolver.d.ts +19 -19
  59. package/lib/src/language/LanguageResolver.js +143 -143
  60. package/lib/src/links/Links.d.ts +39 -39
  61. package/lib/src/links/Links.js +148 -148
  62. package/lib/src/links/Links.test.d.ts +1 -1
  63. package/lib/src/links/Links.test.js +33 -33
  64. package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -10
  65. package/lib/src/neighbourhood/Neighbourhood.js +38 -38
  66. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -25
  67. package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -256
  68. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -19
  69. package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -54
  70. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -24
  71. package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -180
  72. package/lib/src/perspectives/LinkQuery.d.ts +11 -11
  73. package/lib/src/perspectives/LinkQuery.js +80 -80
  74. package/lib/src/perspectives/Perspective.d.ts +38 -38
  75. package/lib/src/perspectives/Perspective.js +144 -144
  76. package/lib/src/perspectives/Perspective.test.d.ts +1 -1
  77. package/lib/src/perspectives/Perspective.test.js +20 -20
  78. package/lib/src/perspectives/PerspectiveClient.d.ts +55 -54
  79. package/lib/src/perspectives/PerspectiveClient.js +418 -410
  80. package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -9
  81. package/lib/src/perspectives/PerspectiveDiff.js +33 -33
  82. package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -16
  83. package/lib/src/perspectives/PerspectiveHandle.js +59 -59
  84. package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -178
  85. package/lib/src/perspectives/PerspectiveProxy.js +501 -540
  86. package/lib/src/perspectives/PerspectiveResolver.d.ts +38 -37
  87. package/lib/src/perspectives/PerspectiveResolver.js +376 -362
  88. package/lib/src/runtime/RuntimeClient.d.ts +33 -33
  89. package/lib/src/runtime/RuntimeClient.js +263 -263
  90. package/lib/src/runtime/RuntimeResolver.d.ts +47 -47
  91. package/lib/src/runtime/RuntimeResolver.js +328 -328
  92. package/lib/src/schema.gql +1 -0
  93. package/lib/src/subject/SDNADecorators.d.ts +45 -45
  94. package/lib/src/subject/SDNADecorators.js +250 -250
  95. package/lib/src/subject/Subject.d.ts +7 -7
  96. package/lib/src/subject/Subject.js +160 -160
  97. package/lib/src/subject/SubjectEntity.d.ts +31 -31
  98. package/lib/src/subject/SubjectEntity.js +250 -250
  99. package/lib/src/subject/util.d.ts +12 -12
  100. package/lib/src/subject/util.js +73 -73
  101. package/lib/src/typeDefs.d.ts +1 -1
  102. package/lib/src/typeDefs.js +1 -0
  103. package/lib/src/unwrapApolloResult.d.ts +2 -2
  104. package/lib/src/unwrapApolloResult.js +14 -12
  105. package/lib/src/utils.d.ts +2 -2
  106. package/lib/src/utils.js +21 -21
  107. package/package.json +61 -61
  108. package/rollup.config.js +26 -26
  109. package/shims/type-graphql.ts +75 -75
  110. package/src/Ad4mClient.test.ts +1089 -1084
  111. package/src/Ad4mClient.ts +62 -62
  112. package/src/Address.ts +1 -1
  113. package/src/Exception.ts +6 -6
  114. package/src/Literal.test.ts +30 -30
  115. package/src/Literal.ts +80 -80
  116. package/src/PubSub.ts +13 -13
  117. package/src/SmartLiteral.ts +74 -74
  118. package/src/agent/Agent.ts +293 -293
  119. package/src/agent/AgentClient.ts +531 -531
  120. package/src/agent/AgentResolver.ts +263 -263
  121. package/src/agent/AgentStatus.ts +43 -43
  122. package/src/buildSchema.ts +41 -41
  123. package/src/expression/Expression.ts +99 -99
  124. package/src/expression/ExpressionClient.ts +98 -98
  125. package/src/expression/ExpressionRef.ts +62 -62
  126. package/src/expression/ExpressionResolver.ts +63 -63
  127. package/src/index.ts +30 -30
  128. package/src/language/Icon.ts +10 -10
  129. package/src/language/Language.ts +266 -266
  130. package/src/language/LanguageClient.ts +159 -159
  131. package/src/language/LanguageContext.ts +37 -37
  132. package/src/language/LanguageHandle.ts +23 -23
  133. package/src/language/LanguageMeta.ts +69 -69
  134. package/src/language/LanguageRef.ts +18 -18
  135. package/src/language/LanguageResolver.ts +98 -98
  136. package/src/links/Links.test.ts +39 -39
  137. package/src/links/Links.ts +107 -107
  138. package/src/neighbourhood/Neighbourhood.ts +22 -22
  139. package/src/neighbourhood/NeighbourhoodClient.ts +275 -275
  140. package/src/neighbourhood/NeighbourhoodProxy.ts +58 -58
  141. package/src/neighbourhood/NeighbourhoodResolver.ts +99 -99
  142. package/src/perspectives/LinkQuery.ts +65 -65
  143. package/src/perspectives/Perspective.test.ts +22 -22
  144. package/src/perspectives/Perspective.ts +118 -118
  145. package/src/perspectives/PerspectiveClient.ts +452 -443
  146. package/src/perspectives/PerspectiveDiff.ts +15 -15
  147. package/src/perspectives/PerspectiveHandle.ts +39 -39
  148. package/src/perspectives/PerspectiveProxy.ts +576 -610
  149. package/src/perspectives/PerspectiveResolver.ts +224 -219
  150. package/src/runtime/RuntimeClient.ts +282 -282
  151. package/src/runtime/RuntimeResolver.ts +192 -192
  152. package/src/subject/SDNADecorators.ts +333 -333
  153. package/src/subject/Subject.ts +152 -152
  154. package/src/subject/SubjectEntity.ts +291 -291
  155. package/src/subject/util.ts +84 -84
  156. package/src/typeDefs.ts +5 -5
  157. package/src/unwrapApolloResult.ts +15 -13
  158. package/src/utils.ts +25 -25
  159. package/tsconfig-browser.json +82 -82
  160. package/tsconfig.json +80 -80
  161. package/yarn-error.log +0 -22814
@@ -1,80 +1,80 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Field, InputType, ObjectType } from "type-graphql";
11
- let LinkQuery = class LinkQuery {
12
- constructor(obj) {
13
- if (obj) {
14
- // @ts-ignore
15
- this.source = obj.source;
16
- // @ts-ignore
17
- this.predicate = obj.predicate;
18
- // @ts-ignore
19
- this.target = obj.target;
20
- // @ts-ignore
21
- if (obj.fromDate) {
22
- // @ts-ignore
23
- this.fromDate = obj.fromDate;
24
- }
25
- ;
26
- // @ts-ignore
27
- if (obj.untilDate) {
28
- // @ts-ignore
29
- this.untilDate = obj.untilDate;
30
- }
31
- // @ts-ignore
32
- if (obj.limit) {
33
- // @ts-ignore
34
- this.limit = obj.limit;
35
- }
36
- }
37
- }
38
- isMatch(l) {
39
- if (this.source)
40
- if (this.source !== l.source)
41
- return false;
42
- if (this.predicate)
43
- if (this.predicate !== l.predicate)
44
- return false;
45
- if (this.target)
46
- if (this.target !== l.target)
47
- return false;
48
- return true;
49
- }
50
- };
51
- __decorate([
52
- Field({ nullable: true }),
53
- __metadata("design:type", String)
54
- ], LinkQuery.prototype, "source", void 0);
55
- __decorate([
56
- Field({ nullable: true }),
57
- __metadata("design:type", String)
58
- ], LinkQuery.prototype, "target", void 0);
59
- __decorate([
60
- Field({ nullable: true }),
61
- __metadata("design:type", String)
62
- ], LinkQuery.prototype, "predicate", void 0);
63
- __decorate([
64
- Field({ nullable: true }),
65
- __metadata("design:type", Date)
66
- ], LinkQuery.prototype, "fromDate", void 0);
67
- __decorate([
68
- Field({ nullable: true }),
69
- __metadata("design:type", Date)
70
- ], LinkQuery.prototype, "untilDate", void 0);
71
- __decorate([
72
- Field({ nullable: true }),
73
- __metadata("design:type", Number)
74
- ], LinkQuery.prototype, "limit", void 0);
75
- LinkQuery = __decorate([
76
- ObjectType(),
77
- InputType(),
78
- __metadata("design:paramtypes", [Object])
79
- ], LinkQuery);
80
- export { LinkQuery };
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Field, InputType, ObjectType } from "type-graphql";
11
+ let LinkQuery = class LinkQuery {
12
+ constructor(obj) {
13
+ if (obj) {
14
+ // @ts-ignore
15
+ this.source = obj.source;
16
+ // @ts-ignore
17
+ this.predicate = obj.predicate;
18
+ // @ts-ignore
19
+ this.target = obj.target;
20
+ // @ts-ignore
21
+ if (obj.fromDate) {
22
+ // @ts-ignore
23
+ this.fromDate = obj.fromDate;
24
+ }
25
+ ;
26
+ // @ts-ignore
27
+ if (obj.untilDate) {
28
+ // @ts-ignore
29
+ this.untilDate = obj.untilDate;
30
+ }
31
+ // @ts-ignore
32
+ if (obj.limit) {
33
+ // @ts-ignore
34
+ this.limit = obj.limit;
35
+ }
36
+ }
37
+ }
38
+ isMatch(l) {
39
+ if (this.source)
40
+ if (this.source !== l.source)
41
+ return false;
42
+ if (this.predicate)
43
+ if (this.predicate !== l.predicate)
44
+ return false;
45
+ if (this.target)
46
+ if (this.target !== l.target)
47
+ return false;
48
+ return true;
49
+ }
50
+ };
51
+ __decorate([
52
+ Field({ nullable: true }),
53
+ __metadata("design:type", String)
54
+ ], LinkQuery.prototype, "source", void 0);
55
+ __decorate([
56
+ Field({ nullable: true }),
57
+ __metadata("design:type", String)
58
+ ], LinkQuery.prototype, "target", void 0);
59
+ __decorate([
60
+ Field({ nullable: true }),
61
+ __metadata("design:type", String)
62
+ ], LinkQuery.prototype, "predicate", void 0);
63
+ __decorate([
64
+ Field({ nullable: true }),
65
+ __metadata("design:type", Date)
66
+ ], LinkQuery.prototype, "fromDate", void 0);
67
+ __decorate([
68
+ Field({ nullable: true }),
69
+ __metadata("design:type", Date)
70
+ ], LinkQuery.prototype, "untilDate", void 0);
71
+ __decorate([
72
+ Field({ nullable: true }),
73
+ __metadata("design:type", Number)
74
+ ], LinkQuery.prototype, "limit", void 0);
75
+ LinkQuery = __decorate([
76
+ ObjectType(),
77
+ InputType(),
78
+ __metadata("design:paramtypes", [Object])
79
+ ], LinkQuery);
80
+ export { LinkQuery };
@@ -1,38 +1,38 @@
1
- import { Link, LinkExpression, LinkExpressionInput, LinkInput } from "../links/Links";
2
- import { LinkQuery } from "./LinkQuery";
3
- /** A Perspective represents subjective meaning, encoded through
4
- * associations between expressions, a.k.a. Links, that is a graph
5
- * over the objective Expressions of any subset of Languages.
6
- *
7
- * This type represents the clean onotological concept of a Perspective.
8
- * An instance of this class can be regarded as an immutable snapshot of
9
- * a mutable perspective.
10
- *
11
- * The types PerspectiveProxy and PerspectiveHandle are used when dealing
12
- * with an instantiated mutable perspective as is done through most of
13
- * the GraphQL mutations.
14
- */
15
- export declare class Perspective {
16
- /** The content of the perspective, a list/graph of links */
17
- links: LinkExpression[];
18
- constructor(links?: LinkExpression[]);
19
- /** Convenience function for filtering links just like with PerspectiveProxy */
20
- get(query: LinkQuery): LinkExpression[];
21
- /** Convenience function to get the target of the first link that matches the given query
22
- * This makes sense when the query is expected to return only one link
23
- * and the target of that link is what you are looking for.
24
- */
25
- getSingleTarget(query: LinkQuery): string | void;
26
- }
27
- export declare class PerspectiveInput {
28
- links: LinkExpressionInput[];
29
- }
30
- export declare class PerspectiveUnsignedInput {
31
- links: LinkInput[];
32
- constructor(links?: LinkInput[]);
33
- static fromLink(link: Link): PerspectiveUnsignedInput;
34
- }
35
- declare const PerspectiveExpression_base: any;
36
- export declare class PerspectiveExpression extends PerspectiveExpression_base {
37
- }
38
- export {};
1
+ import { Link, LinkExpression, LinkExpressionInput, LinkInput } from "../links/Links";
2
+ import { LinkQuery } from "./LinkQuery";
3
+ /** A Perspective represents subjective meaning, encoded through
4
+ * associations between expressions, a.k.a. Links, that is a graph
5
+ * over the objective Expressions of any subset of Languages.
6
+ *
7
+ * This type represents the clean onotological concept of a Perspective.
8
+ * An instance of this class can be regarded as an immutable snapshot of
9
+ * a mutable perspective.
10
+ *
11
+ * The types PerspectiveProxy and PerspectiveHandle are used when dealing
12
+ * with an instantiated mutable perspective as is done through most of
13
+ * the GraphQL mutations.
14
+ */
15
+ export declare class Perspective {
16
+ /** The content of the perspective, a list/graph of links */
17
+ links: LinkExpression[];
18
+ constructor(links?: LinkExpression[]);
19
+ /** Convenience function for filtering links just like with PerspectiveProxy */
20
+ get(query: LinkQuery): LinkExpression[];
21
+ /** Convenience function to get the target of the first link that matches the given query
22
+ * This makes sense when the query is expected to return only one link
23
+ * and the target of that link is what you are looking for.
24
+ */
25
+ getSingleTarget(query: LinkQuery): string | void;
26
+ }
27
+ export declare class PerspectiveInput {
28
+ links: LinkExpressionInput[];
29
+ }
30
+ export declare class PerspectiveUnsignedInput {
31
+ links: LinkInput[];
32
+ constructor(links?: LinkInput[]);
33
+ static fromLink(link: Link): PerspectiveUnsignedInput;
34
+ }
35
+ declare const PerspectiveExpression_base: any;
36
+ export declare class PerspectiveExpression extends PerspectiveExpression_base {
37
+ }
38
+ export {};
@@ -1,144 +1,144 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var PerspectiveUnsignedInput_1;
11
- import { Field, ObjectType, InputType } from "type-graphql";
12
- import { ExpressionGeneric } from "../expression/Expression";
13
- import { LinkExpression, LinkExpressionInput, LinkInput } from "../links/Links";
14
- /** A Perspective represents subjective meaning, encoded through
15
- * associations between expressions, a.k.a. Links, that is a graph
16
- * over the objective Expressions of any subset of Languages.
17
- *
18
- * This type represents the clean onotological concept of a Perspective.
19
- * An instance of this class can be regarded as an immutable snapshot of
20
- * a mutable perspective.
21
- *
22
- * The types PerspectiveProxy and PerspectiveHandle are used when dealing
23
- * with an instantiated mutable perspective as is done through most of
24
- * the GraphQL mutations.
25
- */
26
- let Perspective = class Perspective {
27
- constructor(links) {
28
- if (links) {
29
- this.links = links;
30
- }
31
- else {
32
- this.links = [];
33
- }
34
- }
35
- /** Convenience function for filtering links just like with PerspectiveProxy */
36
- get(query) {
37
- if (!query || !query.source && !query.predicate && !query.target) {
38
- return this.links;
39
- }
40
- if (query.source) {
41
- let result = JSON.parse(JSON.stringify(this.links));
42
- // @ts-ignore
43
- if (query.target)
44
- result = result.filter(l => l.data.target === query.target);
45
- // @ts-ignore
46
- if (query.predicate)
47
- result = result.filter(l => l.data.predicate === query.predicate);
48
- //@ts-ignore
49
- if (query.fromDate)
50
- result = result.filter(l => new Date(l.timestamp) >= query.fromDate);
51
- //@ts-ignore
52
- if (query.untilDate)
53
- result = result.filter(l => new Date(l.timestamp) <= query.untilDate);
54
- // console.debug("result", result)
55
- if (query.limit)
56
- result = result.slice(0, query.limit);
57
- return result;
58
- }
59
- // console.debug("getLinks 3")
60
- if (query.target) {
61
- //@ts-ignore
62
- let result = JSON.parse(JSON.stringify(this.links));
63
- // @ts-ignore
64
- if (query.predicate)
65
- result = result.filter(l => l.data.predicate === query.predicate);
66
- //@ts-ignore
67
- if (query.fromDate)
68
- result = result.filter(l => new Date(l.timestamp) >= query.fromDate);
69
- //@ts-ignore
70
- if (query.untilDate)
71
- result = result.filter(l => new Date(l.timestamp) <= query.untilDate);
72
- if (query.limit)
73
- result = result.slice(0, query.limit);
74
- return result;
75
- }
76
- // console.debug("getLinks 4")
77
- //@ts-ignore
78
- let result = JSON.parse(JSON.stringify(this.links));
79
- result = result.filter(link => link.data.predicate === query.predicate);
80
- if (query.limit)
81
- result = result.slice(0, query.limit);
82
- return result;
83
- }
84
- /** Convenience function to get the target of the first link that matches the given query
85
- * This makes sense when the query is expected to return only one link
86
- * and the target of that link is what you are looking for.
87
- */
88
- getSingleTarget(query) {
89
- delete query.target;
90
- const foundLinks = this.get(query);
91
- if (foundLinks.length)
92
- return foundLinks[0].data.target;
93
- else
94
- return null;
95
- }
96
- };
97
- __decorate([
98
- Field(type => [LinkExpression]),
99
- __metadata("design:type", Array)
100
- ], Perspective.prototype, "links", void 0);
101
- Perspective = __decorate([
102
- ObjectType(),
103
- __metadata("design:paramtypes", [Array])
104
- ], Perspective);
105
- export { Perspective };
106
- let PerspectiveInput = class PerspectiveInput {
107
- };
108
- __decorate([
109
- Field(type => [LinkExpressionInput]),
110
- __metadata("design:type", Array)
111
- ], PerspectiveInput.prototype, "links", void 0);
112
- PerspectiveInput = __decorate([
113
- InputType()
114
- ], PerspectiveInput);
115
- export { PerspectiveInput };
116
- let PerspectiveUnsignedInput = PerspectiveUnsignedInput_1 = class PerspectiveUnsignedInput {
117
- constructor(links) {
118
- if (links)
119
- this.links = links;
120
- else
121
- this.links = [];
122
- }
123
- static fromLink(link) {
124
- let obj = new PerspectiveUnsignedInput_1();
125
- obj.links.push(link);
126
- return obj;
127
- }
128
- };
129
- __decorate([
130
- Field(type => [LinkInput]),
131
- __metadata("design:type", Array)
132
- ], PerspectiveUnsignedInput.prototype, "links", void 0);
133
- PerspectiveUnsignedInput = PerspectiveUnsignedInput_1 = __decorate([
134
- InputType(),
135
- __metadata("design:paramtypes", [Array])
136
- ], PerspectiveUnsignedInput);
137
- export { PerspectiveUnsignedInput };
138
- let PerspectiveExpression = class PerspectiveExpression extends ExpressionGeneric(Perspective) {
139
- };
140
- PerspectiveExpression = __decorate([
141
- ObjectType()
142
- ], PerspectiveExpression);
143
- export { PerspectiveExpression };
144
- ;
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var PerspectiveUnsignedInput_1;
11
+ import { Field, ObjectType, InputType } from "type-graphql";
12
+ import { ExpressionGeneric } from "../expression/Expression";
13
+ import { LinkExpression, LinkExpressionInput, LinkInput } from "../links/Links";
14
+ /** A Perspective represents subjective meaning, encoded through
15
+ * associations between expressions, a.k.a. Links, that is a graph
16
+ * over the objective Expressions of any subset of Languages.
17
+ *
18
+ * This type represents the clean onotological concept of a Perspective.
19
+ * An instance of this class can be regarded as an immutable snapshot of
20
+ * a mutable perspective.
21
+ *
22
+ * The types PerspectiveProxy and PerspectiveHandle are used when dealing
23
+ * with an instantiated mutable perspective as is done through most of
24
+ * the GraphQL mutations.
25
+ */
26
+ let Perspective = class Perspective {
27
+ constructor(links) {
28
+ if (links) {
29
+ this.links = links;
30
+ }
31
+ else {
32
+ this.links = [];
33
+ }
34
+ }
35
+ /** Convenience function for filtering links just like with PerspectiveProxy */
36
+ get(query) {
37
+ if (!query || !query.source && !query.predicate && !query.target) {
38
+ return this.links;
39
+ }
40
+ if (query.source) {
41
+ let result = JSON.parse(JSON.stringify(this.links));
42
+ // @ts-ignore
43
+ if (query.target)
44
+ result = result.filter(l => l.data.target === query.target);
45
+ // @ts-ignore
46
+ if (query.predicate)
47
+ result = result.filter(l => l.data.predicate === query.predicate);
48
+ //@ts-ignore
49
+ if (query.fromDate)
50
+ result = result.filter(l => new Date(l.timestamp) >= query.fromDate);
51
+ //@ts-ignore
52
+ if (query.untilDate)
53
+ result = result.filter(l => new Date(l.timestamp) <= query.untilDate);
54
+ // console.debug("result", result)
55
+ if (query.limit)
56
+ result = result.slice(0, query.limit);
57
+ return result;
58
+ }
59
+ // console.debug("getLinks 3")
60
+ if (query.target) {
61
+ //@ts-ignore
62
+ let result = JSON.parse(JSON.stringify(this.links));
63
+ // @ts-ignore
64
+ if (query.predicate)
65
+ result = result.filter(l => l.data.predicate === query.predicate);
66
+ //@ts-ignore
67
+ if (query.fromDate)
68
+ result = result.filter(l => new Date(l.timestamp) >= query.fromDate);
69
+ //@ts-ignore
70
+ if (query.untilDate)
71
+ result = result.filter(l => new Date(l.timestamp) <= query.untilDate);
72
+ if (query.limit)
73
+ result = result.slice(0, query.limit);
74
+ return result;
75
+ }
76
+ // console.debug("getLinks 4")
77
+ //@ts-ignore
78
+ let result = JSON.parse(JSON.stringify(this.links));
79
+ result = result.filter(link => link.data.predicate === query.predicate);
80
+ if (query.limit)
81
+ result = result.slice(0, query.limit);
82
+ return result;
83
+ }
84
+ /** Convenience function to get the target of the first link that matches the given query
85
+ * This makes sense when the query is expected to return only one link
86
+ * and the target of that link is what you are looking for.
87
+ */
88
+ getSingleTarget(query) {
89
+ delete query.target;
90
+ const foundLinks = this.get(query);
91
+ if (foundLinks.length)
92
+ return foundLinks[0].data.target;
93
+ else
94
+ return null;
95
+ }
96
+ };
97
+ __decorate([
98
+ Field(type => [LinkExpression]),
99
+ __metadata("design:type", Array)
100
+ ], Perspective.prototype, "links", void 0);
101
+ Perspective = __decorate([
102
+ ObjectType(),
103
+ __metadata("design:paramtypes", [Array])
104
+ ], Perspective);
105
+ export { Perspective };
106
+ let PerspectiveInput = class PerspectiveInput {
107
+ };
108
+ __decorate([
109
+ Field(type => [LinkExpressionInput]),
110
+ __metadata("design:type", Array)
111
+ ], PerspectiveInput.prototype, "links", void 0);
112
+ PerspectiveInput = __decorate([
113
+ InputType()
114
+ ], PerspectiveInput);
115
+ export { PerspectiveInput };
116
+ let PerspectiveUnsignedInput = PerspectiveUnsignedInput_1 = class PerspectiveUnsignedInput {
117
+ constructor(links) {
118
+ if (links)
119
+ this.links = links;
120
+ else
121
+ this.links = [];
122
+ }
123
+ static fromLink(link) {
124
+ let obj = new PerspectiveUnsignedInput_1();
125
+ obj.links.push(link);
126
+ return obj;
127
+ }
128
+ };
129
+ __decorate([
130
+ Field(type => [LinkInput]),
131
+ __metadata("design:type", Array)
132
+ ], PerspectiveUnsignedInput.prototype, "links", void 0);
133
+ PerspectiveUnsignedInput = PerspectiveUnsignedInput_1 = __decorate([
134
+ InputType(),
135
+ __metadata("design:paramtypes", [Array])
136
+ ], PerspectiveUnsignedInput);
137
+ export { PerspectiveUnsignedInput };
138
+ let PerspectiveExpression = class PerspectiveExpression extends ExpressionGeneric(Perspective) {
139
+ };
140
+ PerspectiveExpression = __decorate([
141
+ ObjectType()
142
+ ], PerspectiveExpression);
143
+ export { PerspectiveExpression };
144
+ ;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,20 +1,20 @@
1
- import { Perspective } from "./Perspective";
2
- import { Link, LinkExpression } from "../links/Links";
3
- import { LinkQuery } from "./LinkQuery";
4
- const link = new LinkExpression();
5
- link.author = 'did:method:12345';
6
- link.timestamp = new Date().toString();
7
- link.data = new Link({ source: 'root', target: 'perspective://Qm34589a3ccc0' });
8
- link.proof = { signature: 'asdfasdf', key: 'asdfasdf' };
9
- describe('Perspective', () => {
10
- it('implements get()', () => {
11
- let p = new Perspective([link]);
12
- let result = p.get(new LinkQuery({ source: 'root' }));
13
- expect(result).toEqual([link]);
14
- });
15
- it('implements getSingleTarget()', () => {
16
- let p = new Perspective([link]);
17
- let result = p.getSingleTarget(new LinkQuery({ source: 'root' }));
18
- expect(result).toEqual(link.data.target);
19
- });
20
- });
1
+ import { Perspective } from "./Perspective";
2
+ import { Link, LinkExpression } from "../links/Links";
3
+ import { LinkQuery } from "./LinkQuery";
4
+ const link = new LinkExpression();
5
+ link.author = 'did:method:12345';
6
+ link.timestamp = new Date().toString();
7
+ link.data = new Link({ source: 'root', target: 'perspective://Qm34589a3ccc0' });
8
+ link.proof = { signature: 'asdfasdf', key: 'asdfasdf' };
9
+ describe('Perspective', () => {
10
+ it('implements get()', () => {
11
+ let p = new Perspective([link]);
12
+ let result = p.get(new LinkQuery({ source: 'root' }));
13
+ expect(result).toEqual([link]);
14
+ });
15
+ it('implements getSingleTarget()', () => {
16
+ let p = new Perspective([link]);
17
+ let result = p.getSingleTarget(new LinkQuery({ source: 'root' }));
18
+ expect(result).toEqual(link.data.target);
19
+ });
20
+ });