@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
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ import type { AppSignalCb } from '@holochain/client';
3
+ import { Expression } from "../expression/Expression";
4
+ export interface AgentService {
5
+ readonly did: string;
6
+ createSignedExpression(data: any): Expression;
7
+ }
8
+ export interface SignaturesService {
9
+ verify(expr: Expression): boolean;
10
+ }
11
+ export interface LanguageContext {
12
+ agent: AgentService;
13
+ signatures: SignaturesService;
14
+ storageDirectory: string;
15
+ customSettings: object;
16
+ Holochain: HolochainLanguageDelegate | undefined;
17
+ ad4mSignal: Ad4mSignalCB;
18
+ }
19
+ export declare class Dna {
20
+ file: Buffer;
21
+ nick: string;
22
+ zomeCalls: [string, string][];
23
+ }
24
+ export interface HolochainLanguageDelegate {
25
+ /** Installs/registers a given DNA in the ad4m-executor */
26
+ registerDNAs(dnas: Dna[], holochainSignalCallback?: AppSignalCb): Promise<void>;
27
+ /** Makes a single call to a given holochain DNA. Underlying implementation puts these calls into a sync fifo queue */
28
+ call(dnaNick: string, zomeName: string, fnName: string, params: object | string): Promise<any>;
29
+ /** Makes all supplied calls in parallel to the provided holochain dna... Should only be called on read operations to avoid source chain async mutation errors */
30
+ callAsync(calls: {
31
+ dnaNick: string;
32
+ zomeName: string;
33
+ fnName: string;
34
+ params: object | string;
35
+ }[], timeoutMs?: number): Promise<any[]>;
36
+ }
37
+ export type Ad4mSignalCB = (signal: any) => void;
@@ -0,0 +1,9 @@
1
+ import { Icon } from "./Icon";
2
+ export declare class LanguageHandle {
3
+ name: string;
4
+ address: string;
5
+ settings?: string;
6
+ icon?: Icon;
7
+ constructorIcon?: Icon;
8
+ settingsIcon?: Icon;
9
+ }
@@ -0,0 +1,35 @@
1
+ export declare class LanguageMeta {
2
+ name: string;
3
+ address: string;
4
+ description: string;
5
+ author: string;
6
+ templated: boolean;
7
+ templateSourceLanguageAddress?: string;
8
+ templateAppliedParams?: string;
9
+ possibleTemplateParams?: string[];
10
+ sourceCodeLink?: string;
11
+ }
12
+ export declare class LanguageMetaInput {
13
+ name: string;
14
+ description: string;
15
+ possibleTemplateParams?: string[];
16
+ sourceCodeLink?: string;
17
+ constructor(name?: string, description?: string);
18
+ }
19
+ export declare class LanguageMetaInternal {
20
+ name: string;
21
+ address: string;
22
+ description: string;
23
+ templateSourceLanguageAddress?: string;
24
+ templateAppliedParams?: string;
25
+ possibleTemplateParams?: string[];
26
+ sourceCodeLink?: string;
27
+ }
28
+ declare const LanguageExpression_base: any;
29
+ export declare class LanguageExpression extends LanguageExpression_base {
30
+ }
31
+ export declare class LanguageLanguageInput {
32
+ bundle: string;
33
+ meta: LanguageMetaInternal;
34
+ }
35
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Address } from '../Address';
2
+ export declare class LanguageRef {
3
+ address: Address;
4
+ name: string;
5
+ constructor(address?: Address, name?: string);
6
+ }
@@ -0,0 +1,19 @@
1
+ import { LanguageHandle } from "./LanguageHandle";
2
+ import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta";
3
+ import { LanguageRef } from "./LanguageRef";
4
+ /**
5
+ * Resolver classes are used here to define the GraphQL schema
6
+ * (through the type-graphql annotations)
7
+ * and are spawned in the client tests in Ad4mClient.test.ts.
8
+ * For the latter, they return test fixtures.
9
+ */
10
+ export default class LanguageResolver {
11
+ language(address: string): LanguageHandle;
12
+ languages(filter: string): LanguageHandle[];
13
+ languageWriteSettings(languageAddress: string, settings: string): Boolean;
14
+ languageApplyTemplateAndPublish(sourceLanguageHash: string, templateData: string): LanguageRef;
15
+ languagePublish(languagePath: string, languageMeta: LanguageMetaInput): LanguageMeta;
16
+ languageMeta(address: string): LanguageMeta;
17
+ languageSource(address: string): string;
18
+ languageRemove(address: string): Boolean;
19
+ }
@@ -0,0 +1,39 @@
1
+ import { LinkStatus } from "../perspectives/PerspectiveProxy";
2
+ export declare class Link {
3
+ source: string;
4
+ target: string;
5
+ predicate?: string;
6
+ constructor(obj: any);
7
+ }
8
+ export declare class LinkMutations {
9
+ additions: LinkInput[];
10
+ removals: LinkExpressionInput[];
11
+ }
12
+ export declare class LinkExpressionMutations {
13
+ additions: LinkExpression[];
14
+ removals: LinkExpression[];
15
+ constructor(additions: LinkExpression[], removals: LinkExpression[]);
16
+ }
17
+ export declare class LinkInput {
18
+ source: string;
19
+ target: string;
20
+ predicate?: string;
21
+ }
22
+ declare const LinkExpression_base: any;
23
+ export declare class LinkExpression extends LinkExpression_base {
24
+ hash(): number;
25
+ status?: LinkStatus;
26
+ }
27
+ declare const LinkExpressionInput_base: any;
28
+ export declare class LinkExpressionInput extends LinkExpressionInput_base {
29
+ hash: () => number;
30
+ status?: LinkStatus;
31
+ }
32
+ export declare function linkEqual(l1: LinkExpression, l2: LinkExpression): boolean;
33
+ export declare function isLink(l: any): boolean;
34
+ export declare class LinkExpressionUpdated {
35
+ oldLink: LinkExpression;
36
+ newLink: LinkExpression;
37
+ constructor(oldLink: LinkExpression, newLink: LinkExpression);
38
+ }
39
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { Perspective } from "../perspectives/Perspective";
2
+ export declare class Neighbourhood {
3
+ linkLanguage: string;
4
+ meta: Perspective;
5
+ constructor(linkLanguage: string, meta: Perspective);
6
+ }
7
+ declare const NeighbourhoodExpression_base: any;
8
+ export declare class NeighbourhoodExpression extends NeighbourhoodExpression_base {
9
+ }
10
+ export {};
@@ -0,0 +1,25 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { Address } from "../Address";
3
+ import { DID } from "../DID";
4
+ import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language";
5
+ import { Perspective, PerspectiveUnsignedInput } from "../perspectives/Perspective";
6
+ import { PerspectiveHandle } from "../perspectives/PerspectiveHandle";
7
+ export declare class NeighbourhoodClient {
8
+ #private;
9
+ constructor(client: ApolloClient<any>);
10
+ publishFromPerspective(perspectiveUUID: string, linkLanguage: Address, meta: Perspective): Promise<string>;
11
+ joinFromUrl(url: string): Promise<PerspectiveHandle>;
12
+ otherAgents(perspectiveUUID: string): Promise<DID[]>;
13
+ hasTelepresenceAdapter(perspectiveUUID: string): Promise<boolean>;
14
+ onlineAgents(perspectiveUUID: string): Promise<OnlineAgent[]>;
15
+ setOnlineStatus(perspectiveUUID: string, status: Perspective): Promise<boolean>;
16
+ setOnlineStatusU(perspectiveUUID: string, status: PerspectiveUnsignedInput): Promise<boolean>;
17
+ sendSignal(perspectiveUUID: string, remoteAgentDid: string, payload: Perspective): Promise<boolean>;
18
+ sendSignalU(perspectiveUUID: string, remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean>;
19
+ sendBroadcast(perspectiveUUID: string, payload: Perspective): Promise<boolean>;
20
+ sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput): Promise<boolean>;
21
+ dispatchSignal(perspectiveUUID: string, signal: any): void;
22
+ subscribeToSignals(perspectiveUUID: string): Promise<void>;
23
+ addSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): Promise<void>;
24
+ removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void;
25
+ }
@@ -0,0 +1,19 @@
1
+ import { DID } from "../DID";
2
+ import { OnlineAgent } from "../language/Language";
3
+ import { Perspective, PerspectiveExpression, PerspectiveUnsignedInput } from "../perspectives/Perspective";
4
+ import { NeighbourhoodClient } from "./NeighbourhoodClient";
5
+ export declare class NeighbourhoodProxy {
6
+ #private;
7
+ constructor(client: NeighbourhoodClient, pID: string);
8
+ otherAgents(): Promise<DID[]>;
9
+ hasTelepresenceAdapter(): Promise<boolean>;
10
+ onlineAgents(): Promise<OnlineAgent[]>;
11
+ setOnlineStatus(status: Perspective): Promise<boolean>;
12
+ setOnlineStatusU(status: PerspectiveUnsignedInput): Promise<boolean>;
13
+ sendSignal(remoteAgentDid: string, payload: Perspective): Promise<boolean>;
14
+ sendSignalU(remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean>;
15
+ sendBroadcast(payload: Perspective): Promise<boolean>;
16
+ sendBroadcastU(payload: PerspectiveUnsignedInput): Promise<boolean>;
17
+ addSignalHandler(handler: (payload: PerspectiveExpression) => void): Promise<void>;
18
+ removeSignalHandler(handler: (payload: PerspectiveExpression) => void): void;
19
+ }
@@ -0,0 +1,24 @@
1
+ import { PerspectiveHandle } from "../perspectives/PerspectiveHandle";
2
+ import { PerspectiveExpression, PerspectiveInput, PerspectiveUnsignedInput } from "../perspectives/Perspective";
3
+ import { DID } from "../DID";
4
+ import { OnlineAgent } from "../language/Language";
5
+ /**
6
+ * Resolver classes are used here to define the GraphQL schema
7
+ * (through the type-graphql annotations)
8
+ * and are spawned in the client tests in Ad4mClient.test.ts.
9
+ * For the latter, they return test fixtures.
10
+ */
11
+ export default class NeighbourhoodResolver {
12
+ neighbourhoodPublishFromPerspective(perspectiveUUID: string, linkLanguage: string, meta: PerspectiveInput): string;
13
+ neighbourhoodJoinFromUrl(url: string, pubSub: any): PerspectiveHandle;
14
+ neighbourhoodOtherAgents(perspectiveUUID: string): DID[];
15
+ neighbourhoodHasTelepresenceAdapter(perspectiveUUID: string): boolean;
16
+ neighbourhoodOnlineAgents(perspectiveUUID: string): OnlineAgent[];
17
+ neighbourhoodSetOnlineStatus(perspectiveUUID: string, status: PerspectiveInput): boolean;
18
+ neighbourhoodSetOnlineStatusU(perspectiveUUID: string, status: PerspectiveUnsignedInput): boolean;
19
+ neighbourhoodSendSignal(perspectiveUUID: string, recipient: DID, signal: PerspectiveInput): boolean;
20
+ neighbourhoodSendSignalU(perspectiveUUID: string, recipient: DID, signal: PerspectiveUnsignedInput): boolean;
21
+ neighbourhoodSendBroadcast(perspectiveUUID: string, signal: PerspectiveInput): boolean;
22
+ neighbourhoodSendBroadcastU(perspectiveUUID: string, signal: PerspectiveUnsignedInput): boolean;
23
+ neighbourhoodSignal(pID: string): PerspectiveExpression;
24
+ }
@@ -0,0 +1,11 @@
1
+ import { Link } from "../links/Links";
2
+ export declare class LinkQuery {
3
+ source?: string;
4
+ target?: string;
5
+ predicate?: string;
6
+ fromDate?: Date;
7
+ untilDate?: Date;
8
+ limit?: number;
9
+ constructor(obj: object);
10
+ isMatch(l: Link): boolean;
11
+ }
@@ -0,0 +1,38 @@
1
+ import { Link, LinkExpression, LinkExpressionInput, LinkInput } from "../links/Links";
2
+ import { LinkQuery } from "./LinkQuery";
3
+ /** A Perspective represents subjective meaning, encoded through
4
+ * associations between expressions, a.k.a. Links, that is a graph
5
+ * over the objective Expressions of any subset of Languages.
6
+ *
7
+ * This type represents the clean onotological concept of a Perspective.
8
+ * An instance of this class can be regarded as an immutable snapshot of
9
+ * a mutable perspective.
10
+ *
11
+ * The types PerspectiveProxy and PerspectiveHandle are used when dealing
12
+ * with an instantiated mutable perspective as is done through most of
13
+ * the GraphQL mutations.
14
+ */
15
+ export declare class Perspective {
16
+ /** The content of the perspective, a list/graph of links */
17
+ links: LinkExpression[];
18
+ constructor(links?: LinkExpression[]);
19
+ /** Convenience function for filtering links just like with PerspectiveProxy */
20
+ get(query: LinkQuery): LinkExpression[];
21
+ /** Convenience function to get the target of the first link that matches the given query
22
+ * This makes sense when the query is expected to return only one link
23
+ * and the target of that link is what you are looking for.
24
+ */
25
+ getSingleTarget(query: LinkQuery): string | void;
26
+ }
27
+ export declare class PerspectiveInput {
28
+ links: LinkExpressionInput[];
29
+ }
30
+ export declare class PerspectiveUnsignedInput {
31
+ links: LinkInput[];
32
+ constructor(links?: LinkInput[]);
33
+ static fromLink(link: Link): PerspectiveUnsignedInput;
34
+ }
35
+ declare const PerspectiveExpression_base: any;
36
+ export declare class PerspectiveExpression extends PerspectiveExpression_base {
37
+ }
38
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { ExpressionRendered } from "../expression/Expression";
3
+ import { ExpressionClient } from "../expression/ExpressionClient";
4
+ import { Link, LinkExpressionInput, LinkExpression, LinkInput, LinkMutations, LinkExpressionMutations } from "../links/Links";
5
+ import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
6
+ import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
7
+ import { LinkQuery } from "./LinkQuery";
8
+ import { Perspective } from "./Perspective";
9
+ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
10
+ import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
11
+ export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null;
12
+ export type UuidCallback = (uuid: string) => null;
13
+ export type LinkCallback = (link: LinkExpression) => null;
14
+ export type SyncStateChangeCallback = (state: PerspectiveState) => null;
15
+ export declare class PerspectiveClient {
16
+ #private;
17
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
18
+ setExpressionClient(client: ExpressionClient): void;
19
+ setNeighbourhoodClient(client: NeighbourhoodClient): void;
20
+ all(): Promise<PerspectiveProxy[]>;
21
+ byUUID(uuid: string): Promise<PerspectiveProxy | null>;
22
+ snapshotByUUID(uuid: string): Promise<Perspective | null>;
23
+ publishSnapshotByUUID(uuid: string): Promise<string | null>;
24
+ queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]>;
25
+ queryProlog(uuid: string, query: string): Promise<any>;
26
+ add(name: string): Promise<PerspectiveProxy>;
27
+ update(uuid: string, name: string): Promise<PerspectiveProxy>;
28
+ remove(uuid: string): Promise<{
29
+ perspectiveRemove: boolean;
30
+ }>;
31
+ addLink(uuid: string, link: Link, status?: LinkStatus): Promise<LinkExpression>;
32
+ addLinks(uuid: string, links: Link[], status?: LinkStatus): Promise<LinkExpression[]>;
33
+ removeLinks(uuid: string, links: LinkExpressionInput[]): Promise<LinkExpression[]>;
34
+ linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations>;
35
+ addLinkExpression(uuid: string, link: LinkExpressionInput, status?: LinkStatus): Promise<LinkExpression>;
36
+ updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: LinkInput): Promise<LinkExpression>;
37
+ removeLink(uuid: string, link: LinkExpressionInput): Promise<{
38
+ perspectiveRemoveLink: boolean;
39
+ }>;
40
+ getExpression(expressionURI: string): Promise<ExpressionRendered>;
41
+ createExpression(content: any, languageAddress: string): Promise<string>;
42
+ addPerspectiveAddedListener(cb: PerspectiveHandleCallback): void;
43
+ subscribePerspectiveAdded(): void;
44
+ addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback): void;
45
+ subscribePerspectiveUpdated(): void;
46
+ addPerspectiveSyncedListener(cb: SyncStateChangeCallback): void;
47
+ addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void>;
48
+ addPerspectiveRemovedListener(cb: UuidCallback): void;
49
+ subscribePerspectiveRemoved(): void;
50
+ addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
51
+ addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
52
+ addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
53
+ getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy;
54
+ }
@@ -0,0 +1,9 @@
1
+ import { LinkExpression } from "../links/Links";
2
+ export declare class PerspectiveDiff {
3
+ additions: LinkExpression[];
4
+ removals: LinkExpression[];
5
+ }
6
+ declare const PerspectiveDiffExpression_base: any;
7
+ export declare class PerspectiveDiffExpression extends PerspectiveDiffExpression_base {
8
+ }
9
+ export {};
@@ -0,0 +1,16 @@
1
+ import { NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
2
+ export declare enum PerspectiveState {
3
+ Private = "Private",
4
+ NeighbourhoodJoinInitiated = "NeighbourhoodJoinInitiated",
5
+ LinkLanguageFailedToInstall = "LinkLanguageFailedToInstall",
6
+ LinkLanguageInstalledButNotSynced = "LinkLanguageInstalledButNotSynced",
7
+ Synced = "Synced"
8
+ }
9
+ export declare class PerspectiveHandle {
10
+ uuid: string;
11
+ name: string;
12
+ state: PerspectiveState;
13
+ sharedUrl?: string;
14
+ neighbourhood?: NeighbourhoodExpression;
15
+ constructor(uuid?: string, name?: string, state?: PerspectiveState);
16
+ }
@@ -0,0 +1,178 @@
1
+ import { LinkCallback, PerspectiveClient, SyncStateChangeCallback } from "./PerspectiveClient";
2
+ import { Link, LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkMutations } from "../links/Links";
3
+ import { LinkQuery } from "./LinkQuery";
4
+ import { PerspectiveHandle, PerspectiveState } from './PerspectiveHandle';
5
+ import { Perspective } from "./Perspective";
6
+ import { ExpressionRendered } from "../expression/Expression";
7
+ import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
8
+ import { NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
9
+ type PerspectiveListenerTypes = "link-added" | "link-removed" | "link-updated";
10
+ export type LinkStatus = "shared" | "local";
11
+ interface Parameter {
12
+ name: string;
13
+ value: string;
14
+ }
15
+ /** Perspective UI proxy object
16
+ *
17
+ * Convenience object for UIs to interact with a perspective.
18
+ * It is created by some of the methods in the PerspectiveClient class and includes
19
+ * a reference to the PerspectiveClient object that created it.
20
+ */
21
+ export declare class PerspectiveProxy {
22
+ #private;
23
+ constructor(handle: PerspectiveHandle, ad4m: PerspectiveClient);
24
+ executeAction(actions: any, expression: any, parameters: Parameter[]): Promise<void>;
25
+ /** Unique ID of the perspective */
26
+ get uuid(): string;
27
+ /** Given name of the perspective */
28
+ get name(): string;
29
+ /** If the perspective is shared as a Neighbourhood, this is the Neighbourhood URL */
30
+ get sharedUrl(): string | void;
31
+ /** If the perspective is shared as a Neighbourhood, this is the Neighbourhood Expression */
32
+ get neighbourhood(): NeighbourhoodExpression | void;
33
+ /** Returns the state of the perspective **/
34
+ get state(): PerspectiveState;
35
+ /** Returns all the links of this perspective that matches the LinkQuery */
36
+ get(query: LinkQuery): Promise<LinkExpression[]>;
37
+ /** Runs a Prolog query on the perspective's Prolog engine */
38
+ infer(query: string): Promise<any>;
39
+ /** Adds a link to this perspective */
40
+ add(link: Link, status?: LinkStatus): Promise<LinkExpression>;
41
+ /** Adds multiple links to this perspective **/
42
+ addLinks(links: Link[], status?: LinkStatus): Promise<LinkExpression[]>;
43
+ /** Removes multiple links from this perspective **/
44
+ removeLinks(links: LinkExpressionInput[]): Promise<LinkExpression[]>;
45
+ /** Adds and removes multiple links from this perspective **/
46
+ linkMutations(mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations>;
47
+ /** Adds a linkExpression to this perspective */
48
+ addLinkExpression(link: LinkExpression, status?: LinkStatus): Promise<LinkExpression>;
49
+ update(oldLink: LinkExpressionInput, newLink: Link): Promise<LinkExpression>;
50
+ remove(link: LinkExpressionInput): Promise<{
51
+ perspectiveRemoveLink: boolean;
52
+ }>;
53
+ getExpression(expressionURI: string): Promise<ExpressionRendered>;
54
+ createExpression(content: any, languageAddress: string): Promise<string>;
55
+ /** Adds a link listener
56
+ * @param type Can be 'link-added' or 'link-removed'
57
+ * @param cb Callback function that is called when a link is added to the perspective
58
+ */
59
+ addListener(type: PerspectiveListenerTypes, cb: LinkCallback): Promise<void>;
60
+ /** Adds a sync state listener
61
+ * @param cb Callback function that is called when the sync state of the perspective changes
62
+ * @returns A function that can be called to remove the listener
63
+ */
64
+ addSyncStateChangeListener(cb: SyncStateChangeCallback): Promise<void>;
65
+ /** Removes a previously added link listener
66
+ * @param type Can be 'link-added' or 'link-removed'
67
+ * @param cb Callback function that is called when a link is added to the perspective
68
+ */
69
+ removeListener(type: PerspectiveListenerTypes, cb: LinkCallback): Promise<void>;
70
+ /** Create and return a snapshot of this perspective
71
+ * A snapshot is a rendered Perspectie object that contains all the links of the perspective.
72
+ */
73
+ snapshot(): Promise<Perspective>;
74
+ /** Take and load all the links from the given snapshot */
75
+ loadSnapshot(snapshot: Perspective): Promise<void>;
76
+ /** Convenience function to get the target of the first link that matches the given query
77
+ * This makes sense when the query is expected to return only one link
78
+ * and the target of that link is what you are looking for.
79
+ *
80
+ * Works best together with @member setSingelTarget()
81
+ */
82
+ getSingleTarget(query: LinkQuery): Promise<string | void>;
83
+ /** Convenience function to ensure there is only one link with given source and predicate
84
+ * This function will remove all links with the same source and predicate as the given link,
85
+ * and then add the given link.
86
+ * This ensures there is only one target for the given source and predicate.
87
+ *
88
+ * Works best together with @member getSingleTarget()
89
+ */
90
+ setSingleTarget(link: Link, status?: LinkStatus): Promise<void>;
91
+ /** Returns all the Social DNA flows defined in this perspective */
92
+ sdnaFlows(): Promise<string[]>;
93
+ /** Returns all Social DNA flows that can be started from the given expression */
94
+ availableFlows(exprAddr: string): Promise<string[]>;
95
+ /** Starts the Social DNA flow @param flowName on the expression @param exprAddr */
96
+ startFlow(flowName: string, exprAddr: string): Promise<void>;
97
+ /** Returns all expressions in the given state of given Social DNA flow */
98
+ expressionsInFlowState(flowName: string, flowState: number): Promise<string[]>;
99
+ /** Returns the given expression's flow state with regard to given Social DNA flow */
100
+ flowState(flowName: string, exprAddr: string): Promise<number>;
101
+ /** Returns available action names, with regard to Social DNA flow and expression's flow state */
102
+ flowActions(flowName: string, exprAddr: string): Promise<string[]>;
103
+ /** Runs given Social DNA flow action */
104
+ runFlowAction(flowName: string, exprAddr: string, actionName: string): Promise<void>;
105
+ /** Returns the perspective's Social DNA code
106
+ * This will return all SDNA code elements in an array.
107
+ */
108
+ getSdna(): Promise<string[]>;
109
+ /** Adds the given Social DNA code to the perspective's SDNA code */
110
+ addSdna(name: string, sdnaCode: string, type: "subject_class" | "flow" | "custom"): Promise<void>;
111
+ /** Returns all the Subject classes defined in this perspectives SDNA */
112
+ subjectClasses(): Promise<string[]>;
113
+ stringOrTemplateObjectToSubjectClass<T>(subjectClass: T): Promise<string>;
114
+ /** Creates a new subject instance by running its (SDNA defined) constructor,
115
+ * which means adding links around the given expression address so that it
116
+ * conforms to the given subject class.
117
+ *
118
+ * @param subjectClass Either a string with the name of the subject class, or an object
119
+ * with the properties of the subject class. In the latter case, the first subject class
120
+ * that matches the given properties will be used.
121
+ * @param exprAddr The address of the expression to be turned into a subject instance
122
+ */
123
+ createSubject<T>(subjectClass: T, exprAddr: string): Promise<T>;
124
+ /** Removes a subject instance by running its (SDNA defined) destructor,
125
+ * which means removing links around the given expression address
126
+ *
127
+ * @param subjectClass Either a string with the name of the subject class, or an object
128
+ * with the properties of the subject class. In the latter case, the first subject class
129
+ * that matches the given properties will be used.
130
+ * @param exprAddr The address of the expression to be turned into a subject instance
131
+ */
132
+ removeSubject<T>(subjectClass: T, exprAddr: string): Promise<void>;
133
+ /** Checks if the given expression is a subject instance of the given subject class
134
+ * @param expression The expression to be checked
135
+ * @param subjectClass Either a string with the name of the subject class, or an object
136
+ * with the properties of the subject class. In the latter case, the first subject class
137
+ * that matches the given properties will be used.
138
+ */
139
+ isSubjectInstance<T>(expression: string, subjectClass: T): Promise<boolean>;
140
+ /** For an existing subject instance (existing in the perspective's links)
141
+ * this function returns a proxy object that can be used to access the subject's
142
+ * properties and methods.
143
+ *
144
+ * @param base URI of the subject's root expression
145
+ * @param subjectClass Either a string with the name of the subject class, or an object
146
+ * with the properties of the subject class. In the latter case, the first subject class
147
+ * that matches the given properties will be used.
148
+ */
149
+ getSubjectProxy<T>(base: string, subjectClass: T): Promise<T>;
150
+ /** Returns all subject instances of the given subject class as proxy objects.
151
+ * @param subjectClass Either a string with the name of the subject class, or an object
152
+ * with the properties of the subject class. In the latter case, all subject classes
153
+ * that match the given properties will be used.
154
+ */
155
+ getAllSubjectInstances<T>(subjectClass: T): Promise<T[]>;
156
+ getAllSubjectProxies<T>(subjectClass: T): Promise<T[]>;
157
+ /** Returns all subject classes that match the given template object.
158
+ * This function looks at the properties of the template object and
159
+ * its setters and collections to create a Prolog query that finds
160
+ * all subject classes that would be converted to a proxy object
161
+ * with exactly the same properties and collections.
162
+ *
163
+ * Since there could be multiple subject classes that match the given
164
+ * criteria, this function returns a list of class names.
165
+ *
166
+ * @param obj The template object
167
+ */
168
+ subjectClassesByTemplate(obj: object): Promise<string[]>;
169
+ /** Takes a JS class (its constructor) and assumes that it was decorated by
170
+ * the @subjectClass etc. decorators. It then tests if there is a subject class
171
+ * already present in the perspective's SDNA that matches the given class.
172
+ * If there is no such class, it gets the JS class's SDNA by calling its
173
+ * static generateSDNA() function and adds it to the perspective's SDNA.
174
+ */
175
+ ensureSDNASubjectClass(jsClass: any): Promise<void>;
176
+ getNeighbourhoodProxy(): NeighbourhoodProxy;
177
+ }
178
+ export {};
@@ -0,0 +1,37 @@
1
+ import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
2
+ import { LinkQuery } from "./LinkQuery";
3
+ import { Perspective } from "./Perspective";
4
+ import { LinkStatus } from "./PerspectiveProxy";
5
+ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
6
+ export declare const testLink: LinkExpression;
7
+ /**
8
+ * Resolver classes are used here to define the GraphQL schema
9
+ * (through the type-graphql annotations)
10
+ * and are spawned in the client tests in Ad4mClient.test.ts.
11
+ * For the latter, they return test fixtures.
12
+ */
13
+ export default class PerspectiveResolver {
14
+ perspectives(): PerspectiveHandle[];
15
+ perspective(uuid: string): PerspectiveHandle | null;
16
+ perspectiveSnapshot(uuid: string): Perspective | null;
17
+ perspectivePublishSnapshot(uuid: string): String | null;
18
+ perspectiveQueryLinks(uuid: string, query: LinkQuery): LinkExpression[];
19
+ perspectiveQueryProlog(uuid: string, query: String): string;
20
+ perspectiveAdd(name: string, pubSub: any): PerspectiveHandle;
21
+ perspectiveUpdate(uuid: string, name: string, pubSub: any): PerspectiveHandle;
22
+ perspectiveRemove(uuid: string, pubSub: any): boolean;
23
+ perspectiveAddLink(uuid: string, link: LinkInput, status: LinkStatus, pubSub: any): LinkExpression;
24
+ perspectiveAddLinks(uuid: string, links: LinkInput[], status: string, pubSub: any): LinkExpression[];
25
+ perspectiveRemoveLinks(uuid: string, links: LinkExpressionInput[], pubSub: any): LinkExpression[];
26
+ perspectiveLinkMutations(uuid: string, mutations: LinkMutations, status: LinkStatus, pubSub: any): LinkExpressionMutations;
27
+ perspectiveAddLinkExpression(uuid: string, link: LinkExpressionInput, status: LinkStatus, pubSub: any): LinkExpression;
28
+ perspectiveUpdateLink(uuid: string, oldlink: LinkExpressionInput, newlink: LinkInput, pubSub: any): LinkExpression;
29
+ perspectiveRemoveLink(uuid: string, link: LinkExpressionInput, pubSub: any): Boolean;
30
+ perspectiveAdded(): PerspectiveHandle;
31
+ perspectiveUpdated(): PerspectiveHandle;
32
+ perspectiveRemoved(): string;
33
+ perspectiveLinkAdded(uuid: string): LinkExpression;
34
+ perspectiveLinkRemoved(uuid: string): LinkExpression;
35
+ perspectiveLinkUpdated(uuid: string): LinkExpressionUpdated;
36
+ perspectiveSyncStateChange(uuid: string): PerspectiveState;
37
+ }
@@ -0,0 +1,33 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { Perspective, PerspectiveExpression } from "../perspectives/Perspective";
3
+ import { RuntimeInfo, ExceptionInfo, SentMessage } from "./RuntimeResolver";
4
+ export type MessageCallback = (message: PerspectiveExpression) => null;
5
+ export type ExceptionCallback = (info: ExceptionInfo) => null;
6
+ export declare class RuntimeClient {
7
+ #private;
8
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
9
+ info(): Promise<RuntimeInfo>;
10
+ quit(): Promise<Boolean>;
11
+ openLink(url: string): Promise<Boolean>;
12
+ addTrustedAgents(agents: string[]): Promise<string[]>;
13
+ deleteTrustedAgents(agents: string[]): Promise<string[]>;
14
+ getTrustedAgents(): Promise<string[]>;
15
+ addKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]>;
16
+ removeKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]>;
17
+ knownLinkLanguageTemplates(): Promise<string[]>;
18
+ addFriends(dids: string[]): Promise<string[]>;
19
+ removeFriends(dids: string[]): Promise<string[]>;
20
+ friends(): Promise<string[]>;
21
+ hcAgentInfos(): Promise<String>;
22
+ hcAddAgentInfos(agentInfos: String): Promise<void>;
23
+ verifyStringSignedByDid(did: string, didSigningKeyId: string, data: string, signedData: string): Promise<boolean>;
24
+ setStatus(perspective: Perspective): Promise<boolean>;
25
+ friendStatus(did: string): Promise<PerspectiveExpression>;
26
+ friendSendMessage(did: string, message: Perspective): Promise<boolean>;
27
+ messageInbox(filter?: string): Promise<PerspectiveExpression[]>;
28
+ messageOutbox(filter?: string): Promise<SentMessage[]>;
29
+ addMessageCallback(cb: MessageCallback): void;
30
+ subscribeMessageReceived(): void;
31
+ addExceptionCallback(cb: ExceptionCallback): void;
32
+ subscribeExceptionOccurred(): void;
33
+ }