lakutata 3.1.4 → 3.1.6

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 (67) hide show
  1. package/README.md +11 -11
  2. package/README.zh-CN.md +5 -5
  3. package/dist/cjs/exports/NwjsAdapter.d.ts +1 -0
  4. package/dist/cjs/exports/NwjsAdapter.js +20 -0
  5. package/dist/cjs/exports/ReactNativeAdapter.d.ts +1 -0
  6. package/dist/cjs/exports/ReactNativeAdapter.js +20 -0
  7. package/dist/esm/exports/NwjsAdapter.js +1 -0
  8. package/dist/esm/exports/ReactNativeAdapter.js +1 -0
  9. package/dist/types/exports/NwjsAdapter.d.ts +1 -0
  10. package/dist/types/exports/ReactNativeAdapter.d.ts +1 -0
  11. package/doc/en/Application.md +6 -1
  12. package/doc/en/Barcode.md +386 -0
  13. package/doc/en/Cache.md +2 -1
  14. package/doc/en/Command.md +20 -4
  15. package/doc/en/ContainerdIntegration.md +1 -1
  16. package/doc/en/Database.md +4 -0
  17. package/doc/en/DatabaseDrivers.md +75 -4
  18. package/doc/en/Entrypoint.md +4 -2
  19. package/doc/en/Exceptions.md +1 -1
  20. package/doc/en/FFI.md +1 -1
  21. package/doc/en/GRPC.md +1 -1
  22. package/doc/en/GettingStarted.md +16 -2
  23. package/doc/en/HTTP.md +1 -0
  24. package/doc/en/I18n.md +1 -1
  25. package/doc/en/Installers.md +34 -6
  26. package/doc/en/Math.md +1 -1
  27. package/doc/en/Migrations.md +2 -2
  28. package/doc/en/NativeAddons.md +12 -2
  29. package/doc/en/Overview.md +14 -11
  30. package/doc/en/Packaging.md +8 -1
  31. package/doc/en/ProjectStructure.md +18 -3
  32. package/doc/en/ServiceCalls.md +85 -5
  33. package/doc/en/UpgradingFrom1.md +2 -2
  34. package/doc/en/UpgradingFrom2.md +4 -4
  35. package/doc/en/WebRTC.md +4 -4
  36. package/doc/en/examples/MobileApp.md +730 -0
  37. package/doc/en/examples/README.md +2 -0
  38. package/doc/en/examples/TrayApp.md +1061 -0
  39. package/doc/zh/Application.md +3 -1
  40. package/doc/zh/Barcode.md +313 -0
  41. package/doc/zh/Cache.md +1 -1
  42. package/doc/zh/Command.md +12 -3
  43. package/doc/zh/ContainerdIntegration.md +1 -1
  44. package/doc/zh/Database.md +2 -0
  45. package/doc/zh/DatabaseDrivers.md +52 -2
  46. package/doc/zh/Entrypoint.md +3 -1
  47. package/doc/zh/Exceptions.md +1 -1
  48. package/doc/zh/FFI.md +1 -1
  49. package/doc/zh/GRPC.md +1 -1
  50. package/doc/zh/GettingStarted.md +12 -2
  51. package/doc/zh/HTTP.md +1 -0
  52. package/doc/zh/I18n.md +1 -1
  53. package/doc/zh/Installers.md +16 -5
  54. package/doc/zh/Math.md +1 -1
  55. package/doc/zh/Migrations.md +1 -1
  56. package/doc/zh/NativeAddons.md +4 -2
  57. package/doc/zh/Overview.md +5 -4
  58. package/doc/zh/Packaging.md +6 -1
  59. package/doc/zh/ProjectStructure.md +5 -2
  60. package/doc/zh/ServiceCalls.md +65 -2
  61. package/doc/zh/UpgradingFrom1.md +2 -2
  62. package/doc/zh/UpgradingFrom2.md +3 -3
  63. package/doc/zh/WebRTC.md +1 -1
  64. package/doc/zh/examples/MobileApp.md +671 -0
  65. package/doc/zh/examples/README.md +2 -0
  66. package/doc/zh/examples/TrayApp.md +980 -0
  67. package/package.json +36 -16
@@ -15,7 +15,7 @@ The containers it creates are the same as the containers nerdctl creates: they c
15
15
 
16
16
  | Feature | Needs |
17
17
  |---|---|
18
- | Everything | Linux, containerd 1.6 or later with runc, Node.js `^22.13.0 || >=24.11.0`; the application runs as root or as a member of the group owning the socket of containerd |
18
+ | Everything | Linux, containerd 1.6 or later with runc, Node.js `>=18.10.0`; the application runs as root or as a member of the group owning the socket of containerd |
19
19
  | CNI networks (the default `bridge` included), published ports | The CNI plugins (`bridge`, `portmap`, `host-local`… in `/opt/cni/bin`, `/usr/lib/cni` or `/usr/libexec/cni`, the `cniPath` option) and iptables |
20
20
  | `exec()` with `stdin`, separate `stdout`/`stderr`, terminals | `mkfifo` on the host (without it, `exec()` puts both outputs in `stdout`) |
21
21
  | Builds | A BuildKit daemon (`buildkitd`), local or remote |
@@ -103,6 +103,10 @@ The options are the ones of TypeORM, given to it as they are. The options of eac
103
103
  finds the first row of the table: check the values taken from a request before querying with them, or set
104
104
  `invalidWhereValuesBehavior: {undefined: 'throw'}` to throw on them (each key given replaces its default).
105
105
 
106
+ **Paths with aliases.** A path given with an alias of the application (`@data/app.sqlite`, `@app/migrations/*.js`) is
107
+ resolved when the database connects: the file of the database (`database`, the `location` of sql.js) and the globs of
108
+ the entities, the migrations and the subscribers. The aliases are declared by `.alias()` ([Application](Application.md), section 2).
109
+
106
110
  **Databases created with TypeORM 0.3.** If a table or column name has characters outside ASCII, TypeORM 1 names its
