From a133e11335238a8bfc162b5b35f5525145b41d68 Mon Sep 17 00:00:00 2001 From: dk1a Date: Tue, 7 Nov 2023 18:33:09 +0300 Subject: [PATCH] refactor(store): use isSchemaAbiType in resolveUserTypes --- packages/store/ts/config/storeConfig.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/store/ts/config/storeConfig.ts b/packages/store/ts/config/storeConfig.ts index 83b3cb025c..01c2b5e002 100644 --- a/packages/store/ts/config/storeConfig.ts +++ b/packages/store/ts/config/storeConfig.ts @@ -23,7 +23,7 @@ import { } from "@latticexyz/config"; import { DEFAULTS, PATH_DEFAULTS, TABLE_DEFAULTS } from "./defaults"; import { UserType } from "@latticexyz/common/codegen"; -import { SchemaAbiType, schemaAbiTypes } from "@latticexyz/schema-type"; +import { SchemaAbiType, isSchemaAbiType, schemaAbiTypes } from "@latticexyz/schema-type"; const zTableName = zObjectName; const zKeyName = zValueName; @@ -88,17 +88,14 @@ export function resolveUserTypes< >(schema: TSchema, userTypes: TUserTypes): ResolvedSchema { const resolvedSchema: Record = {}; for (const [key, value] of Object.entries(schema)) { - const staticArray = parseStaticArray(value); - - if (userTypes[value] !== undefined) { - // user-defined types + if (isSchemaAbiType(value)) { + resolvedSchema[key] = value; + } else if (userTypes[value] !== undefined) { resolvedSchema[key] = userTypes[value].internalType as SchemaAbiType; - } else if (staticArray) { - // static arrays - resolvedSchema[key] = `${staticArray.elementType as StaticAbiType}[]`; } else { - // abi types - resolvedSchema[key] = value as SchemaAbiType; + const staticArray = parseStaticArray(value); + if (!staticArray) throw new Error(`Unexpected type: ${value}`); + resolvedSchema[key] = `${staticArray.elementType as StaticAbiType}[]`; } } return resolvedSchema as ResolvedSchema;