@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 @@
1
+ import 'reflect-metadata'
@@ -0,0 +1,11 @@
1
+ import { Field, ObjectType } from "type-graphql";
2
+
3
+ @ObjectType()
4
+ export class Icon {
5
+ @Field()
6
+ code: string
7
+
8
+ constructor(code: string) {
9
+ this.code = code
10
+ }
11
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,160 @@
1
+ import { ApolloClient, gql } from "@apollo/client/core"
2
+ import unwrapApolloResult from "../unwrapApolloResult"
3
+ import { LanguageHandle } from "./LanguageHandle"
4
+ import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta"
5
+ import { LanguageRef } from "./LanguageRef"
6
+
7
+ const LANGUAGE_COMPLETE = `
8
+ name
9
+ address
10
+ settings
11
+ icon { code }
12
+ constructorIcon { code }
13
+ settingsIcon { code }
14
+ `
15
+
16
+ const LANGUAGE_META = `
17
+ name
18
+ address
19
+ description
20
+ author
21
+ templated
22
+ templateSourceLanguageAddress
23
+ templateAppliedParams
24
+ possibleTemplateParams
25
+ sourceCodeLink
26
+ `
27
+
28
+ export class LanguageClient {
29
+ #apolloClient: ApolloClient<any>
30
+
31
+ constructor(apolloClient: ApolloClient<any>) {
32
+ this.#apolloClient = apolloClient
33
+ }
34
+
35
+ async byAddress(address: string): Promise<LanguageHandle> {
36
+ const { language } = unwrapApolloResult(await this.#apolloClient.query({
37
+ query: gql`query byAddress($address: String!) {
38
+ language(address: $address) {
39
+ ${LANGUAGE_COMPLETE}
40
+ }
41
+ }`,
42
+ variables: { address }
43
+ }))
44
+ return language
45
+ }
46
+
47
+ async byFilter(filter: string): Promise<LanguageHandle[]> {
48
+ const { languages } = unwrapApolloResult(await this.#apolloClient.query({
49
+ query: gql`query byFilter($filter: String!) {
50
+ languages(filter: $filter) {
51
+ ${LANGUAGE_COMPLETE}
52
+ }
53
+ }`,
54
+ variables: { filter }
55
+ }))
56
+ return languages
57
+ }
58
+
59
+ async all(): Promise<LanguageHandle[]> {
60
+ return this.byFilter('')
61
+ }
62
+
63
+ async writeSettings(
64
+ languageAddress: string,
65
+ settings: string
66
+ ): Promise<Boolean> {
67
+ const { languageWriteSettings } = unwrapApolloResult(await this.#apolloClient.mutate({
68
+ mutation: gql`mutation writeSettings($languageAddress: String!, $settings: String!) {
69
+ languageWriteSettings(languageAddress: $languageAddress, settings: $settings)
70
+ }`,
71
+ variables: { languageAddress, settings }
72
+ }))
73
+ return languageWriteSettings
74
+ }
75
+
76
+ async applyTemplateAndPublish(
77
+ sourceLanguageHash: string,
78
+ templateData: string
79
+ ): Promise<LanguageRef> {
80
+ const { languageApplyTemplateAndPublish } = unwrapApolloResult(await this.#apolloClient.mutate({
81
+ mutation: gql`mutation languageApplyTemplateAndPublish(
82
+ $sourceLanguageHash: String!,
83
+ $templateData: String!,
84
+ ) {
85
+ languageApplyTemplateAndPublish(sourceLanguageHash: $sourceLanguageHash, templateData: $templateData) {
86
+ name, address
87
+ }
88
+ }`,
89
+ variables: { sourceLanguageHash, templateData }
90
+ }))
91
+
92
+ return languageApplyTemplateAndPublish
93
+ }
94
+
95
+ async publish(
96
+ languagePath: string,
97
+ languageMeta: LanguageMetaInput
98
+ ): Promise<LanguageMeta> {
99
+ const { languagePublish } = unwrapApolloResult(await this.#apolloClient.mutate({
100
+ mutation: gql`mutation languagePublish(
101
+ $languagePath: String!,
102
+ $languageMeta: LanguageMetaInput!,
103
+ ) {
104
+ languagePublish(languagePath: $languagePath, languageMeta: $languageMeta) {
105
+ ${LANGUAGE_META}
106
+ }
107
+ }`,
108
+ variables: { languagePath, languageMeta }
109
+ }))
110
+
111
+ return languagePublish
112
+ }
113
+
114
+ async meta(
115
+ address: string,
116
+ ): Promise<LanguageMeta> {
117
+ const { languageMeta } = unwrapApolloResult(await this.#apolloClient.query({
118
+ query: gql`query languageMeta(
119
+ $address: String!,
120
+ ) {
121
+ languageMeta(address: $address) {
122
+ ${LANGUAGE_META}
123
+ }
124
+ }`,
125
+ variables: { address }
126
+ }))
127
+
128
+ return languageMeta
129
+ }
130
+
131
+ async source(
132
+ address: string,
133
+ ): Promise<string> {
134
+ const { languageSource } = unwrapApolloResult(await this.#apolloClient.query({
135
+ query: gql`query languageSource(
136
+ $address: String!,
137
+ ) {
138
+ languageSource(address: $address)
139
+ }`,
140
+ variables: { address }
141
+ }))
142
+
143
+ return languageSource
144
+ }
145
+
146
+ async remove(
147
+ address: string
148
+ ): Promise<Boolean> {
149
+ const { languageRemove } = unwrapApolloResult(await this.#apolloClient.mutate({
150
+ mutation: gql`mutation languageRemove(
151
+ $address: String!,
152
+ ) {
153
+ languageRemove(address: $address)
154
+ }`,
155
+ variables: { address }
156
+ }))
157
+
158
+ return languageRemove
159
+ }
160
+ }
@@ -0,0 +1,37 @@
1
+ import type { AppSignalCb } from '@holochain/client'
2
+ import { Expression } from "../expression/Expression";
3
+
4
+ export interface AgentService {
5
+ readonly did: string
6
+ createSignedExpression(data: any): Expression
7
+ }
8
+
9
+ export interface SignaturesService {
10
+ verify(expr: Expression): boolean
11
+ }
12
+
13
+ export interface LanguageContext {
14
+ agent: AgentService;
15
+ signatures: SignaturesService;
16
+ storageDirectory: string;
17
+ customSettings: object;
18
+ Holochain: HolochainLanguageDelegate | undefined;
19
+ ad4mSignal: Ad4mSignalCB;
20
+ }
21
+
22
+ export class Dna {
23
+ file: Buffer
24
+ nick: string
25
+ zomeCalls: [string, string][]
26
+ }
27
+
28
+ export interface HolochainLanguageDelegate {
29
+ /** Installs/registers a given DNA in the ad4m-executor */
30
+ registerDNAs(dnas: Dna[], holochainSignalCallback?: AppSignalCb): Promise<void>;
31
+ /** Makes a single call to a given holochain DNA. Underlying implementation puts these calls into a sync fifo queue */
32
+ call(dnaNick: string, zomeName: string, fnName: string, params: object|string): Promise<any>;
33
+ /** 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 */
34
+ callAsync(calls: {dnaNick: string, zomeName: string, fnName: string, params: object|string}[], timeoutMs?: number): Promise<any[]>;
35
+ }
36
+
37
+ export type Ad4mSignalCB = (signal: any) => void
@@ -0,0 +1,23 @@
1
+ import { Field, ObjectType } from "type-graphql";
2
+ import { Icon } from "./Icon";
3
+
4
+ @ObjectType()
5
+ export class LanguageHandle {
6
+ @Field()
7
+ name: string;
8
+
9
+ @Field()
10
+ address: string;
11
+
12
+ @Field({nullable: true})
13
+ settings?: string;
14
+
15
+ @Field({nullable: true})
16
+ icon?: Icon;
17
+
18
+ @Field({nullable: true})
19
+ constructorIcon?: Icon;
20
+
21
+ @Field({nullable: true})
22
+ settingsIcon?: Icon;
23
+ }
@@ -0,0 +1,70 @@
1
+ import { Field, InputType, ObjectType } from "type-graphql";
2
+ import { ExpressionGeneric } from "../expression/Expression";
3
+
4
+ @ObjectType()
5
+ export class LanguageMeta {
6
+ @Field()
7
+ name: string;
8
+
9
+ @Field()
10
+ address: string;
11
+
12
+ @Field({nullable: true})
13
+ description: string;
14
+
15
+ @Field()
16
+ author: string;
17
+
18
+ @Field({nullable: true})
19
+ templated: boolean
20
+
21
+ @Field({nullable: true})
22
+ templateSourceLanguageAddress?: string;
23
+
24
+ @Field({nullable: true})
25
+ templateAppliedParams?: string;
26
+
27
+ @Field(type => [String], {nullable: true})
28
+ possibleTemplateParams?: string[];
29
+
30
+ @Field({nullable: true})
31
+ sourceCodeLink?: string;
32
+ }
33
+
34
+ @InputType()
35
+ export class LanguageMetaInput {
36
+ @Field()
37
+ name: string;
38
+
39
+ @Field()
40
+ description: string;
41
+
42
+ @Field(type => [String], {nullable: true})
43
+ possibleTemplateParams?: string[];
44
+
45
+ @Field({nullable: true})
46
+ sourceCodeLink?: string;
47
+
48
+ constructor(name?: string, description?: string) {
49
+ this.name = name
50
+ this.description = description
51
+ if(!this.description) this.description = ""
52
+ }
53
+ }
54
+
55
+ export class LanguageMetaInternal {
56
+ name: string;
57
+ address: string;
58
+ description: string;
59
+ templateSourceLanguageAddress?: string;
60
+ templateAppliedParams?: string;
61
+ possibleTemplateParams?: string[];
62
+ sourceCodeLink?: string;
63
+ }
64
+
65
+ export class LanguageExpression extends ExpressionGeneric(LanguageMetaInternal) {};
66
+
67
+ export class LanguageLanguageInput {
68
+ bundle: string;
69
+ meta: LanguageMetaInternal;
70
+ }
@@ -0,0 +1,18 @@
1
+ import type { Address } from '../Address'
2
+ import { Field, ObjectType } from "type-graphql";
3
+
4
+
5
+ // Unique Language ID with option type
6
+ @ObjectType()
7
+ export class LanguageRef {
8
+ @Field()
9
+ address: Address;
10
+
11
+ @Field()
12
+ name: string;
13
+
14
+ constructor(address?: Address, name?: string) {
15
+ this.address = address
16
+ this.name = name
17
+ }
18
+ }
@@ -0,0 +1,98 @@
1
+
2
+ import { Arg, Mutation, Query, Resolver } from "type-graphql";
3
+ import { Icon } from "./Icon";
4
+ import { LanguageHandle } from "./LanguageHandle";
5
+ import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta"
6
+ import { LanguageRef } from "./LanguageRef";
7
+
8
+ /**
9
+ * Resolver classes are used here to define the GraphQL schema
10
+ * (through the type-graphql annotations)
11
+ * and are spawned in the client tests in Ad4mClient.test.ts.
12
+ * For the latter, they return test fixtures.
13
+ */
14
+ @Resolver()
15
+ export default class LanguageResolver {
16
+ @Query(returns => LanguageHandle, {nullable: true})
17
+ language(@Arg('address') address: string): LanguageHandle {
18
+ let language = new LanguageHandle()
19
+ language.address = address
20
+ language.name = 'test-language'
21
+ language.settings = JSON.stringify({testSetting: 'test'})
22
+ language.icon = new Icon('test-code')
23
+ language.settingsIcon = new Icon('test-code')
24
+ language.constructorIcon = new Icon('test-code')
25
+ return language
26
+ }
27
+
28
+
29
+ @Query(returns => [LanguageHandle])
30
+ languages(@Arg('filter', {nullable: true}) filter: string): LanguageHandle[] {
31
+ let language = new LanguageHandle()
32
+ language.address = 'test-address'
33
+ language.name = 'test-links-language'
34
+
35
+ if(!filter || filter === 'linksAdapter')
36
+ return [language]
37
+ else
38
+ return []
39
+ }
40
+
41
+ @Mutation(returns => Boolean)
42
+ languageWriteSettings(
43
+ @Arg('languageAddress') languageAddress: string,
44
+ @Arg('settings') settings: string
45
+ ): Boolean {
46
+ return true
47
+ }
48
+
49
+ @Mutation()
50
+ languageApplyTemplateAndPublish(
51
+ @Arg('sourceLanguageHash') sourceLanguageHash: string,
52
+ @Arg('templateData') templateData: string,
53
+ ): LanguageRef {
54
+ return new LanguageRef('test-address', `${sourceLanguageHash}-clone`)
55
+ }
56
+
57
+ @Mutation()
58
+ languagePublish(
59
+ @Arg('languagePath') languagePath: string,
60
+ @Arg('languageMeta') languageMeta: LanguageMetaInput,
61
+ ): LanguageMeta {
62
+ let meta = new LanguageMeta()
63
+ meta.name = languageMeta.name
64
+ meta.address = "Qm12345"
65
+ meta.description = languageMeta.description
66
+ meta.author = "did:test:me"
67
+ meta.templated = true
68
+ meta.templateSourceLanguageAddress = "Qm12345"
69
+ meta.templateAppliedParams = JSON.stringify({uuid: 'asdfsdaf', name: 'test template'})
70
+ meta.possibleTemplateParams = languageMeta.possibleTemplateParams
71
+ meta.sourceCodeLink = languageMeta.sourceCodeLink
72
+ return meta
73
+ }
74
+
75
+ @Query()
76
+ languageMeta(@Arg('address') address: string): LanguageMeta {
77
+ let meta = new LanguageMeta()
78
+ meta.name = "test-language"
79
+ meta.address = address
80
+ meta.description = "Language meta for testing"
81
+ meta.author = "did:test:me"
82
+ meta.templated = true
83
+ meta.templateSourceLanguageAddress = "Qm12345"
84
+ meta.templateAppliedParams = JSON.stringify({uuid: 'asdfsdaf', name: 'test template'})
85
+ meta.possibleTemplateParams = ['uuid', 'name']
86
+ meta.sourceCodeLink = "https://github.com/perspect3vism/ad4m"
87
+ return meta
88
+ }
89
+
90
+ @Query()
91
+ languageSource(@Arg('address') address: string): string {
92
+ return "var test = 'language source code'"
93
+ }
94
+
95
+ @Mutation()
96
+ languageRemove(@Arg('address') address: string): Boolean { return true }
97
+ }
98
+