@coasys/ad4m 0.9.1-prerelease → 0.10.0-prerelease

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.js CHANGED
@@ -4634,55 +4634,7 @@ class PerspectiveProxy {
4634
4634
  __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").addPerspectiveSyncStateChangeListener(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$9(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f"));
4635
4635
  }
4636
4636
  async executeAction(actions, expression, parameters) {
4637
- const replaceThis = (input) => {
4638
- if (input) {
4639
- if (input === 'this') {
4640
- return expression;
4641
- }
4642
- else {
4643
- return input;
4644
- }
4645
- }
4646
- else {
4647
- return undefined;
4648
- }
4649
- };
4650
- const replaceParameters = (input) => {
4651
- if (parameters) {
4652
- let output = input;
4653
- for (const parameter of parameters) {
4654
- output = output.replace(parameter.name, parameter.value);
4655
- }
4656
- return output;
4657
- }
4658
- else
4659
- return input;
4660
- };
4661
- for (let command of actions) {
4662
- let source = replaceThis(replaceParameters(command.source));
4663
- let predicate = replaceThis(replaceParameters(command.predicate));
4664
- let target = replaceThis(replaceParameters(command.target));
4665
- let local = command?.local ?? false;
4666
- switch (command.action) {
4667
- case 'addLink':
4668
- await this.add(new Link({ source, predicate, target }), local ? 'local' : 'shared');
4669
- break;
4670
- case 'removeLink':
4671
- const linkExpressions = await this.get(new LinkQuery({ source, predicate, target }));
4672
- for (const linkExpression of linkExpressions) {
4673
- await this.remove(linkExpression);
4674
- }
4675
- break;
4676
- case 'setSingleTarget':
4677
- await this.setSingleTarget(new Link({ source, predicate, target }), local ? 'local' : 'shared');
4678
- break;
4679
- case 'collectionSetter':
4680
- const links = await this.get(new LinkQuery({ source, predicate }));
4681
- await this.removeLinks(links);
4682
- await this.addLinks(parameters.map(p => new Link({ source, predicate, target: p.value })), local ? 'local' : 'shared');
4683
- break;
4684
- }
4685
- }
4637
+ return await __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").executeCommands(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify(actions), expression, JSON.stringify(parameters));
4686
4638
  }
4687
4639
  /** Returns all the links of this perspective that matches the LinkQuery */
4688
4640
  async get(query) {
@@ -4901,15 +4853,24 @@ class PerspectiveProxy {
4901
4853
  * @param exprAddr The address of the expression to be turned into a subject instance
4902
4854
  */
4903
4855
  async createSubject(subjectClass, exprAddr) {
4904
- let className = await this.stringOrTemplateObjectToSubjectClass(subjectClass);
4905
- let result = await this.infer(`subject_class("${className}", C), constructor(C, Actions)`);
4906
- if (!result.length) {
4907
- throw "No constructor found for given subject class: " + className;
4856
+ let className;
4857
+ if (typeof subjectClass === "string") {
4858
+ className = subjectClass;
4859
+ await __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").createSubject(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className }), exprAddr);
4860
+ }
4861
+ else {
4862
+ let query = this.buildQueryFromTemplate(subjectClass);
4863
+ await __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").createSubject(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ query }), exprAddr);
4908
4864
  }
4909
- let actions = result.map(x => eval(x.Actions));
4910
- await this.executeAction(actions[0], exprAddr, undefined);
4911
4865
  return this.getSubjectProxy(exprAddr, subjectClass);
4912
4866
  }
4867
+ async getSubjectData(subjectClass, exprAddr) {
4868
+ if (typeof subjectClass === "string") {
4869
+ return JSON.parse(await __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className: subjectClass }), exprAddr));
4870
+ }
4871
+ let query = this.buildQueryFromTemplate(subjectClass);
4872
+ return JSON.parse(await __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ query }), exprAddr));
4873
+ }
4913
4874
  /** Removes a subject instance by running its (SDNA defined) destructor,
4914
4875
  * which means removing links around the given expression address
4915
4876
  *
@@ -4995,18 +4956,7 @@ class PerspectiveProxy {
4995
4956
  }
4996
4957
  return instances;
4997
4958
  }
4998
- /** Returns all subject classes that match the given template object.
4999
- * This function looks at the properties of the template object and
5000
- * its setters and collections to create a Prolog query that finds
5001
- * all subject classes that would be converted to a proxy object
5002
- * with exactly the same properties and collections.
5003
- *
5004
- * Since there could be multiple subject classes that match the given
5005
- * criteria, this function returns a list of class names.
5006
- *
5007
- * @param obj The template object
5008
- */
5009
- async subjectClassesByTemplate(obj) {
4959
+ buildQueryFromTemplate(obj) {
5010
4960
  // Collect all string properties of the object in a list
5011
4961
  let properties = [];
5012
4962
  // Collect all collections of the object in a list
@@ -5065,6 +5015,21 @@ class PerspectiveProxy {
5065
5015
  query += `, collection_setter(C, "${collectionSetterToName(setCollectionFunction)}", _)`;
5066
5016
  }
5067
5017
  query += ".";
5018
+ return query;
5019
+ }
5020
+ /** Returns all subject classes that match the given template object.
5021
+ * This function looks at the properties of the template object and
5022
+ * its setters and collections to create a Prolog query that finds
5023
+ * all subject classes that would be converted to a proxy object
5024
+ * with exactly the same properties and collections.
5025
+ *
5026
+ * Since there could be multiple subject classes that match the given
5027
+ * criteria, this function returns a list of class names.
5028
+ *
5029
+ * @param obj The template object
5030
+ */
5031
+ async subjectClassesByTemplate(obj) {
5032
+ const query = this.buildQueryFromTemplate(obj);
5068
5033
  let result = await this.infer(query);
5069
5034
  if (!result) {
5070
5035
  return [];
@@ -5357,6 +5322,30 @@ class PerspectiveClient {
5357
5322
  variables: { uuid, name, sdnaCode, sdnaType }
5358
5323
  })).perspectiveAddSdna;
5359
5324
  }
