Skip to content

Commit

Permalink
wip: up
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Oct 29, 2024
1 parent 9df3f30 commit 656dc3b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 47 deletions.
1 change: 1 addition & 0 deletions scripts/docgen/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ for (const namespace of namespaces) {
const id = getId(member)
const data = dataLookup[id]
if (!data) throw new Error(`Could not find data for ${id}`)
// if (!id.includes('TransactionEnvelopeEip1559.getSignPayload')) continue

const { description, displayName } = data
const displayNameWithNamespace =
Expand Down
13 changes: 7 additions & 6 deletions scripts/docgen/render/apiFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function renderParameters(options: {

const link = getTypeLink({ dataLookup, type: parameter })

const c = `\`${type}\``
const c = `\`${type}\``.replace(/(<.*>)/, '')
const listContent = link
? [`- **Type:** [${c}](${link})`]
: [`- **Type:** ${c}`]
Expand Down Expand Up @@ -214,7 +214,10 @@ function renderProperties(options: {
const comment = property.getJsDocs().at(0)?.getDescription()
const tsDoc = getTsDoc(comment, apiItem)

if (type) content.push(`- **Type:** \`${type.replaceAll('`', '')}\``)
if (type)
content.push(
`- **Type:** \`${type.replaceAll('`', '').replace(/(<.*>)/, '')}\``,
)
if (tsDoc?.default) content.push(`- **Default:** \`${tsDoc.default}\``)
const questionToken = property.getQuestionTokenNode()
if (questionToken) content.push('- **Optional**')
Expand Down Expand Up @@ -398,10 +401,8 @@ function resolveErrorData(options: {
}

function extractParameterDeclarations(data: Data) {
const functionNameMatch = data.excerpt.match(
/export( declare)? function (.*?)(\(|<)/,
)
const functionName = functionNameMatch?.[2]
const functionNameMatch = data.excerpt.match(/function (.*?)(\(|<)/)
const functionName = functionNameMatch?.[1]
const file = project.addSourceFileAtPath(data.file.path!)
const declaration = file
.getDescendantsOfKind(ts.SyntaxKind.FunctionDeclaration)
Expand Down
35 changes: 19 additions & 16 deletions src/Bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export namespace Bytes {
*/
export function fromBoolean(
value: boolean,
options: fromBoolean.Options = {},
options: Bytes.fromBoolean.Options = {},
) {
const { size } = options
const bytes = new Uint8Array(1)
Expand Down Expand Up @@ -240,7 +240,10 @@ export namespace Bytes {
* @param options - Encoding options.
* @returns Encoded {@link ox#(Bytes:namespace).(Bytes:type)}.
*/
export function fromHex(value: Hex, options: fromHex.Options = {}): Bytes {
export function fromHex(
value: Hex,
options: Bytes.fromHex.Options = {},
): Bytes {
const { size } = options

if (value.length % 2) throw new Hex.InvalidLengthError(value)
Expand Down Expand Up @@ -309,7 +312,7 @@ export namespace Bytes {
*/
export function fromNumber(
value: bigint | number,
options?: fromNumber.Options | undefined,
options?: Bytes.fromNumber.Options | undefined,
) {
const hex = Hex.fromNumber(value, options)
return Bytes.fromHex(hex)
Expand Down Expand Up @@ -353,7 +356,7 @@ export namespace Bytes {
*/
export function fromString(
value: string,
options: fromString.Options = {},
options: Bytes.fromString.Options = {},
): Bytes {
const { size } = options

Expand Down Expand Up @@ -428,7 +431,7 @@ export namespace Bytes {
export function padLeft(
value: Bytes,
size?: number | undefined,
): padLeft.ReturnType {
): Bytes.padLeft.ReturnType {
return Bytes.pad(value, { dir: 'left', size })
}

Expand Down Expand Up @@ -458,7 +461,7 @@ export namespace Bytes {
export function padRight(
value: Bytes,
size?: number | undefined,
): padRight.ReturnType {
): Bytes.padRight.ReturnType {
return Bytes.pad(value, { dir: 'right', size })
}

Expand Down Expand Up @@ -545,7 +548,7 @@ export namespace Bytes {
value: Bytes,
start?: number | undefined,
end?: number | undefined,
options: slice.Options = {},
options: Bytes.slice.Options = {},
): Bytes {
const { strict } = options
Bytes.assertStartOffset(value, start)
Expand Down Expand Up @@ -586,7 +589,7 @@ export namespace Bytes {
*/
export function toBigInt(
bytes: Bytes,
options: toBigInt.Options = {},
options: Bytes.toBigInt.Options = {},
): bigint {
const { size } = options
if (typeof size !== 'undefined') Bytes.assertSize(bytes, size)
Expand Down Expand Up @@ -629,7 +632,7 @@ export namespace Bytes {
*/
export function toBoolean(
bytes: Bytes,
options: toBoolean.Options = {},
options: Bytes.toBoolean.Options = {},
): boolean {
const { size } = options
let bytes_ = bytes
Expand Down Expand Up @@ -673,7 +676,7 @@ export namespace Bytes {
* @param options - Options.
* @returns Decoded {@link ox#(Hex:type)} value.
*/
export function toHex(value: Bytes, options: toHex.Options = {}): Hex {
export function toHex(value: Bytes, options: Bytes.toHex.Options = {}): Hex {
return Hex.fromBytes(value, options)
}

Expand Down Expand Up @@ -702,7 +705,7 @@ export namespace Bytes {
*/
export function toNumber(
bytes: Bytes,
options: toNumber.Options = {},
options: Bytes.toNumber.Options = {},
): number {
const { size } = options
if (typeof size !== 'undefined') Bytes.assertSize(bytes, size)
Expand Down Expand Up @@ -745,7 +748,7 @@ export namespace Bytes {
*/
export function toString(
bytes: Bytes,
options: toString.Options = {},
options: Bytes.toString.Options = {},
): string {
const { size } = options

Expand Down Expand Up @@ -1077,7 +1080,7 @@ export namespace Bytes {
}

/** @internal */
export function pad(bytes: Bytes, options: pad.Options = {}) {
export function pad(bytes: Bytes, options: Bytes.pad.Options = {}) {
const { dir, size = 32 } = options
if (size === 0) return bytes
if (bytes.length > size)
Expand Down Expand Up @@ -1109,8 +1112,8 @@ export namespace Bytes {
/** @internal */
export function trim(
value: Bytes,
options: trim.Options = {},
): trim.ReturnType {
options: Bytes.trim.Options = {},
): Bytes.trim.ReturnType {
const { dir = 'left' } = options

let data = value
Expand All @@ -1126,7 +1129,7 @@ export namespace Bytes {
? data.slice(sliceLength)
: data.slice(0, data.length - sliceLength)

return data as trim.ReturnType
return data as Bytes.trim.ReturnType
}

/** @internal */
Expand Down
39 changes: 24 additions & 15 deletions src/Hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export namespace Hex {
*/
export function assert(
value: unknown,
options: assert.Options = {},
options: Hex.assert.Options = {},
): asserts value is Hex {
const { strict = true } = options
if (!value) throw new Hex.InvalidHexTypeError(value)
Expand Down Expand Up @@ -203,7 +203,7 @@ export namespace Hex {
*/
export function fromBytes(
value: Bytes,
options: fromBytes.Options = {},
options: Hex.fromBytes.Options = {},
): Hex {
let string = ''
for (let i = 0; i < value.length; i++) string += hexes[value[i]!]
Expand Down Expand Up @@ -251,7 +251,7 @@ export namespace Hex {
*/
export function fromNumber(
value: number | bigint,
options: fromNumber.Options = {},
options: Hex.fromNumber.Options = {},
): Hex {
const { signed, size } = options

Expand Down Expand Up @@ -331,7 +331,7 @@ export namespace Hex {
*/
export function fromString(
value: string,
options: fromString.Options = {},
options: Hex.fromString.Options = {},
): Hex {
return Hex.fromBytes(encoder.encode(value), options)
}
Expand Down Expand Up @@ -396,7 +396,7 @@ export namespace Hex {
export function padLeft(
value: Hex,
size?: number | undefined,
): padLeft.ReturnType {
): Hex.padLeft.ReturnType {
return pad(value, { dir: 'left', size })
}

Expand Down Expand Up @@ -426,7 +426,7 @@ export namespace Hex {
export function padRight(
value: Hex,
size?: number | undefined,
): padRight.ReturnType {
): Hex.padRight.ReturnType {
return pad(value, { dir: 'right', size })
}

Expand Down Expand Up @@ -483,7 +483,7 @@ export namespace Hex {
value: Hex,
start?: number | undefined,
end?: number | undefined,
options: slice.Options = {},
options: Hex.slice.Options = {},
): Hex {
const { strict } = options
assertStartOffset(value, start)
Expand Down Expand Up @@ -548,7 +548,7 @@ export namespace Hex {
* @param value - The {@link ox#(Hex:type)} value to trim.
* @returns The trimmed {@link ox#(Hex:type)} value.
*/
export function trimLeft(value: Hex): trimLeft.ReturnType {
export function trimLeft(value: Hex): Hex.trimLeft.ReturnType {
return trim(value, { dir: 'left' })
}

Expand All @@ -575,7 +575,7 @@ export namespace Hex {
* @param value - The {@link ox#(Hex:type)} value to trim.
* @returns The trimmed {@link ox#(Hex:type)} value.
*/
export function trimRight(value: Hex): trimRight.ReturnType {
export function trimRight(value: Hex): Hex.trimRight.ReturnType {
return trim(value, { dir: 'right' })
}

Expand Down Expand Up @@ -606,7 +606,10 @@ export namespace Hex {
* @param options - Options.
* @returns The decoded BigInt.
*/
export function toBigInt(hex: Hex, options: toBigInt.Options = {}): bigint {
export function toBigInt(
hex: Hex,
options: Hex.toBigInt.Options = {},
): bigint {
const { signed } = options

if (options.size) Hex.assertSize(hex, options.size)
Expand Down Expand Up @@ -657,7 +660,7 @@ export namespace Hex {
*/
export function toBoolean(
hex: Hex,
options: toBoolean.Options = {},
options: Hex.toBoolean.Options = {},
): boolean {
let hex_ = hex
if (options.size) {
Expand Down Expand Up @@ -700,7 +703,7 @@ export namespace Hex {
* @param options - Options.
* @returns The decoded {@link ox#(Bytes:namespace).(Bytes:type)}.
*/
export function toBytes(hex: Hex, options: toBytes.Options = {}): Bytes {
export function toBytes(hex: Hex, options: Hex.toBytes.Options = {}): Bytes {
return Bytes.fromHex(hex, options)
}

Expand Down Expand Up @@ -734,7 +737,10 @@ export namespace Hex {
* @param options - Options.
* @returns The decoded number.
*/
export function toNumber(hex: Hex, options: toNumber.Options = {}): number {
export function toNumber(
hex: Hex,
options: Hex.toNumber.Options = {},
): number {
const { signed, size } = options
if (!signed && !size) return Number(hex)
return Number(Hex.toBigInt(hex, options))
Expand Down Expand Up @@ -769,7 +775,10 @@ export namespace Hex {
* @param options - Options.
* @returns The decoded string.
*/
export function toString(hex: Hex, options: toString.Options = {}): string {
export function toString(
hex: Hex,
options: Hex.toString.Options = {},
): string {
const { size } = options

let bytes = Bytes.fromHex(hex)
Expand Down Expand Up @@ -816,7 +825,7 @@ export namespace Hex {
*/
export function validate(
value: unknown,
options: validate.Options = {},
options: Hex.validate.Options = {},
): value is Hex {
const { strict = true } = options
try {
Expand Down
12 changes: 6 additions & 6 deletions src/TransactionEnvelopeEip1559.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ export namespace TransactionEnvelopeEip1559 {
| envelope
| UnionPartialBy<TransactionEnvelopeEip1559, 'type'>
| TransactionEnvelopeEip1559.Serialized,
options: from.Options<signature> = {},
): from.ReturnType<envelope, signature> {
options: TransactionEnvelopeEip1559.from.Options<signature> = {},
): TransactionEnvelopeEip1559.from.ReturnType<envelope, signature> {
const { signature } = options

const envelope_ = (
Expand Down Expand Up @@ -379,7 +379,7 @@ export namespace TransactionEnvelopeEip1559 {
*/
export function getSignPayload(
envelope: TransactionEnvelopeEip1559,
): getSignPayload.ReturnType {
): TransactionEnvelopeEip1559.getSignPayload.ReturnType {
return TransactionEnvelopeEip1559.hash(envelope, { presign: true })
}

Expand Down Expand Up @@ -427,8 +427,8 @@ export namespace TransactionEnvelopeEip1559 {
*/
export function hash<presign extends boolean = false>(
envelope: TransactionEnvelopeEip1559<presign extends true ? false : true>,
options: hash.Options<presign> = {},
): hash.ReturnType {
options: TransactionEnvelopeEip1559.hash.Options<presign> = {},
): TransactionEnvelopeEip1559.hash.ReturnType {
const { presign } = options
return Hash_keccak256(
TransactionEnvelopeEip1559.serialize({
Expand Down Expand Up @@ -515,7 +515,7 @@ export namespace TransactionEnvelopeEip1559 {
*/
export function serialize(
envelope: PartialBy<TransactionEnvelopeEip1559, 'type'>,
options: serialize.Options = {},
options: TransactionEnvelopeEip1559.serialize.Options = {},
): TransactionEnvelopeEip1559.Serialized {
const {
chainId,
Expand Down
8 changes: 4 additions & 4 deletions src/TransactionEnvelopeLegacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export namespace TransactionEnvelopeLegacy {
*/
export function getSignPayload(
envelope: TransactionEnvelopeLegacy<false>,
): getSignPayload.ReturnType {
): TransactionEnvelopeLegacy.getSignPayload.ReturnType {
return TransactionEnvelopeLegacy.hash(envelope, { presign: true })
}

Expand Down Expand Up @@ -416,8 +416,8 @@ export namespace TransactionEnvelopeLegacy {
*/
export function hash<presign extends boolean = false>(
envelope: TransactionEnvelopeLegacy<presign extends true ? false : true>,
options: hash.Options<presign> = {},
): hash.ReturnType {
options: TransactionEnvelopeLegacy.hash.Options<presign> = {},
): TransactionEnvelopeLegacy.hash.ReturnType {
const { presign } = options
return Hash_keccak256(
TransactionEnvelopeLegacy.serialize({
Expand Down Expand Up @@ -504,7 +504,7 @@ export namespace TransactionEnvelopeLegacy {
*/
export function serialize(
envelope: PartialBy<TransactionEnvelopeLegacy, 'type'>,
options: serialize.Options = {},
options: TransactionEnvelopeLegacy.serialize.Options = {},
): TransactionEnvelopeLegacy.Serialized {
const {
chainId = 0,
Expand Down

0 comments on commit 656dc3b

Please sign in to comment.