generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
CCM-12352: Internal package refactor #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
masl2
merged 21 commits into
main
from
feature/CCM-12352-refactor-helpers-and-datastore
Oct 29, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4bca3e4
Refactor datastore package
m-houston 92fa9b6
Clean up tests
m-houston f1b7f63
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
m-houston cc79105
Make markdownlint config separate for specification docs
m-houston d977710
Update documentation for run functions
m-houston afaa067
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
m-houston 3fa5a8f
Fixup after merging main
m-houston e3c8315
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
m-houston 7c9a282
Merge branch 'refs/heads/main' into feature/CCM-12352-refactor-helper…
m-houston 1313be5
Update after main merge
m-houston 077a43a
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
m-houston 7a6759b
Replace newly introduced cross-package reference
m-houston b9e18db
Remove generated README.md
m-houston b1a295f
Restore dataschema diagram generation
m-houston 445f1f2
Add diagram for Supplier datastore schema
m-houston 0563699
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
m-houston de6b428
Update package-lock conflicts
m-houston b8679a3
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
masl2 62f67c1
update lock
masl2 5b54f85
CCM-12352: single package lock
masl2 55baa29
Merge branch 'main' into feature/CCM-12352-refactor-helpers-and-datas…
masl2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // SEE: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml | ||
| { | ||
| // https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md | ||
| "MD013": false, | ||
| // https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md | ||
| "MD024": { | ||
| "siblings_only": true | ||
| }, | ||
| // https://github.com/DavidAnson/markdownlint/blob/main/doc/md033.md | ||
| "MD033": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "versionGroups": [ | ||
| { | ||
| "dependencies": ["@internal/**", "@nhsdigital/nhs-notify-event-schemas-supplier-api"], | ||
| "specifierTypes": ["*"], | ||
| "label": "Internal deps", | ||
| "isIgnored": true | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Dependency directories | ||
| node_modules/ | ||
|
|
||
| # Built output | ||
| dist/ | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
| coverage/ | ||
|
|
||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # Editor directories and files | ||
| .idea/ | ||
| .vscode/ | ||
| *.suo | ||
| *.ntvs* | ||
| *.njsproj | ||
| *.sln | ||
| *.sw? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { Config } from "jest"; | ||
|
|
||
| const config: Config = { | ||
| preset: "ts-jest", | ||
| testEnvironment: "node", | ||
| testMatch: ["**/src/__tests__/**/*.ts?(x)", "**/src/?(*.)+(spec|test).ts?(x)"], | ||
| collectCoverageFrom: ["src/**/*.ts"], | ||
| coveragePathIgnorePatterns: ["/node_modules/", "__tests__"], | ||
| testPathIgnorePatterns: ["/node_modules/", "/dist/"], | ||
| transform: { | ||
| "^.+\\.tsx?$": ["ts-jest", { }] | ||
| } | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "dependencies": { | ||
| "zod": "^4.1.11" | ||
| }, | ||
| "description": "Common helper utilities for NHS Notify Supplier API", | ||
| "devDependencies": { | ||
| "@stylistic/eslint-plugin": "^3.1.0", | ||
| "@tsconfig/node22": "^22.0.2", | ||
| "@types/jest": "^29.5.14", | ||
| "@typescript-eslint/eslint-plugin": "^8.27.0", | ||
| "@typescript-eslint/parser": "^8.27.0", | ||
| "eslint": "^9.27.0", | ||
| "eslint-plugin-jest": "^29.0.1", | ||
| "jest": "^30.1.3", | ||
| "ts-jest": "^29.4.0", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.8.3" | ||
masl2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| "license": "MIT", | ||
| "main": "src/index.ts", | ||
| "name": "@internal/helpers", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "lint": "eslint .", | ||
| "lint:fix": "eslint . --fix", | ||
| "test": "jest", | ||
| "test:unit": "jest", | ||
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "version": "0.1.0" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { z } from "zod"; | ||
| import { idRef } from "../id-ref"; | ||
|
|
||
| describe("idRef", () => { | ||
| const TestSchema = z.object({ | ||
| domainId: z.uuid(), | ||
| name: z.string(), | ||
| }); | ||
|
|
||
| it("should create an ID reference with the same type as the source schema's ID field", () => { | ||
| const refField = idRef(TestSchema); | ||
|
|
||
| // Should validate UUIDs like the original schema's domainId | ||
| expect(() => refField.parse("not-a-uuid")).toThrow(); | ||
| expect(() => refField.parse("123e4567-e89b-12d3-a456-426614174000")).not.toThrow(); | ||
| }); | ||
|
|
||
| it("should add reference metadata", () => { | ||
| const refField = idRef(TestSchema, "domainId", "TestEntity"); | ||
|
|
||
| expect(refField).toBeDefined(); | ||
| expect(z.globalRegistry.has(refField)).toBe(true); | ||
| expect(z.globalRegistry.get(refField)).toEqual(expect.objectContaining({ | ||
| title: "TestEntity ID Reference", | ||
| description: "Reference to a TestEntity by its unique identifier", | ||
| })); | ||
| }); | ||
|
|
||
| it("should use custom ID field name when provided", () => { | ||
| const CustomSchema = z.object({ | ||
| customId: z.number(), | ||
| name: z.string(), | ||
| }); | ||
|
|
||
| const refField = idRef(CustomSchema, "customId"); | ||
|
|
||
| // Should validate numbers like the custom ID field | ||
| expect(() => refField.parse("not-a-number")).toThrow(); | ||
| expect(() => refField.parse(123)).not.toThrow(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export function DomainBase<T extends string>( | ||
| type: T, | ||
| ): z.ZodObject<{ domainId: z.core.$ZodBranded<z.ZodString, T> }> { | ||
| const idType = z | ||
| .string() | ||
| .brand<T>(type) | ||
| .meta({ | ||
| title: `${type} ID`, | ||
| description: `Unique identifier for the ${type}`, | ||
| examples: ["1y3q9v1zzzz"], | ||
| }) as z.core.$ZodBranded<z.ZodString, T>; | ||
|
|
||
| return z.object({ | ||
| domainId: idType, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| /** | ||
| * Deployment / execution environment identifier. | ||
| * Intentionally liberal; constrain in callers as needed. | ||
| */ | ||
| export const $Environment = z.string().meta({ | ||
| title: 'Environment', | ||
| description: 'The environment in which the configuration has effect', | ||
| examples: ['dev', 'int', 'prod'], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * Creates a field that references another entity by ID, inferring the type from the referenced | ||
| * schema's domainId field. | ||
| * This allows you to indicate relationships without embedding the full entity. | ||
| * | ||
| * @param schema - The Zod object schema representing the referenced entity | ||
| * @param idFieldName - The name of the ID field in the referenced schema (default: 'domainId') | ||
| * @param entityName - Optional custom name for the referenced entity | ||
masl2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @returns A Zod schema for the ID field with reference metadata, with the type inferred from | ||
| * the referenced schema | ||
| * | ||
| * @example | ||
| * import { z } from 'zod'; | ||
| * import { idRef } from './id-ref'; | ||
| * | ||
| * const CustomerSchema = z.object({ domainId: z.string() }); | ||
| * const OrderSchema = z.object({ | ||
| * domainId: z.string(), | ||
| * customerId: idRef(CustomerSchema), // Inferred as ZodString | ||
| * }); | ||
| */ | ||
| // Overload for when a specific ID field is provided | ||
| export function idRef< | ||
| T extends z.ZodObject<Record<string, z.ZodTypeAny>>, | ||
| K extends keyof T["shape"] & string | ||
| >(schema: T, idFieldName: K, entityName?: string): T["shape"][K]; | ||
|
|
||
| // Overload for when using the default "domainId" field | ||
| export function idRef< | ||
| T extends z.ZodObject<Record<string, z.ZodTypeAny>> & { | ||
| shape: { domainId: z.ZodTypeAny } | ||
| } | ||
| >(schema: T, idFieldName?: undefined, entityName?: string): T["shape"]["domainId"]; | ||
|
|
||
| // Implementation | ||
| export function idRef< | ||
| T extends z.ZodObject<Record<string, z.ZodTypeAny>>, | ||
| K extends keyof T["shape"] & string = "domainId", | ||
| >(schema: T, idFieldName?: K, entityName?: string): T["shape"][K] { | ||
| const { shape } = schema; | ||
| const field = idFieldName ?? "domainId"; | ||
|
|
||
| if (!(field in shape)) { | ||
| throw new Error(`ID field '${field}' not found in schema`); | ||
| } | ||
|
|
||
| // Get the ID field schema | ||
| const idFieldSchema = shape[field]; | ||
| if (!idFieldSchema) { | ||
| throw new Error(`ID field '${field}' not found in schema`); | ||
| } | ||
|
|
||
| // Use the provided entity name or the schema description | ||
| const targetEntityName = entityName || schema.description || "Unknown"; | ||
|
|
||
| // Create a new schema with the same type and validation as the ID field | ||
| const resultSchema = idFieldSchema.clone().meta({ | ||
| title: `${targetEntityName} ID Reference`, | ||
| description: `Reference to a ${targetEntityName} by its unique identifier`, | ||
| }); | ||
|
|
||
| return resultSchema as T["shape"][K]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Common helper utilities for NHS Notify Supplier API | ||
| * @module helpers | ||
| */ | ||
|
|
||
| // Export all helpers | ||
| export * from './version'; | ||
| export * from './environment'; | ||
| export * from "./id-ref"; | ||
| export * from "./domain-base"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| /** | ||
| * Semantic version (major.minor.patch) with numeric segments only. | ||
| * Branded for nominal typing. | ||
| */ | ||
| export const $Version = z | ||
| .string() | ||
| .regex(/^[0-9]+\.[0-9]+\.[0-9]+$/) | ||
| .brand('Version'); | ||
|
|
||
| export type Version = z.infer<typeof $Version>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "declaration": true | ||
| }, | ||
| "exclude": [ | ||
| "node_modules", | ||
| "dist" | ||
| ], | ||
| "extends": "../../tsconfig.base.json", | ||
| "include": [ | ||
| "src/**/*", | ||
| "jest.config.ts" | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.