diff --git a/.github/workflows/action-deploy.yaml b/.github/workflows/action-deploy.yaml index afc1877..8a7865b 100644 --- a/.github/workflows/action-deploy.yaml +++ b/.github/workflows/action-deploy.yaml @@ -63,6 +63,7 @@ jobs: - name: Publish to npm uses: JS-DevTools/npm-publish@v3 with: + provenance: true token: ${{ secrets.NPM_TOKEN }} tag: ${{ steps.set-npm-tag.outputs.NPM_TAG }} diff --git a/.github/workflows/action-test.yaml b/.github/workflows/action-test.yaml index b24caa1..9fe73fe 100644 --- a/.github/workflows/action-test.yaml +++ b/.github/workflows/action-test.yaml @@ -30,8 +30,8 @@ jobs: - name: Pre-Run run: | - npm install --package-lock-only - npm install --ignore-scripts + npm install --package-lock-only --force + npm install --ignore-scripts --force - name: Run Tests and Lint run: | diff --git a/__tests__/__utils__/utils.ts b/__tests__/__utils__/utils.ts index 5478f17..a0f7bf2 100644 --- a/__tests__/__utils__/utils.ts +++ b/__tests__/__utils__/utils.ts @@ -33,3 +33,12 @@ export async function expectEvent( emitter.once(name, resolve); }); } + +export function getCurrentDateYYYYMMDD() { + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are 0-based + const day = String(date.getDate()).padStart(2, "0"); + + return `${year}${month}${day}`; +} diff --git a/__tests__/hl7.test.ts b/__tests__/hl7.test.ts index 36bf343..7c7f0f2 100644 --- a/__tests__/hl7.test.ts +++ b/__tests__/hl7.test.ts @@ -5,6 +5,7 @@ import path from "path"; import { describe, expect, test, beforeEach, afterEach } from "vitest"; import fastifyHL7 from "../src"; import { errors } from "../src/errors"; +import { getCurrentDateYYYYMMDD } from "./__utils__/utils.js"; let app: FastifyInstance; @@ -233,11 +234,15 @@ describe("plugin fastify-hl7 tests", () => { test("...getClientByName", async () => { const client = app.hl7.createClient("adt", { host: "0.0.0.0" }); - const clientPullName = app.hl7.getClientByName("adt"); - expect(clientPullName).toEqual(client); }); + + test("...buildDate", async () => { + expect(app.hl7.buildDate(new Date(), "8")).toEqual( + getCurrentDateYYYYMMDD(), + ); + }); }); describe("...hl7", () => { diff --git a/eslint.config.mjs b/eslint.config.mjs index aba2f4b..e13ab99 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,6 +1,6 @@ import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; -import pluginPrettier from 'eslint-plugin-prettier'; +import pluginPrettier from "eslint-plugin-prettier"; export default [ pluginJs.configs.recommended, @@ -8,16 +8,16 @@ export default [ { files: ["**/*.{js,mjs,cjs,ts}"], plugins: { - 'prettier': pluginPrettier - } + prettier: pluginPrettier, + }, }, { rules: { - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-unused-vars': 'off' - } + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-vars": "off", + }, }, { - ignores: [".node_modules/*", "docs/*", "lib/*", "__tests__/*"] - } + ignores: [".node_modules/*", "docs/*", "lib/*", "__tests__/*"], + }, ]; diff --git a/package.json b/package.json index 9f216f7..b9f2f6a 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build:watch": "tsc -p src/tsconfig.esm.json -w", "build:watch:cjs": "tsc -p src/tsconfig.cjs.json -w", "npm:lint": "npmPkgJsonLint .", - "format": "prettier --write 'README.md' 'src/**/*.ts' '__tests__/**/*.ts'", + "format": "prettier --write 'README.md' 'src/**/*.ts' '__tests__/**/*.ts' '*.{mts,mjs}'", "lint": "npm run npm:lint && eslint | snazzy", "lint:fix": "npm run npm:lint && eslint --fix | snazzy", "pack": "npm pack", @@ -65,16 +65,16 @@ "node-hl7-server": "^3.1.0" }, "devDependencies": { - "@eslint/js": "^9.15.0", + "@eslint/js": "^9.16.0", "@shipgirl/typedoc-plugin-versions": "^0.2.8", "@types/eslint__js": "^8.42.3", - "@types/node": "^22.9.0", + "@types/node": "^22.10.1", "@types/tcp-port-used": "^1.0.4", - "@typescript-eslint/eslint-plugin": "^8.14.0", - "@typescript-eslint/parser": "^8.14.0", - "@vitest/coverage-v8": "^2.1.5", - "@vitest/ui": "^2.1.5", - "eslint": "^9.14.0", + "@typescript-eslint/eslint-plugin": "^8.17.0", + "@typescript-eslint/parser": "^8.17.0", + "@vitest/coverage-v8": "^2.1.8", + "@vitest/ui": "^2.1.8", + "eslint": "^9.16.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "fastify": "^5.1.0", @@ -86,12 +86,13 @@ "tcp-port-used": "^1.0.2", "ts-node": "^10.9.2", "tsd": "^0.31.2", - "typedoc": "^0.26.11", - "typescript": "^5.6.3", - "typescript-eslint": "^8.14.0", - "vitest": "^2.1.5" + "typedoc": "^0.27.4", + "typescript": "^5.7.2", + "typescript-eslint": "^8.17.0", + "vitest": "^2.1.8" }, "precommit": [ + "format", "lint:fix", "build" ] diff --git a/src/class/hL7Client.ts b/src/class/hL7Client.ts index 06fa75c..f1d5b5f 100644 --- a/src/class/hL7Client.ts +++ b/src/class/hL7Client.ts @@ -38,7 +38,7 @@ export class HL7Client { /** * Build a HL7 Batch - *@remarks Create a properly formatted HL7 Batch. + * @remarks Create a properly formatted HL7 Batch. * @since 1.0.0 * @param props */ @@ -53,7 +53,7 @@ export class HL7Client { /** * Build Date - *@remarks Build a date string based off HL7 Standards + * @remarks Build a date string based off HL7 Standards * @since 2.1.0 * @param date * @param length Options are 8, 12, or 14 (default) @@ -64,7 +64,7 @@ export class HL7Client { /** * Build a HL7 File Batch - *@remarks Create a properly formatted HL7 File Batch. + * @remarks Create a properly formatted HL7 File Batch. * @since 1.0.0 * @param props */ @@ -83,7 +83,7 @@ export class HL7Client { /** * Build a HL7 Message - *@remarks Create a properly formatted HL7 message. + * @remarks Create a properly formatted HL7 message. * @since 1.0.0 * @param props */ @@ -135,7 +135,7 @@ export class HL7Client { /** * Create an HL7 Outbound Connection - *@remarks Connect to an HL7 Server/Broker + * @remarks Connect to an HL7 Server/Broker * @since 1.0.0 * @param name The name stored within created client connections. * @param props @@ -219,7 +219,7 @@ export class HL7Client { /** * Process a HL7 - *@remarks A HL7 message that could either be a Message (MSH) or Batch (BHS) + * @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS) * @since 1.0.0 * @param text Raw HL& String */ @@ -233,7 +233,7 @@ export class HL7Client { /** * Read File - *@remarks Pass the correct path of the file you want to read. + * @remarks Pass the correct path of the file you want to read. * @since 1.0.0 * @param fullFilePath * @returns FileBatch @@ -248,7 +248,7 @@ export class HL7Client { /** * Read a File Buffer - *@remarks Translate an already Buffered HL7 FHS segment to decode it. + * @remarks Translate an already Buffered HL7 FHS segment to decode it. * @since 1.0.0 * @param fileBuffer * @returns FileBatch diff --git a/src/class/hL7Server.ts b/src/class/hL7Server.ts index 29a6663..054eba8 100644 --- a/src/class/hL7Server.ts +++ b/src/class/hL7Server.ts @@ -1,3 +1,4 @@ +import { EventEmitter } from "node:events"; import Server, { Inbound, InboundHandler, @@ -6,11 +7,12 @@ import Server, { import { AServers } from "../decorate.js"; import { errors } from "../errors.js"; -export class HL7Server { +export class HL7Server extends EventEmitter { private readonly _server: Server; private readonly _serverInboundConnections: AServers[]; constructor(server: Server) { + super(); this._server = server; this._serverInboundConnections = []; } @@ -69,6 +71,9 @@ export class HL7Server { port: props.port.toString(), server: inbound, }); + + this.emit("inbound", props.port.toString()); + return inbound; } diff --git a/src/index.ts b/src/index.ts index 4f81578..52279b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,6 +63,10 @@ const fastifyHL7 = fp(async (fastify, opts) => { // Server Functions server = new HL7Server(serverInstance); + server.on("inbound", (port: string) => { + fastify.log.info("HL7 Inbound Server Listening on Port %s", port); + }); + // before we close fastify, make sure all server instances are closed fastify.addHook("preClose", async () => { if (typeof server !== "undefined") { diff --git a/src/types.ts b/src/types.ts index 74dbcd3..02b8a2b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -41,7 +41,7 @@ declare module "fastify" { * @since 1.0.0 */ closeServerAll: () => Promise; /** Create Client - *@remarks Connecting to a remote server/broker that accepts connections. + * @remarks Connecting to a remote server/broker that accepts connections. * @since 1.0.0 */ createClient: (name: string, props: ClientOptions) => Client; /** Create an incoming port connection on the server. @@ -52,7 +52,7 @@ declare module "fastify" { handler: InboundHandler, ) => Inbound; /** Create Outgoing Client Port - *@remarks This is on the established client that we are already a part off. + * @remarks This is on the established client that we are already a part off. * @since 1.0.0 */ createConnection: ( name: string, @@ -84,7 +84,7 @@ declare module "fastify" { export interface FastifyInstance { /** Main Decorator for Fastify - *@remarks hl7 is the decorator that everything hangs off. + * @remarks hl7 is the decorator that everything hangs off. * @since 1.0.0 **/ hl7: HL7; } diff --git a/vitest.config.mts b/vitest.config.mts index 903abf7..78717c3 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -1,16 +1,19 @@ -import { defineConfig } from 'vitest/config' +import { configDefaults, defineConfig } from "vitest/config"; export default defineConfig({ test: { coverage: { + provider: "v8", exclude: [ - '__tests__/__utils__/**', - 'docker', - 'bin', - 'certs', - 'docs', - 'lib' - ] - } - } -}) + ...configDefaults.exclude, + "__tests__/**/**", + "src/api.ts", + "docker", + "bin", + "certs", + "docs", + "lib", + ], + }, + }, +});