Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform-http): update the adapter configuration to be aligned with DI convention #2999

Merged
merged 2 commits into from
Mar 1, 2025

Conversation

Romakita
Copy link
Collaborator

@Romakita Romakita commented Feb 26, 2025

Information

Type Breaking change
Fix No

Refactor how PlatformAdapter is built. Now, PlatformAdapter declare correctly his dependencies and configure PlatformApplication. It avoid issue if the PlatformAdapter is instanciated in another DI context (CLI DI context).

Summary by CodeRabbit

  • Refactor

    • Streamlined dependency management across core platform components for improved flexibility and reliability.
    • Enhanced middleware configuration to ensure consistent handling of multipart requests.
    • Updated integration points for adapter functionality to simplify dependency registration.
    • Simplified the PlatformApplication and PlatformHandler classes by removing unnecessary dependencies on PlatformAdapter.
    • Adjusted the PlatformKoa and PlatformExpress classes to refine provider registration.
  • New Features

    • Added new navigation items for "Platform Serverless" and "Platform Serverless HTTP" in the documentation.
    • Introduced a new field in issue templates to specify the type of issue being reported.
  • Tests

    • Removed outdated test cases, reflecting the refined approach to middleware and dependency handling.
    • Updated test implementations to align with the new dependency injection strategy.

Copy link

coderabbitai bot commented Feb 26, 2025

Warning

Rate limit exceeded

@Romakita has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 814590c and 43fe027.

📒 Files selected for processing (16)
  • .github/ISSUE_TEMPLATE/01_bug-report.yml (1 hunks)
  • .github/ISSUE_TEMPLATE/02_feature-request.yml (1 hunks)
  • docs/.vitepress/config.mts (2 hunks)
  • packages/platform/platform-express/src/components/PlatformExpress.ts (1 hunks)
  • packages/platform/platform-express/vitest.config.mts (1 hunks)
  • packages/platform/platform-http/src/common/fn/adapter.ts (1 hunks)
  • packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.spec.ts (3 hunks)
  • packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformAdapter.ts (3 hunks)
  • packages/platform/platform-http/src/common/services/PlatformApplication.spec.ts (0 hunks)
  • packages/platform/platform-http/src/common/services/PlatformApplication.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformHandler.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformMiddlewaresChain.ts (1 hunks)
  • packages/platform/platform-http/src/common/utils/createInjector.ts (2 hunks)
  • packages/platform/platform-koa/src/components/PlatformKoa.ts (1 hunks)
  • packages/platform/platform-koa/vitest.config.mts (1 hunks)

Walkthrough

The pull request updates dependency injection and adapter configurations across the platform modules. It removes broad providers arrays in favor of more targeted adapter function calls and modifies function signatures to accept dependency arrays. The changes affect how middleware, application, adapter, and handler classes interact, leading to a streamlined injection process. Test cases are updated to reflect the new injection strategies, and obsolete methods related to multipart handling are removed.

Changes

Files Change Summary
packages/platform/platform-express/src/components/PlatformExpress.ts,
packages/platform/platform-koa/src/components/PlatformKoa.ts
Removed providers arrays and updated the adapter function calls to include explicit dependency objects.
packages/platform/platform-http/src/common/fn/adapter.ts,
packages/platform/platform-http/src/common/utils/createInjector.ts
Updated the adapter function signature to accept an additional imports parameter and simplified provider management in the injector configuration.
packages/platform/platform-http/src/common/services/PlatformAdapter.ts,
packages/platform/platform-http/src/common/services/PlatformHandler.ts,
packages/platform/platform-http/src/common/services/PlatformMiddlewaresChain.ts
Removed redundant provider properties and shifted from using injected PlatformApplication to direct injection of PlatformAdapter for handler mapping and middleware chaining.
packages/platform/platform-http/src/common/services/PlatformApplication.ts,
packages/platform/platform-http/src/common/services/PlatformApplication.spec.ts
Removed the adapter property, constructor, and multer method from the application class, and deleted related tests from the test suite.
packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.ts,
packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.spec.ts
Modified middleware to use an injected PlatformAdapter for multipart handling instead of a mocked application object, updating corresponding tests accordingly.
packages/platform/platform-express/vitest.config.mts,
packages/platform/platform-koa/vitest.config.mts
Adjusted coverage thresholds for statements and lines in the Vitest configuration.
docs/.vitepress/config.mts Added new navigation and sidebar items for "Platform Serverless" and "Platform Serverless HTTP" in the documentation.
.github/ISSUE_TEMPLATE/01_bug-report.yml Simplified the bug report template title and added a new field for issue type.
.github/ISSUE_TEMPLATE/02_feature-request.yml Added a new field for issue type categorization in the feature request template.

