From 066b974ca61b80aae49808fa2f0e18de37292986 Mon Sep 17 00:00:00 2001 From: J M <2364004+Blu-J@users.noreply.github.com> Date: Tue, 8 Feb 2022 09:28:02 -0700 Subject: [PATCH] fix: Properties (#1175) --- .../ui/src/app/util/properties.util.ts | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/frontend/projects/ui/src/app/util/properties.util.ts b/frontend/projects/ui/src/app/util/properties.util.ts index ff4e40e3b..bf1890671 100644 --- a/frontend/projects/ui/src/app/util/properties.util.ts +++ b/frontend/projects/ui/src/app/util/properties.util.ts @@ -10,7 +10,7 @@ function has(obj: Obj, key: K): obj is (Obj & const ajv = new Ajv({ jsonPointers: true, allErrors: true, nullable: true }) -const ajvWithDefaults = new Ajv({ jsonPointers: true, allErrors: true, useDefaults: true, nullable: true, removeAdditional: 'failing' }) +const ajvWithDefaults = new Ajv({ jsonPointers: true, allErrors: true, useDefaults: true, nullable: true, removeAdditional:true }) const schemaV1 = { 'type': 'object', @@ -28,7 +28,10 @@ const schemaV1Compiled = ajv.compile(schemaV1) function isSchemaV1(properties: unknown): properties is PropertiesV1 { return schemaV1Compiled(properties) as any } -const schemaV1CompiledWithDefaults = ajvWithDefaults.compile(schemaV1) +const _schemaV1CompiledWithDefaults = ajvWithDefaults.compile(schemaV1) +function schemaV1CompiledWithDefaults(properties: unknown): properties is PropertiesV1 { + return _schemaV1CompiledWithDefaults(properties) as any +} const schemaV2 = { 'anyOf': [ { @@ -117,9 +120,11 @@ function parsePropertiesV1Permissive (properties: unknown, errorCallback: (err: errorCallback(new TypeError(`${properties} is not an array`)) return {} } - return properties.reduce((prev: PackagePropertiesV2, cur: unknown, idx: number) => { + const parsedProperties : PackagePropertiesV2 = {}; + for(const idx in properties) { + const cur:unknown = properties[idx] if(isSchemaV1(cur)) { - prev[cur.name] = { + parsedProperties[cur.name] = { type: 'string', value: cur.value, description: cur.description, @@ -136,14 +141,24 @@ function parsePropertiesV1Permissive (properties: unknown, errorCallback: (err: } } if (!schemaV1CompiledWithDefaults(cur)) { - for (let err of schemaV1CompiledWithDefaults.errors) { + for (let err of _schemaV1CompiledWithDefaults.errors) { errorCallback(new Error(`/data/${idx}${err.dataPath}: ${err.message}`)) } - return prev + continue + } + parsedProperties[cur.name] = { + + type: 'string', + value: cur.value, + description: cur.description, + copyable: cur.copyable, + qr: cur.qr, + masked: false, } } - return prev - }, { }) + + } + return parsedProperties } function parsePropertiesV2Permissive (properties: unknown, errorCallback: (err: Error) => any): PackageProperties { if (typeof properties !== 'object' || properties === null) { @@ -212,4 +227,5 @@ interface PackagePropertyString extends PackagePropertyBase { interface PackagePropertyObject extends PackagePropertyBase { type: 'object' value: PackagePropertiesV2 -} \ No newline at end of file +} +