@lde/dataset 0.2.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Dataset
2
+
3
+ Classes for working with DCAT Datasets and Distributions.
@@ -0,0 +1,9 @@
1
+ import { Distribution } from './distribution.js';
2
+ export declare class Dataset {
3
+ readonly iri: URL;
4
+ distributions: Distribution[];
5
+ constructor(iri: URL, distributions: Distribution[]);
6
+ getSparqlDistribution(): Distribution | null;
7
+ getDownloadDistributions(): Distribution[];
8
+ }
9
+ //# sourceMappingURL=dataset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../src/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,qBAAa,OAAO;aACU,GAAG,EAAE,GAAG;IAAS,aAAa,EAAE,YAAY,EAAE;gBAA9C,GAAG,EAAE,GAAG,EAAS,aAAa,EAAE,YAAY,EAAE;IAEnE,qBAAqB,IAAI,YAAY,GAAG,IAAI;IAQ5C,wBAAwB,IAAI,YAAY,EAAE;CAqBlD"}
@@ -0,0 +1,20 @@
1
+ export class Dataset {
2
+ iri;
3
+ distributions;
4
+ constructor(iri, distributions) {
5
+ this.iri = iri;
6
+ this.distributions = distributions;
7
+ }
8
+ getSparqlDistribution() {
9
+ return (this.distributions.filter((distribution) => distribution.isSparql() && distribution.isValid)[0] ?? null);
10
+ }
11
+ getDownloadDistributions() {
12
+ const validDistributions = this.distributions.filter((distribution) => distribution.isValid);
13
+ return [
14
+ ...validDistributions.filter((distribution) => distribution.mimeType?.endsWith('+gzip')),
15
+ ...validDistributions.filter((distribution) => distribution.accessUrl?.toString().endsWith('.nt.gz')),
16
+ ...validDistributions.filter((distribution) => undefined !== distribution.mimeType &&
17
+ ['application/n-triples', 'text/turtle'].includes(distribution.mimeType)),
18
+ ];
19
+ }
20
+ }
@@ -0,0 +1,19 @@
1
+ export declare class Distribution {
2
+ readonly accessUrl: URL;
3
+ readonly mimeType: string;
4
+ byteSize?: number;
5
+ lastModified?: Date;
6
+ isValid?: boolean;
7
+ namedGraph?: string;
8
+ subjectFilter?: string;
9
+ constructor(accessUrl: URL, mimeType: string);
10
+ isSparql(): boolean;
11
+ static sparql(endpoint: URL, namedGraph?: string): Distribution;
12
+ }
13
+ export declare enum RdfFormat {
14
+ 'N-Triples' = "application/n-triples",
15
+ 'N-Quads' = "application/n-quads",
16
+ Turtle = "text/turtle"
17
+ }
18
+ export declare function rdfFormatToFileExtension(rdfFormat: RdfFormat): string;
19
+ //# sourceMappingURL=distribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribution.d.ts","sourceRoot":"","sources":["../src/distribution.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;aAQL,SAAS,EAAE,GAAG;aACd,QAAQ,EAAE,MAAM;IAR3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;gBAGZ,SAAS,EAAE,GAAG,EACd,QAAQ,EAAE,MAAM;IAG3B,QAAQ;WAQD,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,EAAE,MAAM;CAOxD;AAED,oBAAY,SAAS;IACnB,WAAW,0BAA0B;IACrC,SAAS,wBAAwB;IACjC,MAAM,gBAAgB;CACvB;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAWrE"}
@@ -0,0 +1,42 @@
1
+ export class Distribution {
2
+ accessUrl;
3
+ mimeType;
4
+ byteSize;
5
+ lastModified;
6
+ isValid;
7
+ namedGraph;
8
+ subjectFilter;
9
+ constructor(accessUrl, mimeType) {
10
+ this.accessUrl = accessUrl;
11
+ this.mimeType = mimeType;
12
+ }
13
+ isSparql() {
14
+ return ((this.mimeType === 'application/sparql-query' ||
15
+ this.mimeType === 'application/sparql-results+json') &&
16
+ this.accessUrl !== null);
17
+ }
18
+ static sparql(endpoint, namedGraph) {
19
+ const distribution = new this(endpoint, 'application/sparql-query');
20
+ distribution.isValid = true;
21
+ distribution.namedGraph = namedGraph;
22
+ return distribution;
23
+ }
24
+ }
25
+ export var RdfFormat;
26
+ (function (RdfFormat) {
27
+ RdfFormat["N-Triples"] = "application/n-triples";
28
+ RdfFormat["N-Quads"] = "application/n-quads";
29
+ RdfFormat["Turtle"] = "text/turtle";
30
+ })(RdfFormat || (RdfFormat = {}));
31
+ export function rdfFormatToFileExtension(rdfFormat) {
32
+ switch (rdfFormat) {
33
+ case RdfFormat['N-Triples']:
34
+ return 'nt';
35
+ case RdfFormat['N-Quads']:
36
+ return 'nq';
37
+ case RdfFormat.Turtle:
38
+ return 'ttl';
39
+ default:
40
+ throw new Error(`Unknown mime type: ${rdfFormat}`);
41
+ }
42
+ }
@@ -0,0 +1,4 @@
1
+ export * from './dataset.js';
2
+ export * from './distribution.js';
3
+ export * from './mediaType.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './dataset.js';
2
+ export * from './distribution.js';
3
+ export * from './mediaType.js';
@@ -0,0 +1,3 @@
1
+ export declare const sparqlMediaTypes: string[];
2
+ export declare const rdfMediaTypes: string[];
3
+ //# sourceMappingURL=mediaType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediaType.d.ts","sourceRoot":"","sources":["../src/mediaType.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAI5B,CAAC;AAEF,eAAO,MAAM,aAAa,UASzB,CAAC"}
@@ -0,0 +1,15 @@
1
+ export const sparqlMediaTypes = [
2
+ 'application/sparql-query',
3
+ 'application/sparql-results+json',
4
+ 'application/sparql-results+xml',
5
+ ];
6
+ export const rdfMediaTypes = [
7
+ 'application/ld+json',
8
+ 'application/ld+json+gzip',
9
+ 'application/n-quads',
10
+ 'application/n-quads+gzip',
11
+ 'application/n-triples',
12
+ 'application/n-triples+gzip',
13
+ 'text/turtle',
14
+ 'text/turtle+gzip',
15
+ ];
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@lde/dataset",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "development": "./src/index.ts",
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "!**/*.tsbuildinfo"
20
+ ],
21
+ "dependencies": {
22
+ "tslib": "^2.3.0"
23
+ }
24
+ }