Skip to content

Commit

Permalink
refactor(store): use isSchemaAbiType in resolveUserTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Nov 7, 2023
1 parent 8d14438 commit a133e11
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/store/ts/config/storeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,17 +88,14 @@ export function resolveUserTypes<
>(schema: TSchema, userTypes: TUserTypes): ResolvedSchema<TSchema, TUserTypes> {
const resolvedSchema: Record<string, SchemaAbiType> = {};
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<TSchema, TUserTypes>;
Expand Down

0 comments on commit a133e11

Please sign in to comment.