From 2804f7744fba6e60b4a04c78e530ddc74ebe6df8 Mon Sep 17 00:00:00 2001 From: jxom Date: Wed, 30 Oct 2024 11:41:45 +1100 Subject: [PATCH] chore: revert declaration merging of types --- scripts/docgen/build.ts | 4 +-- scripts/docgen/render/apiFunction.ts | 36 +++++++++++++++++++++------ scripts/docgen/render/apiNamespace.ts | 10 +++----- scripts/docgen/utils/model.ts | 8 +++--- src/TransactionEip1559.ts | 2 +- src/TransactionEip2930.ts | 2 +- src/TransactionEip4844.ts | 2 +- src/TransactionEip7702.ts | 2 +- src/TransactionLegacy.ts | 2 +- 9 files changed, 40 insertions(+), 28 deletions(-) diff --git a/scripts/docgen/build.ts b/scripts/docgen/build.ts index efc1797b..7be90f86 100644 --- a/scripts/docgen/build.ts +++ b/scripts/docgen/build.ts @@ -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 diff --git a/scripts/docgen/render/apiFunction.ts b/scripts/docgen/render/apiFunction.ts index cc83c3a3..c30f2da9 100644 --- a/scripts/docgen/render/apiFunction.ts +++ b/scripts/docgen/render/apiFunction.ts @@ -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') @@ -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')) @@ -340,7 +341,7 @@ function resolveInlineParameterTypeForOverloads(options: { ) } - return parameter.type + return expandInlineType({ dataLookup, type: parameter }) } function resolveReturnTypeForOverloads(options: { @@ -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 + type: Pick< + NonNullable, + 'primaryCanonicalReference' | 'primaryGenericArguments' | 'type' + > +}) { + const { dataLookup, type } = options + // expand inline type to include namespace (e.g. `Address` => `Address.Address`) + const expandRegex = /^ox!(?.+)(_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 +} diff --git a/scripts/docgen/render/apiNamespace.ts b/scripts/docgen/render/apiNamespace.ts index 06713fa4..08333ba5 100644 --- a/scripts/docgen/render/apiNamespace.ts +++ b/scripts/docgen/render/apiNamespace.ts @@ -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 ?? '') diff --git a/scripts/docgen/utils/model.ts b/scripts/docgen/utils/model.ts index d8693c17..0036d85c 100644 --- a/scripts/docgen/utils/model.ts +++ b/scripts/docgen/utils/model.ts @@ -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 } } diff --git a/src/TransactionEip1559.ts b/src/TransactionEip1559.ts index 421a31ca..ac4d8c07 100644 --- a/src/TransactionEip1559.ts +++ b/src/TransactionEip1559.ts @@ -1,5 +1,5 @@ export type { - TransactionEip1559 as Transaction, + TransactionEip1559, TransactionEip1559_Rpc as Rpc, TransactionEip1559_Type as Type, TransactionEip1559_TypeRpc as TypeRpc, diff --git a/src/TransactionEip2930.ts b/src/TransactionEip2930.ts index a1d0a439..14ed2dd0 100644 --- a/src/TransactionEip2930.ts +++ b/src/TransactionEip2930.ts @@ -1,5 +1,5 @@ export type { - TransactionEip2930 as Transaction, + TransactionEip2930, TransactionEip2930_Rpc as Rpc, TransactionEip2930_Type as Type, TransactionEip2930_TypeRpc as TypeRpc, diff --git a/src/TransactionEip4844.ts b/src/TransactionEip4844.ts index efe819d2..56b3559c 100644 --- a/src/TransactionEip4844.ts +++ b/src/TransactionEip4844.ts @@ -1,5 +1,5 @@ export type { - TransactionEip4844 as Transaction, + TransactionEip4844, TransactionEip4844_Rpc as Rpc, TransactionEip4844_Type as Type, TransactionEip4844_TypeRpc as TypeRpc, diff --git a/src/TransactionEip7702.ts b/src/TransactionEip7702.ts index fd58f4ea..30403447 100644 --- a/src/TransactionEip7702.ts +++ b/src/TransactionEip7702.ts @@ -1,5 +1,5 @@ export type { - TransactionEip7702 as Transaction, + TransactionEip7702, TransactionEip7702_Rpc as Rpc, TransactionEip7702_Type as Type, TransactionEip7702_TypeRpc as TypeRpc, diff --git a/src/TransactionLegacy.ts b/src/TransactionLegacy.ts index 74e2f4ab..9c213cda 100644 --- a/src/TransactionLegacy.ts +++ b/src/TransactionLegacy.ts @@ -1,5 +1,5 @@ export type { - TransactionLegacy as Transaction, + TransactionLegacy, TransactionLegacy_Rpc as Rpc, TransactionLegacy_Type as Type, TransactionLegacy_TypeRpc as TypeRpc,