rizolang 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +430 -2
- package/build/src/ast.d.ts +148 -0
- package/build/src/ast.js +4 -0
- package/build/src/ast.js.map +1 -0
- package/build/src/bin.d.ts +2 -0
- package/build/src/bin.js +8 -0
- package/build/src/bin.js.map +1 -0
- package/build/src/check-api.d.ts +104 -0
- package/build/src/check-api.js +564 -0
- package/build/src/check-api.js.map +1 -0
- package/build/src/checker.d.ts +53 -0
- package/build/src/checker.js +235 -0
- package/build/src/checker.js.map +1 -0
- package/build/src/cli.d.ts +12 -0
- package/build/src/cli.js +170 -0
- package/build/src/cli.js.map +1 -0
- package/build/src/compiler.d.ts +38 -0
- package/build/src/compiler.js +62 -0
- package/build/src/compiler.js.map +1 -0
- package/build/src/diagnostics.d.ts +35 -0
- package/build/src/diagnostics.js +69 -0
- package/build/src/diagnostics.js.map +1 -0
- package/build/src/emit/routes.d.ts +22 -0
- package/build/src/emit/routes.js +316 -0
- package/build/src/emit/routes.js.map +1 -0
- package/build/src/emit/sql.d.ts +11 -0
- package/build/src/emit/sql.js +26 -0
- package/build/src/emit/sql.js.map +1 -0
- package/build/src/emit/typescript.d.ts +13 -0
- package/build/src/emit/typescript.js +77 -0
- package/build/src/emit/typescript.js.map +1 -0
- package/build/src/lexer.d.ts +17 -0
- package/build/src/lexer.js +124 -0
- package/build/src/lexer.js.map +1 -0
- package/build/src/migrations.d.ts +33 -0
- package/build/src/migrations.js +183 -0
- package/build/src/migrations.js.map +1 -0
- package/build/src/parser.d.ts +17 -0
- package/build/src/parser.js +434 -0
- package/build/src/parser.js.map +1 -0
- package/build/src/schema.d.ts +63 -0
- package/build/src/schema.js +151 -0
- package/build/src/schema.js.map +1 -0
- package/build/src/types.d.ts +42 -0
- package/build/src/types.js +77 -0
- package/build/src/types.js.map +1 -0
- package/build/src/version.d.ts +2 -0
- package/build/src/version.js +3 -0
- package/build/src/version.js.map +1 -0
- package/docs/SPEC-COMPACT.md +157 -0
- package/docs/SPEC.md +685 -0
- package/package.json +51 -4
- package/runtime/migrate.ts +131 -0
- package/runtime/password.ts +58 -0
- package/runtime/ratelimit.ts +53 -0
- package/runtime/server.ts +696 -0
- package/runtime/session.ts +50 -0
- package/runtime/types.ts +111 -0
- package/runtime/validate.ts +133 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,431 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Rizo Lang
|
|
4
|
+
|
|
5
|
+
**A modern, simple and secure web language for the AI era.**
|
|
6
|
+
|
|
7
|
+
Write your data models and endpoints in a few readable lines. Rizo Lang compiles them into a PostgreSQL schema, TypeScript types and a ready-to-run Node.js server, with login, validation and permission checks built in.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/chaitanyaaggarwal9/rizolang/actions/workflows/ci.yml)
|
|
10
|
+
[](https://github.com/chaitanyaaggarwal9/rizolang/actions/workflows/codeql.yml)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+

|
|
17
|
+

|
|
18
|
+
[](https://www.npmjs.com/package/rizolang)
|
|
19
|
+
|
|
20
|
+
[Website](https://rizobot.com) · [Language spec](docs/SPEC.md) · [Compact spec for AI](docs/SPEC-COMPACT.md) · [Contributing](CONTRIBUTING.md) · [Security](SECURITY.md)
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Contents
|
|
27
|
+
|
|
28
|
+
- [Why Rizo Lang?](#why-rizo-lang)
|
|
29
|
+
- [A quick look](#a-quick-look)
|
|
30
|
+
- [What the compiler generates](#what-the-compiler-generates)
|
|
31
|
+
- [Getting started](#getting-started)
|
|
32
|
+
- [Language tour](#language-tour)
|
|
33
|
+
- [Security model](#security-model)
|
|
34
|
+
- [Error messages](#error-messages)
|
|
35
|
+
- [Using Rizo Lang with AI](#using-rizo-lang-with-ai)
|
|
36
|
+
- [Project status and roadmap](#project-status-and-roadmap)
|
|
37
|
+
- [Project structure](#project-structure)
|
|
38
|
+
- [Development](#development)
|
|
39
|
+
- [Contributing, security and license](#contributing-security-and-license)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Why Rizo Lang?
|
|
44
|
+
|
|
45
|
+
Most security bugs in web apps are ordinary mistakes:
|
|
46
|
+
- a query built from text,
|
|
47
|
+
- a password returned in a response,
|
|
48
|
+
- an endpoint that forgot to check who is calling,
|
|
49
|
+
- a user editing someone else's data.
|
|
50
|
+
|
|
51
|
+
Rizo Lang is designed so those mistakes **cannot be written**, not just discouraged.
|
|
52
|
+
|
|
53
|
+
| Principle | What it means in practice |
|
|
54
|
+
|-----------|---------------------------|
|
|
55
|
+
| **Dangerous mistakes are impossible** | There is no raw SQL. Every query is generated and parameterized. |
|
|
56
|
+
| **Strict and clear** | Static types everywhere. Every error says what went wrong, where (file:line:column) and how to fix it. |
|
|
57
|
+
| **Small** | The whole language fits in a [short spec](docs/SPEC.md) that an AI can learn from in one read. |
|
|
58
|
+
| **Secure by default** | Passwords are hashed and never returned. Input is validated automatically. Login and ownership are part of the syntax. |
|
|
59
|
+
| **AI-first** | The [compact spec](docs/SPEC-COMPACT.md) works as a system prompt, so even small models can write correct Rizo Lang. |
|
|
60
|
+
|
|
61
|
+
Rizo Lang is part of the [Rizo](https://rizobot.com) ecosystem, alongside **Rizo**, an open-source BYOK AI coding assistant for VS Code. It compiles into technology you already use. Its only runtime is a small, readable library that is copied into your project.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## A quick look
|
|
66
|
+
|
|
67
|
+
```rizo
|
|
68
|
+
// app.rz: a small blog
|
|
69
|
+
auth User by email
|
|
70
|
+
|
|
71
|
+
model User {
|
|
72
|
+
email: Email unique private
|
|
73
|
+
password: Password min 12
|
|
74
|
+
name: Text max 100
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
model Post {
|
|
78
|
+
author: User
|
|
79
|
+
title: Text min 1 max 200
|
|
80
|
+
body: Text
|
|
81
|
+
published: Bool
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
api GET /posts -> list Post.public {
|
|
85
|
+
public
|
|
86
|
+
return db.Post.list(published = true, order title, limit 20)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
api POST /posts -> Post.public {
|
|
90
|
+
requires login
|
|
91
|
+
return db.Post.create(body, author = me)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
api PATCH /posts/:id -> Post.public {
|
|
95
|
+
requires login
|
|
96
|
+
requires owner author
|
|
97
|
+
return db.Post.update(id, body)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
api DELETE /posts/:id {
|
|
101
|
+
requires login
|
|
102
|
+
requires owner author
|
|
103
|
+
return db.Post.delete(id)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
rizolang build app.rz
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
That's a complete backend:
|
|
112
|
+
- **Accounts:** signup, login, logout and sessions.
|
|
113
|
+
- **Validation:** every request body and path parameter is checked against your models.
|
|
114
|
+
- **Ownership:** only a post's author can change or delete it. Everyone else gets 404.
|
|
115
|
+
- **Privacy:** emails and passwords are never returned by any endpoint.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## What the compiler generates
|
|
120
|
+
|
|
121
|
+
`rizolang build app.rz` writes everything to `dist/`:
|
|
122
|
+
|
|
123
|
+
| File | What it is |
|
|
124
|
+
|------|------------|
|
|
125
|
+
| `schema.sql` | PostgreSQL tables with `NOT NULL`, `UNIQUE`, `CHECK` and foreign-key constraints, plus the sessions table |
|
|
126
|
+
| `types.ts` | TypeScript types: `User` (server-only), `UserPublic` (safe to return) and `UserInput` (what clients send) |
|
|
127
|
+
| `routes.ts` | Every endpoint as plain data, **with its SQL written out in full** so you can review exactly what runs |
|
|
128
|
+
| `server.ts` | The entry point: `node server.ts` |
|
|
129
|
+
| `runtime/` | A small Rizo runtime: validation, sessions, password hashing and the HTTP server |
|
|
130
|
+
| `migrate.ts`, `migrations/` | Applies your project's migrations to the database |
|
|
131
|
+
| `package.json`, `tsconfig.json` | Installs the only dependency, the [`pg`](https://www.npmjs.com/package/pg) driver, and type-checks the app |
|
|
132
|
+
|
|
133
|
+
A file with only models (no `auth` or `api`) produces just `schema.sql` and `types.ts`.
|
|
134
|
+
|
|
135
|
+
Part of the `PATCH /posts/:id` route above, as it appears in `routes.ts`:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
{
|
|
139
|
+
method: 'PATCH',
|
|
140
|
+
pattern: '/posts/:id',
|
|
141
|
+
access: 'login',
|
|
142
|
+
sql: 'UPDATE "posts" SET "title" = CASE WHEN $3 THEN $4 ELSE "title" END, ... WHERE "id" = $1 AND "author_id" = $2 RETURNING "id", "author_id" AS "author", ...',
|
|
143
|
+
values: [{ from: 'path', name: 'id' }, { from: 'me' }, ...],
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Getting started
|
|
150
|
+
|
|
151
|
+
### Requirements
|
|
152
|
+
|
|
153
|
+
- **Node.js 22.12+** to run the compiler. The generated server needs **22.18+**, which runs TypeScript directly; Node 24 LTS is recommended.
|
|
154
|
+
- **PostgreSQL 13+**
|
|
155
|
+
|
|
156
|
+
### Install the compiler
|
|
157
|
+
|
|
158
|
+
Rizo Lang is on npm as [`rizolang`](https://www.npmjs.com/package/rizolang):
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
npx rizolang build app.rz # run without installing
|
|
162
|
+
npm install --save-dev rizolang # or add it to your project
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
To build from source instead:
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
git clone https://github.com/chaitanyaaggarwal9/rizolang.git
|
|
169
|
+
cd rizolang
|
|
170
|
+
npm ci
|
|
171
|
+
npm run build
|
|
172
|
+
npm link # optional: makes the `rizolang` command available everywhere
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Build and run an app
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
npx rizolang build app.rz
|
|
179
|
+
cd dist
|
|
180
|
+
npm install
|
|
181
|
+
export DATABASE_URL=postgres://user:pass@localhost:5432/app
|
|
182
|
+
node migrate.ts
|
|
183
|
+
node server.ts
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- `npm install` installs `pg`, the only dependency.
|
|
187
|
+
- `node migrate.ts` creates or updates the tables.
|
|
188
|
+
|
|
189
|
+
When you change your models, run `rizolang build` again. It writes the change as a new file in `migrations/` (commit that folder), and `node migrate.ts` applies it.
|
|
190
|
+
|
|
191
|
+
Changes that would delete data are refused unless you add `--allow-data-loss`. That covers removing a field or model, changing a field's type, and removing a role.
|
|
192
|
+
|
|
193
|
+
### Try it
|
|
194
|
+
|
|
195
|
+
```sh
|
|
196
|
+
# Sign up (this also logs you in; curl keeps the session cookie in ./jar)
|
|
197
|
+
curl -c jar -H 'Content-Type: application/json' \
|
|
198
|
+
-d '{"email":"ann@example.com","password":"correct horse battery","name":"Ann"}' \
|
|
199
|
+
http://127.0.0.1:3000/auth/signup
|
|
200
|
+
|
|
201
|
+
# Create a post as Ann
|
|
202
|
+
curl -b jar -H 'Content-Type: application/json' \
|
|
203
|
+
-d '{"title":"Hello","body":"First post","published":true}' \
|
|
204
|
+
http://127.0.0.1:3000/posts
|
|
205
|
+
|
|
206
|
+
# Anyone can list published posts, one page at a time
|
|
207
|
+
curl 'http://127.0.0.1:3000/posts?limit=10'
|
|
208
|
+
# → { "items": [...], "next": "<cursor>" }; get the next page with ?limit=10&after=<cursor>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
> Session cookies are marked `Secure`, so they are only sent over https. Browsers and curl treat `localhost` and `127.0.0.1` as secure, so the steps above work locally as written. Only if you test over plain http on another host, start the server with `RIZO_DEV_INSECURE_COOKIES=1`. Never use this setting in production.
|
|
212
|
+
|
|
213
|
+
### Configuration
|
|
214
|
+
|
|
215
|
+
| Variable | Default | Meaning |
|
|
216
|
+
|----------|---------|---------|
|
|
217
|
+
| `DATABASE_URL` | (required) | PostgreSQL connection string |
|
|
218
|
+
| `PORT` / `HOST` | `3000` / `127.0.0.1` | Where the server listens |
|
|
219
|
+
| `RIZO_ALLOWED_ORIGINS` | none | Extra origins allowed to send POST, PUT, PATCH or DELETE requests (comma-separated) |
|
|
220
|
+
| `RIZO_TRUST_PROXY` | off | `1` to read the client IP from `X-Forwarded-For` (only behind a trusted proxy) |
|
|
221
|
+
| `RIZO_DB_POOL_SIZE` | `10` | Maximum number of database connections |
|
|
222
|
+
| `RIZO_ADMIN_EMAILS` | none | Makes these **existing** accounts admins at startup (sign up first) |
|
|
223
|
+
| `RIZO_DEV_INSECURE_COOKIES` | off | `1` to allow cookies over http. For local development only |
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Language tour
|
|
228
|
+
|
|
229
|
+
The [full spec](docs/SPEC.md) is the reference. This is the short version.
|
|
230
|
+
|
|
231
|
+
### Models and field types
|
|
232
|
+
|
|
233
|
+
```rizo
|
|
234
|
+
model User {
|
|
235
|
+
email: Email unique private
|
|
236
|
+
password: Password min 12
|
|
237
|
+
name: Text max 100
|
|
238
|
+
age: Number min 0 optional
|
|
239
|
+
isAdmin: Bool
|
|
240
|
+
birthday: Date optional
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
| Type | Stores | Notes |
|
|
245
|
+
|------|--------|-------|
|
|
246
|
+
| `Text` | text | At most 10,000 characters unless you set `max` |
|
|
247
|
+
| `Number` | whole number (32-bit) | Use cents for money |
|
|
248
|
+
| `Bool` | `true` / `false` | |
|
|
249
|
+
| `Email` | email address | Trimmed, lowercased and checked |
|
|
250
|
+
| `Password` | salted scrypt hash | Never stored as plain text and never returned |
|
|
251
|
+
| `Date` | date and time (UTC) | ISO 8601 in JSON |
|
|
252
|
+
| `ID` | UUID | |
|
|
253
|
+
| *a model name* | a link, e.g. `author: User` | A foreign key to that model |
|
|
254
|
+
|
|
255
|
+
Every model gets an `id` automatically.
|
|
256
|
+
|
|
257
|
+
**Modifiers:**
|
|
258
|
+
- `unique`: no two records share the value.
|
|
259
|
+
- `optional`: the value may be missing.
|
|
260
|
+
- `private`: stored, but never returned.
|
|
261
|
+
- `min N` / `max N`: the length for text, the value for numbers.
|
|
262
|
+
|
|
263
|
+
### Login
|
|
264
|
+
|
|
265
|
+
```rizo
|
|
266
|
+
auth User by email
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
This one line adds signup, login and logout (`/auth/signup`, `/auth/login`, `/auth/logout`), plus account management:
|
|
270
|
+
- `GET` and `PATCH /auth/me` to read and edit your profile,
|
|
271
|
+
- `POST /auth/password` to change your password, which logs out your other sessions,
|
|
272
|
+
- `POST /auth/logout-all` to log out everywhere,
|
|
273
|
+
- `DELETE /auth/me` to delete your account.
|
|
274
|
+
|
|
275
|
+
Changing the password and deleting the account need the current password.
|
|
276
|
+
|
|
277
|
+
Add roles with `auth User by email roles admin, editor`, then protect endpoints with `requires role admin`, or with `requires owner author or role admin` so admins can act on anyone's records. Admins assign roles through `PUT /auth/users/:id/role`. To make the first admin, sign up, then restart the server with `RIZO_ADMIN_EMAILS=you@example.com`.
|
|
278
|
+
|
|
279
|
+
**Built in:**
|
|
280
|
+
- Secure session cookies, with only a hash of each token stored in the database.
|
|
281
|
+
- Rate limits on login and signup.
|
|
282
|
+
- The same response for a wrong password and an unknown account, so callers can't find out which emails are registered.
|
|
283
|
+
|
|
284
|
+
### Endpoints
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
api <METHOD> <path> -> Model.public {
|
|
288
|
+
public | requires login
|
|
289
|
+
requires role admin, editor // optional
|
|
290
|
+
requires owner <link field> // optional; "or role admin" lets admins act too
|
|
291
|
+
return db.Model.<action>(...)
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
| Action | Method | Example |
|
|
296
|
+
|--------|--------|---------|
|
|
297
|
+
| `find` | GET | `db.Post.find(id)` |
|
|
298
|
+
| `list` | GET | `db.Post.list(author = me, order title desc, limit 20)`, which returns pages: `{ "items": [...], "next": "<cursor>" }` |
|
|
299
|
+
| `create` | POST | `db.Post.create(body, author = me)` |
|
|
300
|
+
| `update` | PUT / PATCH | `db.Post.update(id, body)` |
|
|
301
|
+
| `delete` | DELETE | `db.Post.delete(id)` |
|
|
302
|
+
|
|
303
|
+
The compiler enforces these rules:
|
|
304
|
+
- Every endpoint must say `public` or `requires login`. There is no default.
|
|
305
|
+
- Endpoints can only return `.public` views.
|
|
306
|
+
- A record's owner is always `me`, the logged-in user. It is never taken from the request body.
|
|
307
|
+
- `requires owner author` is enforced inside the SQL query, so someone else's record looks exactly like a missing one.
|
|
308
|
+
- `GET` endpoints can never change data.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Security model
|
|
313
|
+
|
|
314
|
+
| Threat | How Rizo Lang prevents it |
|
|
315
|
+
|--------|---------------------------|
|
|
316
|
+
| SQL injection | All SQL is written at compile time. Request data only fills `$1, $2, …` parameters. |
|
|
317
|
+
| Leaking passwords or private data | Password and `private` fields are never selected for responses, and the runtime copies only public keys. |
|
|
318
|
+
| Plain-text or weak passwords | scrypt with a random salt. A minimum length of 8, and you can only raise it. |
|
|
319
|
+
| Missing login checks | Every endpoint must declare `public` or `requires login`. |
|
|
320
|
+
| Privilege escalation | Roles are never accepted from requests. Only admins assign them, never to themselves. `RIZO_ADMIN_EMAILS` only promotes accounts that already exist. |
|
|
321
|
+
| Editing someone else's data (IDOR) | `requires owner` becomes part of the `WHERE` clause. Owners are set from the session. |
|
|
322
|
+
| Mass assignment | Unknown body fields are rejected. Ownership links are never accepted from clients. |
|
|
323
|
+
| CSRF | `SameSite=Lax` cookies, JSON-only bodies and an `Origin` check on every POST, PUT, PATCH and DELETE. |
|
|
324
|
+
| Brute force | Rate limits on login and signup. |
|
|
325
|
+
| Account enumeration at login | Identical responses and timing for an unknown account and a wrong password. |
|
|
326
|
+
| Accidental data loss | Migrations that would drop data are refused unless you pass `--allow-data-loss`. Each migration runs in a transaction, and edited migrations are detected. |
|
|
327
|
+
| Leaky logs | Logs contain only the method, route pattern, status, time and request id. |
|
|
328
|
+
| Clickjacking and sniffing | A strict CSP, plus `X-Frame-Options: DENY`, `nosniff` and `no-store` on every response. |
|
|
329
|
+
|
|
330
|
+
Every guarantee is tested, in [`tests/security.test.ts`](tests/security.test.ts) and in the end-to-end suite [`tests/e2e.test.ts`](tests/e2e.test.ts), which attacks a real server backed by PostgreSQL. Found a hole? Please [report it privately](SECURITY.md).
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Error messages
|
|
335
|
+
|
|
336
|
+
Every error has a code, an exact location and a concrete fix. Real output from `rizolang build`:
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
app.rz:14:5 error RZ0318: Endpoint "GET /posts" does not say who may call it.
|
|
340
|
+
14 | api GET /posts -> list Post.public {
|
|
341
|
+
| ^^^
|
|
342
|
+
fix: Add `requires login` for logged-in users only, or `public` if anyone may call it.
|
|
343
|
+
|
|
344
|
+
app.rz:20:18 error RZ0326: "Post.author" links to the auth model, so the server must set it.
|
|
345
|
+
20 | return db.Post.create(body)
|
|
346
|
+
| ^^^^^^
|
|
347
|
+
fix: Write `db.Post.create(body, author = me)`. Otherwise a client could create records owned by someone else.
|
|
348
|
+
|
|
349
|
+
Build failed with 2 errors. No files were written.
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
The full list of error codes is in the [spec](docs/SPEC.md#8-errors).
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Using Rizo Lang with AI
|
|
357
|
+
|
|
358
|
+
Rizo Lang is designed to be written by AI models as well as people:
|
|
359
|
+
- [`docs/SPEC-COMPACT.md`](docs/SPEC-COMPACT.md) is under 1,500 words. Paste it into any model's system prompt.
|
|
360
|
+
- Error messages include a `fix:` line that a model can apply directly.
|
|
361
|
+
- The Rizo VS Code extension ([rizobot.com](https://rizobot.com)) will detect `.rz` files and load the spec automatically.
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Project status and roadmap
|
|
366
|
+
|
|
367
|
+
Rizo Lang is in **early development**, so expect the language to change before 1.0.
|
|
368
|
+
|
|
369
|
+
- [x] **Milestone 1:** models, compiled to a PostgreSQL schema and TypeScript types ([v0.1.0](https://github.com/chaitanyaaggarwal9/rizolang/releases/tag/v0.1.0))
|
|
370
|
+
- [x] **Milestone 2:** `auth`, `api` endpoints, links, `private` fields and a generated Node.js server ([v0.2.0](https://github.com/chaitanyaaggarwal9/rizolang/releases/tag/v0.2.0))
|
|
371
|
+
- [x] **Milestone 3:** roles, pagination, account management and migrations ([v0.3.1](https://github.com/chaitanyaaggarwal9/rizolang/releases/tag/v0.3.1))
|
|
372
|
+
- [ ] **Milestone 4:** frontend `page` blocks compiled to HTML and TypeScript
|
|
373
|
+
- [x] Publish the compiler to npm ([`rizolang`](https://www.npmjs.com/package/rizolang))
|
|
374
|
+
- [ ] A VS Code extension with syntax highlighting
|
|
375
|
+
|
|
376
|
+
See [CHANGELOG.md](CHANGELOG.md) for what changed in each version.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Project structure
|
|
381
|
+
|
|
382
|
+
```
|
|
383
|
+
rizolang/
|
|
384
|
+
├── src/ # the compiler
|
|
385
|
+
│ ├── lexer.ts # source text → tokens
|
|
386
|
+
│ ├── parser.ts # tokens → syntax tree (hand-written recursive descent)
|
|
387
|
+
│ ├── checker.ts # models: types, modifiers, links, names
|
|
388
|
+
│ ├── check-api.ts # auth and api: access, ownership, queries
|
|
389
|
+
│ ├── emit/ # SQL, TypeScript types and routes
|
|
390
|
+
│ └── cli.ts # `rizolang build`
|
|
391
|
+
├── runtime/ # copied into every generated app (validation, sessions, server)
|
|
392
|
+
├── tests/ # unit, security, docs and end-to-end tests
|
|
393
|
+
├── docs/ # SPEC.md and SPEC-COMPACT.md
|
|
394
|
+
└── examples/blog.rz # a complete example app
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Development
|
|
400
|
+
|
|
401
|
+
```sh
|
|
402
|
+
npm ci # install the exact locked dependencies
|
|
403
|
+
npm test # run all tests (end-to-end tests are skipped without a database)
|
|
404
|
+
npm run typecheck # strict type checking
|
|
405
|
+
npm run build # compile the compiler to build/
|
|
406
|
+
|
|
407
|
+
# Run the end-to-end tests against a PostgreSQL database you control.
|
|
408
|
+
# They create and drop their own temporary schema.
|
|
409
|
+
RIZO_TEST_DATABASE_URL=postgres://user:pass@localhost:5432/dev npm test
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
The compiler has **zero runtime dependencies**, and every dev dependency is pinned to an exact version. CI runs:
|
|
413
|
+
- the tests on Node 22, 24 and 26,
|
|
414
|
+
- the end-to-end suite and a real server against PostgreSQL 17,
|
|
415
|
+
- CodeQL,
|
|
416
|
+
- dependency review.
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## Contributing, security and license
|
|
421
|
+
|
|
422
|
+
- **Contributing:** contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md), and propose language changes in an issue first.
|
|
423
|
+
- **Code of Conduct:** this project follows the [Contributor Covenant](CODE_OF_CONDUCT.md).
|
|
424
|
+
- **Security:** please report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md).
|
|
425
|
+
- **License:** [Apache License 2.0](LICENSE).
|
|
426
|
+
|
|
427
|
+
<div align="center">
|
|
428
|
+
|
|
429
|
+
Made for the [Rizo](https://rizobot.com) ecosystem.
|
|
430
|
+
|
|
431
|
+
</div>
|