Skip to content

Commit

Permalink
chore: rename variant to profile
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain authored and twoeths committed Sep 19, 2024
1 parent 0f091db commit 74b1fea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/ssz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<Fields extends Record<string, unknown>> = {
export type ProfileOptions<Fields extends Record<string, unknown>> = {
typeName?: string;
jsonCase?: KeyCase;
casingMap?: CasingMap<Fields>;
Expand All @@ -67,7 +67,7 @@ type CasingMap<Fields extends Record<string, unknown>> = Partial<{[K in keyof Fi
* Container: ordered heterogeneous collection of values
* - Notation: Custom name per instance
*/
export class SimpleVariantType<Fields extends Record<string, Type<unknown>>> extends CompositeType<
export class ProfileType<Fields extends Record<string, Type<unknown>>> extends CompositeType<
ValueOfFields<Fields>,
ContainerTreeViewType<Fields>,
ContainerTreeViewDUType<Fields>
Expand Down Expand Up @@ -97,7 +97,7 @@ export class SimpleVariantType<Fields extends Record<string, Type<unknown>>> ext
protected readonly TreeView: ContainerTreeViewTypeConstructor<Fields>;
protected readonly TreeViewDU: ContainerTreeViewDUTypeConstructor<Fields>;

constructor(readonly fields: Fields, activeFields: BitArray, readonly opts?: SimpleVariantOptions<Fields>) {
constructor(readonly fields: Fields, activeFields: BitArray, readonly opts?: ProfileOptions<Fields>) {
super(opts?.cachePermanentRootStruct);

// Render detailed typeName. Consumers should overwrite since it can get long
Expand Down Expand Up @@ -166,9 +166,9 @@ export class SimpleVariantType<Fields extends Record<string, Type<unknown>>> ext
static named<Fields extends Record<string, Type<unknown>>>(
fields: Fields,
activeFields: BitArray,
opts: Require<SimpleVariantOptions<Fields>, "typeName">
): SimpleVariantType<Fields> {
return new (namedClass(SimpleVariantType, opts.typeName))(fields, activeFields, opts);
opts: Require<ProfileOptions<Fields>, "typeName">
): ProfileType<Fields> {
return new (namedClass(ProfileType, opts.typeName))(fields, activeFields, opts);
}

defaultValue(): ValueOfFields<Fields> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {BitArray, SimpleVariantType, UintNumberType, hash64} from "../../../../src";
import {BitArray, ProfileType, UintNumberType, hash64} from "../../../../src";
import {runTypeTestValid} from "../runTypeTestValid";

// taken from eip spec tests

const uint16 = new UintNumberType(2);
const byteType = new UintNumberType(1);

const Circle1 = new SimpleVariantType(
const Circle1 = new ProfileType(
{
side: uint16,
color: byteType,
},
BitArray.fromBoolArray([true, true, false, false])
);

const Square1 = new SimpleVariantType(
const Square1 = new ProfileType(
{
color: byteType,
radius: uint16,
Expand Down
6 changes: 3 additions & 3 deletions packages/ssz/test/unit/byType/runTypeProofTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
fromHexString,
JsonPath,
OptionalType,
SimpleVariantType,
ProfileType,
StableContainerType,
Type,
} from "../../../src";
Expand Down Expand Up @@ -120,7 +120,7 @@ function getJsonPathView(type: Type<unknown>, view: unknown, jsonPath: JsonPath)
if (typeof jsonProp === "number") {
view = (view as ArrayBasicTreeView<any>).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<Record<string, Type<unknown>>>)["jsonKeyToFieldName"][jsonProp] ?? jsonProp;
Expand Down Expand Up @@ -152,7 +152,7 @@ function getJsonPathValue(type: Type<unknown>, 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<Record<string, Type<unknown>>>)["jsonKeyToFieldName"][jsonProp] === undefined) {
throw Error(`Unknown jsonProp ${jsonProp} for type ${type.typeName}`);
}
Expand Down

0 comments on commit 74b1fea

Please sign in to comment.