@coasys/ad4m 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/lib/index.cjs +19 -47
  2. package/lib/index.js +8081 -0
  3. package/lib/shims/reflect-metadata.js +0 -0
  4. package/lib/shims/type-graphql.js +70 -0
  5. package/lib/src/Ad4mClient.js +66 -0
  6. package/lib/src/Address.js +1 -0
  7. package/lib/src/DID.js +1 -0
  8. package/lib/src/Exception.js +7 -0
  9. package/lib/src/Literal.js +76 -0
  10. package/lib/src/PubSub.js +14 -0
  11. package/lib/src/SmartLiteral.js +74 -0
  12. package/lib/src/agent/Agent.js +337 -0
  13. package/lib/src/agent/AgentClient.js +431 -0
  14. package/lib/src/agent/AgentResolver.js +325 -0
  15. package/lib/src/agent/AgentStatus.js +61 -0
  16. package/lib/src/buildSchema.js +36 -0
  17. package/lib/src/expression/Expression.js +143 -0
  18. package/lib/src/expression/ExpressionClient.js +102 -0
  19. package/lib/src/expression/ExpressionRef.js +67 -0
  20. package/lib/src/expression/ExpressionResolver.js +106 -0
  21. package/lib/src/index.js +30 -0
  22. package/lib/src/jestSetup.js +1 -0
  23. package/lib/src/language/Icon.js +24 -0
  24. package/lib/src/language/Language.js +79 -0
  25. package/lib/src/language/LanguageClient.js +137 -0
  26. package/lib/src/language/LanguageContext.js +2 -0
  27. package/lib/src/language/LanguageHandle.js +41 -0
  28. package/lib/src/language/LanguageMeta.js +89 -0
  29. package/lib/src/language/LanguageRef.js +30 -0
  30. package/lib/src/language/LanguageResolver.js +143 -0
  31. package/lib/src/links/Links.js +148 -0
  32. package/lib/src/links/Links.test.js +33 -0
  33. package/lib/src/neighbourhood/Neighbourhood.js +38 -0
  34. package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -0
  35. package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -0
  36. package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -0
  37. package/lib/src/perspectives/LinkQuery.js +80 -0
  38. package/lib/src/perspectives/Perspective.js +144 -0
  39. package/lib/src/perspectives/Perspective.test.js +20 -0
  40. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -0
  41. package/lib/src/perspectives/PerspectiveClient.js +418 -0
  42. package/lib/src/perspectives/PerspectiveDiff.js +33 -0
  43. package/lib/src/perspectives/PerspectiveHandle.js +59 -0
  44. package/lib/src/perspectives/PerspectiveProxy.d.ts +8 -8
  45. package/lib/src/perspectives/PerspectiveProxy.js +501 -0
  46. package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -0
  47. package/lib/src/perspectives/PerspectiveResolver.js +376 -0
  48. package/lib/src/runtime/RuntimeClient.js +263 -0
  49. package/lib/src/runtime/RuntimeResolver.js +328 -0
  50. package/lib/src/schema.gql +1 -0
  51. package/lib/src/subject/SDNADecorators.js +250 -0
  52. package/lib/src/subject/Subject.js +160 -0
  53. package/lib/src/subject/SubjectEntity.js +250 -0
  54. package/lib/src/subject/util.js +73 -0
  55. package/lib/src/typeDefs.js +380 -0
  56. package/lib/src/unwrapApolloResult.js +14 -0
  57. package/lib/src/utils.js +21 -0
  58. package/package.json +2 -1
  59. package/src/Ad4mClient.test.ts +5 -0
  60. package/src/perspectives/PerspectiveClient.ts +9 -0
  61. package/src/perspectives/PerspectiveProxy.ts +22 -56
  62. package/src/perspectives/PerspectiveResolver.ts +5 -0
  63. package/src/unwrapApolloResult.ts +3 -1
package/lib/index.cjs CHANGED
@@ -3223,7 +3223,9 @@ var extras = {
3223
3223
  gql["default"] = gql;
3224
3224
 
3225
3225
  function unwrapApolloResult(result) {
3226
- //console.debug('GQL result:', result)
3226
+ if (!result) {
3227
+ throw "Got no result from Apollo";
3228
+ }
3227
3229
  //@ts-ignore
3228
3230
  if (result.error) {
3229
3231
  //@ts-ignore
@@ -4597,6 +4599,11 @@ class PerspectiveProxy {
4597
4599
  __classPrivateFieldSet$9(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, [], "f");
4598
4600
  __classPrivateFieldSet$9(this, _PerspectiveProxy_handle, handle, "f");
4599
4601
  __classPrivateFieldSet$9(this, _PerspectiveProxy_client, ad4m, "f");
4602
+ this.uuid = __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid;
4603
+ this.name = __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").name;
4604
+ this.sharedUrl = __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").sharedUrl;
4605
+ this.neighbourhood = __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").neighbourhood;
4606
+ this.state = __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").state;
4600
4607
  __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").addPerspectiveLinkAddedListener(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$9(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f"));
4601
4608
  __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").addPerspectiveLinkRemovedListener(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$9(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f"));
