diff --git a/maas-schemas/package.json b/maas-schemas/package.json index c3654f9ca..e916ec37c 100644 --- a/maas-schemas/package.json +++ b/maas-schemas/package.json @@ -1,6 +1,6 @@ { "name": "maas-schemas", - "version": "20.9.0", + "version": "20.10.0", "description": "Schemas for MaaS infrastructure", "main": "index.js", "engine": { diff --git a/maas-schemas/schemas/maas-backend/products/provider.json b/maas-schemas/schemas/maas-backend/products/provider.json index d3ef206b6..ed49509e6 100644 --- a/maas-schemas/schemas/maas-backend/products/provider.json +++ b/maas-schemas/schemas/maas-backend/products/provider.json @@ -198,6 +198,12 @@ }, "created": { "$ref": "https://schemas.maas.global/core/components/units.json#/definitions/time" + }, + "filters": { + "type": "array", + "items": { + "$ref": "#/definitions/providerFilter" + } } }, "required": [ @@ -213,6 +219,55 @@ ], "additionalProperties": false, "definitions": { + "providerFilter": { + "description": "Product provider filter", + "type": "object", + "required": ["name", "label"], + "properties": { + "name": { + "type": "string" + }, + "label": { + "type": "string" + }, + "default": { + "anyOf": [ + { + "$ref": "#/definitions/providerFilterOption" + }, + { + "type": "null" + } + ] + }, + "selectionOptions": { + "type": "array", + "items": { + "$ref": "#/definitions/providerFilterOption" + } + } + } + }, + "providerFilterOption": { + "description": "Product provider filter option", + "type": "object", + "required": ["value", "label"], + "properties": { + "value": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "label": { + "type": "string" + } + } + }, "selection": { "description": "Optional parameter for selections", "type": "object", @@ -313,6 +368,32 @@ "stationsList": true, "stationsRetrieve": true }, + "filters": [ + { + "name": "ticketType", + "label": "ticketTypeLabel", + "selectionOptions": [ + { + "value": null, + "label": "PLEASE_CHOOSE" + }, + { + "value": "ordinary", + "label": "TYPE_ORDINARY" + } + ], + "default": { + "value": null, + "label": "PLEASE_CHOOSE" + } + }, + { + "name": "ticketZone", + "label": "ticketZoneLabel", + "selectionOptions": [], + "default": null + } + ], "personalDataOptionsAllow": [], "personalDataCreateAllow": [], "optionalParameters": [ diff --git a/maas-schemas/src/io-ts/_translation.log b/maas-schemas/src/io-ts/_translation.log index a42763acd..cdfd71dc5 100644 --- a/maas-schemas/src/io-ts/_translation.log +++ b/maas-schemas/src/io-ts/_translation.log @@ -1950,6 +1950,14 @@ INFO: primitive type "string" used outside top-level definitions in schemas/maas-backend/products/provider.json INFO: primitive type "string" used outside top-level definitions in schemas/maas-backend/products/provider.json +INFO: primitive type "string" used outside top-level definitions + in schemas/maas-backend/products/provider.json +INFO: primitive type "string" used outside top-level definitions + in schemas/maas-backend/products/provider.json +INFO: primitive type "string" used outside top-level definitions + in schemas/maas-backend/products/provider.json +INFO: primitive type "string" used outside top-level definitions + in schemas/maas-backend/products/provider.json WARNING: minItems field not supported outside top-level definitions in schemas/maas-backend/products/provider.json INFO: primitive type "string" used outside top-level definitions diff --git a/maas-schemas/src/io-ts/_types/maas-backend/products/provider.ts b/maas-schemas/src/io-ts/_types/maas-backend/products/provider.ts index 02b1fb463..1864006d0 100644 --- a/maas-schemas/src/io-ts/_types/maas-backend/products/provider.ts +++ b/maas-schemas/src/io-ts/_types/maas-backend/products/provider.ts @@ -19,6 +19,17 @@ import * as PersonalDataValidation_1572_ from '../../core/components/personalDat import * as PersonalDocumentRequiredItem_b279_ from '../../core/components/personalDocumentRequiredItem'; import * as Units_c404_ from '../../core/components/units'; +export type NullBrand = { + readonly Null: unique symbol; +}; +export type NullC = t.BrandC; +export const Null: NullC = t.brand( + t.unknown, + (n): n is t.Branded => n === null, + 'Null', +); +export type Null = t.TypeOf; + export type Defined = {} | null; export class DefinedType extends t.Type { readonly _tag: 'DefinedType' = 'DefinedType'; @@ -36,6 +47,142 @@ export const Defined: DefinedC = new DefinedType(); export const schemaId = 'https://schemas.maas.global/maas-backend/products/provider.json'; +// ProviderFilterOption +// Product provider filter option +export type ProviderFilterOption = t.Branded< + ({ + value?: string | Null; + label?: string; + } & Record) & { + value: Defined; + label: Defined; + }, + ProviderFilterOptionBrand +>; +export type ProviderFilterOptionC = t.BrandC< + t.IntersectionC< + [ + t.IntersectionC< + [ + t.PartialC<{ + value: t.UnionC<[t.StringC, typeof Null]>; + label: t.StringC; + }>, + t.RecordC, + ] + >, + t.TypeC<{ + value: typeof Defined; + label: typeof Defined; + }>, + ] + >, + ProviderFilterOptionBrand +>; +export const ProviderFilterOption: ProviderFilterOptionC = t.brand( + t.intersection([ + t.intersection([ + t.partial({ + value: t.union([t.string, Null]), + label: t.string, + }), + t.record(t.string, t.unknown), + ]), + t.type({ + value: Defined, + label: Defined, + }), + ]), + ( + x, + ): x is t.Branded< + ({ + value?: string | Null; + label?: string; + } & Record) & { + value: Defined; + label: Defined; + }, + ProviderFilterOptionBrand + > => true, + 'ProviderFilterOption', +); +export type ProviderFilterOptionBrand = { + readonly ProviderFilterOption: unique symbol; +}; + +// ProviderFilter +// Product provider filter +export type ProviderFilter = t.Branded< + ({ + name?: string; + label?: string; + default?: ProviderFilterOption | Null; + selectionOptions?: Array; + } & Record) & { + name: Defined; + label: Defined; + }, + ProviderFilterBrand +>; +export type ProviderFilterC = t.BrandC< + t.IntersectionC< + [ + t.IntersectionC< + [ + t.PartialC<{ + name: t.StringC; + label: t.StringC; + default: t.UnionC<[typeof ProviderFilterOption, typeof Null]>; + selectionOptions: t.ArrayC; + }>, + t.RecordC, + ] + >, + t.TypeC<{ + name: typeof Defined; + label: typeof Defined; + }>, + ] + >, + ProviderFilterBrand +>; +export const ProviderFilter: ProviderFilterC = t.brand( + t.intersection([ + t.intersection([ + t.partial({ + name: t.string, + label: t.string, + default: t.union([ProviderFilterOption, Null]), + selectionOptions: t.array(ProviderFilterOption), + }), + t.record(t.string, t.unknown), + ]), + t.type({ + name: Defined, + label: Defined, + }), + ]), + ( + x, + ): x is t.Branded< + ({ + name?: string; + label?: string; + default?: ProviderFilterOption | Null; + selectionOptions?: Array; + } & Record) & { + name: Defined; + label: Defined; + }, + ProviderFilterBrand + > => true, + 'ProviderFilter', +); +export type ProviderFilterBrand = { + readonly ProviderFilter: unique symbol; +}; + // Selection // Optional parameter for selections export type Selection = t.Branded< @@ -470,6 +617,7 @@ export type Provider = t.Branded< >; disruption?: Record & Record; created?: Units_c404_.Time; + filters?: Array; } & { name: Defined; agencyId: Defined; @@ -586,6 +734,7 @@ export type ProviderC = t.BrandC< >; disruption: t.IntersectionC<[t.UnknownRecordC, t.RecordC]>; created: typeof Units_c404_.Time; + filters: t.ArrayC; }>, t.TypeC<{ name: typeof Defined; @@ -683,6 +832,7 @@ export const Provider: ProviderC = t.brand( ), disruption: t.intersection([t.UnknownRecord, t.record(t.string, t.unknown)]), created: Units_c404_.Time, + filters: t.array(ProviderFilter), }), t.type({ name: Defined, @@ -756,6 +906,7 @@ export const Provider: ProviderC = t.brand( >; disruption?: Record & Record; created?: Units_c404_.Time; + filters?: Array; } & { name: Defined; agencyId: Defined; @@ -783,6 +934,23 @@ export const examplesProvider: NonEmptyArray = [ hidden: false, branding: {}, features: { ticket: true, stationsList: true, stationsRetrieve: true }, + filters: [ + { + name: 'ticketType', + label: 'ticketTypeLabel', + selectionOptions: [ + { value: null, label: 'PLEASE_CHOOSE' }, + { value: 'ordinary', label: 'TYPE_ORDINARY' }, + ], + default: { value: null, label: 'PLEASE_CHOOSE' }, + }, + { + name: 'ticketZone', + label: 'ticketZoneLabel', + selectionOptions: [], + default: null, + }, + ], personalDataOptionsAllow: [], personalDataCreateAllow: [], optionalParameters: [