diff --git a/packages/ssz/src/view/container.ts b/packages/ssz/src/view/container.ts index c062e2cd..d65af2f8 100644 --- a/packages/ssz/src/view/container.ts +++ b/packages/ssz/src/view/container.ts @@ -3,6 +3,7 @@ import {Type, ValueOf} from "../type/abstract"; import {isBasicType, BasicType} from "../type/basic"; import {isCompositeType, CompositeType} from "../type/composite"; import {TreeView} from "./abstract"; +import type {NonOptionalFields} from "./stableContainer"; export type FieldEntry>> = { fieldName: keyof Fields; @@ -12,13 +13,16 @@ export type FieldEntry>> = { }; /** Expected API of this View's type. This interface allows to break a recursive dependency between types and views */ -export type ContainerTypeGeneric>> = CompositeType< +export type BasicContainerTypeGeneric>> = CompositeType< ValueOfFields, ContainerTreeViewType, unknown > & { readonly fields: Fields; - readonly fieldsEntries: FieldEntry[]; + readonly fieldsEntries: (FieldEntry | FieldEntry>)[]; +}; + +export type ContainerTypeGeneric>> = BasicContainerTypeGeneric & { readonly fixedEnd: number; }; @@ -35,7 +39,7 @@ export type FieldsView>> = { }; export type ContainerTreeViewType>> = FieldsView & - TreeView>; + TreeView>; export type ContainerTreeViewTypeConstructor>> = { new (type: ContainerTypeGeneric, tree: Tree): ContainerTreeViewType; }; diff --git a/packages/ssz/src/viewDU/container.ts b/packages/ssz/src/viewDU/container.ts index 3e037e0a..4a820f63 100644 --- a/packages/ssz/src/viewDU/container.ts +++ b/packages/ssz/src/viewDU/container.ts @@ -9,7 +9,7 @@ import { import {ByteViews, Type} from "../type/abstract"; import {BasicType, isBasicType} from "../type/basic"; import {CompositeType, isCompositeType, CompositeTypeAny} from "../type/composite"; -import {ContainerTypeGeneric} from "../view/container"; +import {BasicContainerTypeGeneric, ContainerTypeGeneric} from "../view/container"; import {TreeViewDU} from "./abstract"; /* eslint-disable @typescript-eslint/member-ordering */ @@ -36,8 +36,8 @@ type ContainerTreeViewDUCache = { nodesPopulated: boolean; }; -class ContainerTreeViewDU>> extends TreeViewDU< - ContainerTypeGeneric +export class BasicContainerTreeViewDU>> extends TreeViewDU< + BasicContainerTypeGeneric > { protected nodes: Node[] = []; protected caches: unknown[]; @@ -46,7 +46,7 @@ class ContainerTreeViewDU>> extends private nodesPopulated: boolean; constructor( - readonly type: ContainerTypeGeneric, + readonly type: BasicContainerTypeGeneric, protected _rootNode: Node, cache?: ContainerTreeViewDUCache ) { @@ -147,6 +147,16 @@ class ContainerTreeViewDU>> extends // However preserving _SOME_ caches results in a very unpredictable experience. this.viewsChanged.clear(); } +} + +class ContainerTreeViewDU>> extends BasicContainerTreeViewDU { + constructor( + readonly type: ContainerTypeGeneric, + protected _rootNode: Node, + cache?: ContainerTreeViewDUCache + ) { + super(type, _rootNode, cache); + } /** * Same method to `type/container.ts` that call ViewDU.serializeToBytes() of internal fields.