Skip to content

Commit e84bd02

Browse files
committed
CCM-12896: Move generated code to a digital-letters-events package
1 parent 248659c commit e84bd02

14 files changed

Lines changed: 181 additions & 93 deletions

File tree

lambdas/mesh-poll/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"aws-lambda": "^1.0.7",
4-
"typescript-schema-generator": "^0.0.1"
4+
"digital-letters-events": "^0.0.1"
55
},
66
"devDependencies": {
77
"@tsconfig/node22": "^22.0.2",

lambdas/mesh-poll/src/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Context } from 'aws-lambda';
22
import { mockDeep } from 'jest-mock-extended';
3-
import { PDMResourceSubmitted } from 'typescript-schema-generator';
3+
import { PDMResourceSubmitted } from 'digital-letters-events';
44
import { handler } from '..';
55

66
const context = mockDeep<Context>();

lambdas/mesh-poll/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-console -- Allowing console logging as this is an example file. */
22
// Replace me with the actual code for your Lambda function
33
import { Handler } from 'aws-lambda';
4-
import { PDMResourceSubmitted } from 'typescript-schema-generator';
5-
import eventValidator from 'typescript-schema-generator/PDMResourceSubmitted.js';
4+
import { PDMResourceSubmitted } from 'digital-letters-events';
5+
import eventValidator from 'digital-letters-events/PDMResourceSubmitted.js';
66

77
export const handler: Handler = async (event: PDMResourceSubmitted) => {
88
console.log('Received event:', event);

package-lock.json

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"utils/utils",
6161
"utils/sender-management",
6262
"src/cloudevents",
63+
"src/digital-letters-events",
6364
"src/typescript-schema-generator",
6465
"tests/playwright"
6566
]
File renamed without changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# digital-letters-events
2+
3+
This package contains the automatically-generated code that the
4+
[typescript-schema-generator](../typescript-schema-generator/) tool produces.
5+
6+
The source files in this package should not be edited directly. If changes are
7+
required, update the schemas in the
8+
[src/cloudevents/domains](../cloudevents/domains) directory and use the
9+
`typescript-schema-generator` tool to regenerate them.
10+
11+
## Using this Package
12+
13+
### Using Event Types
14+
15+
The event types can be used by simply installing the
16+
`digital-letters-events` package as a dependency and then importing
17+
the desired type:
18+
19+
```typescript
20+
import { PDMResourceSubmitted } from 'digital-letters-events';
21+
22+
const pdmResourceSubmittedEvent: PDMResourceSubmitted = {
23+
type: 'uk.nhs.notify.digital.letters.pdm.resource.submitted.v1',
24+
source:
25+
'/nhs/england/notify/staging/dev-647563337/data-plane/digitalletters/pdm',
26+
dataschema:
27+
'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-submitted-data.schema.json',
28+
specversion: '1.0',
29+
id: '0249e529-f947-4012-819e-b634eb71be79',
30+
subject:
31+
'customer/7ff8ed41-cd5f-20e4-ef4e-34f96d8cc8ac/75027ace-9b8c-bcfe-866e-6c24242cffc3/q58dnxk5e/4cbek805wwx/yiaw7bl0d/her/1ccb7eb8-c6fe-0a42-279a-2a0e48ff1ca9/zk',
32+
time: '2025-11-21T16:01:52.268Z',
33+
datacontenttype: 'application/json',
34+
traceparent: '00-ee4790eb6821064c645406abe918b3da-3a4e6957ce2a15de-01',
35+
tracestate: 'nisi quis',
36+
partitionkey: 'customer-7ff8ed41',
37+
recordedtime: '2025-11-21T16:01:53.268Z',
38+
sampledrate: 1,
39+
sequence: '00000000000350773861',
40+
severitytext: 'INFO',
41+
severitynumber: 2,
42+
dataclassification: 'restricted',
43+
dataregulation: 'ISO-27001',
44+
datacategory: 'non-sensitive',
45+
data: {
46+
messageReference: 'incididunt Ut aute laborum',
47+
senderId: 'officia voluptate culpa Ut dolor',
48+
resourceId: 'a2bcbb42-ab7e-42b6-88d6-74f8d3ca4a09',
49+
retryCount: 97_903_257,
50+
},
51+
};
52+
```
53+
54+
### Using Event Validator Functions
55+
56+
Validator functions for an event can be used by importing the default export
57+
from the relevant JS file in
58+
[`validators`](validators/):
59+
60+
```typescript
61+
import eventValidator from 'digital-letters-events/PDMResourceSubmitted.js';
62+
63+
const event = {};
64+
65+
const isEventValid = eventValidator(event);
66+
if (isEventValid) {
67+
console.log('Event is valid!');
68+
} else {
69+
console.error('Validation failure!', eventValidator.errors);
70+
throw new Error('Event validation failed');
71+
}
72+
```
73+
74+
Note: You will need to make sure the
75+
[`allowJs`](https://www.typescriptlang.org/tsconfig/#allowJs) option is set in
76+
your package's `tsconfig.json` in order to import the JS files.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"dependencies": {
3+
"ajv": "^8.17.1",
4+
"ajv-formats": "^3.0.1"
5+
},
6+
"description": "Generated Typescript types and standalone validator functions for the application's event schemas.",
7+
"devDependencies": {
8+
"rimraf": "^5.0.10",
9+
"typescript": "^5.9.3"
10+
},
11+
"exports": {
12+
".": {
13+
"types": "./types/index.d.ts"
14+
},
15+
"./*.js": {
16+
"default": "./validators/*.js",
17+
"types": "./validators/index.d.ts"
18+
}
19+
},
20+
"name": "digital-letters-events",
21+
"scripts": {
22+
"clean": "rimraf types validators",
23+
"test:unit": "echo \"No unit tests have been implemented for this package\"",
24+
"typecheck": "tsc --noEmit"
25+
},
26+
"version": "0.0.1"
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"isolatedModules": true,
5+
"outDir": "dist"
6+
},
7+
"exclude": [
8+
"node_modules"
9+
],
10+
"extends": "@tsconfig/node22/tsconfig.json",
11+
"include": [
12+
"validators/**/*",
13+
"types/**/*"
14+
]
15+
}

