Skip to content

Commit 9c3fdd5

Browse files
committed
fix: keep auth-sized e.fn exports under declaration serialize limit
Store var seeds only on PublicFn's W and keep full WithSeed on .with via TerminatingFn so tsc -d no longer inlines the use graph.
1 parent 4ac324b commit 9c3fdd5

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

packages/experimental/src/declaration-emit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("declaration emit (TS7056)", () => {
4141
expect(dts).not.toMatch(/\$models/);
4242
expect(dts).toMatch(/export declare const signUpEmail:/);
4343
expect(dts).toMatch(/export declare const signInEmail:/);
44-
// Flat `.with` seeds: var leaves + bound creates, not module wrappers.
44+
// Compact `W` (var leaves) plus bound creates on intersected `.with`.
4545
expect(dts).toMatch(/createUser\?:/);
4646
expect(dts).toMatch(/user\?:/);
4747
} finally {

packages/experimental/src/error.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,14 @@ export class ControlFlow extends Error {
169169
}
170170
}
171171

172-
type ErrorsOf<F extends PublicFn<any, any, any, any, any, any, any, any>> =
172+
type ErrorsOf<F extends PublicFn<any, any, any, any, any, any, any>> =
173173
// `PublicFn` carries the declared error map in its `Er` type parameter.
174174
// Inferring from the generic is cheaper/steadier than pattern-matching the
175175
// optional `$schema` object, and avoids declaration-size blowups.
176-
F extends PublicFn<any, any, any, any, any, infer Er, any, any, any>
177-
? Er
178-
: never;
176+
F extends PublicFn<any, any, any, any, any, infer Er, any> ? Er : never;
179177

180178
export const getErrors = <
181-
F extends PublicFn<any, any, any, any, any, any, any, any>,
179+
F extends PublicFn<any, any, any, any, any, any, any>,
182180
>(
183181
fn: F,
184182
): ErrorsOf<F> | undefined => fn.$schema?.errors;

packages/experimental/src/fn.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,41 @@ type WithFnsSeed<U> = {
188188
: WithFnsSeed<U[K]>;
189189
};
190190

191+
/** Var seeds only - the half of {@link WithSeed} that stays small in
192+
* declaration emit when the `use` fn override map is wide. */
193+
type WithVarsSeed<RV> = { [K in keyof RV]?: RV[K] };
194+
191195
/**
192196
* Flat `.with` seed map stored on exported fns. Evaluating ScopeOf /
193197
* ModuleFns here (instead of embedding those wrappers as type arguments)
194198
* keeps declaration emit small: `.d.ts` shows leaf var shapes and bound
195199
* call signatures, not `ScopeOf<ResolvedVars<entire module graph>>`.
200+
*
201+
* Declaration emit stores {@link WithSeedStored} on the fn (var seeds
202+
* only); terminating `.fn()` intersects a full {@link WithSeed} `.with`.
196203
*/
197-
export type WithSeed<RV, U> = Prettify<
198-
{ [K in keyof RV]?: RV[K] } & WithFnsSeed<U>
199-
>;
204+
export type WithSeed<RV, U> = Prettify<WithVarsSeed<RV> & WithFnsSeed<U>>;
205+
206+
/** What declaration emit stores for `W` - var seeds only so TS does not
207+
* inline `BoundFnCall` per used fn from the builder `use` graph. */
208+
export type WithSeedStored<RV, _U = unknown> = WithVarsSeed<RV>;
200209

201-
/** What `v.fn` / `e.fn` returns: contract params plus a flat {@link WithSeed}
210+
/** What `v.fn` / `e.fn` returns: contract params plus a stored seed map
202211
* for `.with`, never the raw ScopeOf / ModuleFns graph. */
203212
export type PublicFn<
213+
A,
214+
R,
215+
K extends string,
216+
I,
217+
P extends readonly string[],
218+
Er,
219+
W = unknown,
220+
O = unknown,
221+
> = FnDefination<A, R, K, I, P, Er, W, O>;
222+
223+
/** Terminating `.fn()` product: compact {@link WithSeedStored} on the
224+
* fn for declaration emit, full {@link WithSeed} on `.with` while typing. */
225+
type TerminatingFn<
204226
A,
205227
R,
206228
K extends string,
@@ -210,7 +232,9 @@ export type PublicFn<
210232
RV,
211233
U,
212234
O = unknown,
213-
> = FnDefination<A, R, K, I, P, Er, WithSeed<RV, U>, O>;
235+
> = PublicFn<A, R, K, I, P, Er, WithSeedStored<RV, U>, O> & {
236+
with(context: WithSeed<RV, U>): BoundCall<A, R, I, Er>;
237+
};
214238

215239
/** What `.with` returns: the same callable, context baked in.
216240
* Re-exported from the package entry so exporting `.with(...)` results
@@ -615,7 +639,7 @@ export interface Fn<
615639
Fn<Base, BaseFns, BasePL, Prefix>
616640
>,
617641
) => R,
618-
): PublicFn<
642+
): TerminatingFn<
619643
void,
620644
R,
621645
Prefix extends "" ? string : Prefix,
@@ -636,7 +660,7 @@ export interface Fn<
636660
Fn<Base, BaseFns, BasePL, `${Prefix}${K}`>
637661
>,
638662
) => R,
639-
): PublicFn<
663+
): TerminatingFn<
640664
void,
641665
R,
642666
`${Prefix}${K}`,
@@ -675,7 +699,7 @@ export interface Fn<
675699
ChainPL<BasePL, PL>
676700
>,
677701
) => R,
678-
): PublicFn<
702+
): TerminatingFn<
679703
WidenedArgs<I, ChainPL<BasePL, PL>>,
680704
R,
681705
Prefix extends "" ? string : Prefix,
@@ -716,7 +740,7 @@ export interface Fn<
716740
ChainPL<BasePL, PL>
717741
>,
718742
) => R,
719-
): PublicFn<
743+
): TerminatingFn<
720744
WidenedArgs<I, ChainPL<BasePL, PL>>,
721745
R,
722746
`${Prefix}${K}`,

0 commit comments

Comments
 (0)