import { n as writeWarning, t as resolveOptions } from "./helpers-CiCrCN2f.mjs";
import { $t as initData, Cn as setUint64, Ct as getInt8, Dt as getList, Jt as getText, Nt as getPointer, Qt as getUint8, Rt as getStruct, Sn as setUint32, St as getInt64, T as ObjectSize, Tn as testWhich, X as adopt, Xt as getUint32, Yt as getUint16, Zt as getUint64, an as isNull, bn as setText, bt as getInt16, d as getUint16Mask, dn as setFloat32, dt as getAs, en as initList, et as copyFrom, fn as setFloat64, ft as getBit, gn as setInt8, hn as setInt64, ht as getData, it as disown, ln as setBit, mn as setInt32, on as pad, pn as setInt16, q as Struct, r as CompositeList, rn as initStructAt, t as Message, ut as format, vt as getFloat32, wn as setUint8, xn as setUint16, xt as getInt32, yt as getFloat64 } from "./capnp-es.GpvEvMIK-CH8kq1KS.mjs";
import { existsSync } from "@stryke/fs/exists";
import ts from "typescript";
import defu from "defu";
import { Buffer } from "node:buffer";
import { exec } from "node:child_process";

//#region ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/capnp/schema.mjs
var Node_Parameter = class extends Struct {
	static _capnp = {
		displayName: "Parameter",
		id: "b9521bccf10fa3b1",
		size: new ObjectSize(0, 1)
	};
	get name() {
		return getText(0, this);
	}
	set name(value) {
		setText(0, value, this);
	}
	toString() {
		return "Node_Parameter_" + super.toString();
	}
};
var Node_NestedNode = class extends Struct {
	static _capnp = {
		displayName: "NestedNode",
		id: "debf55bbfa0fc242",
		size: new ObjectSize(8, 1)
	};
	/**
	* Unqualified symbol name.  Unlike Node.displayName, this *can* be used programmatically.
	*
	* (On Zooko's triangle, this is the node's petname according to its parent scope.)
	*
	*/
	get name() {
		return getText(0, this);
	}
	set name(value) {
		setText(0, value, this);
	}
	/**
	* ID of the nested node.  Typically, the target node's scopeId points back to this node, but
	* robust code should avoid relying on this.
	*
	*/
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	toString() {
		return "Node_NestedNode_" + super.toString();
	}
};
var Node_SourceInfo_Member = class extends Struct {
	static _capnp = {
		displayName: "Member",
		id: "c2ba9038898e1fa2",
		size: new ObjectSize(0, 1)
	};
	/**
	* Doc comment on the member.
	*
	*/
	get docComment() {
		return getText(0, this);
	}
	set docComment(value) {
		setText(0, value, this);
	}
	toString() {
		return "Node_SourceInfo_Member_" + super.toString();
	}
};
var Node_SourceInfo = class Node_SourceInfo extends Struct {
	static Member = Node_SourceInfo_Member;
	static _capnp = {
		displayName: "SourceInfo",
		id: "f38e1de3041357ae",
		size: new ObjectSize(8, 2)
	};
	static _Members;
	/**
	* ID of the Node which this info describes.
	*
	*/
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	/**
	* The top-level doc comment for the Node.
	*
	*/
	get docComment() {
		return getText(0, this);
	}
	set docComment(value) {
		setText(0, value, this);
	}
	_adoptMembers(value) {
		adopt(value, getPointer(1, this));
	}
	_disownMembers() {
		return disown(this.members);
	}
	/**
	* Information about each member -- i.e. fields (for structs), enumerants (for enums), or
	* methods (for interfaces).
	*
	* This list is the same length and order as the corresponding list in the Node, i.e.
	* Node.struct.fields, Node.enum.enumerants, or Node.interface.methods.
	*
	*/
	get members() {
		return getList(1, Node_SourceInfo._Members, this);
	}
	_hasMembers() {
		return !isNull(getPointer(1, this));
	}
	_initMembers(length) {
		return initList(1, Node_SourceInfo._Members, length, this);
	}
	set members(value) {
		copyFrom(value, getPointer(1, this));
	}
	toString() {
		return "Node_SourceInfo_" + super.toString();
	}
};
var Node_Struct = class Node_Struct extends Struct {
	static _capnp = {
		displayName: "struct",
		id: "9ea0b19b37fb4435",
		size: new ObjectSize(40, 6)
	};
	static _Fields;
	/**
	* Size of the data section, in words.
	*
	*/
	get dataWordCount() {
		return getUint16(14, this);
	}
	set dataWordCount(value) {
		setUint16(14, value, this);
	}
	/**
	* Size of the pointer section, in pointers (which are one word each).
	*
	*/
	get pointerCount() {
		return getUint16(24, this);
	}
	set pointerCount(value) {
		setUint16(24, value, this);
	}
	/**
	* The preferred element size to use when encoding a list of this struct.  If this is anything
	* other than `inlineComposite` then the struct is one word or less in size and is a candidate
	* for list packing optimization.
	*
	*/
	get preferredListEncoding() {
		return getUint16(26, this);
	}
	set preferredListEncoding(value) {
		setUint16(26, value, this);
	}
	/**
	* If true, then this "struct" node is actually not an independent node, but merely represents
	* some named union or group within a particular parent struct.  This node's scopeId refers
	* to the parent struct, which may itself be a union/group in yet another struct.
	*
	* All group nodes share the same dataWordCount and pointerCount as the top-level
	* struct, and their fields live in the same ordinal and offset spaces as all other fields in
	* the struct.
	*
	* Note that a named union is considered a special kind of group -- in fact, a named union
	* is exactly equivalent to a group that contains nothing but an unnamed union.
	*
	*/
	get isGroup() {
		return getBit(224, this);
	}
	set isGroup(value) {
		setBit(224, value, this);
	}
	/**
	* Number of fields in this struct which are members of an anonymous union, and thus may
	* overlap.  If this is non-zero, then a 16-bit discriminant is present indicating which
	* of the overlapping fields is active.  This can never be 1 -- if it is non-zero, it must be
	* two or more.
	*
	* Note that the fields of an unnamed union are considered fields of the scope containing the
	* union -- an unnamed union is not its own group.  So, a top-level struct may contain a
	* non-zero discriminant count.  Named unions, on the other hand, are equivalent to groups
	* containing unnamed unions.  So, a named union has its own independent schema node, with
	* `isGroup` = true.
	*
	*/
	get discriminantCount() {
		return getUint16(30, this);
	}
	set discriminantCount(value) {
		setUint16(30, value, this);
	}
	/**
	* If `discriminantCount` is non-zero, this is the offset of the union discriminant, in
	* multiples of 16 bits.
	*
	*/
	get discriminantOffset() {
		return getUint32(32, this);
	}
	set discriminantOffset(value) {
		setUint32(32, value, this);
	}
	_adoptFields(value) {
		adopt(value, getPointer(3, this));
	}
	_disownFields() {
		return disown(this.fields);
	}
	/**
	* Fields defined within this scope (either the struct's top-level fields, or the fields of
	* a particular group; see `isGroup`).
	*
	* The fields are sorted by ordinal number, but note that because groups share the same
	* ordinal space, the field's index in this list is not necessarily exactly its ordinal.
	* On the other hand, the field's position in this list does remain the same even as the
	* protocol evolves, since it is not possible to insert or remove an earlier ordinal.
	* Therefore, for most use cases, if you want to identify a field by number, it may make the
	* most sense to use the field's index in this list rather than its ordinal.
	*
	*/
	get fields() {
		return getList(3, Node_Struct._Fields, this);
	}
	_hasFields() {
		return !isNull(getPointer(3, this));
	}
	_initFields(length) {
		return initList(3, Node_Struct._Fields, length, this);
	}
	set fields(value) {
		copyFrom(value, getPointer(3, this));
	}
	toString() {
		return "Node_Struct_" + super.toString();
	}
};
var Node_Enum = class Node_Enum extends Struct {
	static _capnp = {
		displayName: "enum",
		id: "b54ab3364333f598",
		size: new ObjectSize(40, 6)
	};
	static _Enumerants;
	_adoptEnumerants(value) {
		adopt(value, getPointer(3, this));
	}
	_disownEnumerants() {
		return disown(this.enumerants);
	}
	/**
	* Enumerants ordered by numeric value (ordinal).
	*
	*/
	get enumerants() {
		return getList(3, Node_Enum._Enumerants, this);
	}
	_hasEnumerants() {
		return !isNull(getPointer(3, this));
	}
	_initEnumerants(length) {
		return initList(3, Node_Enum._Enumerants, length, this);
	}
	set enumerants(value) {
		copyFrom(value, getPointer(3, this));
	}
	toString() {
		return "Node_Enum_" + super.toString();
	}
};
var Node_Interface = class Node_Interface extends Struct {
	static _capnp = {
		displayName: "interface",
		id: "e82753cff0c2218f",
		size: new ObjectSize(40, 6)
	};
	static _Methods;
	static _Superclasses;
	_adoptMethods(value) {
		adopt(value, getPointer(3, this));
	}
	_disownMethods() {
		return disown(this.methods);
	}
	/**
	* Methods ordered by ordinal.
	*
	*/
	get methods() {
		return getList(3, Node_Interface._Methods, this);
	}
	_hasMethods() {
		return !isNull(getPointer(3, this));
	}
	_initMethods(length) {
		return initList(3, Node_Interface._Methods, length, this);
	}
	set methods(value) {
		copyFrom(value, getPointer(3, this));
	}
	_adoptSuperclasses(value) {
		adopt(value, getPointer(4, this));
	}
	_disownSuperclasses() {
		return disown(this.superclasses);
	}
	/**
	* Superclasses of this interface.
	*
	*/
	get superclasses() {
		return getList(4, Node_Interface._Superclasses, this);
	}
	_hasSuperclasses() {
		return !isNull(getPointer(4, this));
	}
	_initSuperclasses(length) {
		return initList(4, Node_Interface._Superclasses, length, this);
	}
	set superclasses(value) {
		copyFrom(value, getPointer(4, this));
	}
	toString() {
		return "Node_Interface_" + super.toString();
	}
};
var Node_Const = class extends Struct {
	static _capnp = {
		displayName: "const",
		id: "b18aa5ac7a0d9420",
		size: new ObjectSize(40, 6)
	};
	_adoptType(value) {
		adopt(value, getPointer(3, this));
	}
	_disownType() {
		return disown(this.type);
	}
	get type() {
		return getStruct(3, Type, this);
	}
	_hasType() {
		return !isNull(getPointer(3, this));
	}
	_initType() {
		return initStructAt(3, Type, this);
	}
	set type(value) {
		copyFrom(value, getPointer(3, this));
	}
	_adoptValue(value) {
		adopt(value, getPointer(4, this));
	}
	_disownValue() {
		return disown(this.value);
	}
	get value() {
		return getStruct(4, Value, this);
	}
	_hasValue() {
		return !isNull(getPointer(4, this));
	}
	_initValue() {
		return initStructAt(4, Value, this);
	}
	set value(value) {
		copyFrom(value, getPointer(4, this));
	}
	toString() {
		return "Node_Const_" + super.toString();
	}
};
var Node_Annotation = class extends Struct {
	static _capnp = {
		displayName: "annotation",
		id: "ec1619d4400a0290",
		size: new ObjectSize(40, 6)
	};
	_adoptType(value) {
		adopt(value, getPointer(3, this));
	}
	_disownType() {
		return disown(this.type);
	}
	get type() {
		return getStruct(3, Type, this);
	}
	_hasType() {
		return !isNull(getPointer(3, this));
	}
	_initType() {
		return initStructAt(3, Type, this);
	}
	set type(value) {
		copyFrom(value, getPointer(3, this));
	}
	get targetsFile() {
		return getBit(112, this);
	}
	set targetsFile(value) {
		setBit(112, value, this);
	}
	get targetsConst() {
		return getBit(113, this);
	}
	set targetsConst(value) {
		setBit(113, value, this);
	}
	get targetsEnum() {
		return getBit(114, this);
	}
	set targetsEnum(value) {
		setBit(114, value, this);
	}
	get targetsEnumerant() {
		return getBit(115, this);
	}
	set targetsEnumerant(value) {
		setBit(115, value, this);
	}
	get targetsStruct() {
		return getBit(116, this);
	}
	set targetsStruct(value) {
		setBit(116, value, this);
	}
	get targetsField() {
		return getBit(117, this);
	}
	set targetsField(value) {
		setBit(117, value, this);
	}
	get targetsUnion() {
		return getBit(118, this);
	}
	set targetsUnion(value) {
		setBit(118, value, this);
	}
	get targetsGroup() {
		return getBit(119, this);
	}
	set targetsGroup(value) {
		setBit(119, value, this);
	}
	get targetsInterface() {
		return getBit(120, this);
	}
	set targetsInterface(value) {
		setBit(120, value, this);
	}
	get targetsMethod() {
		return getBit(121, this);
	}
	set targetsMethod(value) {
		setBit(121, value, this);
	}
	get targetsParam() {
		return getBit(122, this);
	}
	set targetsParam(value) {
		setBit(122, value, this);
	}
	get targetsAnnotation() {
		return getBit(123, this);
	}
	set targetsAnnotation(value) {
		setBit(123, value, this);
	}
	toString() {
		return "Node_Annotation_" + super.toString();
	}
};
const Node_Which = {
	FILE: 0,
	/**
	* Name to present to humans to identify this Node.  You should not attempt to parse this.  Its
	* format could change.  It is not guaranteed to be unique.
	*
	* (On Zooko's triangle, this is the node's nickname.)
	*
	*/
	STRUCT: 1,
	/**
	* If you want a shorter version of `displayName` (just naming this node, without its surrounding
	* scope), chop off this many characters from the beginning of `displayName`.
	*
	*/
	ENUM: 2,
	/**
	* ID of the lexical parent node.  Typically, the scope node will have a NestedNode pointing back
	* at this node, but robust code should avoid relying on this (and, in fact, group nodes are not
	* listed in the outer struct's nestedNodes, since they are listed in the fields).  `scopeId` is
	* zero if the node has no parent, which is normally only the case with files, but should be
	* allowed for any kind of node (in order to make runtime type generation easier).
	*
	*/
	INTERFACE: 3,
	/**
	* List of nodes nested within this node, along with the names under which they were declared.
	*
	*/
	CONST: 4,
	/**
	* Annotations applied to this node.
	*
	*/
	ANNOTATION: 5
};
var Node = class Node extends Struct {
	static FILE = Node_Which.FILE;
	static STRUCT = Node_Which.STRUCT;
	static ENUM = Node_Which.ENUM;
	static INTERFACE = Node_Which.INTERFACE;
	static CONST = Node_Which.CONST;
	static ANNOTATION = Node_Which.ANNOTATION;
	static Parameter = Node_Parameter;
	static NestedNode = Node_NestedNode;
	static SourceInfo = Node_SourceInfo;
	static _capnp = {
		displayName: "Node",
		id: "e682ab4cf923a417",
		size: new ObjectSize(40, 6)
	};
	static _Parameters;
	static _NestedNodes;
	static _Annotations;
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	/**
	* Name to present to humans to identify this Node.  You should not attempt to parse this.  Its
	* format could change.  It is not guaranteed to be unique.
	*
	* (On Zooko's triangle, this is the node's nickname.)
	*
	*/
	get displayName() {
		return getText(0, this);
	}
	set displayName(value) {
		setText(0, value, this);
	}
	/**
	* If you want a shorter version of `displayName` (just naming this node, without its surrounding
	* scope), chop off this many characters from the beginning of `displayName`.
	*
	*/
	get displayNamePrefixLength() {
		return getUint32(8, this);
	}
	set displayNamePrefixLength(value) {
		setUint32(8, value, this);
	}
	/**
	* ID of the lexical parent node.  Typically, the scope node will have a NestedNode pointing back
	* at this node, but robust code should avoid relying on this (and, in fact, group nodes are not
	* listed in the outer struct's nestedNodes, since they are listed in the fields).  `scopeId` is
	* zero if the node has no parent, which is normally only the case with files, but should be
	* allowed for any kind of node (in order to make runtime type generation easier).
	*
	*/
	get scopeId() {
		return getUint64(16, this);
	}
	set scopeId(value) {
		setUint64(16, value, this);
	}
	_adoptParameters(value) {
		adopt(value, getPointer(5, this));
	}
	_disownParameters() {
		return disown(this.parameters);
	}
	/**
	* If this node is parameterized (generic), the list of parameters. Empty for non-generic types.
	*
	*/
	get parameters() {
		return getList(5, Node._Parameters, this);
	}
	_hasParameters() {
		return !isNull(getPointer(5, this));
	}
	_initParameters(length) {
		return initList(5, Node._Parameters, length, this);
	}
	set parameters(value) {
		copyFrom(value, getPointer(5, this));
	}
	/**
	* True if this node is generic, meaning that it or one of its parent scopes has a non-empty
	* `parameters`.
	*
	*/
	get isGeneric() {
		return getBit(288, this);
	}
	set isGeneric(value) {
		setBit(288, value, this);
	}
	_adoptNestedNodes(value) {
		adopt(value, getPointer(1, this));
	}
	_disownNestedNodes() {
		return disown(this.nestedNodes);
	}
	/**
	* List of nodes nested within this node, along with the names under which they were declared.
	*
	*/
	get nestedNodes() {
		return getList(1, Node._NestedNodes, this);
	}
	_hasNestedNodes() {
		return !isNull(getPointer(1, this));
	}
	_initNestedNodes(length) {
		return initList(1, Node._NestedNodes, length, this);
	}
	set nestedNodes(value) {
		copyFrom(value, getPointer(1, this));
	}
	_adoptAnnotations(value) {
		adopt(value, getPointer(2, this));
	}
	_disownAnnotations() {
		return disown(this.annotations);
	}
	/**
	* Annotations applied to this node.
	*
	*/
	get annotations() {
		return getList(2, Node._Annotations, this);
	}
	_hasAnnotations() {
		return !isNull(getPointer(2, this));
	}
	_initAnnotations(length) {
		return initList(2, Node._Annotations, length, this);
	}
	set annotations(value) {
		copyFrom(value, getPointer(2, this));
	}
	get _isFile() {
		return getUint16(12, this) === 0;
	}
	set file(_) {
		setUint16(12, 0, this);
	}
	get struct() {
		testWhich("struct", getUint16(12, this), 1, this);
		return getAs(Node_Struct, this);
	}
	_initStruct() {
		setUint16(12, 1, this);
		return getAs(Node_Struct, this);
	}
	get _isStruct() {
		return getUint16(12, this) === 1;
	}
	set struct(_) {
		setUint16(12, 1, this);
	}
	get enum() {
		testWhich("enum", getUint16(12, this), 2, this);
		return getAs(Node_Enum, this);
	}
	_initEnum() {
		setUint16(12, 2, this);
		return getAs(Node_Enum, this);
	}
	get _isEnum() {
		return getUint16(12, this) === 2;
	}
	set enum(_) {
		setUint16(12, 2, this);
	}
	get interface() {
		testWhich("interface", getUint16(12, this), 3, this);
		return getAs(Node_Interface, this);
	}
	_initInterface() {
		setUint16(12, 3, this);
		return getAs(Node_Interface, this);
	}
	get _isInterface() {
		return getUint16(12, this) === 3;
	}
	set interface(_) {
		setUint16(12, 3, this);
	}
	get const() {
		testWhich("const", getUint16(12, this), 4, this);
		return getAs(Node_Const, this);
	}
	_initConst() {
		setUint16(12, 4, this);
		return getAs(Node_Const, this);
	}
	get _isConst() {
		return getUint16(12, this) === 4;
	}
	set const(_) {
		setUint16(12, 4, this);
	}
	get annotation() {
		testWhich("annotation", getUint16(12, this), 5, this);
		return getAs(Node_Annotation, this);
	}
	_initAnnotation() {
		setUint16(12, 5, this);
		return getAs(Node_Annotation, this);
	}
	get _isAnnotation() {
		return getUint16(12, this) === 5;
	}
	set annotation(_) {
		setUint16(12, 5, this);
	}
	toString() {
		return "Node_" + super.toString();
	}
	which() {
		return getUint16(12, this);
	}
};
var Field_Slot = class extends Struct {
	static _capnp = {
		displayName: "slot",
		id: "c42305476bb4746f",
		size: new ObjectSize(24, 4)
	};
	/**
	* Offset, in units of the field's size, from the beginning of the section in which the field
	* resides.  E.g. for a UInt32 field, multiply this by 4 to get the byte offset from the
	* beginning of the data section.
	*
	*/
	get offset() {
		return getUint32(4, this);
	}
	set offset(value) {
		setUint32(4, value, this);
	}
	_adoptType(value) {
		adopt(value, getPointer(2, this));
	}
	_disownType() {
		return disown(this.type);
	}
	get type() {
		return getStruct(2, Type, this);
	}
	_hasType() {
		return !isNull(getPointer(2, this));
	}
	_initType() {
		return initStructAt(2, Type, this);
	}
	set type(value) {
		copyFrom(value, getPointer(2, this));
	}
	_adoptDefaultValue(value) {
		adopt(value, getPointer(3, this));
	}
	_disownDefaultValue() {
		return disown(this.defaultValue);
	}
	get defaultValue() {
		return getStruct(3, Value, this);
	}
	_hasDefaultValue() {
		return !isNull(getPointer(3, this));
	}
	_initDefaultValue() {
		return initStructAt(3, Value, this);
	}
	set defaultValue(value) {
		copyFrom(value, getPointer(3, this));
	}
	/**
	* Whether the default value was specified explicitly.  Non-explicit default values are always
	* zero or empty values.  Usually, whether the default value was explicit shouldn't matter.
	* The main use case for this flag is for structs representing method parameters:
	* explicitly-defaulted parameters may be allowed to be omitted when calling the method.
	*
	*/
	get hadExplicitDefault() {
		return getBit(128, this);
	}
	set hadExplicitDefault(value) {
		setBit(128, value, this);
	}
	toString() {
		return "Field_Slot_" + super.toString();
	}
};
var Field_Group = class extends Struct {
	static _capnp = {
		displayName: "group",
		id: "cafccddb68db1d11",
		size: new ObjectSize(24, 4)
	};
	/**
	* The ID of the group's node.
	*
	*/
	get typeId() {
		return getUint64(16, this);
	}
	set typeId(value) {
		setUint64(16, value, this);
	}
	toString() {
		return "Field_Group_" + super.toString();
	}
};
const Field_Ordinal_Which = {
	IMPLICIT: 0,
	/**
	* The original ordinal number given to the field.  You probably should NOT use this; if you need
	* a numeric identifier for a field, use its position within the field array for its scope.
	* The ordinal is given here mainly just so that the original schema text can be reproduced given
	* the compiled version -- i.e. so that `capnp compile -ocapnp` can do its job.
	*
	*/
	EXPLICIT: 1
};
var Field_Ordinal = class extends Struct {
	static IMPLICIT = Field_Ordinal_Which.IMPLICIT;
	static EXPLICIT = Field_Ordinal_Which.EXPLICIT;
	static _capnp = {
		displayName: "ordinal",
		id: "bb90d5c287870be6",
		size: new ObjectSize(24, 4)
	};
	get _isImplicit() {
		return getUint16(10, this) === 0;
	}
	set implicit(_) {
		setUint16(10, 0, this);
	}
	/**
	* The original ordinal number given to the field.  You probably should NOT use this; if you need
	* a numeric identifier for a field, use its position within the field array for its scope.
	* The ordinal is given here mainly just so that the original schema text can be reproduced given
	* the compiled version -- i.e. so that `capnp compile -ocapnp` can do its job.
	*
	*/
	get explicit() {
		testWhich("explicit", getUint16(10, this), 1, this);
		return getUint16(12, this);
	}
	get _isExplicit() {
		return getUint16(10, this) === 1;
	}
	set explicit(value) {
		setUint16(10, 1, this);
		setUint16(12, value, this);
	}
	toString() {
		return "Field_Ordinal_" + super.toString();
	}
	which() {
		return getUint16(10, this);
	}
};
const Field_Which = {
	SLOT: 0,
	/**
	* Indicates where this member appeared in the code, relative to other members.
	* Code ordering may have semantic relevance -- programmers tend to place related fields
	* together.  So, using code ordering makes sense in human-readable formats where ordering is
	* otherwise irrelevant, like JSON.  The values of codeOrder are tightly-packed, so the maximum
	* value is count(members) - 1.  Fields that are members of a union are only ordered relative to
	* the other members of that union, so the maximum value there is count(union.members).
	*
	*/
	GROUP: 1
};
var Field = class Field extends Struct {
	static NO_DISCRIMINANT = 65535;
	static SLOT = Field_Which.SLOT;
	static GROUP = Field_Which.GROUP;
	static _capnp = {
		displayName: "Field",
		id: "9aad50a41f4af45f",
		size: new ObjectSize(24, 4),
		defaultDiscriminantValue: getUint16Mask(65535)
	};
	static _Annotations;
	get name() {
		return getText(0, this);
	}
	set name(value) {
		setText(0, value, this);
	}
	/**
	* Indicates where this member appeared in the code, relative to other members.
	* Code ordering may have semantic relevance -- programmers tend to place related fields
	* together.  So, using code ordering makes sense in human-readable formats where ordering is
	* otherwise irrelevant, like JSON.  The values of codeOrder are tightly-packed, so the maximum
	* value is count(members) - 1.  Fields that are members of a union are only ordered relative to
	* the other members of that union, so the maximum value there is count(union.members).
	*
	*/
	get codeOrder() {
		return getUint16(0, this);
	}
	set codeOrder(value) {
		setUint16(0, value, this);
	}
	_adoptAnnotations(value) {
		adopt(value, getPointer(1, this));
	}
	_disownAnnotations() {
		return disown(this.annotations);
	}
	get annotations() {
		return getList(1, Field._Annotations, this);
	}
	_hasAnnotations() {
		return !isNull(getPointer(1, this));
	}
	_initAnnotations(length) {
		return initList(1, Field._Annotations, length, this);
	}
	set annotations(value) {
		copyFrom(value, getPointer(1, this));
	}
	/**
	* If the field is in a union, this is the value which the union's discriminant should take when
	* the field is active.  If the field is not in a union, this is 0xffff.
	*
	*/
	get discriminantValue() {
		return getUint16(2, this, Field._capnp.defaultDiscriminantValue);
	}
	set discriminantValue(value) {
		setUint16(2, value, this, Field._capnp.defaultDiscriminantValue);
	}
	/**
	* A regular, non-group, non-fixed-list field.
	*
	*/
	get slot() {
		testWhich("slot", getUint16(8, this), 0, this);
		return getAs(Field_Slot, this);
	}
	_initSlot() {
		setUint16(8, 0, this);
		return getAs(Field_Slot, this);
	}
	get _isSlot() {
		return getUint16(8, this) === 0;
	}
	set slot(_) {
		setUint16(8, 0, this);
	}
	/**
	* A group.
	*
	*/
	get group() {
		testWhich("group", getUint16(8, this), 1, this);
		return getAs(Field_Group, this);
	}
	_initGroup() {
		setUint16(8, 1, this);
		return getAs(Field_Group, this);
	}
	get _isGroup() {
		return getUint16(8, this) === 1;
	}
	set group(_) {
		setUint16(8, 1, this);
	}
	get ordinal() {
		return getAs(Field_Ordinal, this);
	}
	_initOrdinal() {
		return getAs(Field_Ordinal, this);
	}
	toString() {
		return "Field_" + super.toString();
	}
	which() {
		return getUint16(8, this);
	}
};
var Enumerant = class Enumerant extends Struct {
	static _capnp = {
		displayName: "Enumerant",
		id: "978a7cebdc549a4d",
		size: new ObjectSize(8, 2)
	};
	static _Annotations;
	get name() {
		return getText(0, this);
	}
	set name(value) {
		setText(0, value, this);
	}
	/**
	* Specifies order in which the enumerants were declared in the code.
	* Like utils.Field.codeOrder.
	*
	*/
	get codeOrder() {
		return getUint16(0, this);
	}
	set codeOrder(value) {
		setUint16(0, value, this);
	}
	_adoptAnnotations(value) {
		adopt(value, getPointer(1, this));
	}
	_disownAnnotations() {
		return disown(this.annotations);
	}
	get annotations() {
		return getList(1, Enumerant._Annotations, this);
	}
	_hasAnnotations() {
		return !isNull(getPointer(1, this));
	}
	_initAnnotations(length) {
		return initList(1, Enumerant._Annotations, length, this);
	}
	set annotations(value) {
		copyFrom(value, getPointer(1, this));
	}
	toString() {
		return "Enumerant_" + super.toString();
	}
};
var Superclass = class extends Struct {
	static _capnp = {
		displayName: "Superclass",
		id: "a9962a9ed0a4d7f8",
		size: new ObjectSize(8, 1)
	};
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	_adoptBrand(value) {
		adopt(value, getPointer(0, this));
	}
	_disownBrand() {
		return disown(this.brand);
	}
	get brand() {
		return getStruct(0, Brand, this);
	}
	_hasBrand() {
		return !isNull(getPointer(0, this));
	}
	_initBrand() {
		return initStructAt(0, Brand, this);
	}
	set brand(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Superclass_" + super.toString();
	}
};
var Method = class Method extends Struct {
	static _capnp = {
		displayName: "Method",
		id: "9500cce23b334d80",
		size: new ObjectSize(24, 5)
	};
	static _ImplicitParameters;
	static _Annotations;
	get name() {
		return getText(0, this);
	}
	set name(value) {
		setText(0, value, this);
	}
	/**
	* Specifies order in which the methods were declared in the code.
	* Like utils.Field.codeOrder.
	*
	*/
	get codeOrder() {
		return getUint16(0, this);
	}
	set codeOrder(value) {
		setUint16(0, value, this);
	}
	_adoptImplicitParameters(value) {
		adopt(value, getPointer(4, this));
	}
	_disownImplicitParameters() {
		return disown(this.implicitParameters);
	}
	/**
	* The parameters listed in [] (typically, type / generic parameters), whose bindings are intended
	* to be inferred rather than specified explicitly, although not all languages support this.
	*
	*/
	get implicitParameters() {
		return getList(4, Method._ImplicitParameters, this);
	}
	_hasImplicitParameters() {
		return !isNull(getPointer(4, this));
	}
	_initImplicitParameters(length) {
		return initList(4, Method._ImplicitParameters, length, this);
	}
	set implicitParameters(value) {
		copyFrom(value, getPointer(4, this));
	}
	/**
	* ID of the parameter struct type.  If a named parameter list was specified in the method
	* declaration (rather than a single struct parameter type) then a corresponding struct type is
	* auto-generated.  Such an auto-generated type will not be listed in the interface's
	* `nestedNodes` and its `scopeId` will be zero -- it is completely detached from the namespace.
	* (Awkwardly, it does of course inherit generic parameters from the method's scope, which makes
	* this a situation where you can't just climb the scope chain to find where a particular
	* generic parameter was introduced. Making the `scopeId` zero was a mistake.)
	*
	*/
	get paramStructType() {
		return getUint64(8, this);
	}
	set paramStructType(value) {
		setUint64(8, value, this);
	}
	_adoptParamBrand(value) {
		adopt(value, getPointer(2, this));
	}
	_disownParamBrand() {
		return disown(this.paramBrand);
	}
	/**
	* Brand of param struct type.
	*
	*/
	get paramBrand() {
		return getStruct(2, Brand, this);
	}
	_hasParamBrand() {
		return !isNull(getPointer(2, this));
	}
	_initParamBrand() {
		return initStructAt(2, Brand, this);
	}
	set paramBrand(value) {
		copyFrom(value, getPointer(2, this));
	}
	/**
	* ID of the return struct type; similar to `paramStructType`.
	*
	*/
	get resultStructType() {
		return getUint64(16, this);
	}
	set resultStructType(value) {
		setUint64(16, value, this);
	}
	_adoptResultBrand(value) {
		adopt(value, getPointer(3, this));
	}
	_disownResultBrand() {
		return disown(this.resultBrand);
	}
	/**
	* Brand of result struct type.
	*
	*/
	get resultBrand() {
		return getStruct(3, Brand, this);
	}
	_hasResultBrand() {
		return !isNull(getPointer(3, this));
	}
	_initResultBrand() {
		return initStructAt(3, Brand, this);
	}
	set resultBrand(value) {
		copyFrom(value, getPointer(3, this));
	}
	_adoptAnnotations(value) {
		adopt(value, getPointer(1, this));
	}
	_disownAnnotations() {
		return disown(this.annotations);
	}
	get annotations() {
		return getList(1, Method._Annotations, this);
	}
	_hasAnnotations() {
		return !isNull(getPointer(1, this));
	}
	_initAnnotations(length) {
		return initList(1, Method._Annotations, length, this);
	}
	set annotations(value) {
		copyFrom(value, getPointer(1, this));
	}
	toString() {
		return "Method_" + super.toString();
	}
};
var Type_List = class extends Struct {
	static _capnp = {
		displayName: "list",
		id: "87e739250a60ea97",
		size: new ObjectSize(24, 1)
	};
	_adoptElementType(value) {
		adopt(value, getPointer(0, this));
	}
	_disownElementType() {
		return disown(this.elementType);
	}
	get elementType() {
		return getStruct(0, Type, this);
	}
	_hasElementType() {
		return !isNull(getPointer(0, this));
	}
	_initElementType() {
		return initStructAt(0, Type, this);
	}
	set elementType(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Type_List_" + super.toString();
	}
};
var Type_Enum = class extends Struct {
	static _capnp = {
		displayName: "enum",
		id: "9e0e78711a7f87a9",
		size: new ObjectSize(24, 1)
	};
	get typeId() {
		return getUint64(8, this);
	}
	set typeId(value) {
		setUint64(8, value, this);
	}
	_adoptBrand(value) {
		adopt(value, getPointer(0, this));
	}
	_disownBrand() {
		return disown(this.brand);
	}
	get brand() {
		return getStruct(0, Brand, this);
	}
	_hasBrand() {
		return !isNull(getPointer(0, this));
	}
	_initBrand() {
		return initStructAt(0, Brand, this);
	}
	set brand(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Type_Enum_" + super.toString();
	}
};
var Type_Struct = class extends Struct {
	static _capnp = {
		displayName: "struct",
		id: "ac3a6f60ef4cc6d3",
		size: new ObjectSize(24, 1)
	};
	get typeId() {
		return getUint64(8, this);
	}
	set typeId(value) {
		setUint64(8, value, this);
	}
	_adoptBrand(value) {
		adopt(value, getPointer(0, this));
	}
	_disownBrand() {
		return disown(this.brand);
	}
	get brand() {
		return getStruct(0, Brand, this);
	}
	_hasBrand() {
		return !isNull(getPointer(0, this));
	}
	_initBrand() {
		return initStructAt(0, Brand, this);
	}
	set brand(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Type_Struct_" + super.toString();
	}
};
var Type_Interface = class extends Struct {
	static _capnp = {
		displayName: "interface",
		id: "ed8bca69f7fb0cbf",
		size: new ObjectSize(24, 1)
	};
	get typeId() {
		return getUint64(8, this);
	}
	set typeId(value) {
		setUint64(8, value, this);
	}
	_adoptBrand(value) {
		adopt(value, getPointer(0, this));
	}
	_disownBrand() {
		return disown(this.brand);
	}
	get brand() {
		return getStruct(0, Brand, this);
	}
	_hasBrand() {
		return !isNull(getPointer(0, this));
	}
	_initBrand() {
		return initStructAt(0, Brand, this);
	}
	set brand(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Type_Interface_" + super.toString();
	}
};
const Type_AnyPointer_Unconstrained_Which = {
	/**
	* truly AnyPointer
	*
	*/
	ANY_KIND: 0,
	/**
	* AnyStruct
	*
	*/
	STRUCT: 1,
	/**
	* AnyList
	*
	*/
	LIST: 2,
	/**
	* Capability
	*
	*/
	CAPABILITY: 3
};
var Type_AnyPointer_Unconstrained = class extends Struct {
	static ANY_KIND = Type_AnyPointer_Unconstrained_Which.ANY_KIND;
	static STRUCT = Type_AnyPointer_Unconstrained_Which.STRUCT;
	static LIST = Type_AnyPointer_Unconstrained_Which.LIST;
	static CAPABILITY = Type_AnyPointer_Unconstrained_Which.CAPABILITY;
	static _capnp = {
		displayName: "unconstrained",
		id: "8e3b5f79fe593656",
		size: new ObjectSize(24, 1)
	};
	get _isAnyKind() {
		return getUint16(10, this) === 0;
	}
	set anyKind(_) {
		setUint16(10, 0, this);
	}
	get _isStruct() {
		return getUint16(10, this) === 1;
	}
	set struct(_) {
		setUint16(10, 1, this);
	}
	get _isList() {
		return getUint16(10, this) === 2;
	}
	set list(_) {
		setUint16(10, 2, this);
	}
	get _isCapability() {
		return getUint16(10, this) === 3;
	}
	set capability(_) {
		setUint16(10, 3, this);
	}
	toString() {
		return "Type_AnyPointer_Unconstrained_" + super.toString();
	}
	which() {
		return getUint16(10, this);
	}
};
var Type_AnyPointer_Parameter = class extends Struct {
	static _capnp = {
		displayName: "parameter",
		id: "9dd1f724f4614a85",
		size: new ObjectSize(24, 1)
	};
	/**
	* ID of the generic type whose parameter we're referencing. This should be a parent of the
	* current scope.
	*
	*/
	get scopeId() {
		return getUint64(16, this);
	}
	set scopeId(value) {
		setUint64(16, value, this);
	}
	/**
	* Index of the parameter within the generic type's parameter list.
	*
	*/
	get parameterIndex() {
		return getUint16(10, this);
	}
	set parameterIndex(value) {
		setUint16(10, value, this);
	}
	toString() {
		return "Type_AnyPointer_Parameter_" + super.toString();
	}
};
var Type_AnyPointer_ImplicitMethodParameter = class extends Struct {
	static _capnp = {
		displayName: "implicitMethodParameter",
		id: "baefc9120c56e274",
		size: new ObjectSize(24, 1)
	};
	get parameterIndex() {
		return getUint16(10, this);
	}
	set parameterIndex(value) {
		setUint16(10, value, this);
	}
	toString() {
		return "Type_AnyPointer_ImplicitMethodParameter_" + super.toString();
	}
};
const Type_AnyPointer_Which = {
	/**
	* A regular AnyPointer.
	*
	* The name "unconstrained" means as opposed to constraining it to match a type parameter.
	* In retrospect this name is probably a poor choice given that it may still be constrained
	* to be a struct, list, or capability.
	*
	*/
	UNCONSTRAINED: 0,
	/**
	* This is actually a reference to a type parameter defined within this scope.
	*
	*/
	PARAMETER: 1,
	/**
	* This is actually a reference to an implicit (generic) parameter of a method. The only
	* legal context for this type to appear is inside Method.paramBrand or Method.resultBrand.
	*
	*/
	IMPLICIT_METHOD_PARAMETER: 2
};
var Type_AnyPointer = class extends Struct {
	static UNCONSTRAINED = Type_AnyPointer_Which.UNCONSTRAINED;
	static PARAMETER = Type_AnyPointer_Which.PARAMETER;
	static IMPLICIT_METHOD_PARAMETER = Type_AnyPointer_Which.IMPLICIT_METHOD_PARAMETER;
	static _capnp = {
		displayName: "anyPointer",
		id: "c2573fe8a23e49f1",
		size: new ObjectSize(24, 1)
	};
	/**
	* A regular AnyPointer.
	*
	* The name "unconstrained" means as opposed to constraining it to match a type parameter.
	* In retrospect this name is probably a poor choice given that it may still be constrained
	* to be a struct, list, or capability.
	*
	*/
	get unconstrained() {
		testWhich("unconstrained", getUint16(8, this), 0, this);
		return getAs(Type_AnyPointer_Unconstrained, this);
	}
	_initUnconstrained() {
		setUint16(8, 0, this);
		return getAs(Type_AnyPointer_Unconstrained, this);
	}
	get _isUnconstrained() {
		return getUint16(8, this) === 0;
	}
	set unconstrained(_) {
		setUint16(8, 0, this);
	}
	/**
	* This is actually a reference to a type parameter defined within this scope.
	*
	*/
	get parameter() {
		testWhich("parameter", getUint16(8, this), 1, this);
		return getAs(Type_AnyPointer_Parameter, this);
	}
	_initParameter() {
		setUint16(8, 1, this);
		return getAs(Type_AnyPointer_Parameter, this);
	}
	get _isParameter() {
		return getUint16(8, this) === 1;
	}
	set parameter(_) {
		setUint16(8, 1, this);
	}
	/**
	* This is actually a reference to an implicit (generic) parameter of a method. The only
	* legal context for this type to appear is inside Method.paramBrand or Method.resultBrand.
	*
	*/
	get implicitMethodParameter() {
		testWhich("implicitMethodParameter", getUint16(8, this), 2, this);
		return getAs(Type_AnyPointer_ImplicitMethodParameter, this);
	}
	_initImplicitMethodParameter() {
		setUint16(8, 2, this);
		return getAs(Type_AnyPointer_ImplicitMethodParameter, this);
	}
	get _isImplicitMethodParameter() {
		return getUint16(8, this) === 2;
	}
	set implicitMethodParameter(_) {
		setUint16(8, 2, this);
	}
	toString() {
		return "Type_AnyPointer_" + super.toString();
	}
	which() {
		return getUint16(8, this);
	}
};
const Type_Which = {
	VOID: 0,
	BOOL: 1,
	INT8: 2,
	INT16: 3,
	INT32: 4,
	INT64: 5,
	UINT8: 6,
	UINT16: 7,
	UINT32: 8,
	UINT64: 9,
	FLOAT32: 10,
	FLOAT64: 11,
	TEXT: 12,
	DATA: 13,
	LIST: 14,
	ENUM: 15,
	STRUCT: 16,
	INTERFACE: 17,
	ANY_POINTER: 18
};
var Type = class extends Struct {
	static VOID = Type_Which.VOID;
	static BOOL = Type_Which.BOOL;
	static INT8 = Type_Which.INT8;
	static INT16 = Type_Which.INT16;
	static INT32 = Type_Which.INT32;
	static INT64 = Type_Which.INT64;
	static UINT8 = Type_Which.UINT8;
	static UINT16 = Type_Which.UINT16;
	static UINT32 = Type_Which.UINT32;
	static UINT64 = Type_Which.UINT64;
	static FLOAT32 = Type_Which.FLOAT32;
	static FLOAT64 = Type_Which.FLOAT64;
	static TEXT = Type_Which.TEXT;
	static DATA = Type_Which.DATA;
	static LIST = Type_Which.LIST;
	static ENUM = Type_Which.ENUM;
	static STRUCT = Type_Which.STRUCT;
	static INTERFACE = Type_Which.INTERFACE;
	static ANY_POINTER = Type_Which.ANY_POINTER;
	static _capnp = {
		displayName: "Type",
		id: "d07378ede1f9cc60",
		size: new ObjectSize(24, 1)
	};
	get _isVoid() {
		return getUint16(0, this) === 0;
	}
	set void(_) {
		setUint16(0, 0, this);
	}
	get _isBool() {
		return getUint16(0, this) === 1;
	}
	set bool(_) {
		setUint16(0, 1, this);
	}
	get _isInt8() {
		return getUint16(0, this) === 2;
	}
	set int8(_) {
		setUint16(0, 2, this);
	}
	get _isInt16() {
		return getUint16(0, this) === 3;
	}
	set int16(_) {
		setUint16(0, 3, this);
	}
	get _isInt32() {
		return getUint16(0, this) === 4;
	}
	set int32(_) {
		setUint16(0, 4, this);
	}
	get _isInt64() {
		return getUint16(0, this) === 5;
	}
	set int64(_) {
		setUint16(0, 5, this);
	}
	get _isUint8() {
		return getUint16(0, this) === 6;
	}
	set uint8(_) {
		setUint16(0, 6, this);
	}
	get _isUint16() {
		return getUint16(0, this) === 7;
	}
	set uint16(_) {
		setUint16(0, 7, this);
	}
	get _isUint32() {
		return getUint16(0, this) === 8;
	}
	set uint32(_) {
		setUint16(0, 8, this);
	}
	get _isUint64() {
		return getUint16(0, this) === 9;
	}
	set uint64(_) {
		setUint16(0, 9, this);
	}
	get _isFloat32() {
		return getUint16(0, this) === 10;
	}
	set float32(_) {
		setUint16(0, 10, this);
	}
	get _isFloat64() {
		return getUint16(0, this) === 11;
	}
	set float64(_) {
		setUint16(0, 11, this);
	}
	get _isText() {
		return getUint16(0, this) === 12;
	}
	set text(_) {
		setUint16(0, 12, this);
	}
	get _isData() {
		return getUint16(0, this) === 13;
	}
	set data(_) {
		setUint16(0, 13, this);
	}
	get list() {
		testWhich("list", getUint16(0, this), 14, this);
		return getAs(Type_List, this);
	}
	_initList() {
		setUint16(0, 14, this);
		return getAs(Type_List, this);
	}
	get _isList() {
		return getUint16(0, this) === 14;
	}
	set list(_) {
		setUint16(0, 14, this);
	}
	get enum() {
		testWhich("enum", getUint16(0, this), 15, this);
		return getAs(Type_Enum, this);
	}
	_initEnum() {
		setUint16(0, 15, this);
		return getAs(Type_Enum, this);
	}
	get _isEnum() {
		return getUint16(0, this) === 15;
	}
	set enum(_) {
		setUint16(0, 15, this);
	}
	get struct() {
		testWhich("struct", getUint16(0, this), 16, this);
		return getAs(Type_Struct, this);
	}
	_initStruct() {
		setUint16(0, 16, this);
		return getAs(Type_Struct, this);
	}
	get _isStruct() {
		return getUint16(0, this) === 16;
	}
	set struct(_) {
		setUint16(0, 16, this);
	}
	get interface() {
		testWhich("interface", getUint16(0, this), 17, this);
		return getAs(Type_Interface, this);
	}
	_initInterface() {
		setUint16(0, 17, this);
		return getAs(Type_Interface, this);
	}
	get _isInterface() {
		return getUint16(0, this) === 17;
	}
	set interface(_) {
		setUint16(0, 17, this);
	}
	get anyPointer() {
		testWhich("anyPointer", getUint16(0, this), 18, this);
		return getAs(Type_AnyPointer, this);
	}
	_initAnyPointer() {
		setUint16(0, 18, this);
		return getAs(Type_AnyPointer, this);
	}
	get _isAnyPointer() {
		return getUint16(0, this) === 18;
	}
	set anyPointer(_) {
		setUint16(0, 18, this);
	}
	toString() {
		return "Type_" + super.toString();
	}
	which() {
		return getUint16(0, this);
	}
};
const Brand_Scope_Which = {
	/**
	* ID of the scope to which these params apply.
	*
	*/
	BIND: 0,
	/**
	* List of parameter bindings.
	*
	*/
	INHERIT: 1
};
var Brand_Scope = class Brand_Scope extends Struct {
	static BIND = Brand_Scope_Which.BIND;
	static INHERIT = Brand_Scope_Which.INHERIT;
	static _capnp = {
		displayName: "Scope",
		id: "abd73485a9636bc9",
		size: new ObjectSize(16, 1)
	};
	static _Bind;
	/**
	* ID of the scope to which these params apply.
	*
	*/
	get scopeId() {
		return getUint64(0, this);
	}
	set scopeId(value) {
		setUint64(0, value, this);
	}
	_adoptBind(value) {
		setUint16(8, 0, this);
		adopt(value, getPointer(0, this));
	}
	_disownBind() {
		return disown(this.bind);
	}
	/**
	* List of parameter bindings.
	*
	*/
	get bind() {
		testWhich("bind", getUint16(8, this), 0, this);
		return getList(0, Brand_Scope._Bind, this);
	}
	_hasBind() {
		return !isNull(getPointer(0, this));
	}
	_initBind(length) {
		setUint16(8, 0, this);
		return initList(0, Brand_Scope._Bind, length, this);
	}
	get _isBind() {
		return getUint16(8, this) === 0;
	}
	set bind(value) {
		setUint16(8, 0, this);
		copyFrom(value, getPointer(0, this));
	}
	get _isInherit() {
		return getUint16(8, this) === 1;
	}
	set inherit(_) {
		setUint16(8, 1, this);
	}
	toString() {
		return "Brand_Scope_" + super.toString();
	}
	which() {
		return getUint16(8, this);
	}
};
const Brand_Binding_Which = {
	UNBOUND: 0,
	TYPE: 1
};
var Brand_Binding = class extends Struct {
	static UNBOUND = Brand_Binding_Which.UNBOUND;
	static TYPE = Brand_Binding_Which.TYPE;
	static _capnp = {
		displayName: "Binding",
		id: "c863cd16969ee7fc",
		size: new ObjectSize(8, 1)
	};
	get _isUnbound() {
		return getUint16(0, this) === 0;
	}
	set unbound(_) {
		setUint16(0, 0, this);
	}
	_adoptType(value) {
		setUint16(0, 1, this);
		adopt(value, getPointer(0, this));
	}
	_disownType() {
		return disown(this.type);
	}
	get type() {
		testWhich("type", getUint16(0, this), 1, this);
		return getStruct(0, Type, this);
	}
	_hasType() {
		return !isNull(getPointer(0, this));
	}
	_initType() {
		setUint16(0, 1, this);
		return initStructAt(0, Type, this);
	}
	get _isType() {
		return getUint16(0, this) === 1;
	}
	set type(value) {
		setUint16(0, 1, this);
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Brand_Binding_" + super.toString();
	}
	which() {
		return getUint16(0, this);
	}
};
var Brand = class Brand extends Struct {
	static Scope = Brand_Scope;
	static Binding = Brand_Binding;
	static _capnp = {
		displayName: "Brand",
		id: "903455f06065422b",
		size: new ObjectSize(0, 1)
	};
	static _Scopes;
	_adoptScopes(value) {
		adopt(value, getPointer(0, this));
	}
	_disownScopes() {
		return disown(this.scopes);
	}
	/**
	* For each of the target type and each of its parent scopes, a parameterization may be included
	* in this list. If no parameterization is included for a particular relevant scope, then either
	* that scope has no parameters or all parameters should be considered to be `AnyPointer`.
	*
	*/
	get scopes() {
		return getList(0, Brand._Scopes, this);
	}
	_hasScopes() {
		return !isNull(getPointer(0, this));
	}
	_initScopes(length) {
		return initList(0, Brand._Scopes, length, this);
	}
	set scopes(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Brand_" + super.toString();
	}
};
const Value_Which = {
	VOID: 0,
	BOOL: 1,
	INT8: 2,
	INT16: 3,
	INT32: 4,
	INT64: 5,
	UINT8: 6,
	UINT16: 7,
	UINT32: 8,
	UINT64: 9,
	FLOAT32: 10,
	FLOAT64: 11,
	TEXT: 12,
	DATA: 13,
	LIST: 14,
	ENUM: 15,
	STRUCT: 16,
	/**
	* The only interface value that can be represented statically is "null", whose methods always
	* throw exceptions.
	*
	*/
	INTERFACE: 17,
	ANY_POINTER: 18
};
var Value = class extends Struct {
	static VOID = Value_Which.VOID;
	static BOOL = Value_Which.BOOL;
	static INT8 = Value_Which.INT8;
	static INT16 = Value_Which.INT16;
	static INT32 = Value_Which.INT32;
	static INT64 = Value_Which.INT64;
	static UINT8 = Value_Which.UINT8;
	static UINT16 = Value_Which.UINT16;
	static UINT32 = Value_Which.UINT32;
	static UINT64 = Value_Which.UINT64;
	static FLOAT32 = Value_Which.FLOAT32;
	static FLOAT64 = Value_Which.FLOAT64;
	static TEXT = Value_Which.TEXT;
	static DATA = Value_Which.DATA;
	static LIST = Value_Which.LIST;
	static ENUM = Value_Which.ENUM;
	static STRUCT = Value_Which.STRUCT;
	static INTERFACE = Value_Which.INTERFACE;
	static ANY_POINTER = Value_Which.ANY_POINTER;
	static _capnp = {
		displayName: "Value",
		id: "ce23dcd2d7b00c9b",
		size: new ObjectSize(16, 1)
	};
	get _isVoid() {
		return getUint16(0, this) === 0;
	}
	set void(_) {
		setUint16(0, 0, this);
	}
	get bool() {
		testWhich("bool", getUint16(0, this), 1, this);
		return getBit(16, this);
	}
	get _isBool() {
		return getUint16(0, this) === 1;
	}
	set bool(value) {
		setUint16(0, 1, this);
		setBit(16, value, this);
	}
	get int8() {
		testWhich("int8", getUint16(0, this), 2, this);
		return getInt8(2, this);
	}
	get _isInt8() {
		return getUint16(0, this) === 2;
	}
	set int8(value) {
		setUint16(0, 2, this);
		setInt8(2, value, this);
	}
	get int16() {
		testWhich("int16", getUint16(0, this), 3, this);
		return getInt16(2, this);
	}
	get _isInt16() {
		return getUint16(0, this) === 3;
	}
	set int16(value) {
		setUint16(0, 3, this);
		setInt16(2, value, this);
	}
	get int32() {
		testWhich("int32", getUint16(0, this), 4, this);
		return getInt32(4, this);
	}
	get _isInt32() {
		return getUint16(0, this) === 4;
	}
	set int32(value) {
		setUint16(0, 4, this);
		setInt32(4, value, this);
	}
	get int64() {
		testWhich("int64", getUint16(0, this), 5, this);
		return getInt64(8, this);
	}
	get _isInt64() {
		return getUint16(0, this) === 5;
	}
	set int64(value) {
		setUint16(0, 5, this);
		setInt64(8, value, this);
	}
	get uint8() {
		testWhich("uint8", getUint16(0, this), 6, this);
		return getUint8(2, this);
	}
	get _isUint8() {
		return getUint16(0, this) === 6;
	}
	set uint8(value) {
		setUint16(0, 6, this);
		setUint8(2, value, this);
	}
	get uint16() {
		testWhich("uint16", getUint16(0, this), 7, this);
		return getUint16(2, this);
	}
	get _isUint16() {
		return getUint16(0, this) === 7;
	}
	set uint16(value) {
		setUint16(0, 7, this);
		setUint16(2, value, this);
	}
	get uint32() {
		testWhich("uint32", getUint16(0, this), 8, this);
		return getUint32(4, this);
	}
	get _isUint32() {
		return getUint16(0, this) === 8;
	}
	set uint32(value) {
		setUint16(0, 8, this);
		setUint32(4, value, this);
	}
	get uint64() {
		testWhich("uint64", getUint16(0, this), 9, this);
		return getUint64(8, this);
	}
	get _isUint64() {
		return getUint16(0, this) === 9;
	}
	set uint64(value) {
		setUint16(0, 9, this);
		setUint64(8, value, this);
	}
	get float32() {
		testWhich("float32", getUint16(0, this), 10, this);
		return getFloat32(4, this);
	}
	get _isFloat32() {
		return getUint16(0, this) === 10;
	}
	set float32(value) {
		setUint16(0, 10, this);
		setFloat32(4, value, this);
	}
	get float64() {
		testWhich("float64", getUint16(0, this), 11, this);
		return getFloat64(8, this);
	}
	get _isFloat64() {
		return getUint16(0, this) === 11;
	}
	set float64(value) {
		setUint16(0, 11, this);
		setFloat64(8, value, this);
	}
	get text() {
		testWhich("text", getUint16(0, this), 12, this);
		return getText(0, this);
	}
	get _isText() {
		return getUint16(0, this) === 12;
	}
	set text(value) {
		setUint16(0, 12, this);
		setText(0, value, this);
	}
	_adoptData(value) {
		setUint16(0, 13, this);
		adopt(value, getPointer(0, this));
	}
	_disownData() {
		return disown(this.data);
	}
	get data() {
		testWhich("data", getUint16(0, this), 13, this);
		return getData(0, this);
	}
	_hasData() {
		return !isNull(getPointer(0, this));
	}
	_initData(length) {
		setUint16(0, 13, this);
		return initData(0, length, this);
	}
	get _isData() {
		return getUint16(0, this) === 13;
	}
	set data(value) {
		setUint16(0, 13, this);
		copyFrom(value, getPointer(0, this));
	}
	_adoptList(value) {
		setUint16(0, 14, this);
		adopt(value, getPointer(0, this));
	}
	_disownList() {
		return disown(this.list);
	}
	get list() {
		testWhich("list", getUint16(0, this), 14, this);
		return getPointer(0, this);
	}
	_hasList() {
		return !isNull(getPointer(0, this));
	}
	get _isList() {
		return getUint16(0, this) === 14;
	}
	set list(value) {
		setUint16(0, 14, this);
		copyFrom(value, getPointer(0, this));
	}
	get enum() {
		testWhich("enum", getUint16(0, this), 15, this);
		return getUint16(2, this);
	}
	get _isEnum() {
		return getUint16(0, this) === 15;
	}
	set enum(value) {
		setUint16(0, 15, this);
		setUint16(2, value, this);
	}
	_adoptStruct(value) {
		setUint16(0, 16, this);
		adopt(value, getPointer(0, this));
	}
	_disownStruct() {
		return disown(this.struct);
	}
	get struct() {
		testWhich("struct", getUint16(0, this), 16, this);
		return getPointer(0, this);
	}
	_hasStruct() {
		return !isNull(getPointer(0, this));
	}
	get _isStruct() {
		return getUint16(0, this) === 16;
	}
	set struct(value) {
		setUint16(0, 16, this);
		copyFrom(value, getPointer(0, this));
	}
	get _isInterface() {
		return getUint16(0, this) === 17;
	}
	set interface(_) {
		setUint16(0, 17, this);
	}
	_adoptAnyPointer(value) {
		setUint16(0, 18, this);
		adopt(value, getPointer(0, this));
	}
	_disownAnyPointer() {
		return disown(this.anyPointer);
	}
	get anyPointer() {
		testWhich("anyPointer", getUint16(0, this), 18, this);
		return getPointer(0, this);
	}
	_hasAnyPointer() {
		return !isNull(getPointer(0, this));
	}
	get _isAnyPointer() {
		return getUint16(0, this) === 18;
	}
	set anyPointer(value) {
		setUint16(0, 18, this);
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Value_" + super.toString();
	}
	which() {
		return getUint16(0, this);
	}
};
var Annotation = class extends Struct {
	static _capnp = {
		displayName: "Annotation",
		id: "f1c8950dab257542",
		size: new ObjectSize(8, 2)
	};
	/**
	* ID of the annotation node.
	*
	*/
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	_adoptBrand(value) {
		adopt(value, getPointer(1, this));
	}
	_disownBrand() {
		return disown(this.brand);
	}
	/**
	* Brand of the annotation.
	*
	* Note that the annotation itself is not allowed to be parameterized, but its scope might be.
	*
	*/
	get brand() {
		return getStruct(1, Brand, this);
	}
	_hasBrand() {
		return !isNull(getPointer(1, this));
	}
	_initBrand() {
		return initStructAt(1, Brand, this);
	}
	set brand(value) {
		copyFrom(value, getPointer(1, this));
	}
	_adoptValue(value) {
		adopt(value, getPointer(0, this));
	}
	_disownValue() {
		return disown(this.value);
	}
	get value() {
		return getStruct(0, Value, this);
	}
	_hasValue() {
		return !isNull(getPointer(0, this));
	}
	_initValue() {
		return initStructAt(0, Value, this);
	}
	set value(value) {
		copyFrom(value, getPointer(0, this));
	}
	toString() {
		return "Annotation_" + super.toString();
	}
};
const ElementSize = {
	/**
	* aka "void", but that's a keyword.
	*
	*/
	EMPTY: 0,
	BIT: 1,
	BYTE: 2,
	TWO_BYTES: 3,
	FOUR_BYTES: 4,
	EIGHT_BYTES: 5,
	POINTER: 6,
	INLINE_COMPOSITE: 7
};
var CapnpVersion = class extends Struct {
	static _capnp = {
		displayName: "CapnpVersion",
		id: "d85d305b7d839963",
		size: new ObjectSize(8, 0)
	};
	get major() {
		return getUint16(0, this);
	}
	set major(value) {
		setUint16(0, value, this);
	}
	get minor() {
		return getUint8(2, this);
	}
	set minor(value) {
		setUint8(2, value, this);
	}
	get micro() {
		return getUint8(3, this);
	}
	set micro(value) {
		setUint8(3, value, this);
	}
	toString() {
		return "CapnpVersion_" + super.toString();
	}
};
var CodeGeneratorRequest_RequestedFile_Import = class extends Struct {
	static _capnp = {
		displayName: "Import",
		id: "ae504193122357e5",
		size: new ObjectSize(8, 1)
	};
	/**
	* ID of the imported file.
	*
	*/
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	/**
	* Name which *this* file used to refer to the foreign file.  This may be a relative name.
	* This information is provided because it might be useful for code generation, e.g. to
	* generate #include directives in C++.  We don't put this in Node.file because this
	* information is only meaningful at compile time anyway.
	*
	* (On Zooko's triangle, this is the import's petname according to the importing file.)
	*
	*/
	get name() {
		return getText(0, this);
	}
	set name(value) {
		setText(0, value, this);
	}
	toString() {
		return "CodeGeneratorRequest_RequestedFile_Import_" + super.toString();
	}
};
var CodeGeneratorRequest_RequestedFile = class CodeGeneratorRequest_RequestedFile extends Struct {
	static Import = CodeGeneratorRequest_RequestedFile_Import;
	static _capnp = {
		displayName: "RequestedFile",
		id: "cfea0eb02e810062",
		size: new ObjectSize(8, 2)
	};
	static _Imports;
	/**
	* ID of the file.
	*
	*/
	get id() {
		return getUint64(0, this);
	}
	set id(value) {
		setUint64(0, value, this);
	}
	/**
	* Name of the file as it appeared on the command-line (minus the src-prefix).  You may use
	* this to decide where to write the output.
	*
	*/
	get filename() {
		return getText(0, this);
	}
	set filename(value) {
		setText(0, value, this);
	}
	_adoptImports(value) {
		adopt(value, getPointer(1, this));
	}
	_disownImports() {
		return disown(this.imports);
	}
	/**
	* List of all imported paths seen in this file.
	*
	*/
	get imports() {
		return getList(1, CodeGeneratorRequest_RequestedFile._Imports, this);
	}
	_hasImports() {
		return !isNull(getPointer(1, this));
	}
	_initImports(length) {
		return initList(1, CodeGeneratorRequest_RequestedFile._Imports, length, this);
	}
	set imports(value) {
		copyFrom(value, getPointer(1, this));
	}
	toString() {
		return "CodeGeneratorRequest_RequestedFile_" + super.toString();
	}
};
var CodeGeneratorRequest = class CodeGeneratorRequest extends Struct {
	static RequestedFile = CodeGeneratorRequest_RequestedFile;
	static _capnp = {
		displayName: "CodeGeneratorRequest",
		id: "bfc546f6210ad7ce",
		size: new ObjectSize(0, 4)
	};
	static _Nodes;
	static _SourceInfo;
	static _RequestedFiles;
	_adoptCapnpVersion(value) {
		adopt(value, getPointer(2, this));
	}
	_disownCapnpVersion() {
		return disown(this.capnpVersion);
	}
	/**
	* Version of the `capnp` executable. Generally, code generators should ignore this, but the code
	* generators that ship with `capnp` itself will print a warning if this mismatches since that
	* probably indicates something is misconfigured.
	*
	* The first version of 'capnp' to set this was 0.6.0. So, if it's missing, the compiler version
	* is older than that.
	*
	*/
	get capnpVersion() {
		return getStruct(2, CapnpVersion, this);
	}
	_hasCapnpVersion() {
		return !isNull(getPointer(2, this));
	}
	_initCapnpVersion() {
		return initStructAt(2, CapnpVersion, this);
	}
	set capnpVersion(value) {
		copyFrom(value, getPointer(2, this));
	}
	_adoptNodes(value) {
		adopt(value, getPointer(0, this));
	}
	_disownNodes() {
		return disown(this.nodes);
	}
	/**
	* All nodes parsed by the compiler, including for the files on the command line and their
	* imports.
	*
	*/
	get nodes() {
		return getList(0, CodeGeneratorRequest._Nodes, this);
	}
	_hasNodes() {
		return !isNull(getPointer(0, this));
	}
	_initNodes(length) {
		return initList(0, CodeGeneratorRequest._Nodes, length, this);
	}
	set nodes(value) {
		copyFrom(value, getPointer(0, this));
	}
	_adoptSourceInfo(value) {
		adopt(value, getPointer(3, this));
	}
	_disownSourceInfo() {
		return disown(this.sourceInfo);
	}
	/**
	* Information about the original source code for each node, where available. This array may be
	* omitted or may be missing some nodes if no info is available for them.
	*
	*/
	get sourceInfo() {
		return getList(3, CodeGeneratorRequest._SourceInfo, this);
	}
	_hasSourceInfo() {
		return !isNull(getPointer(3, this));
	}
	_initSourceInfo(length) {
		return initList(3, CodeGeneratorRequest._SourceInfo, length, this);
	}
	set sourceInfo(value) {
		copyFrom(value, getPointer(3, this));
	}
	_adoptRequestedFiles(value) {
		adopt(value, getPointer(1, this));
	}
	_disownRequestedFiles() {
		return disown(this.requestedFiles);
	}
	/**
	* Files which were listed on the command line.
	*
	*/
	get requestedFiles() {
		return getList(1, CodeGeneratorRequest._RequestedFiles, this);
	}
	_hasRequestedFiles() {
		return !isNull(getPointer(1, this));
	}
	_initRequestedFiles(length) {
		return initList(1, CodeGeneratorRequest._RequestedFiles, length, this);
	}
	set requestedFiles(value) {
		copyFrom(value, getPointer(1, this));
	}
	toString() {
		return "CodeGeneratorRequest_" + super.toString();
	}
};
Node_SourceInfo._Members = CompositeList(Node_SourceInfo_Member);
Node_Struct._Fields = CompositeList(Field);
Node_Enum._Enumerants = CompositeList(Enumerant);
Node_Interface._Methods = CompositeList(Method);
Node_Interface._Superclasses = CompositeList(Superclass);
Node._Parameters = CompositeList(Node_Parameter);
Node._NestedNodes = CompositeList(Node_NestedNode);
Node._Annotations = CompositeList(Annotation);
Field._Annotations = CompositeList(Annotation);
Enumerant._Annotations = CompositeList(Annotation);
Method._ImplicitParameters = CompositeList(Node_Parameter);
Method._Annotations = CompositeList(Annotation);
Brand_Scope._Bind = CompositeList(Brand_Binding);
Brand._Scopes = CompositeList(Brand_Scope);
CodeGeneratorRequest_RequestedFile._Imports = CompositeList(CodeGeneratorRequest_RequestedFile_Import);
CodeGeneratorRequest._Nodes = CompositeList(Node);
CodeGeneratorRequest._SourceInfo = CompositeList(Node_SourceInfo);
CodeGeneratorRequest._RequestedFiles = CompositeList(CodeGeneratorRequest_RequestedFile);

