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

feat: add dedupe feature, params option, and more as v1 #99

Merged
merged 97 commits into from
Dec 7, 2024

Conversation

Ryan-Zayne
Copy link
Member

@Ryan-Zayne Ryan-Zayne commented Sep 17, 2024

feat: Add params feature
feat: Add dedupe feature
feat!: move cjs support to legacy entrypoint
refactor: cleaned up some parts of the logic
feat!: deprecate cancelRedundantRequest option
feat: add plugin support
feat: add callApiOptions support, just like query options
feat: add support for responseErrorValidation
feat: improved types
feat: a few code and perf improvements

  • Added vite-env.d.ts file for Vite client types
  • Added tsconfig.json file for TypeScript configuration
  • Added pnpm-workspace.yaml file for pnpm workspace configuration
  • Deleted tsconfig.eslint.json file
  • Added client.ts file with a fetchStuff function
  • Added README.md file with installation and run instructions
  • Added .gitignore file to ignore logs, editor files, and build artifacts
  • Added server.ts file with a foo variable and console.log statements
  • Updated eslint.config.js file to use tsconfig.json as the default project
  • Added index.html file with basic HTML structure and script import
  • Updated autofix.yml, size-limit.yml, lint-and-type.yml, test--release-and-publish.yml, and changeset--release-and-publish.yml workflows to use pnpm version 9.10.0
  • Updated package.json file with dependencies and devDependencies
  • Added pnpm-lock.yaml file with lockfile information
  • Updated types.ts file to include params property in ExtraOptions interface
  • Updated typeof.ts file to use isArray and isString helper functions
  • Updated theme.config.tsx file to remove eslint-disable comments
  • Added vite.svg file for Vite logo

Description

Please include a summary of the change and which issue is fixed (if applicable).

Related Issue

Contribution Guidelines

Before submitting this pull request, please review our Contribution Guidelines to understand how to contribute to this project.

Checklist

  • I have reviewed the Contribution Guidelines linked above.
  • I have tested my changes thoroughly and ensured that all existing tests pass.
  • I have provided clear and concise commit messages.
  • I have updated the project's documentation as necessary.

Screenshots (if applicable)

Additional context (if needed)

feat: Add params feature

- Added vite-env.d.ts file for Vite client types
- Added tsconfig.json file for TypeScript configuration
- Added pnpm-workspace.yaml file for pnpm workspace configuration
- Deleted tsconfig.eslint.json file
- Added client.ts file with a fetchStuff function
- Added README.md file with installation and run instructions
- Added .gitignore file to ignore logs, editor files, and build artifacts
- Added server.ts file with a foo variable and console.log statements
- Updated eslint.config.js file to use tsconfig.json as the default project
- Added index.html file with basic HTML structure and script import
- Updated autofix.yml, size-limit.yml, lint-and-type.yml, test--release-and-publish.yml, and changeset--release-and-publish.yml workflows to use pnpm version 9.10.0
- Updated package.json file with dependencies and devDependencies
- Added pnpm-lock.yaml file with lockfile information
- Updated types.ts file to include params property in ExtraOptions interface
- Updated typeof.ts file to use isArray and isString helper functions
- Updated theme.config.tsx file to remove eslint-disable comments
- Added vite.svg file for Vite logo
@Ryan-Zayne Ryan-Zayne linked an issue Sep 17, 2024 that may be closed by this pull request
Copy link

changeset-bot bot commented Sep 17, 2024

⚠️ No Changeset found

Latest commit: 5bfc458

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Sep 17, 2024

Deploy Preview for zayne-callapi canceled.

Name Link
🔨 Latest commit a19fa39
🔍 Latest deploy log https://app.netlify.com/sites/zayne-callapi/deploys/6754ae69d24ae00008e19929

Copy link

pkg-pr-new bot commented Sep 17, 2024

Open in Stackblitz

npm i https://pkg.pr.new/zayne-labs/call-api/@zayne-labs/callapi@99

commit: a19fa39

@Ryan-Zayne Ryan-Zayne changed the title feat: Add Vite configuration files and dependencies feat: Add Vite configuration files and Params feature Sep 17, 2024
@Ryan-Zayne Ryan-Zayne linked an issue Sep 17, 2024 that may be closed by this pull request
The dedupeStrategy option in the createFetchClient function has been updated to use the "cancel" strategy instead of the deprecated cancelRedundantRequests option. This change ensures that the previous pending request to the same URL will be cancelled and allows the new request to go through. The cancelRedundantRequests option is now deprecated and should be replaced with dedupeStrategy === "cancel".

Refactor the code in createFetchClient.ts to reflect this change.
The createFetchClient function now supports a new dedupeStrategy option that allows controlling the behavior when a duplicate request is detected. The "cancel" strategy will cancel the previous pending request, while the "defer" strategy will return the response from the previous request.

This change ensures that the previous pending request to the same URL will be cancelled and allows the new request to go through. The cancelRedundantRequests option is now deprecated and should be replaced with dedupeStrategy === "cancel".

