@niscorp/moss 0.9.1 → 0.9.3

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 (79) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/DOCS.md +106 -20
  3. package/dist/{chunk-Y7PRASR3.js → chunk-6MZPY4X6.js} +60 -12
  4. package/dist/chunk-6MZPY4X6.js.map +1 -0
  5. package/dist/{chunk-L2GHVTJW.cjs → chunk-EXMOO7ZR.cjs} +135 -87
  6. package/dist/chunk-EXMOO7ZR.cjs.map +1 -0
  7. package/dist/{chunk-TGKDS2T7.cjs → chunk-IY5BOFLK.cjs} +222 -37
  8. package/dist/chunk-IY5BOFLK.cjs.map +1 -0
  9. package/dist/{chunk-WTWRLOPK.js → chunk-MVG333UF.js} +5 -4
  10. package/dist/chunk-MVG333UF.js.map +1 -0
  11. package/dist/{chunk-3RIWTXGI.cjs → chunk-NCQBGK3E.cjs} +6 -2
  12. package/dist/chunk-NCQBGK3E.cjs.map +1 -0
  13. package/dist/{chunk-UUOATPZ7.js → chunk-TAAKHW3U.js} +20 -4
  14. package/dist/chunk-TAAKHW3U.js.map +1 -0
  15. package/dist/{chunk-4ZGAFZGS.js → chunk-TKXYPO2Y.js} +6 -2
  16. package/dist/chunk-TKXYPO2Y.js.map +1 -0
  17. package/dist/{chunk-E6YAYR7G.cjs → chunk-U43CBKKE.cjs} +7 -6
  18. package/dist/chunk-U43CBKKE.cjs.map +1 -0
  19. package/dist/{chunk-TLNRFAQ6.js → chunk-UTFOMFCH.js} +207 -22
  20. package/dist/chunk-UTFOMFCH.js.map +1 -0
  21. package/dist/{chunk-LKTS4PCD.cjs → chunk-YGZS5B2U.cjs} +23 -7
  22. package/dist/chunk-YGZS5B2U.cjs.map +1 -0
  23. package/dist/client/node.d.cts +2 -2
  24. package/dist/client/node.d.ts +2 -2
  25. package/dist/client.cjs +5 -5
  26. package/dist/client.d.cts +7 -4
  27. package/dist/client.d.ts +7 -4
  28. package/dist/client.js +2 -2
  29. package/dist/{document-C3aS9uiW.d.ts → document-BzXQvEc1.d.ts} +2 -1
  30. package/dist/{document-deAs7Dre.d.cts → document-CuF4JqzJ.d.cts} +2 -1
  31. package/dist/{env-CY8EGWnD.d.cts → env-3qvvochI.d.cts} +3 -1
  32. package/dist/{env-DEPqqHEb.d.ts → env-DBPDpfU8.d.ts} +3 -1
  33. package/dist/index.cjs +15 -15
  34. package/dist/index.d.cts +2 -2
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.js +3 -3
  37. package/dist/{messages-CSwCJgH3.d.cts → messages-OSnNJL80.d.cts} +2 -0
  38. package/dist/{messages-CSwCJgH3.d.ts → messages-OSnNJL80.d.ts} +2 -0
  39. package/dist/node.cjs +8 -8
  40. package/dist/node.d.cts +1 -1
  41. package/dist/node.d.ts +1 -1
  42. package/dist/node.js +4 -4
  43. package/dist/protocol.cjs +5 -5
  44. package/dist/protocol.d.cts +1 -1
  45. package/dist/protocol.d.ts +1 -1
  46. package/dist/protocol.js +1 -1
  47. package/dist/terminal/dom/index.d.cts +2 -2
  48. package/dist/terminal/dom/index.d.ts +2 -2
  49. package/dist/terminal/index.cjs +3 -3
  50. package/dist/terminal/index.d.cts +2 -2
  51. package/dist/terminal/index.d.ts +2 -2
  52. package/dist/terminal/index.js +2 -2
  53. package/dist/terminal/react/index.d.cts +2 -2
  54. package/dist/terminal/react/index.d.ts +2 -2
  55. package/dist/terminal/react/server.d.cts +2 -2
  56. package/dist/terminal/react/server.d.ts +2 -2
  57. package/dist/terminal/tty/index.d.cts +2 -2
  58. package/dist/terminal/tty/index.d.ts +2 -2
  59. package/dist/terminal/vue/index.d.cts +2 -2
  60. package/dist/terminal/vue/index.d.ts +2 -2
  61. package/dist/terminal/vue/server.d.cts +2 -2
  62. package/dist/terminal/vue/server.d.ts +2 -2
  63. package/dist/unverified.cjs +3 -3
  64. package/dist/unverified.js +2 -2
  65. package/dist/vite.cjs +9 -9
  66. package/dist/vite.d.cts +1 -1
  67. package/dist/vite.d.ts +1 -1
  68. package/dist/vite.js +4 -4
  69. package/package.json +8 -8
  70. package/dist/chunk-3RIWTXGI.cjs.map +0 -1
  71. package/dist/chunk-4ZGAFZGS.js.map +0 -1
  72. package/dist/chunk-E6YAYR7G.cjs.map +0 -1
  73. package/dist/chunk-L2GHVTJW.cjs.map +0 -1
  74. package/dist/chunk-LKTS4PCD.cjs.map +0 -1
  75. package/dist/chunk-TGKDS2T7.cjs.map +0 -1
  76. package/dist/chunk-TLNRFAQ6.js.map +0 -1
  77. package/dist/chunk-UUOATPZ7.js.map +0 -1
  78. package/dist/chunk-WTWRLOPK.js.map +0 -1
  79. package/dist/chunk-Y7PRASR3.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @niscorp/moss
