orvyn-lang 0.2.0 → 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.
Files changed (55) hide show
  1. package/GUIDE.md +149 -0
  2. package/LANGUAGE.md +744 -27
  3. package/README.md +211 -250
  4. package/brand/orvyn-sunset-animated.svg +15 -0
  5. package/package.json +3 -1
  6. package/src/cli/orvyn.js +186 -10
  7. package/src/core/signal.js +104 -6
  8. package/src/devtools/runtime.js +25 -1
  9. package/src/lang/a11y.js +102 -0
  10. package/src/lang/auth.js +239 -0
  11. package/src/lang/bundle-native.js +10 -6
  12. package/src/lang/codegen.js +428 -57
  13. package/src/lang/device.js +41 -0
  14. package/src/lang/doctor.js +60 -0
  15. package/src/lang/env.js +27 -0
  16. package/src/lang/errors.js +513 -0
  17. package/src/lang/form.js +69 -8
  18. package/src/lang/index.js +2 -1
  19. package/src/lang/lexer.js +2 -0
  20. package/src/lang/list.js +44 -0
  21. package/src/lang/native/android/MainActivity.kt +43 -4
  22. package/src/lang/native/android/OrvynDevice.kt +163 -0
  23. package/src/lang/native/android/OrvynEngine.kt +154 -7
  24. package/src/lang/native/android/OrvynRenderer.kt +518 -44
  25. package/src/lang/native/android.js +74 -11
  26. package/src/lang/native/build.js +130 -60
  27. package/src/lang/native/config.js +108 -0
  28. package/src/lang/native/ios/OrvynApp.swift +6 -0
  29. package/src/lang/native/ios/OrvynEngine.swift +266 -4
  30. package/src/lang/native/ios/OrvynViews.swift +429 -34
  31. package/src/lang/native/ios.js +75 -2
  32. package/src/lang/native-runtime.js +406 -56
  33. package/src/lang/page.js +52 -0
  34. package/src/lang/parser.js +243 -15
  35. package/src/lang/prerender.js +300 -0
  36. package/src/lang/read-import.js +11 -0
  37. package/src/lang/router.js +266 -0
  38. package/src/lang/runtime-shared.js +792 -10
  39. package/src/lang/runtime.js +362 -52
  40. package/src/lang/select.js +13 -0
  41. package/src/lang/server-code.js +233 -0
  42. package/src/lang/server-export.js +78 -0
  43. package/src/lang/server-libs.js +53 -0
  44. package/src/lang/server.js +409 -0
  45. package/src/lang/test-runner.js +134 -0
  46. package/src/lang/types.js +312 -0
  47. package/src/lang/vite-plugin.js +82 -3
  48. package/src/lang/web-overlay.js +578 -0
  49. package/src/lang/widgets.js +94 -0
  50. package/src/lang/words.js +38 -0
  51. package/src/runtime/mount.js +116 -27
  52. package/src/runtime/patch.js +90 -11
  53. package/src/runtime/style.js +11 -1
  54. package/src/styling/fluid.js +91 -4
  55. package/src/styling/spec.js +306 -0
package/LANGUAGE.md CHANGED
@@ -35,7 +35,8 @@ cd my-app
35
35
 
36
36
  orvyn dev # web → http://localhost:5173, reloads when you save
37
37
  orvyn ios # iPhone simulator, reloads when you save
38
- 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
39
40
  orvyn check # find mistakes
40
41
  orvyn build # website → dist/web/
41
42
  orvyn build ios # Xcode project → dist/ios/ (real iPhones, App Store)
@@ -44,6 +45,19 @@ orvyn build android # Android Studio project → dist/android/
44
45
 
45
46
  Your code lives in `src/app.orv`. Orvyn finds it by itself.
46
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
+
47
61
  ### Live reload on iPhone
48
62
 
49
63
  `orvyn ios` builds the app once, then keeps running:
@@ -103,6 +117,34 @@ screen Home {
103
117
  Imported state stays reactive. Assigning to an imported fixed value or function
104
118
  reports a runtime error explaining that the declaration must use `state`.
105
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.
147
+
106
148
  ## Statements (inside `fn` and handlers)
107
149
 
108
150
  ```orv
@@ -117,6 +159,8 @@ print("hello") // logs to the console
117
159
 
118
160
  ### Lists and objects
119
161
 
162
+ Shortcut: `{ email, password }` is the same as `{ email: email, password: password }`.
163
+
120
164
  Change them with these, and the screen updates by itself:
121
165
 
122
166
  ```orv
@@ -144,26 +188,84 @@ saved state darkMode = false
144
188
 
145
189
  The value is stored on the device (browser storage on the web, UserDefaults on
146
190
  iPhone, SharedPreferences on Android) and comes back the next time the app opens.
147
- 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`.
148
202
 
149
203
  ### Internet data
150
204
 
205
+ **Show data from a server with `load`.** It starts loading when the app opens.
206
+ No `wait`, no `start` block:
207
+
151
208
  ```orv
152
- state users = []
209
+ state users = load("https://api.example.com/users")
153
210
 
154
- start {
155
- users = wait fetch("https://api.example.com/users")
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
+ }
156
224
  }
