rizolang 0.0.0-stage → 0.2.0

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.
Files changed (53) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +399 -2
  3. package/build/src/ast.d.ts +133 -0
  4. package/build/src/ast.js +4 -0
  5. package/build/src/ast.js.map +1 -0
  6. package/build/src/bin.d.ts +2 -0
  7. package/build/src/bin.js +8 -0
  8. package/build/src/bin.js.map +1 -0
  9. package/build/src/check-api.d.ts +97 -0
  10. package/build/src/check-api.js +506 -0
  11. package/build/src/check-api.js.map +1 -0
  12. package/build/src/checker.d.ts +53 -0
  13. package/build/src/checker.js +235 -0
  14. package/build/src/checker.js.map +1 -0
  15. package/build/src/cli.d.ts +11 -0
  16. package/build/src/cli.js +94 -0
  17. package/build/src/cli.js.map +1 -0
  18. package/build/src/compiler.d.ts +36 -0
  19. package/build/src/compiler.js +61 -0
  20. package/build/src/compiler.js.map +1 -0
  21. package/build/src/diagnostics.d.ts +35 -0
  22. package/build/src/diagnostics.js +69 -0
  23. package/build/src/diagnostics.js.map +1 -0
  24. package/build/src/emit/routes.d.ts +20 -0
  25. package/build/src/emit/routes.js +246 -0
  26. package/build/src/emit/routes.js.map +1 -0
  27. package/build/src/emit/sql.d.ts +12 -0
  28. package/build/src/emit/sql.js +83 -0
  29. package/build/src/emit/sql.js.map +1 -0
  30. package/build/src/emit/typescript.d.ts +13 -0
  31. package/build/src/emit/typescript.js +74 -0
  32. package/build/src/emit/typescript.js.map +1 -0
  33. package/build/src/lexer.d.ts +17 -0
  34. package/build/src/lexer.js +124 -0
  35. package/build/src/lexer.js.map +1 -0
  36. package/build/src/parser.d.ts +17 -0
  37. package/build/src/parser.js +399 -0
  38. package/build/src/parser.js.map +1 -0
  39. package/build/src/types.d.ts +42 -0
  40. package/build/src/types.js +77 -0
  41. package/build/src/types.js.map +1 -0
  42. package/build/src/version.d.ts +2 -0
  43. package/build/src/version.js +3 -0
  44. package/build/src/version.js.map +1 -0
  45. package/docs/SPEC-COMPACT.md +148 -0
  46. package/docs/SPEC.md +597 -0
  47. package/package.json +48 -4
  48. package/runtime/password.ts +58 -0
  49. package/runtime/ratelimit.ts +53 -0
  50. package/runtime/server.ts +449 -0
  51. package/runtime/session.ts +48 -0
  52. package/runtime/types.ts +76 -0
  53. package/runtime/validate.ts +133 -0
