@netwerk-digitaal-erfgoed/network-of-terms-catalog 9.7.2 → 9.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ import { IRI } from '@netwerk-digitaal-erfgoed/network-of-terms-query';
2
+ export declare class Genre {
3
+ readonly iri: IRI;
4
+ readonly name: string;
5
+ constructor(iri: IRI, name: string);
6
+ }
7
+ export declare const dereferenceGenre: (genre: IRI) => Promise<Genre | null>;
8
+ //# sourceMappingURL=genre.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genre.d.ts","sourceRoot":"","sources":["../src/genre.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,kDAAkD,CAAC;AAMrE,qBAAa,KAAK;aAEE,GAAG,EAAE,GAAG;aACR,IAAI,EAAE,MAAM;gBADZ,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM;CAE/B;AAmCD,eAAO,MAAM,gBAAgB,UAjCY,GAAG,KAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAoCjE,CAAC"}
package/build/genre.js ADDED
@@ -0,0 +1,46 @@
1
+ import { QueryEngine } from '@comunica/query-sparql';
2
+ import memoize from 'memoize';
3
+ const queryEngine = new QueryEngine();
4
+ export class Genre {
5
+ iri;
6
+ name;
7
+ constructor(iri, name) {
8
+ this.iri = iri;
9
+ this.name = name;
10
+ }
11
+ }
12
+ const doDereferenceGenre = async (genre) => {
13
+ // We have to fetch first using a single Accept header value of application/rdf+xml, because the Poolparty server
14
+ // does not properly handle complex Accept headers such as those sent by Comunica.
15
+ const result = await fetch(genre.toString(), {
16
+ headers: {
17
+ Accept: 'application/rdf+xml',
18
+ },
19
+ });
20
+ const xml = await result.text();
21
+ try {
22
+ const data = await queryEngine.queryBindings(`SELECT ?prefLabel WHERE {
23
+ ?s a <http://www.w3.org/2004/02/skos/core#Concept> ;
24
+ <http://www.w3.org/2004/02/skos/core#prefLabel> ?prefLabel .
25
+ } LIMIT 1`, {
26
+ sources: [
27
+ {
28
+ type: 'serialized',
29
+ value: xml,
30
+ mediaType: 'application/rdf+xml',
31
+ },
32
+ ],
33
+ });
34
+ const bindings = await data.toArray({ limit: 1 });
35
+ return new Genre(genre, bindings[0].get('prefLabel')?.value ?? '');
36
+ }
37
+ catch (error) {
38
+ console.error(error);
39
+ return null;
40
+ }
41
+ };
42
+ export const dereferenceGenre = memoize(doDereferenceGenre, {
43
+ cacheKey: String,
44
+ maxAge: 86400,
45
+ });
46
+ //# sourceMappingURL=genre.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genre.js","sourceRoot":"","sources":["../src/genre.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAC;AACnD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,OAAO,KAAK;IAEE;IACA;IAFlB,YACkB,GAAQ,EACR,IAAY;QADZ,QAAG,GAAH,GAAG,CAAK;QACR,SAAI,GAAJ,IAAI,CAAQ;IAC3B,CAAC;CACL;AAED,MAAM,kBAAkB,GAAG,KAAK,EAAE,KAAU,EAAyB,EAAE;IACrE,iHAAiH;IACjH,kFAAkF;IAClF,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE;QAC3C,OAAO,EAAE;YACP,MAAM,EAAE,qBAAqB;SAC9B;KACF,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IAChC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,aAAa,CAC1C;;;cAGQ,EACR;YACE,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,YAAY;oBAClB,KAAK,EAAE,GAAG;oBACV,SAAS,EAAE,qBAAqB;iBACjC;aACF;SACF,CACF,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,CAAC,EAAC,CAAC,CAAC;QAChD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,EAAE;IAC1D,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,KAAK;CACd,CAAC,CAAC"}
package/build/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './getCatalog.js';
2
+ export * from './genre.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
package/build/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './getCatalog.js';
2
+ export * from './genre.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netwerk-digitaal-erfgoed/network-of-terms-catalog",
3
- "version": "9.7.2",
3
+ "version": "9.8.0",
4
4
  "type": "module",
5
5
  "description": "Catalog of Network of Terms datasets",
6
6
  "repository": {
@@ -43,9 +43,11 @@
43
43
  "homepage": "https://github.com/netwerk-digitaal-erfgoed/network-of-terms-catalog#readme",
44
44
  "dependencies": {
45
45
  "@comunica/bindings-factory": "^3.2.0",
46
+ "@comunica/query-sparql": "^3.2.0",
46
47
  "@comunica/query-sparql-rdfjs": "^3.2.0",
47
- "@netwerk-digitaal-erfgoed/network-of-terms-query": "5.2.0",
48
+ "@netwerk-digitaal-erfgoed/network-of-terms-query": "5.3.0",
48
49
  "globby": "^14.0.2",
50
+ "memoize": "^10.0.0",
49
51
  "rdf-parse": "^2.3.3",
50
52
  "rdf-store-stream": "^2.0.1"
51
53
  }