From 553f5ed9879b059a26d1c7ba8542eeb742709844 Mon Sep 17 00:00:00 2001 From: Carina Ursu Date: Wed, 4 May 2022 16:55:15 -0700 Subject: [PATCH] chore: cleanup Signed-off-by: Carina Ursu --- .../__stories__/Collection.stories.tsx | 9 ++-- .../Literals/__stories__/Map.stories.tsx | 5 +- .../__stories__/ProtobufStruct.stories.tsx | 21 +++----- .../src/components/Literals/helpers.ts | 4 +- .../Literals/test/helpers/genMapTestCase.ts | 2 +- .../Literals/test/helpers/literalHelpers.ts | 51 ++++++++++++++----- .../Literals/test/literal.helpers.test.ts | 4 +- 7 files changed, 56 insertions(+), 40 deletions(-) diff --git a/packages/zapp/console/src/components/Literals/__stories__/Collection.stories.tsx b/packages/zapp/console/src/components/Literals/__stories__/Collection.stories.tsx index 76ba85d60..9056dd685 100644 --- a/packages/zapp/console/src/components/Literals/__stories__/Collection.stories.tsx +++ b/packages/zapp/console/src/components/Literals/__stories__/Collection.stories.tsx @@ -18,6 +18,7 @@ const stories = storiesOf('Literals/Collection', module); stories.addDecorator(CardDecorator); function renderCollection(label: string, collection: LiteralCollection) { + const map = { literals: { [label]: { collection, value: 'collection' } } }; return ( <>
@@ -25,9 +26,7 @@ function renderCollection(label: string, collection: LiteralCollection) { OLD - +
@@ -35,9 +34,7 @@ function renderCollection(label: string, collection: LiteralCollection) { NEW - + diff --git a/packages/zapp/console/src/components/Literals/__stories__/Map.stories.tsx b/packages/zapp/console/src/components/Literals/__stories__/Map.stories.tsx index cdd594672..82d4463ff 100644 --- a/packages/zapp/console/src/components/Literals/__stories__/Map.stories.tsx +++ b/packages/zapp/console/src/components/Literals/__stories__/Map.stories.tsx @@ -18,6 +18,7 @@ const stories = storiesOf('Literals/Map', module); stories.addDecorator(CardDecorator); function renderMap(label: string, map: LiteralMap) { + const fullMap = { literals: { [label]: { map, value: 'map' } } }; return ( <>
@@ -25,7 +26,7 @@ function renderMap(label: string, map: LiteralMap) { OLD - +
@@ -33,7 +34,7 @@ function renderMap(label: string, map: LiteralMap) { NEW - + diff --git a/packages/zapp/console/src/components/Literals/__stories__/ProtobufStruct.stories.tsx b/packages/zapp/console/src/components/Literals/__stories__/ProtobufStruct.stories.tsx index 786e2a327..c784fdbf4 100644 --- a/packages/zapp/console/src/components/Literals/__stories__/ProtobufStruct.stories.tsx +++ b/packages/zapp/console/src/components/Literals/__stories__/ProtobufStruct.stories.tsx @@ -12,6 +12,11 @@ const stories = storiesOf('Literals/ProtobufStruct', module); stories.addDecorator(CardDecorator); function renderStruct(label: string, struct: ProtobufStruct) { + const map = { + literals: { + [label]: { scalar: { value: 'generic', generic: struct }, value: 'scalar' }, + }, + }; return ( <>
@@ -19,13 +24,7 @@ function renderStruct(label: string, struct: ProtobufStruct) { OLD - +
@@ -33,13 +32,7 @@ function renderStruct(label: string, struct: ProtobufStruct) { NEW - + diff --git a/packages/zapp/console/src/components/Literals/helpers.ts b/packages/zapp/console/src/components/Literals/helpers.ts index 016d5d2ed..b8e253c10 100644 --- a/packages/zapp/console/src/components/Literals/helpers.ts +++ b/packages/zapp/console/src/components/Literals/helpers.ts @@ -19,7 +19,7 @@ function processPrimitive(primitive: Core.IPrimitive) { case 'duration': return protobufDurationToHMS(primitive.duration!); case 'integer': { - return Long.fromValue(primitive[type] as any as Long).toNumber(); + return Long.fromValue(primitive[type] as Long).toNumber(); } case 'boolean': case 'floatValue': @@ -311,7 +311,7 @@ function processLiteralValue(literal: Core.ILiteral) { export function transformLiteralMap(json: Core.ILiteralMap) { const obj = sortedObjectEntries(json as any) .map(([key, literal]) => ({ - [key]: processLiteralValue(literal as any as Core.Literal), + [key]: processLiteralValue(literal as Core.Literal), })) .reduce( (acc, cur) => ({ diff --git a/packages/zapp/console/src/components/Literals/test/helpers/genMapTestCase.ts b/packages/zapp/console/src/components/Literals/test/helpers/genMapTestCase.ts index e504d1336..505920e21 100644 --- a/packages/zapp/console/src/components/Literals/test/helpers/genMapTestCase.ts +++ b/packages/zapp/console/src/components/Literals/test/helpers/genMapTestCase.ts @@ -27,4 +27,4 @@ const collection = { export default { ...collection, -} as any as TestCaseList; +} as TestCaseList; diff --git a/packages/zapp/console/src/components/Literals/test/helpers/literalHelpers.ts b/packages/zapp/console/src/components/Literals/test/helpers/literalHelpers.ts index 14fbe29f1..90e45ae92 100644 --- a/packages/zapp/console/src/components/Literals/test/helpers/literalHelpers.ts +++ b/packages/zapp/console/src/components/Literals/test/helpers/literalHelpers.ts @@ -10,21 +10,21 @@ export function getIValue( | Protobuf.IStruct | Protobuf.IListValue | null, -): Core.Primitive | Core.IPrimitive { +): Protobuf.IValue & Pick { return { kind, [kind]: value, - } as any as Protobuf.Value; + }; } export function getPrimitive( key: 'integer' | 'floatValue' | 'stringValue' | 'boolean' | 'datetime' | 'duration', value?: Long | number | string | boolean | Protobuf.ITimestamp | Protobuf.IDuration | null, -): Core.Primitive | Core.IPrimitive { +): Core.IPrimitive & Pick { return { [key]: value, value: key, - } as any as Core.Primitive; + }; } export function generateBlobType( @@ -43,18 +43,43 @@ export function generateBlobType( }; } +const getScalar = ( + value: + | Core.IPrimitive + | Core.IBlob + | Core.IBinary + | Core.ISchema + | Core.IVoid + | Core.IError + | Protobuf.IStruct + | Core.IStructuredDataset + | Core.IUnion, + scalarType: any, +): Core.IScalar & Pick => { + return { + [scalarType]: value, + value: scalarType, + }; +}; + // TOP LEVEL SCHEMA GENERATORS: -export const getScalar = ( - value: Core.IPrimitive | Core.IBlob | Core.IBinary, - scalarType: string, -) => { +export const getScalarLiteral = ( + value: + | Core.IPrimitive + | Core.IBlob + | Core.IBinary + | Core.ISchema + | Core.IVoid + | Core.IError + | Protobuf.IStruct + | Core.IStructuredDataset + | Core.IUnion, + scalarType: any, +): Core.ILiteral & Pick => { return { - scalar: { - [scalarType]: value, - value: scalarType, - }, + scalar: getScalar(value, scalarType), value: 'scalar', - } as Core.IScalar; + }; }; export const getCollection = (literals: Core.ILiteral[]) => { diff --git a/packages/zapp/console/src/components/Literals/test/literal.helpers.test.ts b/packages/zapp/console/src/components/Literals/test/literal.helpers.test.ts index e4bd8062e..82428a891 100644 --- a/packages/zapp/console/src/components/Literals/test/literal.helpers.test.ts +++ b/packages/zapp/console/src/components/Literals/test/literal.helpers.test.ts @@ -13,7 +13,7 @@ import { collection, map, } from './helpers/index'; -import { getCollection, getMap, getScalar } from './helpers/literalHelpers'; +import { getCollection, getMap, getScalarLiteral } from './helpers/literalHelpers'; const literalTestCases = { scalar: { @@ -40,7 +40,7 @@ describe('scalar literal', () => { const { value, expected } = cases?.[testKey]!; it(`${testKey}: should return ${expected} for ${value}`, () => { - const scalar = { result_var: { ...getScalar(value, scalarTestType) } }; + const scalar = { result_var: { ...getScalarLiteral(value, scalarTestType) } }; const result = transformLiteralMap(scalar as any); expect(result).toEqual(expected); });