Added rdf-util

main
jaxoncreed 2 years ago
parent d19437b34f
commit d78858dbbc
  1. 621
      package-lock.json
  2. 3
      package.json
  3. 4
      packages/dataset/example/extendedDatasetExample.ts
  4. 9
      packages/dataset/example/loadDataExample.ts
  5. 187
      packages/dataset/example/subscribableDatasetExample.ts
  6. 1
      packages/dataset/package.json
  7. 23
      packages/dataset/src/ExtendedDataset.ts
  8. 2
      packages/dataset/src/ExtendedDatasetFactory.ts
  9. 43
      packages/dataset/src/createDatasetFromSerializedInput.ts
  10. 4
      packages/dataset/src/createExtendedDataset.ts
  11. 3
      packages/dataset/src/createExtendedDatasetFromSerializedInput.ts
  12. 2
      packages/dataset/test/createExtendedDataset.test.ts
  13. 15
      packages/dataset/test/dataset.testHelper.ts
  14. 3
      packages/jsonld-dataset-proxy/package.json
  15. 13
      packages/jsonld-dataset-proxy/src/JsonldDatasetProxyBuilder.ts
  16. 13
      packages/jsonld-dataset-proxy/src/ProxyContext.ts
  17. 5
      packages/jsonld-dataset-proxy/src/arrayProxy/ArrayProxy.ts
  18. 20
      packages/jsonld-dataset-proxy/src/arrayProxy/createArrayHandler.ts
  19. 7
      packages/jsonld-dataset-proxy/src/arrayProxy/modifyArray.ts
  20. 11
      packages/jsonld-dataset-proxy/src/graphOf.ts
  21. 4
      packages/jsonld-dataset-proxy/src/jsonldDatasetProxy.ts
  22. 8
      packages/jsonld-dataset-proxy/src/language/languageMapProxy.ts
  23. 18
      packages/jsonld-dataset-proxy/src/language/languageSet.ts
  24. 19
      packages/jsonld-dataset-proxy/src/language/languageUtils.ts
  25. 2
      packages/jsonld-dataset-proxy/src/language/languagesOf.ts
  26. 5
      packages/jsonld-dataset-proxy/src/subjectProxy/SubjectProxy.ts
  27. 4
      packages/jsonld-dataset-proxy/src/subjectProxy/createSubjectHandler.ts
  28. 4
      packages/jsonld-dataset-proxy/src/subjectProxy/deleteFromDataset.ts
  29. 2
      packages/jsonld-dataset-proxy/src/subjectProxy/getValueForKey.ts
  30. 2
      packages/jsonld-dataset-proxy/src/types.ts
  31. 17
      packages/jsonld-dataset-proxy/src/util/NodeSet.ts
  32. 2
      packages/jsonld-dataset-proxy/src/util/RawObject.ts
  33. 4
      packages/jsonld-dataset-proxy/src/util/addObjectToDataset.ts
  34. 4
      packages/jsonld-dataset-proxy/src/util/getNodeFromRaw.ts
  35. 2
      packages/jsonld-dataset-proxy/src/util/nodeToJsonldRepresentation.ts
  36. 4
      packages/jsonld-dataset-proxy/test/jsonldDatasetProxy.test.ts
  37. 2
      packages/jsonld-dataset-proxy/test/nodeToJsonRepresentation.test.ts
  38. 2
      packages/jsonld-dataset-proxy/test/nodeToString.test.ts
  39. 3
      packages/ldo/README.md
  40. 4
      packages/ldo/package.json
  41. 2
      packages/ldo/src/LdoDataset.ts
  42. 2
      packages/ldo/src/LdoDatasetFactory.ts
  43. 2
      packages/ldo/src/createLdoDataset.ts
  44. 52
      packages/ldo/src/datasetConverters.ts
  45. 31
      packages/ldo/src/methods.ts
  46. 4
      packages/ldo/src/parseRdf.ts
  47. 32
      packages/ldo/src/util.ts
  48. 2
      packages/ldo/test/LdoDataset.test.ts
  49. 2
      packages/ldo/test/methods.test.ts
  50. 2
      packages/rdf-utils/package.json
  51. 27
      packages/rdf-utils/src/datasetConverters.ts
  52. 1
      packages/rdf-utils/src/index.ts
  53. 0
      packages/rdf-utils/src/serializedToQuad.ts
  54. 43
      packages/rdf-utils/src/serializedToQuads.ts
  55. 1
      packages/solid-react/package.json
  56. 6
      packages/solid-react/src/LdoProvider.tsx
  57. 8
      packages/solid-react/src/ldoHooks/helpers/TrackingProxyContext.ts
  58. 66
      packages/solid-react/src/ldoHooks/helpers/UpdateManager.ts
  59. 6
      packages/solid-react/src/ldoHooks/useSubject.ts
  60. 5
      packages/solid-react/src/useLdo.ts
  61. 5
      packages/solid/package.json
  62. 4
      packages/solid/src/SolidLdoDataset.ts
  63. 32
      packages/solid/src/createSolidLdoDataset.ts
  64. 10
      packages/solid/src/document/resource/dataResource/DataResource.ts
  65. 18
      packages/solid/src/util/splitChangesByGraph.ts
  66. 65
      packages/subscribable-dataset/example/extendedDatasetExample.ts
  67. 45
      packages/subscribable-dataset/example/loadDataExample.ts
  68. 5
      packages/subscribable-dataset/example/subscribableDatasetExample.ts
  69. 15
      packages/subscribable-dataset/package.json
  70. 10
      packages/subscribable-dataset/src/ProxyTransactionalDataset.ts
  71. 6
      packages/subscribable-dataset/src/WrapperSubscribableDataset.ts
  72. 2
      packages/subscribable-dataset/src/WrapperSubscribableDatasetFactory.ts
  73. 2
      packages/subscribable-dataset/src/createWrapperSubscribableDataset.ts
  74. 3
      packages/subscribable-dataset/src/createWrapperSubscribableDatasetFromSerializedInput.ts
  75. 43
      packages/subscribable-dataset/src/types.ts
  76. 4
      packages/subscribable-dataset/test/ProxyTransactionalDataset.test.ts
  77. 4
      packages/subscribable-dataset/test/WrapperSubscribableDataset.test.ts

