@coasys/ad4m 0.8.0-fix → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -229
- package/jest.config.js +5 -5
- package/jsdoc.json +27 -27
- package/lib/index.cjs +4522 -4571
- package/lib/index.js +4522 -4571
- package/lib/shims/type-graphql.d.ts +32 -32
- package/lib/shims/type-graphql.js +70 -70
- package/lib/src/Ad4mClient.d.ts +26 -26
- package/lib/src/Ad4mClient.js +66 -66
- package/lib/src/Address.d.ts +1 -1
- package/lib/src/Address.js +1 -1
- package/lib/src/DID.d.ts +1 -1
- package/lib/src/DID.js +1 -1
- package/lib/src/Exception.d.ts +6 -6
- package/lib/src/Exception.js +7 -7
- package/lib/src/Literal.d.ts +7 -7
- package/lib/src/Literal.js +76 -76
- package/lib/src/PubSub.d.ts +14 -14
- package/lib/src/PubSub.js +14 -14
- package/lib/src/SmartLiteral.d.ts +12 -12
- package/lib/src/SmartLiteral.js +74 -74
- package/lib/src/agent/Agent.d.ts +104 -104
- package/lib/src/agent/Agent.js +337 -337
- package/lib/src/agent/AgentClient.d.ts +57 -57
- package/lib/src/agent/AgentClient.js +431 -431
- package/lib/src/agent/AgentResolver.d.ts +30 -30
- package/lib/src/agent/AgentResolver.js +325 -325
- package/lib/src/agent/AgentStatus.d.ts +8 -8
- package/lib/src/agent/AgentStatus.js +61 -61
- package/lib/src/buildSchema.d.ts +1 -1
- package/lib/src/buildSchema.js +36 -36
- package/lib/src/expression/Expression.d.ts +28 -28
- package/lib/src/expression/Expression.js +143 -143
- package/lib/src/expression/ExpressionClient.d.ts +13 -13
- package/lib/src/expression/ExpressionClient.js +102 -102
- package/lib/src/expression/ExpressionRef.d.ts +9 -9
- package/lib/src/expression/ExpressionRef.js +67 -67
- package/lib/src/expression/ExpressionResolver.d.ts +10 -10
- package/lib/src/expression/ExpressionResolver.js +106 -106
- package/lib/src/index.d.ts +30 -30
- package/lib/src/index.js +30 -30
- package/lib/src/jestSetup.d.ts +1 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.d.ts +4 -4
- package/lib/src/language/Icon.js +24 -24
- package/lib/src/language/Language.d.ts +195 -195
- package/lib/src/language/Language.js +79 -79
- package/lib/src/language/LanguageClient.d.ts +17 -17
- package/lib/src/language/LanguageClient.js +137 -137
- package/lib/src/language/LanguageContext.d.ts +37 -37
- package/lib/src/language/LanguageContext.js +2 -2
- package/lib/src/language/LanguageHandle.d.ts +9 -9
- package/lib/src/language/LanguageHandle.js +41 -41
- package/lib/src/language/LanguageMeta.d.ts +35 -35
- package/lib/src/language/LanguageMeta.js +89 -89
- package/lib/src/language/LanguageRef.d.ts +6 -6
- package/lib/src/language/LanguageRef.js +30 -30
- package/lib/src/language/LanguageResolver.d.ts +19 -19
- package/lib/src/language/LanguageResolver.js +143 -143
- package/lib/src/links/Links.d.ts +39 -39
- package/lib/src/links/Links.js +148 -148
- package/lib/src/links/Links.test.d.ts +1 -1
- package/lib/src/links/Links.test.js +33 -33
- package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -10
- package/lib/src/neighbourhood/Neighbourhood.js +38 -38
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -25
- package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -256
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -19
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -54
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -24
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -180
- package/lib/src/perspectives/LinkQuery.d.ts +11 -11
- package/lib/src/perspectives/LinkQuery.js +80 -80
- package/lib/src/perspectives/Perspective.d.ts +38 -38
- package/lib/src/perspectives/Perspective.js +144 -144
- package/lib/src/perspectives/Perspective.test.d.ts +1 -1
- package/lib/src/perspectives/Perspective.test.js +20 -20
- package/lib/src/perspectives/PerspectiveClient.d.ts +55 -54
- package/lib/src/perspectives/PerspectiveClient.js +418 -410
- package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveDiff.js +33 -33
- package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -16
- package/lib/src/perspectives/PerspectiveHandle.js +59 -59
- package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -178
- package/lib/src/perspectives/PerspectiveProxy.js +501 -540
- package/lib/src/perspectives/PerspectiveResolver.d.ts +38 -37
- package/lib/src/perspectives/PerspectiveResolver.js +376 -362
- package/lib/src/runtime/RuntimeClient.d.ts +33 -33
- package/lib/src/runtime/RuntimeClient.js +263 -263
- package/lib/src/runtime/RuntimeResolver.d.ts +47 -47
- package/lib/src/runtime/RuntimeResolver.js +328 -328
- package/lib/src/schema.gql +1 -0
- package/lib/src/subject/SDNADecorators.d.ts +45 -45
- package/lib/src/subject/SDNADecorators.js +250 -250
- package/lib/src/subject/Subject.d.ts +7 -7
- package/lib/src/subject/Subject.js +160 -160
- package/lib/src/subject/SubjectEntity.d.ts +31 -31
- package/lib/src/subject/SubjectEntity.js +250 -250
- package/lib/src/subject/util.d.ts +12 -12
- package/lib/src/subject/util.js +73 -73
- package/lib/src/typeDefs.d.ts +1 -1
- package/lib/src/typeDefs.js +1 -0
- package/lib/src/unwrapApolloResult.d.ts +2 -2
- package/lib/src/unwrapApolloResult.js +14 -12
- package/lib/src/utils.d.ts +2 -2
- package/lib/src/utils.js +21 -21
- package/package.json +61 -61
- package/rollup.config.js +26 -26
- package/shims/type-graphql.ts +75 -75
- package/src/Ad4mClient.test.ts +1089 -1084
- package/src/Ad4mClient.ts +62 -62
- package/src/Address.ts +1 -1
- package/src/Exception.ts +6 -6
- package/src/Literal.test.ts +30 -30
- package/src/Literal.ts +80 -80
- package/src/PubSub.ts +13 -13
- package/src/SmartLiteral.ts +74 -74
- package/src/agent/Agent.ts +293 -293
- package/src/agent/AgentClient.ts +531 -531
- package/src/agent/AgentResolver.ts +263 -263
- package/src/agent/AgentStatus.ts +43 -43
- package/src/buildSchema.ts +41 -41
- package/src/expression/Expression.ts +99 -99
- package/src/expression/ExpressionClient.ts +98 -98
- package/src/expression/ExpressionRef.ts +62 -62
- package/src/expression/ExpressionResolver.ts +63 -63
- package/src/index.ts +30 -30
- package/src/language/Icon.ts +10 -10
- package/src/language/Language.ts +266 -266
- package/src/language/LanguageClient.ts +159 -159
- package/src/language/LanguageContext.ts +37 -37
- package/src/language/LanguageHandle.ts +23 -23
- package/src/language/LanguageMeta.ts +69 -69
- package/src/language/LanguageRef.ts +18 -18
- package/src/language/LanguageResolver.ts +98 -98
- package/src/links/Links.test.ts +39 -39
- package/src/links/Links.ts +107 -107
- package/src/neighbourhood/Neighbourhood.ts +22 -22
- package/src/neighbourhood/NeighbourhoodClient.ts +275 -275
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -58
- package/src/neighbourhood/NeighbourhoodResolver.ts +99 -99
- package/src/perspectives/LinkQuery.ts +65 -65
- package/src/perspectives/Perspective.test.ts +22 -22
- package/src/perspectives/Perspective.ts +118 -118
- package/src/perspectives/PerspectiveClient.ts +452 -443
- package/src/perspectives/PerspectiveDiff.ts +15 -15
- package/src/perspectives/PerspectiveHandle.ts +39 -39
- package/src/perspectives/PerspectiveProxy.ts +576 -610
- package/src/perspectives/PerspectiveResolver.ts +224 -219
- package/src/runtime/RuntimeClient.ts +282 -282
- package/src/runtime/RuntimeResolver.ts +192 -192
- package/src/subject/SDNADecorators.ts +333 -333
- package/src/subject/Subject.ts +152 -152
- package/src/subject/SubjectEntity.ts +291 -291
- package/src/subject/util.ts +84 -84
- package/src/typeDefs.ts +5 -5
- package/src/unwrapApolloResult.ts +15 -13
- package/src/utils.ts +25 -25
- package/tsconfig-browser.json +82 -82
- package/tsconfig.json +80 -80
- package/yarn-error.log +0 -22814
package/src/language/Language.ts
CHANGED
|
@@ -1,266 +1,266 @@
|
|
|
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 { InputType, Field, ObjectType } from "type-graphql";
|
|
7
|
-
import { PerspectiveState } from '../perspectives/PerspectiveHandle';
|
|
8
|
-
|
|
9
|
-
/** Interface of AD4M Languages
|
|
10
|
-
*
|
|
11
|
-
* Any JavaScript module that implements a create() function that returns an object that implements this interface
|
|
12
|
-
* is a valid AD4M language.
|
|
13
|
-
* So the AD4M-internal representation of a language is an object that implements this interface.
|
|
14
|
-
*
|
|
15
|
-
* Since there are a few different kinds of languages, this interface is split into optional sub-interfaces.
|
|
16
|
-
* The only required property is the name of the language.
|
|
17
|
-
*
|
|
18
|
-
* The most usual kind of language is the "Expression Language", which is a language that can be used to create
|
|
19
|
-
* and share Expressions.
|
|
20
|
-
* For that, implement the expressionsAdapter and expressionUI interface.
|
|
21
|
-
*
|
|
22
|
-
* The second most common kind of language is the "Link Language", which is a language that builds the core
|
|
23
|
-
* of AD4M Neighbourhoods.
|
|
24
|
-
* For that, implement the linksAdapter interface.
|
|
25
|
-
*/
|
|
26
|
-
export interface Language {
|
|
27
|
-
readonly name: string;
|
|
28
|
-
|
|
29
|
-
/** Flagging expressions as immutable to enable
|
|
30
|
-
* expression caching in the ad4m-executor
|
|
31
|
-
*/
|
|
32
|
-
isImmutableExpression?(expression: Address): boolean;
|
|
33
|
-
|
|
34
|
-
// Adapter implementations:
|
|
35
|
-
|
|
36
|
-
/** ExpressionAdapter implements means of getting an Expression
|
|
37
|
-
* by address and putting an expression
|
|
38
|
-
*/
|
|
39
|
-
readonly expressionAdapter?: ExpressionAdapter;
|
|
40
|
-
|
|
41
|
-
/** Interface for getting UI/web components for rendering Expressions of this Language */
|
|
42
|
-
readonly expressionUI?: ExpressionUI;
|
|
43
|
-
|
|
44
|
-
/** Interface of LinkLanguages for the core implementation of Neighbourhoods */
|
|
45
|
-
readonly linksAdapter?: LinkSyncAdapter;
|
|
46
|
-
|
|
47
|
-
/** Additional Interface of LinkLanguages that support telepresence features,
|
|
48
|
-
* that is:
|
|
49
|
-
* - seeing who is online and getting a status
|
|
50
|
-
* - sending/receiveing p2p signals to other online agents without affecting
|
|
51
|
-
* the shared Perspective of the Neighbourhood
|
|
52
|
-
* (see TelepresenceAdapter for more details)
|
|
53
|
-
*/
|
|
54
|
-
readonly telepresenceAdapter?: TelepresenceAdapter;
|
|
55
|
-
|
|
56
|
-
/** Implementation of a Language that defines and stores Languages*/
|
|
57
|
-
readonly languageAdapter?: LanguageAdapter;
|
|
58
|
-
|
|
59
|
-
/** Optional adapter for getting Expressions by author */
|
|
60
|
-
readonly getByAuthorAdapter?: GetByAuthorAdapter;
|
|
61
|
-
/** Optional adapter for getting all Expressions */
|
|
62
|
-
readonly getAllAdapter?: GetAllAdapter;
|
|
63
|
-
|
|
64
|
-
/** Optional adapter for direct messaging between agents */
|
|
65
|
-
readonly directMessageAdapter?: DirectMessageAdapter;
|
|
66
|
-
|
|
67
|
-
/** Interface for providing UI components for the settings of this Language */
|
|
68
|
-
readonly settingsUI?: SettingsUI;
|
|
69
|
-
|
|
70
|
-
/** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
|
|
71
|
-
readonly teardown?: () => void;
|
|
72
|
-
|
|
73
|
-
/** All available interactions this agent could execute on given expression */
|
|
74
|
-
interactions(expression: Address): Interaction[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** UI factories returning web components */
|
|
78
|
-
export interface ExpressionUI {
|
|
79
|
-
/** Returns JS code of a web component that renders the given expression */
|
|
80
|
-
icon(): string;
|
|
81
|
-
/** Returns JS code of a web component used to create new expressions */
|
|
82
|
-
constructorIcon(): string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface SettingsUI {
|
|
86
|
-
settingsIcon(): string;
|
|
87
|
-
}
|
|
88
|
-
/** Interface for the most common Expression Languages */
|
|
89
|
-
export interface ExpressionAdapter {
|
|
90
|
-
/** Returns an Expression by address, or null if there is no Expression
|
|
91
|
-
* with that given address
|
|
92
|
-
*/
|
|
93
|
-
get(address: Address): Promise<Expression | null>;
|
|
94
|
-
|
|
95
|
-
/** Strategy for putting an expression with needs to be different
|
|
96
|
-
* for those two cases:
|
|
97
|
-
* 1. PublicSharing means that this language supports the creation
|
|
98
|
-
* and sharing of Expressions, which is the common use-case
|
|
99
|
-
* 2. ReadOnlyLanguage means that the Language implements a pre-defined
|
|
100
|
-
* set of expressions (which can be infinite or finite).
|
|
101
|
-
* For example the url-iframe Language which directly maps URLs to
|
|
102
|
-
* addresses - meaning every well formed URL is an address in this
|
|
103
|
-
* Language. Or a potential Language implementing the verbs/predicates
|
|
104
|
-
* of a spec like FOAF.
|
|
105
|
-
*/
|
|
106
|
-
putAdapter: PublicSharing | ReadOnlyLanguage;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Implement this interface if your Language supports creation of sharing
|
|
110
|
-
* of Expressions.
|
|
111
|
-
* See ExpressionAdapter
|
|
112
|
-
*/
|
|
113
|
-
export interface PublicSharing {
|
|
114
|
-
/** Create an Expression and shares it.
|
|
115
|
-
* Return the Expression's address.
|
|
116
|
-
* @param content is the object created by the constructorIcon component
|
|
117
|
-
*/
|
|
118
|
-
createPublic(content: object): Promise<Address>;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** Implement this interface if your Language is defined over a static
|
|
122
|
-
* set of pre-defined Expressions.
|
|
123
|
-
*/
|
|
124
|
-
export interface ReadOnlyLanguage {
|
|
125
|
-
/** This just calculates the address of an object
|
|
126
|
-
* @param content is the object created by the constructorIcon component
|
|
127
|
-
*/
|
|
128
|
-
addressOf(content: object): Promise<Address>;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface LanguageAdapter {
|
|
132
|
-
getLanguageSource(address: Address): Promise<string>;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Implement this if your Language supports retrieval of all Expressions
|
|
136
|
-
// authored by a given agent
|
|
137
|
-
export interface GetByAuthorAdapter {
|
|
138
|
-
/// Get expressions authored by a given Agent/Identity
|
|
139
|
-
getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Implement this if your Language supports retrieval of all Expressions
|
|
143
|
-
// stored in the space of that Language.
|
|
144
|
-
// Might not be trivial (without trade-off) for Holochain or DHTs
|
|
145
|
-
// in general - hence not a required interface.
|
|
146
|
-
export interface GetAllAdapter {
|
|
147
|
-
/// Get expressions authored by a given Agent/Identity
|
|
148
|
-
getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export type PerspectiveDiffObserver = (diff: PerspectiveDiff)=>void;
|
|
152
|
-
export type SyncStateChangeObserver = (state: PerspectiveState)=>void;
|
|
153
|
-
|
|
154
|
-
/** Interface for "Link Languages" that facilitate the synchronization
|
|
155
|
-
* between agents' local Perspectives inside a Neighbourhood.
|
|
156
|
-
* The assumption is that every version of the shared Perspective
|
|
157
|
-
* is labeled with a unique revision string.
|
|
158
|
-
* Changes are committed and retrieved through diffs.
|
|
159
|
-
* Think of a LinkSyncAdapter as a git branch to which agents commit
|
|
160
|
-
* their changes to and pull diffs from their current revision
|
|
161
|
-
* to the latest one.
|
|
162
|
-
*/
|
|
163
|
-
export interface LinkSyncAdapter {
|
|
164
|
-
writable(): boolean;
|
|
165
|
-
public(): boolean;
|
|
166
|
-
others(): Promise<DID[]>;
|
|
167
|
-
|
|
168
|
-
/** What revision are we on now -> what changes are included in output of render() */
|
|
169
|
-
currentRevision(): Promise<string>;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Check for and get new changes,
|
|
173
|
-
* notify others of local changes.
|
|
174
|
-
* This function will be called every
|
|
175
|
-
* few seconds by the ad4m-executor.
|
|
176
|
-
* */
|
|
177
|
-
sync(): Promise<PerspectiveDiff>;
|
|
178
|
-
|
|
179
|
-
/** Returns the full, rendered Perspective at currentRevision */
|
|
180
|
-
render(): Promise<Perspective>;
|
|
181
|
-
|
|
182
|
-
/** Publish changes */
|
|
183
|
-
commit(diff: PerspectiveDiff): Promise<string>;
|
|
184
|
-
|
|
185
|
-
/** Get push notification when a diff got published */
|
|
186
|
-
addCallback(callback: PerspectiveDiffObserver);
|
|
187
|
-
|
|
188
|
-
/** Add a sync state callback method */
|
|
189
|
-
addSyncStateChangeCallback(callback: SyncStateChangeObserver);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export type MessageCallback = (message: PerspectiveExpression) => void;
|
|
193
|
-
export type StatusCallback = (caller: DID) => Perspective;
|
|
194
|
-
export interface DirectMessageAdapter {
|
|
195
|
-
recipient(): DID;
|
|
196
|
-
|
|
197
|
-
status(): Promise<PerspectiveExpression | void>;
|
|
198
|
-
sendP2P(message: Perspective): Promise<PerspectiveExpression|void>;
|
|
199
|
-
sendInbox(message: Perspective): Promise<PerspectiveExpression|void>;
|
|
200
|
-
|
|
201
|
-
setStatus(status: PerspectiveExpression);
|
|
202
|
-
inbox(filter?: string): Promise<PerspectiveExpression[]>
|
|
203
|
-
addMessageCallback(callback: MessageCallback);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
@ObjectType()
|
|
207
|
-
export class InteractionParameter {
|
|
208
|
-
@Field()
|
|
209
|
-
name: string
|
|
210
|
-
|
|
211
|
-
@Field()
|
|
212
|
-
type: string
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
@ObjectType()
|
|
216
|
-
export class InteractionMeta {
|
|
217
|
-
@Field()
|
|
218
|
-
label: string;
|
|
219
|
-
|
|
220
|
-
@Field()
|
|
221
|
-
name: string;
|
|
222
|
-
|
|
223
|
-
@Field(type => [InteractionParameter])
|
|
224
|
-
parameters: InteractionParameter[]
|
|
225
|
-
}
|
|
226
|
-
export interface Interaction {
|
|
227
|
-
readonly label: string;
|
|
228
|
-
readonly name: string;
|
|
229
|
-
readonly parameters: InteractionParameter[];
|
|
230
|
-
execute(parameters: object): Promise<string|null>;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
@InputType()
|
|
234
|
-
export class InteractionCall {
|
|
235
|
-
@Field()
|
|
236
|
-
name: string;
|
|
237
|
-
@Field()
|
|
238
|
-
parametersStringified: string;
|
|
239
|
-
|
|
240
|
-
public get parameters(): object {
|
|
241
|
-
return JSON.parse(this.parametersStringified)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
constructor(name: string, parameters: object) {
|
|
245
|
-
this.name = name
|
|
246
|
-
this.parametersStringified = JSON.stringify(parameters)
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
@ObjectType()
|
|
251
|
-
export class OnlineAgent {
|
|
252
|
-
@Field()
|
|
253
|
-
did: DID
|
|
254
|
-
@Field()
|
|
255
|
-
status: PerspectiveExpression
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export type TelepresenceSignalCallback = (payload: PerspectiveExpression) => void;
|
|
259
|
-
export interface TelepresenceAdapter {
|
|
260
|
-
setOnlineStatus(status: PerspectiveExpression): Promise<void>;
|
|
261
|
-
getOnlineAgents(): Promise<OnlineAgent[]>;
|
|
262
|
-
|
|
263
|
-
sendSignal(remoteAgentDid: string, payload: PerspectiveExpression): Promise<object>;
|
|
264
|
-
sendBroadcast(payload: PerspectiveExpression): Promise<object>;
|
|
265
|
-
registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
|
|
266
|
-
}
|
|
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 { InputType, Field, ObjectType } from "type-graphql";
|
|
7
|
+
import { PerspectiveState } from '../perspectives/PerspectiveHandle';
|
|
8
|
+
|
|
9
|
+
/** Interface of AD4M Languages
|
|
10
|
+
*
|
|
11
|
+
* Any JavaScript module that implements a create() function that returns an object that implements this interface
|
|
12
|
+
* is a valid AD4M language.
|
|
13
|
+
* So the AD4M-internal representation of a language is an object that implements this interface.
|
|
14
|
+
*
|
|
15
|
+
* Since there are a few different kinds of languages, this interface is split into optional sub-interfaces.
|
|
16
|
+
* The only required property is the name of the language.
|
|
17
|
+
*
|
|
18
|
+
* The most usual kind of language is the "Expression Language", which is a language that can be used to create
|
|
19
|
+
* and share Expressions.
|
|
20
|
+
* For that, implement the expressionsAdapter and expressionUI interface.
|
|
21
|
+
*
|
|
22
|
+
* The second most common kind of language is the "Link Language", which is a language that builds the core
|
|
23
|
+
* of AD4M Neighbourhoods.
|
|
24
|
+
* For that, implement the linksAdapter interface.
|
|
25
|
+
*/
|
|
26
|
+
export interface Language {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
|
|
29
|
+
/** Flagging expressions as immutable to enable
|
|
30
|
+
* expression caching in the ad4m-executor
|
|
31
|
+
*/
|
|
32
|
+
isImmutableExpression?(expression: Address): boolean;
|
|
33
|
+
|
|
34
|
+
// Adapter implementations:
|
|
35
|
+
|
|
36
|
+
/** ExpressionAdapter implements means of getting an Expression
|
|
37
|
+
* by address and putting an expression
|
|
38
|
+
*/
|
|
39
|
+
readonly expressionAdapter?: ExpressionAdapter;
|
|
40
|
+
|
|
41
|
+
/** Interface for getting UI/web components for rendering Expressions of this Language */
|
|
42
|
+
readonly expressionUI?: ExpressionUI;
|
|
43
|
+
|
|
44
|
+
/** Interface of LinkLanguages for the core implementation of Neighbourhoods */
|
|
45
|
+
readonly linksAdapter?: LinkSyncAdapter;
|
|
46
|
+
|
|
47
|
+
/** Additional Interface of LinkLanguages that support telepresence features,
|
|
48
|
+
* that is:
|
|
49
|
+
* - seeing who is online and getting a status
|
|
50
|
+
* - sending/receiveing p2p signals to other online agents without affecting
|
|
51
|
+
* the shared Perspective of the Neighbourhood
|
|
52
|
+
* (see TelepresenceAdapter for more details)
|
|
53
|
+
*/
|
|
54
|
+
readonly telepresenceAdapter?: TelepresenceAdapter;
|
|
55
|
+
|
|
56
|
+
/** Implementation of a Language that defines and stores Languages*/
|
|
57
|
+
readonly languageAdapter?: LanguageAdapter;
|
|
58
|
+
|
|
59
|
+
/** Optional adapter for getting Expressions by author */
|
|
60
|
+
readonly getByAuthorAdapter?: GetByAuthorAdapter;
|
|
61
|
+
/** Optional adapter for getting all Expressions */
|
|
62
|
+
readonly getAllAdapter?: GetAllAdapter;
|
|
63
|
+
|
|
64
|
+
/** Optional adapter for direct messaging between agents */
|
|
65
|
+
readonly directMessageAdapter?: DirectMessageAdapter;
|
|
66
|
+
|
|
67
|
+
/** Interface for providing UI components for the settings of this Language */
|
|
68
|
+
readonly settingsUI?: SettingsUI;
|
|
69
|
+
|
|
70
|
+
/** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
|
|
71
|
+
readonly teardown?: () => void;
|
|
72
|
+
|
|
73
|
+
/** All available interactions this agent could execute on given expression */
|
|
74
|
+
interactions(expression: Address): Interaction[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** UI factories returning web components */
|
|
78
|
+
export interface ExpressionUI {
|
|
79
|
+
/** Returns JS code of a web component that renders the given expression */
|
|
80
|
+
icon(): string;
|
|
81
|
+
/** Returns JS code of a web component used to create new expressions */
|
|
82
|
+
constructorIcon(): string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface SettingsUI {
|
|
86
|
+
settingsIcon(): string;
|
|
87
|
+
}
|
|
88
|
+
/** Interface for the most common Expression Languages */
|
|
89
|
+
export interface ExpressionAdapter {
|
|
90
|
+
/** Returns an Expression by address, or null if there is no Expression
|
|
91
|
+
* with that given address
|
|
92
|
+
*/
|
|
93
|
+
get(address: Address): Promise<Expression | null>;
|
|
94
|
+
|
|
95
|
+
/** Strategy for putting an expression with needs to be different
|
|
96
|
+
* for those two cases:
|
|
97
|
+
* 1. PublicSharing means that this language supports the creation
|
|
98
|
+
* and sharing of Expressions, which is the common use-case
|
|
99
|
+
* 2. ReadOnlyLanguage means that the Language implements a pre-defined
|
|
100
|
+
* set of expressions (which can be infinite or finite).
|
|
101
|
+
* For example the url-iframe Language which directly maps URLs to
|
|
102
|
+
* addresses - meaning every well formed URL is an address in this
|
|
103
|
+
* Language. Or a potential Language implementing the verbs/predicates
|
|
104
|
+
* of a spec like FOAF.
|
|
105
|
+
*/
|
|
106
|
+
putAdapter: PublicSharing | ReadOnlyLanguage;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Implement this interface if your Language supports creation of sharing
|
|
110
|
+
* of Expressions.
|
|
111
|
+
* See ExpressionAdapter
|
|
112
|
+
*/
|
|
113
|
+
export interface PublicSharing {
|
|
114
|
+
/** Create an Expression and shares it.
|
|
115
|
+
* Return the Expression's address.
|
|
116
|
+
* @param content is the object created by the constructorIcon component
|
|
117
|
+
*/
|
|
118
|
+
createPublic(content: object): Promise<Address>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Implement this interface if your Language is defined over a static
|
|
122
|
+
* set of pre-defined Expressions.
|
|
123
|
+
*/
|
|
124
|
+
export interface ReadOnlyLanguage {
|
|
125
|
+
/** This just calculates the address of an object
|
|
126
|
+
* @param content is the object created by the constructorIcon component
|
|
127
|
+
*/
|
|
128
|
+
addressOf(content: object): Promise<Address>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface LanguageAdapter {
|
|
132
|
+
getLanguageSource(address: Address): Promise<string>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Implement this if your Language supports retrieval of all Expressions
|
|
136
|
+
// authored by a given agent
|
|
137
|
+
export interface GetByAuthorAdapter {
|
|
138
|
+
/// Get expressions authored by a given Agent/Identity
|
|
139
|
+
getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Implement this if your Language supports retrieval of all Expressions
|
|
143
|
+
// stored in the space of that Language.
|
|
144
|
+
// Might not be trivial (without trade-off) for Holochain or DHTs
|
|
145
|
+
// in general - hence not a required interface.
|
|
146
|
+
export interface GetAllAdapter {
|
|
147
|
+
/// Get expressions authored by a given Agent/Identity
|
|
148
|
+
getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type PerspectiveDiffObserver = (diff: PerspectiveDiff)=>void;
|
|
152
|
+
export type SyncStateChangeObserver = (state: PerspectiveState)=>void;
|
|
153
|
+
|
|
154
|
+
/** Interface for "Link Languages" that facilitate the synchronization
|
|
155
|
+
* between agents' local Perspectives inside a Neighbourhood.
|
|
156
|
+
* The assumption is that every version of the shared Perspective
|
|
157
|
+
* is labeled with a unique revision string.
|
|
158
|
+
* Changes are committed and retrieved through diffs.
|
|
159
|
+
* Think of a LinkSyncAdapter as a git branch to which agents commit
|
|
160
|
+
* their changes to and pull diffs from their current revision
|
|
161
|
+
* to the latest one.
|
|
162
|
+
*/
|
|
163
|
+
export interface LinkSyncAdapter {
|
|
164
|
+
writable(): boolean;
|
|
165
|
+
public(): boolean;
|
|
166
|
+
others(): Promise<DID[]>;
|
|
167
|
+
|
|
168
|
+
/** What revision are we on now -> what changes are included in output of render() */
|
|
169
|
+
currentRevision(): Promise<string>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Check for and get new changes,
|
|
173
|
+
* notify others of local changes.
|
|
174
|
+
* This function will be called every
|
|
175
|
+
* few seconds by the ad4m-executor.
|
|
176
|
+
* */
|
|
177
|
+
sync(): Promise<PerspectiveDiff>;
|
|
178
|
+
|
|
179
|
+
/** Returns the full, rendered Perspective at currentRevision */
|
|
180
|
+
render(): Promise<Perspective>;
|
|
181
|
+
|
|
182
|
+
/** Publish changes */
|
|
183
|
+
commit(diff: PerspectiveDiff): Promise<string>;
|
|
184
|
+
|
|
185
|
+
/** Get push notification when a diff got published */
|
|
186
|
+
addCallback(callback: PerspectiveDiffObserver);
|
|
187
|
+
|
|
188
|
+
/** Add a sync state callback method */
|
|
189
|
+
addSyncStateChangeCallback(callback: SyncStateChangeObserver);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type MessageCallback = (message: PerspectiveExpression) => void;
|
|
193
|
+
export type StatusCallback = (caller: DID) => Perspective;
|
|
194
|
+
export interface DirectMessageAdapter {
|
|
195
|
+
recipient(): DID;
|
|
196
|
+
|
|
197
|
+
status(): Promise<PerspectiveExpression | void>;
|
|
198
|
+
sendP2P(message: Perspective): Promise<PerspectiveExpression|void>;
|
|
199
|
+
sendInbox(message: Perspective): Promise<PerspectiveExpression|void>;
|
|
200
|
+
|
|
201
|
+
setStatus(status: PerspectiveExpression);
|
|
202
|
+
inbox(filter?: string): Promise<PerspectiveExpression[]>
|
|
203
|
+
addMessageCallback(callback: MessageCallback);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
@ObjectType()
|
|
207
|
+
export class InteractionParameter {
|
|
208
|
+
@Field()
|
|
209
|
+
name: string
|
|
210
|
+
|
|
211
|
+
@Field()
|
|
212
|
+
type: string
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@ObjectType()
|
|
216
|
+
export class InteractionMeta {
|
|
217
|
+
@Field()
|
|
218
|
+
label: string;
|
|
219
|
+
|
|
220
|
+
@Field()
|
|
221
|
+
name: string;
|
|
222
|
+
|
|
223
|
+
@Field(type => [InteractionParameter])
|
|
224
|
+
parameters: InteractionParameter[]
|
|
225
|
+
}
|
|
226
|
+
export interface Interaction {
|
|
227
|
+
readonly label: string;
|
|
228
|
+
readonly name: string;
|
|
229
|
+
readonly parameters: InteractionParameter[];
|
|
230
|
+
execute(parameters: object): Promise<string|null>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@InputType()
|
|
234
|
+
export class InteractionCall {
|
|
235
|
+
@Field()
|
|
236
|
+
name: string;
|
|
237
|
+
@Field()
|
|
238
|
+
parametersStringified: string;
|
|
239
|
+
|
|
240
|
+
public get parameters(): object {
|
|
241
|
+
return JSON.parse(this.parametersStringified)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
constructor(name: string, parameters: object) {
|
|
245
|
+
this.name = name
|
|
246
|
+
this.parametersStringified = JSON.stringify(parameters)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@ObjectType()
|
|
251
|
+
export class OnlineAgent {
|
|
252
|
+
@Field()
|
|
253
|
+
did: DID
|
|
254
|
+
@Field()
|
|
255
|
+
status: PerspectiveExpression
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export type TelepresenceSignalCallback = (payload: PerspectiveExpression) => void;
|
|
259
|
+
export interface TelepresenceAdapter {
|
|
260
|
+
setOnlineStatus(status: PerspectiveExpression): Promise<void>;
|
|
261
|
+
getOnlineAgents(): Promise<OnlineAgent[]>;
|
|
262
|
+
|
|
263
|
+
sendSignal(remoteAgentDid: string, payload: PerspectiveExpression): Promise<object>;
|
|
264
|
+
sendBroadcast(payload: PerspectiveExpression): Promise<object>;
|
|
265
|
+
registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
|
|
266
|
+
}
|