107
111
  indices and constraints differently, and generated migrations would rename them.
108
112
  `namingStrategy: new NamingStrategyV03()` (from `lakutata/orm`) keeps the names of TypeORM 0.3.
@@ -23,8 +23,9 @@ npm install lakutata pg
23
23
  ```
24
24
 
25
25
  There is no `sqlite` type: SQLite files use `better-sqlite3`, or `sqljs` where a native module cannot run. TypeORM also
26
- has drivers for the mobile platforms (`capacitor`, `cordova`, `expo`, `nativescript`, `react-native`); lakutata does
27
- not target them.
26
+ has drivers for the JavaScript of the mobile platforms (`capacitor`, `cordova`, `expo`, `nativescript`, `react-native`);
27
+ lakutata does not use them. A mobile application of the `mobile-react` template runs the lakutata application in a
28
+ Node.js instead, with the drivers of this page (see [The mobile applications](#the-mobile-applications)).
28
29
 
29
30
  ## What applies to every driver
30
31
 
@@ -136,8 +137,14 @@ export const db = buildDatabaseOptions({
136
137
  - The foreign keys are enforced (`PRAGMA foreign_keys = ON`). There is one connection: `poolSize` is not supported.
137
138
  - **`bigint` columns come back as numbers**: values beyond 2^53 lose precision. Keep such values in a text column.
138
139
  - `better-sqlite3` is a native module, compiled for one version of Node.js. An Electron application needs the build of
139
- its Electron (`electron-rebuild`, or the prebuilt binaries of better-sqlite3 for Electron); Bun cannot load it (use
140
- `sqljs` there).
140
+ its Electron (`electron-rebuild`, or the prebuilt binaries of better-sqlite3 for Electron); an NW.js application has
141
+ it built again with the headers of NW.js (0.111.3 or later: use `sqljs` with the earlier releases); Bun cannot load it
142
+ (use `sqljs` there).
143
+ - Built from its sources against the headers of Node.js 24.19 or later, it aborts the process when the garbage collector
144
+ frees one of its objects (`Assertion failed: (env) != nullptr`, in `RemoveEnvironmentCleanupHook`:
145
+ [nodejs/node#65446](https://github.com/nodejs/node/issues/65446)), as every addon built on `node::ObjectWrap` does.
146
+ Its prebuilt binaries are built against earlier headers; `lakutata mobile stage` builds the addons for the mobile
147
+ systems without the cleanup hooks of `node::ObjectWrap` that cause it.
141
148
 
142
149
  ## SQLite: sql.js
143
150
 
@@ -164,6 +171,7 @@ export const db = buildDatabaseOptions({
164
171
  | `database` | | The content of a database to load (a `Uint8Array`), instead of `location` |
165
172
  | `useLocalForage` | `false` | In a browser, save to IndexedDB (through `localforage`) instead of `localStorage` |
166
173
  | `sqlJsConfig` | | The options of the initialization of sql.js (`locateFile` of its `.wasm` file) |
174
+ | `driver` | | A build of sql.js to use instead of the package's: its asm.js build (`sql.js/dist/sql-asm.js`) needs no WebAssembly |
167
175
 
168
176
  - Without `autoSave`, nothing is written to disk until `saveDatabase()` of the entity manager (`SqljsEntityManager`)
169
177
  is called. With `autoSave`, the changes of a transaction are saved once it is committed.
@@ -285,3 +293,66 @@ These drivers come from TypeORM as they are:
285
293
  MySQL, are not read.
286
294
  - **Amazon Aurora through the Data API** (`aurora-mysql`, `aurora-postgres`): `region`, `secretArn`, `resourceArn` and
287
295
  `database` are required; the queries go through the HTTP API of AWS, not through a connection.
296
+
297
+ ## The mobile applications
298
+
299
+ A mobile application of the `mobile-react` template runs its lakutata application in the Node.js it embeds (Node.js
300
+ 24.20), where the drivers of this page work as on a computer. The table gives what was verified on the emulators of
301
+ Android (API 36), iOS (27.2) and HarmonyOS: a database written, closed, then opened again.
302
+
303
+ | Driver | Android | iOS | HarmonyOS |
304
+ |---|---|---|---|
305
+ | `better-sqlite3` | Yes | Yes | Yes |
306
+ | `sqljs`, its asm.js build | Yes | Yes | Yes |
307
+ | `sqljs`, its WebAssembly | Yes | Yes, much slower (the polyfill: 1.5 s where the asm.js build took 0.09 s) | No: `ReferenceError: WebAssembly is not defined` |
308
+ | `mongo-embedded` | Yes | Yes | Yes |
309
+ | `postgres`, `mysql`, `mongodb` (a server on the network) | Yes | Yes | Yes |
310
+
311
+ SQL Server and Oracle have not been checked there.
312
+
313
+ - `lakutata mobile stage` builds `better-sqlite3` from its sources for each system, with the NDK, Xcode or DevEco Studio
314
+ (see the `lakutata mobile` commands in the README of `@lakutata/cli`).
315
+ - The file of a database has to last, and `os.tmpdir()` is the cache of the application, which the system may empty. The
316
+ `App.ts` of the template declares the data directory of the application as the alias `@data`: the `files` directory of
317
+ the application on Android, `Library/Application Support` on iOS, `/data/storage/el2/base/files` on HarmonyOS, and
318
+ `packages/app/data` on the computer of the development. The options of the database name a file there as
319
+ `@data/app.sqlite`: the alias is resolved when the database connects.
320
+ - The asm.js build of sql.js is SQLite compiled to JavaScript: no WebAssembly and no other file, so it runs the same on
321
+ the three systems. The Node.js of HarmonyOS has no WebAssembly, and the one of iOS has only the polyfill of
322
+ nodejs-mobile, which is much slower:
323
+
324
+ ```typescript
325
+ import type {ApplicationOptions} from 'lakutata'
326
+ import {buildDatabaseOptions} from 'lakutata/com/database'
327
+ import {createRequire} from 'node:module'
328
+
329
+ /**
330
+ * The options of the application
331
+ */
332
+ export function config(): ApplicationOptions {
333
+ return {
334
+ id: 'app',
335
+ name: 'app',
336
+ components: {
337
+ db: buildDatabaseOptions({
338
+ type: 'sqljs',
339
+ location: '@data/app.sqlite',
340
+ autoSave: true,
341
+ //The asm.js build of sql.js, instead of its WebAssembly
342
+ driver: createRequire(import.meta.url)('sql.js/dist/sql-asm.js'),
343
+ entities: []
344
+ })
345
+ }
346
+ }
347
+ }
348
+ ```
349
+
350
+ - sql.js 1.15 marks its asm.js build as deprecated: the build prints a warning each time it is loaded, and the authors
351
+ ask the users who cannot leave it to say so ([sql-js/sql.js#635](https://github.com/sql-js/sql.js/issues/635)). The
352
+ build they recommend instead, `sql-wasm-inline.js`, needs WebAssembly, which the Node.js of HarmonyOS does not have.
353
+ For a database that the application keeps, `better-sqlite3`, which works on the three systems, is the better choice.
354
+ - The WebAssembly of sql.js is read from `sql-wasm.wasm`, next to its module, which the bundle of the application does
355
+ not keep: declare the file as a resource in `lakutata.resources` (its `from` is where npm installed `sql.js` in the
356
+ workspace), and give its path among the resources to `sqlJsConfig.locateFile` ([Packaging](Packaging.md), section 6).
357
+ - A database server is reached over the network of the device; from an emulator, the computer is reached through
358
+ `adb reverse` (Android) or `hdc rport` (HarmonyOS).
@@ -60,6 +60,8 @@ The adapters:
60
60
  | `service` | `socketIOServiceEntrypoint()` | `lakutata/adapter/socket.io` | `socket.io` | [ServiceCalls](ServiceCalls.md) |
61
61
  | `service` | `jsonRPCServiceEntrypoint()` | `lakutata/adapter/jsonrpc` | `ws`, for WebSocket | [ServiceCalls](ServiceCalls.md) |
62
62
  | `service` | `electronIPCServiceEntrypoint()` | `lakutata/adapter/electron` | (Electron) | [ServiceCalls](ServiceCalls.md) |
63
+ | `service` | `nwjsServiceEntrypoint()` | `lakutata/adapter/nwjs` | (NW.js) | [ServiceCalls](ServiceCalls.md) |
64
+ | `service` | `reactNativeServiceEntrypoint()` | `lakutata/adapter/react-native` | | [ServiceCalls](ServiceCalls.md) |
63
65
  | `service` | `grpcServiceEntrypoint()` | `@lakutata/grpc/service` | `@lakutata/grpc` | [GRPC](GRPC.md) |
64
66
  | `service` | `natsServiceEntrypoint()` | `@lakutata/nats` | `@lakutata/nats` | [NATS](NATS.md) |
65
67
  | `schedule` | `scheduleEntrypoint()` | `lakutata/com/entrypoint` | | [Schedules](Schedules.md) |
@@ -181,8 +183,8 @@ actions of any other transport (`getActions('schedule')`). Each action is descri
181
183
 
182
184
  ## 6. Pushing events to the clients
183
185
 
184
- The service transports that keep their clients connected (Socket.IO, Electron, the event stream of the HTTP service,
185
- JSON-RPC over WebSocket or stdio, gRPC) can receive events from the application.
186
+ The service transports that keep their clients connected (Socket.IO, Electron, NW.js, the event stream of the HTTP
187
+ service, JSON-RPC over WebSocket or stdio, gRPC) can receive events from the application.
186
188
  `entrypoint.notify(clientId, event, ...args)` sends an event to the client whose id an action found in
187
189
  `this.context.clientId`, and returns whether that client received it. `entrypoint.broadcast(event, ...args)` sends it to
188
190
  every connected client, and returns their number. See [GRPC](GRPC.md) and [ServiceCalls](ServiceCalls.md).
@@ -121,7 +121,7 @@ When an action fails, its transport reports the exception:
121
121
  | Transport | The client receives |
122
122
  |---|---|
123
123
  | HTTP | The status `statusCode` and `{errno, errMsg}` (see [HTTP](HTTP.md), section 6) |
124
- | Socket.IO, Electron, the HTTP service, NATS, gRPC | The whole error: all its own properties (see [ServiceCalls](ServiceCalls.md), section 3) |
124
+ | Socket.IO, Electron, NW.js, the HTTP service, NATS, gRPC | The whole error: all its own properties (see [ServiceCalls](ServiceCalls.md), section 3) |
125
125
  | JSON-RPC | An error with the code `-32602` for an invalid input, `-32601` when no action matches, `-32001` while the application stops, `-32000` otherwise, and the whole error as its `data` |
126
126
  | The command line | `error: <message>` on the standard error, and the exit code 1 (see [CLI](CLI.md)) |
127
127
  | Schedules | No client: the exception is given to `onError`, or logged (see [Schedules](Schedules.md)) |
package/doc/en/FFI.md CHANGED
@@ -433,7 +433,7 @@ Stopping a worker while asynchronous calls run in the threads of its libraries d
433
433
 
434
434
  ## 12. Runtimes
435
435
 
436
- Node.js `^22.13.0 || >=24.11.0`, the main process of Electron and Bun; not the renderers of Electron nor the browsers.
436
+ Node.js `>=18.10.0`, the main process of Electron and Bun; not the renderers of Electron nor the browsers.
437
437
 
438
438
  The tests of the package, including those of the threads of a library, pass on macOS (arm64: Node.js 24, Bun 1.4,
439
439
  Electron 44), on Linux (arm64, glibc and musl: Node.js 24, Bun 1.4) and on Windows 11 (arm64, and x64 under emulation:
package/doc/en/GRPC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The package `@lakutata/grpc` serves the service actions of an application over gRPC, and calls them from another
4
4
  application. Any language with a gRPC library can call them too. It is written in TypeScript over the HTTP/2 module of
5
- Node.js (`^22.13.0 || >=24.11.0`): no native addon and no generated code. `lakutata` does not include it, so install it
5
+ Node.js (`>=18.10.0`): no native addon and no generated code. `lakutata` does not include it, so install it
6
6
  next to it:
7
7
 
8
8
  ```bash
