ProductPromotion
Logo

Java.Script

made by https://0x3d.site

GitHub - remult/remult: Full-stack CRUD, simplified, with SSOT TypeScript entities
Full-stack CRUD, simplified, with SSOT TypeScript entities - remult/remult
Visit Site

GitHub - remult/remult: Full-stack CRUD, simplified, with SSOT TypeScript entities

GitHub - remult/remult: Full-stack CRUD, simplified, with SSOT TypeScript entities

What is Remult?

Remult uses TypeScript entities as a single source of truth for: ✅ CRUD + Realtime API, ✅ frontend type-safe API client, and ✅ backend ORM.

  • :zap: Zero-boilerplate CRUD + Realtime API with paging, sorting, and filtering
  • :ok_hand: Fullstack type-safety for API queries, mutations and RPC, without code generation
  • :sparkles: Input validation, defined once, runs both on the backend and on the frontend for best UX
  • :lock: Fine-grained code-based API authorization
  • :relieved: Incrementally adoptable

Remult supports all major databases, including: PostgreSQL, MySQL, SQLite, MongoDB, MSSQL and Oracle.

Remult is frontend and backend framework agnostic and comes with adapters for Express, Fastify, Next.js, Nuxt, SvelteKit, SolidStart, Nest, Koa, Hapi and Hono.

Want to experience Remult firsthand? Try our interactive online tutorial.

Remult promotes a consistent query syntax for both frontend and Backend code:

// Frontend - GET: /api/products?_limit=10&unitPrice.gt=5,_sort=name
// Backend  - 'select name, unitPrice from products where unitPrice > 5 order by name limit 10'
await repo(Product).find({
  limit: 10,
  orderBy: {
    name: 'asc',
  },
  where: {
    unitPrice: { $gt: 5 },
  },
})

// Frontend - PUT: '/api/products/product7' (body: { "unitPrice" : 7 })
// Backend  - 'update products set unitPrice = 7 where id = product7'
await repo(Product).update('product7', { unitPrice: 7 })

Usage

Define schema in code

// shared/product.ts

import { Entity, Fields } from 'remult'

@Entity('products', {
  allowApiCrud: true,
})
export class Product {
  @Fields.cuid()
  id = ''

  @Fields.string()
  name = ''

  @Fields.number()
  unitPrice = 0
}

👉 Don't like decorators? we have full support for Working without decorators

Add backend API with a single line of code

Example:

// backend/index.ts

import express from 'express'
import { remultExpress } from 'remult/remult-express' // adapters for: Fastify,Next.js, Nuxt, SvelteKit, SolidStart, Nest, more...
import { createPostgresDataProvider } from 'remult/postgres' // supported: PostgreSQL, MySQL, SQLite, MongoDB, MSSQL and Oracle
import { Product } from '../shared/product'

const app = express()

app.use(
  remultExpress({
    entities: [Product],
    dataProvider: createPostgresDataProvider({
      connectionString: 'postgres://user:password@host:5432/database"',
    }),
  }),
)

app.listen()

Remult adds route handlers for a fully functional REST API and realtime live-query endpoints, optionally including an Open API spec and a GraphQL endpoint

Fetch data with type-safe frontend code

const [products, setProducts] = useState<Product[]>([])

useEffect(() => {
  repo(Product)
    .find({
      limit: 10,
      orderBy: {
        name: 'asc',
      },
      where: {
        unitPrice: { $gt: 5 },
      },
    })
    .then(setProducts)
}, [])

:mega: Realtime Live Queries

useEffect(() => {
  return repo(Product)
    .liveQuery({
      limit: 10,
      orderBy: {
        name: 'asc',
      },
      where: {
        unitPrice: { $gt: 5 },
      },
    })
    .subscribe((info) => {
      setProducts(info.applyChanges)
    })
}, [])

:ballot_box_with_check: Data validation and constraints - defined once

import { Entity, Fields, Validators } from 'remult'

@Entity('products', {
  allowApiCrud: true,
})
export class Product {
  @Fields.cuid()
  id = ''

