@lde/pipeline 0.6.11 → 0.6.12
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/dist/sparql/index.d.ts +1 -0
- package/dist/sparql/index.d.ts.map +1 -1
- package/dist/sparql/index.js +1 -0
- package/dist/sparql/selector.d.ts +30 -0
- package/dist/sparql/selector.d.ts.map +1 -0
- package/dist/sparql/selector.js +57 -0
- package/dist/stage.d.ts +6 -1
- package/dist/stage.d.ts.map +1 -1
- package/package.json +9 -5
package/dist/sparql/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { SparqlConstructExecutor, substituteQueryTemplates, NotSupported, readQueryFile, type ExecutableDataset, type Executor, type SparqlConstructExecuteOptions, type SparqlConstructExecutorOptions, type QuadStream, } from './executor.js';
|
|
2
2
|
export { collect } from './collect.js';
|
|
3
|
+
export { SparqlSelector, type SparqlSelectorOptions } from './selector.js';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sparql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sparql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/sparql/index.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SparqlEndpointFetcher } from 'fetch-sparql-endpoint';
|
|
2
|
+
import type { StageSelectorBindings, StageSelector } from '../stage.js';
|
|
3
|
+
export interface SparqlSelectorOptions {
|
|
4
|
+
/** SELECT query projecting at least one named variable. A LIMIT in the query sets the default page size. */
|
|
5
|
+
query: string;
|
|
6
|
+
/** SPARQL endpoint URL. */
|
|
7
|
+
endpoint: URL;
|
|
8
|
+
/** Results per page. Overrides any LIMIT in the query. @default 10 */
|
|
9
|
+
pageSize?: number;
|
|
10
|
+
/** Custom fetcher instance. */
|
|
11
|
+
fetcher?: SparqlEndpointFetcher;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* {@link StageSelector} that pages through SPARQL SELECT results,
|
|
15
|
+
* yielding all projected variable bindings (NamedNode values only) per row.
|
|
16
|
+
*
|
|
17
|
+
* Pagination is an internal detail — consumers iterate binding rows directly.
|
|
18
|
+
* If the query contains a LIMIT, it is used as the default page size
|
|
19
|
+
* (can be overridden by the `pageSize` option). Pagination continues
|
|
20
|
+
* until a page returns fewer results than the page size.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SparqlSelector implements StageSelector {
|
|
23
|
+
private readonly parsed;
|
|
24
|
+
private readonly endpoint;
|
|
25
|
+
private readonly pageSize;
|
|
26
|
+
private readonly fetcher;
|
|
27
|
+
constructor(options: SparqlSelectorOptions);
|
|
28
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<StageSelectorBindings>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../src/sparql/selector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAQ9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKxE,MAAM,WAAW,qBAAqB;IACpC,4GAA4G;IAC5G,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,QAAQ,EAAE,GAAG,CAAC;IACd,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,qBAAqB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,aAAa;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;gBAEpC,OAAO,EAAE,qBAAqB;IAmBnC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,qBAAqB,CAAC;CAkC9E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SparqlEndpointFetcher } from 'fetch-sparql-endpoint';
|
|
2
|
+
import { Generator, Parser, } from 'sparqljs';
|
|
3
|
+
const parser = new Parser();
|
|
4
|
+
const generator = new Generator();
|
|
5
|
+
/**
|
|
6
|
+
* {@link StageSelector} that pages through SPARQL SELECT results,
|
|
7
|
+
* yielding all projected variable bindings (NamedNode values only) per row.
|
|
8
|
+
*
|
|
9
|
+
* Pagination is an internal detail — consumers iterate binding rows directly.
|
|
10
|
+
* If the query contains a LIMIT, it is used as the default page size
|
|
11
|
+
* (can be overridden by the `pageSize` option). Pagination continues
|
|
12
|
+
* until a page returns fewer results than the page size.
|
|
13
|
+
*/
|
|
14
|
+
export class SparqlSelector {
|
|
15
|
+
parsed;
|
|
16
|
+
endpoint;
|
|
17
|
+
pageSize;
|
|
18
|
+
fetcher;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const parsed = parser.parse(options.query);
|
|
21
|
+
if (parsed.type !== 'query' || parsed.queryType !== 'SELECT') {
|
|
22
|
+
throw new Error('Query must be a SELECT query');
|
|
23
|
+
}
|
|
24
|
+
const variables = parsed.variables.filter(isVariableTerm);
|
|
25
|
+
if (variables.length === 0) {
|
|
26
|
+
throw new Error('Query must project at least one named variable (SELECT * is not supported)');
|
|
27
|
+
}
|
|
28
|
+
this.parsed = parsed;
|
|
29
|
+
this.endpoint = options.endpoint;
|
|
30
|
+
this.pageSize = options.pageSize ?? parsed.limit ?? 10;
|
|
31
|
+
this.fetcher = options.fetcher ?? new SparqlEndpointFetcher();
|
|
32
|
+
}
|
|
33
|
+
async *[Symbol.asyncIterator]() {
|
|
34
|
+
let offset = 0;
|
|
35
|
+
while (true) {
|
|
36
|
+
this.parsed.limit = this.pageSize;
|
|
37
|
+
this.parsed.offset = offset;
|
|
38
|
+
const paginatedQuery = generator.stringify(this.parsed);
|
|
39
|
+
const stream = (await this.fetcher.fetchBindings(this.endpoint.toString(), paginatedQuery));
|
|
40
|
+
let pageSize = 0;
|
|
41
|
+
for await (const record of stream) {
|
|
42
|
+
const row = Object.fromEntries(Object.entries(record).filter(([, term]) => term.termType === 'NamedNode'));
|
|
43
|
+
if (Object.keys(row).length > 0) {
|
|
44
|
+
yield row;
|
|
45
|
+
pageSize++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (pageSize === 0 || pageSize < this.pageSize) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
offset += pageSize;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function isVariableTerm(v) {
|
|
56
|
+
return 'termType' in v && v.termType === 'Variable';
|
|
57
|
+
}
|
package/dist/stage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Quad } from '@rdfjs/types';
|
|
1
|
+
import type { NamedNode, Quad } from '@rdfjs/types';
|
|
2
2
|
import type { ExecutableDataset, Executor } from './sparql/executor.js';
|
|
3
3
|
import { NotSupported } from './sparql/executor.js';
|
|
4
4
|
export interface StageOptions {
|
|
@@ -11,4 +11,9 @@ export declare class Stage {
|
|
|
11
11
|
constructor(options: StageOptions);
|
|
12
12
|
run(dataset: ExecutableDataset): Promise<AsyncIterable<Quad> | NotSupported>;
|
|
13
13
|
}
|
|
14
|
+
/** A single row of variable bindings from a selector query. */
|
|
15
|
+
export type StageSelectorBindings = Record<string, NamedNode>;
|
|
16
|
+
/** Stage-level selector that yields variable bindings for use in executor queries. Pagination is an implementation detail. */
|
|
17
|
+
export interface StageSelector extends AsyncIterable<StageSelectorBindings> {
|
|
18
|
+
}
|
|
14
19
|
//# sourceMappingURL=stage.d.ts.map
|
package/dist/stage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage.d.ts","sourceRoot":"","sources":["../src/stage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"stage.d.ts","sourceRoot":"","sources":["../src/stage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;CAClC;AAED,qBAAa,KAAK;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;gBAE3B,OAAO,EAAE,YAAY;IAO3B,GAAG,CACP,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;CAgB/C;AAUD,+DAA+D;AAC/D,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE9D,8HAA8H;AAE9H,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,qBAAqB,CAAC;CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lde/pipeline",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://github.com/ldengine/lde",
|
|
6
6
|
"directory": "packages/pipeline"
|
|
@@ -35,15 +35,19 @@
|
|
|
35
35
|
"!**/*.tsbuildinfo"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@lde/dataset": "0.6.
|
|
39
|
-
"@lde/dataset-registry-client": "0.6.
|
|
40
|
-
"@lde/sparql-importer": "0.2.
|
|
41
|
-
"@lde/sparql-server": "0.4.
|
|
38
|
+
"@lde/dataset": "0.6.6",
|
|
39
|
+
"@lde/dataset-registry-client": "0.6.12",
|
|
40
|
+
"@lde/sparql-importer": "0.2.6",
|
|
41
|
+
"@lde/sparql-server": "0.4.6",
|
|
42
42
|
"@rdfjs/types": "^2.0.1",
|
|
43
43
|
"c12": "^3.0.2",
|
|
44
44
|
"fetch-sparql-endpoint": "^6.0.0",
|
|
45
45
|
"filenamify-url": "^3.0.0",
|
|
46
46
|
"n3": "^1.17.0",
|
|
47
|
+
"sparqljs": "^3.7.3",
|
|
47
48
|
"tslib": "^2.3.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/sparqljs": "^3.1.12"
|
|
48
52
|
}
|
|
49
53
|
}
|