@coasys/ad4m 0.8.0 → 0.8.2-prerelease

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 (66) hide show
  1. package/lib/index.cjs +29 -53
  2. package/lib/index.js +8085 -0
  3. package/lib/shims/reflect-metadata.js +0 -0
  4. package/lib/shims/type-graphql.js +70 -0
  5. package/lib/src/Ad4mClient.js +66 -0
  6. package/lib/src/Address.js +1 -0
  7. package/lib/src/DID.js +1 -0
  8. package/lib/src/Exception.js +7 -0
  9. package/lib/src/Literal.js +76 -0
  10. package/lib/src/PubSub.js +14 -0
  11. package/lib/src/SmartLiteral.js +74 -0
  12. package/lib/src/agent/Agent.js +337 -0
  13. package/lib/src/agent/AgentClient.js +431 -0
  14. package/lib/src/agent/AgentResolver.js +325 -0
  15. package/lib/src/agent/AgentStatus.js +61 -0
  16. package/lib/src/buildSchema.js +36 -0
  17. package/lib/src/expression/Expression.js +143 -0
  18. package/lib/src/expression/ExpressionClient.js +102 -0
  19. package/lib/src/expression/ExpressionRef.js +67 -0
  20. package/lib/src/expression/ExpressionResolver.js +106 -0
  21. package/lib/src/index.js +30 -0
  22. package/lib/src/jestSetup.js +1 -0
  23. package/lib/src/language/Icon.js +24 -0
  24. package/lib/src/language/Language.js +79 -0
  25. package/lib/src/language/LanguageClient.js +137 -0
  26. package/lib/src/language/LanguageContext.js +2 -0
  27. package/lib/src/language/LanguageHandle.js +41 -0
  28. package/lib/src/language/LanguageMeta.js +89 -0
  29. package/lib/src/language/LanguageRef.js +30 -0
  30. package/lib/src/language/LanguageResolver.js +143 -0
  31. package/lib/src/links/Links.js +148 -0
  32. package/lib/src/links/Links.test.js +33 -0
  33. package/lib/src/neighbourhood/Neighbourhood.js +38 -0
  34. package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -0
  35. package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -0
  36. package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -0
  37. package/lib/src/perspectives/LinkQuery.js +80 -0
  38. package/lib/src/perspectives/Perspective.js +144 -0
  39. package/lib/src/perspectives/Perspective.test.js +20 -0
  40. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -0
  41. package/lib/src/perspectives/PerspectiveClient.js +418 -0
  42. package/lib/src/perspectives/PerspectiveDiff.js +33 -0
  43. package/lib/src/perspectives/PerspectiveHandle.js +59 -0
  44. package/lib/src/perspectives/PerspectiveProxy.d.ts +8 -8
  45. package/lib/src/perspectives/PerspectiveProxy.js +501 -0
  46. package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -0
  47. package/lib/src/perspectives/PerspectiveResolver.js +376 -0
  48. package/lib/src/runtime/RuntimeClient.js +263 -0
  49. package/lib/src/runtime/RuntimeResolver.js +328 -0
  50. package/lib/src/schema.gql +1 -0
  51. package/lib/src/subject/SDNADecorators.js +250 -0
  52. package/lib/src/subject/Subject.js +164 -0
  53. package/lib/src/subject/SubjectEntity.js +250 -0
  54. package/lib/src/subject/util.js +73 -0
  55. package/lib/src/typeDefs.js +380 -0
  56. package/lib/src/unwrapApolloResult.js +14 -0
  57. package/lib/src/utils.js +21 -0
  58. package/package.json +9 -2
  59. package/patches/graphql@15.7.2.patch +39 -0
  60. package/pnpm-workspace.yaml +19 -0
  61. package/src/Ad4mClient.test.ts +5 -0
  62. package/src/perspectives/PerspectiveClient.ts +9 -0
  63. package/src/perspectives/PerspectiveProxy.ts +22 -56
  64. package/src/perspectives/PerspectiveResolver.ts +5 -0
  65. package/src/subject/Subject.ts +9 -6
  66. package/src/unwrapApolloResult.ts +3 -1
