Skip to content

feat: Next 13 app Dir fetch support! - #315

Merged
michaelangeloio merged 7 commits into
mainfrom
michaelangelo-io/nextFetchSupport
Aug 9, 2023
Merged

feat: Next 13 app Dir fetch support!#315
michaelangeloio merged 7 commits into
mainfrom
michaelangelo-io/nextFetchSupport

Conversation

@michaelangeloio

@michaelangeloio michaelangeloio commented Jul 23, 2023

Copy link
Copy Markdown
Contributor

Fetch Cache Feature

Since cache is officially supported by the Mozilla spec, and Nodejs now also supports the fetch AP, we can add the cache property to our core client.

Nextjs Fetch Feature

TLDR; Nextjs 13.x App Dir fetch features aren't currently supported in the @ts-rest/next package. These are the features:

This basic PR enables that by adding a initNextClient function for consuming clients in @ts-rest/next!

Now users will be able to consume other APIs in a ts-rest safe way with full fetch support, eg:

const c = initContract();
const contract = c.router({
  getUser: {
    method: 'GET',
    path: '/users/:id',
    responses: {
      200: UserSchema,
    },
  },
});

const usersClient = initNextClient(contract, {
  baseHeaders: {},
  baseUrl: 'http://localhost:5002',
});
👇
await usersClient.getUser({ params: { id: '1' }, next: { revalidate: 1, tags: ['user1'] } });

This PR is designed to only enable this for initNextClient and not the regular initClient. This type is inferred through the Framework generic.

Let me know on any feedback you may have! Happy to make any needed changes!

I'll make some documentation after feedback is collected and this PR is merged.

@changeset-bot

changeset-bot Bot commented Jul 23, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f5240f0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@ts-rest/core Minor
@ts-rest/next Minor
@ts-rest/example-contracts Minor
@ts-rest/non-strict-mode-test Minor
@ts-rest/express Minor
@ts-rest/fastify Minor
@ts-rest/nest Minor
@ts-rest/open-api Minor
@ts-rest/react-query Minor
@ts-rest/solid-query Minor

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercel Bot commented Jul 23, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ts-rest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2023 1:30pm

Comment thread libs/ts-rest/core/src/lib/infer-types.ts
@codecov

codecov Bot commented Jul 23, 2023

Copy link
Copy Markdown

Codecov Report

Merging #315 (f5240f0) into main (d122bb7) will decrease coverage by 0.08%.
The diff coverage is 77.77%.

@@            Coverage Diff             @@
##             main     #315      +/-   ##
==========================================
- Coverage   74.23%   74.15%   -0.08%     
==========================================
  Files          21       22       +1     
  Lines         586      592       +6     
  Branches      151      152       +1     
==========================================
+ Hits          435      439       +4     
- Misses        123      124       +1     
- Partials       28       29       +1     
Files Changed Coverage Δ
libs/ts-rest/next/src/lib/next-client.ts 66.66% <66.66%> (ø)
libs/ts-rest/core/src/lib/client.ts 91.07% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@michaelangeloio michaelangeloio changed the title WIP (Next 13 app Dir fetch support!) feat: WIP (Next 13 app Dir fetch support!) Jul 23, 2023
@michaelangeloio michaelangeloio changed the title feat: WIP (Next 13 app Dir fetch support!) feat: Next 13 app Dir fetch support! Aug 8, 2023
@sonarqubecloud

sonarqubecloud Bot commented Aug 8, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Comment thread libs/ts-rest/core/src/lib/client.ts

@oliverbutler oliverbutler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Spotted an issue in example-microservice/web-app (type error) but this seems to be an existing problem not caused by you

@oliverbutler oliverbutler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Spotted an issue in example-microservice/web-app (type error) but this seems to be an existing problem not caused by you

@michaelangeloio
michaelangeloio merged commit a7755ef into main Aug 9, 2023
@github-actions github-actions Bot mentioned this pull request Aug 8, 2023
@michaelangeloio
michaelangeloio deleted the michaelangelo-io/nextFetchSupport branch August 9, 2023 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants