parent
8f45f4b950
commit
d19437b34f
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@ |
|||||||
|
{ |
||||||
|
"extends": ["../../.eslintrc"] |
||||||
|
} |
@ -0,0 +1,6 @@ |
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
const sharedConfig = require("../../jest.config.js"); |
||||||
|
module.exports = { |
||||||
|
...sharedConfig, |
||||||
|
rootDir: "./", |
||||||
|
}; |
@ -0,0 +1,33 @@ |
|||||||
|
{ |
||||||
|
"name": "@ldo/rdf-utils", |
||||||
|
"version": "0.0.0", |
||||||
|
"description": "Some RDF Utilities to support LDO librariers", |
||||||
|
"main": "dist/index.js", |
||||||
|
"scripts": { |
||||||
|
"build": "tsc --project tsconfig.build.json", |
||||||
|
"watch": "tsc --watch", |
||||||
|
"test": "jest --coverage", |
||||||
|
"test:watch": "jest --watch", |
||||||
|
"prepublishOnly": "npm run test && npm run build", |
||||||
|
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern" |
||||||
|
}, |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/o-development/devtool-boilerplate.git" |
||||||
|
}, |
||||||
|
"author": "Jackson Morgan", |
||||||
|
"license": "MIT", |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/o-development/devtool-boilerplate/issues" |
||||||
|
}, |
||||||
|
"homepage": "https://github.com/o-development/devtool-boilerplate#readme", |
||||||
|
"devDependencies": { |
||||||
|
"@rdfjs/types": "^1.1.0", |
||||||
|
"@types/jsonld": "^1.5.9" |
||||||
|
}, |
||||||
|
"dependencies": { |
||||||
|
"@rdfjs/data-model": "^2.0.1", |
||||||
|
"n3": "^1.17.1", |
||||||
|
"rdf-string": "^1.6.3" |
||||||
|
} |
||||||
|
} |
@ -1,10 +1,20 @@ |
|||||||
import type { DatasetChanges } from "@ldo/subscribable-dataset"; |
import type { BaseQuad, Dataset, Quad } from "@rdfjs/types"; |
||||||
import { datasetToString } from "@ldo/ldo"; |
|
||||||
import type { Quad } from "@rdfjs/types"; |
|
||||||
import { quad as createQuad } from "@rdfjs/data-model"; |
import { quad as createQuad } from "@rdfjs/data-model"; |
||||||
|
import { datasetToString } from "./datasetConverters"; |
||||||
|
|
||||||
// TODO: This file is a clone from the one in the base ldo library. This resused
|
/** |
||||||
// code should be put into a helper library once everything becomes a monorepo.
|
* An interface representing the changes made |
||||||
|
*/ |
||||||
|
export interface DatasetChanges<InAndOutQuad extends BaseQuad = BaseQuad> { |
||||||
|
added?: Dataset<InAndOutQuad, InAndOutQuad>; |
||||||
|
removed?: Dataset<InAndOutQuad, InAndOutQuad>; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Takes Dataset Changes and converts them to SPARQL UPDATE |
||||||
|
* @param changes: Dataset Changes |
||||||
|
* @returns String SPARQL Update |
||||||
|
*/ |
||||||
export async function changesToSparqlUpdate(changes: DatasetChanges<Quad>) { |
export async function changesToSparqlUpdate(changes: DatasetChanges<Quad>) { |
||||||
let output = ""; |
let output = ""; |
||||||
if (changes.removed) { |
if (changes.removed) { |
@ -0,0 +1,60 @@ |
|||||||
|
import type { Dataset } from "@rdfjs/types"; |
||||||
|
import type { ContextDefinition, JsonLdDocument } from "jsonld"; |
||||||
|
import type { WriterOptions } from "n3"; |
||||||
|
import { Writer } from "n3"; |
||||||
|
// import SerializerJsonld from "@rdfjs/serializer-jsonld";
|
||||||
|
// import { Readable } from "readable-stream";
|
||||||
|
|
||||||
|
export async function datasetToString( |
||||||
|
dataset: Dataset, |
||||||
|
options: WriterOptions, |
||||||
|
): Promise<string> { |
||||||
|
return new Promise<string>((resolve, reject) => { |
||||||
|
const writer = new Writer(options); |
||||||
|
for (const quad of dataset) { |
||||||
|
writer.addQuad(quad); |
||||||
|
} |
||||||
|
writer.end(async (error, parsedString: string) => { |
||||||
|
/* istanbul ignore if */ |
||||||
|
if (error) { |
||||||
|
return reject(error); |
||||||
|
} |
||||||
|
return resolve(parsedString); |
||||||
|
}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
export async function datasetToJsonLd( |
||||||
|
_dataset: Dataset, |
||||||
|
_context: ContextDefinition, |
||||||
|
): Promise<JsonLdDocument> { |
||||||
|
throw new Error("JSONLD serialization is not omplemented"); |
||||||
|
} |
||||||
|
|
||||||
|
// export async function datasetToJsonLd(
|
||||||
|
// dataset: Dataset,
|
||||||
|
// context: ContextDefinition
|
||||||
|
// ): Promise<JsonLdDocument> {
|
||||||
|
// return new Promise((resolve, reject) => {
|
||||||
|
// const serializerJsonld = new SerializerJsonld();
|
||||||
|
// const input = new Readable({
|
||||||
|
// objectMode: true,
|
||||||
|
// read: () => {
|
||||||
|
// dataset.forEach((quad) => {
|
||||||
|
// input.push(quad);
|
||||||
|
// });
|
||||||
|
// input.push(null);
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// const output = serializerJsonld.import(input);
|
||||||
|
|
||||||
|
// output.on("data", (jsonld) => {
|
||||||
|
// resolve(jsonld);
|
||||||
|
// });
|
||||||
|
// /* istanbul ignore next */
|
||||||
|
// output.on("error", (err) => {
|
||||||
|
// /* istanbul ignore next */
|
||||||
|
// reject(err);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// }
|
@ -0,0 +1,5 @@ |
|||||||
|
export * from "./nodeSerialization"; |
||||||
|
export * from "@rdfjs/types"; |
||||||
|
export * from "@rdfjs/data-model"; |
||||||
|
export * from "./datasetChanges"; |
||||||
|
export * from "./datasetConverters"; |
@ -0,0 +1,245 @@ |
|||||||
|
import type { |
||||||
|
Quad, |
||||||
|
Term, |
||||||
|
BlankNode, |
||||||
|
DefaultGraph, |
||||||
|
Literal, |
||||||
|
NamedNode, |
||||||
|
} from "@rdfjs/types"; |
||||||
|
import { |
||||||
|
termToString, |
||||||
|
quadToStringQuad, |
||||||
|
stringToTerm, |
||||||
|
stringQuadToQuad, |
||||||
|
} from "rdf-string"; |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* Types |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Generic type to extract a set of termsTypes for a Term |
||||||
|
*/ |
||||||
|
export type NodeTermTypes<Node extends Term> = Set<Node["termType"]>; |
||||||
|
|
||||||
|
export type SubjectNode = NamedNode | BlankNode; |
||||||
|
export const SubjectTermTypes: NodeTermTypes<SubjectNode> = new Set([ |
||||||
|
"NamedNode", |
||||||
|
"BlankNode", |
||||||
|
]); |
||||||
|
export type PredicateNode = NamedNode; |
||||||
|
export const PredicateTermTypes: NodeTermTypes<PredicateNode> = new Set([ |
||||||
|
"NamedNode", |
||||||
|
]); |
||||||
|
export type ObjectNode = NamedNode | BlankNode | Literal; |
||||||
|
export const ObjectTermTypes: NodeTermTypes<ObjectNode> = new Set([ |
||||||
|
"NamedNode", |
||||||
|
"BlankNode", |
||||||
|
"Literal", |
||||||
|
]); |
||||||
|
export type GraphNode = NamedNode | BlankNode | DefaultGraph; |
||||||
|
export const GraphTermTypes: NodeTermTypes<GraphNode> = new Set([ |
||||||
|
"NamedNode", |
||||||
|
"BlankNode", |
||||||
|
"DefaultGraph", |
||||||
|
]); |
||||||
|
export type AnyNode = SubjectNode | PredicateNode | ObjectNode | GraphNode; |
||||||
|
export const AnyTermTypes: NodeTermTypes<AnyNode> = new Set([ |
||||||
|
"NamedNode", |
||||||
|
"BlankNode", |
||||||
|
"DefaultGraph", |
||||||
|
"Literal", |
||||||
|
]); |
||||||
|
|
||||||
|
export interface SimpleQuad extends Quad { |
||||||
|
/** |
||||||
|
* The subject. |
||||||
|
* @see GraphNode |
||||||
|
*/ |
||||||
|
subject: SubjectNode; |
||||||
|
/** |
||||||
|
* The predicate. |
||||||
|
* @see GraphNode |
||||||
|
*/ |
||||||
|
predicate: PredicateNode; |
||||||
|
/** |
||||||
|
* The object. |
||||||
|
* @see GraphNode |
||||||
|
*/ |
||||||
|
object: ObjectNode; |
||||||
|
/** |
||||||
|
* The named graph. |
||||||
|
* @see GraphNode |
||||||
|
*/ |
||||||
|
graph: GraphNode; |
||||||
|
} |
||||||
|
|
||||||
|
export type QuadMatch = [ |
||||||
|
SubjectNode | undefined | null, |
||||||
|
PredicateNode | undefined | null, |
||||||
|
ObjectNode | undefined | null, |
||||||
|
GraphNode | undefined | null, |
||||||
|
]; |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* To String |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Subject Node to a String |
||||||
|
* @param node Input Node |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function subjectNodeToString(node: SubjectNode) { |
||||||
|
return nodeToString(node); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Predicate Node to a String |
||||||
|
* @param node Input Node |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function predicateNodeToString(node: PredicateNode) { |
||||||
|
return nodeToString(node); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Object Node to a String |
||||||
|
* @param node Input Node |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function objectNodeToString(node: ObjectNode) { |
||||||
|
return nodeToString(node); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Graph Node to a String |
||||||
|
* @param node Input Node |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function grpahNodeToString(node: GraphNode) { |
||||||
|
return nodeToString(node); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Any Node to a String |
||||||
|
* @param node Input Node |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function nodeToString(node: AnyNode): string { |
||||||
|
return termToString(node); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Quad to a String |
||||||
|
* @param node Input Quad |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function quadToString(quad: Quad): string { |
||||||
|
return JSON.stringify(quadToStringQuad(quad)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a Quad Match to a String |
||||||
|
* @param node Input Quad |
||||||
|
* @returns String Representation |
||||||
|
*/ |
||||||
|
export function quadMatchToString(quadMatch: QuadMatch): string { |
||||||
|
return JSON.stringify({ |
||||||
|
subject: quadMatch[0] ? subjectNodeToString(quadMatch[0]) : undefined, |
||||||
|
predicate: quadMatch[1] ? predicateNodeToString(quadMatch[1]) : undefined, |
||||||
|
object: quadMatch[2] ? objectNodeToString(quadMatch[2]) : undefined, |
||||||
|
graph: quadMatch[3] ? grpahNodeToString(quadMatch[3]) : undefined, |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* From String |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to a Subject Node |
||||||
|
* @param input String Inupt |
||||||
|
* @returns Node |
||||||
|
*/ |
||||||
|
export function stringToSubjectNode(input: string): SubjectNode { |
||||||
|
return stringToNode(input, SubjectTermTypes) as SubjectNode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to a Predicate Node |
||||||
|
* @param input String Inupt |
||||||
|
* @returns Node |
||||||
|
*/ |
||||||
|
export function stringToPredicateNode(input: string): PredicateNode { |
||||||
|
return stringToNode(input, PredicateTermTypes) as PredicateNode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to an Object Node |
||||||
|
* @param input String Inupt |
||||||
|
* @returns Node |
||||||
|
*/ |
||||||
|
export function stringToObjectNode(input: string): ObjectNode { |
||||||
|
return stringToNode(input, ObjectTermTypes) as ObjectNode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to a Graph Node |
||||||
|
* @param input String Inupt |
||||||
|
* @returns Node |
||||||
|
*/ |
||||||
|
export function stringToGraphNode(input: string): GraphNode { |
||||||
|
return stringToNode(input, GraphTermTypes) as GraphNode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to a Node |
||||||
|
* @param input String Inupt |
||||||
|
* @returns Node |
||||||
|
*/ |
||||||
|
export function stringToNode( |
||||||
|
input: string, |
||||||
|
expectTermType?: NodeTermTypes<Term>, |
||||||
|
): AnyNode { |
||||||
|
const node = stringToTerm(input); |
||||||
|
if (expectTermType && expectTermType.has(node.termType)) { |
||||||
|
throw new Error( |
||||||
|
`Expected term one of term type: [${Array.from(expectTermType).reduce( |
||||||
|
(agg, termType) => `${agg}${termType}, `, |
||||||
|
"", |
||||||
|
)}], but got ${node.termType}.`,
|
||||||
|
); |
||||||
|
} |
||||||
|
return node as AnyNode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to a Quad |
||||||
|
* @param input String Inupt |
||||||
|
* @returns Quad |
||||||
|
*/ |
||||||
|
export function stringToQuad(input: string) { |
||||||
|
return stringQuadToQuad(JSON.parse(input)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Converts a String to a Quad Match |
||||||
|
* @param input String Inupt |
||||||
|
* @returns QuadMatch |
||||||
|
*/ |
||||||
|
export function stringToQuadMatch(input: string) { |
||||||
|
const jsonRep = JSON.parse(input); |
||||||
|
return [ |
||||||
|
jsonRep.subject ? stringToSubjectNode(jsonRep.subject) : undefined, |
||||||
|
jsonRep.predicate ? stringToPredicateNode(jsonRep.predicate) : undefined, |
||||||
|
jsonRep.object ? stringToObjectNode(jsonRep.object) : undefined, |
||||||
|
jsonRep.graph ? stringToGraphNode(jsonRep.graph) : undefined, |
||||||
|
]; |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
{ |
||||||
|
"extends": "../../tsconfig.base.json", |
||||||
|
"compilerOptions": { |
||||||
|
"outDir": "./dist", |
||||||
|
"jsx": "react-jsx" |
||||||
|
}, |
||||||
|
"include": ["./src"] |
||||||
|
} |
@ -1,28 +0,0 @@ |
|||||||
import type { FunctionComponent, Context, PropsWithChildren } from "react"; |
|
||||||
import React, { createContext, useContext } from "react"; |
|
||||||
|
|
||||||
export function createGlobalHook<ReturnValues>(useHook: () => ReturnValues): { |
|
||||||
Provider: FunctionComponent<PropsWithChildren>; |
|
||||||
useGlobal: () => ReturnValues; |
|
||||||
Context: Context<ReturnValues>; |
|
||||||
} { |
|
||||||
// The initial value will be set immediately
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
const CreatedContext = createContext<ReturnValues>(undefined); |
|
||||||
|
|
||||||
const Provider: FunctionComponent<PropsWithChildren> = ({ children }) => { |
|
||||||
const returnValues = useHook(); |
|
||||||
return ( |
|
||||||
<CreatedContext.Provider value={returnValues}> |
|
||||||
{children} |
|
||||||
</CreatedContext.Provider> |
|
||||||
); |
|
||||||
}; |
|
||||||
|
|
||||||
const useGlobal = () => { |
|
||||||
return useContext(CreatedContext); |
|
||||||
}; |
|
||||||
|
|
||||||
return { Provider, useGlobal, Context: CreatedContext }; |
|
||||||
} |
|
@ -1,6 +0,0 @@ |
|||||||
import { useState } from "react"; |
|
||||||
|
|
||||||
export function useForceUpdate() { |
|
||||||
const [, setValue] = useState(0); |
|
||||||
return () => setValue((value) => value + 1); |
|
||||||
} |
|
@ -0,0 +1,3 @@ |
|||||||
|
{ |
||||||
|
"extends": ["../../.eslintrc"] |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
# Solid-Dataset |
||||||
|
|
||||||
|
Pre-alpha |
||||||
|
|
||||||
|
## Notes: |
||||||
|
- Any quads in the default graph will not be synced to Solid Pods, but will be added to the dataset without any syncing |
||||||
|
|
||||||
|
|
||||||
|
## TODO: |
||||||
|
- Create an event for each thing that happens. Like "Loaded" |
||||||
|
- You should be able to initialize classes with loading = true so that there isn't a flash on initial load |
||||||
|
- Access rule stuff just doesn't work. I might need to program a custom implementation for that |
||||||
|
- There should probably be separate libraries for React native and Web React |
@ -0,0 +1,6 @@ |
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
const sharedConfig = require("../../jest.config.js"); |
||||||
|
module.exports = { |
||||||
|
...sharedConfig, |
||||||
|
rootDir: "./", |
||||||
|
}; |
@ -0,0 +1,39 @@ |
|||||||
|
{ |
||||||
|
"name": "@ldo/solid", |
||||||
|
"version": "0.0.0", |
||||||
|
"description": "A library for LDO and Solid", |
||||||
|
"main": "dist/index.js", |
||||||
|
"scripts": { |
||||||
|
"build": "tsc --project tsconfig.build.json", |
||||||
|
"watch": "tsc --watch", |
||||||
|
"test": "jest --coverage", |
||||||
|
"test:watch": "jest --watch", |
||||||
|
"prepublishOnly": "npm run test && npm run build", |
||||||
|
"build:ldo": "ldo build --input src/shapes --output src/ldo", |
||||||
|
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern" |
||||||
|
}, |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/o-development/devtool-boilerplate.git" |
||||||
|
}, |
||||||
|
"author": "Jackson Morgan", |
||||||
|
"license": "MIT", |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/o-development/devtool-boilerplate/issues" |
||||||
|
}, |
||||||
|
"homepage": "https://github.com/o-development/devtool-boilerplate#readme", |
||||||
|
"devDependencies": { |
||||||
|
"@ldo/cli": "^0.0.0", |
||||||
|
"@ldo/jsonld-dataset-proxy": "^0.0.0", |
||||||
|
"@rdfjs/types": "^1.1.0", |
||||||
|
"@types/jest": "^29.0.3", |
||||||
|
"ts-jest": "^29.0.2" |
||||||
|
}, |
||||||
|
"dependencies": { |
||||||
|
"@inrupt/solid-client": "^1.29.0", |
||||||
|
"@ldo/dataset": "^0.0.0", |
||||||
|
"@ldo/ldo": "^0.0.0", |
||||||
|
"@ldo/subscribable-dataset": "^0.0.0", |
||||||
|
"cross-fetch": "^3.1.6" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
import { LdoDataset } from "@ldo/ldo"; |
||||||
|
import type { DataResource } from "./document/resource/dataResource/DataResource"; |
||||||
|
import type { ContainerResource } from "./document/resource/dataResource/containerResource/ContainerResource"; |
||||||
|
import type { AccessRules } from "./document/accessRules/AccessRules"; |
||||||
|
import type { BinaryResource } from "./document/resource/binaryResource/BinaryResource"; |
||||||
|
import type { DocumentGetterOptions } from "./document/DocumentStore"; |
||||||
|
import type { DataResourceStore } from "./document/resource/dataResource/DataResourceStore"; |
||||||
|
import type { ContainerResourceStore } from "./document/resource/dataResource/containerResource/ContainerResourceStore"; |
||||||
|
import type { AccessRulesStore } from "./document/accessRules/AccessRulesStore"; |
||||||
|
import type { BinaryResourceStore } from "./document/resource/binaryResource/BinaryResourceStore"; |
||||||
|
import type { Dataset, DatasetFactory } from "@rdfjs/types"; |
||||||
|
import type { Resource } from "./document/resource/Resource"; |
||||||
|
import { DocumentError } from "./document/errors/DocumentError"; |
||||||
|
|
||||||
|
export interface SolidLdoDatasetArgs { |
||||||
|
dataResourceStore: DataResourceStore; |
||||||
|
containerResourceStore: ContainerResourceStore; |
||||||
|
accessRulesStore: AccessRulesStore; |
||||||
|
binaryResourceStore: BinaryResourceStore; |
||||||
|
initialDataset?: Dataset; |
||||||
|
datasetFactory: DatasetFactory; |
||||||
|
} |
||||||
|
|
||||||
|
export class SolidLdoDataset extends LdoDataset { |
||||||
|
protected dataResourceStore: DataResourceStore; |
||||||
|
protected containerResourceStore: ContainerResourceStore; |
||||||
|
protected accessRulesStore: AccessRulesStore; |
||||||
|
protected binaryResourceStore: BinaryResourceStore; |
||||||
|
|
||||||
|
constructor(args: SolidLdoDatasetArgs) { |
||||||
|
super(args.datasetFactory, args.initialDataset); |
||||||
|
this.dataResourceStore = args.dataResourceStore; |
||||||
|
this.containerResourceStore = args.containerResourceStore; |
||||||
|
this.accessRulesStore = args.accessRulesStore; |
||||||
|
this.binaryResourceStore = args.binaryResourceStore; |
||||||
|
} |
||||||
|
|
||||||
|
getDataResource(uri: string, options?: DocumentGetterOptions): DataResource { |
||||||
|
return this.dataResourceStore.get(uri, options); |
||||||
|
} |
||||||
|
|
||||||
|
getContainerResource( |
||||||
|
uri: string, |
||||||
|
options?: DocumentGetterOptions, |
||||||
|
): ContainerResource { |
||||||
|
return this.containerResourceStore.get(uri, options); |
||||||
|
} |
||||||
|
|
||||||
|
getAccessRules( |
||||||
|
forResource: string | Resource, |
||||||
|
options?: DocumentGetterOptions, |
||||||
|
): AccessRules { |
||||||
|
const resourceIdentifier = |
||||||
|
typeof forResource === "string" |
||||||
|
? this.getDataResource(forResource) |
||||||
|
: forResource; |
||||||
|
return this.accessRulesStore.get(resourceIdentifier, options); |
||||||
|
} |
||||||
|
|
||||||
|
getBinaryResource( |
||||||
|
uri: string, |
||||||
|
options?: DocumentGetterOptions, |
||||||
|
): BinaryResource { |
||||||
|
return this.binaryResourceStore.get(uri, options); |
||||||
|
} |
||||||
|
|
||||||
|
onDocumentError(_callback: (error: DocumentError) => void): void { |
||||||
|
throw new Error("Not Implemented"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
import { SolidLdoDataset } from "./SolidLdoDataset"; |
||||||
|
|
||||||
|
export function createSolidLdoDataset(): SolidLdoDataset { |
||||||
|
throw new Error("Not Implemented"); |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
// document
|
||||||
|
export * from "./document/FetchableDocument"; |
||||||
|
export * from "./document/DocumentStore"; |
||||||
|
|
||||||
|
// document/errors
|
||||||
|
export * from "./document/errors/DocumentError"; |
||||||
|
export * from "./document/errors/DocumentFetchError"; |
||||||
|
|
||||||
|
// document/accessRules
|
||||||
|
export * from "./document/accessRules/AccessRules"; |
||||||
|
export * from "./document/accessRules/AccessRulesStore"; |
||||||
|
|
||||||
|
// document/resource
|
||||||
|
export * from "./document/resource/Resource"; |
||||||
|
|
||||||
|
// document/resource/binaryResource
|
||||||
|
export * from "./document/resource/binaryResource/BinaryResource"; |
||||||
|
export * from "./document/resource/binaryResource/BinaryResourceStore"; |
||||||
|
|
||||||
|
// document/resource/dataResource
|
||||||
|
export * from "./document/resource/dataResource/DataResource"; |
||||||
|
export * from "./document/resource/dataResource/DataResourceStore"; |
||||||
|
|
||||||
|
// document/resource/containerResource
|
||||||
|
export * from "./document/resource/dataResource/containerResource/ContainerResource"; |
||||||
|
export * from "./document/resource/dataResource/containerResource/ContainerResourceStore"; |
@ -0,0 +1,36 @@ |
|||||||
|
import type { ContextDefinition } from "jsonld"; |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* solidContext: JSONLD Context for solid |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
export const solidContext: ContextDefinition = { |
||||||
|
type: { |
||||||
|
"@id": "@type", |
||||||
|
"@container": "@set", |
||||||
|
}, |
||||||
|
Container: "http://www.w3.org/ns/ldp#Container", |
||||||
|
Resource: "http://www.w3.org/ns/ldp#Resource", |
||||||
|
modified: { |
||||||
|
"@id": "http://purl.org/dc/terms/modified", |
||||||
|
"@type": "http://www.w3.org/2001/XMLSchema#string", |
||||||
|
"@container": "@set", |
||||||
|
}, |
||||||
|
contains: { |
||||||
|
"@id": "http://www.w3.org/ns/ldp#contains", |
||||||
|
"@type": "@id", |
||||||
|
"@container": "@set", |
||||||
|
}, |
||||||
|
Resource2: "http://www.w3.org/ns/iana/media-types/text/turtle#Resource", |
||||||
|
mtime: { |
||||||
|
"@id": "http://www.w3.org/ns/posix/stat#mtime", |
||||||
|
"@type": "http://www.w3.org/2001/XMLSchema#decimal", |
||||||
|
"@container": "@set", |
||||||
|
}, |
||||||
|
size: { |
||||||
|
"@id": "http://www.w3.org/ns/posix/stat#size", |
||||||
|
"@type": "http://www.w3.org/2001/XMLSchema#integer", |
||||||
|
"@container": "@set", |
||||||
|
}, |
||||||
|
}; |
@ -0,0 +1,214 @@ |
|||||||
|
import type { Schema } from "shexj"; |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* solidSchema: ShexJ Schema for solid |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
export const solidSchema: Schema = { |
||||||
|
type: "Schema", |
||||||
|
shapes: [ |
||||||
|
{ |
||||||
|
id: "http://www.w3.org/ns/lddps#Container", |
||||||
|
type: "ShapeDecl", |
||||||
|
shapeExpr: { |
||||||
|
type: "Shape", |
||||||
|
expression: { |
||||||
|
id: "http://www.w3.org/ns/lddps#ContainerShape", |
||||||
|
type: "EachOf", |
||||||
|
expressions: [ |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
values: [ |
||||||
|
"http://www.w3.org/ns/ldp#Container", |
||||||
|
"http://www.w3.org/ns/ldp#Resource", |
||||||
|
], |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: -1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "A container on a Solid server", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://purl.org/dc/terms/modified", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
datatype: "http://www.w3.org/2001/XMLSchema#string", |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: 1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "Date modified", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/ns/ldp#contains", |
||||||
|
valueExpr: "http://www.w3.org/ns/lddps#Resource", |
||||||
|
min: 0, |
||||||
|
max: -1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "Defines a Solid Resource", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/ns/posix/stat#mtime", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
datatype: "http://www.w3.org/2001/XMLSchema#decimal", |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: 1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "?", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/ns/posix/stat#size", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
datatype: "http://www.w3.org/2001/XMLSchema#integer", |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: 1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "size of this container", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
extra: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
id: "http://www.w3.org/ns/lddps#Resource", |
||||||
|
type: "ShapeDecl", |
||||||
|
shapeExpr: { |
||||||
|
type: "Shape", |
||||||
|
expression: { |
||||||
|
id: "http://www.w3.org/ns/lddps#ResourceShape", |
||||||
|
type: "EachOf", |
||||||
|
expressions: [ |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
values: [ |
||||||
|
"http://www.w3.org/ns/ldp#Resource", |
||||||
|
"http://www.w3.org/ns/iana/media-types/text/turtle#Resource", |
||||||
|
], |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: -1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "Any resource on a Solid server", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://purl.org/dc/terms/modified", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
datatype: "http://www.w3.org/2001/XMLSchema#string", |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: 1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "Date modified", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/ns/posix/stat#mtime", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
datatype: "http://www.w3.org/2001/XMLSchema#decimal", |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: 1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "?", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: "TripleConstraint", |
||||||
|
predicate: "http://www.w3.org/ns/posix/stat#size", |
||||||
|
valueExpr: { |
||||||
|
type: "NodeConstraint", |
||||||
|
datatype: "http://www.w3.org/2001/XMLSchema#integer", |
||||||
|
}, |
||||||
|
min: 0, |
||||||
|
max: 1, |
||||||
|
annotations: [ |
||||||
|
{ |
||||||
|
type: "Annotation", |
||||||
|
predicate: "http://www.w3.org/2000/01/rdf-schema#comment", |
||||||
|
object: { |
||||||
|
value: "size of this container", |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
extra: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}; |
@ -0,0 +1,28 @@ |
|||||||
|
import type { ShapeType } from "@ldo/ldo"; |
||||||
|
import { solidSchema } from "./solid.schema"; |
||||||
|
import { solidContext } from "./solid.context"; |
||||||
|
import type { Container, Resource } from "./solid.typings"; |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* LDO ShapeTypes solid |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Container ShapeType |
||||||
|
*/ |
||||||
|
export const ContainerShapeType: ShapeType<Container> = { |
||||||
|
schema: solidSchema, |
||||||
|
shape: "http://www.w3.org/ns/lddps#Container", |
||||||
|
context: solidContext, |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Resource ShapeType |
||||||
|
*/ |
||||||
|
export const ResourceShapeType: ShapeType<Resource> = { |
||||||
|
schema: solidSchema, |
||||||
|
shape: "http://www.w3.org/ns/lddps#Resource", |
||||||
|
context: solidContext, |
||||||
|
}; |
@ -0,0 +1,73 @@ |
|||||||
|
import type { ContextDefinition } from "jsonld"; |
||||||
|
|
||||||
|
/** |
||||||
|
* ============================================================================= |
||||||
|
* Typescript Typings for solid |
||||||
|
* ============================================================================= |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Container Type |
||||||
|
*/ |
||||||
|
export interface Container { |
||||||
|
"@id"?: string; |
||||||
|
"@context"?: ContextDefinition; |
||||||
|
/** |
||||||
|
* A container on a Solid server |
||||||
|
*/ |
||||||
|
type?: ( |
||||||
|
| { |
||||||
|
"@id": "Container"; |
||||||
|
} |
||||||
|
| { |
||||||
|
"@id": "Resource"; |
||||||
|
} |
||||||
|
)[]; |
||||||
|
/** |
||||||
|
* Date modified |
||||||
|
*/ |
||||||
|
modified?: string; |
||||||
|
/** |
||||||
|
* Defines a Solid Resource |
||||||
|
*/ |
||||||
|
contains?: Resource[]; |
||||||
|
/** |
||||||
|
* ? |
||||||
|
*/ |
||||||
|
mtime?: number; |
||||||
|
/** |
||||||
|
* size of this container |
||||||
|
*/ |
||||||
|
size?: number; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Resource Type |
||||||
|
*/ |
||||||
|
export interface Resource { |
||||||
|
"@id"?: string; |
||||||
|
"@context"?: ContextDefinition; |
||||||
|
/** |
||||||
|
* Any resource on a Solid server |
||||||
|
*/ |
||||||
|
type?: ( |
||||||
|
| { |
||||||
|
"@id": "Resource"; |
||||||
|
} |
||||||
|
| { |
||||||
|
"@id": "Resource2"; |
||||||
|
} |
||||||
|
)[]; |
||||||
|
/** |
||||||
|
* Date modified |
||||||
|
*/ |
||||||
|
modified?: string; |
||||||
|
/** |
||||||
|
* ? |
||||||
|
*/ |
||||||
|
mtime?: number; |
||||||
|
/** |
||||||
|
* size of this container |
||||||
|
*/ |
||||||
|
size?: number; |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> |
||||||
|
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
||||||
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
||||||
|
PREFIX ldp: <http://www.w3.org/ns/ldp#> |
||||||
|
PREFIX ldps: <http://www.w3.org/ns/lddps#> |
||||||
|
PREFIX dct: <http://purl.org/dc/terms/> |
||||||
|
PREFIX stat: <http://www.w3.org/ns/posix/stat#> |
||||||
|
PREFIX tur: <http://www.w3.org/ns/iana/media-types/text/turtle#> |
||||||
|
|
||||||
|
ldps:Container EXTRA a { |
||||||
|
$ldps:ContainerShape ( |
||||||
|
a [ ldp:Container ldp:Resource ]* |
||||||
|
// rdfs:comment "A container on a Solid server"; |
||||||
|
dct:modified xsd:string? |
||||||
|
// rdfs:comment "Date modified"; |
||||||
|
ldp:contains @ldps:Resource* |
||||||
|
// rdfs:comment "Defines a Solid Resource"; |
||||||
|
stat:mtime xsd:decimal? |
||||||
|
// rdfs:comment "?"; |
||||||
|
stat:size xsd:integer? |
||||||
|
// rdfs:comment "size of this container"; |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
ldps:Resource EXTRA a { |
||||||
|
$ldps:ResourceShape ( |
||||||
|
a [ ldp:Resource tur:Resource ]* |
||||||
|
// rdfs:comment "Any resource on a Solid server"; |
||||||
|
dct:modified xsd:string? |
||||||
|
// rdfs:comment "Date modified"; |
||||||
|
stat:mtime xsd:decimal? |
||||||
|
// rdfs:comment "?"; |
||||||
|
stat:size xsd:integer? |
||||||
|
// rdfs:comment "size of this container"; |
||||||
|
) |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
describe("Trivial", () => { |
||||||
|
it("Trivial", () => { |
||||||
|
expect(true).toBe(true); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1,8 @@ |
|||||||
|
{ |
||||||
|
"extends": "../../tsconfig.base.json", |
||||||
|
"compilerOptions": { |
||||||
|
"outDir": "./dist", |
||||||
|
"jsx": "react-jsx" |
||||||
|
}, |
||||||
|
"include": ["./src"] |
||||||
|
} |
Loading…
Reference in new issue