Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose collection, view and interface information #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,26 @@ async function main() {
ordered,
);

if (!quiet) {
client.on("description", (info) => {
if (info.extractor.shapesGraph) {
try {
const mermaid = info.extractor.shapesGraph!.toMermaid(info.shape);
console.log("mermaid:");
console.log(mermaid);
} catch (ex) {
console.log("Failed mermaid extract");
}
} else {
console.log("No mermaid extracted");
}
});
}

if (verbose) {
client.on("relation", (xs) =>
console.log("Relation", xs.source, xs.type.value, xs.node),
);
client.on("fragment", () => {
console.error("Fragment!");
});
Expand Down
44 changes: 23 additions & 21 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config, intoConfig } from "./config";
import { Member } from "./page";
import { Member, Relation } from "./page";
import rdfDereference, { RdfDereferencer } from "rdf-dereference";
import { FileStateFactory, NoStateFactory, StateFactory } from "./state";
import { CBDShapeExtractor } from "extract-cbd-shape";
Expand All @@ -10,7 +10,6 @@ import { Quad_Object, Term } from "@rdfjs/types";
import {
enhanced_fetch,
extractMainNodeShape,
FetchConfig,
getObjects,
ModulatorFactory,
Notifier,
Expand All @@ -24,7 +23,7 @@ import debug from "debug";
import type { Writer } from "@ajuvercr/js-runner";

export { intoConfig } from "./config";
export { retry_fetch, extractMainNodeShape } from "./utils";
export { extractMainNodeShape, retry_fetch } from "./utils";
export type { Member, Page, Relation } from "./page";
export type { Config, ShapeConfig } from "./config";

Expand Down Expand Up @@ -66,7 +65,7 @@ async function getInfo(

const resp = await rdfDereference.dereference(config.shapeFile, {
localFiles: true,
fetch: config.fetch
fetch: config.fetch,
});
const quads = await streamToArray(resp.data);
config.shape = {
Expand Down Expand Up @@ -113,7 +112,7 @@ async function getInfo(
timestampPaths.length,
isVersionOfPaths.length,
);
} catch (ex: any) { }
} catch (ex: any) {}
}

if (shapeIds.length > 1) {
Expand Down Expand Up @@ -164,6 +163,8 @@ type EventKey<T extends EventMap> = string & keyof T;
type EventReceiver<T> = (params: T) => void;

export type ClientEvents = {
relation: Relation;
description: LDESInfo;
fragment: void;
mutable: void;
poll: void;
Expand Down Expand Up @@ -297,6 +298,7 @@ export class Client {
);

const notifier: Notifier<StrategyEvents, {}> = {
relation: (event) => this.emit("relation", event),
error: (ex: any) => this.emit("error", ex),
fragment: () => this.emit("fragment", undefined),
member: (m) => {
Expand Down Expand Up @@ -336,25 +338,26 @@ export class Client {
this.strategy =
this.ordered !== "none"
? new OrderedStrategy(
this.memberManager,
this.fetcher,
notifier,
factory,
this.ordered,
this.config.polling,
this.config.pollInterval,
)
this.memberManager,
this.fetcher,
notifier,
factory,
this.ordered,
this.config.polling,
this.config.pollInterval,
)
: new UnorderedStrategy(
this.memberManager,
this.fetcher,
notifier,
factory,
this.config.polling,
this.config.pollInterval,
);
this.memberManager,
this.fetcher,
notifier,
factory,
this.config.polling,
this.config.pollInterval,
);

logger("Found %d views, choosing %s", viewQuads.length, ldesId.value);
this.strategy.start(ldesId.value);
this.emit("description", info);
}

stream(strategy?: {
Expand Down Expand Up @@ -523,4 +526,3 @@ export async function processor(
}
};
}

5 changes: 3 additions & 2 deletions lib/strategy/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Member } from "../page";
import { Member, Relation } from "../page";
import { FetchedPage } from "../pageFetcher";
import { RelationChain } from "../relation";
import { TREE } from "@treecg/types";
Expand Down Expand Up @@ -28,8 +28,9 @@ export type PageAndRelation = {
};

export type StrategyEvents = {
relation: Relation;
member: Member;
fragment: {};
fragment: { url: string };
mutable: {};
pollCycle: {};
close: {};
Expand Down
3 changes: 2 additions & 1 deletion lib/strategy/ordered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class OrderedStrategy {
this.handleFetched(page, chain);
},
relationFound: ({ from, target }, { chain }) => {
this.notifier.relation(target, {});
from.expected.push(target.node);
logger("Relation found %s", target.node);
const newChain = chain.push(target.node, this.extractRelation(target));
Expand All @@ -119,7 +120,7 @@ export class OrderedStrategy {
logger("Member done %s", rel.target);
const found = this.findOrDefault(rel);
found.extracting -= 1;
this.notifier.fragment({}, {});
this.notifier.fragment({ url: rel.target }, {});
this.checkEmit();
},
extracted: (member) => {
Expand Down
9 changes: 5 additions & 4 deletions lib/strategy/unordered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class UnorderedStrategy {
private inFlight: number = 0;

private fetchNotifier: Notifier<FetchEvent, { index: number }>;
private memberNotifier: Notifier<MemberEvents, {}>;
private memberNotifier: Notifier<MemberEvents, { url: string }>;

private modulator: Modulator<Node>;

Expand Down Expand Up @@ -61,6 +61,7 @@ export class UnorderedStrategy {
this.handleFetched(page, index);
},
relationFound: ({ from, target }) => {
this.notifier.relation(target, {});
from.expected.push(target.node);
this.inFlight += 1;
this.modulator.push({ target: target.node, expected: [from.target] });
Expand All @@ -75,11 +76,11 @@ export class UnorderedStrategy {
error: (error) => {
this.notifier.error(error, {});
},
done: () => {
done: (_, url) => {
memberLogger("Members on page done");
this.inFlight -= 1;
this.checkEnd();
this.notifier.fragment({}, {});
this.notifier.fragment(url, {});
},
extracted: (mem) => this.notifier.member(mem, {}),
};
Expand Down Expand Up @@ -108,7 +109,7 @@ export class UnorderedStrategy {

private handleFetched(page: FetchedPage, index: number) {
this.modulator.finished(index);
this.manager.extractMembers(page, {}, this.memberNotifier);
this.manager.extractMembers(page, { url: page.url }, this.memberNotifier);
}

private checkEnd() {
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ldes-client",
"description": "This package provides common tooling to work with LDESes.",
"version": "0.0.9",
"version": "0.0.9-pr.33.1",
"main": "dist/lib/client.js",
"bin": {
"ldes-client": "dist/bin/cli.js"
Expand All @@ -27,7 +27,7 @@
"@types/debug": "^4.1.12",
"commander": "^11.1.0",
"debug": "^4.3.4",
"extract-cbd-shape": "^0.1.5",
"extract-cbd-shape": "^0.1.6",
"heap-js": "^2.3.0",
"n3": "^1.17.3",
"rdf-data-factory": "^1.1.2",
Expand Down
Loading