Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make browser version of the SPARQL init actor consistent with Node
When run in a browser environment, developers must now use `Comunica.newEngine().query(...)` instead of `Comunica.evaluateQuery(...)`. The latter function still exist, but is deprecated and will be removed in the next major update.
- Loading branch information
1 parent
6ed2f88
commit 8de84a6
Showing
14 changed files
with
1,934 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
export * from './lib/ActorInitSparql-browser'; | ||
|
||
import {ActorInitSparql} from './lib/ActorInitSparql-browser'; | ||
|
||
/** | ||
* Create a new comunica engine from the default config. | ||
* @return {ActorInitSparql} A comunica engine. | ||
*/ | ||
export function newEngine(): ActorInitSparql { | ||
return require('./engine-default.js'); | ||
} | ||
|
||
// TODO: remove in 2.0.0, this is just here for backwards-compatibility | ||
export function evaluateQuery(query: string, context?: any): any { | ||
return newEngine().query(query, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
export * from './lib/ActorInitSparql'; | ||
export * from './lib/Query'; | ||
export {newEngine} from './index-browser'; | ||
|
||
import {ActorInitSparql} from "./lib/ActorInitSparql"; | ||
import {IQueryOptions, newEngineDynamicArged} from "./lib/QueryDynamic"; | ||
|
||
/** | ||
* Create a new dynamic comunica engine from a given config file. | ||
* @param {IQueryOptions} options Optional options on how to instantiate the query evaluator. | ||
* @return {Promise<QueryEngine>} A promise that resolves to a fully wired comunica engine. | ||
*/ | ||
export function newEngineDynamic(options?: IQueryOptions): Promise<ActorInitSparql> { | ||
return newEngineDynamicArged(options || {}, __dirname, __dirname + '/config/config-default.json'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {ISetupProperties, Runner, Setup} from "@comunica/runner"; | ||
import {existsSync} from "fs"; | ||
import {ActorInitSparql} from "./ActorInitSparql"; | ||
|
||
/** | ||
* Create a new dynamic comunica engine. | ||
* @param {IQueryOptions} options Optional options on how to instantiate the query evaluator. | ||
* @param {string} moduleRootPath The path to the invoking module. | ||
* @param {string} defaultConfigPath The path to the config file. | ||
* @param {boolean} [inDevOverride] If the engine is running in a monorepo development environment. | ||
* Default is determined based on the state of this package. | ||
* @return {Promise<ActorInitSparql>} A promise that resolves to a fully wired comunica engine. | ||
*/ | ||
export function newEngineDynamicArged(options: IQueryOptions, moduleRootPath: string, defaultConfigPath: string, | ||
inDevOverride?: boolean): Promise<ActorInitSparql> { | ||
if (!options.mainModulePath) { | ||
// This makes sure that our configuration is found by Components.js | ||
options.mainModulePath = inDevOverride || isInDev() ? moduleRootPath : moduleRootPath + '../'; | ||
} | ||
const configResourceUrl: string = options.configResourceUrl || defaultConfigPath; | ||
const instanceUri: string = options.instanceUri || 'urn:comunica:sparqlinit'; | ||
|
||
// Instantiate the main runner so that all other actors are instantiated as well, | ||
// and find the SPARQL init actor with the given name | ||
const runnerInstanceUri: string = options.runnerInstanceUri || 'urn:comunica:my'; | ||
|
||
// this needs to happen before any promise gets generated | ||
Setup.preparePromises(); | ||
return Setup.instantiateComponent(configResourceUrl, runnerInstanceUri, options) | ||
.then((runner: Runner) => { | ||
let actor = null; | ||
for (const runningActor of runner.actors) { | ||
if (runningActor.name === instanceUri) { | ||
actor = <any> runningActor; | ||
} | ||
} | ||
if (!actor) { | ||
throw new Error('No SPARQL init actor was found with the name "' + instanceUri + '" in runner "' | ||
+ runnerInstanceUri + '".'); | ||
} | ||
return actor; | ||
}); | ||
} | ||
|
||
function isInDev(): boolean { | ||
return existsSync(__dirname + '/../test'); | ||
} | ||
|
||
/** | ||
* Options for configuring how the query evaluator must be instantiated. | ||
*/ | ||
export interface IQueryOptions extends ISetupProperties { | ||
/** | ||
* The URL or local path to a Components.js config file. | ||
*/ | ||
configResourceUrl?: string; | ||
/** | ||
* A URI identifying the component to instantiate. | ||
*/ | ||
instanceUri?: string; | ||
/** | ||
* A URI identifying the runner component. | ||
*/ | ||
runnerInstanceUri?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.