Skip to content

Commit

Permalink
feat: Hoist TPrimary to root only
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jul 25, 2024
1 parent 5717067 commit 75aad8f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 109 deletions.
143 changes: 52 additions & 91 deletions schemas/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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": {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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": {
Expand Down
24 changes: 8 additions & 16 deletions types/schemas/app/ApplicationData.ts
Original file line number Diff line number Diff line change
@@ -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<TGranular extends ApplicationTypeKeys> {
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;
}

Expand All @@ -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<TGranular>
: ApplicationDataBase<TGranular>;
export type ApplicationData<TPrimary extends PrimaryApplicationType> =
TPrimary extends keyof ApplicationDataVariants
? ApplicationDataVariants[TPrimary]
: ApplicationDataBase;
3 changes: 1 addition & 2 deletions types/schemas/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ApplicationSpecification<
applicationType: TGranular;
data: {
user: User<TPrimary>;
application: ApplicationData<TPrimary, TGranular>;
application: ApplicationData<TPrimary>;
};
}

Expand Down Expand Up @@ -56,7 +56,6 @@ export type App =
// wttSpecificProperty: true,
// },
// application: {
// applicationType: 'wtt.consent',
// wttSpecificProperty: 123,
// somethingShared: 'abc',
// },
Expand Down

0 comments on commit 75aad8f

Please sign in to comment.