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
@@ -0,0 +1,148 @@
1
+ # Rizo Lang (compact spec, v0.2)
2
+
3
+ You are writing Rizo Lang (`.rz` files). Follow these rules exactly. A file contains only `model` blocks, at most one `auth` line, and `api` blocks. Never write SQL, TypeScript or `page` blocks in `.rz` files.
4
+
5
+ ## Example
6
+
7
+ ```rizo
8
+ // comment
9
+ auth User by email
10
+
11
+ model User {
12
+ email: Email unique private
13
+ password: Password min 12
14
+ name: Text max 100
15
+ }
16
+
17
+ model Post {
18
+ author: User
19
+ title: Text min 1 max 200
20
+ views: Number min 0 optional
21
+ published: Bool
22
+ }
23
+
24
+ api GET /posts -> list Post.public {
25
+ public
26
+ return db.Post.list(published = true, order title, limit 20)
27
+ }
28
+
29
+ api GET /posts/:id -> Post.public {
30
+ public
31
+ return db.Post.find(id)
32
+ }
33
+
34
+ api POST /posts -> Post.public {
35
+ requires login
36
+ return db.Post.create(body, author = me)
37
+ }
38
+
39
+ api PATCH /posts/:id -> Post.public {
40
+ requires login
41
+ requires owner author
42
+ return db.Post.update(id, body)
43
+ }
44
+
45
+ api DELETE /posts/:id {
46
+ requires login
47
+ requires owner author
48
+ return db.Post.delete(id)
49
+ }
50
+ ```
51
+
52
+ ## Models
53
+
54
+ - Write `model Name {` with a PascalCase name, one field per line as `name: Type modifiers`, then `}`. No commas or semicolons.
55
+ - Field names are camelCase. Names contain only letters and digits.
56
+ - Every model gets `id: ID` automatically. Never declare `id`.
57
+
58
+ | Type | Meaning | Modifiers allowed |
59
+ |------------|-------------------------------------------------|-------------------------------------|
60
+ | `Text` | text, max 10000 chars by default | unique optional private min max |
61
+ | `Number` | whole number (32-bit). Use cents for money | unique optional private min max |
62
+ | `Bool` | true/false | optional private |
63
+ | `Email` | email address, 3–254 chars, stored lowercase | unique optional private min max |
64
+ | `Password` | hashed, never returned, 8–128 chars | optional min max |
65
+ | `Date` | date and time (UTC) | unique optional private |
66
+ | `ID` | UUID | unique optional private |
67
+ | *Model* | link to another model, e.g. `author: User` | unique optional private |
68
+
69
+ Modifiers:
70
+ - `unique`: no two records share the value.
71
+ - `optional`: the value may be null.
72
+ - `private`: never returned by the API.
73
+ - `min N` / `max N`: the length for text, the value for Number.
74
+
75
+ A field named `password` (or ending in `Password`) must have the type `Password`.
76
+
77
+ ## auth
78
+
79
+ `auth User by email` turns on accounts. User needs `email: Email unique` and one `Password` field. It adds `POST /auth/signup`, `POST /auth/login`, `POST /auth/logout` and `GET /auth/me`. Sessions use a secure cookie. Don't write your own login endpoints.
80
+
81
+ ## api
82
+
83
+ ```
84
+ api METHOD /path/:param -> Model.public {
85
+ public (or: requires login)
86
+ requires owner <link field> (optional)
87
+ return db.Model.action(arguments)
88
+ }
89
+ ```
90
+
91
+ - Every endpoint has **exactly one** of `public` or `requires login`.
92
+ - `requires owner author` lets only the record's owner act; others get 404. It needs `requires login`, and it works with find, update and delete. It is **required** on update and delete of a model that links to the auth model.
93
+ - The return type is `-> Model.public` or `-> list Model.public`, and there is none for delete. Only `.public` can be returned.
94
+ - Paths use lowercase segments and `:camelCase` parameters. Every parameter must be used. `/auth` is reserved.
95
+
96
+ | Action | Method | Result |
97
+ |---------------------------------|--------------|--------------------|
98
+ | `db.M.find(id)` | GET | one record or 404 |
99
+ | `db.M.list(filters, order f desc, limit N)` | GET | list (limit ≤ 100, default 50) |
100
+ | `db.M.create(body)` | POST | 201 new record |
101
+ | `db.M.update(id, body)` | PUT or PATCH | changed record or 404 |
102
+ | `db.M.delete(id)` | DELETE | 204 or 404 |
103
+
104
+ - Filters are `field = value`. A value is `me`, a path parameter, a number, `true` or `false`.
105
+ - `body` is the validated JSON request body.
106
+ - A link to the auth model must be set with `= me` in create, and is never taken from body.
107
+ - You cannot create, update or delete the auth model through `api`.
108
+
109
+ ## Errors
110
+
111
+ The format is `file.rz:LINE:COL error RZxxxx: message`, followed by a `fix:` line. Apply the fix exactly as written.
112
+
113
+ ## Wrong → Right
114
+
115
+ ```rizo
116
+ name: String → name: Text
117
+ age: Int → age: Number
118
+ active: Boolean → active: Bool
119
+ createdAt: DateTime → createdAt: Date
120
+ userId: UUID → userId: ID
121
+ email: Email, → email: Email
122
+ name: Text(100) → name: Text max 100
123
+ email: Email @unique → email: Email unique
124
+ nickname?: Text → nickname: Text optional
125
+ first_name: Text → firstName: Text
126
+ model user { → model User {
127
+ id: ID → (remove it; id is automatic)
128
+ password: Text → password: Password
129
+ password: Password unique → password: Password
130
+ password: Password min 4 → password: Password min 8
131
+ price: Number min 0.5 → priceCents: Number min 50
132
+ isAdmin: Bool max 1 → isAdmin: Bool
133
+ ```
134
+
135
+ In api blocks:
136
+ - Every endpoint needs `public` or `requires login`; never leave it out.
137
+ - Write `db.Post.create(body, author = me)`, not `db.Post.create(body)`.
138
+ - Write `-> Post.public`, not `-> Post`.
139
+ - Use `api DELETE /posts/:id`, not `api GET /posts/:id/delete`.
140
+ - Write `requires owner author` on update and delete of user-owned records.
141
+
142
+ ## Checklist before answering
143
+
144
+ 1. Only `model`, `auth` and `api` blocks, with one item per line.
145
+ 2. Every type is Text, Number, Bool, Email, Password, Date, ID or a model name.
146
+ 3. Model names are PascalCase, field names are camelCase, and no field is named `id`.
147
+ 4. Every endpoint has `public` or `requires login`, a matching method and one `return` line.
148
+ 5. Owned records use `author = me` on create and `requires owner` on update and delete.