From 20be64e799fa31b4de253bd6fa88aa2a8632c177 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 4 Jul 2024 17:35:24 +0300 Subject: [PATCH] docs-util: normalize primary key types in DML (#7941) --- .../src/dml-types-normalizer.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/www/utils/packages/typedoc-plugin-custom/src/dml-types-normalizer.ts b/www/utils/packages/typedoc-plugin-custom/src/dml-types-normalizer.ts index 1e4a66ed40..7a2c65c8ac 100644 --- a/www/utils/packages/typedoc-plugin-custom/src/dml-types-normalizer.ts +++ b/www/utils/packages/typedoc-plugin-custom/src/dml-types-normalizer.ts @@ -19,6 +19,7 @@ export function load(app: Application) { Converter.EVENT_CREATE_DECLARATION, (_context: Context, reflection: DeclarationReflection) => { normalizeNullable(reflection) + normalizePrimary(reflection) }, 2 ) @@ -29,7 +30,7 @@ function normalizeNullable(reflection: DeclarationReflection) { reflection.type?.type !== "reference" || reflection.type.name !== "NullableModifier" || !reflection.type.typeArguments || - reflection.type.typeArguments?.length < 2 + reflection.type.typeArguments.length < 2 ) { return } @@ -45,3 +46,24 @@ function normalizeNullable(reflection: DeclarationReflection) { // set a flag on the property to consider it optional reflection.setFlag(ReflectionFlag.Optional) } + +function normalizePrimary(reflection: DeclarationReflection) { + if ( + reflection.type?.type !== "reference" || + reflection.type.name !== "PrimaryKeyModifier" || + !reflection.type.typeArguments || + reflection.type.typeArguments.length < 2 + ) { + return + } + + const actualType = reflection.type.typeArguments[1] + + if (actualType.type !== "reference") { + return + } + + // change the type argument of primary key modifier to have one type argument + // being the actual type + reflection.type.typeArguments = [actualType] +}