@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.
- package/README.md +229 -229
- package/jest.config.js +5 -5
- package/jsdoc.json +27 -27
- package/lib/index.cjs +4522 -4571
- package/lib/index.js +4522 -4571
- package/lib/shims/type-graphql.d.ts +32 -32
- package/lib/shims/type-graphql.js +70 -70
- package/lib/src/Ad4mClient.d.ts +26 -26
- package/lib/src/Ad4mClient.js +66 -66
- package/lib/src/Address.d.ts +1 -1
- package/lib/src/Address.js +1 -1
- package/lib/src/DID.d.ts +1 -1
- package/lib/src/DID.js +1 -1
- package/lib/src/Exception.d.ts +6 -6
- package/lib/src/Exception.js +7 -7
- package/lib/src/Literal.d.ts +7 -7
- package/lib/src/Literal.js +76 -76
- package/lib/src/PubSub.d.ts +14 -14
- package/lib/src/PubSub.js +14 -14
- package/lib/src/SmartLiteral.d.ts +12 -12
- package/lib/src/SmartLiteral.js +74 -74
- package/lib/src/agent/Agent.d.ts +104 -104
- package/lib/src/agent/Agent.js +337 -337
- package/lib/src/agent/AgentClient.d.ts +57 -57
- package/lib/src/agent/AgentClient.js +431 -431
- package/lib/src/agent/AgentResolver.d.ts +30 -30
- package/lib/src/agent/AgentResolver.js +325 -325
- package/lib/src/agent/AgentStatus.d.ts +8 -8
- package/lib/src/agent/AgentStatus.js +61 -61
- package/lib/src/buildSchema.d.ts +1 -1
- package/lib/src/buildSchema.js +36 -36
- package/lib/src/expression/Expression.d.ts +28 -28
- package/lib/src/expression/Expression.js +143 -143
- package/lib/src/expression/ExpressionClient.d.ts +13 -13
- package/lib/src/expression/ExpressionClient.js +102 -102
- package/lib/src/expression/ExpressionRef.d.ts +9 -9
- package/lib/src/expression/ExpressionRef.js +67 -67
- package/lib/src/expression/ExpressionResolver.d.ts +10 -10
- package/lib/src/expression/ExpressionResolver.js +106 -106
- package/lib/src/index.d.ts +30 -30
- package/lib/src/index.js +30 -30
- package/lib/src/jestSetup.d.ts +1 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.d.ts +4 -4
- package/lib/src/language/Icon.js +24 -24
- package/lib/src/language/Language.d.ts +195 -195
- package/lib/src/language/Language.js +79 -79
- package/lib/src/language/LanguageClient.d.ts +17 -17
- package/lib/src/language/LanguageClient.js +137 -137
- package/lib/src/language/LanguageContext.d.ts +37 -37
- package/lib/src/language/LanguageContext.js +2 -2
- package/lib/src/language/LanguageHandle.d.ts +9 -9
- package/lib/src/language/LanguageHandle.js +41 -41
- package/lib/src/language/LanguageMeta.d.ts +35 -35
- package/lib/src/language/LanguageMeta.js +89 -89
- package/lib/src/language/LanguageRef.d.ts +6 -6
- package/lib/src/language/LanguageRef.js +30 -30
- package/lib/src/language/LanguageResolver.d.ts +19 -19
- package/lib/src/language/LanguageResolver.js +143 -143
- package/lib/src/links/Links.d.ts +39 -39
- package/lib/src/links/Links.js +148 -148
- package/lib/src/links/Links.test.d.ts +1 -1
- package/lib/src/links/Links.test.js +33 -33
- package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -10
- package/lib/src/neighbourhood/Neighbourhood.js +38 -38
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -25
- package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -256
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -19
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -54
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -24
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -180
- package/lib/src/perspectives/LinkQuery.d.ts +11 -11
- package/lib/src/perspectives/LinkQuery.js +80 -80
- package/lib/src/perspectives/Perspective.d.ts +38 -38
- package/lib/src/perspectives/Perspective.js +144 -144
- package/lib/src/perspectives/Perspective.test.d.ts +1 -1
- package/lib/src/perspectives/Perspective.test.js +20 -20
- package/lib/src/perspectives/PerspectiveClient.d.ts +55 -54
- package/lib/src/perspectives/PerspectiveClient.js +418 -410
- package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveDiff.js +33 -33
- package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -16
- package/lib/src/perspectives/PerspectiveHandle.js +59 -59
- package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -178
- package/lib/src/perspectives/PerspectiveProxy.js +501 -540
- package/lib/src/perspectives/PerspectiveResolver.d.ts +38 -37
- package/lib/src/perspectives/PerspectiveResolver.js +376 -362
- package/lib/src/runtime/RuntimeClient.d.ts +33 -33
- package/lib/src/runtime/RuntimeClient.js +263 -263
- package/lib/src/runtime/RuntimeResolver.d.ts +47 -47
- package/lib/src/runtime/RuntimeResolver.js +328 -328
- package/lib/src/schema.gql +1 -0
- package/lib/src/subject/SDNADecorators.d.ts +45 -45
- package/lib/src/subject/SDNADecorators.js +250 -250
- package/lib/src/subject/Subject.d.ts +7 -7
- package/lib/src/subject/Subject.js +160 -160
- package/lib/src/subject/SubjectEntity.d.ts +31 -31
- package/lib/src/subject/SubjectEntity.js +250 -250
- package/lib/src/subject/util.d.ts +12 -12
- package/lib/src/subject/util.js +73 -73
- package/lib/src/typeDefs.d.ts +1 -1
- package/lib/src/typeDefs.js +1 -0
- package/lib/src/unwrapApolloResult.d.ts +2 -2
- package/lib/src/unwrapApolloResult.js +14 -12
- package/lib/src/utils.d.ts +2 -2
- package/lib/src/utils.js +21 -21
- package/package.json +61 -61
- package/rollup.config.js +26 -26
- package/shims/type-graphql.ts +75 -75
- package/src/Ad4mClient.test.ts +1089 -1084
- package/src/Ad4mClient.ts +62 -62
- package/src/Address.ts +1 -1
- package/src/Exception.ts +6 -6
- package/src/Literal.test.ts +30 -30
- package/src/Literal.ts +80 -80
- package/src/PubSub.ts +13 -13
- package/src/SmartLiteral.ts +74 -74
- package/src/agent/Agent.ts +293 -293
- package/src/agent/AgentClient.ts +531 -531
- package/src/agent/AgentResolver.ts +263 -263
- package/src/agent/AgentStatus.ts +43 -43
- package/src/buildSchema.ts +41 -41
- package/src/expression/Expression.ts +99 -99
- package/src/expression/ExpressionClient.ts +98 -98
- package/src/expression/ExpressionRef.ts +62 -62
- package/src/expression/ExpressionResolver.ts +63 -63
- package/src/index.ts +30 -30
- package/src/language/Icon.ts +10 -10
- package/src/language/Language.ts +266 -266
- package/src/language/LanguageClient.ts +159 -159
- package/src/language/LanguageContext.ts +37 -37
- package/src/language/LanguageHandle.ts +23 -23
- package/src/language/LanguageMeta.ts +69 -69
- package/src/language/LanguageRef.ts +18 -18
- package/src/language/LanguageResolver.ts +98 -98
- package/src/links/Links.test.ts +39 -39
- package/src/links/Links.ts +107 -107
- package/src/neighbourhood/Neighbourhood.ts +22 -22
- package/src/neighbourhood/NeighbourhoodClient.ts +275 -275
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -58
- package/src/neighbourhood/NeighbourhoodResolver.ts +99 -99
- package/src/perspectives/LinkQuery.ts +65 -65
- package/src/perspectives/Perspective.test.ts +22 -22
- package/src/perspectives/Perspective.ts +118 -118
- package/src/perspectives/PerspectiveClient.ts +452 -443
- package/src/perspectives/PerspectiveDiff.ts +15 -15
- package/src/perspectives/PerspectiveHandle.ts +39 -39
- package/src/perspectives/PerspectiveProxy.ts +576 -610
- package/src/perspectives/PerspectiveResolver.ts +224 -219
- package/src/runtime/RuntimeClient.ts +282 -282
- package/src/runtime/RuntimeResolver.ts +192 -192
- package/src/subject/SDNADecorators.ts +333 -333
- package/src/subject/Subject.ts +152 -152
- package/src/subject/SubjectEntity.ts +291 -291
- package/src/subject/util.ts +84 -84
- package/src/typeDefs.ts +5 -5
- package/src/unwrapApolloResult.ts +15 -13
- package/src/utils.ts +25 -25
- package/tsconfig-browser.json +82 -82
- package/tsconfig.json +80 -80
- package/yarn-error.log +0 -22814
package/src/Ad4mClient.ts
CHANGED
|
@@ -1,63 +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
|
-
}
|
|
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
63
|
}
|
package/src/Address.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Address = string;
|
|
1
|
+
export type Address = string;
|
package/src/Exception.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export enum ExceptionType {
|
|
2
|
-
LanguageIsNotLoaded,
|
|
3
|
-
ExpressionIsNotVerified,
|
|
4
|
-
AgentIsUntrusted,
|
|
5
|
-
CapabilityRequested,
|
|
6
|
-
}
|
|
1
|
+
export enum ExceptionType {
|
|
2
|
+
LanguageIsNotLoaded,
|
|
3
|
+
ExpressionIsNotVerified,
|
|
4
|
+
AgentIsUntrusted,
|
|
5
|
+
CapabilityRequested,
|
|
6
|
+
}
|
package/src/Literal.test.ts
CHANGED
|
@@ -1,31 +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
|
-
})
|
|
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
31
|
})
|
package/src/Literal.ts
CHANGED
|
@@ -1,81 +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
|
-
|
|
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
81
|
}
|
package/src/PubSub.ts
CHANGED
|
@@ -1,14 +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"
|
|
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
14
|
export const APPS_CHANGED = "apps-changed"
|
package/src/SmartLiteral.ts
CHANGED
|
@@ -1,75 +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
|
-
}
|
|
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
75
|
}
|