elit 3.4.9 → 3.5.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.
Files changed (68) hide show
  1. package/README.md +98 -6
  2. package/dist/build.d.mts +1 -1
  3. package/dist/cli.js +539 -111
  4. package/dist/config.d.mts +9 -2
  5. package/dist/config.d.ts +7 -0
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js.map +1 -1
  8. package/dist/config.mjs.map +1 -1
  9. package/dist/coverage.d.mts +1 -1
  10. package/dist/desktop-cli.d.ts.map +1 -1
  11. package/dist/http.d.ts.map +1 -1
  12. package/dist/http.js +5 -4
  13. package/dist/http.js.map +1 -1
  14. package/dist/http.mjs +5 -4
  15. package/dist/http.mjs.map +1 -1
  16. package/dist/https.js +5 -4
  17. package/dist/https.js.map +1 -1
  18. package/dist/https.mjs +5 -4
  19. package/dist/https.mjs.map +1 -1
  20. package/dist/index.d.mts +1 -1
  21. package/dist/index.js +20 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +20 -1
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/native.js +20 -1
  26. package/dist/native.js.map +1 -1
  27. package/dist/native.mjs +20 -1
  28. package/dist/native.mjs.map +1 -1
  29. package/dist/{server-DpnTyF7I.d.mts → server--YFoC6ln.d.mts} +27 -0
  30. package/dist/{server-BU71N4fk.d.ts → server-DacsdjFJ.d.ts} +27 -0
  31. package/dist/server.d.mts +1 -1
  32. package/dist/server.d.ts.map +1 -1
  33. package/dist/server.js +141 -52
  34. package/dist/server.js.map +1 -1
  35. package/dist/server.mjs +141 -52
  36. package/dist/server.mjs.map +1 -1
  37. package/dist/state.d.ts.map +1 -1
  38. package/dist/state.js +20 -1
  39. package/dist/state.js.map +1 -1
  40. package/dist/state.mjs +20 -1
  41. package/dist/state.mjs.map +1 -1
  42. package/dist/types.d.mts +28 -1
  43. package/dist/types.d.ts +27 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js.map +1 -1
  46. package/dist/wapk-cli.d.ts +15 -4
  47. package/dist/wapk-cli.d.ts.map +1 -1
  48. package/dist/ws.d.mts +1 -1
  49. package/dist/ws.d.ts +1 -1
  50. package/dist/ws.d.ts.map +1 -1
  51. package/dist/ws.js +9 -4
  52. package/dist/ws.js.map +1 -1
  53. package/dist/ws.mjs +9 -4
  54. package/dist/ws.mjs.map +1 -1
  55. package/dist/wss.js +14 -8
  56. package/dist/wss.js.map +1 -1
  57. package/dist/wss.mjs +14 -8
  58. package/dist/wss.mjs.map +1 -1
  59. package/package.json +1 -1
  60. package/src/cli.ts +18 -0
  61. package/src/config.ts +8 -0
  62. package/src/desktop-cli.ts +19 -1
  63. package/src/http.ts +5 -4
  64. package/src/server.ts +182 -56
  65. package/src/state.ts +25 -1
  66. package/src/types.ts +30 -0
  67. package/src/wapk-cli.ts +451 -52
  68. package/src/ws.ts +12 -5
package/README.md CHANGED
@@ -9,7 +9,7 @@ The package is split by runtime. Browser-facing APIs live in `elit` and the clie
9
9
  If you are generating or editing code for Elit, follow these rules first:
10
10
 
11
11
  - Use `elit` or the client subpaths for browser UI code.
12
- - Use `elit/server` for HTTP routes, middleware, dev server, preview server, and server-side shared state.
12
+ - Use `elit/server` for HTTP routes, WebSocket endpoints, middleware, dev server, preview server, and server-side shared state.
13
13
  - Use `elit/desktop` only inside `elit desktop ...` runtime. Those APIs are injected by the native desktop runtime and are not normal browser globals.
14
14
  - Use `elit/build` for programmatic bundling.
15
15
  - Use `elit/database` for the VM-backed file database helpers.
@@ -62,7 +62,7 @@ Use this table as the import map for generated code.
62
62
  | `elit/state` | Reactive state and render helpers | `createState`, `computed`, `reactive`, `text`, `bindValue`, `bindChecked`, `createSharedState` |
63
63
  | `elit/style` | CSS generation and injection | `CreateStyle`, `styles`, `renderStyle`, `injectStyle`, `addClass`, `addTag` |
64
64
  | `elit/router` | Client-side routing | `createRouter`, `createRouterView`, `routerLink` |
