orvyn-lang 0.1.1 → 0.3.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.
- package/GUIDE.md +149 -0
- package/LANGUAGE.md +877 -24
- package/README.md +227 -131
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +216 -489
- package/src/core/signal.js +104 -6
- package/src/devtools/runtime.js +25 -1
- package/src/lang/a11y.js +102 -0
- package/src/lang/auth.js +239 -0
- package/src/lang/bundle-native.js +10 -6
- package/src/lang/codegen.js +498 -64
- package/src/lang/device.js +41 -0
- package/src/lang/doctor.js +60 -0
- package/src/lang/env.js +27 -0
- package/src/lang/errors.js +513 -0
- package/src/lang/form.js +160 -0
- package/src/lang/index.js +2 -1
- package/src/lang/lexer.js +2 -0
- package/src/lang/list.js +44 -0
- package/src/lang/native/android/MainActivity.kt +43 -4
- package/src/lang/native/android/OrvynDevice.kt +163 -0
- package/src/lang/native/android/OrvynEngine.kt +154 -7
- package/src/lang/native/android/OrvynRenderer.kt +519 -40
- package/src/lang/native/android.js +74 -11
- package/src/lang/native/build.js +130 -60
- package/src/lang/native/config.js +108 -0
- package/src/lang/native/ios/OrvynApp.swift +6 -0
- package/src/lang/native/ios/OrvynEngine.swift +268 -4
- package/src/lang/native/ios/OrvynViews.swift +429 -31
- package/src/lang/native/ios.js +75 -2
- package/src/lang/native-runtime.js +423 -57
- package/src/lang/page.js +52 -0
- package/src/lang/parser.js +243 -15
- package/src/lang/prerender.js +300 -0
- package/src/lang/read-import.js +11 -0
- package/src/lang/router.js +266 -0
- package/src/lang/runtime-shared.js +820 -10
- package/src/lang/runtime.js +375 -52
- package/src/lang/select.js +13 -0
- package/src/lang/server-code.js +233 -0
- package/src/lang/server-export.js +78 -0
- package/src/lang/server-libs.js +53 -0
- package/src/lang/server.js +409 -0
- package/src/lang/test-runner.js +134 -0
- package/src/lang/types.js +312 -0
- package/src/lang/validation.js +55 -0
- package/src/lang/vite-plugin.js +82 -3
- package/src/lang/web-overlay.js +578 -0
- package/src/lang/widgets.js +94 -0
- package/src/lang/words.js +38 -0
- package/src/runtime/mount.js +116 -27
- package/src/runtime/patch.js +90 -11
- package/src/runtime/style.js +11 -1
- package/src/styling/fluid.js +91 -4
- package/src/styling/spec.js +306 -0
- package/src/core/context.js +0 -19
- package/src/core/lifecycle.js +0 -8
- package/src/core/resource.js +0 -27
- package/src/core/router.js +0 -20
- package/src/core/theme.js +0 -10
- package/src/devtools/devicePreview/PreviewFrame.js +0 -214
- package/src/devtools/devicePreview/index.js +0 -6
- package/src/devtools/overlay.js +0 -105
- package/src/runtime/createRenderer.js +0 -22
- package/src/runtime/h.js +0 -93
- package/src/runtime/hydrate.js +0 -59
- package/src/runtime/jsx-dev-runtime.js +0 -7
- package/src/runtime/jsx-runtime.js +0 -13
- package/src/runtime/partialHydration.js +0 -154
- package/src/runtime/platform.js +0 -135
- package/src/runtime/renderToStream.js +0 -127
- package/src/runtime/renderToString.js +0 -121
- package/src/runtime/resume.js +0 -62
package/LANGUAGE.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# The Orvyn Language (v0.1)
|
|
2
2
|
|
|
3
|
-
Orvyn files end in `.orv`.
|
|
4
|
-
|
|
3
|
+
Orvyn files end in `.orv`. The compiler turns your code into JavaScript. The web
|
|
4
|
+
runtime renders browser elements; generated iOS and Android projects run the
|
|
5
|
+
same logic with native views.
|
|
5
6
|
|
|
6
7
|
```orv
|
|
7
8
|
state count = 0
|
|
@@ -34,7 +35,8 @@ cd my-app
|
|
|
34
35
|
|
|
35
36
|
orvyn dev # web → http://localhost:5173, reloads when you save
|
|
36
37
|
orvyn ios # iPhone simulator, reloads when you save
|
|
37
|
-
orvyn android # Android emulator or phone
|
|
38
|
+
orvyn android # Android emulator or phone, with live reload
|
|
39
|
+
orvyn test # run the test blocks in your app
|
|
38
40
|
orvyn check # find mistakes
|
|
39
41
|
orvyn build # website → dist/web/
|
|
40
42
|
orvyn build ios # Xcode project → dist/ios/ (real iPhones, App Store)
|
|
@@ -43,6 +45,19 @@ orvyn build android # Android Studio project → dist/android/
|
|
|
43
45
|
|
|
44
46
|
Your code lives in `src/app.orv`. Orvyn finds it by itself.
|
|
45
47
|
|
|
48
|
+
### Instant updates on the web
|
|
49
|
+
|
|
50
|
+
With `orvyn dev`, saving a `.orv` file swaps the new code in without refreshing the page. App `state` and the current screen stay as they are, so you don't have to click your way back.
|
|
51
|
+
|
|
52
|
+
- State keeps its value unless you change its starting value in the code.
|
|
53
|
+
- `state` inside screens and components is kept too, as is the page's scroll position. If you add or remove items with the same state name, a value may move to a neighbour.
|
|
54
|
+
- Typed text that isn't bound to state, and scrolling inside a box or `List`, start again.
|
|
55
|
+
- `start { }` runs again after an update.
|
|
56
|
+
|
|
57
|
+
### Live reload on Android
|
|
58
|
+
|
|
59
|
+
`orvyn android` builds and installs the app once, then reloads it whenever you save a `.orv` file. It works on an emulator or a phone with USB debugging (connect one at a time).
|
|
60
|
+
|
|
46
61
|
### Live reload on iPhone
|
|
47
62
|
|
|
48
63
|
`orvyn ios` builds the app once, then keeps running:
|
|
@@ -75,7 +90,60 @@ Mistakes show in red on the phone and in the terminal, with the line number.
|
|
|
75
90
|
| `screen Name { ... }` | A screen of your app. `App` (or the first screen) is shown first. |
|
|
76
91
|
| `component Name(param) { ... }` | A reusable piece of UI. |
|
|
77
92
|
| `start { ... }` | Runs once when the app opens (load data here). |
|
|
78
|
-
| `use Card, Badge from "./ui"` | Use components or
|
|
93
|
+
| `use Card, Badge from "./ui"` | Use components, functions, values, or state from another `.orv` file. |
|
|
94
|
+
|
|
95
|
+
### Share state between files
|
|
96
|
+
|
|
97
|
+
Every top-level declaration is exported automatically. Import state with `use`
|
|
98
|
+
and read or change it with the same syntax as local state:
|
|
99
|
+
|
|
100
|
+
```orv
|
|
101
|
+
// store.orv
|
|
102
|
+
state count = 0
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```orv
|
|
106
|
+
// app.orv
|
|
107
|
+
use count from "./store"
|
|
108
|
+
|
|
109
|
+
screen Home {
|
|
110
|
+
Column gap: 16 {
|
|
111
|
+
Text "Count: {count}"
|
|
112
|
+
Button "Add", onTap: count += 1
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Imported state stays reactive. Assigning to an imported fixed value or function
|
|
118
|
+
reports a runtime error explaining that the declaration must use `state`.
|
|
119
|
+
|
|
120
|
+
### State inside a component or screen
|
|
121
|
+
|
|
122
|
+
Put `state` (or `let`) at the top of a `component` or `screen` to give each one
|
|
123
|
+
its own private value:
|
|
124
|
+
|
|
125
|
+
```orv
|
|
126
|
+
component Counter(label) {
|
|
127
|
+
state count = 0
|
|
128
|
+
|
|
129
|
+
Row gap: 8 {
|
|
130
|
+
Text "{label}: {count}"
|
|
131
|
+
Button "+", onTap: count += 1
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
screen Home {
|
|
136
|
+
Column gap: 12 {
|
|
137
|
+
Counter label: "First"
|
|
138
|
+
Counter label: "Second"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Each `Counter` keeps its own `count`, survives unrelated updates, and resets when
|
|
144
|
+
it is removed (`if`, list removal, or leaving a `screen` with `go()`). When
|
|
145
|
+
rendering components inside a `for` loop that can reorder, pass `key:` (like
|
|
146
|
+
`Counter label: item.name, key: item.id`) so each item keeps its own state.
|
|
79
147
|
|
|
80
148
|
## Statements (inside `fn` and handlers)
|
|
81
149
|
|
|
@@ -91,6 +159,8 @@ print("hello") // logs to the console
|
|
|
91
159
|
|
|
92
160
|
### Lists and objects
|
|
93
161
|
|
|
162
|
+
Shortcut: `{ email, password }` is the same as `{ email: email, password: password }`.
|
|
163
|
+
|
|
94
164
|
Change them with these, and the screen updates by itself:
|
|
95
165
|
|
|
96
166
|
```orv
|
|
@@ -118,33 +188,179 @@ saved state darkMode = false
|
|
|
118
188
|
|
|
119
189
|
The value is stored on the device (browser storage on the web, UserDefaults on
|
|
120
190
|
iPhone, SharedPreferences on Android) and comes back the next time the app opens.
|
|
121
|
-
It also survives live reload while you develop.
|
|
191
|
+
It also survives live reload while you develop. Each app and module file gets its own storage namespace automatically so keys never collide.
|
|
192
|
+
|
|
193
|
+
- **Versions & migrations:** Bump the version when saved data changes shape:
|
|
194
|
+
```orv
|
|
195
|
+
saved(2, old => ({ name: old.name ?? "Guest", plan: "free" })) state profile = { name: "Guest", plan: "free" }
|
|
196
|
+
```
|
|
197
|
+
`saved(2)` without a migration safely resets older data to the new default.
|
|
198
|
+
- **Reset & storage errors:** Call `profile.reset()` (or `storage.resetAll()`) to reset to default and clear storage. Read `storage.error` (e.g. quota full or corrupted data) and `storage.clearError()`.
|
|
199
|
+
- **Simple key–value data (`storage`):** for small values that aren't state: `storage.set("lastTab", "cart")`, `storage.get("lastTab", "home")` (second argument is the default), `storage.has(key)`, `storage.remove(key)`, `storage.clear()`. Values are saved as JSON, kept separate per app, and screens update when they change. Errors show up in `storage.error`.
|
|
200
|
+
- **Credentials (`secure`):** Ordinary `saved state` is not encrypted; store passwords, API keys, and login tokens in `secure`:
|
|
201
|
+
`secure.set("token", tok)`, `secure.get("token")`, `secure.has("token")`, `secure.remove("token")`, `secure.clear()`, `secure.error`. Uses iOS Keychain on iPhone, KeyStore AES-GCM on Android, and session storage on web (use HttpOnly cookies for production web logins). Try `/lang.html?app=storage`.
|
|
122
202
|
|
|
123
203
|
### Internet data
|
|
124
204
|
|
|
205
|
+
**Show data from a server with `load`.** It starts loading when the app opens.
|
|
206
|
+
No `wait`, no `start` block:
|
|
207
|
+
|
|
208
|
+
```orv
|
|
209
|
+
state users = load("https://api.example.com/users")
|
|
210
|
+
|
|
211
|
+
screen Home {
|
|
212
|
+
Column {
|
|
213
|
+
if users.loading {
|
|
214
|
+
Text "Loading..."
|
|
215
|
+
}
|
|
216
|
+
if users.error {
|
|
217
|
+
Text "Could not load: {users.error}"
|
|
218
|
+
Button "Try again", onTap: users.reload()
|
|
219
|
+
}
|
|
220
|
+
for user in users.data {
|
|
221
|
+
Text user.name
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
| You write | You get |
|
|
228
|
+
|---|---|
|
|
229
|
+
| `users.data` | The data (empty until it arrives, so lists and text just show nothing) |
|
|
230
|
+
| `users.loading` | `true` while waiting |
|
|
231
|
+
| `users.error` | What went wrong, or empty |
|
|
232
|
+
| `users.reload()` | Load again (a "Try again" or refresh button) |
|
|
233
|
+
|
|
234
|
+
**Send data with `post`.** Give it the address and the data. That's all:
|
|
235
|
+
|
|
125
236
|
```orv
|
|
126
|
-
state
|
|
237
|
+
state form = { email: "", password: "" }
|
|
238
|
+
state user = null
|
|
239
|
+
|
|
240
|
+
fn login() {
|
|
241
|
+
user = post("/api/login", form)
|
|
242
|
+
go(Home)
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Orvyn waits for the answer by itself, so `go(Home)` runs only after the server
|
|
247
|
+
has replied and `user` is set.
|
|
248
|
+
|
|
249
|
+
| Function | Use it to |
|
|
250
|
+
|---|---|
|
|
251
|
+
| `load(url)` | Show data on a screen |
|
|
252
|
+
| `get(url)` | Get data inside `fn` or a button |
|
|
253
|
+
| `post(url, data)` | Create something (log in, sign up, add an item) |
|
|
254
|
+
| `put(url, data)` | Replace something |
|
|
255
|
+
| `patch(url, data)` | Change part of something |
|
|
256
|
+
|
|
257
|
+
All of them send your data as JSON and give back the server's answer as normal
|
|
258
|
+
values. You can still write `wait post(...)`; it means the same thing. `fetch(url, options)`
|
|
259
|
+
is still there when you need full control.
|
|
260
|
+
|
|
261
|
+
Use `get`, `post`, `put`, `patch` and `sleep` inside a function, `start` block,
|
|
262
|
+
event handler or lambda. To show data in a screen, use `load`. The compiler
|
|
263
|
+
tells you if you mix these up.
|
|
264
|
+
|
|
265
|
+
**Work stops when you leave its screen.** Anything started from a screen, like
|
|
266
|
+
a button that sends data or a function that repeats with `sleep`, stops once the
|
|
267
|
+
user goes to another screen. A late answer can't change your state after the
|
|
268
|
+
user has moved on. `load` and `start { }` belong to the whole app and keep running.
|
|
269
|
+
|
|
270
|
+
```orv
|
|
271
|
+
state status = "Ready"
|
|
272
|
+
|
|
273
|
+
screen Home {
|
|
274
|
+
Button "Pause", onTap: {
|
|
275
|
+
status = "Waiting"
|
|
276
|
+
sleep(1000)
|
|
277
|
+
status = "Done"
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Try a complete offline app
|
|
283
|
+
|
|
284
|
+
From this repository, run `npm run dev` and open `/lang.html?app=todo`.
|
|
285
|
+
`examples/todo.orv` includes blank-input validation, saved tasks, completion
|
|
286
|
+
toggles, removal, clearing completed tasks, and navigation to an About screen.
|
|
287
|
+
It works without a network request. Saved tasks belong to the current browser
|
|
288
|
+
origin or installed app; they do not sync between devices.
|
|
127
289
|
|
|
128
|
-
|
|
129
|
-
|
|
290
|
+
### Login and auth
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
auth {
|
|
294
|
+
login: Login // where logged-out users go
|
|
295
|
+
home: Home // where to go after logging in
|
|
296
|
+
refresh: "/api/refresh" // optional: renews expired tokens
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
fn signIn() {
|
|
300
|
+
let res = post("/api/login", { email, password })
|
|
301
|
+
auth.login(res) // or auth.login(token, refreshToken, user)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
screen Profile requires auth {
|
|
305
|
+
Text "Hi {auth.user.name}"
|
|
306
|
+
Button "Log out", onTap: auth.logout()
|
|
130
307
|
}
|
|
131
308
|
```
|
|
132
309
|
|
|
133
|
-
`
|
|
134
|
-
|
|
310
|
+
Other `auth { }` settings: `api: "https://api.example.com"` (a separate API server that may receive the token), `logout: Screen`, `keepSaved: true`, `onLogout: fn`.
|
|
311
|
+
|
|
312
|
+
- `auth.isLoggedIn`, `auth.token`, `auth.user`, `auth.error`, `auth.setUser(user)`
|
|
313
|
+
- Tokens are kept in `secure` (Keychain / KeyStore), so users stay logged in after the app restarts.
|
|
314
|
+
- `get`, `post`, `load`, etc. add `Authorization: Bearer <token>` **only** for relative URLs like `/api/me`. For a separate API server add `api: "https://api.example.com"` (or a list). Other sites never get the token. Use `{ auth: false }` to skip it for one request.
|
|
315
|
+
- If a request gets **401**, Orvyn refreshes the token once (the `refresh` URL gets `{ refresh }` and should return `{ token }`) and retries. If refreshing fails, the user is logged out and `auth.error` explains why.
|
|
316
|
+
- `screen X requires auth`: logged-out users go to `loginScreen` and come back to X after `auth.login(...)`. Deep links work too.
|
|
317
|
+
- `auth.logout()` clears tokens, resets saved state and `storage` (set `keepSaved: true` to keep them), clears history, and shows the login screen.
|
|
318
|
+
- Try `/lang.html?app=auth`.
|
|
135
319
|
|
|
136
320
|
### Built-in functions
|
|
137
321
|
|
|
138
322
|
| Function | Does |
|
|
139
323
|
|---|---|
|
|
140
324
|
| `print(x)` | Log to the console |
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
325
|
+
| `load(url, options?)` | Load data with `.loading`, `.success`, `.empty`, `.error`, `.retry()`, `.cancel()` |
|
|
326
|
+
| `task(fn, options?)` | Run an action on demand with `.run()`, `.retry()`, `.cancel()` and the same 4 states |
|
|
327
|
+
| `get(url)` / `post(url, data)` | Get or send data |
|
|
328
|
+
| `fetch(url, options)` | Full control over a request (`timeout`, `signal`, `headers`, `method`) |
|
|
329
|
+
| `go(Screen)` / `back(Home?)` | Navigate between screens |
|
|
330
|
+
| `sleep(ms)` | Pause inside a function or handler |
|
|
144
331
|
| `random(1, 6)` | Random whole number |
|
|
145
332
|
| `len(list)` | Number of items |
|
|
146
333
|
|
|
147
|
-
|
|
334
|
+
- **Loading & recovery:** `load` and `task` expose `.loading`, `.success`, `.empty`, `.error`, `.cancelled`, `.retry()` (or `.reload()`), and `.cancel()`. Pass options like `{ timeout: 5000, retries: 2 }` to handle slow or flaky servers automatically. Older responses are ignored and requests started in a screen are cancelled if you leave it.
|
|
335
|
+
- **Error handling (`try / catch`):** Catch async or sync failures cleanly in any function or handler:
|
|
336
|
+
```orv
|
|
337
|
+
try {
|
|
338
|
+
user = post("/api/login", form)
|
|
339
|
+
go(Home)
|
|
340
|
+
} catch err {
|
|
341
|
+
errorMsg = err
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
- **Automatic double-tap & submit protection:** While an async `Button` `onTap` or `Form` `onSubmit` is pending, extra taps/submits are ignored, the button shows a loading state, and an unhandled `Form` error displays inside the form so the user can retry.
|
|
345
|
+
|
|
346
|
+
### Working with lists
|
|
347
|
+
|
|
348
|
+
Write your list, then a plain word. No arrow functions needed.
|
|
349
|
+
|
|
350
|
+
| Write | You get |
|
|
351
|
+
|---|---|
|
|
352
|
+
| `todos.where(done: false)` | the items that match |
|
|
353
|
+
| `todos.count(done: false)` | how many match (`todos.count()` for all) |
|
|
354
|
+
| `products.first(id: 3)` | the first match, or nothing |
|
|
355
|
+
| `products.search("lamp")` | items with that text anywhere, ignoring capitals |
|
|
356
|
+
| `products.search(query, "name")` | the same, looking in one field |
|
|
357
|
+
| `products.pick("name")` | one field from every item |
|
|
358
|
+
| `cart.total("price", "qty")` | price × qty, added up |
|
|
359
|
+
| `products.sortBy("price")` | lowest first; `sortBy("price", "high")` for highest first |
|
|
360
|
+
|
|
361
|
+
These give you a new list or value; your original list doesn't change. While data is still loading they act on an empty list. `where`, `count` and `first` check for equal values.
|
|
362
|
+
|
|
363
|
+
Advanced: short functions also work, like `todos.filter(t => t.done)`.
|
|
148
364
|
Choose a value: `done ? "Yes" : "No"`.
|
|
149
365
|
|
|
150
366
|
## Values
|
|
@@ -156,6 +372,88 @@ Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
|
|
|
156
372
|
|
|
157
373
|
## Elements
|
|
158
374
|
|
|
375
|
+
### Forms and validation
|
|
376
|
+
|
|
377
|
+
Use `bind` to show state in an input and update it when the user types:
|
|
378
|
+
|
|
379
|
+
```orv
|
|
380
|
+
state name = ""
|
|
381
|
+
|
|
382
|
+
screen Home {
|
|
383
|
+
Input "Your name", bind: name
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
`bind: name` replaces `value: name, onChange: { name = value }`. It works
|
|
388
|
+
with state names, one object field (`bind: profile.name`), or a list entry
|
|
389
|
+
(`bind: items[0]`), including imported state. Input values are text. Do not
|
|
390
|
+
combine `bind` with `value` or `onChange`. For a custom change handler, use the
|
|
391
|
+
explicit `value` and `onChange` form instead.
|
|
392
|
+
|
|
393
|
+
Put inputs inside `Form` and give it an `onSubmit` action. `SubmitButton` runs
|
|
394
|
+
that action; the browser form stays on the current page. Ordinary `Button`
|
|
395
|
+
elements default to `type: "button"`, so they do not submit a form accidentally.
|
|
396
|
+
On native, tapping `SubmitButton` runs the enclosing form's action. Put submission
|
|
397
|
+
logic on `Form onSubmit`, rather than adding an `onTap` to `SubmitButton`.
|
|
398
|
+
|
|
399
|
+
Put rules directly on your inputs. Orvyn displays field errors and runs your
|
|
400
|
+
submit action only when every field passes. You do not need an errors state,
|
|
401
|
+
a separate rules object, or a validation function for this:
|
|
402
|
+
|
|
403
|
+
```orv
|
|
404
|
+
state profile = { name: "", email: "" }
|
|
405
|
+
|
|
406
|
+
fn save() {
|
|
407
|
+
print("Ready to save", profile)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
screen Home {
|
|
411
|
+
Form gap: 12, padding: 24, onSubmit: save {
|
|
412
|
+
Input "Name", bind: profile.name, required: true, minLength: 2
|
|
413
|
+
Input "Email", bind: profile.email, type: "email", required: true
|
|
414
|
+
SubmitButton "Save"
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Errors appear after the first submission attempt. After that, they update as
|
|
420
|
+
users edit the fields. `type: "email"` also enables email validation and requests
|
|
421
|
+
an email keyboard in the generated iOS and Android apps. For a friendlier error,
|
|
422
|
+
add `label: "Full name"` or `message: "Please enter your full name"` to the input.
|
|
423
|
+
The placeholder is the default label used in automatic error messages.
|
|
424
|
+
|
|
425
|
+
Use `bind` for these fields, or explicit `value` and `onChange` props. A validated
|
|
426
|
+
input needs an update handler. Separate forms keep their own errors. If you render
|
|
427
|
+
repeated forms with the same state, give each Form a distinct string or numeric
|
|
428
|
+
`key` to keep their validation state separate. Do not nest forms.
|
|
429
|
+
|
|
430
|
+
For complete control of your own validation UI, `validate()` remains available.
|
|
431
|
+
See `examples/form-manual.orv` for the explicit version with a rules object and
|
|
432
|
+
manual error rendering.
|
|
433
|
+
|
|
434
|
+
`validate(values, rules)` returns `{ valid, errors }`. `valid` is true when
|
|
435
|
+
every field passes. `errors` contains one message per failing field and no entry
|
|
436
|
+
for passing fields. The same validator runs on web, iOS, and Android.
|
|
437
|
+
|
|
438
|
+
| Rule | Meaning |
|
|
439
|
+
|---|---|
|
|
440
|
+
| `required: true` | Reject missing, null, empty, or whitespace-only text. |
|
|
441
|
+
| `minLength: 2` | Require at least this many Unicode code points. |
|
|
442
|
+
| `maxLength: 40` | Allow at most this many Unicode code points. |
|
|
443
|
+
| `email: true` | Check a basic email format; does not verify the mailbox exists. |
|
|
444
|
+
| `label: "Name"` | Use this name in default messages, such as “Name is required.” |
|
|
445
|
+
| `message: "Enter your name"` | Replace the default message for this field. |
|
|
446
|
+
|
|
447
|
+
Validation checks trimmed text without changing your state. Optional empty fields
|
|
448
|
+
skip length and email checks. Length limits are non-negative whole numbers;
|
|
449
|
+
unknown or invalid rules produce an error explaining what to fix. These rules
|
|
450
|
+
validate text fields; numeric and cross-field rules are not included yet.
|
|
451
|
+
|
|
452
|
+
Standalone `validate()` runs only when called. Forms with inline input rules
|
|
453
|
+
handle submission checks and error display automatically.
|
|
454
|
+
To try the complete example, run `npm run dev` here and open `/lang.html?app=form`.
|
|
455
|
+
The example validates locally; it does not send data to a server.
|
|
456
|
+
|
|
159
457
|
`Element firstArgument, name: value, name: value { children }`
|
|
160
458
|
|
|
161
459
|
| Element | First argument | Renders as |
|
|
@@ -165,13 +463,38 @@ Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
|
|
|
165
463
|
| `Box` | — | container |
|
|
166
464
|
| `Text`, `Heading` | text | text |
|
|
167
465
|
| `Button` | label | button |
|
|
466
|
+
| `Form` | — | form container with `onSubmit` |
|
|
467
|
+
| `SubmitButton` | label | submits the enclosing form |
|
|
168
468
|
| `Input` | placeholder | text field |
|
|
169
469
|
| `Image` | source URL | image |
|
|
170
470
|
| `Link` | text | link (`href: "..."`) |
|
|
171
471
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
472
|
+
### Styling, themes & dark mode
|
|
473
|
+
|
|
474
|
+
Style props work the same way across Web, iPhone, and Android:
|
|
475
|
+
|
|
476
|
+
| Category | Props |
|
|
477
|
+
|---|---|
|
|
478
|
+
| Layout & size | `width` (`120` or `"50%"`), `height`, `minWidth`, `maxWidth`, `minHeight`, `maxHeight`, `padding`, `paddingX`, `paddingY`, `margin`, `gap`, `align`, `justify` (`start`, `center`, `end`, `between`, `around`, `evenly`), `center: true`, `wrap: true`, `scroll: true`, `grow` |
|
|
479
|
+
| Appearance | `bg`, `color`, `radius`, `border`, `shadow`, `opacity` |
|
|
480
|
+
| Text & direction | `size`, `weight`, `font` (`sans`, `serif`, `mono`, or font name), `lineHeight`, `textAlign`, `rtl: true` |
|
|
481
|
+
| States | `disabled: true`, `loading: true`, `error: true` / `"message"`, `pressed: { ... }`, `focus: { ... }` |
|
|
482
|
+
|
|
483
|
+
Built-in adaptive theme tokens work out of the box and update automatically with `theme()`:
|
|
484
|
+
|
|
485
|
+
```orv
|
|
486
|
+
// Semantic colors: bg, surface, card, text, muted, primary, border, danger, success, warning
|
|
487
|
+
// Spacing: xs (4), sm (8), md (16), lg (24), xl (32) | Sizes: caption, body, subtitle, title
|
|
488
|
+
Column padding: lg, gap: md {
|
|
489
|
+
Box bg: surface, border: "1px solid border", padding: md, radius: 12 {
|
|
490
|
+
Text "Hello", size: title
|
|
491
|
+
Button theme.dark ? "Light" : "Dark", bg: primary, padding: 10, radius: 8, onTap: theme.toggle()
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Use `theme.toggle()`, `theme("dark")`, `theme("light")`, `theme("system")`, or `theme({ mode: "dark", primary: "#6366f1" })`. Buttons with `bg:` automatically get readable text colour unless you set `color:`.
|
|
497
|
+
Web-only extras (`columns`, `grid`, `position`, `cursor`, `hover`) still work in browsers and warn clearly when used in iOS/Android builds. Try `npm run dev` and open `/lang.html?app=style`.
|
|
175
498
|
|
|
176
499
|
Events: `onTap`, `onChange`, `onSubmit`, `onHover`, `onLeave`. Give a function name,
|
|
177
500
|
one statement, or a block:
|
|
@@ -188,15 +511,29 @@ Inside a view you can use `if` / `else` and `for item in list { ... }`.
|
|
|
188
511
|
|
|
189
512
|
```orv
|
|
190
513
|
screen Home {
|
|
191
|
-
|
|
514
|
+
Column {
|
|
515
|
+
Button "Open item 5", onTap: go(Detail, 5)
|
|
516
|
+
Button "About", onTap: go(About)
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
screen Detail(id) {
|
|
521
|
+
Column {
|
|
522
|
+
Button "Back", onTap: back(Home)
|
|
523
|
+
Text "Showing item {id}"
|
|
524
|
+
}
|
|
192
525
|
}
|
|
193
526
|
|
|
194
527
|
screen About {
|
|
195
|
-
Button "Back", onTap:
|
|
528
|
+
Button "Back", onTap: back(Home)
|
|
196
529
|
}
|
|
197
530
|
```
|
|
198
531
|
|
|
199
|
-
`App` (or the first screen in the file) opens first.
|
|
532
|
+
- `App` (or the first screen in the file) opens first.
|
|
533
|
+
- Pass screen arguments with `go(Detail, { id: 5 })` or `go(Detail, 5)`.
|
|
534
|
+
- **Safe back (`back(Home)`):** `back()` steps back through history, and passing an optional fallback screen like `back(Home)` goes to `Home` instead if the user arrived from a direct link or page refresh (check `canGoBack()` only if you want custom conditional UI).
|
|
535
|
+
- **URLs & deep links:** On web, navigating updates the URL (e.g. `#/detail?id=5`), so browser Refresh, Back, Forward, and direct links (`/detail/5` or `#/detail?id=5`) work automatically. On phones, `back()` and Android’s Back button / iOS edge swipe step back through history, and deep links like `myapp://detail?id=5` open directly to that screen.
|
|
536
|
+
- **Screen state:** App-level `state` (such as a list or search filter) stays intact when navigating; `state` declared inside a screen resets when you leave it or open a different item. Try `npm run dev` and open `/lang.html?app=nav`.
|
|
200
537
|
|
|
201
538
|
## Editor colours (VS Code)
|
|
202
539
|
|
|
@@ -206,6 +543,467 @@ ln -s "$PWD/editors/vscode" ~/.vscode/extensions/orvyn-lang
|
|
|
206
543
|
|
|
207
544
|
Then restart VS Code. `.orv` files get colours, comment toggling and bracket matching.
|
|
208
545
|
|
|
546
|
+
## Environments
|
|
547
|
+
|
|
548
|
+
Keep values that differ between your computer and the released app in `orvyn.config.js`:
|
|
549
|
+
|
|
550
|
+
```js
|
|
551
|
+
export default {
|
|
552
|
+
env: {
|
|
553
|
+
dev: { API_URL: "http://localhost:3000" },
|
|
554
|
+
staging: { API_URL: "https://staging.example.com" },
|
|
555
|
+
prod: { API_URL: "https://api.example.com" }
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Read them as `env.API_URL`. `env.name` is the chosen environment.
|
|
561
|
+
|
|
562
|
+
```
|
|
563
|
+
state users = load("{env.API_URL}/users")
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
- `orvyn dev`, `ios`, `android`, `run` and `check` use `dev`; `orvyn build` uses `prod`. Choose another with `--env staging`.
|
|
567
|
+
- A misspelled or missing value stops the build. `orvyn check --env prod` checks the production values.
|
|
568
|
+
- These values are built into the app, so anyone can read them. Never put secrets or private keys here.
|
|
569
|
+
- To send login tokens to a separate API server, add it to auth: `auth { login: Login, api: env.API_URL }`.
|
|
570
|
+
|
|
571
|
+
## Search engines and AI tools (SEO, AEO, GEO)
|
|
572
|
+
|
|
573
|
+
Describe each screen at its top:
|
|
574
|
+
|
|
575
|
+
```
|
|
576
|
+
screen About {
|
|
577
|
+
page title: "About Acme", description: "Who we are and what we sell", image: "https://example.com/team.png"
|
|
578
|
+
|
|
579
|
+
Column padding: 24 {
|
|
580
|
+
Heading "About Acme"
|
|
581
|
+
Question "Do you ship abroad?" {
|
|
582
|
+
Text "Yes, to 30 countries."
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
`page` takes `title`, `description`, `image`, `type: "article"`, `author`, `date` and `noindex`. It sets the browser title, link previews, the canonical address and structured data. `Question` shows a question with its answer and marks it up as structured data.
|
|
589
|
+
|
|
590
|
+
**Clean addresses.** A site served normally uses `/about` and `/product/5`. Apps opened from a `.html` file keep `#/about`. Old `#/` links still work. Set your host to answer unknown paths with `app.html` (the build makes it): for example `try_files $uri $uri/ /app.html;` in nginx, or `/* /app.html 200` in a Netlify `_redirects` file.
|
|
591
|
+
|
|
592
|
+
**Ready-made pages.** `orvyn build` writes HTML for every screen that needs no value and no login, plus `404.html`, `robots.txt` and, when `site` is set, `sitemap.xml`:
|
|
593
|
+
|
|
594
|
+
```js
|
|
595
|
+
export default {
|
|
596
|
+
site: "https://example.com",
|
|
597
|
+
seo: { allowAI: true } // false asks AI crawlers not to read the site
|
|
598
|
+
}
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
- Screens with values are made only for the values you list with `prebuild` (below).
|
|
602
|
+
- `load` and `get` with a full `https://` address are fetched during the build, so the data is in the page. **That data becomes public.** Nothing is ever sent (`post` doesn't run), and if a request fails the build stops. Relative addresses like `/api/items` show their loading state.
|
|
603
|
+
- The ready-made data is as old as your last build. The app fetches it again when it starts.
|
|
604
|
+
- Responsive sizes and hover styles apply once the app starts.
|
|
605
|
+
- A host or reverse proxy under a subfolder needs Vite's `base` set to that folder.
|
|
606
|
+
|
|
607
|
+
**Pages with values.** List them in the screen. The list can come from your server:
|
|
608
|
+
|
|
609
|
+
```
|
|
610
|
+
screen Product(id) {
|
|
611
|
+
prebuild: get("https://api.example.com/products")
|
|
612
|
+
|
|
613
|
+
state product = load("https://api.example.com/products/{id}")
|
|
614
|
+
page title: "{product.data.name ?? "Product"}", description: "{product.data.about ?? ""}"
|
|
615
|
+
|
|
616
|
+
Column padding: 24 {
|
|
617
|
+
Heading "{product.data.name}"
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
Your server returns a list like `[{ "id": 1, ... }, { "id": 2, ... }]`, and Orvyn takes the `id` from each item because the screen is `Product(id)`. This writes `/product/1`, `/product/2` and so on, and adds them to the sitemap. A fixed list works too: `prebuild: [1, 2, 3]`.
|
|
623
|
+
|
|
624
|
+
`orvyn check` warns about missing, long or repeated titles once your app uses `page`.
|
|
625
|
+
|
|
626
|
+
No tool can promise search rankings or mentions in AI answers. These features make your content readable; the content and links to it still matter.
|
|
627
|
+
|
|
628
|
+
## Form inputs
|
|
629
|
+
|
|
630
|
+
```
|
|
631
|
+
Input "Password", bind: password, type: password
|
|
632
|
+
Input "Age", bind: age, type: number
|
|
633
|
+
TextArea "Your message", bind: message
|
|
634
|
+
Checkbox "I agree", bind: agreed
|
|
635
|
+
Switch "Notifications", bind: notify
|
|
636
|
+
Select "Country", bind: country, options: ["India", "Nepal"]
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
- `Input` types: `text`, `email`, `password` (hidden on every platform), `number`, `phone`. Each shows the matching phone keyboard.
|
|
640
|
+
- Inputs hold text, also with `type: number`: use `Number(age)` to calculate.
|
|
641
|
+
- `Checkbox` and `Switch` hold `true` or `false`. `Select` holds the chosen text, or `""` before choosing.
|
|
642
|
+
- In a `Form`, rules such as `required: true` work on `Input`, `TextArea` and `Select`, not on `Checkbox` or `Switch`.
|
|
643
|
+
- In tests, `type("Country", "India")` chooses and `tap("I agree")` ticks.
|
|
644
|
+
|
|
645
|
+
## Dates, tabs and pop-ups
|
|
646
|
+
|
|
647
|
+
```
|
|
648
|
+
DatePicker "Birthday", bind: birthday // text like "2000-01-31"
|
|
649
|
+
Tabs bind: tab, options: ["Home", "Profile"]
|
|
650
|
+
if tab == "Home" {
|
|
651
|
+
Text "Welcome"
|
|
652
|
+
}
|
|
653
|
+
Button "Help", onTap: help = true
|
|
654
|
+
Modal open: help, onClose: help = false, title: "Need help?" {
|
|
655
|
+
Text "Write to us"
|
|
656
|
+
}
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
`Tabs` is a row of buttons where you place it, not a bar fixed to the bottom. A `Modal` has its own Close button.
|
|
660
|
+
|
|
661
|
+
## Camera, files and location
|
|
662
|
+
|
|
663
|
+
```
|
|
664
|
+
state photo = null
|
|
665
|
+
|
|
666
|
+
fn choose() {
|
|
667
|
+
photo = pickPhoto() // or takePhoto(), pickFile()
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
fn send() {
|
|
671
|
+
post("https://api.example.com/upload", photo)
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
screen Home {
|
|
675
|
+
Button "Choose a photo", onTap: choose()
|
|
676
|
+
if photo {
|
|
677
|
+
Image photo.dataUrl, label: "Your photo", width: 200
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
- `pickPhoto()`, `takePhoto()` and `pickFile()` give `{ name, type, size, dataUrl }`, or `null` if cancelled. `dataUrl` holds the file as text, so `post` can upload it as JSON; your server decodes it. Keep files small (a few MB).
|
|
683
|
+
- `getLocation()` gives `{ latitude, longitude, accuracy }`.
|
|
684
|
+
- Call them from a button tap. Failures (not allowed, no camera) can be caught with `try { } catch err { }`.
|
|
685
|
+
- Phones need a reason in `orvyn.config.js` for `takePhoto` and `getLocation`: `native: { permissions: { camera: "...", location: "..." } }`. The build stops if it is missing.
|
|
686
|
+
- On phones, large chosen photos are scaled down. On Android `takePhoto` returns a small preview-sized picture.
|
|
687
|
+
- In tests: `mock("photo", { name: "a.jpg" })`, `mock("camera", ...)`, `mock("file", ...)`, `mock("location", { latitude: 1, longitude: 2 })`.
|
|
688
|
+
|
|
689
|
+
## Maps
|
|
690
|
+
|
|
691
|
+
```
|
|
692
|
+
Map latitude: 28.6139, longitude: 77.2090, zoom: 14, height: 240, label: "Our office"
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Shows a map with a pin. It shows nothing until both values are there, so `Map latitude: place.latitude, longitude: place.longitude` works with `getLocation()`. Web and Android load OpenStreetMap from the internet without a key (its servers have a usage policy, so check it before heavy use); iPhone uses Apple Maps.
|
|
696
|
+
|
|
697
|
+
## Using libraries
|
|
698
|
+
|
|
699
|
+
Bring in functions from your own JavaScript or TypeScript files, or from an installed package:
|
|
700
|
+
|
|
701
|
+
```
|
|
702
|
+
use formatPrice from "./helpers.js"
|
|
703
|
+
use format from "date-fns" // after: npm install date-fns
|
|
704
|
+
|
|
705
|
+
screen Home {
|
|
706
|
+
Text formatPrice(5)
|
|
707
|
+
}
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
- Use `wait` with functions that take time: `let data = wait loadThing()`.
|
|
711
|
+
- On iPhone and Android only plain JavaScript works: a library that needs the browser page (`document`, `window`) or Node won't run there.
|
|
712
|
+
- Libraries give you functions and values, not native components or React components.
|
|
713
|
+
- The iPhone app's engine has no `crypto`, `fetch`, `URL` or other browser extras, so some packages (`nanoid`, for one) fail there while working on the web. `orvyn test` shows this early. Use such packages on the server instead.
|
|
714
|
+
- With one name, `use dayjs from "dayjs"` also works for a library that only has a default export.
|
|
715
|
+
|
|
716
|
+
## Backend: database and login
|
|
717
|
+
|
|
718
|
+
Create `server.orv` next to your app:
|
|
719
|
+
|
|
720
|
+
```
|
|
721
|
+
table notes {
|
|
722
|
+
text: text required
|
|
723
|
+
done: yesno
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
table posts public {
|
|
727
|
+
title: text required
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
table products public admin {
|
|
731
|
+
name: text required
|
|
732
|
+
price: number
|
|
733
|
+
}
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
Run it with `orvyn serve`. Field types are `text`, `number` and `yesno`.
|
|
737
|
+
|
|
738
|
+
| Table | Who reads | Who adds and changes |
|
|
739
|
+
|---|---|---|
|
|
740
|
+
| `table notes` | each person, only their own | only the owner |
|
|
741
|
+
| `table posts public` | anyone | logged-in people add; only the owner changes |
|
|
742
|
+
| `table products public admin` | anyone | only admins |
|
|
743
|
+
|
|
744
|
+
Make an admin with `orvyn admin you@example.com` after signing up.
|
|
745
|
+
|
|
746
|
+
You get these addresses:
|
|
747
|
+
|
|
748
|
+
| Address | Does |
|
|
749
|
+
|---|---|
|
|
750
|
+
| `POST /api/signup`, `POST /api/login` | `{ email, password }` → `{ token, refresh, user }` |
|
|
751
|
+
| `POST /api/refresh`, `POST /api/logout`, `GET /api/me` | keep or end the session |
|
|
752
|
+
| `GET /api/notes`, `GET /api/notes/1` | list (newest first, 100 per `?page=`) or one; filter with `?done=true` |
|
|
753
|
+
| `POST /api/notes`, `PATCH /api/notes/1`, `DELETE /api/notes/1` | add, change, delete |
|
|
754
|
+
|
|
755
|
+
In your app:
|
|
756
|
+
|
|
757
|
+
```
|
|
758
|
+
auth { login: Login, refresh: "{env.API_URL}/api/refresh", api: env.API_URL }
|
|
759
|
+
|
|
760
|
+
fn signIn() {
|
|
761
|
+
auth.login(post("{env.API_URL}/api/login", { email, password }))
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
state notes = load("{env.API_URL}/api/notes")
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### Your own backend code
|
|
768
|
+
|
|
769
|
+
Write `api` blocks in `server.orv` for anything the app must not decide itself, such as prices:
|
|
770
|
+
|
|
771
|
+
```
|
|
772
|
+
table products public admin {
|
|
773
|
+
name: text required
|
|
774
|
+
price: number required
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
table orders locked {
|
|
778
|
+
product: text
|
|
779
|
+
total: number
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
api post "/order" requires login {
|
|
783
|
+
let product = products.first(id: body.productId)
|
|
784
|
+
if !product {
|
|
785
|
+
fail "Product not found"
|
|
786
|
+
}
|
|
787
|
+
if body.qty < 1 {
|
|
788
|
+
fail "Choose at least one"
|
|
789
|
+
}
|
|
790
|
+
return orders.add(product: product.name, total: product.price * body.qty)
|
|
791
|
+
}
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
In your app: `post("{env.API_URL}/api/order", { productId: 1, qty: 2 })`.
|
|
795
|
+
|
|
796
|
+
- `api get "/..."` or `api post "/..."`, optionally `requires login` or `requires admin`.
|
|
797
|
+
- Inside: `body`, `query`, `user`, your tables, `fail "message"`, `return`, `let`, `if`, `for`, `try`, list words, `now()`.
|
|
798
|
+
- Tables: `all()`, `where(...)`, `first(...)`, `count(...)`, `add(...)`, `update(id, { ... })`, `remove(id)`.
|
|
799
|
+
- Private tables show only the caller's rows. Public tables can be read fully, but only the caller's rows changed. Your code can read and change every row of an `admin` table.
|
|
800
|
+
- **`locked`** tables can be changed only by your `api` code, so nobody can post their own total.
|
|
801
|
+
- If a request fails, everything it changed is undone. Changes run one at a time.
|
|
802
|
+
- Other services: `get(url, headers)` and `post(url, data, headers)`, with keys from `secret("NAME")`, read from the server's environment. Never write keys in the file.
|
|
803
|
+
- **Always check what `body` holds.** It comes from the user.
|
|
804
|
+
- Server code has no arrow functions, `fn` or `while`.
|
|
805
|
+
|
|
806
|
+
**Libraries on the server.** Use your own files and npm packages:
|
|
807
|
+
|
|
808
|
+
```
|
|
809
|
+
use sendEmail from "./email.js"
|
|
810
|
+
use nanoid from "nanoid" // after: npm install nanoid
|
|
811
|
+
|
|
812
|
+
api post "/contact" {
|
|
813
|
+
sendEmail("you@example.com", body.message)
|
|
814
|
+
return { id: nanoid() }
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
- Names are found by name, or as the package's default export when you ask for one name.
|
|
819
|
+
- There is no `new` and no passing of functions: for a library that needs them, write a small `.js` file around it and `use` that.
|
|
820
|
+
- A library can read everything on your server, including the database and secrets. Add only ones you trust. Never pass `body` to a library without checking it.
|
|
821
|
+
- While an `api` waits for a library, other changes wait too.
|
|
822
|
+
- `orvyn build server` copies the files you `use` (not files they import themselves) and lists the packages for `npm install`.
|
|
823
|
+
|
|
824
|
+
### Putting the server online
|
|
825
|
+
|
|
826
|
+
```
|
|
827
|
+
orvyn build server # → dist/server/
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
Upload that folder to any host that runs **Docker** or **Node 24**. Nothing needs installing.
|
|
831
|
+
|
|
832
|
+
| Setting | Meaning |
|
|
833
|
+
|---|---|
|
|
834
|
+
| `PORT` | Port to listen on (default 3000) |
|
|
835
|
+
| `ORVYN_DB` | Where the database file lives. **Put it on a disk that survives restarts** |
|
|
836
|
+
| `ORVYN_ORIGINS` | Your website's address, like `https://example.com` |
|
|
837
|
+
| `ORVYN_PROXY=1` | Set when your host puts a proxy in front (most do). Leave unset otherwise |
|
|
838
|
+
| `ORVYN_ADMIN` | Email to make admin, at the next start after signing up |
|
|
839
|
+
|
|
840
|
+
`GET /api/health` answers `{ "ok": true }` for your host's health check. Then set your app's address in `env.prod.API_URL`. Run only one copy of the server: SQLite is a single file.
|
|
841
|
+
|
|
842
|
+
**Before putting it online**
|
|
843
|
+
|
|
844
|
+
- It listens only on your computer. To accept outside connections use `--host 0.0.0.0`, and put it behind HTTPS: passwords must never travel over plain http.
|
|
845
|
+
- List the websites that may call it: `ORVYN_ORIGINS=https://example.com`.
|
|
846
|
+
- The data is in `orvyn.db`. Back it up and never commit it.
|
|
847
|
+
- Anyone can sign up. There is no email check, password reset, file storage or custom server code yet.
|
|
848
|
+
- The login limit is kept in memory and counts by network address; behind a proxy everyone shares one.
|
|
849
|
+
- It has had no independent security review.
|
|
850
|
+
|
|
851
|
+
## Types and bigger projects
|
|
852
|
+
|
|
853
|
+
Types are optional. Add them where mistakes would hurt; anything without a type is not checked.
|
|
854
|
+
|
|
855
|
+
```
|
|
856
|
+
type Product {
|
|
857
|
+
name: text
|
|
858
|
+
price: number
|
|
859
|
+
note: text? // may be left out
|
|
860
|
+
tags: list of text
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
state cart: list of Product = []
|
|
864
|
+
|
|
865
|
+
fn add(item: Product) {
|
|
866
|
+
cart.add(item)
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
component Card(item: Product) {
|
|
870
|
+
Text "{item.name}: {item.price}"
|
|
871
|
+
}
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
The types are `text`, `number`, `yesno`, your own types, and `list of` any of them. `orvyn check` and the build stop on a misspelled field, a missing field or a wrong kind of value, also inside `.where(...)`, `.total("price")` and the other list words. Types add nothing to the app.
|
|
875
|
+
|
|
876
|
+
Limits: return values of your functions and server data (`load`, `post`) are not checked, and `server.orv` uses its `table` definitions, not these types.
|
|
877
|
+
|
|
878
|
+
**Folders.** Share anything with `use`, including types:
|
|
879
|
+
|
|
880
|
+
```
|
|
881
|
+
src/
|
|
882
|
+
app.orv // screens are found from here
|
|
883
|
+
models/product.orv // type Product { ... }
|
|
884
|
+
state/cart.orv // state cart: list of Product = [], and its functions
|
|
885
|
+
components/card.orv
|
|
886
|
+
screens/checkout.orv
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
```
|
|
890
|
+
use Product from "../models/product"
|
|
891
|
+
use cart, add from "../state/cart"
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
`orvyn check` checks the main file; each other file is checked when the app is built, or with `orvyn check src/state/cart.orv`.
|
|
895
|
+
|
|
896
|
+
## Long lists
|
|
897
|
+
|
|
898
|
+
Put a loop inside `List` when there are many rows:
|
|
899
|
+
|
|
900
|
+
```
|
|
901
|
+
List height: 420, rowHeight: 44 {
|
|
902
|
+
for item in items key item.id {
|
|
903
|
+
Text item.name
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
- Every row is `rowHeight` tall (default 48) and the list is `height` tall (default 480). Content taller than a row is cut off.
|
|
909
|
+
- On the web only the rows in view are drawn. iPhone and Android draw rows as they scroll into sight, but the app still prepares all of them after each change.
|
|
910
|
+
- `key item.id` (also usable in any `for`) keeps each row's view and typed text with its item when the list changes order. Keys must be unique.
|
|
911
|
+
|
|
912
|
+
Images load lazily on the web, show a quiet placeholder and are cached on the phones.
|
|
913
|
+
|
|
914
|
+
## Accessibility
|
|
915
|
+
|
|
916
|
+
- `label:` on an element is what screen readers say: `Button "✕", label: "Delete"`. On an `Image`, `label: ""` marks it as decoration.
|
|
917
|
+
- Text follows the reader's text size setting, and button animations stop when "reduce motion" is on.
|
|
918
|
+
- `orvyn check` warns about images and symbol-only buttons without a label, and colors written in the code that are hard to read on their background. Colors chosen while the app runs aren't checked, and it assumes the light theme.
|
|
919
|
+
|
|
920
|
+
## Testing your app
|
|
921
|
+
|
|
922
|
+
Write tests at the bottom of your `.orv` file and run `orvyn test`:
|
|
923
|
+
|
|
924
|
+
```
|
|
925
|
+
test "adds a todo" {
|
|
926
|
+
type("What needs doing?", "Buy milk")
|
|
927
|
+
tap("Add")
|
|
928
|
+
expect(text("Buy milk"))
|
|
929
|
+
}
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
| In a test | Does |
|
|
933
|
+
|---|---|
|
|
934
|
+
| `tap("Add")` | Taps a button or link, by its text or `label` |
|
|
935
|
+
| `type("Name", "Ana")` | Types into the input with that placeholder or `label` |
|
|
936
|
+
| `expect(...)` | Fails the test when the value is false |
|
|
937
|
+
| `text("1 item")` | True when that text is on screen |
|
|
938
|
+
| `mock("/api/users", data, 200)` | Answers `load`, `get` and `post` to that address |
|
|
939
|
+
| `settle()` | Waits for mocked data to arrive |
|
|
940
|
+
|
|
941
|
+
Each test starts with a fresh app and empty storage. No browser or simulator is needed. Requests without a `mock` fail, so tests never reach real servers. Tests are not included in the built app.
|
|
942
|
+
|
|
943
|
+
## App settings
|
|
944
|
+
|
|
945
|
+
The `native` section of `orvyn.config.js` describes your phone app:
|
|
946
|
+
|
|
947
|
+
```js
|
|
948
|
+
export default {
|
|
949
|
+
native: {
|
|
950
|
+
appName: "Shop",
|
|
951
|
+
appId: "com.yourcompany.shop", // your own; it can't change after publishing
|
|
952
|
+
version: "1.0.0",
|
|
953
|
+
build: 1, // raise it for every upload
|
|
954
|
+
icon: "assets/icon.png", // 1024 x 1024 PNG, no transparency
|
|
955
|
+
splash: { color: "#1d4ed8", image: "assets/logo.png" },
|
|
956
|
+
permissions: { camera: "To scan product codes" },
|
|
957
|
+
ios: { teamId: "ABCDE12345" },
|
|
958
|
+
android: { keystore: "upload.jks", keyAlias: "upload" }
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
Permissions: `camera`, `microphone`, `location`, `photos`, `contacts`, `notifications`. This only declares them in the app; Orvyn has no camera or location functions yet, so declare only what you use (stores reject unused permissions).
|
|
964
|
+
|
|
965
|
+
## Publishing
|
|
966
|
+
|
|
967
|
+
Run `orvyn doctor` at any time. It lists what is missing and how to fix it.
|
|
968
|
+
|
|
969
|
+
### Website
|
|
970
|
+
|
|
971
|
+
```
|
|
972
|
+
orvyn build # → dist/web/, using the prod environment
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
Upload the contents of `dist/web/` to any static host.
|
|
976
|
+
|
|
977
|
+
### App Store
|
|
978
|
+
|
|
979
|
+
You need a Mac with Xcode and a paid Apple Developer account.
|
|
980
|
+
|
|
981
|
+
1. Sign in under Xcode → Settings → Accounts.
|
|
982
|
+
2. Put your Team ID (Apple Developer → Membership details) in `native.ios.teamId`.
|
|
983
|
+
3. Set `appId`, `icon` and a reason for each permission.
|
|
984
|
+
4. Create the app in App Store Connect with the same bundle id.
|
|
985
|
+
5. Build: `orvyn build ios --release` → signed `.ipa` in `dist/ios/build/ipa/`.
|
|
986
|
+
6. Upload it with Apple's **Transporter** app, then submit it in App Store Connect.
|
|
987
|
+
|
|
988
|
+
### Google Play
|
|
989
|
+
|
|
990
|
+
You need a Google Play developer account, Java 17 or newer, the Android SDK and Gradle.
|
|
991
|
+
|
|
992
|
+
1. Create your upload key once. Back it up, and never commit it to git:
|
|
993
|
+
```
|
|
994
|
+
keytool -genkeypair -v -keystore upload.jks -alias upload -keyalg RSA -keysize 2048 -validity 10000
|
|
995
|
+
```
|
|
996
|
+
2. Set `appId`, `icon`, `android.keystore` and `android.keyAlias`.
|
|
997
|
+
3. Give the password in the terminal, never in a file:
|
|
998
|
+
```
|
|
999
|
+
read -s ORVYN_KEYSTORE_PASSWORD && export ORVYN_KEYSTORE_PASSWORD
|
|
1000
|
+
```
|
|
1001
|
+
Set `ORVYN_KEY_PASSWORD` too if the key has a different password.
|
|
1002
|
+
4. Build: `orvyn build android --release` → `dist/android/app/build/outputs/bundle/release/app-release.aab`.
|
|
1003
|
+
5. Upload the `.aab` in Play Console.
|
|
1004
|
+
|
|
1005
|
+
Raise `build` (or `version`) before every new upload.
|
|
1006
|
+
|
|
209
1007
|
## Errors
|
|
210
1008
|
|
|
211
1009
|
The compiler stops at the first error and shows the line:
|
|
@@ -218,10 +1016,65 @@ The compiler stops at the first error and shows the line:
|
|
|
218
1016
|
| ^
|
|
219
1017
|
```
|
|
220
1018
|
|
|
1019
|
+
`orvyn check` also catches common mistakes before the app runs:
|
|
1020
|
+
|
|
1021
|
+
- Typos: `"emial" is not declared. Did you mean "email"?`
|
|
1022
|
+
- Wrong number of values: `greet() takes 1 value, but got 0 values`
|
|
1023
|
+
- Bad navigation: `There is no screen called "Profle". Did you mean "Profile"?` and `Card is a component, not a screen`
|
|
1024
|
+
|
|
1025
|
+
### When something breaks while the app runs
|
|
1026
|
+
|
|
1027
|
+
- The error says which `.orv` line was running: `[Orvyn] Tried to read "name" from something that is missing at shop.orv:42 (in Profile)`. Common JavaScript errors are turned into plain words.
|
|
1028
|
+
- If a screen or component crashes while drawing, it shows a **"Something went wrong"** card with a **Try again** button instead of a blank app. In development the card also shows the message and `file.orv:line`. Released apps hide those details.
|
|
1029
|
+
- Errors in buttons, `start { }` and `wait` are caught and reported too, so one broken button never freezes the app.
|
|
1030
|
+
- **While developing** (`npm run dev`, or `orvyn dev ios` live reload), errors pop up in a box in the middle of the screen, like Next.js. It shows the message, your code with the broken line marked (`> 17 |`), and a tip. With several errors it shows **Error 1 of 3** and ‹ › arrows. **Minimize** turns it into a small pill, **✕** or Escape closes it, and **Try again** redraws the screen. Save a fix and the app reloads without the box. Released apps never show it, and never include your source code.
|
|
1031
|
+
- Handle every error in one place by writing a function called `onError`:
|
|
1032
|
+
|
|
1033
|
+
```
|
|
1034
|
+
fn onError(err) {
|
|
1035
|
+
// err.message, err.file, err.line, err.where ("onTap in Home"), err.kind
|
|
1036
|
+
log.error("Oops:", err.message)
|
|
1037
|
+
}
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
- Logging: `log.info(...)`, `log.warn(...)`, `log.error(...)` print with the `.orv` line. `log.sendTo("https://your-server/logs")` POSTs logs and crash reports as JSON.
|
|
1041
|
+
- Try `/lang.html?app=errors`.
|
|
1042
|
+
|
|
1043
|
+
### Your own error pages
|
|
1044
|
+
|
|
1045
|
+
Declare either of these screens in your main file and Orvyn uses it. Both are optional.
|
|
1046
|
+
|
|
1047
|
+
```
|
|
1048
|
+
// a screen crashed while drawing
|
|
1049
|
+
screen ErrorPage(message, retry) {
|
|
1050
|
+
Column gap: 12, padding: 24 {
|
|
1051
|
+
Heading "Oops!"
|
|
1052
|
+
if message {
|
|
1053
|
+
Text message, color: muted
|
|
1054
|
+
}
|
|
1055
|
+
Button "Try again", onTap: retry()
|
|
1056
|
+
Button "Go home", onTap: back(Home)
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// an address that doesn't exist
|
|
1061
|
+
screen NotFound(url) {
|
|
1062
|
+
Column gap: 12, padding: 24 {
|
|
1063
|
+
Heading "404"
|
|
1064
|
+
Text "There is no page at {url}"
|
|
1065
|
+
Button "Go home", onTap: back(Home)
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
- `ErrorPage` replaces the **"Something went wrong"** card when a screen crashes. `retry()` draws the broken screen again. `message` has the error while developing and is empty in released apps; use `onError` to record the details.
|
|
1071
|
+
- A crash inside a `component` still shows the small card in its place, so one broken row doesn't take over the page. If `ErrorPage` itself crashes, the built-in card is shown.
|
|
1072
|
+
- Errors in buttons and `start { }` don't draw `ErrorPage`, because the screen is still there. Handle them with `try / catch` or `onError`.
|
|
1073
|
+
- `NotFound` is shown for unknown web addresses, phone deep links and `openUrl(...)` (which still returns `false`). The address bar keeps what was typed. Plain anchors like `#top` are ignored. Without `NotFound`, the first screen opens.
|
|
1074
|
+
- These two screens are never used as the first screen of your app.
|
|
1075
|
+
- While developing, the error box still opens on top; close it to see your `ErrorPage`.
|
|
1076
|
+
- Try `/lang.html?app=errorpage`.
|
|
1077
|
+
|
|
221
1078
|
## Not in v0.1 yet
|
|
222
1079
|
|
|
223
|
-
- Native: `Image` sizes, `justify`, and hover events are basic on phones
|
|
224
|
-
- Live reload is iPhone-only for now (Android: `orvyn android` rebuilds)
|
|
225
|
-
- `state` inside components (keep state at the top of the file for now)
|
|
226
|
-
- Browser back button with `go()`
|
|
227
1080
|
- `while` loops
|