@comunica/actor-query-operation-path-one-or-more 5.4.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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2017–now Ruben Taelman, Joachim Van Herwegen
4
+ Comunica Association and Ghent University – imec, Belgium
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -37,6 +37,26 @@ class ActorQueryOperationPathOneOrMore extends actor_abstract_path_1.ActorAbstra
37
37
  metadata: async () => ({ ...await starEval.metadata(), variables }),
38
38
  };
39
39
  }
40
+ if (operation.subject.termType === 'Variable' && operation.subject.equals(operation.object)) {
41
+ const subjectVar = operation.subject;
42
+ const objectVar = this.generateVariable(dataFactory, operation);
43
+ const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({
44
+ context,
45
+ operation: algebraFactory.createPath(subjectVar, predicate, objectVar, operation.graph),
46
+ }));
47
+ const bindingsStream = results.bindingsStream.map(bindings => bindings.get(subjectVar).equals(bindings.get(objectVar)) ? bindings.delete(objectVar) : null);
48
+ return {
49
+ type: 'bindings',
50
+ bindingsStream,
51
+ metadata: async () => {
52
+ const metadata = await results.metadata();
53
+ return {
54
+ ...metadata,
55
+ variables: metadata.variables.filter(({ variable }) => !variable.equals(objectVar)),
56
+ };
57
+ },
58
+ };
59
+ }
40
60
  if (operation.subject.termType === 'Variable' && operation.object.termType === 'Variable') {
41
61
  // Get all the results of subjects with same predicate, but once, then fill in first variable for those
42
62
  const single = algebraFactory.createDistinct(algebraFactory.createPath(operation.subject, predicate.path, operation.object, operation.graph));
@@ -44,6 +64,9 @@ class ActorQueryOperationPathOneOrMore extends actor_abstract_path_1.ActorAbstra
44
64
  const subjectVar = operation.subject;
45
65
  const objectVar = operation.object;
46
66
  const termHashes = {};
67
+ // The path is walked by evaluating one sub-path per reached term,
68
+ // so group those evaluations in the physical query plan
69
+ const alpContext = (0, utils_query_operation_1.groupRepeatedSubOperations)(context, 'alp', this.name);
47
70
  const bindingsStream = new asynciterator_1.MultiTransformIterator(results.bindingsStream, {
48
71
  multiTransform: (bindings) => {
49
72
  const subject = bindings.get(subjectVar);
@@ -51,7 +74,7 @@ class ActorQueryOperationPathOneOrMore extends actor_abstract_path_1.ActorAbstra
51
74
  const graph = operation.graph.termType === 'Variable' ? bindings.get(operation.graph) : operation.graph;
52
75
  return new asynciterator_1.TransformIterator(async () => {
53
76
  const it = new asynciterator_1.BufferedIterator();
54
- await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subject, object, predicate.path, graph, context, termHashes, {}, it, { count: 0 }, algebraFactory, bindingsFactory);
77
+ await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subject, object, predicate.path, graph, alpContext, termHashes, {}, it, { count: 0 }, algebraFactory, bindingsFactory);
55
78
  return it.map((item) => {
56
79
  if (operation.graph.termType === 'Variable') {
57
80
  item = item.set(operation.graph, graph);
@@ -1 +1 @@
1
- {"version":3,"file":"ActorQueryOperationPathOneOrMore.js","sourceRoot":"","sources":["ActorQueryOperationPathOneOrMore.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAGlE,+DAA0D;AAQ1D,2DAAkE;AAClE,6EAAmE;AACnE,2EAAkE;AAClE,iDAA4F;AAE5F;;GAEG;AACH,MAAa,gCAAiC,SAAQ,uCAAiB;IACrD,4BAA4B,CAA+B;IAE3E,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,uBAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;IACxE,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,SAAuB,EAAE,OAAuB;QACxE,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,cAAc,GAAG,IAAI,8BAAc,CAAC,WAAW,CAAC,CAAC;QACvD,MAAM,eAAe,GAAG,MAAM,wCAAe,CAAC,MAAM,CAClD,IAAI,CAAC,4BAA4B,EACjC,OAAO,EACP,WAAW,CACZ,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,6BAA6B,CAAC,cAAc,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAC9F,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YACvB,OAAO,QAAQ,CAAC,SAAS,CAAC;QAC5B,CAAC;QAED,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QAE3B,MAAM,SAAS,GAA2B,SAAS,CAAC,SAAS,CAAC;QAE9D,IAAI,SAAS,CAAC,OAAO,CAAC,QAAQ,KAAK,UAAU,IAAI,SAAS,CAAC,MAAM,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YAC1F,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM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AC,CAAC,CAAC;QACJ,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAAW,CAAC,IAAI,EAAE,EAAE;YACnE,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;gBAChD,OAAO,SAAS,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC;oBAC9C,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAE,CAAE,CAAC,CAAC,CAAC,CAAC;oBAC7E,eAAe,CAAC,QAAQ,EAAE,CAAC;YAC/B,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QACH,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,cAAc;YACd,QAAQ,EAAE,KAAK,IAAG,EAAE,CAAC,CAAC;gBACpB,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE;gBAC3B,SAAS,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,CAAE,SAAS,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC5E,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;aACtD,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AA9ID,4EA8IC","sourcesContent":["import { ActorAbstractPath } from '@comunica/actor-abstract-path';\nimport type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';\nimport type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type {\n IQueryOperationResultBindings,\n Bindings,\n IQueryOperationResult,\n IActionContext,\n ComunicaDataFactory,\n} from '@comunica/types';\nimport { Algebra, AlgebraFactory } from '@comunica/utils-algebra';\nimport { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { getSafeBindings } from '@comunica/utils-query-operation';\nimport { BufferedIterator, MultiTransformIterator, TransformIterator } from 'asynciterator';\n\n/**\n * A comunica Path OneOrMore Query Operation Actor.\n */\nexport class ActorQueryOperationPathOneOrMore extends ActorAbstractPath {\n public readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n\n public constructor(args: IActorQueryOperationPathOneOrMoreArgs) {\n super(args, Algebra.Types.ONE_OR_MORE_PATH);\n this.mediatorMergeBindingsContext = args.mediatorMergeBindingsContext;\n }\n\n public async runOperation(operation: Algebra.Path, context: IActionContext): Promise<IQueryOperationResult> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n const bindingsFactory = await BindingsFactory.create(\n this.mediatorMergeBindingsContext,\n context,\n dataFactory,\n );\n\n const distinct = await this.isPathArbitraryLengthDistinct(algebraFactory, context, operation);\n if (distinct.operation) {\n return distinct.operation;\n }\n\n context = distinct.context;\n\n const predicate = <Algebra.OneOrMorePath> operation.predicate;\n\n if (operation.subject.termType !== 'Variable' && operation.object.termType === 'Variable') {\n const objectVar = operation.object;\n const starEval = await this.getObjectsPredicateStarEval(\n operation.subject,\n predicate.path,\n objectVar,\n operation.graph,\n context,\n false,\n algebraFactory,\n bindingsFactory,\n );\n const variables = (operation.graph.termType === 'Variable' ? [ objectVar, operation.graph ] : [ objectVar ])\n .map(variable => ({ variable, canBeUndef: false }));\n return {\n type: 'bindings',\n bindingsStream: starEval.bindingsStream,\n metadata: async() => ({ ...await starEval.metadata(), variables }),\n };\n }\n if (operation.subject.termType === 'Variable' && operation.object.termType === 'Variable') {\n // Get all the results of subjects with same predicate, but once, then fill in first variable for those\n const single = algebraFactory.createDistinct(\n algebraFactory.createPath(operation.subject, predicate.path, operation.object, operation.graph),\n );\n const results = getSafeBindings(\n await this.mediatorQueryOperation.mediate({ context, operation: single }),\n );\n const subjectVar = operation.subject;\n const objectVar = operation.object;\n\n const termHashes = {};\n\n const bindingsStream: MultiTransformIterator<Bindings, Bindings> = new MultiTransformIterator(\n results.bindingsStream,\n {\n multiTransform: (bindings: Bindings) => {\n const subject = bindings.get(subjectVar);\n const object = bindings.get(objectVar);\n const graph = operation.graph.termType === 'Variable' ? bindings.get(operation.graph) : operation.graph;\n return new TransformIterator<Bindings>(\n async() => {\n const it = new BufferedIterator<Bindings>();\n await this.getSubjectAndObjectBindingsPredicateStar(\n subjectVar,\n objectVar,\n subject!,\n object!,\n predicate.path,\n graph!,\n context,\n termHashes,\n {},\n it,\n { count: 0 },\n algebraFactory,\n bindingsFactory,\n );\n return it.map<Bindings>((item) => {\n if (operation.graph.termType === 'Variable') {\n item = item.set(operation.graph, graph!);\n }\n return item;\n });\n },\n { autoStart: false, maxBufferSize: 128 },\n );\n },\n autoStart: false,\n },\n );\n const variables = (operation.graph.termType === 'Variable' ?\n [ subjectVar, objectVar, operation.graph ] :\n [ subjectVar, objectVar ])\n .map(variable => ({ variable, canBeUndef: false }));\n return {\n type: 'bindings',\n bindingsStream,\n metadata: async() => ({ ...await results.metadata(), variables }),\n };\n }\n if (operation.subject.termType === 'Variable' && operation.object.termType !== 'Variable') {\n return <Promise<IQueryOperationResultBindings>> this.mediatorQueryOperation.mediate({\n context,\n operation: algebraFactory.createPath(\n operation.object,\n algebraFactory.createOneOrMorePath(algebraFactory.createInv(predicate.path)),\n operation.subject,\n operation.graph,\n ),\n });\n }\n // If (!sVar && !oVar)\n const variable = this.generateVariable(dataFactory);\n const results = getSafeBindings(await this.mediatorQueryOperation.mediate({\n context,\n operation: algebraFactory.createPath(operation.subject, predicate, variable, operation.graph),\n }));\n const bindingsStream = results.bindingsStream.map<Bindings>((item) => {\n if (operation.object.equals(item.get(variable))) {\n return operation.graph.termType === 'Variable' ?\n bindingsFactory.bindings([[ operation.graph, item.get(operation.graph)! ]]) :\n bindingsFactory.bindings();\n }\n return null;\n });\n return {\n type: 'bindings',\n bindingsStream,\n metadata: async() => ({\n ...await results.metadata(),\n variables: (operation.graph.termType === 'Variable' ? [ operation.graph ] : [])\n .map(variable => ({ variable, canBeUndef: false })),\n }),\n };\n }\n}\n\nexport interface IActorQueryOperationPathOneOrMoreArgs extends IActorQueryOperationTypedMediatedArgs {\n /**\n * A mediator for creating binding context merge handlers\n */\n mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n}\n"]}
1
+ {"version":3,"file":"ActorQueryOperationPathOneOrMore.js","sourceRoot":"","sources":["ActorQueryOperationPathOneOrMore.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAGlE,+DAA0D;AAQ1D,2DAAkE;AAClE,6EAAmE;AACnE,2EAA8F;AAC9F,iDAA4F;AAE5F;;GAEG;AACH,MAAa,gCAAiC,SAAQ,uCAAiB;IACrD,4BAA4B,CAA+B;IAE3E,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,uBAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;IACxE,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,SAAuB,EAAE,OAAuB;QACxE,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,cAAc,GAAG,IAAI,8BAAc,CAAC,WAAW,CAAC,CAAC;QACvD,MAAM,eAAe,GAAG,MAAM,wCAAe,CAAC,MAAM,CAClD,IAAI,CAAC,4BAA4B,EACjC,OAAO,EACP,WAAW,CACZ,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,6BAA6B,CAAC,cAAc,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAC9F,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YACvB,OAAO,QAAQ,CAAC,SAAS,CAAC;QAC5B,CAAC;QAED,OA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C;CACF;AAtKD,4EAsKC","sourcesContent":["import { ActorAbstractPath } from '@comunica/actor-abstract-path';\nimport type { MediatorMergeBindingsContext } from '@comunica/bus-merge-bindings-context';\nimport type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type {\n IQueryOperationResultBindings,\n Bindings,\n IQueryOperationResult,\n IActionContext,\n ComunicaDataFactory,\n} from '@comunica/types';\nimport { Algebra, AlgebraFactory } from '@comunica/utils-algebra';\nimport { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { getSafeBindings, groupRepeatedSubOperations } from '@comunica/utils-query-operation';\nimport { BufferedIterator, MultiTransformIterator, TransformIterator } from 'asynciterator';\n\n/**\n * A comunica Path OneOrMore Query Operation Actor.\n */\nexport class ActorQueryOperationPathOneOrMore extends ActorAbstractPath {\n public readonly mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n\n public constructor(args: IActorQueryOperationPathOneOrMoreArgs) {\n super(args, Algebra.Types.ONE_OR_MORE_PATH);\n this.mediatorMergeBindingsContext = args.mediatorMergeBindingsContext;\n }\n\n public async runOperation(operation: Algebra.Path, context: IActionContext): Promise<IQueryOperationResult> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new AlgebraFactory(dataFactory);\n const bindingsFactory = await BindingsFactory.create(\n this.mediatorMergeBindingsContext,\n context,\n dataFactory,\n );\n\n const distinct = await this.isPathArbitraryLengthDistinct(algebraFactory, context, operation);\n if (distinct.operation) {\n return distinct.operation;\n }\n\n context = distinct.context;\n\n const predicate = <Algebra.OneOrMorePath> operation.predicate;\n\n if (operation.subject.termType !== 'Variable' && operation.object.termType === 'Variable') {\n const objectVar = operation.object;\n const starEval = await this.getObjectsPredicateStarEval(\n operation.subject,\n predicate.path,\n objectVar,\n operation.graph,\n context,\n false,\n algebraFactory,\n bindingsFactory,\n );\n const variables = (operation.graph.termType === 'Variable' ? [ objectVar, operation.graph ] : [ objectVar ])\n .map(variable => ({ variable, canBeUndef: false }));\n return {\n type: 'bindings',\n bindingsStream: starEval.bindingsStream,\n metadata: async() => ({ ...await starEval.metadata(), variables }),\n };\n }\n if (operation.subject.termType === 'Variable' && operation.subject.equals(operation.object)) {\n const subjectVar = operation.subject;\n const objectVar = this.generateVariable(dataFactory, operation);\n const results = getSafeBindings(await this.mediatorQueryOperation.mediate({\n context,\n operation: algebraFactory.createPath(subjectVar, predicate, objectVar, operation.graph),\n }));\n const bindingsStream = results.bindingsStream.map<Bindings>(bindings =>\n bindings.get(subjectVar)!.equals(bindings.get(objectVar)) ? bindings.delete(objectVar) : null);\n return {\n type: 'bindings',\n bindingsStream,\n metadata: async() => {\n const metadata = await results.metadata();\n return {\n ...metadata,\n variables: metadata.variables.filter(({ variable }) => !variable.equals(objectVar)),\n };\n },\n };\n }\n if (operation.subject.termType === 'Variable' && operation.object.termType === 'Variable') {\n // Get all the results of subjects with same predicate, but once, then fill in first variable for those\n const single = algebraFactory.createDistinct(\n algebraFactory.createPath(operation.subject, predicate.path, operation.object, operation.graph),\n );\n const results = getSafeBindings(\n await this.mediatorQueryOperation.mediate({ context, operation: single }),\n );\n const subjectVar = operation.subject;\n const objectVar = operation.object;\n\n const termHashes = {};\n // The path is walked by evaluating one sub-path per reached term,\n // so group those evaluations in the physical query plan\n const alpContext = groupRepeatedSubOperations(context, 'alp', this.name);\n\n const bindingsStream: MultiTransformIterator<Bindings, Bindings> = new MultiTransformIterator(\n results.bindingsStream,\n {\n multiTransform: (bindings: Bindings) => {\n const subject = bindings.get(subjectVar);\n const object = bindings.get(objectVar);\n const graph = operation.graph.termType === 'Variable' ? bindings.get(operation.graph) : operation.graph;\n return new TransformIterator<Bindings>(\n async() => {\n const it = new BufferedIterator<Bindings>();\n await this.getSubjectAndObjectBindingsPredicateStar(\n subjectVar,\n objectVar,\n subject!,\n object!,\n predicate.path,\n graph!,\n alpContext,\n termHashes,\n {},\n it,\n { count: 0 },\n algebraFactory,\n bindingsFactory,\n );\n return it.map<Bindings>((item) => {\n if (operation.graph.termType === 'Variable') {\n item = item.set(operation.graph, graph!);\n }\n return item;\n });\n },\n { autoStart: false, maxBufferSize: 128 },\n );\n },\n autoStart: false,\n },\n );\n const variables = (operation.graph.termType === 'Variable' ?\n [ subjectVar, objectVar, operation.graph ] :\n [ subjectVar, objectVar ])\n .map(variable => ({ variable, canBeUndef: false }));\n return {\n type: 'bindings',\n bindingsStream,\n metadata: async() => ({ ...await results.metadata(), variables }),\n };\n }\n if (operation.subject.termType === 'Variable' && operation.object.termType !== 'Variable') {\n return <Promise<IQueryOperationResultBindings>> this.mediatorQueryOperation.mediate({\n context,\n operation: algebraFactory.createPath(\n operation.object,\n algebraFactory.createOneOrMorePath(algebraFactory.createInv(predicate.path)),\n operation.subject,\n operation.graph,\n ),\n });\n }\n // If (!sVar && !oVar)\n const variable = this.generateVariable(dataFactory);\n const results = getSafeBindings(await this.mediatorQueryOperation.mediate({\n context,\n operation: algebraFactory.createPath(operation.subject, predicate, variable, operation.graph),\n }));\n const bindingsStream = results.bindingsStream.map<Bindings>((item) => {\n if (operation.object.equals(item.get(variable))) {\n return operation.graph.termType === 'Variable' ?\n bindingsFactory.bindings([[ operation.graph, item.get(operation.graph)! ]]) :\n bindingsFactory.bindings();\n }\n return null;\n });\n return {\n type: 'bindings',\n bindingsStream,\n metadata: async() => ({\n ...await results.metadata(),\n variables: (operation.graph.termType === 'Variable' ? [ operation.graph ] : [])\n .map(variable => ({ variable, canBeUndef: false })),\n }),\n };\n }\n}\n\nexport interface IActorQueryOperationPathOneOrMoreArgs extends IActorQueryOperationTypedMediatedArgs {\n /**\n * A mediator for creating binding context merge handlers\n */\n mediatorMergeBindingsContext: MediatorMergeBindingsContext;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-query-operation-path-one-or-more",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "description": "A path-one-or-more query-operation actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -41,15 +41,15 @@
41
41
  "build:components": "componentsjs-generator"
42
42
  },
43
43
  "dependencies": {
44
- "@comunica/actor-abstract-path": "^5.4.0",
45
- "@comunica/bus-merge-bindings-context": "^5.4.0",
46
- "@comunica/bus-query-operation": "^5.4.0",
47
- "@comunica/context-entries": "^5.4.0",
48
- "@comunica/types": "^5.4.0",
49
- "@comunica/utils-algebra": "^5.4.0",
50
- "@comunica/utils-bindings-factory": "^5.4.0",
51
- "@comunica/utils-query-operation": "^5.4.0",
44
+ "@comunica/actor-abstract-path": "^5.5.0",
45
+ "@comunica/bus-merge-bindings-context": "^5.5.0",
46
+ "@comunica/bus-query-operation": "^5.5.0",
47
+ "@comunica/context-entries": "^5.5.0",
48
+ "@comunica/types": "^5.5.0",
49
+ "@comunica/utils-algebra": "^5.5.0",
50
+ "@comunica/utils-bindings-factory": "^5.5.0",
51
+ "@comunica/utils-query-operation": "^5.5.0",
52
52
  "asynciterator": "^3.10.0"
53
53
  },
54
- "gitHead": "8a0a10913cb705adda45997210ebbe5502274a60"
54
+ "gitHead": "3a258e018a9c5f0b03f531b30ee1cdc659b5b7c9"
55
55
  }