@niscorp/moss 0.9.1 → 0.9.2

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 (69) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/DOCS.md +85 -18
  3. package/dist/{chunk-WTWRLOPK.js → chunk-5ZB7FZ2J.js} +3 -3
  4. package/dist/{chunk-WTWRLOPK.js.map → chunk-5ZB7FZ2J.js.map} +1 -1
  5. package/dist/{chunk-E6YAYR7G.cjs → chunk-6ZWMC2OV.cjs} +6 -6
  6. package/dist/{chunk-E6YAYR7G.cjs.map → chunk-6ZWMC2OV.cjs.map} +1 -1
  7. package/dist/{chunk-UUOATPZ7.js → chunk-FUJRIO4N.js} +20 -4
  8. package/dist/chunk-FUJRIO4N.js.map +1 -0
  9. package/dist/{chunk-TGKDS2T7.cjs → chunk-IY5BOFLK.cjs} +222 -37
  10. package/dist/chunk-IY5BOFLK.cjs.map +1 -0
  11. package/dist/{chunk-LKTS4PCD.cjs → chunk-KMZT6NVL.cjs} +23 -7
  12. package/dist/chunk-KMZT6NVL.cjs.map +1 -0
  13. package/dist/{chunk-L2GHVTJW.cjs → chunk-KVXP6OTW.cjs} +88 -81
  14. package/dist/chunk-KVXP6OTW.cjs.map +1 -0
  15. package/dist/{chunk-3RIWTXGI.cjs → chunk-NCQBGK3E.cjs} +6 -2
  16. package/dist/chunk-NCQBGK3E.cjs.map +1 -0
  17. package/dist/{chunk-4ZGAFZGS.js → chunk-TKXYPO2Y.js} +6 -2
  18. package/dist/chunk-TKXYPO2Y.js.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-Y7PRASR3.js → chunk-WMIJU6ZZ.js} +12 -5
  22. package/dist/chunk-WMIJU6ZZ.js.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/{env-CY8EGWnD.d.cts → env-3qvvochI.d.cts} +3 -1
  30. package/dist/{env-DEPqqHEb.d.ts → env-DBPDpfU8.d.ts} +3 -1
  31. package/dist/index.cjs +15 -15
  32. package/dist/index.js +3 -3
  33. package/dist/{messages-CSwCJgH3.d.cts → messages-OSnNJL80.d.cts} +2 -0
  34. package/dist/{messages-CSwCJgH3.d.ts → messages-OSnNJL80.d.ts} +2 -0
  35. package/dist/node.cjs +8 -8
  36. package/dist/node.js +4 -4
  37. package/dist/protocol.cjs +5 -5
  38. package/dist/protocol.d.cts +1 -1
  39. package/dist/protocol.d.ts +1 -1
  40. package/dist/protocol.js +1 -1
  41. package/dist/terminal/dom/index.d.cts +2 -2
  42. package/dist/terminal/dom/index.d.ts +2 -2
  43. package/dist/terminal/index.cjs +3 -3
  44. package/dist/terminal/index.d.cts +2 -2
  45. package/dist/terminal/index.d.ts +2 -2
  46. package/dist/terminal/index.js +2 -2
  47. package/dist/terminal/react/index.d.cts +2 -2
  48. package/dist/terminal/react/index.d.ts +2 -2
  49. package/dist/terminal/react/server.d.cts +2 -2
  50. package/dist/terminal/react/server.d.ts +2 -2
  51. package/dist/terminal/tty/index.d.cts +2 -2
  52. package/dist/terminal/tty/index.d.ts +2 -2
  53. package/dist/terminal/vue/index.d.cts +2 -2
  54. package/dist/terminal/vue/index.d.ts +2 -2
  55. package/dist/terminal/vue/server.d.cts +2 -2
  56. package/dist/terminal/vue/server.d.ts +2 -2
  57. package/dist/unverified.cjs +3 -3
  58. package/dist/unverified.js +2 -2
  59. package/dist/vite.cjs +9 -9
  60. package/dist/vite.js +4 -4
  61. package/package.json +5 -5
  62. package/dist/chunk-3RIWTXGI.cjs.map +0 -1
  63. package/dist/chunk-4ZGAFZGS.js.map +0 -1
  64. package/dist/chunk-L2GHVTJW.cjs.map +0 -1
  65. package/dist/chunk-LKTS4PCD.cjs.map +0 -1
  66. package/dist/chunk-TGKDS2T7.cjs.map +0 -1
  67. package/dist/chunk-TLNRFAQ6.js.map +0 -1
  68. package/dist/chunk-UUOATPZ7.js.map +0 -1
  69. package/dist/chunk-Y7PRASR3.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @niscorp/moss