@@ -5,7 +5,18 @@ and write an application by hand.
5
5
 
6
6
  ## 1. Requirements
7
7
 
8
- - Node.js `^22.13.0 || >=24.11.0`: 22.13 or a later 22.x, or 24.11 and later (not 23).
8
+ - Node.js 18.10 or later (`>=18.10.0`). A few features need a newer Node.js:
9
+ - the Fastify adapter: Fastify 5 needs Node.js 18.19, 19.9, 20 or later (the Express adapter needs nothing more);
10
+ - the Kafka transport of `@lakutata/queue`: Node.js 22.22, 24.6 or later, as `@platformatic/kafka` needs;
11
+ - the executables of Node.js (`lakutata package exe`, the installers): made by a Node.js 20.12, 21.7 or later, or with
12
+ `--node-program` naming one;
13
+ - `await using` with the objects of the framework: Node.js 18.18, 20.4 or later.
14
+
15
+ On Node.js 18 and 19, an application uses commander 13, @inquirer/prompts 7 and better-sqlite3 11: their next major
16
+ versions need Node.js 20 or later.
17
+
18
+ The projects made by `lakutata create` declare Node.js `>=22.13.0`, which the tools of the web and desktop templates
19
+ need.
9
20
  - TypeScript, with its decorators (`experimentalDecorators`) and their metadata (`emitDecoratorMetadata`). The framework
10
21
  publishes the compiler options it needs as `lakutata/tsconfig.json`; the templates use TypeScript 6.
11
22
  - ES modules (`"type": "module"`), as in the templates; the package also ships CommonJS builds.
@@ -36,13 +47,16 @@ The `default` template is a small HTTP application. Other templates start from a
36
47
  | `web-react`, `web-vue` | An HTTP API serving a React or Vue single-page application (Vite) |
37
48
  | `web-next`, `web-nuxt` | An HTTP API serving a Next.js or Nuxt application from the same process |
38
49
  | `electron-react`, `electron-vue` | A desktop application: Electron, its main process serving a React or Vue renderer over IPC |
50
+ | `nwjs-react`, `nwjs-vue` | A desktop application: NW.js, its background script serving a React or Vue user interface isolated in a webview |
51
+ | `mobile-react` | A mobile application for Android, iOS and HarmonyOS: React Native, the Node.js inside it serving the user interface |
39
52
 
40
53
  ```bash
41
54
  npx @lakutata/cli create --name shop --template service --with i18n,installer
42
55
  ```
43
56
 
44
57
  `--with` adds optional features: `i18n` (messages in several languages) to every template, `installer` (installers
45
- and a system service) to `cli`, `service` and the `web-*` templates. In a terminal, the tool offers them when `--with`
58
+ and a system service) to `cli`, `service` and the `web-*` templates, `win7` (NW.js 0.72, which runs on Windows 7) to
59
+ the `nwjs-*` templates. In a terminal, the tool offers them when `--with`
46
60
  is not given. [ProjectStructure](ProjectStructure.md) describes the files of the templates, and
47
61
  [Command](Command.md) the options of `lakutata create`.
48
62
 
package/doc/en/HTTP.md CHANGED
@@ -105,6 +105,7 @@ Both adapters serve the same actions, with the same results:
105
105
  |---|---|---|
106
106
  | Adapter | `expressHTTPEntrypoint()`, from `lakutata/adapter/express` | `fastifyHTTPEntrypoint()`, from `lakutata/adapter/fastify` |
107
107
  | Install | `express` (4 or 5) | `fastify` (5) |
108
+ | Node.js | 18.10 and later | 18.19, 19.9, 20 and later (Fastify 5 needs `diagnostics_channel.tracingChannel`) |
108
109
 
109
110
  The options of `expressHTTPEntrypoint()`:
110
111
 
package/doc/en/I18n.md CHANGED
@@ -174,7 +174,7 @@ The languages a request asks for are read from the sources below, in order, then
174
174
  | HTTP (Express, Fastify) | The query parameter `?lang=`, the cookie `lang`, then the `Accept-Language` header (by quality) |
175
175
  | Socket.IO | The query parameter `lang`, the cookie `lang` and `Accept-Language` of the connection's handshake |
176
176
  | HTTP service adapter, JSON-RPC (HTTP, WebSocket) | The query parameter `lang`, the cookie `lang` and `Accept-Language` of the HTTP request (for WebSocket, of the request opening the connection) |
177
- | Command line, Electron IPC, JSON-RPC over stdio | The variable named by `environmentVariable` (none by default), `LANGUAGE`, `LC_ALL`, `LC_MESSAGES`, `LANG`, then the language of the process |
177
+ | Command line, Electron IPC, NW.js, React Native, JSON-RPC over stdio | The variable named by `environmentVariable` (none by default), `LANGUAGE`, `LC_ALL`, `LC_MESSAGES`, `LANG`, then the language of the process |
178
178
  | Schedules | None (the default language) |
179
179
 
180
180
  A query or cookie value that is not a language tag is skipped.
@@ -21,7 +21,8 @@ npx lakutata package installer --target pkg # only some of them
21
21
 
22
22
  An installer holds the executable of the directory layout (`lakutata package exe --layout directory`): the program,
23
23
  its native addons (`native/`) and its resources (`resources/`). The program is made with Node.js, or with Bun when
24
- `lakutata.installer.runtime` is `"bun"`.
24
+ `lakutata.installer.runtime` is `"bun"`. On a Node.js older than 20.12, give a newer one with `--node-program`, as for
25
+ the executables.
25
26
 
26
27
  | Platform | Installers (default) | Their files | Made with |
27
28
  |---|---|---|---|
