From e68872627414ef925f888a587b7f98374d1719df Mon Sep 17 00:00:00 2001 From: DafyddLlyr Date: Mon, 29 Jul 2024 11:24:53 +0000 Subject: [PATCH] Add build files for @next --- @next/prototypeApplication.json | 219 ++++++++++++++++++ .../prototypeApplication/ApplicationData.ts | 39 ++++ .../schemas/prototypeApplication/User.ts | 28 +++ .../schemas/prototypeApplication/index.ts | 62 +++++ 4 files changed, 348 insertions(+) create mode 100644 @next/prototypeApplication.json create mode 100644 @next/types/schemas/prototypeApplication/ApplicationData.ts create mode 100644 @next/types/schemas/prototypeApplication/User.ts create mode 100644 @next/types/schemas/prototypeApplication/index.ts diff --git a/@next/prototypeApplication.json b/@next/prototypeApplication.json new file mode 100644 index 00000000..ceec3738 --- /dev/null +++ b/@next/prototypeApplication.json @@ -0,0 +1,219 @@ +{ + "$id": "@next", + "$schema": "http://json-schema.org/draft-07/schema#", + "anyOf": [ + { + "$ref": "#/definitions/PlanningPermissionApplication" + }, + { + "$ref": "#/definitions/PriorApprovalApplication" + }, + { + "$ref": "#/definitions/WorksToTreesApplications" + } + ], + "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" + }, + "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": { + "ppSpecificProperty": { + "type": "boolean" + }, + "role": { + "enum": [ + "applicant", + "agent", + "proxy" + ], + "type": "string" + } + }, + "required": [ + "ppSpecificProperty", + "role" + ], + "type": "object" + }, + "PlanningPermissionApplication": { + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "pp", + "type": "string" + }, + "data": { + "additionalProperties": false, + "properties": { + "application": { + "$ref": "#/definitions/PPApplicationData" + }, + "user": { + "$ref": "#/definitions/PPUser" + } + }, + "required": [ + "user", + "application" + ], + "type": "object" + } + }, + "required": [ + "applicationType", + "data" + ], + "type": "object" + }, + "PriorApprovalApplication": { + "additionalProperties": false, + "properties": { + "applicationType": { + "const": "pa", + "type": "string" + }, + "data": { + "additionalProperties": false, + "properties": { + "application": { + "$ref": "#/definitions/ApplicationDataBase" + }, + "user": { + "$ref": "#/definitions/UserBase" + } + }, + "required": [ + "user", + "application" + ], + "type": "object" + } + }, + "required": [ + "applicationType", + "data" + ], + "type": "object" + }, + "UserBase": { + "additionalProperties": false, + "properties": { + "role": { + "enum": [ + "applicant", + "agent", + "proxy" + ], + "type": "string" + } + }, + "required": [ + "role" + ], + "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": { + "role": { + "enum": [ + "applicant", + "agent", + "proxy" + ], + "type": "string" + }, + "wttSpecificProperty": { + "type": "boolean" + } + }, + "required": [ + "role", + "wttSpecificProperty" + ], + "type": "object" + }, + "WorksToTreesApplications": { + "additionalProperties": false, + "properties": { + "applicationType": { + "enum": [ + "wtt", + "wtt.consent", + "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" + } + }, + "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/@next/types/schemas/prototypeApplication/ApplicationData.ts b/@next/types/schemas/prototypeApplication/ApplicationData.ts new file mode 100644 index 00000000..bd1eac9a --- /dev/null +++ b/@next/types/schemas/prototypeApplication/ApplicationData.ts @@ -0,0 +1,39 @@ +import {PrimaryApplicationType} from '../application/enums/ApplicationTypes'; + +/** + * Base type for ApplicationData. Contains all shared properties across all application types + */ +export interface ApplicationDataBase { + somethingShared: string; +} + +/** + * @description Specific ApplicationData required for "Works to trees" applications + */ +export interface WTTApplicationData extends ApplicationDataBase { + wttSpecificProperty: number; +} + +/** + * @description Specific ApplicationData required for "Planning Permission" applications + */ +export interface PPApplicationData extends ApplicationDataBase { + ppSpecificProperty: number; +} + +/** + * TypeMap of PrimaryApplicationTypes to their specific ApplicationData models + */ +export interface ApplicationDataVariants { + wtt: WTTApplicationData; + pp: PPApplicationData; +} + +/** + * @internal + * Conditional type to return a specific or generic ApplicationData model, based on PrimaryApplicationType + */ +export type ApplicationData = + TPrimary extends keyof ApplicationDataVariants + ? ApplicationDataVariants[TPrimary] + : ApplicationDataBase; diff --git a/@next/types/schemas/prototypeApplication/User.ts b/@next/types/schemas/prototypeApplication/User.ts new file mode 100644 index 00000000..da248014 --- /dev/null +++ b/@next/types/schemas/prototypeApplication/User.ts @@ -0,0 +1,28 @@ +import {PrimaryApplicationType} from '../application/enums/ApplicationTypes'; + +export interface UserBase { + role: 'applicant' | 'agent' | 'proxy'; +} + +export interface WTTUser extends UserBase { + wttSpecificProperty: boolean; +} + +export interface PPUser extends UserBase { + ppSpecificProperty: boolean; +} + +/** + * TypeMap of PrimaryApplicationTypes to their specific User models + */ +interface UserVariants { + wtt: WTTUser; + pp: PPUser; +} + +/** + * @internal + * Conditional type to return a specific or generic User model, based on PrimaryApplicationType + */ +export type User = + TPrimary extends keyof UserVariants ? UserVariants[TPrimary] : UserBase; diff --git a/@next/types/schemas/prototypeApplication/index.ts b/@next/types/schemas/prototypeApplication/index.ts new file mode 100644 index 00000000..065254e4 --- /dev/null +++ b/@next/types/schemas/prototypeApplication/index.ts @@ -0,0 +1,62 @@ +import { + ApplicationTypeKeys, + PrimaryApplicationType, +} from '../application/enums/ApplicationTypes'; +import {ApplicationData} from './ApplicationData'; +import {User} from './User'; + +/** + * @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; + data: { + user: User; + application: ApplicationData; + }; +} + +export type PlanningPermissionApplication = ApplicationSpecification< + 'pp', + 'pp' +>; +// TODO: All granular types + +export type PriorApprovalApplication = ApplicationSpecification<'pa', 'pa'>; +// TODO: All granular types + +export type WorksToTreesApplications = ApplicationSpecification< + 'wtt', + Extract +>; + +/** + * @title PrototypeApplication + * @description + * The root specification for a planning application in England generated by a digital planning service (prototype) + */ +export type PrototypeApplication = + | PlanningPermissionApplication + | PriorApprovalApplication + | WorksToTreesApplications; +// TODO: All the rest! + +// const test: App = { +// applicationType: 'wtt.consent', +// data: { +// user: { +// role: 'agent', +// wttSpecificProperty: true, +// }, +// application: { +// wttSpecificProperty: 123, +// somethingShared: 'abc', +// }, +// }, +// };