Possibly related PRs

  • fix(platform-http): doesn't call inject.get when provider is instance… #2937: The changes in the main PR regarding the adapter function call in PlatformExpress are related to the modifications in the createInjector function, as both involve updates to how dependencies are managed and injected, specifically focusing on the handling of providers.
  • Prepare fastify integration #2922: The changes in the main PR regarding the PlatformExpress class's adapter function call and the removal of the providers array are related to the modifications in the retrieved PR, which also involves changes to the PlatformExpress class, specifically the useContext method. Both PRs modify the same class, indicating a direct connection at the code level.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0623033 and 6a27230.

📒 Files selected for processing (11)
  • packages/platform/platform-express/src/components/PlatformExpress.ts (1 hunks)
  • packages/platform/platform-http/src/common/fn/adapter.ts (1 hunks)
  • packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.spec.ts (3 hunks)
  • packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformAdapter.ts (3 hunks)
  • packages/platform/platform-http/src/common/services/PlatformApplication.spec.ts (0 hunks)
  • packages/platform/platform-http/src/common/services/PlatformApplication.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformHandler.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformMiddlewaresChain.ts (1 hunks)
  • packages/platform/platform-http/src/common/utils/createInjector.ts (2 hunks)
  • packages/platform/platform-koa/src/components/PlatformKoa.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/platform/platform-http/src/common/services/PlatformApplication.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: test-third-parties (20.12.2)
  • GitHub Check: test-specs (20.12.2)
  • GitHub Check: test-security (20.12.2)
  • GitHub Check: test-platform (20.12.2)
  • GitHub Check: test-orm (20.12.2)
  • GitHub Check: test-core (20.12.2)
  • GitHub Check: test-graphql (20.12.2)
  • GitHub Check: CodeQL-Build
🔇 Additional comments (19)
packages/platform/platform-http/src/common/services/PlatformHandler.ts (1)

18-18: New import for PlatformAdapter.
This import aligns with the new injection mechanism for the adapter. No issues identified.

packages/platform/platform-http/src/common/services/PlatformMiddlewaresChain.ts (1)

2-2: Removal of unused imports.
Removing the inject import in favor of only importing what is used (constant, injectable) simplifies the code. Looks good.

packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.ts (1)

9-9: Import of PlatformAdapter.
This import is part of the shift from PlatformApplication to PlatformAdapter. No specific issues found.

packages/platform/platform-http/src/common/utils/createInjector.ts (3)

1-1: Updated import for logger configuration.
Narrowed imports to only what's needed. No issues identified.


20-20: Side-effect call to $adapter.
Ensure that $adapter(settings.adapter) is only needed for its side effects and that discarding its return value is intentional.


22-22: Invoking PlatformAdapter.
inj.invoke(PlatformAdapter) properly initializes the adapter. Confirm that the adapter is configured as expected and no references are required afterward.

packages/platform/platform-koa/src/components/PlatformKoa.ts (1)

189-202: Refactored DI approach

This newly introduced array approach for injecting providers is consistent with the new adapter signature. Please verify if PlatformApplication or any other providers are needed here, otherwise it looks good.

packages/platform/platform-express/src/components/PlatformExpress.ts (1)

278-283: Ensure consistency with adapter approach

This configuration adds only the PlatformHandler to the adapter. If you need to rely on PlatformRequest or PlatformResponse, consider including them. Otherwise, it looks correct.

packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.spec.ts (3)

2-2: New imports for injection

The direct imports of inject from "@tsed/di" and PlatformAdapter are a good step toward a more streamlined approach to dependency injection.

Also applies to: 10-10


25-25: Refactoring test construction

Injecting PlatformMulterMiddleware and PlatformAdapter directly clarifies dependencies and reduces reliance on global mocks. Good improvement.

Also applies to: 29-29, 31-31, 33-33


46-46: Updated test usage of adapter.multipart

Replacing app.multer references with adapter.multipart ensures that the new approach is properly tested. This looks correct and aligned with the updated architecture.

