@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/buildSchema.ts
CHANGED
|
@@ -1,41 +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
|
-
|
|
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
|
+
|
|
@@ -1,99 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,99 +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
|
-
}
|
|
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
99
|
}
|
|
@@ -1,63 +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)
|
|
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
63
|
}
|