Some documentation updates

main
Jackson Morgan 5 months ago
parent 9e61e775cd
commit b6755128db
  1. 7
      packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts
  2. 4
      packages/connected/src/ConnectedContext.ts
  3. 47
      packages/connected/src/ConnectedLdoDataset.ts
  4. 5
      packages/connected/src/ConnectedLdoTransactionDataset.ts
  5. 5
      packages/connected/src/util/splitChangesByGraph.d.ts
  6. 45
      packages/connected/src/util/splitChangesByGraph.js
  7. 1
      packages/connected/src/util/splitChangesByGraph.js.map

@ -41,11 +41,12 @@ export const nextgGraphConnectedPlugin: NextGraphConnectedPlugin = {
"Graph",
// NIKO: Can this always be "data:graph"?
"data:graph",
// NIKO: What are the options here again?
// NIKO: What are the options here again? "private" "protected" "public"
"protected",
// NIKO: What is this? Should it be changed?
// NIKO: What is this? Should it be changed? lookup what the default store
// is
"B381BvfdAFYPBkdhDrsqnMMg5pnJMWJgJbZobZErXZMA",
// NIKO: Can this always be "store"?
// NIKO: Can this always be "store"? yes
"store",
);
return new NextGraphResource(nuri, context);

@ -2,6 +2,10 @@
import type { ConnectedLdoDataset } from "./ConnectedLdoDataset";
import type { ConnectedPlugin } from "./ConnectedPlugin";
/**
* Each Plugin comes with a context. This is the aggregate of all those contexts
* It is passed between the various components of the "connected" library
*/
export type ConnectedContext<
Plugins extends ConnectedPlugin<any, any, any, any>[],
> = {

@ -13,19 +13,55 @@ import type {
import { ConnectedLdoTransactionDataset } from "./ConnectedLdoTransactionDataset";
import type { SubjectNode } from "@ldo/rdf-utils";
/**
* A ConnectedLdoDataset has all the functionality of a LdoDataset with the
* added functionality of keeping track of fetched remote Resources.
*
* It is recommended to use the { @link createConnectedLdoDataset } to
* initialize this class.
*
* @example
* ```typescript
* import { createConnectedLdoDataset } from "@ldo/connected";
* import { ProfileShapeType } from "./.ldo/profile.shapeTypes.ts"
*
* // ...
*
* const connectedLdoDataset = createConnectedLdoDataset();
*
* const profileDocument = connectedLdoDataset
* .getResource("https://example.com/profile");
* await profileDocument.read();
*
* const profile = connectedLdoDataset
* .using(ProfileShapeType)
* .fromSubject("https://example.com/profile#me");
* ```
*/
export class ConnectedLdoDataset<
Plugins extends ConnectedPlugin<any, any, any, any>[],
>
extends LdoDataset
implements IConnectedLdoDataset<Plugins>
{
/**
* @internal
*
* A list of plugins used by this dataset
*/
private plugins: Plugins;
/**
* @internal
*
* A mapping between a resource URI and a Solid resource
* A mapping between a resource URI and a resource
*/
protected resourceMap: Map<string, Plugins[number]["types"]["resource"]>;
/**
* @internal
*
* Context for each plugin (usually utilities for authentication)
*/
protected context: ConnectedContext<Plugins>;
constructor(
@ -47,6 +83,11 @@ export class ConnectedLdoDataset<
);
}
/**
* @internal
*
* A helper function to return a plugin based in the plugin name and uri.
*/
private getValidPlugin(
uri: string,
pluginName?: string,
@ -80,7 +121,7 @@ export class ConnectedLdoDataset<
*
* @example
* ```typescript
* const profileDocument = solidLdoDataset
* const profileDocument = connectedLdoDataset
* .getResource("https://example.com/profile");
* ```
*/
@ -128,7 +169,7 @@ export class ConnectedLdoDataset<
}
/**
* Shorthand for solidLdoDataset
* Shorthand for connectedLdoDataset
* .usingType(shapeType)
* .write(...resources.map((r) => r.uri))
* .fromSubject(subject);

@ -23,8 +23,9 @@ import type {
} from "./results/success/SuccessResult";
/**
* A SolidLdoTransactionDataset has all the functionality of a SolidLdoDataset
* and represents a transaction to the parent SolidLdoDataset.
* A ConnectedLdoTransactionDataset has all the functionality of a
* ConnectedLdoDataset and represents a transaction to the parent
* ConnectedLdoDataset.
*
* It is recommended to use the `startTransaction` method on a SolidLdoDataset
* to initialize this class

@ -1,5 +0,0 @@
import type { GraphNode, DatasetChanges } from "@ldo/rdf-utils";
import type { Quad } from "@rdfjs/types";
export declare function graphNodeToString(graphNode: GraphNode): string;
export declare function stringToGraphNode(input: string): GraphNode;
export declare function splitChangesByGraph(changes: DatasetChanges<Quad>): Map<GraphNode, DatasetChanges<Quad>>;

@ -1,45 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.splitChangesByGraph = exports.stringToGraphNode = exports.graphNodeToString = void 0;
const dataset_1 = require("@ldo/dataset");
const data_model_1 = require("@rdfjs/data-model");
function graphNodeToString(graphNode) {
return graphNode.termType === "DefaultGraph"
? "defaultGraph()"
: graphNode.value;
}
exports.graphNodeToString = graphNodeToString;
function stringToGraphNode(input) {
return input === "defaultGraph()" ? (0, data_model_1.defaultGraph)() : (0, data_model_1.namedNode)(input);
}
exports.stringToGraphNode = stringToGraphNode;
function splitChangesByGraph(changes) {
const changesMap = {};
changes.added?.forEach((quad) => {
const graphHash = graphNodeToString(quad.graph);
if (!changesMap[graphHash]) {
changesMap[graphHash] = {};
}
if (!changesMap[graphHash].added) {
changesMap[graphHash].added = (0, dataset_1.createDataset)();
}
changesMap[graphHash].added?.add((0, data_model_1.quad)(quad.subject, quad.predicate, quad.object, quad.graph));
});
changes.removed?.forEach((quad) => {
const graphHash = graphNodeToString(quad.graph);
if (!changesMap[graphHash]) {
changesMap[graphHash] = {};
}
if (!changesMap[graphHash].removed) {
changesMap[graphHash].removed = (0, dataset_1.createDataset)();
}
changesMap[graphHash].removed?.add((0, data_model_1.quad)(quad.subject, quad.predicate, quad.object, quad.graph));
});
const finalMap = new Map();
Object.entries(changesMap).forEach(([key, value]) => {
finalMap.set(stringToGraphNode(key), value);
});
return finalMap;
}
exports.splitChangesByGraph = splitChangesByGraph;
//# sourceMappingURL=splitChangesByGraph.js.map

@ -1 +0,0 @@
{"version":3,"file":"splitChangesByGraph.js","sourceRoot":"","sources":["splitChangesByGraph.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAG7C,kDAAgF;AAQhF,SAAgB,iBAAiB,CAAC,SAAoB;IACpD,OAAO,SAAS,CAAC,QAAQ,KAAK,cAAc;QAC1C,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC;AACtB,CAAC;AAJD,8CAIC;AAQD,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,OAAO,KAAK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