@ldo/connected-nextgraph 1.0.0-alpha.11
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/LICENSE.txt +21 -0
- package/README.md +186 -0
- package/dist/cjs/NextGraphConnectedPlugin.js +37 -0
- package/dist/cjs/NextGraphConnectedPlugin.js.map +1 -0
- package/dist/cjs/createNextGraphLdoDataset.js +13 -0
- package/dist/cjs/createNextGraphLdoDataset.js.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/notifications/NextGraphNotificationMessage.js +3 -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/cjs/resources/NextGraphResource.js +163 -0
- package/dist/cjs/resources/NextGraphResource.js.map +1 -0
- package/dist/cjs/results/NextGraphReadSuccess.js +12 -0
- package/dist/cjs/results/NextGraphReadSuccess.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util/NextGraphNotificationMessage.js +3 -0
- package/dist/cjs/util/NextGraphNotificationMessage.js.map +1 -0
- package/dist/cjs/util/isNextGraphUri.js +13 -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 +156 -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/types/NextGraphConnectedPlugin.d.ts +22 -0
- 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/types/notifications/NextGraphNotificationMessage.d.ts +16 -0
- package/dist/types/notifications/NextGraphNotificationMessage.d.ts.map +1 -0
- package/dist/types/notifications/NextGraphNotificationSubscription.d.ts +9 -0
- package/dist/types/notifications/NextGraphNotificationSubscription.d.ts.map +1 -0
- package/dist/types/resources/NextGraphResource.d.ts +48 -0
- package/dist/types/resources/NextGraphResource.d.ts.map +1 -0
- package/dist/types/results/NextGraphReadSuccess.d.ts +6 -0
- package/dist/types/results/NextGraphReadSuccess.d.ts.map +1 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/util/NextGraphNotificationMessage.d.ts +16 -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 +74 -0
- package/src/NextGraphConnectedPlugin.ts +87 -0
- package/src/createNextGraphLdoDataset.ts +13 -0
- package/src/index.ts +10 -0
- package/src/notifications/NextGraphNotificationMessage.ts +15 -0
- package/src/notifications/NextGraphNotificationSubscription.ts +23 -0
- package/src/resources/NextGraphResource.ts +271 -0
- package/src/results/NextGraphReadSuccess.ts +6 -0
- package/src/types.ts +8 -0
- package/src/util/NextGraphNotificationMessage.ts +15 -0
- package/src/util/isNextGraphUri.ts +10 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jackson Morgan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# `@ldo/connected-nextgraph`
|
|
2
|
+
|
|
3
|
+
The `@ldo/connected-nextgraph` library allows you to integrate [NextGraph](https://nextgraph.org) with the [LDO](https://ldo.js.org) ecosystem. It provides a `ConnectedLdoDataset` that manages RDF data across decentralized NextGraph resources with real-time synchronization and read/write capabilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
First, install the required libraries:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
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
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage:
|
|
23
|
+
|
|
24
|
+
### 1. Setup: Create a ConnectedLdoDataset
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { createNextGraphLdoDataset } from "@ldo/connected-nextgraph";
|
|
28
|
+
|
|
29
|
+
// Create the dataset
|
|
30
|
+
const ldoDataset = createNextGraphLdoDataset();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Connect to a NextGraph Wallet Session
|
|
34
|
+
|
|
35
|
+
Before you can create or access resources, you need an active session:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import ng from "nextgraph" // or `import ng from "nextgraphweb"` for the browser
|
|
39
|
+
|
|
40
|
+
// Open your nextgraph wallet
|
|
41
|
+
const openedWallet = await ng.wallet_open_with_mnemonic_words(
|
|
42
|
+
walletBinary,
|
|
43
|
+
mnemonic,
|
|
44
|
+
[1, 2, 3, 4]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Start a session
|
|
48
|
+
const session = await ng.session_in_memory_start(
|
|
49
|
+
openedWallet.V0.wallet_id,
|
|
50
|
+
openedWallet.V0.personal_site
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### 3. Link Your Dataset to the NextGraph Session
|
|
57
|
+
```ts
|
|
58
|
+
ldoDataset.setContext("nextgraph", {
|
|
59
|
+
ng,
|
|
60
|
+
sessionId: session.session_id
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. Create a Resource
|
|
65
|
+
|
|
66
|
+
To create a new resource in your store:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const resource = await ldoDataset.createResource("nextgraph");
|
|
70
|
+
if (!resource.isError) {
|
|
71
|
+
console.log("Created resource:", resource.uri);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 5. Read and Monitor a Resource**
|
|
76
|
+
|
|
77
|
+
#### Read Existing Resource
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const resource = ldoDataset.getResource(existingUri);
|
|
81
|
+
const readResult = await resource.read();
|
|
82
|
+
|
|
83
|
+
if (!readResult.isError) {
|
|
84
|
+
console.log("Resource loaded!", readResult.type);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Read Only If Unfetched
|
|
89
|
+
|
|
90
|
+
Avoid redundant fetches:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
const readResult = await resource.readIfUnfetched();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Subscribe to Notifications
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const unsubscribeId = await resource.subscribeToNotifications();
|
|
100
|
+
await resource.unsubscribeFromNotification(unsubscribeId);
|
|
101
|
+
await resource.unsubscribeFromAllNotifications();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### 6. Write Data to a Resource
|
|
107
|
+
|
|
108
|
+
You can write RDF data to a resource using `update()`:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { parseRdf } from "@ldo/ldo";
|
|
112
|
+
|
|
113
|
+
const ttlData = `
|
|
114
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
|
115
|
+
<#spiderman> a foaf:Person ; foaf:name "Spiderman" .
|
|
116
|
+
`;
|
|
117
|
+
|
|
118
|
+
const triples = await parseRdf(ttlData);
|
|
119
|
+
|
|
120
|
+
await resource.update({
|
|
121
|
+
added: triples,
|
|
122
|
+
removed: undefined
|
|
123
|
+
});
|
|
124
|
+
```
|
|
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
|
+
|
|
179
|
+
## Sponsorship
|
|
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/).
|
|
181
|
+
|
|
182
|
+
[<img src="https://nlnet.nl/logo/banner.png" alt="nlnet foundation logo" width="300" />](https://nlnet.nl/)
|
|
183
|
+
[<img src="https://nlnet.nl/image/logos/NGI0Entrust_tag.svg" alt="NGI Zero Entrust Logo" width="300" />](https://nlnet.nl/)
|
|
184
|
+
|
|
185
|
+
## Liscense
|
|
186
|
+
MIT
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextGraphConnectedPlugin = void 0;
|
|
4
|
+
const NextGraphResource_js_1 = require("./resources/NextGraphResource.js");
|
|
5
|
+
const isNextGraphUri_js_1 = require("./util/isNextGraphUri.js");
|
|
6
|
+
exports.nextGraphConnectedPlugin = {
|
|
7
|
+
name: "nextgraph",
|
|
8
|
+
getResource: function (uri, context) {
|
|
9
|
+
return new NextGraphResource_js_1.NextGraphResource(uri, context);
|
|
10
|
+
},
|
|
11
|
+
createResource: async function (context, options) {
|
|
12
|
+
const storeType = options?.storeType;
|
|
13
|
+
const storeRepo = options?.storeRepo ??
|
|
14
|
+
(storeType === "protected"
|
|
15
|
+
? context.nextgraph.protectedStoreId
|
|
16
|
+
: storeType === "public"
|
|
17
|
+
? context.nextgraph.publicStoreId
|
|
18
|
+
: storeType === "private"
|
|
19
|
+
? context.nextgraph.privateStoreId
|
|
20
|
+
: undefined);
|
|
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);
|
|
24
|
+
await newResource.read();
|
|
25
|
+
return newResource;
|
|
26
|
+
},
|
|
27
|
+
isUriValid: function (uri) {
|
|
28
|
+
return (0, isNextGraphUri_js_1.isNextGraphUri)(uri);
|
|
29
|
+
},
|
|
30
|
+
initialContext: {
|
|
31
|
+
sessionId: undefined,
|
|
32
|
+
},
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
34
|
+
// @ts-ignore "Types" only exists for the typing system
|
|
35
|
+
types: {},
|
|
36
|
+
};
|
|
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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNextGraphLdoDataset = void 0;
|
|
4
|
+
const connected_1 = require("@ldo/connected");
|
|
5
|
+
const NextGraphConnectedPlugin_js_1 = require("./NextGraphConnectedPlugin.js");
|
|
6
|
+
const dataset_1 = require("@ldo/dataset");
|
|
7
|
+
const subscribable_dataset_1 = require("@ldo/subscribable-dataset");
|
|
8
|
+
function createNextGraphLdoDataset() {
|
|
9
|
+
const nextGraphLdoDataset = new connected_1.ConnectedLdoDataset([NextGraphConnectedPlugin_js_1.nextGraphConnectedPlugin], (0, dataset_1.createDatasetFactory)(), (0, subscribable_dataset_1.createTransactionDatasetFactory)());
|
|
10
|
+
return nextGraphLdoDataset;
|
|
11
|
+
}
|
|
12
|
+
exports.createNextGraphLdoDataset = createNextGraphLdoDataset;
|
|
13
|
+
//# sourceMappingURL=createNextGraphLdoDataset.js.map
|
|
@@ -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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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);
|
|
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"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NextGraphResource = void 0;
|
|
7
|
+
const connected_1 = require("@ldo/connected");
|
|
8
|
+
const connected_2 = require("@ldo/connected");
|
|
9
|
+
const events_1 = __importDefault(require("events"));
|
|
10
|
+
const rdf_utils_1 = require("@ldo/rdf-utils");
|
|
11
|
+
const data_model_1 = require("@rdfjs/data-model");
|
|
12
|
+
const NextGraphReadSuccess_js_1 = require("../results/NextGraphReadSuccess.js");
|
|
13
|
+
const NextGraphNotificationSubscription_js_1 = require("../notifications/NextGraphNotificationSubscription.js");
|
|
14
|
+
const ldo_1 = require("@ldo/ldo");
|
|
15
|
+
const dataset_1 = require("@ldo/dataset");
|
|
16
|
+
class NextGraphResource extends events_1.default {
|
|
17
|
+
constructor(uri, context) {
|
|
18
|
+
super();
|
|
19
|
+
this.type = "NextGraphResource";
|
|
20
|
+
this.isError = false;
|
|
21
|
+
this.fetched = false;
|
|
22
|
+
this.loading = false;
|
|
23
|
+
this.present = undefined;
|
|
24
|
+
this.uri = uri;
|
|
25
|
+
this.status = new connected_2.Unfetched(this);
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.notificationSubscription = new NextGraphNotificationSubscription_js_1.NextGraphNotificationSubscription(this, this.onNotification.bind(this), this.context);
|
|
28
|
+
}
|
|
29
|
+
isLoading() {
|
|
30
|
+
return this.loading;
|
|
31
|
+
}
|
|
32
|
+
isFetched() {
|
|
33
|
+
return this.fetched;
|
|
34
|
+
}
|
|
35
|
+
isUnfetched() {
|
|
36
|
+
return !this.fetched;
|
|
37
|
+
}
|
|
38
|
+
isDoingInitialFetch() {
|
|
39
|
+
return this.loading && !this.fetched;
|
|
40
|
+
}
|
|
41
|
+
isPresent() {
|
|
42
|
+
return this.present;
|
|
43
|
+
}
|
|
44
|
+
isAbsent() {
|
|
45
|
+
return !this.present;
|
|
46
|
+
}
|
|
47
|
+
isSubscribedToNotifications() {
|
|
48
|
+
return this.notificationSubscription.isSubscribedToNotifications();
|
|
49
|
+
}
|
|
50
|
+
handleThrownError(err) {
|
|
51
|
+
const error = connected_1.UnexpectedResourceError.fromThrown(this, err);
|
|
52
|
+
this.loading = false;
|
|
53
|
+
this.status = error;
|
|
54
|
+
this.emit("update");
|
|
55
|
+
return error;
|
|
56
|
+
}
|
|
57
|
+
overwriteQuads(quads) {
|
|
58
|
+
const dataset = this.context.dataset;
|
|
59
|
+
const graphNode = (0, data_model_1.namedNode)(this.uri);
|
|
60
|
+
dataset.deleteMatches(undefined, undefined, undefined, graphNode);
|
|
61
|
+
dataset.addAll(quads.map((ngQuad) => {
|
|
62
|
+
return (0, data_model_1.quad)(ngQuad.subject, ngQuad.predicate, ngQuad.object, graphNode);
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
async read() {
|
|
66
|
+
try {
|
|
67
|
+
this.loading = true;
|
|
68
|
+
this.emit("update");
|
|
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);
|
|
75
|
+
this.loading = false;
|
|
76
|
+
this.fetched = true;
|
|
77
|
+
this.present = true;
|
|
78
|
+
this.status = result;
|
|
79
|
+
this.emit("update");
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (err === "RepoNotFound") {
|
|
84
|
+
const result = new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, false);
|
|
85
|
+
this.loading = false;
|
|
86
|
+
this.fetched = true;
|
|
87
|
+
this.present = false;
|
|
88
|
+
this.status = result;
|
|
89
|
+
this.emit("update");
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
return this.handleThrownError(err);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async readIfUnfetched() {
|
|
96
|
+
if (this.isFetched()) {
|
|
97
|
+
return new NextGraphReadSuccess_js_1.NextGraphReadSuccess(this, true);
|
|
98
|
+
}
|
|
99
|
+
return this.read();
|
|
100
|
+
}
|
|
101
|
+
async update(datasetChanges) {
|
|
102
|
+
this.loading = true;
|
|
103
|
+
this.emit("update");
|
|
104
|
+
// Optimistically apply updates
|
|
105
|
+
this.context.dataset.bulk(datasetChanges);
|
|
106
|
+
try {
|
|
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);
|
|
109
|
+
return new connected_1.UpdateSuccess(this);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
// Revert data on error
|
|
113
|
+
this.context.dataset.bulk({
|
|
114
|
+
added: datasetChanges.removed,
|
|
115
|
+
removed: datasetChanges.added,
|
|
116
|
+
});
|
|
117
|
+
return this.handleThrownError(err);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async notificationToQuads(notificationString) {
|
|
121
|
+
const rawTriples = JSON.parse(notificationString);
|
|
122
|
+
const triples = (await Promise.all(rawTriples.map(async (rawTriple) => (0, ldo_1.parseRdf)(`${rawTriple}.`, { baseIRI: this.uri })))).reduce((agg, ldoDataset) => {
|
|
123
|
+
ldoDataset.forEach((quad) => {
|
|
124
|
+
agg.add((0, data_model_1.quad)(quad.subject, quad.predicate, quad.object, (0, data_model_1.namedNode)(this.uri)));
|
|
125
|
+
});
|
|
126
|
+
return agg;
|
|
127
|
+
}, (0, dataset_1.createDataset)());
|
|
128
|
+
return triples;
|
|
129
|
+
}
|
|
130
|
+
async onNotification(response) {
|
|
131
|
+
if (response.V0.State) {
|
|
132
|
+
if (!response.V0.State.graph) {
|
|
133
|
+
this.overwriteQuads([]);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const json_str = new TextDecoder().decode(response.V0.State.graph.triples);
|
|
137
|
+
const triples = await this.notificationToQuads(json_str);
|
|
138
|
+
this.overwriteQuads(triples);
|
|
139
|
+
}
|
|
140
|
+
else if (response.V0.Patch?.graph) {
|
|
141
|
+
const insertsString = new TextDecoder().decode(response.V0.Patch.graph.inserts);
|
|
142
|
+
const removesString = new TextDecoder().decode(response.V0.Patch.graph.removes);
|
|
143
|
+
const [added, removed] = await Promise.all([insertsString, removesString].map(async (str) => {
|
|
144
|
+
return this.notificationToQuads(str);
|
|
145
|
+
}));
|
|
146
|
+
this.context.dataset.bulk({
|
|
147
|
+
added,
|
|
148
|
+
removed,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async subscribeToNotifications(callbacks) {
|
|
153
|
+
return await this.notificationSubscription.subscribeToNotifications(callbacks);
|
|
154
|
+
}
|
|
155
|
+
unsubscribeFromNotifications(subscriptionId) {
|
|
156
|
+
return this.notificationSubscription.unsubscribeFromNotification(subscriptionId);
|
|
157
|
+
}
|
|
158
|
+
unsubscribeFromAllNotifications() {
|
|
159
|
+
return this.notificationSubscription.unsubscribeFromAllNotifications();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.NextGraphResource = NextGraphResource;
|
|
163
|
+
//# sourceMappingURL=NextGraphResource.js.map
|
|
@@ -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,kDAAkE;AAClE,gFAA0E;AAC1E,gHAA0G;AAC1G,kCAAoC;AAEpC,0CAA6C;AAE7C,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;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,WAAW;QACT,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,m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,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,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextGraphReadSuccess = void 0;
|
|
4
|
+
const connected_1 = require("@ldo/connected");
|
|
5
|
+
class NextGraphReadSuccess extends connected_1.ReadSuccess {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.type = "nextGraphReadSuccess";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.NextGraphReadSuccess = NextGraphReadSuccess;
|
|
12
|
+
//# sourceMappingURL=NextGraphReadSuccess.js.map
|
|
@@ -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":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
9
|
+
function isNextGraphUri(uri) {
|
|
10
|
+
return uri.startsWith("did:ng");
|
|
11
|
+
}
|
|
12
|
+
exports.isNextGraphUri = isNextGraphUri;
|
|
13
|
+
//# sourceMappingURL=isNextGraphUri.js.map
|
|
@@ -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 @@
|
|
|
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"}
|