621
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -8,8 +8,7 @@
"test": "lerna run test",
"build": "lerna run build",
"demo-react": "lerna run start --scope @ldo/demo-react",
"lint": "lerna run lint",
"postinstall": "npm run build"
"lint": "lerna run lint"
},
"devDependencies": {
"@types/node": "^20.5.7",

@ -1,14 +1,14 @@
import { createDataset } from "../src";
import { quad, namedNode, literal } from "@rdfjs/data-model";
// Required for advanced features:
import { dataset as initializeDatasetCore } from "@rdfjs/dataset";
import { ExtendedDatasetFactory } from "../src";
import { quad, namedNode, literal } from "@ldo/rdf-utils";
import type {
Dataset,
Quad,
DatasetCoreFactory,
DatasetCore,
} from "@rdfjs/types";
} from "@ldo/rdf-utils";
/**
* Create a dataset with default settings

@ -1,4 +1,4 @@
import { serializedToDataset, serializedToSubscribableDataset } from "../src";
import { serializedToDataset } from "../src";
async function run(): Promise<void> {
// Create an ExtendedDataset using Turtle
@ -31,14 +31,11 @@ async function run(): Promise<void> {
"@id": "https://jackson.solidcommunity.net/profile/card#me",
},
];
const jsonLdDataset = await serializedToSubscribableDataset(
JSON.stringify(jsonLdData),
{
const jsonLdDataset = await serializedToDataset(JSON.stringify(jsonLdData), {
baseIRI:
"https://jackson.solidcommunity.net/IndividualChats/jackson.solidcommunity.net/index.ttl#",
format: "application/json-ld",
},
);
});
// Returns true because the input data describes the same triple.
console.log(turtleDataset.equals(jsonLdDataset));
}

@ -1,187 +0,0 @@
import type { DatasetChanges } from "../src";
import { createSubscribableDataset } from "../src";
import { quad, namedNode, literal } from "@rdfjs/data-model";
import type { Dataset } from "@rdfjs/types";
// Create an empty subscribable dataset
const subscribableDataset = createSubscribableDataset();
// Add some initial quads
subscribableDataset.addAll([
quad(
namedNode("http://example.org/cartoons#Zuko"),
namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
namedNode("http://example.org/cartoons#Firebender"),
namedNode("http://example.org/cartoons"),
),
quad(
namedNode("http://example.org/cartoons#Zuko"),
namedNode("http://example.org/cartoons#name"),
literal("Zuko"),
namedNode("http://example.org/cartoons"),
),
]);
// Set up listeners
// Listener that will trigger whenever a quad containing the named
// node "http://example.org/cartoons#Zuko" is added or removed.
subscribableDataset.on(
namedNode("http://example.org/cartoons#Zuko"),
(zukoQuads: Dataset, changes: DatasetChanges) => {
console.log("ZUKO NODE CHANGED ============");
console.log(zukoQuads.toString());
console.log("Added Quads:");
console.log(changes.added?.toString());
console.log("Removed Quads:");
console.log(changes.removed?.toString());
console.log("\n\n");
},
);
// Listener that will trigger whenever a quad containing the named
// node "http://example.org/cartoons" is added or removed. This is
// useful for keeping track of the cartoons graph.
subscribableDataset.on(
namedNode("http://example.org/cartoons"),
(cartoonGraphQuads: Dataset, changes: DatasetChanges) => {
console.log("CARTOON GRAPH CHANGED ============");
console.log(cartoonGraphQuads.toString());
console.log("Added Quads:");
console.log(changes.added?.toString());
console.log("Removed Quads:");
console.log(changes.removed?.toString());
console.log("\n\n");
},
);
// Modify the dataset
/*
Prints:
CARTOON GRAPH CHANGED ============
<http://example.org/cartoons#Zuko> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Firebender> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#name> "Zuko" <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Waterbender> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#name> "Katara" <http://example.org/cartoons> .
Added Quads:
<http://example.org/cartoons#Katara> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Waterbender> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#name> "Katara" <http://example.org/cartoons> .
Removed Quads:
undefined
*/
subscribableDataset.addAll([
quad(
namedNode("http://example.org/cartoons#Katara"),
namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
namedNode("http://example.org/cartoons#Waterbender"),
namedNode("http://example.org/cartoons"),
),
quad(
namedNode("http://example.org/cartoons#Katara"),
namedNode("http://example.org/cartoons#name"),
literal("Katara"),
namedNode("http://example.org/cartoons"),
),
]);
/*
Prints:
ZUKO NODE CHANGED ============
<http://example.org/cartoons#Zuko> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Firebender> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#name> "Zuko" <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
Added Quads:
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
Removed Quads:
undefined
CARTOON GRAPH CHANGED ============
<http://example.org/cartoons#Zuko> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Firebender> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#name> "Zuko" <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Waterbender> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#name> "Katara" <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
Added Quads:
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
Removed Quads:
undefined
*/
subscribableDataset.addAll([
quad(
namedNode("http://example.org/cartoons#Katara"),
namedNode("http://example.org/cartoons#hasEnemy"),
namedNode("http://example.org/cartoons#Zuko"),
namedNode("http://example.org/cartoons"),
),
quad(
namedNode("http://example.org/cartoons#Zuko"),
namedNode("http://example.org/cartoons#hasEnemy"),
namedNode("http://example.org/cartoons#Katara"),
namedNode("http://example.org/cartoons"),
),
]);
// If there are many operation you want to do at once, use transactions.
// An update will not be triggered until the transaction is committed.
const transactionalDataset = subscribableDataset.startTransaction();
// Delete all triples with a "hasEnemy" predicate
transactionalDataset.deleteMatches(
undefined,
namedNode("http://example.org/cartoons#hasEnemy"),
undefined,
undefined,
);
// Add "hasFrient" predicate
transactionalDataset.addAll([
quad(
namedNode("http://example.org/cartoons#Katara"),
namedNode("http://example.org/cartoons#hasFriend"),
namedNode("http://example.org/cartoons#Zuko"),
namedNode("http://example.org/cartoons"),
),
quad(
namedNode("http://example.org/cartoons#Zuko"),
namedNode("http://example.org/cartoons#hasFriend"),
namedNode("http://example.org/cartoons#Katara"),
namedNode("http://example.org/cartoons"),
),
]);
/*
Prints:
ZUKO NODE CHANGED ============
<http://example.org/cartoons#Zuko> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Firebender> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#name> "Zuko" <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
Added Quads:
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
Removed Quads:
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
CARTOON GRAPH CHANGED ============
<http://example.org/cartoons#Zuko> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Firebender> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#name> "Zuko" <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/cartoons#Waterbender> <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#name> "Katara" <http://example.org/cartoons> .
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
Added Quads:
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasFriend> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
Removed Quads:
<http://example.org/cartoons#Katara> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Zuko> <http://example.org/cartoons> .
<http://example.org/cartoons#Zuko> <http://example.org/cartoons#hasEnemy> <http://example.org/cartoons#Katara> <http://example.org/cartoons> .
*/
transactionalDataset.commit();

@ -8,7 +8,6 @@
"watch": "tsc --watch",
"test": "jest --coverage",
"example:extendedDataset": "ts-node ./example/extendedDatasetExample.ts",
"example:subscribableDataset": "ts-node ./example/subscribableDatasetExample.ts",
"example:loadData": "ts-node ./example/loadDataExample.ts",
"prepublishOnly": "npm run test && npm run build",
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern"

@ -1,13 +1,13 @@
import type {
DatasetCore,
Dataset,
BaseQuad,
Stream,
Term,
DatasetCoreFactory,
Quad,
} from "@rdfjs/types";
import { Writer } from "n3";
import {
type DatasetCore,
type Dataset,
type BaseQuad,
type Stream,
type Term,
type DatasetCoreFactory,
type Quad,
datasetToString,
} from "@ldo/rdf-utils";
import { Readable } from "readable-stream";
/**
@ -309,8 +309,7 @@ export default class ExtendedDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* No prior normalization is required, therefore the results for the same quads may vary depending on the Dataset implementation.
*/
toString(): string {
const writer = new Writer<InAndOutQuad>({ format: "N-Triples" });
return writer.quadsToString(this.toArray() as Quad[]);
return datasetToString(this as Dataset<Quad>, { format: "N-Triples" });
}
/**

@ -3,7 +3,7 @@ import type {
BaseQuad,
Dataset,
DatasetCoreFactory,
} from "@rdfjs/types";
} from "@ldo/rdf-utils";
import ExtendedDataset from "./ExtendedDataset";
/**

@ -1,11 +1,9 @@
import type { Dataset, DatasetFactory, Quad } from "@rdfjs/types";
import type { ParserOptions } from "n3";
import { Parser } from "n3";
// import { Readable } from "readable-stream";
// import ParserJsonld from "@rdfjs/parser-jsonld";
import type { Dataset, DatasetFactory, Quad } from "@ldo/rdf-utils";
import type { ParserOptions } from "@ldo/rdf-utils";
import { serializedToQuads } from "@ldo/rdf-utils";
/**
* Creates a dataset with a string input that could be SON-LD, Turtle, N-Triples, TriG, RDF*, or N3.
* Creates a dataset with a string input that could be JON-LD, Turtle, N-Triples, TriG, RDF*, or N3.
* @param datasetFactory A datasetFactory that will initialize a returned dataset.\
* @param data A string representation of RDF Data in JSON-LD, Turtle, N-Triples, TriG, RDF*, or N3.
* @param options Parser options: {
@ -23,37 +21,6 @@ export default async function createDatasetFromSerializedInput<
data: string,
options?: ParserOptions,
): Promise<ReturnDataset> {
// JSON-LD Parsing
if (options && options.format === "application/json-ld") {
throw new Error("Not Implemented");
// return new Promise((resolve, reject) => {
// JSON.parse(data);
// const parserJsonld = new ParserJsonld();
// const input = new Readable({
// read: () => {
// input.push(data);
// input.push(null);
// },
// });
// const output = parserJsonld.import(input);
// const quads: Quad[] = [];
// output.on("data", (quad) => {
// quads.push(quad);
// });
// output.on("end", () => {
// resolve((datasetFactory.dataset(quads) as unknown) as ReturnDataset);
// });
// /* istanbul ignore next */
// output.on("error", (err) => {
// /* istanbul ignore next */
// reject(err);
// });
// });
}
// N3 Parsing
const parser = new Parser(options as ParserOptions);
const quads = parser.parse(data);
const quads = await serializedToQuads(data, options);
return datasetFactory.dataset(quads) as unknown as ReturnDataset;
}

