@comunica/bus-query-operation 3.3.0 → 4.0.1

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/lib/Bindings.js DELETED
@@ -1,283 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.materializeOperation = exports.materializeTerm = void 0;
4
- const rdf_data_factory_1 = require("rdf-data-factory");
5
- const rdf_string_1 = require("rdf-string");
6
- const rdf_terms_1 = require("rdf-terms");
7
- const sparqlalgebrajs_1 = require("sparqlalgebrajs");
8
- const DF = new rdf_data_factory_1.DataFactory();
9
- const TRUE = DF.literal('true', DF.namedNode('http://www.w3.org/2001/XMLSchema#boolean'));
10
- /**
11
- * Materialize a term with the given binding.
12
- *
13
- * If the given term is a variable,
14
- * and that variable exist in the given bindings object,
15
- * the value of that binding is returned.
16
- * In all other cases, the term itself is returned.
17
- *
18
- * @param {RDF.Term} term A term.
19
- * @param {Bindings} bindings A bindings object.
20
- * @return {RDF.Term} The materialized term.
21
- */
22
- function materializeTerm(term, bindings) {
23
- if (term.termType === 'Variable') {
24
- const value = bindings.get(term);
25
- if (value) {
26
- return value;
27
- }
28
- }
29
- if (term.termType === 'Quad' && (0, rdf_terms_1.someTermsNested)(term, value => value.termType === 'Variable')) {
30
- return (0, rdf_terms_1.mapTermsNested)(term, subTerm => materializeTerm(subTerm, bindings));
31
- }
32
- return term;
33
- }
34
- exports.materializeTerm = materializeTerm;
35
- /**
36
- * Materialize the given operation (recursively) with the given bindings.
37
- * Essentially, the variables in the given operation
38
- * which don't appear in the projection operation will be replaced
39
- * by the terms bound to the variables in the given bindings.
40
- * @param {Algebra.Operation} operation SPARQL algebra operation.
41
- * And the variables that appear in the projection operation
42
- * will be added to a new values operation.
43
- * @param {Bindings} bindings A bindings object.
44
- * @param bindingsFactory The bindings factory.
45
- * @param options Options for materializations.
46
- * @param options.strictTargetVariables If target variable bindings (such as on SELECT or BIND) should not be allowed.
47
- * @param options.bindFilter If filter expressions should be materialized.
48
- * @param options.originalBindings The bindings object as it was at the top level call of materializeOperation.
49
- * @return Algebra.Operation A new operation materialized with the given bindings.
50
- */
51
- function materializeOperation(operation, bindings, bindingsFactory, options = {}) {
52
- options = {
53
- strictTargetVariables: 'strictTargetVariables' in options ? options.strictTargetVariables : false,
54
- bindFilter: 'bindFilter' in options ? options.bindFilter : true,
55
- originalBindings: 'originalBindings' in options ? options.originalBindings : bindings,
56
- };
57
- return sparqlalgebrajs_1.Util.mapOperation(operation, {
58
- path(op, factory) {
59
- // Materialize variables in a path expression.
60
- // The predicate expression will be recursed.
61
- return {
62
- recurse: false,
63
- result: Object.assign(factory.createPath(materializeTerm(op.subject, bindings), op.predicate, materializeTerm(op.object, bindings), materializeTerm(op.graph, bindings)), { metadata: op.metadata }),
64
- };
65
- },
66
- pattern(op, factory) {
67
- // Materialize variables in the quad pattern.
68
- return {
69
- recurse: false,
70
- result: Object.assign(factory.createPattern(materializeTerm(op.subject, bindings), materializeTerm(op.predicate, bindings), materializeTerm(op.object, bindings), materializeTerm(op.graph, bindings)), { metadata: op.metadata }),
71
- };
72
- },
73
- extend(op) {
74
- // Materialize an extend operation.
75
- // If strictTargetVariables is true, we throw if the extension target variable is attempted to be bound.
76
- // Otherwise, we remove the extend operation.
77
- if (bindings.has(op.variable)) {
78
- if (options.strictTargetVariables) {
79
- throw new Error(`Tried to bind variable ${(0, rdf_string_1.termToString)(op.variable)} in a BIND operator.`);
80
- }
81
- else {
82
- return {
83
- recurse: true,
84
- result: materializeOperation(op.input, bindings, bindingsFactory, options),
85
- };
86
- }
87
- }
88
- return {
89
- recurse: true,
90
- result: op,
91
- };
92
- },
93
- group(op, factory) {
94
- // Materialize a group operation.
95
- // If strictTargetVariables is true, we throw if the group target variable is attempted to be bound.
96
- // Otherwise, we just filter out the bound variables.
97
- if (options.strictTargetVariables) {
98
- for (const variable of op.variables) {
99
- if (bindings.has(variable)) {
100
- throw new Error(`Tried to bind variable ${(0, rdf_string_1.termToString)(variable)} in a GROUP BY operator.`);
101
- }
102
- }
103
- return {
104
- recurse: true,
105
- result: op,
106
- };
107
- }
108
- const variables = op.variables.filter(variable => !bindings.has(variable));
109
- return {
110
- recurse: true,
111
- result: factory.createGroup(op.input, variables, op.aggregates),
112
- };
113
- },
114
- project(op, factory) {
115
- // Materialize a project operation.
116
- // If strictTargetVariables is true, we throw if the project target variable is attempted to be bound.
117
- // Otherwise, we make a values clause out of the target variable and its value in InitialBindings.
118
- if (options.strictTargetVariables) {
119
- for (const variable of op.variables) {
120
- if (bindings.has(variable)) {
121
- throw new Error(`Tried to bind variable ${(0, rdf_string_1.termToString)(variable)} in a SELECT operator.`);
122
- }
123
- }
124
- return {
125
- recurse: true,
126
- result: op,
127
- };
128
- }
129
- // Only include non-projected variables in the bindings that will be passed down recursively.
130
- // This will result in non-projected variables being replaced with their InitialBindings values.
131
- for (const bindingKey of bindings.keys()) {
132
- for (const curVariable of op.variables) {
133
- if (curVariable.equals(bindingKey)) {
134
- bindings = bindings.delete(bindingKey);
135
- break;
136
- }
137
- }
138
- }
139
- // Find projected variables which are present in the originalBindings.
140
- // This will result in projected variables being handled via a values clause.
141
- const values = createValuesFromBindings(factory, options.originalBindings, op.variables);
142
- let recursionResult = materializeOperation(op.input, bindings, bindingsFactory, options);
143
- if (values.length > 0) {
144
- recursionResult = factory.createJoin([...values, recursionResult]);
145
- }
146
- return {
147
- recurse: false,
148
- result: factory.createProject(recursionResult, op.variables),
149
- };
150
- },
151
- filter(op, factory) {
152
- const originalBindings = options.originalBindings;
153
- if (op.expression.expressionType !== 'operator' || originalBindings.size === 0) {
154
- return {
155
- recurse: false,
156
- result: op,
157
- };
158
- }
159
- // Make a values clause using all the variables from originalBindings.
160
- const values = createValuesFromBindings(factory, originalBindings);
161
- // Recursively materialize the filter expression
162
- const recursionResultExpression = materializeOperation(op.expression, bindings, bindingsFactory, options);
163
- // Recursively materialize the filter input
164
- let recursionResultInput = materializeOperation(op.input, bindings, bindingsFactory, options);
165
- if (values.length > 0) {
166
- recursionResultInput = factory.createJoin([...values, recursionResultInput]);
167
- }
168
- return {
169
- // Recursion already taken care of above.
170
- recurse: false,
171
- result: factory.createFilter(recursionResultInput, recursionResultExpression),
172
- };
173
- },
174
- values(op, factory) {
175
- // Materialize a values operation.
176
- // If strictTargetVariables is true, we throw if the values target variable is attempted to be bound.
177
- // Otherwise, we just filter out the bound variables and their bindings.
178
- if (options.strictTargetVariables) {
179
- for (const variable of op.variables) {
180
- if (bindings.has(variable)) {
181
- throw new Error(`Tried to bind variable ${(0, rdf_string_1.termToString)(variable)} in a VALUES operator.`);
182
- }
183
- }
184
- }
185
- else {
186
- const variables = op.variables.filter(variable => !bindings.has(variable));
187
- const valueBindings = op.bindings.map((binding) => {
188
- const newBinding = { ...binding };
189
- let valid = true;
190
- // eslint-disable-next-line unicorn/no-array-for-each
191
- bindings.forEach((value, key) => {
192
- const keyString = (0, rdf_string_1.termToString)(key);
193
- if (keyString in newBinding) {
194
- if (!value.equals(newBinding[keyString])) {
195
- // If the value of the binding is not equal, remove this binding completely from the VALUES clause
196
- valid = false;
197
- }
198
- delete newBinding[keyString];
199
- }
200
- });
201
- return valid ? newBinding : undefined;
202
- }).filter(Boolean);
203
- return {
204
- recurse: true,
205
- result: factory.createValues(variables, valueBindings),
206
- };
207
- }
208
- return {
209
- recurse: false,
210
- result: op,
211
- };
212
- },
213
- expression(op, factory) {
214
- if (!options.bindFilter) {
215
- return {
216
- recurse: false,
217
- result: op,
218
- };
219
- }
220
- if (op.expressionType === 'term') {
221
- // Materialize a term expression
222
- return {
223
- recurse: false,
224
- result: factory.createTermExpression(materializeTerm(op.term, bindings)),
225
- };
226
- }
227
- if (op.expressionType === 'operator') {
228
- if (op.operator === 'bound' && op.args.length === 1 && op.args[0].expressionType === 'term' &&
229
- [...bindings.keys()].some(variable => op.args[0].term.equals(variable))) {
230
- return {
231
- recurse: false,
232
- result: factory.createTermExpression(TRUE),
233
- };
234
- }
235
- return {
236
- recurse: true,
237
- result: op,
238
- };
239
- }
240
- if (op.expressionType === 'aggregate' &&
241
- 'variable' in op &&
242
- bindings.has(op.variable)) {
243
- // Materialize a bound aggregate operation.
244
- // If strictTargetVariables is true, we throw if the expression target variable is attempted to be bound.
245
- // Otherwise, we ignore this operation.
246
- if (options.strictTargetVariables) {
247
- throw new Error(`Tried to bind ${(0, rdf_string_1.termToString)(op.variable)} in a ${op.aggregator} aggregate.`);
248
- }
249
- else {
250
- return {
251
- recurse: true,
252
- result: op,
253
- };
254
- }
255
- }
256
- return {
257
- recurse: true,
258
- result: op,
259
- };
260
- },
261
- });
262
- }
263
- exports.materializeOperation = materializeOperation;
264
- /**
265
- * Make a values operation containing the values that are present in `bindings` for variables present in `variables`.
266
- * If no `variables` argument is given, this method returns a values operation
267
- * containing every binding from `bindings`.
268
- * @param {Factory} factory The Factory used to create the values operation.
269
- * @param {Bindings} bindings A bindings object.
270
- * @param {Variable[]} variables A list of variables.
271
- * @returns Algebra.Values A new values operation the given bindings.
272
- */
273
- function createValuesFromBindings(factory, bindings, variables) {
274
- const values = [];
275
- for (const [variable, binding] of bindings) {
276
- if (!variables || variables.some(v => v.equals(variable))) {
277
- const newBinding = { [(0, rdf_string_1.termToString)(variable)]: binding };
278
- values.push(factory.createValues([variable], [newBinding]));
279
- }
280
- }
281
- return values;
282
- }
283
- //# sourceMappingURL=Bindings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Bindings.js","sourceRoot":"","sources":["Bindings.ts"],"names":[],"mappings":";;;AAIA,uDAA+C;AAC/C,2CAA0C;AAC1C,yCAA4D;AAE5D,qDAAuC;AAEvC,MAAM,EAAE,GAAG,IAAI,8BAAW,EAAE,CAAC;AAE7B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,0CAA0C,CAAC,CAAC,CAAC;AAE1F;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,IAAc,EAAE,QAAkB;I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C,OAAgB,EAAE,QAAkB,EAAE,SAAsB;IAC5F,MAAM,MAAM,GAAqB,EAAE,CAAC;IAEpC,KAAK,MAAM,CAAE,QAAQ,EAAE,OAAO,CAAE,IAAI,QAAQ,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC1D,MAAM,UAAU,GAAG,EAAE,CAAC,IAAA,yBAAY,EAAC,QAAQ,CAAC,CAAC,EAAgC,OAAO,EAAE,CAAC;YAEvF,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAE,QAAQ,CAAE,EAAE,CAAE,UAAU,CAAE,CAAC,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { BindingsFactory } from '@comunica/bindings-factory';\nimport type { Bindings } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { Variable } from 'rdf-data-factory';\nimport { DataFactory } from 'rdf-data-factory';\nimport { termToString } from 'rdf-string';\nimport { mapTermsNested, someTermsNested } from 'rdf-terms';\nimport type { Algebra, Factory } from 'sparqlalgebrajs';\nimport { Util } from 'sparqlalgebrajs';\n\nconst DF = new DataFactory();\n\nconst TRUE = DF.literal('true', DF.namedNode('http://www.w3.org/2001/XMLSchema#boolean'));\n\n/**\n * Materialize a term with the given binding.\n *\n * If the given term is a variable,\n * and that variable exist in the given bindings object,\n * the value of that binding is returned.\n * In all other cases, the term itself is returned.\n *\n * @param {RDF.Term} term A term.\n * @param {Bindings} bindings A bindings object.\n * @return {RDF.Term} The materialized term.\n */\nexport function materializeTerm(term: RDF.Term, bindings: Bindings): RDF.Term {\n if (term.termType === 'Variable') {\n const value = bindings.get(term);\n if (value) {\n return value;\n }\n }\n if (term.termType === 'Quad' && someTermsNested(term, value => value.termType === 'Variable')) {\n return mapTermsNested(term, subTerm => materializeTerm(subTerm, bindings));\n }\n return term;\n}\n\n/**\n * Materialize the given operation (recursively) with the given bindings.\n * Essentially, the variables in the given operation\n * which don't appear in the projection operation will be replaced\n * by the terms bound to the variables in the given bindings.\n * @param {Algebra.Operation} operation SPARQL algebra operation.\n * And the variables that appear in the projection operation\n * will be added to a new values operation.\n * @param {Bindings} bindings A bindings object.\n * @param bindingsFactory The bindings factory.\n * @param options Options for materializations.\n * @param options.strictTargetVariables If target variable bindings (such as on SELECT or BIND) should not be allowed.\n * @param options.bindFilter If filter expressions should be materialized.\n * @param options.originalBindings The bindings object as it was at the top level call of materializeOperation.\n * @return Algebra.Operation A new operation materialized with the given bindings.\n */\nexport function materializeOperation(\n operation: Algebra.Operation,\n bindings: Bindings,\n bindingsFactory: BindingsFactory,\n options: {\n strictTargetVariables?: boolean;\n bindFilter?: boolean;\n originalBindings?: Bindings;\n } = {},\n): Algebra.Operation {\n options = {\n strictTargetVariables: 'strictTargetVariables' in options ? options.strictTargetVariables : false,\n bindFilter: 'bindFilter' in options ? options.bindFilter : true,\n originalBindings: 'originalBindings' in options ? options.originalBindings : bindings,\n };\n\n return Util.mapOperation(operation, {\n path(op: Algebra.Path, factory: Factory) {\n // Materialize variables in a path expression.\n // The predicate expression will be recursed.\n return {\n recurse: false,\n result: Object.assign(factory.createPath(\n materializeTerm(op.subject, bindings),\n op.predicate,\n materializeTerm(op.object, bindings),\n materializeTerm(op.graph, bindings),\n ), { metadata: op.metadata }),\n };\n },\n pattern(op: Algebra.Pattern, factory: Factory) {\n // Materialize variables in the quad pattern.\n return {\n recurse: false,\n result: Object.assign(factory.createPattern(\n materializeTerm(op.subject, bindings),\n materializeTerm(op.predicate, bindings),\n materializeTerm(op.object, bindings),\n materializeTerm(op.graph, bindings),\n ), { metadata: op.metadata }),\n };\n },\n extend(op: Algebra.Extend) {\n // Materialize an extend operation.\n // If strictTargetVariables is true, we throw if the extension target variable is attempted to be bound.\n // Otherwise, we remove the extend operation.\n if (bindings.has(op.variable)) {\n if (options.strictTargetVariables) {\n throw new Error(`Tried to bind variable ${termToString(op.variable)} in a BIND operator.`);\n } else {\n return {\n recurse: true,\n result: materializeOperation(op.input, bindings, bindingsFactory, options),\n };\n }\n }\n return {\n recurse: true,\n result: op,\n };\n },\n group(op: Algebra.Group, factory: Factory) {\n // Materialize a group operation.\n // If strictTargetVariables is true, we throw if the group target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a GROUP BY operator.`);\n }\n }\n return {\n recurse: true,\n result: op,\n };\n }\n const variables = op.variables.filter(variable => !bindings.has(variable));\n return {\n recurse: true,\n result: factory.createGroup(\n op.input,\n variables,\n op.aggregates,\n ),\n };\n },\n project(op: Algebra.Project, factory: Factory) {\n // Materialize a project operation.\n // If strictTargetVariables is true, we throw if the project target variable is attempted to be bound.\n // Otherwise, we make a values clause out of the target variable and its value in InitialBindings.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a SELECT operator.`);\n }\n }\n return {\n recurse: true,\n result: op,\n };\n }\n\n // Only include non-projected variables in the bindings that will be passed down recursively.\n // This will result in non-projected variables being replaced with their InitialBindings values.\n for (const bindingKey of bindings.keys()) {\n for (const curVariable of op.variables) {\n if (curVariable.equals(bindingKey)) {\n bindings = bindings.delete(bindingKey);\n break;\n }\n }\n }\n\n // Find projected variables which are present in the originalBindings.\n // This will result in projected variables being handled via a values clause.\n const values: Algebra.Operation[] =\n createValuesFromBindings(factory, <Bindings> options.originalBindings, op.variables);\n\n let recursionResult: Algebra.Operation = materializeOperation(\n op.input,\n bindings,\n bindingsFactory,\n options,\n );\n\n if (values.length > 0) {\n recursionResult = factory.createJoin([ ...values, recursionResult ]);\n }\n\n return {\n recurse: false,\n result: factory.createProject(recursionResult, op.variables),\n };\n },\n filter(op: Algebra.Filter, factory: Factory) {\n const originalBindings: Bindings = <Bindings> options.originalBindings;\n if (op.expression.expressionType !== 'operator' || originalBindings.size === 0) {\n return {\n recurse: false,\n result: op,\n };\n }\n\n // Make a values clause using all the variables from originalBindings.\n const values: Algebra.Operation[] = createValuesFromBindings(factory, originalBindings);\n\n // Recursively materialize the filter expression\n const recursionResultExpression: Algebra.Expression = <Algebra.Expression> materializeOperation(\n op.expression,\n bindings,\n bindingsFactory,\n options,\n );\n\n // Recursively materialize the filter input\n let recursionResultInput: Algebra.Operation = materializeOperation(\n op.input,\n bindings,\n bindingsFactory,\n options,\n );\n\n if (values.length > 0) {\n recursionResultInput = factory.createJoin([ ...values, recursionResultInput ]);\n }\n\n return {\n // Recursion already taken care of above.\n recurse: false,\n result: factory.createFilter(recursionResultInput, recursionResultExpression),\n };\n },\n values(op: Algebra.Values, factory: Factory) {\n // Materialize a values operation.\n // If strictTargetVariables is true, we throw if the values target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables and their bindings.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a VALUES operator.`);\n }\n }\n } else {\n const variables = op.variables.filter(variable => !bindings.has(variable));\n const valueBindings: Record<string, RDF.Literal | RDF.NamedNode>[] = <any> op.bindings.map((binding) => {\n const newBinding = { ...binding };\n let valid = true;\n // eslint-disable-next-line unicorn/no-array-for-each\n bindings.forEach((value: RDF.Term, key: RDF.Variable) => {\n const keyString = termToString(key);\n if (keyString in newBinding) {\n if (!value.equals(newBinding[keyString])) {\n // If the value of the binding is not equal, remove this binding completely from the VALUES clause\n valid = false;\n }\n delete newBinding[keyString];\n }\n });\n return valid ? newBinding : undefined;\n }).filter(Boolean);\n return {\n recurse: true,\n result: factory.createValues(\n variables,\n valueBindings,\n ),\n };\n }\n return {\n recurse: false,\n result: op,\n };\n },\n expression(op: Algebra.Expression, factory: Factory) {\n if (!options.bindFilter) {\n return {\n recurse: false,\n result: op,\n };\n }\n\n if (op.expressionType === 'term') {\n // Materialize a term expression\n return {\n recurse: false,\n result: factory.createTermExpression(materializeTerm(op.term, bindings)),\n };\n }\n if (op.expressionType === 'operator') {\n if (op.operator === 'bound' && op.args.length === 1 && op.args[0].expressionType === 'term' &&\n [ ...bindings.keys() ].some(variable => op.args[0].term.equals(variable))) {\n return {\n recurse: false,\n result: factory.createTermExpression(TRUE),\n };\n }\n return {\n recurse: true,\n result: op,\n };\n }\n if (op.expressionType === 'aggregate' &&\n 'variable' in op &&\n bindings.has(<RDF.Variable> op.variable)) {\n // Materialize a bound aggregate operation.\n // If strictTargetVariables is true, we throw if the expression target variable is attempted to be bound.\n // Otherwise, we ignore this operation.\n if (options.strictTargetVariables) {\n throw new Error(`Tried to bind ${termToString(op.variable)} in a ${op.aggregator} aggregate.`);\n } else {\n return {\n recurse: true,\n result: op,\n };\n }\n }\n return {\n recurse: true,\n result: op,\n };\n },\n });\n}\n\n/**\n * Make a values operation containing the values that are present in `bindings` for variables present in `variables`.\n * If no `variables` argument is given, this method returns a values operation\n * containing every binding from `bindings`.\n * @param {Factory} factory The Factory used to create the values operation.\n * @param {Bindings} bindings A bindings object.\n * @param {Variable[]} variables A list of variables.\n * @returns Algebra.Values A new values operation the given bindings.\n */\nfunction createValuesFromBindings(factory: Factory, bindings: Bindings, variables?: Variable[]): Algebra.Values[] {\n const values: Algebra.Values[] = [];\n\n for (const [ variable, binding ] of bindings) {\n if (!variables || variables.some(v => v.equals(variable))) {\n const newBinding = { [termToString(variable)]: <RDF.NamedNode | RDF.Literal> binding };\n\n values.push(factory.createValues([ variable ], [ newBinding ]));\n }\n }\n\n return values;\n}\n"]}
@@ -1,18 +0,0 @@
1
- import { AsyncIterator, DESTINATION } from 'asynciterator';
2
- type InternalSource<T> = AsyncIterator<T> & {
3
- [DESTINATION]?: AsyncIterator<any>;
4
- };
5
- /**
6
- * An AsyncIterator with a callback for when this iterator is closed in any way.
7
- * In contrast to ClosableTransformIterator, this does not add the overhead of a TransformIterator.
8
- */
9
- export declare class ClosableIterator<S> extends AsyncIterator<S> {
10
- protected readonly _source: InternalSource<S>;
11
- private readonly onClose;
12
- constructor(source: AsyncIterator<S>, options: {
13
- onClose: () => void;
14
- });
15
- read(): S | null;
16
- protected _end(destroy: boolean): void;
17
- }
18
- export {};
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClosableIterator = void 0;
4
- const asynciterator_1 = require("asynciterator");
5
- /**
6
- * An AsyncIterator with a callback for when this iterator is closed in any way.
7
- * In contrast to ClosableTransformIterator, this does not add the overhead of a TransformIterator.
8
- */
9
- class ClosableIterator extends asynciterator_1.AsyncIterator {
10
- constructor(source, options) {
11
- super();
12
- this.onClose = options.onClose;
13
- this._source = source;
14
- // Wire up the source for reading
15
- this._source[asynciterator_1.DESTINATION] = this;
16
- this._source.on('end', destinationClose);
17
- this._source.on('error', destinationEmitError);
18
- this._source.on('readable', destinationSetReadable);
19
- this.readable = this._source.readable;
20
- }
21
- read() {
22
- const ret = this._source.read();
23
- if (!ret) {
24
- // Mark as non-readable if ret was null
25
- this.readable = false;
26
- // Close this iterator if the source is empty
27
- if (this._source.done) {
28
- this.close();
29
- }
30
- }
31
- return ret;
32
- }
33
- _end(destroy) {
34
- this.onClose();
35
- this._source.removeListener('end', destinationClose);
36
- this._source.removeListener('error', destinationEmitError);
37
- this._source.removeListener('readable', destinationSetReadable);
38
- delete this._source[asynciterator_1.DESTINATION];
39
- this._source.destroy();
40
- super._end(destroy);
41
- }
42
- }
43
- exports.ClosableIterator = ClosableIterator;
44
- // Helpers below are copied from AsyncIterator, as they are not exported from there.
45
- function destinationSetReadable() {
46
- this[asynciterator_1.DESTINATION].readable = true;
47
- }
48
- function destinationEmitError(error) {
49
- this[asynciterator_1.DESTINATION].emit('error', error);
50
- }
51
- function destinationClose() {
52
- this[asynciterator_1.DESTINATION].close();
53
- }
54
- //# sourceMappingURL=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E,oBAAoB,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,OAAO,CAAC,2BAAW,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF;AAzCD,4CAyCC;AAED,oFAAoF;AAEpF,SAAS,sBAAsB;IAC7B,IAAI,CAAC,2BAAW,CAAE,CAAC,QAAQ,GAAG,IAAI,CAAC;AACrC,CAAC;AACD,SAAS,oBAAoB,CAA6B,KAAY;IACpE,IAAI,CAAC,2BAAW,CAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC;AACD,SAAS,gBAAgB;IACvB,IAAI,CAAC,2BAAW,CAAE,CAAC,KAAK,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import { AsyncIterator, DESTINATION } from 'asynciterator';\n\ntype InternalSource<T> =\n AsyncIterator<T> & { [DESTINATION]?: AsyncIterator<any> };\n\n/**\n * An AsyncIterator with a callback for when this iterator is closed in any way.\n * In contrast to ClosableTransformIterator, this does not add the overhead of a TransformIterator.\n */\nexport class ClosableIterator<S> extends AsyncIterator<S> {\n protected readonly _source: InternalSource<S>;\n private readonly onClose: () => void;\n\n public constructor(source: AsyncIterator<S>, options: { onClose: () => void }) {\n super();\n this.onClose = options.onClose;\n this._source = <InternalSource<S>> source;\n\n // Wire up the source for reading\n this._source[DESTINATION] = this;\n this._source.on('end', destinationClose);\n this._source.on('error', destinationEmitError);\n this._source.on('readable', destinationSetReadable);\n this.readable = this._source.readable;\n }\n\n public override read(): S | null {\n const ret = this._source.read();\n if (!ret) {\n // Mark as non-readable if ret was null\n this.readable = false;\n\n // Close this iterator if the source is empty\n if (this._source.done) {\n this.close();\n }\n }\n return ret;\n }\n\n protected override _end(destroy: boolean): void {\n this.onClose();\n\n this._source.removeListener('end', destinationClose);\n this._source.removeListener('error', destinationEmitError);\n this._source.removeListener('readable', destinationSetReadable);\n delete this._source[DESTINATION];\n this._source.destroy();\n super._end(destroy);\n }\n}\n\n// Helpers below are copied from AsyncIterator, as they are not exported from there.\n\nfunction destinationSetReadable<S>(this: InternalSource<S>): void {\n this[DESTINATION]!.readable = true;\n}\nfunction destinationEmitError<S>(this: InternalSource<S>, error: Error): void {\n this[DESTINATION]!.emit('error', error);\n}\nfunction destinationClose<S>(this: InternalSource<S>): void {\n this[DESTINATION]!.close();\n}\n"]}
@@ -1,15 +0,0 @@
1
- import type { AsyncIterator, TransformIteratorOptions } from 'asynciterator';
2
- import { TransformIterator } from 'asynciterator';
3
- declare type MaybePromise<T> = T | Promise<T>;
4
- declare type SourceExpression<T> = MaybePromise<AsyncIterator<T>> | (() => MaybePromise<AsyncIterator<T>>);
5
- /**
6
- * A TransformIterator with a callback for when this iterator is closed in any way.
7
- */
8
- export declare class ClosableTransformIterator<S, D = S> extends TransformIterator<S, D> {
9
- private readonly onClose;
10
- constructor(source: SourceExpression<S>, options: TransformIteratorOptions<S> & {
11
- onClose: () => void;
12
- });
13
- protected _end(destroy: boolean): void;
14
- }
15
- export {};
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClosableTransformIterator = void 0;
4
- const asynciterator_1 = require("asynciterator");
5
- /**
6
- * A TransformIterator with a callback for when this iterator is closed in any way.
7
- */
8
- class ClosableTransformIterator extends asynciterator_1.TransformIterator {
9
- constructor(source, options) {
10
- super(source, options);
11
- this.onClose = options.onClose;
12
- }
13
- _end(destroy) {
14
- this.onClose();
15
- super._end(destroy);
16
- }
17
- }
18
- exports.ClosableTransformIterator = ClosableTransformIterator;
19
- //# sourceMappingURL=ClosableTransformIterator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ClosableTransformIterator.js","sourceRoot":"","sources":["ClosableTransformIterator.ts"],"names":[],"mappings":";;;AACA,iDAAkD;AAKlD;;GAEG;AACH,MAAa,yBAAoC,SAAQ,iCAAuB;IAG9E,YAAmB,MAA2B,EAAE,OAA8D;QAC5G,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAEkB,IAAI,CAAC,OAAgB;QACtC,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF;AAZD,8DAYC","sourcesContent":["import type { AsyncIterator, TransformIteratorOptions } from 'asynciterator';\nimport { TransformIterator } from 'asynciterator';\n\ndeclare type MaybePromise<T> = T | Promise<T>;\ndeclare type SourceExpression<T> = MaybePromise<AsyncIterator<T>> | (() => MaybePromise<AsyncIterator<T>>);\n\n/**\n * A TransformIterator with a callback for when this iterator is closed in any way.\n */\nexport class ClosableTransformIterator<S, D = S> extends TransformIterator<S, D> {\n private readonly onClose: () => void;\n\n public constructor(source: SourceExpression<S>, options: TransformIteratorOptions<S> & { onClose: () => void }) {\n super(source, options);\n this.onClose = options.onClose;\n }\n\n protected override _end(destroy: boolean): void {\n this.onClose();\n super._end(destroy);\n }\n}\n"]}