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. 15
      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. 33
      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", "test": "lerna run test",
"build": "lerna run build", "build": "lerna run build",
"demo-react": "lerna run start --scope @ldo/demo-react", "demo-react": "lerna run start --scope @ldo/demo-react",
"lint": "lerna run lint", "lint": "lerna run lint"
"postinstall": "npm run build"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.5.7", "@types/node": "^20.5.7",

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

@ -1,4 +1,4 @@
import { serializedToDataset, serializedToSubscribableDataset } from "../src"; import { serializedToDataset } from "../src";
async function run(): Promise<void> { async function run(): Promise<void> {
// Create an ExtendedDataset using Turtle // Create an ExtendedDataset using Turtle
@ -31,14 +31,11 @@ async function run(): Promise<void> {
"@id": "https://jackson.solidcommunity.net/profile/card#me", "@id": "https://jackson.solidcommunity.net/profile/card#me",
}, },
]; ];
const jsonLdDataset = await serializedToSubscribableDataset( const jsonLdDataset = await serializedToDataset(JSON.stringify(jsonLdData), {
JSON.stringify(jsonLdData), baseIRI:
{ "https://jackson.solidcommunity.net/IndividualChats/jackson.solidcommunity.net/index.ttl#",
baseIRI: format: "application/json-ld",
"https://jackson.solidcommunity.net/IndividualChats/jackson.solidcommunity.net/index.ttl#", });
format: "application/json-ld",
},
);
// Returns true because the input data describes the same triple. // Returns true because the input data describes the same triple.
console.log(turtleDataset.equals(jsonLdDataset)); 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", "watch": "tsc --watch",
"test": "jest --coverage", "test": "jest --coverage",
"example:extendedDataset": "ts-node ./example/extendedDatasetExample.ts", "example:extendedDataset": "ts-node ./example/extendedDatasetExample.ts",
"example:subscribableDataset": "ts-node ./example/subscribableDatasetExample.ts",
"example:loadData": "ts-node ./example/loadDataExample.ts", "example:loadData": "ts-node ./example/loadDataExample.ts",
"prepublishOnly": "npm run test && npm run build", "prepublishOnly": "npm run test && npm run build",
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern" "lint": "eslint src/** --fix --no-error-on-unmatched-pattern"

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

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

@ -1,11 +1,9 @@
import type { Dataset, DatasetFactory, Quad } from "@rdfjs/types"; import type { Dataset, DatasetFactory, Quad } from "@ldo/rdf-utils";
import type { ParserOptions } from "n3"; import type { ParserOptions } from "@ldo/rdf-utils";
import { Parser } from "n3"; import { serializedToQuads } from "@ldo/rdf-utils";
// import { Readable } from "readable-stream";
// import ParserJsonld from "@rdfjs/parser-jsonld";
/** /**
* 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 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 data A string representation of RDF Data in JSON-LD, Turtle, N-Triples, TriG, RDF*, or N3.
* @param options Parser options: { * @param options Parser options: {
@ -23,37 +21,6 @@ export default async function createDatasetFromSerializedInput<
data: string, data: string,
options?: ParserOptions, options?: ParserOptions,
): Promise<ReturnDataset> { ): Promise<ReturnDataset> {
// JSON-LD Parsing const quads = await serializedToQuads(data, options);
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);
return datasetFactory.dataset(quads) as unknown as ReturnDataset; return datasetFactory.dataset(quads) as unknown as ReturnDataset;
} }

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

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

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

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

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

@ -1,8 +1,13 @@
import { blankNode, namedNode } from "@rdfjs/data-model"; import { blankNode, namedNode } from "@ldo/rdf-utils";
import type { BlankNode, NamedNode } from "@rdfjs/types"; import type {
BlankNode,
NamedNode,
GraphNode,
QuadMatch,
} from "@ldo/rdf-utils";
import type { LanguageOrdering } from "./language/languageTypes"; import type { LanguageOrdering } from "./language/languageTypes";
import type { ProxyContext } from "./ProxyContext"; 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 * 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 * Designates that all Jsonld Dataset Proxies created should write to the
* specified graphs * specified graphs
*/ */
write(...graphs: GraphType[]): JsonldDatasetProxyBuilder { write(...graphs: GraphNode[]): JsonldDatasetProxyBuilder {
return new JsonldDatasetProxyBuilder( return new JsonldDatasetProxyBuilder(
this.proxyContext.duplicate({ writeGraphs: graphs }), 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 type { ArrayProxyTarget } from "./arrayProxy/createArrayHandler";
import { createArrayHandler } from "./arrayProxy/createArrayHandler"; import { createArrayHandler } from "./arrayProxy/createArrayHandler";
import { createSubjectHandler } from "./subjectProxy/createSubjectHandler"; import { createSubjectHandler } from "./subjectProxy/createSubjectHandler";
import type { SubjectProxy } from "./subjectProxy/SubjectProxy"; import type { SubjectProxy } from "./subjectProxy/SubjectProxy";
import type { ArrayProxy } from "./arrayProxy/ArrayProxy"; import type { ArrayProxy } from "./arrayProxy/ArrayProxy";
import type { GraphType, QuadMatch } from "./types";
import { _getUnderlyingArrayTarget } from "./types"; import { _getUnderlyingArrayTarget } from "./types";
import type { ContextUtil } from "./ContextUtil"; import type { ContextUtil } from "./ContextUtil";
import type { LanguageOrdering } from "./language/languageTypes"; import type { LanguageOrdering } from "./language/languageTypes";
@ -12,7 +17,7 @@ import type { LanguageOrdering } from "./language/languageTypes";
export interface ProxyContextOptions { export interface ProxyContextOptions {
dataset: Dataset; dataset: Dataset;
contextUtil: ContextUtil; contextUtil: ContextUtil;
writeGraphs: GraphType[]; writeGraphs: GraphNode[];
languageOrdering: LanguageOrdering; languageOrdering: LanguageOrdering;
prefilledArrayTargets?: ArrayProxyTarget[]; prefilledArrayTargets?: ArrayProxyTarget[];
state?: Record<string, unknown>; state?: Record<string, unknown>;
@ -29,7 +34,7 @@ export class ProxyContext {
readonly dataset: Dataset; readonly dataset: Dataset;
readonly contextUtil: ContextUtil; readonly contextUtil: ContextUtil;
readonly writeGraphs: GraphType[]; readonly writeGraphs: GraphNode[];
readonly languageOrdering: LanguageOrdering; readonly languageOrdering: LanguageOrdering;
public state: Record<string, unknown>; 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 { ArrayProxyTarget } from "./createArrayHandler";
import type { import type {
ObjectType,
_getNodeAtIndex, _getNodeAtIndex,
_getUnderlyingArrayTarget, _getUnderlyingArrayTarget,
_getUnderlyingDataset, _getUnderlyingDataset,
@ -14,7 +13,7 @@ import type { ProxyContext } from "../ProxyContext";
export type ArrayProxy = Array<unknown> & { export type ArrayProxy = Array<unknown> & {
readonly [_getUnderlyingDataset]: Dataset; readonly [_getUnderlyingDataset]: Dataset;
readonly [_getUnderlyingMatch]: ArrayProxyTarget[0]; readonly [_getUnderlyingMatch]: ArrayProxyTarget[0];
readonly [_getNodeAtIndex]: (index: number) => ObjectType | undefined; readonly [_getNodeAtIndex]: (index: number) => ObjectNode | undefined;
readonly [_getUnderlyingArrayTarget]: ArrayProxyTarget; readonly [_getUnderlyingArrayTarget]: ArrayProxyTarget;
[_proxyContext]: ProxyContext; [_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 type { ObjectJsonRepresentation } from "../util/nodeToJsonldRepresentation";
import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation"; import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation";
import { quad } from "@rdfjs/data-model";
import type { ArrayMethodBuildersType } from "./arrayMethods"; import type { ArrayMethodBuildersType } from "./arrayMethods";
import { arrayMethodsBuilders, methodNames } from "./arrayMethods"; import { arrayMethodsBuilders, methodNames } from "./arrayMethods";
import type { ObjectType, QuadMatch, SubjectType } from "../types";
import { import {
_getNodeAtIndex, _getNodeAtIndex,
_getUnderlyingArrayTarget, _getUnderlyingArrayTarget,
@ -20,7 +24,7 @@ import { filterQuadsByLanguageOrdering } from "../language/languageUtils";
export type ArrayProxyTarget = [ export type ArrayProxyTarget = [
quadMatch: QuadMatch, quadMatch: QuadMatch,
curArray: ObjectType[], curArray: ObjectNode[],
isSubjectOriented?: boolean, isSubjectOriented?: boolean,
isLangStringArray?: boolean, isLangStringArray?: boolean,
]; ];
@ -38,12 +42,12 @@ function updateArrayOrder(
quads.toArray().forEach((quad) => { quads.toArray().forEach((quad) => {
// If this this a subject-oriented document // If this this a subject-oriented document
if (target[2]) { if (target[2]) {
datasetObjects.add(quad.subject as SubjectType); datasetObjects.add(quad.subject as SubjectNode);
} else { } else {
datasetObjects.add(quad.object as ObjectType); datasetObjects.add(quad.object as ObjectNode);
} }
}); });
const processedObjects: ObjectType[] = []; const processedObjects: ObjectNode[] = [];
target[1].forEach((arrItem) => { target[1].forEach((arrItem) => {
if (datasetObjects.has(arrItem)) { if (datasetObjects.has(arrItem)) {
processedObjects.push(arrItem); processedObjects.push(arrItem);
@ -82,7 +86,7 @@ export function createArrayHandler(
case _proxyContext: case _proxyContext:
return proxyContext; return proxyContext;
case _getNodeAtIndex: case _getNodeAtIndex:
return (index: number): ObjectType | undefined => { return (index: number): ObjectNode | undefined => {
updateArrayOrder(target, proxyContext); updateArrayOrder(target, proxyContext);
return target[1][index]; return target[1][index];
}; };

@ -1,9 +1,8 @@
import { defaultGraph } from "@rdfjs/data-model"; import { defaultGraph } from "@ldo/rdf-utils";
import type { Quad } from "@rdfjs/types"; import type { Quad, ObjectNode } from "@ldo/rdf-utils";
import { ProxyTransactionalDataset } from "@ldo/subscribable-dataset"; import { ProxyTransactionalDataset } from "@ldo/subscribable-dataset";
import { createDatasetFactory } from "@ldo/dataset"; import { createDatasetFactory } from "@ldo/dataset";
import type { ProxyContext } from "../ProxyContext"; import type { ProxyContext } from "../ProxyContext";
import type { ObjectType } from "../types";
import { addObjectToDataset } from "../util/addObjectToDataset"; import { addObjectToDataset } from "../util/addObjectToDataset";
import { import {
getNodeFromRawObject, getNodeFromRawObject,
@ -121,7 +120,7 @@ export function modifyArray<ReturnType>(
.map((addedValue) => { .map((addedValue) => {
return getNodeFromRawValue(key, addedValue, proxyContext); return getNodeFromRawValue(key, addedValue, proxyContext);
}) })
.filter((val) => val != undefined) as ObjectType[]) .filter((val) => val != undefined) as ObjectNode[])
: []; : [];
// Allow the base array to be modified // 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 { import {
getSubjectProxyFromObject, getSubjectProxyFromObject,
isSubjectProxy, isSubjectProxy,
} from "./subjectProxy/isSubjectProxy"; } from "./subjectProxy/isSubjectProxy";
import type { GraphType, ObjectLike, ObjectType } from "./types"; import type { ObjectLike } from "./types";
import { import {
_getNodeAtIndex, _getNodeAtIndex,
_getUnderlyingDataset, _getUnderlyingDataset,
@ -25,14 +26,14 @@ export function graphOf<Subject extends ObjectLike, Key extends keyof Subject>(
object?: NonNullable<Subject[Key]> extends Array<unknown> object?: NonNullable<Subject[Key]> extends Array<unknown>
? number | ObjectLike ? number | ObjectLike
: ObjectLike, : ObjectLike,
): GraphType[] { ): GraphNode[] {
const subjectProxy = getSubjectProxyFromObject(subject); const subjectProxy = getSubjectProxyFromObject(subject);
const proxyContext = subjectProxy[_proxyContext]; const proxyContext = subjectProxy[_proxyContext];
const subjectNode = subjectProxy[_getUnderlyingNode]; const subjectNode = subjectProxy[_getUnderlyingNode];
const predicateNode = namedNode( const predicateNode = namedNode(
proxyContext.contextUtil.keyToIri(predicate as string), proxyContext.contextUtil.keyToIri(predicate as string),
); );
let objectNode: ObjectType | null; let objectNode: ObjectNode | null;
if (object == null) { if (object == null) {
objectNode = null; objectNode = null;
} else if (typeof object === "number") { } else if (typeof object === "number") {
@ -58,5 +59,5 @@ export function graphOf<Subject extends ObjectLike, Key extends keyof Subject>(
predicateNode, predicateNode,
objectNode, 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 { defaultGraph } from "@ldo/rdf-utils";
import type { Dataset } from "@rdfjs/types"; import type { Dataset } from "@ldo/rdf-utils";
import type { ContextDefinition } from "jsonld"; import type { ContextDefinition } from "jsonld";
import { ContextUtil } from "./ContextUtil"; import { ContextUtil } from "./ContextUtil";
import { JsonldDatasetProxyBuilder } from "./JsonldDatasetProxyBuilder"; 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 { ProxyContext } from "../ProxyContext";
import type { PredicateType, SubjectType } from "../types";
import { import {
languageKeyToLiteralLanguage, languageKeyToLiteralLanguage,
quadsToLanguageQuadMap, quadsToLanguageQuadMap,
@ -12,8 +12,8 @@ import LanguageSet from "./languageSet";
export function createLanguageMapProxy< export function createLanguageMapProxy<
Target extends LanguageMap | LanguageSetMap, Target extends LanguageMap | LanguageSetMap,
>( >(
subject: SubjectType, subject: SubjectNode,
predicate: PredicateType, predicate: PredicateNode,
proxyContext: ProxyContext, proxyContext: ProxyContext,
isArray: boolean, isArray: boolean,
): Target { ): Target {

@ -1,20 +1,24 @@
import type { Dataset, Literal } from "@rdfjs/types"; import { literal, quad } from "@ldo/rdf-utils";
import type { PredicateType, SubjectType } from "../types"; import type {
Dataset,
Literal,
PredicateNode,
SubjectNode,
} from "@ldo/rdf-utils";
import type { LanguageKey } from "./languageTypes"; import type { LanguageKey } from "./languageTypes";
import type { LiteralObjectQuad } from "./languageUtils"; import type { LiteralObjectQuad } from "./languageUtils";
import { languageDeleteMatch, languageMatch } from "./languageUtils"; import { languageDeleteMatch, languageMatch } from "./languageUtils";
import { literal, quad } from "@rdfjs/data-model";
import type { ProxyContext } from "../ProxyContext"; import type { ProxyContext } from "../ProxyContext";
export default class LanguageSet implements Set<string> { export default class LanguageSet implements Set<string> {
private subject: SubjectType; private subject: SubjectNode;
private predicate: PredicateType; private predicate: PredicateNode;
private languageKey: LanguageKey; private languageKey: LanguageKey;
private proxyContext: ProxyContext; private proxyContext: ProxyContext;
constructor( constructor(
subject: SubjectType, subject: SubjectNode,
predicate: PredicateType, predicate: PredicateNode,
languageKey: LanguageKey, languageKey: LanguageKey,
proxyContext: ProxyContext, 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 { createDataset } from "@ldo/dataset";
import type { PredicateType, SubjectType } from "../types";
import type { LanguageKey, LanguageOrdering } from "./languageTypes"; import type { LanguageKey, LanguageOrdering } from "./languageTypes";
/** /**
@ -13,8 +20,8 @@ import type { LanguageKey, LanguageOrdering } from "./languageTypes";
*/ */
export function languageMatch( export function languageMatch(
dataset: Dataset, dataset: Dataset,
subject: SubjectType, subject: ObjectNode,
predicate: PredicateType, predicate: PredicateNode,
languageKey: LanguageKey, languageKey: LanguageKey,
): Dataset<LiteralObjectQuad> { ): Dataset<LiteralObjectQuad> {
const literalLanguage = languageKeyToLiteralLanguage(languageKey); const literalLanguage = languageKeyToLiteralLanguage(languageKey);
@ -34,8 +41,8 @@ export function languageMatch(
*/ */
export function languageDeleteMatch( export function languageDeleteMatch(
dataset: Dataset, dataset: Dataset,
subject: SubjectType, subject: SubjectNode,
predicate: PredicateType, predicate: PredicateNode,
languageKey: LanguageKey, languageKey: LanguageKey,
): void { ): void {
const quadsToDelete = languageMatch(dataset, subject, predicate, languageKey); 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 { getSubjectProxyFromObject } from "../subjectProxy/isSubjectProxy";
import type { ObjectLike } from "../types"; import type { ObjectLike } from "../types";
import { _getUnderlyingNode, _proxyContext } 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 { ContextDefinition } from "jsonld";
import type { ProxyContext } from "../ProxyContext"; import type { ProxyContext } from "../ProxyContext";
import type { import type {
GraphType,
_getUnderlyingDataset, _getUnderlyingDataset,
_getUnderlyingNode, _getUnderlyingNode,
_proxyContext, _proxyContext,
@ -16,5 +15,5 @@ export type SubjectProxy = {
readonly [_getUnderlyingDataset]: Dataset; readonly [_getUnderlyingDataset]: Dataset;
readonly [_getUnderlyingNode]: NamedNode | BlankNode; readonly [_getUnderlyingNode]: NamedNode | BlankNode;
[_proxyContext]: ProxyContext; [_proxyContext]: ProxyContext;
readonly [_writeGraphs]: GraphType[]; readonly [_writeGraphs]: GraphNode[];
}; };

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

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

@ -1,5 +1,5 @@
import type { SubjectProxyTarget } from "./createSubjectHandler"; import type { SubjectProxyTarget } from "./createSubjectHandler";
import { namedNode } from "@rdfjs/data-model"; import { namedNode } from "@ldo/rdf-utils";
import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation"; import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation";
import type { SubjectProxy } from "./SubjectProxy"; import type { SubjectProxy } from "./SubjectProxy";
import type { ArrayProxy } from "../arrayProxy/ArrayProxy"; 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 _getUnderlyingNode = Symbol("_getUnderlyingNode");
export const _getUnderlyingMatch = Symbol("_getUnderlyingMatch"); export const _getUnderlyingMatch = Symbol("_getUnderlyingMatch");
export const _isSubjectOriented = Symbol("_isSubjectOriented"); export const _isSubjectOriented = Symbol("_isSubjectOriented");

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

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

@ -1,5 +1,5 @@
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types"; import type { BlankNode, Literal, NamedNode } from "@ldo/rdf-utils";
import { namedNode, literal, blankNode } from "@rdfjs/data-model"; import { namedNode, literal, blankNode } from "@ldo/rdf-utils";
import type { ContextUtil } from "../ContextUtil"; import type { ContextUtil } from "../ContextUtil";
import { _getUnderlyingNode } from "../types"; import { _getUnderlyingNode } from "../types";
import type { RawObject, RawValue } from "./RawObject"; 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 { ProxyContext } from "../ProxyContext";
import type { SubjectProxy } from "../subjectProxy/SubjectProxy"; import type { SubjectProxy } from "../subjectProxy/SubjectProxy";

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

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

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

@ -22,7 +22,6 @@
}, },
"homepage": "https://github.com/o-development/ldo#readme", "homepage": "https://github.com/o-development/ldo#readme",
"devDependencies": { "devDependencies": {
"@rdfjs/types": "^1.1.0",
"@types/jest": "^27.0.3", "@types/jest": "^27.0.3",
"@types/jsonld": "^1.5.6", "@types/jsonld": "^1.5.6",
"@types/n3": "^1.10.4", "@types/n3": "^1.10.4",
@ -36,10 +35,9 @@
"dependencies": { "dependencies": {
"@ldo/dataset": "^0.0.0", "@ldo/dataset": "^0.0.0",
"@ldo/jsonld-dataset-proxy": "^0.0.0", "@ldo/jsonld-dataset-proxy": "^0.0.0",
"@ldo/rdf-utils": "^0.0.0",
"@ldo/subscribable-dataset": "^0.0.0", "@ldo/subscribable-dataset": "^0.0.0",
"@rdfjs/data-model": "^1.2.0",
"buffer": "^6.0.3", "buffer": "^6.0.3",
"n3": "^1.16.2",
"readable-stream": "^4.3.0" "readable-stream": "^4.3.0"
}, },
"overrides": { "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 jsonldDatasetProxy from "@ldo/jsonld-dataset-proxy";
import { WrapperSubscribableDataset } from "@ldo/subscribable-dataset"; import { WrapperSubscribableDataset } from "@ldo/subscribable-dataset";
import { LdoBuilder } from "./LdoBuilder"; 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"; 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 { createDataset } from "@ldo/dataset";
import { LdoDatasetFactory } from "./LdoDatasetFactory"; 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 { 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 { import {
getProxyFromObject, getProxyFromObject,
_getUnderlyingDataset, _getUnderlyingDataset,
_proxyContext, _proxyContext,
write as writeDependency, write as writeDependency,
} from "@ldo/jsonld-dataset-proxy"; } from "@ldo/jsonld-dataset-proxy";
import type { Quad, WriterOptions } from "n3"; import type { SubscribableDataset } from "@ldo/subscribable-dataset";
import type { import type { WriterOptions, Dataset, Quad } from "@ldo/rdf-utils";
DatasetChanges, import { changesToSparqlUpdate, datasetToString } from "@ldo/rdf-utils";
SubscribableDataset,
} from "@ldo/subscribable-dataset";
import { datasetToString } from "./datasetConverters";
import type { LdoBase } from "./util"; import type { LdoBase } from "./util";
import { import {
canDatasetStartTransaction, canDatasetStartTransaction,
@ -26,7 +23,7 @@ export {
setLanguagePreferences, setLanguagePreferences,
} from "@ldo/jsonld-dataset-proxy"; } from "@ldo/jsonld-dataset-proxy";
export function write(...graphs: (GraphType | string)[]): InteractOptions { export function write(...graphs: (GraphNode | string)[]): InteractOptions {
return writeDependency(...normalizeNodeNames(graphs)); return writeDependency(...normalizeNodeNames(graphs));
} }
@ -72,21 +69,7 @@ export function getDataset(ldo: LdoBase): Dataset {
export async function toSparqlUpdate(ldo: LdoBase): Promise<string> { export async function toSparqlUpdate(ldo: LdoBase): Promise<string> {
const [dataset] = getTransactionalDatasetFromLdo(ldo); const [dataset] = getTransactionalDatasetFromLdo(ldo);
const changes = dataset.getChanges(); const changes = dataset.getChanges();
let output = ""; return changesToSparqlUpdate(changes);
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", " ");
} }
export async function serialize( 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 { JsonLdDocument } from "jsonld";
import type { ParserOptions } from "n3"; import type { ParserOptions } from "@ldo/rdf-utils";
import { createDatasetFromSerializedInput } from "@ldo/dataset"; import { createDatasetFromSerializedInput } from "@ldo/dataset";
import { createLdoDataset, createLdoDatasetFactory } from "./createLdoDataset"; import { createLdoDataset, createLdoDatasetFactory } from "./createLdoDataset";
import type { LdoDataset } from "./LdoDataset"; import type { LdoDataset } from "./LdoDataset";

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

@ -22,11 +22,11 @@
}, },
"homepage": "https://github.com/o-development/devtool-boilerplate#readme", "homepage": "https://github.com/o-development/devtool-boilerplate#readme",
"devDependencies": { "devDependencies": {
"@rdfjs/types": "^1.1.0",
"@types/jsonld": "^1.5.9" "@types/jsonld": "^1.5.9"
}, },
"dependencies": { "dependencies": {
"@rdfjs/data-model": "^2.0.1", "@rdfjs/data-model": "^2.0.1",
"@rdfjs/types": "^1.1.0",
"n3": "^1.17.1", "n3": "^1.17.1",
"rdf-string": "^1.6.3" "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 { ContextDefinition, JsonLdDocument } from "jsonld";
import type { WriterOptions } from "n3"; import type { WriterOptions as WriterOptionsImport } from "n3";
import { Writer } from "n3"; import { Writer } from "n3";
// import SerializerJsonld from "@rdfjs/serializer-jsonld"; // import SerializerJsonld from "@rdfjs/serializer-jsonld";
// import { Readable } from "readable-stream"; // import { Readable } from "readable-stream";
export async function datasetToString( export type WriterOptions = WriterOptionsImport;
dataset: Dataset,
export function datasetToString(
dataset: DatasetCore<Quad>,
options: WriterOptions, options: WriterOptions,
): Promise<string> { ): string {
return new Promise<string>((resolve, reject) => { const writer = new Writer(options);
const writer = new Writer(options); const quadArr: Quad[] = [];
for (const quad of dataset) { for (const quad of dataset) {
writer.addQuad(quad); quadArr.push(quad);
} }
writer.end(async (error, parsedString: string) => { return writer.quadsToString(quadArr);
/* istanbul ignore if */
if (error) {
return reject(error);
}
return resolve(parsedString);
});
});
} }
export async function datasetToJsonLd( export async function datasetToJsonLd(
_dataset: Dataset, _dataset: DatasetCore,
_context: ContextDefinition, _context: ContextDefinition,
): Promise<JsonLdDocument> { ): Promise<JsonLdDocument> {
throw new Error("JSONLD serialization is not omplemented"); throw new Error("JSONLD serialization is not omplemented");

@ -3,3 +3,4 @@ export * from "@rdfjs/types";
export * from "@rdfjs/data-model"; export * from "@rdfjs/data-model";
export * from "./datasetChanges"; export * from "./datasetChanges";
export * from "./datasetConverters"; 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-env": "^7.22.10",
"@babel/preset-react": "^7.22.5", "@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.11", "@babel/preset-typescript": "^7.22.11",
"@rdfjs/types": "^1.1.0",
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
"@types/jsonld": "^1.5.8", "@types/jsonld": "^1.5.8",
"@types/n3": "^1.10.4", "@types/n3": "^1.10.4",

@ -5,11 +5,7 @@ import { createLdoDataset } from "@ldo/ldo";
import type { LdoContextData } from "./LdoContext"; import type { LdoContextData } from "./LdoContext";
import { LdoContextProvider } from "./LdoContext"; import { LdoContextProvider } from "./LdoContext";
import { UpdateManager } from "./ldoHooks/helpers/UpdateManager"; import { UpdateManager } from "./ldoHooks/helpers/UpdateManager";
import { BinaryResourceStore } from "./document/resource/binaryResource/BinaryResourceStore"; import type { Dataset } from "@ldo/rdf-utils";
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";
export interface LdoProviderProps extends PropsWithChildren { export interface LdoProviderProps extends PropsWithChildren {
fetch?: typeof fetch; fetch?: typeof fetch;

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

@ -1,35 +1,27 @@
import type { DatasetChanges } from "@ldo/subscribable-dataset"; import type { DatasetChanges } from "@ldo/subscribable-dataset";
import { createDataset } from "@ldo/dataset"; import { createDataset } from "@ldo/dataset";
import { quadMatchToString } from "@ldo/rdf-utils";
import type { import type {
Quad,
QuadMatch, QuadMatch,
SubjectType, SubjectNode,
PredicateType, PredicateNode,
ObjectType, ObjectNode,
} from "@ldo/jsonld-dataset-proxy"; } from "@ldo/rdf-utils";
import { nodeToString } from "@ldo/jsonld-dataset-proxy";
import type { Quad } from "@rdfjs/types";
export type TripleMatch = [QuadMatch[0], QuadMatch[1], QuadMatch[2]];
export class UpdateManager { export class UpdateManager {
private tripleMatchListenerMap: Record<string, Set<() => void>> = {}; private quadMatchListenerMap: Record<string, Set<() => void>> = {};
private listenerHashMap: Map<() => void, Set<string>> = new Map(); private listenerHashMap: Map<() => void, Set<string>> = new Map();
private tripleMatchToHash(tripleMatch: TripleMatch): string { registerListener(quadMatch: QuadMatch, callback: () => void): void {
return `${nodeToString(tripleMatch[0])}${nodeToString( const hash = quadMatchToString(quadMatch);
tripleMatch[1], if (!this.quadMatchListenerMap[hash]) {
)}${nodeToString(tripleMatch[2])}`; this.quadMatchListenerMap[hash] = new Set();
}
registerListener(tripleMatch: TripleMatch, callback: () => void): void {
const hash = this.tripleMatchToHash(tripleMatch);
if (!this.tripleMatchListenerMap[hash]) {
this.tripleMatchListenerMap[hash] = new Set();
} }
if (!this.listenerHashMap.has(callback)) { if (!this.listenerHashMap.has(callback)) {
this.listenerHashMap.set(callback, new Set()); this.listenerHashMap.set(callback, new Set());
} }
this.tripleMatchListenerMap[hash].add(callback); this.quadMatchListenerMap[hash].add(callback);
this.listenerHashMap.get(callback)?.add(hash); this.listenerHashMap.get(callback)?.add(hash);
} }
@ -37,7 +29,7 @@ export class UpdateManager {
const hashSet = this.listenerHashMap.get(callback); const hashSet = this.listenerHashMap.get(callback);
if (hashSet) { if (hashSet) {
hashSet.forEach((hash) => { 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 // Cast the input because RDFJS types assume RDF 1.2 where a Subject can
// be a Quad // be a Quad
const quad = tempQuad as { const quad = tempQuad as {
subject: SubjectType; subject: SubjectNode;
predicate: PredicateType; predicate: PredicateNode;
object: ObjectType; object: ObjectNode;
}; };
const tripleMatches: TripleMatch[] = [ const quadMatches: QuadMatch[] = [
[null, null, null], [null, null, null, null],
[quad.subject, null, null], [quad.subject, null, null, null],
[quad.subject, quad.predicate, null], [quad.subject, quad.predicate, null, null],
[quad.subject, null, quad.object], [quad.subject, null, quad.object, null],
[null, quad.predicate, null], [null, quad.predicate, null, null],
[null, quad.predicate, quad.object], [null, quad.predicate, quad.object, null],
[null, null, quad.object], [null, null, quad.object, null],
[quad.subject, quad.predicate, quad.object], [quad.subject, quad.predicate, quad.object, null],
]; ];
tripleMatches.forEach((tripleMatch) => { quadMatches.forEach((quadMatch) => {
const hash = this.tripleMatchToHash(tripleMatch); const hash = quadMatchToString(quadMatch);
this.tripleMatchListenerMap[hash]?.forEach((callback) => { this.quadMatchListenerMap[hash]?.forEach((callback) => {
listenersToNotify.add(callback); listenersToNotify.add(callback);
}); });
delete this.tripleMatchListenerMap[hash]; delete this.quadMatchListenerMap[hash];
}); });
}); });
listenersToNotify.forEach((listener) => { 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 { import {
ContextUtil, ContextUtil,
JsonldDatasetProxyBuilder, JsonldDatasetProxyBuilder,
@ -8,11 +9,10 @@ import { LdoBuilder } from "@ldo/ldo";
import { useLdoContext } from "../LdoContext"; import { useLdoContext } from "../LdoContext";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { TrackingProxyContext } from "./helpers/TrackingProxyContext"; import { TrackingProxyContext } from "./helpers/TrackingProxyContext";
import { defaultGraph } from "@rdfjs/data-model";
export function useSubject<Type extends LdoBase>( export function useSubject<Type extends LdoBase>(
shapeType: ShapeType<Type>, shapeType: ShapeType<Type>,
subject: string | SubjectType, subject: string | SubjectNode,
): [Type, undefined] | [undefined, Error] { ): [Type, undefined] | [undefined, Error] {
const { dataset, updateManager } = useLdoContext(); 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 { BinaryResource } from "./document/resource/binaryResource/BinaryResource";
import type { ContainerResource } from "./document/resource/dataResource/containerResource/ContainerResource"; import type { ContainerResource } from "./document/resource/dataResource/containerResource/ContainerResource";
import type { AccessRules } from "./document/accessRules/AccessRules"; import type { AccessRules } from "./document/accessRules/AccessRules";
import type { SubjectType } from "@ldo/jsonld-dataset-proxy";
import type { DatasetChanges } from "@ldo/subscribable-dataset"; import type { DatasetChanges } from "@ldo/subscribable-dataset";
import type { Quad } from "@rdfjs/types"; import type { Quad, SubjectNode } from "@ldo/rdf-utils";
export interface UseLdoReturn { export interface UseLdoReturn {
changeData<Type extends LdoBase>(input: Type, ...resources: Resource[]): Type; changeData<Type extends LdoBase>(input: Type, ...resources: Resource[]): Type;
commitData(input: LdoBase): Promise<void>; commitData(input: LdoBase): Promise<void>;
createData<Type extends LdoBase>( createData<Type extends LdoBase>(
shapeType: ShapeType<Type>, shapeType: ShapeType<Type>,
subject: string | SubjectType, subject: string | SubjectNode,
...resources: Resource[] ...resources: Resource[]
): Type; ): Type;
dataset: LdoDataset; dataset: LdoDataset;

@ -24,16 +24,13 @@
"homepage": "https://github.com/o-development/devtool-boilerplate#readme", "homepage": "https://github.com/o-development/devtool-boilerplate#readme",
"devDependencies": { "devDependencies": {
"@ldo/cli": "^0.0.0", "@ldo/cli": "^0.0.0",
"@ldo/jsonld-dataset-proxy": "^0.0.0",
"@rdfjs/types": "^1.1.0",
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
"ts-jest": "^29.0.2" "ts-jest": "^29.0.2"
}, },
"dependencies": { "dependencies": {
"@inrupt/solid-client": "^1.29.0",
"@ldo/dataset": "^0.0.0", "@ldo/dataset": "^0.0.0",
"@ldo/ldo": "^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" "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 { ContainerResourceStore } from "./document/resource/dataResource/containerResource/ContainerResourceStore";
import type { AccessRulesStore } from "./document/accessRules/AccessRulesStore"; import type { AccessRulesStore } from "./document/accessRules/AccessRulesStore";
import type { BinaryResourceStore } from "./document/resource/binaryResource/BinaryResourceStore"; 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 type { Resource } from "./document/resource/Resource";
import { DocumentError } from "./document/errors/DocumentError"; import type { DocumentError } from "./document/errors/DocumentError";
export interface SolidLdoDatasetArgs { export interface SolidLdoDatasetArgs {
dataResourceStore: DataResourceStore; 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 { export interface CreateSolidLdoDatasetOptions {
throw new Error("Not Implemented"); 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 { Resource } from "../Resource";
import { DocumentFetchError } from "../../errors/DocumentFetchError"; import { DocumentFetchError } from "../../errors/DocumentFetchError";
import { DocumentError } from "../../errors/DocumentError"; import { DocumentError } from "../../errors/DocumentError";
import { namedNode, quad as createQuad } from "@rdfjs/data-model"; import {
import type { DatasetChanges } from "@ldo/subscribable-dataset"; namedNode,
import type { Quad } from "@rdfjs/types"; quad as createQuad,
import { changesToSparqlUpdate } from "../../../util/changesToSparqlUpdate"; changesToSparqlUpdate,
} from "@ldo/rdf-utils";
import type { DatasetChanges, Quad } from "@ldo/rdf-utils";
import type { SolidLdoDataset } from "../../../SolidLdoDataset"; import type { SolidLdoDataset } from "../../../SolidLdoDataset";
export interface DataResourceDependencies extends ResourceDependencies { export interface DataResourceDependencies extends ResourceDependencies {

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

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

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

@ -1,15 +1,15 @@
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { namedNode, blankNode, defaultGraph } from "@ldo/rdf-utils";
import type { import type {
DatasetChanges,
Dataset, Dataset,
BaseQuad, BaseQuad,
Stream, Stream,
Term, Term,
DatasetFactory, DatasetFactory,
} from "@rdfjs/types"; } from "@ldo/rdf-utils";
import { namedNode, blankNode, defaultGraph } from "@rdfjs/data-model";
import type { import type {
SubscribableTerms, SubscribableTerms,
DatasetChanges,
nodeEventListener, nodeEventListener,
SubscribableDataset, SubscribableDataset,
TransactionalDataset, 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"; 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 type { WrapperSubscribableDataset } from ".";
import { createDataset } from "@ldo/dataset"; import { createDataset } from "@ldo/dataset";
import WrapperSubscribableDatasetFactory from "./WrapperSubscribableDatasetFactory"; import WrapperSubscribableDatasetFactory from "./WrapperSubscribableDatasetFactory";

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

@ -1,11 +1,9 @@
import type { import type {
Dataset, Dataset,
NamedNode,
BlankNode,
DefaultGraph,
BaseQuad, BaseQuad,
} from "@rdfjs/types"; DatasetChanges,
QuadMatch,
} from "@ldo/rdf-utils";
/** /**
* An event listeners for nodes * An event listeners for nodes
@ -47,7 +45,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* @returns * @returns
*/ */
addListener( addListener(
eventName: DatasetEventMatch, eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>, listener: nodeEventListener<InAndOutQuad>,
): this; ): this;
@ -59,7 +57,7 @@ export interface SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
* @returns true if the event had listeners, false otherwise. * @returns true if the event had listeners, false otherwise.
*/ */
emit( emit(
eventName: DatasetEventMatch, eventName: QuadMatch,
dataset: Dataset<InAndOutQuad, InAndOutQuad>, dataset: Dataset<InAndOutQuad, InAndOutQuad>,
datasetChanges: DatasetChanges<InAndOutQuad>, datasetChanges: DatasetChanges<InAndOutQuad>,
): boolean; ): 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. * 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. * 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. * 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. * 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() * Alias for emitter.removeListener()
*/ */
off( off(eventName: QuadMatch, listener: nodeEventListener<InAndOutQuad>): void;
eventName: DatasetEventMatch,
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. * 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( on(eventName: QuadMatch, listener: nodeEventListener<InAndOutQuad>): this;
eventName: DatasetEventMatch,
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. * 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( once(eventName: QuadMatch, listener: nodeEventListener<InAndOutQuad>): this;
eventName: DatasetEventMatch,
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. * 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( prependListener(
eventName: DatasetEventMatch, eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>, listener: nodeEventListener<InAndOutQuad>,
): this; ): 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. * 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( prependOnceListener(
eventName: DatasetEventMatch, eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>, listener: nodeEventListener<InAndOutQuad>,
): this; ): this;
/** /**
* Removes all listeners, or those of the specified eventName. * 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. * Removes the specified listener from the listener array for the event named eventName.
*/ */
removeListener( removeListener(
eventName: DatasetEventMatch, eventName: QuadMatch,
listener: nodeEventListener<InAndOutQuad>, listener: nodeEventListener<InAndOutQuad>,
): this; ): 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()). * 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 { import type {
Dataset, Dataset,
DatasetCoreFactory, DatasetCoreFactory,
Quad, Quad,
DatasetCore, DatasetCore,
} from "@rdfjs/types"; } from "@ldo/rdf-utils";
import type { BulkEditableDataset } from "../src"; import type { BulkEditableDataset } from "../src";
import { ExtendedDatasetFactory } from "@ldo/dataset"; import { ExtendedDatasetFactory } from "@ldo/dataset";
import { ProxyTransactionalDataset } from "../src"; import { ProxyTransactionalDataset } from "../src";
import { namedNode, literal, quad } from "@rdfjs/data-model";
import datasetCoreFactory from "@rdfjs/dataset"; import datasetCoreFactory from "@rdfjs/dataset";
describe("ProxyTransactionalDataset", () => { describe("ProxyTransactionalDataset", () => {

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

Loading…
Cancel
Save