5325
+ async executeCommands(uuid, commands, expression, parameters) {
5326
+ return unwrapApolloResult(await __classPrivateFieldGet$8(this, _PerspectiveClient_apolloClient, "f").mutate({
5327
+ mutation: gql `mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String) {
5328
+ perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters)
5329
+ }`,
5330
+ variables: { uuid, commands, expression, parameters }
5331
+ })).perspectiveExecuteCommands;
5332
+ }
5333
+ async createSubject(uuid, subjectClass, expressionAddress) {
5334
+ return unwrapApolloResult(await __classPrivateFieldGet$8(this, _PerspectiveClient_apolloClient, "f").mutate({
5335
+ mutation: gql `mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
5336
+ perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
5337
+ }`,
5338
+ variables: { uuid, subjectClass, expressionAddress }
5339
+ })).perspectiveCreateSubject;
5340
+ }
5341
+ async getSubjectData(uuid, subjectClass, expressionAddress) {
5342
+ return unwrapApolloResult(await __classPrivateFieldGet$8(this, _PerspectiveClient_apolloClient, "f").mutate({
5343
+ mutation: gql `mutation perspectiveGetSubjectData($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
5344
+ perspectiveGetSubjectData(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
5345
+ }`,
5346
+ variables: { uuid, subjectClass, expressionAddress }
5347
+ })).perspectiveGetSubjectData;
5348
+ }
5360
5349
  // ExpressionClient functions, needed for Subjects:
5361
5350
  async getExpression(expressionURI) {
5362
5351
  return await __classPrivateFieldGet$8(this, _PerspectiveClient_expressionClient, "f").get(expressionURI);
@@ -6337,7 +6326,7 @@ var __classPrivateFieldGet$4 = (undefined && undefined.__classPrivateFieldGet) |
6337
6326
  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");
6338
6327
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6339
6328
  };
6340
- var _RuntimeClient_apolloClient, _RuntimeClient_messageReceivedCallbacks, _RuntimeClient_exceptionOccurredCallbacks;
6329
+ var _RuntimeClient_apolloClient, _RuntimeClient_messageReceivedCallbacks, _RuntimeClient_exceptionOccurredCallbacks, _RuntimeClient_notificationTriggeredCallbacks, _RuntimeClient_notificationRequestedCallbacks;
6341
6330
  const PERSPECTIVE_EXPRESSION_FIELDS = `
6342
6331
  author
6343
6332
  timestamp
@@ -6351,17 +6340,43 @@ data {
6351
6340
  }
6352
6341
  proof { valid, invalid, signature, key }
6353
6342
  `;
