@lde/pipeline 0.6.25 → 0.6.26
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/executor.d.ts +10 -13
- package/dist/sparql/executor.d.ts.map +1 -1
- package/dist/sparql/executor.js +29 -28
- package/dist/sparql/index.d.ts +1 -1
- package/dist/sparql/index.d.ts.map +1 -1
- package/dist/sparql/index.js +1 -1
- package/dist/stage.d.ts +4 -2
- package/dist/stage.d.ts.map +1 -1
- package/dist/stage.js +9 -6
- package/package.json +1 -1
|
@@ -45,12 +45,16 @@ export interface SparqlConstructExecutorOptions {
|
|
|
45
45
|
fetcher?: SparqlEndpointFetcher;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* A streaming SPARQL CONSTRUCT executor
|
|
49
|
-
*
|
|
48
|
+
* A streaming SPARQL CONSTRUCT executor.
|
|
49
|
+
*
|
|
50
|
+
* Queries **without** `#subjectFilter#` are parsed once in the constructor
|
|
51
|
+
* (fast path). Queries that contain the template are stored as raw strings
|
|
52
|
+
* and parsed at {@link execute} time after substitution.
|
|
50
53
|
*
|
|
51
54
|
* Template substitution (applied in order):
|
|
52
|
-
* 1.
|
|
53
|
-
* 2.
|
|
55
|
+
* 1. `#subjectFilter#` — replaced with `distribution.subjectFilter` (deferred to execute)
|
|
56
|
+
* 2. `FROM <graph>` — set via `withDefaultGraph` if the distribution has a named graph
|
|
57
|
+
* 3. `?dataset` — replaced with the dataset IRI (string substitution on the serialised query)
|
|
54
58
|
*
|
|
55
59
|
* @example
|
|
56
60
|
* ```typescript
|
|
@@ -68,7 +72,8 @@ export interface SparqlConstructExecutorOptions {
|
|
|
68
72
|
* ```
|
|
69
73
|
*/
|
|
70
74
|
export declare class SparqlConstructExecutor implements Executor {
|
|
71
|
-
private readonly
|
|
75
|
+
private readonly rawQuery;
|
|
76
|
+
private readonly preParsed?;
|
|
72
77
|
private readonly fetcher;
|
|
73
78
|
private readonly generator;
|
|
74
79
|
constructor(options: SparqlConstructExecutorOptions);
|
|
@@ -89,14 +94,6 @@ export declare class SparqlConstructExecutor implements Executor {
|
|
|
89
94
|
*/
|
|
90
95
|
static fromFile(filename: string, options?: Omit<SparqlConstructExecutorOptions, 'query'>): Promise<SparqlConstructExecutor>;
|
|
91
96
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Substitute template variables in a SPARQL query.
|
|
94
|
-
*
|
|
95
|
-
* - `#subjectFilter#` — replaced with the distribution's subject filter
|
|
96
|
-
* - `#namedGraph#` — replaced with `FROM <graph>` clause if the distribution has a named graph
|
|
97
|
-
* - `?dataset` — replaced with the dataset IRI
|
|
98
|
-
*/
|
|
99
|
-
export declare function substituteQueryTemplates(query: string, distribution: Distribution | null, dataset: Dataset): string;
|
|
100
97
|
/**
|
|
101
98
|
* Read a SPARQL query from a file.
|
|
102
99
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/sparql/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAO5C;;GAEG;AACH,qBAAa,YAAY;aACK,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;CAC5C;AAED,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,CACL,OAAO,EAAE,OAAO,EAChB,YAAY,EA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,MAAM,CAAC,IAAI,CAAC,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,qBAAqB,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,uBAAwB,YAAW,QAAQ;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;gBAEjC,OAAO,EAAE,8BAA8B;IAkBnD;;;;;;;OAOG;IACG,OAAO,CACX,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,UAAU,CAAC;IAiCtB;;;;;OAKG;WACiB,QAAQ,CAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,IAAI,CAAC,8BAA8B,EAAE,OAAO,CAAC,GACtD,OAAO,CAAC,uBAAuB,CAAC;CAIpC;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAErE"}
|
package/dist/sparql/executor.js
CHANGED
|
@@ -14,12 +14,16 @@ export class NotSupported {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* A streaming SPARQL CONSTRUCT executor
|
|
18
|
-
*
|
|
17
|
+
* A streaming SPARQL CONSTRUCT executor.
|
|
18
|
+
*
|
|
19
|
+
* Queries **without** `#subjectFilter#` are parsed once in the constructor
|
|
20
|
+
* (fast path). Queries that contain the template are stored as raw strings
|
|
21
|
+
* and parsed at {@link execute} time after substitution.
|
|
19
22
|
*
|
|
20
23
|
* Template substitution (applied in order):
|
|
21
|
-
* 1.
|
|
22
|
-
* 2.
|
|
24
|
+
* 1. `#subjectFilter#` — replaced with `distribution.subjectFilter` (deferred to execute)
|
|
25
|
+
* 2. `FROM <graph>` — set via `withDefaultGraph` if the distribution has a named graph
|
|
26
|
+
* 3. `?dataset` — replaced with the dataset IRI (string substitution on the serialised query)
|
|
23
27
|
*
|
|
24
28
|
* @example
|
|
25
29
|
* ```typescript
|
|
@@ -37,16 +41,19 @@ export class NotSupported {
|
|
|
37
41
|
* ```
|
|
38
42
|
*/
|
|
39
43
|
export class SparqlConstructExecutor {
|
|
40
|
-
|
|
44
|
+
rawQuery;
|
|
45
|
+
preParsed;
|
|
41
46
|
fetcher;
|
|
42
47
|
generator = new Generator();
|
|
43
48
|
constructor(options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
this.rawQuery = options.query;
|
|
50
|
+
if (!options.query.includes('#subjectFilter#')) {
|
|
51
|
+
const parsed = new Parser().parse(options.query);
|
|
52
|
+
if (parsed.type !== 'query' || parsed.queryType !== 'CONSTRUCT') {
|
|
53
|
+
throw new Error('Query must be a CONSTRUCT query');
|
|
54
|
+
}
|
|
55
|
+
this.preParsed = parsed;
|
|
48
56
|
}
|
|
49
|
-
this.query = parsed;
|
|
50
57
|
this.fetcher =
|
|
51
58
|
options.fetcher ??
|
|
52
59
|
new SparqlEndpointFetcher({
|
|
@@ -63,7 +70,18 @@ export class SparqlConstructExecutor {
|
|
|
63
70
|
*/
|
|
64
71
|
async execute(dataset, distribution, options) {
|
|
65
72
|
const endpoint = distribution.accessUrl;
|
|
66
|
-
let ast
|
|
73
|
+
let ast;
|
|
74
|
+
if (this.preParsed) {
|
|
75
|
+
ast = structuredClone(this.preParsed);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const substituted = this.rawQuery.replace('#subjectFilter#', distribution.subjectFilter ?? '');
|
|
79
|
+
const parsed = new Parser().parse(substituted);
|
|
80
|
+
if (parsed.type !== 'query' || parsed.queryType !== 'CONSTRUCT') {
|
|
81
|
+
throw new Error('Query must be a CONSTRUCT query');
|
|
82
|
+
}
|
|
83
|
+
ast = parsed;
|
|
84
|
+
}
|
|
67
85
|
if (distribution.namedGraph) {
|
|
68
86
|
withDefaultGraph(ast, distribution.namedGraph);
|
|
69
87
|
}
|
|
@@ -86,23 +104,6 @@ export class SparqlConstructExecutor {
|
|
|
86
104
|
return new SparqlConstructExecutor({ ...options, query });
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Substitute template variables in a SPARQL query.
|
|
91
|
-
*
|
|
92
|
-
* - `#subjectFilter#` — replaced with the distribution's subject filter
|
|
93
|
-
* - `#namedGraph#` — replaced with `FROM <graph>` clause if the distribution has a named graph
|
|
94
|
-
* - `?dataset` — replaced with the dataset IRI
|
|
95
|
-
*/
|
|
96
|
-
export function substituteQueryTemplates(query, distribution, dataset) {
|
|
97
|
-
const subjectFilter = distribution?.subjectFilter ?? '';
|
|
98
|
-
const namedGraph = distribution?.namedGraph
|
|
99
|
-
? `FROM <${distribution.namedGraph}>`
|
|
100
|
-
: '';
|
|
101
|
-
return query
|
|
102
|
-
.replace('#subjectFilter#', subjectFilter)
|
|
103
|
-
.replaceAll('?dataset', `<${dataset.iri}>`)
|
|
104
|
-
.replace('#namedGraph#', namedGraph);
|
|
105
|
-
}
|
|
106
107
|
/**
|
|
107
108
|
* Read a SPARQL query from a file.
|
|
108
109
|
*/
|
package/dist/sparql/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { SparqlConstructExecutor,
|
|
1
|
+
export { SparqlConstructExecutor, NotSupported, readQueryFile, type ExecuteOptions, type Executor, type SparqlConstructExecutorOptions, type QuadStream, type VariableBindings, } from './executor.js';
|
|
2
2
|
export { SparqlSelector, type SparqlSelectorOptions } from './selector.js';
|
|
3
3
|
export { injectValues } from './values.js';
|
|
4
4
|
export { withDefaultGraph } from './graph.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sparql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sparql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,8BAA8B,EACnC,KAAK,UAAU,EACf,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/sparql/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { SparqlConstructExecutor,
|
|
1
|
+
export { SparqlConstructExecutor, NotSupported, readQueryFile, } from './executor.js';
|
|
2
2
|
export { SparqlSelector } from './selector.js';
|
|
3
3
|
export { injectValues } from './values.js';
|
|
4
4
|
export { withDefaultGraph } from './graph.js';
|
package/dist/stage.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import { Dataset, Distribution } from '@lde/dataset';
|
|
|
2
2
|
import type { Executor, VariableBindings } from './sparql/executor.js';
|
|
3
3
|
import { NotSupported } from './sparql/executor.js';
|
|
4
4
|
import type { Writer } from './writer/writer.js';
|
|
5
|
+
/** A selector, or a factory that receives the runtime distribution. */
|
|
6
|
+
export type StageSelectorInput = StageSelector | ((distribution: Distribution) => StageSelector);
|
|
5
7
|
export interface StageOptions {
|
|
6
8
|
name: string;
|
|
7
9
|
executors: Executor | Executor[];
|
|
8
|
-
selector?:
|
|
10
|
+
selector?: StageSelectorInput;
|
|
9
11
|
/** Maximum number of bindings per executor call. @default 10 */
|
|
10
12
|
batchSize?: number;
|
|
11
13
|
/** Maximum concurrent in-flight executor batches. @default 10 */
|
|
@@ -20,7 +22,7 @@ export declare class Stage {
|
|
|
20
22
|
readonly name: string;
|
|
21
23
|
readonly stages: readonly Stage[];
|
|
22
24
|
private readonly executors;
|
|
23
|
-
private readonly
|
|
25
|
+
private readonly selectorInput?;
|
|
24
26
|
private readonly batchSize;
|
|
25
27
|
private readonly maxConcurrency;
|
|
26
28
|
constructor(options: StageOptions);
|
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,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"stage.d.ts","sourceRoot":"","sources":["../src/stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjD,uEAAuE;AACvE,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,CAAC,CAAC,YAAY,EAAE,YAAY,KA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|
|
11
11
|
constructor(options) {
|
|
@@ -14,13 +14,16 @@ export class Stage {
|
|
|
14
14
|
this.executors = Array.isArray(options.executors)
|
|
15
15
|
? options.executors
|
|
16
16
|
: [options.executors];
|
|
17
|
-
this.
|
|
17
|
+
this.selectorInput = options.selector;
|
|
18
18
|
this.batchSize = options.batchSize ?? 10;
|
|
19
19
|
this.maxConcurrency = options.maxConcurrency ?? 10;
|
|
20
20
|
}
|
|
21
21
|
async run(dataset, distribution, writer, options) {
|
|
22
|
-
if (this.
|
|
23
|
-
|
|
22
|
+
if (this.selectorInput) {
|
|
23
|
+
const selector = typeof this.selectorInput === 'function'
|
|
24
|
+
? this.selectorInput(distribution)
|
|
25
|
+
: this.selectorInput;
|
|
26
|
+
return this.runWithSelector(selector, dataset, distribution, writer, options);
|
|
24
27
|
}
|
|
25
28
|
const streams = await this.executeAll(dataset, distribution);
|
|
26
29
|
if (streams instanceof NotSupported) {
|
|
@@ -28,10 +31,10 @@ export class Stage {
|
|
|
28
31
|
}
|
|
29
32
|
await writer.write(dataset, mergeStreams(streams));
|
|
30
33
|
}
|
|
31
|
-
async runWithSelector(dataset, distribution, writer, options) {
|
|
34
|
+
async runWithSelector(selector, dataset, distribution, writer, options) {
|
|
32
35
|
// Peek the first batch to detect an empty selector before starting the
|
|
33
36
|
// writer (important because e.g. SparqlUpdateWriter does CLEAR GRAPH).
|
|
34
|
-
const batches = batch(
|
|
37
|
+
const batches = batch(selector, this.batchSize);
|
|
35
38
|
const iter = batches[Symbol.asyncIterator]();
|
|
36
39
|
const first = await iter.next();
|
|
37
40
|
if (first.done) {
|