@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.
Files changed (114) hide show
  1. package/README.md +229 -0
  2. package/jest-setup.ts +1 -0
  3. package/jest.config.js +6 -0
  4. package/jsdoc.json +28 -0
  5. package/lib/index.cjs +8144 -0
  6. package/lib/shims/reflect-metadata.d.ts +0 -0
  7. package/lib/shims/type-graphql.d.ts +32 -0
  8. package/lib/src/Ad4mClient.d.ts +26 -0
  9. package/lib/src/Address.d.ts +1 -0
  10. package/lib/src/DID.d.ts +1 -0
  11. package/lib/src/Exception.d.ts +6 -0
  12. package/lib/src/Literal.d.ts +7 -0
  13. package/lib/src/PubSub.d.ts +14 -0
  14. package/lib/src/SmartLiteral.d.ts +12 -0
  15. package/lib/src/agent/Agent.d.ts +104 -0
  16. package/lib/src/agent/AgentClient.d.ts +57 -0
  17. package/lib/src/agent/AgentResolver.d.ts +30 -0
  18. package/lib/src/agent/AgentStatus.d.ts +8 -0
  19. package/lib/src/buildSchema.d.ts +1 -0
  20. package/lib/src/expression/Expression.d.ts +28 -0
  21. package/lib/src/expression/ExpressionClient.d.ts +13 -0
  22. package/lib/src/expression/ExpressionRef.d.ts +9 -0
  23. package/lib/src/expression/ExpressionResolver.d.ts +10 -0
  24. package/lib/src/index.d.ts +30 -0
  25. package/lib/src/jestSetup.d.ts +1 -0
  26. package/lib/src/language/Icon.d.ts +4 -0
  27. package/lib/src/language/Language.d.ts +195 -0
  28. package/lib/src/language/LanguageClient.d.ts +17 -0
  29. package/lib/src/language/LanguageContext.d.ts +37 -0
  30. package/lib/src/language/LanguageHandle.d.ts +9 -0
  31. package/lib/src/language/LanguageMeta.d.ts +35 -0
  32. package/lib/src/language/LanguageRef.d.ts +6 -0
  33. package/lib/src/language/LanguageResolver.d.ts +19 -0
  34. package/lib/src/links/Links.d.ts +39 -0
  35. package/lib/src/links/Links.test.d.ts +1 -0
  36. package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -0
  37. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
  38. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
  39. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
  40. package/lib/src/perspectives/LinkQuery.d.ts +11 -0
  41. package/lib/src/perspectives/Perspective.d.ts +38 -0
  42. package/lib/src/perspectives/Perspective.test.d.ts +1 -0
  43. package/lib/src/perspectives/PerspectiveClient.d.ts +54 -0
  44. package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -0
  45. package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -0
  46. package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -0
  47. package/lib/src/perspectives/PerspectiveResolver.d.ts +37 -0
  48. package/lib/src/runtime/RuntimeClient.d.ts +33 -0
  49. package/lib/src/runtime/RuntimeResolver.d.ts +47 -0
  50. package/lib/src/schema.gql +382 -0
  51. package/lib/src/subject/SDNADecorators.d.ts +45 -0
  52. package/lib/src/subject/Subject.d.ts +7 -0
  53. package/lib/src/subject/SubjectEntity.d.ts +31 -0
  54. package/lib/src/subject/util.d.ts +12 -0
  55. package/lib/src/typeDefs.d.ts +1 -0
  56. package/lib/src/unwrapApolloResult.d.ts +2 -0
  57. package/lib/src/utils.d.ts +2 -0
  58. package/package.json +60 -0
  59. package/rollup.config.js +27 -0
  60. package/shims/reflect-metadata.ts +0 -0
  61. package/shims/type-graphql.ts +75 -0
  62. package/src/Ad4mClient.test.ts +1085 -0
  63. package/src/Ad4mClient.ts +63 -0
  64. package/src/Address.ts +1 -0
  65. package/src/DID.ts +1 -0
  66. package/src/Exception.ts +6 -0
  67. package/src/Literal.test.ts +31 -0
  68. package/src/Literal.ts +81 -0
  69. package/src/PubSub.ts +14 -0
  70. package/src/SmartLiteral.ts +75 -0
  71. package/src/agent/Agent.ts +293 -0
  72. package/src/agent/AgentClient.ts +531 -0
  73. package/src/agent/AgentResolver.ts +263 -0
  74. package/src/agent/AgentStatus.ts +44 -0
  75. package/src/buildSchema.ts +41 -0
  76. package/src/expression/Expression.ts +99 -0
  77. package/src/expression/ExpressionClient.ts +99 -0
  78. package/src/expression/ExpressionRef.ts +63 -0
  79. package/src/expression/ExpressionResolver.ts +64 -0
  80. package/src/index.ts +30 -0
  81. package/src/jestSetup.ts +1 -0
  82. package/src/language/Icon.ts +11 -0
  83. package/src/language/Language.ts +266 -0
  84. package/src/language/LanguageClient.ts +160 -0
  85. package/src/language/LanguageContext.ts +37 -0
  86. package/src/language/LanguageHandle.ts +23 -0
  87. package/src/language/LanguageMeta.ts +70 -0
  88. package/src/language/LanguageRef.ts +18 -0
  89. package/src/language/LanguageResolver.ts +98 -0
  90. package/src/links/Links.test.ts +40 -0
  91. package/src/links/Links.ts +107 -0
  92. package/src/neighbourhood/Neighbourhood.ts +22 -0
  93. package/src/neighbourhood/NeighbourhoodClient.ts +276 -0
  94. package/src/neighbourhood/NeighbourhoodProxy.ts +58 -0
  95. package/src/neighbourhood/NeighbourhoodResolver.ts +100 -0
  96. package/src/perspectives/LinkQuery.ts +66 -0
  97. package/src/perspectives/Perspective.test.ts +23 -0
  98. package/src/perspectives/Perspective.ts +118 -0
  99. package/src/perspectives/PerspectiveClient.ts +444 -0
  100. package/src/perspectives/PerspectiveDiff.ts +15 -0
  101. package/src/perspectives/PerspectiveHandle.ts +39 -0
  102. package/src/perspectives/PerspectiveProxy.ts +611 -0
  103. package/src/perspectives/PerspectiveResolver.ts +220 -0
  104. package/src/runtime/RuntimeClient.ts +283 -0
  105. package/src/runtime/RuntimeResolver.ts +193 -0
  106. package/src/subject/SDNADecorators.ts +334 -0
  107. package/src/subject/Subject.ts +153 -0
  108. package/src/subject/SubjectEntity.ts +292 -0
  109. package/src/subject/util.ts +85 -0
  110. package/src/typeDefs.ts +6 -0
  111. package/src/unwrapApolloResult.ts +14 -0
  112. package/src/utils.ts +25 -0
  113. package/tsconfig-browser.json +82 -0
  114. package/tsconfig.json +80 -0
File without changes
@@ -0,0 +1,32 @@
1
+ import * as src from "../node_modules/type-graphql/dist/index.js";
2
+ export declare const dummyValue = "";
3
+ export declare function dummyFn(): void;
4
+ export declare function dummyDecorator(): typeof dummyFn;
5
+ export declare const Arg: typeof src.Arg;
6
+ export declare const Args: typeof src.Args;
7
+ export declare const ArgsType: typeof src.ArgsType;
8
+ export declare const Authorized: typeof src.Authorized;
9
+ export declare const Ctx: typeof src.Ctx;
10
+ export declare const registerEnumType: typeof src.registerEnumType;
11
+ export declare const Field: typeof src.Field;
12
+ export declare const FieldResolver: typeof src.FieldResolver;
13
+ export declare const Info: typeof src.Info;
14
+ export declare const InputType: typeof src.InputType;
15
+ export declare const InterfaceType: typeof src.InterfaceType;
16
+ export declare const Mutation: typeof src.Mutation;
17
+ export declare const ObjectType: typeof src.ObjectType;
18
+ export declare const PubSub: typeof src.PubSub;
19
+ export declare const Query: typeof src.Query;
20
+ export declare const Resolver: typeof src.Resolver;
21
+ export declare const Root: typeof src.Root;
22
+ export declare const Subscription: typeof src.Subscription;
23
+ export declare const createUnionType: typeof src.createUnionType;
24
+ export declare const UseMiddleware: typeof src.UseMiddleware;
25
+ export declare const PubSubEngine: typeof src.PubSubEngine;
26
+ export declare class ClassType<t> {
27
+ }
28
+ export declare const Int: typeof src.Int;
29
+ export declare const Float: typeof src.Float;
30
+ export declare const ID: typeof src.ID;
31
+ export declare const GraphQLISODateTime: typeof src.GraphQLISODateTime;
32
+ export declare const GraphQLTimestamp: typeof src.GraphQLTimestamp;
@@ -0,0 +1,26 @@
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
+ * Client for the Ad4m interface wrapping GraphQL queryies
10
+ * for convenient use in user facing code.
11
+ *
12
+ * Aggregates the six sub-clients:
13
+ * AgentClient, ExpressionClient, LanguageClient,
14
+ * NeighbourhoodClient, PerspectiveClient and RuntimeClient
15
+ * for the respective functionality.
16
+ */
17
+ export declare class Ad4mClient {
18
+ #private;
19
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
20
+ get agent(): AgentClient;
21
+ get expression(): ExpressionClient;
22
+ get languages(): LanguageClient;
23
+ get neighbourhood(): NeighbourhoodClient;
24
+ get perspective(): PerspectiveClient;
25
+ get runtime(): RuntimeClient;
26
+ }
@@ -0,0 +1 @@
1
+ export type Address = string;
@@ -0,0 +1 @@
1
+ export type DID = string;
@@ -0,0 +1,6 @@
1
+ export declare enum ExceptionType {
2
+ LanguageIsNotLoaded = 0,
3
+ ExpressionIsNotVerified = 1,
4
+ AgentIsUntrusted = 2,
5
+ CapabilityRequested = 3
6
+ }
@@ -0,0 +1,7 @@
1
+ export declare class Literal {
2
+ #private;
3
+ static fromUrl(url: string): Literal;
4
+ static from(literal: any): Literal;
5
+ toUrl(): string;
6
+ get(): any;
7
+ }
@@ -0,0 +1,14 @@
1
+ export declare const AGENT_UPDATED = "agent-updated-topic";
2
+ export declare const AGENT_STATUS_CHANGED = "agent-status-changed-topic";
3
+ export declare const RUNTIME_MESSAGED_RECEIVED_TOPIC = "runtime-messaged-received-topic";
4
+ export declare const PERSPECTIVE_ADDED_TOPIC = "perspective-added-topic";
5
+ export declare const PERSPECTIVE_UPDATED_TOPIC = "perspective-updated-topic";
6
+ export declare const PERSPECTIVE_REMOVED_TOPIC = "perspective-removed-topic";
7
+ export declare const LINK_ADDED_TOPIC = "link-added-topic";
8
+ export declare const LINK_REMOVED_TOPIC = "link-removed-topic";
9
+ export declare const LINK_UDATED_TOPIC = "link-updated-topic";
10
+ export declare const SIGNAL = "signal";
11
+ export declare const EXCEPTION_OCCURRED_TOPIC = "exception-occurred-topic";
12
+ export declare const NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC = "neighbourhood-signal-received-topic";
13
+ export declare const PERSPECTIVE_SYNC_STATE_CHANGE = "perspective-sync-state-change";
14
+ export declare const APPS_CHANGED = "apps-changed";
@@ -0,0 +1,12 @@
1
+ import { PerspectiveProxy } from "./perspectives/PerspectiveProxy";
2
+ export declare const SMART_LITERAL_CONTENT_PREDICATE = "smart_literal://content";
3
+ export declare class SmartLiteral {
4
+ #private;
5
+ constructor(perspective: PerspectiveProxy, base: string);
6
+ get base(): string;
7
+ static create(perspective: PerspectiveProxy, literal: any): Promise<SmartLiteral>;
8
+ static isSmartLiteralBase(perspective: PerspectiveProxy, base: string): Promise<boolean>;
9
+ static getAllSmartLiterals(perspective: PerspectiveProxy): Promise<SmartLiteral[]>;
10
+ get(): Promise<any>;
11
+ set(content: any): Promise<void>;
12
+ }
@@ -0,0 +1,104 @@
1
+ import { Perspective } from "../perspectives/Perspective";
2
+ /** AD4M's representation of an Agent
3
+ *
4
+ * AD4M Agents are build around DIDs, which are used to identify and authenticate the Agent.
5
+ * Conceptually, an Agent is regarded as something that can speak and that can listen.
6
+ *
7
+ * Agents speak by creating Expressions in AD4M Languages which are signed by the Agent's DID key,
8
+ * And they also speak (broadcast) by putting semantic statements into their public "Agent Perspective".
9
+ * They listen (can receive messages) through their "direct message Language".
10
+ *
11
+ * These three aspects are represented by the three fields of this class.
12
+ *
13
+ * This class is used as format for the Expressions in the Agent language.
14
+ * Since AD4M treats DID URIs as addresses for the Agent Language,
15
+ * DIDs are resolved to Expressions that are objects of this class.
16
+ * Thus, this is how agents see (other) agents.
17
+ */
18
+ export declare class Agent {
19
+ /** The DID of the Agent
20
+ * All epxressions authored by them are signed with the keys mentioned
21
+ * in the DID document behind this DID URI.
22
+ */
23
+ did: string;
24
+ /** The Perspective that holds the public-facing semantics/statements of the Agent
25
+ * Holds and shares a Perspective that links all information
26
+ * this agent wants to offer as public-facing semantics.
27
+ * This should be used for any kind of user profile information.
28
+ */
29
+ perspective?: Perspective;
30
+ /** Address of the Language by which the Agent will receive DMs */
31
+ directMessageLanguage?: string;
32
+ constructor(did: string, perspective?: Perspective);
33
+ }
34
+ declare const AgentExpression_base: any;
35
+ export declare class AgentExpression extends AgentExpression_base {
36
+ }
37
+ export declare class EntanglementProof {
38
+ did: string;
39
+ didSigningKeyId: string;
40
+ deviceKeyType: string;
41
+ deviceKey: string;
42
+ deviceKeySignedByDid: string;
43
+ didSignedByDeviceKey?: string;
44
+ constructor(did: string, didSigningKeyId: string, deviceKeyType: string, deviceKey: string, deviceKeySignedByDid: string, didSignedByDeviceKey?: string);
45
+ }
46
+ export declare class EntanglementProofInput {
47
+ did: string;
48
+ didSigningKeyId: string;
49
+ deviceKeyType: string;
50
+ deviceKey: string;
51
+ deviceKeySignedByDid: string;
52
+ didSignedByDeviceKey: string;
53
+ constructor(did: string, didSigningKeyId: string, deviceKeyType: string, deviceKey: string, deviceKeySignedByDid: string, didSignedByDeviceKey: string);
54
+ }
55
+ export declare class AgentSignature {
56
+ signature: string;
57
+ publicKey: string;
58
+ constructor(signature: string, publicKey: string);
59
+ }
60
+ export declare class Resource {
61
+ domain: string;
62
+ pointers: string[];
63
+ constructor(domain: string, pointers: string[]);
64
+ }
65
+ export declare class Capability {
66
+ with: Resource;
67
+ can: string[];
68
+ constructor(withF: Resource, can: string[]);
69
+ }
70
+ export declare class AuthInfo {
71
+ appName: string;
72
+ appDesc: string;
73
+ appUrl: string;
74
+ appIconPath?: string;
75
+ capabilities: Capability[];
76
+ constructor(appName: string, appDesc: string, appUrl: string, capabilities: Capability[], appIconPath?: string);
77
+ }
78
+ export declare class Apps {
79
+ requestId: string;
80
+ token: string;
81
+ revoked?: boolean;
82
+ auth: AuthInfo;
83
+ constructor(requestId: string, auth: AuthInfo, token: string, revoked?: boolean);
84
+ }
85
+ export declare class ResourceInput {
86
+ domain: string;
87
+ pointers: string[];
88
+ constructor(domain: string, pointers: string[]);
89
+ }
90
+ export declare class CapabilityInput {
91
+ with: ResourceInput;
92
+ can: string[];
93
+ constructor(withF: ResourceInput, can: string[]);
94
+ }
95
+ export declare class AuthInfoInput {
96
+ appName: string;
97
+ appDesc: string;
98
+ appDomain: string;
99
+ appUrl?: string;
100
+ appIconPath?: string;
101
+ capabilities?: CapabilityInput[];
102
+ constructor(appName: string, appDesc: string, appDomain: string, appUrl?: string, appIconPath?: string, capabilities?: CapabilityInput[]);
103
+ }
104
+ export {};
@@ -0,0 +1,57 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { PerspectiveInput } from "../perspectives/Perspective";
3
+ import { Agent, Apps, AuthInfoInput, EntanglementProof, EntanglementProofInput } from "./Agent";
4
+ import { AgentStatus } from "./AgentStatus";
5
+ import { LinkMutations } from "../links/Links";
6
+ export interface InitializeArgs {
7
+ did: string;
8
+ didDocument: string;
9
+ keystore: string;
10
+ passphrase: string;
11
+ }
12
+ export type AgentUpdatedCallback = (agent: Agent) => null;
13
+ export type AgentStatusChangedCallback = (agent: Agent) => null;
14
+ export type AgentAppsUpdatedCallback = () => null;
15
+ /**
16
+ * Provides access to all functions regarding the local agent,
17
+ * such as generating, locking, unlocking, importing the DID keystore,
18
+ * as well as updating the publicly shared Agent expression.
19
+ */
20
+ export declare class AgentClient {
21
+ #private;
22
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
23
+ /**
24
+ * Returns the Agent expression of the local agent as it is shared
25
+ * publicly via the AgentLanguage.
26
+ *
27
+ * I.e. this is the users profile.
28
+ */
29
+ me(): Promise<Agent>;
30
+ status(): Promise<AgentStatus>;
31
+ generate(passphrase: string): Promise<AgentStatus>;
32
+ import(args: InitializeArgs): Promise<AgentStatus>;
33
+ lock(passphrase: string): Promise<AgentStatus>;
34
+ unlock(passphrase: string, holochain?: boolean): Promise<AgentStatus>;
35
+ byDID(did: string): Promise<Agent>;
36
+ updatePublicPerspective(perspective: PerspectiveInput): Promise<Agent>;
37
+ mutatePublicPerspective(mutations: LinkMutations): Promise<Agent>;
38
+ updateDirectMessageLanguage(directMessageLanguage: string): Promise<Agent>;
39
+ addEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]>;
40
+ deleteEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]>;
41
+ getEntanglementProofs(): Promise<string[]>;
42
+ entanglementProofPreFlight(deviceKey: string, deviceKeyType: string): Promise<EntanglementProof>;
43
+ addUpdatedListener(listener: any): void;
44
+ addAppChangedListener(listener: any): void;
45
+ subscribeAgentUpdated(): void;
46
+ subscribeAppsChanged(): void;
47
+ addAgentStatusChangedListener(listener: any): void;
48
+ subscribeAgentStatusChanged(): void;
49
+ requestCapability(authInfo: AuthInfoInput): Promise<string>;
50
+ permitCapability(auth: string): Promise<string>;
51
+ generateJwt(requestId: string, rand: string): Promise<string>;
52
+ getApps(): Promise<Apps[]>;
53
+ removeApp(requestId: string): Promise<Apps[]>;
54
+ revokeToken(requestId: string): Promise<Apps[]>;
55
+ isLocked(): Promise<boolean>;
56
+ signMessage(message: string): Promise<string>;
57
+ }
@@ -0,0 +1,30 @@
1
+ import { PerspectiveInput } from "../perspectives/Perspective";
2
+ import { Agent, AgentSignature, AuthInfoInput, EntanglementProof, EntanglementProofInput } from "./Agent";
3
+ import { AgentStatus } from "./AgentStatus";
4
+ export declare const TEST_AGENT_DID = "did:ad4m:test";
5
+ export default class AgentResolver {
6
+ agent(): Agent;
7
+ agentStatus(): AgentStatus;
8
+ agentGenerate(passphrase: string, pubSub: any): AgentStatus;
9
+ agentImport(did: string, didDocument: string, keystore: string, passphrase: string): AgentStatus;
10
+ agentLock(passphrase: string, pubSub: any): AgentStatus;
11
+ agentUnlock(passphrase: string, holochain: boolean, pubSub: any): AgentStatus;
12
+ agentByDID(did: string): Agent;
13
+ agentUpdatePublicPerspective(perspective: PerspectiveInput, pubSub: any): Agent;
14
+ agentUpdateDirectMessageLanguage(directMessageLanguage: string, pubSub: any): Agent;
15
+ agentUpdated(): Agent;
16
+ agentStatusChanged(): AgentStatus;
17
+ agentAddEntanglementProofs(proofs: EntanglementProofInput[]): EntanglementProof[];
18
+ agentDeleteEntanglementProofs(proofs: EntanglementProofInput[]): EntanglementProof[];
19
+ agentGetEntanglementProofs(): EntanglementProof[];
20
+ agentEntanglementProofPreFlight(deviceKey: string, deviceKeyType: string): EntanglementProof;
21
+ agentRequestCapability(authInfo: AuthInfoInput): String;
22
+ agentPermitCapability(auth: string): String;
23
+ agentGenerateJwt(requestId: string, rand: string): String;
24
+ agentIsLocked(): Boolean;
25
+ agentGetApps(): [];
26
+ agentAppsChanged(): null;
27
+ agentRemoveApp(requestId: string, pubSub: any): [];
28
+ agentRevokeToken(requestId: string): any[];
29
+ agentSignMessage(message: string): AgentSignature;
30
+ }
@@ -0,0 +1,8 @@
1
+ export declare class AgentStatus {
2
+ isInitialized: Boolean;
3
+ isUnlocked: Boolean;
4
+ did?: string;
5
+ didDocument?: string;
6
+ error?: string;
7
+ constructor(obj?: object);
8
+ }
@@ -0,0 +1 @@
1
+ import "reflect-metadata";
@@ -0,0 +1,28 @@
1
+ import { ClassType } from "type-graphql";
2
+ import { Icon } from "../language/Icon";
3
+ import { LanguageRef } from "../language/LanguageRef";
4
+ export declare class ExpressionProof {
5
+ signature: string;
6
+ key: string;
7
+ valid?: boolean;
8
+ invalid?: boolean;
9
+ constructor(sig: string, k: string);
10
+ }
11
+ export declare class ExpressionProofInput {
12
+ signature: string;
13
+ key: string;
14
+ valid?: boolean;
15
+ invalid?: boolean;
16
+ }
17
+ export declare function ExpressionGeneric<DataType>(DataTypeClass: ClassType<DataType>): any;
18
+ export declare function ExpressionGenericInput<DataType>(DataTypeClass: ClassType<DataType>): any;
19
+ declare const Expression_base: any;
20
+ export declare class Expression extends Expression_base {
21
+ }
22
+ declare const ExpressionRendered_base: any;
23
+ export declare class ExpressionRendered extends ExpressionRendered_base {
24
+ language: LanguageRef;
25
+ icon: Icon;
26
+ }
27
+ export declare function isExpression(e: any): boolean;
28
+ export {};
@@ -0,0 +1,13 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { InteractionCall, InteractionMeta } from "../language/Language";
3
+ import { ExpressionRendered } from "./Expression";
4
+ export declare class ExpressionClient {
5
+ #private;
6
+ constructor(client: ApolloClient<any>);
7
+ get(url: string): Promise<ExpressionRendered>;
8
+ getMany(urls: string[]): Promise<ExpressionRendered[]>;
9
+ getRaw(url: string): Promise<string>;
10
+ create(content: any, languageAddress: string): Promise<string>;
11
+ interactions(url: string): Promise<InteractionMeta[]>;
12
+ interact(url: string, interactionCall: InteractionCall): Promise<string | null>;
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { Address } from '../Address';
2
+ import { LanguageRef } from '../language/LanguageRef';
3
+ export declare class ExpressionRef {
4
+ language: LanguageRef;
5
+ expression: Address;
6
+ constructor(lang: LanguageRef, expr: Address);
7
+ }
8
+ export declare function exprRef2String(ref: ExpressionRef): string;
9
+ export declare function parseExprUrl(url: string): ExpressionRef;
@@ -0,0 +1,10 @@
1
+ import { ExpressionRendered } from "./Expression";
2
+ import { InteractionCall, InteractionMeta } from "../language/Language";
3
+ export default class ExpressionResolver {
4
+ expression(url: string): ExpressionRendered;
5
+ expressionMany(urls: string[]): (ExpressionRendered | null)[];
6
+ expressionRaw(url: string): string;
7
+ expressionCreate(content: string, languageAddress: string): string;
8
+ expressionInteractions(url: string): InteractionMeta[];
9
+ expressionInteract(url: string, interactionCall: InteractionCall): string | null;
10
+ }
@@ -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";
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,4 @@
1
+ export declare class Icon {
2
+ code: string;
3
+ constructor(code: string);
4
+ }
@@ -0,0 +1,195 @@
1
+ import type { Address } from '../Address';
2
+ import { DID } from '../DID';
3
+ import type { Expression } from '../expression/Expression';
4
+ import { Perspective, PerspectiveExpression } from '../perspectives/Perspective';
5
+ import { PerspectiveDiff } from '../perspectives/PerspectiveDiff';
6
+ import { PerspectiveState } from '../perspectives/PerspectiveHandle';
7
+ /** Interface of AD4M Languages
8
+ *
9
+ * Any JavaScript module that implements a create() function that returns an object that implements this interface
10
+ * is a valid AD4M language.
11
+ * So the AD4M-internal representation of a language is an object that implements this interface.
12
+ *
13
+ * Since there are a few different kinds of languages, this interface is split into optional sub-interfaces.
14
+ * The only required property is the name of the language.
15
+ *
16
+ * The most usual kind of language is the "Expression Language", which is a language that can be used to create
17
+ * and share Expressions.
18
+ * For that, implement the expressionsAdapter and expressionUI interface.
19
+ *
20
+ * The second most common kind of language is the "Link Language", which is a language that builds the core
21
+ * of AD4M Neighbourhoods.
22
+ * For that, implement the linksAdapter interface.
23
+ */
24
+ export interface Language {
25
+ readonly name: string;
26
+ /** Flagging expressions as immutable to enable
27
+ * expression caching in the ad4m-executor
28
+ */
29
+ isImmutableExpression?(expression: Address): boolean;
30
+ /** ExpressionAdapter implements means of getting an Expression
31
+ * by address and putting an expression
32
+ */
33
+ readonly expressionAdapter?: ExpressionAdapter;
34
+ /** Interface for getting UI/web components for rendering Expressions of this Language */
35
+ readonly expressionUI?: ExpressionUI;
36
+ /** Interface of LinkLanguages for the core implementation of Neighbourhoods */
37
+ readonly linksAdapter?: LinkSyncAdapter;
38
+ /** Additional Interface of LinkLanguages that support telepresence features,
39
+ * that is:
40
+ * - seeing who is online and getting a status
41
+ * - sending/receiveing p2p signals to other online agents without affecting
42
+ * the shared Perspective of the Neighbourhood
43
+ * (see TelepresenceAdapter for more details)
44
+ */
45
+ readonly telepresenceAdapter?: TelepresenceAdapter;
46
+ /** Implementation of a Language that defines and stores Languages*/
47
+ readonly languageAdapter?: LanguageAdapter;
48
+ /** Optional adapter for getting Expressions by author */
49
+ readonly getByAuthorAdapter?: GetByAuthorAdapter;
50
+ /** Optional adapter for getting all Expressions */
51
+ readonly getAllAdapter?: GetAllAdapter;
52
+ /** Optional adapter for direct messaging between agents */
53
+ readonly directMessageAdapter?: DirectMessageAdapter;
54
+ /** Interface for providing UI components for the settings of this Language */
55
+ readonly settingsUI?: SettingsUI;
56
+ /** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
57
+ readonly teardown?: () => void;
58
+ /** All available interactions this agent could execute on given expression */
59
+ interactions(expression: Address): Interaction[];
60
+ }
61
+ /** UI factories returning web components */
62
+ export interface ExpressionUI {
63
+ /** Returns JS code of a web component that renders the given expression */
64
+ icon(): string;
65
+ /** Returns JS code of a web component used to create new expressions */
66
+ constructorIcon(): string;
67
+ }
68
+ export interface SettingsUI {
69
+ settingsIcon(): string;
70
+ }
71
+ /** Interface for the most common Expression Languages */
72
+ export interface ExpressionAdapter {
73
+ /** Returns an Expression by address, or null if there is no Expression
74
+ * with that given address
75
+ */
76
+ get(address: Address): Promise<Expression | null>;
77
+ /** Strategy for putting an expression with needs to be different
78
+ * for those two cases:
79
+ * 1. PublicSharing means that this language supports the creation
80
+ * and sharing of Expressions, which is the common use-case
81
+ * 2. ReadOnlyLanguage means that the Language implements a pre-defined
82
+ * set of expressions (which can be infinite or finite).
83
+ * For example the url-iframe Language which directly maps URLs to
84
+ * addresses - meaning every well formed URL is an address in this
85
+ * Language. Or a potential Language implementing the verbs/predicates
86
+ * of a spec like FOAF.
87
+ */
88
+ putAdapter: PublicSharing | ReadOnlyLanguage;
89
+ }
90
+ /** Implement this interface if your Language supports creation of sharing
91
+ * of Expressions.
92
+ * See ExpressionAdapter
93
+ */
94
+ export interface PublicSharing {
95
+ /** Create an Expression and shares it.
96
+ * Return the Expression's address.
97
+ * @param content is the object created by the constructorIcon component
98
+ */
99
+ createPublic(content: object): Promise<Address>;
100
+ }
101
+ /** Implement this interface if your Language is defined over a static
102
+ * set of pre-defined Expressions.
103
+ */
104
+ export interface ReadOnlyLanguage {
105
+ /** This just calculates the address of an object
106
+ * @param content is the object created by the constructorIcon component
107
+ */
108
+ addressOf(content: object): Promise<Address>;
109
+ }
110
+ export interface LanguageAdapter {
111
+ getLanguageSource(address: Address): Promise<string>;
112
+ }
113
+ export interface GetByAuthorAdapter {
114
+ getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
115
+ }
116
+ export interface GetAllAdapter {
117
+ getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
118
+ }
119
+ export type PerspectiveDiffObserver = (diff: PerspectiveDiff) => void;
120
+ export type SyncStateChangeObserver = (state: PerspectiveState) => void;
121
+ /** Interface for "Link Languages" that facilitate the synchronization
122
+ * between agents' local Perspectives inside a Neighbourhood.
123
+ * The assumption is that every version of the shared Perspective
124
+ * is labeled with a unique revision string.
125
+ * Changes are committed and retrieved through diffs.
126
+ * Think of a LinkSyncAdapter as a git branch to which agents commit
127
+ * their changes to and pull diffs from their current revision
128
+ * to the latest one.
129
+ */
130
+ export interface LinkSyncAdapter {
131
+ writable(): boolean;
132
+ public(): boolean;
133
+ others(): Promise<DID[]>;
134
+ /** What revision are we on now -> what changes are included in output of render() */
135
+ currentRevision(): Promise<string>;
136
+ /**
137
+ * Check for and get new changes,
138
+ * notify others of local changes.
139
+ * This function will be called every
140
+ * few seconds by the ad4m-executor.
141
+ * */
142
+ sync(): Promise<PerspectiveDiff>;
143
+ /** Returns the full, rendered Perspective at currentRevision */
144
+ render(): Promise<Perspective>;
145
+ /** Publish changes */
146
+ commit(diff: PerspectiveDiff): Promise<string>;
147
+ /** Get push notification when a diff got published */
148
+ addCallback(callback: PerspectiveDiffObserver): any;
149
+ /** Add a sync state callback method */
150
+ addSyncStateChangeCallback(callback: SyncStateChangeObserver): any;
151
+ }
152
+ export type MessageCallback = (message: PerspectiveExpression) => void;
153
+ export type StatusCallback = (caller: DID) => Perspective;
154
+ export interface DirectMessageAdapter {
155
+ recipient(): DID;
156
+ status(): Promise<PerspectiveExpression | void>;
157
+ sendP2P(message: Perspective): Promise<PerspectiveExpression | void>;
158
+ sendInbox(message: Perspective): Promise<PerspectiveExpression | void>;
159
+ setStatus(status: PerspectiveExpression): any;
160
+ inbox(filter?: string): Promise<PerspectiveExpression[]>;
161
+ addMessageCallback(callback: MessageCallback): any;
162
+ }
163
+ export declare class InteractionParameter {
164
+ name: string;
165
+ type: string;
166
+ }
167
+ export declare class InteractionMeta {
168
+ label: string;
169
+ name: string;
170
+ parameters: InteractionParameter[];
171
+ }
172
+ export interface Interaction {
173
+ readonly label: string;
174
+ readonly name: string;
175
+ readonly parameters: InteractionParameter[];
176
+ execute(parameters: object): Promise<string | null>;
177
+ }
178
+ export declare class InteractionCall {
179
+ name: string;
180
+ parametersStringified: string;
181
+ get parameters(): object;
182
+ constructor(name: string, parameters: object);
183
+ }
184
+ export declare class OnlineAgent {
185
+ did: DID;
186
+ status: PerspectiveExpression;
187
+ }
188
+ export type TelepresenceSignalCallback = (payload: PerspectiveExpression) => void;
189
+ export interface TelepresenceAdapter {
190
+ setOnlineStatus(status: PerspectiveExpression): Promise<void>;
191
+ getOnlineAgents(): Promise<OnlineAgent[]>;
192
+ sendSignal(remoteAgentDid: string, payload: PerspectiveExpression): Promise<object>;
193
+ sendBroadcast(payload: PerspectiveExpression): Promise<object>;
194
+ registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
195
+ }
@@ -0,0 +1,17 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { LanguageHandle } from "./LanguageHandle";
3
+ import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta";
4
+ import { LanguageRef } from "./LanguageRef";
5
+ export declare class LanguageClient {
6
+ #private;
7
+ constructor(apolloClient: ApolloClient<any>);
8
+ byAddress(address: string): Promise<LanguageHandle>;
9
+ byFilter(filter: string): Promise<LanguageHandle[]>;
10
+ all(): Promise<LanguageHandle[]>;
11
+ writeSettings(languageAddress: string, settings: string): Promise<Boolean>;
12
+ applyTemplateAndPublish(sourceLanguageHash: string, templateData: string): Promise<LanguageRef>;
13
+ publish(languagePath: string, languageMeta: LanguageMetaInput): Promise<LanguageMeta>;
14
+ meta(address: string): Promise<LanguageMeta>;
15
+ source(address: string): Promise<string>;
16
+ remove(address: string): Promise<Boolean>;
17
+ }