Julien-R44 / tuyau

RPC / E2E Client For AdonisJS
https://tuyau.julr.dev
MIT License
83 stars 1 forks source link

Issue with Importing Tuyau Schemas into Next.js #12

Open mohitxskull opened 11 hours ago

mohitxskull commented 11 hours ago

When importing Tuyau schemas into a Next.js project, I encountered errors related to missing types and disallowed decorators. To resolve this, I added the following to my Next.js tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}

And as i am directly importing .ts files i need to add this in next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  transpilePackages: ['@package/name'],
  webpack: (config) => {
    config.resolve.extensionAlias = {
      '.js': ['.ts', '.tsx', '.js', '.jsx'],
      '.mjs': ['.mts', '.mjs'],
      '.cjs': ['.cts', '.cjs'],
    };
    return config;
  },
};

export default nextConfig;

Additionally, I created a ./client/index.ts file in my backend project to export the necessary schemas:

/// <reference path="../adonisrc.ts" />
/// <reference path="../app/validators/custom/index.ts" />
/// <reference path="../config/auth.ts" />

export * from './schema.js'

I believe this approach could be documented in the Tuyau documentation to help other developers facing similar issues.

Julien-R44 commented 7 hours ago

Hey! thanks for the explanations, that’s really cool

I’m not very familiar with Next.JS, so I was wondering if you’d be interested in opening a PR? Ideally with the following things:

That would be amazing to have

Thanks again for the explanation

mohitxskull commented 7 hours ago

Sure, I'd be happy to do that :)

AdonisJS is a beautiful framework, I use it a lot, and I love the work of you people as I regularly dig inside the codebase of AdonisJS and the packages maintained officially by the core team and it helps me learn a lot of things.

Thank you for your work.

As for the PR

Julien-R44 commented 7 hours ago

Are you open to the idea of having a index.ts in ./adonisjs folder and referencing all the required types there rather than doing it in every project you import the api?

What you mean by that? You're including /// references in there ? If so, yeah, absolutely

mohitxskull commented 7 hours ago

Like this, So we just need to simple import the routes on the client side and don't need to do any extra work.

image