swordjs / sword-framework

A small and flexible for serverless nodejs framework 💗
25 stars 3 forks source link

[RFC-v2.0] Thoughts on type declaration front-to-back synchronization #15

Open seho-dev opened 1 year ago

seho-dev commented 1 year ago

The existing framework is a pure api implementation, we can not give the type declaration file to the front-end, because the front and back-end projects are usually split. Unlike frameworks like tsrpc, which are very simple to synchronize types via soft links, we can take other measures, and the current mainstream solutions are the following:

monorepo, which puts the types into a separate repository create a new branch, and put the type into it provide a repository/npm package to upload the types But all of these approaches require additional technical means, such as using git to manage them, or writing a git action / pipeline to customize the logic of storing types, which is not possible for a single-warehouse project, and is a good idea, but it comes at a price. developers to choose from.

Additions to existing solutions

We will export a type package to the root directory, so that it can be published directly to github/npm, and in the root directory we will agree to a special folder (share/type), but of course you can configure your export path in detail from the share directory in sword.config.ts, for example if your api implementation repository is in a monorepo architecture For example, if your api implementation repository is in a monorepo architecture, you can export the files directly to another subrepository of yours, and of course your export operations can be configured as soft links, which means you don't need to spend extra disk space for this in monorepo.

Extended Solution Additions

If you think the existing solution is still not enough for you, then we have a local network based solution, when we start the api server, a doc server will be opened automatically, and when our proto changes, this doc server will be updated automatically, so what does this doc server do? Our sword.js vscode plugin can download the latest proto to the front-end file in real time by filling in the subscription address, so that the front-end and back-end can get the latest proto seamlessly in the case of intranet/intranet penetration!

Translated with www.DeepL.com/Translator (free version)