@comunica/actor-query-operation-from-quad 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-query-operation-from-quad/^3.0.0/components/context.jsonld"
|
|
26
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-operation-from-quad/^3.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/^
|
|
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
|
"caqofq": "npmd:@comunica/actor-query-operation-from-quad/^3.0.0/",
|
|
@@ -60,6 +60,6 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
60
60
|
* @return {Operation} The transformed operation.
|
|
61
61
|
*/
|
|
62
62
|
static createOperation(pattern: Algebra.From): Algebra.Operation;
|
|
63
|
-
testOperation(
|
|
63
|
+
testOperation(_operation: Algebra.From, _context: IActionContext): Promise<IActorTest>;
|
|
64
64
|
runOperation(operationOriginal: Algebra.From, context: IActionContext): Promise<IQueryOperationResult>;
|
|
65
65
|
}
|
|
@@ -181,7 +181,7 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
181
181
|
}
|
|
182
182
|
return operation;
|
|
183
183
|
}
|
|
184
|
-
async testOperation(
|
|
184
|
+
async testOperation(_operation, _context) {
|
|
185
185
|
return true;
|
|
186
186
|
}
|
|
187
187
|
async runOperation(operationOriginal, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperationFromQuad.js","sourceRoot":"","sources":["ActorQueryOperationFromQuad.ts"],"names":[],"mappings":";;;AACA,uEAAiF;AAIjF,qDAAmD;AAEnD;;GAEG;AACH,MAAa,2BAA4B,SAAQ,sDAA8C;IAI7F,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,SAA4B,EACtD,WAAmE;QACnE,MAAM,eAAe,GAA4B,EAAE,CAAC;QACpD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACxC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,KAAK,UAAU,EAAE;gBACvD,yGAAyG;gBACzG,IAAI,GAAG,KAAK,WAAW,EAAE;oBACvB,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;iBACvC;qBAAM;oBACL,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;iBACxD;aACF;iBAAM,IAAI,2BAA2B,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE;gBAClF,eAAe,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;aACpD;iBAAM;gBACL,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;aACvC;SACF;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,0BAA0B,CAAC,SAA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AAC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';\nimport type { IActorTest } from '@comunica/core';\nimport type { IActionContext, IQueryOperationResult } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\n/**\n * A comunica From Query Operation Actor.\n */\nexport class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {\n private static readonly FACTORY: Factory = new Factory();\n private static readonly ALGEBRA_TYPES: string[] = Object.keys(Algebra.types).map(key => (<any> Algebra.types)[key]);\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, 'from');\n }\n\n /**\n * Create a deep copy of the given operation.\n * @param {Operation} operation An operation.\n * @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.\n * @return {Operation} The copied operation.\n */\n public static copyOperation(operation: Algebra.Operation,\n recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation): Algebra.Operation {\n const copiedOperation: Algebra.Operation = <any> {};\n for (const key of Object.keys(operation)) {\n if (Array.isArray(operation[key]) && key !== 'template') {\n // We exclude the 'template' entry, as we don't want to modify the template value of construct operations\n if (key === 'variables') {\n copiedOperation[key] = operation[key];\n } else {\n copiedOperation[key] = operation[key].map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(operation[key].type)) {\n copiedOperation[key] = recursiveCb(operation[key]);\n } else {\n copiedOperation[key] = operation[key];\n }\n }\n return copiedOperation;\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as default graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} defaultGraphs Graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationDefaultGraph(operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n if (operation.type === 'bgp') {\n return ActorQueryOperationFromQuad.joinOperations(operation.patterns.map((pattern: Algebra.Pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return ActorQueryOperationFromQuad.FACTORY.createBgp([ pattern ]);\n }\n const bgps = defaultGraphs.map((graph: RDF.Term) =>\n ActorQueryOperationFromQuad.FACTORY.createBgp([ Object.assign(\n ActorQueryOperationFromQuad.FACTORY\n .createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n { metadata: pattern.metadata },\n ) ]));\n return ActorQueryOperationFromQuad.unionOperations(bgps);\n }));\n }\n if (operation.graph.termType !== 'DefaultGraph') {\n return operation;\n }\n const paths = defaultGraphs.map(\n (graph: RDF.Term) => {\n if (operation.type === 'path') {\n return ActorQueryOperationFromQuad.FACTORY\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n }\n return Object.assign(ActorQueryOperationFromQuad.FACTORY\n .createPattern(operation.subject, operation.predicate, operation.object, graph),\n { metadata: operation.metadata });\n },\n );\n return ActorQueryOperationFromQuad.unionOperations(paths);\n }\n\n return ActorQueryOperationFromQuad.copyOperation(operation,\n (subOperation: Algebra.Operation) => this.applyOperationDefaultGraph(subOperation, defaultGraphs));\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as named graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} namedGraphs Graph terms.\n * @param {RDF.Term[]} defaultGraphs Default graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationNamedGraph(operation: Algebra.Operation, namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[]): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n const patternGraph: RDF.Term = operation.type === 'bgp' ? operation.patterns[0].graph : operation.graph;\n if (patternGraph.termType === 'DefaultGraph') {\n // SPARQL spec (8.2) describes that when FROM NAMED's are used without a FROM, the default graph must be empty.\n // The FROMs are transformed before this step to a named node, so this will not apply to this case anymore.\n return { type: Algebra.types.BGP, patterns: []};\n }\n if (patternGraph.termType === 'Variable') {\n if (namedGraphs.length === 1) {\n const graph: RDF.NamedNode = namedGraphs[0];\n // If the pattern graph is a variable, replace the graph and bind the variable using VALUES\n const bindings: Record<string, RDF.Literal | RDF.NamedNode> = {};\n bindings[`?${patternGraph.value}`] = graph;\n const values: Algebra.Values = ActorQueryOperationFromQuad.FACTORY\n .createValues([ patternGraph ], [ bindings ]);\n\n let pattern: Algebra.Operation;\n if (operation.type === 'bgp') {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createBgp(operation.patterns.map((pat: Algebra.Pattern) => ActorQueryOperationFromQuad.FACTORY\n .createPattern(pat.subject, pat.predicate, pat.object, graph)));\n } else if (operation.type === 'path') {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n } else {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createPattern(operation.subject, operation.predicate, operation.object, graph);\n }\n\n return ActorQueryOperationFromQuad.FACTORY.createJoin([ values, pattern ]);\n }\n // If the pattern graph is a variable, take the union of the pattern applied to each available named graph\n return ActorQueryOperationFromQuad.unionOperations(namedGraphs.map(\n (graph: RDF.NamedNode) => ActorQueryOperationFromQuad.applyOperationNamedGraph(\n operation, [ graph ], defaultGraphs,\n ),\n ));\n }\n // The pattern's graph is defined (including the default graphs)\n const isNamedGraphAvailable: boolean = [ ...namedGraphs, ...defaultGraphs ].some(\n (namedGraph: RDF.Term) => namedGraph.equals(patternGraph),\n );\n if (isNamedGraphAvailable) {\n // Return the pattern as-is if the pattern's graph was selected in a FROM NAMED\n return operation;\n }\n // No-op if the pattern's graph was not selected in a FROM NAMED.\n return { type: Algebra.types.BGP, patterns: []};\n }\n\n return ActorQueryOperationFromQuad.copyOperation(operation,\n (subOperation: Algebra.Operation) => this.applyOperationNamedGraph(subOperation, namedGraphs, defaultGraphs));\n }\n\n /**\n * Transform the given array of operations into a join operation.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Join} A join operation.\n */\n public static joinOperations(operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return ActorQueryOperationFromQuad.FACTORY.createJoin(operations);\n }\n throw new Error('A join can only be applied on at least one operation');\n }\n\n /**\n * Transform the given array of operations into a union operation.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Union} A union operation.\n */\n public static unionOperations(operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return ActorQueryOperationFromQuad.FACTORY.createUnion(operations);\n }\n throw new Error('A union can only be applied on at least one operation');\n }\n\n /**\n * Transform an operation based on the default and named graphs in the pattern.\n *\n * FROM sets the default graph.\n * If multiple are available, take the union of the operation for all of them at quad-pattern level.\n *\n * FROM NAMED indicates which named graphs are available.\n * This will rewrite the query so that only triples from the given named graphs can be selected.\n *\n * @param {From} pattern A from operation.\n * @return {Operation} The transformed operation.\n */\n public static createOperation(pattern: Algebra.From): Algebra.Operation {\n let operation: Algebra.Operation = pattern.input;\n if (pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(operation, pattern.default);\n }\n if (pattern.named.length > 0 || pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationNamedGraph(operation, pattern.named, pattern.default);\n }\n return operation;\n }\n\n public async testOperation(operation: Algebra.From, context: IActionContext): Promise<IActorTest> {\n return true;\n }\n\n public async runOperation(\n operationOriginal: Algebra.From,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorQueryOperationFrom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AO,EAAE,CAAC;AACjC,yCAAa,GAAa,MAAM,CAAC,IAAI,CAAC,yBAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAQ,yBAAO,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';\nimport type { IActorTest } from '@comunica/core';\nimport type { IActionContext, IQueryOperationResult } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\n/**\n * A comunica From Query Operation Actor.\n */\nexport class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {\n private static readonly FACTORY: Factory = new Factory();\n private static readonly ALGEBRA_TYPES: string[] = Object.keys(Algebra.types).map(key => (<any> Algebra.types)[key]);\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, 'from');\n }\n\n /**\n * Create a deep copy of the given operation.\n * @param {Operation} operation An operation.\n * @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.\n * @return {Operation} The copied operation.\n */\n public static copyOperation(\n operation: Algebra.Operation,\n recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation,\n ): Algebra.Operation {\n const copiedOperation: Algebra.Operation = <any> {};\n for (const key of Object.keys(operation)) {\n if (Array.isArray(operation[key]) && key !== 'template') {\n // We exclude the 'template' entry, as we don't want to modify the template value of construct operations\n if (key === 'variables') {\n copiedOperation[key] = operation[key];\n } else {\n copiedOperation[key] = operation[key].map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(operation[key].type)) {\n copiedOperation[key] = recursiveCb(operation[key]);\n } else {\n copiedOperation[key] = operation[key];\n }\n }\n return copiedOperation;\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as default graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} defaultGraphs Graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationDefaultGraph(operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n if (operation.type === 'bgp') {\n return ActorQueryOperationFromQuad.joinOperations(operation.patterns.map((pattern: Algebra.Pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return ActorQueryOperationFromQuad.FACTORY.createBgp([ pattern ]);\n }\n const bgps = defaultGraphs.map((graph: RDF.Term) =>\n ActorQueryOperationFromQuad.FACTORY.createBgp([ Object.assign(\n ActorQueryOperationFromQuad.FACTORY\n .createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n { metadata: pattern.metadata },\n ) ]));\n return ActorQueryOperationFromQuad.unionOperations(bgps);\n }));\n }\n if (operation.graph.termType !== 'DefaultGraph') {\n return operation;\n }\n const paths = defaultGraphs.map(\n (graph: RDF.Term) => {\n if (operation.type === 'path') {\n return ActorQueryOperationFromQuad.FACTORY\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n }\n return Object.assign(ActorQueryOperationFromQuad.FACTORY\n .createPattern(\n operation.subject,\n operation.predicate,\n operation.object,\n graph,\n ), { metadata: operation.metadata });\n },\n );\n return ActorQueryOperationFromQuad.unionOperations(paths);\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this.applyOperationDefaultGraph(subOperation, defaultGraphs),\n );\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as named graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} namedGraphs Graph terms.\n * @param {RDF.Term[]} defaultGraphs Default graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationNamedGraph(\n operation: Algebra.Operation,\n namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n const patternGraph: RDF.Term = operation.type === 'bgp' ? operation.patterns[0].graph : operation.graph;\n if (patternGraph.termType === 'DefaultGraph') {\n // SPARQL spec (8.2) describes that when FROM NAMED's are used without a FROM, the default graph must be empty.\n // The FROMs are transformed before this step to a named node, so this will not apply to this case anymore.\n return { type: Algebra.types.BGP, patterns: []};\n }\n if (patternGraph.termType === 'Variable') {\n if (namedGraphs.length === 1) {\n const graph: RDF.NamedNode = namedGraphs[0];\n // If the pattern graph is a variable, replace the graph and bind the variable using VALUES\n const bindings: Record<string, RDF.Literal | RDF.NamedNode> = {};\n bindings[`?${patternGraph.value}`] = graph;\n const values: Algebra.Values = ActorQueryOperationFromQuad.FACTORY\n .createValues([ patternGraph ], [ bindings ]);\n\n let pattern: Algebra.Operation;\n if (operation.type === 'bgp') {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createBgp(operation.patterns.map((pat: Algebra.Pattern) => ActorQueryOperationFromQuad.FACTORY\n .createPattern(pat.subject, pat.predicate, pat.object, graph)));\n } else if (operation.type === 'path') {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n } else {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createPattern(operation.subject, operation.predicate, operation.object, graph);\n }\n\n return ActorQueryOperationFromQuad.FACTORY.createJoin([ values, pattern ]);\n }\n // If the pattern graph is a variable, take the union of the pattern applied to each available named graph\n return ActorQueryOperationFromQuad.unionOperations(namedGraphs.map(\n (graph: RDF.NamedNode) => ActorQueryOperationFromQuad.applyOperationNamedGraph(\n operation,\n [ graph ],\n defaultGraphs,\n ),\n ));\n }\n // The pattern's graph is defined (including the default graphs)\n const isNamedGraphAvailable: boolean = [ ...namedGraphs, ...defaultGraphs ].some(\n (namedGraph: RDF.Term) => namedGraph.equals(patternGraph),\n );\n if (isNamedGraphAvailable) {\n // Return the pattern as-is if the pattern's graph was selected in a FROM NAMED\n return operation;\n }\n // No-op if the pattern's graph was not selected in a FROM NAMED.\n return { type: Algebra.types.BGP, patterns: []};\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this.applyOperationNamedGraph(subOperation, namedGraphs, defaultGraphs),\n );\n }\n\n /**\n * Transform the given array of operations into a join operation.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Join} A join operation.\n */\n public static joinOperations(operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return ActorQueryOperationFromQuad.FACTORY.createJoin(operations);\n }\n throw new Error('A join can only be applied on at least one operation');\n }\n\n /**\n * Transform the given array of operations into a union operation.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Union} A union operation.\n */\n public static unionOperations(operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return ActorQueryOperationFromQuad.FACTORY.createUnion(operations);\n }\n throw new Error('A union can only be applied on at least one operation');\n }\n\n /**\n * Transform an operation based on the default and named graphs in the pattern.\n *\n * FROM sets the default graph.\n * If multiple are available, take the union of the operation for all of them at quad-pattern level.\n *\n * FROM NAMED indicates which named graphs are available.\n * This will rewrite the query so that only triples from the given named graphs can be selected.\n *\n * @param {From} pattern A from operation.\n * @return {Operation} The transformed operation.\n */\n public static createOperation(pattern: Algebra.From): Algebra.Operation {\n let operation: Algebra.Operation = pattern.input;\n if (pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(operation, pattern.default);\n }\n if (pattern.named.length > 0 || pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationNamedGraph(operation, pattern.named, pattern.default);\n }\n return operation;\n }\n\n public async testOperation(_operation: Algebra.From, _context: IActionContext): Promise<IActorTest> {\n return true;\n }\n\n public async runOperation(\n operationOriginal: Algebra.From,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-from-quad",
|
|
3
|
-
"version": "3.0.1
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "A from query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
|
-
"
|
|
7
|
-
"
|
|
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-query-operation-from-quad"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
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
|
"query-operation",
|
|
21
20
|
"from"
|
|
22
21
|
],
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
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-query-operation": "3.0.1-alpha.45.0",
|
|
36
|
-
"@comunica/core": "3.0.1-alpha.45.0",
|
|
37
|
-
"@comunica/types": "3.0.1-alpha.45.0",
|
|
38
|
-
"@rdfjs/types": "*",
|
|
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
|
-
"
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@comunica/bus-query-operation": "^3.0.1",
|
|
41
|
+
"@comunica/core": "^3.0.1",
|
|
42
|
+
"@comunica/types": "^3.0.1",
|
|
43
|
+
"@rdfjs/types": "*",
|
|
44
|
+
"sparqlalgebrajs": "^4.3.3"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "9c0b537cd927d29590c287fe882185d88a65461b"
|
|
47
47
|
}
|