Skip to content

Commit 2052c7a

Browse files
committed
feat(lint): add linting and type checking scripts; update package.json and config files
1 parent 6054b00 commit 2052c7a

41 files changed

Lines changed: 575 additions & 1036 deletions

Some content is hidden

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

AGENTS.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ This is a monorepo containing:
88

99
- **packages/events** - Event schemas and domain models using Zod
1010
- **packages/event-builder** - CloudEvent builders for domain objects
11+
- **packages/file-store** - Loads on-disk config stores and validates records against the Zod schemas
12+
- **packages/ddb-publisher** - CLI and release bundle for auditing and publishing config-store records into DynamoDB
1113
- **lambdas/** - Lambda function implementations
1214
- **infrastructure/** - Terraform infrastructure as code
1315
- **docs/** - Documentation site
16+
- **actions/ddb-publish** - Composite GitHub Action wrapper around the bundled DynamoDB publisher
17+
- **tests/example-config-store** - Minimal end-to-end config-store fixture used by CLI and integration tests
1418

1519
## Event Builder Package
1620

@@ -46,6 +50,8 @@ The event-builder package provides functions to build CloudEvents from domain ob
4650

4751
All functions accept domain objects and a starting counter, returning an array of CloudEvents.
4852

53+
The package also exports single-record builders (`buildLetterVariantEvent()`, `buildPackSpecificationEvent()`, `buildSupplierEvent()`, `buildVolumeGroupEvent()`, `buildSupplierAllocationEvent()`, `buildSupplierPackEvent()`), plus `configFromEnv()`, `buildEventSource()`, and `buildBaseEventEnvelope()` from `packages/event-builder/src/index.ts`.
54+
4955
### Testing
5056

5157
```bash
@@ -94,8 +100,25 @@ const description = $Postage.shape.deliveryDays.meta()?.description;
94100

95101
1. Update domain schema in `packages/events/src/domain/`
96102
2. Update event builder if needed in `packages/event-builder/src/`
97-
3. Update test files in `__tests__/` directories
98-
4. Run tests: `npm test`
103+
3. If the persisted JSON shape or entity folders change, update `packages/file-store/src/`, `packages/ddb-publisher/src/`, and sample records in `tests/example-config-store/`
104+
4. Update test files in `packages/events/src/**/__tests__/`, `packages/event-builder/src/__tests__/`, `packages/file-store/src/__tests__/`, and `packages/ddb-publisher/src/__tests__/` / `src/__integration__/` as needed
105+
5. Regenerate schema artefacts from `packages/events` when required: `npm run gen:jsonschema`, `npm run gen:asyncapi`, `npm run gen:erd`
106+
6. Run tests: `npm run test:unit`
107+
108+
### Working with the Config Store and DDB Publisher
109+
110+
1. Persisted entity directories are fixed to: `volume-group`, `letter-variant`, `pack-specification`, `supplier`, `supplier-allocation`, `supplier-pack`
111+
2. Use `loadConfigStore()` from `packages/file-store/src/loader/config-store-loader.ts` to read JSON records and `validateConfigStore()` from `packages/file-store/src/validation/config-store-validator.ts` to collect schema issues
112+
3. Record filenames matter: `supplier/sup-1.json` must contain `"id": "sup-1"`, or validation fails
113+
4. For local validation without AWS calls, run:
114+
115+
```bash
116+
npm run cli --workspace @supplier-config/ddb-publisher -- \
117+
--source tests/example-config-store \
118+
--env draft \
119+
--table supplier-config-draft \
120+
--dry-run
121+
```
99122

100123
### Adding Metadata to Schema Fields
101124

@@ -139,16 +162,29 @@ Common markdown rules to follow:
139162
# Install all dependencies
140163
npm install
141164

142-
# Run tests for specific workspace
143-
npm test --workspace=packages/events
144-
npm test --workspace=packages/event-builder
165+
# Run unit tests for all workspaces
166+
npm run test:unit
167+
168+
# Run tests for specific workspaces
169+
npm run test:unit --workspace @nhsdigital/nhs-notify-event-schemas-supplier-config
170+
npm run test:unit --workspace @supplier-config/event-builder
171+
172+
# Run integration tests for the DynamoDB publisher
173+
npm run test:integration --workspace @supplier-config/ddb-publisher
145174

146175
# Build all packages
147176
npm run build --workspaces
148177

149178
# Lint all code
150179
npm run lint
151180

181+
# Type check all workspaces
182+
npm run typecheck
183+
184+
# Check/fix dependency version drift across workspaces
185+
npm run deps:check
186+
npm run deps:sync
187+
152188
# Check markdown formatting
153189
./scripts/githooks/check-markdown-format.sh <file>
154190

@@ -173,9 +209,17 @@ Check the error output for specific Zod validation failures. Common issues:
173209
- Wrong data types (string vs number)
174210
- Invalid date formats
175211

212+
### Local DynamoDB and Testcontainers
213+
214+
- `SUPPLIER_CONFIG_DDB_ENDPOINT_URL=http://localhost:8000` points `ddb-publisher` at DynamoDB Local; when the endpoint is localhost-based, the CLI supplies default fake AWS credentials if they are unset
215+
- `packages/ddb-publisher/src/__integration__/publish-action.integration.test.ts` uses Testcontainers; if Docker startup fails under Colima, retry with `TESTCONTAINERS_RYUK_DISABLED=true` or `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock`
216+
176217
## Agent Notes
177218

