@lde/sparql-qlever 0.13.0 → 0.14.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.
@@ -1 +1 @@
1
- {"version":3,"file":"importer.d.ts","sourceRoot":"","sources":["../src/importer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,iBAAiB,EAC7B,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,yBAAyB;IACzB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,yJAAyJ;IACzJ,+BAA+B,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,sBAAsB;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAWD,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;gBAE9B,OAAO,EAAE,qBAAqB;IAa7B,MAAM,CACjB,aAAa,EAAE,YAAY,EAAE,GAC5B,OAAO,CAAC,YAAY,GAAG,gBAAgB,GAAG,YAAY,CAAC;YA+B5C,QAAQ;IA4CtB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,aAAa;IAIrB;;OAEG;YACW,eAAe;IA0B7B,yDAAyD;YAC3C,eAAe;YAaf,cAAc;YAKd,KAAK;CA0CpB"}
1
+ {"version":3,"file":"importer.d.ts","sourceRoot":"","sources":["../src/importer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,iBAAiB,EAC7B,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,yBAAyB;IACzB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,yJAAyJ;IACzJ,+BAA+B,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,sBAAsB;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAWD,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;gBAE9B,OAAO,EAAE,qBAAqB;IAa7B,MAAM,CACjB,aAAa,EAAE,YAAY,EAAE,GAC5B,OAAO,CAAC,YAAY,GAAG,gBAAgB,GAAG,YAAY,CAAC;YA+B5C,QAAQ;IAkDtB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,aAAa;IAIrB;;OAEG;YACW,eAAe;IA0B7B,yDAAyD;YAC3C,eAAe;YAaf,cAAc;YAKd,KAAK;CA0CpB"}
package/dist/importer.js CHANGED
@@ -44,7 +44,7 @@ export class Importer {
44
44
  return result;
45
45
  }
46
46
  async doImport(distribution) {
47
- const localFile = await this.options.downloader.download(distribution);
47
+ const { path: localFile, headers } = await this.options.downloader.download(distribution);
48
48
  if (await this.isIndexUpToDate(localFile)) {
49
49
  const tripleCount = await this.readTripleCount(localFile);
50
50
  if (tripleCount === 0) {
@@ -52,7 +52,7 @@ export class Importer {
52
52
  }
53
53
  return new ImportSuccessful(distribution, undefined, tripleCount);
54
54
  }
55
- const format = fileFormatFromMimeType(distribution.mimeType);
55
+ const { format, warning } = fileFormatFor(distribution.mimeType, basename(localFile), headers.get('Content-Type') ?? undefined);
56
56
  let logs;
57
57
  try {
58
58
  logs = await this.index(localFile, format);
@@ -71,7 +71,8 @@ export class Importer {
71
71
  return new ImportFailed(distribution, 'Indexed 0 triples from distribution');
72
72
  }
73
73
  await this.writeCacheInfo(localFile);
74
- return new ImportSuccessful(distribution, undefined, tripleCount);
74
+ const warnings = warning ? [warning] : [];
75
+ return new ImportSuccessful(distribution, undefined, tripleCount, warnings);
75
76
  }
76
77
  parseTripleCount(logs) {
77
78
  // Extract num-triples.normal from the metadata JSON that the index
@@ -163,10 +164,54 @@ const defaultQleverIndexOptions = {
163
164
  'parse-parallel': true,
164
165
  'only-pso-and-pos-permutations': false,
165
166
  };
166
- function fileFormatFromMimeType(mimeType) {
167
- const format = supportedFormats.get(mimeType);
168
- if (format === undefined) {
169
- throw new Error(`Unsupported media type: ${mimeType}`);
167
+ const extensionFormats = new Map([
168
+ ['.nt', 'nt'],
169
+ ['.nq', 'nq'],
170
+ ['.ttl', 'ttl'],
171
+ ]);
172
+ const compressionTypes = new Set([
173
+ 'application/gzip',
174
+ 'application/x-gzip',
175
+ 'application/octet-stream',
176
+ ]);
177
+ /**
178
+ * Determine the QLever format flag for a distribution.
179
+ *
180
+ * Priority:
181
+ * 1. Server Content-Type (if it maps to a supported RDF format)
182
+ * 2. File extension (fallback when Content-Type is a compression type or missing)
183
+ * 3. Declared MIME type from the dataset registry (last resort)
184
+ */
185
+ function fileFormatFor(declaredMimeType, filename, serverContentType) {
186
+ const declaredFormat = supportedFormats.get(declaredMimeType);
187
+ if (declaredFormat === undefined) {
188
+ throw new Error(`Unsupported media type: ${declaredMimeType}`);
189
+ }
190
+ // Try server Content-Type first (strip parameters like "; charset=utf-8").
191
+ if (serverContentType) {
192
+ const actualType = serverContentType.split(';')[0].trim();
193
+ if (!compressionTypes.has(actualType)) {
194
+ const serverFormat = supportedFormats.get(actualType);
195
+ if (serverFormat !== undefined && serverFormat !== declaredFormat) {
196
+ return {
197
+ format: serverFormat,
198
+ warning: `Server Content-Type ${actualType} does not match declared media type ${declaredMimeType}; using ${serverFormat} format`,
199
+ };
200
+ }
201
+ if (serverFormat !== undefined) {
202
+ return { format: serverFormat };
203
+ }
204
+ }
205
+ }
206
+ // Fall back to file extension.
207
+ const stripped = filename.replace(/\.(gz|bz2|xz|zst)$/i, '');
208
+ const extension = stripped.slice(stripped.lastIndexOf('.'));
209
+ const extensionFormat = extensionFormats.get(extension);
210
+ if (extensionFormat !== undefined && extensionFormat !== declaredFormat) {
211
+ return {
212
+ format: extensionFormat,
213
+ warning: `Declared media type ${declaredMimeType} does not match file extension ${extension}; using ${extensionFormat} format`,
214
+ };
170
215
  }
171
- return format;
216
+ return { format: declaredFormat };
172
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/sparql-qlever",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/ldelements/lde.git",
6
6
  "directory": "packages/sparql-qlever"
@@ -25,8 +25,8 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@lde/dataset": "0.7.2",
28
- "@lde/distribution-downloader": "0.5.3",
29
- "@lde/sparql-importer": "0.5.0",
28
+ "@lde/distribution-downloader": "0.6.0",
29
+ "@lde/sparql-importer": "0.6.0",
30
30
  "@lde/sparql-server": "0.4.10",
31
31
  "@lde/task-runner": "0.2.10",
32
32
  "@lde/task-runner-docker": "0.2.11",