feat(dsl): support static value fields on classes#35
Conversation
Unblocks ChainSafe/lodestar#8900 Support was previously added in ChainSafe/lodestar-z#328 but the DSL update removed it
There was a problem hiding this comment.
The DSL was deliberately designed so the same declarations describe the type for both the Zig and JS sides; .static = .{ .COMPRESS_SIZE = 48 } breaks that symmetry and introduces a JS-shaped DSL surface that Zig doesn't need.
In Zig, the natural way to express BlsPublicKey.COMPRESS_SIZE already exists as a first-class language feature — namespace-level variables on a container's namespace:
pub const BlsPublicKey = struct {
pub const COMPRESS_SIZE: u32 = 48;
pub const SERIALIZE_SIZE: u32 = 96;
bytes: [96]u8,
};Accessed as BlsPublicKey.COMPRESS_SIZE in Zig, which is exactly the access shape we want on the JS constructor too. So the source of truth can be one decl, not a value duplicated into a .static block.
I would suggest to instead walk @typeInfo(T).@"struct".decls at comptime, filter to supported scalar/string types, attach each as an own property of the constructor.
For reference, we introduced js.prop earlier because there was no Zig analogue for JS shaped getter/setters. But for this feature we already have.
Unblocks ChainSafe/lodestar#8900
Support was previously added in ChainSafe/lodestar-z#328
but the DSL update removed it