6343
+ const NOTIFICATION_DEFINITION_FIELDS = `
6344
+ description
6345
+ appName
6346
+ appUrl
6347
+ appIconPath
6348
+ trigger
6349
+ perspectiveIds
6350
+ webhookUrl
6351
+ webhookAuth
6352
+ `;
6353
+ const NOTIFICATION_FIELDS = `
6354
+ id
6355
+ granted
6356
+ ${NOTIFICATION_DEFINITION_FIELDS}
6357
+ `;
6358
+ const TRIGGERED_NOTIFICATION_FIELDS = `
6359
+ notification { ${NOTIFICATION_FIELDS} }
6360
+ perspectiveId
6361
+ triggerMatch
6362
+ `;
6354
6363
  class RuntimeClient {
6355
6364
  constructor(client, subscribe = true) {
6356
6365
  _RuntimeClient_apolloClient.set(this, void 0);
6357
6366
  _RuntimeClient_messageReceivedCallbacks.set(this, void 0);
6358
6367
  _RuntimeClient_exceptionOccurredCallbacks.set(this, void 0);
6368
+ _RuntimeClient_notificationTriggeredCallbacks.set(this, void 0);
6369
+ _RuntimeClient_notificationRequestedCallbacks.set(this, void 0);
6359
6370
  __classPrivateFieldSet$4(this, _RuntimeClient_apolloClient, client, "f");
6360
6371
  __classPrivateFieldSet$4(this, _RuntimeClient_messageReceivedCallbacks, [], "f");
6361
6372
  __classPrivateFieldSet$4(this, _RuntimeClient_exceptionOccurredCallbacks, [], "f");
6373
+ __classPrivateFieldSet$4(this, _RuntimeClient_notificationTriggeredCallbacks, [], "f");
6374
+ __classPrivateFieldSet$4(this, _RuntimeClient_notificationRequestedCallbacks, [], "f");
6362
6375
  if (subscribe) {
6363
6376
  this.subscribeMessageReceived();
6364
6377
  this.subscribeExceptionOccurred();
6378
+ this.subscribeNotificationTriggered();
6379
+ this.subscribeNotificationRequested();
6365
6380
  }
6366
6381
  }
6367
6382
  async info() {
@@ -6545,6 +6560,86 @@ class RuntimeClient {
6545
6560
  }));
6546
6561
  return runtimeMessageOutbox;
6547
6562
  }
