From 8a493e69418698fdf318b4318b18d8ebcac62daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 23 Jul 2024 17:16:51 +0100 Subject: [PATCH 1/9] feat(wip): Initial setup of a generic application type --- schemas/discriminated.json | 159 ++++++++++++++++++ scripts/build-schema.sh | 4 +- .../application/enums/ApplicationTypes.ts | 4 + types/schemas/discriminated/User.ts | 30 ++++ types/schemas/discriminated/index.ts | 33 ++++ 5 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 schemas/discriminated.json create mode 100644 types/schemas/discriminated/User.ts create mode 100644 types/schemas/discriminated/index.ts diff --git a/schemas/discriminated.json b/schemas/discriminated.json new file mode 100644 index 00000000..29649659 --- /dev/null +++ b/schemas/discriminated.json @@ -0,0 +1,159 @@ +{ + "$id": "@next", + "$schema": "http://json-schema.org/draft-07/schema#", + "anyOf": [ + { + "$ref": "#/definitions/PlanningPermissionApplication" + }, + { + "$ref": "#/definitions/PriorApprovalApplication" + }, + { + "$ref": "#/definitions/WorksToTreesApplication" + } + ], + "definitions": { + "PPUser": { + "additionalProperties": false, + "properties": { + "ppSpecificProperty": { + "type": "boolean" + }, + "role": { + "enum": [ + "applicant", + "agent", + "proxy" + ], + "type": "string" + } + }, + "required": [ + "ppSpecificProperty", + "role" + ], + "type": "object" + }, + "PlanningPermissionApplication": { + "additionalProperties": false, + "description": "Application for a \"Planning Permission\" project", + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "user": { + "$ref": "#/definitions/PPUser" + } + }, + "required": [ + "user" + ], + "type": "object" + }, + "primaryApplicationType": { + "const": "pp", + "type": "string" + } + }, + "required": [ + "primaryApplicationType", + "data" + ], + "type": "object" + }, + "PriorApprovalApplication": { + "additionalProperties": false, + "description": "Application for a \"Prior Approval\" project", + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "user": { + "$ref": "#/definitions/UserBase" + } + }, + "required": [ + "user" + ], + "type": "object" + }, + "primaryApplicationType": { + "const": "pa", + "type": "string" + } + }, + "required": [ + "primaryApplicationType", + "data" + ], + "type": "object" + }, + "UserBase": { + "additionalProperties": false, + "properties": { + "role": { + "enum": [ + "applicant", + "agent", + "proxy" + ], + "type": "string" + } + }, + "required": [ + "role" + ], + "type": "object" + }, + "WTTUser": { + "additionalProperties": false, + "properties": { + "role": { + "enum": [ + "applicant", + "agent", + "proxy" + ], + "type": "string" + }, + "wttSpecificProperty": { + "type": "boolean" + } + }, + "required": [ + "role", + "wttSpecificProperty" + ], + "type": "object" + }, + "WorksToTreesApplication": { + "additionalProperties": false, + "description": "Application for a \"Works to trees\" project", + "properties": { + "data": { + "additionalProperties": false, + "properties": { + "user": { + "$ref": "#/definitions/WTTUser" + } + }, + "required": [ + "user" + ], + "type": "object" + }, + "primaryApplicationType": { + "const": "wtt", + "type": "string" + } + }, + "required": [ + "primaryApplicationType", + "data" + ], + "type": "object" + } + }, + "description": "The root specification for a planning application in England generated by a digital planning service", + "title": "App" +} \ No newline at end of file diff --git a/scripts/build-schema.sh b/scripts/build-schema.sh index f16a8058..36a36320 100755 --- a/scripts/build-schema.sh +++ b/scripts/build-schema.sh @@ -7,8 +7,8 @@ version="${VERSION:-@next}" echo "Version set to $version" -dirs=("application") -types=("Application") +dirs=("application" "discriminated") +types=("Application" "App") for i in "${!dirs[@]}"; do dir=${dirs[$i]} diff --git a/types/schemas/application/enums/ApplicationTypes.ts b/types/schemas/application/enums/ApplicationTypes.ts index b9d516de..40bc0d7c 100644 --- a/types/schemas/application/enums/ApplicationTypes.ts +++ b/types/schemas/application/enums/ApplicationTypes.ts @@ -180,6 +180,10 @@ type GenericApplicationType = { description: (typeof ApplicationTypes)[TKey]; }; +type ExtractPrimaryKeys = T extends `${infer K}.${string}` ? K : T; + +export type PrimaryApplicationTypes = ExtractPrimaryKeys; + type ApplicationTypeMap = { [K in ApplicationTypeKeys]: GenericApplicationType; }; diff --git a/types/schemas/discriminated/User.ts b/types/schemas/discriminated/User.ts new file mode 100644 index 00000000..09afce99 --- /dev/null +++ b/types/schemas/discriminated/User.ts @@ -0,0 +1,30 @@ +import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes'; + +export interface UserBase { + role: 'applicant' | 'agent' | 'proxy'; +} + +export interface WTTUser extends UserBase { + wttSpecificProperty: boolean; +} + +export interface PPUser extends UserBase { + ppSpecificProperty: boolean; +} + +/** + * @internal + */ +interface UserVariants { + wtt: WTTUser; + pp: PPUser; +} + +/** + * @internal + */ +export type User = + T extends keyof UserVariants + ? UserVariants[T] + : // Default value for non-specific application types + UserBase; diff --git a/types/schemas/discriminated/index.ts b/types/schemas/discriminated/index.ts new file mode 100644 index 00000000..580f77b9 --- /dev/null +++ b/types/schemas/discriminated/index.ts @@ -0,0 +1,33 @@ +import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {User} from './User'; + +interface GenericApplication { + primaryApplicationType: T; + data: { + user: User; + }; +} + +/** + * @description Application for a "Planning Permission" project + */ +export type PlanningPermissionApplication = GenericApplication<'pp'>; + +/** + * @description Application for a "Prior Approval" project + */ +export type PriorApprovalApplication = GenericApplication<'pa'>; + +/** + * @description Application for a "Works to trees" project + */ +export type WorksToTreesApplication = GenericApplication<'wtt'>; + +/** + * @title App + * @description The root specification for a planning application in England generated by a digital planning service + */ +export type App = + | PlanningPermissionApplication + | PriorApprovalApplication + | WorksToTreesApplication; From 05872ca89fd6654e56118e3a8fbf259901a4da1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 24 Jul 2024 08:42:31 +0100 Subject: [PATCH 2/9] wip: Application data --- schemas/discriminated.json | 199 ++++++++++++++++-- .../application/enums/ApplicationTypes.ts | 2 +- .../schemas/discriminated/ApplicationData.ts | 37 ++++ types/schemas/discriminated/index.ts | 31 ++- 4 files changed, 248 insertions(+), 21 deletions(-) create mode 100644 types/schemas/discriminated/ApplicationData.ts diff --git a/schemas/discriminated.json b/schemas/discriminated.json index 29649659..86fd5d1e 100644 --- a/schemas/discriminated.json +++ b/schemas/discriminated.json @@ -13,6 +13,144 @@ } ], "definitions": { + "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" + }, + "PAApplicationData": { + "additionalProperties": false, + "properties": { + "applicationType": { + "$ref": "#/definitions/ApplicationTypeKeys" + } + }, + "required": [ + "applicationType" + ], + "type": "object" + }, + "PPApplicationData": { + "additionalProperties": false, + "properties": { + "applicationType": { + "$ref": "#/definitions/ApplicationTypeKeys" + }, + "ppSpecificProperty": { + "type": "number" + } + }, + "required": [ + "applicationType", + "ppSpecificProperty" + ], + "type": "object" + }, "PPUser": { "additionalProperties": false, "properties": { @@ -38,25 +176,28 @@ "additionalProperties": false, "description": "Application for a \"Planning Permission\" project", "properties": { + "applicationType": { + "$ref": "#/definitions/ApplicationTypeKeys" + }, "data": { "additionalProperties": false, "properties": { + "application": { + "$ref": "#/definitions/PAApplicationData" + }, "user": { "$ref": "#/definitions/PPUser" } }, "required": [ - "user" + "user", + "application" ], "type": "object" - }, - "primaryApplicationType": { - "const": "pp", - "type": "string" } }, "required": [ - "primaryApplicationType", + "applicationType", "data" ], "type": "object" @@ -65,25 +206,28 @@ "additionalProperties": false, "description": "Application for a \"Prior Approval\" project", "properties": { + "applicationType": { + "$ref": "#/definitions/ApplicationTypeKeys" + }, "data": { "additionalProperties": false, "properties": { + "application": { + "$ref": "#/definitions/PPApplicationData" + }, "user": { "$ref": "#/definitions/UserBase" } }, "required": [ - "user" + "user", + "application" ], "type": "object" - }, - "primaryApplicationType": { - "const": "pa", - "type": "string" } }, "required": [ - "primaryApplicationType", + "applicationType", "data" ], "type": "object" @@ -105,6 +249,22 @@ ], "type": "object" }, + "WTTApplicationData": { + "additionalProperties": false, + "properties": { + "applicationType": { + "$ref": "#/definitions/ApplicationTypeKeys" + }, + "wttSpecificProperty": { + "type": "number" + } + }, + "required": [ + "applicationType", + "wttSpecificProperty" + ], + "type": "object" + }, "WTTUser": { "additionalProperties": false, "properties": { @@ -130,25 +290,28 @@ "additionalProperties": false, "description": "Application for a \"Works to trees\" project", "properties": { + "applicationType": { + "$ref": "#/definitions/ApplicationTypeKeys" + }, "data": { "additionalProperties": false, "properties": { + "application": { + "$ref": "#/definitions/WTTApplicationData" + }, "user": { "$ref": "#/definitions/WTTUser" } }, "required": [ - "user" + "user", + "application" ], "type": "object" - }, - "primaryApplicationType": { - "const": "wtt", - "type": "string" } }, "required": [ - "primaryApplicationType", + "applicationType", "data" ], "type": "object" diff --git a/types/schemas/application/enums/ApplicationTypes.ts b/types/schemas/application/enums/ApplicationTypes.ts index 40bc0d7c..67a32d98 100644 --- a/types/schemas/application/enums/ApplicationTypes.ts +++ b/types/schemas/application/enums/ApplicationTypes.ts @@ -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 = { value: TKey; diff --git a/types/schemas/discriminated/ApplicationData.ts b/types/schemas/discriminated/ApplicationData.ts new file mode 100644 index 00000000..c2e3c523 --- /dev/null +++ b/types/schemas/discriminated/ApplicationData.ts @@ -0,0 +1,37 @@ +import {ApplicationTypeOf} from '.'; +import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes'; + +/** + * @internal + */ +interface ApplicationDataBase { + applicationType: ApplicationTypeOf; +} + +export interface WTTApplicationData extends ApplicationDataBase<'wtt'> { + wttSpecificProperty: number; +} + +export interface PPApplicationData extends ApplicationDataBase<'pp'> { + ppSpecificProperty: number; +} + +export type PAApplicationData = ApplicationDataBase<'pa'>; + +/** + * @internal + */ +interface ApplicationDataVariants { + wtt: WTTApplicationData; + pp: PAApplicationData; + pa: PPApplicationData; +} + +/** + * @internal + */ +export type ApplicationData = + T extends keyof ApplicationDataVariants + ? ApplicationDataVariants[T] + : // No fallback, all ApplicationData variants require a primary type + never; diff --git a/types/schemas/discriminated/index.ts b/types/schemas/discriminated/index.ts index 580f77b9..769dc16a 100644 --- a/types/schemas/discriminated/index.ts +++ b/types/schemas/discriminated/index.ts @@ -1,10 +1,23 @@ -import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import { + ApplicationTypeKeys, + PrimaryApplicationTypes, +} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {ApplicationData} from './ApplicationData'; import {User} from './User'; +/** + * @internal + */ +export type ApplicationTypeOf = Extract< + ApplicationTypeKeys, + `${T}.${string}` +>; + interface GenericApplication { - primaryApplicationType: T; + applicationType: ApplicationTypeOf; data: { user: User; + application: ApplicationData; }; } @@ -31,3 +44,17 @@ export type App = | PlanningPermissionApplication | PriorApprovalApplication | WorksToTreesApplication; + +const test: App = { + applicationType: 'wtt.consent', + data: { + user: { + role: 'agent', + wttSpecificProperty: true, + }, + application: { + applicationType: 'wtt.notice', + wttSpecificProperty: 123, + }, + }, +}; From c937dce19beb572d444edc5231825ac6fe25f825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 24 Jul 2024 12:21:16 +0100 Subject: [PATCH 3/9] feat: Handle primary and granular application types for ts-json-schema-generator --- schemas/discriminated.json | 334 +++++++++--------- .../schemas/discriminated/ApplicationData.ts | 34 +- types/schemas/discriminated/index.ts | 34 +- 3 files changed, 206 insertions(+), 196 deletions(-) diff --git a/schemas/discriminated.json b/schemas/discriminated.json index 86fd5d1e..e20a8088 100644 --- a/schemas/discriminated.json +++ b/schemas/discriminated.json @@ -9,145 +9,151 @@ "$ref": "#/definitions/PriorApprovalApplication" }, { - "$ref": "#/definitions/WorksToTreesApplication" + "$ref": "#/definitions/WorksToTreesApplications" } ], "definitions": { - "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" + "BaseWTT": { + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "wtt", + "type": "string" + }, + "data": { + "additionalProperties": false, + "properties": { + "application": { + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "wtt", + "type": "string" + }, + "somethingShared": { + "type": "string" + }, + "wttSpecificProperty": { + "type": "number" + } + }, + "required": [ + "applicationType", + "somethingShared", + "wttSpecificProperty" + ], + "type": "object" + }, + "user": { + "$ref": "#/definitions/WTTUser" + } + }, + "required": [ + "user", + "application" + ], + "type": "object" + } + }, + "required": [ + "applicationType", + "data" ], - "type": "string" + "type": "object" }, - "PAApplicationData": { + "ConsentWTT": { "additionalProperties": false, "properties": { "applicationType": { - "$ref": "#/definitions/ApplicationTypeKeys" + "const": "wtt.consent", + "type": "string" + }, + "data": { + "additionalProperties": false, + "properties": { + "application": { + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "wtt.consent", + "type": "string" + }, + "somethingShared": { + "type": "string" + }, + "wttSpecificProperty": { + "type": "number" + } + }, + "required": [ + "applicationType", + "somethingShared", + "wttSpecificProperty" + ], + "type": "object" + }, + "user": { + "$ref": "#/definitions/WTTUser" + } + }, + "required": [ + "user", + "application" + ], + "type": "object" } }, "required": [ - "applicationType" + "applicationType", + "data" ], "type": "object" }, - "PPApplicationData": { + "NoticeWTT": { "additionalProperties": false, "properties": { "applicationType": { - "$ref": "#/definitions/ApplicationTypeKeys" + "const": "wtt.notice", + "type": "string" }, - "ppSpecificProperty": { - "type": "number" + "data": { + "additionalProperties": false, + "properties": { + "application": { + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "wtt.notice", + "type": "string" + }, + "somethingShared": { + "type": "string" + }, + "wttSpecificProperty": { + "type": "number" + } + }, + "required": [ + "applicationType", + "somethingShared", + "wttSpecificProperty" + ], + "type": "object" + }, + "user": { + "$ref": "#/definitions/WTTUser" + } + }, + "required": [ + "user", + "application" + ], + "type": "object" } }, "required": [ "applicationType", - "ppSpecificProperty" + "data" ], "type": "object" }, @@ -177,13 +183,32 @@ "description": "Application for a \"Planning Permission\" project", "properties": { "applicationType": { - "$ref": "#/definitions/ApplicationTypeKeys" + "const": "pp", + "type": "string" }, "data": { "additionalProperties": false, "properties": { "application": { - "$ref": "#/definitions/PAApplicationData" + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "pp", + "type": "string" + }, + "ppSpecificProperty": { + "type": "number" + }, + "somethingShared": { + "type": "string" + } + }, + "required": [ + "applicationType", + "ppSpecificProperty", + "somethingShared" + ], + "type": "object" }, "user": { "$ref": "#/definitions/PPUser" @@ -207,13 +232,28 @@ "description": "Application for a \"Prior Approval\" project", "properties": { "applicationType": { - "$ref": "#/definitions/ApplicationTypeKeys" + "const": "pa", + "type": "string" }, "data": { "additionalProperties": false, "properties": { "application": { - "$ref": "#/definitions/PPApplicationData" + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "pa", + "type": "string" + }, + "somethingShared": { + "type": "string" + } + }, + "required": [ + "applicationType", + "somethingShared" + ], + "type": "object" }, "user": { "$ref": "#/definitions/UserBase" @@ -249,22 +289,6 @@ ], "type": "object" }, - "WTTApplicationData": { - "additionalProperties": false, - "properties": { - "applicationType": { - "$ref": "#/definitions/ApplicationTypeKeys" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "wttSpecificProperty" - ], - "type": "object" - }, "WTTUser": { "additionalProperties": false, "properties": { @@ -286,35 +310,19 @@ ], "type": "object" }, - "WorksToTreesApplication": { - "additionalProperties": false, - "description": "Application for a \"Works to trees\" project", - "properties": { - "applicationType": { - "$ref": "#/definitions/ApplicationTypeKeys" + "WorksToTreesApplications": { + "anyOf": [ + { + "$ref": "#/definitions/BaseWTT" }, - "data": { - "additionalProperties": false, - "properties": { - "application": { - "$ref": "#/definitions/WTTApplicationData" - }, - "user": { - "$ref": "#/definitions/WTTUser" - } - }, - "required": [ - "user", - "application" - ], - "type": "object" + { + "$ref": "#/definitions/ConsentWTT" + }, + { + "$ref": "#/definitions/NoticeWTT" } - }, - "required": [ - "applicationType", - "data" ], - "type": "object" + "description": "Application for a \"Works to trees\" project" } }, "description": "The root specification for a planning application in England generated by a digital planning service", diff --git a/types/schemas/discriminated/ApplicationData.ts b/types/schemas/discriminated/ApplicationData.ts index c2e3c523..7d3257d8 100644 --- a/types/schemas/discriminated/ApplicationData.ts +++ b/types/schemas/discriminated/ApplicationData.ts @@ -1,37 +1,39 @@ -import {ApplicationTypeOf} from '.'; -import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import { + ApplicationTypeKeys, + PrimaryApplicationTypes, +} from '../digitalPlanningApplication/enums/ApplicationTypes'; /** * @internal */ -interface ApplicationDataBase { - applicationType: ApplicationTypeOf; +export interface ApplicationDataBase { + applicationType: TGranular; + somethingShared: string; } -export interface WTTApplicationData extends ApplicationDataBase<'wtt'> { +export interface WTTApplicationData { wttSpecificProperty: number; } -export interface PPApplicationData extends ApplicationDataBase<'pp'> { +export interface PPApplicationData { ppSpecificProperty: number; } -export type PAApplicationData = ApplicationDataBase<'pa'>; - /** * @internal */ -interface ApplicationDataVariants { +export interface ApplicationDataVariants { wtt: WTTApplicationData; - pp: PAApplicationData; - pa: PPApplicationData; + pp: PPApplicationData; } /** * @internal */ -export type ApplicationData = - T extends keyof ApplicationDataVariants - ? ApplicationDataVariants[T] - : // No fallback, all ApplicationData variants require a primary type - never; +export type ApplicationData< + TPrimary extends PrimaryApplicationTypes, + TGranular extends ApplicationTypeKeys, +> = TPrimary extends keyof ApplicationDataVariants + ? ApplicationDataVariants[TPrimary] & ApplicationDataBase + : // Fallback to shared values only + ApplicationDataBase; diff --git a/types/schemas/discriminated/index.ts b/types/schemas/discriminated/index.ts index 769dc16a..02aa04f7 100644 --- a/types/schemas/discriminated/index.ts +++ b/types/schemas/discriminated/index.ts @@ -5,36 +5,35 @@ import { import {ApplicationData} from './ApplicationData'; import {User} from './User'; -/** - * @internal - */ -export type ApplicationTypeOf = Extract< - ApplicationTypeKeys, - `${T}.${string}` ->; - -interface GenericApplication { - applicationType: ApplicationTypeOf; +interface GenericApplication< + TPrimary extends PrimaryApplicationTypes, + TGranular extends ApplicationTypeKeys, +> { + applicationType: TGranular; data: { - user: User; - application: ApplicationData; + user: User; + application: ApplicationData; }; } /** * @description Application for a "Planning Permission" project */ -export type PlanningPermissionApplication = GenericApplication<'pp'>; +export type PlanningPermissionApplication = GenericApplication<'pp', 'pp'>; /** * @description Application for a "Prior Approval" project */ -export type PriorApprovalApplication = GenericApplication<'pa'>; +export type PriorApprovalApplication = GenericApplication<'pa', 'pa'>; + +export type BaseWTT = GenericApplication<'wtt', 'wtt'>; +export type ConsentWTT = GenericApplication<'wtt', 'wtt.consent'>; +export type NoticeWTT = GenericApplication<'wtt', 'wtt.notice'>; /** * @description Application for a "Works to trees" project */ -export type WorksToTreesApplication = GenericApplication<'wtt'>; +export type WorksToTreesApplications = BaseWTT | ConsentWTT | NoticeWTT; /** * @title App @@ -43,7 +42,7 @@ export type WorksToTreesApplication = GenericApplication<'wtt'>; export type App = | PlanningPermissionApplication | PriorApprovalApplication - | WorksToTreesApplication; + | WorksToTreesApplications; const test: App = { applicationType: 'wtt.consent', @@ -53,8 +52,9 @@ const test: App = { wttSpecificProperty: true, }, application: { - applicationType: 'wtt.notice', + applicationType: 'wtt.consent', wttSpecificProperty: 123, + somethingShared: 'abc', }, }, }; From b5591e47deed45305429802d71ac2ce7af2bcb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 24 Jul 2024 14:33:43 +0100 Subject: [PATCH 4/9] chore: Docs and tidy up --- schemas/discriminated.json | 7 +- .../application/enums/ApplicationTypes.ts | 2 +- .../schemas/discriminated/ApplicationData.ts | 18 +++-- types/schemas/discriminated/User.ts | 12 ++-- types/schemas/discriminated/index.ts | 70 ++++++++++--------- 5 files changed, 58 insertions(+), 51 deletions(-) diff --git a/schemas/discriminated.json b/schemas/discriminated.json index e20a8088..51902063 100644 --- a/schemas/discriminated.json +++ b/schemas/discriminated.json @@ -180,7 +180,6 @@ }, "PlanningPermissionApplication": { "additionalProperties": false, - "description": "Application for a \"Planning Permission\" project", "properties": { "applicationType": { "const": "pp", @@ -229,7 +228,6 @@ }, "PriorApprovalApplication": { "additionalProperties": false, - "description": "Application for a \"Prior Approval\" project", "properties": { "applicationType": { "const": "pa", @@ -321,10 +319,9 @@ { "$ref": "#/definitions/NoticeWTT" } - ], - "description": "Application for a \"Works to trees\" project" + ] } }, - "description": "The root specification for a planning application in England generated by a digital planning service", + "description": "(Temporary name to not clash with the existing `Application` type)\nThe root specification for a planning application in England generated by a digital planning service", "title": "App" } \ No newline at end of file diff --git a/types/schemas/application/enums/ApplicationTypes.ts b/types/schemas/application/enums/ApplicationTypes.ts index 67a32d98..2de754ec 100644 --- a/types/schemas/application/enums/ApplicationTypes.ts +++ b/types/schemas/application/enums/ApplicationTypes.ts @@ -182,7 +182,7 @@ type GenericApplicationType = { type ExtractPrimaryKeys = T extends `${infer K}.${string}` ? K : T; -export type PrimaryApplicationTypes = ExtractPrimaryKeys; +export type PrimaryApplicationType = ExtractPrimaryKeys; type ApplicationTypeMap = { [K in ApplicationTypeKeys]: GenericApplicationType; diff --git a/types/schemas/discriminated/ApplicationData.ts b/types/schemas/discriminated/ApplicationData.ts index 7d3257d8..229a1a0a 100644 --- a/types/schemas/discriminated/ApplicationData.ts +++ b/types/schemas/discriminated/ApplicationData.ts @@ -1,26 +1,33 @@ import { ApplicationTypeKeys, - PrimaryApplicationTypes, + PrimaryApplicationType, } from '../digitalPlanningApplication/enums/ApplicationTypes'; /** * @internal + * Base type for ApplicationData. Contains all shared properties across all application types */ export interface ApplicationDataBase { applicationType: TGranular; somethingShared: string; } +/** + * @description Specific ApplicationData required for "Works to trees" applications + */ export interface WTTApplicationData { wttSpecificProperty: number; } +/** + * @description Specific ApplicationData required for "Planning Permission" applications + */ export interface PPApplicationData { ppSpecificProperty: number; } /** - * @internal + * TypeMap of PrimaryApplicationTypes to their specific ApplicationData models */ export interface ApplicationDataVariants { wtt: WTTApplicationData; @@ -29,11 +36,12 @@ export interface ApplicationDataVariants { /** * @internal + * Conditional type to return a specific or generic ApplicationData model, based on PrimaryApplicationType + * TPrimary and TGranular are both required as the granular variable is exposed, and must match the value in the Application root */ export type ApplicationData< - TPrimary extends PrimaryApplicationTypes, + TPrimary extends PrimaryApplicationType, TGranular extends ApplicationTypeKeys, > = TPrimary extends keyof ApplicationDataVariants ? ApplicationDataVariants[TPrimary] & ApplicationDataBase - : // Fallback to shared values only - ApplicationDataBase; + : ApplicationDataBase; diff --git a/types/schemas/discriminated/User.ts b/types/schemas/discriminated/User.ts index 09afce99..15d8c87b 100644 --- a/types/schemas/discriminated/User.ts +++ b/types/schemas/discriminated/User.ts @@ -1,4 +1,4 @@ -import {PrimaryApplicationTypes} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {PrimaryApplicationType} from '../digitalPlanningApplication/enums/ApplicationTypes'; export interface UserBase { role: 'applicant' | 'agent' | 'proxy'; @@ -13,7 +13,7 @@ export interface PPUser extends UserBase { } /** - * @internal + * TypeMap of PrimaryApplicationTypes to their specific User models */ interface UserVariants { wtt: WTTUser; @@ -22,9 +22,7 @@ interface UserVariants { /** * @internal + * Conditional type to return a specific or generic User model, based on PrimaryApplicationType */ -export type User = - T extends keyof UserVariants - ? UserVariants[T] - : // Default value for non-specific application types - UserBase; +export type User = + TPrimary extends keyof UserVariants ? UserVariants[TPrimary] : UserBase; diff --git a/types/schemas/discriminated/index.ts b/types/schemas/discriminated/index.ts index 02aa04f7..ce35cfbb 100644 --- a/types/schemas/discriminated/index.ts +++ b/types/schemas/discriminated/index.ts @@ -1,12 +1,18 @@ import { ApplicationTypeKeys, - PrimaryApplicationTypes, + PrimaryApplicationType, } from '../digitalPlanningApplication/enums/ApplicationTypes'; import {ApplicationData} from './ApplicationData'; import {User} from './User'; -interface GenericApplication< - TPrimary extends PrimaryApplicationTypes, +/** + * @internal + * The generic base type for all applications + * Takes a primary and granular application type which allows child properties to differ based on these inputs + * Deriving `TPrimary` from `TGranular` is possible in TS, but not in a way which is currently compatible with ts-json-schema-generator + */ +interface ApplicationSpecification< + TPrimary extends PrimaryApplicationType, TGranular extends ApplicationTypeKeys, > { applicationType: TGranular; @@ -16,45 +22,43 @@ interface GenericApplication< }; } -/** - * @description Application for a "Planning Permission" project - */ -export type PlanningPermissionApplication = GenericApplication<'pp', 'pp'>; - -/** - * @description Application for a "Prior Approval" project - */ -export type PriorApprovalApplication = GenericApplication<'pa', 'pa'>; +export type PlanningPermissionApplication = ApplicationSpecification< + 'pp', + 'pp' +>; +// TODO: All granular types -export type BaseWTT = GenericApplication<'wtt', 'wtt'>; -export type ConsentWTT = GenericApplication<'wtt', 'wtt.consent'>; -export type NoticeWTT = GenericApplication<'wtt', 'wtt.notice'>; +export type PriorApprovalApplication = ApplicationSpecification<'pa', 'pa'>; +// TODO: All granular types -/** - * @description Application for a "Works to trees" project - */ export type WorksToTreesApplications = BaseWTT | ConsentWTT | NoticeWTT; +export type BaseWTT = ApplicationSpecification<'wtt', 'wtt'>; +export type ConsentWTT = ApplicationSpecification<'wtt', 'wtt.consent'>; +export type NoticeWTT = ApplicationSpecification<'wtt', 'wtt.notice'>; /** * @title App - * @description The root specification for a planning application in England generated by a digital planning service + * @description + * (Temporary name to not clash with the existing `Application` type) + * The root specification for a planning application in England generated by a digital planning service */ export type App = | PlanningPermissionApplication | PriorApprovalApplication | WorksToTreesApplications; +// TODO: All the rest! -const test: App = { - applicationType: 'wtt.consent', - data: { - user: { - role: 'agent', - wttSpecificProperty: true, - }, - application: { - applicationType: 'wtt.consent', - wttSpecificProperty: 123, - somethingShared: 'abc', - }, - }, -}; +// const test: App = { +// applicationType: 'wtt.consent', +// data: { +// user: { +// role: 'agent', +// wttSpecificProperty: true, +// }, +// application: { +// applicationType: 'wtt.consent', +// wttSpecificProperty: 123, +// somethingShared: 'abc', +// }, +// }, +// }; From 06a37baf1d02148c95a4a17c6045b83e354fff2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 24 Jul 2024 14:40:53 +0100 Subject: [PATCH 5/9] chore: Standardise temporary schema name 'app' --- schemas/{discriminated.json => app.json} | 0 scripts/build-schema.sh | 2 +- types/schemas/{discriminated => app}/ApplicationData.ts | 0 types/schemas/{discriminated => app}/User.ts | 0 types/schemas/{discriminated => app}/index.ts | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename schemas/{discriminated.json => app.json} (100%) rename types/schemas/{discriminated => app}/ApplicationData.ts (100%) rename types/schemas/{discriminated => app}/User.ts (100%) rename types/schemas/{discriminated => app}/index.ts (100%) diff --git a/schemas/discriminated.json b/schemas/app.json similarity index 100% rename from schemas/discriminated.json rename to schemas/app.json diff --git a/scripts/build-schema.sh b/scripts/build-schema.sh index 36a36320..2eb42443 100755 --- a/scripts/build-schema.sh +++ b/scripts/build-schema.sh @@ -7,7 +7,7 @@ version="${VERSION:-@next}" echo "Version set to $version" -dirs=("application" "discriminated") +dirs=("application" "app") types=("Application" "App") for i in "${!dirs[@]}"; do diff --git a/types/schemas/discriminated/ApplicationData.ts b/types/schemas/app/ApplicationData.ts similarity index 100% rename from types/schemas/discriminated/ApplicationData.ts rename to types/schemas/app/ApplicationData.ts diff --git a/types/schemas/discriminated/User.ts b/types/schemas/app/User.ts similarity index 100% rename from types/schemas/discriminated/User.ts rename to types/schemas/app/User.ts diff --git a/types/schemas/discriminated/index.ts b/types/schemas/app/index.ts similarity index 100% rename from types/schemas/discriminated/index.ts rename to types/schemas/app/index.ts From 83d407dc95b037f92cc88f84ded7bb55c44c8432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 25 Jul 2024 10:53:05 +0100 Subject: [PATCH 6/9] feat: Hoist TPrimary to root only --- schemas/app.json | 143 ++++++++++----------------- types/schemas/app/ApplicationData.ts | 24 ++--- types/schemas/app/index.ts | 3 +- 3 files changed, 61 insertions(+), 109 deletions(-) diff --git a/schemas/app.json b/schemas/app.json index 51902063..e436a7ef 100644 --- a/schemas/app.json +++ b/schemas/app.json @@ -13,6 +13,19 @@ } ], "definitions": { + "ApplicationDataBase": { + "additionalProperties": false, + "description": "Base type for ApplicationData. Contains all shared properties across all application types", + "properties": { + "somethingShared": { + "type": "string" + } + }, + "required": [ + "somethingShared" + ], + "type": "object" + }, "BaseWTT": { "additionalProperties": false, "properties": { @@ -24,25 +37,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt", - "type": "string" - }, - "somethingShared": { - "type": "string" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "somethingShared", - "wttSpecificProperty" - ], - "type": "object" + "$ref": "#/definitions/WTTApplicationData" }, "user": { "$ref": "#/definitions/WTTUser" @@ -72,25 +67,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt.consent", - "type": "string" - }, - "somethingShared": { - "type": "string" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "somethingShared", - "wttSpecificProperty" - ], - "type": "object" + "$ref": "#/definitions/WTTApplicationData" }, "user": { "$ref": "#/definitions/WTTUser" @@ -120,25 +97,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt.notice", - "type": "string" - }, - "somethingShared": { - "type": "string" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "somethingShared", - "wttSpecificProperty" - ], - "type": "object" + "$ref": "#/definitions/WTTApplicationData" }, "user": { "$ref": "#/definitions/WTTUser" @@ -157,6 +116,23 @@ ], "type": "object" }, + "PPApplicationData": { + "additionalProperties": false, + "description": "Specific ApplicationData required for \"Planning Permission\" applications", + "properties": { + "ppSpecificProperty": { + "type": "number" + }, + "somethingShared": { + "type": "string" + } + }, + "required": [ + "ppSpecificProperty", + "somethingShared" + ], + "type": "object" + }, "PPUser": { "additionalProperties": false, "properties": { @@ -189,25 +165,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "pp", - "type": "string" - }, - "ppSpecificProperty": { - "type": "number" - }, - "somethingShared": { - "type": "string" - } - }, - "required": [ - "applicationType", - "ppSpecificProperty", - "somethingShared" - ], - "type": "object" + "$ref": "#/definitions/PPApplicationData" }, "user": { "$ref": "#/definitions/PPUser" @@ -237,21 +195,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "pa", - "type": "string" - }, - "somethingShared": { - "type": "string" - } - }, - "required": [ - "applicationType", - "somethingShared" - ], - "type": "object" + "$ref": "#/definitions/ApplicationDataBase" }, "user": { "$ref": "#/definitions/UserBase" @@ -287,6 +231,23 @@ ], "type": "object" }, + "WTTApplicationData": { + "additionalProperties": false, + "description": "Specific ApplicationData required for \"Works to trees\" applications", + "properties": { + "somethingShared": { + "type": "string" + }, + "wttSpecificProperty": { + "type": "number" + } + }, + "required": [ + "somethingShared", + "wttSpecificProperty" + ], + "type": "object" + }, "WTTUser": { "additionalProperties": false, "properties": { diff --git a/types/schemas/app/ApplicationData.ts b/types/schemas/app/ApplicationData.ts index 229a1a0a..fb95ca79 100644 --- a/types/schemas/app/ApplicationData.ts +++ b/types/schemas/app/ApplicationData.ts @@ -1,28 +1,23 @@ -import { - ApplicationTypeKeys, - PrimaryApplicationType, -} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {PrimaryApplicationType} from '../digitalPlanningApplication/enums/ApplicationTypes'; /** - * @internal * Base type for ApplicationData. Contains all shared properties across all application types */ -export interface ApplicationDataBase { - applicationType: TGranular; +export interface ApplicationDataBase { somethingShared: string; } /** * @description Specific ApplicationData required for "Works to trees" applications */ -export interface WTTApplicationData { +export interface WTTApplicationData extends ApplicationDataBase { wttSpecificProperty: number; } /** * @description Specific ApplicationData required for "Planning Permission" applications */ -export interface PPApplicationData { +export interface PPApplicationData extends ApplicationDataBase { ppSpecificProperty: number; } @@ -37,11 +32,8 @@ export interface ApplicationDataVariants { /** * @internal * Conditional type to return a specific or generic ApplicationData model, based on PrimaryApplicationType - * TPrimary and TGranular are both required as the granular variable is exposed, and must match the value in the Application root */ -export type ApplicationData< - TPrimary extends PrimaryApplicationType, - TGranular extends ApplicationTypeKeys, -> = TPrimary extends keyof ApplicationDataVariants - ? ApplicationDataVariants[TPrimary] & ApplicationDataBase - : ApplicationDataBase; +export type ApplicationData = + TPrimary extends keyof ApplicationDataVariants + ? ApplicationDataVariants[TPrimary] + : ApplicationDataBase; diff --git a/types/schemas/app/index.ts b/types/schemas/app/index.ts index ce35cfbb..8cd96be2 100644 --- a/types/schemas/app/index.ts +++ b/types/schemas/app/index.ts @@ -18,7 +18,7 @@ interface ApplicationSpecification< applicationType: TGranular; data: { user: User; - application: ApplicationData; + application: ApplicationData; }; } @@ -56,7 +56,6 @@ export type App = // wttSpecificProperty: true, // }, // application: { -// applicationType: 'wtt.consent', // wttSpecificProperty: 123, // somethingShared: 'abc', // }, From 23001127ed6d5fc3f1023c2e47b3a18a41d92da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 25 Jul 2024 11:27:38 +0100 Subject: [PATCH 7/9] feat: Remove repetiton by using `Extract<>` --- schemas/app.json | 129 +++++++++---------------------------- types/schemas/app/index.ts | 8 +-- 2 files changed, 34 insertions(+), 103 deletions(-) diff --git a/schemas/app.json b/schemas/app.json index e436a7ef..adbb73cd 100644 --- a/schemas/app.json +++ b/schemas/app.json @@ -26,96 +26,6 @@ ], "type": "object" }, - "BaseWTT": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt", - "type": "string" - }, - "data": { - "additionalProperties": false, - "properties": { - "application": { - "$ref": "#/definitions/WTTApplicationData" - }, - "user": { - "$ref": "#/definitions/WTTUser" - } - }, - "required": [ - "user", - "application" - ], - "type": "object" - } - }, - "required": [ - "applicationType", - "data" - ], - "type": "object" - }, - "ConsentWTT": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt.consent", - "type": "string" - }, - "data": { - "additionalProperties": false, - "properties": { - "application": { - "$ref": "#/definitions/WTTApplicationData" - }, - "user": { - "$ref": "#/definitions/WTTUser" - } - }, - "required": [ - "user", - "application" - ], - "type": "object" - } - }, - "required": [ - "applicationType", - "data" - ], - "type": "object" - }, - "NoticeWTT": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt.notice", - "type": "string" - }, - "data": { - "additionalProperties": false, - "properties": { - "application": { - "$ref": "#/definitions/WTTApplicationData" - }, - "user": { - "$ref": "#/definitions/WTTUser" - } - }, - "required": [ - "user", - "application" - ], - "type": "object" - } - }, - "required": [ - "applicationType", - "data" - ], - "type": "object" - }, "PPApplicationData": { "additionalProperties": false, "description": "Specific ApplicationData required for \"Planning Permission\" applications", @@ -270,17 +180,38 @@ "type": "object" }, "WorksToTreesApplications": { - "anyOf": [ - { - "$ref": "#/definitions/BaseWTT" - }, - { - "$ref": "#/definitions/ConsentWTT" + "additionalProperties": false, + "properties": { + "applicationType": { + "enum": [ + "wtt", + "wtt.consent", + "wtt.notice" + ], + "type": "string" }, - { - "$ref": "#/definitions/NoticeWTT" + "data": { + "additionalProperties": false, + "properties": { + "application": { + "$ref": "#/definitions/WTTApplicationData" + }, + "user": { + "$ref": "#/definitions/WTTUser" + } + }, + "required": [ + "user", + "application" + ], + "type": "object" } - ] + }, + "required": [ + "applicationType", + "data" + ], + "type": "object" } }, "description": "(Temporary name to not clash with the existing `Application` type)\nThe root specification for a planning application in England generated by a digital planning service", diff --git a/types/schemas/app/index.ts b/types/schemas/app/index.ts index 8cd96be2..e520863a 100644 --- a/types/schemas/app/index.ts +++ b/types/schemas/app/index.ts @@ -31,10 +31,10 @@ export type PlanningPermissionApplication = ApplicationSpecification< export type PriorApprovalApplication = ApplicationSpecification<'pa', 'pa'>; // TODO: All granular types -export type WorksToTreesApplications = BaseWTT | ConsentWTT | NoticeWTT; -export type BaseWTT = ApplicationSpecification<'wtt', 'wtt'>; -export type ConsentWTT = ApplicationSpecification<'wtt', 'wtt.consent'>; -export type NoticeWTT = ApplicationSpecification<'wtt', 'wtt.notice'>; +export type WorksToTreesApplications = ApplicationSpecification< + 'wtt', + Extract +>; /** * @title App From 20e5e4e3024e33702421dde3fd6a57ffcf43b58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 25 Jul 2024 21:18:16 +0100 Subject: [PATCH 8/9] chore: Fixes after rebase --- .../planningPermission/fullHouseholderInConservationArea.ts | 2 +- types/schemas/app/ApplicationData.ts | 2 +- types/schemas/app/User.ts | 2 +- types/schemas/app/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/application/data/planningPermission/fullHouseholderInConservationArea.ts b/examples/application/data/planningPermission/fullHouseholderInConservationArea.ts index b022088a..0dae1104 100644 --- a/examples/application/data/planningPermission/fullHouseholderInConservationArea.ts +++ b/examples/application/data/planningPermission/fullHouseholderInConservationArea.ts @@ -1,4 +1,4 @@ -import { Application } from "../../../../types/schemas/application"; +import {Application} from '../../../../types/schemas/application'; const version = process.env['VERSION'] || '@next'; diff --git a/types/schemas/app/ApplicationData.ts b/types/schemas/app/ApplicationData.ts index fb95ca79..bd1eac9a 100644 --- a/types/schemas/app/ApplicationData.ts +++ b/types/schemas/app/ApplicationData.ts @@ -1,4 +1,4 @@ -import {PrimaryApplicationType} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {PrimaryApplicationType} from '../application/enums/ApplicationTypes'; /** * Base type for ApplicationData. Contains all shared properties across all application types diff --git a/types/schemas/app/User.ts b/types/schemas/app/User.ts index 15d8c87b..da248014 100644 --- a/types/schemas/app/User.ts +++ b/types/schemas/app/User.ts @@ -1,4 +1,4 @@ -import {PrimaryApplicationType} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {PrimaryApplicationType} from '../application/enums/ApplicationTypes'; export interface UserBase { role: 'applicant' | 'agent' | 'proxy'; diff --git a/types/schemas/app/index.ts b/types/schemas/app/index.ts index e520863a..7bb032e8 100644 --- a/types/schemas/app/index.ts +++ b/types/schemas/app/index.ts @@ -1,7 +1,7 @@ import { ApplicationTypeKeys, PrimaryApplicationType, -} from '../digitalPlanningApplication/enums/ApplicationTypes'; +} from '../application/enums/ApplicationTypes'; import {ApplicationData} from './ApplicationData'; import {User} from './User'; From 5d87b03770c8eb42fe40fae8ba1ffc3a5c5a9c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 29 Jul 2024 12:21:39 +0100 Subject: [PATCH 9/9] chore: App => PrototypeApplication --- schemas/{app.json => prototypeApplication.json} | 4 ++-- scripts/build-schema.sh | 4 ++-- .../{app => prototypeApplication}/ApplicationData.ts | 0 types/schemas/{app => prototypeApplication}/User.ts | 0 types/schemas/{app => prototypeApplication}/index.ts | 7 +++---- 5 files changed, 7 insertions(+), 8 deletions(-) rename schemas/{app.json => prototypeApplication.json} (95%) rename types/schemas/{app => prototypeApplication}/ApplicationData.ts (100%) rename types/schemas/{app => prototypeApplication}/User.ts (100%) rename types/schemas/{app => prototypeApplication}/index.ts (91%) diff --git a/schemas/app.json b/schemas/prototypeApplication.json similarity index 95% rename from schemas/app.json rename to schemas/prototypeApplication.json index adbb73cd..ceec3738 100644 --- a/schemas/app.json +++ b/schemas/prototypeApplication.json @@ -214,6 +214,6 @@ "type": "object" } }, - "description": "(Temporary name to not clash with the existing `Application` type)\nThe root specification for a planning application in England generated by a digital planning service", - "title": "App" + "description": "The root specification for a planning application in England generated by a digital planning service (prototype)", + "title": "PrototypeApplication" } \ No newline at end of file diff --git a/scripts/build-schema.sh b/scripts/build-schema.sh index 2eb42443..01b53d9d 100755 --- a/scripts/build-schema.sh +++ b/scripts/build-schema.sh @@ -7,8 +7,8 @@ version="${VERSION:-@next}" echo "Version set to $version" -dirs=("application" "app") -types=("Application" "App") +dirs=("application" "prototypeApplication") +types=("Application" "PrototypeApplication") for i in "${!dirs[@]}"; do dir=${dirs[$i]} diff --git a/types/schemas/app/ApplicationData.ts b/types/schemas/prototypeApplication/ApplicationData.ts similarity index 100% rename from types/schemas/app/ApplicationData.ts rename to types/schemas/prototypeApplication/ApplicationData.ts diff --git a/types/schemas/app/User.ts b/types/schemas/prototypeApplication/User.ts similarity index 100% rename from types/schemas/app/User.ts rename to types/schemas/prototypeApplication/User.ts diff --git a/types/schemas/app/index.ts b/types/schemas/prototypeApplication/index.ts similarity index 91% rename from types/schemas/app/index.ts rename to types/schemas/prototypeApplication/index.ts index 7bb032e8..065254e4 100644 --- a/types/schemas/app/index.ts +++ b/types/schemas/prototypeApplication/index.ts @@ -37,12 +37,11 @@ export type WorksToTreesApplications = ApplicationSpecification< >; /** - * @title App + * @title PrototypeApplication * @description - * (Temporary name to not clash with the existing `Application` type) - * The root specification for a planning application in England generated by a digital planning service + * The root specification for a planning application in England generated by a digital planning service (prototype) */ -export type App = +export type PrototypeApplication = | PlanningPermissionApplication | PriorApprovalApplication | WorksToTreesApplications;