@@ -68,19 +69,19 @@ The installers are configured by `lakutata.installer` in the `package.json` of t
68
69
  | `description`, `homepage`, `license` | Those of the `package.json` | The information of the packages |
69
70
  | `maintainer` | The `author` of the `package.json` | Its maintainer (`Name <email>`); without one, the tool warns |
70
71
  | `vendor` | None | Its vendor; on Windows, the publisher is the vendor, else the maintainer |
71
- | `runtime` | `node` | `node` or `bun` for the executable; `electron` for an Electron application (section 8) |
72
+ | `runtime` | `node` | `node` or `bun` for the executable; `electron` for an Electron application (section 8), `nwjs` for an NW.js application (section 9) |
72
73
  | `addToPath` | `true` | Put the program in the PATH: `/usr/bin/<program>` on Linux, `/usr/local/bin/<program>` on macOS, the PATH of the machine on Windows |
73
74
  | `service` | None | `true`, or the options of the service (section 4) |
74
75
  | `linux.targets` | `deb`, `rpm`, `tar.gz`; on Alpine `apk`, `tar.gz` | The Linux installers (`deb`, `rpm`, `archlinux`, `tar.gz`; `apk`, `tar.gz` on Alpine) |
75
76
  | `linux.depends`, `linux.recommends` | None | The system packages it needs and recommends (the C++ runtime library is always added) |
76
77
  | `linux.section`, `linux.priority` | None | Its section and its priority (deb) |
77
- | `mac.targets` | `pkg`, `tar.gz` | The macOS installers |
78
+ | `mac.targets` | `pkg`, `tar.gz` | The macOS installers (`dmg` too, for an NW.js application) |
78
79
  | `win.targets` | `nsis`, `msi`, `zip` | The Windows installers |
79
80
  | `linux.scripts`, `mac.scripts`, `win.scripts`… | None | The scripts of the installers (section 5) |
80
81
  | `electron` | None | The configuration of electron-builder (section 8) |
81
82
 
82
83
  `lakutata.icon` (beside `lakutata.installer`) is a square PNG image of 256 pixels or more: the icon of the Windows
83
- executable and installers, and of the Electron applications.
84
+ executable and installers, and of the Electron and NW.js applications.
84
85
 
85
86
  The configuration is checked before anything is built, the options of the installers that are not made included, and an
86
87
  error names the field:
@@ -202,8 +203,9 @@ fi
202
203
 
203
204
  ## 6. Signing
204
205
 
205
- - **macOS**: the `pkg` installers are not signed, and the program they install is signed ad hoc only. The Developer ID
206
- signature and the notarization, which distribution outside the machines of the organization needs, are not made yet.
206
+ - **macOS**: the `pkg` installers and the `dmg` images are not signed, and the program or the application they install
207
+ is signed ad hoc only. The Developer ID signature and the notarization, which distribution outside the machines of the
208
+ organization needs, are not made yet.
207
209
  - **Windows**: the NSIS and MSI installers are not signed: sign them with signtool before distributing them. The program
208
210
  made with Node.js keeps the signature of `node.exe`, which no longer matches, and the tool warns of it.
209
211
  - **Linux**: the packages are not signed.
@@ -278,3 +280,29 @@ and `electron-vue` templates are configured this way.
278
280
  ([NativeAddons](NativeAddons.md), section 4).
279
281
  - On Linux arm64, the deb and rpm packages need the fpm of the system (`gem install fpm`, `USE_SYSTEM_FPM=true`), as the
280
282
  `Dockerfile.installer` of the Electron templates installs it.
283
+
284
+ ## 9. NW.js applications
285
+
286
+ With `"runtime": "nwjs"`, the installers hold an NW.js application made by the builder: the normal flavor of the NW.js
287
+ of the application (its `lakutata.nwjs`, given by `lakutata nwjs use`), downloaded once into the cache of lakutata and
288
+ checked against the checksums of its release, with the application in it: its bundle for the Node.js of that NW.js, its
289
+ native addons, its resources (`lakutata.resources`, read through `resourcesPath()`) and the manifest of NW.js. The
290
+ `nwjs-react` and `nwjs-vue` templates are configured this way.
291
+
292
+ - **The runtime** is named after the application: on Windows, `<name>.exe`, whose icon and version information are
293
+ those of the application; on Linux, `<name>`; on macOS, `<productName>.app`, whose `Info.plist` gives its name, its
294
+ identifier (`appId`), its version and its icon, and which is signed again ad hoc.
295
+ - **The installers** are those of a desktop application: `dmg` on macOS, `nsis` on Windows and `deb` on Linux by
296
+ default (also `pkg` and `tar.gz` on macOS, `msi` and `zip` on Windows, `rpm` and `tar.gz` on Linux). The Windows
297
+ installers add the application to the start menu and to the desktop; the `dmg` disk image holds it beside a link to
298
+ /Applications, where its user drags it, and the `pkg` package installs it there (an Intel application, on the Macs
299
+ of Apple silicon too); the Linux packages add its desktop entry and its icons, and depend on the libraries of
300
+ Chromium.
301
+ - **The architecture** is the one of the machine, or the one of `--arch` (`x64`, `ia32`, `arm64`): `ia32` makes the
302
+ installers of 32-bit Windows, which install the application among the programs of 32 bits. A release of NW.js
303
+ without a build for the Macs of Apple silicon (0.72) is packaged for Intel.
304
+ - **An NW.js application is not a service**, and is not put in the PATH (`addToPath` is `false` by default).
305
+ - **The scripts** run as for the other applications, but a macOS application is removed by deleting it: no removal
306
+ script runs there.
307
+ - **Native addons** are made to load in NW.js: built again for its architecture, or with its headers when they use the
308
+ V8 API, and, on Windows, given the Node.js of NW.js ([NativeAddons](NativeAddons.md), section 4).
package/doc/en/Math.md CHANGED
@@ -348,7 +348,7 @@ $ curl -X POST localhost:8080/solve -H 'Content-Type: application/json' -d '{"eq
348
348
  - The bundles, the executables and the installers made by `lakutata package` carry the compiled addon