4602
4609
  __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").addPerspectiveLinkUpdatedListener(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet$9(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f"));
@@ -4653,26 +4660,6 @@ class PerspectiveProxy {
4653
4660
  }
4654
4661
  }
4655
4662
  }
4656
- /** Unique ID of the perspective */
4657
- get uuid() {
4658
- return __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid;
4659
- }
4660
- /** Given name of the perspective */
4661
- get name() {
4662
- return __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").name;
4663
- }
4664
- /** If the perspective is shared as a Neighbourhood, this is the Neighbourhood URL */
4665
- get sharedUrl() {
4666
- return __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").sharedUrl;
4667
- }
4668
- /** If the perspective is shared as a Neighbourhood, this is the Neighbourhood Expression */
4669
- get neighbourhood() {
4670
- return __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").neighbourhood;
4671
- }
4672
- /** Returns the state of the perspective **/
4673
- get state() {
4674
- return __classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").state;
4675
- }
4676
4663
  /** Returns all the links of this perspective that matches the LinkQuery */
4677
4664
  async get(query) {
4678
4665
  return await __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").queryLinks(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, query);
@@ -4854,32 +4841,8 @@ class PerspectiveProxy {
4854
4841
  return links.map(link => link.data.target).map(t => Literal.fromUrl(t).get());
4855
4842
  }
4856
4843
  /** Adds the given Social DNA code to the perspective's SDNA code */
4857
- async addSdna(name, sdnaCode, type) {
4858
- let predicate = "ad4m://has_custom_sdna";
4859
- if (type === 'subject_class')
4860
- predicate = "ad4m://has_subject_class";
4861
- else if (type === 'flow')
4862
- predicate = "ad4m://has_flow";
4863
- const literalName = Literal.from(name).toUrl();
4864
- const links = await this.get(new exports.LinkQuery({
4865
- source: "ad4m://self",
4866
- predicate,
4867
- target: literalName
4868
- }));
4869
- const sdnaLinks = [];
4870
- if (links.length === 0) {
4871
- sdnaLinks.push(new exports.Link({
4872
- source: "ad4m://self",
4873
- predicate,
4874
- target: literalName
4875
- }));
4876
- }
4877
- sdnaLinks.push(new exports.Link({
4878
- source: literalName,
4879
- predicate: "ad4m://sdna",
4880
- target: Literal.from(sdnaCode).toUrl()
4881
- }));
4882
- await this.addLinks(sdnaLinks);
4844
+ async addSdna(name, sdnaCode, sdnaType) {
4845
+ return __classPrivateFieldGet$9(this, _PerspectiveProxy_client, "f").addSdna(__classPrivateFieldGet$9(this, _PerspectiveProxy_handle, "f").uuid, name, sdnaCode, sdnaType);
4883
4846
  }
4884
4847
  /** Returns all the Subject classes defined in this perspectives SDNA */
4885
4848
  async subjectClasses() {
@@ -5357,6 +5320,14 @@ class PerspectiveClient {
5357
5320
  variables: { uuid, link }
5358
5321
  }));
5359
5322
  }
5323
+ async addSdna(uuid, name, sdnaCode, sdnaType) {
5324
+ return unwrapApolloResult(await __classPrivateFieldGet$8(this, _PerspectiveClient_apolloClient, "f").mutate({
5325
+ mutation: gql `mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String!, $sdnaType: String!) {
5326
+ perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType)
5327
+ }`,
5328
+ variables: { uuid, name, sdnaCode, sdnaType }
5329
+ })).perspectiveAddSdna;
5330
+ }
5360
5331
  // ExpressionClient functions, needed for Subjects:
5361
5332
  async getExpression(expressionURI) {
5362
5333
  return await __classPrivateFieldGet$8(this, _PerspectiveClient_expressionClient, "f").get(expressionURI);
@@ -7708,6 +7679,7 @@ type Mutation {
7708
7679
  perspectiveAddLink(link: LinkInput!, status: String = "shared", uuid: String!): LinkExpression!
7709
7680
  perspectiveAddLinkExpression(link: LinkExpressionInput!, status: String, uuid: String!): LinkExpression!
7710
7681
  perspectiveAddLinks(links: [LinkInput!]!, status: String, uuid: String!): [LinkExpression!]!
7682
+ perspectiveAddSdna(name: String!, sdnaCode: String!, sdnaType: String!, uuid: String!): Boolean!
7711
7683
  perspectiveLinkMutations(mutations: LinkMutations!, status: String, uuid: String!): LinkExpressionMutations!
7712
7684
  perspectivePublishSnapshot(uuid: String!): String
7713
7685
  perspectiveRemove(uuid: String!): Boolean!