@comunica/bus-bindings-aggregator-factory 5.3.0 → 5.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Comunica Bus Bindings Aggregator Factory
2
2
 
3
- [![npm version](https://badge.fury.io/js/%40comunica%2Fbus-expression-evaluator-aggregate.svg)](https://www.npmjs.com/package/@comunica/bus-expression-evaluator-aggregate)
3
+ [![npm version](https://badge.fury.io/js/%40comunica%2Fbus-bindings-aggregator-factory.svg)](https://www.npmjs.com/package/@comunica/bus-bindings-aggregator-factory)
4
4
 
5
5
  A comunica bus for bindings-aggregator-factory events.
6
6
 
@@ -15,8 +15,6 @@ and should only be used by [developers that want to build their own query engine
15
15
  $ yarn add @comunica/bus-bindings-aggregator-factory
16
16
  ```
17
17
 
18
- ## Usage
19
-
20
18
  ## Bus usage
21
19
 
22
20
  * **Context**: `"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-bindings-aggregator-factory/^1.0.0/components/context.jsonld"`
@@ -24,4 +22,4 @@ $ yarn add @comunica/bus-bindings-aggregator-factory
24
22
 
25
23
  ## Creating actors on this bus
26
24
 
27
- Actors extending [`ActorBindingsAggregatorFactory`](https://comunica.github.io/comunica/modules/_comunica_bus_bindings_aggregator_factory.html) are automatically subscribed to this bus.
25
+ Actors extending [`ActorBindingsAggregatorFactory`](https://comunica.github.io/comunica/classes/_comunica_bus-bindings-aggregator-factory.ActorBindingsAggregatorFactory.html) are automatically subscribed to this bus.
@@ -215,31 +215,12 @@
215
215
  ],
216
216
  "constructorArguments": []
217
217
  },
218
- {
219
- "@id": "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IBindingsAggregator",
220
- "@type": "AbstractClass",
221
- "requireElement": "IBindingsAggregator",
222
- "comment": "Instances of this interface perform a specific aggregation of bindings. You can put bindings and when all bindings have been put, request the result.",
223
- "parameters": [],
224
- "memberFields": [
225
- {
226
- "@id": "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IBindingsAggregator__member_putBindings",
227
- "memberFieldName": "putBindings"
228
- },
229
- {
230
- "@id": "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IBindingsAggregator__member_result",
231
- "memberFieldName": "result"
232
- }
233
- ],
234
- "constructorArguments": []
235
- },
236
218
  {
237
219
  "@id": "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IActorBindingsAggregatorFactoryOutput",
238
220
  "@type": "AbstractClass",
239
221
  "requireElement": "IActorBindingsAggregatorFactoryOutput",
240
222
  "extends": [
241
- "cc:components/Actor.jsonld#IActorOutput",
242
- "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IBindingsAggregator"
223
+ "cc:components/Actor.jsonld#IActorOutput"
243
224
  ],
244
225
  "parameters": [],
245
226
  "constructorArguments": []
@@ -47,11 +47,6 @@
47
47
  "@prefix": true,
48
48
  "@context": {}
49
49
  },
50
- "IBindingsAggregator": {
51
- "@id": "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IBindingsAggregator",
52
- "@prefix": true,
53
- "@context": {}
54
- },
55
50
  "IActorBindingsAggregatorFactoryOutput": {
56
51
  "@id": "cbbaf:components/ActorBindingsAggregatorFactory.jsonld#IActorBindingsAggregatorFactoryOutput",
57
52
  "@prefix": true,
@@ -1,8 +1,8 @@
1
1
  import type { MediatorExpressionEvaluatorFactory } from '@comunica/bus-expression-evaluator-factory';
2
2
  import type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@comunica/core';
3
3
  import { Actor } from '@comunica/core';
4
+ import type { IBindingsAggregator as IBindingsAggregatorType } from '@comunica/types';
4
5
  import type { Algebra } from '@comunica/utils-algebra';
5
- import type * as RDF from '@rdfjs/types';
6
6
  /**
7
7
  * A comunica actor for creating Binding-Aggregator-factories.
8
8
  *
@@ -24,23 +24,19 @@ export declare abstract class ActorBindingsAggregatorFactory<TS = undefined> ext
24
24
  protected constructor(args: IActorBindingsAggregatorFactoryArgs<TS>);
25
25
  }
26
26
  export interface IActionBindingsAggregatorFactory extends IAction {
27
+ /**
28
+ * The aggregate to create an aggregator for.
29
+ * Can also be an extension aggregate ({@link Algebra.BoundNamedAggregate}).
30
+ * TODO(next major): include Algebra.BoundNamedAggregate in the type.
31
+ */
27
32
  expr: Algebra.AggregateExpression;
28
33
  }
29
34
  /**
30
- * Instances of this interface perform a specific aggregation of bindings.
31
- * You can put bindings and when all bindings have been put, request the result.
35
+ * An aggregator of RDF bindings.
36
+ * Defined in `@comunica/types`, and exposed here for backwards compatibility.
37
+ * @deprecated use export from `@comunica/types` instead.
32
38
  */
33
- export interface IBindingsAggregator {
34
- /**
35
- * Registers bindings to the aggregator. Each binding you put has the ability to change the aggregation result.
36
- * @param bindings the bindings to put.
37
- */
38
- putBindings: (bindings: RDF.Bindings) => Promise<void>;
39
- /**
40
- * Request the result term of aggregating the bindings you have put in the aggregator.
41
- */
42
- result: () => Promise<RDF.Term | undefined>;
43
- }
39
+ export type IBindingsAggregator = IBindingsAggregatorType;
44
40
  export interface IActorBindingsAggregatorFactoryOutput extends IActorOutput, IBindingsAggregator {
45
41
  }
46
42
  export interface IActorBindingsAggregatorFactoryArgs<TS = undefined> extends IActorArgs<IActionBindingsAggregatorFactory, IActorTest, IActorBindingsAggregatorFactoryOutput, TS> {
@@ -1 +1 @@
1
- {"version":3,"file":"ActorBindingsAggregatorFactory.js","sourceRoot":"","sources":["ActorBindingsAggregatorFactory.ts"],"names":[],"mappings":";;;AAIA,yCAAuC;AAIvC;;;;;;;;;;GAUG;AACH,MAAsB,8BAA+C,SAAQ,YAK5E;IACoB,kCAAkC,CAAqC;IAC1F,4BAA4B;IAC5B;;;;OAIG;IACH,2BAA2B;IAC3B,YAAsB,IAA6C;QACjE,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,kCAAkC,GAAG,IAAI,CAAC,kCAAkC,CAAC;IACpF,CAAC;CACF;AAlBD,wEAkBC","sourcesContent":["import type {\n MediatorExpressionEvaluatorFactory,\n} from '@comunica/bus-expression-evaluator-factory';\nimport type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport type { Algebra } from '@comunica/utils-algebra';\nimport type * as RDF from '@rdfjs/types';\n\n/**\n * A comunica actor for creating Binding-Aggregator-factories.\n *\n * Actor types:\n * * Input: IActionBindingsAggregatorFactory: A SPARQL expression and a factory for an expression evaluator.\n * * Test: <none>\n * * Output: IActorBindingsAggregatorFactoryOutput: An aggregator of RDF bindings.\n *\n * @see IActionBindingsAggregatorFactory\n * @see IActorBindingsAggregatorFactoryOutput\n */\nexport abstract class ActorBindingsAggregatorFactory<TS = undefined> extends Actor<\nIActionBindingsAggregatorFactory,\nIActorTest,\nIActorBindingsAggregatorFactoryOutput,\nTS\n> {\n protected readonly mediatorExpressionEvaluatorFactory: MediatorExpressionEvaluatorFactory;\n /* eslint-disable max-len */\n /**\n * @param args -\n * \\ @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus\n * \\ @defaultNested {Creation of Aggregator failed: none of the configured actors were able to handle ${action.expr.aggregator}} busFailMessage\n */\n /* eslint-enable max-len */\n protected constructor(args: IActorBindingsAggregatorFactoryArgs<TS>) {\n super(args);\n this.mediatorExpressionEvaluatorFactory = args.mediatorExpressionEvaluatorFactory;\n }\n}\n\nexport interface IActionBindingsAggregatorFactory extends IAction {\n expr: Algebra.AggregateExpression;\n}\n\n/**\n * Instances of this interface perform a specific aggregation of bindings.\n * You can put bindings and when all bindings have been put, request the result.\n */\nexport interface IBindingsAggregator {\n /**\n * Registers bindings to the aggregator. Each binding you put has the ability to change the aggregation result.\n * @param bindings the bindings to put.\n */\n putBindings: (bindings: RDF.Bindings) => Promise<void>;\n\n /**\n * Request the result term of aggregating the bindings you have put in the aggregator.\n */\n result: () => Promise<RDF.Term | undefined>;\n}\n\nexport interface IActorBindingsAggregatorFactoryOutput extends IActorOutput, IBindingsAggregator {}\n\nexport interface IActorBindingsAggregatorFactoryArgs<TS = undefined> extends IActorArgs<\nIActionBindingsAggregatorFactory,\nIActorTest,\nIActorBindingsAggregatorFactoryOutput,\nTS\n> {\n mediatorExpressionEvaluatorFactory: MediatorExpressionEvaluatorFactory;\n}\n\nexport type MediatorBindingsAggregatorFactory = Mediate<\nIActionBindingsAggregatorFactory,\nIActorBindingsAggregatorFactoryOutput\n>;\n"]}
1
+ {"version":3,"file":"ActorBindingsAggregatorFactory.js","sourceRoot":"","sources":["ActorBindingsAggregatorFactory.ts"],"names":[],"mappings":";;;AAIA,yCAAuC;AAIvC;;;;;;;;;;GAUG;AACH,MAAsB,8BAA+C,SAAQ,YAK5E;IACoB,kCAAkC,CAAqC;IAC1F,4BAA4B;IAC5B;;;;OAIG;IACH,2BAA2B;IAC3B,YAAsB,IAA6C;QACjE,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,kCAAkC,GAAG,IAAI,CAAC,kCAAkC,CAAC;IACpF,CAAC;CACF;AAlBD,wEAkBC","sourcesContent":["import type {\n MediatorExpressionEvaluatorFactory,\n} from '@comunica/bus-expression-evaluator-factory';\nimport type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport type { IBindingsAggregator as IBindingsAggregatorType } from '@comunica/types';\nimport type { Algebra } from '@comunica/utils-algebra';\n\n/**\n * A comunica actor for creating Binding-Aggregator-factories.\n *\n * Actor types:\n * * Input: IActionBindingsAggregatorFactory: A SPARQL expression and a factory for an expression evaluator.\n * * Test: <none>\n * * Output: IActorBindingsAggregatorFactoryOutput: An aggregator of RDF bindings.\n *\n * @see IActionBindingsAggregatorFactory\n * @see IActorBindingsAggregatorFactoryOutput\n */\nexport abstract class ActorBindingsAggregatorFactory<TS = undefined> extends Actor<\nIActionBindingsAggregatorFactory,\nIActorTest,\nIActorBindingsAggregatorFactoryOutput,\nTS\n> {\n protected readonly mediatorExpressionEvaluatorFactory: MediatorExpressionEvaluatorFactory;\n /* eslint-disable max-len */\n /**\n * @param args -\n * \\ @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus\n * \\ @defaultNested {Creation of Aggregator failed: none of the configured actors were able to handle ${action.expr.aggregator}} busFailMessage\n */\n /* eslint-enable max-len */\n protected constructor(args: IActorBindingsAggregatorFactoryArgs<TS>) {\n super(args);\n this.mediatorExpressionEvaluatorFactory = args.mediatorExpressionEvaluatorFactory;\n }\n}\n\nexport interface IActionBindingsAggregatorFactory extends IAction {\n /**\n * The aggregate to create an aggregator for.\n * Can also be an extension aggregate ({@link Algebra.BoundNamedAggregate}).\n * TODO(next major): include Algebra.BoundNamedAggregate in the type.\n */\n expr: Algebra.AggregateExpression;\n}\n\n/**\n * An aggregator of RDF bindings.\n * Defined in `@comunica/types`, and exposed here for backwards compatibility.\n * @deprecated use export from `@comunica/types` instead.\n */\n// TODO (next major): remove\nexport type IBindingsAggregator = IBindingsAggregatorType;\n\nexport interface IActorBindingsAggregatorFactoryOutput extends IActorOutput, IBindingsAggregator {}\n\nexport interface IActorBindingsAggregatorFactoryArgs<TS = undefined> extends IActorArgs<\nIActionBindingsAggregatorFactory,\nIActorTest,\nIActorBindingsAggregatorFactoryOutput,\nTS\n> {\n mediatorExpressionEvaluatorFactory: MediatorExpressionEvaluatorFactory;\n}\n\nexport type MediatorBindingsAggregatorFactory = Mediate<\nIActionBindingsAggregatorFactory,\nIActorBindingsAggregatorFactoryOutput\n>;\n"]}
@@ -4,6 +4,11 @@ import type * as RDF from '@rdfjs/types';
4
4
  /**
5
5
  * This is the base class for all aggregators.
6
6
  * NOTE: The wildcard count aggregator significantly differs from the others and overloads parts of this class.
7
+ * TODO(next major): In the extension aggregator (NamedAggregator) we basically have a copy of this AggregateEvaluator,
8
+ * but that one supports a list of arguments. Instead, we should generalize this class to a list of arguments,
9
+ * possibly empty, and to asynchronous putTerm and termResult.
10
+ * That way, the aggregator of extension aggregates (NamedAggregator) extend this abstract class instead of
11
+ * near-copying implementation.
7
12
  */
8
13
  export declare abstract class AggregateEvaluator {
9
14
  protected readonly evaluator: IExpressionEvaluator;
@@ -40,6 +40,11 @@ const RdfString = __importStar(require("rdf-string"));
40
40
  /**
41
41
  * This is the base class for all aggregators.
42
42
  * NOTE: The wildcard count aggregator significantly differs from the others and overloads parts of this class.
43
+ * TODO(next major): In the extension aggregator (NamedAggregator) we basically have a copy of this AggregateEvaluator,
44
+ * but that one supports a list of arguments. Instead, we should generalize this class to a list of arguments,
45
+ * possibly empty, and to asynchronous putTerm and termResult.
46
+ * That way, the aggregator of extension aggregates (NamedAggregator) extend this abstract class instead of
47
+ * near-copying implementation.
43
48
  */
44
49
  class AggregateEvaluator {
45
50
  evaluator;
@@ -1 +1 @@
1
- {"version":3,"file":"AggregateEvaluator.js","sourceRoot":"","sources":["AggregateEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAAoE;AAEpE,2EAA6D;AAE7D,sDAAwC;AAExC;;;GAGG;AACH,MAAsB,kBAAkB;IASjB;IACA;IACF;IAVX,aAAa,GAAG,KAAK,CAAC;IAEX,cAAc,CAAc;IAE5B,iBAAiB,CAAqB;IACtC,eAAe,CAAuB;IAEzD,YACqB,SAA+B,EAC/B,QAAiB,EACnB,aAAa,KAAK;QAFhB,cAAS,GAAT,SAAS,CAAsB;QAC/B,aAAQ,GAAR,QAAQ,CAAS;QACnB,eAAU,GAAV,UAAU,CAAQ;QAEnC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,yCAAuB,CAAC,iBAAiB,CAAC,CAAC;QAC9F,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAExE,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,CAAC;IAKM,cAAc;QACnB,OA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E,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAEO,SAAS,CAAC,GAAY;QAC5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,GAAG,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAES,oBAAoB,CAAC,IAAc;QAC3C,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QAC1G,CAAC;aAAM,IACL,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAChG,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,QAAQ,CAAC,KAAK,eAAe,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QAC1I,CAAC;QACD,OAA6B,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF;AAlGD,gDAkGC","sourcesContent":["import { KeysExpressionEvaluator } from '@comunica/context-entries';\nimport type { IExpressionEvaluator, ISuperTypeProvider } from '@comunica/types';\nimport * as Eval from '@comunica/utils-expression-evaluator';\nimport type * as RDF from '@rdfjs/types';\nimport * as RdfString from 'rdf-string';\n\n/**\n * This is the base class for all aggregators.\n * NOTE: The wildcard count aggregator significantly differs from the others and overloads parts of this class.\n */\nexport abstract class AggregateEvaluator {\n private errorOccurred = false;\n\n protected readonly variableValues: Set<string>;\n\n protected readonly superTypeProvider: ISuperTypeProvider;\n protected readonly termTransformer: Eval.TermTransformer;\n\n protected constructor(\n protected readonly evaluator: IExpressionEvaluator,\n protected readonly distinct: boolean,\n private readonly throwError = false,\n ) {\n this.errorOccurred = false;\n this.superTypeProvider = evaluator.context.getSafe(KeysExpressionEvaluator.superTypeProvider);\n this.termTransformer = new Eval.TermTransformer(this.superTypeProvider);\n\n this.variableValues = new Set();\n }\n\n protected abstract putTerm(term: RDF.Term): void;\n protected abstract termResult(): RDF.Term | undefined;\n\n public emptyValueTerm(): RDF.Term | undefined {\n return undefined;\n }\n\n /**\n * The spec says to throw an error when a set function is called on an empty\n * set (unless explicitly mentioned otherwise like COUNT).\n * However, aggregate error handling says to not bind the result in case of an\n * error. So to simplify logic in the caller, we return undefined by default.\n */\n public emptyValue(): RDF.Term | undefined {\n const val = this.emptyValueTerm();\n if (val === undefined && this.throwError) {\n throw new Eval.EmptyAggregateError();\n }\n return val;\n }\n\n /**\n * Base implementation of putBindings, that evaluates to a term and then calls putTerm.\n * The WildcardCountAggregator will completely discard this implementation.\n * @param bindings\n */\n public async putBindings(bindings: RDF.Bindings): Promise<void> {\n if (this.errorOccurred) {\n return;\n }\n try {\n const term = await this.evaluator.evaluate(bindings);\n if (!term || this.errorOccurred) {\n return;\n }\n\n // Handle DISTINCT before putting the term\n if (!this.distinct || !this.variableValues.has(RdfString.termToString(term))) {\n this.putTerm(term);\n if (this.distinct) {\n this.variableValues.add(RdfString.termToString(term));\n }\n }\n } catch (error: unknown) {\n // Per SPARQL spec, aggregate functions ignore unbound variables.\n // An UnboundVariableError simply means this binding has no value for the aggregate variable,\n // so we skip it rather than treating it as an error (which would cause the entire aggregate to fail).\n if (error instanceof Eval.UnboundVariableError) {\n return;\n }\n this.safeThrow(error);\n }\n }\n\n public async result(): Promise<RDF.Term | undefined> {\n if (this.errorOccurred) {\n return undefined;\n }\n return this.termResult();\n }\n\n private safeThrow(err: unknown): void {\n if (this.throwError) {\n throw err;\n } else {\n this.errorOccurred = true;\n }\n }\n\n protected termToNumericOrError(term: RDF.Term): Eval.NumericLiteral {\n if (term.termType !== 'Literal') {\n throw new Error(`Term with value ${term.value} has type ${term.termType} and is not a numeric literal`);\n } else if (\n !Eval.isSubTypeOf(term.datatype.value, Eval.TypeAlias.SPARQL_NUMERIC, this.superTypeProvider)) {\n throw new Error(`Term datatype ${term.datatype.value} with value ${term.value} has type ${term.termType} and is not a numeric literal`);\n }\n return <Eval.NumericLiteral> this.termTransformer.transformLiteral(term);\n }\n}\n"]}
1
+ {"version":3,"file":"AggregateEvaluator.js","sourceRoot":"","sources":["AggregateEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAAoE;AAEpE,2EAA6D;AAE7D,sDAAwC;AAExC;;;;;;;;GAQG;AACH,MAAsB,kBAAkB;IASjB;IACA;IACF;IAVX,aAAa,GAAG,KAAK,CAAC;IAEX,cAAc,CAAc;IAE5B,iBAAiB,CAAqB;IACtC,eAAe,CAAuB;IAEzD,YACqB,SAA+B,EAC/B,QAAiB,EACnB,aAAa,KAAK;QAFhB,cAAS,GAAT,SAAS,CAAsB;QAC/B,aAAQ,GAAR,QAAQ,CAAS;QACnB,eAAU,GAAV,UAAU,CAAQ;QAEnC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,yCAAuB,CAAC,iBAAiB,CAAC,CAAC;QAC9F,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAExE,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,CAAC;IAKM,cAAc;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,UAAU;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAClC,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC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EAAE,CAAC;YACpB,MAAM,GAAG,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAES,oBAAoB,CAAC,IAAc;QAC3C,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QAC1G,CAAC;aAAM,IACL,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAChG,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,QAAQ,CAAC,KAAK,eAAe,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QAC1I,CAAC;QACD,OAA6B,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF;AAlGD,gDAkGC","sourcesContent":["import { KeysExpressionEvaluator } from '@comunica/context-entries';\nimport type { IExpressionEvaluator, ISuperTypeProvider } from '@comunica/types';\nimport * as Eval from '@comunica/utils-expression-evaluator';\nimport type * as RDF from '@rdfjs/types';\nimport * as RdfString from 'rdf-string';\n\n/**\n * This is the base class for all aggregators.\n * NOTE: The wildcard count aggregator significantly differs from the others and overloads parts of this class.\n * TODO(next major): In the extension aggregator (NamedAggregator) we basically have a copy of this AggregateEvaluator,\n * but that one supports a list of arguments. Instead, we should generalize this class to a list of arguments,\n * possibly empty, and to asynchronous putTerm and termResult.\n * That way, the aggregator of extension aggregates (NamedAggregator) extend this abstract class instead of\n * near-copying implementation.\n */\nexport abstract class AggregateEvaluator {\n private errorOccurred = false;\n\n protected readonly variableValues: Set<string>;\n\n protected readonly superTypeProvider: ISuperTypeProvider;\n protected readonly termTransformer: Eval.TermTransformer;\n\n protected constructor(\n protected readonly evaluator: IExpressionEvaluator,\n protected readonly distinct: boolean,\n private readonly throwError = false,\n ) {\n this.errorOccurred = false;\n this.superTypeProvider = evaluator.context.getSafe(KeysExpressionEvaluator.superTypeProvider);\n this.termTransformer = new Eval.TermTransformer(this.superTypeProvider);\n\n this.variableValues = new Set();\n }\n\n protected abstract putTerm(term: RDF.Term): void;\n protected abstract termResult(): RDF.Term | undefined;\n\n public emptyValueTerm(): RDF.Term | undefined {\n return undefined;\n }\n\n /**\n * The spec says to throw an error when a set function is called on an empty\n * set (unless explicitly mentioned otherwise like COUNT).\n * However, aggregate error handling says to not bind the result in case of an\n * error. So to simplify logic in the caller, we return undefined by default.\n */\n public emptyValue(): RDF.Term | undefined {\n const val = this.emptyValueTerm();\n if (val === undefined && this.throwError) {\n throw new Eval.EmptyAggregateError();\n }\n return val;\n }\n\n /**\n * Base implementation of putBindings, that evaluates to a term and then calls putTerm.\n * The WildcardCountAggregator will completely discard this implementation.\n * @param bindings\n */\n public async putBindings(bindings: RDF.Bindings): Promise<void> {\n if (this.errorOccurred) {\n return;\n }\n try {\n const term = await this.evaluator.evaluate(bindings);\n if (!term || this.errorOccurred) {\n return;\n }\n\n // Handle DISTINCT before putting the term\n if (!this.distinct || !this.variableValues.has(RdfString.termToString(term))) {\n this.putTerm(term);\n if (this.distinct) {\n this.variableValues.add(RdfString.termToString(term));\n }\n }\n } catch (error: unknown) {\n // Per SPARQL spec, aggregate functions ignore unbound variables.\n // An UnboundVariableError simply means this binding has no value for the aggregate variable,\n // so we skip it rather than treating it as an error (which would cause the entire aggregate to fail).\n if (error instanceof Eval.UnboundVariableError) {\n return;\n }\n this.safeThrow(error);\n }\n }\n\n public async result(): Promise<RDF.Term | undefined> {\n if (this.errorOccurred) {\n return undefined;\n }\n return this.termResult();\n }\n\n private safeThrow(err: unknown): void {\n if (this.throwError) {\n throw err;\n } else {\n this.errorOccurred = true;\n }\n }\n\n protected termToNumericOrError(term: RDF.Term): Eval.NumericLiteral {\n if (term.termType !== 'Literal') {\n throw new Error(`Term with value ${term.value} has type ${term.termType} and is not a numeric literal`);\n } else if (\n !Eval.isSubTypeOf(term.datatype.value, Eval.TypeAlias.SPARQL_NUMERIC, this.superTypeProvider)) {\n throw new Error(`Term datatype ${term.datatype.value} with value ${term.value} has type ${term.termType} and is not a numeric literal`);\n }\n return <Eval.NumericLiteral> this.termTransformer.transformLiteral(term);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/bus-bindings-aggregator-factory",
3
- "version": "5.3.0",
3
+ "version": "5.5.0",
4
4
  "description": "A comunica actor for creating Binding-Aggregators.",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -36,14 +36,14 @@
36
36
  "build:components": "componentsjs-generator"
37
37
  },
38
38
  "dependencies": {
39
- "@comunica/bus-expression-evaluator-factory": "^5.3.0",
40
- "@comunica/context-entries": "^5.3.0",
41
- "@comunica/core": "^5.3.0",
42
- "@comunica/types": "^5.3.0",
43
- "@comunica/utils-algebra": "^5.3.0",
44
- "@comunica/utils-expression-evaluator": "^5.3.0",
39
+ "@comunica/bus-expression-evaluator-factory": "^5.5.0",
40
+ "@comunica/context-entries": "^5.5.0",
41
+ "@comunica/core": "^5.5.0",
42
+ "@comunica/types": "^5.5.0",
43
+ "@comunica/utils-algebra": "^5.5.0",
44
+ "@comunica/utils-expression-evaluator": "^5.5.0",
45
45
  "@rdfjs/types": "*",
46
46
  "rdf-string": "^2.0.1"
47
47
  },
48
- "gitHead": "8a9d8e4a706d64268e1e222b4c561caa47798f72"
48
+ "gitHead": "3a258e018a9c5f0b03f531b30ee1cdc659b5b7c9"
49
49
  }