65
- | `elit/server` | HTTP router, dev server, middleware, shared server state | `ServerRouter`, `createDevServer`, `cors`, `logger`, `rateLimit`, `compress`, `security`, `StateManager` |
65
+ | `elit/server` | HTTP router, dev server, middleware, WebSocket endpoints, shared server state | `ServerRouter`, `createDevServer`, `cors`, `logger`, `rateLimit`, `compress`, `security`, `StateManager` |
66
66
  | `elit/build` | Programmatic build API | `build` |
67
67
  | `elit/desktop` | Native desktop window APIs | `createWindow`, `createWindowServer`, `onMessage`, `windowQuit`, `windowSetTitle`, `windowEval` |
68
68
  | `elit/database` | VM-backed file database | `Database`, `create`, `read`, `save`, `update`, `rename`, `remove` |
@@ -255,12 +255,14 @@ Useful flags:
255
255
  - `elit native generate android ./src/native-screen.ts --name HomeScreen --package com.example.app`
256
256
  - `elit native generate ios ./src/native-screen.ts --out ./ios/HomeScreen.swift --no-preview`
257
257
  - `elit native generate ir ./src/native-screen.ts --platform android --export screen`
258
+ - `elit wapk pack . --password-env WAPK_PASSWORD`
258
259
  - `elit wapk ./app.wapk --runtime node|bun|deno`
259
- - `elit wapk run ./app.wapk --sync-interval 100 --watcher`
260
+ - `elit wapk run ./app.wapk --password-env WAPK_PASSWORD --sync-interval 100 --watcher`
260
261
  - `elit wapk pack . --include-deps`
261
- - `elit wapk inspect ./app.wapk`
262
+ - `elit wapk inspect ./app.wapk --password-env WAPK_PASSWORD`
262
263
  - `elit wapk extract ./app.wapk`
263
264
  - `elit desktop wapk ./app.wapk --runtime node|bun|deno --watcher`
265
+ - `elit desktop wapk run ./app.wapk --runtime bun --password-env WAPK_PASSWORD`
264
266
 
265
267
  Desktop mode notes:
266
268
 
@@ -306,8 +308,12 @@ WAPK mode notes:
306
308
  - `elit desktop wapk <file.wapk>` and `elit desktop wapk run <file.wapk>` run packaged apps in desktop mode.
307
309
  - During run, the archive is expanded into a temporary work directory and changes are synced back to the same `.wapk` file.
308
310
  - Use `--sync-interval <ms>` for polling mode, or `--watcher` / `--use-watcher` for event-driven sync.
309
- - Configure package metadata in `elit.config.*` under `wapk`.
310
- - See the full example app at `examples/wapk-example`.
311
+ - Use `--password` or, preferably, `--password-env` when packing, inspecting, extracting, or running a locked archive.
312
+ - `inspect` without credentials still reports whether the archive is locked, but it does not print the archive contents.
313
+ - Locked archives stay encrypted when live sync writes changes back into the same `.wapk` file.
314
+ - Configure package metadata in `elit.config.*` under `wapk`, and use `wapk.lock` when you want password-protected archives by default.
315
+ - WAPK stays unlocked by default unless `wapk.lock.password`, `wapk.lock.passwordEnv`, `--password`, or `--password-env` is provided.
316
+ - See [docs/wapk.md](docs/wapk.md) for the full archive guide and `examples/wapk-example` for an end-to-end sample.
311
317
 
312
318
  ## Config File
313
319
 
@@ -380,6 +386,10 @@ The config shape is:
380
386
  port?: number;
381
387
  env?: Record<string, string | number | boolean>;
382
388
  desktop?: Record<string, unknown>;
389
+ lock?: {
390
+ password?: string;
391
+ passwordEnv?: string;
392
+ };
383
393
  };
384
394
  }
385
395
  ```
@@ -402,6 +412,17 @@ export default {
402
412
  basePath: '',
403
413
  ssr: () => documentShell,
404
414
  api,
415
+ ws: [
416
+ {
417
+ path: '/ws',
418
+ handler: ({ ws, query }) => {
419
+ ws.send(JSON.stringify({ type: 'connected', room: query.room || 'general' }));
420
+ ws.on('message', (message) => {
421
+ ws.send(message.toString());
422
+ });
423
+ },
424
+ },
425
+ ],
405
426
  },
406
427
  ],
407
428
  },
@@ -421,6 +442,14 @@ export default {
421
442
  root: './dist',
422
443
  index: './index.html',
423
444
  port: 4173,
445
+ ws: [
446
+ {
447
+ path: '/ws',
448
+ handler: ({ ws }) => {
449
+ ws.on('message', (message) => ws.send(message.toString()));
450
+ },
451
+ },
452
+ ],
424
453
  },
425
454
  test: {
426
455
  include: ['testing/unit/**/*.test.ts'],
@@ -460,10 +489,19 @@ export default {
460
489
  env: {
461
490
  NODE_ENV: 'production',
462
491
  },
492
+ lock: {
493
+ passwordEnv: 'WAPK_PASSWORD',
494
+ },
463
495
  },
464
496
  };
465
497
  ```
466
498
 
499
+ Notes:
500
+
501
+ - `dev.ws` and `preview.ws` register global WebSocket endpoints.
502
+ - `clients[].ws` registers client-specific endpoints and prefixes each path with that client's `basePath`.
503
+ - The internal Elit HMR and shared-state socket uses `/__elit_ws`, so do not reuse that path for custom endpoints.
504
+
467
505
  Important details:
468
506
 
469
507
  - `build` may be a single object or an array. If it is an array, all builds run sequentially.
@@ -473,6 +511,7 @@ Important details:
473
511
  - `desktop` config provides defaults for `elit desktop`, `elit desktop run`, `elit desktop build`, and `elit desktop wapk`. Use `desktop.entry` for hybrid defaults, `desktop.native.entry` for native defaults, and `desktop.mode` to choose which one runs by default.
474
512
  - `mobile` config provides defaults for `elit mobile init|sync|open|run|build`.
475
513
  - `wapk` config is loaded from `elit.config.*`, then package metadata is used as fallback.
514
+ - `wapk.lock.passwordEnv` is the safest reusable way to protect archives without putting the password directly into shell history or committed config.
476
515
  - `wapk run` and `desktop wapk run` sync runtime file changes back into the same `.wapk` archive.
477
516
 
478
517
  ## Browser Patterns
@@ -606,6 +645,49 @@ const server = createDevServer({
606
645
  console.log(server.url);
607
646
  ```
608
647
 
648
+ ### Custom WebSocket Endpoints
649
+
650
+ Server:
651
+
652
+ ```ts
653
+ import { createDevServer } from 'elit/server';
654
+
655
+ const server = createDevServer({
656
+ root: '.',
657
+ open: false,
658
+ ws: [
659
+ {
660
+ path: '/ws',
661
+ handler: ({ ws, query }) => {
662
+ ws.send(JSON.stringify({ type: 'connected', room: query.room || 'general' }));
663
+
664
+ ws.on('message', (message) => {
665
+ ws.send(message.toString());
666
+ });
667
+ },
668
+ },
669
+ ],
670
+ });
671
+ ```
672
+
673
+ Client:
674
+
675
+ ```ts
676
+ const socket = new WebSocket(`ws://${location.host}/ws?room=general`);
677
+
678
+ socket.addEventListener('message', (event) => {
679
+ console.log(event.data);
680
+ });
681
+
682
+ socket.send('hello');
683
+ ```
684
+
685
+ Notes:
686
+
687
+ - Use `dev.ws` or `preview.ws` for global endpoints.
688
+ - Use `clients[].ws` when each client should expose its own endpoint under its `basePath`.
689
+ - Do not use `/__elit_ws`; Elit reserves that path for internal HMR and shared-state traffic.
690
+
609
691
  ### Shared State Between Server and Client
610
692
 
611
693
  Client:
@@ -787,6 +869,16 @@ npx elit test --coverage --coverage-reporter text,html
787
869
 
788
870
  The package also exports `elit/test`, `elit/test-runtime`, and `elit/test-reporter` for advanced use, but most users should stay on the CLI.
789
871
 
872
+ ## Changelog
873
+
874
+ Latest release notes live in [CHANGELOG.md](CHANGELOG.md).
875
+
876
+ Highlights in `v3.5.1`:
877
+
878
+ - Added first-class custom WebSocket endpoints for `dev`, `preview`, and `clients[]` config.
879
+ - Moved internal HMR and shared-state traffic to `/__elit_ws` so custom endpoints do not collide with Elit internals.
880
+ - Tightened cross-runtime WebSocket path matching so root endpoints no longer swallow every upgrade request.
881
+
790
882
  ## Good Defaults For Generated Code
791
883
 
792
884
  When writing new Elit code, these defaults are usually correct:
package/dist/build.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as BuildOptions, a as BuildResult } from './server-DpnTyF7I.mjs';
1
+ import { B as BuildOptions, a as BuildResult } from './server--YFoC6ln.mjs';
2
2
  import './http.mjs';
3
3
  import 'node:events';
4
4
  import './ws.mjs';