2
2
 
3
+ ## 0.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 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.
8
+ - **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.
9
+ - **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.
10
+ - **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.
11
+ - **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).
12
+ - **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.
13
+ - **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.
14
+
15
+ **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'`.
16
+
3
17
  ## 0.9.1
4
18
 
5
19
  ### Patch Changes
package/DOCS.md CHANGED
@@ -874,6 +874,14 @@ it does nothing else:
874
874
  has every place, and every other visitor with nobody signed in is sent
875
875
  `at_capacity` until one of those closes. People who are signed in go on
876
876
  being served.
877
+ - A connection whose other end went away without closing — a phone killed, out
878
+ of battery, out of signal — keeps its place for at most a minute. The Node
879
+ transport sends every connection the WebSocket protocol's own ping every 30
880
+ seconds, and closes one that has not answered the last one. A browser that is
881
+ awake answers it by itself, whatever its moss; one that is asleep (a phone
882
+ that has put the page away) does not, and its connection is closed too. That
883
+ close is like any other: the place is given back, a shell for nobody is
884
+ disposed, and a signed-in person's shell starts its idle time.
877
885
  - It is counted by the process that takes the connection. A deployment of N
878
886
  processes holds up to N times the limit.
879
887
  - Moss builds no limit for each address, because the address is not moss's
@@ -2160,8 +2168,8 @@ server.nudge('usr_ada', 'notes-changed');
2160
2168
  has `upgrade` (below) and `seal`. `seal` is set by the socket, on a
2161
2169
  connection whose browser holds a seal: a transport leaves it out.
2162
2170
  - `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`,
2171
+ render-delta | session | pong | error`.
2172
+ - What a terminal sends is `event | publish | resync | reset | back | popTo | ping`,
2165
2173
  each with exactly the fields the protocol names (`src/protocol/messages.ts`;
2166
2174
  the type of these is not exported, a terminal written by hand sends the
2167
2175
  object).
@@ -2186,6 +2194,10 @@ server.nudge('usr_ada', 'notes-changed');
2186
2194
  with whole frames, the state both ends can always agree on. Distinct from
2187
2195
  `reset`: the shell is fine, only this connection's copy drifted, so nothing
2188
2196
  is torn down and no other terminal notices.
2197
+ - `ping` is answered `pong`, with a shell or without one, and reaches no shell:
2198
+ it is how a terminal finds out whether a socket that has gone quiet is still
2199
+ there. It came without a protocol of its own: a server from before it answers
2200
+ `invalid_message`, which a terminal takes as an answer all the same.
2189
2201
  - `reset` names no canvas, deliberately: it is the recovery for a session whose
2190
2202
  canvases are the broken thing, so it must not travel through one. It is
2191
2203
  protocol-level, not app-level — no action declares it and no charter grants
@@ -2224,7 +2236,9 @@ server.nudge('usr_ada', 'notes-changed');
2224
2236
  for as long as it is refused.
2225
2237
  - `4426`: the two ends speak protocols the other cannot (below).
2226
2238
  - `error` codes: `invalid_token`, `session_failed`, `at_capacity`,
2227
- `client_too_old`, `server_too_old`, `no_shell` (the app serves no shell),
2239
+ `client_too_old`, `server_too_old`, `no_shell` (the app serves no shell: it
2240
+ sends an empty `frame` once it listens, as a server with a shell sends its
2241
+ first, and answers every message with this),
2228
2242
  `invalid_message`
2229
2243
  (what was sent is not JSON, not one of the messages above, or one of them
2230
2244
  with a field it does not have: nothing of it is acted on), `message_failed`
@@ -2882,7 +2896,12 @@ goes around moss: see [`FunctionSession`](#functionsession).
2882
2896
  identical either way. See [Wire size](#wire-size). `env` defaults to
2883
2897
  `browserEnv()`, and `url` (the socket's address) to `env.defaultUrl()`.
2884
2898
  - `WireEnv` — the host seam: `{ tokens: { load, save, clear, held?, key? },
2885
- socket({ url, offered }), defaultUrl() }`. The socket API is WHATWG-standard
2899
+ socket({ url, offered }), defaultUrl(), onResume?, visible? }`. `onResume(resumed)`
2900
+ calls `resumed` when the page is shown again or the network comes back and
2901
+ returns the unsubscribe; `browserEnv` listens for `visibilitychange`, a
2902
+ `pageshow` from the back-forward cache and `online`. `visible()` says
2903
+ whether the page is on screen (`browserEnv`: not `document.hidden`); absent,
2904
+ it always is. `nodeEnv` has neither. The socket API is WHATWG-standard
2886
2905
  in every host (browser, Node ≥22, Bun); an env only constructs it —