349
349
  (`build/Release/math.node`). Build them on each target platform, after installing the package there; the rules of
350
350
  the native addons apply (see [Packaging](Packaging.md) and [NativeAddons](NativeAddons.md)).
351
- - The package runs in Node.js `^22.13.0 || >=24.11.0`, in Bun and in the main process of Electron, which load the
351
+ - The package runs in Node.js `>=18.10.0`, in Bun and in the main process of Electron, which load the
352
352
  addon compiled for Node.js; not in the renderers of Electron nor in the browsers. In Bun, terminating a worker thread
353
353
  while operations of the addon still run in it ends the whole process with a fatal error of Node-API (a bug of Bun
354
354
  1.4).
@@ -143,8 +143,8 @@ export class Migrations1792161460658 implements MigrationInterface {
143
143
  compiled files.
144
144
  - Read the migration before running it: a renamed property becomes a column dropped and a column added, with the data
145
145
  of the old one lost. Edit the SQL when needed.
146
- - When nothing changed, the command writes nothing and exits with the code 1 (`No changes in database schema were
147
- found`).
146
+ - When nothing changed, the command writes nothing, says so (`No changes in database schema were found`) and exits with
147
+ the code 0.
148
148
  - With several databases, each database whose tables differ gets its own file. Give each database a `migrations` option
149
149
  that lists only its own files (`'build/migrations/*-db.js'`), or the databases would run each other's migrations.
150
150
 
@@ -66,14 +66,13 @@ And `src/index.ts`, the same for all three:
66
66
  ```typescript
67
67
  import {createRequire} from 'node:module'
68
68
  import path from 'node:path'
69
- import {fileURLToPath} from 'node:url'
70
69
 
71
70
  type Binding = {
72
71
  greet(name: string): string
73
72
  }
74
73
 
75
74
  /** The addon built into build/Release, loaded from the directory of the package */
76
- const binding: Binding = createRequire(import.meta.url)('node-gyp-build')(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'))
75
+ const binding: Binding = createRequire(__filename)('node-gyp-build')(path.resolve(__dirname, '..'))
77
76
 
78
77
  export function greet(name: string): string {
79
78
  return binding.greet(name)
@@ -96,6 +95,8 @@ export function greet(name: string): string {
96
95
  for the architecture of the machine (`rustup target add` adds the other ones).
97
96
  - **Node-API**: the addons are built for Node-API version 8, which every supported version of Node.js and of Electron
98
97
  provides, so they are not rebuilt for each of them.
98
+ - **CommonJS**: the package is CommonJS (`"type": "commonjs"`). The bundles of `lakutata package` are CommonJS and
99
+ load it with `require`, which can load an ES module only on Node.js 20.19, 22.12 or later.
99
100
  - The package is `"private": true`, like every package that `lakutata add` creates: an addon is usually shipped with
100
101
  its application rather than published.
101
102
 
@@ -214,5 +215,14 @@ The application depends on the addon package, and imports it as any package (`im
214
215
  - **Electron**: the addons are copied as they are installed. The addons that `lakutata add` creates run in Electron
215
216
  without being rebuilt, as do all the addons built on Node-API; an addon built on the V8 API of Node.js must be
216
217
  installed in its build for Electron before packing (`electron-rebuild`).
218
+ - **NW.js**: the addons are made to load in NW.js when the application runs in it (`lakutata nwjs run`, and once
219
+ packaged). The ones built for another architecture than the one of the runtime are built again from their sources,
220
+ with the headers of the Node.js of NW.js; so are the ones built on the V8 API of Node.js, with the headers of NW.js
221
+ (NW.js 0.111.3 or later: the earlier releases, such as 0.72 for Windows 7, run the addons of Node-API only). On
222
+ Windows, the addons load the Node.js of NW.js (`node.dll`). The addons of the project are left as they are, for its
223
+ tests with Node.js.
224
+ - **Mobile applications** (React Native): `lakutata mobile stage` builds the addons from their sources for Android, iOS
225
+ and HarmonyOS, against the libnode the application embeds (see the `lakutata mobile` commands in the README of
226
+ `@lakutata/cli`).
217
227
  - **Bun**: Bun loads the addons of Node-API; an executable of Bun warns of the addons built on the V8 API of Node.js.
218
228
  - **Alpine (musl)**: the executables of Node.js do not load native addons there: make them with Bun.
@@ -1,10 +1,11 @@
1
1
  # Lakutata Overview
2
2
 
3
3
  **Lakutata** is an IoC application framework for Node.js and TypeScript. It gives web services, CLI tools, desktop
4
- (Electron) applications and embedded devices one programming model: an application is a tree of objects (components,
5
- providers, controllers) that a container creates. DTOs validate their options and inputs, and transports expose
6
- the controllers: HTTP (Express, Fastify), CLI (Commander), service RPC (HTTP, Socket.IO, JSON-RPC 2.0, gRPC, NATS,
7
- Electron IPC), schedules and message queues. One controller method can serve all of them at once.
4
+ (Electron, NW.js) applications and embedded devices one programming model: an application is a tree of objects
5
+ (components, providers, controllers) that a container creates. DTOs validate their options and inputs, and transports
6
+ expose the controllers: HTTP (Express, Fastify), CLI (Commander), service RPC (HTTP, Socket.IO, JSON-RPC 2.0, gRPC,
7
+ NATS, Electron IPC, NW.js, React Native), schedules and message queues. One controller method can serve all of them at
8
+ once.
8
9
 
9
10
  The package `lakutata` re-exports the `@lakutata/*` packages under its subpaths (see the table below) and presets two
10
11
  components in every application: `log` (the `Logger`, which writes pino-compatible JSON lines) and `entrypoint` (the
@@ -30,7 +31,7 @@ tool, a web and a desktop application, calls between services, background jobs,
30
31
  | `lakutata/decorator/ctrl` | `@HTTPAction`, `@GET`…`@OPTIONS`, `@CLIAction`, `@ServiceAction`, `@Schedule`, `@Prefix`, `@UseMiddlewares` |
31
32
  | `lakutata/adapter/express`, `lakutata/adapter/fastify` | The HTTP transports |
32
33
  | `lakutata/adapter/commander` | The CLI transport |
33
- | `lakutata/adapter/socket.io`, `lakutata/adapter/jsonrpc`, `lakutata/adapter/electron` | The service transports |
34
+ | `lakutata/adapter/socket.io`, `lakutata/adapter/jsonrpc`, `lakutata/adapter/electron`, `lakutata/adapter/nwjs`, `lakutata/adapter/react-native` | The service transports |
34
35
  | `lakutata/com/logger` | The `Logger` component, preset as `log` (pino-compatible JSON lines) |
35
36
  | `lakutata/orm`, `lakutata/decorator/orm` | TypeORM and its decorators |
36
37
  | `lakutata/com/database`, `lakutata/provider/database` | The `Database` component and provider |
@@ -46,11 +47,12 @@ tool, a web and a desktop application, calls between services, background jobs,
46
47
 
47
48
  Not part of this package: `@lakutata/cli` (the `lakutata` command for creating projects, running migrations and packing
48
49
  applications, see [Command](Command.md)), `@lakutata/grpc` (a gRPC client, server and service transport),
49
- `@lakutata/nats` (a NATS component and service transport), `@lakutata/dbus` (D-Bus), `@lakutata/mcp` (the Model
50
- Context Protocol), `@lakutata/webrtc` (WebRTC: the signaling, a TURN server, a media server, peer connections),
51
- `@lakutata/ffi` (the C functions of native libraries), `@lakutata/math` (symbolic and numeric mathematics, as functions
52
- that need no lakutata application) and `@lakutata/netif` (servers and UDP sockets listening on a network interface
53
- whatever its addresses, the interfaces of the machine and their changes).
50
+ `@lakutata/nats` (a NATS component and service transport), `@lakutata/dbus` (D-Bus), `@lakutata/mcp` (the Model Context
51
+ Protocol), `@lakutata/webrtc` (WebRTC: the signaling, a TURN server, a media server, peer connections), `@lakutata/ffi`
52
+ (the C functions of native libraries), `@lakutata/math` (symbolic and numeric mathematics, as functions that need no
53
+ lakutata application), `@lakutata/barcode` (barcodes and QR codes, generated and read in a native addon) and
54
+ `@lakutata/netif` (servers and UDP sockets listening on a network interface whatever its addresses, the interfaces of
55
+ the machine and their changes).
54
56
 
55
57
  ## The guides
56
58
 
@@ -74,7 +76,7 @@ whatever its addresses, the interfaces of the machine and their changes).
74
76
  | [Middlewares](Middlewares.md) | The middlewares and the access control of the actions |
75
77
  | [HTTP](HTTP.md) | The HTTP adapters: routes, input, responses, errors, the features of Express and Fastify |
76
78
  | [CLI](CLI.md) | Command line tools: commands, options, prompts, output and exit codes |
77
- | [ServiceCalls](ServiceCalls.md) | The service actions over HTTP, Socket.IO, JSON-RPC 2.0 and Electron: patterns, responses, clients and their events |
79
+ | [ServiceCalls](ServiceCalls.md) | The service actions over HTTP, Socket.IO, JSON-RPC 2.0, Electron and NW.js: patterns, responses, clients and their events |
78
80
  | [GRPC](GRPC.md) | The service actions over gRPC (`@lakutata/grpc`), and calling them from other applications and languages |
79
81
  | [NATS](NATS.md) | The NATS component, the service actions over NATS (`@lakutata/nats`), the service proxies and their events |
80
82
  | [Schedules](Schedules.md) | Scheduled jobs: intervals, cron expressions, jobs run by one instance |
@@ -95,6 +97,7 @@ whatever its addresses, the interfaces of the machine and their changes).
95
97
  | [MCP](MCP.md) | The tools, resources and prompts of the Model Context Protocol (`@lakutata/mcp`), over stdio and HTTP |