@@ -0,0 +1,328 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Arg, Mutation, Resolver, Query, Subscription, ObjectType, Field } from "type-graphql";
14
+ import { Perspective, PerspectiveExpression, PerspectiveInput } from "../perspectives/Perspective";
15
+ import { ExpressionProof } from "../expression/Expression";
16
+ import { LinkExpression } from "../links/Links";
17
+ import { ExceptionType } from "../Exception";
18
+ import { RUNTIME_MESSAGED_RECEIVED_TOPIC, EXCEPTION_OCCURRED_TOPIC } from '../PubSub';
19
+ const testLink = new LinkExpression();
20
+ testLink.author = "did:ad4m:test";
21
+ testLink.timestamp = Date.now();
22
+ testLink.data = {
23
+ source: 'root',
24
+ target: 'neighbourhood://Qm12345'
25
+ };
26
+ testLink.proof = {
27
+ signature: '',
28
+ key: '',
29
+ valid: true
30
+ };
31
+ const testPerspectiveExpression = new PerspectiveExpression();
32
+ testPerspectiveExpression.author = 'did:ad4m:test';
33
+ testPerspectiveExpression.timestamp = Date.now().toString();
34
+ testPerspectiveExpression.proof = new ExpressionProof('', '');
35
+ testPerspectiveExpression.data = new Perspective([testLink]);
36
+ let SentMessage = class SentMessage {
37
+ };
38
+ __decorate([
39
+ Field(),
40
+ __metadata("design:type", String)
41
+ ], SentMessage.prototype, "recipient", void 0);
42
+ __decorate([
43
+ Field(),
44
+ __metadata("design:type", PerspectiveExpression)
45
+ ], SentMessage.prototype, "message", void 0);
46
+ SentMessage = __decorate([
47
+ ObjectType()
48
+ ], SentMessage);
49
+ export { SentMessage };
50
+ let RuntimeInfo = class RuntimeInfo {
51
+ };
52
+ __decorate([
53
+ Field(),
54
+ __metadata("design:type", String)
55
+ ], RuntimeInfo.prototype, "ad4mExecutorVersion", void 0);
56
+ __decorate([
57
+ Field(),
58
+ __metadata("design:type", Boolean)
59
+ ], RuntimeInfo.prototype, "isInitialized", void 0);
60
+ __decorate([
61
+ Field(),
62
+ __metadata("design:type", Boolean)
63
+ ], RuntimeInfo.prototype, "isUnlocked", void 0);
64
+ RuntimeInfo = __decorate([
65
+ ObjectType()
66
+ ], RuntimeInfo);
67
+ export { RuntimeInfo };
68
+ let ExceptionInfo = class ExceptionInfo {
69
+ };
70
+ __decorate([
71
+ Field(),
72
+ __metadata("design:type", String)
73
+ ], ExceptionInfo.prototype, "title", void 0);
74
+ __decorate([
75
+ Field(),
76
+ __metadata("design:type", String)
77
+ ], ExceptionInfo.prototype, "message", void 0);
78
+ __decorate([
79
+ Field(),
80
+ __metadata("design:type", Number)
81
+ ], ExceptionInfo.prototype, "type", void 0);
82
+ __decorate([
83
+ Field({ nullable: true }),
84
+ __metadata("design:type", String)
85
+ ], ExceptionInfo.prototype, "addon", void 0);
86
+ ExceptionInfo = __decorate([
87
+ ObjectType()
88
+ ], ExceptionInfo);
89
+ export { ExceptionInfo };
90
+ /**
91
+ * Resolver classes are used here to define the GraphQL schema
92
+ * (through the type-graphql annotations)
93
+ * and are spawned in the client tests in Ad4mClient.test.ts.
94
+ * For the latter, they return test fixtures.
95
+ */
96
+ let RuntimeResolver = class RuntimeResolver {
97
+ runtimeQuit() {
98
+ return true;
99
+ }
100
+ runtimeOpenLink(url) {
101
+ return true;
102
+ }
103
+ runtimeInfo() {
104
+ return {
105
+ ad4mExecutorVersion: "x.x.x",
106
+ isInitialized: true,
107
+ isUnlocked: true
108
+ };
109
+ }
110
+ addTrustedAgents(agents) {
111
+ return agents;
112
+ }
113
+ deleteTrustedAgents(agents) {
114
+ return [];
115
+ }
116
+ getTrustedAgents() {
117
+ return ["agentPubKey"];
118
+ }
119
+ runtimeKnownLinkLanguageTemplates() {
120
+ return ["Qm12345abcdef"];
121
+ }
122
+ runtimeAddKnownLinkLanguageTemplates(addresses) {
123
+ return addresses;
124
+ }
125
+ runtimeRemoveKnownLinkLanguageTemplates(addresses) {
126
+ return [];
127
+ }
128
+ runtimeFriends() {
129
+ return ["did:test:friend"];
130
+ }
131
+ runtimeAddFriends(dids) {
132
+ return dids;
133
+ }
134
+ runtimeRemoveFriends(dids) {
135
+ return [];
136
+ }
137
+ runtimeHcAgentInfos() {
138
+ return JSON.stringify([{ "agent": { "type": "Buffer", "data": [9, 191, 231, 58, 255, 107, 202, 55, 206, 57, 9, 103, 17, 34, 206, 195, 207, 114, 5, 73, 77, 198, 56, 136, 17, 227, 242, 231, 194, 135, 128, 48, 170, 189, 119, 186] }, "signature": { "type": "Buffer", "data": [195, 143, 170, 36, 234, 123, 255, 85, 188, 138, 124, 2, 91, 18, 53, 231, 44, 41, 240, 8, 80, 131, 100, 150, 165, 125, 146, 90, 17, 200, 190, 129, 114, 211, 11, 146, 150, 128, 198, 199, 79, 118, 157, 101, 194, 68, 58, 245, 98, 182, 79, 139, 140, 41, 143, 129, 8, 136, 87, 77, 180, 231, 218, 11] }, "agent_info": { "type": "Buffer", "data": [134, 165, 115, 112, 97, 99, 101, 196, 36, 203, 165, 212, 173, 24, 215, 165, 196, 25, 145, 248, 113, 246, 139, 205, 182, 241, 138, 57, 0, 26, 8, 217, 179, 23, 126, 59, 136, 128, 213, 110, 225, 173, 72, 197, 95, 165, 97, 103, 101, 110, 116, 196, 36, 9, 191, 231, 58, 255, 107, 202, 55, 206, 57, 9, 103, 17, 34, 206, 195, 207, 114, 5, 73, 77, 198, 56, 136, 17, 227, 242, 231, 194, 135, 128, 48, 170, 189, 119, 186, 164, 117, 114, 108, 115, 145, 217, 99, 107, 105, 116, 115, 117, 110, 101, 45, 112, 114, 111, 120, 121, 58, 47, 47, 101, 83, 52, 86, 112, 54, 109, 118, 80, 48, 122, 116, 85, 101, 104, 114, 117, 113, 89, 52, 102, 66, 53, 101, 69, 98, 121, 48, 69, 66, 100, 89, 84, 50, 95, 67, 48, 69, 112, 77, 111, 76, 111, 47, 107, 105, 116, 115, 117, 110, 101, 45, 113, 117, 105, 99, 47, 104, 47, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 56, 46, 54, 48, 47, 112, 47, 55, 55, 52, 52, 47, 45, 45, 172, 115, 105, 103, 110, 101, 100, 95, 97, 116, 95, 109, 115, 207, 0, 0, 1, 123, 233, 104, 189, 50, 176, 101, 120, 112, 105, 114, 101, 115, 95, 97, 102, 116, 101, 114, 95, 109, 115, 206, 0, 18, 79, 128, 169, 109, 101, 116, 97, 95, 105, 110, 102, 111, 196, 34, 129, 187, 100, 104, 116, 95, 115, 116, 111, 114, 97, 103, 101, 95, 97, 114, 99, 95, 104, 97, 108, 102, 95, 108, 101, 110, 103, 116, 104, 206, 128, 0, 0, 1] } }, { "agent": { "type": "Buffer", "data": [98, 187, 145, 48, 115, 209, 94, 143, 31, 153, 102, 69, 138, 29, 133, 213, 34, 52, 39, 164, 157, 139, 178, 111, 23, 33, 118, 250, 28, 155, 78, 246, 128, 49, 179, 38] }, "signature": { "type": "Buffer", "data": [233, 192, 38, 3, 59, 248, 124, 231, 57, 255, 40, 154, 50, 60, 119, 252, 68, 198, 154, 109, 175, 155, 106, 217, 211, 155, 109, 223, 249, 91, 221, 210, 17, 132, 72, 230, 11, 230, 247, 119, 72, 244, 145, 91, 75, 7, 67, 5, 130, 151, 44, 231, 52, 220, 28, 154, 212, 82, 58, 90, 203, 211, 236, 4] }, "agent_info": { "type": "Buffer", "data": [134, 165, 115, 112, 97, 99, 101, 196, 36, 203, 165, 212, 173, 24, 215, 165, 196, 25, 145, 248, 113, 246, 139, 205, 182, 241, 138, 57, 0, 26, 8, 217, 179, 23, 126, 59, 136, 128, 213, 110, 225, 173, 72, 197, 95, 165, 97, 103, 101, 110, 116, 196, 36, 98, 187, 145, 48, 115, 209, 94, 143, 31, 153, 102, 69, 138, 29, 133, 213, 34, 52, 39, 164, 157, 139, 178, 111, 23, 33, 118, 250, 28, 155, 78, 246, 128, 49, 179, 38, 164, 117, 114, 108, 115, 145, 217, 99, 107, 105, 116, 115, 117, 110, 101, 45, 112, 114, 111, 120, 121, 58, 47, 47, 55, 101, 77, 106, 48, 73, 83, 72, 56, 56, 81, 56, 45, 89, 51, 74, 89, 70, 53, 76, 72, 57, 83, 54, 68, 119, 71, 73, 49, 88, 45, 115, 87, 53, 68, 104, 66, 87, 121, 71, 119, 78, 115, 47, 107, 105, 116, 115, 117, 110, 101, 45, 113, 117, 105, 99, 47, 104, 47, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 56, 46, 54, 48, 47, 112, 47, 55, 55, 52, 52, 47, 45, 45, 172, 115, 105, 103, 110, 101, 100, 95, 97, 116, 95, 109, 115, 207, 0, 0, 1, 123, 233, 103, 45, 197, 176, 101, 120, 112, 105, 114, 101, 115, 95, 97, 102, 116, 101, 114, 95, 109, 115, 206, 0, 18, 79, 128, 169, 109, 101, 116, 97, 95, 105, 110, 102, 111, 196, 34, 129, 187, 100, 104, 116, 95, 115, 116, 111, 114, 97, 103, 101, 95, 97, 114, 99, 95, 104, 97, 108, 102, 95, 108, 101, 110, 103, 116, 104, 206, 128, 0, 0, 1] } }, { "agent": { "type": "Buffer", "data": [181, 101, 115, 45, 214, 127, 198, 153, 159, 184, 30, 87, 67, 224, 208, 184, 203, 176, 130, 158, 236, 127, 153, 125, 243, 183, 188, 167, 154, 25, 118, 254, 101, 145, 210, 109] }, "signature": { "type": "Buffer", "data": [88, 189, 229, 122, 44, 171, 194, 156, 90, 79, 148, 49, 207, 224, 34, 199, 219, 88, 24, 243, 103, 127, 123, 41, 87, 171, 127, 92, 6, 216, 198, 171, 26, 226, 237, 217, 122, 78, 98, 146, 55, 255, 68, 240, 202, 83, 58, 140, 147, 185, 3, 66, 15, 216, 210, 22, 99, 197, 73, 234, 120, 17, 74, 1] }, "agent_info": { "type": "Buffer", "data": [134, 165, 115, 112, 97, 99, 101, 196, 36, 203, 165, 212, 173, 24, 215, 165, 196, 25, 145, 248, 113, 246, 139, 205, 182, 241, 138, 57, 0, 26, 8, 217, 179, 23, 126, 59, 136, 128, 213, 110, 225, 173, 72, 197, 95, 165, 97, 103, 101, 110, 116, 196, 36, 181, 101, 115, 45, 214, 127, 198, 153, 159, 184, 30, 87, 67, 224, 208, 184, 203, 176, 130, 158, 236, 127, 153, 125, 243, 183, 188, 167, 154, 25, 118, 254, 101, 145, 210, 109, 164, 117, 114, 108, 115, 145, 217, 99, 107, 105, 116, 115, 117, 110, 101, 45, 112, 114, 111, 120, 121, 58, 47, 47, 114, 70, 71, 83, 100, 113, 104, 101, 68, 107, 70, 70, 56, 69, 102, 109, 45, 69, 116, 55, 119, 81, 101, 120, 83, 88, 55, 65, 112, 69, 51, 89, 86, 99, 45, 120, 102, 52, 104, 106, 77, 115, 77, 47, 107, 105, 116, 115, 117, 110, 101, 45, 113, 117, 105, 99, 47, 104, 47, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 56, 46, 54, 48, 47, 112, 47, 55, 55, 52, 52, 47, 45, 45, 172, 115, 105, 103, 110, 101, 100, 95, 97, 116, 95, 109, 115, 207, 0, 0, 1, 123, 233, 113, 23, 220, 176, 101, 120, 112, 105, 114, 101, 115, 95, 97, 102, 116, 101, 114, 95, 109, 115, 206, 0, 18, 79, 128, 169, 109, 101, 116, 97, 95, 105, 110, 102, 111, 196, 34, 129, 187, 100, 104, 116, 95, 115, 116, 111, 114, 97, 103, 101, 95, 97, 114, 99, 95, 104, 97, 108, 102, 95, 108, 101, 110, 103, 116, 104, 206, 128, 0, 0, 1] } }, { "agent": { "type": "Buffer", "data": [3, 171, 237, 107, 186, 245, 165, 47, 237, 235, 211, 49, 245, 62, 113, 53, 255, 252, 223, 226, 75, 118, 148, 187, 23, 53, 70, 174, 160, 184, 64, 63, 94, 210, 227, 56] }, "signature": { "type": "Buffer", "data": [129, 12, 55, 104, 239, 121, 138, 2, 86, 106, 136, 51, 219, 79, 170, 8, 195, 69, 81, 188, 225, 192, 247, 196, 54, 39, 164, 110, 75, 39, 240, 56, 245, 189, 154, 77, 72, 11, 97, 250, 202, 149, 242, 97, 128, 28, 47, 164, 236, 104, 136, 82, 212, 246, 44, 143, 132, 119, 255, 135, 112, 11, 20, 13] }, "agent_info": { "type": "Buffer", "data": [134, 165, 115, 112, 97, 99, 101, 196, 36, 203, 165, 212, 173, 24, 215, 165, 196, 25, 145, 248, 113, 246, 139, 205, 182, 241, 138, 57, 0, 26, 8, 217, 179, 23, 126, 59, 136, 128, 213, 110, 225, 173, 72, 197, 95, 165, 97, 103, 101, 110, 116, 196, 36, 3, 171, 237, 107, 186, 245, 165, 47, 237, 235, 211, 49, 245, 62, 113, 53, 255, 252, 223, 226, 75, 118, 148, 187, 23, 53, 70, 174, 160, 184, 64, 63, 94, 210, 227, 56, 164, 117, 114, 108, 115, 145, 217, 97, 107, 105, 116, 115, 117, 110, 101, 45, 112, 114, 111, 120, 121, 58, 47, 47, 104, 121, 112, 115, 86, 121, 103, 117, 80, 84, 115, 53, 118, 73, 80, 65, 102, 97, 112, 90, 88, 113, 117, 84, 115, 79, 80, 100, 67, 81, 79, 79, 117, 103, 57, 51, 82, 103, 106, 95, 114, 85, 73, 47, 107, 105, 116, 115, 117, 110, 101, 45, 113, 117, 105, 99, 47, 104, 47, 49, 54, 53, 46, 50, 50, 46, 51, 50, 46, 49, 49, 47, 112, 47, 53, 55, 55, 57, 47, 45, 45, 172, 115, 105, 103, 110, 101, 100, 95, 97, 116, 95, 109, 115, 207, 0, 0, 1, 123, 233, 113, 188, 123, 176, 101, 120, 112, 105, 114, 101, 115, 95, 97, 102, 116, 101, 114, 95, 109, 115, 206, 0, 18, 79, 128, 169, 109, 101, 116, 97, 95, 105, 110, 102, 111, 196, 34, 129, 187, 100, 104, 116, 95, 115, 116, 111, 114, 97, 103, 101, 95, 97, 114, 99, 95, 104, 97, 108, 102, 95, 108, 101, 110, 103, 116, 104, 206, 128, 0, 0, 1] } }]);
139
+ }
140
+ runtimeHcAddAgentInfos(agentInfos) {
141
+ return true;
142
+ }
143
+ runtimeVerifyStringSignedByDid(did, didSigningKeyId, data, signedData) {
144
+ return true;
145
+ }
146
+ runtimeSetStatus(status) {
147
+ return true;
148
+ }
149
+ runtimeFriendStatus(did) {
150
+ return testPerspectiveExpression;
151
+ }
152
+ runtimeFriendSendMessage(did, message) {
153
+ return true;
154
+ }
155
+ runtimeMessageInbox(filter) {
156
+ return [testPerspectiveExpression];
157
+ }
158
+ runtimeMessageOutbox(filter) {
159
+ return [{
160
+ recipient: "did:test:recipient",
161
+ message: testPerspectiveExpression
162
+ }];
163
+ }
164
+ runtimeMessageReceived() {
165
+ return testPerspectiveExpression;
166
+ }
167
+ exceptionOccurred() {
168
+ return {
169
+ title: "Test title",
170
+ message: "Test message",
171
+ type: ExceptionType.LanguageIsNotLoaded,
172
+ };
173
+ }
174
+ };
175
+ __decorate([
176
+ Mutation(returns => Boolean),
177
+ __metadata("design:type", Function),
178
+ __metadata("design:paramtypes", []),
179
+ __metadata("design:returntype", Boolean)
180
+ ], RuntimeResolver.prototype, "runtimeQuit", null);
181
+ __decorate([
182
+ Mutation(returns => Boolean),
183
+ __param(0, Arg('url')),
184
+ __metadata("design:type", Function),
185
+ __metadata("design:paramtypes", [String]),
186
+ __metadata("design:returntype", Boolean)
187
+ ], RuntimeResolver.prototype, "runtimeOpenLink", null);
188
+ __decorate([
189
+ Query(returns => RuntimeInfo),
190
+ __metadata("design:type", Function),
191
+ __metadata("design:paramtypes", []),
192
+ __metadata("design:returntype", RuntimeInfo)
193
+ ], RuntimeResolver.prototype, "runtimeInfo", null);
194
+ __decorate([
195
+ Mutation(returns => [String]),
196
+ __param(0, Arg("agents", type => [String])),
197
+ __metadata("design:type", Function),
198
+ __metadata("design:paramtypes", [Array]),
199
+ __metadata("design:returntype", Array)
200
+ ], RuntimeResolver.prototype, "addTrustedAgents", null);
201
+ __decorate([
202
+ Mutation(returns => [String]),
203
+ __param(0, Arg("agents", type => [String])),
204
+ __metadata("design:type", Function),
205
+ __metadata("design:paramtypes", [Array]),
206
+ __metadata("design:returntype", Array)
207
+ ], RuntimeResolver.prototype, "deleteTrustedAgents", null);
208
+ __decorate([
209
+ Query(returns => [String]),
210
+ __metadata("design:type", Function),
211
+ __metadata("design:paramtypes", []),
212
+ __metadata("design:returntype", Array)
213
+ ], RuntimeResolver.prototype, "getTrustedAgents", null);
214
+ __decorate([
215
+ Query(returns => [String]),
216
+ __metadata("design:type", Function),
217
+ __metadata("design:paramtypes", []),
218
+ __metadata("design:returntype", Array)
219
+ ], RuntimeResolver.prototype, "runtimeKnownLinkLanguageTemplates", null);
220
+ __decorate([
221
+ Mutation(returns => [String]),
222
+ __param(0, Arg("addresses", type => [String])),
223
+ __metadata("design:type", Function),
224
+ __metadata("design:paramtypes", [Array]),
225
+ __metadata("design:returntype", Array)
226
+ ], RuntimeResolver.prototype, "runtimeAddKnownLinkLanguageTemplates", null);
227
+ __decorate([
228
+ Mutation(returns => [String]),
229
+ __param(0, Arg("addresses", type => [String])),
230
+ __metadata("design:type", Function),
231
+ __metadata("design:paramtypes", [Array]),
232
+ __metadata("design:returntype", Array)
233
+ ], RuntimeResolver.prototype, "runtimeRemoveKnownLinkLanguageTemplates", null);
234
+ __decorate([
235
+ Query(returns => [String]),
236
+ __metadata("design:type", Function),
237
+ __metadata("design:paramtypes", []),
238
+ __metadata("design:returntype", Array)
239
+ ], RuntimeResolver.prototype, "runtimeFriends", null);
240
+ __decorate([
241
+ Mutation(returns => [String]),
242
+ __param(0, Arg("dids", type => [String])),
243
+ __metadata("design:type", Function),
244
+ __metadata("design:paramtypes", [Array]),
245
+ __metadata("design:returntype", Array)
246
+ ], RuntimeResolver.prototype, "runtimeAddFriends", null);
247
+ __decorate([
248
+ Mutation(returns => [String]),
249
+ __param(0, Arg("dids", type => [String])),
250
+ __metadata("design:type", Function),
251
+ __metadata("design:paramtypes", [Array]),
252
+ __metadata("design:returntype", Array)
253
+ ], RuntimeResolver.prototype, "runtimeRemoveFriends", null);
254
+ __decorate([
255
+ Query(),
256
+ __metadata("design:type", Function),
257
+ __metadata("design:paramtypes", []),
258
+ __metadata("design:returntype", String)
259
+ ], RuntimeResolver.prototype, "runtimeHcAgentInfos", null);
260
+ __decorate([
261
+ Mutation(returns => Boolean),
262
+ __param(0, Arg("agentInfos", type => String)),
263
+ __metadata("design:type", Function),
264
+ __metadata("design:paramtypes", [Object]),
265
+ __metadata("design:returntype", Boolean)
266
+ ], RuntimeResolver.prototype, "runtimeHcAddAgentInfos", null);
267
+ __decorate([
268
+ Query(returns => Boolean),
269
+ __param(0, Arg("did", type => String)),
270
+ __param(1, Arg("didSigningKeyId", type => String)),
271
+ __param(2, Arg("data", type => String)),
272
+ __param(3, Arg("signedData", type => String)),
273
+ __metadata("design:type", Function),
274
+ __metadata("design:paramtypes", [String, String, String, String]),
275
+ __metadata("design:returntype", void 0)
276
+ ], RuntimeResolver.prototype, "runtimeVerifyStringSignedByDid", null);
277
+ __decorate([
278
+ Mutation(),
279
+ __param(0, Arg("status", type => PerspectiveInput)),
280
+ __metadata("design:type", Function),
281
+ __metadata("design:paramtypes", [Perspective]),
282
+ __metadata("design:returntype", Boolean)
283
+ ], RuntimeResolver.prototype, "runtimeSetStatus", null);
284
+ __decorate([
285
+ Query({ nullable: true }),
286
+ __param(0, Arg("did", type => String)),
287
+ __metadata("design:type", Function),
288
+ __metadata("design:paramtypes", [String]),
289
+ __metadata("design:returntype", PerspectiveExpression)
290
+ ], RuntimeResolver.prototype, "runtimeFriendStatus", null);
291
+ __decorate([
292
+ Mutation(),
293
+ __param(0, Arg("did", type => String)),
294
+ __param(1, Arg("message", type => PerspectiveInput)),
295
+ __metadata("design:type", Function),
296
+ __metadata("design:paramtypes", [String, PerspectiveInput]),
297
+ __metadata("design:returntype", Boolean)
298
+ ], RuntimeResolver.prototype, "runtimeFriendSendMessage", null);
299
+ __decorate([
300
+ Query(returns => [PerspectiveExpression]),
301
+ __param(0, Arg("filter", type => String, { nullable: true })),
302
+ __metadata("design:type", Function),
303
+ __metadata("design:paramtypes", [String]),
304
+ __metadata("design:returntype", Array)
305
+ ], RuntimeResolver.prototype, "runtimeMessageInbox", null);
306
+ __decorate([
307
+ Query(returns => [SentMessage]),
308
+ __param(0, Arg("filter", type => String, { nullable: true })),
309
+ __metadata("design:type", Function),
310
+ __metadata("design:paramtypes", [String]),
311
+ __metadata("design:returntype", Array)
312
+ ], RuntimeResolver.prototype, "runtimeMessageOutbox", null);
313
+ __decorate([
314
+ Subscription({ topics: RUNTIME_MESSAGED_RECEIVED_TOPIC, nullable: true }),
315
+ __metadata("design:type", Function),
316
+ __metadata("design:paramtypes", []),
317
+ __metadata("design:returntype", PerspectiveExpression)
318
+ ], RuntimeResolver.prototype, "runtimeMessageReceived", null);
319
+ __decorate([
320
+ Subscription({ topics: EXCEPTION_OCCURRED_TOPIC, nullable: true }),
321
+ __metadata("design:type", Function),
322
+ __metadata("design:paramtypes", []),
323
+ __metadata("design:returntype", ExceptionInfo)
324
+ ], RuntimeResolver.prototype, "exceptionOccurred", null);
325
+ RuntimeResolver = __decorate([
326
+ Resolver()
327
+ ], RuntimeResolver);
328
+ export default RuntimeResolver;
@@ -248,6 +248,7 @@ type Mutation {
248
248
  perspectiveAddLink(link: LinkInput!, status: String = "shared", uuid: String!): LinkExpression!
249
249
  perspectiveAddLinkExpression(link: LinkExpressionInput!, status: String, uuid: String!): LinkExpression!
250
250
  perspectiveAddLinks(links: [LinkInput!]!, status: String, uuid: String!): [LinkExpression!]!
251
+ perspectiveAddSdna(name: String!, sdnaCode: String!, sdnaType: String!, uuid: String!): Boolean!
251
252
  perspectiveLinkMutations(mutations: LinkMutations!, status: String, uuid: String!): LinkExpressionMutations!
252
253
  perspectivePublishSnapshot(uuid: String!): String
253
254
  perspectiveRemove(uuid: String!): Boolean!
@@ -0,0 +1,250 @@
1
+ import { Subject } from "./Subject";
2
+ import { capitalize, propertyNameToSetterName, singularToPlural, stringifyObjectLiteral } from "./util";
3
+ export class PerspectiveAction {
4
+ }
5
+ export function addLink(source, predicate, target) {
6
+ return {
7
+ action: "addLink",
8
+ source,
9
+ predicate,
10
+ target,
11
+ };
12
+ }
13
+ export function hasLink(predicate) {
14
+ return `triple(this, "${predicate}", _)`;
15
+ }
16
+ export function instanceQuery(options) {
17
+ return function (target, key, descriptor) {
18
+ const originalMethod = descriptor.value;
19
+ if (typeof originalMethod !== "function") {
20
+ throw new Error("instanceQuery decorator can only be applied to methods");
21
+ }
22
+ descriptor.value = async function (perspective) {
23
+ let instances = [];
24
+ //@ts-ignore
25
+ let subjectClassName = target.name;
26
+ let query = `subject_class("${subjectClassName}", C), instance(C, Instance)`;
27
+ if (options && options.where) {
28
+ for (let prop in options.where) {
29
+ let value = options.where[prop];
30
+ query += `, property_getter(C, Instance, "${prop}", "${value}")`;
31
+ }
32
+ }
33
+ if (options && options.condition) {
34
+ query += ', ' + options.condition;
35
+ }
36
+ let results = await perspective.infer(query);
37
+ if (results == false) {
38
+ return instances;
39
+ }
40
+ if (typeof results == "string") {
41
+ throw results;
42
+ }
43
+ for (let result of results) {
44
+ let instance = result.Instance;
45
+ let subject = new Subject(perspective, instance, subjectClassName);
46
+ await subject.init();
47
+ instances.push(subject);
48
+ }
49
+ return instances;
50
+ };
51
+ };
52
+ }
53
+ export function subjectProperty(opts) {
54
+ return function (target, key) {
55
+ target["__properties"] = target["__properties"] || {};
56
+ target["__properties"][key] = target["__properties"][key] || {};
57
+ target["__properties"][key] = { ...target["__properties"][key], ...opts };
58
+ if (opts.writable) {
59
+ const value = key;
60
+ target[`set${capitalize(value)}`] = () => { };
61
+ }
62
+ Object.defineProperty(target, key, { configurable: true, writable: true });
63
+ };
64
+ }
65
+ export function subjectFlag(opts) {
66
+ return function (target, key) {
67
+ target["__properties"] = target["__properties"] || {};
68
+ target["__properties"][key] = target["__properties"][key] || {};
69
+ target["__properties"][key] = {
70
+ ...target["__properties"][key],
71
+ through: opts.through,
72
+ required: true,
73
+ initial: opts.value,
74
+ flag: true
75
+ };
76
+ // @ts-ignore
77
+ target[key] = opts.value;
78
+ Object.defineProperty(target, key, { configurable: true, writable: true });
79
+ };
80
+ }
81
+ export function subjectCollection(opts) {
82
+ return function (target, key) {
83
+ target["__collections"] = target["__collections"] || {};
84
+ target["__collections"][key] = opts;
85
+ const value = key;
86
+ target[`add${capitalize(value)}`] = () => { };
87
+ target[`remove${capitalize(value)}`] = () => { };
88
+ target[`setCollection${capitalize(value)}`] = () => { };
89
+ Object.defineProperty(target, key, { configurable: true, writable: true });
90
+ };
91
+ }
92
+ export function makeRandomPrologAtom(length) {
93
+ let result = '';
94
+ let characters = 'abcdefghijklmnopqrstuvwxyz';
95
+ let charactersLength = characters.length;
96
+ for (let i = 0; i < length; i++) {
97
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
98
+ }
99
+ return result;
100
+ }
101
+ export function SDNAClass(opts) {
102
+ return function (target) {
103
+ target.prototype.className = opts.name;
104
+ target.className = opts.name;
105
+ target.generateSDNA = function () {
106
+ let sdna = "";
107
+ let subjectName = opts.name;
108
+ let obj = target.prototype;
109
+ let uuid = makeRandomPrologAtom(8);
110
+ sdna += `subject_class("${subjectName}", ${uuid}).\n`;
111
+ let classRemoverActions = [];
112
+ let constructorActions = [];
113
+ if (obj.subjectConstructor && obj.subjectConstructor.length) {
114
+ constructorActions = constructorActions.concat(obj.subjectConstructor);
115
+ }
116
+ let instanceConditions = [];
117
+ if (obj.isSubjectInstance && obj.isSubjectInstance.length) {
118
+ instanceConditions = instanceConditions.concat(obj.isSubjectInstance);
119
+ }
120
+ let propertiesCode = [];
121
+ let properties = obj.__properties || {};
122
+ for (let property in properties) {
123
+ let propertyCode = `property(${uuid}, "${property}").\n`;
124
+ let { through, initial, required, resolveLanguage, writable, flag, getter, setter, local } = properties[property];
125
+ if (resolveLanguage) {
126
+ propertyCode += `property_resolve(${uuid}, "${property}").\n`;
127
+ propertyCode += `property_resolve_language(${uuid}, "${property}", "${resolveLanguage}").\n`;
128
+ }
129
+ if (getter) {
130
+ propertyCode += `property_getter(${uuid}, Base, "${property}", Value) :- ${getter}.\n`;
131
+ }
132
+ else if (through) {
133
+ propertyCode += `property_getter(${uuid}, Base, "${property}", Value) :- triple(Base, "${through}", Value).\n`;
134
+ if (required) {
135
+ if (flag) {
136
+ instanceConditions.push(`triple(Base, "${through}", "${initial}")`);
137
+ }
138
+ else {
139
+ instanceConditions.push(`triple(Base, "${through}", _)`);
140
+ }
141
+ }
142
+ }
143
+ if (setter) {
144
+ propertyCode += `property_setter(${uuid}, "${property}", Actions) :- ${setter}.\n`;
145
+ }
146
+ else if (writable) {
147
+ let setter = obj[propertyNameToSetterName(property)];
148
+ if (typeof setter === "function") {
149
+ let action = [{
150
+ action: "setSingleTarget",
151
+ source: "this",
152
+ predicate: through,
153
+ target: "value",
154
+ ...(local && { local: true })
155
+ }];
156
+ propertyCode += `property_setter(${uuid}, "${property}", '${stringifyObjectLiteral(action)}').\n`;
157
+ }
158
+ }
159
+ propertiesCode.push(propertyCode);
160
+ if (initial) {
161
+ constructorActions.push({
162
+ action: "addLink",
163
+ source: "this",
164
+ predicate: through,
165
+ target: initial,
166
+ });
167
+ classRemoverActions.push({
168
+ action: "removeLink",
169
+ source: "this",
170
+ predicate: through,
171
+ target: initial,
172
+ });
173
+ }
174
+ }
175
+ let collectionsCode = [];
176
+ let collections = obj.__collections || {};
177
+ for (let collection in collections) {
178
+ let collectionCode = `collection(${uuid}, "${collection}").\n`;
179
+ let { through, where, local } = collections[collection];
180
+ if (through) {
181
+ if (where) {
182
+ if (!where.isInstance && !where.condition) {
183
+ throw "'where' needs one of 'isInstance' or 'condition'";
184
+ }
185
+ let conditions = [];
186
+ if (where.isInstance) {
187
+ let otherClass;
188
+ if (where.isInstance.name) {
189
+ otherClass = where.isInstance.name;
190
+ }
191
+ else {
192
+ otherClass = where.isInstance;
193
+ }
194
+ conditions.push(`instance(OtherClass, Target), subject_class("${otherClass}", OtherClass)`);
195
+ }
196
+ if (where.condition) {
197
+ conditions.push(where.condition);
198
+ }
199
+ const conditionString = conditions.join(", ");
200
+ collectionCode += `collection_getter(${uuid}, Base, "${collection}", List) :- setof(Target, (triple(Base, "${through}", Target), ${conditionString}), List).\n`;
201
+ }
202
+ else {
203
+ collectionCode += `collection_getter(${uuid}, Base, "${collection}", List) :- findall(C, triple(Base, "${through}", C), List).\n`;
204
+ }
205
+ let collectionAdderAction = [{
206
+ action: "addLink",
207
+ source: "this",
208
+ predicate: through,
209
+ target: "value",
210
+ ...(local && { local: true })
211
+ }];
212
+ let collectionRemoverAction = [{
213
+ action: "removeLink",
214
+ source: "this",
215
+ predicate: through,
216
+ target: "value",
217
+ }];
218
+ let collectionSetterAction = [{
219
+ action: "collectionSetter",
220
+ source: "this",
221
+ predicate: through,
222
+ target: "value",
223
+ ...(local && { local: true })
224
+ }];
225
+ collectionCode += `collection_adder(${uuid}, "${singularToPlural(collection)}", '${stringifyObjectLiteral(collectionAdderAction)}').\n`;
226
+ collectionCode += `collection_remover(${uuid}, "${singularToPlural(collection)}", '${stringifyObjectLiteral(collectionRemoverAction)}').\n`;
227
+ collectionCode += `collection_setter(${uuid}, "${singularToPlural(collection)}", '${stringifyObjectLiteral(collectionSetterAction)}').\n`;
228
+ }
229
+ collectionsCode.push(collectionCode);
230
+ }
231
+ let subjectContructorJSONString = stringifyObjectLiteral(constructorActions);
232
+ sdna += `constructor(${uuid}, '${subjectContructorJSONString}').\n`;
233
+ if (instanceConditions.length > 0) {
234
+ let instanceConditionProlog = instanceConditions.join(", ");
235
+ sdna += `instance(${uuid}, Base) :- ${instanceConditionProlog}.\n`;
236
+ sdna += "\n";
237
+ }
238
+ sdna += `destructor(${uuid}, '${stringifyObjectLiteral(classRemoverActions)}').\n`;
239
+ sdna += "\n";
240
+ sdna += propertiesCode.join("\n");
241
+ sdna += "\n";
242
+ sdna += collectionsCode.join("\n");
243
+ return {
244
+ sdna,
245
+ name: subjectName
246
+ };
247
+ };
248
+ Object.defineProperty(target, 'type', { configurable: true });
249
+ };
250
+ }