@@ -13,6 +13,7 @@ import { type ContainerResolver } from '@adonisjs/fold'
1313import type { Item } from './resource/item.ts'
1414import { type Paginator } from './paginator.ts'
1515import type { Collection } from './resource/collection.ts'
16+ import { type BaseTransformer } from './base_transformer.ts'
1617
1718/**
1819 * Counter to increment the depth. At max we will allow fetching
@@ -434,6 +435,42 @@ export type InferData<
434435 ? UnpackValues < Awaited < ReturnType < Transformer [ Variant ] > > , MaxDepth , Depth , false >
435436 : never
436437
438+ /**
439+ * Infers the data structure for all variant methods of a transformer class, excluding
440+ * the default 'toObject' method and base transformer methods.
441+ *
442+ * @template Transformer - The resource class to infer variant data from
443+ * @template MaxDepth - Maximum depth allowed for unpacking (defaults to -1 for unlimited)
444+ * @template Depth - Current depth level (defaults to 0)
445+ *
446+ * @example
447+ * ```typescript
448+ * class UserResource {
449+ * toObject() { return { id: 1, name: "John" } }
450+ * toSummary() { return { id: 1 } }
451+ * toProfile() { return { id: 1, name: "John", email: "john@example .com" } }
452+ * }
453+ *
454+ * type UserVariants = InferVariants<UserResource>
455+ * // Result: {
456+ * // toSummary: { id: number }
457+ * // toProfile: { id: number; name: string; email: string }
458+ * // }
459+ * ```
460+ */
461+ export type InferVariants < Transformer , MaxDepth extends number = - 1 , Depth extends number = 0 > = {
462+ [ O in {
463+ [ K in keyof Transformer ] : 'toObject' extends K
464+ ? never
465+ : K extends keyof BaseTransformer < any >
466+ ? never
467+ : Transformer [ K ] extends ( ...args : any [ ] ) => unknown
468+ ? K
469+ : never
470+ } [ keyof Transformer ] &
471+ string ] : InferData < Transformer , O , MaxDepth , Depth >
472+ }
473+
437474/**
438475 * Function interface for the main serialize function that handles different data types.
439476 * Provides overloads for serializing Items, Collections, Paginators, and resource data.
0 commit comments