96
98
  | [WebRTC](WebRTC.md) | Peer-to-peer connections and a media server (`@lakutata/webrtc`): the signaling, the TURN server, browsers and applications, the actions of an application called through data channels, WHIP and WHEP |
97
99
  | [FFI](FFI.md) | The C functions of native libraries (`@lakutata/ffi`): declarations copied from headers, structs, callbacks, memory, packaging |
100
+ | [Barcode](Barcode.md) | Barcodes and QR codes (`@lakutata/barcode`): generating them as PNG, SVG or pixels, sizes for print, EAN, UPC and GS1, reading them from images |
98
101
  | [Math](Math.md) | Mathematics (`@lakutata/math`): formulas and exact results, equations, decimals of any precision, matrices, statistics, numeric solutions, units |
99
102
  | [Netif](Netif.md) | Network interfaces (`@lakutata/netif`): a server listening on an interface whatever its addresses, the connections of the other interfaces refused, the interfaces and their changes, UDP on one interface |
100
103
  | [Command](Command.md) | The `lakutata` command: creating projects, migrations, translations, environment variables |
@@ -10,6 +10,10 @@ A compiled application can be shipped without its `node_modules`, in three forms
10
10
  `lakutata package bundle`, `package exe` and `package installer` make them with `@lakutata/builder`, which the project
11
11
  installs (`npm install --save-dev @lakutata/builder`; the templates that pack their application already have it).
12
12
 
13
+ A mobile application of the `mobile-react` template is shipped another way: `lakutata mobile stage` bundles its
14
+ application for the Node.js the mobile application embeds, and its native projects make the release builds for the
15
+ stores (see the section The packaging of the README the template gives the project).
16
+
13
17
  ## 1. What is packed
14
18
 
15
19
  - **The compiled application**: the output of `tsc` (which emits the metadata of the decorators), not the TypeScript
@@ -49,6 +53,7 @@ directory, once moved with them.
49
53
  | `--outfile <file>` | The bundle, `dist/<name>.cjs` by default |
