@comunica/mediator-join-coefficients-fixed 3.2.0 → 3.2.4-alpha.47.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.
@@ -28,7 +28,8 @@
28
28
  "ct:components/IQueryOperationResult.jsonld#IQueryOperationResultBoolean",
29
29
  "ct:components/IQueryOperationResult.jsonld#IQueryOperationResultVoid"
30
30
  ]
31
- }
31
+ },
32
+ "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinTestSideData"
32
33
  ]
33
34
  }
34
35
  ],
@@ -83,6 +84,10 @@
83
84
  {
84
85
  "@type": "ParameterRangeGenericTypeReference",
85
86
  "parameterRangeGenericType": "npmd:@comunica/core/^3.0.0/components/Mediator.jsonld#Mediator__generic_O"
87
+ },
88
+ {
89
+ "@type": "ParameterRangeGenericTypeReference",
90
+ "parameterRangeGenericType": "npmd:@comunica/core/^3.0.0/components/Mediator.jsonld#Mediator__generic_TS"
86
91
  }
87
92
  ]
88
93
  },
@@ -183,7 +188,8 @@
183
188
  "ct:components/IQueryOperationResult.jsonld#IQueryOperationResultBoolean",
184
189
  "ct:components/IQueryOperationResult.jsonld#IQueryOperationResultVoid"
185
190
  ]
186
- }
191
+ },
192
+ "cbrj:components/ActorRdfJoin.jsonld#IActorRdfJoinTestSideData"
187
193
  ]
188
194
  }
189
195
  ],
@@ -1,5 +1,5 @@
1
- import type { ActorRdfJoin, IActionRdfJoin } from '@comunica/bus-rdf-join';
2
- import type { IActorReply, IMediatorArgs } from '@comunica/core';
1
+ import type { ActorRdfJoin, IActionRdfJoin, IActorRdfJoinTestSideData } from '@comunica/bus-rdf-join';
2
+ import type { IActorReply, IMediatorArgs, TestResult } from '@comunica/core';
3
3
  import { Mediator } from '@comunica/core';
4
4
  import type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';
5
5
  import type { IQueryOperationResult } from '@comunica/types';
@@ -7,15 +7,15 @@ import type { IQueryOperationResult } from '@comunica/types';
7
7
  * A mediator that mediates over actors implementing the Join Coefficients mediator type and assigns fixed weights
8
8
  * to calculate an overall score and pick the actor with the lowest score.
9
9
  */
10
- export declare class MediatorJoinCoefficientsFixed extends Mediator<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult> {
10
+ export declare class MediatorJoinCoefficientsFixed extends Mediator<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult, IActorRdfJoinTestSideData> {
11
11
  readonly cpuWeight: number;
12
12
  readonly memoryWeight: number;
13
13
  readonly timeWeight: number;
14
14
  readonly ioWeight: number;
15
15
  constructor(args: IMediatorJoinCoefficientsFixedArgs);
16
- protected mediateWith(action: IActionRdfJoin, testResults: IActorReply<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult>[]): Promise<ActorRdfJoin>;
16
+ protected mediateWith(action: IActionRdfJoin, testResults: IActorReply<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult, IActorRdfJoinTestSideData>[]): Promise<TestResult<ActorRdfJoin, IActorRdfJoinTestSideData>>;
17
17
  }
18
- export interface IMediatorJoinCoefficientsFixedArgs extends IMediatorArgs<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult> {
18
+ export interface IMediatorJoinCoefficientsFixedArgs extends IMediatorArgs<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult, IActorRdfJoinTestSideData> {
19
19
  /**
20
20
  * Weight for the CPU cost
21
21
  */
@@ -14,32 +14,35 @@ class MediatorJoinCoefficientsFixed extends core_1.Mediator {
14
14
  async mediateWith(action, testResults) {
15
15
  // Obtain test results
16
16
  const errors = [];
17
- const promises = testResults
18
- .map(({ reply }) => reply)
19
- .map(promise => promise.catch((error) => {
20
- errors.push(error);
21
- }));
22
- const coefficients = await Promise.all(promises);
17
+ const promises = testResults.map(({ reply }) => reply);
18
+ const results = (await Promise.all(promises)).map((testResult) => {
19
+ if (testResult.isFailed()) {
20
+ errors.push(testResult.getFailMessage());
21
+ // eslint-disable-next-line array-callback-return
22
+ return;
23
+ }
24
+ return { value: testResult.get(), sideData: testResult.getSideData() };
25
+ });
23
26
  // Calculate costs
24
- let costs = coefficients
27
+ let costs = results
25
28
  // eslint-disable-next-line array-callback-return
26
- .map((coeff) => {
27
- if (coeff) {
28
- return coeff.iterations * this.cpuWeight +
29
- coeff.persistedItems * this.memoryWeight +
30
- coeff.blockingItems * this.timeWeight +
31
- coeff.requestTime * this.ioWeight;
29
+ .map((result) => {
30
+ if (result) {
31
+ return result.value.iterations * this.cpuWeight +
32
+ result.value.persistedItems * this.memoryWeight +
33
+ result.value.blockingItems * this.timeWeight +
34
+ result.value.requestTime * this.ioWeight;
32
35
  }
33
36
  });
34
37
  const maxCost = Math.max(...costs.filter(cost => cost !== undefined));
35
38
  // If we have a limit indicator in the context,
36
- // increase cost of entries that have a number of iterations that is higher than the limit AND persist items.
39
+ // increase cost of entries that have a number of iterations that is higher than the limit AND block items.
37
40
  // In these cases, join operators that produce results early on will be preferred.
38
41
  const limitIndicator = action.context.get(context_entries_1.KeysQueryOperation.limitIndicator);
39
42
  if (limitIndicator) {
40
43
  costs = costs.map((cost, i) => {
41
- if (cost !== undefined && coefficients[i].persistedItems > 0 &&
42
- coefficients[i].iterations > limitIndicator) {
44
+ if (cost !== undefined && (results[i]?.value).blockingItems > 0 &&
45
+ (results[i]?.value).iterations > limitIndicator) {
43
46
  return cost + maxCost;
44
47
  }
45
48
  return cost;
@@ -56,7 +59,7 @@ class MediatorJoinCoefficientsFixed extends core_1.Mediator {
56
59
  }
57
60
  // Reject if all actors rejected
58
61
  if (minIndex < 0) {
59
- throw new Error(`All actors rejected their test in ${this.name}\n${errors.map(error => error.message).join('\n')}`);
62
+ return (0, core_1.failTest)(this.constructFailureMessage(action, errors));
60
63
  }
61
64
  // Return actor with lowest cost
62
65
  const bestActor = testResults[minIndex].actor;
@@ -65,18 +68,18 @@ class MediatorJoinCoefficientsFixed extends core_1.Mediator {
65
68
  core_1.Actor.getContextLogger(action.context)?.debug(`Determined physical join operator '${bestActor.logicalType}-${bestActor.physicalName}'`, {
66
69
  entries: action.entries.length,
67
70
  variables: await Promise.all(action.entries
68
- .map(async (entry) => (await entry.output.metadata()).variables.map(variable => variable.value))),
71
+ .map(async (entry) => (await entry.output.metadata()).variables.map(variable => variable.variable.value))),
69
72
  costs: Object.fromEntries(costs.map((coeff, i) => [
70
73
  `${testResults[i].actor.logicalType}-${testResults[i].actor.physicalName}`,
71
74
  coeff,
72
75
  ]).filter(entry => entry[1] !== undefined)),
73
- coefficients: Object.fromEntries(coefficients.map((coeff, i) => [
76
+ coefficients: Object.fromEntries(results.map((result, i) => [
74
77
  `${testResults[i].actor.logicalType}-${testResults[i].actor.physicalName}`,
75
- coeff,
78
+ result?.value,
76
79
  ]).filter(entry => entry[1] !== undefined)),
77
80
  });
78
81
  }
79
- return bestActor;
82
+ return (0, core_1.passTestWithSideData)(bestActor, results[minIndex].sideData);
80
83
  }
81
84
  }
82
85
  exports.MediatorJoinCoefficientsFixed = MediatorJoinCoefficientsFixed;
@@ -1 +1 @@
1
- {"version":3,"file":"MediatorJoinCoefficientsFixed.js","sourceRoot":"","sources":["MediatorJoinCoefficientsFixed.ts"],"names":[],"mappings":";;;AACA,+DAA+D;AAE/D,yCAAiD;AAIjD;;;GAGG;AACH,MAAa,6BACX,SAAQ,eAA4F;IAMpG,YAAmB,IAAwC;QACzD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAES,KAAK,CAAC,WAAW,CACzB,MAAsB,EACtB,WAA8G;QAE9G,sBAAsB;QACtB,MAAM,MAAM,GAAY,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,WAAW;aACzB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC;aACzB,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAA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C,CAAC;gBACjG,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;oBAChD,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE;oBAC1E,KAAK;iBACN,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;gBAC3C,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC9D,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE;oBAC1E,KAAK;iBACN,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;aAC5C,CAAC,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA1FD,sEA0FC","sourcesContent":["import type { ActorRdfJoin, IActionRdfJoin } from '@comunica/bus-rdf-join';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorReply, IMediatorArgs } from '@comunica/core';\nimport { Actor, Mediator } from '@comunica/core';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type { IQueryOperationResult } from '@comunica/types';\n\n/**\n * A mediator that mediates over actors implementing the Join Coefficients mediator type and assigns fixed weights\n * to calculate an overall score and pick the actor with the lowest score.\n */\nexport class MediatorJoinCoefficientsFixed\n extends Mediator<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult> {\n public readonly cpuWeight: number;\n public readonly memoryWeight: number;\n public readonly timeWeight: number;\n public readonly ioWeight: number;\n\n public constructor(args: IMediatorJoinCoefficientsFixedArgs) {\n super(args);\n }\n\n protected async mediateWith(\n action: IActionRdfJoin,\n testResults: IActorReply<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult>[],\n ): Promise<ActorRdfJoin> {\n // Obtain test results\n const errors: Error[] = [];\n const promises = testResults\n .map(({ reply }) => reply)\n .map(promise => promise.catch((error) => {\n errors.push(error);\n }));\n const coefficients = await Promise.all(promises);\n\n // Calculate costs\n let costs: (number | undefined)[] = coefficients\n // eslint-disable-next-line array-callback-return\n .map((coeff) => {\n if (coeff) {\n return coeff.iterations * this.cpuWeight +\n coeff.persistedItems * this.memoryWeight +\n coeff.blockingItems * this.timeWeight +\n coeff.requestTime * this.ioWeight;\n }\n });\n const maxCost = Math.max(...(<number[]> costs.filter(cost => cost !== undefined)));\n\n // If we have a limit indicator in the context,\n // increase cost of entries that have a number of iterations that is higher than the limit AND persist items.\n // In these cases, join operators that produce results early on will be preferred.\n const limitIndicator: number | undefined = action.context.get(KeysQueryOperation.limitIndicator);\n if (limitIndicator) {\n costs = costs.map((cost, i) => {\n if (cost !== undefined && (<any> coefficients[i]).persistedItems > 0 &&\n\n (<any> coefficients[i]).iterations > limitIndicator) {\n return cost + maxCost;\n }\n return cost;\n });\n }\n\n // Determine index with lowest cost\n let minIndex = -1;\n let minValue = Number.POSITIVE_INFINITY;\n for (const [ i, cost ] of costs.entries()) {\n if (cost !== undefined && (minIndex === -1 || cost < minValue)) {\n minIndex = i;\n minValue = cost;\n }\n }\n\n // Reject if all actors rejected\n if (minIndex < 0) {\n throw new Error(`All actors rejected their test in ${this.name}\\n${\n errors.map(error => error.message).join('\\n')}`);\n }\n\n // Return actor with lowest cost\n const bestActor = testResults[minIndex].actor;\n\n // Emit calculations in logger\n if (bestActor.includeInLogs) {\n Actor.getContextLogger(action.context)?.debug(`Determined physical join operator '${bestActor.logicalType}-${bestActor.physicalName}'`, {\n entries: action.entries.length,\n variables: await Promise.all(action.entries\n .map(async entry => (await entry.output.metadata()).variables.map(variable => variable.value))),\n costs: Object.fromEntries(costs.map((coeff, i) => [\n `${testResults[i].actor.logicalType}-${testResults[i].actor.physicalName}`,\n coeff,\n ]).filter(entry => entry[1] !== undefined)),\n coefficients: Object.fromEntries(coefficients.map((coeff, i) => [\n `${testResults[i].actor.logicalType}-${testResults[i].actor.physicalName}`,\n coeff,\n ]).filter(entry => entry[1] !== undefined)),\n });\n }\n\n return bestActor;\n }\n}\n\nexport interface IMediatorJoinCoefficientsFixedArgs\n extends IMediatorArgs<ActorRdfJoin, IActionRdfJoin, IMediatorTypeJoinCoefficients, IQueryOperationResult> {\n /**\n * Weight for the CPU cost\n */\n cpuWeight: number;\n /**\n * Weight for the memory cost\n */\n memoryWeight: number;\n /**\n * Weight for the execution time cost\n */\n timeWeight: number;\n /**\n * Weight for the I/O cost\n */\n ioWeight: number;\n}\n"]}
1
+ {"version":3,"file":"MediatorJoinCoefficientsFixed.js","sourceRoot":"","sources":["MediatorJoinCoefficientsFixed.ts"],"names":[],"mappings":";;;AACA,+DAA+D;AAE/D,yCAAiF;AAIjF;;;GAGG;AACH,MAAa,6BAA8B,SAAQ,eAMlD;IAMC,YAAmB,IAAwC;QACzD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAES,KAAK,CAAC,WAAW,CACzB,MAAsB,EACtB,WAMD;QAEC,sBAAsB;QACtB,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QACvD,MAAM,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAC/D,IAAI,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;gB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AQ,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC1G,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;oBAChD,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE;oBAC1E,KAAK;iBACN,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;gBAC3C,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC1D,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE;oBAC1E,MAAM,EAAE,KAAK;iBACd,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;aAC5C,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAA,2BAAoB,EAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAE,CAAC,QAAQ,CAAC,CAAC;IACtE,CAAC;CACF;AAvGD,sEAuGC","sourcesContent":["import type { ActorRdfJoin, IActionRdfJoin, IActorRdfJoinTestSideData } from '@comunica/bus-rdf-join';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorReply, IMediatorArgs, TestResult } from '@comunica/core';\nimport { passTestWithSideData, failTest, Actor, Mediator } from '@comunica/core';\nimport type { IMediatorTypeJoinCoefficients } from '@comunica/mediatortype-join-coefficients';\nimport type { IQueryOperationResult } from '@comunica/types';\n\n/**\n * A mediator that mediates over actors implementing the Join Coefficients mediator type and assigns fixed weights\n * to calculate an overall score and pick the actor with the lowest score.\n */\nexport class MediatorJoinCoefficientsFixed extends Mediator<\n ActorRdfJoin,\nIActionRdfJoin,\nIMediatorTypeJoinCoefficients,\nIQueryOperationResult,\nIActorRdfJoinTestSideData\n> {\n public readonly cpuWeight: number;\n public readonly memoryWeight: number;\n public readonly timeWeight: number;\n public readonly ioWeight: number;\n\n public constructor(args: IMediatorJoinCoefficientsFixedArgs) {\n super(args);\n }\n\n protected async mediateWith(\n action: IActionRdfJoin,\n testResults: IActorReply<\n ActorRdfJoin,\nIActionRdfJoin,\nIMediatorTypeJoinCoefficients,\nIQueryOperationResult,\nIActorRdfJoinTestSideData\n>[],\n ): Promise<TestResult<ActorRdfJoin, IActorRdfJoinTestSideData>> {\n // Obtain test results\n const errors: string[] = [];\n const promises = testResults.map(({ reply }) => reply);\n const results = (await Promise.all(promises)).map((testResult) => {\n if (testResult.isFailed()) {\n errors.push(testResult.getFailMessage());\n // eslint-disable-next-line array-callback-return\n return;\n }\n return { value: testResult.get(), sideData: testResult.getSideData() };\n });\n\n // Calculate costs\n let costs: (number | undefined)[] = results\n // eslint-disable-next-line array-callback-return\n .map((result) => {\n if (result) {\n return result.value.iterations * this.cpuWeight +\n result.value.persistedItems * this.memoryWeight +\n result.value.blockingItems * this.timeWeight +\n result.value.requestTime * this.ioWeight;\n }\n });\n const maxCost = Math.max(...(<number[]> costs.filter(cost => cost !== undefined)));\n\n // If we have a limit indicator in the context,\n // increase cost of entries that have a number of iterations that is higher than the limit AND block items.\n // In these cases, join operators that produce results early on will be preferred.\n const limitIndicator: number | undefined = action.context.get(KeysQueryOperation.limitIndicator);\n if (limitIndicator) {\n costs = costs.map((cost, i) => {\n if (cost !== undefined && (<any> results[i]?.value).blockingItems > 0 &&\n\n (<any> results[i]?.value).iterations > limitIndicator) {\n return cost + maxCost;\n }\n return cost;\n });\n }\n\n // Determine index with lowest cost\n let minIndex = -1;\n let minValue = Number.POSITIVE_INFINITY;\n for (const [ i, cost ] of costs.entries()) {\n if (cost !== undefined && (minIndex === -1 || cost < minValue)) {\n minIndex = i;\n minValue = cost;\n }\n }\n\n // Reject if all actors rejected\n if (minIndex < 0) {\n return failTest(this.constructFailureMessage(action, errors));\n }\n\n // Return actor with lowest cost\n const bestActor = testResults[minIndex].actor;\n\n // Emit calculations in logger\n if (bestActor.includeInLogs) {\n Actor.getContextLogger(action.context)?.debug(`Determined physical join operator '${bestActor.logicalType}-${bestActor.physicalName}'`, {\n entries: action.entries.length,\n variables: await Promise.all(action.entries\n .map(async entry => (await entry.output.metadata()).variables.map(variable => variable.variable.value))),\n costs: Object.fromEntries(costs.map((coeff, i) => [\n `${testResults[i].actor.logicalType}-${testResults[i].actor.physicalName}`,\n coeff,\n ]).filter(entry => entry[1] !== undefined)),\n coefficients: Object.fromEntries(results.map((result, i) => [\n `${testResults[i].actor.logicalType}-${testResults[i].actor.physicalName}`,\n result?.value,\n ]).filter(entry => entry[1] !== undefined)),\n });\n }\n\n return passTestWithSideData(bestActor, results[minIndex]!.sideData);\n }\n}\n\nexport interface IMediatorJoinCoefficientsFixedArgs extends IMediatorArgs<\n ActorRdfJoin,\nIActionRdfJoin,\nIMediatorTypeJoinCoefficients,\nIQueryOperationResult,\nIActorRdfJoinTestSideData\n> {\n /**\n * Weight for the CPU cost\n */\n cpuWeight: number;\n /**\n * Weight for the memory cost\n */\n memoryWeight: number;\n /**\n * Weight for the execution time cost\n */\n timeWeight: number;\n /**\n * Weight for the I/O cost\n */\n ioWeight: number;\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@comunica/mediator-join-coefficients-fixed",
3
- "version": "3.2.0",
3
+ "version": "3.2.4-alpha.47.0",
4
4
  "description": "A join-coefficients-fixed mediator",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
7
+ "funding": {
8
+ "type": "opencollective",
9
+ "url": "https://opencollective.com/comunica-association"
10
+ },
7
11
  "homepage": "https://comunica.dev/",
8
12
  "repository": {
9
13
  "type": "git",
@@ -35,11 +39,11 @@
35
39
  "build:components": "componentsjs-generator"
36
40
  },
37
41
  "dependencies": {
38
- "@comunica/bus-rdf-join": "^3.2.0",
39
- "@comunica/context-entries": "^3.2.0",
40
- "@comunica/core": "^3.2.0",
41
- "@comunica/mediatortype-join-coefficients": "^3.2.0",
42
- "@comunica/types": "^3.2.0"
42
+ "@comunica/bus-rdf-join": "3.2.4-alpha.47.0",
43
+ "@comunica/context-entries": "3.2.4-alpha.47.0",
44
+ "@comunica/core": "3.2.4-alpha.47.0",
45
+ "@comunica/mediatortype-join-coefficients": "3.2.4-alpha.47.0",
46
+ "@comunica/types": "3.2.4-alpha.47.0"
43
47
  },
44
- "gitHead": "87baf2afed021a254859e64b92f34d9b51c6a7db"
48
+ "gitHead": "85bd4c5cf07dfc293ebbc3a1416b70e2db8bfc48"
45
49
  }