Core Concepts
/
Resources & the DSL
Resources & the DSL
Author your data model in TypeScript with the resource() DSL and typed field builders.
View as Markdown
llms.txt
A resource is a named model scoped to an app. Its fields carry types, and those types are the schema — the compiler reads them directly rather than trusting a separate declaration.
resources/airports.ts
ts · copy
1
import
{
resource
,
s
}
from
"rastack/define"
;
2
3
export
const
Airport
=
resource
(
"airports"
,
"airport"
,
{
4
code
:
s
.
string
({
maxLength
:
3
,
unique
:
true
}),
5
name
:
s
.
string
({
maxLength
:
120
}),
6
elevation
:
s
.
int
({
min
:
0
}),
7
active
:
s
.
boolean
({
default
:
true
}),
8
},
{
9
search
:
[
"code"
,
"name"
],
10
admin
:
{
listDisplay
:
[
"code"
,
"name"
]
},
11
});
The signature is resource(app, model, fields, options?). The first two arguments become the URL segments — /api/airports/v1/airport/ — and the field map defines the columns.
Field builders
Every field comes from s.*. Scalars carry a __rastackScalar discriminant and their constraints come from the call arguments:
Builder
Type
Common constraints
s.string()
text
maxLength, unique, default
s.int() · s.float()
number
min, max, unique
s.boolean()
bool
default
s.datetime()
timestamp
autoNow
s.ref(() => Model)
foreign key
nullable
Options
The fourth argument configures behaviour across every surface:
search — fields the changelist and API search over.
admin — how the record renders in the admin site (listDisplay, etc.).
access — row-level security (see Security & Access Control).
sync — opt into local-first replication (see Local-First Sync).
Tip
Prefer no DSL at all? The compiler can infer resources straight from plain TypeScript interfaces — see Interface-Driven Entities.
Build with AI
Every page is available as clean Markdown for LLMs and coding agents. Point one at the files below to build on top of React API Stack.
React API Stack · alpha · built to scale to millions