157
225
  ```
158
226
 
159
- `fetch` gives back the JSON directly. To send data: `fetch(url, { method: "POST", body: { name: "A" } })`.
160
- `wait` pauses until it's done: use it with `fetch` and `sleep(1000)`.
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) |
161
233
 
162
- Use `wait` inside a function, `start` block, event handler block, or lambda.
163
- The compiler makes that function async automatically. A lambda containing
164
- `wait` returns a promise; using it in `map` produces a list of promises, not
165
- finished results. For sequential work, use `for` inside a function instead.
166
- Top-level initializers and screen rendering cannot use `wait` directly.
234
+ **Send data with `post`.** Give it the address and the data. That's all:
235
+
236
+ ```orv
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.
167
269
 
168
270
  ```orv
169
271
  state status = "Ready"
@@ -171,7 +273,7 @@ state status = "Ready"
171
273
  screen Home {
172
274
  Button "Pause", onTap: {
173
275
  status = "Waiting"
174
- wait sleep(1000)
276
+ sleep(1000)
175
277
  status = "Done"
176
278
  }
177
279
  }
@@ -185,18 +287,80 @@ toggles, removal, clearing completed tasks, and navigation to an About screen.
185
287
  It works without a network request. Saved tasks belong to the current browser
186
288
  origin or installed app; they do not sync between devices.
187
289
 
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()
307
+ }
308
+ ```
309
+
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`.
319
+
188
320
  ### Built-in functions
189
321
 
190
322
  | Function | Does |
191
323
  |---|---|
192
324
  | `print(x)` | Log to the console |
193
- | `fetch(url)` | Get data from the internet |
194
- | `go(Screen)` | Open another screen |
195
- | `sleep(ms)` | Wait (use with `wait`) |
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 |
196
331
  | `random(1, 6)` | Random whole number |
197
332
  | `len(list)` | Number of items |
198
333
 
199
- Short functions: `todos.filter(t => t.done)`, `prices.map((p, i) => p * 2)`.
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)`.
200
364
  Choose a value: `done ? "Yes" : "No"`.
201
365
 
202
366
  ## Values
@@ -305,9 +469,32 @@ The example validates locally; it does not send data to a server.
305
469
  | `Image` | source URL | image |
306
470
  | `Link` | text | link (`href: "..."`) |
307
471
 
308
- Style props: `bg`, `color`, `size`, `padding`, `margin`, `gap`, `radius`, `width`,
309
- `height`, `align`, `justify`, `border`, `shadow`, and the rest of Orvyn's style props.
310
- Plain words like `black` or `center` are treated as text.
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`.
311
498
 
312
499
  Events: `onTap`, `onChange`, `onSubmit`, `onHover`, `onLeave`. Give a function name,
313
500
  one statement, or a block:
@@ -324,15 +511,29 @@ Inside a view you can use `if` / `else` and `for item in list { ... }`.
324
511
 
325
512
  ```orv
326
513
  screen Home {
327
- Button "About", onTap: go(About)
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
+ }
328
525
  }
329
526
 
330
527
  screen About {
331
- Button "Back", onTap: go(Home)
528
+ Button "Back", onTap: back(Home)
332
529
  }
333
530
  ```
334
531
 
335
- `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`.
336
537
 
337
538
  ## Editor colours (VS Code)
338
539
 
@@ -342,6 +543,467 @@ ln -s "$PWD/editors/vscode" ~/.vscode/extensions/orvyn-lang
342
543
 
343
544
  Then restart VS Code. `.orv` files get colours, comment toggling and bracket matching.
344
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
+
345
1007
  ## Errors
346
1008
 
347
1009
  The compiler stops at the first error and shows the line:
@@ -354,10 +1016,65 @@ The compiler stops at the first error and shows the line:
354
1016
  | ^
355
1017
  ```
356
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
+
357
1078
  ## Not in v0.1 yet
358
1079
 
359
- - Native: `Image` sizes, `justify`, and hover events are basic on phones
360
- - Live reload is iPhone-only for now (Android: `orvyn android` rebuilds)
361
- - `state` inside components (keep state at the top of the file for now)
362
- - Browser back button with `go()`
363
1080
  - `while` loops