@ldo/connected-nextgraph 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (89) hide show
  1. package/README.md +65 -3
  2. package/dist/{NextGraphConnectedPlugin.js → cjs/NextGraphConnectedPlugin.js} +9 -10
  3. package/dist/cjs/NextGraphConnectedPlugin.js.map +1 -0
  4. package/dist/{createNextGraphLdoDataset.js → cjs/createNextGraphLdoDataset.js} +2 -2
  5. package/dist/cjs/createNextGraphLdoDataset.js.map +1 -0
  6. package/dist/{index.js → cjs/index.js} +6 -5
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/cjs/notifications/NextGraphNotificationMessage.js.map +1 -0
  9. package/dist/cjs/notifications/NextGraphNotificationSubscription.js +15 -0
  10. package/dist/cjs/notifications/NextGraphNotificationSubscription.js.map +1 -0
  11. package/dist/{resources → cjs/resources}/NextGraphResource.js +19 -27
  12. package/dist/cjs/resources/NextGraphResource.js.map +1 -0
  13. package/dist/cjs/results/NextGraphReadSuccess.js.map +1 -0
  14. package/dist/cjs/types.js.map +1 -0
  15. package/dist/cjs/util/NextGraphNotificationMessage.js.map +1 -0
  16. package/dist/{util → cjs/util}/isNextGraphUri.js +5 -0
  17. package/dist/cjs/util/isNextGraphUri.js.map +1 -0
  18. package/dist/esm/NextGraphConnectedPlugin.js +34 -0
  19. package/dist/esm/NextGraphConnectedPlugin.js.map +1 -0
  20. package/dist/esm/createNextGraphLdoDataset.js +9 -0
  21. package/dist/esm/createNextGraphLdoDataset.js.map +1 -0
  22. package/dist/esm/index.js +7 -0
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/esm/notifications/NextGraphNotificationMessage.js +2 -0
  25. package/dist/esm/notifications/NextGraphNotificationMessage.js.map +1 -0
  26. package/dist/esm/notifications/NextGraphNotificationSubscription.js +11 -0
  27. package/dist/esm/notifications/NextGraphNotificationSubscription.js.map +1 -0
  28. package/dist/esm/resources/NextGraphResource.js +156 -0
  29. package/dist/esm/resources/NextGraphResource.js.map +1 -0
  30. package/dist/esm/results/NextGraphReadSuccess.js +8 -0
  31. package/dist/esm/results/NextGraphReadSuccess.js.map +1 -0
  32. package/dist/esm/types.js +2 -0
  33. package/dist/esm/types.js.map +1 -0
  34. package/dist/esm/util/NextGraphNotificationMessage.js +2 -0
  35. package/dist/esm/util/NextGraphNotificationMessage.js.map +1 -0
  36. package/dist/esm/util/isNextGraphUri.js +9 -0
  37. package/dist/esm/util/isNextGraphUri.js.map +1 -0
  38. package/dist/{NextGraphConnectedPlugin.d.ts → types/NextGraphConnectedPlugin.d.ts} +5 -2
  39. package/dist/types/NextGraphConnectedPlugin.d.ts.map +1 -0
  40. package/dist/types/createNextGraphLdoDataset.d.ts +3 -0
  41. package/dist/types/createNextGraphLdoDataset.d.ts.map +1 -0
  42. package/dist/types/index.d.ts +7 -0
  43. package/dist/types/index.d.ts.map +1 -0
  44. package/dist/{notifications → types/notifications}/NextGraphNotificationMessage.d.ts +1 -0
  45. package/dist/types/notifications/NextGraphNotificationMessage.d.ts.map +1 -0
  46. package/dist/{notifications → types/notifications}/NextGraphNotificationSubscription.d.ts +3 -2
  47. package/dist/types/notifications/NextGraphNotificationSubscription.d.ts.map +1 -0
  48. package/dist/{resources → types/resources}/NextGraphResource.d.ts +14 -6
  49. package/dist/types/resources/NextGraphResource.d.ts.map +1 -0
  50. package/dist/{results → types/results}/NextGraphReadSuccess.d.ts +2 -1
  51. package/dist/types/results/NextGraphReadSuccess.d.ts.map +1 -0
  52. package/dist/{types.d.ts → types/types.d.ts} +4 -0
  53. package/dist/types/types.d.ts.map +1 -0
  54. package/dist/{util → types/util}/NextGraphNotificationMessage.d.ts +1 -0
  55. package/dist/types/util/NextGraphNotificationMessage.d.ts.map +1 -0
  56. package/dist/types/util/isNextGraphUri.d.ts +8 -0
  57. package/dist/types/util/isNextGraphUri.d.ts.map +1 -0
  58. package/package.json +28 -16
  59. package/src/NextGraphConnectedPlugin.ts +10 -6
  60. package/src/createNextGraphLdoDataset.ts +1 -1
  61. package/src/index.ts +7 -5
  62. package/src/notifications/NextGraphNotificationSubscription.ts +3 -5
  63. package/src/resources/NextGraphResource.ts +24 -29
  64. package/src/results/NextGraphReadSuccess.ts +1 -1
  65. package/src/util/isNextGraphUri.ts +1 -1
  66. package/dist/NextGraphConnectedPlugin.js.map +0 -1
  67. package/dist/createNextGraphLdoDataset.d.ts +0 -2
  68. package/dist/createNextGraphLdoDataset.js.map +0 -1
  69. package/dist/createSolidLdoDataset.d.ts +0 -2
  70. package/dist/createSolidLdoDataset.js +0 -13
  71. package/dist/createSolidLdoDataset.js.map +0 -1
  72. package/dist/index.d.ts +0 -5
  73. package/dist/index.js.map +0 -1
  74. package/dist/notifications/NextGraphNotificationMessage.js.map +0 -1
  75. package/dist/notifications/NextGraphNotificationSubscription.js +0 -20
  76. package/dist/notifications/NextGraphNotificationSubscription.js.map +0 -1
  77. package/dist/resources/NextGraphResource.js.map +0 -1
  78. package/dist/results/NextGraphReadSuccess.js.map +0 -1
  79. package/dist/results/NoNextGraphStoreError.d.ts +0 -5
  80. package/dist/results/NoNextGraphStoreError.js +0 -12
  81. package/dist/results/NoNextGraphStoreError.js.map +0 -1
  82. package/dist/types.js.map +0 -1
  83. package/dist/util/NextGraphNotificationMessage.js.map +0 -1
  84. package/dist/util/isNextGraphUri.d.ts +0 -2
  85. package/dist/util/isNextGraphUri.js.map +0 -1
  86. /package/dist/{notifications → cjs/notifications}/NextGraphNotificationMessage.js +0 -0
  87. /package/dist/{results → cjs/results}/NextGraphReadSuccess.js +0 -0
  88. /package/dist/{types.js → cjs/types.js} +0 -0
  89. /package/dist/{util → cjs/util}/NextGraphNotificationMessage.js +0 -0
