You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
import {
|
|
ContextUtil,
|
|
JsonldDatasetProxyBuilder,
|
|
} from "@ldo/jsonld-dataset-proxy";
|
|
import { LdoBuilder } from "@ldo/ldo";
|
|
import type { LdoBase, LdoDataset, ShapeType } from "@ldo/ldo";
|
|
import { TrackingProxyContext } from "./TrackingProxyContext";
|
|
import { defaultGraph } from "@rdfjs/data-model";
|
|
import type { nodeEventListener } from "@ldo/subscribable-dataset";
|
|
import type { Quad } from "@rdfjs/types";
|
|
|
|
/**
|
|
* @internal
|
|
* Creates a Linked Data Object builder that when creating linked data objects
|
|
* it tracks when something that was read from it is updated and triggers some
|
|
* action based on that.
|
|
*/
|
|
export function createTrackingProxyBuilder<Type extends LdoBase>(
|
|
dataset: LdoDataset,
|
|
shapeType: ShapeType<Type>,
|
|
onUpdate: nodeEventListener<Quad>,
|
|
): LdoBuilder<Type> {
|
|
// Remove all current subscriptions
|
|
// dataset.removeListenerFromAllEvents(onUpdate);
|
|
|
|
// Rebuild the LdoBuilder from scratch to inject TrackingProxyContext
|
|
const contextUtil = new ContextUtil(shapeType.context);
|
|
const proxyContext = new TrackingProxyContext(
|
|
{
|
|
dataset,
|
|
contextUtil,
|
|
writeGraphs: [defaultGraph()],
|
|
languageOrdering: ["none", "en", "other"],
|
|
},
|
|
onUpdate,
|
|
);
|
|
const builder = new LdoBuilder(
|
|
new JsonldDatasetProxyBuilder(proxyContext),
|
|
shapeType,
|
|
);
|
|
return builder;
|
|
}
|
|
|