2
2
 
3
+ ## 0.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 637d412: **A vex read returns stamped JSON columns upgraded.** A JSON column whose values carry the grammar stamp they were written at in another JSON column of the row can now be named once on the engine, with a strata upgrader beside it: `createQueryEngine({ upgrader: await createUpgrader(grammars, { transform: evaluate }), upgradedColumns: { answers: { plan: { stamp: 'grammar', kind: 'acme.answers/plan' } } } })`. A kind can also be read from the row: `kind: { grammar: 'acme.notes', column: 'kind' }`. Every read that returns the column (a replay, a generated read, a reactive read's every answer, `engine.test`) hands its mapping and its caller the value upgraded, with the stamp set to the stamp the upgrade gives back. A read returns the column only as one of its own fields, with its stamp (and kind) column beside it; vex refuses any other read of it when the read is compiled. A row that does not upgrade refuses the read, or, where the column says `unreadable: 'omit'` or `'null'`, is left out or has that value set to null, with a line in `meta.warnings`. New exports: `UpgradedColumnsSchema`, `UNREADABLE_MODES`, and the types `UpgradedColumn`, `UpgradedColumns`, `ColumnUpgrader`.
8
+
9
+ **Moss takes them on the manifest.** `defineApp({ upgradedColumns })` hands them to the app's engine and to the one that answers intents, with the upgrader moss builds from nova's, Prism's and vex's grammars and the app's `grammars`. Only the app's own tables can be named. The boot is refused where a table named is a feature's, the artifactory's or the generation pointer's (their owners read them as stored), where a kind is in none of those grammars, where a column or its stamp is not a json column of the database, or where a seeded read does not compile: an app that names `upgradedColumns` has every seeded read compiled at boot and on a refresh, so a read of an upgraded column that vex refuses stops the boot rather than its first replay.
10
+
11
+ **The rulebook** says so under "Using Vex" and in rule 19.
12
+
13
+ **What to change:** nothing. An app or engine that names no `upgradedColumns` reads every column as stored, as before. No grammar, table, entry or cache format changes.
14
+
15
+ ## 0.9.2
16
+
17
+ ### Patch Changes
18
+
19
+ - a740e2a: A terminal on a phone no longer loses what is pressed around a reconnect, and either end finds out when a socket has died.
20
+ - **Connected means the screen arrived.** The wire reads `'open'` from the connection's first frame, not from the socket opening: an event sent in between reached a server that was not listening yet, and was lost without a word. A server that serves no shell now sends an empty frame too.
21
+ - **The page coming back is a check.** `WireEnv.onResume` (in `browserEnv`: `visibilitychange`, a `pageshow` from the back-forward cache, `online`) makes a closed connection again at once instead of after the backoff, and asks an open one for its screen (`resync`) while its status stays `'open'`; one that answers nothing within 2 seconds, or closes meanwhile, is replaced at once.
22
+ - **A quiet socket is checked too.** After 25 seconds of hearing nothing, while the page is visible (`WireEnv.visible`), the wire sends a `ping`, which the server answers `pong`; no answer within 10 seconds replaces the socket. Nothing waits for the answer meanwhile. `ping` comes without a protocol of its own: a server from before it answers `invalid_message`, which counts as an answer.
23
+ - **An event pressed while nothing can carry it is kept**, with the tree of its canvas, and sent once that canvas comes back exactly as it was — all kept events together, in order, or none of them; a press on the live screen, or 5 seconds, or a change of who is signed in, drops them. `droppedEvents()` on what `createWire` returns counts them (optional on the `Wire` type, so a stand-in wire an app makes itself still fits).
24
+ - **The server finds connections that are gone.** The Node transport pings every connection every 30 seconds (the WebSocket protocol's own ping, which a browser that is awake answers by itself, whatever its moss) and closes one that has not answered the last ping. A phone that went away without closing no longer keeps its shell for nobody, or its place under `anonymousShellMax`, until TCP gives up, and a signed-in person's shell starts its idle time. A phone that has put the page away answers nothing either: its shell for nobody is disposed after about a minute instead of whenever TCP gave up.
25
+ - **A screen sent again draws nothing.** A frame or canvas identical to the one on screen notifies no subscriber: a page coming back does not redraw an unchanged app, and a reconnect redraws no canvas that did not change.
26
+
27
+ **What to change:** nothing. An app that wants to tell the person a press was dropped reads `wire.droppedEvents()`. Update the server before its pages: a terminal of this release against a server of an earlier one logs an `invalid_message` warning for each ping, and against one that serves no shell it stays `'connecting'`.
28
+
3
29
  ## 0.9.1
4
30
 
5
31
  ### Patch Changes
package/DOCS.md CHANGED
@@ -59,6 +59,7 @@ type NiscApp = {
59
59
  shell?: ShellManifest; // the server shell, as data — THE APP
60
60
  pages?: Record<string, PageManifest>; // what is drawn at a path and kept by nothing
61
61
  grammars?: readonly Sequence[]; // the app's own strata grammar sequences
62
+ upgradedColumns?: UpgradedColumns; // JSON columns every vex read returns upgraded
62
63
  // the code seams
63
64
  scope?: (principal: string | null, identity?: IdentityRecord) => Record<string, unknown>;
64
65
  identity?: { as?: string; resolve: (principal, read) => Promise<IdentityRecord> };
@@ -190,8 +191,26 @@ reaction's `run` — and `features`. Absent `shell`, the app serves data only
190
191
  app does not hand over: ``shell.canvases.1.reconcile: "keyed" is not a
191
192
  reconciler the app hands over in `reconcilers` ``.
192
193
  - `grammars` — strata sequences for documents only this app defines the shape
193
- of (its kit's component props). See "Documents are read in this code's
194
- grammars" below.
194
+ of (its kit's component props, and the values of its `upgradedColumns`). See
195
+ "Documents are read in this code's grammars" below.
196
+ - `upgradedColumns` — the app's JSON columns whose values are stamped in
197
+ another column of the row, keyed by table and column:
198
+ `{ answers: { plan: { stamp: 'grammar', kind: 'acme.answers/plan' } } }`, or
199
+ with the kind read from the row, `kind: { grammar: 'acme.notes', column: 'kind' }`,
200
+ and what a read does with a row that does not upgrade, `unreadable: 'refuse' | 'omit' | 'null'`.
201
+ Moss hands them to the app's engine, and to the one that answers intents,
202
+ with the upgrader it builds from nova's, Prism's and vex's grammars and the
203
+ app's `grammars`: every read through either returns those columns upgraded,
204
+ before its mapping. What a read must select and what a row that does not
205
+ upgrade does are vex's ([Upgraded columns](../vex/DOCS.md#upgraded-columns)).
206
+ Only the app's own tables can be named: a feature's tables, the
207
+ artifactory's and the generation pointer's are read by their owner's own
208
+ entries, which read them as stored. **The boot is refused** where a table
209
+ named is one of those, where a kind, or the grammar of a kind read from the
210
+ row, is in none of the upgrader's grammars, where a column or its stamp is not a json
211
+ column of the database, and where a seeded read in `entries` does not compile
212
+ (moss compiles each one at boot, and each one a refresh hands over, only for
213
+ an app that names `upgradedColumns`).
195
214
 
196
215
  A `LayoutVariant` is `{ action: string; layout: LayoutNode }` — ring 2: the
197
216
  charter's `layouts` section selects who is granted which variant id, and moss
@@ -874,6 +893,14 @@ it does nothing else:
874
893
  has every place, and every other visitor with nobody signed in is sent
875
894
  `at_capacity` until one of those closes. People who are signed in go on
876
895
  being served.
896
+ - A connection whose other end went away without closing — a phone killed, out
897
+ of battery, out of signal — keeps its place for at most a minute. The Node
898
+ transport sends every connection the WebSocket protocol's own ping every 30
899
+ seconds, and closes one that has not answered the last one. A browser that is
900
+ awake answers it by itself, whatever its moss; one that is asleep (a phone
901
+ that has put the page away) does not, and its connection is closed too. That
902
+ close is like any other: the place is given back, a shell for nobody is
903
+ disposed, and a signed-in person's shell starts its idle time.
877
904
  - It is counted by the process that takes the connection. A deployment of N
878
905
  processes holds up to N times the limit.
879
906
  - Moss builds no limit for each address, because the address is not moss's
@@ -2160,8 +2187,8 @@ server.nudge('usr_ada', 'notes-changed');
2160
2187
  has `upgrade` (below) and `seal`. `seal` is set by the socket, on a
2161
2188
  connection whose browser holds a seal: a transport leaves it out.
2162
2189
  - `ServerMessage` (`@niscorp/moss/protocol`) — what the server sends: `hello | catalog | frame | render |
2163
- render-delta | session | error`.
2164
- - What a terminal sends is `event | publish | resync | reset | back | popTo`,
2190
+ render-delta | session | pong | error`.
2191
+ - What a terminal sends is `event | publish | resync | reset | back | popTo | ping`,
2165
2192
  each with exactly the fields the protocol names (`src/protocol/messages.ts`;
2166
2193
  the type of these is not exported, a terminal written by hand sends the
2167
2194
  object).
@@ -2186,6 +2213,10 @@ server.nudge('usr_ada', 'notes-changed');
2186
2213
  with whole frames, the state both ends can always agree on. Distinct from
2187
2214
  `reset`: the shell is fine, only this connection's copy drifted, so nothing
2188
2215
  is torn down and no other terminal notices.
2216
+ - `ping` is answered `pong`, with a shell or without one, and reaches no shell:
2217
+ it is how a terminal finds out whether a socket that has gone quiet is still
2218
+ there. It came without a protocol of its own: a server from before it answers
2219
+ `invalid_message`, which a terminal takes as an answer all the same.
2189
2220
  - `reset` names no canvas, deliberately: it is the recovery for a session whose
2190
2221
  canvases are the broken thing, so it must not travel through one. It is
2191
2222
  protocol-level, not app-level — no action declares it and no charter grants
@@ -2224,7 +2255,9 @@ server.nudge('usr_ada', 'notes-changed');
2224
2255
  for as long as it is refused.
2225
2256
  - `4426`: the two ends speak protocols the other cannot (below).
2226
2257
  - `error` codes: `invalid_token`, `session_failed`, `at_capacity`,
2227
- `client_too_old`, `server_too_old`, `no_shell` (the app serves no shell),
2258
+ `client_too_old`, `server_too_old`, `no_shell` (the app serves no shell: it
2259
+ sends an empty `frame` once it listens, as a server with a shell sends its
2260
+ first, and answers every message with this),
2228
2261
  `invalid_message`
2229
2262
  (what was sent is not JSON, not one of the messages above, or one of them
2230
2263
  with a field it does not have: nothing of it is acted on), `message_failed`
@@ -2882,7 +2915,12 @@ goes around moss: see [`FunctionSession`](#functionsession).
2882
2915
  identical either way. See [Wire size](#wire-size). `env` defaults to
2883
2916
  `browserEnv()`, and `url` (the socket's address) to `env.defaultUrl()`.
2884
2917
  - `WireEnv` — the host seam: `{ tokens: { load, save, clear, held?, key? },
2885
- socket({ url, offered }), defaultUrl() }`. The socket API is WHATWG-standard
2918
+ socket({ url, offered }), defaultUrl(), onResume?, visible? }`. `onResume(resumed)`
2919
+ calls `resumed` when the page is shown again or the network comes back and
2920
+ returns the unsubscribe; `browserEnv` listens for `visibilitychange`, a
2921
+ `pageshow` from the back-forward cache and `online`. `visible()` says
2922
+ whether the page is on screen (`browserEnv`: not `document.hidden`); absent,
2923
+ it always is. `nodeEnv` has neither. The socket API is WHATWG-standard
2886
2924
  in every host (browser, Node ≥22, Bun); an env only constructs it —
2887
2925
  `new WebSocket(url, offered)`. What is offered is who the terminal is, so an
2888
2926
  env that drops it connects as nobody. `held()` is for a host whose browser
@@ -2916,15 +2954,22 @@ goes around moss: see [`FunctionSession`](#functionsession).
2916
2954
  - **A page with nothing left to happen opens no socket.** When `initial.live`
2917
2955
  is `false`, the wire does not connect and `status()` is `'static'`. `reset()`,
2918
2956
  or a token arriving, connects after all.
2919
- - `Wire` — `{ subscribe, snapshot, status, dispatch(canvas, event), publish,
2920
- reset, back, popTo(canvas, instance), dispose }`. `snapshot()` is a
2921
- `WireSnapshot`, `{ frame, trees }`, where `trees` is a map from a canvas's id
2922
- to its tree. `status()` is a `WireStatus`,
2957
+ - `Wire` — `{ subscribe, snapshot, status, droppedEvents?, dispatch(canvas,
2958
+ event), publish, reset, back, popTo(canvas, instance), dispose }`.
2959
+ `snapshot()` is a `WireSnapshot`, `{ frame, trees }`, where `trees` is a map
2960
+ from a canvas's id to its tree. `status()` is a `WireStatus`,
2923
2961
  `'connecting' | 'open' | 'closed' | 'incompatible' | 'static'`, and changes notify subscribers like
2924
2962
  snapshot changes do (a renderer must be able to tell a dead socket from an
2925
- empty app). Hand it to a renderer.
2926
-
2927
- Reconnect is exponential backoff with jitter, capped at 30s, reset when a
2963
+ empty app). It is `'open'` from the connection's first frame, not from the
2964
+ socket opening: the server sends that frame once it listens, and a message
2965
+ before it would be lost. `droppedEvents()` is how many events the wire kept
2966
+ while it could not send them and then dropped (below); it only grows, and
2967
+ subscribers are told when it does. `createWire` always gives it; it is
2968
+ optional on the type so that a wire an app makes itself, a stand-in in a
2969
+ check, need not count. Hand it to a renderer.
2970
+
2971
+ Reconnect is exponential backoff with jitter, capped at 30s (or at once when
2972
+ the page comes back, below), reset when a
2928
2973
  connection is served its first frame and on any principal change (a session
2929
2974
  grant or a close-code recovery starts the backoff clean). Not when the socket
2930
2975
  opens: a server opens a connection before it refuses it (`4503`, `4500`), so
@@ -2953,13 +2998,54 @@ already, may have carried another principal, or may be a connect still in
2953
2998
  flight when `reset()` was called; whichever, nothing it says afterwards is
2954
2999
  heard, and its closing schedules nothing.
2955
3000
 
2956
- **Nothing is sent on a socket that is not open, and nothing is queued.**
2957
- `dispatch` and `publish` are dropped unless `status()` is `'open'` — the posture
2958
- `back` and `popTo` always had. A server-drawn page is on screen before its
2959
- socket is, so there is a moment in which something can be pressed with nothing
2960
- to send it over; an intention replayed against a screen that may have moved is
2961
- worse than one lost, and a browser socket that is still connecting throws on
2962
- `send`.
3001
+ **When the page comes back, the wire checks its socket.** A phone that puts a
3002
+ page away may kill its socket without the page hearing of it until later. On
3003
+ `onResume`, a closed connection is made again at once instead of after the
3004
+ backoff, and one that still reads open is sent `{ type: 'resync' }`. Until
3005
+ anything is heard on it, events are kept (below) and `publish`, `back` and
3006
+ `popTo` are dropped; one that answers nothing within 2 seconds is replaced, and
3007
+ one that closes meanwhile is made again at once. `status()` stays `'open'`
3008
+ through it: on a live socket it is over in a round trip, and saying otherwise
3009
+ would flicker every target on every return to the page. `reset()` is still sent
3010
+ on that socket. A connection still being made is left to finish.
3011
+
3012
+ **A socket that has gone quiet is pinged.** A socket can also die while its
3013
+ page is on screen — a network that switches, a router that drops a connection
3014
+ that says nothing. When nothing has been heard on an open connection for 25
3015
+ seconds and `visible()` is not `false`, the wire sends `{ type: 'ping' }`.
3016
+ Anything heard is the answer; one that has heard nothing 10 seconds later is
3017
+ replaced, and one that closes meanwhile is made again at once. Unlike a page
3018
+ coming back, nothing is kept while a ping is answered: the screen of a quiet
3019
+ socket is current, so presses, `back` and `publish` are sent as ever, and one
3020
+ sent onto a socket that turns out dead is lost. Nobody waits on the answer, so
3021
+ it is given long enough to spare a socket that works on a slow link. A server
3022
+ that keeps talking is never pinged; a hidden page is not pinged, and is checked
3023
+ when it comes back. 25 seconds is below the 30 to 60 seconds after which
3024
+ proxies and NATs commonly drop a quiet connection, so the ping also keeps it
3025
+ from being dropped.
3026
+
3027
+ **A screen sent again draws nothing.** A reconnect, and a page coming back,
3028
+ is sent every screen whole. A frame or a canvas whose text is the same as the
3029
+ one on screen changes nothing and tells no subscriber; a sign-in or sign-out,
3030
+ which blanks the screen, draws the next one whatever it is.
3031
+
3032
+ **Nothing is sent on a socket that is not open. An event is kept, and sent
3033
+ only onto the screen it was pressed on.** A server-drawn page is on screen
3034
+ before its socket is, and a page that comes back is on screen before its
3035
+ connection is, so there is a moment in which something can be pressed with
3036
+ nothing to send it over. `dispatch` then keeps the event with the tree of the
3037
+ canvas it names, as the terminal showed it. Once the connection is open and
3038
+ every canvas the kept events name has come back on it, they are sent, in the
3039
+ order they were pressed, if each of those canvases came back exactly as it
3040
+ was; otherwise all of them are dropped. They are also dropped when that has
3041
+ not happened 5 seconds after the first was pressed, and when a sign-in or
3042
+ sign-out changes who the terminal is. Dropped together, because an intention
3043
+ replayed against a screen that has moved since is worse than one lost, and so
3044
+ is half of a sequence. `droppedEvents()` counts them, for an app that tells
3045
+ the person. An event pressed while nothing can carry it joins the kept ones;
3046
+ one pressed once the connection is open drops them and is sent, because it was
3047
+ pressed on the screen the person sees now. `publish`, `back` and `popTo` name
3048
+ no canvas to check against, and are dropped unless the connection is open.
2963
3049
 
2964
3050
  `back()` sends `{ type: 'back' }` and nothing else — no location is held here,
2965
3051
  so what comes back is whatever canvases moved, over the same stream every other
@@ -1,6 +1,6 @@
1
- import { entriesOf, receiveManifest, verifiedAtBoot, verifyManifest, withFragments, candidateOf, FRAME_LAYOUT_REF, canvasLayoutRef, functionsIn, charterOverFunctions, refusalOf, functionsWarning, layoutMisfits, freezeDeep, entryMisfits, sessionOn, endlessChains, actionLayoutRef, endShell, GENERATED_ID_PREFIX, layoutNameRefusal, actionOfLayoutRef, withLayoutInPlace, canvasesOf, treeOf, buildShell, SHELL_GONE, draftedIn, attach, holdGranted, layoutsOf, withVariants, variantLayouts } from './chunk-WTWRLOPK.js';
1
+ import { entriesOf, receiveManifest, verifiedAtBoot, verifyManifest, withFragments, candidateOf, FRAME_LAYOUT_REF, canvasLayoutRef, functionsIn, charterOverFunctions, refusalOf, functionsWarning, layoutMisfits, freezeDeep, entryMisfits, sessionOn, endlessChains, actionLayoutRef, endShell, GENERATED_ID_PREFIX, layoutNameRefusal, actionOfLayoutRef, withLayoutInPlace, canvasesOf, treeOf, buildShell, SHELL_GONE, draftedIn, attach, holdGranted, layoutsOf, withVariants, variantLayouts } from './chunk-MVG333UF.js';
2
2
  import { emitterOf, FabricMessageSchema, spanClock } from './chunk-QAHDSRPK.js';
3
- import { DEFAULT_TOKEN_KEY, sessionNameOf, SNAPSHOT_ELEMENT_ID, CLOSE_SHELL_FAILED, CLOSE_PROTOCOL_MISMATCH, CLOSE_INVALID_TOKEN, CLOSE_AT_CAPACITY, PROTOCOL_MIN, PROTOCOL, offeredSealed, offeredToken, ClientMessageSchema } from './chunk-4ZGAFZGS.js';
3
+ import { DEFAULT_TOKEN_KEY, sessionNameOf, SNAPSHOT_ELEMENT_ID, CLOSE_SHELL_FAILED, CLOSE_PROTOCOL_MISMATCH, CLOSE_INVALID_TOKEN, CLOSE_AT_CAPACITY, PROTOCOL_MIN, PROTOCOL, offeredSealed, offeredToken, ClientMessageSchema } from './chunk-TKXYPO2Y.js';
4
4
  import { z } from 'zod';
5
5
  import { randomBytes, createHash, timingSafeEqual, randomUUID } from 'crypto';
6
6
  import { createPostgresCache, createPostgresAdapter, resolve, pruneOptional, mutationMisfits, createMemoryCache, seedCache, handleDiscovery, handleQuery, mergeScopePolicies, createScopePolicy, createQueryEngine, scopeGrants, tablesChangedBy } from '@niscorp/vex';
@@ -731,7 +731,12 @@ var createDataLayer = async (deps) => {
731
731
  const table = deps.cache ?? createPostgresCache({ pool: deps.pool });
732
732
  await table.init?.();
733
733
  const { cache, askFirst } = createEntryCache(table);
734
- const engine = createQueryEngine({ adapter, cache, ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {} });
734
+ const engine = createQueryEngine({
735
+ adapter,
736
+ cache,
737
+ ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {},
738
+ ...deps.upgradedColumns !== void 0 && deps.upgrader !== void 0 ? { upgradedColumns: deps.upgradedColumns, upgrader: deps.upgrader } : {}
739
+ });
735
740
  const schema = await engine.introspect();
736
741
  return { engine, adapter, schema, grants: scopeGrants(schema.entities.map((e) => e.name)), askFirst };
737
742
  };
@@ -991,7 +996,8 @@ var createIntentAnswers = (deps) => {
991
996
  generateDsl: writers.generateDsl,
992
997
  mapToShape: writers.mapToShape,
993
998
  ...deps.behaviors !== void 0 ? { behaviors: deps.behaviors } : {},
994
- ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {}
999
+ ...deps.vexConfig !== void 0 ? { config: deps.vexConfig } : {},
1000
+ ...deps.upgradedColumns !== void 0 && deps.upgrader !== void 0 ? { upgradedColumns: deps.upgradedColumns, upgrader: deps.upgrader } : {}
995
1001
  });
996
1002
  await engine.introspect();
997
1003
  return engine;
@@ -1018,7 +1024,7 @@ var prepareEngine = async (config) => {
1018
1024
  );
1019
1025
  });
1020
1026
  const grammars = await createGrammarUpgrader({ grammars: config.grammars });
1021
- const layer = await createDataLayer(config);
1027
+ const layer = await createDataLayer({ ...config, upgrader: grammars });
1022
1028
  return {
1023
1029
  grammars,
1024
1030
  engine: layer.engine,
@@ -1042,7 +1048,8 @@ var lazyIntentAnswers = (prepared, config) => {
1042
1048
  schema,
1043
1049
  cache: engine.cache,
1044
1050
  ...config.behaviors !== void 0 ? { behaviors: config.behaviors } : {},
1045
- ...config.vexConfig !== void 0 ? { vexConfig: config.vexConfig } : {}
1051
+ ...config.vexConfig !== void 0 ? { vexConfig: config.vexConfig } : {},
1052
+ ...config.upgradedColumns !== void 0 ? { upgradedColumns: config.upgradedColumns, upgrader: prepared.grammars } : {}
1046
1053
  });
1047
1054
  return answers;
1048
1055
  };