2887
2906
  `new WebSocket(url, offered)`. What is offered is who the terminal is, so an
2888
2907
  env that drops it connects as nobody. `held()` is for a host whose browser
@@ -2916,15 +2935,22 @@ goes around moss: see [`FunctionSession`](#functionsession).
2916
2935
  - **A page with nothing left to happen opens no socket.** When `initial.live`
2917
2936
  is `false`, the wire does not connect and `status()` is `'static'`. `reset()`,
2918
2937
  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`,
2938
+ - `Wire` — `{ subscribe, snapshot, status, droppedEvents?, dispatch(canvas,
2939
+ event), publish, reset, back, popTo(canvas, instance), dispose }`.
2940
+ `snapshot()` is a `WireSnapshot`, `{ frame, trees }`, where `trees` is a map
2941
+ from a canvas's id to its tree. `status()` is a `WireStatus`,
2923
2942
  `'connecting' | 'open' | 'closed' | 'incompatible' | 'static'`, and changes notify subscribers like
2924
2943
  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
2944
+ empty app). It is `'open'` from the connection's first frame, not from the
2945
+ socket opening: the server sends that frame once it listens, and a message
2946
+ before it would be lost. `droppedEvents()` is how many events the wire kept
2947
+ while it could not send them and then dropped (below); it only grows, and
2948
+ subscribers are told when it does. `createWire` always gives it; it is
2949
+ optional on the type so that a wire an app makes itself, a stand-in in a
2950
+ check, need not count. Hand it to a renderer.
2951
+
2952
+ Reconnect is exponential backoff with jitter, capped at 30s (or at once when
2953
+ the page comes back, below), reset when a
2928
2954
  connection is served its first frame and on any principal change (a session
2929
2955
  grant or a close-code recovery starts the backoff clean). Not when the socket
2930
2956
  opens: a server opens a connection before it refuses it (`4503`, `4500`), so
@@ -2953,13 +2979,54 @@ already, may have carried another principal, or may be a connect still in
2953
2979
  flight when `reset()` was called; whichever, nothing it says afterwards is
2954
2980
  heard, and its closing schedules nothing.
2955
2981
 
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`.
2982
+ **When the page comes back, the wire checks its socket.** A phone that puts a
2983
+ page away may kill its socket without the page hearing of it until later. On
2984
+ `onResume`, a closed connection is made again at once instead of after the
2985
+ backoff, and one that still reads open is sent `{ type: 'resync' }`. Until
2986
+ anything is heard on it, events are kept (below) and `publish`, `back` and
2987
+ `popTo` are dropped; one that answers nothing within 2 seconds is replaced, and
2988
+ one that closes meanwhile is made again at once. `status()` stays `'open'`
2989
+ through it: on a live socket it is over in a round trip, and saying otherwise
2990
+ would flicker every target on every return to the page. `reset()` is still sent
2991
+ on that socket. A connection still being made is left to finish.
2992
+
2993
+ **A socket that has gone quiet is pinged.** A socket can also die while its
2994
+ page is on screen — a network that switches, a router that drops a connection
2995
+ that says nothing. When nothing has been heard on an open connection for 25
2996
+ seconds and `visible()` is not `false`, the wire sends `{ type: 'ping' }`.
2997
+ Anything heard is the answer; one that has heard nothing 10 seconds later is
2998
+ replaced, and one that closes meanwhile is made again at once. Unlike a page
2999
+ coming back, nothing is kept while a ping is answered: the screen of a quiet
3000
+ socket is current, so presses, `back` and `publish` are sent as ever, and one
3001
+ sent onto a socket that turns out dead is lost. Nobody waits on the answer, so
3002
+ it is given long enough to spare a socket that works on a slow link. A server
3003
+ that keeps talking is never pinged; a hidden page is not pinged, and is checked
3004
+ when it comes back. 25 seconds is below the 30 to 60 seconds after which
3005
+ proxies and NATs commonly drop a quiet connection, so the ping also keeps it
3006
+ from being dropped.
3007
+
3008
+ **A screen sent again draws nothing.** A reconnect, and a page coming back,
3009
+ is sent every screen whole. A frame or a canvas whose text is the same as the
3010
+ one on screen changes nothing and tells no subscriber; a sign-in or sign-out,
3011
+ which blanks the screen, draws the next one whatever it is.
3012
+
3013
+ **Nothing is sent on a socket that is not open. An event is kept, and sent
3014
+ only onto the screen it was pressed on.** A server-drawn page is on screen
3015
+ before its socket is, and a page that comes back is on screen before its
3016
+ connection is, so there is a moment in which something can be pressed with
3017
+ nothing to send it over. `dispatch` then keeps the event with the tree of the
3018
+ canvas it names, as the terminal showed it. Once the connection is open and
3019
+ every canvas the kept events name has come back on it, they are sent, in the
3020
+ order they were pressed, if each of those canvases came back exactly as it
3021
+ was; otherwise all of them are dropped. They are also dropped when that has
3022
+ not happened 5 seconds after the first was pressed, and when a sign-in or
3023
+ sign-out changes who the terminal is. Dropped together, because an intention
3024
+ replayed against a screen that has moved since is worse than one lost, and so
3025
+ is half of a sequence. `droppedEvents()` counts them, for an app that tells
3026
+ the person. An event pressed while nothing can carry it joins the kept ones;
3027
+ one pressed once the connection is open drops them and is sent, because it was
3028
+ pressed on the screen the person sees now. `publish`, `back` and `popTo` name
3029
+ no canvas to check against, and are dropped unless the connection is open.
2963
3030
 
2964
3031
  `back()` sends `{ type: 'back' }` and nothing else — no location is held here,
2965
3032
  so what comes back is whatever canvases moved, over the same stream every other
@@ -1,5 +1,5 @@
1
1
  import { spanClock } from './chunk-QAHDSRPK.js';
2
- import { CLOSE_SIGNED_OUT, encodeDelta, frameHash } from './chunk-4ZGAFZGS.js';
2
+ import { CLOSE_SIGNED_OUT, encodeDelta, frameHash } from './chunk-TKXYPO2Y.js';
3
3
  import { verifyCharter, resolvePrincipal, normalizeRole } from '@niscorp/charter';
4
4
  import { LayoutNodeSchema, ActionFragmentSchema, ActionDefinitionSchema, collectChannels, auditAction, canvasTreeOf, NovaEventSchema, createComponentRegistry, createLayoutStore, createShell } from '@niscorp/nova';
5
5
  import { chainCycles, walkNodes, isRecord } from '@niscorp/nova/reflect';
@@ -919,5 +919,5 @@ var buildShell = async (host, asked) => {
919
919
  };
920
920
 
921
921
  export { FRAME_LAYOUT_REF, GENERATED_ID_PREFIX, SHELL_GONE, actionLayoutRef, actionOfLayoutRef, attach, buildShell, candidateOf, canvasLayoutRef, canvasesOf, charterOverFunctions, defineApp, draftedIn, endShell, endlessChains, entriesOf, entryMisfits, freezeDeep, functionsIn, functionsWarning, holdGranted, layoutMisfits, layoutNameRefusal, layoutsOf, receiveManifest, refusalOf, sessionOn, treeOf, variantLayouts, verifiedAtBoot, verifyApp, verifyManifest, wholeShellOf, withFragments, withLayoutInPlace, withVariants };
922
- //# sourceMappingURL=chunk-WTWRLOPK.js.map
923
- //# sourceMappingURL=chunk-WTWRLOPK.js.map
922
+ //# sourceMappingURL=chunk-5ZB7FZ2J.js.map
923
+ //# sourceMappingURL=chunk-5ZB7FZ2J.js.map