@coasys/ad4m 0.9.0 → 0.9.1-prerelease.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/lib/index.cjs +209 -124
- package/lib/index.js +209 -124
- package/lib/src/Exception.d.ts +2 -1
- package/lib/src/Exception.js +1 -0
- package/lib/src/PubSub.d.ts +2 -0
- package/lib/src/PubSub.js +2 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +3 -0
- package/lib/src/perspectives/PerspectiveClient.js +24 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +3 -1
- package/lib/src/perspectives/PerspectiveProxy.js +32 -68
- package/lib/src/perspectives/PerspectiveResolver.d.ts +3 -0
- package/lib/src/perspectives/PerspectiveResolver.js +37 -0
- package/lib/src/runtime/RuntimeClient.d.ts +12 -1
- package/lib/src/runtime/RuntimeClient.js +108 -2
- package/lib/src/runtime/RuntimeResolver.d.ts +34 -0
- package/lib/src/runtime/RuntimeResolver.js +214 -2
- package/lib/src/schema.gql +40 -0
- package/lib/src/subject/SubjectEntity.js +4 -55
- package/lib/src/typeDefs.js +40 -0
- package/package.json +7 -13
- package/src/Ad4mClient.test.ts +95 -32
- package/src/Exception.ts +1 -0
- package/src/PubSub.ts +2 -0
- package/src/perspectives/PerspectiveClient.ts +27 -0
- package/src/perspectives/PerspectiveProxy.ts +36 -67
- package/src/perspectives/PerspectiveResolver.ts +29 -1
- package/src/runtime/RuntimeClient.ts +120 -1
- package/src/runtime/RuntimeResolver.ts +167 -3
- package/src/subject/SubjectEntity.ts +4 -56
|
@@ -10,7 +10,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _PerspectiveProxy_handle, _PerspectiveProxy_client, _PerspectiveProxy_perspectiveLinkAddedCallbacks, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks;
|
|
13
|
-
import { Link } from "../links/Links";
|
|
14
13
|
import { LinkQuery } from "./LinkQuery";
|
|
15
14
|
import { Literal } from "../Literal";
|
|
16
15
|
import { Subject } from "../subject/Subject";
|
|
@@ -46,55 +45,7 @@ export class PerspectiveProxy {
|
|
|
46
45
|
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addPerspectiveSyncStateChangeListener(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f"));
|
|
47
46
|
}
|
|
48
47
|
async executeAction(actions, expression, parameters) {
|
|
49
|
-
|
|
50
|
-
if (input) {
|
|
51
|
-
if (input === 'this') {
|
|
52
|
-
return expression;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return input;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const replaceParameters = (input) => {
|
|
63
|
-
if (parameters) {
|
|
64
|
-
let output = input;
|
|
65
|
-
for (const parameter of parameters) {
|
|
66
|
-
output = output.replace(parameter.name, parameter.value);
|
|
67
|
-
}
|
|
68
|
-
return output;
|
|
69
|
-
}
|
|
70
|
-
else
|
|
71
|
-
return input;
|
|
72
|
-
};
|
|
73
|
-
for (let command of actions) {
|
|
74
|
-
let source = replaceThis(replaceParameters(command.source));
|
|
75
|
-
let predicate = replaceThis(replaceParameters(command.predicate));
|
|
76
|
-
let target = replaceThis(replaceParameters(command.target));
|
|
77
|
-
let local = command?.local ?? false;
|
|
78
|
-
switch (command.action) {
|
|
79
|
-
case 'addLink':
|
|
80
|
-
await this.add(new Link({ source, predicate, target }), local ? 'local' : 'shared');
|
|
81
|
-
break;
|
|
82
|
-
case 'removeLink':
|
|
83
|
-
const linkExpressions = await this.get(new LinkQuery({ source, predicate, target }));
|
|
84
|
-
for (const linkExpression of linkExpressions) {
|
|
85
|
-
await this.remove(linkExpression);
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
case 'setSingleTarget':
|
|
89
|
-
await this.setSingleTarget(new Link({ source, predicate, target }), local ? 'local' : 'shared');
|
|
90
|
-
break;
|
|
91
|
-
case 'collectionSetter':
|
|
92
|
-
const links = await this.get(new LinkQuery({ source, predicate }));
|
|
93
|
-
await this.removeLinks(links);
|
|
94
|
-
await this.addLinks(parameters.map(p => new Link({ source, predicate, target: p.value })), local ? 'local' : 'shared');
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
48
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").executeCommands(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify(actions), expression, JSON.stringify(parameters));
|
|
98
49
|
}
|
|
99
50
|
/** Returns all the links of this perspective that matches the LinkQuery */
|
|
100
51
|
async get(query) {
|
|
@@ -313,15 +264,24 @@ export class PerspectiveProxy {
|
|
|
313
264
|
* @param exprAddr The address of the expression to be turned into a subject instance
|
|
314
265
|
*/
|
|
315
266
|
async createSubject(subjectClass, exprAddr) {
|
|
316
|
-
let className
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
267
|
+
let className;
|
|
268
|
+
if (typeof subjectClass === "string") {
|
|
269
|
+
className = subjectClass;
|
|
270
|
+
await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").createSubject(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className }), exprAddr);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
let query = this.buildQueryFromTemplate(subjectClass);
|
|
274
|
+
await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").createSubject(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ query }), exprAddr);
|
|
320
275
|
}
|
|
321
|
-
let actions = result.map(x => eval(x.Actions));
|
|
322
|
-
await this.executeAction(actions[0], exprAddr, undefined);
|
|
323
276
|
return this.getSubjectProxy(exprAddr, subjectClass);
|
|
324
277
|
}
|
|
278
|
+
async getSubjectData(subjectClass, exprAddr) {
|
|
279
|
+
if (typeof subjectClass === "string") {
|
|
280
|
+
return JSON.parse(await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className: subjectClass }), exprAddr));
|
|
281
|
+
}
|
|
282
|
+
let query = this.buildQueryFromTemplate(subjectClass);
|
|
283
|
+
return JSON.parse(await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ query }), exprAddr));
|
|
284
|
+
}
|
|
325
285
|
/** Removes a subject instance by running its (SDNA defined) destructor,
|
|
326
286
|
* which means removing links around the given expression address
|
|
327
287
|
*
|
|
@@ -407,18 +367,7 @@ export class PerspectiveProxy {
|
|
|
407
367
|
}
|
|
408
368
|
return instances;
|
|
409
369
|
}
|
|
410
|
-
|
|
411
|
-
* This function looks at the properties of the template object and
|
|
412
|
-
* its setters and collections to create a Prolog query that finds
|
|
413
|
-
* all subject classes that would be converted to a proxy object
|
|
414
|
-
* with exactly the same properties and collections.
|
|
415
|
-
*
|
|
416
|
-
* Since there could be multiple subject classes that match the given
|
|
417
|
-
* criteria, this function returns a list of class names.
|
|
418
|
-
*
|
|
419
|
-
* @param obj The template object
|
|
420
|
-
*/
|
|
421
|
-
async subjectClassesByTemplate(obj) {
|
|
370
|
+
buildQueryFromTemplate(obj) {
|
|
422
371
|
// Collect all string properties of the object in a list
|
|
423
372
|
let properties = [];
|
|
424
373
|
// Collect all collections of the object in a list
|
|
@@ -477,6 +426,21 @@ export class PerspectiveProxy {
|
|
|
477
426
|
query += `, collection_setter(C, "${collectionSetterToName(setCollectionFunction)}", _)`;
|
|
478
427
|
}
|
|
479
428
|
query += ".";
|
|
429
|
+
return query;
|
|
430
|
+
}
|
|
431
|
+
/** Returns all subject classes that match the given template object.
|
|
432
|
+
* This function looks at the properties of the template object and
|
|
433
|
+
* its setters and collections to create a Prolog query that finds
|
|
434
|
+
* all subject classes that would be converted to a proxy object
|
|
435
|
+
* with exactly the same properties and collections.
|
|
436
|
+
*
|
|
437
|
+
* Since there could be multiple subject classes that match the given
|
|
438
|
+
* criteria, this function returns a list of class names.
|
|
439
|
+
*
|
|
440
|
+
* @param obj The template object
|
|
441
|
+
*/
|
|
442
|
+
async subjectClassesByTemplate(obj) {
|
|
443
|
+
const query = this.buildQueryFromTemplate(obj);
|
|
480
444
|
let result = await this.infer(query);
|
|
481
445
|
if (!result) {
|
|
482
446
|
return [];
|
|
@@ -28,6 +28,9 @@ export default class PerspectiveResolver {
|
|
|
28
28
|
perspectiveUpdateLink(uuid: string, oldlink: LinkExpressionInput, newlink: LinkInput, pubSub: any): LinkExpression;
|
|
29
29
|
perspectiveRemoveLink(uuid: string, link: LinkExpressionInput, pubSub: any): Boolean;
|
|
30
30
|
perspectiveAddSdna(uuid: string, name: string, sdnaCode: string, sdnaType: string, pubSub: any): Boolean;
|
|
31
|
+
perspectiveExecuteCommands(uuid: string, commands: string, expression: string, parameters: string): Boolean;
|
|
32
|
+
perspectiveCreateSubject(uuid: string, SubjectClass: string, expressionAddress: string): Boolean;
|
|
33
|
+
perspectiveGetSubjectData(uuid: string, SubjectClass: string, expressionAddress: string): String;
|
|
31
34
|
perspectiveAdded(): PerspectiveHandle;
|
|
32
35
|
perspectiveUpdated(): PerspectiveHandle;
|
|
33
36
|
perspectiveRemoved(): string;
|
|
@@ -154,6 +154,15 @@ let PerspectiveResolver = class PerspectiveResolver {
|
|
|
154
154
|
perspectiveAddSdna(uuid, name, sdnaCode, sdnaType, pubSub) {
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
|
+
perspectiveExecuteCommands(uuid, commands, expression, parameters) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
perspectiveCreateSubject(uuid, SubjectClass, expressionAddress) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
perspectiveGetSubjectData(uuid, SubjectClass, expressionAddress) {
|
|
164
|
+
return "";
|
|
165
|
+
}
|
|
157
166
|
perspectiveAdded() {
|
|
158
167
|
const perspective = new PerspectiveHandle('00001', 'New Perspective');
|
|
159
168
|
return perspective;
|
|
@@ -324,6 +333,34 @@ __decorate([
|
|
|
324
333
|
__metadata("design:paramtypes", [String, String, String, String, Object]),
|
|
325
334
|
__metadata("design:returntype", Boolean)
|
|
326
335
|
], PerspectiveResolver.prototype, "perspectiveAddSdna", null);
|
|
336
|
+
__decorate([
|
|
337
|
+
Mutation(returns => Boolean),
|
|
338
|
+
__param(0, Arg('uuid')),
|
|
339
|
+
__param(1, Arg('commands')),
|
|
340
|
+
__param(2, Arg('expression')),
|
|
341
|
+
__param(3, Arg('parameters', type => String, { nullable: true })),
|
|
342
|
+
__metadata("design:type", Function),
|
|
343
|
+
__metadata("design:paramtypes", [String, String, String, String]),
|
|
344
|
+
__metadata("design:returntype", Boolean)
|
|
345
|
+
], PerspectiveResolver.prototype, "perspectiveExecuteCommands", null);
|
|
346
|
+
__decorate([
|
|
347
|
+
Mutation(returns => Boolean),
|
|
348
|
+
__param(0, Arg('uuid')),
|
|
349
|
+
__param(1, Arg('subjectClass')),
|
|
350
|
+
__param(2, Arg('expressionAddress')),
|
|
351
|
+
__metadata("design:type", Function),
|
|
352
|
+
__metadata("design:paramtypes", [String, String, String]),
|
|
353
|
+
__metadata("design:returntype", Boolean)
|
|
354
|
+
], PerspectiveResolver.prototype, "perspectiveCreateSubject", null);
|
|
355
|
+
__decorate([
|
|
356
|
+
Mutation(returns => String),
|
|
357
|
+
__param(0, Arg('uuid')),
|
|
358
|
+
__param(1, Arg('subjectClass')),
|
|
359
|
+
__param(2, Arg('expressionAddress')),
|
|
360
|
+
__metadata("design:type", Function),
|
|
361
|
+
__metadata("design:paramtypes", [String, String, String]),
|
|
362
|
+
__metadata("design:returntype", String)
|
|
363
|
+
], PerspectiveResolver.prototype, "perspectiveGetSubjectData", null);
|
|
327
364
|
__decorate([
|
|
328
365
|
Subscription({ topics: PERSPECTIVE_ADDED_TOPIC, nullable: true }),
|
|
329
366
|
__metadata("design:type", Function),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ApolloClient } from "@apollo/client/core";
|
|
2
2
|
import { Perspective, PerspectiveExpression } from "../perspectives/Perspective";
|
|
3
|
-
import { RuntimeInfo, ExceptionInfo, SentMessage } from "./RuntimeResolver";
|
|
3
|
+
import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification } from "./RuntimeResolver";
|
|
4
4
|
export type MessageCallback = (message: PerspectiveExpression) => null;
|
|
5
5
|
export type ExceptionCallback = (info: ExceptionInfo) => null;
|
|
6
|
+
export type NotificationTriggeredCallback = (notification: TriggeredNotification) => null;
|
|
7
|
+
export type NotificationRequestedCallback = (notification: Notification) => null;
|
|
6
8
|
export declare class RuntimeClient {
|
|
7
9
|
#private;
|
|
8
10
|
constructor(client: ApolloClient<any>, subscribe?: boolean);
|
|
@@ -26,6 +28,15 @@ export declare class RuntimeClient {
|
|
|
26
28
|
friendSendMessage(did: string, message: Perspective): Promise<boolean>;
|
|
27
29
|
messageInbox(filter?: string): Promise<PerspectiveExpression[]>;
|
|
28
30
|
messageOutbox(filter?: string): Promise<SentMessage[]>;
|
|
31
|
+
requestInstallNotification(notification: NotificationInput): Promise<any>;
|
|
32
|
+
grantNotification(id: string): Promise<boolean>;
|
|
33
|
+
notifications(): Promise<Notification[]>;
|
|
34
|
+
updateNotification(id: string, notification: NotificationInput): Promise<boolean>;
|
|
35
|
+
removeNotification(id: string): Promise<boolean>;
|
|
36
|
+
addNotificationTriggeredCallback(cb: NotificationTriggeredCallback): void;
|
|
37
|
+
addNotificationRequestedCallback(cb: NotificationRequestedCallback): void;
|
|
38
|
+
subscribeNotificationTriggered(): void;
|
|
39
|
+
subscribeNotificationRequested(): void;
|
|
29
40
|
addMessageCallback(cb: MessageCallback): void;
|
|
30
41
|
subscribeMessageReceived(): void;
|
|
31
42
|
addExceptionCallback(cb: ExceptionCallback): void;
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _RuntimeClient_apolloClient, _RuntimeClient_messageReceivedCallbacks, _RuntimeClient_exceptionOccurredCallbacks;
|
|
12
|
+
var _RuntimeClient_apolloClient, _RuntimeClient_messageReceivedCallbacks, _RuntimeClient_exceptionOccurredCallbacks, _RuntimeClient_notificationTriggeredCallbacks, _RuntimeClient_notificationRequestedCallbacks;
|
|
13
13
|
import { gql } from "@apollo/client/core";
|
|
14
14
|
import unwrapApolloResult from "../unwrapApolloResult";
|
|
15
15
|
const PERSPECTIVE_EXPRESSION_FIELDS = `
|
|
@@ -25,17 +25,43 @@ data {
|
|
|
25
25
|
}
|
|
26
26
|
proof { valid, invalid, signature, key }
|
|
27
27
|
`;
|
|
28
|
+
const NOTIFICATION_DEFINITION_FIELDS = `
|
|
29
|
+
description
|
|
30
|
+
appName
|
|
31
|
+
appUrl
|
|
32
|
+
appIconPath
|
|
33
|
+
trigger
|
|
34
|
+
perspectiveIds
|
|
35
|
+
webhookUrl
|
|
36
|
+
webhookAuth
|
|
37
|
+
`;
|
|
38
|
+
const NOTIFICATION_FIELDS = `
|
|
39
|
+
id
|
|
40
|
+
granted
|
|
41
|
+
${NOTIFICATION_DEFINITION_FIELDS}
|
|
42
|
+
`;
|
|
43
|
+
const TRIGGERED_NOTIFICATION_FIELDS = `
|
|
44
|
+
notification { ${NOTIFICATION_FIELDS} }
|
|
45
|
+
perspectiveId
|
|
46
|
+
triggerMatch
|
|
47
|
+
`;
|
|
28
48
|
export class RuntimeClient {
|
|
29
49
|
constructor(client, subscribe = true) {
|
|
30
50
|
_RuntimeClient_apolloClient.set(this, void 0);
|
|
31
51
|
_RuntimeClient_messageReceivedCallbacks.set(this, void 0);
|
|
32
52
|
_RuntimeClient_exceptionOccurredCallbacks.set(this, void 0);
|
|
53
|
+
_RuntimeClient_notificationTriggeredCallbacks.set(this, void 0);
|
|
54
|
+
_RuntimeClient_notificationRequestedCallbacks.set(this, void 0);
|
|
33
55
|
__classPrivateFieldSet(this, _RuntimeClient_apolloClient, client, "f");
|
|
34
56
|
__classPrivateFieldSet(this, _RuntimeClient_messageReceivedCallbacks, [], "f");
|
|
35
57
|
__classPrivateFieldSet(this, _RuntimeClient_exceptionOccurredCallbacks, [], "f");
|
|
58
|
+
__classPrivateFieldSet(this, _RuntimeClient_notificationTriggeredCallbacks, [], "f");
|
|
59
|
+
__classPrivateFieldSet(this, _RuntimeClient_notificationRequestedCallbacks, [], "f");
|
|
36
60
|
if (subscribe) {
|
|
37
61
|
this.subscribeMessageReceived();
|
|
38
62
|
this.subscribeExceptionOccurred();
|
|
63
|
+
this.subscribeNotificationTriggered();
|
|
64
|
+
this.subscribeNotificationRequested();
|
|
39
65
|
}
|
|
40
66
|
}
|
|
41
67
|
async info() {
|
|
@@ -219,6 +245,86 @@ export class RuntimeClient {
|
|
|
219
245
|
}));
|
|
220
246
|
return runtimeMessageOutbox;
|
|
221
247
|
}
|
|
248
|
+
async requestInstallNotification(notification) {
|
|
249
|
+
const { runtimeRequestInstallNotification } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").mutate({
|
|
250
|
+
mutation: gql `mutation runtimeRequestInstallNotification($notification: NotificationInput!) {
|
|
251
|
+
runtimeRequestInstallNotification(notification: $notification)
|
|
252
|
+
}`,
|
|
253
|
+
variables: { notification }
|
|
254
|
+
}));
|
|
255
|
+
return runtimeRequestInstallNotification;
|
|
256
|
+
}
|
|
257
|
+
async grantNotification(id) {
|
|
258
|
+
const { runtimeGrantNotification } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").mutate({
|
|
259
|
+
mutation: gql `mutation runtimeGrantNotification($id: String!) {
|
|
260
|
+
runtimeGrantNotification(id: $id)
|
|
261
|
+
}`,
|
|
262
|
+
variables: { id }
|
|
263
|
+
}));
|
|
264
|
+
return runtimeGrantNotification;
|
|
265
|
+
}
|
|
266
|
+
async notifications() {
|
|
267
|
+
const { runtimeNotifications } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").query({
|
|
268
|
+
query: gql `query runtimeNotifications {
|
|
269
|
+
runtimeNotifications { ${NOTIFICATION_FIELDS} }
|
|
270
|
+
}`,
|
|
271
|
+
}));
|
|
272
|
+
return runtimeNotifications;
|
|
273
|
+
}
|
|
274
|
+
async updateNotification(id, notification) {
|
|
275
|
+
const { runtimeUpdateNotification } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").mutate({
|
|
276
|
+
mutation: gql `mutation runtimeUpdateNotification($id: String!, $notification: NotificationInput!) {
|
|
277
|
+
runtimeUpdateNotification(id: $id, notification: $notification)
|
|
278
|
+
}`,
|
|
279
|
+
variables: { id, notification }
|
|
280
|
+
}));
|
|
281
|
+
return runtimeUpdateNotification;
|
|
282
|
+
}
|
|
283
|
+
async removeNotification(id) {
|
|
284
|
+
const { runtimeRemoveNotification } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").mutate({
|
|
285
|
+
mutation: gql `mutation runtimeRemoveNotification($id: String!) {
|
|
286
|
+
runtimeRemoveNotification(id: $id)
|
|
287
|
+
}`,
|
|
288
|
+
variables: { id }
|
|
289
|
+
}));
|
|
290
|
+
return runtimeRemoveNotification;
|
|
291
|
+
}
|
|
292
|
+
addNotificationTriggeredCallback(cb) {
|
|
293
|
+
__classPrivateFieldGet(this, _RuntimeClient_notificationTriggeredCallbacks, "f").push(cb);
|
|
294
|
+
}
|
|
295
|
+
addNotificationRequestedCallback(cb) {
|
|
296
|
+
__classPrivateFieldGet(this, _RuntimeClient_notificationRequestedCallbacks, "f").push(cb);
|
|
297
|
+
}
|
|
298
|
+
subscribeNotificationTriggered() {
|
|
299
|
+
__classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").subscribe({
|
|
300
|
+
query: gql ` subscription {
|
|
301
|
+
runtimeNotificationTriggered { ${TRIGGERED_NOTIFICATION_FIELDS} }
|
|
302
|
+
}
|
|
303
|
+
`
|
|
304
|
+
}).subscribe({
|
|
305
|
+
next: result => {
|
|
306
|
+
__classPrivateFieldGet(this, _RuntimeClient_notificationTriggeredCallbacks, "f").forEach(cb => {
|
|
307
|
+
cb(result.data.runtimeNotificationTriggered);
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
error: (e) => console.error(e)
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
subscribeNotificationRequested() {
|
|
314
|
+
__classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").subscribe({
|
|
315
|
+
query: gql ` subscription {
|
|
316
|
+
runtimeNotificationRequested { ${NOTIFICATION_FIELDS} }
|
|
317
|
+
}
|
|
318
|
+
`
|
|
319
|
+
}).subscribe({
|
|
320
|
+
next: result => {
|
|
321
|
+
__classPrivateFieldGet(this, _RuntimeClient_notificationRequestedCallbacks, "f").forEach(cb => {
|
|
322
|
+
cb(result.data.runtimeNotificationRequested);
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
error: (e) => console.error(e)
|
|
326
|
+
});
|
|
327
|
+
}
|
|
222
328
|
addMessageCallback(cb) {
|
|
223
329
|
__classPrivateFieldGet(this, _RuntimeClient_messageReceivedCallbacks, "f").push(cb);
|
|
224
330
|
}
|
|
@@ -260,4 +366,4 @@ export class RuntimeClient {
|
|
|
260
366
|
});
|
|
261
367
|
}
|
|
262
368
|
}
|
|
263
|
-
_RuntimeClient_apolloClient = new WeakMap(), _RuntimeClient_messageReceivedCallbacks = new WeakMap(), _RuntimeClient_exceptionOccurredCallbacks = new WeakMap();
|
|
369
|
+
_RuntimeClient_apolloClient = new WeakMap(), _RuntimeClient_messageReceivedCallbacks = new WeakMap(), _RuntimeClient_exceptionOccurredCallbacks = new WeakMap(), _RuntimeClient_notificationTriggeredCallbacks = new WeakMap(), _RuntimeClient_notificationRequestedCallbacks = new WeakMap();
|
|
@@ -15,6 +15,33 @@ export declare class ExceptionInfo {
|
|
|
15
15
|
type: ExceptionType;
|
|
16
16
|
addon?: string;
|
|
17
17
|
}
|
|
18
|
+
export declare class NotificationInput {
|
|
19
|
+
description: string;
|
|
20
|
+
appName: string;
|
|
21
|
+
appUrl: string;
|
|
22
|
+
appIconPath: string;
|
|
23
|
+
trigger: string;
|
|
24
|
+
perspectiveIds: string[];
|
|
25
|
+
webhookUrl: string;
|
|
26
|
+
webhookAuth: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class Notification {
|
|
29
|
+
id: string;
|
|
30
|
+
granted: boolean;
|
|
31
|
+
description: string;
|
|
32
|
+
appName: string;
|
|
33
|
+
appUrl: string;
|
|
34
|
+
appIconPath: string;
|
|
35
|
+
trigger: string;
|
|
36
|
+
perspectiveIds: string[];
|
|
37
|
+
webhookUrl: string;
|
|
38
|
+
webhookAuth: string;
|
|
39
|
+
}
|
|
40
|
+
export declare class TriggeredNotification {
|
|
41
|
+
notification: Notification;
|
|
42
|
+
perspectiveId: string;
|
|
43
|
+
triggerMatch: string;
|
|
44
|
+
}
|
|
18
45
|
/**
|
|
19
46
|
* Resolver classes are used here to define the GraphQL schema
|
|
20
47
|
* (through the type-graphql annotations)
|
|
@@ -44,4 +71,11 @@ export default class RuntimeResolver {
|
|
|
44
71
|
runtimeMessageOutbox(filter?: string): SentMessage[];
|
|
45
72
|
runtimeMessageReceived(): PerspectiveExpression;
|
|
46
73
|
exceptionOccurred(): ExceptionInfo;
|
|
74
|
+
runtimeRequestInstallNotification(notification: NotificationInput): string;
|
|
75
|
+
runtimeNotifications(): Notification[];
|
|
76
|
+
runtimeUpdateNotification(id: string, notification: NotificationInput): boolean;
|
|
77
|
+
runtimeRemoveNotification(id: string): boolean;
|
|
78
|
+
runtimeGrantNotification(id: string): boolean;
|
|
79
|
+
runtimeNotificationRequested(): Notification;
|
|
80
|
+
runtimeNotificationTriggered(): TriggeredNotification;
|
|
47
81
|
}
|
|
@@ -10,12 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
-
import { Arg, Mutation, Resolver, Query, Subscription, ObjectType, Field, Int } from "type-graphql";
|
|
13
|
+
import { Arg, Mutation, Resolver, Query, Subscription, ObjectType, Field, Int, InputType } from "type-graphql";
|
|
14
14
|
import { Perspective, PerspectiveExpression, PerspectiveInput } from "../perspectives/Perspective";
|
|
15
15
|
import { ExpressionProof } from "../expression/Expression";
|
|
16
16
|
import { LinkExpression } from "../links/Links";
|
|
17
17
|
import { ExceptionType } from "../Exception";
|
|
18
|
-
import { RUNTIME_MESSAGED_RECEIVED_TOPIC, EXCEPTION_OCCURRED_TOPIC } from '../PubSub';
|
|
18
|
+
import { RUNTIME_MESSAGED_RECEIVED_TOPIC, EXCEPTION_OCCURRED_TOPIC, RUNTIME_NOTIFICATION_REQUESTED_TOPIC, RUNTIME_NOTIFICATION_TRIGGERED_TOPIC } from '../PubSub';
|
|
19
19
|
const testLink = new LinkExpression();
|
|
20
20
|
testLink.author = "did:ad4m:test";
|
|
21
21
|
testLink.timestamp = Date.now();
|
|
@@ -87,6 +87,113 @@ ExceptionInfo = __decorate([
|
|
|
87
87
|
ObjectType()
|
|
88
88
|
], ExceptionInfo);
|
|
89
89
|
export { ExceptionInfo };
|
|
90
|
+
// This class defines a Notification and is what an app provides
|
|
91
|
+
// when registering and installing a notification.
|
|
92
|
+
let NotificationInput = class NotificationInput {
|
|
93
|
+
};
|
|
94
|
+
__decorate([
|
|
95
|
+
Field(),
|
|
96
|
+
__metadata("design:type", String)
|
|
97
|
+
], NotificationInput.prototype, "description", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
Field(),
|
|
100
|
+
__metadata("design:type", String)
|
|
101
|
+
], NotificationInput.prototype, "appName", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
Field(),
|
|
104
|
+
__metadata("design:type", String)
|
|
105
|
+
], NotificationInput.prototype, "appUrl", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
Field(),
|
|
108
|
+
__metadata("design:type", String)
|
|
109
|
+
], NotificationInput.prototype, "appIconPath", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
Field(),
|
|
112
|
+
__metadata("design:type", String)
|
|
113
|
+
], NotificationInput.prototype, "trigger", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
Field(type => [String]),
|
|
116
|
+
__metadata("design:type", Array)
|
|
117
|
+
], NotificationInput.prototype, "perspectiveIds", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
Field(),
|
|
120
|
+
__metadata("design:type", String)
|
|
121
|
+
], NotificationInput.prototype, "webhookUrl", void 0);
|
|
122
|
+
__decorate([
|
|
123
|
+
Field(),
|
|
124
|
+
__metadata("design:type", String)
|
|
125
|
+
], NotificationInput.prototype, "webhookAuth", void 0);
|
|
126
|
+
NotificationInput = __decorate([
|
|
127
|
+
InputType()
|
|
128
|
+
], NotificationInput);
|
|
129
|
+
export { NotificationInput };
|
|
130
|
+
// This is a notification as it is stored in the runtime.
|
|
131
|
+
// Above definition plus ID and granted flag.
|
|
132
|
+
let Notification = class Notification {
|
|
133
|
+
};
|
|
134
|
+
__decorate([
|
|
135
|
+
Field(),
|
|
136
|
+
__metadata("design:type", String)
|
|
137
|
+
], Notification.prototype, "id", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
Field(),
|
|
140
|
+
__metadata("design:type", Boolean)
|
|
141
|
+
], Notification.prototype, "granted", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
Field(),
|
|
144
|
+
__metadata("design:type", String)
|
|
145
|
+
], Notification.prototype, "description", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
Field(),
|
|
148
|
+
__metadata("design:type", String)
|
|
149
|
+
], Notification.prototype, "appName", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
Field(),
|
|
152
|
+
__metadata("design:type", String)
|
|
153
|
+
], Notification.prototype, "appUrl", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
Field(),
|
|
156
|
+
__metadata("design:type", String)
|
|
157
|
+
], Notification.prototype, "appIconPath", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
Field(),
|
|
160
|
+
__metadata("design:type", String)
|
|
161
|
+
], Notification.prototype, "trigger", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
Field(type => [String]),
|
|
164
|
+
__metadata("design:type", Array)
|
|
165
|
+
], Notification.prototype, "perspectiveIds", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
Field(),
|
|
168
|
+
__metadata("design:type", String)
|
|
169
|
+
], Notification.prototype, "webhookUrl", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
Field(),
|
|
172
|
+
__metadata("design:type", String)
|
|
173
|
+
], Notification.prototype, "webhookAuth", void 0);
|
|
174
|
+
Notification = __decorate([
|
|
175
|
+
ObjectType()
|
|
176
|
+
], Notification);
|
|
177
|
+
export { Notification };
|
|
178
|
+
// This is what is sent to the launcher and the webhook.
|
|
179
|
+
let TriggeredNotification = class TriggeredNotification {
|
|
180
|
+
};
|
|
181
|
+
__decorate([
|
|
182
|
+
Field(),
|
|
183
|
+
__metadata("design:type", Notification)
|
|
184
|
+
], TriggeredNotification.prototype, "notification", void 0);
|
|
185
|
+
__decorate([
|
|
186
|
+
Field(),
|
|
187
|
+
__metadata("design:type", String)
|
|
188
|
+
], TriggeredNotification.prototype, "perspectiveId", void 0);
|
|
189
|
+
__decorate([
|
|
190
|
+
Field(),
|
|
191
|
+
__metadata("design:type", String)
|
|
192
|
+
], TriggeredNotification.prototype, "triggerMatch", void 0);
|
|
193
|
+
TriggeredNotification = __decorate([
|
|
194
|
+
ObjectType()
|
|
195
|
+
], TriggeredNotification);
|
|
196
|
+
export { TriggeredNotification };
|
|
90
197
|
/**
|
|
91
198
|
* Resolver classes are used here to define the GraphQL schema
|
|
92
199
|
* (through the type-graphql annotations)
|
|
@@ -171,6 +278,64 @@ let RuntimeResolver = class RuntimeResolver {
|
|
|
171
278
|
type: ExceptionType.LanguageIsNotLoaded,
|
|
172
279
|
};
|
|
173
280
|
}
|
|
281
|
+
runtimeRequestInstallNotification(notification) {
|
|
282
|
+
return "new-notification-id";
|
|
283
|
+
}
|
|
284
|
+
runtimeNotifications() {
|
|
285
|
+
return [{
|
|
286
|
+
id: "test-id",
|
|
287
|
+
granted: false,
|
|
288
|
+
description: "Test description",
|
|
289
|
+
appName: "Test app name",
|
|
290
|
+
appUrl: "https://example.com",
|
|
291
|
+
appIconPath: "https://fluxsocial.io/favicon",
|
|
292
|
+
trigger: "triple(X, ad4m://has_type, flux://message)",
|
|
293
|
+
perspectiveIds: ["u983ud-jdhh38d"],
|
|
294
|
+
webhookUrl: "https://example.com/webhook",
|
|
295
|
+
webhookAuth: "test-auth",
|
|
296
|
+
}];
|
|
297
|
+
}
|
|
298
|
+
runtimeUpdateNotification(id, notification) {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
runtimeRemoveNotification(id) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
runtimeGrantNotification(id) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
runtimeNotificationRequested() {
|
|
308
|
+
return {
|
|
309
|
+
id: "test-id",
|
|
310
|
+
granted: false,
|
|
311
|
+
description: "Test description",
|
|
312
|
+
appName: "Test app name",
|
|
313
|
+
appUrl: "https://example.com",
|
|
314
|
+
appIconPath: "https://fluxsocial.io/favicon",
|
|
315
|
+
trigger: "triple(X, ad4m://has_type, flux://message)",
|
|
316
|
+
perspectiveIds: ["u983ud-jdhh38d"],
|
|
317
|
+
webhookUrl: "https://example.com/webhook",
|
|
318
|
+
webhookAuth: "test-auth",
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
runtimeNotificationTriggered() {
|
|
322
|
+
return {
|
|
323
|
+
perspectiveId: "test-perspective-id",
|
|
324
|
+
triggerMatch: "test-trigger-match",
|
|
325
|
+
notification: {
|
|
326
|
+
id: "test-id",
|
|
327
|
+
granted: false,
|
|
328
|
+
description: "Test description",
|
|
329
|
+
appName: "Test app name",
|
|
330
|
+
appUrl: "https://example.com",
|
|
331
|
+
appIconPath: "https://fluxsocial.io/favicon",
|
|
332
|
+
trigger: "triple(X, ad4m://has_type, flux://message)",
|
|
333
|
+
perspectiveIds: ["u983ud-jdhh38d"],
|
|
334
|
+
webhookUrl: "https://example.com/webhook",
|
|
335
|
+
webhookAuth: "test-auth",
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
174
339
|
};
|
|
175
340
|
__decorate([
|
|
176
341
|
Mutation(returns => Boolean),
|
|
@@ -322,6 +487,53 @@ __decorate([
|
|
|
322
487
|
__metadata("design:paramtypes", []),
|
|
323
488
|
__metadata("design:returntype", ExceptionInfo)
|
|
324
489
|
], RuntimeResolver.prototype, "exceptionOccurred", null);
|
|
490
|
+
__decorate([
|
|
491
|
+
Mutation(),
|
|
492
|
+
__param(0, Arg("notification", type => NotificationInput)),
|
|
493
|
+
__metadata("design:type", Function),
|
|
494
|
+
__metadata("design:paramtypes", [NotificationInput]),
|
|
495
|
+
__metadata("design:returntype", String)
|
|
496
|
+
], RuntimeResolver.prototype, "runtimeRequestInstallNotification", null);
|
|
497
|
+
__decorate([
|
|
498
|
+
Query(returns => [Notification]),
|
|
499
|
+
__metadata("design:type", Function),
|
|
500
|
+
__metadata("design:paramtypes", []),
|
|
501
|
+
__metadata("design:returntype", Array)
|
|
502
|
+
], RuntimeResolver.prototype, "runtimeNotifications", null);
|
|
503
|
+
__decorate([
|
|
504
|
+
Mutation(),
|
|
505
|
+
__param(0, Arg("id", type => String)),
|
|
506
|
+
__param(1, Arg("notification", type => NotificationInput)),
|
|
507
|
+
__metadata("design:type", Function),
|
|
508
|
+
__metadata("design:paramtypes", [String, NotificationInput]),
|
|
509
|
+
__metadata("design:returntype", Boolean)
|
|
510
|
+
], RuntimeResolver.prototype, "runtimeUpdateNotification", null);
|
|
511
|
+
__decorate([
|
|
512
|
+
Mutation(),
|
|
513
|
+
__param(0, Arg("id", type => String)),
|
|
514
|
+
__metadata("design:type", Function),
|
|
515
|
+
__metadata("design:paramtypes", [String]),
|
|
516
|
+
__metadata("design:returntype", Boolean)
|
|
517
|
+
], RuntimeResolver.prototype, "runtimeRemoveNotification", null);
|
|
518
|
+
__decorate([
|
|
519
|
+
Mutation(),
|
|
520
|
+
__param(0, Arg("id", type => String)),
|
|
521
|
+
__metadata("design:type", Function),
|
|
522
|
+
__metadata("design:paramtypes", [String]),
|
|
523
|
+
__metadata("design:returntype", Boolean)
|
|
524
|
+
], RuntimeResolver.prototype, "runtimeGrantNotification", null);
|
|
525
|
+
__decorate([
|
|
526
|
+
Subscription({ topics: RUNTIME_NOTIFICATION_REQUESTED_TOPIC, nullable: true }),
|
|
527
|
+
__metadata("design:type", Function),
|
|
528
|
+
__metadata("design:paramtypes", []),
|
|
529
|
+
__metadata("design:returntype", Notification)
|
|
530
|
+
], RuntimeResolver.prototype, "runtimeNotificationRequested", null);
|
|
531
|
+
__decorate([
|
|
532
|
+
Subscription({ topics: RUNTIME_NOTIFICATION_TRIGGERED_TOPIC, nullable: true }),
|
|
533
|
+
__metadata("design:type", Function),
|
|
534
|
+
__metadata("design:paramtypes", []),
|
|
535
|
+
__metadata("design:returntype", TriggeredNotification)
|
|
536
|
+
], RuntimeResolver.prototype, "runtimeNotificationTriggered", null);
|
|
325
537
|
RuntimeResolver = __decorate([
|
|
326
538
|
Resolver()
|
|
327
539
|
], RuntimeResolver);
|