@@ -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
2929Once the JSON schemas have been built, types can be generated on their own by
3030running 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
3537Once the JSON schemas have been built, the validation functions can be
3638generated 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