parent
d896f50c75
commit
3c571a6098
@ -0,0 +1,15 @@ |
|||||||
|
import type { ConnectedPlugin } from "@ldo/connected"; |
||||||
|
import type { NextGraphUri } from "./types"; |
||||||
|
import type { NextGraphResource } from "./resources/NextGraphResource"; |
||||||
|
|
||||||
|
export interface NextGraphConnectedPlugin extends ConnectedPlugin { |
||||||
|
name: "nextGraph"; |
||||||
|
getResource(uri: NextGraphUri): NextGraphResource; |
||||||
|
} |
||||||
|
|
||||||
|
export const nextGraphConnectedPlugin: NextGraphConnectedPlugin = { |
||||||
|
name: "nextGraph", |
||||||
|
getResource(_uri: NextGraphUri): NextGraphResource { |
||||||
|
throw new Error("Not Implemented"); |
||||||
|
}, |
||||||
|
}; |
@ -0,0 +1,13 @@ |
|||||||
|
import { ConnectedLdoDataset } from "@ldo/connected"; |
||||||
|
import { solidConnectedPlugin } from "./NextGraphConnectedPlugin"; |
||||||
|
import { createDatasetFactory } from "@ldo/dataset"; |
||||||
|
import { createTransactionDatasetFactory } from "@ldo/subscribable-dataset"; |
||||||
|
|
||||||
|
export function createSolidLdoDataset() { |
||||||
|
const solidLdoDataset = new ConnectedLdoDataset( |
||||||
|
[solidConnectedPlugin], |
||||||
|
createDatasetFactory(), |
||||||
|
createTransactionDatasetFactory(), |
||||||
|
); |
||||||
|
return solidLdoDataset; |
||||||
|
} |
@ -0,0 +1,6 @@ |
|||||||
|
export * from "./types"; |
||||||
|
export * from "./NextGraphConnectedPlugin"; |
||||||
|
|
||||||
|
export * from "./resources/NextGraphResource"; |
||||||
|
|
||||||
|
export * from "./util/isSolidUri"; |
@ -0,0 +1,3 @@ |
|||||||
|
import type { Resource } from "@ldo/connected"; |
||||||
|
|
||||||
|
export class NextGraphResource implements Resource {} |
@ -0,0 +1,8 @@ |
|||||||
|
export type NextGraphUriPrefix = `did:ng`; |
||||||
|
|
||||||
|
/** |
||||||
|
* A NextGraph is a URI that is valid in the NextGraph ecosystem |
||||||
|
*/ |
||||||
|
// The & {} allows for alias preservation
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
export type NextGraphUri = `${NextGraphUriPrefix}${string}` & {}; |
@ -0,0 +1,10 @@ |
|||||||
|
import type { NextGraphUri } from "../types"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if a provided string is a leaf URI |
||||||
|
* @param uri - the string to check |
||||||
|
* @returns true if the string is a leaf URI |
||||||
|
*/ |
||||||
|
export function isNextGraphUri(uri: string): uri is NextGraphUri { |
||||||
|
return uri.startsWith("did:ng"); |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
import type { ConnectedPlugin } from "@ldo/connected"; |
||||||
|
import type { SolidContainerUri, SolidLeafUri, SolidUri } from "./types"; |
||||||
|
import type { SolidLeaf } from "./resources/SolidLeaf"; |
||||||
|
import type { SolidContainer } from "./resources/SolidContainer"; |
||||||
|
|
||||||
|
export interface SolidConnectedPlugin extends ConnectedPlugin { |
||||||
|
name: "solid"; |
||||||
|
identifierType: SolidUri; |
||||||
|
getResource: |
||||||
|
| ((uri: SolidLeafUri) => SolidLeaf) |
||||||
|
| ((uri: SolidContainerUri) => SolidContainer); |
||||||
|
} |
||||||
|
|
||||||
|
export const solidConnectedPlugin: SolidConnectedPlugin = { |
||||||
|
name: "solid", |
||||||
|
identifierType: "https://example.com", |
||||||
|
getResource(_uri: SolidUri): SolidContainer | SolidLeaf { |
||||||
|
throw new Error("Not Implemented"); |
||||||
|
}, |
||||||
|
}; |
@ -0,0 +1,13 @@ |
|||||||
|
import { ConnectedLdoDataset } from "@ldo/connected"; |
||||||
|
import { solidConnectedPlugin } from "./SolidConnectedPlugin"; |
||||||
|
import { createDatasetFactory } from "@ldo/dataset"; |
||||||
|
import { createTransactionDatasetFactory } from "@ldo/subscribable-dataset"; |
||||||
|
|
||||||
|
export function createSolidLdoDataset() { |
||||||
|
const solidLdoDataset = new ConnectedLdoDataset( |
||||||
|
[solidConnectedPlugin], |
||||||
|
createDatasetFactory(), |
||||||
|
createTransactionDatasetFactory(), |
||||||
|
); |
||||||
|
return solidLdoDataset; |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
export * from "./types"; |
||||||
|
export * from "./SolidConnectedPlugin"; |
||||||
|
|
||||||
|
export * from "./resources/SolidResource"; |
||||||
|
export * from "./resources/SolidContainer"; |
||||||
|
export * from "./resources/SolidLeaf"; |
||||||
|
|
||||||
|
export * from "./util/isSolidUri"; |
@ -0,0 +1,3 @@ |
|||||||
|
import { SolidResource } from "./SolidResource"; |
||||||
|
|
||||||
|
export class SolidContainer extends SolidResource {} |
@ -0,0 +1,3 @@ |
|||||||
|
import { SolidResource } from "./SolidResource"; |
||||||
|
|
||||||
|
export class SolidLeaf extends SolidResource {} |
@ -0,0 +1,3 @@ |
|||||||
|
import type { Resource } from "@ldo/connected"; |
||||||
|
|
||||||
|
export class SolidResource implements Resource {} |
@ -0,0 +1,19 @@ |
|||||||
|
import { ConnectedLdoDataset } from "@ldo/connected"; |
||||||
|
import { solidConnectedPlugin } from "./SolidConnectedPlugin"; |
||||||
|
import { createDatasetFactory } from "@ldo/dataset"; |
||||||
|
import { createTransactionDatasetFactory } from "@ldo/subscribable-dataset"; |
||||||
|
import { nextGraphConnectedPlugin } from "@ldo/connected-nextgraph"; |
||||||
|
|
||||||
|
const dataset = new ConnectedLdoDataset( |
||||||
|
[solidConnectedPlugin, nextGraphConnectedPlugin], |
||||||
|
createDatasetFactory(), |
||||||
|
createTransactionDatasetFactory(), |
||||||
|
); |
||||||
|
|
||||||
|
const stringId: string = "blah"; |
||||||
|
const allResources = dataset.getResource(stringId); |
||||||
|
const containerResource = dataset.getResource("https://example.com/container/"); |
||||||
|
const leafResource = dataset.getResource( |
||||||
|
"https://example.com/container/index.ttl", |
||||||
|
); |
||||||
|
const nextGraphResource = dataset.getResource("did:ng:cool", "solid"); |
@ -0,0 +1,114 @@ |
|||||||
|
export type SolidUriPrefix = `http${"s" | ""}://`; |
||||||
|
|
||||||
|
/** |
||||||
|
* A SolidUri is a URI that is valid in the Solid ecosystem ("http" and "https") |
||||||
|
*/ |
||||||
|
export type SolidUri = `${SolidUriPrefix}${string}`; |
||||||
|
|
||||||
|
/** |
||||||
|
* A SolidLeafUri is any URI that has a pahtname that ends in a "/". It represents a |
||||||
|
* container. |
||||||
|
*/ |
||||||
|
// The & {} allows for alias preservation
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
export type SolidContainerUri = `${SolidUri}/${NonPathnameEnding}` & {}; |
||||||
|
|
||||||
|
/** |
||||||
|
* A LeafUri is any URI that does not have a pahtname that ends in a "/". It |
||||||
|
* represents a data resource or a binary resource. Not a container. |
||||||
|
*/ |
||||||
|
export type SolidLeafUri = |
||||||
|
// The & {} allows for alias preservation
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
`${SolidUri}${EveryLegalPathnameCharacterOtherThanSlash}${NonPathnameEnding}` & {}; |
||||||
|
|
||||||
|
/** |
||||||
|
* @internal |
||||||
|
*/ |
||||||
|
type NonPathnameEnding = "" | `?${string}` | `#${string}`; |
||||||
|
|
||||||
|
/** |
||||||
|
* @internal |
||||||
|
*/ |
||||||
|
type EveryLegalPathnameCharacterOtherThanSlash = |
||||||
|
| "A" |
||||||
|
| "B" |
||||||
|
| "C" |
||||||
|
| "D" |
||||||
|
| "E" |
||||||
|
| "F" |
||||||
|
| "G" |
||||||
|
| "H" |
||||||
|
| "I" |
||||||
|
| "J" |
||||||
|
| "K" |
||||||
|
| "L" |
||||||
|
| "M" |
||||||
|
| "N" |
||||||
|
| "O" |
||||||
|
| "P" |
||||||
|
| "Q" |
||||||
|
| "R" |
||||||
|
| "S" |
||||||
|
| "T" |
||||||
|
| "U" |
||||||
|
| "V" |
||||||
|
| "W" |
||||||
|
| "X" |
||||||
|
| "Y" |
||||||
|
| "Z" |
||||||
|
| "a" |
||||||
|
| "b" |
||||||
|
| "c" |
||||||
|
| "d" |
||||||
|
| "e" |
||||||
|
| "f" |
||||||
|
| "g" |
||||||
|
| "h" |
||||||
|
| "i" |
||||||
|
| "j" |
||||||
|
| "k" |
||||||
|
| "l" |
||||||
|
| "m" |
||||||
|
| "n" |
||||||
|
| "o" |
||||||
|
| "p" |
||||||
|
| "q" |
||||||
|
| "r" |
||||||
|
| "s" |
||||||
|
| "t" |
||||||
|
| "u" |
||||||
|
| "v" |
||||||
|
| "w" |
||||||
|
| "x" |
||||||
|
| "y" |
||||||
|
| "z" |
||||||
|
| "1" |
||||||
|
| "2" |
||||||
|
| "3" |
||||||
|
| "4" |
||||||
|
| "5" |
||||||
|
| "6" |
||||||
|
| "7" |
||||||
|
| "8" |
||||||
|
| "9" |
||||||
|
| "0" |
||||||
|
| "-" |
||||||
|
| "." |
||||||
|
| "_" |
||||||
|
| "~" |
||||||
|
| ":" |
||||||
|
| "[" |
||||||
|
| "]" |
||||||
|
| "@" |
||||||
|
| "!" |
||||||
|
| "$" |
||||||
|
| "&" |
||||||
|
| "'" |
||||||
|
| "(" |
||||||
|
| ")" |
||||||
|
| "*" |
||||||
|
| "+" |
||||||
|
| "," |
||||||
|
| ";" |
||||||
|
| "="; |
@ -0,0 +1,43 @@ |
|||||||
|
import type { SolidContainerUri, SolidLeafUri, SolidUri } from "../types"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if a provided string is a leaf URI |
||||||
|
* @param uri - the string to check |
||||||
|
* @returns true if the string is a leaf URI |
||||||
|
*/ |
||||||
|
export function isSolidUri(uri: string): uri is SolidUri { |
||||||
|
try { |
||||||
|
const url = new URL(uri); |
||||||
|
return url.protocol === "https:" || url.protocol === "http:"; |
||||||
|
} catch { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if a provided string is a Container URI |
||||||
|
* @param uri - the string to check |
||||||
|
* @returns true if the string is a container URI |
||||||
|
*/ |
||||||
|
export function isSolidContainerUri(uri: string): uri is SolidContainerUri { |
||||||
|
try { |
||||||
|
const url = new URL(uri); |
||||||
|
return url.pathname.endsWith("/"); |
||||||
|
} catch { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if a provided string is a leaf URI |
||||||
|
* @param uri - the string to check |
||||||
|
* @returns true if the string is a leaf URI |
||||||
|
*/ |
||||||
|
export function isSolidLeafUri(uri: string): uri is SolidLeafUri { |
||||||
|
try { |
||||||
|
const url = new URL(uri); |
||||||
|
return url.pathname.endsWith("/"); |
||||||
|
} catch { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
@ -1,6 +1,6 @@ |
|||||||
import type { Resource } from "./Resource"; |
import type { Resource } from "./Resource"; |
||||||
|
|
||||||
export interface ConnectedLdoPlugin { |
export interface ConnectedPlugin { |
||||||
name: string; |
name: string; |
||||||
getResource(uri: string): Resource; |
getResource(uri: string): Resource; |
||||||
} |
} |
@ -0,0 +1,5 @@ |
|||||||
|
import { ConnectedLdoDataset } from "./ConnectedLdoDataset"; |
||||||
|
|
||||||
|
export * from "./ConnectedLdoDataset"; |
||||||
|
export * from "./ConnectedPlugin"; |
||||||
|
export * from "./Resource"; |
@ -1,55 +0,0 @@ |
|||||||
import { createDatasetFactory } from "@ldo/dataset"; |
|
||||||
import { ConnectedLdoDataset } from "./ConnectedLdoDataset"; |
|
||||||
import { createTransactionDatasetFactory } from "@ldo/subscribable-dataset"; |
|
||||||
import type { ContainerUri, LeafUri } from "../../solid/src/index"; |
|
||||||
import { SolidContainer, SolidLeaf } from "./Resource"; |
|
||||||
|
|
||||||
interface SolidPlugin { |
|
||||||
name: "solid"; |
|
||||||
getResource(uri: ContainerUri): SolidContainer; |
|
||||||
getResource(uri: LeafUri): SolidLeaf; |
|
||||||
getResource(uri: string): SolidLeaf | SolidContainer; |
|
||||||
} |
|
||||||
|
|
||||||
const solidPlugin: SolidPlugin = { |
|
||||||
name: "solid", |
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
getResource(_uri: string): any { |
|
||||||
throw new Error(); |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
interface NextgraphPlugin { |
|
||||||
name: "nextgraph"; |
|
||||||
getResource(uri: ContainerUri); |
|
||||||
getResource(uri: string): "nextgraphResource"; |
|
||||||
} |
|
||||||
|
|
||||||
const nextgraphPlugin: NextgraphPlugin = { |
|
||||||
name: "nextgraph", |
|
||||||
getResource(_uri: string): "nextgraphResource" { |
|
||||||
return "nextgraphResource"; |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
async function main() { |
|
||||||
const dataset = new ConnectedLdoDataset( |
|
||||||
[solidPlugin, nextgraphPlugin], |
|
||||||
createDatasetFactory(), |
|
||||||
createTransactionDatasetFactory(), |
|
||||||
); |
|
||||||
|
|
||||||
const solidContainerResource = dataset.getResource("https://example.com/"); |
|
||||||
const solidLeafResource = dataset.getResource( |
|
||||||
"https://example.com/resource.ttl", |
|
||||||
); |
|
||||||
const stringUri: string = "https://example.com/"; |
|
||||||
const allResources = dataset.getResource(stringUri); |
|
||||||
const solidResource = dataset.getResource(stringUri, "solid"); |
|
||||||
const nextgraphResource = dataset.getResource(stringUri, "nextgraph"); |
|
||||||
|
|
||||||
const nextgraphResource2 = dataset.getResource( |
|
||||||
"did:ng:o:OGNxCWfTXMfYIJi8HCEfL6_uExLtCHrK0JGT4fU5pH4A:v:R2y5iENVwuaaoW86TvMbfZfCIrNXaNIFA3BF6fx9svQA", |
|
||||||
); |
|
||||||
} |
|
||||||
main(); |
|
Loading…
Reference in new issue