@@ -3,7 +3,8 @@ import type {
33 SecuritySchemeObject ,
44 ServerObject ,
55} from '../openApi/3.1.x/types/spec' ;
6- import type { ContextFile as CtxFile , IRContext } from './context' ;
6+ import type { StringCase } from '../types/case' ;
7+ import type { IRContext } from './context' ;
78import type { IRMediaType } from './mediaType' ;
89
910interface IRBodyObject {
@@ -24,6 +25,86 @@ interface IRComponentsObject {
2425 schemas ?: Record < string , IRSchemaObject > ;
2526}
2627
28+ interface IRContextFile {
29+ /**
30+ * Define casing for identifiers in this file.
31+ */
32+ case ?: StringCase ;
33+ /**
34+ * Should the exports from this file be re-exported in the index barrel file?
35+ */
36+ exportFromIndex ?: boolean ;
37+ /**
38+ * Unique file identifier.
39+ */
40+ id : string ;
41+ /**
42+ * Relative file path to the output path.
43+ *
44+ * @example
45+ * 'bar/foo.ts'
46+ */
47+ path : string ;
48+ }
49+
50+ interface IRHooks {
51+ /**
52+ * Hooks specifically for overriding operations behavior.
53+ *
54+ * Use these to classify operations, decide which outputs to generate,
55+ * or apply custom behavior to individual operations.
56+ */
57+ operations ?: {
58+ /**
59+ * Classify the given operation into one or more kinds.
60+ *
61+ * Each kind determines how we treat the operation (e.g., generating queries or mutations).
62+ *
63+ * **Default behavior:**
64+ * - GET → 'query'
65+ * - DELETE, PATCH, POST, PUT → 'mutation'
66+ *
67+ * **Resolution order:**
68+ * 1. If `isQuery` or `isMutation` returns `true` or `false`, that overrides `getKind`.
69+ * 2. If `isQuery` or `isMutation` returns `undefined`, the result of `getKind` is used.
70+ *
71+ * @param operation - The operation object to classify.
72+ * @returns An array containing one or more of 'query' or 'mutation'.
73+ */
74+ getKind ?: (
75+ operation : IROperationObject ,
76+ ) => ReadonlyArray < 'mutation' | 'query' > ;
77+ /**
78+ * Check if the given operation should be treated as a mutation.
79+ *
80+ * This affects which outputs are generated for the operation.
81+ *
82+ * **Default behavior:** DELETE, PATCH, POST, and PUT operations are treated as mutations.
83+ *
84+ * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
85+ * If it returns `undefined`, `getKind` is used instead.
86+ *
87+ * @param operation - The operation object to check.
88+ * @returns true if the operation is a mutation, false otherwise, or undefined to fallback to `getKind`.
89+ */
90+ isMutation ?: ( operation : IROperationObject ) => boolean | undefined ;
91+ /**
92+ * Check if the given operation should be treated as a query.
93+ *
94+ * This affects which outputs are generated for the operation.
95+ *
96+ * **Default behavior:** GET operations are treated as queries.
97+ *
98+ * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
99+ * If it returns `undefined`, `getKind` is used instead.
100+ *
101+ * @param operation - The operation object to check.
102+ * @returns true if the operation is a query, false otherwise, or undefined to fallback to `getKind`.
103+ */
104+ isQuery ?: ( operation : IROperationObject ) => boolean | undefined ;
105+ } ;
106+ }
107+
27108interface IROperationObject {
28109 body ?: IRBodyObject ;
29110 deprecated ?: boolean ;
@@ -221,7 +302,8 @@ export namespace IR {
221302 export type BodyObject = IRBodyObject ;
222303 export type ComponentsObject = IRComponentsObject ;
223304 export type Context < Spec extends Record < string , any > = any > = IRContext < Spec > ;
224- export type ContextFile = CtxFile ;
305+ export type ContextFile = IRContextFile ;
306+ export type Hooks = IRHooks ;
225307 export type Model = IRModel ;
226308 export type OperationObject = IROperationObject ;
227309 export type ParameterObject = IRParameterObject ;
0 commit comments