//#endregion
//#region ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/shared/capnp-es.CbTQkT9D.mjs
const GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE = "CAPNP-ES000 Don't know how to generate a %s field with an explicit default value.";
const GEN_FIELD_NON_INLINE_STRUCT_LIST = "CAPNP-ES001 Don't know how to generate non-inline struct lists.";
const GEN_NODE_LOOKUP_FAIL = "CAPNP-ES002 Failed to look up node id %s.";
const GEN_NODE_UNKNOWN_TYPE = `CAPNP-ES003 Don't know how to generate a "%s" node.`;
const GEN_SERIALIZE_UNKNOWN_VALUE = "CAPNP-ES004 Don't know how to serialize a value of kind %s.";
const GEN_UNKNOWN_STRUCT_FIELD = "CAPNP-ES005 Don't know how to generate a struct field of kind %d.";
const GEN_UNKNOWN_TYPE = "CAPNP-ES006 Unknown slot type encountered: %d";
const GEN_UNSUPPORTED_LIST_ELEMENT_TYPE = "CAPNP-ES007 Encountered an unsupported list element type: %d";
const GEN_TS_EMIT_FAILED = "CAPNP-ES009 Failed to transpile emitted schema source code; see above for error messages.";
const GEN_UNKNOWN_DEFAULT = "CAPNP-ES010 Don't know how to generate a default value for %s fields.";
const ConcreteListType = {
	[Type.ANY_POINTER]: "$.AnyPointerList",
	[Type.BOOL]: "$.BoolList",
	[Type.DATA]: "$.DataList",
	[Type.ENUM]: "$.Uint16List",
	[Type.FLOAT32]: "$.Float32List",
	[Type.FLOAT64]: "$.Float64List",
	[Type.INT16]: "$.Int16List",
	[Type.INT32]: "$.Int32List",
	[Type.INT64]: "$.Int64List",
	[Type.INT8]: "$.Int8List",
	[Type.INTERFACE]: "$.InterfaceList",
	[Type.LIST]: "$.PointerList",
	[Type.STRUCT]: "$.CompositeList",
	[Type.TEXT]: "$.TextList",
	[Type.UINT16]: "$.Uint16List",
	[Type.UINT32]: "$.Uint32List",
	[Type.UINT64]: "$.Uint64List",
	[Type.UINT8]: "$.Uint8List",
	[Type.VOID]: "$.VoidList"
};
const Primitives = {
	[Type.BOOL]: {
		byteLength: 1,
		getter: "getBit",
		mask: "getBitMask",
		setter: "setBit"
	},
	[Type.ENUM]: {
		byteLength: 2,
		getter: "getUint16",
		mask: "getUint16Mask",
		setter: "setUint16"
	},
	[Type.FLOAT32]: {
		byteLength: 4,
		getter: "getFloat32",
		mask: "getFloat32Mask",
		setter: "setFloat32"
	},
	[Type.FLOAT64]: {
		byteLength: 8,
		getter: "getFloat64",
		mask: "getFloat64Mask",
		setter: "setFloat64"
	},
	[Type.INT16]: {
		byteLength: 2,
		getter: "getInt16",
		mask: "getInt16Mask",
		setter: "setInt16"
	},
	[Type.INT32]: {
		byteLength: 4,
		getter: "getInt32",
		mask: "getInt32Mask",
		setter: "setInt32"
	},
	[Type.INT64]: {
		byteLength: 8,
		getter: "getInt64",
		mask: "getInt64Mask",
		setter: "setInt64"
	},
	[Type.INT8]: {
		byteLength: 1,
		getter: "getInt8",
		mask: "getInt8Mask",
		setter: "setInt8"
	},
	[Type.UINT16]: {
		byteLength: 2,
		getter: "getUint16",
		mask: "getUint16Mask",
		setter: "setUint16"
	},
	[Type.UINT32]: {
		byteLength: 4,
		getter: "getUint32",
		mask: "getUint32Mask",
		setter: "setUint32"
	},
	[Type.UINT64]: {
		byteLength: 8,
		getter: "getUint64",
		mask: "getUint64Mask",
		setter: "setUint64"
	},
	[Type.UINT8]: {
		byteLength: 1,
		getter: "getUint8",
		mask: "getUint8Mask",
		setter: "setUint8"
	},
	[Type.VOID]: {
		byteLength: 0,
		getter: "getVoid",
		mask: "getVoidMask",
		setter: "setVoid"
	}
};
const SOURCE_COMMENT = `
/* eslint-disable */
// biome-ignore lint: disable

// Generated by storm-capnpc
// Note: Do not edit this file manually - it will be overwritten automatically

`;
const TS_FILE_ID = "e37ded525a68a7c9";
/**
* A function for converting hex <-> dec w/o loss of precision.
*
* The problem is that parseInt("0x12345...") isn't precise enough to convert
* 64-bit integers correctly.
*
* Internally, this uses arrays to encode decimal digits starting with the least
* significant:
* 8 = [8]
* 16 = [6, 1]
* 1024 = [4, 2, 0, 1]
*
* Source: http://www.danvk.org/hex2dec.html
*/
var hex2dec;
var hasRequiredHex2dec;
function requireHex2dec() {
	if (hasRequiredHex2dec) return hex2dec;
	hasRequiredHex2dec = 1;
	function add(x, y, base) {
		var z = [];
		var n = Math.max(x.length, y.length);
		var carry = 0;
		var i = 0;
		while (i < n || carry) {
			var xi = i < x.length ? x[i] : 0;
			var yi = i < y.length ? y[i] : 0;
			var zi = carry + xi + yi;
			z.push(zi % base);
			carry = Math.floor(zi / base);
			i++;
		}
		return z;
	}
	function multiplyByNumber(num, x, base) {
		if (num < 0) return null;
		if (num == 0) return [];
		var result = [];
		var power = x;
		while (true) {
			if (num & 1) result = add(result, power, base);
			num = num >> 1;
			if (num === 0) break;
			power = add(power, power, base);
		}
		return result;
	}
	function parseToDigitsArray(str, base) {
		var digits = str.split("");
		var ary = [];
		for (var i = digits.length - 1; i >= 0; i--) {
			var n = parseInt(digits[i], base);
			if (isNaN(n)) return null;
			ary.push(n);
		}
		return ary;
	}
	function convertBase(str, fromBase, toBase) {
		var digits = parseToDigitsArray(str, fromBase);
		if (digits === null) return null;
		var outArray = [];
		var power = [1];
		for (var i = 0; i < digits.length; i++) {
			if (digits[i]) outArray = add(outArray, multiplyByNumber(digits[i], power, toBase), toBase);
			power = multiplyByNumber(fromBase, power, toBase);
		}
		var out = "";
		for (var i = outArray.length - 1; i >= 0; i--) out += outArray[i].toString(toBase);
		if (out === "") out = "0";
		return out;
	}
	function decToHex(decStr, opts) {
		var hidePrefix = opts && opts.prefix === false;
		var hex = convertBase(decStr, 10, 16);
		return hex ? hidePrefix ? hex : "0x" + hex : null;
	}
	function hexToDec(hexStr) {
		if (hexStr.substring(0, 2) === "0x") hexStr = hexStr.substring(2);
		hexStr = hexStr.toLowerCase();
		return convertBase(hexStr, 16, 10);
	}
	hex2dec = {
		hexToDec,
		decToHex
	};
	return hex2dec;
}
var hex2decExports = requireHex2dec();
function c2s(s) {
	return splitCamel(s).map((x) => x.toUpperCase()).join("_");
}
function c2t(s) {
	return s[0].toUpperCase() + s.slice(1);
}
function splitCamel(s) {
	let wasLo = false;
	return s.split("").reduce((a, c) => {
		const lo = c.toUpperCase() !== c;
		const up = c.toLowerCase() !== c;
		if (a.length === 0 || wasLo && up) a.push(c);
		else {
			const i = a.length - 1;
			a[i] = a[i] + c;
		}
		wasLo = lo;
		return a;
	}, []);
}
function hexToBigInt(hexString) {
	return BigInt(hex2decExports.hexToDec(hexString));
}
function compareCodeOrder(a, b) {
	return a.codeOrder - b.codeOrder;
}
function getConcreteListType(ctx, type) {
	if (!type._isList) return getJsType(ctx, type, false);
	const { elementType } = type.list;
	const elementTypeWhich = elementType.which();
	if (elementTypeWhich === Type.LIST) return `$.PointerList(${getConcreteListType(ctx, elementType)})`;
	else if (elementTypeWhich === Type.STRUCT) {
		if (lookupNode(ctx, elementType.struct.typeId).struct.preferredListEncoding !== ElementSize.INLINE_COMPOSITE) throw new Error(GEN_FIELD_NON_INLINE_STRUCT_LIST);
		return `$.CompositeList(${getJsType(ctx, elementType, false)})`;
	}
	return ConcreteListType[elementTypeWhich];
}
function getDisplayNamePrefix(node) {
	return node.displayName.slice(node.displayNamePrefixLength);
}
function getFullClassName(node) {
	return node.displayName.split(":")[1].split(".").map((s) => c2t(s)).join("_");
}
function getJsType(ctx, type, constructor) {
	const whichType = type.which();
	switch (whichType) {
		case Type.ANY_POINTER: return "$.Pointer";
		case Type.BOOL: return "boolean";
		case Type.DATA: return "$.Data";
		case Type.ENUM: return getFullClassName(lookupNode(ctx, type.enum.typeId));
		case Type.FLOAT32:
		case Type.FLOAT64:
		case Type.INT16:
		case Type.INT32:
		case Type.INT8:
		case Type.UINT16:
		case Type.UINT32:
		case Type.UINT8: return "number";
		case Type.UINT64:
		case Type.INT64: return "bigint";
		case Type.INTERFACE: return getFullClassName(lookupNode(ctx, type.interface.typeId));
		case Type.LIST: return `$.List${constructor ? "Ctor" : ""}<${getJsType(ctx, type.list.elementType, false)}>`;
		case Type.STRUCT: {
			const c = getFullClassName(lookupNode(ctx, type.struct.typeId));
			return constructor ? `$.StructCtor<${c}>` : c;
		}
		case Type.TEXT: return "string";
		case Type.VOID: return "$.Void";
		default: throw new Error(format(GEN_UNKNOWN_TYPE, whichType));
	}
}
function getUnnamedUnionFields(node) {
	return node.struct.fields.filter((field) => field.discriminantValue !== Field.NO_DISCRIMINANT);
}
function hasNode(ctx, lookup) {
	const id = typeof lookup === "bigint" ? lookup : lookup.id;
	return ctx.nodes.some((n) => n.id === id);
}
function loadRequestedFile(req, file) {
	const ctx = new CodeGeneratorFileContext(req, file);
	ctx.tsPath = lookupNode(ctx, file.id).displayName.replace(/\.capnp$/, "") + ".ts";
	return ctx;
}
function lookupNode(ctx, lookup) {
	const id = typeof lookup === "bigint" ? lookup : lookup.id;
	const node = ctx.nodes.find((n) => n.id === id);
	if (node === void 0) throw new Error(format(GEN_NODE_LOOKUP_FAIL, id));
	return node;
}
function lookupNodeSourceInfo(ctx, lookup) {
	const id = typeof lookup === "bigint" ? lookup : lookup.id;
	return ctx.req.sourceInfo.find((s) => s.id === id);
}
function needsConcreteListClass(field) {
	if (!field._isSlot) return false;
	const slotType = field.slot.type;
	if (!slotType._isList) return false;
	const { elementType } = slotType.list;
	return elementType._isStruct || elementType._isList;
}
function createBigInt(value) {
	let v = value.toString(16);
	let sign = "";
	if (v[0] === "-") {
		v = v.slice(1);
		sign = "-";
	}
	return `${sign}BigInt("0x${v}")`;
}
function extractJSDocs(sourceInfo) {
	const docComment = sourceInfo?.docComment;
	if (!docComment) return "";
	return "/**\n" + docComment.toString().split("\n").map((l) => `* ${l}`).join("\n") + "\n*/";
}
function generateEnumNode(ctx, className, parentNode, fields) {
	const fieldIndexInCodeOrder = fields.map(({ codeOrder }, fieldIndex) => ({
		fieldIndex,
		codeOrder
	})).sort(compareCodeOrder).map(({ fieldIndex }) => fieldIndex);
	const sourceInfo = lookupNodeSourceInfo(ctx, parentNode);
	const propInits = fieldIndexInCodeOrder.map((index) => {
		const field = fields[index];
		return `
      ${extractJSDocs(sourceInfo?.members.at(index))}
      ${c2s(field.name)}: ${field.discriminantValue || index}`;
	});
	ctx.codeParts.push(`
    export const ${className} = {
      ${propInits.join(",\n")}
    } as const;

    export type ${className} = (typeof ${className})[keyof typeof ${className}];
  `);
}
function generateInterfaceClasses(ctx, node) {
	generateMethodStructs(ctx, node);
	generateClient(ctx, node);
	generateServer(ctx, node);
}
function generateMethodStructs(ctx, node) {
	for (const method of node.interface.methods) {
		const paramNode = lookupNode(ctx, method.paramStructType);
		const resultNode = lookupNode(ctx, method.resultStructType);
		generateNode(ctx, paramNode);
		generateNode(ctx, resultNode);
		generateResultPromise(ctx, resultNode);
	}
}
function generateServer(ctx, node) {
	const fullClassName = getFullClassName(node);
	const serverName = `${fullClassName}$Server`;
	const serverTargetName = `${serverName}$Target`;
	const clientName = `${fullClassName}$Client`;
	const methodSignatures = node.interface.methods.map((method) => {
		const paramTypeName = getFullClassName(lookupNode(ctx, method.paramStructType));
		const resultTypeName = getFullClassName(lookupNode(ctx, method.resultStructType));
		return `${method.name}(params: ${paramTypeName}, results: ${resultTypeName}): Promise<void>;`;
	}).join("\n");
	ctx.codeParts.push(`
  export interface ${serverTargetName} {
    ${methodSignatures}
  }`);
	const members = [];
	members.push(`public override readonly target: ${serverTargetName};`);
	const codeServerMethods = [];
	let index = 0;
	for (const method of node.interface.methods) {
		codeServerMethods.push(`{
        ...${clientName}.methods[${index}],
        impl: target.${method.name}
      }`);
		index++;
	}
	members.push(`
      constructor(target: ${serverTargetName}) {
        super(target, [
          ${codeServerMethods.join(",\n")}
        ]);
        this.target = target;
      }
      client(): ${clientName} {
        return new ${clientName}(this);
      }
  `);
	ctx.codeParts.push(`
    export class ${serverName} extends $.Server {
      ${members.join("\n")}
    }
  `);
}
function generateClient(ctx, node) {
	const clientName = `${getFullClassName(node)}$Client`;
	const members = [];
	members.push(`
    client: $.Client;
    static readonly interfaceId: bigint = ${createBigInt(node.id)};
    constructor(client: $.Client) {
      this.client = client;
    }
  `);
	const methods = [];
	const methodDefs = [];
	const methodDefTypes = [];
	for (let index = 0; index < node.interface.methods.length; index++) generateClientMethod(ctx, node, clientName, methods, methodDefs, methodDefTypes, index);
	members.push(`
    static readonly methods:[
      ${methodDefTypes.join(",\n")}
    ] = [
      ${methodDefs.join(",\n")}
    ];
    ${methods.join("\n")}
    `);
	ctx.codeParts.push(`
    export class ${clientName} {
      ${members.join("\n")}
    }
    $.Registry.register(${clientName}.interfaceId, ${clientName});
  `);
}
function generateResultPromise(ctx, node) {
	const nodeId = node.id;
	if (ctx.generatedResultsPromiseIds.has(nodeId)) return;
	ctx.generatedResultsPromiseIds.add(nodeId);
	const resultsClassName = getFullClassName(node);
	const fullClassName = `${resultsClassName}$Promise`;
	const members = [];
	members.push(`
    pipeline: $.Pipeline<any, any, ${resultsClassName}>;
    constructor(pipeline: $.Pipeline<any, any, ${resultsClassName}>) {
      this.pipeline = pipeline;
    }
  `);
	const { struct } = node;
	const fields = struct.fields.toArray().sort(compareCodeOrder);
	const generatePromiseFieldMethod = (field) => {
		let jsType;
		let isInterface = false;
		let slot;
		if (field._isSlot) {
			slot = field.slot;
			const slotType = slot.type;
			if (slotType.which() !== Type.INTERFACE) return;
			isInterface = true;
			jsType = getJsType(ctx, slotType, false);
		} else if (field._isGroup) return;
		else throw new Error(format(GEN_UNKNOWN_STRUCT_FIELD, field.which()));
		const promisedJsType = jsType;
		if (isInterface) jsType = `${jsType}$Client`;
		const { name } = field;
		const properName = c2t(name);
		members.push(`
      get${properName}(): ${jsType} {
        return new ${jsType}(this.pipeline.getPipeline(${promisedJsType}, ${slot.offset}).client());
      }
    `);
	};
	for (const field of fields) generatePromiseFieldMethod(field);
	members.push(`
    async promise(): Promise<${resultsClassName}> {
      return await this.pipeline.struct();
    }
  `);
	ctx.codeParts.push(`
    export class ${fullClassName} {
      ${members.join("\n")}
    }
  `);
}
function generateClientMethod(ctx, node, clientName, methodsCode, methodDefs, methodDefTypes, index) {
	const method = node.interface.methods[index];
	const { name } = method;
	const paramTypeName = getFullClassName(lookupNode(ctx, method.paramStructType));
	const resultTypeName = getFullClassName(lookupNode(ctx, method.resultStructType));
	methodDefTypes.push(`$.Method<${paramTypeName}, ${resultTypeName}>`);
	methodDefs.push(`{
    ParamsClass: ${paramTypeName},
    ResultsClass: ${resultTypeName},
    interfaceId: ${clientName}.interfaceId,
    methodId: ${index},
    interfaceName: "${node.displayName}",
    methodName: "${method.name}"
  }`);
	const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node)?.members.at(index));
	methodsCode.push(`
    ${docComment}
    ${name}(paramsFunc?: (params: ${paramTypeName}) => void): ${resultTypeName}$Promise {
      const answer = this.client.call({
        method: ${clientName}.methods[${index}],
        paramsFunc: paramsFunc
      });
      const pipeline = new $.Pipeline(${resultTypeName}, answer);
      return new ${resultTypeName}$Promise(pipeline);
    }
  `);
}
function generateStructNode(ctx, node) {
	const displayNamePrefix = getDisplayNamePrefix(node);
	const fullClassName = getFullClassName(node);
	const nestedNodes = node.nestedNodes.map(({ id }) => lookupNode(ctx, id)).filter((node2) => !node2._isConst && !node2._isAnnotation);
	const nodeId = node.id;
	const nodeIdHex = nodeId.toString(16);
	const unionFields = getUnnamedUnionFields(node);
	const { struct } = node;
	const { dataWordCount, discriminantCount, discriminantOffset, pointerCount } = struct;
	const dataByteLength = dataWordCount * 8;
	const fields = struct.fields.toArray();
	const fieldIndexInCodeOrder = fields.map(({ codeOrder }, fieldIndex) => ({
		fieldIndex,
		codeOrder
	})).sort(compareCodeOrder).map(({ fieldIndex }) => fieldIndex);
	const concreteLists = fields.filter((field) => needsConcreteListClass(field)).sort(compareCodeOrder);
	const consts = ctx.nodes.filter((node2) => node2.scopeId === nodeId && node2._isConst);
	const hasUnnamedUnion = discriminantCount !== 0;
	if (hasUnnamedUnion) generateEnumNode(ctx, fullClassName + "_Which", node, unionFields);
	const members = [];
	members.push(...consts.map((node2) => {
		return `static readonly ${c2s(getDisplayNamePrefix(node2))} = ${createValue(node2.const.value)}`;
	}), ...unionFields.sort(compareCodeOrder).map((field) => createUnionConstProperty(fullClassName, field)), ...nestedNodes.map((node2) => createNestedNodeProperty(node2)));
	const defaultValues = [];
	for (const index of fieldIndexInCodeOrder) {
		const field = fields[index];
		if (field._isSlot && field.slot.hadExplicitDefault && field.slot.type.which() !== Type.VOID) defaultValues.push(generateDefaultValue(field));
	}
	members.push(`
      public static override readonly _capnp = {
        displayName: "${displayNamePrefix}",
        id: "${nodeIdHex}",
        size: new $.ObjectSize(${dataByteLength}, ${pointerCount}),
        ${defaultValues.join(",")}
      }`, ...concreteLists.map((field) => createConcreteListProperty(ctx, field)));
	for (const index of fieldIndexInCodeOrder) {
		const field = fields[index];
		generateStructFieldMethods(ctx, members, node, field, index);
	}
	members.push(`public override toString(): string { return "${fullClassName}_" + super.toString(); }`);
	if (hasUnnamedUnion) members.push(`
      which(): ${fullClassName}_Which {
        return $.utils.getUint16(${discriminantOffset * 2}, this) as ${fullClassName}_Which;
      }
    `);
	const classCode = `
  ${extractJSDocs(lookupNodeSourceInfo(ctx, node))}
  export class ${fullClassName} extends $.Struct {
    ${members.join("\n")}
  }`;
	ctx.codeParts.push(classCode);
	ctx.concreteLists.push(...concreteLists.map((field) => [fullClassName, field]));
}
function generateStructFieldMethods(ctx, members, node, field, fieldIndex) {
	let jsType;
	let whichType;
	if (field._isSlot) {
		const slotType = field.slot.type;
		jsType = getJsType(ctx, slotType, false);
		whichType = slotType.which();
	} else if (field._isGroup) {
		jsType = getFullClassName(lookupNode(ctx, field.group.typeId));
		whichType = "group";
	} else throw new Error(format(GEN_UNKNOWN_STRUCT_FIELD, field.which()));
	if (whichType === Type.INTERFACE) jsType = `${jsType}$Client`;
	const { discriminantOffset } = node.struct;
	const { name } = field;
	const accessorName = name === "constructor" ? "$constructor" : name;
	const capitalizedName = c2t(name);
	const { discriminantValue } = field;
	const fullClassName = getFullClassName(node);
	const hadExplicitDefault = field._isSlot && field.slot.hadExplicitDefault;
	const maybeDefaultArg = hadExplicitDefault ? `, ${fullClassName}._capnp.default${capitalizedName}` : "";
	const union = discriminantValue !== Field.NO_DISCRIMINANT;
	const offset = field._isSlot ? field.slot.offset : 0;
	let adopt = false;
	let disown = false;
	let has = false;
	let init;
	let get;
	let set;
	switch (whichType) {
		case Type.ANY_POINTER:
			adopt = true;
			disown = true;
			has = true;
			get = `$.utils.getPointer(${offset}, this${maybeDefaultArg})`;
			set = `$.utils.copyFrom(value, ${get})`;
			break;
		case Type.BOOL:
		case Type.ENUM:
		case Type.FLOAT32:
		case Type.FLOAT64:
		case Type.INT16:
		case Type.INT32:
		case Type.INT64:
		case Type.INT8:
		case Type.UINT16:
		case Type.UINT32:
		case Type.UINT64:
		case Type.UINT8: {
			const { byteLength, getter, setter } = Primitives[whichType];
			const byteOffset = offset * byteLength;
			get = `$.utils.${getter}(${byteOffset}, this${maybeDefaultArg})`;
			set = `$.utils.${setter}(${byteOffset}, value, this${maybeDefaultArg})`;
			if (whichType === Type.ENUM) get = `${get} as ${jsType}`;
			break;
		}
		case Type.DATA:
			adopt = true;
			disown = true;
			has = true;
			get = `$.utils.getData(${offset}, this${maybeDefaultArg})`;
			set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
			init = `$.utils.initData(${offset}, length, this)`;
			break;
		case Type.INTERFACE:
			get = `new ${jsType}($.utils.getInterfaceClientOrNullAt(${offset}, this))`;
			set = `$.utils.setInterfacePointer(this.segment.message.addCap(value.client), $.utils.getPointer(${offset}, this))`;
			break;
		case Type.LIST: {
			const elementType = field.slot.type.list.elementType.which();
			let listClass = ConcreteListType[elementType];
			if (elementType === Type.LIST || elementType === Type.STRUCT) listClass = `${fullClassName}._${capitalizedName}`;
			else if (listClass === void 0) throw new Error(format(GEN_UNSUPPORTED_LIST_ELEMENT_TYPE, elementType));
			adopt = true;
			disown = true;
			has = true;
			get = `$.utils.getList(${offset}, ${listClass}, this${maybeDefaultArg})`;
			set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
			init = `$.utils.initList(${offset}, ${listClass}, length, this)`;
			if (elementType === Type.ENUM) {
				get = `${get} as ${jsType}`;
				init = `${init} as ${jsType}`;
			}
			break;
		}
		case Type.STRUCT:
			adopt = true;
			disown = true;
			has = true;
			get = `$.utils.getStruct(${offset}, ${jsType}, this${maybeDefaultArg})`;
			set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
			init = `$.utils.initStructAt(${offset}, ${jsType}, this)`;
			break;
		case Type.TEXT:
			get = `$.utils.getText(${offset}, this${maybeDefaultArg})`;
			set = `$.utils.setText(${offset}, value, this)`;
			break;
		case Type.VOID: break;
		case "group":
			if (hadExplicitDefault) throw new Error(format(GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE, "group"));
			get = `$.utils.getAs(${jsType}, this)`;
			init = get;
			break;
	}
	if (adopt) members.push(`
      _adopt${capitalizedName}(value: $.Orphan<${jsType}>): void {
        ${union ? `$.utils.setUint16(${discriminantOffset * 2}, ${discriminantValue}, this);` : ""}
        $.utils.adopt(value, $.utils.getPointer(${offset}, this));
      }
    `);
	if (disown) members.push(`
      _disown${capitalizedName}(): $.Orphan<${jsType}> {
        return $.utils.disown(this.${name === "constructor" ? `$${name}` : name});
      }
    `);
	if (get) {
		const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node)?.members.at(fieldIndex));
		members.push(`
      ${docComment}
      get ${accessorName}(): ${jsType} {
        ${union ? `$.utils.testWhich(${JSON.stringify(name)}, $.utils.getUint16(${discriminantOffset * 2}, this), ${discriminantValue}, this);` : ""}
        return ${get};
      }
    `);
	}
	if (has) members.push(`
      _has${capitalizedName}(): boolean {
        return !$.utils.isNull($.utils.getPointer(${offset}, this));
      }
    `);
	if (init) {
		const params = whichType === Type.DATA || whichType === Type.LIST ? `length: number` : "";
		members.push(`
      _init${capitalizedName}(${params}): ${jsType} {
        ${union ? `$.utils.setUint16(${discriminantOffset * 2}, ${discriminantValue}, this);` : ""}
        return ${init};
      }
    `);
	}
	if (union) members.push(`
      get _is${capitalizedName}(): boolean {
        return $.utils.getUint16(${discriminantOffset * 2}, this) === ${discriminantValue};
      }
    `);
	if (set || union) {
		const param = set ? `value: ${jsType}` : `_: true`;
		members.push(`
      set ${accessorName}(${param}) {
        ${union ? `$.utils.setUint16(${discriminantOffset * 2}, ${discriminantValue}, this);` : ""}
        ${set ? `${set};` : ""}
      }
    `);
	}
}
function generateDefaultValue(field) {
	const { name, slot } = field;
	const whichSlotType = slot.type.which();
	const primitive = Primitives[whichSlotType];
	let initializer;
	switch (whichSlotType) {
		case Type_Which.ANY_POINTER:
		case Type_Which.DATA:
		case Type_Which.LIST:
		case Type_Which.STRUCT:
		case Type_Which.INTERFACE:
			initializer = createValue(slot.defaultValue);
			break;
		case Type_Which.TEXT:
			initializer = JSON.stringify(slot.defaultValue.text);
			break;
		case Type_Which.BOOL: {
			const value = createValue(slot.defaultValue);
			const bitOffset = slot.offset % 8;
			initializer = `$.${primitive.mask}(${value}, ${bitOffset})`;
			break;
		}
		case Type_Which.ENUM:
		case Type_Which.FLOAT32:
		case Type_Which.FLOAT64:
		case Type_Which.INT16:
		case Type_Which.INT32:
		case Type_Which.INT64:
		case Type_Which.INT8:
		case Type_Which.UINT16:
		case Type_Which.UINT32:
		case Type_Which.UINT64:
		case Type_Which.UINT8: {
			const value = createValue(slot.defaultValue);
			initializer = `$.${primitive.mask}(${value})`;
			break;
		}
		default: throw new Error(format(GEN_UNKNOWN_DEFAULT, whichSlotType));
	}
	return `default${c2t(name)}: ${initializer}`;
}
function createConcreteListProperty(ctx, field) {
	return `static ${`_${c2t(field.name)}`}: ${getJsType(ctx, field.slot.type, true)};`;
}
function createUnionConstProperty(fullClassName, field) {
	const name = c2s(field.name);
	return `static readonly ${name} = ${`${fullClassName}_Which.${name}`};`;
}
function createValue(value) {
	let p;
	switch (value.which()) {
		case Value.BOOL: return value.bool ? `true` : `false`;
		case Value.ENUM: return String(value.enum);
		case Value.FLOAT32: return String(value.float32);
		case Value.FLOAT64: return String(value.float64);
		case Value.INT8: return String(value.int8);
		case Value.INT16: return String(value.int16);
		case Value.INT32: return String(value.int32);
		case Value.INT64: return createBigInt(value.int64);
		case Value.UINT8: return String(value.uint8);
		case Value.UINT16: return String(value.uint16);
		case Value.UINT32: return String(value.uint32);
		case Value.UINT64: return createBigInt(value.uint64);
		case Value.TEXT: return JSON.stringify(value.text);
		case Value.VOID: return "undefined";
		case Value.ANY_POINTER:
			p = value.anyPointer;
			break;
		case Value.DATA:
			p = value.data;
			break;
		case Value.LIST:
			p = value.list;
			break;
		case Value.STRUCT:
			p = value.struct;
			break;
		case Value.INTERFACE:
			testWhich("interface", getUint16(0, value), 17, value);
			p = getPointer(0, value);
			break;
		default: throw new Error(format(GEN_SERIALIZE_UNKNOWN_VALUE, value.which()));
	}
	const message = new Message();
	message.setRoot(p);
	const buf = new Uint8Array(message.toPackedArrayBuffer());
	const values = [];
	for (let i = 0; i < buf.byteLength; i++) values.push(`0x${pad(buf[i].toString(16), 2)}`);
	return `$.readRawPointer(new Uint8Array([${values.join(",")}]).buffer)`;
}
function createNestedNodeProperty(node) {
	return `static readonly ${getDisplayNamePrefix(node)} = ${getFullClassName(node)};`;
}
function generateInterfaceNode(ctx, node) {
	const displayNamePrefix = getDisplayNamePrefix(node);
	const fullClassName = getFullClassName(node);
	const nestedNodes = node.nestedNodes.map((n) => lookupNode(ctx, n)).filter((n) => !n._isConst && !n._isAnnotation);
	const nodeId = node.id;
	const nodeIdHex = nodeId.toString(16);
	const consts = ctx.nodes.filter((n) => n.scopeId === nodeId && n._isConst);
	const members = [];
	members.push(...consts.map((node2) => {
		return `static readonly ${c2s(getDisplayNamePrefix(node2))} = ${createValue(node2.const.value)}`;
	}), ...nestedNodes.map((node2) => createNestedNodeProperty(node2)), `static readonly Client = ${fullClassName}$Client;
     static readonly Server = ${fullClassName}$Server;
     public static override readonly _capnp = {
        displayName: "${displayNamePrefix}",
        id: "${nodeIdHex}",
        size: new $.ObjectSize(0, 0),
      }
    public override toString(): string { return "${fullClassName}_" + super.toString(); }`);
	const classCode = `
  ${extractJSDocs(lookupNodeSourceInfo(ctx, node))}
  export class ${fullClassName} extends $.Interface {
    ${members.join("\n")}
  }`;
	generateInterfaceClasses(ctx, node);
	ctx.codeParts.push(classCode);
}
function generateNode(ctx, node) {
	const nodeId = node.id;
	const nodeIdHex = nodeId.toString(16);
	if (ctx.generatedNodeIds.has(nodeIdHex)) return;
	ctx.generatedNodeIds.add(nodeIdHex);
	const nestedNodes = node.nestedNodes.map((node2) => lookupNode(ctx, node2));
	for (const nestedNode of nestedNodes) generateNode(ctx, nestedNode);
	const groupNodes = ctx.nodes.filter((node2) => node2.scopeId === nodeId && node2._isStruct && node2.struct.isGroup);
	for (const groupNode of groupNodes) generateNode(ctx, groupNode);
	const nodeType = node.which();
	switch (nodeType) {
		case Node.STRUCT:
			generateStructNode(ctx, node);
			break;
		case Node.CONST: break;
		case Node.ENUM:
			generateEnumNode(ctx, getFullClassName(node), node, node.enum.enumerants.toArray());
			break;
		case Node.INTERFACE:
			generateInterfaceNode(ctx, node);
			break;
		case Node.ANNOTATION: break;
		default: throw new Error(format(GEN_NODE_UNKNOWN_TYPE, nodeType));
	}
}
var CodeGeneratorContext = class {
	files = [];
};
var CodeGeneratorFileContext = class {
	constructor(req, file) {
		this.req = req;
		this.file = file;
		this.nodes = req.nodes.toArray();
		this.imports = file.imports.toArray();
	}
	nodes;
	imports;
	concreteLists = [];
	generatedNodeIds = /* @__PURE__ */ new Set();
	generatedResultsPromiseIds = /* @__PURE__ */ new Set();
	tsPath = "";
	codeParts = [];
	toString() {
		return this.file?.filename ?? "CodeGeneratorFileContext()";
	}
};
function generateFileId(ctx) {
	ctx.codeParts.push(`export const _capnpFileId = BigInt("0x${ctx.file.id.toString(16)}");`);
}
function generateConcreteListInitializer(ctx, fullClassName, field) {
	const name = `_${c2t(field.name)}`;
	const type = getConcreteListType(ctx, field.slot.type);
	ctx.codeParts.push(`${fullClassName}.${name} = ${type};`);
}
function generateCapnpImport(ctx) {
	const fileNode = lookupNode(ctx, ctx.file);
	const tsFileId = hexToBigInt(TS_FILE_ID);
	const tsImportPathAnnotation = ctx.nodes.find((n) => n.id === tsFileId)?.nestedNodes.find((n) => n.name === "importPath");
	const importAnnotation = tsImportPathAnnotation && fileNode.annotations.find((a) => a.id === tsImportPathAnnotation.id);
	const importPath = importAnnotation === void 0 ? "@stryke/capnp" : importAnnotation.value.text;
	ctx.codeParts.push(`import * as $ from '${importPath}';`);
}
function generateNestedImports(ctx) {
	for (const imp of ctx.imports) {
		const { name } = imp;
		let importPath;
		if (name.startsWith("/capnp/")) importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
		else {
			importPath = name.replace(/\.capnp$/, "");
			if (importPath[0] !== ".") importPath = `./${importPath}`;
		}
		const imports = getImportNodes(ctx, lookupNode(ctx, imp)).flatMap((node) => {
			const fullClassName = getFullClassName(node);
			if (node._isInterface) return [fullClassName, `${fullClassName}$Client`];
			return fullClassName;
		}).sort().join(", ");
		if (imports.length === 0) continue;
		ctx.codeParts.push(`import { ${imports} } from "${importPath}";`);
	}
}
function getImportNodes(ctx, node, visitedIds = /* @__PURE__ */ new Set()) {
	visitedIds.add(node.id);
	const nodes = node.nestedNodes.filter(({ id }) => hasNode(ctx, id)).filter(({ id }) => !visitedIds.has(id)).map(({ id }) => lookupNode(ctx, id)).filter((node2) => node2._isStruct || node2._isEnum || node2._isInterface);
	return nodes.concat(nodes.flatMap((node2) => getImportNodes(ctx, node2, visitedIds)));
}
async function compileAll(codeGenRequest, opts) {
	const req = new Message(codeGenRequest, false).getRoot(CodeGeneratorRequest);
	const ctx = new CodeGeneratorContext();
	ctx.files = req.requestedFiles.map((file) => loadRequestedFile(req, file));
	if (ctx.files.length === 0) throw new Error(GEN_NO_FILES);
	const files = new Map(ctx.files.map((file) => [file.tsPath, compileFile(file)]));
	if (files.size === 0) throw new Error(GEN_NO_FILES);
	if (opts?.dts === true || opts?.js === true) tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);
	if (!opts?.ts) {
		for (const [fileName] of files) if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) files.delete(fileName);
	}
	return {
		ctx,
		files
	};
}
function compileFile(ctx) {
	generateCapnpImport(ctx);
	generateNestedImports(ctx);
	generateFileId(ctx);
	const nestedNodes = lookupNode(ctx, ctx.file).nestedNodes.map((n) => lookupNode(ctx, n));
	for (const node of nestedNodes) generateNode(ctx, node);
	for (const [fullClassName, field] of ctx.concreteLists) generateConcreteListInitializer(ctx, fullClassName, field);
	const sourceFile = ts.createSourceFile(ctx.tsPath, ctx.codeParts.map((p) => p.toString()).join(""), ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
	return SOURCE_COMMENT + ts.createPrinter().printFile(sourceFile);
}
function tsCompile(files, dts, js, tsconfig) {
	if (!dts && !js) return;
	const compileOptions = {
		moduleResolution: ts.ModuleResolutionKind.Bundler,
		target: ts.ScriptTarget.ESNext,
		strict: true,
		...tsconfig,
		noEmitOnError: false,
		noFallthroughCasesInSwitch: true,
		preserveConstEnums: true,
		noImplicitReturns: true,
		noUnusedLocals: false,
		noUnusedParameters: false,
		removeComments: false,
		skipLibCheck: true,
		sourceMap: false,
		emitDeclarationOnly: dts && !js,
		declaration: dts
	};
	const compilerHost = ts.createCompilerHost(compileOptions);
	compilerHost.writeFile = (fileName, declaration) => {
		files.set(fileName, declaration);
	};
	const _readFile = compilerHost.readFile;
	compilerHost.readFile = (filename) => {
		if (files.has(filename)) return files.get(filename);
		return _readFile(filename);
	};
	const program = ts.createProgram([...files.keys()], compileOptions, compilerHost);
	const emitResult = program.emit();
	const allDiagnostics = [...ts.getPreEmitDiagnostics(program), ...emitResult.diagnostics];
	if (allDiagnostics.length > 0) {
		for (const diagnostic of allDiagnostics) {
			const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
			if (diagnostic.file && diagnostic.start) {
				const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
				console.log(`${diagnostic.file.fileName}:${line + 1}:${character + 1} ${message}`);
			} else console.log(`==> ${message}`);
		}
		throw new Error(GEN_TS_EMIT_FAILED);
	}
}

//#endregion
//#region src/compile.ts
/**
* Compiles Cap'n Proto schemas into TypeScript files.
*
* @param options - The options for the compilation process.
* @returns A promise that resolves to the compilation result.
*/
async function capnpc(options) {
	const { output, tsconfig, schemas = [], tty } = options;
	let dataBuf = Buffer.alloc(0);
	if (tty) {
		const chunks = [];
		process.stdin.on("data", (chunk) => {
			chunks.push(chunk);
		});
		await new Promise((resolve) => {
			process.stdin.on("end", resolve);
		});
		const reqBuffer = Buffer.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
		let i = 0;
		for (const chunk of chunks) {
			chunk.copy(reqBuffer, i);
			i += chunk.byteLength;
		}
		dataBuf = reqBuffer;
	}
	if (dataBuf.byteLength === 0) {
		const opts = [];
		if (output && existsSync(output)) opts.push(`-o-:${output}`);
		else {
			if (output && !existsSync(output)) writeWarning(`Output directory "${output}" does not exist, will write to schema path...`);
			opts.push("-o-");
		}
		dataBuf = await new Promise((resolve) => {
			exec(`capnpc ${opts.join(" ")} ${schemas.join(" ")}`, { encoding: "buffer" }, (error, stdout, stderr) => {
				if (stderr.length > 0) process.stderr.write(stderr);
				if (error) throw error;
				resolve(stdout);
			});
		});
	}
	return compileAll(dataBuf, {
		ts: options.ts ?? true,
		js: false,
		dts: false,
		tsconfig: tsconfig.options
	});
}
/**
* Compiles Cap'n Proto schemas into TypeScript files.
*
* @param dataBuf - The buffer containing the Cap'n Proto schema data.
* @param options - The options for the compilation process.
* @returns A promise that resolves to the compilation result.
*/
async function compile(dataBuf, options) {
	const resolvedOptions = await resolveOptions(options);
	if (!resolvedOptions) {
		writeWarning("✖ Unable to resolve Cap'n Proto compiler options - the program will terminate", { logLevel: "all" });
		return;
	}
	return compileAll(dataBuf, defu({ tsconfig: resolvedOptions.tsconfig.options }, resolvedOptions, {
		ts: true,
		js: false,
		dts: false
	}));
}

//#endregion
export { compile as n, capnpc as t };
//# sourceMappingURL=compile-C4mWgxdv.mjs.map