Additionally, the types.ts and utils.ts files have been updated to support the new dedupeStrategy option and related functionality.
refactor: ensure caching mechanism only works if a key is available
@Ryan-Zayne Ryan-Zayne marked this pull request as ready for review September 19, 2024 16:51
Ryan-Zayne and others added 16 commits September 19, 2024 17:52
…recate cancelRedundantRequests option, and stabilize current API
…recate cancelRedundantRequests option, and stabilize current API
This commit updates the map types in the `types.ts` file and adds a new type helper called `Awaitable` in the `type-helpers.ts` file. The map types have been modified to include the `Awaitable` type, which represents a promise or a non-promise value. This change improves the type safety and readability of the codebase.

Refactor the map types and add Awaitable type helper
@Ryan-Zayne Ryan-Zayne changed the title feat: Add Vite configuration files and Params feature feat: Add Dedupe and Params feature Sep 22, 2024
This commit deduplicates interceptors in the `handleMergeInterceptors` function. It ensures that only unique interceptors are executed by creating a new array of unique interceptors before mapping and executing them. This change improves the efficiency and reliability of the interceptor handling logic.

Additionally, this commit updates the package.json version to 1.0.0-rc-7.
…st deduplication

- Update the resolveHeaders function to handle various types of auth and body options
- Add requestKey option to callApi function in dev/src/client.ts
- Enhance error handling in createFetchClient to better distinguish between HTTP and JavaScript errors
- Improve request deduplication logic to provide more informative abort messages
- Add Register interface to allow custom meta types
- Fix isHTTPError type guard with explicit return type, as the inferred one stopped working
- Replace PossibleJavascriptErrorNames with explicit error name union
- Update error type checking to use isPlainObject for better accuracy
- Fix bug in resolveErrorResult where error data was not being set correctly
Rename withConfig directory to options for better semantic meaning and update related imports
🎯 What:
- Moved URL and plugin logic into dedicated files
- Extracted constants into separate utility file
- Enhanced type definitions in both packages
- Removed unused dev server files

💡 Why:
- Better code organization and maintainability
- Improved type safety and developer experience
- Reduced code duplication between packages

🔧 Changes:
- Created new files: plugins.ts, url.ts, constants.ts
- Updated package dependencies
- Refined type helpers and common utilities
- Streamlined fetch client implementation

📦 Packages affected:
- callapi
- callapi-legacy
…ling

- Introduce `mergedInterceptorsExecutionOrder` option to control the order of execution for merged interceptors
- Refactor `initializePlugins` function to handle the new `mergedInterceptorsExecutionOrder` option
- Update `createFetchClient` and `createFetchClientWithOptions` to use the new `interceptors` object from `initializePlugins`
- Bump package versions to reflect the changes
…bility.

- Updated version number to "1.0.0-rc.28" in the package.json file.
- Refactored the way headers are handled and added a new function to retrieve headers in the createFetchClient function.
- Update the plugin initialization configuration to use a base configuration in the callapi-legacy package.
- Updated the response to the user's request:  Changed the responseParser function to return an Awaitable object and updated the responseType to use the getResponseType function instead of handleResponseType. Added the plugins property to the BaseCallApiExtraOptions interface to allow extending the library's behavior.
- Refactored URL generation function to correctly replace parameters in the URL string.
- The main goal of the changes is to add functions for picking and omitting keys from objects, as well as functions for splitting and generating configurations in a TypeScript file related to API calls.
- Refactor isPlainObject function to improve code readability by ignoring prettier formatting for a specific condition.
- Updated the version in the package.json file to "1.0.0-rc.46".
- Update the headers handling and request key generation in the createFetchClient function.
- The main goal of the changes is to refactor the way headers are handled and to introduce a new mergedInterceptorsExecutionOrder option in the createFetchClientWithOptions function.
- Update the plugin initialization configuration to use a base configuration in the callapi module.
- Updated the response to the user's request:  The main goal of the changes is to update the reference from `handleResponseType` to `getResponseType` in the `responseType` property and add a new `Awaitable` type to the `responseParser` property.
- The main goal of the changes is to update the way URL parameters are replaced in the `mergeUrlWithParams` function.
- The main goal of the changes is to add functions for picking and omitting keys from objects, splitting base and regular configurations, generating request keys, and handling response types in a TypeScript file.
- Refactored the isPlainObject function to improve code readability by using prettier-ignore for a specific condition.
- Updated the version in package.json to "1.0.0-rc.30".
- Refactor response handling and cloning logic in createFetchClient function.
- Added a custom function to validate response error data from the API.
- The main goal of the changes is to add a new parameter for validation in the getResponseData function and update the resolveSuccessResult function to use the new data parameter instead of successData.
- Updated the version in the package.json file to "1.0.0-rc.48".
- Refactor response handling to clone only when necessary and simplify data validation and handling.
- The main goal of the changes is to ensure the response is cloned when specific strategies are set to avoid errors from reading the response more than once.
- Added a custom function to validate response error data from the API.
- The main goal of the changes is to add a new parameter for validation in the getResponseData function and update the resolveSuccessResult function to use the new data parameter instead of successData.
@Ryan-Zayne Ryan-Zayne changed the title feat: add dedupe feature, params option, and more feat: add dedupe feature, params option, and more as v1 Dec 7, 2024
@Ryan-Zayne Ryan-Zayne merged commit 8ff8fb0 into main Dec 7, 2024
9 of 10 checks passed
@Ryan-Zayne Ryan-Zayne deleted the feature/dedupe branch December 7, 2024 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant