Comparing version 1.1.87 to 1.1.88
@@ -14,2 +14,4 @@ /// <reference types="node" /> | ||
main(context: ConnectorContext<any>, taskConfig: TaskConfig, config: JSTask): Promise<any>; | ||
getModule: <T>(modules: any, moduleName: string) => T; | ||
executeDoer: <T>(env: Environment, doerName: string, context: ConnectorContext<any>, coreConfig: T, runAsTask?: boolean, metadata?: any) => Promise<any>; | ||
} | ||
@@ -22,2 +24,3 @@ export declare class JSModule { | ||
private _module?; | ||
get errors(): IMap<Error>; | ||
get path(): string; | ||
@@ -28,8 +31,13 @@ get code(): string; | ||
get setup(): any; | ||
get hasErrors(): boolean; | ||
constructor(path: string, code: string); | ||
get module(): Module; | ||
get module(): Module | undefined; | ||
get name(): string; | ||
getMethod(name?: string): any; | ||
} | ||
export declare type JSModuleFunction = (env: Environment, context: ConnectorContext<any>, modules: IMap<JSModule>, parameters: any) => Promise<any>; | ||
export declare type JSModuleFunction = (env: Environment, context: ConnectorContext<any>, modules: IMap<JSModule>, parameters: any, utilities: JSModuleUtilities) => Promise<any>; | ||
export interface JSModuleUtilities { | ||
getModule: <T>(modules: any, moduleName: string) => JSModule; | ||
executeDoer: <T>(env: Environment, doerName: string, context: ConnectorContext<any>, coreConfig: T, runAsTask: boolean, metadata: any) => Promise<any>; | ||
} | ||
export interface JSTask { | ||
@@ -36,0 +44,0 @@ module: string; |
@@ -24,5 +24,22 @@ "use strict"; | ||
this.hasModule = (name) => !!this.modules[name]; | ||
this.getModule = (modules, moduleName) => { | ||
const module = modules[moduleName]; | ||
if (!module) | ||
throw new Error(`No JSModule with the name '${moduleName}' has been loaded`); | ||
return module.exports; | ||
}; | ||
this.executeDoer = (env, doerName, context, coreConfig, runAsTask = false, metadata = {}) => __awaiter(this, void 0, void 0, function* () { | ||
const doer = env.getDoer(doerName); | ||
const config = { name: `JSModule`, doer: doerName, config: coreConfig, metadata }; | ||
if (runAsTask) { | ||
return yield doer.execute(context, config); | ||
} | ||
else { | ||
return yield doer.main(context, config, coreConfig); | ||
} | ||
}); | ||
} | ||
setup() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const errors = []; | ||
for (const [name, code] of Object.entries(this.config)) { | ||
@@ -33,3 +50,8 @@ const newModule = new JSModule(name, code); | ||
this.modules[newModule.name] = newModule; | ||
if (newModule.hasErrors) | ||
errors.push(newModule); | ||
} | ||
if (errors.length > 0) { | ||
console.error(`The following ${errors.length} JSDoer modules have errors: ${errors.map(error => error.name).join(', ')}`); | ||
} | ||
}); | ||
@@ -52,3 +74,5 @@ } | ||
const method = module.getMethod(config.method); | ||
const output = yield method(this.env, context, this.modules, config.parameters); | ||
const output = yield method(this.env, context, this.modules, config.parameters, { | ||
getModule: this.getModule, executeDoer: this.executeDoer | ||
}); | ||
return output; | ||
@@ -70,17 +94,27 @@ } | ||
} | ||
get errors() { return this._errors; } | ||
get path() { return this._path; } | ||
get code() { return this._code; } | ||
get exports() { return this.module.exports; } | ||
get main() { | ||
return (typeof this.module.exports === 'function' ? | ||
get exports() { | ||
return (this.module ? | ||
this.module.exports : | ||
typeof this.module.exports.main === 'function' ? | ||
this.module.exports.main : | ||
null); | ||
{}); | ||
} | ||
get main() { | ||
return (!this.module ? | ||
null : | ||
typeof this.module.exports === 'function' ? | ||
this.module.exports : | ||
typeof this.module.exports.main === 'function' ? | ||
this.module.exports.main : | ||
null); | ||
} | ||
get setup() { | ||
return (utilities_1.isObject(this.module.exports) && typeof this.module.exports.setup === 'function' ? | ||
this.module.exports.setup : | ||
null); | ||
return (!this.module ? | ||
null : | ||
utilities_1.isObject(this.module.exports) && typeof this.module.exports.setup === 'function' ? | ||
this.module.exports.setup : | ||
null); | ||
} | ||
get hasErrors() { return Object.keys(this._errors).length > 0; } | ||
get module() { | ||
@@ -91,2 +125,3 @@ if (!this._module) { | ||
this._module.paths = require.main.paths; | ||
this._module.path = this.path; | ||
this._module._compile(this.code, this.path); | ||
@@ -96,3 +131,2 @@ } | ||
this._errors.module = err; | ||
throw err; | ||
} | ||
@@ -112,6 +146,5 @@ } | ||
this._errors.name = err; | ||
throw err; | ||
} | ||
} | ||
return this._name; | ||
return this._name || this.path; | ||
} | ||
@@ -118,0 +151,0 @@ getMethod(name = 'main') { |
{ | ||
"name": "low", | ||
"version": "1.1.87", | ||
"version": "1.1.88", | ||
"description": "a templating driven low-code framework for rapid systems development", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "624e363d46e725f63fd1e28bebfe25ac2d153d0f", | ||
"gitHead": "93bee593919ef9efc187bab8523fd2ca55f2de5c", | ||
"devDependencies": { | ||
@@ -28,0 +28,0 @@ "@types/jest": "^24.9.0", |
@@ -14,2 +14,4 @@ import Module from 'module'; | ||
async setup() { | ||
const errors = []; | ||
for (const [name, code] of Object.entries(this.config)) { | ||
@@ -19,3 +21,8 @@ const newModule = new JSModule(name, code as string); | ||
this.modules[newModule.name] = newModule; | ||
if (newModule.hasErrors) errors.push(newModule); | ||
} | ||
if (errors.length > 0) { | ||
console.error(`The following ${errors.length} JSDoer modules have errors: ${errors.map(error => error.name).join(', ')}`); | ||
} | ||
} | ||
@@ -39,3 +46,5 @@ | ||
const method = module.getMethod(config.method); | ||
const output = await method(this.env, context, this.modules, config.parameters); | ||
const output = await method(this.env, context, this.modules, config.parameters, { | ||
getModule: this.getModule, executeDoer: this.executeDoer | ||
}); | ||
return output; | ||
@@ -47,2 +56,18 @@ } catch (err) { | ||
} | ||
getModule = <T>(modules: any, moduleName: string) => { | ||
const module = modules[moduleName]; | ||
if (!module) throw new Error(`No JSModule with the name '${moduleName}' has been loaded`); | ||
return module.exports as T; | ||
} | ||
executeDoer = async <T>(env: Environment, doerName: string, context: ConnectorContext<any>, coreConfig: T, runAsTask = false, metadata: any = {}) => { | ||
const doer = env.getDoer(doerName); | ||
const config = { name: `JSModule`, doer: doerName, config: coreConfig, metadata }; | ||
if (runAsTask) { | ||
return await doer.execute(context, config as TaskConfig); | ||
} else { | ||
return await doer.main(context, config as TaskConfig, coreConfig); | ||
} | ||
} | ||
} | ||
@@ -57,7 +82,18 @@ | ||
get errors() { return this._errors; } | ||
get path() { return this._path; } | ||
get code() { return this._code; } | ||
get exports() { return this.module.exports; } | ||
get exports() { | ||
return ( | ||
this.module ? | ||
this.module.exports : | ||
{} | ||
); | ||
} | ||
get main() { | ||
return ( | ||
!this.module ? | ||
null : | ||
typeof this.module.exports === 'function' ? | ||
@@ -73,2 +109,4 @@ this.module.exports : | ||
return ( | ||
!this.module ? | ||
null : | ||
isObject(this.module.exports) && typeof this.module.exports.setup === 'function' ? | ||
@@ -80,2 +118,4 @@ this.module.exports.setup : | ||
get hasErrors() { return Object.keys(this._errors).length > 0; } | ||
constructor(path: string, code: string) { | ||
@@ -91,6 +131,6 @@ this._path = path; | ||
this._module.paths = (require as any).main.paths; | ||
(this._module as any).path = this.path; | ||
(this._module as any)._compile(this.code, this.path); | ||
} catch (err) { | ||
this._errors.module = err as Error; | ||
throw err; | ||
} | ||
@@ -113,6 +153,5 @@ } | ||
this._errors.name = err as Error; | ||
throw err; | ||
} | ||
} | ||
return this._name; | ||
return this._name || this.path; | ||
} | ||
@@ -127,4 +166,9 @@ | ||
export type JSModuleFunction = (env: Environment, context: ConnectorContext<any>, modules: IMap<JSModule>, parameters: any) => Promise<any>; | ||
export type JSModuleFunction = (env: Environment, context: ConnectorContext<any>, modules: IMap<JSModule>, parameters: any, utilities: JSModuleUtilities) => Promise<any>; | ||
export interface JSModuleUtilities { | ||
getModule: <T>(modules: any, moduleName: string) => JSModule; | ||
executeDoer: <T>(env: Environment, doerName: string, context: ConnectorContext<any>, coreConfig: T, runAsTask: boolean, metadata: any) => Promise<any> | ||
} | ||
export interface JSTask { | ||
@@ -131,0 +175,0 @@ module: string; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
523401
5075