@lde/dataset-registry-client 0.4.0 → 0.4.3

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.
package/README.md CHANGED
@@ -1,4 +1,3 @@
1
1
  # Dataset registry Client
2
2
 
3
3
  A client for registries that contain [DCAT-AP 3.0](https://semiceu.github.io/DCAT-AP/releases/3.0.0/) dataset descriptions.
4
-
@@ -0,0 +1,74 @@
1
+ import { Dataset } from '@lde/dataset';
2
+ import { Paginator } from './paginator.js';
3
+ export declare class Client {
4
+ private readonly sparqlEndpoint;
5
+ private readonly schema;
6
+ constructor(sparqlEndpoint: URL, schema?: {
7
+ readonly '@type': "dcat:Dataset";
8
+ readonly title: {
9
+ readonly '@id': "dcterms:title";
10
+ readonly '@multilang': true;
11
+ };
12
+ readonly description: {
13
+ readonly '@id': "dcterms:description";
14
+ readonly '@optional': true;
15
+ readonly '@multilang': true;
16
+ };
17
+ readonly language: {
18
+ readonly '@id': "dcterms:language";
19
+ readonly '@optional': true;
20
+ readonly '@array': true;
21
+ };
22
+ readonly license: {
23
+ readonly '@id': "dcterms:license";
24
+ readonly '@optional': true;
25
+ };
26
+ readonly creator: {
27
+ readonly '@id': "dcterms:creator";
28
+ readonly '@optional': true;
29
+ readonly '@array': true;
30
+ readonly '@schema': {
31
+ readonly name: {
32
+ readonly '@id': "foaf:name";
33
+ readonly '@multilang': true;
34
+ };
35
+ };
36
+ };
37
+ readonly publisher: {
38
+ readonly '@id': "dcterms:publisher";
39
+ readonly '@optional': true;
40
+ readonly '@schema': {
41
+ readonly name: {
42
+ readonly '@id': "foaf:name";
43
+ readonly '@multilang': true;
44
+ };
45
+ };
46
+ };
47
+ readonly distribution: {
48
+ readonly '@id': "dcat:distribution";
49
+ readonly '@array': true;
50
+ readonly '@schema': {
51
+ readonly '@type': "dcat:Distribution";
52
+ readonly accessURL: "dcat:accessURL";
53
+ readonly mediaType: "dcat:mediaType";
54
+ readonly byteSize: {
55
+ readonly '@id': "dcat:byteSize";
56
+ readonly '@type': "xsd:nonNegativeInteger";
57
+ readonly '@optional': true;
58
+ };
59
+ readonly conformsTo: {
60
+ readonly '@id': "dcterms:conformsTo";
61
+ readonly '@optional': true;
62
+ };
63
+ readonly modified: {
64
+ readonly '@id': "dcterms:modified";
65
+ readonly '@type': "xsd:dateTime";
66
+ readonly '@optional': true;
67
+ };
68
+ };
69
+ };
70
+ });
71
+ query(criteria: object): Promise<Paginator<Dataset>>;
72
+ query(constructQuery: string): Promise<Paginator<Dataset>>;
73
+ }
74
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AAIrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,cAAc,EAAE,GAAG,EACnB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAAgB;IAGlC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpD,KAAK,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;CAoElE"}
package/dist/client.js ADDED
@@ -0,0 +1,67 @@
1
+ import { Dataset, Distribution } from '@lde/dataset';
2
+ import { DatasetSchema } from './schema.js';
3
+ import { createLens } from 'ldkit';
4
+ import { prepareQuery } from './query.js';
5
+ import { Paginator } from './paginator.js';
6
+ export class Client {
7
+ sparqlEndpoint;
8
+ schema;
9
+ constructor(sparqlEndpoint, schema = DatasetSchema) {
10
+ this.sparqlEndpoint = sparqlEndpoint;
11
+ this.schema = schema;
12
+ }
13
+ async query(args = {}) {
14
+ const datasets = createLens(this.schema, {
15
+ sources: [this.sparqlEndpoint.toString()],
16
+ // logQuery: (query) => console.debug(query),
17
+ });
18
+ let results;
19
+ let total;
20
+ let pageSize;
21
+ if (typeof args === 'string') {
22
+ // Custom query has no paginated results.
23
+ results = await datasets.query(prepareQuery(args));
24
+ total = results.length;
25
+ pageSize = total;
26
+ }
27
+ else {
28
+ // With search criteria the results are paginated.
29
+ total = await datasets.count({ ...args });
30
+ pageSize = 1000;
31
+ }
32
+ return new Paginator(async (offset, limit) => {
33
+ let items;
34
+ if (typeof args === 'string') {
35
+ // Custom query has no paginated results.
36
+ // TODO: we could add a convention here like {OFFSET} {LIMIT} in the query string.
37
+ items = await datasets.query(prepareQuery(args));
38
+ }
39
+ else {
40
+ items = await datasets.find({ ...args, take: limit, skip: offset });
41
+ }
42
+ return items.map((dataset) => new Dataset({
43
+ iri: new URL(dataset.$id),
44
+ title: dataset.title,
45
+ description: dataset.description,
46
+ language: dataset.language,
47
+ license: dataset.license ? new URL(dataset.license) : undefined,
48
+ distributions: dataset.distribution.map((d) => {
49
+ const distribution = new Distribution(new URL(d.accessURL), d.mediaType, d.conformsTo ? new URL(d.conformsTo) : undefined);
50
+ distribution.byteSize = d.byteSize ?? undefined;
51
+ distribution.lastModified = d.modified ?? undefined;
52
+ return distribution;
53
+ }),
54
+ creator: dataset.creator.map((creator) => ({
55
+ iri: new URL(creator.$id),
56
+ name: creator.name,
57
+ })),
58
+ publisher: dataset.publisher
59
+ ? {
60
+ iri: new URL(dataset.publisher.$id),
61
+ name: dataset.publisher.name,
62
+ }
63
+ : undefined,
64
+ }));
65
+ }, total, pageSize);
66
+ }
67
+ }
package/dist/dcat.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export declare const dcat: import("ldkit/namespaces").NamespaceInterface<{
2
+ readonly iri: "http://www.w3.org/ns/dcat#";
3
+ readonly prefix: "dcat:";
4
+ readonly terms: readonly ["Dataset", "Distribution", "accessURL", "keyword", "mediaType", "byteSize", "distribution", "modified", "downloadURL"];
5
+ }>;
6
+ //# sourceMappingURL=dcat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dcat.d.ts","sourceRoot":"","sources":["../src/dcat.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI;;;;EAcN,CAAC"}
package/dist/dcat.js ADDED
@@ -0,0 +1,16 @@
1
+ import { createNamespace } from 'ldkit/namespaces';
2
+ export const dcat = createNamespace({
3
+ iri: 'http://www.w3.org/ns/dcat#',
4
+ prefix: 'dcat:',
5
+ terms: [
6
+ 'Dataset',
7
+ 'Distribution',
8
+ 'accessURL',
9
+ 'keyword',
10
+ 'mediaType',
11
+ 'byteSize',
12
+ 'distribution',
13
+ 'modified',
14
+ 'downloadURL',
15
+ ],
16
+ });
@@ -0,0 +1,5 @@
1
+ export * from './client.js';
2
+ export * from './dcat.js';
3
+ export * from './paginator.js';
4
+ export * from './schema.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './client.js';
2
+ export * from './dcat.js';
3
+ export * from './paginator.js';
4
+ export * from './schema.js';
@@ -0,0 +1,8 @@
1
+ export declare class Paginator<T> implements AsyncIterable<T> {
2
+ private readonly fetchPage;
3
+ readonly total: number;
4
+ private readonly pageSize;
5
+ constructor(fetchPage: (offset: number, limit: number) => Promise<T[]>, total: number, pageSize?: number);
6
+ [Symbol.asyncIterator](): AsyncIterator<T>;
7
+ }
8
+ //# sourceMappingURL=paginator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../src/paginator.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAEjD,OAAO,CAAC,QAAQ,CAAC,SAAS;aACV,KAAK,EAAE,MAAM;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,EAC3D,KAAK,EAAE,MAAM,EACZ,QAAQ,SAAO;IAG3B,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;CAgBlD"}
@@ -0,0 +1,23 @@
1
+ export class Paginator {
2
+ fetchPage;
3
+ total;
4
+ pageSize;
5
+ constructor(fetchPage, total, pageSize = 1000) {
6
+ this.fetchPage = fetchPage;
7
+ this.total = total;
8
+ this.pageSize = pageSize;
9
+ }
10
+ async *[Symbol.asyncIterator]() {
11
+ let offset = 0;
12
+ while (true) {
13
+ if (offset >= this.total) {
14
+ break;
15
+ }
16
+ const items = await this.fetchPage(offset, this.pageSize);
17
+ for (const item of items) {
18
+ yield item;
19
+ }
20
+ offset += items.length;
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,2 @@
1
+ export declare function prepareQuery(query: string): string;
2
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAelD"}
package/dist/query.js ADDED
@@ -0,0 +1,18 @@
1
+ import { Generator, Parser } from 'sparqljs';
2
+ import { ldkit, rdf } from 'ldkit/namespaces';
3
+ import { DataFactory } from 'n3';
4
+ const generator = new Generator();
5
+ export function prepareQuery(query) {
6
+ const parsed = new Parser().parse(query);
7
+ if (parsed.type !== 'query' || 'CONSTRUCT' !== parsed.queryType) {
8
+ throw new Error('Must be CONSTRUCT query');
9
+ }
10
+ const template = parsed.template;
11
+ template.push({
12
+ subject: template[0].subject,
13
+ predicate: DataFactory.namedNode(rdf.type),
14
+ object: DataFactory.namedNode(ldkit.Resource),
15
+ });
16
+ parsed.template = template;
17
+ return generator.stringify(parsed);
18
+ }
@@ -0,0 +1,66 @@
1
+ export declare const DatasetSchema: {
2
+ readonly '@type': "dcat:Dataset";
3
+ readonly title: {
4
+ readonly '@id': "dcterms:title";
5
+ readonly '@multilang': true;
6
+ };
7
+ readonly description: {
8
+ readonly '@id': "dcterms:description";
9
+ readonly '@optional': true;
10
+ readonly '@multilang': true;
11
+ };
12
+ readonly language: {
13
+ readonly '@id': "dcterms:language";
14
+ readonly '@optional': true;
15
+ readonly '@array': true;
16
+ };
17
+ readonly license: {
18
+ readonly '@id': "dcterms:license";
19
+ readonly '@optional': true;
20
+ };
21
+ readonly creator: {
22
+ readonly '@id': "dcterms:creator";
23
+ readonly '@optional': true;
24
+ readonly '@array': true;
25
+ readonly '@schema': {
26
+ readonly name: {
27
+ readonly '@id': "foaf:name";
28
+ readonly '@multilang': true;
29
+ };
30
+ };
31
+ };
32
+ readonly publisher: {
33
+ readonly '@id': "dcterms:publisher";
34
+ readonly '@optional': true;
35
+ readonly '@schema': {
36
+ readonly name: {
37
+ readonly '@id': "foaf:name";
38
+ readonly '@multilang': true;
39
+ };
40
+ };
41
+ };
42
+ readonly distribution: {
43
+ readonly '@id': "dcat:distribution";
44
+ readonly '@array': true;
45
+ readonly '@schema': {
46
+ readonly '@type': "dcat:Distribution";
47
+ readonly accessURL: "dcat:accessURL";
48
+ readonly mediaType: "dcat:mediaType";
49
+ readonly byteSize: {
50
+ readonly '@id': "dcat:byteSize";
51
+ readonly '@type': "xsd:nonNegativeInteger";
52
+ readonly '@optional': true;
53
+ };
54
+ readonly conformsTo: {
55
+ readonly '@id': "dcterms:conformsTo";
56
+ readonly '@optional': true;
57
+ };
58
+ readonly modified: {
59
+ readonly '@id': "dcterms:modified";
60
+ readonly '@type': "xsd:dateTime";
61
+ readonly '@optional': true;
62
+ };
63
+ };
64
+ };
65
+ };
66
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEhB,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,67 @@
1
+ import { dcterms, foaf, xsd } from 'ldkit/namespaces';
2
+ import { dcat } from './dcat.js';
3
+ export const DatasetSchema = {
4
+ '@type': dcat.Dataset,
5
+ title: {
6
+ '@id': dcterms.title,
7
+ '@multilang': true,
8
+ },
9
+ description: {
10
+ '@id': dcterms.description,
11
+ '@optional': true, // But required in DCAT-AP 3.0
12
+ '@multilang': true,
13
+ },
14
+ language: {
15
+ '@id': dcterms.language,
16
+ '@optional': true,
17
+ '@array': true,
18
+ },
19
+ license: {
20
+ '@id': dcterms.license,
21
+ '@optional': true,
22
+ },
23
+ creator: {
24
+ '@id': dcterms.creator,
25
+ '@optional': true, // But required in DCAT-AP 3.0
26
+ '@array': true,
27
+ '@schema': {
28
+ name: {
29
+ '@id': foaf.name,
30
+ '@multilang': true,
31
+ },
32
+ },
33
+ },
34
+ publisher: {
35
+ '@id': dcterms.publisher,
36
+ '@optional': true,
37
+ '@schema': {
38
+ name: {
39
+ '@id': foaf.name,
40
+ '@multilang': true,
41
+ },
42
+ },
43
+ },
44
+ distribution: {
45
+ '@id': dcat.distribution,
46
+ '@array': true,
47
+ '@schema': {
48
+ '@type': dcat.Distribution,
49
+ accessURL: dcat.accessURL,
50
+ mediaType: dcat.mediaType,
51
+ byteSize: {
52
+ '@id': dcat.byteSize,
53
+ '@type': xsd.nonNegativeInteger,
54
+ '@optional': true,
55
+ },
56
+ conformsTo: {
57
+ '@id': dcterms.conformsTo,
58
+ '@optional': true,
59
+ },
60
+ modified: {
61
+ '@id': dcterms.modified,
62
+ '@type': xsd.dateTime,
63
+ '@optional': true,
64
+ },
65
+ },
66
+ },
67
+ };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@lde/dataset-registry-client",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
+ "repository": {
5
+ "url": "https://github.com/ldengine/lde"
6
+ },
4
7
  "type": "module",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  "./package.json": "./package.json",
10
10
  ".": {
@@ -14,12 +14,15 @@
14
14
  "default": "./dist/index.js"
15
15
  }
16
16
  },
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
17
20
  "files": [
18
21
  "dist",
19
22
  "!**/*.tsbuildinfo"
20
23
  ],
21
24
  "dependencies": {
22
- "@lde/dataset": "0.3.1",
25
+ "@lde/dataset": "0.4.1",
23
26
  "ldkit": "^2.5.1",
24
27
  "n3": "^1.26.0",
25
28
  "sparqljs": "^3.7.3",