Created rdf-utils

main
jaxoncreed 2 years ago
parent 8f45f4b950
commit d19437b34f
  1. 9474
      package-lock.json
  2. 8
      packages/dataset/package.json
  3. 12
      packages/jsonld-dataset-proxy/src/types.ts
  4. 3
      packages/rdf-utils/.eslintrc
  5. 6
      packages/rdf-utils/jest.config.js
  6. 33
      packages/rdf-utils/package.json
  7. 20
      packages/rdf-utils/src/datasetChanges.ts
  8. 60
      packages/rdf-utils/src/datasetConverters.ts
  9. 5
      packages/rdf-utils/src/index.ts
  10. 245
      packages/rdf-utils/src/nodeSerialization.ts
  11. 0
      packages/rdf-utils/src/serializedToQuad.ts
  12. 8
      packages/rdf-utils/tsconfig.build.json
  13. 4
      packages/schema-converter-shex/package.json
  14. 2
      packages/solid-react/package.json
  15. 28
      packages/solid-react/src/util/createGlobalHook.tsx
  16. 6
      packages/solid-react/src/util/useForceReload.ts
  17. 3
      packages/solid/.eslintrc
  18. 13
      packages/solid/README.md
  19. 6
      packages/solid/jest.config.js
  20. 39
      packages/solid/package.json
  21. 70
      packages/solid/src/SolidLdoDataset.ts
  22. 5
      packages/solid/src/createSolidLdoDataset.ts
  23. 19
      packages/solid/src/document/DocumentStore.ts
  24. 17
      packages/solid/src/document/FetchableDocument.ts
  25. 0
      packages/solid/src/document/accessRules/AccessRules.ts
  26. 15
      packages/solid/src/document/accessRules/AccessRulesStore.ts
  27. 0
      packages/solid/src/document/errors/DocumentError.ts
  28. 0
      packages/solid/src/document/errors/DocumentFetchError.ts
  29. 0
      packages/solid/src/document/resource/Resource.ts
  30. 0
      packages/solid/src/document/resource/binaryResource/BinaryResource.ts
  31. 15
      packages/solid/src/document/resource/binaryResource/BinaryResourceStore.ts
  32. 6
      packages/solid/src/document/resource/dataResource/DataResource.ts
  33. 15
      packages/solid/src/document/resource/dataResource/DataResourceStore.ts
  34. 0
      packages/solid/src/document/resource/dataResource/containerResource/ContainerResource.ts
  35. 15
      packages/solid/src/document/resource/dataResource/containerResource/ContainerResourceStore.ts
  36. 26
      packages/solid/src/index.ts
  37. 36
      packages/solid/src/ldo/solid.context.ts
  38. 214
      packages/solid/src/ldo/solid.schema.ts
  39. 28
      packages/solid/src/ldo/solid.shapeTypes.ts
  40. 73
      packages/solid/src/ldo/solid.typings.ts
  41. 36
      packages/solid/src/shapes/solid.shex
  42. 0
      packages/solid/src/util/splitChangesByGraph.ts
  43. 5
      packages/solid/test/trivial.test.ts
  44. 8
      packages/solid/tsconfig.build.json
  45. 37
      packages/subscribable-dataset/src/types.ts
  46. 2
      tsconfig.base.json

9474
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -24,10 +24,8 @@
},
"homepage": "https://github.com/o-development/o-dataset-pack#readme",
"devDependencies": {
"@rdfjs/types": "^1.0.1",
"@types/jest": "^27.0.3",
"@types/jsonld": "^1.5.6",
"@types/n3": "^1.10.4",
"@types/rdfjs__dataset": "^1.0.4",
"@types/readable-stream": "^2.3.13",
"jest": "^27.4.5",
@ -35,13 +33,9 @@
"ts-node": "^9.1.1"
},
"dependencies": {
"@rdfjs/data-model": "^1.2.0",
"@ldo/rdf-utils": "^0.0.0",
"@rdfjs/dataset": "^1.1.0",
"buffer": "^6.0.3",
"n3": "^1.10.0",
"readable-stream": "^4.2.0"
},
"overrides": {
"readable-stream": "^4.2.0"
},
"files": [

@ -11,15 +11,3 @@ export const _writeGraphs = Symbol("_writeGraphs");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ObjectLike = Record<string | number | symbol, any>;
export type SubjectType = NamedNode | BlankNode;
export type PredicateType = NamedNode;
export type ObjectType = NamedNode | BlankNode | Literal;
export type GraphType = NamedNode | BlankNode | DefaultGraph;
export type QuadMatch = [
SubjectType | undefined | null,
PredicateType | undefined | null,
ObjectType | undefined | null,
GraphType | undefined | null,
];

@ -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 { datasetToString } from "@ldo/ldo";
import type { Quad } from "@rdfjs/types";
import type { BaseQuad, Dataset, Quad } from "@rdfjs/types";
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>) {
let output = "";
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"]
}

