@forrestjs/core
Advanced tools
Comparing version 5.0.0-alpha.24 to 5.0.0-alpha.25
{ | ||
"name": "@forrestjs/core", | ||
"description": "ForrestJS is the Javascript plugin syste.", | ||
"version": "5.0.0-alpha.24", | ||
"version": "5.0.0-alpha.25", | ||
"main": "src/index.js", | ||
@@ -36,3 +36,3 @@ "types": "types/index.d.ts", | ||
}, | ||
"gitHead": "efb95cf450fad6505d5e54559806b23a35759cd7", | ||
"gitHead": "581a5821c64a13664597849613c5ee7207a1e1e0", | ||
"devDependencies": { | ||
@@ -39,0 +39,0 @@ "jest": "^28.1.0", |
181
src/index.js
@@ -12,3 +12,3 @@ const { traceHook, logTrace, logBoot } = require('./tracer'); | ||
* @param {string} key | ||
* @param {?any} defaultValue | ||
* @param {any} [defaultValue] | ||
* @returns {any} | ||
@@ -18,13 +18,83 @@ */ | ||
/** | ||
* @callback ForrestJSSetter | ||
* @param {string} key | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
/** | ||
* @callback ForrestJSRegisterTargets | ||
* @param {Object} targets | ||
* @returns {void} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSExtensionLog | ||
* @property {name} string | ||
* @property {hook} string | ||
* @property {priority} number | ||
* @property {trace} any | ||
* @property {boolean} enabled | ||
* @property {optional} enabled | ||
* @property {function} handler | ||
* @property {logLevel} string | ||
* @property {Object} meta | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSActionLog | ||
* @property {any} args | ||
* @property {ForrestJSContext} context | ||
* @property {string} mode | ||
* @property {function} onError | ||
* @property {function} onItemError | ||
* @property {any} trace | ||
*/ | ||
/** | ||
* @callback ForrestJSCreateSyncExtension | ||
* @param {String} target | ||
* @param {Object} params | ||
* @returns {Array.<any, ForrestJSExtensionLog, ForrestJSActionLog>} | ||
*/ | ||
/** | ||
* @callback ForrestJSCreateAsycExtension | ||
* @param {String} target | ||
* @param {Object} params | ||
* @returns {Promise} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSCreateExtension | ||
* @property {ForrestJSCreateSyncExtension} sync | ||
* @property {ForrestJSCreateSyncExtension} waterfall | ||
* @property {ForrestJSCreateAsycExtension} serie | ||
* @property {ForrestJSCreateAsycExtension} parallel | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSLogger | ||
* @property {function} error | ||
* @property {function} warn | ||
* @property {function} info | ||
* @property {function} http | ||
* @property {function} verbose | ||
* @property {function} debug | ||
* @property {function} silly | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSContext | ||
* @property {ForrestJSLogger} log | ||
* @property {ForrestJSGetter} getConfig | ||
* @property {() => void} setConfig | ||
* @property {ForrestJSSetter} setConfig | ||
* @property {ForrestJSGetter} getContext | ||
* @property {() => void} setContext | ||
* @property {ForrestJSSetter} setContext | ||
* @property {ForrestJSRegisterTargets} registerTargets | ||
* @property {ForrestJSCreateExtension} createExtension | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSExtension | ||
* @property {string} target | ||
* @property {() => vlid} handler | ||
* @interface ForrestJSParams | ||
*/ | ||
@@ -34,10 +104,24 @@ | ||
* @callback ForrestJSHandler | ||
* @param {ForrestJSContext} target | ||
* @returns {Array.ForrestJSExtension} | ||
* @param {ForrestJSParams} params | ||
* @param {ForrestJSContext} context | ||
* @returns {any} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSExtension | ||
* @property {string} target | ||
* @property {ForrestJSHandler} handler | ||
* @property {boolean} [enabled] | ||
* @property {boolean} [optional] | ||
* @property {string} [name] | ||
* @property {string} [trace] | ||
* @property {string} [logLevel] | ||
* @property {Object} [meta] | ||
* @property {number} [priority] | ||
*/ | ||
/** | ||
* @callback ForrestJSService | ||
* @param {ForrestJSContext} target | ||
* @returns {Array.ForrestJSExtension} | ||
* @param {ForrestJSContext} context | ||
* @returns {ForrestJSExtension|Array.<ForrestJSExtension>} | ||
*/ | ||
@@ -47,4 +131,4 @@ | ||
* @callback ForrestJSFeature | ||
* @param {Object} target | ||
* @returns {Array.ForrestJSExtension} | ||
* @param {ForrestJSContext} context | ||
* @returns {ForrestJSExtension|Array.<ForrestJSExtension>} | ||
*/ | ||
@@ -54,8 +138,8 @@ | ||
* @typedef {Object} ForrestJSAppManifest | ||
* @property {Array.ForrestJSService} services | ||
* @property {Array.ForrestJSFeature} features | ||
* @property {Object} settings | ||
* @property {Object} context | ||
* @property {string|null} trace | ||
* @property {string} logLevel | ||
* @property {Array.<ForrestJSService|ForrestJSExtension>} [services = []] | ||
* @property {Array.<ForrestJSFeature|ForrestJSExtension>} [features = []] | ||
* @property {Object} [settings = {}] | ||
* @property {Object} [context = {}] | ||
* @property {string|null} [trace] | ||
* @property {string} [logLevel = 'info'] | ||
*/ | ||
@@ -69,3 +153,2 @@ | ||
*/ | ||
const run = ({ | ||
@@ -90,35 +173,39 @@ services = [], | ||
exports.run = run; | ||
exports.default = run; | ||
module.exports = run; | ||
module.exports.run = run; | ||
// exports.run = run; | ||
// exports.run.run = run; | ||
// // exports.default = run; | ||
// Export global API: | ||
exports.createApp = createApp; | ||
exports.startApp = startApp; | ||
exports.traceHook = traceHook; | ||
exports.logTrace = logTrace; | ||
exports.logBoot = logBoot; | ||
exports.createAction = createAction; | ||
exports.registerAction = registerAction; | ||
exports.getTarget = getTarget; | ||
exports.createExtension = createExtension; | ||
module.exports.createApp = createApp; | ||
module.exports.startApp = startApp; | ||
module.exports.traceHook = traceHook; | ||
module.exports.logTrace = logTrace; | ||
module.exports.logBoot = logBoot; | ||
module.exports.createAction = createAction; | ||
module.exports.registerAction = registerAction; | ||
module.exports.getTarget = getTarget; | ||
module.exports.createExtension = createExtension; | ||
// Export the internal constants: | ||
exports.CORE = constants.CORE; | ||
exports.BOOT = constants.BOOT; | ||
exports.SERVICE = constants.SERVICE; | ||
exports.FEATURE = constants.FEATURE; | ||
exports.SYMBOLS = constants.SYMBOLS; | ||
exports.SEPARATOR = constants.SEPARATOR; | ||
exports.START = constants.START; | ||
exports.SETTINGS = constants.SETTINGS; | ||
exports.INIT_SERVICE = constants.INIT_SERVICE; | ||
exports.INIT_SERVICES = constants.INIT_SERVICES; | ||
exports.INIT_FEATURE = constants.INIT_FEATURE; | ||
exports.INIT_FEATURES = constants.INIT_FEATURES; | ||
exports.START_SERVICE = constants.START_SERVICE; | ||
exports.START_SERVICES = constants.START_SERVICES; | ||
exports.START_FEATURE = constants.START_FEATURE; | ||
exports.START_FEATURES = constants.START_FEATURES; | ||
exports.FINISH = constants.FINISH; | ||
module.exports.CORE = constants.CORE; | ||
module.exports.BOOT = constants.BOOT; | ||
module.exports.SERVICE = constants.SERVICE; | ||
module.exports.FEATURE = constants.FEATURE; | ||
module.exports.SYMBOLS = constants.SYMBOLS; | ||
module.exports.SEPARATOR = constants.SEPARATOR; | ||
module.exports.START = constants.START; | ||
module.exports.SETTINGS = constants.SETTINGS; | ||
module.exports.INIT_SERVICE = constants.INIT_SERVICE; | ||
module.exports.INIT_SERVICES = constants.INIT_SERVICES; | ||
module.exports.INIT_FEATURE = constants.INIT_FEATURE; | ||
module.exports.INIT_FEATURES = constants.INIT_FEATURES; | ||
module.exports.START_SERVICE = constants.START_SERVICE; | ||
module.exports.START_SERVICES = constants.START_SERVICES; | ||
module.exports.START_FEATURE = constants.START_FEATURE; | ||
module.exports.START_FEATURES = constants.START_FEATURES; | ||
module.exports.FINISH = constants.FINISH; | ||
// module.exports = startApp; |
@@ -1,65 +0,118 @@ | ||
export default run; | ||
export type ForrestJSGetter = (key: string, defaultValue: any | null) => any; | ||
export type ForrestJSContext = { | ||
getConfig: ForrestJSGetter; | ||
setConfig: () => void; | ||
getContext: ForrestJSGetter; | ||
setContext: () => void; | ||
}; | ||
export type ForrestJSExtension = { | ||
target: string; | ||
handler: () => vlid; | ||
}; | ||
export type ForrestJSHandler = (target: ForrestJSContext) => Array.ForrestJSExtension; | ||
export type ForrestJSService = (target: ForrestJSContext) => Array.ForrestJSExtension; | ||
export type ForrestJSFeature = (target: any) => Array.ForrestJSExtension; | ||
export type ForrestJSAppManifest = { | ||
services: Array.ForrestJSService; | ||
features: Array.ForrestJSFeature; | ||
settings: any; | ||
context: any; | ||
trace: string | null; | ||
logLevel: string; | ||
}; | ||
export = run; | ||
/** | ||
* @callback ForrestJSGetter | ||
* @param {string} key | ||
* @param {?any} defaultValue | ||
* @param {any} [defaultValue] | ||
* @returns {any} | ||
*/ | ||
/** | ||
* @callback ForrestJSSetter | ||
* @param {string} key | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
/** | ||
* @callback ForrestJSRegisterTargets | ||
* @param {Object} targets | ||
* @returns {void} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSExtensionLog | ||
* @property {name} string | ||
* @property {hook} string | ||
* @property {priority} number | ||
* @property {trace} any | ||
* @property {boolean} enabled | ||
* @property {optional} enabled | ||
* @property {function} handler | ||
* @property {logLevel} string | ||
* @property {Object} meta | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSActionLog | ||
* @property {any} args | ||
* @property {ForrestJSContext} context | ||
* @property {string} mode | ||
* @property {function} onError | ||
* @property {function} onItemError | ||
* @property {any} trace | ||
*/ | ||
/** | ||
* @callback ForrestJSCreateSyncExtension | ||
* @param {String} target | ||
* @param {Object} params | ||
* @returns {Array.<any, ForrestJSExtensionLog, ForrestJSActionLog>} | ||
*/ | ||
/** | ||
* @callback ForrestJSCreateAsycExtension | ||
* @param {String} target | ||
* @param {Object} params | ||
* @returns {Promise} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSCreateExtension | ||
* @property {ForrestJSCreateSyncExtension} sync | ||
* @property {ForrestJSCreateSyncExtension} waterfall | ||
* @property {ForrestJSCreateAsycExtension} serie | ||
* @property {ForrestJSCreateAsycExtension} parallel | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSLogger | ||
* @property {function} error | ||
* @property {function} warn | ||
* @property {function} info | ||
* @property {function} http | ||
* @property {function} verbose | ||
* @property {function} debug | ||
* @property {function} silly | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSContext | ||
* @property {ForrestJSGetter} getConfig | ||
* @property {() => void} setConfig | ||
* @property {ForrestJSSetter} setConfig | ||
* @property {ForrestJSGetter} getContext | ||
* @property {() => void} setContext | ||
* @property {ForrestJSSetter} setContext | ||
* @property {ForrestJSRegisterTargets} registerTargets | ||
* @property {ForrestJSCreateExtension} createExtension | ||
* @property {ForrestJSLogger} log | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSExtension | ||
* @property {string} target | ||
* @property {() => vlid} handler | ||
* @interface ForrestJSParams | ||
*/ | ||
/** | ||
* @callback ForrestJSHandler | ||
* @param {ForrestJSContext} target | ||
* @returns {Array.ForrestJSExtension} | ||
* @param {ForrestJSParams} params | ||
* @param {ForrestJSContext} context | ||
* @returns {any} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSExtension | ||
* @property {string} target | ||
* @property {ForrestJSHandler} handler | ||
* @property {boolean} [enabled] | ||
* @property {boolean} [optional] | ||
* @property {string} [name] | ||
* @property {string} [trace] | ||
* @property {string} [logLevel] | ||
* @property {Object} [meta] | ||
* @property {number} [priority] | ||
*/ | ||
/** | ||
* @callback ForrestJSService | ||
* @param {ForrestJSContext} target | ||
* @returns {Array.ForrestJSExtension} | ||
* @param {ForrestJSContext} context | ||
* @returns {ForrestJSExtension|Array.<ForrestJSExtension>} | ||
*/ | ||
/** | ||
* @callback ForrestJSFeature | ||
* @param {Object} target | ||
* @returns {Array.ForrestJSExtension} | ||
* @param {ForrestJSContext} context | ||
* @returns {ForrestJSExtension|Array.<ForrestJSExtension>} | ||
*/ | ||
/** | ||
* @typedef {Object} ForrestJSAppManifest | ||
* @property {Array.ForrestJSService} services | ||
* @property {Array.ForrestJSFeature} features | ||
* @property {Object} settings | ||
* @property {Object} context | ||
* @property {string|null} trace | ||
* @property {string} logLevel | ||
* @property {Array.<ForrestJSService|ForrestJSExtension>} [services = []] | ||
* @property {Array.<ForrestJSFeature|ForrestJSExtension>} [features = []] | ||
* @property {Object} [settings = {}] | ||
* @property {Object} [context = {}] | ||
* @property {string|null} [trace] | ||
* @property {string} [logLevel = 'info'] | ||
*/ | ||
@@ -72,3 +125,14 @@ /** | ||
*/ | ||
export function run({ services, features, settings, context, trace, logLevel, }?: ForrestJSAppManifest): Promise<any>; | ||
declare function run({ services, features, settings, context, trace, logLevel, }?: ForrestJSAppManifest): Promise<any>; | ||
declare namespace run { | ||
export { run, createApp, startApp, traceHook, logTrace, logBoot, createAction, registerAction, getTarget, createExtension, CORE, BOOT, SERVICE, FEATURE, SYMBOLS, SEPARATOR, START, SETTINGS, INIT_SERVICE, INIT_SERVICES, INIT_FEATURE, INIT_FEATURES, START_SERVICE, START_SERVICES, START_FEATURE, START_FEATURES, FINISH, ForrestJSGetter, ForrestJSSetter, ForrestJSRegisterTargets, ForrestJSExtensionLog, ForrestJSActionLog, ForrestJSCreateSyncExtension, ForrestJSCreateAsycExtension, ForrestJSCreateExtension, ForrestJSLogger, ForrestJSContext, ForrestJSHandler, ForrestJSExtension, ForrestJSService, ForrestJSFeature, ForrestJSAppManifest }; | ||
} | ||
type ForrestJSAppManifest = { | ||
services?: Array<ForrestJSService | ForrestJSExtension>; | ||
features?: Array<ForrestJSFeature | ForrestJSExtension>; | ||
settings?: any; | ||
context?: any; | ||
trace?: string | null; | ||
logLevel?: string; | ||
}; | ||
import { createApp } from "./create-app"; | ||
@@ -82,2 +146,60 @@ import { startApp } from "./create-app"; | ||
import { createExtension } from "./create-extension"; | ||
export { createApp, startApp, traceHook, logTrace, logBoot, createAction, registerAction, getTarget, createExtension, CORE, BOOT, SERVICE, FEATURE, SYMBOLS, SEPARATOR, START, SETTINGS, INIT_SERVICE, INIT_SERVICES, INIT_FEATURE, INIT_FEATURES, START_SERVICE, START_SERVICES, START_FEATURE, START_FEATURES, FINISH }; | ||
type ForrestJSGetter = (key: string, defaultValue?: any) => any; | ||
type ForrestJSSetter = (key: string, value: any) => any; | ||
type ForrestJSRegisterTargets = (targets: any) => void; | ||
type ForrestJSExtensionLog = { | ||
string: void; | ||
number: priority; | ||
any: trace; | ||
enabled: boolean; | ||
handler: Function; | ||
meta: any; | ||
}; | ||
type ForrestJSActionLog = { | ||
args: any; | ||
context: ForrestJSContext; | ||
mode: string; | ||
onError: Function; | ||
onItemError: Function; | ||
trace: any; | ||
}; | ||
type ForrestJSCreateSyncExtension = (target: string, params: any) => Array<any, ForrestJSExtensionLog, ForrestJSActionLog>; | ||
type ForrestJSCreateAsycExtension = (target: string, params: any) => Promise<any>; | ||
type ForrestJSCreateExtension = { | ||
sync: ForrestJSCreateSyncExtension; | ||
waterfall: ForrestJSCreateSyncExtension; | ||
serie: ForrestJSCreateAsycExtension; | ||
parallel: ForrestJSCreateAsycExtension; | ||
}; | ||
type ForrestJSLogger = { | ||
error: Function; | ||
warn: Function; | ||
info: Function; | ||
http: Function; | ||
verbose: Function; | ||
debug: Function; | ||
silly: Function; | ||
}; | ||
type ForrestJSContext = { | ||
getConfig: ForrestJSGetter; | ||
setConfig: ForrestJSSetter; | ||
getContext: ForrestJSGetter; | ||
setContext: ForrestJSSetter; | ||
registerTargets: ForrestJSRegisterTargets; | ||
createExtension: ForrestJSCreateExtension; | ||
log: ForrestJSLogger; | ||
}; | ||
type ForrestJSHandler = (params: ForrestJSParams, context: ForrestJSContext) => any; | ||
type ForrestJSExtension = { | ||
target: string; | ||
handler: ForrestJSHandler; | ||
enabled?: boolean; | ||
optional?: boolean; | ||
name?: string; | ||
trace?: string; | ||
logLevel?: string; | ||
meta?: any; | ||
priority?: number; | ||
}; | ||
type ForrestJSService = (context: ForrestJSContext) => ForrestJSExtension | Array<ForrestJSExtension>; | ||
type ForrestJSFeature = (context: ForrestJSContext) => ForrestJSExtension | Array<ForrestJSExtension>; |
54379
1560