src/typescript-schema-generator/README.md

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,83 +21,21 @@ This will produce the following:
2121

2222
- Flattened JSON Event schemas in the [`schemas`](../../schemas/) directory
2323
- A full set of JSON schemas in the [`output`](../../output/) directory
24-
- A type definition for each event in the [`types`](./types/) directory
25-
- A validator function for each event in the [`validators`](./validators/) directory
24+
- A type definition for each event in the [`src/digital-letters-events/types`](../digital-letters-events/types/) directory
25+
- A validator function for each event in the [`src/digital-letters-events/validators`](../digital-letters-events/validators/) directory
2626

2727
### Generating Types
2828

2929
Once the JSON schemas have been built, types can be generated on their own by
3030
running the `generate-types` script from this package. This will update the
31-
type definitions in [`types`](./types/) only.
31+
type definitions in the
32+
[`src/digital-letters-events/types`](../digital-letters-events/types/)
33+
directory only.
3234

3335
### Generating Validators
3436

3537
Once the JSON schemas have been built, the validation functions can be
3638
generated on their own by running the `generate-validators` script from this
37-
package. This will update the validator functions in [`validators`](./validators/) only.
38-
39-
## Using Generated Code
40-
41-
### Using Generated Types
42-
43-
The generated types can be used by simply installing
44-
`typescript-schema-generator` as a dependency of your package and the importing
45-
the desired type:
46-
47-
```typescript
48-
import { PDMResourceSubmitted } from 'typescript-schema-generator';
49-
50-
const pdmResourceSubmittedEvent: PDMResourceSubmitted = {
51-
type: 'uk.nhs.notify.digital.letters.pdm.resource.submitted.v1',
52-
source:
53-
'/nhs/england/notify/staging/dev-647563337/data-plane/digitalletters/pdm',
54-
dataschema:
55-
'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-submitted-data.schema.json',
56-
specversion: '1.0',
57-
id: '0249e529-f947-4012-819e-b634eb71be79',
58-
subject:
59-
'customer/7ff8ed41-cd5f-20e4-ef4e-34f96d8cc8ac/75027ace-9b8c-bcfe-866e-6c24242cffc3/q58dnxk5e/4cbek805wwx/yiaw7bl0d/her/1ccb7eb8-c6fe-0a42-279a-2a0e48ff1ca9/zk',
60-
time: '2025-11-21T16:01:52.268Z',
61-
datacontenttype: 'application/json',
62-
traceparent: '00-ee4790eb6821064c645406abe918b3da-3a4e6957ce2a15de-01',
63-
tracestate: 'nisi quis',
64-
partitionkey: 'customer-7ff8ed41',
65-
recordedtime: '2025-11-21T16:01:53.268Z',
66-
sampledrate: 1,
67-
sequence: '00000000000350773861',
68-
severitytext: 'INFO',
69-
severitynumber: 2,
70-
dataclassification: 'restricted',
71-
dataregulation: 'ISO-27001',
72-
datacategory: 'non-sensitive',
73-
data: {
74-
messageReference: 'incididunt Ut aute laborum',
75-
senderId: 'officia voluptate culpa Ut dolor',
76-
resourceId: 'a2bcbb42-ab7e-42b6-88d6-74f8d3ca4a09',
77-
retryCount: 97_903_257,
78-
},
79-
};
80-
```
81-
82-
### Using Generated Validator Functions
83-
84-
Validator functions for an event can be used by importing the default export
85-
from the relevant JS file in [`validators`](./validators/):
86-
87-
```typescript
88-
import eventValidator from 'typescript-schema-generator/PDMResourceSubmitted.js';
89-
90-
const event = {};
91-
92-
const isEventValid = eventValidator(event);
93-
if (isEventValid) {
94-
console.log('Event is valid!');
95-
} else {
96-
console.error('Validation failure!', eventValidator.errors);
97-
throw new Error('Event validation failed');
98-
}
99-
```
100-
101-
Note: You will need to make sure the
102-
[`allowJs`](https://www.typescriptlang.org/tsconfig/#allowJs) option is set in
103-
your package's `tsconfig.json` in order to import the JS files.
39+
package. This will update the validator functions in the
40+
[`src/digital-letters-events/validators`](../digital-letters-events/validators/)
41+
directory only.

0 commit comments

Comments
 (0)