0.3.9 ā€¢ Published 9 months ago

@tsdl/core v0.3.9

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

//: <> (AUTO GENERATED - DO NOT EDIT ME. EDIT README IN PROJECT ROOT)

TSDL core utils and types

@tsdl/bun, @tsdl/client, @tsdl/core, @tsdl/dashboard, @tsdl/express, @tsdl/gui, @tsdl/node, @tsdl/react-query, @tsdl/server, @tsdl/tree


TSDL, short for Type-Safe Data Layer, is a transport layer designed to blur the line between client and server side. TSDL is an end-to-end http communication framework that makes your backend a type-safe library for your frontend.

šŸ‘‰ Installation

Example code

Server side

const router = tsdl.router({
   auth: tsdl.router({
      login: tsdl // āœ“ structured and nestable routes, easily refactored
         .use(logger) // āœ“ reusable and powerful middleware support
         .use(cors)
         .input(loginSchema) // āœ“ Zod, Ajv, Joi, Yup etc. or custom
         .query(async ({ input }) => {
            input.username // āœ“ type inferred and input schema validated
            const user = await db.findOne({
               where: { username: input.username }
            });

            if (!user) {
               // āœ“ consistent and simple error handling
               throw new TSDLError(404, "oops");
            }
            // āœ“ return any JS value to the client
            return user;
         }),
   }),
});

Client side

const onSubmit = async () => {
   try {
      const result = await tsdl.auth.login({
         username: form.username, // āœ“ write with confidence, inputs are type safe
      });

      // āœ“ correctly inferred JSON serialized type
      console.log(result);
   } catch(e) {
      // (e is unknown by default, this is just for type inference)
      if (e instanceof TSDLError) {
         // āœ“ handle errors with confidence and consistency
         console.log(e.message); // "oops"
         console.log(e.code); // "Not Found"
         console.log(e.numberCode); // 404
      }
   }
}

Ready to dive in? Getting started guide

Links

Features

Replaces

  • Rest APIs
  • Express/Koa/Nest etc.
  • GraphQL

Introduces

Contributing

TSDL is developed as a monorepo using Nx for cloud runs and caching as well as Lerna for package linking and publishing.

  1. Clone the repository
    git clone https://github.com/asplunds/tsdl.git tsdl
  2. Install dependencies (also initializes husky, & symlinks packages)
    npm i
  3. Start hacking! Unit tests are located in /tests. For playing, use /playground (it's git ignored but included in workspaces). You can find examples in /examples.

Docs (nextra)

  1. cd meta/docs
  2. npm run dev (assuming dependencies are installed)
  3. npm run build check that it builds
  4. npm run start preview

Publishing (access only)

Publish npm packages

  1. Run lints, build packages, bump package versions and publish
    npm run release

Detecting circular dependencies

If you suspect you have caused a circular dependency (easily done in monorepos), you can run npx madge -c in the project root.

Deploying documentation

Merge into branch preview (for preview) or branch docs for live. The CI/CD workflows will automatically build the Nextra documentation site and deploy it to Cloudflare.

Credits

TSDL was originally created by the developers at Enter Technologies, it's used internally on projects such as GyRank and markanvisning.se but was later open sourced.


This README is auto-generated

0.3.9

9 months ago

0.3.0

10 months ago

0.3.8

9 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.1.30

11 months ago

0.1.31

11 months ago

0.1.32

11 months ago

0.1.33

11 months ago

0.2.0

11 months ago

0.2.6

11 months ago

0.2.5

11 months ago

0.1.29

11 months ago

0.1.27

11 months ago

0.1.23

11 months ago

0.1.22

12 months ago

0.1.16

12 months ago

0.1.15

12 months ago

0.1.14

12 months ago

0.1.13

12 months ago

0.1.8

12 months ago

0.1.6

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago

0.0.11

12 months ago

0.0.10

12 months ago