From 74b1fea15877f768f36321c81cf5839aff751270 Mon Sep 17 00:00:00 2001 From: Cayman Date: Mon, 20 May 2024 10:38:07 -0400 Subject: [PATCH] chore: rename variant to profile --- packages/ssz/src/index.ts | 2 +- .../src/type/{simpleVariant.ts => profile.ts} | 18 +++++++++--------- .../src/view/{simpleVariant.ts => profile.ts} | 0 .../viewDU/{simpleVariant.ts => profile.ts} | 2 +- .../{simpleVariant => profile}/valid.test.ts | 6 +++--- .../ssz/test/unit/byType/runTypeProofTest.ts | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) rename packages/ssz/src/type/{simpleVariant.ts => profile.ts} (97%) rename packages/ssz/src/view/{simpleVariant.ts => profile.ts} (100%) rename packages/ssz/src/viewDU/{simpleVariant.ts => profile.ts} (99%) rename packages/ssz/test/unit/byType/{simpleVariant => profile}/valid.test.ts (85%) diff --git a/packages/ssz/src/index.ts b/packages/ssz/src/index.ts index 6001704f..7d33d5de 100644 --- a/packages/ssz/src/index.ts +++ b/packages/ssz/src/index.ts @@ -16,7 +16,7 @@ export {VectorBasicType} from "./type/vectorBasic"; export {VectorCompositeType} from "./type/vectorComposite"; export {ListUintNum64Type} from "./type/listUintNum64"; export {StableContainerType} from "./type/stableContainer"; -export {SimpleVariantType} from "./type/simpleVariant"; +export {ProfileType} from "./type/profile"; // Base types export {ArrayType} from "./type/array"; diff --git a/packages/ssz/src/type/simpleVariant.ts b/packages/ssz/src/type/profile.ts similarity index 97% rename from packages/ssz/src/type/simpleVariant.ts rename to packages/ssz/src/type/profile.ts index 1da9aa5a..a6897910 100644 --- a/packages/ssz/src/type/simpleVariant.ts +++ b/packages/ssz/src/type/profile.ts @@ -21,12 +21,12 @@ import { FieldEntry, ContainerTreeViewType, ContainerTreeViewTypeConstructor, -} from "../view/simpleVariant"; +} from "../view/profile"; import { getContainerTreeViewDUClass, ContainerTreeViewDUType, ContainerTreeViewDUTypeConstructor, -} from "../viewDU/simpleVariant"; +} from "../viewDU/profile"; import {Case} from "../util/strings"; import {BitArray} from "../value/bitArray"; import {getActiveFields, mixInActiveFields, setActiveFields} from "./stableContainer"; @@ -36,14 +36,14 @@ import {zeroHash} from "../util/zeros"; type BytesRange = {start: number; end: number}; /** - * SimpleVariant: ordered heterogeneous collection of values that inherits merkleization from a base stable container + * Profile: ordered heterogeneous collection of values that inherits merkleization from a base stable container * * Limitations: * - No reordering of fields for merkleization * - No optional fields */ -export type SimpleVariantOptions> = { +export type ProfileOptions> = { typeName?: string; jsonCase?: KeyCase; casingMap?: CasingMap; @@ -67,7 +67,7 @@ type CasingMap> = Partial<{[K in keyof Fi * Container: ordered heterogeneous collection of values * - Notation: Custom name per instance */ -export class SimpleVariantType>> extends CompositeType< +export class ProfileType>> extends CompositeType< ValueOfFields, ContainerTreeViewType, ContainerTreeViewDUType @@ -97,7 +97,7 @@ export class SimpleVariantType>> ext protected readonly TreeView: ContainerTreeViewTypeConstructor; protected readonly TreeViewDU: ContainerTreeViewDUTypeConstructor; - constructor(readonly fields: Fields, activeFields: BitArray, readonly opts?: SimpleVariantOptions) { + constructor(readonly fields: Fields, activeFields: BitArray, readonly opts?: ProfileOptions) { super(opts?.cachePermanentRootStruct); // Render detailed typeName. Consumers should overwrite since it can get long @@ -166,9 +166,9 @@ export class SimpleVariantType>> ext static named>>( fields: Fields, activeFields: BitArray, - opts: Require, "typeName"> - ): SimpleVariantType { - return new (namedClass(SimpleVariantType, opts.typeName))(fields, activeFields, opts); + opts: Require, "typeName"> + ): ProfileType { + return new (namedClass(ProfileType, opts.typeName))(fields, activeFields, opts); } defaultValue(): ValueOfFields { diff --git a/packages/ssz/src/view/simpleVariant.ts b/packages/ssz/src/view/profile.ts similarity index 100% rename from packages/ssz/src/view/simpleVariant.ts rename to packages/ssz/src/view/profile.ts diff --git a/packages/ssz/src/viewDU/simpleVariant.ts b/packages/ssz/src/viewDU/profile.ts similarity index 99% rename from packages/ssz/src/viewDU/simpleVariant.ts rename to packages/ssz/src/viewDU/profile.ts index e3bd1f0d..5afa08e5 100644 --- a/packages/ssz/src/viewDU/simpleVariant.ts +++ b/packages/ssz/src/viewDU/profile.ts @@ -2,7 +2,7 @@ import {getNodeAtDepth, LeafNode, Node, setNodesAtDepth} from "@chainsafe/persis import {ByteViews, Type} from "../type/abstract"; import {BasicType, isBasicType} from "../type/basic"; import {CompositeType, isCompositeType, CompositeTypeAny} from "../type/composite"; -import {ContainerTypeGeneric} from "../view/simpleVariant"; +import {ContainerTypeGeneric} from "../view/profile"; import {TreeViewDU} from "./abstract"; /* eslint-disable @typescript-eslint/member-ordering */ diff --git a/packages/ssz/test/unit/byType/simpleVariant/valid.test.ts b/packages/ssz/test/unit/byType/profile/valid.test.ts similarity index 85% rename from packages/ssz/test/unit/byType/simpleVariant/valid.test.ts rename to packages/ssz/test/unit/byType/profile/valid.test.ts index 4ea7725d..2c4abc63 100644 --- a/packages/ssz/test/unit/byType/simpleVariant/valid.test.ts +++ b/packages/ssz/test/unit/byType/profile/valid.test.ts @@ -1,4 +1,4 @@ -import {BitArray, SimpleVariantType, UintNumberType, hash64} from "../../../../src"; +import {BitArray, ProfileType, UintNumberType, hash64} from "../../../../src"; import {runTypeTestValid} from "../runTypeTestValid"; // taken from eip spec tests @@ -6,7 +6,7 @@ import {runTypeTestValid} from "../runTypeTestValid"; const uint16 = new UintNumberType(2); const byteType = new UintNumberType(1); -const Circle1 = new SimpleVariantType( +const Circle1 = new ProfileType( { side: uint16, color: byteType, @@ -14,7 +14,7 @@ const Circle1 = new SimpleVariantType( BitArray.fromBoolArray([true, true, false, false]) ); -const Square1 = new SimpleVariantType( +const Square1 = new ProfileType( { color: byteType, radius: uint16, diff --git a/packages/ssz/test/unit/byType/runTypeProofTest.ts b/packages/ssz/test/unit/byType/runTypeProofTest.ts index dd501498..e0b36e2a 100644 --- a/packages/ssz/test/unit/byType/runTypeProofTest.ts +++ b/packages/ssz/test/unit/byType/runTypeProofTest.ts @@ -6,7 +6,7 @@ import { fromHexString, JsonPath, OptionalType, - SimpleVariantType, + ProfileType, StableContainerType, Type, } from "../../../src"; @@ -120,7 +120,7 @@ function getJsonPathView(type: Type, view: unknown, jsonPath: JsonPath) if (typeof jsonProp === "number") { view = (view as ArrayBasicTreeView).get(jsonProp); } else if (typeof jsonProp === "string") { - if (type instanceof ContainerType || type instanceof StableContainerType || type instanceof SimpleVariantType) { + if (type instanceof ContainerType || type instanceof StableContainerType || type instanceof ProfileType) { // Coerce jsonProp to a fieldName. JSON paths may be in JSON notation or fieldName notation const fieldName = (type as ContainerType>>)["jsonKeyToFieldName"][jsonProp] ?? jsonProp; @@ -152,7 +152,7 @@ function getJsonPathValue(type: Type, json: unknown, jsonPath: JsonPath if (typeof jsonProp === "number") { json = (json as unknown[])[jsonProp]; } else if (typeof jsonProp === "string") { - if (type instanceof ContainerType || type instanceof StableContainerType || type instanceof SimpleVariantType) { + if (type instanceof ContainerType || type instanceof StableContainerType || type instanceof ProfileType) { if ((type as ContainerType>>)["jsonKeyToFieldName"][jsonProp] === undefined) { throw Error(`Unknown jsonProp ${jsonProp} for type ${type.typeName}`); }