Skip to content

Commit

Permalink
chore: generate types
Browse files Browse the repository at this point in the history
  • Loading branch information
cambio-deca committed Nov 27, 2023
1 parent 0815b5f commit 93a2617
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions maas-schemas/src/io-ts/_types/core/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,33 @@ export type EmptyObjectBrand = {
readonly EmptyObject: unique symbol;
};

// Nationality
// ISO 3166-1 alpha-2 country code, see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
export type Nationality = t.Branded<string, NationalityBrand>;
export type NationalityC = t.BrandC<t.StringC, NationalityBrand>;
export const Nationality: NationalityC = t.brand(
t.string,
(x): x is t.Branded<string, NationalityBrand> =>
typeof x !== 'string' || x.match(RegExp('^[A-Z]{2,2}$', 'u')) !== null,
'Nationality',
);
export type NationalityBrand = {
readonly Nationality: unique symbol;
};
/** require('io-ts-validator').validator(nonEmptyArray(Nationality)).decodeSync(examplesNationality) // => examplesNationality */
export const examplesNationality: NonEmptyArray<Nationality> = [
'FI',
'GB',
] as unknown as NonEmptyArray<Nationality>;
// NEGATIVE Test Case: empty string
/** require('io-ts-validator').validator(Nationality).decodeEither("")._tag // => 'Left' */
// NEGATIVE Test Case: emoji
/** require('io-ts-validator').validator(Nationality).decodeEither("💩")._tag // => 'Left' */
// NEGATIVE Test Case: lower case alpha-2 country code
/** require('io-ts-validator').validator(Nationality).decodeEither("fi")._tag // => 'Left' */
// NEGATIVE Test Case: alpha-3 country code
/** require('io-ts-validator').validator(Nationality).decodeEither("FIN")._tag // => 'Left' */

// Common
// The default export. More information at the top.
export type Common = t.Branded<unknown, CommonBrand>;
Expand Down
4 changes: 4 additions & 0 deletions maas-schemas/src/io-ts/_types/core/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type Customer = t.Branded<
state?: Address_2d0a_.State;
country?: Address_2d0a_.Country;
zipCode?: Address_2d0a_.ZipCode;
nationality?: Common_ffba_.Nationality;
locale?: I18n_b70d_.Locale;
appInstanceId?: Common_ffba_.AppInstanceId;
opaqueId?: Common_ffba_.OpaqueId;
Expand Down Expand Up @@ -118,6 +119,7 @@ export type CustomerC = t.BrandC<
state: typeof Address_2d0a_.State;
country: typeof Address_2d0a_.Country;
zipCode: typeof Address_2d0a_.ZipCode;
nationality: typeof Common_ffba_.Nationality;
locale: typeof I18n_b70d_.Locale;
appInstanceId: typeof Common_ffba_.AppInstanceId;
opaqueId: typeof Common_ffba_.OpaqueId;
Expand Down Expand Up @@ -204,6 +206,7 @@ export const Customer: CustomerC = t.brand(
state: Address_2d0a_.State,
country: Address_2d0a_.Country,
zipCode: Address_2d0a_.ZipCode,
nationality: Common_ffba_.Nationality,
locale: I18n_b70d_.Locale,
appInstanceId: Common_ffba_.AppInstanceId,
opaqueId: Common_ffba_.OpaqueId,
Expand Down Expand Up @@ -274,6 +277,7 @@ export const Customer: CustomerC = t.brand(
state?: Address_2d0a_.State;
country?: Address_2d0a_.Country;
zipCode?: Address_2d0a_.ZipCode;
nationality?: Common_ffba_.Nationality;
locale?: I18n_b70d_.Locale;
appInstanceId?: Common_ffba_.AppInstanceId;
opaqueId?: Common_ffba_.OpaqueId;
Expand Down

0 comments on commit 93a2617

Please sign in to comment.