Skip to content

Commit

Permalink
feat: Include created (ingested) timestamp in Member
Browse files Browse the repository at this point in the history
  • Loading branch information
smessie committed Oct 17, 2024
1 parent 1b91f4e commit ef801c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/memberManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Quad, Term } from "@rdfjs/types";
import { Fragment, Member } from "./page";
import { FetchedPage } from "./pageFetcher";
import { CBDShapeExtractor } from "extract-cbd-shape";
import { DC, TREE } from "@treecg/types";
import { DC, LDES, TREE } from "@treecg/types";
import { LDESInfo } from "./client";
import { getObjects, memberFromQuads, Notifier } from "./utils";
import { RdfStore } from "rdf-stores";
Expand Down Expand Up @@ -161,7 +161,7 @@ export class Manager {
member: Term,
data: RdfStore,
): Promise<Quad[]> {
return await this.extractor.extract(data, member, this.shapeId);
return await this.extractor.extract(data, member, this.shapeId, [namedNode(LDES.custom("IngestionMetadata"))]);
}

private async extractMember(
Expand All @@ -171,6 +171,7 @@ export class Manager {
if (this.state.has(member.value)) return;

const quads: Quad[] = await this.extractMemberQuads(member, data);
const created = getObjects(data, member, DC.terms.custom("created"), namedNode(LDES.custom("IngestionMetadata")))[0]?.value;

if (quads.length > 0) {
this.state.add(member.value);
Expand All @@ -179,6 +180,7 @@ export class Manager {
quads,
this.timestampPath,
this.isVersionOfPath,
created ? new Date(created) : undefined,
);
}
}
Expand Down
11 changes: 8 additions & 3 deletions lib/page.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Quad, Term } from "@rdfjs/types";
import { RDF, TREE } from "@treecg/types";
import { DC, LDES, RDF, TREE } from "@treecg/types";
import { CBDShapeExtractor } from "extract-cbd-shape";
import { State } from "./state";
import { RdfStore } from "rdf-stores";
import { getObjects, memberFromQuads } from "./utils";
import { Condition } from "./condition";
import { RelationCondition } from "./condition/range";
import { getLoggerFor } from "./utils/logUtil";
import { DataFactory } from "n3";

const { namedNode } = DataFactory;

export interface Member {
id: Term;
quads: Quad[];
timestamp?: string | Date;
isVersionOf?: string;
type?: Term;
created?: Date;
}

export interface Relations {
Expand Down Expand Up @@ -53,8 +57,9 @@ export function extractMembers(
const members = getObjects(store, stream, TREE.terms.member, null);

async function extractMember(member: Term) {
const quads = await extractor.extract(store, member, shapeId);
cb(memberFromQuads(member, quads, timestampPath, isVersionOfPath));
const quads = await extractor.extract(store, member, shapeId, [namedNode(LDES.custom("IngestionMetadata"))]);
const created = getObjects(store, member, DC.terms.custom("created"), namedNode(LDES.custom("IngestionMetadata")))[0]?.value;
cb(memberFromQuads(member, quads, timestampPath, isVersionOfPath, created ? new Date(created) : undefined));
}

const out: Promise<void>[] = [];
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export function memberFromQuads(
quads: Quad[],
timestampPath: Term | undefined,
isVersionOfPath: Term | undefined,
created?: Date,
): Member {
// Get timestamp
let timestamp: string | Date | undefined;
Expand Down Expand Up @@ -553,7 +554,7 @@ export function memberFromQuads(
const type: Term | undefined = quads.find(
(x) => x.subject.equals(member) && x.predicate.value === RDF.type,
)?.object;
return { quads, id: member, isVersionOf, timestamp, type };
return { quads, id: member, isVersionOf, timestamp, type, created };
}

/**
Expand Down

0 comments on commit ef801c0

Please sign in to comment.