Partial implementation of nextgraph plugin

main
Jackson Morgan 5 months ago
parent 6f2406bfb7
commit 9e61e775cd
  1. 32
      packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts
  2. 1
      packages/connected-nextgraph/src/notifications/NextGraphNotificationMessage.ts
  3. 8
      packages/connected-nextgraph/src/resources/NextGraphResource.ts
  4. 15
      packages/connected-solid/src/notifications/SolidNotificationSubscription.ts
  5. 8
      packages/connected-solid/src/resources/SolidResource.ts
  6. 5
      packages/connected/src/SubscriptionCallbacks.ts
  7. 1
      packages/connected/src/index.ts

@ -1,6 +1,8 @@
import type { ConnectedContext, ConnectedPlugin } from "@ldo/connected";
import type { NextGraphUri } from "./types";
import type { NextGraphResource } from "./resources/NextGraphResource";
import { NextGraphResource } from "./resources/NextGraphResource";
import ng from "nextgraph";
import { isNextGraphUri } from "./util/isNextGraphUri";
export interface NextGraphConnectedContext {
sessionId?: string;
@ -23,16 +25,34 @@ export interface NextGraphConnectedPlugin
export const nextgGraphConnectedPlugin: NextGraphConnectedPlugin = {
name: "nextgraph",
getResource: function (_uri: NextGraphUri): NextGraphResource {
throw new Error("Function not implemented.");
getResource: function (
uri: NextGraphUri,
context: ConnectedContext<NextGraphConnectedPlugin[]>,
): NextGraphResource {
// NIKO: Do I need to split into "base?" Remind me again of why I need base?
return new NextGraphResource(uri, context);
},
createResource: function (): Promise<NextGraphResource> {
throw new Error("Function not implemented.");
createResource: async function (
context: ConnectedContext<NextGraphConnectedPlugin[]>,
): Promise<NextGraphResource> {
const nuri: NextGraphUri = await ng.doc_create(
context.nextgraph.sessionId,
"Graph",
// NIKO: Can this always be "data:graph"?
"data:graph",
// NIKO: What are the options here again?
"protected",
// NIKO: What is this? Should it be changed?
"B381BvfdAFYPBkdhDrsqnMMg5pnJMWJgJbZobZErXZMA",
// NIKO: Can this always be "store"?
"store",
);
return new NextGraphResource(nuri, context);
},
isUriValid: function (uri: string): uri is NextGraphUri {
throw new Error("Function not implemented.");
return isNextGraphUri(uri);
},
initialContext: {

@ -0,0 +1 @@
export interface NextGraphNotificationMessage {}

@ -1,6 +1,7 @@
import type {
ConnectedContext,
ReadSuccess,
SubscriptionCallbacks,
UpdateSuccess,
} from "@ldo/connected";
import {
@ -14,6 +15,7 @@ import EventEmitter from "events";
import type { NextGraphConnectedPlugin } from "../NextGraphConnectedPlugin";
import ng from "nextgraph";
import type { DatasetChanges } from "@ldo/rdf-utils";
import type { NextGraphNotificationMessage } from "../notifications/NextGraphNotificationMessage";
export class NextGraphResource
extends (EventEmitter as new () => ResourceEventEmitter)
@ -77,11 +79,13 @@ export class NextGraphResource
throw new Error("Method Not Implemented");
}
protected async onNotification(message: unknown) {
protected async onNotification(_message: unknown) {
// TODO
}
subscribeToNotifications(callbacks?: SubscriptionCallbacks): Promise<string> {
subscribeToNotifications(
_callbacks?: SubscriptionCallbacks<NextGraphNotificationMessage>,
): Promise<string> {
throw new Error("Method not implemented.");
}

@ -1,4 +1,4 @@
import type { ConnectedContext } from "@ldo/connected";
import type { ConnectedContext, SubscriptionCallbacks } from "@ldo/connected";
import type { NotificationCallbackError } from "./results/NotificationErrors";
import { v4 } from "uuid";
import type { SolidContainer } from "../resources/SolidContainer";
@ -6,12 +6,6 @@ import type { SolidLeaf } from "../resources/SolidLeaf";
import type { SolidNotificationMessage } from "./SolidNotificationMessage";
import type { SolidConnectedPlugin } from "../SolidConnectedPlugin";
export interface SubscriptionCallbacks {
onNotification?: (message: SolidNotificationMessage) => void;
// TODO: make notification errors more specific
onNotificationError?: (error: Error) => void;
}
/**
* @internal
* Abstract class for notification subscription methods.
@ -20,7 +14,10 @@ export abstract class SolidNotificationSubscription {
protected resource: SolidContainer | SolidLeaf;
protected parentSubscription: (message: SolidNotificationMessage) => void;
protected context: ConnectedContext<SolidConnectedPlugin[]>;
protected subscriptions: Record<string, SubscriptionCallbacks> = {};
protected subscriptions: Record<
string,
SubscriptionCallbacks<SolidNotificationMessage>
> = {};
private isOpen: boolean = false;
constructor(
@ -48,7 +45,7 @@ export abstract class SolidNotificationSubscription {
* subscribeToNotifications
*/
async subscribeToNotifications(
subscriptionCallbacks?: SubscriptionCallbacks,
subscriptionCallbacks?: SubscriptionCallbacks<SolidNotificationMessage>,
): Promise<string> {
const subscriptionId = v4();
this.subscriptions[subscriptionId] = subscriptionCallbacks ?? {};

@ -6,6 +6,7 @@ import type {
Resource,
ResourceEventEmitter,
ResourceSuccess,
SubscriptionCallbacks,
Unfetched,
} from "@ldo/connected";
import type { SolidContainerUri, SolidLeafUri } from "../types";
@ -13,10 +14,7 @@ import EventEmitter from "events";
import type { SolidConnectedPlugin } from "../SolidConnectedPlugin";
import type { BatchedRequester } from "../requester/BatchedRequester";
import type { WacRule } from "../wac/WacRule";
import type {
SolidNotificationSubscription,
SubscriptionCallbacks,
} from "../notifications/SolidNotificationSubscription";
import type { SolidNotificationSubscription } from "../notifications/SolidNotificationSubscription";
import { Websocket2023NotificationSubscription } from "../notifications/Websocket2023NotificationSubscription";
import { getParentUri } from "../util/rdfUtils";
import { isReadSuccess } from "../requester/results/success/SolidReadSuccess";
@ -784,7 +782,7 @@ export abstract class SolidResource
* // ... From there you can wait for a file to be changed on the Pod.
*/
async subscribeToNotifications(
callbacks?: SubscriptionCallbacks,
callbacks?: SubscriptionCallbacks<SolidNotificationMessage>,
): Promise<string> {
return await this.notificationSubscription.subscribeToNotifications(
callbacks,

@ -0,0 +1,5 @@
export interface SubscriptionCallbacks<NotificationMessage> {
onNotification?: (message: NotificationMessage) => void;
// TODO: make notification errors more specific
onNotificationError?: (error: Error) => void;
}

@ -7,6 +7,7 @@ export * from "./InvalidIdentifierResource";
export * from "./ConnectedContext";
export * from "./methods";
export * from "./createConntectedLdoDataset";
export * from "./SubscriptionCallbacks";
export * from "./util/splitChangesByGraph";

Loading…
Cancel
Save