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