Also applies to: 50-50, 57-57, 63-63

packages/platform/platform-http/src/common/fn/adapter.ts (2)

2-2: Imports updated for DI rework

Bringing in ProviderOpts and PlatformAdapter aligns with the new DI approach. This looks correct and necessary.

Also applies to: 4-4


11-17: Extended adapter function signature

The introduction of an optional second argument to configure additional providers is a solid improvement. Ensure concurrency is handled carefully if providers are updated after the adapter is set. Overall, this pattern fosters clarity in dependency registration.

Also applies to: 18-18, 23-30, 31-36

packages/platform/platform-http/src/common/services/PlatformAdapter.ts (5)

4-5: No issues found with the new imports.
These imports correctly pull in additional DI and hook features.


14-16: Clarify usage of newly imported dependencies.
Imports for Platform, PlatformApplication, and PlatformHandler work fine, but ensure that usage in other parts of the code (or re-exports) is properly aligned with the updated DI context.


21-21: Use caution when converting from a getter to a readonly injection.
Previously, this property was a getter. Now it is a readonly field injected at construction time. While this is generally acceptable, confirm that existing references to this.app (which might have expected lazy evaluation) still function as intended.


23-33: Ensure that the constructor injection does not introduce circular references.
Injecting PlatformApplication within the PlatformAdapter constructor is straightforward, but double-check that other parts of the application will not cause circular injection or timing issues (e.g., if PlatformApplication also injects adapters at some point).

Also note that $on("$afterInvoke", PlatformAdapter, ...) is triggered after this class is invoked, setting PLATFORM_NAME in the configuration. Please confirm that there is no duplication or conflict with other modules that might also override PLATFORM_NAME.


99-99: Good practice to explicitly declare imports in the DI metadata.
Declaring [PlatformApplication, Platform, PlatformHandler] as imports for this adapter is clear and helps avoid hidden dependency issues.

packages/platform/platform-http/src/common/services/PlatformApplication.ts (1)

3-3: Scope declaration is consistent with the single instance usage.
Introducing ProviderScope.SINGLETON is appropriate for an application-level service. Make sure this aligns with how the rest of the platform expects to interact with PlatformApplication.

