@lango-project/lango-client 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +200 -0
- package/NOTICE +2 -0
- package/README.md +929 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/runtime.mjs +607 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/application.mjs +429 -0
- package/dist/application.mjs.map +1 -0
- package/dist/coordinator.mjs +91 -0
- package/dist/coordinator.mjs.map +1 -0
- package/dist/demo.mjs +110 -0
- package/dist/demo.mjs.map +1 -0
- package/dist/demo_controls.mjs +59 -0
- package/dist/demo_controls.mjs.map +1 -0
- package/dist/errors.mjs +201 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/form_state.mjs +266 -0
- package/dist/form_state.mjs.map +1 -0
- package/dist/heartbeat.mjs +330 -0
- package/dist/heartbeat.mjs.map +1 -0
- package/dist/inheritance.mjs +240 -0
- package/dist/inheritance.mjs.map +1 -0
- package/dist/input_values.mjs +65 -0
- package/dist/input_values.mjs.map +1 -0
- package/dist/library.mjs +824 -0
- package/dist/library.mjs.map +1 -0
- package/dist/navigation.mjs +466 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/node/.lango/bignumber.mjs +3119 -0
- package/dist/node/.lango/runtime.mjs +609 -0
- package/dist/node/.lango/xmldom/conventions.js +429 -0
- package/dist/node/.lango/xmldom/dom-parser.js +591 -0
- package/dist/node/.lango/xmldom/dom.js +3759 -0
- package/dist/node/.lango/xmldom/entities.js +2171 -0
- package/dist/node/.lango/xmldom/errors.js +205 -0
- package/dist/node/.lango/xmldom/grammar.js +559 -0
- package/dist/node/.lango/xmldom/index.js +41 -0
- package/dist/node/.lango/xmldom/package.json +1 -0
- package/dist/node/.lango/xmldom/sax.js +983 -0
- package/dist/node/.lango/xmldom.LICENSE.md +8 -0
- package/dist/node/browser_host.mjs +351 -0
- package/dist/node/browser_host.mjs.map +1 -0
- package/dist/node/create_app.mjs +118 -0
- package/dist/node/create_app.mjs.map +1 -0
- package/dist/presentation.mjs +89 -0
- package/dist/presentation.mjs.map +1 -0
- package/dist/protocol.mjs +706 -0
- package/dist/protocol.mjs.map +1 -0
- package/dist/session.mjs +471 -0
- package/dist/session.mjs.map +1 -0
- package/dist/tokens.mjs +298 -0
- package/dist/tokens.mjs.map +1 -0
- package/examples/contacts.lango +293 -0
- package/examples/contacts_flow.lango +174 -0
- package/examples/contacts_store.lango +109 -0
- package/examples/contacts_store_test.lango +65 -0
- package/examples/demo.css +87 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +32 -0
- package/examples/pages.lango +174 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +68 -4
- package/src/application.lango +327 -0
- package/src/browser_host.lango +276 -0
- package/src/coordinator.lango +57 -0
- package/src/demo.lango +110 -0
- package/src/demo_controls.lango +53 -0
- package/src/errors.lango +149 -0
- package/src/errors_test.lango +157 -0
- package/src/form_state.lango +168 -0
- package/src/heartbeat.lango +230 -0
- package/src/heartbeat_test.lango +479 -0
- package/src/inheritance.lango +167 -0
- package/src/input_values.lango +37 -0
- package/src/library.lango +599 -0
- package/src/logout_test.lango +564 -0
- package/src/navigation.lango +309 -0
- package/src/navigation_test.lango +556 -0
- package/src/presentation.lango +55 -0
- package/src/protocol.lango +787 -0
- package/src/renderer_test.lango +2047 -0
- package/src/session.lango +343 -0
- package/src/session_test.lango +455 -0
- package/src/tabs_test.lango +216 -0
- package/src/tokens.lango +215 -0
- package/template/.vscode/extensions.json +3 -0
- package/template/.vscode/settings.json +9 -0
- package/template/README.md +44 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +10 -0
- package/template/public/index.html +24 -0
- package/template/src/client.lango +78 -0
- package/template/src/pages.lango +55 -0
- package/template/src/server.lango +24 -0
- package/template/src/worker.lango +77 -0
- package/template/test/app.lango +9 -0
- package/tools/browser_runner.lango +32 -0
- package/tools/browser_test.lango +343 -0
- package/tools/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
package/README.md
CHANGED
|
@@ -1,3 +1,930 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lango-project/lango-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser controls and protocol handling for Lango server-driven UI, implemented
|
|
4
|
+
in Lango. `lango-ui` builds server responses; this package collects form values
|
|
5
|
+
and applies responses to browser controls.
|
|
6
|
+
|
|
7
|
+
## Build and demo
|
|
8
|
+
|
|
9
|
+
Development requires `@lango-project/lango-js` 0.1.8 or newer:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install
|
|
13
|
+
npm test
|
|
14
|
+
npm run build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The demo requires its API server. From this project directory, build and
|
|
18
|
+
start the complete local example with the adjacent source checkouts:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm --prefix ../lango-api run build
|
|
22
|
+
node ../lango-js/src/cli.mjs build ../lango-ui/src/library.lango --out ../lango-ui/dist/library.mjs
|
|
23
|
+
node ../lango-js/src/cli.mjs build src/demo.lango --out dist/demo.mjs --target browser
|
|
24
|
+
node ../lango-js/src/cli.mjs build examples/worker.lango --out .demo-server/worker.mjs
|
|
25
|
+
node ../lango-js/src/cli.mjs build examples/server.lango --out .demo-server/server.mjs --executable
|
|
26
|
+
node .demo-server/server.mjs
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Open `http://localhost:8080/`. Stop any previous static server
|
|
30
|
+
on port 8080 first. The example uses the synchronous worker API on port 8081 and port 8080 for
|
|
31
|
+
static files and a same-origin proxy. The initial GET serves a fixed HTML shell. The browser sends a form-scoped
|
|
32
|
+
`url` event. A shared `lango-ui/Pages` registry selects the exact page and longest
|
|
33
|
+
matching template prefix. The first response replaces `content` with a template
|
|
34
|
+
Container holding the page Form in `__content__`. Profile/Details navigation
|
|
35
|
+
replaces only that page Form; the Admin layout link switches the whole template.
|
|
36
|
+
Back/Forward sends another URL event; refreshing a registered URL returns the shell again. The page root keeps its session/sequence, while
|
|
37
|
+
replaced content Forms receive fresh instances. The legacy `/examples/index.html`
|
|
38
|
+
address redirects to `/`. Save sends a real form request through `lango-api` and
|
|
39
|
+
`lango-ui`; the response updates the email and disables the button. Log out ends the current session, starts a new anonymous one, clears the template marker and reloads the current URL;
|
|
40
|
+
the status text reports completion or failure. Its signing key is retained in the ignored `.demo-server/jwt.key` so
|
|
41
|
+
client identity survives demo server restarts. Both servers stop with Ctrl+C. This server is a local example, not a
|
|
42
|
+
production static-file or reverse-proxy implementation.
|
|
43
|
+
The example also retains revocations and UI sequence reservations in
|
|
44
|
+
`.demo-server/runtime.sqlite`. Restarting it preserves consumed sequences and
|
|
45
|
+
logout invalidation; reservations interrupted during execution stay pending
|
|
46
|
+
until session expiry.
|
|
47
|
+
|
|
48
|
+
`npm run build` builds the browser demo and library dependencies.
|
|
49
|
+
|
|
50
|
+
## Browser adapter
|
|
51
|
+
|
|
52
|
+
`mount(document, root, definition)` returns a control with `element`, `name`,
|
|
53
|
+
`controls`, `getValue()`, `setValue(value)` and `applyProperty(name, value)`.
|
|
54
|
+
The built-in control types are `Text`, `Select`, `Checkbox`, `Button`, `Value`,
|
|
55
|
+
`Panel`, `Container`, and `Form`. Text uses an input element; Value stores data without displaying it.
|
|
56
|
+
Container values are nested maps. Text content is assigned as text, not HTML.
|
|
57
|
+
|
|
58
|
+
The protocol entry exports `collectValues(controls)` and
|
|
59
|
+
`applyResponse(controls, response, formId, seqno, effects)`. It validates the
|
|
60
|
+
response identity and all targets before changing values. Supported commands
|
|
61
|
+
are enabled/visible and classes/style updates plus focus/toast effects supplied by
|
|
62
|
+
the host adapter. Nested targets use path arrays; strings address top-level controls.
|
|
63
|
+
|
|
64
|
+
Token persistence, bootstrap, idle renewal, logout, event replay protection and
|
|
65
|
+
form inheritance are implemented. Scoped theme/control selection and CSS presentation are available; business idempotency remains pending. Form values
|
|
66
|
+
retain their nested container structure; managed forms have independent request
|
|
67
|
+
queues and sequence counters.
|
|
68
|
+
|
|
69
|
+
## Structural responses
|
|
70
|
+
|
|
71
|
+
Pass `new Renderer(document)` as the session's `effects` adapter to create,
|
|
72
|
+
replace and remove DOM controls. Replacements are prepared off-DOM and all
|
|
73
|
+
value/command targets are validated against the projected tree before commit.
|
|
74
|
+
Replacements preserve the target name (inferred from the map key if omitted).
|
|
75
|
+
Example:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"replace": { "address": { "city": { "type": "Text", "value": "Ankara" } } },
|
|
80
|
+
"remove": [["address", "warning"]]
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This is the `ui` field of a response. A top-level remove target may also be a
|
|
85
|
+
string. Overlapping ancestor/descendant targets in one structural patch are
|
|
86
|
+
rejected. Removing a missing target is a no-op. Replacing a missing target is
|
|
87
|
+
an error. Values and commands may address controls introduced by replacements.
|
|
88
|
+
Unknown control types or invalid follow-up targets leave the mounted tree
|
|
89
|
+
unchanged. The structural and value phase is transactional: failures restore
|
|
90
|
+
the original node identities, sibling order, control arrays, and values.
|
|
91
|
+
|
|
92
|
+
Custom structural adapters must implement `capture(control)` and
|
|
93
|
+
`restore(snapshot, operation)` alongside create/replace/remove. An operation
|
|
94
|
+
contains `type`, `old`, optional `new`, and `owner`. Capture must not mutate the
|
|
95
|
+
mounted tree; restore must recover even when the failed operation partially
|
|
96
|
+
modified it. Controls with custom `applyProperty` must supply
|
|
97
|
+
`snapshotState()` and `restoreState(snapshot)`. Simple value controls without
|
|
98
|
+
custom property handling use getValue/setValue and enabled/visible snapshots.
|
|
99
|
+
|
|
100
|
+
Commands execute in their original order after the structural/value commit.
|
|
101
|
+
Each state command restores its own pre-command state on failure and stops the
|
|
102
|
+
remaining commands; already committed values and earlier commands remain.
|
|
103
|
+
Focus and toast are effects and cannot be rolled back. If an adapter's restore
|
|
104
|
+
hook itself fails, remaining rollback steps are attempted and the caller
|
|
105
|
+
receives `UiClientRollbackFailed`.
|
|
106
|
+
|
|
107
|
+
## Form requests
|
|
108
|
+
|
|
109
|
+
The `./session` entry exports `Session(options)` with `formId`, `controls`,
|
|
110
|
+
optional DOM `root`, and `effects`. `session.send(path, event, name)` returns a
|
|
111
|
+
Promise. Each session serializes requests, allocates sequence numbers when
|
|
112
|
+
sending, and collects current values after the previous response was applied.
|
|
113
|
+
Paths must be same-origin absolute paths. Requests use JSON POST.
|
|
114
|
+
Each Session generates an opaque `formInstanceId`, stable across its requests
|
|
115
|
+
and never persisted. It changes for a replacement Session even when its form
|
|
116
|
+
name is reused. UI dispatch combines it with the verified session identity and
|
|
117
|
+
sequence to reject repeated events without blocking replacements.
|
|
118
|
+
|
|
119
|
+
The root is inert and marked `aria-busy` while requests remain pending. Errors
|
|
120
|
+
reject the caller's Promise and release the UI; the queue accepts subsequent
|
|
121
|
+
requests. There are no automatic retries: a failed HTTP request may already
|
|
122
|
+
have executed its server handler. UI Dispatcher returns 409 `UiReplayConflict`
|
|
123
|
+
for consumed sequences or higher sequences arriving while the same instance is
|
|
124
|
+
busy. The client reports the error and releases its queue; it does not replay
|
|
125
|
+
the event or apply a cached response. A later user action gets a new sequence.
|
|
126
|
+
Gaps remain valid because failed requests may not have reached the dispatcher.
|
|
127
|
+
Business idempotency and recovery of lost responses remain separate work.
|
|
128
|
+
|
|
129
|
+
For testing, `transport: { send(path, input, token) }` can replace fetch and
|
|
130
|
+
return a Promise of either a protocol response or `{ body, token }` when a
|
|
131
|
+
token was renewed. Run the asynchronous queue tests with
|
|
132
|
+
`node ../lango-js/src/cli.mjs run src/session_test.lango`.
|
|
133
|
+
|
|
134
|
+
## Token persistence
|
|
135
|
+
|
|
136
|
+
Each Session owns its in-memory token. Every received token also updates the
|
|
137
|
+
shared latest-token store and localStorage, under `lango:last-token` by default.
|
|
138
|
+
Application accepts a custom `storageKey` to separate applications sharing an
|
|
139
|
+
origin, or a `tokens` TokenStore adapter. Standalone sessions accept the same
|
|
140
|
+
`tokens` option. The `./tokens` entry exports `TokenStore(storage, key)` for
|
|
141
|
+
custom storage and testing.
|
|
142
|
+
|
|
143
|
+
At startup or when creating a new form, the last stored token is used as the
|
|
144
|
+
initial token. Existing forms keep their own tokens. Sequence numbers are not
|
|
145
|
+
persisted and start from one for a new Session. The client treats token contents
|
|
146
|
+
as opaque; the server must verify identity such as clientId and establish the
|
|
147
|
+
new session/form context rather than restoring old sequence state.
|
|
148
|
+
|
|
149
|
+
Fetch sends `Authorization: Bearer <token>` and reads renewals from
|
|
150
|
+
`X-Lango-Token`. Renewal headers are saved before parsing/applying the response,
|
|
151
|
+
including HTTP errors; disposed sessions ignore late renewals. If localStorage
|
|
152
|
+
is inaccessible, the client logs a warning and continues in memory.
|
|
153
|
+
Set `Application` option `bootstrapPath: "/_lango/start"` when the server has a
|
|
154
|
+
TokenService. Bootstrap exchanges the persisted token for a new session token;
|
|
155
|
+
all initial forms wait for it before sending. ClientId is retained when the
|
|
156
|
+
old signature can be verified, including an expired token; sessionId and auth
|
|
157
|
+
state restart. The API still rejects expired tokens on ordinary endpoints.
|
|
158
|
+
Bootstrap failure rejects queued form requests rather than sending the old
|
|
159
|
+
session token. Later-created forms start from the latest token as usual.
|
|
160
|
+
Bootstrap commits a token only after a successful HTTP response and JSON parse;
|
|
161
|
+
superseded or cancelled initialization responses cannot replace a newer token.
|
|
162
|
+
|
|
163
|
+
## Tabs, browser profiles, and devices
|
|
164
|
+
|
|
165
|
+
Configure `bootstrapPath` for every JWT-backed Application. Each page instance
|
|
166
|
+
bootstraps a new `sessionId`, anonymous by default, while recovering only
|
|
167
|
+
`clientId` from a valid stored seed. Reload also creates a new session. Starting
|
|
168
|
+
another tab does not revoke or authenticate an already-running tab. Without
|
|
169
|
+
bootstrap, manually sharing the same token also shares its session and logout
|
|
170
|
+
scope; separate tab sessions cannot be assumed.
|
|
171
|
+
|
|
172
|
+
The localStorage entry is a shared, best-effort seed for future bootstrap, not
|
|
173
|
+
the active credential for every tab. Initialization rereads the current entry
|
|
174
|
+
rather than relying on its constructor-time copy. An explicitly supplied
|
|
175
|
+
previous token takes precedence, including after logout. Ordinary requests,
|
|
176
|
+
ping and logout use the tab's own in-memory tokens; storage writes from another
|
|
177
|
+
tab do not replace them. No login/logout state is broadcast to other sessions.
|
|
178
|
+
|
|
179
|
+
Clearing a store always clears its local credential. It removes the shared entry
|
|
180
|
+
only when the value still matches that local credential, so a newer token from
|
|
181
|
+
another tab is normally retained. Storage read/remove is not a cross-tab atomic
|
|
182
|
+
transaction; the seed may still race with concurrent writes. Session isolation
|
|
183
|
+
and authorization do not depend on which seed wins. With no stored seed,
|
|
184
|
+
simultaneous first launches can register separate client identities.
|
|
185
|
+
|
|
186
|
+
Separate browser profiles/devices without a transferred seed receive independent
|
|
187
|
+
client identities. `clientId` identifies recoverable client state, not hardware,
|
|
188
|
+
an account, or authority to terminate other sessions. Logout revokes only its
|
|
189
|
+
current `sessionId`, including that session's forms. All-session or all-device
|
|
190
|
+
logout needs an application account/session registry and authorization policy.
|
|
191
|
+
Applications sharing an origin should use distinct `storageKey` values unless
|
|
192
|
+
they deliberately share the same server identity namespace.
|
|
193
|
+
|
|
194
|
+
## Logout
|
|
195
|
+
|
|
196
|
+
Call `application.logout()` to end the current server session and start a new
|
|
197
|
+
anonymous session. It returns a Promise of the new opaque token. Concurrent
|
|
198
|
+
calls share one operation. Options `logoutPath` and `bootstrapPath` select the
|
|
199
|
+
same-origin endpoints, defaulting to `/_lango/logout` and `/_lango/start` for
|
|
200
|
+
this operation. Initial automatic bootstrap still requires `bootstrapPath`.
|
|
201
|
+
|
|
202
|
+
```lango
|
|
203
|
+
logout(application)
|
|
204
|
+
return application.logout().then((token)
|
|
205
|
+
context log
|
|
206
|
+
log.info("Anonymous session is ready")
|
|
207
|
+
)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The application immediately detaches all form bindings, disposes their sessions
|
|
211
|
+
and heartbeat, and marks its root inert and busy. Queued requests do not send;
|
|
212
|
+
late form and ping responses cannot update controls or tokens. An initial
|
|
213
|
+
bootstrap already in progress is awaited so logout revokes the session that was
|
|
214
|
+
actually issued. If bootstrap failed, logout can still revoke the previously
|
|
215
|
+
stored credential. Sent requests may still have server side effects.
|
|
216
|
+
|
|
217
|
+
After the API confirms `{ "loggedOut": true }`, the TokenStore clears its local
|
|
218
|
+
credential and removes the persisted entry if it still matches. Another tab's
|
|
219
|
+
newer seed is retained. The previous token is used only for the
|
|
220
|
+
following bootstrap's identity recovery. A successful bootstrap persists the
|
|
221
|
+
new anonymous token, creates fresh form sessions with `seqno` starting from
|
|
222
|
+
one, reattaches bindings, and restarts idle renewal if enabled. The control tree,
|
|
223
|
+
values, and enabled/visible properties are retained; applications must clear
|
|
224
|
+
or replace private screen content according to their own UI policy.
|
|
225
|
+
|
|
226
|
+
Logout errors reject the Promise and leave forms paused. No bootstrap follows
|
|
227
|
+
an unconfirmed logout, and response token headers are ignored. Retrying
|
|
228
|
+
`application.logout()` repeats the failed revocation. If revocation succeeded
|
|
229
|
+
but anonymous bootstrap failed, retry performs only bootstrap. A network error
|
|
230
|
+
can hide a successful server revocation; a later 401 does not prove logout
|
|
231
|
+
success, so automatic recovery stops. Reload to start an anonymous session;
|
|
232
|
+
revocation confirmation and account-wide coordination remain separate concerns.
|
|
233
|
+
Disposing the application during logout prevents form recreation and cancels
|
|
234
|
+
any pending bootstrap commit.
|
|
235
|
+
|
|
236
|
+
For standalone sessions, `TokenStore.logout(path)` confirms server revocation,
|
|
237
|
+
clears its local credential and matching persisted seed, and resolves with the previous token for an
|
|
238
|
+
explicit `initialize(bootstrapPath, previousToken)` call. It does not manage or
|
|
239
|
+
dispose standalone sessions; their owner must stop them before logout. Storage
|
|
240
|
+
adapters must implement `getItem`, `setItem`, and `removeItem`. Custom TokenStore
|
|
241
|
+
adapters used with Application logout must also implement `logout`, `initialize`,
|
|
242
|
+
and `cancelInitialization`. Sharing one store between independently managed
|
|
243
|
+
applications requires external lifecycle coordination.
|
|
244
|
+
|
|
245
|
+
## Idle token renewal
|
|
246
|
+
|
|
247
|
+
Application enables a Heartbeat when `bootstrapPath` or `pingPath` is supplied.
|
|
248
|
+
After 60 seconds without form request activity it sends one JSON POST to
|
|
249
|
+
`/_lango/ping` for a snapshot of the managed forms. Bootstrap completion also
|
|
250
|
+
resets the idle period. Configure it through Application options:
|
|
251
|
+
|
|
252
|
+
```lango
|
|
253
|
+
{
|
|
254
|
+
bootstrapPath: "/_lango/start"
|
|
255
|
+
pingPath: "/_lango/ping"
|
|
256
|
+
pingIdleMs: 60000
|
|
257
|
+
pingEnabled: true
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Set `pingEnabled: false` to disable automatic renewal, or explicitly enable
|
|
262
|
+
it when using a preinitialized custom token store. Choose an idle interval
|
|
263
|
+
shorter than the server's token lifetime. Ping paths must remain same-origin;
|
|
264
|
+
a custom path can be mapped to the API's reserved endpoint by a proxy.
|
|
265
|
+
|
|
266
|
+
The batch waits for already-queued requests in every participating form.
|
|
267
|
+
Requests queued afterward wait behind the ping barrier, then use their form's
|
|
268
|
+
renewed token. Ping does not advance `seqno`, collect values, apply UI commands,
|
|
269
|
+
or mark forms busy by itself. Forms created after the participant snapshot join
|
|
270
|
+
the next ping. Disposed sessions ignore late renewals, including when a new
|
|
271
|
+
form reuses the same name.
|
|
272
|
+
|
|
273
|
+
All returned form IDs and token strings are validated before applying any
|
|
274
|
+
renewal. Each received token updates its Session and the shared latest-token
|
|
275
|
+
localStorage record. A failed ping leaves tokens unchanged and releases the
|
|
276
|
+
normal queues; automatic scheduling retries after another idle interval.
|
|
277
|
+
Expired credentials still require a new bootstrap/authentication flow: ping
|
|
278
|
+
does not silently reset a session or restore login state.
|
|
279
|
+
The API also enforces an absolute session lifetime (eight hours by default).
|
|
280
|
+
Renewals and login within that session do not reset its deadline. Once it
|
|
281
|
+
expires, ordinary requests and ping return 401; reload for a new anonymous
|
|
282
|
+
bootstrap and authenticate again if needed.
|
|
283
|
+
|
|
284
|
+
`application.dispose()` cancels scheduling and releases queued work; a late
|
|
285
|
+
response cannot update disposed forms. Requests disable HTTP caching and
|
|
286
|
+
redirect following. `pingTransport` may supply `send(path, input)`, returning
|
|
287
|
+
a Promise of the batch response, for custom transports. The `./heartbeat`
|
|
288
|
+
entry exports `Heartbeat` for standalone session management; use `sessions`,
|
|
289
|
+
`start`, `activity`, `ping`, and `dispose` to manage its lifecycle.
|
|
290
|
+
|
|
291
|
+
## Event binding
|
|
292
|
+
|
|
293
|
+
Create `new Binding(form, session)` once after mounting the form. Event
|
|
294
|
+
listeners live on the form root and resolve controls against the current
|
|
295
|
+
tree, so replacement controls require no individual listener setup. Calling
|
|
296
|
+
`binding.dispose()` removes the listeners. Duplicate bindings on a root are
|
|
297
|
+
rejected.
|
|
298
|
+
|
|
299
|
+
`event: "/app/save"` means click for a Button and change for other controls.
|
|
300
|
+
Use `events: { click: "/app/save", change: "/app/edit", input: "/app/search" }`
|
|
301
|
+
for explicit event mappings; supported types are click, change, and input.
|
|
302
|
+
Mappings must use same-origin paths. An explicit mapping overrides the shorthand
|
|
303
|
+
for that event type. The request's `name` is a string for a top-level named
|
|
304
|
+
control, an array for a nested named path, and null for an unnamed source.
|
|
305
|
+
|
|
306
|
+
Disabled, hidden, or inert controls and their descendants do not send events.
|
|
307
|
+
An outer form ignores events bubbling from an inner Form. `Application` manages
|
|
308
|
+
the inner forms' bindings and sessions automatically.
|
|
309
|
+
Errors go to `context log` by default; a third constructor argument implementing
|
|
310
|
+
`error(error)` may override error reporting.
|
|
311
|
+
|
|
312
|
+
## Managed form lifecycle
|
|
313
|
+
|
|
314
|
+
The `./application` entry exports `Application(document, root, definition,
|
|
315
|
+
options = {})`. It mounts the control tree and creates a Session/Binding pair
|
|
316
|
+
for every named Form. It reconciles the registry after each response, retaining
|
|
317
|
+
unchanged forms and disposing removed or replaced forms. New form instances
|
|
318
|
+
start with a fresh sequence counter even when their names are unchanged.
|
|
319
|
+
|
|
320
|
+
`application.control` exposes the mounted root control. Use
|
|
321
|
+
`application.session("profile")` or
|
|
322
|
+
`application.session(["profile", "address"])` to access a managed session.
|
|
323
|
+
Top-level form ids are their names; nested wire ids are JSON-encoded name
|
|
324
|
+
paths. Controls continue to use paths relative to the active form in requests.
|
|
325
|
+
Unnamed managed forms and duplicate form paths are rejected.
|
|
326
|
+
|
|
327
|
+
`application.dispose()` closes all bindings and sessions without removing the
|
|
328
|
+
DOM. `options.transport` and `options.errors` configure the shared transport
|
|
329
|
+
and error reporting adapters. Each form still owns its own queue.
|
|
330
|
+
|
|
331
|
+
Disposal blocks future and queued sends and ignores late responses. An HTTP
|
|
332
|
+
request already sent may still execute on the server. Parent forms continue
|
|
333
|
+
collecting nested physical values as before.
|
|
334
|
+
|
|
335
|
+
## Inherited form values
|
|
336
|
+
|
|
337
|
+
A nested Form can declare an `inherit` map. Keys are aliases in that form's
|
|
338
|
+
request `values`; paths refer to concrete controls in the nearest ancestor Form:
|
|
339
|
+
|
|
340
|
+
```lango
|
|
341
|
+
{
|
|
342
|
+
type: "Form"
|
|
343
|
+
name: "details"
|
|
344
|
+
inherit: {
|
|
345
|
+
customerId: "customerId"
|
|
346
|
+
city: {
|
|
347
|
+
path: ["address", "city"]
|
|
348
|
+
writable: true
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
controls: []
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
String and path-array entries are read-only. Descriptors use `path` and optional
|
|
356
|
+
Boolean `writable`, default false. Aliases must not collide with the child's
|
|
357
|
+
own controls or reserved value-tree names. Paths cannot cross another Form or
|
|
358
|
+
re-export the parent's virtual aliases. A root Form cannot inherit.
|
|
359
|
+
|
|
360
|
+
The client resolves sources and collects their current values when sending,
|
|
361
|
+
after earlier conflicting requests complete. A missing or removed source fails
|
|
362
|
+
the send before HTTP; replacing a source makes the next send use its replacement.
|
|
363
|
+
Inherited aliases are virtual values, not DOM controls or event targets. They
|
|
364
|
+
are not copied into the physical control tree or the parent's nested collection.
|
|
365
|
+
|
|
366
|
+
Response `vals` can write through a writable alias to the original source,
|
|
367
|
+
including its nested value paths. These writes participate in value rollback.
|
|
368
|
+
Writes to a read-only alias fail before applying the response. Writable aliases also accept saved-value
|
|
369
|
+
acknowledgements and field errors;
|
|
370
|
+
other state commands and structural replacement/removal cannot target inherited
|
|
371
|
+
aliases. This is a UI editing contract; the server must independently validate
|
|
372
|
+
authorization and all incoming values.
|
|
373
|
+
|
|
374
|
+
Managed requests reserve their own form subtree and declared inherited reads
|
|
375
|
+
or writes. Parent/descendant requests serialize, as do overlapping inherited
|
|
376
|
+
writes or read/write pairs. Unrelated siblings remain parallel; sharing a
|
|
377
|
+
read-only source alone does not serialize them. Requests retain their own
|
|
378
|
+
`seqno` and token. Disposal releases reservations and prevents a late inherited
|
|
379
|
+
write from changing a retained parent. This coordination covers managed
|
|
380
|
+
requests within one Application, not other tabs or application databases.
|
|
381
|
+
Direct edits to controls while an inherited request is pending follow the
|
|
382
|
+
normal response update rules; the coordinator does not version user edits.
|
|
383
|
+
|
|
384
|
+
New managed forms seed their token from the page's bootstrap snapshot, rather
|
|
385
|
+
than the latest token persisted by another form. Parent login, private claims,
|
|
386
|
+
and later renewals do not automatically propagate to children or siblings.
|
|
387
|
+
Logout creates a new page snapshot. The server decides any deliberate claim
|
|
388
|
+
inheritance or authentication policy; the browser treats tokens as opaque.
|
|
389
|
+
Standalone Sessions retain their existing token initialization behavior.
|
|
390
|
+
|
|
391
|
+
## URL navigation
|
|
392
|
+
|
|
393
|
+
The `./navigation` entry exports `Navigation(window, options)`:
|
|
394
|
+
|
|
395
|
+
```lango
|
|
396
|
+
import js global window
|
|
397
|
+
import js "@lango-project/lango-client/navigation" as routing
|
|
398
|
+
|
|
399
|
+
navigation = new routing/Navigation(window, {
|
|
400
|
+
rootRedirect: "/profile"
|
|
401
|
+
onUrl: handleUrl
|
|
402
|
+
})
|
|
403
|
+
return navigation.start()
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
`onUrl` receives `{ url, source }`, where `url` is pathname + query + fragment,
|
|
407
|
+
including the initial page. Sources are `start`, `navigate`, `history`, `hash`, and `refresh`.
|
|
408
|
+
The optional root redirect uses replaceState rather than adding a history entry;
|
|
409
|
+
its explicit query/fragment wins, otherwise the incoming ones are retained.
|
|
410
|
+
`navigate(url, replace = false)` validates same-origin HTTP(S) URLs, updates browser
|
|
411
|
+
history and returns the consumer result as a Promise. Back/Forward reruns the URL
|
|
412
|
+
consumer; there is no form/screen cache in this milestone. Refresh starts a new
|
|
413
|
+
page/session through the existing bootstrap contract.
|
|
414
|
+
|
|
415
|
+
URL consumers run in order with captured URL snapshots. Duplicate notifications
|
|
416
|
+
from popstate/hashchange are coalesced. Errors do not block later navigation;
|
|
417
|
+
`options.errors.error(error)` receives event-listener failures, or the standard
|
|
418
|
+
log reports them. A failed current URL can be retried with `navigate(currentUrl)`
|
|
419
|
+
without adding another history entry. `refresh()` explicitly reruns the current
|
|
420
|
+
URL without changing history, for example after logout. `start()` is idempotent, `idle()` waits for
|
|
421
|
+
the notification queue, and `dispose()` removes listeners and skips queued work.
|
|
422
|
+
An already-running consumer owns its cancellation; dispose its Application/Session
|
|
423
|
+
when removing the page.
|
|
424
|
+
|
|
425
|
+
Document-level delegation intercepts ordinary internal anchor clicks, including
|
|
426
|
+
anchors inserted after startup. Modified/middle clicks, downloads, explicit
|
|
427
|
+
browsing targets, prevented events, and disabled/hidden/inert ancestors retain
|
|
428
|
+
native behavior. Same-document fragments retain browser scrolling and are
|
|
429
|
+
observed through hashchange. External HTTP(S) links without a target receive
|
|
430
|
+
`target="_blank"` and `rel="noopener"`; mail/tel and other native schemes are left
|
|
431
|
+
to the browser. Script/credential-bearing/external programmatic destinations are
|
|
432
|
+
rejected.
|
|
433
|
+
|
|
434
|
+
`Navigation` does not bypass form requests. In the demo, the root Form owns a
|
|
435
|
+
hidden `Value` named `url`. Its consumer updates that value and sends
|
|
436
|
+
`session.send("/app/url", "url", null)` through the normal form/JWT/sequence queue.
|
|
437
|
+
The server reads `context form` and calls `pages.render()` with its `url` and
|
|
438
|
+
`template` Values. It applies the returned structural replacement and template
|
|
439
|
+
marker in the same response. `examples/pages.lango` defines the shared registry
|
|
440
|
+
used by both GET shell selection and the worker URL handler. Unknown page and
|
|
441
|
+
asset paths remain 404s. A new template is created before its page; within the
|
|
442
|
+
same prefix only `content.__content__` is replaced, retaining the template DOM
|
|
443
|
+
and values. Leaving a prefix discards its template; returning recreates it.
|
|
444
|
+
There is no cache of templates for previously visited prefixes. Refresh starts a
|
|
445
|
+
new root form; logout clears the marker and calls `navigation.refresh()` so the
|
|
446
|
+
new anonymous session receives a fresh template and page.
|
|
447
|
+
|
|
448
|
+
## Custom controls and themes
|
|
449
|
+
|
|
450
|
+
Use one `Types` registry per application to select browser control classes. A
|
|
451
|
+
registry may also override standard types, for example `Text`, for a theme:
|
|
452
|
+
|
|
453
|
+
```lango
|
|
454
|
+
import "./library"
|
|
455
|
+
class Control
|
|
456
|
+
class Types
|
|
457
|
+
|
|
458
|
+
class Label : Control
|
|
459
|
+
methods
|
|
460
|
+
setValue(value)
|
|
461
|
+
|
|
462
|
+
Label(document, definition, types)
|
|
463
|
+
super(document, definition, types, {
|
|
464
|
+
tag: "p"
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
Label:setValue(value)
|
|
468
|
+
super.setValue(value)
|
|
469
|
+
@element.textContent = value
|
|
470
|
+
return null
|
|
471
|
+
|
|
472
|
+
createTypes()
|
|
473
|
+
types = new Types({
|
|
474
|
+
classes: {
|
|
475
|
+
Label: ["theme-label"]
|
|
476
|
+
Button: ["theme-button"]
|
|
477
|
+
}
|
|
478
|
+
})
|
|
479
|
+
types.registerType("Label", Label)
|
|
480
|
+
return types
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Pass that registry as `options.types` to `Application`, or to
|
|
484
|
+
`mount(document, root, definition, types)` and `Renderer(document, types)` when
|
|
485
|
+
using those adapters directly. All descendants and structural replacements use
|
|
486
|
+
the same registry. Registration is sealed at first creation; duplicate names and
|
|
487
|
+
unknown wire types fail explicitly. Registries are independent; there is no
|
|
488
|
+
process-wide control registration.
|
|
489
|
+
|
|
490
|
+
Custom classes extend `Control` and accept `(document, definition, types)`.
|
|
491
|
+
`super` accepts trusted element options `{ tag, container }`; `container: true`
|
|
492
|
+
builds children through the registry and preserves normal value paths. `Form`
|
|
493
|
+
remains the wire type for a managed form boundary. An overridden standard type
|
|
494
|
+
keeps its normal wire type. Custom controls use normal delegated click/change/input
|
|
495
|
+
events and `getValue`/`setValue`. Base construction calls `setValue` and state
|
|
496
|
+
setters, so overrides must work before any fields initialized after `super`. Keep constructors synchronous and clean up any
|
|
497
|
+
resources acquired before a constructor throws.
|
|
498
|
+
|
|
499
|
+
Override `dispose()` to release listeners, timers or third-party widget resources.
|
|
500
|
+
It runs on committed removal/replacement and Application disposal; discarded
|
|
501
|
+
prepared replacements also release resources. Rollback retains the old controls
|
|
502
|
+
and disposes the abandoned new ones. Cleanup walks children before their parent
|
|
503
|
+
and reports individual disposal failures through the standard log. A subclass's
|
|
504
|
+
own `dispose()` need not traverse children. Value rollback calls `setValue` again;
|
|
505
|
+
if a custom widget has additional state, extend `snapshotState`/`restoreState`
|
|
506
|
+
using `super` to preserve it along with the base state. Constructors and rollback
|
|
507
|
+
hooks must not send requests or perform unrelated application effects.
|
|
508
|
+
|
|
509
|
+
Definitions support `classes` as an array of CSS class tokens and `style` as a
|
|
510
|
+
map of CSS property names to string values:
|
|
511
|
+
|
|
512
|
+
```lango
|
|
513
|
+
{
|
|
514
|
+
type: "Label"
|
|
515
|
+
name: "heading"
|
|
516
|
+
value: "Profile"
|
|
517
|
+
classes: ["heading", "accent"]
|
|
518
|
+
style: {
|
|
519
|
+
"margin-block": "1rem"
|
|
520
|
+
"--accent-color": "#0f766e"
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
Theme classes from `Types({ classes })` are initial defaults, combined with the
|
|
526
|
+
control's explicit classes. Subsequent `setProperty` commands for `classes`
|
|
527
|
+
replace the complete class list. Commands for `style` replace the server-managed
|
|
528
|
+
inline properties; unrelated inline properties are retained. Null clears either
|
|
529
|
+
setting. Invalid classes/styles are rejected during response planning, before
|
|
530
|
+
structural or value changes. A failed DOM style update restores that command's
|
|
531
|
+
previous CSS state. Earlier successful commands stay committed as in the normal
|
|
532
|
+
command contract. CSS is applied through `className` and `style.setProperty`;
|
|
533
|
+
control definitions do not load scripts or stylesheets.
|
|
534
|
+
|
|
535
|
+
Load theme CSS explicitly from the HTML shell with a normal stylesheet link. The
|
|
536
|
+
demo uses `/assets/demo.css`, theme classes, a CSS custom property and the Lango
|
|
537
|
+
`Label` class in `src/demo_controls.lango`. Its fixed CSS endpoint serves
|
|
538
|
+
`text/css`, a content-based ETag, `public, max-age=0, must-revalidate`, and 304 on
|
|
539
|
+
an exact matching `If-None-Match`. Unknown assets remain 404s; the HTML shell is
|
|
540
|
+
still `no-store`. Versioned immutable asset manifests and on-demand theme/package
|
|
541
|
+
loading are future additions.
|
|
542
|
+
|
|
543
|
+
With adjacent API/UI builds available, `npm run test:demo` rebuilds the demo and
|
|
544
|
+
checks its real HTTP flow, including CSS caching, custom-control module assets,
|
|
545
|
+
deep links, template switches, replay, save and logout. It needs free local ports
|
|
546
|
+
8080 and 8081 and stops the server it starts. It does not launch a browser; DOM
|
|
547
|
+
and custom-control behavior are covered by the renderer tests in `npm test`.
|
|
548
|
+
|
|
549
|
+
## Select and Checkbox inputs
|
|
550
|
+
|
|
551
|
+
`Select` is a native single-select control. Its `options` list contains maps with
|
|
552
|
+
string `value` and `text`, plus an optional Boolean `disabled` (default false):
|
|
553
|
+
|
|
554
|
+
```lango
|
|
555
|
+
{
|
|
556
|
+
type: "Select"
|
|
557
|
+
name: "country"
|
|
558
|
+
label: "Country"
|
|
559
|
+
value: "tr"
|
|
560
|
+
event: "/preferences/change"
|
|
561
|
+
options: [{
|
|
562
|
+
value: "tr"
|
|
563
|
+
text: "Türkiye"
|
|
564
|
+
}, {
|
|
565
|
+
value: "gb"
|
|
566
|
+
text: "United Kingdom"
|
|
567
|
+
}]
|
|
568
|
+
}
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
Values are strings or null. Null means no selection (`selectedIndex = -1`);
|
|
572
|
+
`""` can be a separate, real option value. Omitted initial values stay unselected;
|
|
573
|
+
the first option is not implicitly chosen. Non-string or duplicate option values,
|
|
574
|
+
missing/non-string text, invalid disabled flags and values absent from the option
|
|
575
|
+
list are rejected. Option text is assigned as text. A disabled option may still
|
|
576
|
+
be selected by the server to display an existing value. Replace the Select
|
|
577
|
+
structurally to change its option list. Multiple selection is not supported.
|
|
578
|
+
|
|
579
|
+
`Checkbox` uses a native checkbox and carries a Boolean value:
|
|
580
|
+
|
|
581
|
+
```lango
|
|
582
|
+
{
|
|
583
|
+
type: "Checkbox"
|
|
584
|
+
name: "subscribed"
|
|
585
|
+
label: "Receive updates"
|
|
586
|
+
value: false
|
|
587
|
+
event: "/preferences/change"
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
An omitted/null initial Checkbox value defaults to false. Subsequent `setValue`
|
|
592
|
+
or `vals` writes require true or false; null, numbers and strings are rejected.
|
|
593
|
+
There is no tri-state value. Collection reads the live native checked/selection
|
|
594
|
+
state, including edits since the last server response. Rollback restores those
|
|
595
|
+
unsent edits if another setter fails.
|
|
596
|
+
|
|
597
|
+
The optional `label` string sets an accessible name through `aria-label`; it does
|
|
598
|
+
not draw a caption. Provide a visible label with the application's layout or a
|
|
599
|
+
custom control. `event` defaults to `change` for both inputs; explicit `events`
|
|
600
|
+
entries take precedence. Normal enabled/visible commands, inheritance, theme
|
|
601
|
+
classes, replacement, and form-scoped requests apply. Only the selected scalar
|
|
602
|
+
and checked Boolean go into `values`; option definitions stay in the UI tree.
|
|
603
|
+
The server must validate the submitted values against its own rules. The demo
|
|
604
|
+
shows preference changes, typed save responses, server-side 400 validation and
|
|
605
|
+
Save re-enabling after a change.
|
|
606
|
+
|
|
607
|
+
## Validation and unsaved changes
|
|
608
|
+
|
|
609
|
+
A value control can declare local validation rules. Event sources opt into a
|
|
610
|
+
whole-form check with `validate: true`, for example on a Save button:
|
|
611
|
+
|
|
612
|
+
```lango
|
|
613
|
+
{
|
|
614
|
+
type: "Text"
|
|
615
|
+
name: "email"
|
|
616
|
+
value: ""
|
|
617
|
+
validation: {
|
|
618
|
+
required: true
|
|
619
|
+
maxLength: 254
|
|
620
|
+
pattern: "[^ @]+@[^ @]+[.][^ @]+"
|
|
621
|
+
message: "Enter a valid email address."
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
Supported rules are `required`, `minLength`, `maxLength`, `pattern`, and an optional
|
|
627
|
+
shared `message`. Lengths are nonnegative integers (JavaScript string lengths);
|
|
628
|
+
patterns match the entire value and use JavaScript RegExp syntax. Unknown rules,
|
|
629
|
+
invalid patterns and inconsistent length ranges fail when constructing a control.
|
|
630
|
+
Required text rejects blank/whitespace, required Select rejects null/empty string,
|
|
631
|
+
and required Checkbox requires true. Optional empty values skip length/pattern
|
|
632
|
+
checks. This first contract has no cross-field or asynchronous validators.
|
|
633
|
+
|
|
634
|
+
`session.validate(report = true)` returns `{ path, message, control }` entries
|
|
635
|
+
and normally reports the first error using native browser validity UI. It checks
|
|
636
|
+
owned fields and writable inherited aliases, skipping disabled/hidden/inert
|
|
637
|
+
subtrees and child Form boundaries. Child forms validate through their own
|
|
638
|
+
sessions. Input/change events update local validity even when they have no
|
|
639
|
+
server event mapping. Controls set `aria-invalid` and `data-lango-error` and use
|
|
640
|
+
`setCustomValidity`/`reportValidity` when available. Custom widgets can override
|
|
641
|
+
`validate()`/`reportValidity()` to use their own presentation.
|
|
642
|
+
|
|
643
|
+
For a request whose named source has `validate: true`, Session validates again
|
|
644
|
+
when its queue reaches the request. Failure rejects with `UiValidationFailed`
|
|
645
|
+
without sending HTTP or consuming a sequence number; busy state is released
|
|
646
|
+
before native error reporting. Ordinary change events remain available for
|
|
647
|
+
server-side interaction with an incomplete form. Programmatic `session.send`
|
|
648
|
+
uses the same named-source check. A server must still validate client input.
|
|
649
|
+
|
|
650
|
+
`control.isDirty()` compares live values against the initial/saved baseline.
|
|
651
|
+
Text, Select and Checkbox track changes by default; hidden Value, labels and
|
|
652
|
+
other custom types default to no tracking. `trackChanges: true/false` overrides
|
|
653
|
+
that choice. Object/array baselines are copied, and object key order does not
|
|
654
|
+
create a difference. A control tree aggregates its descendants; `session.isDirty()`
|
|
655
|
+
uses its own form scope plus writable inherited sources. `application.isDirty()`
|
|
656
|
+
aggregates all managed sessions. `control.markClean()` explicitly establishes a
|
|
657
|
+
new local baseline for that control/subtree.
|
|
658
|
+
|
|
659
|
+
Normal responses and change events do not automatically mark data saved. The
|
|
660
|
+
server acknowledges an accepted field value with a `setProperty` command named
|
|
661
|
+
`savedValue`. That command changes only the baseline. If the current value has
|
|
662
|
+
changed again since the acknowledged value, the field stays dirty. `vals` still
|
|
663
|
+
performs its normal value updates before commands; acknowledge the canonical
|
|
664
|
+
value used in those updates. Replacement controls start clean; removed controls
|
|
665
|
+
leave dirty tracking. Failed requests/patches do not create a save acknowledgement.
|
|
666
|
+
|
|
667
|
+
The server can show a field error with `setProperty("error", message)`; null
|
|
668
|
+
clears it. This reports native validity without changing the value or dirty
|
|
669
|
+
baseline. Session reports server errors after releasing its busy state so the
|
|
670
|
+
input can receive browser focus. Editing/revalidating the field clears that server message and applies
|
|
671
|
+
local rules. Writable inherited aliases accept `savedValue` and `error` commands
|
|
672
|
+
for their physical source; other inherited state commands remain forbidden.
|
|
673
|
+
Read-only aliases accept neither command. Custom `applyProperty` overrides should
|
|
674
|
+
forward these base properties through `super`.
|
|
675
|
+
|
|
676
|
+
Pass `options.window` to Application for a `beforeunload` warning while dirty;
|
|
677
|
+
disposal removes the listener. The browser controls the actual unload dialog.
|
|
678
|
+
For SPA navigation, use a synchronous Boolean guard:
|
|
679
|
+
|
|
680
|
+
```lango
|
|
681
|
+
canLeave = (event)
|
|
682
|
+
capture application
|
|
683
|
+
return application.confirmDiscard(window)
|
|
684
|
+
navigation = new routing/Navigation(window, {
|
|
685
|
+
onUrl: handleUrl
|
|
686
|
+
beforeNavigate: canLeave
|
|
687
|
+
})
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
A false guard result cancels navigate/refresh without an event request. For
|
|
691
|
+
Back/Forward and native fragment changes, Navigation restores the previous
|
|
692
|
+
managed history position, retaining the forward entries and form tree. It owns
|
|
693
|
+
the `__langoNavigation` history-state marker and preserves other object-state
|
|
694
|
+
keys. Use Navigation to make same-document history changes; unrelated routers
|
|
695
|
+
must not rewrite its marker or history. Requests during asynchronous history
|
|
696
|
+
restoration fail with `UiNavigationRestoringHistory` until the restoration event
|
|
697
|
+
arrives. `start` does not ask the guard. Confirmation does not clear dirty state;
|
|
698
|
+
a failed page load therefore retains its unsaved baseline.
|
|
699
|
+
|
|
700
|
+
The demo guards navigation and logout, and allows its explicit post-logout
|
|
701
|
+
refresh after the user has already accepted discard. It shows a brief validation/
|
|
702
|
+
request error summary; `blocked@example.com` demonstrates a server field error.
|
|
703
|
+
A successful save acknowledges the accepted values, so leaving afterwards does
|
|
704
|
+
not ask to discard unchanged data.
|
|
705
|
+
|
|
706
|
+
## Persistent contact-book example
|
|
707
|
+
|
|
708
|
+
The same demo now includes a complete contact book at
|
|
709
|
+
`http://localhost:8080/contacts`. After the adjacent API/UI projects are built,
|
|
710
|
+
run from this project directory:
|
|
711
|
+
|
|
712
|
+
```sh
|
|
713
|
+
npm run build
|
|
714
|
+
npm run build:demo-server
|
|
715
|
+
npm run demo
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
Use **New contact**, fill the name/email/country/update fields and save. The saved
|
|
719
|
+
contacts selector supports **Open selected contact**. Editing and saving updates
|
|
720
|
+
the record; check the deletion confirmation before **Delete contact**. New/Open
|
|
721
|
+
and deletion warn before discarding dirty edits. Navigation, reload and logout
|
|
722
|
+
use the existing unsaved-change guards. Save validates locally and on the server;
|
|
723
|
+
field errors retain the editor. Successful saves return canonical trimmed names,
|
|
724
|
+
lowercase emails, a new record version and explicit clean-baseline acknowledgements.
|
|
725
|
+
|
|
726
|
+
The Lango implementation is split between `examples/contacts.lango` (UI and event
|
|
727
|
+
handlers) and `examples/contacts_store.lango` (synchronous parameterized SQLite
|
|
728
|
+
queries). Each API worker opens its own connection and closes it at shutdown.
|
|
729
|
+
Business records live in `.demo-server/contacts.sqlite`, separate from API
|
|
730
|
+
JWT/replay state. Records survive server restarts. UI event requests require the bearer returned by explicit `/_lango/start`;
|
|
731
|
+
a missing bearer returns 401. Every query includes the verified token's `clientId`; client-supplied form values do not select an owner.
|
|
732
|
+
This local example partitions data by recoverable browser client identity, not
|
|
733
|
+
by a signed-in user account. Logout changes the session while that recovered
|
|
734
|
+
client identity retains access to its records. Clearing the browser identity
|
|
735
|
+
seed starts a different client; the old records remain in SQLite.
|
|
736
|
+
|
|
737
|
+
Email uniqueness is scoped to each client. New drafts get a stable UUID, and
|
|
738
|
+
updates/deletes include a positive record version. Conditional writes reject a
|
|
739
|
+
stale version rather than overwriting another edit. Conflicts keep the editor
|
|
740
|
+
and show a reload instruction; choose the contact and Open again to get its
|
|
741
|
+
latest version. Missing/foreign records do not reveal another client's data.
|
|
742
|
+
A lost save acknowledgement can still leave an uncertain outcome; open the
|
|
743
|
+
record to inspect it. The existing UI replay protection is not a general business
|
|
744
|
+
idempotency/result-recovery mechanism.
|
|
745
|
+
|
|
746
|
+
`npm test` includes a real SQLite test with two connections, reopen/persistence,
|
|
747
|
+
owner isolation, duplicate emails, parameter-bound text and stale writes/deletes.
|
|
748
|
+
`npm run test:demo` also runs HTTP create/read/update/delete, malformed field
|
|
749
|
+
validation, duplicate email, stale-version and cross-client scenarios. Browser
|
|
750
|
+
DOM/dirty/discard behavior is tested separately by the renderer suite.
|
|
751
|
+
|
|
752
|
+
For a form-internal action that replaces edits, set `confirmDirty: true` on its
|
|
753
|
+
named event source (also supported by the server Button builder). Session checks
|
|
754
|
+
its dirty scope before queueing: cancellation resolves false with no HTTP, busy
|
|
755
|
+
state or seqno; confirmation leaves the baseline unchanged until a response
|
|
756
|
+
replaces or acknowledges it. Application passes its configured `window` to each
|
|
757
|
+
session; a standalone Session needs `options.window`. A dirty discard action
|
|
758
|
+
without a confirmation window fails with `UiDiscardConfirmationUnavailable`.
|
|
759
|
+
|
|
760
|
+
## UI protocol version
|
|
761
|
+
|
|
762
|
+
UI event requests and patch responses carry a top-level numeric `protocol: 1`.
|
|
763
|
+
`protocolVersion()` is exported by `./protocol`; the server exports the same
|
|
764
|
+
function from `lango-ui`. This version is independent of npm package versions.
|
|
765
|
+
Bootstrap, ping, logout and ordinary API responses use their existing contracts.
|
|
766
|
+
|
|
767
|
+
An explicit unsupported value (including a string or null) raises
|
|
768
|
+
`UiProtocolUnsupported`. The client checks before preparing controls or applying
|
|
769
|
+
values/commands. Dispatcher rejects it before replay reservation or handler
|
|
770
|
+
execution; a verified HTTP request receives status 400 with `protocol: 1` and
|
|
771
|
+
`error: "UiProtocolUnsupported"`. Retrying the same seqno with the supported
|
|
772
|
+
protocol remains possible because the rejected request did not reserve it.
|
|
773
|
+
|
|
774
|
+
For the unversioned preview clients/examples, an omitted protocol field is
|
|
775
|
+
accepted as protocol 1. New clients and server response builders always emit the
|
|
776
|
+
field. This bridge does not make unknown controls or commands compatible: their
|
|
777
|
+
normal validation still applies. Changing required fields, value meanings,
|
|
778
|
+
command/control semantics or ordering guarantees requires a new protocol version.
|
|
779
|
+
Optional additive metadata can remain in version 1 when older peers can safely
|
|
780
|
+
ignore it. Upgrade the client and UI server together when moving between protocol
|
|
781
|
+
versions; there is no automatic downgrade or feature negotiation.
|
|
782
|
+
|
|
783
|
+
## Create a complete API/UI application
|
|
784
|
+
|
|
785
|
+
The updated starter release set is `lango-js` 0.1.11, `lango-client` 0.2.1,
|
|
786
|
+
and `lango-api`/`lango-ui` 0.2.0. Once the patch versions are published:
|
|
787
|
+
|
|
788
|
+
```sh
|
|
789
|
+
npx --package @lango-project/lango-client@0.2.1 lango-create-app my-app
|
|
790
|
+
cd my-app
|
|
791
|
+
npm install
|
|
792
|
+
npm test
|
|
793
|
+
npm run build
|
|
794
|
+
npm start
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
Open http://localhost:8080/. The generator pins the release set, includes VS Code
|
|
798
|
+
recommendations/settings and preserves an existing `.git` directory. It refuses
|
|
799
|
+
to overwrite a nonempty project. Runtime files stay in ignored `.lango/`, build
|
|
800
|
+
outputs in `dist/`; the generated lock file should be committed after installation.
|
|
801
|
+
The starter contains Lango browser/server/worker/page sources, an HTML shell with
|
|
802
|
+
an import map, CSS and a protocol test. The example validates a name and returns
|
|
803
|
+
an explicit save acknowledgement; business persistence is left to the application.
|
|
804
|
+
The contact-book demo remains a separate persistence example.
|
|
805
|
+
|
|
806
|
+
The Node-only `./host` entry exports `BrowserHost(options)`. Applications supply
|
|
807
|
+
`appRoot`, a Pages registry, `worker`, `shell`, and an exact URL-to-file `assets`
|
|
808
|
+
map. The host serves the shell for registered page paths and `/`, mounts the
|
|
809
|
+
packaged browser SDK under `/vendor/lango-client/`, and proxies `/app/*` and
|
|
810
|
+
`/_lango/*` JSON requests to the worker API. Unknown paths are 404; asset content
|
|
811
|
+
uses ETag/revalidation and the shell is no-store. Files are loaded at startup,
|
|
812
|
+
so rebuild/restart to apply changes. Default loopback ports are 8080/8081; pass
|
|
813
|
+
distinct `port` and `apiPort` values to change them. `start()`/`close()` return
|
|
814
|
+
Promises; close coalesces and releases both servers/workers. SIGINT/SIGTERM invoke
|
|
815
|
+
close. This is the local development host; deployment policy remains explicit.
|
|
816
|
+
|
|
817
|
+
BrowserHost accepts `bodyLimit` (default 1048576 bytes) and `bodyTimeoutMs`
|
|
818
|
+
(default 30000 ms). The same limits apply at the browser-facing proxy and its
|
|
819
|
+
worker API. Oversized uploads receive 413 `RequestTooLarge`; an unfinished body
|
|
820
|
+
receives 408 `RequestTimeout`. Rejected/disconnected uploads do not reach a
|
|
821
|
+
handler, and rejection closes the upload connection after sending its response.
|
|
822
|
+
Limits count bytes and preserve UTF-8 characters split between network chunks.
|
|
823
|
+
The deadline covers body reception after headers; header limits remain Node's
|
|
824
|
+
HTTP server policy. The worker API exposes `/health` and `/ready` on its separate
|
|
825
|
+
loopback port; BrowserHost does not expose those paths on the browser port.
|
|
826
|
+
|
|
827
|
+
BrowserHost also accepts `rateLimit` (requests per IP per fixed window, default
|
|
828
|
+
0/disabled), `rateWindowMs` (60000) and `rateMaxClients` (10000). These apply to
|
|
829
|
+
proxied POST requests before buffering, using the actual frontend socket address;
|
|
830
|
+
forwarded headers cannot change identity. Its private loopback API keeps the
|
|
831
|
+
general limiter disabled so users are not combined into one proxy-IP quota.
|
|
832
|
+
The API's separate telemetry quota still applies. Rejections return
|
|
833
|
+
429/Retry-After and close the connection. Counts are bounded, process-local and
|
|
834
|
+
reset on restart; a distributed ingress policy remains separate.
|
|
835
|
+
|
|
836
|
+
## Labels, errors and keyboard focus
|
|
837
|
+
|
|
838
|
+
Built-in Text, Select and Checkbox controls with a `label` render a visible,
|
|
839
|
+
implicitly associated HTML label as well as their accessible name. Inline errors
|
|
840
|
+
are visible text connected through `aria-describedby`; required fields expose
|
|
841
|
+
`aria-required`. Hiding or replacing a control includes its label and error text,
|
|
842
|
+
and structural rollback restores the complete wrapper.
|
|
843
|
+
|
|
844
|
+
`control.element` remains the native input/select for value access and focus.
|
|
845
|
+
`control.node` is its structural DOM root (the label wrapper for labeled fields,
|
|
846
|
+
otherwise the element itself). Custom renderers should replace/remove/capture
|
|
847
|
+
node and focus element. Native input classes/styles remain on element; style
|
|
848
|
+
`.lango-field`, `.lango-caption` and `.lango-field-error` for the surrounding UI.
|
|
849
|
+
Label content uses textContent, including when supplied text contains markup.
|
|
850
|
+
|
|
851
|
+
A queued request temporarily makes its form inert. When work finishes, the
|
|
852
|
+
previous focus is restored if the element is still attached and enabled and the
|
|
853
|
+
user has not focused something elsewhere. Removed/disabled/hidden targets are
|
|
854
|
+
not focused. Server field errors and client validation then focus/report the
|
|
855
|
+
invalid input using the existing native validity behavior.
|
|
856
|
+
|
|
857
|
+
## Chromium and accessibility checks
|
|
858
|
+
|
|
859
|
+
Browser checks are Lango programs using Playwright and axe. They are separate
|
|
860
|
+
from `npm test`, so ordinary tests do not require a browser download:
|
|
861
|
+
|
|
862
|
+
```sh
|
|
863
|
+
npm install
|
|
864
|
+
npm run browser:install
|
|
865
|
+
npm run build
|
|
866
|
+
npm run build:demo-server
|
|
867
|
+
npm run test:browser
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
Build the sibling API/UI projects before running the demo server. To test a
|
|
871
|
+
built starter instead, run `npm run test:browser -- /absolute/app/path starter`.
|
|
872
|
+
The runner stores its browser and download scratch files in ignored
|
|
873
|
+
`.test-output/` (also on Windows). The fixture uses ports 8080/8081 and shuts
|
|
874
|
+
down after success/failure. Screenshots and complete axe results are written to
|
|
875
|
+
`.test-output/browser-demo/` and `.test-output/browser-starter/`; failures also
|
|
876
|
+
include page errors, console/server output, DOM and a screenshot. Fixture content
|
|
877
|
+
is synthetic; do not point these artifact-producing checks at personal data.
|
|
878
|
+
|
|
879
|
+
The starter check covers real startup, visible labels, Tab/Enter, validation
|
|
880
|
+
without a request, canonical save, focus restoration, reload and a 390px viewport.
|
|
881
|
+
The demo check covers contact saving, checkbox label activation, dirty-navigation
|
|
882
|
+
cancellation, server field errors, Back/Forward and reload. Axe scans the tested
|
|
883
|
+
screens without suppressing rules. Chromium coverage does not establish full
|
|
884
|
+
accessibility compliance or cross-browser support; screen-reader/manual checks
|
|
885
|
+
and Firefox/WebKit coverage remain separate. See the
|
|
886
|
+
[Playwright accessibility guide](https://playwright.dev/docs/accessibility-testing).
|
|
887
|
+
|
|
888
|
+
## Private error reports
|
|
889
|
+
|
|
890
|
+
The optional `./errors` entry exports `ErrorReporter(options)`. Supply `window`
|
|
891
|
+
to listen to error/unhandledrejection events and call `reporter.error(error)`
|
|
892
|
+
from your existing error presenter. The starter wires both paths while retaining
|
|
893
|
+
a generic visible error message. `clear()` is a no-op so a reporter can also be
|
|
894
|
+
used as a Binding error adapter; it does not render UI. Call `dispose()` to
|
|
895
|
+
remove listeners and discard unsent reports when the application is torn down.
|
|
896
|
+
|
|
897
|
+
Only version/source/code/count are queued. Raw errors, messages, stacks, URLs,
|
|
898
|
+
form values and tokens are neither retained nor serialized. Known primitive
|
|
899
|
+
UI error strings select a fixed category; other errors become UnexpectedError.
|
|
900
|
+
Validation/disposed UI errors are ignored. Unknown source/code arguments to
|
|
901
|
+
`report(source, code)` become fixed safe defaults. The fingerprint on the server
|
|
902
|
+
therefore groups categories, not messages or stack traces.
|
|
903
|
+
|
|
904
|
+
Repeated categories are grouped for one second, with counts capped at 100.
|
|
905
|
+
At most ten attempts per minute are sent; excess/failing reports are dropped,
|
|
906
|
+
without retry or reporting their own failures. `flush()` returns a Promise and
|
|
907
|
+
allows explicit flushing. The native transport POSTs only to
|
|
908
|
+
`/_lango/client-error`, omits credentials and referrer, refuses redirects, disables
|
|
909
|
+
caching and has a five-second timeout. No token store participates. Server
|
|
910
|
+
validation/quota are independent of client-side limits. A custom
|
|
911
|
+
`options.transport.send(report)` can replace transport; its author is responsible
|
|
912
|
+
for retaining these privacy and network policies. No global handlers are attached
|
|
913
|
+
until an ErrorReporter is explicitly created with a window.
|
|
914
|
+
|
|
915
|
+
BrowserHost requires the optional peer `@lango-project/lango-api` at runtime;
|
|
916
|
+
browser-only SDK use does not. Browser code and Node host/CLI artifacts have
|
|
917
|
+
separate output/runtime directories. The starter uses the npm packages through
|
|
918
|
+
normal Node resolution and browser import maps, without adjacent source checkout
|
|
919
|
+
paths or npm links.
|
|
920
|
+
|
|
921
|
+
Before publishing, maintainers can pack the four built packages, generate a
|
|
922
|
+
project with the packed CLI, install the tarballs there, and run its test/build.
|
|
923
|
+
`npm run test:starter -- /absolute/path/to/built-project` runs the real HTTP smoke
|
|
924
|
+
check (ports 8080/8081): deep URL shell, browser assets without Node imports, CSS
|
|
925
|
+
304, oversized upload rejection, protocol rejection/retry, save acknowledgement and graceful shutdown. The
|
|
926
|
+
ordinary client suite includes generator overwrite/.git/version-pin checks.
|
|
927
|
+
The smoke also checks anonymous category-only telemetry through the proxy.
|
|
928
|
+
For the frontend quota variant, set the fixture's BrowserHost `rateLimit` to 6,
|
|
929
|
+
rebuild it, and append `--rate-limit` to the smoke command; the next POST must
|
|
930
|
+
return 429/Retry-After after the six expected POST attempts.
|