@coasys/ad4m 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -0
- package/jest-setup.ts +1 -0
- package/jest.config.js +6 -0
- package/jsdoc.json +28 -0
- package/lib/index.cjs +8144 -0
- package/lib/shims/reflect-metadata.d.ts +0 -0
- package/lib/shims/type-graphql.d.ts +32 -0
- package/lib/src/Ad4mClient.d.ts +26 -0
- package/lib/src/Address.d.ts +1 -0
- package/lib/src/DID.d.ts +1 -0
- package/lib/src/Exception.d.ts +6 -0
- package/lib/src/Literal.d.ts +7 -0
- package/lib/src/PubSub.d.ts +14 -0
- package/lib/src/SmartLiteral.d.ts +12 -0
- package/lib/src/agent/Agent.d.ts +104 -0
- package/lib/src/agent/AgentClient.d.ts +57 -0
- package/lib/src/agent/AgentResolver.d.ts +30 -0
- package/lib/src/agent/AgentStatus.d.ts +8 -0
- package/lib/src/buildSchema.d.ts +1 -0
- package/lib/src/expression/Expression.d.ts +28 -0
- package/lib/src/expression/ExpressionClient.d.ts +13 -0
- package/lib/src/expression/ExpressionRef.d.ts +9 -0
- package/lib/src/expression/ExpressionResolver.d.ts +10 -0
- package/lib/src/index.d.ts +30 -0
- package/lib/src/jestSetup.d.ts +1 -0
- package/lib/src/language/Icon.d.ts +4 -0
- package/lib/src/language/Language.d.ts +195 -0
- package/lib/src/language/LanguageClient.d.ts +17 -0
- package/lib/src/language/LanguageContext.d.ts +37 -0
- package/lib/src/language/LanguageHandle.d.ts +9 -0
- package/lib/src/language/LanguageMeta.d.ts +35 -0
- package/lib/src/language/LanguageRef.d.ts +6 -0
- package/lib/src/language/LanguageResolver.d.ts +19 -0
- package/lib/src/links/Links.d.ts +39 -0
- package/lib/src/links/Links.test.d.ts +1 -0
- package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
- package/lib/src/perspectives/LinkQuery.d.ts +11 -0
- package/lib/src/perspectives/Perspective.d.ts +38 -0
- package/lib/src/perspectives/Perspective.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +54 -0
- package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -0
- package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -0
- package/lib/src/perspectives/PerspectiveResolver.d.ts +37 -0
- package/lib/src/runtime/RuntimeClient.d.ts +33 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +47 -0
- package/lib/src/schema.gql +382 -0
- package/lib/src/subject/SDNADecorators.d.ts +45 -0
- package/lib/src/subject/Subject.d.ts +7 -0
- package/lib/src/subject/SubjectEntity.d.ts +31 -0
- package/lib/src/subject/util.d.ts +12 -0
- package/lib/src/typeDefs.d.ts +1 -0
- package/lib/src/unwrapApolloResult.d.ts +2 -0
- package/lib/src/utils.d.ts +2 -0
- package/package.json +60 -0
- package/rollup.config.js +27 -0
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +75 -0
- package/src/Ad4mClient.test.ts +1085 -0
- package/src/Ad4mClient.ts +63 -0
- package/src/Address.ts +1 -0
- package/src/DID.ts +1 -0
- package/src/Exception.ts +6 -0
- package/src/Literal.test.ts +31 -0
- package/src/Literal.ts +81 -0
- package/src/PubSub.ts +14 -0
- package/src/SmartLiteral.ts +75 -0
- package/src/agent/Agent.ts +293 -0
- package/src/agent/AgentClient.ts +531 -0
- package/src/agent/AgentResolver.ts +263 -0
- package/src/agent/AgentStatus.ts +44 -0
- package/src/buildSchema.ts +41 -0
- package/src/expression/Expression.ts +99 -0
- package/src/expression/ExpressionClient.ts +99 -0
- package/src/expression/ExpressionRef.ts +63 -0
- package/src/expression/ExpressionResolver.ts +64 -0
- package/src/index.ts +30 -0
- package/src/jestSetup.ts +1 -0
- package/src/language/Icon.ts +11 -0
- package/src/language/Language.ts +266 -0
- package/src/language/LanguageClient.ts +160 -0
- package/src/language/LanguageContext.ts +37 -0
- package/src/language/LanguageHandle.ts +23 -0
- package/src/language/LanguageMeta.ts +70 -0
- package/src/language/LanguageRef.ts +18 -0
- package/src/language/LanguageResolver.ts +98 -0
- package/src/links/Links.test.ts +40 -0
- package/src/links/Links.ts +107 -0
- package/src/neighbourhood/Neighbourhood.ts +22 -0
- package/src/neighbourhood/NeighbourhoodClient.ts +276 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -0
- package/src/neighbourhood/NeighbourhoodResolver.ts +100 -0
- package/src/perspectives/LinkQuery.ts +66 -0
- package/src/perspectives/Perspective.test.ts +23 -0
- package/src/perspectives/Perspective.ts +118 -0
- package/src/perspectives/PerspectiveClient.ts +444 -0
- package/src/perspectives/PerspectiveDiff.ts +15 -0
- package/src/perspectives/PerspectiveHandle.ts +39 -0
- package/src/perspectives/PerspectiveProxy.ts +611 -0
- package/src/perspectives/PerspectiveResolver.ts +220 -0
- package/src/runtime/RuntimeClient.ts +283 -0
- package/src/runtime/RuntimeResolver.ts +193 -0
- package/src/subject/SDNADecorators.ts +334 -0
- package/src/subject/Subject.ts +153 -0
- package/src/subject/SubjectEntity.ts +292 -0
- package/src/subject/util.ts +85 -0
- package/src/typeDefs.ts +6 -0
- package/src/unwrapApolloResult.ts +14 -0
- package/src/utils.ts +25 -0
- package/tsconfig-browser.json +82 -0
- package/tsconfig.json +80 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Arg,
|
|
3
|
+
Mutation,
|
|
4
|
+
Query,
|
|
5
|
+
Resolver,
|
|
6
|
+
Subscription,
|
|
7
|
+
PubSub,
|
|
8
|
+
} from "type-graphql";
|
|
9
|
+
import { Perspective, PerspectiveInput } from "../perspectives/Perspective";
|
|
10
|
+
import {
|
|
11
|
+
Agent,
|
|
12
|
+
AgentSignature,
|
|
13
|
+
Apps,
|
|
14
|
+
AuthInfoInput,
|
|
15
|
+
EntanglementProof,
|
|
16
|
+
EntanglementProofInput,
|
|
17
|
+
} from "./Agent";
|
|
18
|
+
import { AgentStatus } from "./AgentStatus";
|
|
19
|
+
import { AGENT_STATUS_CHANGED, AGENT_UPDATED, APPS_CHANGED } from "../PubSub";
|
|
20
|
+
|
|
21
|
+
export const TEST_AGENT_DID = "did:ad4m:test";
|
|
22
|
+
|
|
23
|
+
@Resolver()
|
|
24
|
+
export default class AgentResolver {
|
|
25
|
+
@Query((returns) => Agent)
|
|
26
|
+
agent(): Agent {
|
|
27
|
+
return new Agent(TEST_AGENT_DID);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Query((returns) => AgentStatus)
|
|
31
|
+
agentStatus(): AgentStatus {
|
|
32
|
+
return new AgentStatus({ did: TEST_AGENT_DID });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Mutation((returns) => AgentStatus)
|
|
36
|
+
agentGenerate(
|
|
37
|
+
@Arg("passphrase") passphrase: string,
|
|
38
|
+
@PubSub() pubSub: any
|
|
39
|
+
): AgentStatus {
|
|
40
|
+
const status = new AgentStatus({
|
|
41
|
+
did: TEST_AGENT_DID,
|
|
42
|
+
didDocument: "did document",
|
|
43
|
+
isInitialized: true,
|
|
44
|
+
isUnlocked: true,
|
|
45
|
+
});
|
|
46
|
+
pubSub.publish(AGENT_STATUS_CHANGED, { status });
|
|
47
|
+
return status;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Mutation((returns) => AgentStatus)
|
|
51
|
+
agentImport(
|
|
52
|
+
@Arg("did") did: string,
|
|
53
|
+
@Arg("didDocument") didDocument: string,
|
|
54
|
+
@Arg("keystore") keystore: string,
|
|
55
|
+
@Arg("passphrase") passphrase: string
|
|
56
|
+
): AgentStatus {
|
|
57
|
+
return new AgentStatus({
|
|
58
|
+
did,
|
|
59
|
+
didDocument,
|
|
60
|
+
isInitialized: true,
|
|
61
|
+
isUnlocked: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Mutation((returns) => AgentStatus)
|
|
66
|
+
agentLock(
|
|
67
|
+
@Arg("passphrase") passphrase: string,
|
|
68
|
+
@PubSub() pubSub: any
|
|
69
|
+
): AgentStatus {
|
|
70
|
+
const status = new AgentStatus({
|
|
71
|
+
isInitialized: true,
|
|
72
|
+
did: TEST_AGENT_DID,
|
|
73
|
+
});
|
|
74
|
+
pubSub.publish(AGENT_STATUS_CHANGED, { status });
|
|
75
|
+
return status;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Mutation((returns) => AgentStatus)
|
|
79
|
+
agentUnlock(
|
|
80
|
+
@Arg("passphrase") passphrase: string,
|
|
81
|
+
@Arg("holochain") holochain: boolean,
|
|
82
|
+
@PubSub() pubSub: any
|
|
83
|
+
): AgentStatus {
|
|
84
|
+
const status = new AgentStatus({
|
|
85
|
+
isInitialized: true,
|
|
86
|
+
isUnlocked: true,
|
|
87
|
+
did: TEST_AGENT_DID,
|
|
88
|
+
});
|
|
89
|
+
pubSub.publish(AGENT_STATUS_CHANGED, { status });
|
|
90
|
+
return status;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Query((returns) => Agent, { nullable: true })
|
|
94
|
+
agentByDID(@Arg("did") did: string): Agent {
|
|
95
|
+
return new Agent(did);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Mutation((returns) => Agent)
|
|
99
|
+
agentUpdatePublicPerspective(
|
|
100
|
+
@Arg("perspective") perspective: PerspectiveInput,
|
|
101
|
+
@PubSub() pubSub: any
|
|
102
|
+
): Agent {
|
|
103
|
+
const agent = new Agent(TEST_AGENT_DID, perspective as Perspective);
|
|
104
|
+
agent.directMessageLanguage = "lang://test";
|
|
105
|
+
pubSub.publish(AGENT_UPDATED, { agent });
|
|
106
|
+
return agent;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Mutation((returns) => Agent)
|
|
110
|
+
agentUpdateDirectMessageLanguage(
|
|
111
|
+
@Arg("directMessageLanguage") directMessageLanguage: string,
|
|
112
|
+
@PubSub() pubSub: any
|
|
113
|
+
): Agent {
|
|
114
|
+
const agent = new Agent(TEST_AGENT_DID, new Perspective());
|
|
115
|
+
agent.directMessageLanguage = directMessageLanguage;
|
|
116
|
+
pubSub.publish(AGENT_UPDATED, { agent });
|
|
117
|
+
return agent;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Subscription({ topics: AGENT_UPDATED, nullable: true })
|
|
121
|
+
agentUpdated(): Agent {
|
|
122
|
+
return new Agent(TEST_AGENT_DID);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Subscription({ topics: AGENT_STATUS_CHANGED, nullable: true })
|
|
126
|
+
agentStatusChanged(): AgentStatus {
|
|
127
|
+
return new AgentStatus({ isInitialized: true, did: TEST_AGENT_DID });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@Mutation((returns) => [EntanglementProof])
|
|
131
|
+
agentAddEntanglementProofs(
|
|
132
|
+
@Arg("proofs", (type) => [EntanglementProofInput])
|
|
133
|
+
proofs: EntanglementProofInput[]
|
|
134
|
+
): EntanglementProof[] {
|
|
135
|
+
return [
|
|
136
|
+
new EntanglementProof(
|
|
137
|
+
"did:key:hash",
|
|
138
|
+
"did-key-id",
|
|
139
|
+
"ethereum",
|
|
140
|
+
"ethAddr",
|
|
141
|
+
"sig",
|
|
142
|
+
"sig2"
|
|
143
|
+
),
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@Mutation((returns) => [EntanglementProof])
|
|
148
|
+
agentDeleteEntanglementProofs(
|
|
149
|
+
@Arg("proofs", (type) => [EntanglementProofInput])
|
|
150
|
+
proofs: EntanglementProofInput[]
|
|
151
|
+
): EntanglementProof[] {
|
|
152
|
+
return [
|
|
153
|
+
new EntanglementProof(
|
|
154
|
+
"did:key:hash",
|
|
155
|
+
"did-key-id",
|
|
156
|
+
"ethereum",
|
|
157
|
+
"ethAddr",
|
|
158
|
+
"sig",
|
|
159
|
+
"sig2"
|
|
160
|
+
),
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Query((returns) => [EntanglementProof])
|
|
165
|
+
agentGetEntanglementProofs(): EntanglementProof[] {
|
|
166
|
+
return [
|
|
167
|
+
new EntanglementProof(
|
|
168
|
+
"did:key:hash",
|
|
169
|
+
"did-key-id",
|
|
170
|
+
"ethereum",
|
|
171
|
+
"ethAddr",
|
|
172
|
+
"sig",
|
|
173
|
+
"sig2"
|
|
174
|
+
),
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Mutation((returns) => EntanglementProof)
|
|
179
|
+
agentEntanglementProofPreFlight(
|
|
180
|
+
@Arg("deviceKey") deviceKey: string,
|
|
181
|
+
@Arg("deviceKeyType") deviceKeyType: string
|
|
182
|
+
): EntanglementProof {
|
|
183
|
+
return new EntanglementProof(
|
|
184
|
+
"did:key:hash",
|
|
185
|
+
"did-key-id",
|
|
186
|
+
deviceKeyType,
|
|
187
|
+
deviceKey,
|
|
188
|
+
"sig"
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Mutation((returns) => String)
|
|
193
|
+
agentRequestCapability(@Arg("authInfo") authInfo: AuthInfoInput): String {
|
|
194
|
+
return "test-request-id";
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@Mutation((returns) => String)
|
|
198
|
+
agentPermitCapability(@Arg("auth") auth: string): String {
|
|
199
|
+
return "123";
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@Mutation((returns) => String)
|
|
203
|
+
agentGenerateJwt(
|
|
204
|
+
@Arg("requestId") requestId: string,
|
|
205
|
+
@Arg("rand") rand: string
|
|
206
|
+
): String {
|
|
207
|
+
return "test-jwt";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@Query((returns) => Boolean)
|
|
211
|
+
agentIsLocked(): Boolean {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@Query((returns) => [Apps])
|
|
216
|
+
agentGetApps(): [] {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@Subscription((returns) => [Apps], { topics: APPS_CHANGED, nullable: true })
|
|
222
|
+
agentAppsChanged(): null {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@Mutation((returns) => [Apps])
|
|
228
|
+
agentRemoveApp(@Arg("requestId") requestId: string, @PubSub() pubSub: any): [] {
|
|
229
|
+
pubSub.publish(APPS_CHANGED, { });
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@Mutation((returns) => [Apps])
|
|
234
|
+
agentRevokeToken(@Arg("requestId") requestId: string): any[] {
|
|
235
|
+
return [
|
|
236
|
+
{
|
|
237
|
+
revoked: true,
|
|
238
|
+
requestId: "test-request-id",
|
|
239
|
+
auth: {
|
|
240
|
+
appName: "test-app",
|
|
241
|
+
appDesc: "-",
|
|
242
|
+
appUrl: "-",
|
|
243
|
+
appIconPath: "_",
|
|
244
|
+
capabilities: [
|
|
245
|
+
{
|
|
246
|
+
with: {
|
|
247
|
+
domain: "*",
|
|
248
|
+
pointers: ["*"],
|
|
249
|
+
},
|
|
250
|
+
can: ["*"],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
token: "test-token",
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@Mutation((returns) => AgentSignature)
|
|
260
|
+
agentSignMessage(@Arg("message") message: string): AgentSignature {
|
|
261
|
+
return new AgentSignature("test-message-signature", "test-public-key");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Field, ObjectType } from "type-graphql";
|
|
2
|
+
|
|
3
|
+
@ObjectType()
|
|
4
|
+
export class AgentStatus {
|
|
5
|
+
@Field()
|
|
6
|
+
isInitialized: Boolean
|
|
7
|
+
|
|
8
|
+
@Field()
|
|
9
|
+
isUnlocked: Boolean
|
|
10
|
+
|
|
11
|
+
@Field({nullable: true})
|
|
12
|
+
did?: string
|
|
13
|
+
|
|
14
|
+
@Field({nullable: true})
|
|
15
|
+
didDocument?: string
|
|
16
|
+
|
|
17
|
+
@Field({nullable: true})
|
|
18
|
+
error?: string
|
|
19
|
+
|
|
20
|
+
constructor(obj?: object) {
|
|
21
|
+
if(obj) {
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
this.isInitialized = obj.isInitialized
|
|
24
|
+
if(!this.isInitialized) {
|
|
25
|
+
this.isInitialized = false
|
|
26
|
+
}
|
|
27
|
+
//@ts-ignore
|
|
28
|
+
this.isUnlocked = obj.isUnlocked
|
|
29
|
+
if(!this.isUnlocked) {
|
|
30
|
+
this.isUnlocked = false
|
|
31
|
+
}
|
|
32
|
+
//@ts-ignore
|
|
33
|
+
this.did = obj.did
|
|
34
|
+
//@ts-ignore
|
|
35
|
+
this.didDocument = obj.didDocument
|
|
36
|
+
//@ts-ignore
|
|
37
|
+
this.error = obj.error
|
|
38
|
+
} else {
|
|
39
|
+
this.isInitialized = false
|
|
40
|
+
this.isUnlocked = false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { buildSchema } from "type-graphql";
|
|
6
|
+
import AgentResolver from "./agent/AgentResolver";
|
|
7
|
+
import ExpressionResolver from "./expression/ExpressionResolver"
|
|
8
|
+
import LanguageResolver from "./language/LanguageResolver";
|
|
9
|
+
import NeighbourhoodResolver from "./neighbourhood/NeighbourhoodResolver";
|
|
10
|
+
import PerspectiveResolver from "./perspectives/PerspectiveResolver";
|
|
11
|
+
import RuntimeResolver from "./runtime/RuntimeResolver";
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = path.dirname(__filename);
|
|
15
|
+
|
|
16
|
+
buildSchema({
|
|
17
|
+
resolvers: [
|
|
18
|
+
AgentResolver,
|
|
19
|
+
ExpressionResolver,
|
|
20
|
+
LanguageResolver,
|
|
21
|
+
NeighbourhoodResolver,
|
|
22
|
+
PerspectiveResolver,
|
|
23
|
+
RuntimeResolver
|
|
24
|
+
],
|
|
25
|
+
emitSchemaFile: {
|
|
26
|
+
path: __dirname + '/schema.gql',
|
|
27
|
+
commentDescriptions: true
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
.then(() => {
|
|
31
|
+
const schemaFile = fs.readFileSync(__dirname+'/schema.gql')
|
|
32
|
+
const schemaFileWithoutComments = schemaFile.toString().split("\n").filter((line)=>!line.startsWith('#')).join("\n")
|
|
33
|
+
const typeDefsFile = `
|
|
34
|
+
export const typeDefsString = \`${schemaFileWithoutComments}\`
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
fs.writeFileSync(__dirname+'/typeDefs.js', typeDefsFile)
|
|
38
|
+
//fs.writeFileSync(__dirname+'/src/typeDefs.js', typeDefsFile)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ClassType, Field, InputType, ObjectType } from "type-graphql";
|
|
2
|
+
import { Icon } from "../language/Icon";
|
|
3
|
+
import { LanguageRef } from "../language/LanguageRef";
|
|
4
|
+
|
|
5
|
+
@ObjectType()
|
|
6
|
+
@InputType()
|
|
7
|
+
export class ExpressionProof {
|
|
8
|
+
@Field({nullable: true})
|
|
9
|
+
signature: string;
|
|
10
|
+
|
|
11
|
+
@Field({nullable: true})
|
|
12
|
+
key: string;
|
|
13
|
+
|
|
14
|
+
@Field({nullable: true})
|
|
15
|
+
valid?: boolean;
|
|
16
|
+
|
|
17
|
+
@Field({nullable: true})
|
|
18
|
+
invalid?: boolean;
|
|
19
|
+
|
|
20
|
+
constructor(sig: string, k: string) {
|
|
21
|
+
this.key = k
|
|
22
|
+
this.signature = sig
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@InputType()
|
|
27
|
+
export class ExpressionProofInput {
|
|
28
|
+
@Field({nullable: true})
|
|
29
|
+
signature: string;
|
|
30
|
+
|
|
31
|
+
@Field({nullable: true})
|
|
32
|
+
key: string;
|
|
33
|
+
|
|
34
|
+
@Field({nullable: true})
|
|
35
|
+
valid?: boolean;
|
|
36
|
+
|
|
37
|
+
@Field({nullable: true})
|
|
38
|
+
invalid?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//Note having any as return type here fixes compilation errors but I think we loose the ExpressionClass type in resulting .d.ts gql files
|
|
42
|
+
export function ExpressionGeneric<DataType>(DataTypeClass: ClassType<DataType>): any {
|
|
43
|
+
@ObjectType()
|
|
44
|
+
abstract class ExpressionClass {
|
|
45
|
+
@Field()
|
|
46
|
+
author: string;
|
|
47
|
+
|
|
48
|
+
@Field()
|
|
49
|
+
timestamp: string;
|
|
50
|
+
|
|
51
|
+
@Field(type => DataTypeClass)
|
|
52
|
+
data: DataType;
|
|
53
|
+
|
|
54
|
+
@Field()
|
|
55
|
+
proof: ExpressionProof;
|
|
56
|
+
|
|
57
|
+
constructor(author: string, timestamp: string, data: DataType, proof: ExpressionProof) {
|
|
58
|
+
this.author = author;
|
|
59
|
+
this.timestamp = timestamp;
|
|
60
|
+
this.data = data;
|
|
61
|
+
this.proof = proof;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return ExpressionClass;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function ExpressionGenericInput<DataType>(DataTypeClass: ClassType<DataType>): any {
|
|
68
|
+
@InputType()
|
|
69
|
+
abstract class ExpressionClass {
|
|
70
|
+
@Field()
|
|
71
|
+
author: string;
|
|
72
|
+
|
|
73
|
+
@Field()
|
|
74
|
+
timestamp: string;
|
|
75
|
+
|
|
76
|
+
@Field(type => DataTypeClass)
|
|
77
|
+
data: DataType;
|
|
78
|
+
|
|
79
|
+
@Field()
|
|
80
|
+
proof: ExpressionProofInput;
|
|
81
|
+
}
|
|
82
|
+
return ExpressionClass;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ObjectType()
|
|
86
|
+
export class Expression extends ExpressionGeneric(Object) {};
|
|
87
|
+
|
|
88
|
+
@ObjectType()
|
|
89
|
+
export class ExpressionRendered extends ExpressionGeneric(String) {
|
|
90
|
+
@Field()
|
|
91
|
+
language: LanguageRef
|
|
92
|
+
|
|
93
|
+
@Field()
|
|
94
|
+
icon: Icon
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export function isExpression(e: any): boolean {
|
|
98
|
+
return e && e.author && e.timestamp && e.data
|
|
99
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ApolloClient, gql } from "@apollo/client/core";
|
|
2
|
+
import { InteractionCall, InteractionMeta } from "../language/Language";
|
|
3
|
+
import unwrapApolloResult from "../unwrapApolloResult";
|
|
4
|
+
import { ExpressionRendered } from "./Expression";
|
|
5
|
+
|
|
6
|
+
export class ExpressionClient {
|
|
7
|
+
#apolloClient: ApolloClient<any>
|
|
8
|
+
|
|
9
|
+
constructor(client: ApolloClient<any>) {
|
|
10
|
+
this.#apolloClient = client
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async get(url: string): Promise<ExpressionRendered> {
|
|
14
|
+
const { expression } = unwrapApolloResult(await this.#apolloClient.query({
|
|
15
|
+
query: gql`query expression($url: String!) {
|
|
16
|
+
expression(url: $url) {
|
|
17
|
+
author
|
|
18
|
+
timestamp
|
|
19
|
+
data
|
|
20
|
+
language {
|
|
21
|
+
address
|
|
22
|
+
}
|
|
23
|
+
proof {
|
|
24
|
+
valid
|
|
25
|
+
invalid
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}`,
|
|
29
|
+
variables: { url }
|
|
30
|
+
}))
|
|
31
|
+
return expression
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getMany(urls: string[]): Promise<ExpressionRendered[]> {
|
|
35
|
+
const { expressionMany } = unwrapApolloResult(await this.#apolloClient.query({
|
|
36
|
+
query: gql`query expressionMany($urls: [String!]!) {
|
|
37
|
+
expressionMany(urls: $urls) {
|
|
38
|
+
author
|
|
39
|
+
timestamp
|
|
40
|
+
data
|
|
41
|
+
language {
|
|
42
|
+
address
|
|
43
|
+
}
|
|
44
|
+
proof {
|
|
45
|
+
valid
|
|
46
|
+
invalid
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}`,
|
|
50
|
+
variables: { urls }
|
|
51
|
+
}))
|
|
52
|
+
return expressionMany
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async getRaw(url: string): Promise<string> {
|
|
56
|
+
const { expressionRaw } = unwrapApolloResult(await this.#apolloClient.query({
|
|
57
|
+
query: gql`query expressionRaw($url: String!) {
|
|
58
|
+
expressionRaw(url: $url)
|
|
59
|
+
}`,
|
|
60
|
+
variables: { url }
|
|
61
|
+
}))
|
|
62
|
+
return expressionRaw
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async create(content: any, languageAddress: string): Promise<string> {
|
|
66
|
+
content = JSON.stringify(content)
|
|
67
|
+
const { expressionCreate } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
68
|
+
mutation: gql`mutation expressionCreate($content: String!, $languageAddress: String!){
|
|
69
|
+
expressionCreate(content: $content, languageAddress: $languageAddress)
|
|
70
|
+
}`,
|
|
71
|
+
variables: { content, languageAddress }
|
|
72
|
+
}))
|
|
73
|
+
return expressionCreate
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async interactions(url: string): Promise<InteractionMeta[]> {
|
|
77
|
+
const { expressionInteractions } = unwrapApolloResult(await this.#apolloClient.query({
|
|
78
|
+
query: gql`query expressionInteractions($url: String!) {
|
|
79
|
+
expressionInteractions(url: $url) {
|
|
80
|
+
label
|
|
81
|
+
name
|
|
82
|
+
parameters { name, type }
|
|
83
|
+
}
|
|
84
|
+
}`,
|
|
85
|
+
variables: { url }
|
|
86
|
+
}))
|
|
87
|
+
return expressionInteractions
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async interact(url: string, interactionCall: InteractionCall): Promise<string|null> {
|
|
91
|
+
const { expressionInteract } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
92
|
+
mutation: gql`mutation expressionInteract($url: String!, $interactionCall: InteractionCall!){
|
|
93
|
+
expressionInteract(url: $url, interactionCall: $interactionCall)
|
|
94
|
+
}`,
|
|
95
|
+
variables: { url, interactionCall }
|
|
96
|
+
}))
|
|
97
|
+
return expressionInteract
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Address } from '../Address';
|
|
2
|
+
import { LanguageRef } from '../language/LanguageRef';
|
|
3
|
+
import { Field, ObjectType } from "type-graphql";
|
|
4
|
+
|
|
5
|
+
// Expression address + unique Language ID = global expression URL
|
|
6
|
+
@ObjectType()
|
|
7
|
+
export class ExpressionRef {
|
|
8
|
+
@Field()
|
|
9
|
+
language: LanguageRef;
|
|
10
|
+
|
|
11
|
+
@Field()
|
|
12
|
+
expression: Address;
|
|
13
|
+
|
|
14
|
+
constructor(lang: LanguageRef, expr: Address) {
|
|
15
|
+
this.language = lang
|
|
16
|
+
this.expression = expr
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Creates unique expression URI like this:
|
|
21
|
+
// expr:Qm3490gfwe489hf34:Qm90ghjoaw4iehioefwe4ort
|
|
22
|
+
export function exprRef2String(ref: ExpressionRef): string {
|
|
23
|
+
if(ref.language.address === 'did')
|
|
24
|
+
return ref.expression.toString()
|
|
25
|
+
else
|
|
26
|
+
return `${ref.language.address}://${ref.expression}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseExprUrl(url: string): ExpressionRef {
|
|
30
|
+
if(url.startsWith("literal://")) {
|
|
31
|
+
const languageRef = new LanguageRef()
|
|
32
|
+
languageRef.address = 'literal'
|
|
33
|
+
languageRef.name = 'literal'
|
|
34
|
+
const content = url.substring(10)
|
|
35
|
+
return new ExpressionRef(languageRef, content)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const URIregexp = /^([^:^\s]+):\/\/([\s\S]+)$/
|
|
39
|
+
const URImatches = URIregexp.exec(url)
|
|
40
|
+
|
|
41
|
+
if(URImatches && URImatches.length == 3) {
|
|
42
|
+
const language = URImatches[1]
|
|
43
|
+
const expression = URImatches[2]
|
|
44
|
+
|
|
45
|
+
const languageRef = new LanguageRef()
|
|
46
|
+
languageRef.address = language
|
|
47
|
+
|
|
48
|
+
const ref = new ExpressionRef(languageRef, expression)
|
|
49
|
+
return ref
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const DIDregexp = /^did:([^\s]+)$/
|
|
53
|
+
const DIDmatches = DIDregexp.exec(url)
|
|
54
|
+
|
|
55
|
+
if(DIDmatches && DIDmatches.length == 2) {
|
|
56
|
+
const languageRef = new LanguageRef()
|
|
57
|
+
languageRef.address = 'did'
|
|
58
|
+
const ref = new ExpressionRef(languageRef, url)
|
|
59
|
+
return ref
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw new Error("Couldn't parse string as expression URL or DID: " + url)
|
|
63
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Arg, Mutation, Query, Resolver } from "type-graphql";
|
|
2
|
+
import { LanguageRef } from "../language/LanguageRef";
|
|
3
|
+
import { ExpressionProof, ExpressionRendered } from "./Expression";
|
|
4
|
+
import { InteractionCall, InteractionMeta } from "../language/Language"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const e = new ExpressionRendered()
|
|
8
|
+
e.author = 'did:ad4m:test'
|
|
9
|
+
e.timestamp = Date.now().toString()
|
|
10
|
+
e.proof = new ExpressionProof('', '')
|
|
11
|
+
e.data = JSON.stringify({ type: 'test expression', content: 'test'})
|
|
12
|
+
e.language = new LanguageRef('test-language-address')
|
|
13
|
+
const testExpression = e
|
|
14
|
+
@Resolver()
|
|
15
|
+
export default class ExpressionResolver {
|
|
16
|
+
@Query(returns => ExpressionRendered, {nullable: true})
|
|
17
|
+
expression(@Arg('url') url: string): ExpressionRendered {
|
|
18
|
+
if(url === 'neighbourhood://Qm123') {
|
|
19
|
+
return testExpression
|
|
20
|
+
} else {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Query(returns => [ExpressionRendered], {nullable: "items"})
|
|
26
|
+
expressionMany(@Arg('urls', type => [String]) urls: string[]): (ExpressionRendered | null)[] {
|
|
27
|
+
return [testExpression, null]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Query(returns => String, {nullable: true})
|
|
31
|
+
expressionRaw(@Arg('url') url: string): string {
|
|
32
|
+
if(url === 'neighbourhood://Qm123') {
|
|
33
|
+
return JSON.stringify(testExpression)
|
|
34
|
+
} else {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Mutation(returns => String)
|
|
40
|
+
expressionCreate(
|
|
41
|
+
@Arg('content') content: string,
|
|
42
|
+
@Arg('languageAddress') languageAddress: string
|
|
43
|
+
): string {
|
|
44
|
+
return "Qm1234"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Query(returns => [InteractionMeta])
|
|
48
|
+
expressionInteractions(@Arg('url') url: string): InteractionMeta[] {
|
|
49
|
+
const interaction = {
|
|
50
|
+
label: "Add a comment",
|
|
51
|
+
name: "add_comment",
|
|
52
|
+
parameters: [{name: 'comment', type: 'string'}]
|
|
53
|
+
} as InteractionMeta
|
|
54
|
+
return [interaction]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Mutation(returns => String, {nullable: true})
|
|
58
|
+
expressionInteract(
|
|
59
|
+
@Arg('url') url: string,
|
|
60
|
+
@Arg('interactionCall') interactionCall: InteractionCall
|
|
61
|
+
): string|null {
|
|
62
|
+
return "test result"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export * from "./Ad4mClient"
|
|
2
|
+
export * from "./Address";
|
|
3
|
+
export * from "./agent/Agent";
|
|
4
|
+
export * from "./agent/AgentStatus";
|
|
5
|
+
export * from "./Exception";
|
|
6
|
+
export * from "./expression/Expression";
|
|
7
|
+
export * from "./expression/ExpressionRef";
|
|
8
|
+
export * from "./language/Icon";
|
|
9
|
+
export * from "./language/Language";
|
|
10
|
+
export * from "./language/LanguageRef";
|
|
11
|
+
export * from "./language/LanguageContext";
|
|
12
|
+
export * from "./language/LanguageHandle";
|
|
13
|
+
export * from "./language/LanguageMeta";
|
|
14
|
+
export * from "./links/Links";
|
|
15
|
+
export * from "./Literal";
|
|
16
|
+
export * from "./perspectives/Perspective";
|
|
17
|
+
export * from "./perspectives/PerspectiveHandle";
|
|
18
|
+
export * from "./perspectives/PerspectiveProxy";
|
|
19
|
+
export * from "./perspectives/PerspectiveDiff";
|
|
20
|
+
export * from "./perspectives/LinkQuery";
|
|
21
|
+
export * from "./SmartLiteral";
|
|
22
|
+
export * from "./subject/SDNADecorators";
|
|
23
|
+
export * from "./subject/Subject";
|
|
24
|
+
export * from "./neighbourhood/Neighbourhood";
|
|
25
|
+
export * from "./neighbourhood/NeighbourhoodProxy";
|
|
26
|
+
export * from "./typeDefs";
|
|
27
|
+
export * from "./DID";
|
|
28
|
+
export * from "./utils";
|
|
29
|
+
export * from './subject/SubjectEntity'
|
|
30
|
+
export * from "./agent/AgentClient";
|