178219
- The project uses Zod 4.x for schema validation
179220
- Metadata is stored in Zod's global registry via `.meta()`
180221
- Test files should be updated whenever domain models change
181222
- Always run markdown linter when editing `.md` files to catch formatting issues
223+
- `tests/example-config-store/` is the shared fixture for local CLI runs and `ddb-publisher` integration tests
224+
- Persisted entity directory names are enforced by `packages/file-store/src/types.ts` and `packages/file-store/src/loader/config-store-loader.ts`
225+
- Root automation entry points are `npm run test:unit`, `npm run test:integration`, and `npm run typecheck`

eslint.config.mjs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@ import {
2020
} from 'eslint-config-airbnb-extended';
2121
import { rules as prettierConfigRules } from 'eslint-config-prettier';
2222

23-
import { dirname } from 'node:path';
24-
import { fileURLToPath } from 'node:url';
25-
import { FlatCompat } from '@eslint/eslintrc';
26-
27-
const __filename = fileURLToPath(import.meta.url);
28-
const __dirname = dirname(__filename);
29-
30-
const compat = new FlatCompat({
31-
baseDirectory: __dirname,
32-
});
3323

3424
export default defineConfig([
3525
globalIgnores([
3626
'**/*/coverage/*',
3727
'**/.build',
3828
'**/node_modules',
3929
'**/dist',
30+
'**/artifacts/**',
4031
'**/test-results',
4132
'**/playwright-report*',
4233
'eslint.config.mjs',
@@ -61,7 +52,17 @@ export default defineConfig([
6152
ignores: ['**/*.json'],
6253
languageOptions: {
6354
parserOptions: {
64-
projectService: true,
55+
projectService: {
56+
allowDefaultProject: [
57+
'*.js',
58+
'*.mjs',
59+
'*.ts',
60+
'packages/*/jest*.config.ts',
61+
'packages/*/scripts/*.{js,mjs,ts}',
62+
'scripts/*.{js,mjs,ts}',
63+
'scripts/*/*.{js,mjs,ts}',
64+
],
65+
},
6566
tsconfigRootDir: import.meta.dirname,
6667
},
6768
},
@@ -72,6 +73,11 @@ export default defineConfig([
7273
extends: [tseslint.configs.disableTypeChecked],
7374
},
7475

76+
{
77+
files: ['**/*.config.ts', '**/jest*.config.ts'],
78+
extends: [tseslint.configs.disableTypeChecked],
79+
},
80+
7581
{
7682
settings: {
7783
'import-x/resolver-next': [
@@ -196,6 +202,7 @@ export default defineConfig([
196202
},
197203
],
198204
'import-x/extensions': 0,
205+
'unicorn/no-array-callback-reference': 0,
199206
},
200207
},
201208
{
@@ -205,14 +212,21 @@ export default defineConfig([
205212
},
206213
},
207214
{
208-
files: ['**/__tests__/**'],
215+
files: [
216+
'**/__tests__/**',
217+
'**/__integration__/**',
218+
'tests/**',
219+
'**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs}',
220+
],
209221
rules: {
210222
'import-x/no-extraneous-dependencies': [
211223
2,
212224
{
213225
devDependencies: true,
214226
},
215227
],
228+
'security/detect-non-literal-fs-filename': 0,
229+
'sonarjs/publicly-writable-directories': 0,
216230
},
217231
},
218232
{
@@ -230,23 +244,33 @@ export default defineConfig([
230244
},
231245
},
232246
{
233-
files: ['scripts/**'],
247+
files: [
248+
'scripts/**',
249+
'packages/*/scripts/*.{js,mjs,ts}',
250+
],
251+
extends: [tseslint.configs.disableTypeChecked],
234252
rules: {
235253
'import-x/no-extraneous-dependencies': [
236254
'error',
237255
{ devDependencies: true },
238256
],
257+
'no-console': 0,
258+
'security/detect-non-literal-fs-filename': 0,
239259
},
240260
},
241261
// Add CLI directory override to allow console usage
242262
{
243-
files: ['**/cli/**/*.{js,jsx,ts,tsx,mjs,cjs}'],
263+
files: [
264+
'**/cli.{js,jsx,ts,tsx,mjs,cjs}',
265+
'**/cli/**/*.{js,jsx,ts,tsx,mjs,cjs}',
266+
],
244267
rules: {
245268
'no-console': 0,
246269
'import-x/no-extraneous-dependencies': [
247270
'error',
248271
{ devDependencies: true },
249272
],
273+
'security/detect-non-literal-fs-filename': 0,
250274
},
251275
},
252276
// misc rule overrides
@@ -256,6 +280,7 @@ export default defineConfig([
256280
'no-underscore-dangle': 0,
257281
'no-await-in-loop': 0,
258282
'no-plusplus': [2, { allowForLoopAfterthoughts: true }],
283+
'import-x/prefer-default-export': 0,
259284
'unicorn/prefer-top-level-await': 0, // top level await is not available in commonjs
260285
},
261286
},

lambdas/example-lambda/.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

lambdas/example-lambda/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

lambdas/example-lambda/jest.config.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

lambdas/example-lambda/package.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

lambdas/example-lambda/src/__tests__/index.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

lambdas/example-lambda/src/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

lambdas/example-lambda/tsconfig.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)