From 58d9f8785b97978b1d1da1598f18c7354793c602 Mon Sep 17 00:00:00 2001 From: marcink Date: Tue, 21 Nov 2023 11:36:31 +0100 Subject: [PATCH 1/2] Product filters backend response filters. --- maas-schemas/package.json | 2 +- .../maas-backend/products/provider.json | 84 +++++++++ maas-schemas/src/io-ts/_translation.log | 8 + .../_types/maas-backend/products/provider.ts | 170 ++++++++++++++++++ 4 files changed, 263 insertions(+), 1 deletion(-) 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..32f287b15 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,35 @@ "stationsList": true, "stationsRetrieve": true }, + "filters": { + "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..081729cbf 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,25 @@ export const examplesProvider: NonEmptyArray = [ hidden: false, branding: {}, features: { ticket: true, stationsList: true, stationsRetrieve: true }, + filters: { + 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: [ From c395650f44fc902fc2f680e2a26363a3b92311b6 Mon Sep 17 00:00:00 2001 From: marcink Date: Tue, 21 Nov 2023 11:43:31 +0100 Subject: [PATCH 2/2] Product filters backend response filters. --- .../maas-backend/products/provider.json | 47 +++++++++---------- .../_types/maas-backend/products/provider.ts | 36 +++++++------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/maas-schemas/schemas/maas-backend/products/provider.json b/maas-schemas/schemas/maas-backend/products/provider.json index 32f287b15..ed49509e6 100644 --- a/maas-schemas/schemas/maas-backend/products/provider.json +++ b/maas-schemas/schemas/maas-backend/products/provider.json @@ -368,35 +368,32 @@ "stationsList": true, "stationsRetrieve": true }, - "filters": { - "filters": [ - { - "name": "ticketType", - "label": "ticketTypeLabel", - "selectionOptions": [ - { - "value": null, - "label": "PLEASE_CHOOSE" - }, - { - "value": "ordinary", - "label": "TYPE_ORDINARY" - } - ], - "default": { + "filters": [ + { + "name": "ticketType", + "label": "ticketTypeLabel", + "selectionOptions": [ + { "value": null, "label": "PLEASE_CHOOSE" + }, + { + "value": "ordinary", + "label": "TYPE_ORDINARY" } - }, - { - "name": "ticketZone", - "label": "ticketZoneLabel", - "selectionOptions": [ - ], - "default": null + ], + "default": { + "value": null, + "label": "PLEASE_CHOOSE" } - ] - }, + }, + { + "name": "ticketZone", + "label": "ticketZoneLabel", + "selectionOptions": [], + "default": null + } + ], "personalDataOptionsAllow": [], "personalDataCreateAllow": [], "optionalParameters": [ 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 081729cbf..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 @@ -934,25 +934,23 @@ export const examplesProvider: NonEmptyArray = [ hidden: false, branding: {}, features: { ticket: true, stationsList: true, stationsRetrieve: true }, - filters: { - 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, - }, - ], - }, + 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: [