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

refactor new api #16

Merged
merged 9 commits into from
Sep 12, 2024
Merged

refactor new api #16

merged 9 commits into from
Sep 12, 2024

Conversation

alimd
Copy link
Member

@alimd alimd commented Sep 12, 2024

  • feat(api-server): Add NanotronUrl class for handling client request URLs
  • refactor(api-server): Update HttpResponseHeaders interface properties
  • refactor(api-server): Update type.ts with NativeClientRequest and NativeServerResponse types
  • refactor(api-server): types
  • refactor(api-server): Update main.ts exports with NanotronClientRequest, NanotronServerResponse, and NanotronUrl types
  • refactor(api-server): Update NanotronServerResponse class
  • refactor(api-server): Update NanotronClientRequest class
  • refactor(api-server): Update NanotronClientRequest class and NanotronServerResponse class

This commit adds a new file, `url.ts`, which contains the implementation of the `NanotronUrl` class. This class extends the `URL` class from the `node:url` module and provides additional functionality for handling client request URLs in the Nanotron API server.

The `NanotronUrl` class includes a static property `versionPattern_` which is a regular expression used to match and replace the version prefix in the URL. It also has properties `method` and `debugId` which store the HTTP method and the debug ID of the request respectively.

The constructor of the `NanotronUrl` class takes a `clientRequest` object of type `IncomingMessage` and a `prefix` parameter which represents the URL prefix. It modifies the URL by removing the prefix and replacing the version prefix with a single `/`. The modified URL is then passed to the `URL` constructor along with a default base URL.

This commit enhances the functionality of the Nanotron API server by providing a dedicated class for handling client request URLs. This improves code organization and maintainability.
…st, NanotronServerResponse, and NanotronUrl types
- Update import statements and types in NanotronServerResponse class
- Add NanotronClientRequest and NativeServerResponse types to type imports
- Remove unused import of ServerResponse from node:http
- Update constructor parameters to store NanotronClientRequest and NativeServerResponse
- Update logger method calls with debugId from clientRequest.url
- Update replyErrorResponse and replyError methods to use clientRequest instead of config
- Update replyJson method to use debugId from clientRequest.url in logger error call
- Update reply method to use debugId from clientRequest.url in logger method call
- Remove unnecessary error logging in replyJson and reply methods
- Update imports and remove unused dependencies
- Add type annotations for properties and parameters
- Refactor constructor to accept NanotronUrl, NativeClientRequest, NativeServerResponse, and DefineRouteOption
- Create NanotronServerResponse instance in constructor
- Update logger method calls
…ServerResponse class

- Removed unused imports and updated the imports for NanotronClientRequest and NanotronServerResponse classes in api-server.ts.
- Added import for NanotronUrl in api-server.ts.

- Updated the type definitions in type.ts to include NativeClientRequest and NativeServerResponse types.

- Updated the bodyLimit default value in NanotronApiServer class to 1MiB.

- Refactored the handleClientRequest_ method in NanotronApiServer class to use the new NativeClientRequest and NativeServerResponse types.

- Updated the getRouteOption_ method in NanotronApiServer class to use the new NanotronUrl class.

- Removed unused code and added error handling in the handleClientRequest_ method.

- Updated the comments and log messages for better clarity and readability.
@alimd alimd requested a review from a team September 12, 2024 08:34
@alimd alimd self-assigned this Sep 12, 2024
@alimd alimd added refactor Updating the code with simpler, easier to understand or more efficient syntax or methods. breaking-change A change that changes the API or breaks backward compatibility for users. new-feature New features or options. labels Sep 12, 2024
@alimd alimd merged commit 036508c into next Sep 12, 2024
2 checks passed
@alimd alimd deleted the feat/new-api branch September 12, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A change that changes the API or breaks backward compatibility for users. new-feature New features or options. refactor Updating the code with simpler, easier to understand or more efficient syntax or methods.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant