Skip to content

Commit e08e48d

Browse files
m-houstonmasl2
andauthored
CCM-12352: Internal package refactor (#198)
* Refactor datastore package * Clean up tests * Make markdownlint config separate for specification docs * Update documentation for run functions * Fixup after merging main * Update after main merge * Replace newly introduced cross-package reference * Remove generated README.md * Restore dataschema diagram generation * Add diagram for Supplier datastore schema * Update package-lock conflicts * update lock --------- Co-authored-by: Mark Slowey <[email protected]>
1 parent e802a39 commit e08e48d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2267
-160
lines changed

.markdownlint.jsonc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SEE: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
2+
{
3+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
4+
"MD013": false,
5+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
6+
"MD024": {
7+
"siblings_only": true
8+
},
9+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md033.md
10+
"MD033": false
11+
}

.syncpackrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"versionGroups": [
3+
{
4+
"dependencies": ["@internal/**", "@nhsdigital/nhs-notify-event-schemas-supplier-api"],
5+
"specifierTypes": ["*"],
6+
"label": "Internal deps",
7+
"isIgnored": true
8+
}
9+
]
10+
}

internal/datastore/jest.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const baseJestConfig: Config = {
1515
// Indicates which provider should be used to instrument code for coverage
1616
coverageProvider: 'babel',
1717

18+
// Module name mapper to handle TypeScript path aliases
19+
moduleNameMapper: {
20+
'^@internal/helpers$': '<rootDir>/../helpers/src'
21+
},
22+
1823
coverageThreshold: {
1924
global: {
2025
branches: 100,

internal/datastore/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"dependencies": {
33
"@aws-sdk/client-dynamodb": "^3.858.0",
44
"@aws-sdk/lib-dynamodb": "^3.858.0",
5+
"@internal/helpers": "*",
56
"pino": "^9.7.0",
6-
"zod": "^4.0.14"
7+
"zod": "^4.1.11"
78
},
89
"devDependencies": {
910
"@stylistic/eslint-plugin": "^3.1.0",
@@ -18,15 +19,15 @@
1819
"testcontainers": "^11.4.0",
1920
"ts-jest": "^29.4.0",
2021
"ts-node": "^10.9.2",
21-
"typescript": "^5.8.2",
22+
"typescript": "^5.8.3",
2223
"zod-mermaid": "^1.0.9"
2324
},
2425
"license": "MIT",
2526
"main": "src/index.ts",
26-
"name": "datastore",
27+
"name": "@internal/datastore",
2728
"private": true,
2829
"scripts": {
29-
"diagrams": "ts-node src/cli/diagrams.ts",
30+
"diagrams": "tsx src/cli/diagrams.ts",
3031
"lint": "eslint .",
3132
"lint:fix": "eslint . --fix",
3233
"test:unit": "jest",

internal/datastore/src/cli/diagrams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LetterSchema, MISchema } from '../types';
1+
import {LetterSchema, MISchema, SupplierSchema} from '../types';
22
import { generateMermaidDiagram } from 'zod-mermaid';
33
import * as fs from 'node:fs';
44

@@ -11,7 +11,7 @@ This document contains the mermaid diagrams for the data store schemas used in t
1111
The schemas are generated from Zod definitions and provide a visual representation of the data structure.
1212
`);
1313

14-
for (const [name, schema] of Object.entries({ Letter: [LetterSchema], MI: [MISchema] })) {
14+
for (const [name, schema] of Object.entries({ Letter: [LetterSchema], MI: [MISchema], Supplier: [SupplierSchema] })) {
1515
const mermaid = generateMermaidDiagram(schema);
1616
fs.writeSync(out, `
1717
## ${name} schema

internal/datastore/src/types.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ erDiagram
3131
erDiagram
3232
MI {
3333
string id
34-
string supplierId "ref: Supplier"
34+
string supplierId
3535
string specificationId
3636
string groupId
3737
string lineItem
@@ -40,7 +40,16 @@ erDiagram
4040
string createdAt
4141
string updatedAt
4242
}
43+
```
44+
45+
## Supplier schema
46+
47+
```mermaid
48+
erDiagram
4349
Supplier {
50+
string id
51+
string name
52+
string apimId
53+
string status "enum: ENABLED, DISABLED"
4454
}
45-
MI }o--|| Supplier : "supplierId"
4655
```

internal/datastore/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod';
2-
import { idRef } from 'zod-mermaid';
2+
import { idRef } from '@internal/helpers';
33

44
export const SupplerStatus = z.enum(['ENABLED', 'DISABLED']);
55

@@ -29,7 +29,7 @@ export const LetterSchemaBase = z.object({
2929
});
3030

3131
export const LetterSchema = LetterSchemaBase.extend({
32-
supplierId: z.string(),
32+
supplierId: idRef(SupplierSchema, 'id'),
3333
url: z.url(),
3434
createdAt: z.string(),
3535
updatedAt: z.string(),
@@ -57,7 +57,7 @@ export const MISchemaBase = z.object({
5757
});
5858

5959
export const MISchema = MISchemaBase.extend({
60-
supplierId: idRef(SupplierSchema),
60+
supplierId: idRef(SupplierSchema, 'id'),
6161
createdAt: z.string(),
6262
updatedAt: z.string(),
6363
ttl: z.int(),

internal/datastore/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"compilerOptions": {
3-
"isolatedModules": true
4-
},
5-
"extends": "@tsconfig/node22/tsconfig.json",
2+
"compilerOptions": {},
3+
"extends": "../../tsconfig.base.json",
64
"include": [
75
"src/**/*",
86
"jest.config.ts"

internal/helpers/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dependency directories
2+
node_modules/
3+
4+
# Built output
5+
dist/
6+
7+
# Coverage directory used by tools like istanbul
8+
coverage/
9+
10+
# Logs
11+
logs
12+
*.log
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
17+
# Editor directories and files
18+
.idea/
19+
.vscode/
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

internal/helpers/jest.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
4+
preset: "ts-jest",
5+
testEnvironment: "node",
6+
testMatch: ["**/src/__tests__/**/*.ts?(x)", "**/src/?(*.)+(spec|test).ts?(x)"],
7+
collectCoverageFrom: ["src/**/*.ts"],
8+
coveragePathIgnorePatterns: ["/node_modules/", "__tests__"],
9+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
10+
transform: {
11+
"^.+\\.tsx?$": ["ts-jest", { }]
12+
}
13+
};
14+
15+
export default config;

0 commit comments

Comments
 (0)