Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add StableContainer #373

Merged
merged 20 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added packages/ssz/package.tgz
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/ssz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export {OptionalType} from "./type/optional";
export {VectorBasicType} from "./type/vectorBasic";
export {VectorCompositeType} from "./type/vectorComposite";
export {ListUintNum64Type} from "./type/listUintNum64";
export {StableContainerType} from "./type/stableContainer";
export {ProfileType} from "./type/profile";

// Base types
export {ArrayType} from "./type/array";
Expand Down
13 changes: 13 additions & 0 deletions packages/ssz/src/type/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {CompositeType, isCompositeType} from "./composite";
import {addLengthNode, getLengthFromRootNode} from "./arrayBasic";
/* eslint-disable @typescript-eslint/member-ordering */

export type NonOptionalType<T extends Type<unknown>> = T extends OptionalType<infer U> ? U : T;
export type NonOptionalFields<Fields extends Record<string, Type<unknown>>> = {
[K in keyof Fields]: NonOptionalType<Fields[K]>;
};

export type OptionalOpts = {
typeName?: string;
};
Expand Down Expand Up @@ -258,3 +263,11 @@ export class OptionalType<ElementType extends Type<unknown>> extends CompositeTy
return this.elementType.equals(a, b);
}
}

export function isOptionalType(type: Type<unknown>): type is OptionalType<Type<unknown>> {
return type instanceof OptionalType;
}

export function toNonOptionalType<T extends Type<unknown>>(type: T): NonOptionalType<T> {
return (isOptionalType(type) ? type.elementType : type) as NonOptionalType<T>;
}
Loading
Loading