@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.
Files changed (73) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +186 -0
  3. package/dist/cjs/NextGraphConnectedPlugin.js +37 -0
  4. package/dist/cjs/NextGraphConnectedPlugin.js.map +1 -0
  5. package/dist/cjs/createNextGraphLdoDataset.js +13 -0
  6. package/dist/cjs/createNextGraphLdoDataset.js.map +1 -0
  7. package/dist/cjs/index.js +23 -0
  8. package/dist/cjs/index.js.map +1 -0
  9. package/dist/cjs/notifications/NextGraphNotificationMessage.js +3 -0
  10. package/dist/cjs/notifications/NextGraphNotificationMessage.js.map +1 -0
  11. package/dist/cjs/notifications/NextGraphNotificationSubscription.js +15 -0
  12. package/dist/cjs/notifications/NextGraphNotificationSubscription.js.map +1 -0
  13. package/dist/cjs/resources/NextGraphResource.js +163 -0
  14. package/dist/cjs/resources/NextGraphResource.js.map +1 -0
  15. package/dist/cjs/results/NextGraphReadSuccess.js +12 -0
  16. package/dist/cjs/results/NextGraphReadSuccess.js.map +1 -0
  17. package/dist/cjs/types.js +3 -0
  18. package/dist/cjs/types.js.map +1 -0
  19. package/dist/cjs/util/NextGraphNotificationMessage.js +3 -0
  20. package/dist/cjs/util/NextGraphNotificationMessage.js.map +1 -0
  21. package/dist/cjs/util/isNextGraphUri.js +13 -0
  22. package/dist/cjs/util/isNextGraphUri.js.map +1 -0
  23. package/dist/esm/NextGraphConnectedPlugin.js +34 -0
  24. package/dist/esm/NextGraphConnectedPlugin.js.map +1 -0
  25. package/dist/esm/createNextGraphLdoDataset.js +9 -0
  26. package/dist/esm/createNextGraphLdoDataset.js.map +1 -0
  27. package/dist/esm/index.js +7 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/notifications/NextGraphNotificationMessage.js +2 -0
  30. package/dist/esm/notifications/NextGraphNotificationMessage.js.map +1 -0
  31. package/dist/esm/notifications/NextGraphNotificationSubscription.js +11 -0
  32. package/dist/esm/notifications/NextGraphNotificationSubscription.js.map +1 -0
  33. package/dist/esm/resources/NextGraphResource.js +156 -0
  34. package/dist/esm/resources/NextGraphResource.js.map +1 -0
  35. package/dist/esm/results/NextGraphReadSuccess.js +8 -0
  36. package/dist/esm/results/NextGraphReadSuccess.js.map +1 -0
  37. package/dist/esm/types.js +2 -0
  38. package/dist/esm/types.js.map +1 -0
  39. package/dist/esm/util/NextGraphNotificationMessage.js +2 -0
  40. package/dist/esm/util/NextGraphNotificationMessage.js.map +1 -0
  41. package/dist/esm/util/isNextGraphUri.js +9 -0
  42. package/dist/esm/util/isNextGraphUri.js.map +1 -0
  43. package/dist/types/NextGraphConnectedPlugin.d.ts +22 -0
  44. package/dist/types/NextGraphConnectedPlugin.d.ts.map +1 -0
  45. package/dist/types/createNextGraphLdoDataset.d.ts +3 -0
  46. package/dist/types/createNextGraphLdoDataset.d.ts.map +1 -0
  47. package/dist/types/index.d.ts +7 -0
  48. package/dist/types/index.d.ts.map +1 -0
  49. package/dist/types/notifications/NextGraphNotificationMessage.d.ts +16 -0
  50. package/dist/types/notifications/NextGraphNotificationMessage.d.ts.map +1 -0
  51. package/dist/types/notifications/NextGraphNotificationSubscription.d.ts +9 -0
  52. package/dist/types/notifications/NextGraphNotificationSubscription.d.ts.map +1 -0
  53. package/dist/types/resources/NextGraphResource.d.ts +48 -0
  54. package/dist/types/resources/NextGraphResource.d.ts.map +1 -0
  55. package/dist/types/results/NextGraphReadSuccess.d.ts +6 -0
  56. package/dist/types/results/NextGraphReadSuccess.d.ts.map +1 -0
  57. package/dist/types/types.d.ts +6 -0
  58. package/dist/types/types.d.ts.map +1 -0
  59. package/dist/types/util/NextGraphNotificationMessage.d.ts +16 -0
  60. package/dist/types/util/NextGraphNotificationMessage.d.ts.map +1 -0
  61. package/dist/types/util/isNextGraphUri.d.ts +8 -0
  62. package/dist/types/util/isNextGraphUri.d.ts.map +1 -0
  63. package/package.json +74 -0
  64. package/src/NextGraphConnectedPlugin.ts +87 -0
  65. package/src/createNextGraphLdoDataset.ts +13 -0
  66. package/src/index.ts +10 -0
  67. package/src/notifications/NextGraphNotificationMessage.ts +15 -0
  68. package/src/notifications/NextGraphNotificationSubscription.ts +23 -0
  69. package/src/resources/NextGraphResource.ts +271 -0
  70. package/src/results/NextGraphReadSuccess.ts +6 -0
  71. package/src/types.ts +8 -0
  72. package/src/util/NextGraphNotificationMessage.ts +15 -0
  73. package/src/util/isNextGraphUri.ts +10 -0
