From 642923a6462408cdae082d01f18d84e8259ce91d Mon Sep 17 00:00:00 2001 From: Eric Law <39393654+acn-ericlaw@users.noreply.github.com> Date: Sat, 21 Dec 2024 14:20:24 -0800 Subject: [PATCH] fix unit test --- dist/models/composable.js | 2 +- dist/models/composable.js.map | 2 +- dist/resources/templates/preload.template | 6 +++--- dist/util/function-registry.d.ts | 13 ++++++++++++- dist/util/function-registry.js | 13 ++++++++++++- dist/util/function-registry.js.map | 2 +- test/po.test.ts | 2 +- 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dist/models/composable.js b/dist/models/composable.js index e93f7b2..e6b64cc 100644 --- a/dist/models/composable.js +++ b/dist/models/composable.js @@ -16,7 +16,7 @@ export function preload(instances = 1, isPublic = false, isInterceptor = false) descriptor.value = function (...args) { if (this.name && this.handleEvent instanceof Function) { log.info(`Loading ${this.constructor.name} as ${this.name}`); - registry.saveFunction(this, instances, isPublic, isInterceptor); + registry.saveFunction(this, Math.min(500, Math.max(1, instances)), isPublic, isInterceptor); } else { log.error(`Unable to load ${this.constructor.name} because it does not implement Composable`); diff --git a/dist/models/composable.js.map b/dist/models/composable.js.map index e37f622..4efe1c9 100644 --- a/dist/models/composable.js.map +++ b/dist/models/composable.js.map @@ -1 +1 @@ -{"version":3,"file":"composable.js","sourceRoot":"","sources":["../../src/models/composable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;AACjC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAgBxC;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,SAAS,GAAC,CAAC,EAAE,QAAQ,GAAC,KAAK,EAAE,aAAa,GAAC,KAAK;IACtE,OAAO,UAAU,OAAO,EAAE,WAAmB,EAAE,UAA8B;QAC3E,IAAI,YA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E,CAAC;YAChC,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;YAChC,UAAU,CAAC,KAAK,GAAG,UAAU,GAAG,IAAI;gBAClC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW,YAAY,QAAQ,EAAE,CAAC;oBACpD,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;oBAC7D,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;gBAChG,CAAC;qBAAM,CAAC;oBACJ,GAAG,CAAC,KAAK,CAAC,kBAAkB,IAAI,CAAC,WAAW,CAAC,IAAI,2CAA2C,CAAC,CAAC;gBAClG,CAAC;gBACD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAClC,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,KAAK,CAAC,wFAAwF,WAAW,EAAE,CAAC,CAAC;QACrH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/resources/templates/preload.template b/dist/resources/templates/preload.template index 0f87de0..8f4baa8 100644 --- a/dist/resources/templates/preload.template +++ b/dist/resources/templates/preload.template @@ -7,7 +7,7 @@ import fs from 'fs'; import { fileURLToPath } from "url"; import { Logger, AppConfig, FunctionRegistry, Platform } from 'mercury'; -// import the user functions +// import composable functions ${import-statements} const log = Logger.getInstance(); @@ -39,9 +39,9 @@ export class ComposableLoader { // initialize base configuration const config = AppConfig.getInstance(resourcePath); log.info(`Base configuration ${config.getId()}`); - // load composable functions + // initialize composable functions ${service-list} - // register them into the event system + // register the functions into the event system const platform = Platform.getInstance(); const registry = new FunctionRegistry(); const registered = registry.getFunctions(); diff --git a/dist/util/function-registry.d.ts b/dist/util/function-registry.d.ts index f825716..5931b6c 100644 --- a/dist/util/function-registry.d.ts +++ b/dist/util/function-registry.d.ts @@ -2,7 +2,7 @@ import { EventEnvelope } from '../models/event-envelope.js'; export declare class FunctionRegistry { constructor(); /** - * Save a Composable class to the registry by name. + * Save a Composable function to the registry by name. * * @param that is the class instance of the Composable function * @param instances for concurrency @@ -10,7 +10,18 @@ export declare class FunctionRegistry { * @param isInterceptor is true if function is an event interceptor */ saveFunction(that: object, instances: number, isPublic: boolean, isInterceptor: boolean): void; + /** + * Remove a composable function from the registry by name. + * + * @param name of the function + */ removeFunction(name: string): void; + /** + * Retrieve metadata for the composable function + * + * @param name of the function + * @returns map of key-values + */ getMetadata(name: string): object; /** * Retrieve a function by name so that you can register it programmatically. diff --git a/dist/util/function-registry.js b/dist/util/function-registry.js index bac34bc..8fb4570 100644 --- a/dist/util/function-registry.js +++ b/dist/util/function-registry.js @@ -6,7 +6,7 @@ export class FunctionRegistry { } } /** - * Save a Composable class to the registry by name. + * Save a Composable function to the registry by name. * * @param that is the class instance of the Composable function * @param instances for concurrency @@ -16,9 +16,20 @@ export class FunctionRegistry { saveFunction(that, instances, isPublic, isInterceptor) { self.saveFunction(that, instances, isPublic, isInterceptor); } + /** + * Remove a composable function from the registry by name. + * + * @param name of the function + */ removeFunction(name) { self.removeFunction(name); } + /** + * Retrieve metadata for the composable function + * + * @param name of the function + * @returns map of key-values + */ getMetadata(name) { return self.getMetadata(name); } diff --git a/dist/util/function-registry.js.map b/dist/util/function-registry.js.map index 663b826..67c6c7a 100644 --- a/dist/util/function-registry.js.map +++ b/dist/util/function-registry.js.map @@ -1 +1 @@ -{"version":3,"file":"function-registry.js","sourceRoot":"","sources":["../../src/util/function-registry.ts"],"names":[],"mappings":"AAEA,IAAI,IAAI,GAAmB,IAAI,CAAC;AAEhC,MAAM,OAAO,gBAAgB;IAEzB;QACI,IAAI,IAAI,IAAI,IAAI,EAAE,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QAC9D,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,IAAY;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,GAAG,CAAA,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IAC1C,CAAC;IAED,YAAY;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;CAEJ"} \ No newline at end of file +{"version":3,"file":"function-registry.js","sourceRoot":"","sources":["../../src/util/function-registry.ts"],"names":[],"mappings":"AAEA,IAAI,IAAI,GAAmB,IAAI,CAAC;AAEhC,MAAM,OAAO,gBAAgB;IAEzB;QACI,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACf,IAAI,GAAG,IAAI,cAAc,EAAE,CAAC;QAChC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,CAAC,IAAY,EAAE,SAAiB,EAAE,QAAiB,EAAE,aAAsB;QACnF,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,IAAY;QACvB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;OAOG;IACH,WAAW,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;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 --- a/test/po.test.ts +++ b/test/po.test.ts @@ -129,7 +129,7 @@ describe('post office use cases', () => { const appConfig = AppConfig.getInstance(resourcePath).getReader(); // save the helloWorld as DEMO_LIBRARY_FUNCTION so that it can be retrieved by name const helloWorld = new HelloWorld(); - registry.saveFunction(helloWorld); + registry.saveFunction(helloWorld, 1, false, false); platform = Platform.getInstance(); // register a hello.world function to echo the incoming payload platform.register(HELLO_WORLD_SERVICE, helloWorld.handleEvent, false, HELLO_WORLD_INSTANCES);