package/README.md CHANGED
@@ -7,7 +7,16 @@ The `@ldo/connected-nextgraph` library allows you to integrate [NextGraph](https
7
7
  First, install the required libraries:
8
8
 
9
9
  ```bash
10
- npm install nextgraph @ldo/connected-nextgraph
10
+ npm install @ldo/connected-nextgraph
11
+ ```
12
+
13
+ Also install a version of next-graph you wish to use
14
+
15
+ ```bash
16
+ # For applications on NodeJS
17
+ npm install nextgraph
18
+ # For applications running in the web browser
19
+ npm install nextgraphweb
11
20
  ```
12
21
 
13
22
  ## Usage:
@@ -26,7 +35,7 @@ const ldoDataset = createNextGraphLdoDataset();
26
35
  Before you can create or access resources, you need an active session:
27
36
 
28
37
  ```ts
29
- import ng from "nextgraph";
38
+ import ng from "nextgraph" // or `import ng from "nextgraphweb"` for the browser
30
39
 
31
40
  // Open your nextgraph wallet
32
41
  const openedWallet = await ng.wallet_open_with_mnemonic_words(
@@ -45,9 +54,9 @@ const session = await ng.session_in_memory_start(
45
54
  ---
46
55
 
47
56
  ### 3. Link Your Dataset to the NextGraph Session
48
-
49
57
  ```ts
50
58
  ldoDataset.setContext("nextgraph", {
59
+ ng,
51
60
  sessionId: session.session_id
52
61
  });
53
62
  ```
@@ -114,6 +123,59 @@ await resource.update({
114
123
  });
115
124
  ```
116
125
 
126
+ ## Using NextGraph with React
127
+
128
+ You can also use the `@ldo/react` library with `@ldo/connected-nextgraph`.
129
+
130
+ ### 1. Create the react methods
131
+
132
+ First, we initialize some methods to use with the `@ldo/connected-nextgraph` and
133
+ `@ldo/react` libraries.
134
+
135
+ ```typescript
136
+ // ./reactMethods.ts
137
+ import { nextGraphConnectedPlugin } from "@ldo/connected-nextgraph";
138
+ import { createLdoReactMethods } from "@ldo/react";
139
+ import ng from "nextgraphweb";
140
+
141
+ export const {
142
+ dataset,
143
+ useLdo,
144
+ useMatchObject,
145
+ useMatchSubject,
146
+ useResource,
147
+ useSubject,
148
+ useSubscribeToResource,
149
+ } = createLdoReactMethods([nextGraphConnectedPlugin]);
150
+
151
+ // Set NG on the data. When the sessionId is retrieved, `setContext` can be
152
+ // called at any time to set that as well.
153
+ dataset.setContext("nextgraph", {
154
+ ng,
155
+ sessionId: "SOME_ID"
156
+ });
157
+ ```
158
+
159
+ ### 2. Use the methods in your React components
160
+
161
+ From there, you can import these created methods in your React component and use
162
+ them as you would use any of the methods in the [@ldo/react-solid](https://ldo.js.org/latest/guides/solid_react/)
163
+ library.
164
+
165
+ ```typescript
166
+ import { FunctionComponent } from "react";
167
+ import { PostShShapeType } from "./.ldo/post.shapeTypes.js";
168
+ import { useResource, useSubject } from "./reactMethods.js";
169
+
170
+ export const UseSubjectTest: FunctionComponent = () => {
171
+ useResource("did:ng:SOME_URI");
172
+ const post = useSubject(PostShShapeType, `SomeOtherUri`);
173
+
174
+ return <p role="article">{post.articleBody}</p>;
175
+ };
176
+ ```
177
+
178
+
117
179
  ## Sponsorship
118
180
  This project was made possible by a grant from NGI Zero Entrust via nlnet. Learn more on the [NLnet project page](https://nlnet.nl/project/SolidUsableApps/).
119
181
 
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.nextGraphConnectedPlugin = void 0;
7
- const NextGraphResource_1 = require("./resources/NextGraphResource");
8
- const nextgraph_1 = __importDefault(require("nextgraph"));
9
- const isNextGraphUri_1 = require("./util/isNextGraphUri");
4
+ const NextGraphResource_js_1 = require("./resources/NextGraphResource.js");
5
+ const isNextGraphUri_js_1 = require("./util/isNextGraphUri.js");
10
6
  exports.nextGraphConnectedPlugin = {
11
7
  name: "nextgraph",
12
8
  getResource: function (uri, context) {
13
- return new NextGraphResource_1.NextGraphResource(uri, context);
9
+ return new NextGraphResource_js_1.NextGraphResource(uri, context);
14
10
  },
15
11
  createResource: async function (context, options) {
16
12
  const storeType = options?.storeType;
@@ -22,17 +18,20 @@ exports.nextGraphConnectedPlugin = {
22
18
  : storeType === "private"
23
19
  ? context.nextgraph.privateStoreId
24
20
  : undefined);
25
- const nuri = await nextgraph_1.default.doc_create(context.nextgraph.sessionId, "Graph", "data:graph", "store", storeType, storeRepo);
26
- const newResource = new NextGraphResource_1.NextGraphResource(nuri, context);
21
+ const primaryClass = options?.primaryClass ?? "data:graph";
22
+ const nuri = await context.nextgraph.ng.doc_create(context.nextgraph.sessionId, "Graph", primaryClass, "store", storeType, storeRepo);
23
+ const newResource = new NextGraphResource_js_1.NextGraphResource(nuri, context);
27
24
  await newResource.read();
28
25
  return newResource;
29
26
  },
30
27
  isUriValid: function (uri) {
31
- return (0, isNextGraphUri_1.isNextGraphUri)(uri);
28
+ return (0, isNextGraphUri_js_1.isNextGraphUri)(uri);
32
29
  },
33
30
  initialContext: {
34
31
  sessionId: undefined,
35
32
  },
33
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34
+ // @ts-ignore "Types" only exists for the typing system
36
35
  types: {},
37
36
  };
38
37
  //# sourceMappingURL=NextGraphConnectedPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphConnectedPlugin.js","sourceRoot":"","sources":["../../src/NextGraphConnectedPlugin.ts"],"names":[],"mappings":";;;AAEA,2EAAqE;AACrE,gEAA0D;AAkC7C,QAAA,wBAAwB,GAA6B;IAChE,IAAI,EAAE,WAAW;IAEjB,WAAW,EAAE,UACX,GAAiB,EACjB,OAAqD;QAErD,OAAO,IAAI,wCAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,cAAc,EAAE,KAAK,WACnB,OAAqD,EACrD,OAAwC;QAExC,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,CAAC;QACrC,MAAM,SAAS,GACb,OAAO,EAAE,SAAS;YAClB,CAAC,SAAS,KAAK,WAAW;gBACxB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,gBAAgB;gBACpC,CAAC,CAAC,SAAS,KAAK,QAAQ;oBACxB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa;oBACjC,CAAC,CAAC,SAAS,KAAK,SAAS;wBACzB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,cAAc;wBAClC,CAAC,CAAC,SAAS,CAAC,CAAC;QACjB,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,YAAY,CAAC;QAE3D,MAAM,IAAI,GAAiB,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,CAC9D,OAAO,CAAC,SAAS,CAAC,SAAS,EAC3B,OAAO,EACP,YAAY,EACZ,OAAO,EACP,SAAS,EACT,SAAS,CACV,CAAC;QACF,MAAM,WAAW,GAAG,IAAI,wCAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACzD,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,UAAU,EAAE,UAAU,GAAW;QAC/B,OAAO,IAAA,kCAAc,EAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,cAAc,EAAE;QACd,SAAS,EAAE,SAAS;KACrB;IACD,6DAA6D;IAC7D,uDAAuD;IACvD,KAAK,EAAE,EAAE;CACV,CAAC"}
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNextGraphLdoDataset = void 0;
4
4
  const connected_1 = require("@ldo/connected");
5
- const NextGraphConnectedPlugin_1 = require("./NextGraphConnectedPlugin");
5
+ const NextGraphConnectedPlugin_js_1 = require("./NextGraphConnectedPlugin.js");
6
6
  const dataset_1 = require("@ldo/dataset");
7
7
  const subscribable_dataset_1 = require("@ldo/subscribable-dataset");
8
8
  function createNextGraphLdoDataset() {
9
- const nextGraphLdoDataset = new connected_1.ConnectedLdoDataset([NextGraphConnectedPlugin_1.nextGraphConnectedPlugin], (0, dataset_1.createDatasetFactory)(), (0, subscribable_dataset_1.createTransactionDatasetFactory)());
9
+ const nextGraphLdoDataset = new connected_1.ConnectedLdoDataset([NextGraphConnectedPlugin_js_1.nextGraphConnectedPlugin], (0, dataset_1.createDatasetFactory)(), (0, subscribable_dataset_1.createTransactionDatasetFactory)());
10
10
  return nextGraphLdoDataset;
11
11
  }
12
12
  exports.createNextGraphLdoDataset = createNextGraphLdoDataset;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNextGraphLdoDataset.js","sourceRoot":"","sources":["../../src/createNextGraphLdoDataset.ts"],"names":[],"mappings":";;;AAAA,8CAAqD;AACrD,+EAAyE;AACzE,0CAAoD;AACpD,oEAA4E;AAE5E,SAAgB,yBAAyB;IACvC,MAAM,mBAAmB,GAAG,IAAI,+BAAmB,CACjD,CAAC,sDAAwB,CAAC,EAC1B,IAAA,8BAAoB,GAAE,EACtB,IAAA,sDAA+B,GAAE,CAClC,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAPD,8DAOC"}
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./NextGraphConnectedPlugin"), exports);
19
- __exportStar(require("./resources/NextGraphResource"), exports);
20
- __exportStar(require("./util/isNextGraphUri"), exports);
21
- __exportStar(require("./results/NextGraphReadSuccess"), exports);
17
+ __exportStar(require("./types.js"), exports);
18
+ __exportStar(require("./NextGraphConnectedPlugin.js"), exports);
19
+ __exportStar(require("./resources/NextGraphResource.js"), exports);
20
+ __exportStar(require("./util/isNextGraphUri.js"), exports);
21
+ __exportStar(require("./results/NextGraphReadSuccess.js"), exports);
22
+ __exportStar(require("./createNextGraphLdoDataset.js"), exports);
22
23
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,gEAA8C;AAE9C,mEAAiD;AAEjD,2DAAyC;AAEzC,oEAAkD;AAElD,iEAA+C"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationMessage.js","sourceRoot":"","sources":["../../../src/notifications/NextGraphNotificationMessage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NextGraphNotificationSubscription = void 0;
4
+ const connected_1 = require("@ldo/connected");
5
+ class NextGraphNotificationSubscription extends connected_1.NotificationSubscription {
6
+ async open() {
7
+ this.unsub = await this.context.nextgraph.ng.doc_subscribe(this.resource.uri, this.context.nextgraph.sessionId, this.onNotification.bind(this));
8
+ }
9
+ async close() {
10
+ this.unsub?.();
11
+ this.unsub = undefined;
12
+ }
13
+ }
14
+ exports.NextGraphNotificationSubscription = NextGraphNotificationSubscription;
15
+ //# sourceMappingURL=NextGraphNotificationSubscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationSubscription.js","sourceRoot":"","sources":["../../../src/notifications/NextGraphNotificationSubscription.ts"],"names":[],"mappings":";;;AAAA,8CAA0D;AAI1D,MAAa,iCAAkC,SAAQ,oCAGtD;IAGW,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,aAAa,CACxD,IAAI,CAAC,QAAQ,CAAC,GAAG,EACjB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAChC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/B,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,KAAK;QACnB,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;CACF;AAlBD,8EAkBC"}
@@ -7,11 +7,10 @@ exports.NextGraphResource = void 0;
7
7
  const connected_1 = require("@ldo/connected");
8
8
  const connected_2 = require("@ldo/connected");
9
9
  const events_1 = __importDefault(require("events"));
10
- const nextgraph_1 = __importDefault(require("nextgraph"));
11
10
  const rdf_utils_1 = require("@ldo/rdf-utils");
12
- const data_model_1 = require("@rdfjs/data-model");
13
- const NextGraphReadSuccess_1 = require("../results/NextGraphReadSuccess");
14
- const NextGraphNotificationSubscription_1 = require("../notifications/NextGraphNotificationSubscription");
11
+ const rdf_utils_2 = require("@ldo/rdf-utils");
12
+ const NextGraphReadSuccess_js_1 = require("../results/NextGraphReadSuccess.js");
13
+ const NextGraphNotificationSubscription_js_1 = require("../notifications/NextGraphNotificationSubscription.js");
15
14
  const ldo_1 = require("@ldo/ldo");
16
15
  const dataset_1 = require("@ldo/dataset");
17
16
  class NextGraphResource extends events_1.default {
@@ -25,7 +24,7 @@ class NextGraphResource extends events_1.default {
25
24
  this.uri = uri;
26
25
  this.status = new connected_2.Unfetched(this);
27
26
  this.context = context;
28
- this.notificationSubscription = new NextGraphNotificationSubscription_1.NextGraphNotificationSubscription(this, this.onNotification.bind(this), this.context);
27
+ this.notificationSubscription = new NextGraphNotificationSubscription_js_1.NextGraphNotificationSubscription(this, this.onNotification.bind(this), this.context);
29
28
  }
30
29
  isLoading() {
31
30
  return this.loading;
@@ -57,32 +56,22 @@ class NextGraphResource extends events_1.default {
57
56
  }
58
57
  overwriteQuads(quads) {
59
58
  const dataset = this.context.dataset;
60
- const graphNode = (0, data_model_1.namedNode)(this.uri);
59
+ const graphNode = (0, rdf_utils_2.namedNode)(this.uri);
61
60
  dataset.deleteMatches(undefined, undefined, undefined, graphNode);
62
61
  dataset.addAll(quads.map((ngQuad) => {
63
- return (0, data_model_1.quad)(ngQuad.subject, ngQuad.predicate, ngQuad.object, graphNode);
62
+ return (0, rdf_utils_2.quad)(ngQuad.subject, ngQuad.predicate, ngQuad.object, graphNode);
64
63
  }));
65
64
  }
66
65
  async read() {
67
66
  try {
68
67
  this.loading = true;
69
68
  this.emit("update");
70
- await new Promise(async (resolve, reject) => {
71
- let unsub;
72
- try {
73
- unsub = await nextgraph_1.default.doc_subscribe(this.uri, this.context.nextgraph.sessionId, async (response) => {
74
- if (response.V0.State) {
75
- unsub();
76
- await this.onNotification(response);
77
- resolve();
78
- }
79
- });
80
- }
81
- catch (err) {
82
- reject(err);
83
- }
84
- });
85
- const result = new NextGraphReadSuccess_1.NextGraphReadSuccess(this, false);
69
+ // Fetch the data once using construct
70
+ const sparqlResult = await this.context.nextgraph.ng.sparql_query(this.context.nextgraph.sessionId, `CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <${this.uri}> { ?s ?p ?o } }`, undefined, this.uri);
71
+ // Update the dataset
72
+ this.overwriteQuads(sparqlResult);
73
+ // Update statuses
74
+ const result = new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, false);
86
75
  this.loading = false;
87
76
  this.fetched = true;
88
77
  this.present = true;
@@ -92,7 +81,7 @@ class NextGraphResource extends events_1.default {
92
81
  }
93
82
  catch (err) {
94
83
  if (err === "RepoNotFound") {
95
- const result = new NextGraphReadSuccess_1.NextGraphReadSuccess(this, false);
84
+ const result = new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, false);
96
85
  this.loading = false;
97
86
  this.fetched = true;
98
87
  this.present = false;
@@ -105,19 +94,22 @@ class NextGraphResource extends events_1.default {
105
94
  }
106
95
  async readIfUnfetched() {
107
96
  if (this.isFetched()) {
108
- return new NextGraphReadSuccess_1.NextGraphReadSuccess(this, true);
97
+ return new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, true);
109
98
  }
110
99
  return this.read();
111
100
  }
112
101
  async update(datasetChanges) {
113
102
  this.loading = true;
114
103
  this.emit("update");
104
+ // Optimistically apply updates
115
105
  this.context.dataset.bulk(datasetChanges);
116
106
  try {
117
- await nextgraph_1.default.sparql_update(this.context.nextgraph.sessionId, await (0, rdf_utils_1.changesToSparqlUpdate)(datasetChanges), this.uri);
107
+ // Perform Update with remote
108
+ await this.context.nextgraph.ng.sparql_update(this.context.nextgraph.sessionId, await (0, rdf_utils_1.changesToSparqlUpdate)(datasetChanges), this.uri);
118
109
  return new connected_1.UpdateSuccess(this);
119
110
  }
120
111
  catch (err) {
112
+ // Revert data on error
121
113
  this.context.dataset.bulk({
122
114
  added: datasetChanges.removed,
123
115
  removed: datasetChanges.added,
@@ -129,7 +121,7 @@ class NextGraphResource extends events_1.default {
129
121
  const rawTriples = JSON.parse(notificationString);
130
122
  const triples = (await Promise.all(rawTriples.map(async (rawTriple) => (0, ldo_1.parseRdf)(`${rawTriple}.`, { baseIRI: this.uri })))).reduce((agg, ldoDataset) => {
131
123
  ldoDataset.forEach((quad) => {
132
- agg.add(quad);
124
+ agg.add((0, rdf_utils_2.quad)(quad.subject, quad.predicate, quad.object, (0, rdf_utils_2.namedNode)(this.uri)));
133
125
  });
134
126
  return agg;
135
127
  }, (0, dataset_1.createDataset)());
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphResource.js","sourceRoot":"","sources":["../../../src/resources/NextGraphResource.ts"],"names":[],"mappings":";;;;;;AAKA,8CAAwE;AACxE,8CAKwB;AAExB,oDAAkC;AAElC,8CAA4E;AAG5E,8CAA+D;AAC/D,gFAA0E;AAC1E,gHAA0G;AAC1G,kCAAoC;AAEpC,0CAA6C;AAC7C,MAAa,iBACX,SAAS,gBAA+C;IAsBxD,YACE,GAAiB,EACjB,OAAqD;QAErD,KAAK,EAAE,CAAC;QAtBM,SAAI,GAAG,mBAA4B,CAAC;QACpC,YAAO,GAAG,KAAc,CAAC;QAIjC,YAAO,GAAY,KAAK,CAAC;QACzB,YAAO,GAAY,KAAK,CAAC;QACzB,YAAO,GAAwB,SAAS,CAAC;QAgB/C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,wBAAwB,GAAG,IAAI,wEAAiC,CACnE,IAAI,EACJ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAC9B,IAAI,CAAC,OAAO,CACb,CAAC;IACJ,CAAC;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ACF,MAAM,aAAa,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAChC,CAAC;YAEF,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CACxC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAC/C,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC,CAAC,CACH,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;gBACxB,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,wBAAwB,CAC5B,SAA+D;QAE/D,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAC,wBAAwB,CACjE,SAAS,CACV,CAAC;IACJ,CAAC;IAED,4BAA4B,CAAC,cAAsB;QACjD,OAAO,IAAI,CAAC,wBAAwB,CAAC,2BAA2B,CAC9D,cAAc,CACf,CAAC;IACJ,CAAC;IAED,+BAA+B;QAC7B,OAAO,IAAI,CAAC,wBAAwB,CAAC,+BAA+B,EAAE,CAAC;IACzE,CAAC;CACF;AArPD,8CAqPC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphReadSuccess.js","sourceRoot":"","sources":["../../../src/results/NextGraphReadSuccess.ts"],"names":[],"mappings":";;;AAAA,8CAA6C;AAG7C,MAAa,oBAAqB,SAAQ,uBAA8B;IAAxE;;QACE,SAAI,GAAG,sBAA+B,CAAC;IACzC,CAAC;CAAA;AAFD,oDAEC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationMessage.js","sourceRoot":"","sources":["../../../src/util/NextGraphNotificationMessage.ts"],"names":[],"mappings":""}
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNextGraphUri = void 0;
4
+ /**
5
+ * Checks if a provided string is a leaf URI
6
+ * @param uri - the string to check
7
+ * @returns true if the string is a leaf URI
8
+ */
4
9
  function isNextGraphUri(uri) {
5
10
  return uri.startsWith("did:ng");
6
11
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNextGraphUri.js","sourceRoot":"","sources":["../../../src/util/isNextGraphUri.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,SAAgB,cAAc,CAAC,GAAW;IACxC,OAAO,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC;AAFD,wCAEC"}
@@ -0,0 +1,34 @@
1
+ import { NextGraphResource } from "./resources/NextGraphResource.js";
2
+ import { isNextGraphUri } from "./util/isNextGraphUri.js";
3
+ export const nextGraphConnectedPlugin = {
4
+ name: "nextgraph",
5
+ getResource: function (uri, context) {
6
+ return new NextGraphResource(uri, context);
7
+ },
8
+ createResource: async function (context, options) {
9
+ const storeType = options?.storeType;
10
+ const storeRepo = options?.storeRepo ??
11
+ (storeType === "protected"
12
+ ? context.nextgraph.protectedStoreId
13
+ : storeType === "public"
14
+ ? context.nextgraph.publicStoreId
15
+ : storeType === "private"
16
+ ? context.nextgraph.privateStoreId
17
+ : undefined);
18
+ const primaryClass = options?.primaryClass ?? "data:graph";
19
+ const nuri = await context.nextgraph.ng.doc_create(context.nextgraph.sessionId, "Graph", primaryClass, "store", storeType, storeRepo);
20
+ const newResource = new NextGraphResource(nuri, context);
21
+ await newResource.read();
22
+ return newResource;
23
+ },
24
+ isUriValid: function (uri) {
25
+ return isNextGraphUri(uri);
26
+ },
27
+ initialContext: {
28
+ sessionId: undefined,
29
+ },
30
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31
+ // @ts-ignore "Types" only exists for the typing system
32
+ types: {},
33
+ };
34
+ //# sourceMappingURL=NextGraphConnectedPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphConnectedPlugin.js","sourceRoot":"","sources":["../../src/NextGraphConnectedPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAkC1D,MAAM,CAAC,MAAM,wBAAwB,GAA6B;IAChE,IAAI,EAAE,WAAW;IAEjB,WAAW,EAAE,UACX,GAAiB,EACjB,OAAqD;QAErD,OAAO,IAAI,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,cAAc,EAAE,KAAK,WACnB,OAAqD,EACrD,OAAwC;QAExC,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,CAAC;QACrC,MAAM,SAAS,GACb,OAAO,EAAE,SAAS;YAClB,CAAC,SAAS,KAAK,WAAW;gBACxB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,gBAAgB;gBACpC,CAAC,CAAC,SAAS,KAAK,QAAQ;oBACxB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa;oBACjC,CAAC,CAAC,SAAS,KAAK,SAAS;wBACzB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,cAAc;wBAClC,CAAC,CAAC,SAAS,CAAC,CAAC;QACjB,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,YAAY,CAAC;QAE3D,MAAM,IAAI,GAAiB,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,CAC9D,OAAO,CAAC,SAAS,CAAC,SAAS,EAC3B,OAAO,EACP,YAAY,EACZ,OAAO,EACP,SAAS,EACT,SAAS,CACV,CAAC;QACF,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACzD,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,UAAU,EAAE,UAAU,GAAW;QAC/B,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,cAAc,EAAE;QACd,SAAS,EAAE,SAAS;KACrB;IACD,6DAA6D;IAC7D,uDAAuD;IACvD,KAAK,EAAE,EAAE;CACV,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ConnectedLdoDataset } from "@ldo/connected";
2
+ import { nextGraphConnectedPlugin } from "./NextGraphConnectedPlugin.js";
3
+ import { createDatasetFactory } from "@ldo/dataset";
4
+ import { createTransactionDatasetFactory } from "@ldo/subscribable-dataset";
5
+ export function createNextGraphLdoDataset() {
6
+ const nextGraphLdoDataset = new ConnectedLdoDataset([nextGraphConnectedPlugin], createDatasetFactory(), createTransactionDatasetFactory());
7
+ return nextGraphLdoDataset;
8
+ }
9
+ //# sourceMappingURL=createNextGraphLdoDataset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNextGraphLdoDataset.js","sourceRoot":"","sources":["../../src/createNextGraphLdoDataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAE5E,MAAM,UAAU,yBAAyB;IACvC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CACjD,CAAC,wBAAwB,CAAC,EAC1B,oBAAoB,EAAE,EACtB,+BAA+B,EAAE,CAClC,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./types.js";
2
+ export * from "./NextGraphConnectedPlugin.js";
3
+ export * from "./resources/NextGraphResource.js";
4
+ export * from "./util/isNextGraphUri.js";
5
+ export * from "./results/NextGraphReadSuccess.js";
6
+ export * from "./createNextGraphLdoDataset.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,+BAA+B,CAAC;AAE9C,cAAc,kCAAkC,CAAC;AAEjD,cAAc,0BAA0B,CAAC;AAEzC,cAAc,mCAAmC,CAAC;AAElD,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=NextGraphNotificationMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationMessage.js","sourceRoot":"","sources":["../../../src/notifications/NextGraphNotificationMessage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { NotificationSubscription } from "@ldo/connected";
2
+ export class NextGraphNotificationSubscription extends NotificationSubscription {
3
+ async open() {
4
+ this.unsub = await this.context.nextgraph.ng.doc_subscribe(this.resource.uri, this.context.nextgraph.sessionId, this.onNotification.bind(this));
5
+ }
6
+ async close() {
7
+ this.unsub?.();
8
+ this.unsub = undefined;
9
+ }
10
+ }
11
+ //# sourceMappingURL=NextGraphNotificationSubscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationSubscription.js","sourceRoot":"","sources":["../../../src/notifications/NextGraphNotificationSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAI1D,MAAM,OAAO,iCAAkC,SAAQ,wBAGtD;IAGW,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,aAAa,CACxD,IAAI,CAAC,QAAQ,CAAC,GAAG,EACjB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAChC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/B,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,KAAK;QACnB,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,156 @@
1
+ import { UnexpectedResourceError, UpdateSuccess } from "@ldo/connected";
2
+ import { Unfetched, } from "@ldo/connected";
3
+ import EventEmitter from "events";
4
+ import { changesToSparqlUpdate } from "@ldo/rdf-utils";
5
+ import { namedNode, quad as createQuad } from "@ldo/rdf-utils";
6
+ import { NextGraphReadSuccess } from "../results/NextGraphReadSuccess.js";
7
+ import { NextGraphNotificationSubscription } from "../notifications/NextGraphNotificationSubscription.js";
8
+ import { parseRdf } from "@ldo/ldo";
9
+ import { createDataset } from "@ldo/dataset";
10
+ export class NextGraphResource extends EventEmitter {
11
+ constructor(uri, context) {
12
+ super();
13
+ this.type = "NextGraphResource";
14
+ this.isError = false;
15
+ this.fetched = false;
16
+ this.loading = false;
17
+ this.present = undefined;
18
+ this.uri = uri;
19
+ this.status = new Unfetched(this);
20
+ this.context = context;
21
+ this.notificationSubscription = new NextGraphNotificationSubscription(this, this.onNotification.bind(this), this.context);
22
+ }
23
+ isLoading() {
24
+ return this.loading;
25
+ }
26
+ isFetched() {
27
+ return this.fetched;
28
+ }
29
+ isUnfetched() {
30
+ return !this.fetched;
31
+ }
32
+ isDoingInitialFetch() {
33
+ return this.loading && !this.fetched;
34
+ }
35
+ isPresent() {
36
+ return this.present;
37
+ }
38
+ isAbsent() {
39
+ return !this.present;
40
+ }
41
+ isSubscribedToNotifications() {
42
+ return this.notificationSubscription.isSubscribedToNotifications();
43
+ }
44
+ handleThrownError(err) {
45
+ const error = UnexpectedResourceError.fromThrown(this, err);
46
+ this.loading = false;
47
+ this.status = error;
48
+ this.emit("update");
49
+ return error;
50
+ }
51
+ overwriteQuads(quads) {
52
+ const dataset = this.context.dataset;
53
+ const graphNode = namedNode(this.uri);
54
+ dataset.deleteMatches(undefined, undefined, undefined, graphNode);
55
+ dataset.addAll(quads.map((ngQuad) => {
56
+ return createQuad(ngQuad.subject, ngQuad.predicate, ngQuad.object, graphNode);
57
+ }));
58
+ }
59
+ async read() {
60
+ try {
61
+ this.loading = true;
62
+ this.emit("update");
63
+ // Fetch the data once using construct
64
+ const sparqlResult = await this.context.nextgraph.ng.sparql_query(this.context.nextgraph.sessionId, `CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <${this.uri}> { ?s ?p ?o } }`, undefined, this.uri);
65
+ // Update the dataset
66
+ this.overwriteQuads(sparqlResult);
67
+ // Update statuses
68
+ const result = new NextGraphReadSuccess(this, false);
69
+ this.loading = false;
70
+ this.fetched = true;
71
+ this.present = true;
72
+ this.status = result;
73
+ this.emit("update");
74
+ return result;
75
+ }
76
+ catch (err) {
77
+ if (err === "RepoNotFound") {
78
+ const result = new NextGraphReadSuccess(this, false);
79
+ this.loading = false;
80
+ this.fetched = true;
81
+ this.present = false;
82
+ this.status = result;
83
+ this.emit("update");
84
+ return result;
85
+ }
86
+ return this.handleThrownError(err);
87
+ }
88
+ }
89
+ async readIfUnfetched() {
90
+ if (this.isFetched()) {
91
+ return new NextGraphReadSuccess(this, true);
92
+ }
93
+ return this.read();
94
+ }
95
+ async update(datasetChanges) {
96
+ this.loading = true;
97
+ this.emit("update");
98
+ // Optimistically apply updates
99
+ this.context.dataset.bulk(datasetChanges);
100
+ try {
101
+ // Perform Update with remote
102
+ await this.context.nextgraph.ng.sparql_update(this.context.nextgraph.sessionId, await changesToSparqlUpdate(datasetChanges), this.uri);
103
+ return new UpdateSuccess(this);
104
+ }
105
+ catch (err) {
106
+ // Revert data on error
107
+ this.context.dataset.bulk({
108
+ added: datasetChanges.removed,
109
+ removed: datasetChanges.added,
110
+ });
111
+ return this.handleThrownError(err);
112
+ }
113
+ }
114
+ async notificationToQuads(notificationString) {
115
+ const rawTriples = JSON.parse(notificationString);
116
+ const triples = (await Promise.all(rawTriples.map(async (rawTriple) => parseRdf(`${rawTriple}.`, { baseIRI: this.uri })))).reduce((agg, ldoDataset) => {
117
+ ldoDataset.forEach((quad) => {
118
+ agg.add(createQuad(quad.subject, quad.predicate, quad.object, namedNode(this.uri)));
119
+ });
120
+ return agg;
121
+ }, createDataset());
122
+ return triples;
123
+ }
124
+ async onNotification(response) {
125
+ if (response.V0.State) {
126
+ if (!response.V0.State.graph) {
127
+ this.overwriteQuads([]);
128
+ return;
129
+ }
130
+ const json_str = new TextDecoder().decode(response.V0.State.graph.triples);
131
+ const triples = await this.notificationToQuads(json_str);
132
+ this.overwriteQuads(triples);
133
+ }
134
+ else if (response.V0.Patch?.graph) {
135
+ const insertsString = new TextDecoder().decode(response.V0.Patch.graph.inserts);
136
+ const removesString = new TextDecoder().decode(response.V0.Patch.graph.removes);
137
+ const [added, removed] = await Promise.all([insertsString, removesString].map(async (str) => {
138
+ return this.notificationToQuads(str);
139
+ }));
140
+ this.context.dataset.bulk({
141
+ added,
142
+ removed,
143
+ });
144
+ }
145
+ }
146
+ async subscribeToNotifications(callbacks) {
147
+ return await this.notificationSubscription.subscribeToNotifications(callbacks);
148
+ }
149
+ unsubscribeFromNotifications(subscriptionId) {
150
+ return this.notificationSubscription.unsubscribeFromNotification(subscriptionId);
151
+ }
152
+ unsubscribeFromAllNotifications() {
153
+ return this.notificationSubscription.unsubscribeFromAllNotifications();
154
+ }
155
+ }
156
+ //# sourceMappingURL=NextGraphResource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphResource.js","sourceRoot":"","sources":["../../../src/resources/NextGraphResource.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,SAAS,GAIV,MAAM,gBAAgB,CAAC;AAExB,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAuB,MAAM,gBAAgB,CAAC;AAG5E,OAAO,EAAE,SAAS,EAAE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AAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,wBAAwB,CAC5B,SAA+D;QAE/D,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAC,wBAAwB,CACjE,SAAS,CACV,CAAC;IACJ,CAAC;IAED,4BAA4B,CAAC,cAAsB;QACjD,OAAO,IAAI,CAAC,wBAAwB,CAAC,2BAA2B,CAC9D,cAAc,CACf,CAAC;IACJ,CAAC;IAED,+BAA+B;QAC7B,OAAO,IAAI,CAAC,wBAAwB,CAAC,+BAA+B,EAAE,CAAC;IACzE,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import { ReadSuccess } from "@ldo/connected";
2
+ export class NextGraphReadSuccess extends ReadSuccess {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.type = "nextGraphReadSuccess";
6
+ }
7
+ }
8
+ //# sourceMappingURL=NextGraphReadSuccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphReadSuccess.js","sourceRoot":"","sources":["../../../src/results/NextGraphReadSuccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,OAAO,oBAAqB,SAAQ,WAA8B;IAAxE;;QACE,SAAI,GAAG,sBAA+B,CAAC;IACzC,CAAC;CAAA"}