@bettercorp/service-base
Advanced tools
Comparing version 8.5.2-rc.0 to 9.0.0
@@ -10,1 +10,2 @@ export { SecConfig } from "./interfaces/serviceConfig"; | ||
export { ServicesClient } from "./service/serviceClient"; | ||
export { GenericClient } from "./clients/service-generic/plugin"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ServicesClient = exports.ServicesBase = exports.LoggerBase = exports.EventsBase = exports.ConfigBase = exports.SecConfig = void 0; | ||
exports.GenericClient = exports.ServicesClient = exports.ServicesBase = exports.LoggerBase = exports.EventsBase = exports.ConfigBase = exports.SecConfig = void 0; | ||
var serviceConfig_1 = require("./interfaces/serviceConfig"); | ||
@@ -16,2 +16,4 @@ Object.defineProperty(exports, "SecConfig", { enumerable: true, get: function () { return serviceConfig_1.SecConfig; } }); | ||
Object.defineProperty(exports, "ServicesClient", { enumerable: true, get: function () { return serviceClient_1.ServicesClient; } }); | ||
var plugin_1 = require("./clients/service-generic/plugin"); | ||
Object.defineProperty(exports, "GenericClient", { enumerable: true, get: function () { return plugin_1.GenericClient; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -11,7 +11,3 @@ /// <reference types="node" /> | ||
export type DynamicallyReferencedMethodEmitIEvents<Interface extends DynamicallyReferencedMethodBase, Method extends string> = Interface[Method] extends (...a: infer Arguments) => infer Return ? [event: Method, ...a: Arguments] : [noMatchingEvent: never]; | ||
export type DynamicallyReferencedMethodEmitEARIEvents<Interface extends DynamicallyReferencedMethodBase, Method extends string, ArgsReference extends boolean = true, ShowTimeout extends boolean = true> = ArgsReference extends true ? Interface[Method] extends (...a: infer Arguments) => infer Return ? ShowTimeout extends true ? [ | ||
event: Method, | ||
timeoutSeconds?: number, | ||
...a: Arguments | ||
] : [event: Method, ...a: Arguments] : [event: Method, noMatchingEvent: never] : Interface[Method] extends (...a: infer Arguments) => infer Return ? Return extends Promise<unknown> ? Return : Promise<Return> : Promise<never>; | ||
export type DynamicallyReferencedMethodEmitEARIEvents<Interface extends DynamicallyReferencedMethodBase, Method extends string, ArgsReference extends boolean = true, ShowTimeout extends boolean = true> = ArgsReference extends true ? Interface[Method] extends (...a: infer Arguments) => infer Return ? ShowTimeout extends true ? [event: Method, timeoutSeconds?: number, ...a: Arguments] : [event: Method, ...a: Arguments] : [event: Method, noMatchingEvent: never] : Interface[Method] extends (...a: infer Arguments) => infer Return ? Return extends Promise<unknown> ? Return : Promise<Return> : Promise<never>; | ||
export interface IServiceEvents<onEvents, emitEvents, onReturnableEvents, emitReturnableEvents, onBroadcast, emitBroadcast> { | ||
@@ -21,8 +17,8 @@ onBroadcast<TA extends string>(...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<onBroadcast>, TA, false>): Promise<void>; | ||
onEvent<TA extends string>(...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<onEvents>, TA, false>): Promise<void>; | ||
emitEvent<TA extends string>(...args: DynamicallyReferencedMethodEmitIEvents<DynamicallyReferencedMethodType<emitEvents>, TA>): Promise<void>; | ||
onEventSpecific<TA extends string>(serverId: string, ...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<onEvents>, TA, false>): Promise<void>; | ||
emitEvent<TA extends string>(...args: DynamicallyReferencedMethodEmitIEvents<DynamicallyReferencedMethodType<emitEvents>, TA>): Promise<void>; | ||
emitEventSpecific<TA extends string>(serverId: string, ...args: DynamicallyReferencedMethodEmitIEvents<DynamicallyReferencedMethodType<emitEvents>, TA>): Promise<void>; | ||
onReturnableEvent<TA extends string>(...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<onReturnableEvents>, TA, true>): Promise<void>; | ||
emitEventAndReturn<TA extends string>(...args: DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<emitReturnableEvents>, TA, true, false>): DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<onReturnableEvents>, TA, false>; | ||
onReturnableEventSpecific<TA extends string>(serverId: string, ...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<onReturnableEvents>, TA, true>): Promise<void>; | ||
emitEventAndReturn<TA extends string>(...args: DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<emitReturnableEvents>, TA, true, false>): DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<onReturnableEvents>, TA, false>; | ||
emitEventAndReturnSpecific<TA extends string>(serverId: string, ...args: DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<emitReturnableEvents>, TA, true, false>): DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<onReturnableEvents>, TA, false>; | ||
@@ -29,0 +25,0 @@ emitEventAndReturnTimed<TA extends string>(...args: DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<emitReturnableEvents>, TA, true, true>): DynamicallyReferencedMethodEmitEARIEvents<DynamicallyReferencedMethodType<onReturnableEvents>, TA, false>; |
@@ -30,2 +30,3 @@ "use strict"; | ||
const config_1 = require("../../config/config"); | ||
const yaml_1 = require("yaml"); | ||
class Config extends config_1.ConfigBase { | ||
@@ -79,10 +80,11 @@ constructor(pluginName, cwd, pluginCwd, log, deploymentProfile) { | ||
if (fs.existsSync(this._secConfigFilePath)) { | ||
defConfig = JSON.parse(fs.readFileSync(this._secConfigFilePath, "utf8").toString()); | ||
defConfig.plugins = defConfig.plugins || {}; | ||
defConfig.deploymentProfiles = defConfig.deploymentProfiles || {}; | ||
let tdefConfig = (0, yaml_1.parse)(fs.readFileSync(this._secConfigFilePath, "utf8").toString()) ?? | ||
{}; | ||
defConfig.plugins = tdefConfig.plugins ?? {}; | ||
defConfig.deploymentProfiles = tdefConfig.deploymentProfiles ?? {}; | ||
defConfig.deploymentProfiles.default = | ||
defConfig.deploymentProfiles.default || {}; | ||
defConfig.deploymentProfiles.default ?? {}; | ||
} | ||
else { | ||
await this.log.debug("! sec.config.json CAN`T BE FOUND ... we will try create one / work in memory! {secFile}", { secFile: this._secConfigFilePath }); | ||
await this.log.debug("! sec.config.yaml CAN`T BE FOUND ... we will try create one / work in memory! {secFile}", { secFile: this._secConfigFilePath }); | ||
} | ||
@@ -102,3 +104,3 @@ let existingDefinedPlugins = Object.keys(defConfig.deploymentProfiles.default); | ||
fs.accessSync(this._secConfigFilePath, fs.constants.W_OK); | ||
fs.writeFileSync(this._secConfigFilePath, JSON.stringify(this._appConfig, "", 2)); | ||
fs.writeFileSync(this._secConfigFilePath, (0, yaml_1.stringify)(this._appConfig)); | ||
this._canWriteChanges = true; | ||
@@ -124,3 +126,3 @@ } | ||
} | ||
fs.writeFileSync(this._secConfigFilePath, JSON.stringify(this._appConfig, "", 2)); | ||
fs.writeFileSync(this._secConfigFilePath, (0, yaml_1.stringify)(this._appConfig)); | ||
} | ||
@@ -127,0 +129,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
process.env.BSB_SEC_JSON || | ||
"./sec.config.json", | ||
"./sec.config.yaml", | ||
}; | ||
@@ -13,0 +13,0 @@ } |
@@ -17,3 +17,3 @@ /// <reference types="node" /> | ||
run(): Promise<void>; | ||
registerPluginClient<pluginClientOnEvents, pluginClientEmitEvents, pluginClientOnReturnableEvents, pluginClientEmitReturnableEvents, pluginCallableMethods, pluginClientConfigType extends IPluginConfig, pluginClientOnBroadcast, pluginClientEmitBroadcast>(pluginName: string): Promise<RegisteredPlugin<pluginClientOnEvents, pluginClientEmitEvents, pluginClientOnReturnableEvents, pluginClientEmitReturnableEvents, pluginCallableMethods, pluginClientConfigType, pluginClientOnBroadcast, pluginClientEmitBroadcast>>; | ||
initPluginClient<pluginClientOnEvents, pluginClientEmitEvents, pluginClientOnReturnableEvents, pluginClientEmitReturnableEvents, pluginCallableMethods, pluginClientConfigType extends IPluginConfig, pluginClientOnBroadcast, pluginClientEmitBroadcast>(pluginName: string): Promise<RegisteredPlugin<pluginClientOnEvents, pluginClientEmitEvents, pluginClientOnReturnableEvents, pluginClientEmitReturnableEvents, pluginCallableMethods, pluginClientConfigType, pluginClientOnBroadcast, pluginClientEmitBroadcast>>; | ||
protected _clients: Array<ServicesClient>; | ||
@@ -20,0 +20,0 @@ constructor(pluginName: string, cwd: string, pluginCwd: string, log: IPluginLogger); |
@@ -8,3 +8,3 @@ "use strict"; | ||
async run() { } | ||
registerPluginClient(pluginName) { | ||
initPluginClient(pluginName) { | ||
throw static_1.ErrorMessages.BSBNotInit; | ||
@@ -11,0 +11,0 @@ } |
@@ -15,4 +15,4 @@ /// <reference types="node" /> | ||
onEvent<TA extends string>(...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<emitEvents>, TA, false>): Promise<void>; | ||
emitEvent<TA extends string>(...args: DynamicallyReferencedMethodEmitIEvents<DynamicallyReferencedMethodType<onEvents>, TA>): Promise<void>; | ||
onEventSpecific<TA extends string>(serverId: string, ...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<emitEvents>, TA, false>): Promise<void>; | ||
emitEvent<TA extends string>(...args: DynamicallyReferencedMethodEmitIEvents<DynamicallyReferencedMethodType<onEvents>, TA>): Promise<void>; | ||
emitEventSpecific<TA extends string>(serverId: string, ...args: DynamicallyReferencedMethodEmitIEvents<DynamicallyReferencedMethodType<onEvents>, TA>): Promise<void>; | ||
@@ -28,3 +28,3 @@ onReturnableEvent<TA extends string>(...args: DynamicallyReferencedMethodOnIEvents<DynamicallyReferencedMethodType<emitReturnableEvents>, TA, true>): Promise<void>; | ||
export declare class ServicesClient<onEvents = ServiceEvents, emitEvents = ServiceEvents, onReturnableEvents = ServiceReturnableEvents, emitReturnableEvents = ServiceReturnableEvents, callableMethods = ServiceCallable, onBroadcast = ServiceBroadcasts, emitBroadcast = ServiceBroadcasts> { | ||
readonly _pluginName: string; | ||
readonly pluginName: string; | ||
readonly initBeforePlugins?: Array<string>; | ||
@@ -36,4 +36,5 @@ readonly initAfterPlugins?: Array<string>; | ||
protected _plugin: RegisteredPlugin<onEvents, emitEvents, onReturnableEvents, emitReturnableEvents, callableMethods, any, onBroadcast, emitBroadcast>; | ||
protected _register(): Promise<void>; | ||
_init(): Promise<void>; | ||
init(): Promise<void>; | ||
constructor(self: ServicesBase<any, any, any>); | ||
} |
@@ -6,2 +6,3 @@ "use strict"; | ||
const static_1 = require("../interfaces/static"); | ||
const tools_1 = require("@bettercorp/tools"); | ||
class RegisteredPlugin extends base_1.DefaultBase { | ||
@@ -23,6 +24,6 @@ receiveStream(listener, timeoutSeconds) { | ||
} | ||
onEventSpecific(serverId, ...args) { | ||
emitEvent(...args) { | ||
throw static_1.ErrorMessages.BSBNotInit; | ||
} | ||
emitEvent(...args) { | ||
onEventSpecific(serverId, ...args) { | ||
throw static_1.ErrorMessages.BSBNotInit; | ||
@@ -57,3 +58,6 @@ } | ||
class ServicesClient { | ||
async _register() { | ||
async _init() { | ||
if (!tools_1.Tools.isString(this.pluginName) || this.pluginName === "") { | ||
throw 'pluginName is not set in this client. Please update the clients definition '; | ||
} | ||
this._referencedPlugin.initBeforePlugins = (this._referencedPlugin.initBeforePlugins || []).concat(this.initBeforePlugins || []); | ||
@@ -64,5 +68,7 @@ this._referencedPlugin.initAfterPlugins = (this._referencedPlugin.initAfterPlugins || []).concat(this.initAfterPlugins || []); | ||
if (this._plugin === undefined) { | ||
this._plugin = await this._referencedPlugin.registerPluginClient(this._pluginName); | ||
this._plugin = await this._referencedPlugin.initPluginClient(this.pluginName); | ||
} | ||
} | ||
async init() { | ||
} | ||
constructor(self) { | ||
@@ -69,0 +75,0 @@ this._referencedPlugin = self; |
@@ -37,3 +37,3 @@ "use strict"; | ||
SBBase.setupServicePluginSpecific(plugin, events); | ||
plugin.registerPluginClient = async (pluginName) => { | ||
plugin.initPluginClient = async (pluginName) => { | ||
let mappedPluginName = await config.getAppPluginMappedName(pluginName); | ||
@@ -40,0 +40,0 @@ await log.debug("Registering new plugin client in {callerPlugin} for {pluginName} as {mappedPluginName}", { |
@@ -6,2 +6,3 @@ import { IPluginLogger } from "../interfaces/logger"; | ||
private static findPluginsFiles; | ||
private static findDependentPlugins; | ||
private static findPluginsInBase; | ||
@@ -8,0 +9,0 @@ static findNPMPlugins(coreLogger: IPluginLogger, cwd: string): Promise<Array<IReadyPlugin>>; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const service_1 = require("../interfaces/service"); | ||
const tools_1 = require("@bettercorp/tools"); | ||
class SBPlugins { | ||
@@ -72,3 +73,42 @@ static getPluginType(name) { | ||
} | ||
static async findPluginsInBase(coreLogger, path, libOnly = false) { | ||
static async findDependentPlugins(plugin, coreLogger, pluginJson, npmPluginsDir, knownDependencies = {}) { | ||
let arrOfPlugins = []; | ||
for (let dependency of Object.keys(pluginJson.dependencies || {})) { | ||
if (knownDependencies[dependency] !== undefined) { | ||
await coreLogger.info(`FIND: CHECK [{plugin}] DEPENDENCY [{dependency}] IGNORED BECAUSE [{reason}]`, { | ||
dependency, | ||
plugin, | ||
reason: knownDependencies[dependency] === true ? "EXISTS" : "INVALID", | ||
}); | ||
continue; | ||
} | ||
await coreLogger.info(`FIND: CHECK [{plugin}] DEPENDENCY [{dependency}]`, { dependency, plugin }); | ||
let path = dependency.split("/"); | ||
let dependencyPath = (0, path_1.join)(npmPluginsDir, ...path); | ||
await coreLogger.debug(`FIND: CHECK [{dependency}] {dependencyPath}`, { | ||
dependency, | ||
dependencyPath, | ||
}); | ||
if ((0, fs_1.statSync)(dependencyPath).isDirectory()) { | ||
let response = await SBPlugins.findPluginsInBase(coreLogger, dependencyPath, true, npmPluginsDir, knownDependencies); | ||
if (tools_1.Tools.isArray(response)) { | ||
knownDependencies[dependency] = false; | ||
arrOfPlugins = arrOfPlugins.concat(response); | ||
} | ||
else { | ||
knownDependencies[dependency] = response.plugins.length > 0; | ||
arrOfPlugins = arrOfPlugins.concat(response.plugins); | ||
knownDependencies = { | ||
...knownDependencies, | ||
...(response.knownDependencies ?? {}), | ||
}; | ||
} | ||
} | ||
} | ||
return { | ||
plugins: arrOfPlugins, | ||
knownDependencies: knownDependencies, | ||
}; | ||
} | ||
static async findPluginsInBase(coreLogger, path, libOnly = false, findLinkedPluginsNpmDir, knownDependencies) { | ||
const pluginJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(path, "./package.json"), "utf8").toString()); | ||
@@ -97,12 +137,22 @@ if (pluginJson.bsb_project !== true) { | ||
const packageVersion = pluginJson.version; | ||
return await SBPlugins.findPluginsFiles(coreLogger, innerPluginLibPlugin, packageVersion, libOnly, path); | ||
let returnableListOfPlugins = await SBPlugins.findPluginsFiles(coreLogger, innerPluginLibPlugin, packageVersion, libOnly, path); | ||
if (tools_1.Tools.isString(findLinkedPluginsNpmDir)) { | ||
let response = await SBPlugins.findDependentPlugins(pluginJson.name, coreLogger, pluginJson, findLinkedPluginsNpmDir, knownDependencies); | ||
returnableListOfPlugins = returnableListOfPlugins.concat(response.plugins); | ||
return { | ||
plugins: returnableListOfPlugins, | ||
knownDependencies: response.knownDependencies ?? {}, | ||
}; | ||
} | ||
return returnableListOfPlugins; | ||
} | ||
static async findNPMPlugins(coreLogger, cwd) { | ||
let arrOfPlugins = []; | ||
if (!(0, fs_1.existsSync)((0, path_1.join)(cwd, "./package.json"))) { | ||
const pkgJsonFile = (0, path_1.join)(cwd, "./package.json"); | ||
if (!(0, fs_1.existsSync)(pkgJsonFile)) { | ||
await coreLogger.error(`Unable to find package.json in {pakDir}`, { | ||
pakDir: (0, path_1.join)(cwd, "./package.json"), | ||
pakDir: pkgJsonFile, | ||
}); | ||
return []; | ||
} | ||
const pluginJson = JSON.parse((0, fs_1.readFileSync)(pkgJsonFile, "utf8").toString()); | ||
const npmPluginsDir = (0, path_1.join)(cwd, "./node_modules"); | ||
@@ -116,40 +166,33 @@ await coreLogger.info(`FIND: NPM plugins in: {npmPluginsDir}`, { | ||
} | ||
for (const dirFileWhat of (0, fs_1.readdirSync)(npmPluginsDir)) { | ||
const knownDependenciesCacheFile = (0, path_1.join)(npmPluginsDir, "./.bsb-known-dependencies.json"); | ||
let arrOfPlugins = []; | ||
if ((0, fs_1.existsSync)(knownDependenciesCacheFile)) { | ||
try { | ||
const pluginPath = (0, path_1.join)(npmPluginsDir, dirFileWhat); | ||
if (dirFileWhat.indexOf(".") === 0) { | ||
continue; | ||
} | ||
if (dirFileWhat.indexOf("@") === 0) { | ||
await coreLogger.debug(`FIND: GROUP [{dirFileWhat}] {pluginPath}`, { | ||
dirFileWhat, | ||
pluginPath, | ||
}); | ||
for (const groupPluginName of (0, fs_1.readdirSync)(pluginPath)) { | ||
if (groupPluginName.indexOf(".") === 0) { | ||
let knownDependencies = JSON.parse((0, fs_1.readFileSync)(knownDependenciesCacheFile, "utf8").toString()); | ||
if (Object.keys(knownDependencies).length > 0) { | ||
for (let dependency of Object.keys(knownDependencies)) { | ||
if (knownDependencies[dependency] !== true) { | ||
continue; | ||
} | ||
const groupPluginPath = (0, path_1.join)(pluginPath, groupPluginName); | ||
await coreLogger.debug(`FIND: CHECK [{dirFileWhat}/{groupPluginName}] {groupPluginPath}`, { dirFileWhat, groupPluginName, groupPluginPath }); | ||
if ((0, fs_1.statSync)(groupPluginPath).isDirectory()) { | ||
arrOfPlugins = arrOfPlugins.concat(await SBPlugins.findPluginsInBase(coreLogger, groupPluginPath, true)); | ||
} | ||
let response = await SBPlugins.findPluginsInBase(coreLogger, (0, path_1.join)(npmPluginsDir, dependency), true); | ||
arrOfPlugins = arrOfPlugins.concat(response); | ||
} | ||
} | ||
else { | ||
await coreLogger.debug(`FIND: CHECK [{dirFileWhat}] {pluginPath}`, { | ||
dirFileWhat, | ||
pluginPath, | ||
}); | ||
if ((0, fs_1.statSync)(pluginPath).isDirectory()) { | ||
arrOfPlugins = arrOfPlugins.concat(await SBPlugins.findPluginsInBase(coreLogger, pluginPath, true)); | ||
} | ||
} | ||
} | ||
catch (err) { | ||
await coreLogger.error("{message}", { | ||
message: err.message || err.toString(), | ||
}); | ||
catch (e) { | ||
await coreLogger.error(`Cannot read known dependencies: {knownDependenciesCacheFile}`, { knownDependenciesCacheFile }); | ||
} | ||
} | ||
if (arrOfPlugins.length === 0) { | ||
let response = await SBPlugins.findDependentPlugins("self", coreLogger, pluginJson, npmPluginsDir, {}); | ||
setTimeout(async () => { | ||
try { | ||
(0, fs_1.writeFileSync)(knownDependenciesCacheFile, JSON.stringify(response.knownDependencies, null, 2)); | ||
} | ||
catch (e) { | ||
await coreLogger.warn(`Cannot cache known dependencies: {knownDependenciesCacheFile}`, { knownDependenciesCacheFile }); | ||
} | ||
}, 1000); | ||
arrOfPlugins = response.plugins; | ||
} | ||
return arrOfPlugins; | ||
@@ -156,0 +199,0 @@ } |
@@ -85,5 +85,8 @@ "use strict"; | ||
mappedName: plugin.mappedName, | ||
clientPlugin: client._pluginName, | ||
clientPlugin: client.pluginName, | ||
}); | ||
await client._register(); | ||
await client._init(); | ||
client._init = undefined; | ||
await client.init(); | ||
client.init = undefined; | ||
} | ||
@@ -90,0 +93,0 @@ await this.log.info("Ready {pluginName} ({mappedName}) as new base service platform", { |
@@ -207,3 +207,2 @@ "use strict"; | ||
runTest("16MB"); | ||
runTest("128MB", 1); | ||
}); | ||
@@ -210,0 +209,0 @@ }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -8,2 +31,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const plugin_1 = require("../../../plugins/events-default/plugin"); | ||
const emitDirect = __importStar(require("../../../plugins/events-default/events/emit")); | ||
const broadcast_1 = require("./events/broadcast"); | ||
@@ -13,2 +37,3 @@ const emit_1 = require("./events/emit"); | ||
const emitStreamAndReceiveStream_1 = require("./events/emitStreamAndReceiveStream"); | ||
const crypto_1 = require("crypto"); | ||
const debug = (...a) => { }; | ||
@@ -46,2 +71,59 @@ const fakeLogger = { | ||
describe("plugins/events-default", () => { | ||
describe("Events Emit", async () => { | ||
it("_lastReceivedMessageIds should be empty on init", async () => { | ||
let emit = new emitDirect.default(fakeLogger); | ||
assert_1.default.equal(emit._lastReceivedMessageIds.length, 0); | ||
}); | ||
it("_lastReceivedMessageIds should contain latest emit ID", async () => { | ||
let emit = new emitDirect.default(fakeLogger); | ||
await emit.onEvent("a", "b", "c", async () => { }); | ||
await emit.emitEvent("a", "b", "c", []); | ||
assert_1.default.equal(emit._lastReceivedMessageIds.length, 1); | ||
}); | ||
it("_lastReceivedMessageIds should call only once", async () => { | ||
let emit = new emitDirect.default(fakeLogger); | ||
let testID = (0, crypto_1.randomUUID)(); | ||
let called = 0; | ||
await emit.onEvent("a", "b", "c", async () => { | ||
called++; | ||
}); | ||
emit.emit(`b-c`, { | ||
msgID: testID, | ||
data: [], | ||
}); | ||
assert_1.default.equal(called, 1); | ||
}); | ||
it("_lastReceivedMessageIds should call only once, per id", async () => { | ||
let emit = new emitDirect.default(fakeLogger); | ||
let testID1 = (0, crypto_1.randomUUID)(); | ||
let testID2 = (0, crypto_1.randomUUID)(); | ||
let called = 0; | ||
await emit.onEvent("a", "b", "c", async () => { | ||
called++; | ||
}); | ||
emit.emit(`b-c`, { | ||
msgID: testID1, | ||
data: [], | ||
}); | ||
emit.emit(`b-c`, { | ||
msgID: testID2, | ||
data: [], | ||
}); | ||
assert_1.default.equal(called, 2); | ||
}); | ||
it("_lastReceivedMessageIds should cycle ids > 50", async () => { | ||
let emit = new emitDirect.default(fakeLogger); | ||
let testIDs = "." | ||
.repeat(100) | ||
.split("") | ||
.map(() => (0, crypto_1.randomUUID)()); | ||
await emit.onEvent("a", "b", "c", async () => { }); | ||
for (let emitID of testIDs) | ||
emit.emit(`b-c`, { | ||
msgID: emitID, | ||
data: [], | ||
}); | ||
assert_1.default.equal(emit._lastReceivedMessageIds.length, 51); | ||
}); | ||
}); | ||
(0, broadcast_1.broadcast)(async () => { | ||
@@ -48,0 +130,0 @@ const refP = new plugin_1.Events("test-plugin", process.cwd(), process.cwd(), fakeLogger); |
@@ -8,4 +8,4 @@ { | ||
"engines": { | ||
"npm": ">=8.0.0", | ||
"node": ">=16.0.0" | ||
"npm": ">=9.0.0", | ||
"node": ">=18.0.0" | ||
}, | ||
@@ -33,3 +33,3 @@ "scripts": { | ||
"main": "lib/index.js", | ||
"version": "8.5.2-rc.0", | ||
"version": "9.0.0+v9", | ||
"devDependencies": { | ||
@@ -51,5 +51,72 @@ "@types/assert": "^1.5.6", | ||
"dependencies": { | ||
"@bettercorp/tools": "^2.0.20220714140658" | ||
"@bettercorp/tools": "^2.0.20220714140658", | ||
"yaml": "^2.3.1" | ||
}, | ||
"bsb_project": true | ||
} | ||
"bsb_project": true, | ||
"bsbInit": { | ||
"project": { | ||
"dependencies": { | ||
"@bettercorp/tools": "latest" | ||
}, | ||
"devDependencies": { | ||
"@types/assert": "^1.5.6", | ||
"@types/chai": "^4.3.3", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^18.7.16", | ||
"@typescript-eslint/eslint-plugin": "^5.31.0", | ||
"@typescript-eslint/parser": "^5.31.0", | ||
"eslint": "^8.20.0", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.7.4" | ||
}, | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
"build": "npm run build-plugin && npm run build-clients", | ||
"build-plugin": "rm -rfv ./lib && tsc", | ||
"build-clients": "node node_modules/@bettercorp/service-base/build-lib-clients.js", | ||
"dev": "nodemon --config node_modules/@bettercorp/service-base/development/nodemon.json", | ||
"start": "ts-node node_modules/@bettercorp/service-base/lib/cli.js", | ||
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx", | ||
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' node ./node_modules/nyc/bin/nyc.js --reporter json --reporter lcov ./node_modules/mocha/bin/mocha.js -r ts-node/register 'src/tests/**/*.ts' --reporter json --reporter-options output=junit.json", | ||
"testDev": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' node ./node_modules/nyc/bin/nyc.js ./node_modules/mocha/bin/mocha.js -r ts-node/register 'src/tests/**/*.ts'" | ||
}, | ||
"main": "lib/index.js" | ||
}, | ||
"gitignore": [ | ||
"/lib", | ||
"/node_modules", | ||
"/sec.config.json", | ||
"/junit.xml", | ||
"/test-file-*", | ||
"/dist-clients" | ||
], | ||
"files": [ | ||
{ | ||
"src": "tsconfig.json", | ||
"dst": "tsconfig.json", | ||
"canOverwrite": true | ||
}, | ||
{ | ||
"src": "eslintrc.js", | ||
"dst": ".eslintrc.js", | ||
"canOverwrite": true | ||
}, | ||
{ | ||
"src": "eslintignore", | ||
"dst": ".eslintignore", | ||
"canOverwrite": true | ||
} | ||
], | ||
"directories": [ | ||
"src", | ||
"src/clients", | ||
"src/plugins", | ||
"src/shared", | ||
"src/tests" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
438979
161
5615
1
2
0
3
+ Addedyaml@^2.3.1
+ Addedyaml@2.7.0(transitive)