6563
+ async requestInstallNotification(notification) {
6564
+ const { runtimeRequestInstallNotification } = unwrapApolloResult(await __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").mutate({
6565
+ mutation: gql `mutation runtimeRequestInstallNotification($notification: NotificationInput!) {
6566
+ runtimeRequestInstallNotification(notification: $notification)
6567
+ }`,
6568
+ variables: { notification }
6569
+ }));
6570
+ return runtimeRequestInstallNotification;
6571
+ }
6572
+ async grantNotification(id) {
6573
+ const { runtimeGrantNotification } = unwrapApolloResult(await __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").mutate({
6574
+ mutation: gql `mutation runtimeGrantNotification($id: String!) {
6575
+ runtimeGrantNotification(id: $id)
6576
+ }`,
6577
+ variables: { id }
6578
+ }));
6579
+ return runtimeGrantNotification;
6580
+ }
6581
+ async notifications() {
6582
+ const { runtimeNotifications } = unwrapApolloResult(await __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").query({
6583
+ query: gql `query runtimeNotifications {
6584
+ runtimeNotifications { ${NOTIFICATION_FIELDS} }
6585
+ }`,
6586
+ }));
6587
+ return runtimeNotifications;
6588
+ }
6589
+ async updateNotification(id, notification) {
6590
+ const { runtimeUpdateNotification } = unwrapApolloResult(await __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").mutate({
6591
+ mutation: gql `mutation runtimeUpdateNotification($id: String!, $notification: NotificationInput!) {
6592
+ runtimeUpdateNotification(id: $id, notification: $notification)
6593
+ }`,
6594
+ variables: { id, notification }
6595
+ }));
6596
+ return runtimeUpdateNotification;
6597
+ }
6598
+ async removeNotification(id) {
6599
+ const { runtimeRemoveNotification } = unwrapApolloResult(await __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").mutate({
6600
+ mutation: gql `mutation runtimeRemoveNotification($id: String!) {
6601
+ runtimeRemoveNotification(id: $id)
6602
+ }`,
6603
+ variables: { id }
6604
+ }));
6605
+ return runtimeRemoveNotification;
6606
+ }
6607
+ addNotificationTriggeredCallback(cb) {
6608
+ __classPrivateFieldGet$4(this, _RuntimeClient_notificationTriggeredCallbacks, "f").push(cb);
6609
+ }
6610
+ addNotificationRequestedCallback(cb) {
6611
+ __classPrivateFieldGet$4(this, _RuntimeClient_notificationRequestedCallbacks, "f").push(cb);
6612
+ }
6613
+ subscribeNotificationTriggered() {
6614
+ __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").subscribe({
6615
+ query: gql ` subscription {
6616
+ runtimeNotificationTriggered { ${TRIGGERED_NOTIFICATION_FIELDS} }
6617
+ }
6618
+ `
6619
+ }).subscribe({
6620
+ next: result => {
6621
+ __classPrivateFieldGet$4(this, _RuntimeClient_notificationTriggeredCallbacks, "f").forEach(cb => {
6622
+ cb(result.data.runtimeNotificationTriggered);
6623
+ });
6624
+ },
6625
+ error: (e) => console.error(e)
6626
+ });
6627
+ }
6628
+ subscribeNotificationRequested() {
6629
+ __classPrivateFieldGet$4(this, _RuntimeClient_apolloClient, "f").subscribe({
6630
+ query: gql ` subscription {
6631
+ runtimeNotificationRequested { ${NOTIFICATION_FIELDS} }
6632
+ }
6633
+ `
6634
+ }).subscribe({
6635
+ next: result => {
6636
+ __classPrivateFieldGet$4(this, _RuntimeClient_notificationRequestedCallbacks, "f").forEach(cb => {
6637
+ cb(result.data.runtimeNotificationRequested);
6638
+ });
6639
+ },
6640
+ error: (e) => console.error(e)
6641
+ });
6642
+ }
6548
6643
  addMessageCallback(cb) {
6549
6644
  __classPrivateFieldGet$4(this, _RuntimeClient_messageReceivedCallbacks, "f").push(cb);
6550
6645
  }
@@ -6586,7 +6681,7 @@ class RuntimeClient {
6586
6681
  });
6587
6682
  }
6588
6683
  }
6589
- _RuntimeClient_apolloClient = new WeakMap(), _RuntimeClient_messageReceivedCallbacks = new WeakMap(), _RuntimeClient_exceptionOccurredCallbacks = new WeakMap();
6684
+ _RuntimeClient_apolloClient = new WeakMap(), _RuntimeClient_messageReceivedCallbacks = new WeakMap(), _RuntimeClient_exceptionOccurredCallbacks = new WeakMap(), _RuntimeClient_notificationTriggeredCallbacks = new WeakMap(), _RuntimeClient_notificationRequestedCallbacks = new WeakMap();
6590
6685
 
6591
6686
  var __classPrivateFieldSet$3 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
6592
6687
  if (kind === "m") throw new TypeError("Private method is not writable");
@@ -6756,6 +6851,7 @@ var ExceptionType;
6756
6851
  ExceptionType["ExpressionIsNotVerified"] = "EXPRESSION_IS_NOT_VERIFIED";
6757
6852
  ExceptionType["AgentIsUntrusted"] = "AGENT_IS_UNTRUSTED";
6758
6853
  ExceptionType["CapabilityRequested"] = "CAPABILITY_REQUESTED";
6854
+ ExceptionType["InstallNotificationRequest"] = "INSTALL_NOTIFICATION_REQUEST";
6759
6855
  })(ExceptionType || (ExceptionType = {}));
6760
6856
 
6761
6857
  var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
