@coasys/ad4m 0.13.0-test-2 → 0.13.0-test-3
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/lib/index.cjs +1060 -147
- package/lib/index.js +1054 -147
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.js +0 -1
- package/lib/src/language/Language.d.ts +26 -214
- package/lib/src/language/Language.js +28 -2
- package/lib/src/model/Ad4mModel.d.ts +25 -1
- package/lib/src/model/Ad4mModel.js +139 -30
- package/lib/src/model/Ad4mModel.test.js +214 -32
- package/lib/src/model/ModelQueryBuilder.d.ts +19 -0
- package/lib/src/model/ModelQueryBuilder.js +62 -18
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +1 -0
- package/lib/src/model/hydration.js +279 -70
- package/lib/src/model/query-sparql.d.ts +78 -1
- package/lib/src/model/query-sparql.js +447 -16
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +495 -0
- package/lib/src/model/query-utils.js +4 -0
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.js +48 -2
- package/lib/src/model/types.d.ts +49 -1
- package/lib/src/perspectives/PerspectiveClient.d.ts +2 -0
- package/lib/src/perspectives/PerspectiveClient.js +37 -9
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +169 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +3 -0
- package/lib/src/perspectives/PerspectiveProxy.js +15 -0
- package/package.json +1 -1
- package/src/Ad4mClient.test.ts +56 -1
- package/src/index.ts +0 -1
- package/src/language/Language.ts +54 -275
- package/src/model/Ad4mModel.test.ts +222 -35
- package/src/model/Ad4mModel.ts +144 -30
- package/src/model/ModelQueryBuilder.ts +66 -18
- package/src/model/hydration-batching.test.ts +563 -0
- package/src/model/hydration.ts +249 -47
- package/src/model/query-sparql.test.ts +568 -0
- package/src/model/query-sparql.ts +473 -16
- package/src/model/query-utils.ts +4 -0
- package/src/model/subscription-delta.test.ts +207 -0
- package/src/model/subscription-pool.ts +50 -2
- package/src/model/types.ts +50 -1
- package/src/perspectives/PerspectiveClient.test.ts +204 -0
- package/src/perspectives/PerspectiveClient.ts +36 -7
- package/src/perspectives/PerspectiveProxy.ts +18 -0
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.d.ts +0 -42
- package/lib/src/model/surreal-utils.js +0 -128
- package/src/language/LanguageContext.ts +0 -37
- package/tsconfig-browser.json +0 -82
package/package.json
CHANGED
package/src/Ad4mClient.test.ts
CHANGED
|
@@ -32,6 +32,19 @@ import { PerspectiveState } from "./perspectives/PerspectiveHandle";
|
|
|
32
32
|
|
|
33
33
|
jest.setTimeout(15000)
|
|
34
34
|
|
|
35
|
+
/** Wait for a mock function to reach the expected call count (with timeout). */
|
|
36
|
+
async function waitForCalls(fn: jest.Mock, count: number, timeoutMs = 2000): Promise<void> {
|
|
37
|
+
const start = Date.now();
|
|
38
|
+
while (fn.mock.calls.length < count) {
|
|
39
|
+
if (Date.now() - start > timeoutMs) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`waitForCalls timed out after ${timeoutMs}ms: expected ${count} calls but received ${fn.mock.calls.length}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
await new Promise(r => setTimeout(r, 50));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
35
48
|
async function createGqlServer(port: number) {
|
|
36
49
|
const schema = await buildSchema({
|
|
37
50
|
resolvers: [
|
|
@@ -730,6 +743,7 @@ describe('Ad4mClient', () => {
|
|
|
730
743
|
link.target = 'perspective://Qm34589a3ccc0'
|
|
731
744
|
await perspective.add(link)
|
|
732
745
|
|
|
746
|
+
await waitForCalls(linkAdded, 1)
|
|
733
747
|
expect(linkAdded).toBeCalledTimes(1)
|
|
734
748
|
expect(linkRemoved).toBeCalledTimes(0)
|
|
735
749
|
|
|
@@ -738,6 +752,7 @@ describe('Ad4mClient', () => {
|
|
|
738
752
|
await perspective.addListener('link-removed', linkRemoved)
|
|
739
753
|
await perspective.remove(testLink)
|
|
740
754
|
|
|
755
|
+
await waitForCalls(linkRemoved, 1)
|
|
741
756
|
expect(linkAdded).toBeCalledTimes(1)
|
|
742
757
|
expect(linkRemoved).toBeCalledTimes(1)
|
|
743
758
|
})
|
|
@@ -750,6 +765,7 @@ describe('Ad4mClient', () => {
|
|
|
750
765
|
await perspective.addListener('link-added', linkAdded)
|
|
751
766
|
await perspective.add({source: 'root', target: 'neighbourhood://Qm12345'})
|
|
752
767
|
|
|
768
|
+
await waitForCalls(linkAdded, 1)
|
|
753
769
|
expect(linkAdded).toBeCalledTimes(1)
|
|
754
770
|
|
|
755
771
|
linkAdded.mockClear();
|
|
@@ -759,7 +775,10 @@ describe('Ad4mClient', () => {
|
|
|
759
775
|
await perspective.removeListener('link-added', linkAdded)
|
|
760
776
|
await perspective.add({source: 'root', target: 'neighbourhood://Qm123456'})
|
|
761
777
|
|
|
762
|
-
|
|
778
|
+
// With proxy caching, removeListener operates on the same proxy,
|
|
779
|
+
// so the callback should NOT fire after removal.
|
|
780
|
+
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
781
|
+
expect(linkAdded).toBeCalledTimes(0)
|
|
763
782
|
})
|
|
764
783
|
|
|
765
784
|
it('addSyncStateChangeListener() smoke test', async () => {
|
|
@@ -770,6 +789,7 @@ describe('Ad4mClient', () => {
|
|
|
770
789
|
await perspective.addSyncStateChangeListener(syncState)
|
|
771
790
|
await perspective.add({source: 'root', target: 'neighbourhood://Qm12345'})
|
|
772
791
|
|
|
792
|
+
await waitForCalls(syncState, 1)
|
|
773
793
|
expect(syncState).toBeCalledTimes(1)
|
|
774
794
|
expect(syncState).toBeCalledWith(PerspectiveState.Synced)
|
|
775
795
|
})
|
|
@@ -818,6 +838,41 @@ describe('Ad4mClient', () => {
|
|
|
818
838
|
);
|
|
819
839
|
expect(result).toBeTruthy();
|
|
820
840
|
})
|
|
841
|
+
|
|
842
|
+
it('byUUID() returns same reference on repeated calls (proxy cache hit)', async () => {
|
|
843
|
+
const p1 = await ad4mClient.perspective.byUUID('00001')
|
|
844
|
+
const p2 = await ad4mClient.perspective.byUUID('00001')
|
|
845
|
+
expect(p1).toBe(p2) // strict reference equality
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
it('update() then byUUID() returns updated name (in-place update)', async () => {
|
|
849
|
+
const updated = await ad4mClient.perspective.update('00001', 'updated-name')
|
|
850
|
+
expect(updated.name).toBe('updated-name')
|
|
851
|
+
const fetched = await ad4mClient.perspective.byUUID('00001')
|
|
852
|
+
expect(fetched).toBe(updated) // same reference
|
|
853
|
+
expect(fetched.name).toBe('updated-name')
|
|
854
|
+
})
|
|
855
|
+
|
|
856
|
+
it('remove() evicts proxy from cache (new reference on next fetch)', async () => {
|
|
857
|
+
// First populate cache
|
|
858
|
+
const p = await ad4mClient.perspective.byUUID('00003')
|
|
859
|
+
expect(p).toBeTruthy()
|
|
860
|
+
// Remove evicts from cache
|
|
861
|
+
await ad4mClient.perspective.remove('00003')
|
|
862
|
+
// Now byUUID should query server — server returns a new handle for any uuid
|
|
863
|
+
// but the cache was cleared, so a new proxy is created
|
|
864
|
+
const p2 = await ad4mClient.perspective.byUUID('00003')
|
|
865
|
+
expect(p2).not.toBe(p) // different reference after eviction + re-fetch
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
it('all() returns cached proxies for known UUIDs', async () => {
|
|
869
|
+
// First get a proxy via byUUID
|
|
870
|
+
const p1 = await ad4mClient.perspective.byUUID('00001')
|
|
871
|
+
// all() should return the same cached proxy for '00001'
|
|
872
|
+
const allPerspectives = await ad4mClient.perspective.all()
|
|
873
|
+
const match = allPerspectives.find(p => p.uuid === '00001')
|
|
874
|
+
expect(match).toBe(p1) // same reference
|
|
875
|
+
})
|
|
821
876
|
})
|
|
822
877
|
|
|
823
878
|
describe('.runtime', () => {
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ export * from "./expression/ExpressionRef";
|
|
|
8
8
|
export * from "./language/Icon";
|
|
9
9
|
export * from "./language/Language";
|
|
10
10
|
export * from "./language/LanguageRef";
|
|
11
|
-
export * from "./language/LanguageContext";
|
|
12
11
|
export * from "./language/LanguageHandle";
|
|
13
12
|
export * from "./language/LanguageMeta";
|
|
14
13
|
export * from "./links/Links";
|
package/src/language/Language.ts
CHANGED
|
@@ -1,234 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type { Expression } from '../expression/Expression'
|
|
4
|
-
import { Perspective, PerspectiveExpression } from '../perspectives/Perspective';
|
|
5
|
-
import { PerspectiveDiff } from '../perspectives/PerspectiveDiff';
|
|
1
|
+
import { DID } from "../DID";
|
|
2
|
+
import { PerspectiveExpression } from "../perspectives/Perspective";
|
|
6
3
|
import { InputType, Field, ObjectType } from "type-graphql";
|
|
7
|
-
import { PerspectiveState } from '../perspectives/PerspectiveHandle';
|
|
8
|
-
import { LinkQuery } from '../perspectives/LinkQuery';
|
|
9
4
|
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* and
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* The
|
|
24
|
-
*
|
|
25
|
-
*
|
|
5
|
+
/**
|
|
6
|
+
* # AD4M Language — client-side types
|
|
7
|
+
*
|
|
8
|
+
* This file only contains the client-visible types that the AD4M GraphQL
|
|
9
|
+
* API exposes on top of a running Language — interaction metadata, online
|
|
10
|
+
* agent records, and the telepresence-signal callback shape.
|
|
11
|
+
*
|
|
12
|
+
* **If you're authoring an AD4M Language**, you don't consume types from
|
|
13
|
+
* here — use [`@coasys/ad4m-ldk`](https://www.npmjs.com/package/@coasys/ad4m-ldk)
|
|
14
|
+
* (or the [Rust ALDK](https://crates.io/crates/ad4m-ldk)), which provide
|
|
15
|
+
* the capability traits, typed runtime-import wrappers, and authoring
|
|
16
|
+
* macros/helpers.
|
|
17
|
+
*
|
|
18
|
+
* The normative interface definition lives in
|
|
19
|
+
* [`docs-src/ad4m-lang.wit`](https://github.com/coasys/ad4m/blob/dev/docs-src/ad4m-lang.wit).
|
|
20
|
+
* The prose spec is
|
|
21
|
+
* [`docs-src/language-interface-spec.md`](https://github.com/coasys/ad4m/blob/dev/docs-src/language-interface-spec.md).
|
|
26
22
|
*/
|
|
27
|
-
export interface Language {
|
|
28
|
-
readonly name: string;
|
|
29
|
-
|
|
30
|
-
/** Flagging expressions as immutable to enable
|
|
31
|
-
* expression caching in the ad4m-executor
|
|
32
|
-
*/
|
|
33
|
-
isImmutableExpression?(expression: Address): boolean;
|
|
34
|
-
|
|
35
|
-
// Adapter implementations:
|
|
36
|
-
|
|
37
|
-
/** ExpressionAdapter implements means of getting an Expression
|
|
38
|
-
* by address and putting an expression
|
|
39
|
-
*/
|
|
40
|
-
readonly expressionAdapter?: ExpressionAdapter;
|
|
41
|
-
|
|
42
|
-
/** Interface for getting UI/web components for rendering Expressions of this Language */
|
|
43
|
-
readonly expressionUI?: ExpressionUI;
|
|
44
|
-
|
|
45
|
-
// TODO: Rename linksAdapter to perspectiveSyncAdapter needs a lot of changes elsewhere...
|
|
46
|
-
/** Interface of LinkLanguages for the core implementation of Neighbourhoods */
|
|
47
|
-
readonly perspectiveSyncAdapter?: PerspectiveSyncAdapter;
|
|
48
|
-
|
|
49
|
-
/** Interface for Languages that implement a query return a Perspective (snapshot)
|
|
50
|
-
* Used for back-links and wrapping of APIs that implement queries.
|
|
51
|
-
*/
|
|
52
|
-
readonly pespectiveQueryAdapter?: PerspectiveQueryAdapter;
|
|
53
|
-
|
|
54
|
-
/** Additional Interface of LinkLanguages that support telepresence features,
|
|
55
|
-
* that is:
|
|
56
|
-
* - seeing who is online and getting a status
|
|
57
|
-
* - sending/receiveing p2p signals to other online agents without affecting
|
|
58
|
-
* the shared Perspective of the Neighbourhood
|
|
59
|
-
* (see TelepresenceAdapter for more details)
|
|
60
|
-
*/
|
|
61
|
-
readonly telepresenceAdapter?: TelepresenceAdapter;
|
|
62
|
-
|
|
63
|
-
/** Implementation of a Language that defines and stores Languages*/
|
|
64
|
-
readonly languageAdapter?: LanguageAdapter;
|
|
65
|
-
|
|
66
|
-
/** Optional adapter for getting Expressions by author */
|
|
67
|
-
readonly getByAuthorAdapter?: GetByAuthorAdapter;
|
|
68
|
-
/** Optional adapter for getting all Expressions */
|
|
69
|
-
readonly getAllAdapter?: GetAllAdapter;
|
|
70
|
-
|
|
71
|
-
/** Optional adapter for direct messaging between agents */
|
|
72
|
-
readonly directMessageAdapter?: DirectMessageAdapter;
|
|
73
|
-
|
|
74
|
-
/** Interface for providing UI components for the settings of this Language */
|
|
75
|
-
readonly settingsUI?: SettingsUI;
|
|
76
|
-
|
|
77
|
-
/** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
|
|
78
|
-
readonly teardown?: () => void;
|
|
79
|
-
|
|
80
|
-
/** All available interactions this agent could execute on given expression */
|
|
81
|
-
interactions(expression: Address): Interaction[];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** UI factories returning web components */
|
|
85
|
-
export interface ExpressionUI {
|
|
86
|
-
/** Returns JS code of a web component that renders the given expression */
|
|
87
|
-
icon(): string;
|
|
88
|
-
/** Returns JS code of a web component used to create new expressions */
|
|
89
|
-
constructorIcon(): string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface SettingsUI {
|
|
93
|
-
settingsIcon(): string;
|
|
94
|
-
}
|
|
95
|
-
/** Interface for the most common Expression Languages */
|
|
96
|
-
export interface ExpressionAdapter {
|
|
97
|
-
/** Returns an Expression by address, or null if there is no Expression
|
|
98
|
-
* with that given address
|
|
99
|
-
*/
|
|
100
|
-
get(address: Address): Promise<Expression | null>;
|
|
101
|
-
|
|
102
|
-
/** Strategy for putting an expression with needs to be different
|
|
103
|
-
* for those two cases:
|
|
104
|
-
* 1. PublicSharing means that this language supports the creation
|
|
105
|
-
* and sharing of Expressions, which is the common use-case
|
|
106
|
-
* 2. ReadOnlyLanguage means that the Language implements a pre-defined
|
|
107
|
-
* set of expressions (which can be infinite or finite).
|
|
108
|
-
* For example the url-iframe Language which directly maps URLs to
|
|
109
|
-
* addresses - meaning every well formed URL is an address in this
|
|
110
|
-
* Language. Or a potential Language implementing the verbs/predicates
|
|
111
|
-
* of a spec like FOAF.
|
|
112
|
-
*/
|
|
113
|
-
putAdapter: PublicSharing | ReadOnlyLanguage;
|
|
114
|
-
}
|
|
115
23
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* @param content is the object created by the constructorIcon component
|
|
124
|
-
*/
|
|
125
|
-
createPublic(content: object): Promise<Address>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Implement this interface if your Language is defined over a static
|
|
129
|
-
* set of pre-defined Expressions.
|
|
130
|
-
*/
|
|
131
|
-
export interface ReadOnlyLanguage {
|
|
132
|
-
/** This just calculates the address of an object
|
|
133
|
-
* @param content is the object created by the constructorIcon component
|
|
134
|
-
*/
|
|
135
|
-
addressOf(content: object): Promise<Address>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export interface LanguageAdapter {
|
|
139
|
-
getLanguageSource(address: Address): Promise<string>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Implement this if your Language supports retrieval of all Expressions
|
|
143
|
-
// authored by a given agent
|
|
144
|
-
export interface GetByAuthorAdapter {
|
|
145
|
-
/// Get expressions authored by a given Agent/Identity
|
|
146
|
-
getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Implement this if your Language supports retrieval of all Expressions
|
|
150
|
-
// stored in the space of that Language.
|
|
151
|
-
// Might not be trivial (without trade-off) for Holochain or DHTs
|
|
152
|
-
// in general - hence not a required interface.
|
|
153
|
-
export interface GetAllAdapter {
|
|
154
|
-
/// Get expressions authored by a given Agent/Identity
|
|
155
|
-
getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export type PerspectiveDiffObserver = (diff: PerspectiveDiff)=>void;
|
|
159
|
-
export type SyncStateChangeObserver = (state: PerspectiveState)=>void;
|
|
160
|
-
|
|
161
|
-
/** Interface for "Link Languages" that facilitate the synchronization
|
|
162
|
-
* between agents' local Perspectives inside a Neighbourhood.
|
|
163
|
-
* The assumption is that every version of the shared Perspective
|
|
164
|
-
* is labeled with a unique revision string.
|
|
165
|
-
* Changes are committed and retrieved through diffs.
|
|
166
|
-
* Think of a PerspectiveSyncAdapter as a git branch to which agents commit
|
|
167
|
-
* their changes to and pull diffs from their current revision
|
|
168
|
-
* to the latest one.
|
|
169
|
-
*/
|
|
170
|
-
export interface PerspectiveSyncAdapter {
|
|
171
|
-
writable(): boolean;
|
|
172
|
-
public(): boolean;
|
|
173
|
-
others(): Promise<DID[]>;
|
|
174
|
-
|
|
175
|
-
/** What revision are we on now -> what changes are included in output of render() */
|
|
176
|
-
currentRevision(): Promise<string>;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Check for and get new changes,
|
|
180
|
-
* notify others of local changes.
|
|
181
|
-
* This function will be called every
|
|
182
|
-
* few seconds by the ad4m-executor.
|
|
183
|
-
* */
|
|
184
|
-
sync(): Promise<PerspectiveDiff>;
|
|
185
|
-
|
|
186
|
-
/** Returns the full, rendered Perspective at currentRevision */
|
|
187
|
-
render(): Promise<Perspective>;
|
|
188
|
-
|
|
189
|
-
/** Publish changes */
|
|
190
|
-
commit(diff: PerspectiveDiff): Promise<string>;
|
|
191
|
-
|
|
192
|
-
/** Get push notification when a diff got published */
|
|
193
|
-
addCallback(callback: PerspectiveDiffObserver);
|
|
194
|
-
|
|
195
|
-
/** Add a sync state callback method */
|
|
196
|
-
addSyncStateChangeCallback(callback: SyncStateChangeObserver);
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Set the local agents (DIDs) that own this perspective/neighbourhood.
|
|
200
|
-
* This is used to determine which agents should be registered in the DHT.
|
|
201
|
-
* Optional - if not implemented, all local agents may be registered.
|
|
202
|
-
*
|
|
203
|
-
* This is a temporary hack to support multiple users on one node joining the same neighbourhood.
|
|
204
|
-
* Once we migrate the LanguageController to Rust and run Languages per user, each user will get their
|
|
205
|
-
* own language instance and we won't need to explicitly set local agents. This will provide better
|
|
206
|
-
* isolation and avoid the need to share language state between users.
|
|
207
|
-
*/
|
|
208
|
-
setLocalAgents?(agents: DID[]): void;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export type MessageCallback = (message: PerspectiveExpression) => void;
|
|
212
|
-
export type StatusCallback = (caller: DID) => Perspective;
|
|
213
|
-
export interface DirectMessageAdapter {
|
|
214
|
-
recipient(): DID;
|
|
215
|
-
|
|
216
|
-
status(): Promise<PerspectiveExpression | void>;
|
|
217
|
-
sendP2P(message: Perspective): Promise<PerspectiveExpression|void>;
|
|
218
|
-
sendInbox(message: Perspective): Promise<PerspectiveExpression|void>;
|
|
219
|
-
|
|
220
|
-
setStatus(status: PerspectiveExpression);
|
|
221
|
-
inbox(filter?: string): Promise<PerspectiveExpression[]>
|
|
222
|
-
addMessageCallback(callback: MessageCallback);
|
|
223
|
-
}
|
|
24
|
+
// ----- Interaction metadata --------------------------------------------------
|
|
25
|
+
//
|
|
26
|
+
// Languages optionally publish a list of user-invocable actions per
|
|
27
|
+
// Expression ("interactions"). The runtime surfaces these to UIs via
|
|
28
|
+
// GraphQL, which is why `InteractionParameter` / `InteractionMeta` /
|
|
29
|
+
// `InteractionCall` need the type-graphql decorators — they cross the
|
|
30
|
+
// GraphQL boundary as first-class objects.
|
|
224
31
|
|
|
225
32
|
@ObjectType()
|
|
226
33
|
export class InteractionParameter {
|
|
227
34
|
@Field()
|
|
228
|
-
name: string
|
|
35
|
+
name: string;
|
|
229
36
|
|
|
230
37
|
@Field()
|
|
231
|
-
type: string
|
|
38
|
+
type: string;
|
|
232
39
|
}
|
|
233
40
|
|
|
234
41
|
@ObjectType()
|
|
@@ -239,85 +46,57 @@ export class InteractionMeta {
|
|
|
239
46
|
@Field()
|
|
240
47
|
name: string;
|
|
241
48
|
|
|
242
|
-
@Field(
|
|
243
|
-
parameters: InteractionParameter[]
|
|
49
|
+
@Field(() => [InteractionParameter])
|
|
50
|
+
parameters: InteractionParameter[];
|
|
244
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Runtime-side interaction object. The runtime constructs one of these
|
|
55
|
+
* from a Language's `interactions(address)` description and exposes
|
|
56
|
+
* `execute()` to UI callers. Language authors describe interactions
|
|
57
|
+
* via the ALDK, not by constructing this type directly.
|
|
58
|
+
*/
|
|
245
59
|
export interface Interaction {
|
|
246
60
|
readonly label: string;
|
|
247
61
|
readonly name: string;
|
|
248
62
|
readonly parameters: InteractionParameter[];
|
|
249
|
-
execute(parameters: object): Promise<string|null>;
|
|
63
|
+
execute(parameters: object): Promise<string | null>;
|
|
250
64
|
}
|
|
251
65
|
|
|
252
66
|
@InputType()
|
|
253
67
|
export class InteractionCall {
|
|
254
68
|
@Field()
|
|
255
69
|
name: string;
|
|
70
|
+
|
|
256
71
|
@Field()
|
|
257
72
|
parametersStringified: string;
|
|
258
73
|
|
|
259
74
|
public get parameters(): object {
|
|
260
|
-
return JSON.parse(this.parametersStringified)
|
|
75
|
+
return JSON.parse(this.parametersStringified);
|
|
261
76
|
}
|
|
262
77
|
|
|
263
78
|
constructor(name: string, parameters: object) {
|
|
264
|
-
this.name = name
|
|
265
|
-
this.parametersStringified = JSON.stringify(parameters)
|
|
79
|
+
this.name = name;
|
|
80
|
+
this.parametersStringified = JSON.stringify(parameters);
|
|
266
81
|
}
|
|
267
82
|
}
|
|
268
83
|
|
|
84
|
+
// ----- Telepresence ----------------------------------------------------------
|
|
85
|
+
|
|
269
86
|
@ObjectType()
|
|
270
87
|
export class OnlineAgent {
|
|
271
88
|
@Field()
|
|
272
|
-
did: DID
|
|
273
|
-
@Field()
|
|
274
|
-
status: PerspectiveExpression
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export type TelepresenceSignalCallback = (payload: PerspectiveExpression, recipientDid?: string) => void;
|
|
278
|
-
export interface TelepresenceAdapter {
|
|
279
|
-
setOnlineStatus(status: PerspectiveExpression): Promise<void>;
|
|
280
|
-
getOnlineAgents(): Promise<OnlineAgent[]>;
|
|
89
|
+
did: DID;
|
|
281
90
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
|
|
91
|
+
@Field()
|
|
92
|
+
status: PerspectiveExpression;
|
|
285
93
|
}
|
|
286
94
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
*
|
|
290
|
-
* access to other shared perspectives without forcing a full-sync.
|
|
291
|
-
*
|
|
292
|
-
* All PerspectiveQuery Languages are supposed to implement `linkQuery` which is a simple graph query
|
|
293
|
-
* specifying non or all of source, predicate, target of the links we want to get.
|
|
294
|
-
* This is enough to implement simple back-links.
|
|
295
|
-
*
|
|
296
|
-
* Prolog queries are optional since this requires a Prolog engine to be available.
|
|
297
|
-
*
|
|
95
|
+
/**
|
|
96
|
+
* Callback shape used by the client to receive telepresence signals
|
|
97
|
+
* from a Neighbourhood's link Language.
|
|
298
98
|
*/
|
|
299
|
-
export
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
/** Tells ADAM if Prolog queries are implemented by this Language.
|
|
304
|
-
* If not, prologQuery won't be used, instead in some circumstances,
|
|
305
|
-
* linkQuery() might be called with an all-query, followed by using
|
|
306
|
-
* ADAM's internal Prolog engine on the result.
|
|
307
|
-
*/
|
|
308
|
-
supportsPrologQueries(): boolean;
|
|
309
|
-
|
|
310
|
-
/** Same semantic as PerspectiveProxy.infer, will return plain Prolog results */
|
|
311
|
-
infer(prologQuery: string): Promise<any>
|
|
312
|
-
|
|
313
|
-
/** Specify which links shall be returned through Prolog.
|
|
314
|
-
* Assumes unbound variables in query that describe a LinkExpression:
|
|
315
|
-
* - Source
|
|
316
|
-
* - Predicate
|
|
317
|
-
* - Target
|
|
318
|
-
* - Author
|
|
319
|
-
* - Timestamp
|
|
320
|
-
* Will construct a Perspective where each link is a solution to the query.
|
|
321
|
-
*/
|
|
322
|
-
prologQuery(query: string): Promise<Perspective>;
|
|
323
|
-
}
|
|
99
|
+
export type TelepresenceSignalCallback = (
|
|
100
|
+
payload: PerspectiveExpression,
|
|
101
|
+
recipientDid?: string,
|
|
102
|
+
) => void;
|