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

feat: Option to request and include metadata from ldes #68

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ldes-client <url> [-f] [--save <path>] [--pollInterval <number>] [--shape <shape
- `--shape`: shape file to which LDES members should conform (overwrite LDES configured shape)
- `-t` `--default-timezone`: default timezone to use for dates in tree:InBetweenRelation. `AoE|Z|±HH:mm` Default: `AoE`.
- `--condition <condition_file>`: filter the LDES stream to only emit members that adhere to this condition
- `-m`, `--metadata`: include metadata in the emitted members. Notifies the ldes server that it is interested in metadata.
- Others soon coming


Expand Down
4 changes: 4 additions & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let save: string | undefined;
let onlyDefaultGraph: boolean = false;
let loose: boolean = false;
let defaultTimezone: string | undefined;
let includeMetadata: boolean = false;

const fetch_config: FetchConfig = {
retry: {},
Expand Down Expand Up @@ -94,6 +95,7 @@ program
)
.option("--http-codes [codes...]", "What HTTP codes to retry")
.option("-t --default-timezone <timezone>", "Default timezone for dates in tree:InBetweenRelation", "AoE")
.option("-m, --metadata", "include metadata in the output members")
.action((url: string, program) => {
urlIsView = program.urlIsView;
noShape = !program.shape;
Expand All @@ -110,6 +112,7 @@ program
materialize = program.materializeVersion;
lastVersionOnly = program.lastVersionOnly;
defaultTimezone = program.defaultTimezone;
includeMetadata = program.metadata;

fetch_config.concurrent = parseInt(program.concurrent);
if (program.basicAuth) {
Expand Down Expand Up @@ -165,6 +168,7 @@ async function main() {
defaultTimezone,
materialize,
lastVersionOnly,
includeMetadata,
fetch: enhanced_fetch(fetch_config),
}),
ordered,
Expand Down
1 change: 1 addition & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export class Client {
this.config.loose,
this.config.condition,
this.config.defaultTimezone,
this.config.includeMetadata || false,
this.config.fetch,
);

Expand Down
2 changes: 2 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Config {
onlyDefaultGraph?: boolean;
materialize?: boolean;
lastVersionOnly?: boolean;
includeMetadata?: boolean;
fetch?: typeof fetch;
}

Expand All @@ -41,6 +42,7 @@ const defaultConfig: Config = {
defaultTimezone: "AoE",
materialize: false,
lastVersionOnly: false,
includeMetadata: false,
};

const defaultTarget: WithTarget = {
Expand Down
15 changes: 12 additions & 3 deletions lib/pageFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RdfDereferencer } from "rdf-dereference";
import { IDereferenceOptions, RdfDereferencer } from "rdf-dereference";
import { Notifier } from "./utils";
import { extractRelations, Relation, Relations } from "./page";
import { SimpleRelation } from "./relation";
Expand Down Expand Up @@ -70,6 +70,7 @@ export class Fetcher {
private fetch_f?: typeof fetch;
private condition: Condition;
private defaultTimezone: string;
private includeMetadata: boolean;

private closed = false;

Expand All @@ -80,13 +81,15 @@ export class Fetcher {
loose: boolean,
condition: Condition,
defaultTimezone: string,
includeMetadata: boolean,
fetch_f?: typeof fetch,
) {
this.dereferencer = dereferencer;
this.loose = loose;
this.fetch_f = fetch_f;
this.condition = condition;
this.defaultTimezone = defaultTimezone;
this.includeMetadata = includeMetadata;
}

close() {
Expand All @@ -95,10 +98,16 @@ export class Fetcher {

async fetch<S>(node: Node, state: S, notifier: Notifier<FetchEvent, S>) {
try {
const resp = await this.dereferencer.dereference(node.target, {
const options: IDereferenceOptions = {
localFiles: true,
fetch: this.fetch_f,
});
};
if (this.includeMetadata) {
options.headers = {
Accept: "application/metadata+trig",
};
ajuvercr marked this conversation as resolved.
Show resolved Hide resolved
}
const resp = await this.dereferencer.dereference(node.target, options);

node.target = resp.url;

Expand Down
Loading
Loading