@@ -7820,6 +7916,9 @@ type Mutation {
7820
7916
  perspectiveAddLinkExpression(link: LinkExpressionInput!, status: String, uuid: String!): LinkExpression!
7821
7917
  perspectiveAddLinks(links: [LinkInput!]!, status: String, uuid: String!): [LinkExpression!]!
7822
7918
  perspectiveAddSdna(name: String!, sdnaCode: String!, sdnaType: String!, uuid: String!): Boolean!
7919
+ perspectiveCreateSubject(expressionAddress: String!, subjectClass: String!, uuid: String!): Boolean!
7920
+ perspectiveExecuteCommands(commands: String!, expression: String!, parameters: String, uuid: String!): Boolean!
7921
+ perspectiveGetSubjectData(expressionAddress: String!, subjectClass: String!, uuid: String!): String!
7823
7922
  perspectiveLinkMutations(mutations: LinkMutations!, status: String, uuid: String!): LinkExpressionMutations!
7824
7923
  perspectivePublishSnapshot(uuid: String!): String
7825
7924
  perspectiveRemove(uuid: String!): Boolean!
@@ -7830,12 +7929,16 @@ type Mutation {
7830
7929
  runtimeAddFriends(dids: [String!]!): [String!]!
7831
7930
  runtimeAddKnownLinkLanguageTemplates(addresses: [String!]!): [String!]!
7832
7931
  runtimeFriendSendMessage(did: String!, message: PerspectiveInput!): Boolean!
7932
+ runtimeGrantNotification(id: String!): Boolean!
7833
7933
  runtimeHcAddAgentInfos(agentInfos: String!): Boolean!
7834
7934
  runtimeOpenLink(url: String!): Boolean!
7835
7935
  runtimeQuit: Boolean!
7836
7936
  runtimeRemoveFriends(dids: [String!]!): [String!]!
7837
7937
  runtimeRemoveKnownLinkLanguageTemplates(addresses: [String!]!): [String!]!
7938
+ runtimeRemoveNotification(id: String!): Boolean!
7939
+ runtimeRequestInstallNotification(notification: NotificationInput!): String!
7838
7940
  runtimeSetStatus(status: PerspectiveInput!): Boolean!
7941
+ runtimeUpdateNotification(id: String!, notification: NotificationInput!): Boolean!
7839
7942
  }
7840
7943
 
7841
7944
  type Neighbourhood {
@@ -7850,6 +7953,30 @@ type NeighbourhoodExpression {
7850
7953
  timestamp: String!
7851
7954
  }
7852
7955
 
7956
+ type Notification {
7957
+ appIconPath: String!
7958
+ appName: String!
7959
+ appUrl: String!
7960
+ description: String!
7961
+ granted: Boolean!
7962
+ id: String!
7963
+ perspectiveIds: [String!]!
7964
+ trigger: String!
7965
+ webhookAuth: String!
7966
+ webhookUrl: String!
7967
+ }
7968
+
7969
+ input NotificationInput {
7970
+ appIconPath: String!
7971
+ appName: String!
7972
+ appUrl: String!
7973
+ description: String!
7974
+ perspectiveIds: [String!]!
7975
+ trigger: String!
7976
+ webhookAuth: String!
7977
+ webhookUrl: String!
7978
+ }
7979
+
7853
7980
  type OnlineAgent {
7854
7981
  did: String!
7855
7982
  status: PerspectiveExpression!
@@ -7913,6 +8040,7 @@ type Query {
7913
8040
  runtimeKnownLinkLanguageTemplates: [String!]!
7914
8041
  runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
7915
8042
  runtimeMessageOutbox(filter: String): [SentMessage!]!
8043
+ runtimeNotifications: [Notification!]!
7916
8044
  runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
7917
8045
  }
7918
8046
 
@@ -7951,6 +8079,14 @@ type Subscription {
7951
8079
  perspectiveSyncStateChange(uuid: String!): String!
7952
8080
  perspectiveUpdated: PerspectiveHandle
7953
8081
  runtimeMessageReceived: PerspectiveExpression
8082
+ runtimeNotificationRequested: Notification
8083
+ runtimeNotificationTriggered: TriggeredNotification
8084
+ }
8085
+
8086
+ type TriggeredNotification {
8087
+ notification: Notification!
8088
+ perspectiveId: String!
8089
+ triggerMatch: String!
7954
8090
  }
7955
8091
  `;
7956
8092
 
@@ -8015,61 +8151,10 @@ class SubjectEntity {
8015
8151
  }
8016
8152
  async getData(id) {
8017
8153
  const tempId = id ?? __classPrivateFieldGet(this, _SubjectEntity_baseExpression, "f");
8018
- let isInstance = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").isSubjectInstance(tempId, __classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f"));
8019
- if (!isInstance) {
8020
- throw `Not a valid subject instance of ${__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f")} for ${tempId}`;
8021
- }
8022
- let results = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f")}", C), property(C, Property)`);
8023
- let properties = results.map(result => result.Property);
8024
- for (let p of properties) {
8025
- const resolveExpressionURI = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f")}", C), property_resolve(C, "${p}")`);
8026
- const getProperty = async () => {
8027
- let results = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f")}", C), property_getter(C, "${tempId}", "${p}", Value)`);
8028
- if (results && results.length > 0) {
8029
- let expressionURI = results[0].Value;
8030
- if (resolveExpressionURI) {
8031
- try {
8032
- const expression = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").getExpression(expressionURI);
8033
- try {
8034
- return JSON.parse(expression.data);
8035
- }
8036
- catch (e) {
8037
- return expression.data;
8038
- }
8039
- }
8040
- catch (err) {
8041
- return expressionURI;
8042
- }
8043
- }
8044
- else {
8045
- return expressionURI;
8046
- }
8047
- }
8048
- else if (results) {
8049
- return results;
8050
- }
8051
- else {
8052
- return undefined;
8053
- }
8054
- };
8055
- this[p] = await getProperty();
8056
- }
8057
- let results2 = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f")}", C), collection(C, Collection)`);
8058
- if (!results2)
8059
- results2 = [];
8060
- let collections = results2.map(result => result.Collection);
8061
- for (let c of collections) {
8062
- const getProperty = async () => {
8063
- let results = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f")}", C), collection_getter(C, "${tempId}", "${c}", Value)`);
8064
- if (results && results.length > 0 && results[0].Value) {
8065
- return eval(results[0].Value);
8066
- }
8067
- else {
8068
- return [];
8069
- }
8070
- };
8071
- this[c] = await getProperty();
8072
- }
8154
+ console.log("SubjectEntity: getData");
8155
+ let data = await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").getSubjectData(__classPrivateFieldGet(this, _SubjectEntity_subjectClass, "f"), tempId);
8156
+ console.log("SubjectEntity got data:", data);
8157
+ Object.assign(this, data);
8073
8158
  __classPrivateFieldSet(this, _SubjectEntity_baseExpression, tempId, "f");
8074
8159
  return this;
8075
8160
  }
@@ -2,5 +2,6 @@ export declare enum ExceptionType {
2
2
  LanguageIsNotLoaded = "LANGUAGE_IS_NOT_LOADED",
3
3
  ExpressionIsNotVerified = "EXPRESSION_IS_NOT_VERIFIED",
4
4
  AgentIsUntrusted = "AGENT_IS_UNTRUSTED",
5
- CapabilityRequested = "CAPABILITY_REQUESTED"
5
+ CapabilityRequested = "CAPABILITY_REQUESTED",
6
+ InstallNotificationRequest = "INSTALL_NOTIFICATION_REQUEST"
6
7
  }
@@ -4,4 +4,5 @@ export var ExceptionType;
4
4
  ExceptionType["ExpressionIsNotVerified"] = "EXPRESSION_IS_NOT_VERIFIED";
5
5
  ExceptionType["AgentIsUntrusted"] = "AGENT_IS_UNTRUSTED";
6
6
  ExceptionType["CapabilityRequested"] = "CAPABILITY_REQUESTED";
7
+ ExceptionType["InstallNotificationRequest"] = "INSTALL_NOTIFICATION_REQUEST";
7
8
  })(ExceptionType || (ExceptionType = {}));
@@ -9,6 +9,8 @@ export declare const LINK_REMOVED_TOPIC = "link-removed-topic";
9
9
  export declare const LINK_UDATED_TOPIC = "link-updated-topic";
10
10
  export declare const SIGNAL = "signal";
11
11
  export declare const EXCEPTION_OCCURRED_TOPIC = "exception-occurred-topic";
12
+ export declare const RUNTIME_NOTIFICATION_REQUESTED_TOPIC = "runtime-notification-requested-topic";
13
+ export declare const RUNTIME_NOTIFICATION_TRIGGERED_TOPIC = "runtime-notification-triggered-topic";
12
14
  export declare const NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC = "neighbourhood-signal-received-topic";
13
15
  export declare const PERSPECTIVE_SYNC_STATE_CHANGE = "perspective-sync-state-change";
14
16
  export declare const APPS_CHANGED = "apps-changed";
package/lib/src/PubSub.js CHANGED
@@ -9,6 +9,8 @@ export const LINK_REMOVED_TOPIC = 'link-removed-topic';
9
9
  export const LINK_UDATED_TOPIC = 'link-updated-topic';
10
10
  export const SIGNAL = "signal";
11
11
  export const EXCEPTION_OCCURRED_TOPIC = "exception-occurred-topic";
12
+ export const RUNTIME_NOTIFICATION_REQUESTED_TOPIC = "runtime-notification-requested-topic";
13
+ export const RUNTIME_NOTIFICATION_TRIGGERED_TOPIC = "runtime-notification-triggered-topic";
12
14
  export const NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC = "neighbourhood-signal-received-topic";
13
15
  export const PERSPECTIVE_SYNC_STATE_CHANGE = "perspective-sync-state-change";
14
16
  export const APPS_CHANGED = "apps-changed";
@@ -38,6 +38,9 @@ export declare class PerspectiveClient {
38
38
  perspectiveRemoveLink: boolean;
39
39
  }>;
40
40
  addSdna(uuid: string, name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom"): Promise<boolean>;
41
+ executeCommands(uuid: string, commands: string, expression: string, parameters: string): Promise<boolean>;
42
+ createSubject(uuid: string, subjectClass: string, expressionAddress: string): Promise<boolean>;
43
+ getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string>;
41
44
  getExpression(expressionURI: string): Promise<ExpressionRendered>;
42
45
  createExpression(content: any, languageAddress: string): Promise<string>;
43
46
  addPerspectiveAddedListener(cb: PerspectiveHandleCallback): void;
@@ -266,6 +266,30 @@ export class PerspectiveClient {
266
266
  variables: { uuid, name, sdnaCode, sdnaType }
267
267
  })).perspectiveAddSdna;
268
268
  }
269
+ async executeCommands(uuid, commands, expression, parameters) {
270
+ return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
271
+ mutation: gql `mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String) {
272
+ perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters)
273
+ }`,
274
+ variables: { uuid, commands, expression, parameters }
275
+ })).perspectiveExecuteCommands;
276
+ }
277
+ async createSubject(uuid, subjectClass, expressionAddress) {
278
+ return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
279
+ mutation: gql `mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
280
+ perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
281
+ }`,
282
+ variables: { uuid, subjectClass, expressionAddress }
283
+ })).perspectiveCreateSubject;
284
+ }
285
+ async getSubjectData(uuid, subjectClass, expressionAddress) {
286
+ return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
287
+ mutation: gql `mutation perspectiveGetSubjectData($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
288
+ perspectiveGetSubjectData(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
289
+ }`,
290
+ variables: { uuid, subjectClass, expressionAddress }
291
+ })).perspectiveGetSubjectData;
292
+ }
269
293
  // ExpressionClient functions, needed for Subjects:
270
294
  async getExpression(expressionURI) {
271
295
  return await __classPrivateFieldGet(this, _PerspectiveClient_expressionClient, "f").get(expressionURI);
@@ -31,7 +31,7 @@ export declare class PerspectiveProxy {
31
31
  /** Returns the state of the perspective **/
32
32
  state: PerspectiveState | null;
33
33
  constructor(handle: PerspectiveHandle, ad4m: PerspectiveClient);
34
- executeAction(actions: any, expression: any, parameters: Parameter[]): Promise<void>;
34
+ executeAction(actions: any, expression: any, parameters: Parameter[]): Promise<boolean>;
35
35
  /** Returns all the links of this perspective that matches the LinkQuery */
36
36
  get(query: LinkQuery): Promise<LinkExpression[]>;
37
37
  /** Runs a Prolog query on the perspective's Prolog engine */
@@ -121,6 +121,7 @@ export declare class PerspectiveProxy {
121
121
  * @param exprAddr The address of the expression to be turned into a subject instance
122
122
  */
123
123
  createSubject<T>(subjectClass: T, exprAddr: string): Promise<T>;
124
+ getSubjectData<T>(subjectClass: T, exprAddr: string): Promise<T>;
124
125
  /** Removes a subject instance by running its (SDNA defined) destructor,
125
126
  * which means removing links around the given expression address
126
127
  *
@@ -159,6 +160,7 @@ export declare class PerspectiveProxy {
159
160
  * that match the given properties will be used.
160
161
  */
161
162
  getAllSubjectProxies<T>(subjectClass: T): Promise<T[]>;
163
+ private buildQueryFromTemplate;
162
164
  /** Returns all subject classes that match the given template object.
163
165
  * This function looks at the properties of the template object and
164
166
  * its setters and collections to create a Prolog query that finds