Skip to content

Commit

Permalink
chore: revert declaration merging of types
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Oct 30, 2024
1 parent fdf97c9 commit 2804f77
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 28 deletions.
4 changes: 1 addition & 3 deletions scripts/docgen/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ 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 =
name === displayName ? displayName : `${name}.${displayName}`
const displayNameWithNamespace = `${name}.${displayName}`

if (member.kind === model.ApiItemKind.Function) {
// Resolve overloads for function
Expand Down
36 changes: 28 additions & 8 deletions scripts/docgen/render/apiFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ function renderReturnType(options: {
const content = ['## Return Type']
if (comment) content.push(comment)
const link = getTypeLink({ dataLookup, type: returnType })
const c = `\`${returnType.type}\``
const type = expandInlineType({ dataLookup, type: returnType })
const c = `\`${type}\``
content.push(link ? `[${c}](${link})` : c)

return content.join('\n\n')
Expand Down Expand Up @@ -306,9 +307,9 @@ function renderErrors(options: {
for (const errorId of errorIds) {
const errorData = dataLookup[errorId]
if (!errorData) continue
const name = errorData.module + '.' + errorData.displayName
const name = errorData.displayName.replace('_', '.')
errorsContent.push(
`- [\`${name}\`](/api/${errorData.module}/errors#${name.toLowerCase().replace('.', '')})`,
`- [\`${name}\`](/api/${name.split('.')[0]}/errors#${name.toLowerCase().replace('.', '')})`,
)
}
content.push(errorsContent.join('\n'))
Expand Down Expand Up @@ -340,7 +341,7 @@ function resolveInlineParameterTypeForOverloads(options: {
)
}

return parameter.type
return expandInlineType({ dataLookup, type: parameter })
}

function resolveReturnTypeForOverloads(options: {
Expand Down Expand Up @@ -461,9 +462,28 @@ function getTypeLink(options: {
})()
if (!data) return

const displayNameWithNamespace = (() => {
if (data.module === data.displayName) return data.displayName
return `${data.module}.${data.displayName}`
})()
const displayNameWithNamespace = `${data.module}.${data.displayName}`
return `/api/${data.module}/types#${displayNameWithNamespace.toLowerCase().replace('.', '')}`
}

function expandInlineType(options: {
dataLookup: Record<string, Data>
type: Pick<
NonNullable<Data['returnType']>,
'primaryCanonicalReference' | 'primaryGenericArguments' | 'type'
>
}) {
const { dataLookup, type } = options
// expand inline type to include namespace (e.g. `Address` => `Address.Address`)
const expandRegex = /^ox!(?<type>.+)(_2):type/
if (
type.primaryCanonicalReference &&
expandRegex.test(type.primaryCanonicalReference) &&
!type.primaryGenericArguments
) {
const groups =
type.primaryCanonicalReference.match(expandRegex)?.groups ?? {}
if (groups.type) return groups.type
} else if (dataLookup[`ox!${type.type}:type`]) return type.type
return type.type
}
10 changes: 3 additions & 7 deletions scripts/docgen/render/apiNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,9 @@ export function renderNamespaceTypes(options: {
const data = dataLookup[id]
if (!data) throw new Error(`Could not find type data for ${id}`)

const name = (() => {
if (apiItem.parent?.displayName === data.displayName)
return data.displayName
if (apiItem.parent?.displayName)
return `${apiItem.parent.displayName}.${data.displayName}`
return data.displayName
})()
const name = apiItem.parent?.displayName
? `${apiItem.parent.displayName}.${data.displayName}`
: data.displayName

content.push(`## \`${name}\``)
content.push(data.comment?.summary ?? '')
Expand Down
8 changes: 3 additions & 5 deletions scripts/docgen/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,9 @@ export function createResolveDeclarationReference(
if (item) {
const url = getLinkForApiItem(item)
const namespaceName = item.parent?.displayName
const text = (() => {
if (namespaceName === item.displayName) return item.displayName
if (namespaceName) return `${namespaceName}.${item.displayName}`
return item.displayName
})()
const text = namespaceName
? `${namespaceName}.${item.displayName}`
: item.displayName
return { url, text }
}

Expand Down
2 changes: 1 addition & 1 deletion src/TransactionEip1559.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type {
TransactionEip1559 as Transaction,
TransactionEip1559,
TransactionEip1559_Rpc as Rpc,
TransactionEip1559_Type as Type,
TransactionEip1559_TypeRpc as TypeRpc,
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionEip2930.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type {
TransactionEip2930 as Transaction,
TransactionEip2930,
TransactionEip2930_Rpc as Rpc,
TransactionEip2930_Type as Type,
TransactionEip2930_TypeRpc as TypeRpc,
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionEip4844.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type {
TransactionEip4844 as Transaction,
TransactionEip4844,
TransactionEip4844_Rpc as Rpc,
TransactionEip4844_Type as Type,
TransactionEip4844_TypeRpc as TypeRpc,
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionEip7702.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type {
TransactionEip7702 as Transaction,
TransactionEip7702,
TransactionEip7702_Rpc as Rpc,
TransactionEip7702_Type as Type,
TransactionEip7702_TypeRpc as TypeRpc,
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionLegacy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type {
TransactionLegacy as Transaction,
TransactionLegacy,
TransactionLegacy_Rpc as Rpc,
TransactionLegacy_Type as Type,
TransactionLegacy_TypeRpc as TypeRpc,
Expand Down

0 comments on commit 2804f77

Please sign in to comment.