@@ -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 "@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
+ 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,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AAI,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"}
@@ -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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=NextGraphNotificationMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationMessage.js","sourceRoot":"","sources":["../../../src/util/NextGraphNotificationMessage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Checks if a provided string is a leaf URI
3
+ * @param uri - the string to check
4
+ * @returns true if the string is a leaf URI
5
+ */
6
+ export function isNextGraphUri(uri) {
7
+ return uri.startsWith("did:ng");
8
+ }
9
+ //# sourceMappingURL=isNextGraphUri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNextGraphUri.js","sourceRoot":"","sources":["../../../src/util/isNextGraphUri.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { ConnectedContext, ConnectedPlugin } from "@ldo/connected";
2
+ import type { NextGraphUri } from "./types.js";
3
+ import { NextGraphResource } from "./resources/NextGraphResource.js";
4
+ export interface NextGraphConnectedContext {
5
+ ng?: any;
6
+ sessionId?: string;
7
+ protectedStoreId?: string;
8
+ privateStoreId?: string;
9
+ publicStoreId?: string;
10
+ }
11
+ export interface NextGraphCreateResourceOptions {
12
+ storeType?: "public" | "protected" | "private" | "group" | "dialog";
13
+ storeRepo?: string;
14
+ primaryClass?: string;
15
+ }
16
+ export interface NextGraphConnectedPlugin extends ConnectedPlugin<"nextgraph", NextGraphUri, NextGraphResource, NextGraphConnectedContext, NextGraphCreateResourceOptions> {
17
+ name: "nextgraph";
18
+ getResource: (uri: NextGraphUri, context: ConnectedContext<this[]>) => NextGraphResource;
19
+ createResource(context: ConnectedContext<this[]>): Promise<NextGraphResource>;
20
+ }
21
+ export declare const nextGraphConnectedPlugin: NextGraphConnectedPlugin;
22
+ //# sourceMappingURL=NextGraphConnectedPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphConnectedPlugin.d.ts","sourceRoot":"","sources":["../../src/NextGraphConnectedPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGrE,MAAM,WAAW,yBAAyB;IAGxC,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,8BAA8B;IAC7C,SAAS,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,wBACf,SAAQ,eAAe,CACrB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,CAC/B;IACD,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,EAAE,CACX,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,KAC9B,iBAAiB,CAAC;IACvB,cAAc,CAAC,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/E;AAED,eAAO,MAAM,wBAAwB,EAAE,wBAiDtC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ConnectedLdoDataset } from "@ldo/connected";
2
+ export declare function createNextGraphLdoDataset(): ConnectedLdoDataset<import("./NextGraphConnectedPlugin.js").NextGraphConnectedPlugin[]>;
3
+ //# sourceMappingURL=createNextGraphLdoDataset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNextGraphLdoDataset.d.ts","sourceRoot":"","sources":["../../src/createNextGraphLdoDataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAKrD,wBAAgB,yBAAyB,4FAOxC"}
@@ -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.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","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,16 @@
1
+ export interface NextGraphNotificationMessage {
2
+ V0: {
3
+ State?: {
4
+ graph: {
5
+ triples: AllowSharedBufferSource;
6
+ };
7
+ };
8
+ Patch?: {
9
+ graph: {
10
+ inserts: AllowSharedBufferSource;
11
+ removes: AllowSharedBufferSource;
12
+ };
13
+ };
14
+ };
15
+ }
16
+ //# sourceMappingURL=NextGraphNotificationMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationMessage.d.ts","sourceRoot":"","sources":["../../../src/notifications/NextGraphNotificationMessage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,4BAA4B;IAC3C,EAAE,EAAE;QACF,KAAK,CAAC,EAAE;YACN,KAAK,EAAE;gBACL,OAAO,EAAE,uBAAuB,CAAC;aAClC,CAAC;SACH,CAAC;QACF,KAAK,CAAC,EAAE;YACN,KAAK,EAAE;gBACL,OAAO,EAAE,uBAAuB,CAAC;gBACjC,OAAO,EAAE,uBAAuB,CAAC;aAClC,CAAC;SACH,CAAC;KACH,CAAC;CACH"}
@@ -0,0 +1,9 @@
1
+ import { NotificationSubscription } from "@ldo/connected";
2
+ import type { NextGraphConnectedPlugin } from "../NextGraphConnectedPlugin.js";
3
+ import type { NextGraphNotificationMessage } from "./NextGraphNotificationMessage.js";
4
+ export declare class NextGraphNotificationSubscription extends NotificationSubscription<NextGraphConnectedPlugin, NextGraphNotificationMessage> {
5
+ private unsub;
6
+ protected open(): Promise<void>;
7
+ protected close(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=NextGraphNotificationSubscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationSubscription.d.ts","sourceRoot":"","sources":["../../../src/notifications/NextGraphNotificationSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEtF,qBAAa,iCAAkC,SAAQ,wBAAwB,CAC7E,wBAAwB,EACxB,4BAA4B,CAC7B;IACC,OAAO,CAAC,KAAK,CAA2B;cAExB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;cAQrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAIvC"}
@@ -0,0 +1,48 @@
1
+ import type { ConnectedContext, NotificationSubscription, SubscriptionCallbacks } from "@ldo/connected";
2
+ import { UnexpectedResourceError, UpdateSuccess } from "@ldo/connected";
3
+ import { type ConnectedResult, type Resource } from "@ldo/connected";
4
+ import type { NextGraphUri } from "../types.js";
5
+ import type { NextGraphConnectedPlugin } from "../NextGraphConnectedPlugin.js";
6
+ import { type DatasetChanges } from "@ldo/rdf-utils";
7
+ import type { NextGraphNotificationMessage } from "../notifications/NextGraphNotificationMessage.js";
8
+ import type { Quad } from "@rdfjs/types";
9
+ import { NextGraphReadSuccess } from "../results/NextGraphReadSuccess.js";
10
+ declare const NextGraphResource_base: new () => import("typed-emitter").default<{
11
+ update: () => void;
12
+ notification: () => void;
13
+ }>;
14
+ export declare class NextGraphResource extends NextGraphResource_base implements Resource<NextGraphUri> {
15
+ readonly uri: NextGraphUri;
16
+ readonly type: "NextGraphResource";
17
+ readonly isError: false;
18
+ status: ConnectedResult;
19
+ protected context: ConnectedContext<NextGraphConnectedPlugin[]>;
20
+ private fetched;
21
+ private loading;
22
+ private present;
23
+ /**
24
+ * @internal
25
+ * Handles notification subscriptions
26
+ */
27
+ protected notificationSubscription: NotificationSubscription<NextGraphConnectedPlugin, NextGraphNotificationMessage>;
28
+ constructor(uri: NextGraphUri, context: ConnectedContext<NextGraphConnectedPlugin[]>);
29
+ isLoading(): boolean;
30
+ isFetched(): boolean;
31
+ isUnfetched(): boolean;
32
+ isDoingInitialFetch(): boolean;
33
+ isPresent(): boolean | undefined;
34
+ isAbsent(): boolean | undefined;
35
+ isSubscribedToNotifications(): boolean;
36
+ private handleThrownError;
37
+ private overwriteQuads;
38
+ read(): Promise<NextGraphReadSuccess | UnexpectedResourceError<NextGraphResource>>;
39
+ readIfUnfetched(): Promise<NextGraphReadSuccess | UnexpectedResourceError<NextGraphResource>>;
40
+ update(datasetChanges: DatasetChanges<Quad>): Promise<UpdateSuccess<NextGraphResource> | UnexpectedResourceError<NextGraphResource>>;
41
+ private notificationToQuads;
42
+ protected onNotification(response: NextGraphNotificationMessage): Promise<void>;
43
+ subscribeToNotifications(callbacks?: SubscriptionCallbacks<NextGraphNotificationMessage>): Promise<string>;
44
+ unsubscribeFromNotifications(subscriptionId: string): Promise<void>;
45
+ unsubscribeFromAllNotifications(): Promise<void>;
46
+ }
47
+ export {};
48
+ //# sourceMappingURL=NextGraphResource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphResource.d.ts","sourceRoot":"","sources":["../../../src/resources/NextGraphResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAA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AI,OAAO,GAAG,SAAS;IAI/B,2BAA2B,IAAI,OAAO;IAItC,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,cAAc;IAgBhB,IAAI,IAAI,OAAO,CACnB,oBAAoB,GAAG,uBAAuB,CAAC,iBAAiB,CAAC,CAClE;IAqCK,eAAe,IAAI,OAAO,CAC9B,oBAAoB,GAAG,uBAAuB,CAAC,iBAAiB,CAAC,CAClE;IAOK,MAAM,CACV,cAAc,EAAE,cAAc,CAAC,IAAI,CAAC,GACnC,OAAO,CACN,aAAa,CAAC,iBAAiB,CAAC,GAChC,uBAAuB,CAAC,iBAAiB,CAAC,CAC7C;YAyBa,mBAAmB;cA0BjB,cAAc,CAAC,QAAQ,EAAE,4BAA4B;IAgC/D,wBAAwB,CAC5B,SAAS,CAAC,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,GAC9D,OAAO,CAAC,MAAM,CAAC;IAMlB,4BAA4B,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnE,+BAA+B,IAAI,OAAO,CAAC,IAAI,CAAC;CAGjD"}
@@ -0,0 +1,6 @@
1
+ import { ReadSuccess } from "@ldo/connected";
2
+ import type { NextGraphResource } from "../resources/NextGraphResource.js";
3
+ export declare class NextGraphReadSuccess extends ReadSuccess<NextGraphResource> {
4
+ type: "nextGraphReadSuccess";
5
+ }
6
+ //# sourceMappingURL=NextGraphReadSuccess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphReadSuccess.d.ts","sourceRoot":"","sources":["../../../src/results/NextGraphReadSuccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,qBAAa,oBAAqB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;IACtE,IAAI,yBAAmC;CACxC"}
@@ -0,0 +1,6 @@
1
+ export type NextGraphUriPrefix = `did:ng`;
2
+ /**
3
+ * A NextGraph is a URI that is valid in the NextGraph ecosystem
4
+ */
5
+ export type NextGraphUri = `${NextGraphUriPrefix}${string}` & {};
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE1C;;GAEG;AAGH,MAAM,MAAM,YAAY,GAAG,GAAG,kBAAkB,GAAG,MAAM,EAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ export interface NextGraphNotificationMessage {
2
+ V0: {
3
+ State: {
4
+ graph: {
5
+ triples: AllowSharedBufferSource;
6
+ };
7
+ };
8
+ Patch: {
9
+ graph: {
10
+ inserts: AllowSharedBufferSource;
11
+ removes: AllowSharedBufferSource;
12
+ };
13
+ };
14
+ };
15
+ }
16
+ //# sourceMappingURL=NextGraphNotificationMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NextGraphNotificationMessage.d.ts","sourceRoot":"","sources":["../../../src/util/NextGraphNotificationMessage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,4BAA4B;IAC3C,EAAE,EAAE;QACF,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,uBAAuB,CAAC;aAClC,CAAC;SACH,CAAC;QACF,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,uBAAuB,CAAC;gBACjC,OAAO,EAAE,uBAAuB,CAAC;aAClC,CAAC;SACH,CAAC;KACH,CAAC;CACH"}
@@ -0,0 +1,8 @@
1
+ import type { NextGraphUri } from "../types.js";
2
+ /**
3
+ * Checks if a provided string is a leaf URI
4
+ * @param uri - the string to check
5
+ * @returns true if the string is a leaf URI
6
+ */
7
+ export declare function isNextGraphUri(uri: string): uri is NextGraphUri;
8
+ //# sourceMappingURL=isNextGraphUri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNextGraphUri.d.ts","sourceRoot":"","sources":["../../../src/util/isNextGraphUri.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,YAAY,CAE/D"}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@ldo/connected-nextgraph",
3
+ "version": "1.0.0-alpha.11",
4
+ "description": "A plugin for @ldo/connected to work with the Solid ecosystem.",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.js",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/esm/index.js",
13
+ "require": "./dist/cjs/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "scripts": {
18
+ "build": "rimraf dist && npm run build:cjs && npm run build:esm",
19
+ "build:cjs": "tsc --project tsconfig.cjs.json",
20
+ "build:esm": "tsc --project tsconfig.esm.json",
21
+ "test": "npm run test:integration",
22
+ "prepublishOnly": " npm run build",
23
+ "lint": "eslint src/** --fix --no-error-on-unmatched-pattern",
24
+ "docs": "typedoc --plugin typedoc-plugin-markdown",
25
+ "start-test-server": "./test/ngd -vv --save-key -l 14400 --base ./test/nextgraph-data",
26
+ "start-integration-test": "vitest run --coverage",
27
+ "test:integration": "start-server-and-test start-test-server http-get://localhost:14400 start-integration-test"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/o-development/ldo.git"
32
+ },
33
+ "author": "Jackson Morgan",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/o-development/ldo/issues"
37
+ },
38
+ "homepage": "https://github.com/o-development/ldo/tree/main/packages/solid#readme",
39
+ "devDependencies": {
40
+ "@inrupt/solid-client-authn-core": "^2.2.6",
41
+ "@ldo/cli": "^1.0.0-alpha.11",
42
+ "@rdfjs/data-model": "^1.2.0",
43
+ "@rdfjs/types": "^1.0.1",
44
+ "@solid-notifications/types": "^0.1.2",
45
+ "@solid/community-server": "^7.1.3",
46
+ "cross-env": "^7.0.3",
47
+ "dotenv": "^16.3.1",
48
+ "jest-rdf": "^1.8.0",
49
+ "nextgraph": "^0.1.1-alpha.7",
50
+ "start-server-and-test": "^2.0.11",
51
+ "ts-node": "^10.9.1",
52
+ "typed-emitter": "^2.1.0",
53
+ "typedoc": "^0.25.4",
54
+ "typedoc-plugin-markdown": "^3.17.1"
55
+ },
56
+ "dependencies": {
57
+ "@ldo/connected": "^1.0.0-alpha.11",
58
+ "@ldo/dataset": "^1.0.0-alpha.11",
59
+ "@ldo/ldo": "^1.0.0-alpha.11",
60
+ "@ldo/rdf-utils": "^1.0.0-alpha.11",
61
+ "@solid-notifications/subscription": "^0.1.2",
62
+ "cross-fetch": "^3.1.6",
63
+ "http-link-header": "^1.1.1",
64
+ "ws": "^8.18.0"
65
+ },
66
+ "files": [
67
+ "dist",
68
+ "src"
69
+ ],
70
+ "publishConfig": {
71
+ "access": "public"
72
+ },
73
+ "gitHead": "84bd3d7cf0a1b28c5e20b019a6451973d69d0198"
74
+ }
@@ -0,0 +1,87 @@
1
+ import type { ConnectedContext, ConnectedPlugin } from "@ldo/connected";
2
+ import type { NextGraphUri } from "./types.js";
3
+ import { NextGraphResource } from "./resources/NextGraphResource.js";
4
+ import { isNextGraphUri } from "./util/isNextGraphUri.js";
5
+
6
+ export interface NextGraphConnectedContext {
7
+ // NG does not have a type definition
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ ng?: any;
10
+ sessionId?: string;
11
+ protectedStoreId?: string;
12
+ privateStoreId?: string;
13
+ publicStoreId?: string;
14
+ }
15
+
16
+ export interface NextGraphCreateResourceOptions {
17
+ storeType?: "public" | "protected" | "private" | "group" | "dialog";
18
+ storeRepo?: string;
19
+ primaryClass?: string;
20
+ }
21
+
22
+ export interface NextGraphConnectedPlugin
23
+ extends ConnectedPlugin<
24
+ "nextgraph",
25
+ NextGraphUri,
26
+ NextGraphResource,
27
+ NextGraphConnectedContext,
28
+ NextGraphCreateResourceOptions
29
+ > {
30
+ name: "nextgraph";
31
+ getResource: (
32
+ uri: NextGraphUri,
33
+ context: ConnectedContext<this[]>,
34
+ ) => NextGraphResource;
35
+ createResource(context: ConnectedContext<this[]>): Promise<NextGraphResource>;
36
+ }
37
+
38
+ export const nextGraphConnectedPlugin: NextGraphConnectedPlugin = {
39
+ name: "nextgraph",
40
+
41
+ getResource: function (
42
+ uri: NextGraphUri,
43
+ context: ConnectedContext<NextGraphConnectedPlugin[]>,
44
+ ): NextGraphResource {
45
+ return new NextGraphResource(uri, context);
46
+ },
47
+
48
+ createResource: async function (
49
+ context: ConnectedContext<NextGraphConnectedPlugin[]>,
50
+ options?: NextGraphCreateResourceOptions,
51
+ ): Promise<NextGraphResource> {
52
+ const storeType = options?.storeType;
53
+ const storeRepo =
54
+ options?.storeRepo ??
55
+ (storeType === "protected"
56
+ ? context.nextgraph.protectedStoreId
57
+ : storeType === "public"
58
+ ? context.nextgraph.publicStoreId
59
+ : storeType === "private"
60
+ ? context.nextgraph.privateStoreId
61
+ : undefined);
62
+ const primaryClass = options?.primaryClass ?? "data:graph";
63
+
64
+ const nuri: NextGraphUri = await context.nextgraph.ng.doc_create(
65
+ context.nextgraph.sessionId,
66
+ "Graph",
67
+ primaryClass,
68
+ "store",
69
+ storeType,
70
+ storeRepo,
71
+ );
72
+ const newResource = new NextGraphResource(nuri, context);
73
+ await newResource.read();
74
+ return newResource;
75
+ },
76
+
77
+ isUriValid: function (uri: string): uri is NextGraphUri {
78
+ return isNextGraphUri(uri);
79
+ },
80
+
81
+ initialContext: {
82
+ sessionId: undefined,
83
+ },
84
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
85
+ // @ts-ignore "Types" only exists for the typing system
86
+ types: {},
87
+ };
@@ -0,0 +1,13 @@
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
+
6
+ export function createNextGraphLdoDataset() {
7
+ const nextGraphLdoDataset = new ConnectedLdoDataset(
8
+ [nextGraphConnectedPlugin],
9
+ createDatasetFactory(),
10
+ createTransactionDatasetFactory(),
11
+ );
12
+ return nextGraphLdoDataset;
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./types.js";
2
+ export * from "./NextGraphConnectedPlugin.js";
3
+
4
+ export * from "./resources/NextGraphResource.js";
5
+
6
+ export * from "./util/isNextGraphUri.js";
7
+
8
+ export * from "./results/NextGraphReadSuccess.js";
9
+
10
+ export * from "./createNextGraphLdoDataset.js";
@@ -0,0 +1,15 @@
1
+ export interface NextGraphNotificationMessage {
2
+ V0: {
3
+ State?: {
4
+ graph: {
5
+ triples: AllowSharedBufferSource;
6
+ };
7
+ };
8
+ Patch?: {
9
+ graph: {
10
+ inserts: AllowSharedBufferSource;
11
+ removes: AllowSharedBufferSource;
12
+ };
13
+ };
14
+ };
15
+ }
@@ -0,0 +1,23 @@
1
+ import { NotificationSubscription } from "@ldo/connected";
2
+ import type { NextGraphConnectedPlugin } from "../NextGraphConnectedPlugin.js";
3
+ import type { NextGraphNotificationMessage } from "./NextGraphNotificationMessage.js";
4
+
5
+ export class NextGraphNotificationSubscription extends NotificationSubscription<
6
+ NextGraphConnectedPlugin,
7
+ NextGraphNotificationMessage
8
+ > {
9
+ private unsub: (() => void) | undefined;
10
+
11
+ protected async open(): Promise<void> {
12
+ this.unsub = await this.context.nextgraph.ng.doc_subscribe(
13
+ this.resource.uri,
14
+ this.context.nextgraph.sessionId,
15
+ this.onNotification.bind(this),
16
+ );
17
+ }
18
+
19
+ protected async close(): Promise<void> {
20
+ this.unsub?.();
21
+ this.unsub = undefined;
22
+ }
23
+ }