@@ -1053,6 +1060,20 @@ var tablesByFeature = (config) => (feature) => {
1053
1060
  if (kept === void 0) throw new Error(`moss: the data module was asked for the tables of a feature it was never told of ("${feature}").`);
1054
1061
  return kept.names;
1055
1062
  };
1063
+ var refuseUpgradedOwnedTables = (config) => {
1064
+ const owners = new Map([
1065
+ ...(config.featureTables ?? []).flatMap((tables) => tables.names.map((name) => [name, `the feature "${tables.feature}"`])),
1066
+ ...ARTIFACT_TABLES.map((name) => [name, "the artifactory"]),
1067
+ ...POINTER.tables.map((name) => [name, POINTER.owner])
1068
+ ]);
1069
+ const owned = Object.keys(config.upgradedColumns ?? {}).flatMap((table) => {
1070
+ const owner = owners.get(table);
1071
+ return owner === void 0 ? [] : [`"${table}" is ${owner}'s`];
1072
+ });
1073
+ if (owned.length > 0) {
1074
+ throw new Error(`moss: the app's \`upgradedColumns\` name tables it does not own (${owned.join("; ")}). Their owner reads them as stored: name only the app's own tables.`);
1075
+ }
1076
+ };
1056
1077
  var createUpgradeStore = (prepared, tablesOf) => async (feature, store) => {
1057
1078
  const own = tablesOf(feature);
1058
1079
  if (store.schema !== void 0) {
@@ -1066,6 +1087,7 @@ var createUpgradeStore = (prepared, tablesOf) => async (feature, store) => {
1066
1087
  await prepared.upgradeStore(store);
1067
1088
  };
1068
1089
  var createDataWith = (prepared, config) => {
1090
+ refuseUpgradedOwnedTables(config);
1069
1091
  const { grammars, engine, grants } = prepared;
1070
1092
  const governed = { charter: config.charter, behaviors: { ...config.behaviors, ...config.rowRules } };
1071
1093
  const policies = createPolicies({ ...governed, grants });
@@ -1461,6 +1483,19 @@ var generatedInForce = async (inForce2, heldTo, whose) => {
1461
1483
  };
1462
1484
  return { actions: await passed("action", readAction), fragments: await passed("fragment", readFragment) };
1463
1485
  };
1486
+ var refuseUnrunnable = (entries, compile2, heading) => {
1487
+ if (compile2 === void 0) return;
1488
+ const unrunnable = entries.flatMap((entry) => {
1489
+ if (!("dsl" in entry)) return [];
1490
+ try {
1491
+ compile2(entry.dsl);
1492
+ return [];
1493
+ } catch (error) {
1494
+ return [` "${entry.fingerprint}": ${error instanceof Error ? error.message : String(error)}`];
1495
+ }
1496
+ });
1497
+ if (unrunnable.length > 0) throw new Error([heading, ...unrunnable].join("\n"));
1498
+ };
1464
1499
  var compileEntries = async (entries) => {
1465
1500
  const compiled = createMemoryCache();
1466
1501
  await seedCache(compiled, entries);
@@ -1471,7 +1506,8 @@ var mergedEntries = (own, sets) => {
1471
1506
  for (const entry of [...own, ...[...sets.values()].flat()]) byFingerprint.set(entry.fingerprint, entry);
1472
1507
  return Object.freeze([...byFingerprint.values()]);
1473
1508
  };
1474
- var createEntriesInForce = (own) => {
1509
+ var createEntriesInForce = (own, compileRead) => {
1510
+ refuseUnrunnable(own, compileRead, "Seeded reads that do not run \u2014 refusing to serve:");
1475
1511
  let sets = /* @__PURE__ */ new Map();
1476
1512
  let list = mergedEntries(own, sets);
1477
1513
  let byFingerprint = new Map(list.map((entry) => [entry.fingerprint, entry]));
@@ -1484,6 +1520,7 @@ var createEntriesInForce = (own) => {
1484
1520
  holdsSet: (source) => sets.has(source),
1485
1521
  withSet: (source, handed) => mergedEntries(own, new Map([...sets, [source, handed]])),
1486
1522
  takeSet: (source, handed, taken) => {
1523
+ refuseUnrunnable(handed, compileRead, "Refresh refused \u2014 seeded reads that do not run:");
1487
1524
  sets = new Map([...sets, [source, handed]]);
1488
1525
  list = mergedEntries(own, sets);
1489
1526
  byFingerprint = new Map(list.map((entry) => [entry.fingerprint, entry]));
@@ -1989,7 +2026,7 @@ var tell = (listener, ...told) => {
1989
2026
  };
1990
2027
  var createRunningManifest = (config) => {
1991
2028
  const { shipped } = config;
1992
- const entries = createEntriesInForce(entriesOf(shipped));
2029
+ const entries = createEntriesInForce(entriesOf(shipped), config.compileSeeded);
1993
2030
  let defaults = NO_DEFAULTS;
1994
2031
  const usage = createUsage(config.touchEveryMs ?? TOUCH_EVERY_MS);
1995
2032
  let functionIds;
@@ -2568,6 +2605,10 @@ var messageHandler = (session, connection, send) => {
2568
2605
  send({ type: "error", code: "invalid_message", message: INVALID_MESSAGE });
2569
2606
  return;
2570
2607
  }
2608
+ if (message.type === "ping") {
2609
+ send({ type: "pong" });
2610
+ return;
2611
+ }
2571
2612
  if (session === void 0) {
2572
2613
  send({ type: "error", code: "no_shell", message: "This app serves no shell.", ...message.type === "event" ? { canvas: message.canvas } : {} });
2573
2614
  return;
@@ -2663,7 +2704,10 @@ var served = async (config, connection, send, close, opening, who) => {
2663
2704
  if (close.ended()) return void 0;
2664
2705
  send({ type: "hello", protocol: PROTOCOL, principal: who.principal, catalog: { actions: ids, hash } });
2665
2706
  const session = await opening.session?.(who.token, who.principal);
2666
- if (session === void 0) return void 0;
2707
+ if (session === void 0) {
2708
+ if (!close.ended()) send({ type: "frame", tree: [] });
2709
+ return void 0;
2710
+ }
2667
2711
  if (!close.ended()) session.attach(connection, { delta: opening.delta });
2668
2712
  close.whenClosed(() => session.detach(connection));
2669
2713
  return session;
@@ -3431,6 +3475,7 @@ var buildData = (app, runtime) => createData({
3431
3475
  featureTables: featureTablesOf(app),
3432
3476
  tables: runtime.tables,
3433
3477
  grammars: app.grammars,
3478
+ upgradedColumns: app.upgradedColumns,
3434
3479
  charter: app.charter,
3435
3480
  behaviors: app.behaviors,
3436
3481
  rowRules: rowRulesBeside(app.behaviors),
@@ -3525,7 +3570,10 @@ var buildRunningManifest = async (app, runtime, data, saved) => {
3525
3570
  // Polled on the clock a socket's credential is re-verified on.
3526
3571
  pointer: { read: data.pointer.read, move: data.pointer.move, ...runtime.sessionRevalidateMs !== void 0 ? { everyMs: runtime.sessionRevalidateMs } : {} },
3527
3572
  shells: [...app.shell !== void 0 ? [app.shell] : [], ...Object.values(app.pages ?? {})],
3528
- ...saved !== void 0 ? { published: saved.published().inForce, reads: { written: data.vexEntry, compile: data.compileQuery, savedOf: saved.of } } : {}
3573
+ ...saved !== void 0 ? { published: saved.published().inForce, reads: { written: data.vexEntry, compile: data.compileQuery, savedOf: saved.of } } : {},
3574
+ // Only where the app names upgradedColumns: vex refuses some reads of those when it compiles a read, and a seeded
3575
+ // read is otherwise first compiled at its first replay. An app that names none boots as before.
3576
+ ...app.upgradedColumns !== void 0 ? { compileSeeded: data.compileQuery } : {}
3529
3577
  });
3530
3578
  data.dropOnChange(running.onChange);
3531
3579
  data.entriesHeldBy({ get: running.cacheEntry, entries: running.cacheEntries });
@@ -3583,5 +3631,5 @@ var subscribeReactions = ({ app, onWrite, deliver }) => {
3583
3631
  };
3584
3632
 
3585
3633
  export { MOSS_SEQUENCE, createServer, exportDocuments, migrateTables, mintDevToken, mintSession, renderDocument, revokeAllFor, sessionCookies, tableStatus };
3586
- //# sourceMappingURL=chunk-Y7PRASR3.js.map
3587
- //# sourceMappingURL=chunk-Y7PRASR3.js.map
3634
+ //# sourceMappingURL=chunk-6MZPY4X6.js.map
3635
+ //# sourceMappingURL=chunk-6MZPY4X6.js.map