@ldo/connected-nextgraph 1.0.0-alpha.2 → 1.0.0-alpha.20
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/README.md +65 -3
- package/dist/{NextGraphConnectedPlugin.js → cjs/NextGraphConnectedPlugin.js} +9 -10
- package/dist/cjs/NextGraphConnectedPlugin.js.map +1 -0
- package/dist/{createNextGraphLdoDataset.js → cjs/createNextGraphLdoDataset.js} +2 -2
- package/dist/cjs/createNextGraphLdoDataset.js.map +1 -0
- package/dist/{index.js → cjs/index.js} +6 -5
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/notifications/NextGraphNotificationMessage.js.map +1 -0
- package/dist/cjs/notifications/NextGraphNotificationSubscription.js +15 -0
- package/dist/cjs/notifications/NextGraphNotificationSubscription.js.map +1 -0
- package/dist/{resources → cjs/resources}/NextGraphResource.js +43 -27
- package/dist/cjs/resources/NextGraphResource.js.map +1 -0
- package/dist/cjs/results/NextGraphReadSuccess.js.map +1 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util/NextGraphNotificationMessage.js.map +1 -0
- package/dist/{util → cjs/util}/isNextGraphUri.js +5 -0
- package/dist/cjs/util/isNextGraphUri.js.map +1 -0
- package/dist/esm/NextGraphConnectedPlugin.js +34 -0
- package/dist/esm/NextGraphConnectedPlugin.js.map +1 -0
- package/dist/esm/createNextGraphLdoDataset.js +9 -0
- package/dist/esm/createNextGraphLdoDataset.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/notifications/NextGraphNotificationMessage.js +2 -0
- package/dist/esm/notifications/NextGraphNotificationMessage.js.map +1 -0
- package/dist/esm/notifications/NextGraphNotificationSubscription.js +11 -0
- package/dist/esm/notifications/NextGraphNotificationSubscription.js.map +1 -0
- package/dist/esm/resources/NextGraphResource.js +157 -0
- package/dist/esm/resources/NextGraphResource.js.map +1 -0
- package/dist/esm/results/NextGraphReadSuccess.js +8 -0
- package/dist/esm/results/NextGraphReadSuccess.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util/NextGraphNotificationMessage.js +2 -0
- package/dist/esm/util/NextGraphNotificationMessage.js.map +1 -0
- package/dist/esm/util/isNextGraphUri.js +9 -0
- package/dist/esm/util/isNextGraphUri.js.map +1 -0
- package/dist/{NextGraphConnectedPlugin.d.ts → types/NextGraphConnectedPlugin.d.ts} +5 -2
- package/dist/types/NextGraphConnectedPlugin.d.ts.map +1 -0
- package/dist/types/createNextGraphLdoDataset.d.ts +3 -0
- package/dist/types/createNextGraphLdoDataset.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{notifications → types/notifications}/NextGraphNotificationMessage.d.ts +1 -0
- package/dist/types/notifications/NextGraphNotificationMessage.d.ts.map +1 -0
- package/dist/{notifications → types/notifications}/NextGraphNotificationSubscription.d.ts +3 -2
- package/dist/types/notifications/NextGraphNotificationSubscription.d.ts.map +1 -0
- package/dist/{resources → types/resources}/NextGraphResource.d.ts +14 -6
- package/dist/types/resources/NextGraphResource.d.ts.map +1 -0
- package/dist/{results → types/results}/NextGraphReadSuccess.d.ts +2 -1
- package/dist/types/results/NextGraphReadSuccess.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +4 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/{util → types/util}/NextGraphNotificationMessage.d.ts +1 -0
- package/dist/types/util/NextGraphNotificationMessage.d.ts.map +1 -0
- package/dist/types/util/isNextGraphUri.d.ts +8 -0
- package/dist/types/util/isNextGraphUri.d.ts.map +1 -0
- package/package.json +28 -15
- package/src/NextGraphConnectedPlugin.ts +10 -6
- package/src/createNextGraphLdoDataset.ts +1 -1
- package/src/index.ts +7 -5
- package/src/notifications/NextGraphNotificationSubscription.ts +3 -5
- package/src/resources/NextGraphResource.ts +26 -28
- package/src/results/NextGraphReadSuccess.ts +1 -1
- package/src/util/isNextGraphUri.ts +1 -1
- package/dist/NextGraphConnectedPlugin.js.map +0 -1
- package/dist/createNextGraphLdoDataset.d.ts +0 -2
- package/dist/createNextGraphLdoDataset.js.map +0 -1
- package/dist/createSolidLdoDataset.d.ts +0 -2
- package/dist/createSolidLdoDataset.js +0 -13
- package/dist/createSolidLdoDataset.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js.map +0 -1
- package/dist/notifications/NextGraphNotificationMessage.js.map +0 -1
- package/dist/notifications/NextGraphNotificationSubscription.js +0 -20
- package/dist/notifications/NextGraphNotificationSubscription.js.map +0 -1
- package/dist/resources/NextGraphResource.js.map +0 -1
- package/dist/results/NextGraphReadSuccess.js.map +0 -1
- package/dist/results/NoNextGraphStoreError.d.ts +0 -5
- package/dist/results/NoNextGraphStoreError.js +0 -12
- package/dist/results/NoNextGraphStoreError.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/util/NextGraphNotificationMessage.js.map +0 -1
- package/dist/util/isNextGraphUri.d.ts +0 -2
- package/dist/util/isNextGraphUri.js.map +0 -1
- /package/dist/{notifications → cjs/notifications}/NextGraphNotificationMessage.js +0 -0
- /package/dist/{results → cjs/results}/NextGraphReadSuccess.js +0 -0
- /package/dist/{types.js → cjs/types.js} +0 -0
- /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
|
|
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
|
|
8
|
-
const
|
|
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
|
|
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
|
|
26
|
-
const
|
|
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,
|
|
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
|
|
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([
|
|
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"}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -7,13 +30,13 @@ exports.NextGraphResource = void 0;
|
|
|
7
30
|
const connected_1 = require("@ldo/connected");
|
|
8
31
|
const connected_2 = require("@ldo/connected");
|
|
9
32
|
const events_1 = __importDefault(require("events"));
|
|
10
|
-
const nextgraph_1 = __importDefault(require("nextgraph"));
|
|
11
33
|
const rdf_utils_1 = require("@ldo/rdf-utils");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
34
|
+
const rdfdm = __importStar(require("@rdfjs/data-model"));
|
|
35
|
+
const NextGraphReadSuccess_js_1 = require("../results/NextGraphReadSuccess.js");
|
|
36
|
+
const NextGraphNotificationSubscription_js_1 = require("../notifications/NextGraphNotificationSubscription.js");
|
|
15
37
|
const ldo_1 = require("@ldo/ldo");
|
|
16
38
|
const dataset_1 = require("@ldo/dataset");
|
|
39
|
+
const { namedNode, quad: createQuad } = rdfdm;
|
|
17
40
|
class NextGraphResource extends events_1.default {
|
|
18
41
|
constructor(uri, context) {
|
|
19
42
|
super();
|
|
@@ -25,7 +48,7 @@ class NextGraphResource extends events_1.default {
|
|
|
25
48
|
this.uri = uri;
|
|
26
49
|
this.status = new connected_2.Unfetched(this);
|
|
27
50
|
this.context = context;
|
|
28
|
-
this.notificationSubscription = new
|
|
51
|
+
this.notificationSubscription = new NextGraphNotificationSubscription_js_1.NextGraphNotificationSubscription(this, this.onNotification.bind(this), this.context);
|
|
29
52
|
}
|
|
30
53
|
isLoading() {
|
|
31
54
|
return this.loading;
|
|
@@ -57,32 +80,22 @@ class NextGraphResource extends events_1.default {
|
|
|
57
80
|
}
|
|
58
81
|
overwriteQuads(quads) {
|
|
59
82
|
const dataset = this.context.dataset;
|
|
60
|
-
const graphNode =
|
|
83
|
+
const graphNode = namedNode(this.uri);
|
|
61
84
|
dataset.deleteMatches(undefined, undefined, undefined, graphNode);
|
|
62
85
|
dataset.addAll(quads.map((ngQuad) => {
|
|
63
|
-
return (
|
|
86
|
+
return createQuad(ngQuad.subject, ngQuad.predicate, ngQuad.object, graphNode);
|
|
64
87
|
}));
|
|
65
88
|
}
|
|
66
89
|
async read() {
|
|
67
90
|
try {
|
|
68
91
|
this.loading = true;
|
|
69
92
|
this.emit("update");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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);
|
|
93
|
+
// Fetch the data once using construct
|
|
94
|
+
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);
|
|
95
|
+
// Update the dataset
|
|
96
|
+
this.overwriteQuads(sparqlResult);
|
|
97
|
+
// Update statuses
|
|
98
|
+
const result = new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, false);
|
|
86
99
|
this.loading = false;
|
|
87
100
|
this.fetched = true;
|
|
88
101
|
this.present = true;
|
|
@@ -92,7 +105,7 @@ class NextGraphResource extends events_1.default {
|
|
|
92
105
|
}
|
|
93
106
|
catch (err) {
|
|
94
107
|
if (err === "RepoNotFound") {
|
|
95
|
-
const result = new
|
|
108
|
+
const result = new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, false);
|
|
96
109
|
this.loading = false;
|
|
97
110
|
this.fetched = true;
|
|
98
111
|
this.present = false;
|
|
@@ -105,19 +118,22 @@ class NextGraphResource extends events_1.default {
|
|
|
105
118
|
}
|
|
106
119
|
async readIfUnfetched() {
|
|
107
120
|
if (this.isFetched()) {
|
|
108
|
-
return new
|
|
121
|
+
return new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, true);
|
|
109
122
|
}
|
|
110
123
|
return this.read();
|
|
111
124
|
}
|
|
112
125
|
async update(datasetChanges) {
|
|
113
126
|
this.loading = true;
|
|
114
127
|
this.emit("update");
|
|
128
|
+
// Optimistically apply updates
|
|
115
129
|
this.context.dataset.bulk(datasetChanges);
|
|
116
130
|
try {
|
|
117
|
-
|
|
131
|
+
// Perform Update with remote
|
|
132
|
+
await this.context.nextgraph.ng.sparql_update(this.context.nextgraph.sessionId, await (0, rdf_utils_1.changesToSparqlUpdate)(datasetChanges), this.uri);
|
|
118
133
|
return new connected_1.UpdateSuccess(this);
|
|
119
134
|
}
|
|
120
135
|
catch (err) {
|
|
136
|
+
// Revert data on error
|
|
121
137
|
this.context.dataset.bulk({
|
|
122
138
|
added: datasetChanges.removed,
|
|
123
139
|
removed: datasetChanges.added,
|
|
@@ -129,7 +145,7 @@ class NextGraphResource extends events_1.default {
|
|
|
129
145
|
const rawTriples = JSON.parse(notificationString);
|
|
130
146
|
const triples = (await Promise.all(rawTriples.map(async (rawTriple) => (0, ldo_1.parseRdf)(`${rawTriple}.`, { baseIRI: this.uri })))).reduce((agg, ldoDataset) => {
|
|
131
147
|
ldoDataset.forEach((quad) => {
|
|
132
|
-
agg.add(quad);
|
|
148
|
+
agg.add(createQuad(quad.subject, quad.predicate, quad.object, namedNode(this.uri)));
|
|
133
149
|
});
|
|
134
150
|
return agg;
|
|
135
151
|
}, (0, dataset_1.createDataset)());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextGraphResource.js","sourceRoot":"","sources":["../../../src/resources/Next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,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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B,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 @@
|
|
|
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,157 @@
|
|
|
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 * as rdfdm from "@rdfjs/data-model";
|
|
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
|
+
const { namedNode, quad: createQuad } = rdfdm;
|
|
11
|
+
export class NextGraphResource extends EventEmitter {
|
|
12
|
+
constructor(uri, context) {
|
|
13
|
+
super();
|
|
14
|
+
this.type = "NextGraphResource";
|
|
15
|
+
this.isError = false;
|
|
16
|
+
this.fetched = false;
|
|
17
|
+
this.loading = false;
|
|
18
|
+
this.present = undefined;
|
|
19
|
+
this.uri = uri;
|
|
20
|
+
this.status = new Unfetched(this);
|
|
21
|
+
this.context = context;
|
|
22
|
+
this.notificationSubscription = new NextGraphNotificationSubscription(this, this.onNotification.bind(this), this.context);
|
|
23
|
+
}
|
|
24
|
+
isLoading() {
|
|
25
|
+
return this.loading;
|
|
26
|
+
}
|
|
27
|
+
isFetched() {
|
|
28
|
+
return this.fetched;
|
|
29
|
+
}
|
|
30
|
+
isUnfetched() {
|
|
31
|
+
return !this.fetched;
|
|
32
|
+
}
|
|
33
|
+
isDoingInitialFetch() {
|
|
34
|
+
return this.loading && !this.fetched;
|
|
35
|
+
}
|
|
36
|
+
isPresent() {
|
|
37
|
+
return this.present;
|
|
38
|
+
}
|
|
39
|
+
isAbsent() {
|
|
40
|
+
return !this.present;
|
|
41
|
+
}
|
|
42
|
+
isSubscribedToNotifications() {
|
|
43
|
+
return this.notificationSubscription.isSubscribedToNotifications();
|
|
44
|
+
}
|
|
45
|
+
handleThrownError(err) {
|
|
46
|
+
const error = UnexpectedResourceError.fromThrown(this, err);
|
|
47
|
+
this.loading = false;
|
|
48
|
+
this.status = error;
|
|
49
|
+
this.emit("update");
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
overwriteQuads(quads) {
|
|
53
|
+
const dataset = this.context.dataset;
|
|
54
|
+
const graphNode = namedNode(this.uri);
|
|
55
|
+
dataset.deleteMatches(undefined, undefined, undefined, graphNode);
|
|
56
|
+
dataset.addAll(quads.map((ngQuad) => {
|
|
57
|
+
return createQuad(ngQuad.subject, ngQuad.predicate, ngQuad.object, graphNode);
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async read() {
|
|
61
|
+
try {
|
|
62
|
+
this.loading = true;
|
|
63
|
+
this.emit("update");
|
|
64
|
+
// Fetch the data once using construct
|
|
65
|
+
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);
|
|
66
|
+
// Update the dataset
|
|
67
|
+
this.overwriteQuads(sparqlResult);
|
|
68
|
+
// Update statuses
|
|
69
|
+
const result = new NextGraphReadSuccess(this, false);
|
|
70
|
+
this.loading = false;
|
|
71
|
+
this.fetched = true;
|
|
72
|
+
this.present = true;
|
|
73
|
+
this.status = result;
|
|
74
|
+
this.emit("update");
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (err === "RepoNotFound") {
|
|
79
|
+
const result = new NextGraphReadSuccess(this, false);
|
|
80
|
+
this.loading = false;
|
|
81
|
+
this.fetched = true;
|
|
82
|
+
this.present = false;
|
|
83
|
+
this.status = result;
|
|
84
|
+
this.emit("update");
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
return this.handleThrownError(err);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async readIfUnfetched() {
|
|
91
|
+
if (this.isFetched()) {
|
|
92
|
+
return new NextGraphReadSuccess(this, true);
|
|
93
|
+
}
|
|
94
|
+
return this.read();
|
|
95
|
+
}
|
|
96
|
+
async update(datasetChanges) {
|
|
97
|
+
this.loading = true;
|
|
98
|
+
this.emit("update");
|
|
99
|
+
// Optimistically apply updates
|
|
100
|
+
this.context.dataset.bulk(datasetChanges);
|
|
101
|
+
try {
|
|
102
|
+
// Perform Update with remote
|
|
103
|
+
await this.context.nextgraph.ng.sparql_update(this.context.nextgraph.sessionId, await changesToSparqlUpdate(datasetChanges), this.uri);
|
|
104
|
+
return new UpdateSuccess(this);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// Revert data on error
|
|
108
|
+
this.context.dataset.bulk({
|
|
109
|
+
added: datasetChanges.removed,
|
|
110
|
+
removed: datasetChanges.added,
|
|
111
|
+
});
|
|
112
|
+
return this.handleThrownError(err);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async notificationToQuads(notificationString) {
|
|
116
|
+
const rawTriples = JSON.parse(notificationString);
|
|
117
|
+
const triples = (await Promise.all(rawTriples.map(async (rawTriple) => parseRdf(`${rawTriple}.`, { baseIRI: this.uri })))).reduce((agg, ldoDataset) => {
|
|
118
|
+
ldoDataset.forEach((quad) => {
|
|
119
|
+
agg.add(createQuad(quad.subject, quad.predicate, quad.object, namedNode(this.uri)));
|
|
120
|
+
});
|
|
121
|
+
return agg;
|
|
122
|
+
}, createDataset());
|
|
123
|
+
return triples;
|
|
124
|
+
}
|
|
125
|
+
async onNotification(response) {
|
|
126
|
+
if (response.V0.State) {
|
|
127
|
+
if (!response.V0.State.graph) {
|
|
128
|
+
this.overwriteQuads([]);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const json_str = new TextDecoder().decode(response.V0.State.graph.triples);
|
|
132
|
+
const triples = await this.notificationToQuads(json_str);
|
|
133
|
+
this.overwriteQuads(triples);
|
|
134
|
+
}
|
|
135
|
+
else if (response.V0.Patch?.graph) {
|
|
136
|
+
const insertsString = new TextDecoder().decode(response.V0.Patch.graph.inserts);
|
|
137
|
+
const removesString = new TextDecoder().decode(response.V0.Patch.graph.removes);
|
|
138
|
+
const [added, removed] = await Promise.all([insertsString, removesString].map(async (str) => {
|
|
139
|
+
return this.notificationToQuads(str);
|
|
140
|
+
}));
|
|
141
|
+
this.context.dataset.bulk({
|
|
142
|
+
added,
|
|
143
|
+
removed,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async subscribeToNotifications(callbacks) {
|
|
148
|
+
return await this.notificationSubscription.subscribeToNotifications(callbacks);
|
|
149
|
+
}
|
|
150
|
+
unsubscribeFromNotifications(subscriptionId) {
|
|
151
|
+
return this.notificationSubscription.unsubscribeFromNotification(subscriptionId);
|
|
152
|
+
}
|
|
153
|
+
unsubscribeFromAllNotifications() {
|
|
154
|
+
return this.notificationSubscription.unsubscribeFromAllNotifications();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=NextGraphResource.js.map
|