From 778d49ef85ef401d43bf2546972cd638e7be5094 Mon Sep 17 00:00:00 2001 From: Jackson Morgan Date: Wed, 12 Mar 2025 15:08:14 -0400 Subject: [PATCH] Setup connected-nextgraph structure --- package-lock.json | 7 +++++++ packages/connected-nextgraph/package.json | 1 + .../src/NextGraphConnectedPlugin.ts | 3 +++ .../src/createSolidLdoDataset.ts | 10 +++++----- .../src/resources/NextGraphResource.ts | 17 ++++++++++++++--- .../src/util/NextGraphNotificationMessage.ts | 15 +++++++++++++++ packages/connected/src/ConnectedContext.ts | 8 ++++++++ packages/connected/src/index.ts | 1 + 8 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 packages/connected-nextgraph/src/util/NextGraphNotificationMessage.ts create mode 100644 packages/connected/src/ConnectedContext.ts diff --git a/package-lock.json b/package-lock.json index f91e193..c601804 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14687,6 +14687,12 @@ "dev": true, "license": "MIT" }, + "node_modules/nextgraph": { + "version": "0.1.1-alpha.3", + "resolved": "https://registry.npmjs.org/nextgraph/-/nextgraph-0.1.1-alpha.3.tgz", + "integrity": "sha512-rXpyah3Y5ybuM7swfsKE2nON4eQHXZ68AMnRXFeeI/fkJjvh0Gw/vrrADAEVJJ9vSln+pFydH38vUfyVW5h3yw==", + "license": "MIT/Apache-2.0" + }, "node_modules/node-addon-api": { "version": "3.2.1", "dev": true, @@ -20716,6 +20722,7 @@ "@solid-notifications/subscription": "^0.1.2", "cross-fetch": "^3.1.6", "http-link-header": "^1.1.1", + "nextgraph": "^0.1.1-alpha.3", "ws": "^8.18.0" }, "devDependencies": { diff --git a/packages/connected-nextgraph/package.json b/packages/connected-nextgraph/package.json index 7d44a6f..fc5fb00 100644 --- a/packages/connected-nextgraph/package.json +++ b/packages/connected-nextgraph/package.json @@ -46,6 +46,7 @@ "@solid-notifications/subscription": "^0.1.2", "cross-fetch": "^3.1.6", "http-link-header": "^1.1.1", + "nextgraph": "^0.1.1-alpha.3", "ws": "^8.18.0" }, "files": [ diff --git a/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts b/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts index fd46bdf..529467a 100644 --- a/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts +++ b/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts @@ -5,6 +5,9 @@ import type { NextGraphResource } from "./resources/NextGraphResource"; export interface NextGraphConnectedPlugin extends ConnectedPlugin { name: "nextGraph"; getResource(uri: NextGraphUri): NextGraphResource; + context: { + sessionId: string; + }; } export const nextGraphConnectedPlugin: NextGraphConnectedPlugin = { diff --git a/packages/connected-nextgraph/src/createSolidLdoDataset.ts b/packages/connected-nextgraph/src/createSolidLdoDataset.ts index 27611df..7f887b7 100644 --- a/packages/connected-nextgraph/src/createSolidLdoDataset.ts +++ b/packages/connected-nextgraph/src/createSolidLdoDataset.ts @@ -1,13 +1,13 @@ import { ConnectedLdoDataset } from "@ldo/connected"; -import { solidConnectedPlugin } from "./NextGraphConnectedPlugin"; +import { nextGraphConnectedPlugin } from "./NextGraphConnectedPlugin"; import { createDatasetFactory } from "@ldo/dataset"; import { createTransactionDatasetFactory } from "@ldo/subscribable-dataset"; -export function createSolidLdoDataset() { - const solidLdoDataset = new ConnectedLdoDataset( - [solidConnectedPlugin], +export function createNextGraphLdoDataset() { + const nextGraphLdoDataset = new ConnectedLdoDataset( + [nextGraphConnectedPlugin], createDatasetFactory(), createTransactionDatasetFactory(), ); - return solidLdoDataset; + return nextGraphLdoDataset; } diff --git a/packages/connected-nextgraph/src/resources/NextGraphResource.ts b/packages/connected-nextgraph/src/resources/NextGraphResource.ts index b06f939..d11336b 100644 --- a/packages/connected-nextgraph/src/resources/NextGraphResource.ts +++ b/packages/connected-nextgraph/src/resources/NextGraphResource.ts @@ -1,3 +1,4 @@ +import type { ConnectedContext } from "@ldo/connected"; import { Unfetched, type ConnectedResult, @@ -8,6 +9,8 @@ import { } from "@ldo/connected"; import type { NextGraphUri } from "../types"; import EventEmitter from "events"; +import type { NextGraphConnectedPlugin } from "../NextGraphConnectedPlugin"; +import ng from "nextgraph"; export class NextGraphResource extends (EventEmitter as new () => ResourceEventEmitter) @@ -16,11 +19,16 @@ export class NextGraphResource public readonly uri: NextGraphUri; public readonly type = "NextGraphResource" as const; public status: ConnectedResult; + protected context: ConnectedContext; - constructor(uri: NextGraphUri) { + constructor( + uri: NextGraphUri, + context: ConnectedContext, + ) { super(); this.uri = uri; this.status = new Unfetched(this); + this.context = context; } isLoading(): boolean { @@ -59,8 +67,12 @@ export class NextGraphResource throw new Error("Method not implemented."); } + protected async onNotification(message: unknown) { + // TODO + } + subscribeToNotifications(callbacks?: SubscriptionCallbacks): Promise { - throw new Error("Method not implemented."); + ng. } unsubscribeFromNotifications(subscriptionId: string): Promise { @@ -70,5 +82,4 @@ export class NextGraphResource unsubscribeFromAllNotifications(): Promise { throw new Error("Method not implemented."); } - } diff --git a/packages/connected-nextgraph/src/util/NextGraphNotificationMessage.ts b/packages/connected-nextgraph/src/util/NextGraphNotificationMessage.ts new file mode 100644 index 0000000..ab25a75 --- /dev/null +++ b/packages/connected-nextgraph/src/util/NextGraphNotificationMessage.ts @@ -0,0 +1,15 @@ +export interface NextGraphNotificationMessage { + V0: { + State: { + graph: { + triples: AllowSharedBufferSource; + }; + }; + Patch: { + graph: { + inserts: AllowSharedBufferSource; + removes: AllowSharedBufferSource; + }; + }; + }; +} diff --git a/packages/connected/src/ConnectedContext.ts b/packages/connected/src/ConnectedContext.ts new file mode 100644 index 0000000..b705546 --- /dev/null +++ b/packages/connected/src/ConnectedContext.ts @@ -0,0 +1,8 @@ +import type { ConnectedLdoDataset } from "./ConnectedLdoDataset"; +import type { ConnectedPlugin } from "./ConnectedPlugin"; + +export type ConnectedContext = { + dataset: ConnectedLdoDataset; +} & { + [P in Plugins[number] as P["name"]]: P["context"]; +}; diff --git a/packages/connected/src/index.ts b/packages/connected/src/index.ts index 86a9f6c..13899ef 100644 --- a/packages/connected/src/index.ts +++ b/packages/connected/src/index.ts @@ -2,6 +2,7 @@ export * from "./ConnectedLdoDataset"; export * from "./ConnectedPlugin"; export * from "./Resource"; export * from "./InvalidIdentifierResource"; +export * from "./ConnectedContext"; export * from "./notifications/NotificationMessage"; export * from "./notifications/NotificationSubscription";