Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,20 @@ To be released.
matching. The deprecated `Router` export from *@fedify/fedify* remains
available for compatibility. [[#418], [#758] by ChanHaeng Lee]

- Significantly sped up TypeScript type-checking by simplifying the internal
`path` parameter types of the `setObjectDispatcher()`,
`setCollectionDispatcher()`, and `setOrderedCollectionDispatcher()` methods.
These methods previously expanded `path` into thousands of RFC 6570
template-literal variants, which dominated type-checking time; a full
codebase type check now completes in roughly 13 seconds instead of around
99 seconds. The public dispatcher method signatures and runtime path
validation are unchanged. This is a partial fix for [#613] that targets
the dispatcher overload hot path; other contributors to `check-all` cost
may remain. [[#613], [#800] by ChanHaeng Lee]

[#316]: https://github.com/fedify-dev/fedify/issues/316
[#418]: https://github.com/fedify-dev/fedify/issues/418
[#613]: https://github.com/fedify-dev/fedify/issues/613
[#619]: https://github.com/fedify-dev/fedify/issues/619
[#620]: https://github.com/fedify-dev/fedify/issues/620
[#735]: https://github.com/fedify-dev/fedify/issues/735
Expand All @@ -276,6 +288,7 @@ To be released.
[#778]: https://github.com/fedify-dev/fedify/pull/778
[#782]: https://github.com/fedify-dev/fedify/issues/782
[#787]: https://github.com/fedify-dev/fedify/pull/787
[#800]: https://github.com/fedify-dev/fedify/pull/800

### @fedify/cli

Expand Down
201 changes: 18 additions & 183 deletions packages/fedify/src/federation/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,43 +593,12 @@ export class FederationBuilderImpl<TContextData>
this.webFingerLinksDispatcher = dispatcher;
}

setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path:
`${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`,
dispatcher: ObjectDispatcher<TContextData, TObject, TParam>,
): ObjectCallbackSetters<TContextData, TObject, TParam>;
setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path:
`${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`,
dispatcher: ObjectDispatcher<TContextData, TObject, TParam>,
): ObjectCallbackSetters<TContextData, TObject, TParam>;
setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path:
`${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`,
dispatcher: ObjectDispatcher<TContextData, TObject, TParam>,
): ObjectCallbackSetters<TContextData, TObject, TParam>;
setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<TParam>}${string}`,
dispatcher: ObjectDispatcher<TContextData, TObject, TParam>,
): ObjectCallbackSetters<TContextData, TObject, TParam>;
setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
TParam
>}${string}`,
dispatcher: ObjectDispatcher<TContextData, TObject, TParam>,
): ObjectCallbackSetters<TContextData, TObject, TParam>;
setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}`,
dispatcher: ObjectDispatcher<TContextData, TObject, TParam>,
): ObjectCallbackSetters<TContextData, TObject, TParam>;
/**
* The RFC 6570 template-literal `path` overloads were removed for
* type-checking efficiency, so the URI variable types can no longer be
* inferred from `path` (now typed as a plain `string`); to use them, specify
* the variable name through the `TParam` generic argument.
*/
setObjectDispatcher<TObject extends Object, TParam extends string>(
cls: ConstructorWithTypeId<TObject>,
path: string,
Expand Down Expand Up @@ -1253,94 +1222,12 @@ export class FederationBuilderImpl<TContextData>
return setters;
}

setCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<
TParam
>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
setCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<
TParam
>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
setCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
TParam
>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
setCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
/**
* The RFC 6570 template-literal `path` overloads were removed for
* type-checking efficiency, so the URI variable types can no longer be
* inferred from `path` (now typed as a plain `string`); to use them, specify
* the variable name through the `TParam` generic argument.
*/
setCollectionDispatcher<
TObject extends Object,
TParam extends string,
Expand Down Expand Up @@ -1368,64 +1255,12 @@ export class FederationBuilderImpl<TContextData>
);
}

setOrderedCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
TParam
>}${string}${Rfc6570Expression<TParam>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
setOrderedCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<
TParam
>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
setOrderedCollectionDispatcher<
TObject extends Object,
TParam extends string,
>(
name: string | symbol,
itemType: ConstructorWithTypeId<TObject>,
path: `${string}${Rfc6570Expression<TParam>}${string}`,
dispatcher: CustomCollectionDispatcher<
TObject,
TParam,
RequestContext<TContextData>,
TContextData
>,
): CustomCollectionCallbackSetters<
TParam,
RequestContext<TContextData>,
TContextData
>;
/**
* The RFC 6570 template-literal `path` overloads were removed for
* type-checking efficiency, so the URI variable types can no longer be
* inferred from `path` (now typed as a plain `string`); to use them, specify
* the variable name through the `TParam` generic argument.
*/
setOrderedCollectionDispatcher<
TObject extends Object,
TParam extends string,
Expand Down
Loading