@@ -43,7 +42,7 @@ export class PlatformHandler {
.on("alterHandler", (handlerMetadata: PlatformHandlerMetadata) => {
const handler = handlerMetadata.isInjectable() ? this.createHandler(handlerMetadata) : handlerMetadata.handler;

return this.platformApplication.adapter.mapHandler(handler, handlerMetadata);
return inject(PlatformAdapter).mapHandler(handler, handlerMetadata);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider storing the adapter instance in a property.
Directly calling inject(PlatformAdapter) on each handler mapping might cause minor overhead and makes it less explicit than having a dedicated property injection. Consider injecting once (e.g., in the constructor) to keep the code consistent and potentially more efficient.

@@ -39,7 +38,7 @@ export class PlatformMulterMiddleware implements MiddlewareMethods {
delete settings.dest;
}

const multer = this.app.multer(settings);
const multer = inject(PlatformAdapter).multipart(settings);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Refactor injection usage.
Using inject(PlatformAdapter).multipart(settings) is correct for dynamically retrieving the adapter. If this call happens frequently, consider storing a reference in the class to avoid repetitive injection.

this.rawApp = app;
this.rawCallback = callback;
}
rawCallback(): any {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Empty method body may lead to unhandled callbacks.
Previously, rawCallback might have been populated by the adapter; now it is an empty method returning any. Verify if other parts of the platform expect a functional implementation. If so, consider either implementing a default callback or refactoring the call site.

@Romakita Romakita force-pushed the fix-adapter-injection branch from 6a27230 to f703e46 Compare February 26, 2025 17:36
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a27230 and f703e46.

📒 Files selected for processing (12)
  • packages/platform/platform-express/src/components/PlatformExpress.ts (1 hunks)
  • packages/platform/platform-express/vitest.config.mts (1 hunks)
  • packages/platform/platform-http/src/common/fn/adapter.ts (1 hunks)
  • packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.spec.ts (3 hunks)
  • packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformAdapter.ts (3 hunks)
  • packages/platform/platform-http/src/common/services/PlatformApplication.spec.ts (0 hunks)
  • packages/platform/platform-http/src/common/services/PlatformApplication.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformHandler.ts (2 hunks)
  • packages/platform/platform-http/src/common/services/PlatformMiddlewaresChain.ts (1 hunks)
  • packages/platform/platform-http/src/common/utils/createInjector.ts (2 hunks)
  • packages/platform/platform-koa/src/components/PlatformKoa.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/platform/platform-http/src/common/services/PlatformApplication.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: test-third-parties (20.12.2)
  • GitHub Check: test-specs (20.12.2)
  • GitHub Check: test-security (20.12.2)
  • GitHub Check: test-platform (20.12.2)
  • GitHub Check: test-orm (20.12.2)
  • GitHub Check: test-graphql (20.12.2)
  • GitHub Check: test-core (20.12.2)
  • GitHub Check: CodeQL-Build
🔇 Additional comments (21)
packages/platform/platform-express/vitest.config.mts (1)

13-16: Consider verifying coverage objectives.

You've slightly lowered the coverage thresholds from 96.63 to 96.61. Please confirm that this change is intentional and won't mask any regressions in test coverage.

packages/platform/platform-http/src/common/services/PlatformHandler.ts (2)

18-18: Import for PlatformAdapter looks correct.

This import is properly aligned with the direct injection usage in this file.


45-45: Consider storing the adapter instance in a property.
We've flagged this in an earlier commit. Reiterating the recommendation to store the PlatformAdapter instance in a class property or constructor injection for consistency and possible performance benefits.

packages/platform/platform-http/src/common/services/PlatformMiddlewaresChain.ts (1)

2-2: Removal of unused import is good.

Dropping inject from the imports helps keep the file clean.

packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.ts (2)

9-9: Import for PlatformAdapter looks appropriate.

This aligns with the direct injection used in the middleware.


41-41: Refactor repeated injection usage.
Injecting PlatformAdapter inline may cause overhead if called frequently. Consider storing the adapter instance in the class to avoid repetitive injection calls.

packages/platform/platform-koa/src/components/PlatformKoa.ts (1)

189-202: Adopt the new targeted DI approach carefully.

This new adapter(PlatformKoa, [...]) array-based provider registration aligns well with your refactoring goal of explicitly declaring dependencies. Since the old providers property was removed, ensure all references to it are replaced or removed accordingly. Also confirm whether additional tokens (e.g., PlatformApplication, Platform) need registering or are covered by this slimmed-down list.

packages/platform/platform-http/src/common/utils/createInjector.ts (2)

1-1: Fresh import usage is aligned with the DI patterns.

Importing injector and setLoggerConfiguration from @tsed/di looks correct and consistent with the codebase’s DI design. No immediate concerns here.


20-22: Confirm the adapter call and injector invocation sequence.

These combined lines ($adapter(settings.adapter) followed by inj.invoke(PlatformAdapter)) depend on the adapter’s internal logic. Verify that no other tokens or providers are necessary before invoking PlatformAdapter. If any providers were previously automatically injected, confirm they’re now handled by the new approach.

packages/platform/platform-express/src/components/PlatformExpress.ts (1)

278-283: Narrow provider array for PlatformExpress requires verification.

Registering only PlatformHandler in adapter(PlatformExpress, [...]) follows the new DI pattern. However, confirm that you don’t need PlatformRequest, PlatformResponse, or others. If future logic relies on them, they should also be declared here or seamlessly injected elsewhere.

packages/platform/platform-http/src/common/services/PlatformAdapter.ts (2)

4-16: Validate import statements
The new imports from @tsed/di and @tsed/hooks look correct. Ensure your environment is configured for ESM builds and that the “.js” extension usage is consistently handled across modules.


99-99: Explicitly declaring imports
Registering these dependencies ensures the PlatformAdapter has all required services at injection time. This approach aligns well with Ts.ED’s DI patterns.

packages/platform/platform-http/src/common/services/PlatformApplication.ts (2)

3-3: Check the provider scope
Using ProviderScope.SINGLETON helps reuse a single instance. However, confirm that a shared instance of PlatformApplication does not introduce side effects when handling multiple requests or distinct contexts.


21-21: Method rawCallback() is empty
This repeats the prior concern: an empty implementation might lead to unhandled callbacks if other parts of the platform assume a functional method.

packages/platform/platform-http/src/common/middlewares/PlatformMulterMiddleware.spec.ts (7)

2-2: Use of inject is aligned with the new DI approach.
This import correctly introduces the inject function from @tsed/di for a streamlined dependency injection workflow.


10-10: New PlatformAdapter import is consistent with DI refactor.
Importing PlatformAdapter here ensures it can be directly injected and tested, removing reliance on a mock app object.


25-33: Direct injection of PlatformMulterMiddleware and PlatformAdapter is a clean refactor.
Replacing PlatformTest.invoke(...) with inject(...) removes boilerplate while maintaining test clarity. The return structure now includes adapter, avoiding the previous mock app.


46-46: Destructuring adapter in test setup.
Including adapter in the returned object aligns with the updated dependency injection flow, ensuring consistent usage in tests.


50-50: Replacing app.multer with adapter.multipart in assertions.
This change correctly tests the new adapter-based approach to file handling, reflecting the updated middleware logic.


57-57: Storage test aligned with adapter injection.
The refactoring to rely on adapter.multipart with a storage parameter is coherent with the new design.


63-63: Adapter-based assertion for multipart call.
Confirming that the adapter.multipart method is called with the correct options ensures correctness when using a custom storage.

Comment on lines +2 to +4
import {GlobalProviders, injector, ProviderOpts, refValue} from "@tsed/di";

import type {PlatformAdapter} from "../services/PlatformAdapter.js";
import {PlatformAdapter} from "../services/PlatformAdapter.js";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Use consistent ESM extension
The import statements with ".js" extension are valid for ESM usage. Just ensure your bundler or environment supports it consistently across the platform.

Comment on lines +11 to +18
* Set the platform adapter token and his dependencies
*/
export function adapter(adapter?: Type<PlatformAdapter<any>>): Type<PlatformAdapter<any>> {
export function adapter(adapter: Type<PlatformAdapter<any>>, imports?: ProviderOpts[]): Type<PlatformAdapter<any>>;
/**
* Get the platform adapter token
*/
export function adapter(): Type<PlatformAdapter<any>>;
export function adapter(adapter?: Type<PlatformAdapter<any>>, imports: ProviderOpts[] = []): Type<PlatformAdapter<any>> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Clarify function overload documentation
The JSDoc references “Set the platform adapter token and his dependencies,” but doesn’t address the overload that retrieves the adapter token. Consider updating or separating the doc blocks to reflect both usage scenarios.

Comment on lines +24 to +36
imports?.forEach(({token, useClass}) => {
const provider = GlobalProviders.get(token);
if (useClass && provider) {
provider.useClass = useClass;
injector().set(token, provider);
}
});

injector()
.addProvider(PlatformAdapter, {
useClass: adapter
})
.alias(PlatformAdapter, "PlatformAdapter");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Handle missing providers and possible concurrency side effects
When reassigning provider.useClass in the loop, ensure that GlobalProviders.get(token) is defined. Otherwise, a missing provider might cause runtime errors. Also verify if reassigning useClass could lead to concurrency or lifecycle issues if multiple calls to adapter() modify the same provider in parallel.

Comment on lines +21 to +32
readonly app = inject<PlatformApplication<App>>(PlatformApplication);

constructor() {
const platformApp = inject(PlatformApplication);

const {app, callback} = this.createApp();
platformApp.rawApp = app as any;
platformApp.rawCallback = callback;

$on("$afterInvoke", PlatformAdapter, () => {
configuration().set("PLATFORM_NAME", constant("PLATFORM_NAME") || this.NAME);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Unify usage of injected references and confirm $afterInvoke usage
The constructor re-injects PlatformApplication instead of relying on this.app. You could reference this.app to avoid redundancy. Also verify that $afterInvoke is the desired lifecycle hook for finalizing the PLATFORM_NAME; depending on your application flow, you might need an earlier or later hook.

@Romakita Romakita force-pushed the fix-adapter-injection branch from f703e46 to 35071a7 Compare February 27, 2025 09:39
@Romakita Romakita force-pushed the fix-adapter-injection branch from 814590c to 43fe027 Compare March 1, 2025 08:15
@Romakita Romakita merged commit 1682d9c into production Mar 1, 2025
1 of 9 checks passed
@Romakita Romakita deleted the fix-adapter-injection branch March 1, 2025 08:16
@Romakita
Copy link
Collaborator Author

Romakita commented Mar 1, 2025

🎉 This PR is included in version 8.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant