@coasys/ad4m 0.8.0-fix
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 +8165 -0
- package/lib/index.js +8130 -0
- package/lib/shims/reflect-metadata.d.ts +0 -0
- package/lib/shims/reflect-metadata.js +0 -0
- package/lib/shims/type-graphql.d.ts +32 -0
- package/lib/shims/type-graphql.js +70 -0
- package/lib/src/Ad4mClient.d.ts +26 -0
- package/lib/src/Ad4mClient.js +66 -0
- package/lib/src/Address.d.ts +1 -0
- package/lib/src/Address.js +1 -0
- package/lib/src/DID.d.ts +1 -0
- package/lib/src/DID.js +1 -0
- package/lib/src/Exception.d.ts +6 -0
- package/lib/src/Exception.js +7 -0
- package/lib/src/Literal.d.ts +7 -0
- package/lib/src/Literal.js +76 -0
- package/lib/src/PubSub.d.ts +14 -0
- package/lib/src/PubSub.js +14 -0
- package/lib/src/SmartLiteral.d.ts +12 -0
- package/lib/src/SmartLiteral.js +74 -0
- package/lib/src/agent/Agent.d.ts +104 -0
- package/lib/src/agent/Agent.js +337 -0
- package/lib/src/agent/AgentClient.d.ts +57 -0
- package/lib/src/agent/AgentClient.js +431 -0
- package/lib/src/agent/AgentResolver.d.ts +30 -0
- package/lib/src/agent/AgentResolver.js +325 -0
- package/lib/src/agent/AgentStatus.d.ts +8 -0
- package/lib/src/agent/AgentStatus.js +61 -0
- package/lib/src/buildSchema.d.ts +1 -0
- package/lib/src/buildSchema.js +36 -0
- package/lib/src/expression/Expression.d.ts +28 -0
- package/lib/src/expression/Expression.js +143 -0
- package/lib/src/expression/ExpressionClient.d.ts +13 -0
- package/lib/src/expression/ExpressionClient.js +102 -0
- package/lib/src/expression/ExpressionRef.d.ts +9 -0
- package/lib/src/expression/ExpressionRef.js +67 -0
- package/lib/src/expression/ExpressionResolver.d.ts +10 -0
- package/lib/src/expression/ExpressionResolver.js +106 -0
- package/lib/src/index.d.ts +30 -0
- package/lib/src/index.js +30 -0
- package/lib/src/jestSetup.d.ts +1 -0
- package/lib/src/jestSetup.js +1 -0
- package/lib/src/language/Icon.d.ts +4 -0
- package/lib/src/language/Icon.js +24 -0
- package/lib/src/language/Language.d.ts +195 -0
- package/lib/src/language/Language.js +79 -0
- package/lib/src/language/LanguageClient.d.ts +17 -0
- package/lib/src/language/LanguageClient.js +137 -0
- package/lib/src/language/LanguageContext.d.ts +37 -0
- package/lib/src/language/LanguageContext.js +2 -0
- package/lib/src/language/LanguageHandle.d.ts +9 -0
- package/lib/src/language/LanguageHandle.js +41 -0
- package/lib/src/language/LanguageMeta.d.ts +35 -0
- package/lib/src/language/LanguageMeta.js +89 -0
- package/lib/src/language/LanguageRef.d.ts +6 -0
- package/lib/src/language/LanguageRef.js +30 -0
- package/lib/src/language/LanguageResolver.d.ts +19 -0
- package/lib/src/language/LanguageResolver.js +143 -0
- package/lib/src/links/Links.d.ts +39 -0
- package/lib/src/links/Links.js +148 -0
- package/lib/src/links/Links.test.d.ts +1 -0
- package/lib/src/links/Links.test.js +33 -0
- package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -0
- package/lib/src/neighbourhood/Neighbourhood.js +38 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -0
- package/lib/src/perspectives/LinkQuery.d.ts +11 -0
- package/lib/src/perspectives/LinkQuery.js +80 -0
- package/lib/src/perspectives/Perspective.d.ts +38 -0
- package/lib/src/perspectives/Perspective.js +144 -0
- package/lib/src/perspectives/Perspective.test.d.ts +1 -0
- package/lib/src/perspectives/Perspective.test.js +20 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +54 -0
- package/lib/src/perspectives/PerspectiveClient.js +410 -0
- package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -0
- package/lib/src/perspectives/PerspectiveDiff.js +33 -0
- package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -0
- package/lib/src/perspectives/PerspectiveHandle.js +59 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -0
- package/lib/src/perspectives/PerspectiveProxy.js +540 -0
- package/lib/src/perspectives/PerspectiveResolver.d.ts +37 -0
- package/lib/src/perspectives/PerspectiveResolver.js +362 -0
- package/lib/src/runtime/RuntimeClient.d.ts +33 -0
- package/lib/src/runtime/RuntimeClient.js +263 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +47 -0
- package/lib/src/runtime/RuntimeResolver.js +328 -0
- package/lib/src/schema.gql +382 -0
- package/lib/src/subject/SDNADecorators.d.ts +45 -0
- package/lib/src/subject/SDNADecorators.js +250 -0
- package/lib/src/subject/Subject.d.ts +7 -0
- package/lib/src/subject/Subject.js +160 -0
- package/lib/src/subject/SubjectEntity.d.ts +31 -0
- package/lib/src/subject/SubjectEntity.js +250 -0
- package/lib/src/subject/util.d.ts +12 -0
- package/lib/src/subject/util.js +73 -0
- package/lib/src/typeDefs.d.ts +1 -0
- package/lib/src/typeDefs.js +379 -0
- package/lib/src/unwrapApolloResult.d.ts +2 -0
- package/lib/src/unwrapApolloResult.js +12 -0
- package/lib/src/utils.d.ts +2 -0
- package/lib/src/utils.js +21 -0
- package/package.json +61 -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
- package/yarn-error.log +22814 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ApolloClient } from '@apollo/client/core'
|
|
2
|
+
import { AgentClient } from './agent/AgentClient'
|
|
3
|
+
import { LanguageClient } from './language/LanguageClient'
|
|
4
|
+
import { NeighbourhoodClient } from './neighbourhood/NeighbourhoodClient'
|
|
5
|
+
import { PerspectiveClient } from './perspectives/PerspectiveClient'
|
|
6
|
+
import { RuntimeClient } from './runtime/RuntimeClient'
|
|
7
|
+
import { ExpressionClient } from './expression/ExpressionClient'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Client for the Ad4m interface wrapping GraphQL queryies
|
|
11
|
+
* for convenient use in user facing code.
|
|
12
|
+
*
|
|
13
|
+
* Aggregates the six sub-clients:
|
|
14
|
+
* AgentClient, ExpressionClient, LanguageClient,
|
|
15
|
+
* NeighbourhoodClient, PerspectiveClient and RuntimeClient
|
|
16
|
+
* for the respective functionality.
|
|
17
|
+
*/
|
|
18
|
+
export class Ad4mClient {
|
|
19
|
+
#apolloClient: ApolloClient<any>
|
|
20
|
+
#agentClient: AgentClient
|
|
21
|
+
#expressionClient: ExpressionClient
|
|
22
|
+
#languageClient: LanguageClient
|
|
23
|
+
#neighbourhoodClient: NeighbourhoodClient
|
|
24
|
+
#perspectiveClient: PerspectiveClient
|
|
25
|
+
#runtimeClient: RuntimeClient
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
29
|
+
this.#apolloClient = client
|
|
30
|
+
this.#agentClient = new AgentClient(this.#apolloClient, subscribe)
|
|
31
|
+
this.#expressionClient = new ExpressionClient(this.#apolloClient)
|
|
32
|
+
this.#languageClient = new LanguageClient(this.#apolloClient)
|
|
33
|
+
this.#neighbourhoodClient = new NeighbourhoodClient(this.#apolloClient)
|
|
34
|
+
this.#perspectiveClient = new PerspectiveClient(this.#apolloClient, subscribe)
|
|
35
|
+
this.#perspectiveClient.setExpressionClient(this.#expressionClient)
|
|
36
|
+
this.#perspectiveClient.setNeighbourhoodClient(this.#neighbourhoodClient)
|
|
37
|
+
this.#runtimeClient = new RuntimeClient(this.#apolloClient, subscribe)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get agent(): AgentClient {
|
|
41
|
+
return this.#agentClient
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get expression(): ExpressionClient {
|
|
45
|
+
return this.#expressionClient
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get languages(): LanguageClient {
|
|
49
|
+
return this.#languageClient
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get neighbourhood(): NeighbourhoodClient {
|
|
53
|
+
return this.#neighbourhoodClient
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get perspective(): PerspectiveClient {
|
|
57
|
+
return this.#perspectiveClient
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get runtime(): RuntimeClient {
|
|
61
|
+
return this.#runtimeClient
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/Address.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Address = string;
|
package/src/DID.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DID = string;
|
package/src/Exception.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Literal } from './Literal'
|
|
2
|
+
|
|
3
|
+
describe("Literal", () => {
|
|
4
|
+
it("can handle strings", () => {
|
|
5
|
+
const testString = "test string"
|
|
6
|
+
const testUrl = "literal://string:test%20string"
|
|
7
|
+
expect(Literal.from(testString).toUrl()).toBe(testUrl)
|
|
8
|
+
expect(Literal.fromUrl(testUrl).get()).toBe(testString)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it("can handle numbers", () => {
|
|
12
|
+
const testNumber = 3.1415
|
|
13
|
+
const testUrl = "literal://number:3.1415"
|
|
14
|
+
expect(Literal.from(testNumber).toUrl()).toBe(testUrl)
|
|
15
|
+
expect(Literal.fromUrl(testUrl).get()).toBe(testNumber)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("can handle objects", () => {
|
|
19
|
+
const testObject = {testNumber: "1337", testString: "test"}
|
|
20
|
+
const testUrl = "literal://json:%7B%22testNumber%22%3A%221337%22%2C%22testString%22%3A%22test%22%7D"
|
|
21
|
+
expect(Literal.from(testObject).toUrl()).toBe(testUrl)
|
|
22
|
+
expect(Literal.fromUrl(testUrl).get()).toStrictEqual(testObject)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it("can handle special characters", () => {
|
|
26
|
+
const testString = "message(X) :- triple('ad4m://self', _, X)."
|
|
27
|
+
const testUrl = "literal://string:message%28X%29%20%3A-%20triple%28%27ad4m%3A%2F%2Fself%27%2C%20_%2C%20X%29."
|
|
28
|
+
expect(Literal.from(testString).toUrl()).toBe(testUrl)
|
|
29
|
+
expect(Literal.fromUrl(testUrl).get()).toBe(testString)
|
|
30
|
+
})
|
|
31
|
+
})
|
package/src/Literal.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function encodeRFC3986URIComponent(str) {
|
|
2
|
+
return encodeURIComponent(str)
|
|
3
|
+
.replace(
|
|
4
|
+
/[!'()*]/g,
|
|
5
|
+
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Literal {
|
|
10
|
+
#literal?: any
|
|
11
|
+
#url?: string
|
|
12
|
+
|
|
13
|
+
public static fromUrl(url: string) {
|
|
14
|
+
if(!url || !url.startsWith("literal://"))
|
|
15
|
+
throw new Error("Can't create Literal from non-literal URL")
|
|
16
|
+
const l = new Literal()
|
|
17
|
+
l.#url = url
|
|
18
|
+
return l
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static from(literal: any) {
|
|
22
|
+
const l = new Literal()
|
|
23
|
+
l.#literal = literal
|
|
24
|
+
return l
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toUrl(): string {
|
|
28
|
+
if(this.#url && !this.#literal)
|
|
29
|
+
return this.#url
|
|
30
|
+
if(!this.#url && !this.#literal)
|
|
31
|
+
throw new Error("Can't turn empty Literal into URL")
|
|
32
|
+
|
|
33
|
+
let encoded
|
|
34
|
+
switch(typeof this.#literal) {
|
|
35
|
+
case 'string':
|
|
36
|
+
encoded = `string:${encodeRFC3986URIComponent(this.#literal)}`
|
|
37
|
+
break;
|
|
38
|
+
case 'number':
|
|
39
|
+
encoded = `number:${encodeRFC3986URIComponent(this.#literal)}`
|
|
40
|
+
break;
|
|
41
|
+
case 'object':
|
|
42
|
+
encoded = `json:${encodeRFC3986URIComponent(JSON.stringify(this.#literal))}`
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return `literal://${encoded}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get(): any {
|
|
50
|
+
if(this.#literal)
|
|
51
|
+
return this.#literal
|
|
52
|
+
|
|
53
|
+
if(!this.#url)
|
|
54
|
+
throw new Error("Can't render empty Literal")
|
|
55
|
+
|
|
56
|
+
if(!this.#url.startsWith("literal://"))
|
|
57
|
+
throw new Error("Can't render Literal from non-literal URL")
|
|
58
|
+
|
|
59
|
+
// get rid of "literal://"
|
|
60
|
+
const body = this.#url.substring(10)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if(body.startsWith("string:")) {
|
|
64
|
+
return decodeURIComponent(body.substring(7))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if(body.startsWith("number:")) {
|
|
68
|
+
const numberString = body.substring(7)
|
|
69
|
+
return parseFloat(numberString)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(body.startsWith("json:")) {
|
|
73
|
+
const json = body.substring(5)
|
|
74
|
+
return JSON.parse(decodeURIComponent(json))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
throw new Error(`Can't parse unknown literal: ${body}`)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
}
|
package/src/PubSub.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const AGENT_UPDATED = 'agent-updated-topic'
|
|
2
|
+
export const AGENT_STATUS_CHANGED = 'agent-status-changed-topic'
|
|
3
|
+
export const RUNTIME_MESSAGED_RECEIVED_TOPIC = 'runtime-messaged-received-topic'
|
|
4
|
+
export const PERSPECTIVE_ADDED_TOPIC = 'perspective-added-topic'
|
|
5
|
+
export const PERSPECTIVE_UPDATED_TOPIC = 'perspective-updated-topic'
|
|
6
|
+
export const PERSPECTIVE_REMOVED_TOPIC = 'perspective-removed-topic'
|
|
7
|
+
export const LINK_ADDED_TOPIC = 'link-added-topic'
|
|
8
|
+
export const LINK_REMOVED_TOPIC = 'link-removed-topic'
|
|
9
|
+
export const LINK_UDATED_TOPIC = 'link-updated-topic'
|
|
10
|
+
export const SIGNAL = "signal"
|
|
11
|
+
export const EXCEPTION_OCCURRED_TOPIC = "exception-occurred-topic"
|
|
12
|
+
export const NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC = "neighbourhood-signal-received-topic"
|
|
13
|
+
export const PERSPECTIVE_SYNC_STATE_CHANGE = "perspective-sync-state-change"
|
|
14
|
+
export const APPS_CHANGED = "apps-changed"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Link } from "./links/Links";
|
|
2
|
+
import { Literal } from "./Literal";
|
|
3
|
+
import { LinkQuery } from "./perspectives/LinkQuery";
|
|
4
|
+
import { PerspectiveProxy } from "./perspectives/PerspectiveProxy";
|
|
5
|
+
|
|
6
|
+
export const SMART_LITERAL_CONTENT_PREDICATE = "smart_literal://content"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function makeRandomStringID(length: number): string {
|
|
10
|
+
let result = '';
|
|
11
|
+
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
12
|
+
let charactersLength = characters.length;
|
|
13
|
+
for (let i = 0; i < length; i++) {
|
|
14
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SmartLiteral {
|
|
20
|
+
#perspective: PerspectiveProxy
|
|
21
|
+
#base: string
|
|
22
|
+
|
|
23
|
+
constructor(perspective: PerspectiveProxy, base: string) {
|
|
24
|
+
this.#perspective = perspective
|
|
25
|
+
this.#base = base
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get base() {
|
|
29
|
+
return this.#base
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static async create(perspective: PerspectiveProxy, literal: any): Promise<SmartLiteral> {
|
|
33
|
+
const base = Literal.from(makeRandomStringID(10)).toUrl()
|
|
34
|
+
const smartLiteral = new SmartLiteral(perspective, base)
|
|
35
|
+
await smartLiteral.set(literal)
|
|
36
|
+
return smartLiteral
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static async isSmartLiteralBase(perspective: PerspectiveProxy, base: string): Promise<boolean> {
|
|
40
|
+
let links = await perspective.get(new LinkQuery({
|
|
41
|
+
source: base,
|
|
42
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
43
|
+
}))
|
|
44
|
+
return links.length > 0
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static async getAllSmartLiterals(perspective: PerspectiveProxy): Promise<SmartLiteral[]> {
|
|
48
|
+
let links = await perspective.get(new LinkQuery({
|
|
49
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
50
|
+
}))
|
|
51
|
+
return links.map(link => new SmartLiteral(perspective, link.data.source))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async get(): Promise<any> {
|
|
55
|
+
let link = await this.#perspective.getSingleTarget(new LinkQuery({
|
|
56
|
+
source: this.#base,
|
|
57
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE
|
|
58
|
+
}))
|
|
59
|
+
|
|
60
|
+
if(!link) {
|
|
61
|
+
throw `No content for smart literal ${this.#base}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return Literal.fromUrl(link).get()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async set(content: any) {
|
|
68
|
+
let literal = Literal.from(content)
|
|
69
|
+
await this.#perspective.setSingleTarget(new Link({
|
|
70
|
+
source: this.#base,
|
|
71
|
+
predicate: SMART_LITERAL_CONTENT_PREDICATE,
|
|
72
|
+
target: literal.toUrl()
|
|
73
|
+
}))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Field, ObjectType, InputType } from "type-graphql";
|
|
2
|
+
import { Perspective } from "../perspectives/Perspective";
|
|
3
|
+
import { ExpressionGeneric } from "../expression/Expression";
|
|
4
|
+
|
|
5
|
+
/** AD4M's representation of an Agent
|
|
6
|
+
*
|
|
7
|
+
* AD4M Agents are build around DIDs, which are used to identify and authenticate the Agent.
|
|
8
|
+
* Conceptually, an Agent is regarded as something that can speak and that can listen.
|
|
9
|
+
*
|
|
10
|
+
* Agents speak by creating Expressions in AD4M Languages which are signed by the Agent's DID key,
|
|
11
|
+
* And they also speak (broadcast) by putting semantic statements into their public "Agent Perspective".
|
|
12
|
+
* They listen (can receive messages) through their "direct message Language".
|
|
13
|
+
*
|
|
14
|
+
* These three aspects are represented by the three fields of this class.
|
|
15
|
+
*
|
|
16
|
+
* This class is used as format for the Expressions in the Agent language.
|
|
17
|
+
* Since AD4M treats DID URIs as addresses for the Agent Language,
|
|
18
|
+
* DIDs are resolved to Expressions that are objects of this class.
|
|
19
|
+
* Thus, this is how agents see (other) agents.
|
|
20
|
+
*/
|
|
21
|
+
@ObjectType()
|
|
22
|
+
export class Agent {
|
|
23
|
+
/** The DID of the Agent
|
|
24
|
+
* All epxressions authored by them are signed with the keys mentioned
|
|
25
|
+
* in the DID document behind this DID URI.
|
|
26
|
+
*/
|
|
27
|
+
@Field()
|
|
28
|
+
did: string;
|
|
29
|
+
|
|
30
|
+
/** The Perspective that holds the public-facing semantics/statements of the Agent
|
|
31
|
+
* Holds and shares a Perspective that links all information
|
|
32
|
+
* this agent wants to offer as public-facing semantics.
|
|
33
|
+
* This should be used for any kind of user profile information.
|
|
34
|
+
*/
|
|
35
|
+
@Field((type) => Perspective, { nullable: true })
|
|
36
|
+
perspective?: Perspective;
|
|
37
|
+
|
|
38
|
+
/** Address of the Language by which the Agent will receive DMs */
|
|
39
|
+
@Field({ nullable: true })
|
|
40
|
+
directMessageLanguage?: string;
|
|
41
|
+
|
|
42
|
+
constructor(did: string, perspective?: Perspective) {
|
|
43
|
+
this.did = did;
|
|
44
|
+
if (perspective) {
|
|
45
|
+
this.perspective = perspective;
|
|
46
|
+
} else {
|
|
47
|
+
this.perspective = new Perspective();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ObjectType()
|
|
53
|
+
export class AgentExpression extends ExpressionGeneric(Agent) {}
|
|
54
|
+
|
|
55
|
+
@ObjectType()
|
|
56
|
+
export class EntanglementProof {
|
|
57
|
+
@Field()
|
|
58
|
+
did: string;
|
|
59
|
+
|
|
60
|
+
@Field()
|
|
61
|
+
didSigningKeyId: string;
|
|
62
|
+
|
|
63
|
+
@Field()
|
|
64
|
+
deviceKeyType: string;
|
|
65
|
+
|
|
66
|
+
@Field()
|
|
67
|
+
deviceKey: string;
|
|
68
|
+
|
|
69
|
+
@Field()
|
|
70
|
+
deviceKeySignedByDid: string;
|
|
71
|
+
|
|
72
|
+
@Field({ nullable: true })
|
|
73
|
+
didSignedByDeviceKey?: string;
|
|
74
|
+
|
|
75
|
+
constructor(
|
|
76
|
+
did: string,
|
|
77
|
+
didSigningKeyId: string,
|
|
78
|
+
deviceKeyType: string,
|
|
79
|
+
deviceKey: string,
|
|
80
|
+
deviceKeySignedByDid: string,
|
|
81
|
+
didSignedByDeviceKey?: string
|
|
82
|
+
) {
|
|
83
|
+
this.did = did;
|
|
84
|
+
this.didSigningKeyId = didSigningKeyId;
|
|
85
|
+
this.deviceKeyType = deviceKeyType;
|
|
86
|
+
this.deviceKey = deviceKey;
|
|
87
|
+
this.deviceKeySignedByDid = deviceKeySignedByDid;
|
|
88
|
+
this.didSignedByDeviceKey = didSignedByDeviceKey;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@InputType()
|
|
93
|
+
export class EntanglementProofInput {
|
|
94
|
+
@Field()
|
|
95
|
+
did: string;
|
|
96
|
+
|
|
97
|
+
@Field()
|
|
98
|
+
didSigningKeyId: string;
|
|
99
|
+
|
|
100
|
+
@Field()
|
|
101
|
+
deviceKeyType: string;
|
|
102
|
+
|
|
103
|
+
@Field()
|
|
104
|
+
deviceKey: string;
|
|
105
|
+
|
|
106
|
+
@Field()
|
|
107
|
+
deviceKeySignedByDid: string;
|
|
108
|
+
|
|
109
|
+
@Field()
|
|
110
|
+
didSignedByDeviceKey: string;
|
|
111
|
+
|
|
112
|
+
constructor(
|
|
113
|
+
did: string,
|
|
114
|
+
didSigningKeyId: string,
|
|
115
|
+
deviceKeyType: string,
|
|
116
|
+
deviceKey: string,
|
|
117
|
+
deviceKeySignedByDid: string,
|
|
118
|
+
didSignedByDeviceKey: string
|
|
119
|
+
) {
|
|
120
|
+
this.did = did;
|
|
121
|
+
this.didSigningKeyId = didSigningKeyId;
|
|
122
|
+
this.deviceKeyType = deviceKeyType;
|
|
123
|
+
this.deviceKey = deviceKey;
|
|
124
|
+
this.deviceKeySignedByDid = deviceKeySignedByDid;
|
|
125
|
+
this.didSignedByDeviceKey = didSignedByDeviceKey;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ObjectType()
|
|
130
|
+
export class AgentSignature {
|
|
131
|
+
@Field()
|
|
132
|
+
signature: string;
|
|
133
|
+
|
|
134
|
+
@Field()
|
|
135
|
+
publicKey: string;
|
|
136
|
+
|
|
137
|
+
constructor(signature: string, publicKey: string) {
|
|
138
|
+
this.signature = signature;
|
|
139
|
+
this.publicKey = publicKey;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@ObjectType()
|
|
144
|
+
export class Resource {
|
|
145
|
+
@Field()
|
|
146
|
+
domain: string;
|
|
147
|
+
|
|
148
|
+
@Field((type) => [String])
|
|
149
|
+
pointers: string[];
|
|
150
|
+
|
|
151
|
+
constructor(domain: string, pointers: string[]) {
|
|
152
|
+
this.domain = domain;
|
|
153
|
+
this.pointers = pointers;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@ObjectType()
|
|
158
|
+
export class Capability {
|
|
159
|
+
@Field((type) => Resource)
|
|
160
|
+
with: Resource;
|
|
161
|
+
|
|
162
|
+
@Field((type) => [String])
|
|
163
|
+
can: string[];
|
|
164
|
+
|
|
165
|
+
constructor(withF: Resource, can: string[]) {
|
|
166
|
+
this.with = withF;
|
|
167
|
+
this.can = can;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ObjectType()
|
|
172
|
+
export class AuthInfo {
|
|
173
|
+
@Field()
|
|
174
|
+
appName: string;
|
|
175
|
+
|
|
176
|
+
@Field()
|
|
177
|
+
appDesc: string;
|
|
178
|
+
|
|
179
|
+
@Field()
|
|
180
|
+
appUrl: string;
|
|
181
|
+
|
|
182
|
+
@Field({nullable: true})
|
|
183
|
+
appIconPath?: string;
|
|
184
|
+
|
|
185
|
+
@Field((type) => [Capability])
|
|
186
|
+
capabilities: Capability[];
|
|
187
|
+
|
|
188
|
+
constructor(
|
|
189
|
+
appName: string,
|
|
190
|
+
appDesc: string,
|
|
191
|
+
appUrl: string,
|
|
192
|
+
capabilities: Capability[],
|
|
193
|
+
appIconPath?: string
|
|
194
|
+
) {
|
|
195
|
+
this.appName = appName;
|
|
196
|
+
this.appDesc = appDesc;
|
|
197
|
+
this.appIconPath = appIconPath;
|
|
198
|
+
this.appUrl = appUrl;
|
|
199
|
+
this.capabilities = capabilities;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@ObjectType()
|
|
204
|
+
export class Apps {
|
|
205
|
+
@Field()
|
|
206
|
+
requestId: string;
|
|
207
|
+
|
|
208
|
+
@Field()
|
|
209
|
+
token: string;
|
|
210
|
+
|
|
211
|
+
@Field({ nullable: true })
|
|
212
|
+
revoked?: boolean;
|
|
213
|
+
|
|
214
|
+
@Field()
|
|
215
|
+
auth: AuthInfo;
|
|
216
|
+
|
|
217
|
+
constructor(
|
|
218
|
+
requestId: string,
|
|
219
|
+
auth: AuthInfo,
|
|
220
|
+
token: string,
|
|
221
|
+
revoked?: boolean
|
|
222
|
+
) {
|
|
223
|
+
this.requestId = requestId;
|
|
224
|
+
this.auth = auth;
|
|
225
|
+
this.token = token;
|
|
226
|
+
this.revoked = revoked;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@InputType()
|
|
231
|
+
export class ResourceInput {
|
|
232
|
+
@Field()
|
|
233
|
+
domain: string;
|
|
234
|
+
|
|
235
|
+
@Field((type) => [String])
|
|
236
|
+
pointers: string[];
|
|
237
|
+
|
|
238
|
+
constructor(domain: string, pointers: string[]) {
|
|
239
|
+
this.domain = domain;
|
|
240
|
+
this.pointers = pointers;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@InputType()
|
|
245
|
+
export class CapabilityInput {
|
|
246
|
+
@Field((type) => ResourceInput)
|
|
247
|
+
with: ResourceInput;
|
|
248
|
+
|
|
249
|
+
@Field((type) => [String])
|
|
250
|
+
can: string[];
|
|
251
|
+
|
|
252
|
+
constructor(withF: ResourceInput, can: string[]) {
|
|
253
|
+
this.with = withF;
|
|
254
|
+
this.can = can;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@InputType()
|
|
259
|
+
export class AuthInfoInput {
|
|
260
|
+
@Field()
|
|
261
|
+
appName: string;
|
|
262
|
+
|
|
263
|
+
@Field()
|
|
264
|
+
appDesc: string;
|
|
265
|
+
|
|
266
|
+
@Field()
|
|
267
|
+
appDomain: string;
|
|
268
|
+
|
|
269
|
+
@Field({ nullable: true })
|
|
270
|
+
appUrl?: string;
|
|
271
|
+
|
|
272
|
+
@Field({ nullable: true })
|
|
273
|
+
appIconPath?: string;
|
|
274
|
+
|
|
275
|
+
@Field((type) => [CapabilityInput], { nullable: true })
|
|
276
|
+
capabilities?: CapabilityInput[];
|
|
277
|
+
|
|
278
|
+
constructor(
|
|
279
|
+
appName: string,
|
|
280
|
+
appDesc: string,
|
|
281
|
+
appDomain: string,
|
|
282
|
+
appUrl?: string,
|
|
283
|
+
appIconPath?: string,
|
|
284
|
+
capabilities?: CapabilityInput[]
|
|
285
|
+
) {
|
|
286
|
+
this.appName = appName;
|
|
287
|
+
this.appDesc = appDesc;
|
|
288
|
+
this.appUrl = appUrl;
|
|
289
|
+
this.appDomain = appDomain;
|
|
290
|
+
this.capabilities = capabilities;
|
|
291
|
+
this.appIconPath = appIconPath;
|
|
292
|
+
}
|
|
293
|
+
}
|