package/docs/SPEC.md ADDED
@@ -0,0 +1,597 @@
1
+ # Rizo Lang Specification
2
+
3
+ Version 0.2 (draft) · Milestone 2: models, auth and APIs
4
+
5
+ Rizo Lang is a secure, simple, full-stack web language. Source files end in `.rz`. The compiler, `rizolang`, turns Rizo Lang into existing technology: a PostgreSQL schema, TypeScript types and a Node.js server. HTML and TypeScript frontends come later.
6
+
7
+ This document is the complete language reference. It is written for people and for AI models alike. If something is not described here, it is not part of the language.
8
+
9
+ > **Status:** `model`, `auth` and `api` blocks are available. `page` and other blocks are planned but are **not** available yet. Using them is a compile error (RZ0211).
10
+
11
+ ---
12
+
13
+ ## 1. Design rules
14
+
15
+ 1. **Dangerous mistakes are impossible, not just unlikely.** There is no raw SQL and no way to build a query from text.
16
+ 2. **Strict and clear.** Every value has a static type. Every error says what went wrong, where and how to fix it.
17
+ 3. **Small.** The whole language fits in this document.
18
+ 4. **Secure by default.**
19
+ - Passwords are hashed automatically and can never be returned in an API response or logged.
20
+ - Inputs are validated automatically.
21
+ - Login and ownership checks are part of the syntax.
22
+
23
+ ---
24
+
25
+ ## 2. Files and basic syntax
26
+
27
+ - A source file is UTF-8 text with the extension `.rz`.
28
+ - A file contains `model` blocks, at most one `auth` line, and `api` blocks, in any order.
29
+ - Comments start with `//` and run to the end of the line. A comment after a path needs a space before it.
30
+ - Whitespace separates tokens. Indentation has no meaning, but two spaces are conventional.
31
+ - **One item per line.** Each field, and each statement in an `api` block, goes on its own line. Commas appear only between query arguments.
32
+ - Names contain only ASCII letters and digits and start with a letter. Underscores and hyphens are not allowed in names.
33
+ - Numbers are whole numbers, optionally negative: `100`, `0`, `-5`. Decimals are not allowed.
34
+ - There are no quoted strings.
35
+ - Lines and columns in error messages start at 1. A tab counts as one column.
36
+
37
+ ---
38
+
39
+ ## 3. Models
40
+
41
+ A model describes one kind of record stored in the database.
42
+
43
+ ```rizo
44
+ model User {
45
+ email: Email unique private
46
+ password: Password
47
+ name: Text max 100
48
+ }
49
+
50
+ model Post {
51
+ author: User
52
+ title: Text max 200
53
+ published: Bool
54
+ }
55
+ ```
56
+
57
+ - A model starts with the lowercase keyword `model`, then a PascalCase name, then `{`. It ends with `}`.
58
+ - A model has at least one field. Model names are unique in a file, and field names are unique in a model.
59
+ - A field is written `name: Type` followed by zero or more modifiers, all on one line.
60
+ - Every model automatically gets an `id: ID` field (a UUID generated by the database). **Do not declare `id`.**
61
+
62
+ ### 3.1 Field types
63
+
64
+ | Type | Meaning | PostgreSQL | TypeScript | Modifiers allowed |
65
+ |------------|-----------------------------------------------|---------------|----------------|--------------------------------------|
66
+ | `Text` | Text. At most 10,000 characters by default. | `TEXT` | `string` | unique, optional, private, min, max |
67
+ | `Number` | Whole number, −2147483648 to 2147483647. | `INTEGER` | `number` | unique, optional, private, min, max |
68
+ | `Bool` | `true` or `false`. | `BOOLEAN` | `boolean` | optional, private |
69
+ | `Email` | Email address, 3–254 chars, stored lowercase. | `TEXT` | `string` | unique, optional, private, min, max |
70
+ | `Password` | Stored only as a salted hash. | `TEXT` (`<name>_hash`) | `PasswordHash` | optional, min, max |
71
+ | `Date` | Date and time, in UTC. | `TIMESTAMPTZ` | `Date` | unique, optional, private |
72
+ | `ID` | A UUID. | `UUID` | `string` | unique, optional, private |
73
+ | *Model* | A link to a record of that model. | `UUID` (`<name>_id`) + foreign key | `string` | unique, optional, private |
74
+
75
+ - `Number` is for whole numbers. Store money as cents.
76
+ - `Email` values are trimmed and lowercased. They must look like `name@domain.tld`.
77
+ - `Password`:
78
+ - The plain-text password is never stored. `password` is stored as `password_hash`.
79
+ - `min` and `max` limit the plain-text length. The defaults are 8 and 128, and you can only tighten them.
80
+ - A field named `password`, `passwd`, `pwd`, `passcode` or `passphrase`, or ending in `Password`, `Passwd`, `Passcode` or `Passphrase`, must have the type `Password`.
81
+ - **Links:** a field whose type is another model's name, such as `author: User`.
82
+ - It stores that record's id in the column `<name>_id`, with a foreign key and an index.
83
+ - Models may link in any order, and a model may link to itself.
84
+ - A required link cannot point to a record that doesn't exist. A record that others link to cannot be deleted.
85
+ - When the linked record is deleted, an optional link becomes `null`.
86
+
87
+ ### 3.2 Modifiers
88
+
89
+ Modifiers come after the type, on the same line, in any order, each at most once.
90
+
91
+ | Modifier | Meaning |
92
+ |------------|------------------------------------------------------------------------------------------------|
93
+ | `unique` | No two records may have the same value. |
94
+ | `optional` | The value may be missing (`null`). Without it, the field is required. |
95
+ | `private` | Stored and accepted as input, but **never returned** by any endpoint, and not allowed in filters or ordering. |
96
+ | `min N` | Text, Email, Password: minimum length in characters. Number: minimum value. |
97
+ | `max N` | Text, Email, Password: maximum length in characters. Number: maximum value. |
98
+
99
+ | Type | Default min | Default max | Allowed range for `min`/`max` |
100
+ |------------|-------------|-------------|-------------------------------|
101
+ | `Text` | none | 10000 | 0 to 1000000 (`max` ≥ 1) |
102
+ | `Email` | 3 | 254 | 3 to 254 |
103
+ | `Password` | 8 | 128 | 8 to 128 |
104
+ | `Number` | none | none | −2147483648 to 2147483647 |
105
+
106
+ - `min` must be ≤ `max` after defaults are applied.
107
+ - `unique` is not allowed on `Bool` or `Password`.
108
+ - `min` and `max` are not allowed on `Bool`, `Date`, `ID` or links.
109
+ - `private` is not allowed on `Password`, which is always hidden.
110
+
111
+ ### 3.3 Naming
112
+
113
+ | Thing | Style | Example | In PostgreSQL |
114
+ |------------|------------|---------------------|-----------------------------|
115
+ | Model name | PascalCase | `BlogPost` | table `blog_posts` |
116
+ | Field name | camelCase | `firstName` | column `first_name` |
117
+ | Link field | camelCase | `author: User` | column `author_id` |
118
+
119
+ - **Table names** are the snake_case plural of the model name:
120
+ - `+s` by default,
121
+ - `+es` after `s`, `x`, `z`, `ch` or `sh`,
122
+ - consonant + `y` becomes `ies`.
123
+ - **Reserved names:**
124
+ - Model names: the seven type names, plus `PasswordHash`, `String`, `Boolean`, `Object`, `Array`, `Promise`, `Record`, `Error`, `Map`, `Set`, `Symbol`, `BigInt`, `Function`, `JSON`, `Math`, `Partial` and `Readonly`.
125
+ - Field name: `id`.
126
+ - Two names must never produce the same table, column or TypeScript type. Table and column names must be at most 63 characters.
127
+
128
+ ---
129
+
130
+ ## 4. Login: the `auth` line
131
+
132
+ ```rizo
133
+ auth User by email
134
+ ```
135
+
136
+ This line turns on accounts and sessions. It is written `auth <Model> by <field>`.
137
+
138
+ Rules (error RZ0317):
139
+ - The field must be declared as `Email unique`, and it must not be optional.
140
+ - The model must have exactly one required `Password` field.
141
+ - A link from the model to itself must be optional.
142
+ - There can be at most one `auth` line per file.
143
+
144
+ It adds four endpoints. Paths under `/auth` are reserved.
145
+
146
+ | Endpoint | Body | Result |
147
+ |---------------------|-----------------------------------|-----------------------------------------------|
148
+ | `POST /auth/signup` | The model's fields, like `User.input` | 201 with `User.public`, and logs the user in |
149
+ | `POST /auth/login` | `{ "email": ..., "password": ... }` | 200 with `User.public`, or 401 |
150
+ | `POST /auth/logout` | none | 204; the session is deleted |
151
+ | `GET /auth/me` | none | 200 with `User.public`, or 401 |
152
+
153
+ **How login works**
154
+ - Passwords are hashed with scrypt (N=2^15, r=8, p=3) and a random salt.
155
+ - A wrong password and an unknown email give the same 401 response, in about the same time.
156
+ - After 5 failed logins for an account, or 20 from one address, within 15 minutes, login answers 429. Signups are limited to 10 per hour per address.
157
+
158
+ **How sessions work**
159
+ - The session is a random 256-bit token in the `rizo_session` cookie: `HttpOnly; Secure; SameSite=Lax; Path=/`, lasting 7 days.
160
+ - The database stores only a SHA-256 hash of the token, in the table `_rizo_sessions`.
161
+
162
+ ---
163
+
164
+ ## 5. Endpoints: `api` blocks
165
+
166
+ ```rizo
167
+ api GET /posts/:id -> Post.public {
168
+ public
169
+ return db.Post.find(id)
170
+ }
171
+ ```
172
+
173
+ An endpoint has a header, an access rule, an optional owner rule and one return line:
174
+
175
+ ```
176
+ api <METHOD> <path> [-> <return type>] {
177
+ public | requires login
178
+ [requires owner <link field>]
179
+ return db.<Model>.<action>(<arguments>)
180
+ }
181
+ ```
182
+
183
+ ### 5.1 Header
184
+
185
+ - **Method:** `GET`, `POST`, `PUT`, `PATCH` or `DELETE`, in uppercase.
186
+ - **Path:** starts with `/`.
187
+ - Static segments use lowercase letters, digits and single hyphens.
188
+ - Parameters are written `:camelCase`, for example `/posts/:id`.
189
+ - No trailing slash, no empty segment, and no parameter may appear twice.
190
+ - `me` and `body` cannot be parameter names.
191
+ - **Return type:**
192
+ - `-> Model.public` for one record.
193
+ - `-> list Model.public` for many records.
194
+ - Nothing at all for `delete`.
195
+ - Endpoints can only return the `.public` view.
196
+
197
+ ### 5.2 Access
198
+
199
+ Every endpoint must contain **exactly one** of these lines (RZ0318):
200
+
201
+ - `public`: anyone may call the endpoint.
202
+ - `requires login`: the caller must have a valid session, otherwise the response is 401.
203
+
204
+ There is no default, so an endpoint can never be left open by accident. `requires login` needs an `auth` line.
205
+
206
+ `requires owner <field>` adds an ownership check (RZ0329):
207
+ - It needs `requires login`.
208
+ - `<field>` must be a link to the auth model, for example `author`.
209
+ - It works with `find`, `update` and `delete`.
210
+ - The check is part of the SQL `WHERE` clause. A record owned by someone else behaves exactly like a missing one (404), so callers can't tell that it exists.
211
+ - It is **required** for `update` and `delete` on a model that links to the auth model (RZ0331), so one user can never change another user's records.
212
+ - A public endpoint can't update or delete such a model either: `requires owner` needs `requires login`.
213
+
214
+ ### 5.3 Queries
215
+
216
+ The return line is `return db.<Model>.<action>(...)`. There are five actions. Each one has exactly one allowed method (RZ0328), so `GET` never changes data.
217
+
218
+ | Action | Method | Arguments | Result |
219
+ |----------|---------------|---------------------------------------------------|-------------------------------------------|
220
+ | `find` | GET | `(id)`: a path parameter | 200 with the record, or 404 |
221
+ | `list` | GET | filters, `order`, `limit` (all optional) | 200 with an array |
222
+ | `create` | POST | `(body)` then optional `field = value` | 201 with the new record |
223
+ | `update` | PUT or PATCH | `(id, body)` | 200 with the updated record, or 404 |
224
+ | `delete` | DELETE | `(id)` | 204, or 404 |
225
+
226
+ **`list` arguments**, separated by commas:
227
+ - `field = value`: filters by equality, combined with AND.
228
+ - `order field` or `order field desc`: sorts. The default order is by `id`.
229
+ - `limit N`: N is 1 to 100, and the default is 50.
230
+
231
+ Hidden fields (Password or `private`) cannot be used in filters or ordering.
232
+
233
+ **Values** on the right of `=`:
234
+ - `me`: the logged-in user. It only works with a link to the auth model, and is not allowed in public endpoints.
235
+ - A path parameter's name, such as `userId`. Its type comes from the field it's compared with.
236
+ - A whole number, for `Number` fields.
237
+ - `true` or `false`, for `Bool` fields.
238
+
239
+ **`body`** is the JSON request body. It is validated before the query runs:
240
+ - Unknown keys are rejected.
241
+ - Required fields must be present.
242
+ - `null` is only allowed for optional fields.
243
+ - Every limit from the model is checked.
244
+ - In `update`, every field is optional, and only the fields that are sent are changed.
245
+
246
+ **Ownership is never taken from the client** (RZ0326):
247
+ - A link to the auth model is never part of `body`.
248
+ - In `create`, it must be assigned `= me`: `db.Post.create(body, author = me)`.
249
+ - `update` can never change it.
250
+
251
+ The auth model itself cannot be created, updated or deleted through `api` blocks (RZ0327). Accounts are created through `/auth/signup`.
252
+
253
+ Every path parameter must be used in the query (RZ0323).
254
+
255
+ ### 5.4 A complete example
256
+
257
+ ```rizo
258
+ auth User by email
259
+
260
+ model User {
261
+ email: Email unique private
262
+ password: Password min 12
263
+ name: Text max 100
264
+ }
265
+
266
+ model Post {
267
+ author: User
268
+ title: Text min 1 max 200
269
+ published: Bool
270
+ }
271
+
272
+ api GET /posts -> list Post.public {
273
+ public
274
+ return db.Post.list(published = true, order title, limit 20)
275
+ }
276
+
277
+ api POST /posts -> Post.public {
278
+ requires login
279
+ return db.Post.create(body, author = me)
280
+ }
281
+
282
+ api PATCH /posts/:id -> Post.public {
283
+ requires login
284
+ requires owner author
285
+ return db.Post.update(id, body)
286
+ }
287
+
288
+ api DELETE /posts/:id {
289
+ requires login
290
+ requires owner author
291
+ return db.Post.delete(id)
292
+ }
293
+ ```
294
+
295
+ ---
296
+
297
+ ## 6. What the compiler generates
298
+
299
+ `rizolang build app.rz` writes everything to `dist/`.
300
+
301
+ | File | Contents |
302
+ |----------------------|------------------------------------------------------------------------------|
303
+ | `schema.sql` | PostgreSQL 13+ tables, constraints, foreign keys and the sessions table, inside one transaction |
304
+ | `types.ts` | `Model`, `ModelPublic` and `ModelInput` types for every model |
305
+ | `routes.ts` | Every endpoint as data, with its SQL written out in full |
306
+ | `server.ts` | The entry point |
307
+ | `runtime/` | The Rizo runtime: validation, sessions, password hashing and the HTTP server |
308
+ | `package.json`, `tsconfig.json` | To install `pg` and type-check the app |
309
+
310
+ `routes.ts`, `server.ts`, `runtime/`, `package.json` and `tsconfig.json` are written only when the file has an `auth` line or `api` blocks.
311
+
312
+ The three types:
313
+ - `User` is the stored record. It is for server use only, and holds a `PasswordHash`.
314
+ - `UserPublic` (`User.public`) leaves out Password and `private` fields.
315
+ - `UserInput` (`User.input`) is what a client sends. Passwords are plain text here, and links to the auth model are left out.
316
+
317
+ ### Running the server
318
+
319
+ Needs Node.js 22.18 or newer.
320
+
321
+ ```sh
322
+ cd dist && npm install
323
+ psql "$DATABASE_URL" -f schema.sql
324
+ DATABASE_URL=postgres://user:pass@localhost:5432/app node server.ts
325
+ ```
326
+
327
+ | Variable | Default | Meaning |
328
+ |-----------------------------|-------------|------------------------------------------------------------|
329
+ | `DATABASE_URL` | (required) | PostgreSQL connection string |
330
+ | `PORT`, `HOST` | `3000`, `127.0.0.1` | Where to listen |
331
+ | `RIZO_ALLOWED_ORIGINS` | none | Comma-separated extra origins allowed to send POST, PUT, PATCH or DELETE requests |
332
+ | `RIZO_TRUST_PROXY` | off | `1` to read the client IP from `X-Forwarded-For` (only behind a trusted proxy) |
333
+ | `RIZO_DEV_INSECURE_COOKIES` | off | `1` to drop the `Secure` cookie flag for local http. **Never in production.** |
334
+ | `RIZO_DB_POOL_SIZE` | `10` | Maximum number of database connections |
335
+
336
+ ### HTTP behaviour
337
+
338
+ - **Requests:**
339
+ - Bodies must be JSON (`Content-Type: application/json`) and at most 1 MB. Endpoints without `body` reject a request body.
340
+ - Path parameters are validated by type. An invalid id gets 400 before any query runs.
341
+ - **Responses** are JSON:
342
+ - Errors look like `{ "error": { "code": "...", "message": "...", "field": "..." } }`.
343
+ - Status codes: 400 invalid input, 401 not logged in, 403 cross-site request, 404 not found, 405 wrong method, 409 duplicate or still in use, 413 too large, 415 not JSON, 429 too many attempts, 500 internal error (with a request id).
344
+ - Every response carries `Cache-Control: no-store`, `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY`, `Referrer-Policy: no-referrer` and a `Content-Security-Policy` that allows nothing.
345
+ - **Cross-site requests:** POST, PUT, PATCH and DELETE requests with an `Origin` header from another site are rejected with 403.
346
+ - **Logs:** one line per request: the method, the route pattern (such as `/posts/:id`), the status, the time and a request id. Logs never contain URLs with values, bodies, cookies or passwords.
347
+
348
+ ---
349
+
350
+ ## 7. Security guarantees
351
+
352
+ These are enforced by the compiler and the runtime, and covered by `tests/security.test.ts` and `tests/e2e.test.ts`:
353
+
354
+ 1. A Password or `private` field never appears in a `.public` type or in any response.
355
+ 2. A Password is never stored in plain text.
356
+ 3. All SQL is written at compile time. Request data only fills `$1, $2, …` parameters, and names can't break out of their quotes.
357
+ 4. Every endpoint declares its access, and `requires owner` is enforced inside the query. Records that belong to a user can only be changed or deleted by that user.
358
+ 5. A record's owner is always the logged-in user. It is never taken from the request.
359
+ 6. All input is validated against the model before it reaches the database, and unknown fields are rejected.
360
+ 7. `GET` endpoints never change data. Cross-site writes are rejected.
361
+ 8. When there is any compile error, no output is written.
362
+
363
+ ---
364
+
365
+ ## 8. Errors
366
+
367
+ ```
368
+ app.rz:3:9 error RZ0301: Unknown field type "String" on field "User.name".
369
+ 3 | name: String
370
+ | ^^^^^^
371
+ fix: Use "Text" instead. Valid types: Text, Number, Bool, Email, Password, Date, ID, or a model name (User).
372
+ ```
373
+
374
+ - The first line is always `<file>:<line>:<column> error <code>: <message>`. The `fix:` line says exactly what to change.
375
+ - Syntax errors (RZ01xx, RZ02xx) stop at the first error. Checking errors (RZ03xx) are all reported together.
376
+ - `rizolang` exits with 0 on success and 1 on any error.
377
+
378
+ | Code | Meaning |
379
+ |--------|-------------------------------------------------------------------------|
380
+ | RZ0101 | Unexpected character (semicolon, underscore, quote…) |
381
+ | RZ0102 | Invalid number (decimal, too large, letters attached) |
382
+ | RZ0201 | Expected `model`, `auth` or `api` at the top level |
383
+ | RZ0202 | Missing model name |
384
+ | RZ0203 | Missing `{` |
385
+ | RZ0204 | Expected a field name or `}` |
386
+ | RZ0205 | Missing `:` after a field name |
387
+ | RZ0206 | Missing field type |
388
+ | RZ0207 | Unknown modifier |
389
+ | RZ0208 | Missing number after `min`/`max` |
390
+ | RZ0209 | Field or statement does not start on a new line |
391
+ | RZ0210 | Block missing its closing `}` |
392
+ | RZ0211 | Block type not available yet (e.g. `page`) |
393
+ | RZ0212 | Unexpected token after a field or statement |
394
+ | RZ0213 | Missing or invalid HTTP method |
395
+ | RZ0214 | Missing path |
396
+ | RZ0215 | Invalid return type (must be `Model.public` or `list Model.public`) |
397
+ | RZ0216 | Unknown statement in an `api` block |
398
+ | RZ0217 | Invalid query syntax |
399
+ | RZ0218 | Invalid `auth` line |
400
+ | RZ0301 | Unknown field type |
401
+ | RZ0302 | Modifier not allowed on this type |
402
+ | RZ0303 | Modifier repeated |
403
+ | RZ0304 | `min` greater than `max` |
404
+ | RZ0305 | `min`/`max` value out of range |
405
+ | RZ0306 | Duplicate model name |
406
+ | RZ0307 | Duplicate field name |
407
+ | RZ0308 | Field named `id` (it is automatic) |
408
+ | RZ0309 | Model name not PascalCase |
409
+ | RZ0310 | Field name not camelCase |
410
+ | RZ0311 | Reserved model name |
411
+ | RZ0312 | Two names map to the same table, column or TypeScript type |
412
+ | RZ0313 | Model has no fields |
413
+ | RZ0314 | Name too long for PostgreSQL |
414
+ | RZ0315 | Password-like field (e.g. `password`) not using `Password` |
415
+ | RZ0316 | Unknown model |
416
+ | RZ0317 | Invalid `auth` model |
417
+ | RZ0318 | Endpoint access missing, repeated or contradictory |
418
+ | RZ0319 | Login used without an `auth` line |
419
+ | RZ0320 | Missing, repeated or misplaced `return` line |
420
+ | RZ0321 | Return type does not match the query |
421
+ | RZ0322 | Invalid path |
422
+ | RZ0323 | Unknown or unused path parameter |
423
+ | RZ0324 | Duplicate endpoint |
424
+ | RZ0325 | Invalid query action or arguments |
425
+ | RZ0326 | Link to the auth model not set to `me` |
426
+ | RZ0327 | Creating, changing or deleting the auth model through `api` |
427
+ | RZ0328 | HTTP method does not match the query action |
428
+ | RZ0329 | Invalid `requires owner` |
429
+ | RZ0330 | `me` used in a public endpoint |
430
+ | RZ0331 | `update` or `delete` of an owned record without `requires owner` |
431
+ | RZ0901 | Cannot read the input file |
432
+ | RZ0902 | Input file does not end in `.rz` |
433
+ | RZ0903 | Wrong command-line usage |
434
+
435
+ ---
436
+
437
+ ## 9. Common mistakes
438
+
439
+ The examples below use the `User` and `Post` models from §3.
440
+
441
+ **Types from other languages.**
442
+
443
+ ```rizo
444
+ // Wrong
445
+ name: String
446
+ age: Int
447
+ active: Boolean
448
+ createdAt: DateTime
449
+
450
+ // Right
451
+ name: Text
452
+ age: Number
453
+ active: Bool
454
+ createdAt: Date
455
+ ```
456
+
457
+ **Commas, semicolons, decorators or arguments in fields.**
458
+
459
+ ```rizo
460
+ // Wrong
461
+ email: Email, name: Text;
462
+ name: Text(100)
463
+ email: Email @unique
464
+ nickname?: Text
465
+
466
+ // Right
467
+ name: Text max 100
468
+ email: Email unique
469
+ nickname: Text optional
470
+ ```
471
+
472
+ **Declaring `id`, or snake_case names.**
473
+
474
+ ```rizo
475
+ // Wrong
476
+ model blog_post {
477
+ id: ID
478
+ first_name: Text
479
+ }
480
+
481
+ // Right
482
+ model BlogPost {
483
+ firstName: Text
484
+ }
485
+ ```
486
+
487
+ **Weak or plain-text passwords.**
488
+
489
+ ```rizo
490
+ // Wrong
491
+ password: Text
492
+ password: Password unique min 4
493
+
494
+ // Right
495
+ password: Password min 12
496
+ ```
497
+
498
+ **Forgetting to say who may call an endpoint.**
499
+
500
+ ```rizo
501
+ // Wrong
502
+ api GET /posts -> list Post.public {
503
+ return db.Post.list()
504
+ }
505
+
506
+ // Right
507
+ api GET /posts -> list Post.public {
508
+ public
509
+ return db.Post.list()
510
+ }
511
+ ```
512
+
513
+ **Letting the client choose the owner.**
514
+
515
+ ```rizo
516
+ // Wrong
517
+ api POST /posts -> Post.public {
518
+ requires login
519
+ return db.Post.create(body)
520
+ }
521
+
522
+ // Right
523
+ api POST /posts -> Post.public {
524
+ requires login
525
+ return db.Post.create(body, author = me)
526
+ }
527
+ ```
528
+
529
+ **Changing data without an ownership check, or with the wrong method.**
530
+
531
+ ```rizo
532
+ // Wrong
533
+ api GET /posts/:id/delete {
534
+ requires login
535
+ return db.Post.delete(id)
536
+ }
537
+
538
+ // Right
539
+ api DELETE /posts/:id {
540
+ requires login
541
+ requires owner author
542
+ return db.Post.delete(id)
543
+ }
544
+ ```
545
+
546
+ **Returning the full record instead of the public view.**
547
+
548
+ ```rizo
549
+ // Wrong
550
+ api GET /users/:id -> User {
551
+ public
552
+ return db.User.find(id)
553
+ }
554
+
555
+ // Right
556
+ api GET /users/:id -> User.public {
557
+ public
558
+ return db.User.find(id)
559
+ }
560
+ ```
561
+
562
+ ---
563
+
564
+ ## 10. Grammar
565
+
566
+ ```ebnf
567
+ file = { model | auth | api } ;
568
+ model = "model" NAME "{" { field } "}" ;
569
+ field = NAME ":" TYPE { modifier } NEWLINE ;
570
+ modifier = "unique" | "optional" | "private" | "min" INT | "max" INT ;
571
+ TYPE = "Text" | "Number" | "Bool" | "Email" | "Password" | "Date" | "ID" | NAME ;
572
+ auth = "auth" NAME "by" NAME NEWLINE ;
573
+ api = "api" METHOD PATH [ "->" rettype ] "{" { statement NEWLINE } "}" ;
574
+ METHOD = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" ;
575
+ PATH = "/" [ segment { "/" segment } ] ;
576
+ segment = LOWER { LOWER | DIGIT | "-" } | ":" NAME ;
577
+ rettype = [ "list" ] NAME "." "public" ;
578
+ statement = "public" | "requires" "login" | "requires" "owner" NAME | "return" query ;
579
+ query = "db" "." NAME "." ACTION "(" [ arg { "," arg } ] ")" ;
580
+ ACTION = "find" | "list" | "create" | "update" | "delete" ;
581
+ arg = NAME | NAME "=" value | "order" NAME [ "asc" | "desc" ] | "limit" INT ;
582
+ value = NAME | INT | "true" | "false" ;
583
+ NAME = LETTER { LETTER | DIGIT } ;
584
+ INT = [ "-" ] DIGIT { DIGIT } ;
585
+ comment = "//" { any character except newline } ;
586
+ ```
587
+
588
+ ---
589
+
590
+ ## 11. Planned (not available yet)
591
+
592
+ These are **not** part of the language yet. Using them is an error.
593
+
594
+ - Roles (`requires role admin`).
595
+ - Pagination, and filters other than `=`.
596
+ - Changing or deleting accounts.
597
+ - Frontend `page` blocks.
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "rizolang",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Rizo Lang: a secure, simple, full-stack web language for the AI era. Compiles to PostgreSQL and TypeScript.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://rizobot.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/chaitanyaaggarwal9/rizolang.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/chaitanyaaggarwal9/rizolang/issues"
13
+ },
14
+ "keywords": [
15
+ "rizo",
16
+ "rizolang",
17
+ "programming-language",
18
+ "compiler",
19
+ "postgresql",
20
+ "typescript",
21
+ "secure-by-default"
22
+ ],
23
+ "type": "module",
24
+ "bin": {
25
+ "rizolang": "build/src/bin.js"
26
+ },
27
+ "files": [
28
+ "build/src",
29
+ "runtime",
30
+ "docs",
31
+ "LICENSE",
32
+ "README.md"
33
+ ],
34
+ "engines": {
35
+ "node": ">=22.12.0"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "typecheck": "tsc -p tsconfig.json",
40
+ "test": "vitest run",
41
+ "test:watch": "vitest"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "26.6.6",
45
+ "@types/pg": "8.23.1",
46
+ "pg": "8.23.1",
47
+ "typescript": "7.0.2",
48
+ "vitest": "5.1.0"
49
+ }
50
+ }