@ -33,8 +33,8 @@
"dist"
],
"dependencies": {
"@ldo/traverser-shexj": "^0.0.0",
"dts-dom": "^3.6.0",
"jsonld2graphobject": "^0.0.5",
"shexj-traverser": "^2.0.1"
"jsonld2graphobject": "^0.0.5"
}
}

@ -26,7 +26,6 @@
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.11",
"@ldo/cli": "^0.0.0",
"@rdfjs/types": "^1.1.0",
"@types/jest": "^29.0.3",
"@types/jsonld": "^1.5.8",
@ -39,6 +38,7 @@
"@ldo/dataset": "^0.0.0",
"@ldo/jsonld-dataset-proxy": "^0.0.0",
"@ldo/ldo": "^0.0.0",
"@ldo/solid": "^0.0.0",
"@ldo/subscribable-dataset": "^0.0.0",
"cross-fetch": "^3.1.6",
"solid-authn-react-native": "^2.0.3",

@ -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");
}

@ -4,6 +4,10 @@ import type { FetchableDocument } from "./FetchableDocument";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DocumentStoreDependencies {}
export interface DocumentGetterOptions {
autoLoad?: boolean;
}
export abstract class DocumentStore<
DocumentType extends FetchableDocument,
Initializer,
@ -17,18 +21,27 @@ export abstract class DocumentStore<
this.dependencies = dependencies;
}
get(initializerInput: Initializer): DocumentType {
get(
initializerInput: Initializer,
options?: DocumentGetterOptions,
): DocumentType {
const initializer = this.normalizeInitializer(initializerInput);
const document = this.documentMap.get(initializer);
if (document) {
if (options?.autoLoad) {
document.reload();
}
return document;
}
const newDocument = this.create(initializer);
const newDocument = this.create(initializer, options);
this.documentMap.set(initializer, newDocument);
return newDocument;
}
protected abstract create(initializer: Initializer): DocumentType;
protected abstract create(
initializer: Initializer,
options?: DocumentGetterOptions,
): DocumentType;
protected normalizeInitializer(initializer: Initializer): Initializer {
return initializer;

@ -1,8 +1,10 @@
import EventEmitter from "events";
import type { DocumentError } from "./errors/DocumentError";
import type { DocumentGetterOptions } from "./DocumentStore";
export interface FetchableDocumentDependencies {
onDocumentError?: (error: DocumentError) => void;
documentGetterOptions?: DocumentGetterOptions;
}
const STATE_UPDATE = "stateUpdate";
@ -12,7 +14,7 @@ export abstract class FetchableDocument extends EventEmitter {
protected _isWriting: boolean;
protected _didInitialFetch: boolean;
protected _error?: DocumentError;
private dependencies;
private dependencies: FetchableDocumentDependencies;
constructor(dependencies: FetchableDocumentDependencies) {
super();
@ -20,6 +22,11 @@ export abstract class FetchableDocument extends EventEmitter {
this._isWriting = false;
this._didInitialFetch = false;
this.dependencies = dependencies;
// Trigger load if autoload is true
if (this.dependencies.documentGetterOptions?.autoLoad) {
this._isLoading = true;
this.read();
}
}
/**
* ===========================================================================
@ -34,6 +41,14 @@ export abstract class FetchableDocument extends EventEmitter {
return this._didInitialFetch;
}
get isLoadingInitial() {
return this._isLoading && !this._didInitialFetch;
}
get isReloading() {
return this._isLoading && this._didInitialFetch;
}
get error() {
return this._error;
}

@ -1,4 +1,7 @@
import type { DocumentStoreDependencies } from "../DocumentStore";
import type {
DocumentGetterOptions,
DocumentStoreDependencies,
} from "../DocumentStore";
import { DocumentStore } from "../DocumentStore";
import type { Resource } from "../resource/Resource";
import type { AccessRulesDependencies } from "./AccessRules";
@ -13,7 +16,13 @@ export class AccessRulesStore extends DocumentStore<
Resource,
AccessRulesStoreDependencies
> {
create(initializer: Resource) {
return new AccessRules(initializer, this.dependencies);
protected create(
initializer: Resource,
documentGetterOptions: DocumentGetterOptions,
) {
return new AccessRules(initializer, {
...this.dependencies,
documentGetterOptions,
});
}
}

@ -1,4 +1,7 @@
import type { DocumentStoreDependencies } from "../../DocumentStore";
import type {
DocumentGetterOptions,
DocumentStoreDependencies,
} from "../../DocumentStore";
import { DocumentStore } from "../../DocumentStore";
import type { BinaryResourceDependencies } from "./BinaryResource";
import { BinaryResource } from "./BinaryResource";
@ -12,8 +15,14 @@ export class BinaryResourceStore extends DocumentStore<
string,
BinaryResourceStoreDependencies
> {
create(initializer: string) {
return new BinaryResource(initializer, this.dependencies);
protected create(
initializer: string,
documentGetterOptions: DocumentGetterOptions,
) {
return new BinaryResource(initializer, {
...this.dependencies,
documentGetterOptions,
});
}
protected normalizeInitializer(initializer: string): string {

@ -1,4 +1,3 @@
import type { LdoDataset } from "@ldo/ldo";
import { parseRdf } from "@ldo/ldo";
import type { ResourceDependencies } from "../Resource";
import { Resource } from "../Resource";
@ -8,11 +7,10 @@ import { namedNode, quad as createQuad } from "@rdfjs/data-model";
import type { DatasetChanges } from "@ldo/subscribable-dataset";
import type { Quad } from "@rdfjs/types";
import { changesToSparqlUpdate } from "../../../util/changesToSparqlUpdate";
import type { UpdateManager } from "../../../ldoHooks/helpers/UpdateManager";
import type { SolidLdoDataset } from "../../../SolidLdoDataset";
export interface DataResourceDependencies extends ResourceDependencies {
dataset: LdoDataset;
updateManager: UpdateManager;
dataset: SolidLdoDataset;
}
export class DataResource extends Resource {

@ -1,4 +1,7 @@
import type { DocumentStoreDependencies } from "../../DocumentStore";
import type {
DocumentGetterOptions,
DocumentStoreDependencies,
} from "../../DocumentStore";
import { DocumentStore } from "../../DocumentStore";
import type { DataResourceDependencies } from "./DataResource";
import { DataResource } from "./DataResource";
@ -12,8 +15,14 @@ export class DataResourceStore extends DocumentStore<
string,
DataResourceStoreDependencies
> {
protected create(initializer: string) {
return new DataResource(initializer, this.dependencies);
protected create(
initializer: string,
documentGetterOptions: DocumentGetterOptions,
) {
return new DataResource(initializer, {
...this.dependencies,
documentGetterOptions,
});
}
protected normalizeInitializer(initializer: string): string {

@ -1,4 +1,7 @@
import type { DocumentStoreDependencies } from "../../../DocumentStore";
import type {
DocumentGetterOptions,
DocumentStoreDependencies,
} from "../../../DocumentStore";
import { DocumentStore } from "../../../DocumentStore";
import type { Resource } from "../../Resource";
import type { ContainerResourceDependencies } from "./ContainerResource";
@ -13,8 +16,14 @@ export class ContainerResourceStore extends DocumentStore<
string,
ContainerResourceStoreDependencies
> {
protected create(initializer: string) {
return new ContainerResource(initializer, this.dependencies);
protected create(
initializer: string,
documentGetterOptions: DocumentGetterOptions,
) {
return new ContainerResource(initializer, {
...this.dependencies,
documentGetterOptions,
});
}
protected normalizeInitializer(initializer: string) {

@ -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"]
}

@ -5,18 +5,7 @@ import type {
DefaultGraph,
BaseQuad,
} from "@rdfjs/types";
/**
* An interface representing the changes made
*/
export interface DatasetChanges<InAndOutQuad extends BaseQuad = BaseQuad> {
added?: Dataset<InAndOutQuad, InAndOutQuad>;
removed?: Dataset<InAndOutQuad, InAndOutQuad>;
}
/**
* Types of nodes a subscribable dataset can subscribe to
*/
export type SubscribableTerms = NamedNode | BlankNode | DefaultGraph;
/**
* An event listeners for nodes
@ -58,7 +47,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* @returns
*/
addListener(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -70,7 +59,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* @returns true if the event had listeners, false otherwise.
*/
emit(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
dataset: Dataset<InAndOutQuad, InAndOutQuad>,
datasetChanges: DatasetChanges<InAndOutQuad>,
): boolean;
@ -78,7 +67,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
/**
* Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.
*/
eventNames(): SubscribableTerms[];
eventNames(): DatasetEventMatch[];
/**
* Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to events.defaultMaxListeners.
@ -88,18 +77,18 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
/**
* Returns the number of listeners listening to the event named eventName.
*/
listenerCount(eventName: SubscribableTerms): number;
listenerCount(eventName: DatasetEventMatch): number;
/**
* Returns a copy of the array of listeners for the event named eventName.
*/
listeners(eventName: SubscribableTerms): nodeEventListener<InAndOutQuad>[];
listeners(eventName: DatasetEventMatch): nodeEventListener<InAndOutQuad>[];
/**
* Alias for emitter.removeListener()
*/
off(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): void;
@ -107,7 +96,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
*/
on(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -115,7 +104,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.
*/
once(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -123,7 +112,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
*/
prependListener(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -131,20 +120,20 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.
*/
prependOnceListener(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
/**
* Removes all listeners, or those of the specified eventName.
*/
removeAllListeners(eventName: SubscribableTerms): this;
removeAllListeners(eventName: DatasetEventMatch): this;
/**
* Removes the specified listener from the listener array for the event named eventName.
*/
removeListener(
eventName: SubscribableTerms,
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -156,7 +145,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
/**
* Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).
*/
rawListeners(eventName: SubscribableTerms): nodeEventListener<InAndOutQuad>[];
rawListeners(eventName: DatasetEventMatch): nodeEventListener<InAndOutQuad>[];
/**
* ==================================================================

@ -7,7 +7,7 @@
"esModuleInterop": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"lib": ["ES2021"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES2021",

Loading…
Cancel
Save