@ -3,10 +3,10 @@ import type {
DatasetCoreFactory,
DatasetCore,
Quad,
} from "@rdfjs/types";
} from "@ldo/rdf-utils";
import ExtendedDatasetFactory from "./ExtendedDatasetFactory";
import { dataset as initializeDatasetCore } from "@rdfjs/dataset";
import type { ExtendedDataset } from ".";
import type ExtendedDataset from "./ExtendedDataset";
/**
* Creates a dataset factory that generates ExtendedDatasets

@ -1,5 +1,4 @@
import type { ParserOptions } from "n3";
import type { Quad } from "@rdfjs/types";
import type { ParserOptions, Quad } from "@ldo/rdf-utils";
import createDatasetFromSerializedInput from "./createDatasetFromSerializedInput";
import { createExtendedDatasetFactory } from "./createExtendedDataset";
import type ExtendedDataset from "./ExtendedDataset";

@ -1,5 +1,5 @@
import { createDataset } from "../src";
import { quad, namedNode } from "@rdfjs/data-model";
import { quad, namedNode } from "@ldo/rdf-utils";
describe("createExtendedDataset", () => {
it("creates a dataset when give another datset", () => {

@ -1,12 +1,13 @@
import { namedNode, literal, quad } from "@rdfjs/data-model";
import type { Quad_Object, Quad_Predicate } from "n3";
import { namedNode, literal, quad } from "@ldo/rdf-utils";
import type {
SubjectNode,
ObjectNode,
PredicateNode,
BaseQuad,
Dataset,
Quad_Subject,
DatasetFactory,
Quad,
} from "@rdfjs/types";
} from "@ldo/rdf-utils";
import { Readable } from "stream";
export default function testDataset(
@ -476,9 +477,9 @@ export default function testDataset(
initializeDataset();
const mappedDataset = dataset.map((curQuad) => {
return quad(
curQuad.predicate as Quad_Subject,
curQuad.predicate as Quad_Predicate,
curQuad.predicate as Quad_Object,
curQuad.predicate as SubjectNode,
curQuad.predicate as PredicateNode,
curQuad.predicate as ObjectNode,
);
});
expect(mappedDataset.size).toBe(2);

@ -23,7 +23,6 @@
},
"homepage": "https://github.com/o-development/jsonld-dataset-proxy#readme",
"devDependencies": {
"@rdfjs/types": "^1.0.1",
"@types/jest": "^27.0.3",
"@types/jsonld": "^1.5.6",
"@types/n3": "^1.10.4",
@ -40,8 +39,8 @@
],
"dependencies": {
"@ldo/dataset": "^0.0.0",
"@ldo/rdf-utils": "^0.0.0",
"@ldo/subscribable-dataset": "^0.0.0",
"@rdfjs/data-model": "^1.2.0",
"jsonld2graphobject": "^0.0.4"
}
}

@ -1,8 +1,13 @@
import { blankNode, namedNode } from "@rdfjs/data-model";
import type { BlankNode, NamedNode } from "@rdfjs/types";
import { blankNode, namedNode } from "@ldo/rdf-utils";
import type {
BlankNode,
NamedNode,
GraphNode,
QuadMatch,
} from "@ldo/rdf-utils";
import type { LanguageOrdering } from "./language/languageTypes";
import type { ProxyContext } from "./ProxyContext";
import type { GraphType, ObjectLike, QuadMatch } from "./types";
import type { ObjectLike } from "./types";
/**
* Helps build JSON LD Dataset Proxies for a specific dataset and context
@ -18,7 +23,7 @@ export class JsonldDatasetProxyBuilder {
* Designates that all Jsonld Dataset Proxies created should write to the
* specified graphs
*/
write(...graphs: GraphType[]): JsonldDatasetProxyBuilder {
write(...graphs: GraphNode[]): JsonldDatasetProxyBuilder {
return new JsonldDatasetProxyBuilder(
this.proxyContext.duplicate({ writeGraphs: graphs }),
);

@ -1,10 +1,15 @@
import type { BlankNode, Dataset, NamedNode } from "@rdfjs/types";
import type {
BlankNode,
Dataset,
NamedNode,
GraphNode,
QuadMatch,
} from "@ldo/rdf-utils";
import type { ArrayProxyTarget } from "./arrayProxy/createArrayHandler";
import { createArrayHandler } from "./arrayProxy/createArrayHandler";
import { createSubjectHandler } from "./subjectProxy/createSubjectHandler";
import type { SubjectProxy } from "./subjectProxy/SubjectProxy";
import type { ArrayProxy } from "./arrayProxy/ArrayProxy";
import type { GraphType, QuadMatch } from "./types";
import { _getUnderlyingArrayTarget } from "./types";
import type { ContextUtil } from "./ContextUtil";
import type { LanguageOrdering } from "./language/languageTypes";
@ -12,7 +17,7 @@ import type { LanguageOrdering } from "./language/languageTypes";
export interface ProxyContextOptions {
dataset: Dataset;
contextUtil: ContextUtil;
writeGraphs: GraphType[];
writeGraphs: GraphNode[];
languageOrdering: LanguageOrdering;
prefilledArrayTargets?: ArrayProxyTarget[];
state?: Record<string, unknown>;
@ -29,7 +34,7 @@ export class ProxyContext {
readonly dataset: Dataset;
readonly contextUtil: ContextUtil;
readonly writeGraphs: GraphType[];
readonly writeGraphs: GraphNode[];
readonly languageOrdering: LanguageOrdering;
public state: Record<string, unknown>;

@ -1,7 +1,6 @@
import type { Dataset } from "@rdfjs/types";
import type { Dataset, ObjectNode } from "@ldo/rdf-utils";
import type { ArrayProxyTarget } from "./createArrayHandler";
import type {
ObjectType,
_getNodeAtIndex,
_getUnderlyingArrayTarget,
_getUnderlyingDataset,
@ -14,7 +13,7 @@ import type { ProxyContext } from "../ProxyContext";
export type ArrayProxy = Array<unknown> & {
readonly [_getUnderlyingDataset]: Dataset;
readonly [_getUnderlyingMatch]: ArrayProxyTarget[0];
readonly [_getNodeAtIndex]: (index: number) => ObjectType | undefined;
readonly [_getNodeAtIndex]: (index: number) => ObjectNode | undefined;
readonly [_getUnderlyingArrayTarget]: ArrayProxyTarget;
[_proxyContext]: ProxyContext;
};

@ -1,10 +1,14 @@
import type { NamedNode } from "@rdfjs/types";
import { quad } from "@ldo/rdf-utils";
import type {
NamedNode,
ObjectNode,
QuadMatch,
SubjectNode,
} from "@ldo/rdf-utils";
import type { ObjectJsonRepresentation } from "../util/nodeToJsonldRepresentation";
import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation";
import { quad } from "@rdfjs/data-model";
import type { ArrayMethodBuildersType } from "./arrayMethods";
import { arrayMethodsBuilders, methodNames } from "./arrayMethods";
import type { ObjectType, QuadMatch, SubjectType } from "../types";
import {
_getNodeAtIndex,
_getUnderlyingArrayTarget,
@ -20,7 +24,7 @@ import { filterQuadsByLanguageOrdering } from "../language/languageUtils";
export type ArrayProxyTarget = [
quadMatch: QuadMatch,
curArray: ObjectType[],
curArray: ObjectNode[],
isSubjectOriented?: boolean,
isLangStringArray?: boolean,
];
@ -38,12 +42,12 @@ function updateArrayOrder(
quads.toArray().forEach((quad) => {
// If this this a subject-oriented document
if (target[2]) {
datasetObjects.add(quad.subject as SubjectType);
datasetObjects.add(quad.subject as SubjectNode);
} else {
datasetObjects.add(quad.object as ObjectType);
datasetObjects.add(quad.object as ObjectNode);
}
});
const processedObjects: ObjectType[] = [];
const processedObjects: ObjectNode[] = [];
target[1].forEach((arrItem) => {
if (datasetObjects.has(arrItem)) {
processedObjects.push(arrItem);
@ -82,7 +86,7 @@ export function createArrayHandler(
case _proxyContext:
return proxyContext;
case _getNodeAtIndex:
return (index: number): ObjectType | undefined => {
return (index: number): ObjectNode | undefined => {
updateArrayOrder(target, proxyContext);
return target[1][index];
};

@ -1,9 +1,8 @@
import { defaultGraph } from "@rdfjs/data-model";
import type { Quad } from "@rdfjs/types";
import { defaultGraph } from "@ldo/rdf-utils";
import type { Quad, ObjectNode } from "@ldo/rdf-utils";
import { ProxyTransactionalDataset } from "@ldo/subscribable-dataset";
import { createDatasetFactory } from "@ldo/dataset";
import type { ProxyContext } from "../ProxyContext";
import type { ObjectType } from "../types";
import { addObjectToDataset } from "../util/addObjectToDataset";
import {
getNodeFromRawObject,
@ -121,7 +120,7 @@ export function modifyArray<ReturnType>(
.map((addedValue) => {
return getNodeFromRawValue(key, addedValue, proxyContext);
})
.filter((val) => val != undefined) as ObjectType[])
.filter((val) => val != undefined) as ObjectNode[])
: [];
// Allow the base array to be modified

@ -1,9 +1,10 @@
import { namedNode } from "@rdfjs/data-model";
import type { ObjectNode, GraphNode } from "@ldo/rdf-utils";
import { namedNode } from "@ldo/rdf-utils";
import {
getSubjectProxyFromObject,
isSubjectProxy,
} from "./subjectProxy/isSubjectProxy";
import type { GraphType, ObjectLike, ObjectType } from "./types";
import type { ObjectLike } from "./types";
import {
_getNodeAtIndex,
_getUnderlyingDataset,
@ -25,14 +26,14 @@ export function graphOf<Subject extends ObjectLike, Key extends keyof Subject>(
object?: NonNullable<Subject[Key]> extends Array<unknown>
? number | ObjectLike
: ObjectLike,
): GraphType[] {
): GraphNode[] {
const subjectProxy = getSubjectProxyFromObject(subject);
const proxyContext = subjectProxy[_proxyContext];
const subjectNode = subjectProxy[_getUnderlyingNode];
const predicateNode = namedNode(
proxyContext.contextUtil.keyToIri(predicate as string),
);
let objectNode: ObjectType | null;
let objectNode: ObjectNode | null;
if (object == null) {
objectNode = null;
} else if (typeof object === "number") {
@ -58,5 +59,5 @@ export function graphOf<Subject extends ObjectLike, Key extends keyof Subject>(
predicateNode,
objectNode,
);
return quads.toArray().map((quad): GraphType => quad.graph as GraphType);
return quads.toArray().map((quad): GraphNode => quad.graph as GraphNode);
}

@ -1,5 +1,5 @@
import { defaultGraph } from "@rdfjs/data-model";
import type { Dataset } from "@rdfjs/types";
import { defaultGraph } from "@ldo/rdf-utils";
import type { Dataset } from "@ldo/rdf-utils";
import type { ContextDefinition } from "jsonld";
import { ContextUtil } from "./ContextUtil";
import { JsonldDatasetProxyBuilder } from "./JsonldDatasetProxyBuilder";

@ -1,6 +1,6 @@
import { literal, quad } from "@rdfjs/data-model";
import type { PredicateNode, SubjectNode } from "@ldo/rdf-utils";
import { literal, quad } from "@ldo/rdf-utils";
import type { ProxyContext } from "../ProxyContext";
import type { PredicateType, SubjectType } from "../types";
import {
languageKeyToLiteralLanguage,
quadsToLanguageQuadMap,
@ -12,8 +12,8 @@ import LanguageSet from "./languageSet";
export function createLanguageMapProxy<
Target extends LanguageMap | LanguageSetMap,
>(
subject: SubjectType,
predicate: PredicateType,
subject: SubjectNode,
predicate: PredicateNode,
proxyContext: ProxyContext,
isArray: boolean,
): Target {

@ -1,20 +1,24 @@
import type { Dataset, Literal } from "@rdfjs/types";
import type { PredicateType, SubjectType } from "../types";
import { literal, quad } from "@ldo/rdf-utils";
import type {
Dataset,
Literal,
PredicateNode,
SubjectNode,
} from "@ldo/rdf-utils";
import type { LanguageKey } from "./languageTypes";
import type { LiteralObjectQuad } from "./languageUtils";
import { languageDeleteMatch, languageMatch } from "./languageUtils";
import { literal, quad } from "@rdfjs/data-model";
import type { ProxyContext } from "../ProxyContext";
export default class LanguageSet implements Set<string> {
private subject: SubjectType;
private predicate: PredicateType;
private subject: SubjectNode;
private predicate: PredicateNode;
private languageKey: LanguageKey;
private proxyContext: ProxyContext;
constructor(
subject: SubjectType,
predicate: PredicateType,
subject: SubjectNode,
predicate: PredicateNode,
languageKey: LanguageKey,
proxyContext: ProxyContext,
) {

@ -1,6 +1,13 @@
import type { Dataset, Literal, Quad, Quad_Object } from "@rdfjs/types";
import type {
Dataset,
Literal,
Quad,
ObjectNode,
PredicateNode,
SubjectNode,
Quad_Object,
} from "@ldo/rdf-utils";
import { createDataset } from "@ldo/dataset";
import type { PredicateType, SubjectType } from "../types";
import type { LanguageKey, LanguageOrdering } from "./languageTypes";
/**
@ -13,8 +20,8 @@ import type { LanguageKey, LanguageOrdering } from "./languageTypes";
*/
export function languageMatch(
dataset: Dataset,
subject: SubjectType,
predicate: PredicateType,
subject: ObjectNode,
predicate: PredicateNode,
languageKey: LanguageKey,
): Dataset<LiteralObjectQuad> {
const literalLanguage = languageKeyToLiteralLanguage(languageKey);
@ -34,8 +41,8 @@ export function languageMatch(
*/
export function languageDeleteMatch(
dataset: Dataset,
subject: SubjectType,
predicate: PredicateType,
subject: SubjectNode,
predicate: PredicateNode,
languageKey: LanguageKey,
): void {
const quadsToDelete = languageMatch(dataset, subject, predicate, languageKey);

@ -1,4 +1,4 @@
import { namedNode } from "@rdfjs/data-model";
import { namedNode } from "@ldo/rdf-utils";
import { getSubjectProxyFromObject } from "../subjectProxy/isSubjectProxy";
import type { ObjectLike } from "../types";
import { _getUnderlyingNode, _proxyContext } from "../types";

@ -1,8 +1,7 @@
import type { BlankNode, Dataset, NamedNode } from "@rdfjs/types";
import type { BlankNode, Dataset, NamedNode, GraphNode } from "@ldo/rdf-utils";
import type { ContextDefinition } from "jsonld";
import type { ProxyContext } from "../ProxyContext";
import type {
GraphType,
_getUnderlyingDataset,
_getUnderlyingNode,
_proxyContext,
@ -16,5 +15,5 @@ export type SubjectProxy = {
readonly [_getUnderlyingDataset]: Dataset;
readonly [_getUnderlyingNode]: NamedNode | BlankNode;
[_proxyContext]: ProxyContext;
readonly [_writeGraphs]: GraphType[];
readonly [_writeGraphs]: GraphNode[];
};

@ -1,5 +1,5 @@
import type { BlankNode, NamedNode } from "@rdfjs/types";
import { namedNode, quad } from "@rdfjs/data-model";
import { namedNode, quad } from "@ldo/rdf-utils";
import type { BlankNode, NamedNode } from "@ldo/rdf-utils";
import { addObjectToDataset } from "../util/addObjectToDataset";
import { deleteValueFromDataset } from "./deleteFromDataset";
import {

@ -1,5 +1,5 @@
import type { Term } from "@rdfjs/types";
import { namedNode, quad } from "@rdfjs/data-model";
import { namedNode, quad } from "@ldo/rdf-utils";
import type { Term } from "@ldo/rdf-utils";
import type { SubjectProxyTarget } from "./createSubjectHandler";
import type { ProxyContext } from "../ProxyContext";

@ -1,5 +1,5 @@
import type { SubjectProxyTarget } from "./createSubjectHandler";
import { namedNode } from "@rdfjs/data-model";
import { namedNode } from "@ldo/rdf-utils";
import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation";
import type { SubjectProxy } from "./SubjectProxy";
import type { ArrayProxy } from "../arrayProxy/ArrayProxy";

@ -1,5 +1,3 @@
import type { BlankNode, DefaultGraph, Literal, NamedNode } from "@rdfjs/types";
export const _getUnderlyingNode = Symbol("_getUnderlyingNode");
export const _getUnderlyingMatch = Symbol("_getUnderlyingMatch");
export const _isSubjectOriented = Symbol("_isSubjectOriented");

@ -1,5 +1,10 @@
import type { BlankNode, DefaultGraph, Literal, NamedNode } from "@rdfjs/types";
import type { ObjectType } from "../types";
import type {
BlankNode,
DefaultGraph,
Literal,
NamedNode,
ObjectNode,
} from "@ldo/rdf-utils";
export function nodeToString(
node: NamedNode | BlankNode | DefaultGraph | Literal | null | undefined,
@ -21,19 +26,19 @@ export function nodeToString(
export class NodeSet {
private set: Set<string> = new Set();
private map: Record<string, ObjectType> = {};
private map: Record<string, ObjectNode> = {};
add(node: ObjectType) {
add(node: ObjectNode) {
const key = nodeToString(node);
this.set.add(key);
this.map[key] = node;
}
has(node: ObjectType): boolean {
has(node: ObjectNode): boolean {
return this.set.has(nodeToString(node));
}
delete(node: ObjectType) {
delete(node: ObjectNode) {
const key = nodeToString(node);
delete this.map[key];
return this.set.delete(nodeToString(node));

@ -1,4 +1,4 @@
import type { BlankNode, NamedNode } from "@rdfjs/types";
import type { BlankNode, NamedNode } from "@ldo/rdf-utils";
import { _getUnderlyingNode } from "../types";
import type { SubjectProxy } from "../subjectProxy/SubjectProxy";

@ -1,5 +1,5 @@
import type { BlankNode, NamedNode } from "@rdfjs/types";
import { literal, namedNode, quad } from "@rdfjs/data-model";
import type { BlankNode, NamedNode } from "@ldo/rdf-utils";
import { literal, namedNode, quad } from "@ldo/rdf-utils";
import { _getUnderlyingNode } from "../types";
import type { SubjectProxy } from "../subjectProxy/SubjectProxy";
import { getNodeFromRawObject, getNodeFromRawValue } from "./getNodeFromRaw";

@ -1,5 +1,5 @@
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
import { namedNode, literal, blankNode } from "@rdfjs/data-model";
import type { BlankNode, Literal, NamedNode } from "@ldo/rdf-utils";
import { namedNode, literal, blankNode } from "@ldo/rdf-utils";
import type { ContextUtil } from "../ContextUtil";
import { _getUnderlyingNode } from "../types";
import type { RawObject, RawValue } from "./RawObject";

@ -1,4 +1,4 @@
import type { Literal, Quad_Object } from "@rdfjs/types";
import type { Literal, Quad_Object } from "@ldo/rdf-utils";
import type { ProxyContext } from "../ProxyContext";
import type { SubjectProxy } from "../subjectProxy/SubjectProxy";

@ -25,8 +25,8 @@ import {
tinyPatientDataWithBlankNodes,
tinyPatientDataWithLanguageTags,
} from "./patientExampleData";
import { namedNode, quad, literal, defaultGraph } from "@rdfjs/data-model";
import type { Dataset, NamedNode } from "@rdfjs/types";
import { namedNode, quad, literal, defaultGraph } from "@ldo/rdf-utils";
import type { Dataset, NamedNode } from "@ldo/rdf-utils";
import type { ContextDefinition } from "jsonld";
describe("jsonldDatasetProxy", () => {

@ -1,7 +1,7 @@
import { createDataset } from "@ldo/dataset";
import { ContextUtil } from "../src/ContextUtil";
import { nodeToJsonldRepresentation } from "../src/util/nodeToJsonldRepresentation";
import { literal, defaultGraph } from "@rdfjs/data-model";
import { literal, defaultGraph } from "@ldo/rdf-utils";
import { ProxyContext } from "../src";
describe("objectToJsonRepresentation", () => {

@ -1,4 +1,4 @@
import { blankNode, defaultGraph, literal, namedNode } from "@rdfjs/data-model";
import { blankNode, defaultGraph, literal, namedNode } from "@ldo/rdf-utils";
import { nodeToString } from "../src";
describe("nodeToString", () => {

@ -352,9 +352,8 @@ commitTransaction(profile);
### `getDataset(linkedDataObject)`
Returns the Linked Data Object's underlying RDFJS dataset. Modifying this dataset will change the Linked Data Object as well.
```typescript
import { Dataset } from "@rdfjs/types";
import { getDataset } from "ldo"
const dataset: Dataset = dataset(profile);
const dataset = getDataset(profile);
```
## Sponsorship

@ -22,7 +22,6 @@
},
"homepage": "https://github.com/o-development/ldo#readme",
"devDependencies": {
"@rdfjs/types": "^1.1.0",
"@types/jest": "^27.0.3",
"@types/jsonld": "^1.5.6",
"@types/n3": "^1.10.4",
@ -36,10 +35,9 @@
"dependencies": {
"@ldo/dataset": "^0.0.0",
"@ldo/jsonld-dataset-proxy": "^0.0.0",
"@ldo/rdf-utils": "^0.0.0",
"@ldo/subscribable-dataset": "^0.0.0",
"@rdfjs/data-model": "^1.2.0",
"buffer": "^6.0.3",
"n3": "^1.16.2",
"readable-stream": "^4.3.0"
},
"overrides": {

@ -1,4 +1,4 @@
import type { Quad } from "@rdfjs/types";
import type { Quad } from "@ldo/rdf-utils";
import jsonldDatasetProxy from "@ldo/jsonld-dataset-proxy";
import { WrapperSubscribableDataset } from "@ldo/subscribable-dataset";
import { LdoBuilder } from "./LdoBuilder";

@ -1,4 +1,4 @@
import type { DatasetFactory, Dataset, Quad } from "@rdfjs/types";
import type { DatasetFactory, Dataset, Quad } from "@ldo/rdf-utils";
import { LdoDataset } from "./LdoDataset";
/**

@ -1,4 +1,4 @@
import type { Dataset, DatasetFactory, Quad } from "@rdfjs/types";
import type { Dataset, DatasetFactory, Quad } from "@ldo/rdf-utils";
import { createDataset } from "@ldo/dataset";
import { LdoDatasetFactory } from "./LdoDatasetFactory";

@ -1,52 +0,0 @@
import type { Dataset } from "@rdfjs/types";
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> {
// 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);
// });
// });
// }

@ -1,18 +1,15 @@
import type { Dataset } from "@rdfjs/types";
import type { JsonLdDocument } from "jsonld";
import type { GraphType, InteractOptions } from "@ldo/jsonld-dataset-proxy";
import type { GraphNode, DatasetChanges } from "@ldo/rdf-utils";
import type { InteractOptions } from "@ldo/jsonld-dataset-proxy";
import {
getProxyFromObject,
_getUnderlyingDataset,
_proxyContext,
write as writeDependency,
} from "@ldo/jsonld-dataset-proxy";
import type { Quad, WriterOptions } from "n3";
import type {
DatasetChanges,
SubscribableDataset,
} from "@ldo/subscribable-dataset";
import { datasetToString } from "./datasetConverters";
import type { SubscribableDataset } from "@ldo/subscribable-dataset";
import type { WriterOptions, Dataset, Quad } from "@ldo/rdf-utils";
import { changesToSparqlUpdate, datasetToString } from "@ldo/rdf-utils";
import type { LdoBase } from "./util";
import {
canDatasetStartTransaction,
@ -26,7 +23,7 @@ export {
setLanguagePreferences,
} from "@ldo/jsonld-dataset-proxy";
export function write(...graphs: (GraphType | string)[]): InteractOptions {
export function write(...graphs: (GraphNode | string)[]): InteractOptions {
return writeDependency(...normalizeNodeNames(graphs));
}
@ -72,21 +69,7 @@ export function getDataset(ldo: LdoBase): Dataset {
export async function toSparqlUpdate(ldo: LdoBase): Promise<string> {
const [dataset] = getTransactionalDatasetFromLdo(ldo);
const changes = dataset.getChanges();
let output = "";
if (changes.removed) {
output += `DELETE DATA { ${await datasetToString(changes.removed, {
format: "N-Triples",
})} }`;
}
if (changes.added && changes.removed) {
output += "; ";
}
if (changes.added) {
output += `INSERT DATA { ${await datasetToString(changes.added, {
format: "N-Triples",
})} }`;
}
return output.replaceAll("\n", " ");
return changesToSparqlUpdate(changes);
}
export async function serialize(

@ -1,6 +1,6 @@
import type { Dataset } from "@rdfjs/types";
import type { Dataset } from "@ldo/rdf-utils";
import type { JsonLdDocument } from "jsonld";
import type { ParserOptions } from "n3";
import type { ParserOptions } from "@ldo/rdf-utils";
import { createDatasetFromSerializedInput } from "@ldo/dataset";
import { createLdoDataset, createLdoDatasetFactory } from "./createLdoDataset";
import type { LdoDataset } from "./LdoDataset";

@ -1,20 +1,16 @@
import { namedNode } from "@rdfjs/data-model";
import type { Dataset } from "@rdfjs/types";
import type {
ArrayProxy,
GraphType,
ObjectType,
PredicateType,
SubjectProxy,
SubjectType,
} from "@ldo/jsonld-dataset-proxy";
import { namedNode } from "@ldo/rdf-utils";
import type { Dataset } from "@ldo/rdf-utils";
import type { ArrayProxy, SubjectProxy } from "@ldo/jsonld-dataset-proxy";
import {
getProxyFromObject,
_getUnderlyingDataset,
_proxyContext,
} from "@ldo/jsonld-dataset-proxy";
import type { Quad } from "n3";
import type { SubscribableDataset, TransactionalDataset } from "@ldo/subscribable-dataset";
import type { Quad, AnyNode } from "@ldo/rdf-utils";
import type {
SubscribableDataset,
TransactionalDataset,
} from "@ldo/subscribable-dataset";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type LdoBase = Record<string, any>;
@ -24,9 +20,9 @@ export type LdoBase = Record<string, any>;
* @param input A Node or string
* @returns A node
*/
export function normalizeNodeName<
NodeType extends SubjectType | PredicateType | ObjectType | GraphType,
>(input: NodeType | string): NodeType {
export function normalizeNodeName<NodeType extends AnyNode>(
input: NodeType | string,
): NodeType {
return (typeof input === "string" ? namedNode(input) : input) as NodeType;
}
@ -35,9 +31,9 @@ export function normalizeNodeName<
* @param inputs An array of nodes/strings
* @returns An array of nodes
*/
export function normalizeNodeNames<
NodeType extends SubjectType | PredicateType | ObjectType | GraphType,
>(inputs: (NodeType | string)[]): NodeType[] {
export function normalizeNodeNames<NodeType extends AnyNode>(
inputs: (NodeType | string)[],
): NodeType[] {
return inputs.map((input) => normalizeNodeName<NodeType>(input));
}

@ -1,4 +1,4 @@
import { literal, namedNode, quad } from "@rdfjs/data-model";
import { literal, namedNode, quad } from "@ldo/rdf-utils";
import { createDataset } from "@ldo/dataset";
import type { SolidProfileShape } from "./profileData";
import { ProfileShapeType } from "./profileData";

@ -1,4 +1,4 @@
import { namedNode } from "@rdfjs/data-model";
import { namedNode } from "@ldo/rdf-utils";
import type { SubjectProxy } from "@ldo/jsonld-dataset-proxy";
import {
getProxyFromObject,

@ -22,11 +22,11 @@
},
"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",
"@rdfjs/types": "^1.1.0",
"n3": "^1.17.1",
"rdf-string": "^1.6.3"
}

@ -1,31 +1,26 @@
import type { Dataset } from "@rdfjs/types";
import type { DatasetCore, Quad } from "@rdfjs/types";
import type { ContextDefinition, JsonLdDocument } from "jsonld";
import type { WriterOptions } from "n3";
import type { WriterOptions as WriterOptionsImport } from "n3";
import { Writer } from "n3";
// import SerializerJsonld from "@rdfjs/serializer-jsonld";
// import { Readable } from "readable-stream";
export async function datasetToString(
dataset: Dataset,
export type WriterOptions = WriterOptionsImport;
export function datasetToString(
dataset: DatasetCore<Quad>,
options: WriterOptions,
): Promise<string> {
return new Promise<string>((resolve, reject) => {
): string {
const writer = new Writer(options);
const quadArr: Quad[] = [];
for (const quad of dataset) {
writer.addQuad(quad);
}
writer.end(async (error, parsedString: string) => {
/* istanbul ignore if */
if (error) {
return reject(error);
quadArr.push(quad);
}
return resolve(parsedString);
});
});
return writer.quadsToString(quadArr);
}
export async function datasetToJsonLd(
_dataset: Dataset,
_dataset: DatasetCore,
_context: ContextDefinition,
): Promise<JsonLdDocument> {
throw new Error("JSONLD serialization is not omplemented");

@ -3,3 +3,4 @@ export * from "@rdfjs/types";
export * from "@rdfjs/data-model";
export * from "./datasetChanges";
export * from "./datasetConverters";
export * from "./serializedToQuads";

@ -0,0 +1,43 @@
import type { Quad } from "@rdfjs/types";
import type { ParserOptions as ParserOptionsImport } from "n3";
import { Parser } from "n3";
export type ParserOptions = ParserOptionsImport;
export async function serializedToQuads(
data: string,
options?: ParserOptions,
): Promise<Quad[]> {
// JSON-LD Parsing
if (options && options.format === "application/json-ld") {
throw new Error("Not Implemented");
// return new Promise((resolve, reject) => {
// JSON.parse(data);
// const parserJsonld = new ParserJsonld();
// const input = new Readable({
// read: () => {
// input.push(data);
// input.push(null);
// },
// });
// const output = parserJsonld.import(input);
// const quads: Quad[] = [];
// output.on("data", (quad) => {
// quads.push(quad);
// });
// output.on("end", () => {
// resolve((datasetFactory.dataset(quads) as unknown) as ReturnDataset);
// });
// /* istanbul ignore next */
// output.on("error", (err) => {
// /* istanbul ignore next */
// reject(err);
// });
// });
}
// N3 Parsing
const parser = new Parser(options as ParserOptions);
return parser.parse(data);
}

@ -26,7 +26,6 @@
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.11",
"@rdfjs/types": "^1.1.0",
"@types/jest": "^29.0.3",
"@types/jsonld": "^1.5.8",
"@types/n3": "^1.10.4",

@ -5,11 +5,7 @@ import { createLdoDataset } from "@ldo/ldo";
import type { LdoContextData } from "./LdoContext";
import { LdoContextProvider } from "./LdoContext";
import { UpdateManager } from "./ldoHooks/helpers/UpdateManager";
import { BinaryResourceStore } from "./document/resource/binaryResource/BinaryResourceStore";
import { DataResourceStore } from "./document/resource/dataResource/DataResourceStore";
import { ContainerResourceStore } from "./document/resource/dataResource/containerResource/ContainerResourceStore";
import { AccessRulesStore } from "./document/accessRules/AccessRulesStore";
import type { Dataset } from "@rdfjs/types";
import type { Dataset } from "@ldo/rdf-utils";
export interface LdoProviderProps extends PropsWithChildren {
fetch?: typeof fetch;

@ -5,7 +5,7 @@ import type {
} from "@ldo/jsonld-dataset-proxy";
import { ProxyContext } from "@ldo/jsonld-dataset-proxy";
import type { UpdateManager } from "./UpdateManager";
import { namedNode } from "@rdfjs/data-model";
import { namedNode } from "@ldo/rdf-utils";
export class TrackingProxyContext extends ProxyContext {
private updateManager: UpdateManager;
@ -34,13 +34,13 @@ export class TrackingProxyContext extends ProxyContext {
// Do Nothing
} else if (key === "@id") {
this.updateManager.registerListener(
[subject, null, null],
[subject, null, null, null],
this.listener,
);
} else if (!this.contextUtil.isArray(key)) {
const predicate = namedNode(this.contextUtil.keyToIri(key));
this.updateManager.registerListener(
[subject, predicate, null],
[subject, predicate, null, null],
this.listener,
);
}
@ -66,7 +66,7 @@ export class TrackingProxyContext extends ProxyContext {
) => {
if (qualifiedArrayMethods.has(key)) {
this.updateManager.registerListener(
[target[0][0], target[0][1], target[0][2]],
[target[0][0], target[0][1], target[0][2], null],
this.listener,
);
}

@ -1,35 +1,27 @@
import type { DatasetChanges } from "@ldo/subscribable-dataset";
import { createDataset } from "@ldo/dataset";
import { quadMatchToString } from "@ldo/rdf-utils";
import type {
Quad,
QuadMatch,
SubjectType,
PredicateType,
ObjectType,
} from "@ldo/jsonld-dataset-proxy";
import { nodeToString } from "@ldo/jsonld-dataset-proxy";
import type { Quad } from "@rdfjs/types";
export type TripleMatch = [QuadMatch[0], QuadMatch[1], QuadMatch[2]];
SubjectNode,
PredicateNode,
ObjectNode,
} from "@ldo/rdf-utils";
export class UpdateManager {
private tripleMatchListenerMap: Record<string, Set<() => void>> = {};
private quadMatchListenerMap: Record<string, Set<() => void>> = {};
private listenerHashMap: Map<() => void, Set<string>> = new Map();
private tripleMatchToHash(tripleMatch: TripleMatch): string {
return `${nodeToString(tripleMatch[0])}${nodeToString(
tripleMatch[1],
)}${nodeToString(tripleMatch[2])}`;
}
registerListener(tripleMatch: TripleMatch, callback: () => void): void {
const hash = this.tripleMatchToHash(tripleMatch);
if (!this.tripleMatchListenerMap[hash]) {
this.tripleMatchListenerMap[hash] = new Set();
registerListener(quadMatch: QuadMatch, callback: () => void): void {
const hash = quadMatchToString(quadMatch);
if (!this.quadMatchListenerMap[hash]) {
this.quadMatchListenerMap[hash] = new Set();
}
if (!this.listenerHashMap.has(callback)) {
this.listenerHashMap.set(callback, new Set());
}
this.tripleMatchListenerMap[hash].add(callback);
this.quadMatchListenerMap[hash].add(callback);
this.listenerHashMap.get(callback)?.add(hash);
}
@ -37,7 +29,7 @@ export class UpdateManager {
const hashSet = this.listenerHashMap.get(callback);
if (hashSet) {
hashSet.forEach((hash) => {
this.tripleMatchListenerMap[hash]?.delete(callback);
this.quadMatchListenerMap[hash]?.delete(callback);
});
}
}
@ -54,27 +46,27 @@ export class UpdateManager {
// Cast the input because RDFJS types assume RDF 1.2 where a Subject can
// be a Quad
const quad = tempQuad as {
subject: SubjectType;
predicate: PredicateType;
object: ObjectType;
subject: SubjectNode;
predicate: PredicateNode;
object: ObjectNode;
};
const tripleMatches: TripleMatch[] = [
[null, null, null],
[quad.subject, null, null],
[quad.subject, quad.predicate, null],
[quad.subject, null, quad.object],
[null, quad.predicate, null],
[null, quad.predicate, quad.object],
[null, null, quad.object],
[quad.subject, quad.predicate, quad.object],
const quadMatches: QuadMatch[] = [
[null, null, null, null],
[quad.subject, null, null, null],
[quad.subject, quad.predicate, null, null],
[quad.subject, null, quad.object, null],
[null, quad.predicate, null, null],
[null, quad.predicate, quad.object, null],
[null, null, quad.object, null],
[quad.subject, quad.predicate, quad.object, null],
];
tripleMatches.forEach((tripleMatch) => {
const hash = this.tripleMatchToHash(tripleMatch);
this.tripleMatchListenerMap[hash]?.forEach((callback) => {
quadMatches.forEach((quadMatch) => {
const hash = quadMatchToString(quadMatch);
this.quadMatchListenerMap[hash]?.forEach((callback) => {
listenersToNotify.add(callback);
});
delete this.tripleMatchListenerMap[hash];
delete this.quadMatchListenerMap[hash];
});
});
listenersToNotify.forEach((listener) => {

@ -1,4 +1,5 @@
import type { SubjectType } from "@ldo/jsonld-dataset-proxy";
import { defaultGraph } from "@ldo/rdf-utils";
import type { SubjectNode } from "@ldo/rdf-utils";
import {
ContextUtil,
JsonldDatasetProxyBuilder,
@ -8,11 +9,10 @@ import { LdoBuilder } from "@ldo/ldo";
import { useLdoContext } from "../LdoContext";
import { useCallback, useEffect, useMemo, useState } from "react";
import { TrackingProxyContext } from "./helpers/TrackingProxyContext";
import { defaultGraph } from "@rdfjs/data-model";
export function useSubject<Type extends LdoBase>(
shapeType: ShapeType<Type>,
subject: string | SubjectType,
subject: string | SubjectNode,
): [Type, undefined] | [undefined, Error] {
const { dataset, updateManager } = useLdoContext();

@ -8,16 +8,15 @@ import type { DataResource } from "./document/resource/dataResource/DataResource
import type { BinaryResource } from "./document/resource/binaryResource/BinaryResource";
import type { ContainerResource } from "./document/resource/dataResource/containerResource/ContainerResource";
import type { AccessRules } from "./document/accessRules/AccessRules";
import type { SubjectType } from "@ldo/jsonld-dataset-proxy";
import type { DatasetChanges } from "@ldo/subscribable-dataset";
import type { Quad } from "@rdfjs/types";
import type { Quad, SubjectNode } from "@ldo/rdf-utils";
export interface UseLdoReturn {
changeData<Type extends LdoBase>(input: Type, ...resources: Resource[]): Type;
commitData(input: LdoBase): Promise<void>;
createData<Type extends LdoBase>(
shapeType: ShapeType<Type>,
subject: string | SubjectType,
subject: string | SubjectNode,
...resources: Resource[]
): Type;
dataset: LdoDataset;

@ -24,16 +24,13 @@
"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",
"@ldo/rdf-utils": "^0.0.0",
"cross-fetch": "^3.1.6"
}
}

@ -8,9 +8,9 @@ import type { DataResourceStore } from "./document/resource/dataResource/DataRes
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 { Dataset, DatasetFactory } from "@ldo/rdf-utils";
import type { Resource } from "./document/resource/Resource";
import { DocumentError } from "./document/errors/DocumentError";
import type { DocumentError } from "./document/errors/DocumentError";
export interface SolidLdoDatasetArgs {
dataResourceStore: DataResourceStore;

@ -1,5 +1,31 @@
import { SolidLdoDataset } from "./SolidLdoDataset";
import type { Dataset } from "@ldo/rdf-utils";
import type { SolidLdoDataset } from "./SolidLdoDataset";
import { AccessRulesStore } from "./document/accessRules/AccessRulesStore";
import { BinaryResourceStore } from "./document/resource/binaryResource/BinaryResourceStore";
import { DataResourceStore } from "./document/resource/dataResource/DataResourceStore";
import { ContainerResourceStore } from "./document/resource/dataResource/containerResource/ContainerResourceStore";
export function createSolidLdoDataset(): SolidLdoDataset {
throw new Error("Not Implemented");
export interface CreateSolidLdoDatasetOptions {
fetch?: typeof fetch;
dataset?: Dataset;
}
export function createSolidLdoDataset(
options?: CreateSolidLdoDatasetOptions,
): SolidLdoDataset {
const finalFetch = fetch || vbhyg
// Ingnoring this because we're setting up circular dependencies
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const dependencies: LdoContextData = {
onDocumentError,
fetch: finalFetch,
dataset: ldoDataset,
updateManager: new UpdateManager(),
};
const binaryResourceStore = new BinaryResourceStore(dependencies);
const dataResourceStore = new DataResourceStore(dependencies);
const containerResourceStore = new ContainerResourceStore(dependencies);
const accessRulesStore = new AccessRulesStore(dependencies);
}

@ -3,10 +3,12 @@ import type { ResourceDependencies } from "../Resource";
import { Resource } from "../Resource";
import { DocumentFetchError } from "../../errors/DocumentFetchError";
import { DocumentError } from "../../errors/DocumentError";
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 {
namedNode,
quad as createQuad,
changesToSparqlUpdate,
} from "@ldo/rdf-utils";
import type { DatasetChanges, Quad } from "@ldo/rdf-utils";
import type { SolidLdoDataset } from "../../../SolidLdoDataset";
export interface DataResourceDependencies extends ResourceDependencies {

@ -1,25 +1,23 @@
import type { DatasetChanges } from "@ldo/subscribable-dataset";
import { createDataset } from "@ldo/dataset";
import type { GraphType } from "@ldo/jsonld-dataset-proxy";
import type { Quad } from "@rdfjs/types";
import { defaultGraph, namedNode, quad as createQuad } from "@rdfjs/data-model";
import type { GraphNode, DatasetChanges, Quad } from "@ldo/rdf-utils";
import { defaultGraph, namedNode, quad as createQuad } from "@ldo/rdf-utils";
export function graphNodeToString(graphNode: GraphType): string {
export function graphNodeToString(graphNode: GraphNode): string {
return graphNode.termType === "DefaultGraph"
? "defaultGraph()"
: graphNode.value;
}
export function stringToGraphNode(input: string): GraphType {
export function stringToGraphNode(input: string): GraphNode {
return input === "defaultGraph()" ? defaultGraph() : namedNode(input);
}
export function splitChangesByGraph(
changes: DatasetChanges<Quad>,
): Map<GraphType, DatasetChanges<Quad>> {
): Map<GraphNode, DatasetChanges<Quad>> {
const changesMap: Record<string, DatasetChanges<Quad>> = {};
changes.added?.forEach((quad) => {
const graphHash = graphNodeToString(quad.graph as GraphType);
const graphHash = graphNodeToString(quad.graph as GraphNode);
if (!changesMap[graphHash]) {
changesMap[graphHash] = {};
}
@ -32,7 +30,7 @@ export function splitChangesByGraph(
});
changes.removed?.forEach((quad) => {
const graphHash = graphNodeToString(quad.graph as GraphType);
const graphHash = graphNodeToString(quad.graph as GraphNode);
if (!changesMap[graphHash]) {
changesMap[graphHash] = {};
}
@ -44,7 +42,7 @@ export function splitChangesByGraph(
);
});
const finalMap = new Map<GraphType, DatasetChanges<Quad>>();
const finalMap = new Map<GraphNode, DatasetChanges<Quad>>();
Object.entries(changesMap).forEach(([key, value]) => {
finalMap.set(stringToGraphNode(key), value);
});

@ -1,65 +0,0 @@
import { createDataset } from "../src";
import { quad, namedNode, literal } from "@rdfjs/data-model";
// Required for advanced features:
import { dataset as initializeDatasetCore } from "@rdfjs/dataset";
import { ExtendedDatasetFactory } from "../src";
import type {
Dataset,
Quad,
DatasetCoreFactory,
DatasetCore,
} from "@rdfjs/types";
/**
* Create a dataset with default settings
*/
const defaultDataset = createDataset();
/**
* Create a dataset with default settings and initialized values
*/
const initializedQuads = [
quad(
namedNode("http://example.org/cartoons#Tom"),
namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
namedNode("http://example.org/cartoons#Cat"),
),
quad(
namedNode("http://example.org/cartoons#Tom"),
namedNode("http://example.org/cartoons#name"),
literal("Tom"),
),
];
const defaultDataset2 = createDataset(initializedQuads);
/**
* (Advanced Feature) Create a dataset by injecting a chosen datasetCore and datasetCoreFactory
*/
const datasetFactory: DatasetCoreFactory = {
dataset: (quads?: Dataset<Quad> | Quad[]): DatasetCore => {
return initializeDatasetCore(
Array.isArray(quads) ? quads : quads?.toArray(),
);
},
};
const extendedDatasetFactory = new ExtendedDatasetFactory(datasetFactory);
const customDataset = extendedDatasetFactory.dataset(initializedQuads);
/**
* Do all the methods of the RDFJS Dataset interface. For a full list of methods, go to
* https://rdf.js.org/dataset-spec/#data-interfaces
*/
defaultDataset.add(
quad(
namedNode("http://example.org/cartoons#Miuki"),
namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
namedNode("http://example.org/cartoons#Cat"),
),
);
const combinedDataset = defaultDataset.union(defaultDataset2);
const differenceDataset = combinedDataset.difference(customDataset);
// Prints true because "defaultDataset2" and "customDataset" have equal values
// combinedDataset = defaultDataset ∪ defaultDataset2
// differenceDatasset = defaultDataset \ customDataset
// Therefore differenceDataset == defaultDataset
console.log(differenceDataset.equals(defaultDataset));

@ -1,45 +0,0 @@
import { serializedToDataset, serializedToSubscribableDataset } from "../src";
async function run(): Promise<void> {
// Create an ExtendedDataset using Turtle
const turtleData = `
@prefix : <#>.
@prefix elem: <http://purl.org/dc/elements/1.1/>.
@prefix card: </profile/card#>.
:this
elem:author card:me.
`;
const turtleDataset = await serializedToDataset(turtleData, {
baseIRI:
"https://jackson.solidcommunity.net/IndividualChats/jackson.solidcommunity.net/index.ttl#",
// NOTE: the "format" field isn't required because Turtle is the default parser
});
// Create a SubcribableDataset using JSON-LD
const jsonLdData = [
{
"@id":
"https://jackson.solidcommunity.net/IndividualChats/jackson.solidcommunity.net/index.ttl#this",
"http://purl.org/dc/elements/1.1/author": [
{
"@id": "https://jackson.solidcommunity.net/profile/card#me",
},
],
},
{
"@id": "https://jackson.solidcommunity.net/profile/card#me",
},
];
const jsonLdDataset = await serializedToSubscribableDataset(
JSON.stringify(jsonLdData),
{
baseIRI:
"https://jackson.solidcommunity.net/IndividualChats/jackson.solidcommunity.net/index.ttl#",
format: "application/json-ld",
},
);
// Returns true because the input data describes the same triple.
console.log(turtleDataset.equals(jsonLdDataset));
}
run();

@ -1,7 +1,6 @@
import type { DatasetChanges } from "../src";
import { createSubscribableDataset } from "../src";
import { quad, namedNode, literal } from "@rdfjs/data-model";
import type { Dataset } from "@rdfjs/types";
import { quad, namedNode, literal } from "@ldo/rdf-utils";
import type { Dataset, DatasetChanges } from "@ldo/rdf-utils";
// Create an empty subscribable dataset
const subscribableDataset = createSubscribableDataset();

@ -7,9 +7,7 @@
"build": "tsc --project tsconfig.build.json",
"watch": "tsc --watch",
"test": "jest --coverage",
"example:extendedDataset": "ts-node ./example/extendedDatasetExample.ts",
"example:subscribableDataset": "ts-node ./example/subscribableDatasetExample.ts",
"example:loadData": "ts-node ./example/loadDataExample.ts",
"prepublishOnly": "npm run test && npm run build",
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern"
},
@ -24,26 +22,17 @@
},
"homepage": "https://github.com/o-development/o-dataset-pack#readme",
"devDependencies": {
"@rdfjs/types": "^1.0.1",
"@rdfjs/dataset": "^1.1.0",
"@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",
"ts-jest": "^27.1.2",
"ts-node": "^9.1.1"
},
"dependencies": {
"@ldo/dataset": "^0.0.0",
"@rdfjs/data-model": "^1.2.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"
"@ldo/rdf-utils": "^0.0.0"
},
"files": [
"dist"

@ -1,9 +1,11 @@
import type { Dataset, BaseQuad, Term, DatasetFactory } from "@rdfjs/types";
import type {
BulkEditableDataset,
Dataset,
BaseQuad,
Term,
DatasetFactory,
DatasetChanges,
TransactionalDataset,
} from "./types";
} from "@ldo/rdf-utils";
import type { BulkEditableDataset, TransactionalDataset } from "./types";
import { ExtendedDataset } from "@ldo/dataset";
/**

@ -1,15 +1,15 @@
import { EventEmitter } from "events";
import { namedNode, blankNode, defaultGraph } from "@ldo/rdf-utils";
import type {
DatasetChanges,
Dataset,
BaseQuad,
Stream,
Term,
DatasetFactory,
} from "@rdfjs/types";
import { namedNode, blankNode, defaultGraph } from "@rdfjs/data-model";
} from "@ldo/rdf-utils";
import type {
SubscribableTerms,
DatasetChanges,
nodeEventListener,
SubscribableDataset,
TransactionalDataset,

@ -1,4 +1,4 @@
import type { DatasetFactory, BaseQuad, Dataset } from "@rdfjs/types";
import type { DatasetFactory, BaseQuad, Dataset } from "@ldo/rdf-utils";
import WrapperSubscribableDataset from "./WrapperSubscribableDataset";
/**

@ -1,4 +1,4 @@
import type { Dataset, DatasetFactory, Quad } from "@rdfjs/types";
import type { Dataset, DatasetFactory, Quad } from "@ldo/rdf-utils";
import type { WrapperSubscribableDataset } from ".";
import { createDataset } from "@ldo/dataset";
import WrapperSubscribableDatasetFactory from "./WrapperSubscribableDatasetFactory";

@ -1,5 +1,4 @@
import type { ParserOptions } from "n3";
import type { Quad } from "@rdfjs/types";
import type { ParserOptions, Quad } from "@ldo/rdf-utils";
import { createDatasetFromSerializedInput } from "@ldo/dataset";
import { createWrapperSubscribableDatasetFactory } from "./createWrapperSubscribableDataset";
import type WrapperSubscribableDataset from "./WrapperSubscribableDataset";

@ -1,11 +1,9 @@
import type {
Dataset,
NamedNode,
BlankNode,
DefaultGraph,
BaseQuad,
} from "@rdfjs/types";
DatasetChanges,
QuadMatch,
} from "@ldo/rdf-utils";
/**
* An event listeners for nodes
@ -47,7 +45,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* @returns
*/
addListener(
eventName: DatasetEventMatch,
eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -59,7 +57,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* @returns true if the event had listeners, false otherwise.
*/
emit(
eventName: DatasetEventMatch,
eventName: QuadMatch,
dataset: Dataset<InAndOutQuad, InAndOutQuad>,
datasetChanges: DatasetChanges<InAndOutQuad>,
): boolean;
@ -67,7 +65,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(): DatasetEventMatch[];
eventNames(): QuadMatch[];
/**
* Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to events.defaultMaxListeners.
@ -77,42 +75,33 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
/**
* Returns the number of listeners listening to the event named eventName.
*/
listenerCount(eventName: DatasetEventMatch): number;
listenerCount(eventName: QuadMatch): number;
/**
* Returns a copy of the array of listeners for the event named eventName.
*/
listeners(eventName: DatasetEventMatch): nodeEventListener<InAndOutQuad>[];
listeners(eventName: QuadMatch): nodeEventListener<InAndOutQuad>[];
/**
* Alias for emitter.removeListener()
*/
off(
eventName: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): void;
off(eventName: QuadMatch, listener: nodeEventListener<InAndOutQuad>): void;
/**
* 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: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
on(eventName: QuadMatch, listener: nodeEventListener<InAndOutQuad>): this;
/**
* 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: DatasetEventMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
once(eventName: QuadMatch, listener: nodeEventListener<InAndOutQuad>): this;
/**
* 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: DatasetEventMatch,
eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -120,20 +109,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: DatasetEventMatch,
eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
/**
* Removes all listeners, or those of the specified eventName.
*/
removeAllListeners(eventName: DatasetEventMatch): this;
removeAllListeners(eventName: QuadMatch): this;
/**
* Removes the specified listener from the listener array for the event named eventName.
*/
removeListener(
eventName: DatasetEventMatch,
eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>,
): this;
@ -145,7 +134,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: DatasetEventMatch): nodeEventListener<InAndOutQuad>[];
rawListeners(eventName: QuadMatch): nodeEventListener<InAndOutQuad>[];
/**
* ==================================================================

@ -1,13 +1,13 @@
import { namedNode, literal, quad } from "@ldo/rdf-utils";
import type {
Dataset,
DatasetCoreFactory,
Quad,
DatasetCore,
} from "@rdfjs/types";
} from "@ldo/rdf-utils";
import type { BulkEditableDataset } from "../src";
import { ExtendedDatasetFactory } from "@ldo/dataset";
import { ProxyTransactionalDataset } from "../src";
import { namedNode, literal, quad } from "@rdfjs/data-model";
import datasetCoreFactory from "@rdfjs/dataset";
describe("ProxyTransactionalDataset", () => {

@ -7,8 +7,8 @@ import {
quad,
defaultGraph,
blankNode,
} from "@rdfjs/data-model";
import type { Quad, BlankNode } from "@rdfjs/types";
} from "@ldo/rdf-utils";
import type { Quad, BlankNode } from "@ldo/rdf-utils";
import testDataset from "@ldo/dataset/test/dataset.testHelper";
describe("WrapperSubscribableDataset", () => {

Loading…
Cancel
Save