  @Fields.string({
    validate: Validators.required,
  })
  name = ''

  @Fields.number<Product>({
    validate: (product) => product.unitPrice > 0 || 'must be greater than 0',
  })
  unitPrice = 0
}

Enforced in frontend:

try {
  await repo(Product).insert({ name: '', unitPrice: -1 })
} catch (e: any) {
  console.error(e)
  /* Detailed error object ->
{
  "modelState": {
    "name": "Should not be empty",
    "unitPrice": "must be greater than 0"
  },
  "message": "Name: Should not be empty"
}
*/
}

Enforced in backend:

// POST '/api/products' BODY: { "name":"", "unitPrice":-1 }
// Response: status 400, body:
{
  "modelState": {
    "name": "Should not be empty",
    "unitPrice": "must be greater than 0"
  },
  "message": "Name: Should not be empty"
}

:lock: Secure the API with fine-grained authorization

@Entity<Article>('Articles', {
  allowApiRead: true,
  allowApiInsert: Allow.authenticated,
  allowApiUpdate: (article) => article.author == remult.user.id,
  apiPrefilter: () => {
    if (remult.isAllowed('admin')) return {}
    return {
      author: remult.user.id,
    }
  },
})
export class Article {
  @Fields.string({ allowApiUpdate: false })
  slug = ''

  @Fields.string({ allowApiUpdate: false })
  authorId = remult.user!.id

  @Fields.string()
  content = ''
}

:rocket: Relations

await repo(Categories).find({
  orderBy: {
    name: 'asc ',
  },
  include: {
    products: {
      where: {
        unitPrice: { $gt: 5 },
      },
    },
  },
})

// Entity Definitions
export class Product {
  //...
  @Relations.toOne(Category)
  category?: Category
}
export class Category {
  //...
  @Relations.toMany<Category, Product>(() => Product, `category`)
  products?: Product[]
}

Automatic admin UI

Automatic admin UI

What about complex CRUD?

While simple CRUD shouldn’t require any backend coding, using Remult means having the ability to handle any complex scenario by controlling the backend in numerous ways:

  • Backend computed (read-only) fields - from simple expressions to complex data lookups or even direct db access (SQL)
  • Custom side-effects with entity lifecycle hooks (before/after saving/deleting)
  • Backend only updatable fields (e.g. “last updated at”)
  • Relations
  • Roll-your-own type-safe endpoints with Backend Methods
  • Roll-your-own low-level endpoints (Express, Fastify, koa, others…)

Installation

The remult package is one and the same for both the frontend bundle and the backend. Install it once for a monolith project or per-repo in a monorepo.

npm i remult

Tutorials

The best way to learn Remult is by following a tutorial of a simple Todo web app with a Node.js Express backend.

Demo

Documentation

The documentation covers the main features of Remult. However, it is still a work-in-progress.

Example Apps

Status

Remult is production-ready and, in fact, used in production apps since 2018. However, we’re keeping the major version at zero so we can use community feedback to finalize the v1 API.

Motivation

Full-stack web development is (still) too complicated. Simple CRUD, a common requirement of any business application, should be simple to build, maintain, and extend when the need arises.

Remult abstracts away repetitive, boilerplate, error-prone, and poorly designed code on the one hand, and enables total flexibility and control on the other. Remult helps building fullstack apps using only TypeScript code you can easily follow and safely refactor, and fits nicely into any existing or new project by being minimalistic and completely unopinionated regarding the developer’s choice of other frameworks and tools.

Other frameworks tend to fall into either too much abstraction (no-code, low-code, BaaS) or partial abstraction (MVC frameworks, GraphQL, ORMs, API generators, code generators), and tend to be opinionated regarding the development tool-chain, deployment environment, configuration/conventions or DSL. Remult attempts to strike a better balance.

Contributing

Contributions are welcome. See CONTRIBUTING.md.

  • :speech_balloon: Any feedback or suggestions? Start a discussion.
  • :muscle: Want to help out? Look for "help wanted" labeled issues.
  • :star: Give this repo a star.

License

Remult is MIT Licensed.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory