@comunica/actor-optimize-query-operation-group-sources 3.0.1-alpha.45.0 → 3.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/README.md CHANGED
@@ -23,7 +23,7 @@ After installing, this package can be added to your engine's configuration as fo
23
23
  {
24
24
  "@context": [
25
25
  ...
26
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-group-sources/^1.0.0/components/context.jsonld"
26
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-group-sources/^1.0.0/components/context.jsonld"
27
27
  ],
28
28
  "actors": [
29
29
  ...
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "@context": [
3
- "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^6.0.0/components/context.jsonld",
4
4
  {
5
5
  "npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
6
6
  "caoqogs": "npmd:@comunica/actor-optimize-query-operation-group-sources/^3.0.0/",
@@ -30,7 +30,7 @@ class ActorOptimizeQueryOperationGroupSources extends bus_optimize_query_operati
30
30
  */
31
31
  async groupOperation(operation, context) {
32
32
  // Return operation as-is if the operation already has a single source, or if the operation has no children.
33
- if (bus_query_operation_1.ActorQueryOperation.getOperationSource(operation) || !('input' in operation)) {
33
+ if (bus_query_operation_1.ActorQueryOperation.getOperationSource(operation) ?? !('input' in operation)) {
34
34
  return operation;
35
35
  }
36
36
  // If operation has a single input, move source annotation upwards if the source can handle it.
@@ -1 +1 @@
1
- {"version":3,"file":"ActorOptimizeQueryOperationGroupSources.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationGroupSources.ts"],"names":[],"mappings":";;;AAEA,yFAAqF;AACrF,uEAAoE;AAGpE,qDAAmD;AAEnD,MAAM,EAAE,GAAG,IAAI,yBAAO,EAAE,CAAC;AAEzB;;GAEG;AACH,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,qCAAqC,CAChD,SAAY,EACZ,MAA2B,EAC3B,MAAuC,EACvC,OAAuB;QAEvB,IAAI,MAAM,IAAI,yCAAmB;aAC9B,wBAAwB,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,EAAE;YACrF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,CAAC,MAAM,6CAA6C,SAAS,CAAC,IAAI,kBAAkB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtJ,SAAS,GAAG,yCAAmB,CAAC,qBAAqB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACzE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;gBAC1B,yCAAmB,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;aAClD;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAxKD,0FAwKC","sourcesContent":["import type { IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationOutput, IActorOptimizeQueryOperationArgs } from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport { ActorQueryOperation } from '@comunica/bus-query-operation';\nimport type { IActorTest } from '@comunica/core';\nimport type { IActionContext, IQuerySourceWrapper } from '@comunica/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\nconst AF = new Factory();\n\n/**\n * A comunica Group Sources Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationGroupSources extends ActorOptimizeQueryOperation {\n public constructor(args: IActorOptimizeQueryOperationArgs) {\n super(args);\n }\n\n public async test(action: IActionOptimizeQueryOperation): Promise<IActorTest> {\n if (ActorQueryOperation.getOperationSource(action.operation)) {\n throw new Error(`Actor ${this.name} does not work with top-level operation sources.`);\n }\n return true;\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n return { operation: await this.groupOperation(action.operation, action.context), context: action.context };\n }\n\n /**\n * Group operations belonging to the same source together, only if that source accepts the grouped operations.\n * This grouping will be done recursively for the whole operation tree.\n * Operations annotated with sources are considered leaves in the tree.\n * @param operation An operation to group.\n * @param context The action context.\n */\n public async groupOperation(operation: Algebra.Operation, context: IActionContext): Promise<Algebra.Operation> {\n // Return operation as-is if the operation already has a single source, or if the operation has no children.\n if (ActorQueryOperation.getOperationSource(operation) || !('input' in operation)) {\n return operation;\n }\n\n // If operation has a single input, move source annotation upwards if the source can handle it.\n if (!Array.isArray(operation.input)) {\n const groupedInput = await this.groupOperation(operation.input, context);\n if (groupedInput.metadata?.scopedSource) {\n const source: IQuerySourceWrapper = ActorQueryOperation.getOperationSource(groupedInput)!;\n if (ActorQueryOperation\n .doesShapeAcceptOperation(await source.source.getSelectorShape(context), operation)) {\n this.logDebug(context, `Hoist 1 source-specific operation into a single ${operation.type} operation for ${source.source.toString()}`);\n ActorQueryOperation.removeOperationSource(groupedInput);\n operation = ActorQueryOperation.assignOperationSource(operation, source);\n }\n }\n return <Algebra.Operation> { ...operation, input: groupedInput };\n }\n\n // If operation has multiple inputs, cluster source annotations.\n const inputs: Algebra.Operation[] = await Promise.all(operation.input\n .map(subInput => this.groupOperation(subInput, context)));\n const clusters = this.clusterOperationsWithEqualSources(inputs);\n\n // If we just have a single cluster, move the source annotation upwards\n if (clusters.length === 1) {\n const newInputs = clusters[0];\n const source = ActorQueryOperation.getOperationSource(clusters[0][0])!;\n return <Algebra.Operation> {\n ...await this.moveSourceAnnotationUpwardsIfPossible(operation, newInputs, source, context),\n input: newInputs,\n };\n }\n\n // If the number of clusters is equal to the number of original inputs, do nothing.\n if (clusters.length === inputs.length) {\n return <Algebra.Operation> { ...operation, input: inputs };\n }\n\n // If we have multiple clusters, created nested multi-operations\n let multiFactoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation;\n switch (operation.type) {\n case Algebra.types.JOIN:\n multiFactoryMethod = AF.createJoin.bind(AF);\n break;\n case Algebra.types.UNION:\n multiFactoryMethod = AF.createUnion.bind(AF);\n break;\n case Algebra.types.ALT:\n multiFactoryMethod = AF.createAlt.bind(AF);\n break;\n case Algebra.types.SEQ:\n multiFactoryMethod = AF.createSeq.bind(AF);\n break;\n default:\n // While LeftJoin and Minus are also multi-operations,\n // these can never occur because they only have 2 inputs,\n // so these cases will always be captured by one of the 2 if-cases above\n // (clusters.length === 1 or clusters.length === input.length)\n\n // In all other cases, error\n throw new Error(`Unsupported operation '${operation.type}' detected while grouping sources`);\n }\n return await this.groupOperationMulti(clusters, multiFactoryMethod, context);\n }\n\n protected async groupOperationMulti(\n clusters: Algebra.Operation[][],\n factoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation,\n context: IActionContext,\n ): Promise<Algebra.Operation> {\n let flatten = true;\n const nestedMerges = await Promise.all(clusters.map(async cluster => {\n const source = ActorQueryOperation.getOperationSource(cluster[0])!;\n const merged = await this\n .moveSourceAnnotationUpwardsIfPossible(factoryMethod(cluster, true), cluster, source, context);\n if (ActorQueryOperation.getOperationSource(merged)) {\n flatten = false;\n }\n return merged;\n }));\n return factoryMethod(nestedMerges, flatten);\n }\n\n /**\n * Cluster the given operations by equal source annotations.\n * @param operationsIn An array of operations to cluster.\n */\n public clusterOperationsWithEqualSources(operationsIn: Algebra.Operation[]): Algebra.Operation[][] {\n // Operations can have a source, or no source at all\n const sourceOperations: Map<IQuerySourceWrapper, Algebra.Operation[]> = new Map();\n const sourcelessOperations: Algebra.Operation[] = [];\n\n // Cluster by source\n for (const operation of operationsIn) {\n const source: IQuerySourceWrapper = ActorQueryOperation.getOperationSource(operation)!;\n if (source) {\n if (!sourceOperations.has(source)) {\n sourceOperations.set(source, []);\n }\n sourceOperations.get(source)!.push(operation);\n } else {\n sourcelessOperations.push(operation);\n }\n }\n\n // Return clusters\n const clusters: Algebra.Operation[][] = [];\n if (sourcelessOperations.length > 0) {\n clusters.push(sourcelessOperations);\n }\n for (const [ source, operations ] of sourceOperations.entries()) {\n clusters.push(operations\n .map(operation => ActorQueryOperation.assignOperationSource(operation, source)));\n }\n return clusters;\n }\n\n /**\n * If the given source accepts the grouped operation, annotate the grouped operation with the source,\n * and remove the source annotation from the seperate input operations.\n * Otherwise, return the grouped operation unchanged.\n * @param operation A grouped operation consisting of all given input operations.\n * @param inputs An array of operations that share the same source annotation.\n * @param source The common source.\n * @param context The action context.\n */\n public async moveSourceAnnotationUpwardsIfPossible<O extends Algebra.Operation>(\n operation: O,\n inputs: Algebra.Operation[],\n source: IQuerySourceWrapper | undefined,\n context: IActionContext,\n ): Promise<O> {\n if (source && ActorQueryOperation\n .doesShapeAcceptOperation(await source.source.getSelectorShape(context), operation)) {\n this.logDebug(context, `Hoist ${inputs.length} source-specific operations into a single ${operation.type} operation for ${source.source.toString()}`);\n operation = ActorQueryOperation.assignOperationSource(operation, source);\n for (const input of inputs) {\n ActorQueryOperation.removeOperationSource(input);\n }\n }\n return operation;\n }\n}\n"]}
1
+ {"version":3,"file":"ActorOptimizeQueryOperationGroupSources.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationGroupSources.ts"],"names":[],"mappings":";;;AAKA,yFAAqF;AACrF,uEAAoE;AAGpE,qDAAmD;AAEnD,MAAM,EAAE,GAAG,IAAI,yBAAO,EAAE,CAAC;AAEzB;;GAEG;AACH,MAAa,uCAAwC,SAAQ,0DAA2B;IACtF,YAAmB,IAAsC;QACvD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAAqC;QACrD,IAAI,yCAAmB,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,kDAAkD,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,MAAqC;QACpD,OAAO,EAAE,SAAS,EAAE,MAAM,IA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AAC,OAAO,EAAE,SAAS,MAAM,CAAC,MAAM,6CAA6C,SAAS,CAAC,IAAI,kBAAkB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtJ,SAAS,GAAG,yCAAmB,CAAC,qBAAqB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACzE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,yCAAmB,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAxKD,0FAwKC","sourcesContent":["import type {\n IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationOutput,\n IActorOptimizeQueryOperationArgs,\n} from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport { ActorQueryOperation } from '@comunica/bus-query-operation';\nimport type { IActorTest } from '@comunica/core';\nimport type { IActionContext, IQuerySourceWrapper } from '@comunica/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\nconst AF = new Factory();\n\n/**\n * A comunica Group Sources Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationGroupSources extends ActorOptimizeQueryOperation {\n public constructor(args: IActorOptimizeQueryOperationArgs) {\n super(args);\n }\n\n public async test(action: IActionOptimizeQueryOperation): Promise<IActorTest> {\n if (ActorQueryOperation.getOperationSource(action.operation)) {\n throw new Error(`Actor ${this.name} does not work with top-level operation sources.`);\n }\n return true;\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n return { operation: await this.groupOperation(action.operation, action.context), context: action.context };\n }\n\n /**\n * Group operations belonging to the same source together, only if that source accepts the grouped operations.\n * This grouping will be done recursively for the whole operation tree.\n * Operations annotated with sources are considered leaves in the tree.\n * @param operation An operation to group.\n * @param context The action context.\n */\n public async groupOperation(operation: Algebra.Operation, context: IActionContext): Promise<Algebra.Operation> {\n // Return operation as-is if the operation already has a single source, or if the operation has no children.\n if (ActorQueryOperation.getOperationSource(operation) ?? !('input' in operation)) {\n return operation;\n }\n\n // If operation has a single input, move source annotation upwards if the source can handle it.\n if (!Array.isArray(operation.input)) {\n const groupedInput = await this.groupOperation(operation.input, context);\n if (groupedInput.metadata?.scopedSource) {\n const source: IQuerySourceWrapper = ActorQueryOperation.getOperationSource(groupedInput)!;\n if (ActorQueryOperation\n .doesShapeAcceptOperation(await source.source.getSelectorShape(context), operation)) {\n this.logDebug(context, `Hoist 1 source-specific operation into a single ${operation.type} operation for ${source.source.toString()}`);\n ActorQueryOperation.removeOperationSource(groupedInput);\n operation = ActorQueryOperation.assignOperationSource(operation, source);\n }\n }\n return <Algebra.Operation> { ...operation, input: groupedInput };\n }\n\n // If operation has multiple inputs, cluster source annotations.\n const inputs: Algebra.Operation[] = await Promise.all(operation.input\n .map(subInput => this.groupOperation(subInput, context)));\n const clusters = this.clusterOperationsWithEqualSources(inputs);\n\n // If we just have a single cluster, move the source annotation upwards\n if (clusters.length === 1) {\n const newInputs = clusters[0];\n const source = ActorQueryOperation.getOperationSource(clusters[0][0])!;\n return <Algebra.Operation> {\n ...await this.moveSourceAnnotationUpwardsIfPossible(operation, newInputs, source, context),\n input: newInputs,\n };\n }\n\n // If the number of clusters is equal to the number of original inputs, do nothing.\n if (clusters.length === inputs.length) {\n return <Algebra.Operation> { ...operation, input: inputs };\n }\n\n // If we have multiple clusters, created nested multi-operations\n let multiFactoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation;\n switch (operation.type) {\n case Algebra.types.JOIN:\n multiFactoryMethod = AF.createJoin.bind(AF);\n break;\n case Algebra.types.UNION:\n multiFactoryMethod = AF.createUnion.bind(AF);\n break;\n case Algebra.types.ALT:\n multiFactoryMethod = <any> AF.createAlt.bind(AF);\n break;\n case Algebra.types.SEQ:\n multiFactoryMethod = <any> AF.createSeq.bind(AF);\n break;\n default:\n // While LeftJoin and Minus are also multi-operations,\n // these can never occur because they only have 2 inputs,\n // so these cases will always be captured by one of the 2 if-cases above\n // (clusters.length === 1 or clusters.length === input.length)\n\n // In all other cases, error\n throw new Error(`Unsupported operation '${operation.type}' detected while grouping sources`);\n }\n return await this.groupOperationMulti(clusters, multiFactoryMethod, context);\n }\n\n protected async groupOperationMulti(\n clusters: Algebra.Operation[][],\n factoryMethod: (children: Algebra.Operation[], flatten: boolean) => Algebra.Operation,\n context: IActionContext,\n ): Promise<Algebra.Operation> {\n let flatten = true;\n const nestedMerges = await Promise.all(clusters.map(async(cluster) => {\n const source = ActorQueryOperation.getOperationSource(cluster[0])!;\n const merged = await this\n .moveSourceAnnotationUpwardsIfPossible(factoryMethod(cluster, true), cluster, source, context);\n if (ActorQueryOperation.getOperationSource(merged)) {\n flatten = false;\n }\n return merged;\n }));\n return factoryMethod(nestedMerges, flatten);\n }\n\n /**\n * Cluster the given operations by equal source annotations.\n * @param operationsIn An array of operations to cluster.\n */\n public clusterOperationsWithEqualSources(operationsIn: Algebra.Operation[]): Algebra.Operation[][] {\n // Operations can have a source, or no source at all\n const sourceOperations: Map<IQuerySourceWrapper, Algebra.Operation[]> = new Map();\n const sourcelessOperations: Algebra.Operation[] = [];\n\n // Cluster by source\n for (const operation of operationsIn) {\n const source: IQuerySourceWrapper = ActorQueryOperation.getOperationSource(operation)!;\n if (source) {\n if (!sourceOperations.has(source)) {\n sourceOperations.set(source, []);\n }\n sourceOperations.get(source)!.push(operation);\n } else {\n sourcelessOperations.push(operation);\n }\n }\n\n // Return clusters\n const clusters: Algebra.Operation[][] = [];\n if (sourcelessOperations.length > 0) {\n clusters.push(sourcelessOperations);\n }\n for (const [ source, operations ] of sourceOperations.entries()) {\n clusters.push(operations\n .map(operation => ActorQueryOperation.assignOperationSource(operation, source)));\n }\n return clusters;\n }\n\n /**\n * If the given source accepts the grouped operation, annotate the grouped operation with the source,\n * and remove the source annotation from the seperate input operations.\n * Otherwise, return the grouped operation unchanged.\n * @param operation A grouped operation consisting of all given input operations.\n * @param inputs An array of operations that share the same source annotation.\n * @param source The common source.\n * @param context The action context.\n */\n public async moveSourceAnnotationUpwardsIfPossible<O extends Algebra.Operation>(\n operation: O,\n inputs: Algebra.Operation[],\n source: IQuerySourceWrapper | undefined,\n context: IActionContext,\n ): Promise<O> {\n if (source && ActorQueryOperation\n .doesShapeAcceptOperation(await source.source.getSelectorShape(context), operation)) {\n this.logDebug(context, `Hoist ${inputs.length} source-specific operations into a single ${operation.type} operation for ${source.source.toString()}`);\n operation = ActorQueryOperation.assignOperationSource(operation, source);\n for (const input of inputs) {\n ActorQueryOperation.removeOperationSource(input);\n }\n }\n return operation;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
1
  {
2
2
  "name": "@comunica/actor-optimize-query-operation-group-sources",
3
- "version": "3.0.1-alpha.45.0",
3
+ "version": "3.0.1",
4
4
  "description": "A group-sources optimize-query-operation actor",
5
5
  "lsd:module": true,
6
- "main": "lib/index.js",
7
- "typings": "lib/index",
6
+ "license": "MIT",
7
+ "homepage": "https://comunica.dev/",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/comunica/comunica.git",
11
11
  "directory": "packages/actor-optimize-query-operation-group-sources"
12
12
  },
13
- "publishConfig": {
14
- "access": "public"
13
+ "bugs": {
14
+ "url": "https://github.com/comunica/comunica/issues"
15
15
  },
16
- "sideEffects": false,
17
16
  "keywords": [
18
17
  "comunica",
19
18
  "actor",
20
19
  "optimize-query-operation",
21
20
  "group-sources"
22
21
  ],
23
- "license": "MIT",
24
- "bugs": {
25
- "url": "https://github.com/comunica/comunica/issues"
22
+ "sideEffects": false,
23
+ "main": "lib/index.js",
24
+ "typings": "lib/index",
25
+ "publishConfig": {
26
+ "access": "public"
26
27
  },
27
- "homepage": "https://comunica.dev/",
28
28
  "files": [
29
29
  "components",
30
30
  "lib/**/*.d.ts",
31
31
  "lib/**/*.js",
32
32
  "lib/**/*.js.map"
33
33
  ],
34
- "dependencies": {
35
- "@comunica/bus-optimize-query-operation": "3.0.1-alpha.45.0",
36
- "@comunica/bus-query-operation": "3.0.1-alpha.45.0",
37
- "@comunica/core": "3.0.1-alpha.45.0",
38
- "@comunica/types": "3.0.1-alpha.45.0",
39
- "sparqlalgebrajs": "^4.3.3"
40
- },
41
34
  "scripts": {
42
35
  "build": "npm run build:ts && npm run build:components",
43
36
  "build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
44
37
  "build:components": "componentsjs-generator"
45
38
  },
46
- "gitHead": "b5a3900c24e29fa7b3243ab50bc9745d286fbce8"
39
+ "dependencies": {
40
+ "@comunica/bus-optimize-query-operation": "^3.0.1",
41
+ "@comunica/bus-query-operation": "^3.0.1",
42
+ "@comunica/core": "^3.0.1",
43
+ "@comunica/types": "^3.0.1",
44
+ "sparqlalgebrajs": "^4.3.3"
45
+ },
46
+ "gitHead": "9c0b537cd927d29590c287fe882185d88a65461b"
47
47
  }