50
54
  | `--no-minify` | Do not minify the bundle (the names of the classes are kept either way) |
51
55
  | `--external <modules...>` | Modules left out of the bundle, loaded at run time from a `node_modules` next to it |
56
+ | `--node <version>` | The version of Node.js running the bundle (`18.10` for NW.js 0.70): the bundle is written in the syntax that version reads; the one running the tool by default |
52
57
 
53
58
  ## 3. Native addons
54
59
 
@@ -124,11 +129,12 @@ architecture for Linux (`docker run --platform linux/arm64`); the README of the
124
129
 
125
130
  | Option | Meaning |
126
131
  |---|---|
127
- | `--runtime node` (default) | The bundle is embedded in a copy of the Node.js running the tool (a single executable application of Node.js): about 110 MB on macOS arm64 |
132
+ | `--runtime node` (default) | The bundle is embedded in a copy of the Node.js running the tool, or of `--node-program` (a single executable application of Node.js): about 110 MB on macOS arm64 |
128
133
  | `--runtime bun` | The bundle is compiled by Bun (the `bun` package of the project, else the `bun` of the system): about 70 MB on macOS arm64, and it starts faster; the runtime is then Bun |
129
134
  | `--layout file` (default) | One file: the native addons, the files read by path and the resources are embedded, and extracted when it starts |
130
135
  | `--layout directory` | `dist/<name>/` holds the executable, `native/` and `resources/`, loaded from there without extraction (the installers use it) |
131
136
  | `--outdir <directory>` | Where the executable is written, `dist` by default |
137
+ | `--node-program <path>` | The node embedded instead of the one running the tool: a Node.js 20.12, 21.7 or later (`$(nvm which 22)`), so that an older Node.js can run the tool; the bundle follows its syntax |
132
138
  | `--entry`, `--no-minify`, `--external` | As for a bundle |
133
139
 
134
140
  - **Extraction**: an executable of the file layout extracts what it embeds at its first run, into its cache directory,
@@ -171,6 +177,7 @@ of the project (it may be outside the package, such as `../ui/dist`), `to` its p
171
177
  | An executable, file layout | `true` | The directory the resources were extracted to |
172
178
  | An executable, directory layout, or an installed application | `true` | `resources` next to the executable |
173
179
  | A packaged Electron application | `true` | `main.resources` in the resources of Electron |
180
+ | An NW.js application (run by `lakutata nwjs run`, or packaged) | `true` | `resources` in the directory of the application |
174
181
 
175
182
  `resourcesPath()` returns the path even when the application declares no resources, so the directory may not exist.
176
183
  The application chooses where to read its files from:
@@ -53,8 +53,8 @@ templates other than `cli` do.
53
53
  ## 2. The workspace templates
54
54
 
55
55
  The other templates are npm workspaces: the application is the package `packages/app`, and the templates with an
56
- interface or with installers add `packages/ui` (the web pages, or the renderer of Electron) and `packages/resources`
57
- (the icon). The `service` template:
56
+ interface or with installers add `packages/ui` (the web pages, the renderer of Electron, or the user interface of
57
+ NW.js) and `packages/resources` (the icon). The `service` template:
58
58
 
59
59
  ```
60
60
  shop/
@@ -93,6 +93,20 @@ The other templates add to this layout:
93
93
  it into `dist/` ([Packaging](Packaging.md)).
94
94
  - `electron-react` and `electron-vue`: the main process of Electron in `packages/app` (its window and its service
95
95
  actions over IPC), the renderer in `packages/ui`, and the scripts that make the installers.
96
+ - `nwjs-react` and `nwjs-vue`: the background script of NW.js in `packages/app` (its window, whose host page in
97
+ `packages/app/host` holds the user interface in a webview, and its service actions), the user interface in
98
+ `packages/ui`, the version of NW.js in `packages/app/nwjs.json` (written by `npm run nwjs:use -- <version>`), and the
99
+ scripts that make the installers.
100
+ - `mobile-react`: the application in `packages/app`, which runs in a Node.js embedded in the mobile application and
101
+ serves its actions to the user interface of React Native; the user interface in `packages/ui` (`src/App.tsx`), the
102
+ same on the three systems; `packages/ipc`, which connects the user interface to the Node.js side: the native module
103
+ embedding Node.js (`native`) and the `ipc` the user interface imports (Electron and NW.js have such a channel of their
104
+ own, React Native has none, so the template brings it as a package); at the root, the application of React Native
105
+ itself: its entry (`index.js`, which registers the component of `packages/ui`), `app.json`, the configurations of
106
+ Metro and Babel, and the native projects (`android`, `ios`, `harmony`), which carry the id of the application
107
+ (`lakutata create --bundle-id`); and the scripts that download the libnode, run the application on an emulator, a
108
+ device or a simulator, and deploy its Node.js side (`npm run node:android`, `npm run android`, `npm run
109
+ deploy:android`, and the same for `ios` and `harmony`).
96
110
 
97
111
  The packed forms are written to `dist/` at the root of the workspace; `.gitignore` leaves out `build`, `dist` and the
98
112
  outputs of the interfaces.
@@ -105,8 +119,9 @@ outputs of the interfaces.
105
119
  |---|---|---|
106
120
  | `i18n` | all | The messages of the languages in `src/locales` (`en`, `zh-CN`), the `i18n` component, the language middleware, and the scripts `i18n:check` and `i18n:types` ([I18n](I18n.md)) |
107
121
  | `installer` | `cli`, `service`, `web-*` | The `lakutata.installer` of the application, the scripts that make the installers (on the machine, and for Linux in Docker), and for the services a system service ([Installers](Installers.md)) |
122
+ | `win7` | `nwjs-*` | NW.js 0.72.0 instead of the release the template was published with: the last release running on Windows 7, 8 and 8.1, and the script `package:ia32` that makes the installers of 32-bit Windows |
108
123
 
109
- The Electron templates make installers without this feature.
124
+ The Electron and NW.js templates make installers without the `installer` feature.
110
125
 
111
126
  ## 4. Templates of your own
112
127