diff --git a/CHANGES.md b/CHANGES.md index ab426ace9..397f897ae 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 @@ -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 diff --git a/packages/fedify/src/federation/builder.ts b/packages/fedify/src/federation/builder.ts index 6aa15016b..1503ccf7b 100644 --- a/packages/fedify/src/federation/builder.ts +++ b/packages/fedify/src/federation/builder.ts @@ -593,43 +593,12 @@ export class FederationBuilderImpl this.webFingerLinksDispatcher = dispatcher; } - setObjectDispatcher( - cls: ConstructorWithTypeId, - path: - `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, - dispatcher: ObjectDispatcher, - ): ObjectCallbackSetters; - setObjectDispatcher( - cls: ConstructorWithTypeId, - path: - `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, - dispatcher: ObjectDispatcher, - ): ObjectCallbackSetters; - setObjectDispatcher( - cls: ConstructorWithTypeId, - path: - `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, - dispatcher: ObjectDispatcher, - ): ObjectCallbackSetters; - setObjectDispatcher( - cls: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression}${string}`, - dispatcher: ObjectDispatcher, - ): ObjectCallbackSetters; - setObjectDispatcher( - cls: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}${Rfc6570Expression< - TParam - >}${string}`, - dispatcher: ObjectDispatcher, - ): ObjectCallbackSetters; - setObjectDispatcher( - cls: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}`, - dispatcher: ObjectDispatcher, - ): ObjectCallbackSetters; + /** + * 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( cls: ConstructorWithTypeId, path: string, @@ -1253,94 +1222,12 @@ export class FederationBuilderImpl return setters; } - setCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression< - TParam - >}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - TContextData - >; - setCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression< - TParam - >}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - TContextData - >; - setCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}${Rfc6570Expression< - TParam - >}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - TContextData - >; - setCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - 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, @@ -1368,64 +1255,12 @@ export class FederationBuilderImpl ); } - setOrderedCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}${Rfc6570Expression< - TParam - >}${string}${Rfc6570Expression}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - TContextData - >; - setOrderedCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}${Rfc6570Expression< - TParam - >}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - TContextData - >; - setOrderedCollectionDispatcher< - TObject extends Object, - TParam extends string, - >( - name: string | symbol, - itemType: ConstructorWithTypeId, - path: `${string}${Rfc6570Expression}${string}`, - dispatcher: CustomCollectionDispatcher< - TObject, - TParam, - RequestContext, - TContextData - >, - ): CustomCollectionCallbackSetters< - TParam, - RequestContext, - 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,