diff --git a/lerna.json b/lerna.json index 0ced961..5c5c926 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "1.0.0-alpha.2" + "version": "1.0.0-alpha.8" } diff --git a/package-lock.json b/package-lock.json index 06d9270..ae84d0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18785,6 +18785,7 @@ "version": "0.1.1-alpha.7", "resolved": "https://registry.npmjs.org/nextgraph/-/nextgraph-0.1.1-alpha.7.tgz", "integrity": "sha512-Dd0Fl18roKVxAHm0Z39k5Ylsgbqkev0JFOveUYnp5fLYwmECm2gUhO/Nb1P8m79V7D/jW6rHEU5edQA5sx0zFg==", + "dev": true, "license": "MIT/Apache-2.0" }, "node_modules/node-addon-api": { @@ -26244,11 +26245,11 @@ }, "packages/cli": { "name": "@ldo/cli", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/schema-converter-shex": "^1.0.0-alpha.2", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/schema-converter-shex": "^1.0.0-alpha.3", "@shexjs/parser": "^1.0.0-alpha.24", "child-process-promise": "^2.2.1", "commander": "^9.3.0", @@ -26430,12 +26431,12 @@ }, "packages/connected": { "name": "@ldo/connected", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/dataset": "^1.0.0-alpha.2", - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/rdf-utils": "^1.0.0-alpha.2" + "@ldo/dataset": "^1.0.0-alpha.3", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/rdf-utils": "^1.0.0-alpha.3" }, "devDependencies": { "@rdfjs/data-model": "^1.2.0", @@ -26450,21 +26451,21 @@ }, "packages/connected-nextgraph": { "name": "@ldo/connected-nextgraph", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.8", "license": "MIT", "dependencies": { - "@ldo/dataset": "^1.0.0-alpha.2", - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/connected": "^1.0.0-alpha.3", + "@ldo/dataset": "^1.0.0-alpha.3", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@solid-notifications/subscription": "^0.1.2", "cross-fetch": "^3.1.6", "http-link-header": "^1.1.1", - "nextgraph": "^0.1.1-alpha.7", "ws": "^8.18.0" }, "devDependencies": { "@inrupt/solid-client-authn-core": "^2.2.6", - "@ldo/cli": "^1.0.0-alpha.2", + "@ldo/cli": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "@rdfjs/types": "^1.0.1", "@solid-notifications/types": "^0.1.2", @@ -26472,6 +26473,7 @@ "cross-env": "^7.0.3", "dotenv": "^16.3.1", "jest-rdf": "^1.8.0", + "nextgraph": "^0.1.1-alpha.7", "start-server-and-test": "^2.0.11", "ts-node": "^10.9.1", "typed-emitter": "^2.1.0", @@ -26481,12 +26483,12 @@ }, "packages/connected-solid": { "name": "@ldo/connected-solid", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/dataset": "^1.0.0-alpha.2", - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/dataset": "^1.0.0-alpha.3", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@solid-notifications/subscription": "^0.1.2", "cross-fetch": "^3.1.6", "http-link-header": "^1.1.1", @@ -26494,7 +26496,7 @@ }, "devDependencies": { "@inrupt/solid-client-authn-core": "^2.2.6", - "@ldo/cli": "^1.0.0-alpha.2", + "@ldo/cli": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "@rdfjs/types": "^1.0.1", "@solid-notifications/types": "^0.1.2", @@ -26509,10 +26511,10 @@ }, "packages/dataset": { "name": "@ldo/dataset", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@rdfjs/dataset": "^1.1.0", "buffer": "^6.0.3", "readable-stream": "^4.2.0" @@ -26578,11 +26580,11 @@ }, "packages/jsonld-dataset-proxy": { "name": "@ldo/jsonld-dataset-proxy", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/rdf-utils": "^1.0.0-alpha.2", - "@ldo/subscribable-dataset": "^1.0.0-alpha.2", + "@ldo/rdf-utils": "^1.0.0-alpha.3", + "@ldo/subscribable-dataset": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "@rdfjs/dataset": "^1.1.0", "jsonld2graphobject": "^0.0.4" @@ -26605,18 +26607,18 @@ }, "packages/ldo": { "name": "@ldo/ldo", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/dataset": "^1.0.0-alpha.2", - "@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.2", - "@ldo/subscribable-dataset": "^1.0.0-alpha.2", + "@ldo/dataset": "^1.0.0-alpha.3", + "@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.3", + "@ldo/subscribable-dataset": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "buffer": "^6.0.3", "readable-stream": "^4.3.0" }, "devDependencies": { - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@rdfjs/types": "^1.0.1", "@types/jsonld": "^1.5.6", "@types/n3": "^1.10.4", @@ -26650,7 +26652,7 @@ }, "packages/rdf-utils": { "name": "@ldo/rdf-utils", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { "@rdfjs/data-model": "^1.2.0", @@ -26664,14 +26666,14 @@ }, "packages/react": { "name": "@ldo/react", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/connected": "^1.0.0-alpha.2", - "@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.2", - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/rdf-utils": "^1.0.0-alpha.2", - "@ldo/subscribable-dataset": "^1.0.0-alpha.2", + "@ldo/connected": "^1.0.0-alpha.3", + "@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.3", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/rdf-utils": "^1.0.0-alpha.3", + "@ldo/subscribable-dataset": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "cross-fetch": "^3.1.6" }, @@ -26684,15 +26686,15 @@ }, "packages/schema-converter-shex": { "name": "@ldo/schema-converter-shex", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/traverser-shexj": "^1.0.0-alpha.2", + "@ldo/traverser-shexj": "^1.0.0-alpha.3", "dts-dom": "~3.6.0", "jsonld2graphobject": "^0.0.5" }, "devDependencies": { - "@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.2", + "@ldo/jsonld-dataset-proxy": "^1.0.0-alpha.3", "@shexjs/parser": "^1.0.0-alpha.24", "@types/jsonld": "^1.5.6", "@types/shexj": "^2.1.3", @@ -26743,12 +26745,13 @@ }, "packages/solid-react": { "name": "@ldo/solid-react", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.5", "license": "MIT", "dependencies": { - "@inrupt/solid-client-authn-browser": "^2.0.0", - "@ldo/connected": "^1.0.0-alpha.2", - "@ldo/connected-solid": "^1.0.0-alpha.2", + "@inrupt/solid-client-authn-browser": "2.3.0", + "@ldo/connected": "^1.0.0-alpha.3", + "@ldo/connected-solid": "^1.0.0-alpha.3", + "@ldo/react": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "cross-fetch": "^3.1.6" }, @@ -26756,7 +26759,7 @@ "@babel/core": "^7.26.10", "@babel/preset-env": "^7.26.9", "@inrupt/jest-jsdom-polyfills": "^3.2.6", - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@rdfjs/types": "^1.0.1", "@testing-library/react": "^14.1.2", "babel-jest": "^29.7.0", @@ -26769,14 +26772,14 @@ }, "packages/solid-type-index": { "name": "@ldo/solid-type-index", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.5", "license": "MIT", "dependencies": { - "@ldo/connected-solid": "^1.0.0-alpha.2", - "@ldo/solid-react": "^1.0.0-alpha.2" + "@ldo/connected-solid": "^1.0.0-alpha.3", + "@ldo/solid-react": "^1.0.0-alpha.5" }, "devDependencies": { - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@rdfjs/types": "^1.0.1", "@testing-library/react": "^14.1.2", "jest-environment-jsdom": "^29.7.0", @@ -26786,11 +26789,11 @@ }, "packages/subscribable-dataset": { "name": "@ldo/subscribable-dataset", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/dataset": "^1.0.0-alpha.2", - "@ldo/rdf-utils": "^1.0.0-alpha.2" + "@ldo/dataset": "^1.0.0-alpha.3", + "@ldo/rdf-utils": "^1.0.0-alpha.3" }, "devDependencies": { "@rdfjs/data-model": "^1.2.0", @@ -26837,15 +26840,15 @@ }, "packages/traverser-shexj": { "name": "@ldo/traverser-shexj", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { - "@ldo/type-traverser": "^1.0.0-alpha.2" + "@ldo/type-traverser": "^1.0.0-alpha.3" } }, "packages/type-traverser": { "name": "@ldo/type-traverser", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "license": "MIT", "dependencies": { "uuid": "^8.3.2" diff --git a/packages/cli/package.json b/packages/cli/package.json index 42729c1..070e095 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@ldo/cli", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "description": "A Command Line Interface for Linked Data Objects", "main": "./dist/index.js", "bin": { @@ -40,8 +40,8 @@ "rimraf": "^3.0.2" }, "dependencies": { - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/schema-converter-shex": "^1.0.0-alpha.2", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/schema-converter-shex": "^1.0.0-alpha.3", "@shexjs/parser": "^1.0.0-alpha.24", "child-process-promise": "^2.2.1", "commander": "^9.3.0", diff --git a/packages/connected-nextgraph/README.md b/packages/connected-nextgraph/README.md index 0e6f5b4..7195422 100644 --- a/packages/connected-nextgraph/README.md +++ b/packages/connected-nextgraph/README.md @@ -7,7 +7,16 @@ The `@ldo/connected-nextgraph` library allows you to integrate [NextGraph](https First, install the required libraries: ```bash -npm install nextgraph @ldo/connected-nextgraph +npm install @ldo/connected-nextgraph +``` + +Also install a version of next-graph you wish to use + +```bash +# For applications on NodeJS +npm install nextgraph +# For applications running in the web browser +npm install nextgraphweb ``` ## Usage: @@ -26,7 +35,7 @@ const ldoDataset = createNextGraphLdoDataset(); Before you can create or access resources, you need an active session: ```ts -import ng from "nextgraph"; +import ng from "nextgraph" // or `import ng from "nextgraphweb"` for the browser // Open your nextgraph wallet const openedWallet = await ng.wallet_open_with_mnemonic_words( @@ -45,9 +54,9 @@ const session = await ng.session_in_memory_start( --- ### 3. Link Your Dataset to the NextGraph Session - ```ts ldoDataset.setContext("nextgraph", { + ng, sessionId: session.session_id }); ``` @@ -114,6 +123,59 @@ await resource.update({ }); ``` +## Using NextGraph with React + +You can also use the `@ldo/react` library with `@ldo/connected-nextgraph`. + +### 1. Create the react methods + +First, we initialize some methods to use with the `@ldo/connected-nextgraph` and +`@ldo/react` libraries. + +```typescript +// ./reactMethods.ts +import { nextGraphConnectedPlugin } from "@ldo/connected-nextgraph"; +import { createLdoReactMethods } from "@ldo/react"; +import ng from "nextgraphweb"; + +export const { + dataset, + useLdo, + useMatchObject, + useMatchSubject, + useResource, + useSubject, + useSubscribeToResource, +} = createLdoReactMethods([nextGraphConnectedPlugin]); + +// Set NG on the data. When the sessionId is retrieved, `setContext` can be +// called at any time to set that as well. +dataset.setContext("nextgraph", { + ng, + sessionId: "SOME_ID" +}); +``` + +### 2. Use the methods in your React components + +From there, you can import these created methods in your React component and use +them as you would use any of the methods in the [@ldo/react-solid](https://ldo.js.org/latest/guides/solid_react/) +library. + +```typescript +import { FunctionComponent } from "react"; +import { PostShShapeType } from "./.ldo/post.shapeTypes"; +import { useResource, useSubject } from "./reactMethods"; + +export const UseSubjectTest: FunctionComponent = () => { + useResource("did:ng:SOME_URI"); + const post = useSubject(PostShShapeType, `SomeOtherUri`); + + return
{post.articleBody}
; +}; +``` + + ## Sponsorship 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/). diff --git a/packages/connected-nextgraph/package.json b/packages/connected-nextgraph/package.json index 4d4b441..b68e3a4 100644 --- a/packages/connected-nextgraph/package.json +++ b/packages/connected-nextgraph/package.json @@ -1,6 +1,6 @@ { "name": "@ldo/connected-nextgraph", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.8", "description": "A plugin for @ldo/connected to work with the Solid ecosystem.", "main": "dist/index.js", "scripts": { @@ -26,7 +26,7 @@ "homepage": "https://github.com/o-development/ldobjects/tree/main/packages/solid#readme", "devDependencies": { "@inrupt/solid-client-authn-core": "^2.2.6", - "@ldo/cli": "^1.0.0-alpha.2", + "@ldo/cli": "^1.0.0-alpha.3", "@rdfjs/data-model": "^1.2.0", "@rdfjs/types": "^1.0.1", "@solid-notifications/types": "^0.1.2", @@ -34,6 +34,7 @@ "cross-env": "^7.0.3", "dotenv": "^16.3.1", "jest-rdf": "^1.8.0", + "nextgraph": "^0.1.1-alpha.7", "start-server-and-test": "^2.0.11", "ts-node": "^10.9.1", "typed-emitter": "^2.1.0", @@ -41,13 +42,13 @@ "typedoc-plugin-markdown": "^3.17.1" }, "dependencies": { - "@ldo/dataset": "^1.0.0-alpha.2", - "@ldo/ldo": "^1.0.0-alpha.2", - "@ldo/rdf-utils": "^1.0.0-alpha.2", + "@ldo/connected": "^1.0.0-alpha.3", + "@ldo/dataset": "^1.0.0-alpha.3", + "@ldo/ldo": "^1.0.0-alpha.3", + "@ldo/rdf-utils": "^1.0.0-alpha.3", "@solid-notifications/subscription": "^0.1.2", "cross-fetch": "^3.1.6", "http-link-header": "^1.1.1", - "nextgraph": "^0.1.1-alpha.7", "ws": "^8.18.0" }, "files": [ diff --git a/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts b/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts index e091b2c..b70fe37 100644 --- a/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts +++ b/packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts @@ -1,10 +1,12 @@ import type { ConnectedContext, ConnectedPlugin } from "@ldo/connected"; import type { NextGraphUri } from "./types"; import { NextGraphResource } from "./resources/NextGraphResource"; -import ng from "nextgraph"; import { isNextGraphUri } from "./util/isNextGraphUri"; export interface NextGraphConnectedContext { + // NG does not have a type definition + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ng?: any; sessionId?: string; protectedStoreId?: string; privateStoreId?: string; @@ -14,6 +16,7 @@ export interface NextGraphConnectedContext { export interface NextGraphCreateResourceOptions { storeType?: "public" | "protected" | "private" | "group" | "dialog"; storeRepo?: string; + primaryClass?: string; } export interface NextGraphConnectedPlugin @@ -56,11 +59,12 @@ export const nextGraphConnectedPlugin: NextGraphConnectedPlugin = { : storeType === "private" ? context.nextgraph.privateStoreId : undefined); + const primaryClass = options?.primaryClass ?? "data:graph"; - const nuri: NextGraphUri = await ng.doc_create( + const nuri: NextGraphUri = await context.nextgraph.ng.doc_create( context.nextgraph.sessionId, "Graph", - "data:graph", + primaryClass, "store", storeType, storeRepo, diff --git a/packages/connected-nextgraph/src/index.ts b/packages/connected-nextgraph/src/index.ts index bf2cfc8..89e8617 100644 --- a/packages/connected-nextgraph/src/index.ts +++ b/packages/connected-nextgraph/src/index.ts @@ -6,3 +6,5 @@ export * from "./resources/NextGraphResource"; export * from "./util/isNextGraphUri"; export * from "./results/NextGraphReadSuccess"; + +export * from "./createNextGraphLdoDataset"; diff --git a/packages/connected-nextgraph/src/notifications/NextGraphNotificationSubscription.ts b/packages/connected-nextgraph/src/notifications/NextGraphNotificationSubscription.ts index 2a34e39..a4a5caf 100644 --- a/packages/connected-nextgraph/src/notifications/NextGraphNotificationSubscription.ts +++ b/packages/connected-nextgraph/src/notifications/NextGraphNotificationSubscription.ts @@ -1,7 +1,6 @@ import { NotificationSubscription } from "@ldo/connected"; import type { NextGraphConnectedPlugin } from "../NextGraphConnectedPlugin"; import type { NextGraphNotificationMessage } from "./NextGraphNotificationMessage"; -import ng from "nextgraph"; export class NextGraphNotificationSubscription extends NotificationSubscription< NextGraphConnectedPlugin, @@ -10,8 +9,7 @@ export class NextGraphNotificationSubscription extends NotificationSubscription< private unsub: (() => void) | undefined; protected async open(): Promise