Skip to content

Commit

Permalink
feat: Match granular application type to primary type
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jul 23, 2024
1 parent c54ab40 commit b77604b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 4 deletions.
167 changes: 164 additions & 3 deletions schemas/discriminated.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,155 @@
}
],
"definitions": {
"Application<\"pa\">": {
"additionalProperties": false,
"properties": {
"applicationType": {
"$ref": "#/definitions/ApplicationTypeKeys",
"description": "Enforces an application type which matches the given primary type"
}
},
"required": [
"applicationType"
],
"type": "object"
},
"Application<\"pp\">": {
"additionalProperties": false,
"properties": {
"applicationType": {
"$ref": "#/definitions/ApplicationTypeKeys",
"description": "Enforces an application type which matches the given primary type"
}
},
"required": [
"applicationType"
],
"type": "object"
},
"Application<\"wtt\">": {
"additionalProperties": false,
"properties": {
"applicationType": {
"$ref": "#/definitions/ApplicationTypeKeys",
"description": "Enforces an application type which matches the given primary type"
}
},
"required": [
"applicationType"
],
"type": "object"
},
"ApplicationTypeKeys": {
"enum": [
"advertConsent",
"amendment",
"amendment.minorMaterial",
"amendment.nonMaterial",
"approval",
"approval.conditions",
"approval.reservedMatters",
"complianceConfirmation",
"environmentalImpact",
"environmentalImpact.scoping",
"environmentalImpact.screening",
"hazardousSubstanceConsent",
"hedgerowRemovalNotice",
"landDrainageConsent",
"ldc",
"ldc.breachOfCondition",
"ldc.existing",
"ldc.listedBuildingWorks",
"ldc.proposed",
"listed",
"notifyCompletion",
"obligation",
"obligation.discharge",
"obligation.modify",
"onshoreExtractionOilAndGas",
"onshoreExtractionOilAndGas.other",
"onshoreExtractionOilAndGas.pp.extension",
"onshoreExtractionOilAndGas.pp.waste",
"onshoreExtractionOilAndGas.pp.working",
"onshoreExtractionOilAndGas.review",
"onshoreExtractionOilAndGas.variation",
"pa",
"pa.part1.classA",
"pa.part1.classAA",
"pa.part3.classG",
"pa.part3.classM",
"pa.part3.classMA",
"pa.part3.classN",
"pa.part3.classQ",
"pa.part3.classR",
"pa.part3.classS",
"pa.part3.classT",
"pa.part3.classV",
"pa.part4.classBB",
"pa.part4.classBC",
"pa.part4.classCA",
"pa.part4.classE",
"pa.part6",
"pa.part6.classA",
"pa.part6.classB",
"pa.part6.classE",
"pa.part7.classC",
"pa.part7.classM",
"pa.part9.classD",
"pa.part11.classB",
"pa.part14.classA",
"pa.part14.classB",
"pa.part14.classJ",
"pa.part14.classK",
"pa.part14.classOA",
"pa.part16.classA",
"pa.part17",
"pa.part17.classB",
"pa.part17.classC",
"pa.part17.classG",
"pa.part18.classA",
"pa.part19.classTA",
"pa.part20.classA",
"pa.part20.classAA",
"pa.part20.classAB",
"pa.part20.classAC",
"pa.part20.classAD",
"pa.part20.classZA",
"pp",
"pp.full",
"pp.full.advertConsent",
"pp.full.demolition",
"pp.full.fastTrack.affordable",
"pp.full.householder",
"pp.full.householder.listed",
"pp.full.householder.retro",
"pp.full.major",
"pp.full.major.technicalDetails",
"pp.full.major.technicalDetails.waste",
"pp.full.major.waste",
"pp.full.minor",
"pp.full.minor.listed",
"pp.full.minor.technicalDetails",
"pp.mineralExtraction",
"pp.outline",
"pp.outline.all",
"pp.outline.some",
"pp.outline.minor",
"pp.outline.minor.all",
"pp.outline.minor.some",
"pp.outline.major",
"pp.outline.major.all",
"pp.outline.major.all.waste",
"pp.outline.major.some",
"pp.outline.major.some.waste",
"pp.pip",
"rightsOfWayOrder",
"wtt",
"wtt.consent",
"wtt.notice"
],
"type": "string"
},
"PPUser": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -41,12 +190,16 @@
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/Application%3C%22pp%22%3E"
},
"user": {
"$ref": "#/definitions/PPUser"
}
},
"required": [
"user"
"user",
"application"
],
"type": "object"
},
Expand All @@ -68,12 +221,16 @@
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/Application%3C%22pa%22%3E"
},
"user": {
"$ref": "#/definitions/UserBase"
}
},
"required": [
"user"
"user",
"application"
],
"type": "object"
},
Expand Down Expand Up @@ -133,12 +290,16 @@
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/Application%3C%22wtt%22%3E"
},
"user": {
"$ref": "#/definitions/WTTUser"
}
},
"required": [
"user"
"user",
"application"
],
"type": "object"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const ApplicationTypes = {
'Works to trees - Notification of proposed works to a tree in a Conservation Area',
};

type ApplicationTypeKeys = keyof typeof ApplicationTypes;
export type ApplicationTypeKeys = keyof typeof ApplicationTypes;

type GenericApplicationType<TKey extends ApplicationTypeKeys> = {
value: TKey;
Expand Down
17 changes: 17 additions & 0 deletions types/schemas/discriminated/Application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
ApplicationTypeKeys,
PrimaryApplicationTypes,
} from '../digitalPlanningApplication/enums/ApplicationTypes';

/**
* @internal
* @description Enforces an application type which matches the given primary type
*/
type ApplicationTypeOf<T extends PrimaryApplicationTypes> = Extract<
ApplicationTypeKeys,
`${T}.${string}`
>;

export interface Application<T extends PrimaryApplicationTypes> {
applicationType: ApplicationTypeOf<T>;
}
2 changes: 2 additions & 0 deletions types/schemas/discriminated/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes';
import {Application} from './Application';
import {User} from './User';

interface GenericApplication<T extends PrimaryApplicationTypes> {
primaryApplicationType: T;
data: {
user: User<T>;
application: Application<T>;
};
}

Expand Down

0 comments on commit b77604b

Please sign in to comment.