lakutata 3.1.5 → 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.
- package/README.md +6 -6
- package/README.zh-CN.md +3 -3
- package/dist/cjs/exports/ReactNativeAdapter.d.ts +1 -0
- package/dist/cjs/exports/ReactNativeAdapter.js +20 -0
- package/dist/esm/exports/ReactNativeAdapter.js +1 -0
- package/dist/types/exports/ReactNativeAdapter.d.ts +1 -0
- package/doc/en/Application.md +5 -0
- package/doc/en/Barcode.md +386 -0
- package/doc/en/Command.md +11 -1
- package/doc/en/Database.md +4 -0
- package/doc/en/DatabaseDrivers.md +72 -2
- package/doc/en/Entrypoint.md +1 -0
- package/doc/en/GettingStarted.md +1 -0
- package/doc/en/I18n.md +1 -1
- package/doc/en/Migrations.md +2 -2
- package/doc/en/NativeAddons.md +3 -0
- package/doc/en/Overview.md +10 -7
- package/doc/en/Packaging.md +4 -0
- package/doc/en/ProjectStructure.md +10 -0
- package/doc/en/ServiceCalls.md +41 -5
- package/doc/en/examples/MobileApp.md +730 -0
- package/doc/en/examples/README.md +2 -0
- package/doc/en/examples/TrayApp.md +1061 -0
- package/doc/zh/Application.md +2 -0
- package/doc/zh/Barcode.md +313 -0
- package/doc/zh/Command.md +6 -1
- package/doc/zh/Database.md +2 -0
- package/doc/zh/DatabaseDrivers.md +51 -1
- package/doc/zh/Entrypoint.md +1 -0
- package/doc/zh/GettingStarted.md +1 -0
- package/doc/zh/I18n.md +1 -1
- package/doc/zh/Migrations.md +1 -1
- package/doc/zh/NativeAddons.md +1 -0
- package/doc/zh/Overview.md +4 -3
- package/doc/zh/Packaging.md +2 -0
- package/doc/zh/ProjectStructure.md +1 -0
- package/doc/zh/ServiceCalls.md +28 -2
- package/doc/zh/examples/MobileApp.md +671 -0
- package/doc/zh/examples/README.md +2 -0
- package/doc/zh/examples/TrayApp.md +980 -0
- package/package.json +15 -5
package/doc/en/Entrypoint.md
CHANGED
|
@@ -61,6 +61,7 @@ The adapters:
|
|
|
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
63
|
| `service` | `nwjsServiceEntrypoint()` | `lakutata/adapter/nwjs` | (NW.js) | [ServiceCalls](ServiceCalls.md) |
|
|
64
|
+
| `service` | `reactNativeServiceEntrypoint()` | `lakutata/adapter/react-native` | | [ServiceCalls](ServiceCalls.md) |
|
|
64
65
|
| `service` | `grpcServiceEntrypoint()` | `@lakutata/grpc/service` | `@lakutata/grpc` | [GRPC](GRPC.md) |
|
|
65
66
|
| `service` | `natsServiceEntrypoint()` | `@lakutata/nats` | `@lakutata/nats` | [NATS](NATS.md) |
|
|
66
67
|
| `schedule` | `scheduleEntrypoint()` | `lakutata/com/entrypoint` | | [Schedules](Schedules.md) |
|
package/doc/en/GettingStarted.md
CHANGED
|
@@ -48,6 +48,7 @@ The `default` template is a small HTTP application. Other templates start from a
|
|
|
48
48
|
| `web-next`, `web-nuxt` | An HTTP API serving a Next.js or Nuxt application from the same process |
|
|
49
49
|
| `electron-react`, `electron-vue` | A desktop application: Electron, its main process serving a React or Vue renderer over IPC |
|
|
50
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 |
|
|
51
52
|
|
|
52
53
|
```bash
|
|
53
54
|
npx @lakutata/cli create --name shop --template service --with i18n,installer
|
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, NW.js, 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.
|
package/doc/en/Migrations.md
CHANGED
|
@@ -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
|
|
147
|
-
|
|
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
|
|
package/doc/en/NativeAddons.md
CHANGED
|
@@ -221,5 +221,8 @@ The application depends on the addon package, and imports it as any package (`im
|
|
|
221
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
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
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`).
|
|
224
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.
|
|
225
228
|
- **Alpine (musl)**: the executables of Node.js do not load native addons there: make them with Bun.
|
package/doc/en/Overview.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
(Electron, NW.js) applications and embedded devices one programming model: an application is a tree of objects
|
|
5
5
|
(components, providers, controllers) that a container creates. DTOs validate their options and inputs, and transports
|
|
6
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), schedules and message queues. One controller method can serve all of them at
|
|
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`, `lakutata/adapter/nwjs` | 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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
whatever its addresses, the interfaces of
|
|
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
|
|
|
@@ -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 |
|
package/doc/en/Packaging.md
CHANGED
|
@@ -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
|
|
@@ -97,6 +97,16 @@ The other templates add to this layout:
|
|
|
97
97
|
`packages/app/host` holds the user interface in a webview, and its service actions), the user interface in
|
|
98
98
|
`packages/ui`, the version of NW.js in `packages/app/nwjs.json` (written by `npm run nwjs:use -- <version>`), and the
|
|
99
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`).
|
|
100
110
|
|
|
101
111
|
The packed forms are written to `dist/` at the root of the workspace; `.gitignore` leaves out `build`, `dist` and the
|
|
102
112
|
outputs of the interfaces.
|
package/doc/en/ServiceCalls.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A service action (`@ServiceAction`) is called with a message rather than a URL: an object whose keys select the action,
|
|
4
4
|
its **pattern**, and whose other keys are the input. The same actions can be served over several transports at once:
|
|
5
|
-
plain HTTP, Socket.IO, JSON-RPC 2.0 (over HTTP, WebSocket or the standard input and output), the IPC of Electron
|
|
6
|
-
windows of NW.js
|
|
7
|
-
|
|
8
|
-
[Entrypoint](Entrypoint.md).
|
|
5
|
+
plain HTTP, Socket.IO, JSON-RPC 2.0 (over HTTP, WebSocket or the standard input and output), the IPC of Electron, the
|
|
6
|
+
windows of NW.js and the user interface of a mobile application of React Native, as this guide describes, and gRPC, NATS
|
|
7
|
+
and the data channels of WebRTC, which have their own guides. The controllers and their actions are described in
|
|
8
|
+
[Controllers](Controllers.md), the entrypoint and its adapters in [Entrypoint](Entrypoint.md).
|
|
9
9
|
|
|
10
10
|
## 1. A first service
|
|
11
11
|
|
|
@@ -136,7 +136,8 @@ class OrderController extends Controller {
|
|
|
136
136
|
|
|
137
137
|
## 3. The response
|
|
138
138
|
|
|
139
|
-
The HTTP service, Socket.IO, Electron
|
|
139
|
+
The HTTP service, Socket.IO, Electron, NW.js and React Native answer with an envelope; JSON-RPC answers with its own
|
|
140
|
+
responses (section 4).
|
|
140
141
|
|
|
141
142
|
```text
|
|
142
143
|
{"success": true, "error": null, "payload": <the result>}
|
|
@@ -180,6 +181,7 @@ export async function call<T>(message: Record<string, unknown>): Promise<T> {
|
|
|
180
181
|
| `jsonRPCServiceEntrypoint()` | `lakutata/adapter/jsonrpc` | `ws`, for WebSocket | A JSON-RPC 2.0 request | Notifications (WebSocket, stdio) |
|
|
181
182
|
| `electronIPCServiceEntrypoint()` | `lakutata/adapter/electron` | (Electron) | `ipcRenderer.invoke()` | IPC messages |
|
|
182
183
|
| `nwjsServiceEntrypoint()` | `lakutata/adapter/nwjs` | (NW.js) | A call of its bridge, by the host page of a window | Calls of the function the host page gives |
|
|
184
|
+
| `reactNativeServiceEntrypoint()` | `lakutata/adapter/react-native` | | A line of JSON from the host | Lines of JSON |
|
|
183
185
|
| `grpcServiceEntrypoint()` | `@lakutata/grpc/service` | `@lakutata/grpc` | See [GRPC](GRPC.md) | gRPC streams |
|
|
184
186
|
| `natsServiceEntrypoint()` | `@lakutata/nats` | `@lakutata/nats` | See [NATS](NATS.md) | NATS messages |
|
|
185
187
|
| `webrtcServiceEntrypoint()` | `@lakutata/webrtc` | `@lakutata/webrtc` | A JSON-RPC 2.0 request on a data channel, see [WebRTC](WebRTC.md) | Notifications |
|
|
@@ -510,6 +512,38 @@ window.addEventListener('message', async (event) => {
|
|
|
510
512
|
- The NW.js templates of `lakutata create` contain such a host page (`packages/app/host`), and a `window.ipc` for the
|
|
511
513
|
interface like the one of the Electron templates.
|
|
512
514
|
|
|
515
|
+
### React Native
|
|
516
|
+
|
|
517
|
+
`reactNativeServiceEntrypoint()` serves the actions to the user interface of a mobile application of React Native
|
|
518
|
+
(Android, iOS, HarmonyOS), in the Node.js that the application embeds. The native module of the application starts
|
|
519
|
+
Node.js and gives it one end of a socket, whose file descriptor is in the environment variable `LAKUTATA_NODE_FD`. The
|
|
520
|
+
adapter reads the messages of the host on that socket and writes its responses and events there, one JSON object per
|
|
521
|
+
line. The values arrive as JSON carries them: a `Date` arrives as its string, a `Buffer` as `{type, data}`, `undefined`
|
|
522
|
+
is left out, and a result that JSON cannot hold (a `bigint`, a cycle) is answered with an error.
|
|
523
|
+
|
|
524
|
+
| Option | Default | Meaning |
|
|
525
|
+
|---|---|---|
|
|
526
|
+
| `socket` | a socket on the file descriptor in `LAKUTATA_NODE_FD` | The connection to the host, or a stand-in in the tests |
|
|
527
|
+
| `pause` | | Called when the application goes to the background, before the host is told that the application is ready for it |
|
|
528
|
+
| `resume` | | Called when the application comes back from the background |
|
|
529
|
+
|
|
530
|
+
| The host writes | The adapter answers |
|
|
531
|
+
|---|---|
|
|
532
|
+
| `{"type":"invoke","id":1,"clientId":"ui","data":{"cmd":"greet","name":"you"}}` | `{"type":"response","id":1,"response":{"success":true,"error":null,"payload":…}}` |
|
|
533
|
+
| `{"type":"subscribe","clientId":"ui"}` | `{"type":"subscribed","clientId":"ui"}`, then the events pushed to the client |
|
|
534
|
+
| `{"type":"unsubscribe","clientId":"ui"}` | Nothing; the requests of the client in progress are aborted |
|
|
535
|
+
| `{"type":"pause"}` | `{"type":"paused"}`, once the `pause` option has run |
|
|
536
|
+
| `{"type":"resume"}` | Nothing; the `resume` option runs |
|
|
537
|
+
|
|
538
|
+
- The lines that the host writes before the application listens wait in the socket: none is lost. The answer to the
|
|
539
|
+
subscription tells the interface that the application is ready.
|
|
540
|
+
- On iOS, the host asks the system for time to finish before the application is suspended, sends `pause`, and lets the
|
|
541
|
+
application be suspended once `paused` comes (or when the time runs out).
|
|
542
|
+
- When Node.js ends (`process.exit()`, an uncaught exception), the mobile application keeps running: the native module
|
|
543
|
+
reports the exit code and can start Node.js again.
|
|
544
|
+
- The `mobile-react` template of `lakutata create` contains such a native module, and an `ipc` for the interface like
|
|
545
|
+
the one of the Electron templates, both in its package `packages/ipc`.
|
|
546
|
+
|
|
513
547
|
## 5. Clients and events
|
|
514
548
|
|
|
515
549
|
The transports that keep their clients connected can push events to them. A client is identified by the id it gives:
|
|
@@ -523,6 +557,7 @@ The transports that keep their clients connected can push events to them. A clie
|
|
|
523
557
|
| JSON-RPC over stdio | `'stdio'` |
|
|
524
558
|
| Electron | The id the page gives when it subscribes or invokes |
|
|
525
559
|
| NW.js | The id the host page gives to the bridge for its page |
|
|
560
|
+
| React Native | The id the user interface gives when it subscribes or invokes |
|
|
526
561
|
| WebRTC | The member id of the caller in its room |
|
|
527
562
|
|
|
528
563
|
An action reads the id of its client in `this.context.clientId`. The `entrypoint` component pushes the events:
|
|
@@ -559,6 +594,7 @@ A client receives `notify(clientId, 'progress', 50, 'half')` as:
|
|
|
559
594
|
| JSON-RPC (WebSocket, stdio) | `{"jsonrpc": "2.0", "method": "progress", "params": [50, "half"]}` |
|
|
560
595
|
| Electron | `('progress', [50, 'half'])`, through the `subscribe` of the preload script above |
|
|
561
596
|
| NW.js | `('progress', [50, 'half'])`, given to the function of the `subscribe` of the bridge |
|
|
597
|
+
| React Native | The line `{"type":"event","clientId":…,"event":"progress","args":[50,"half"]}`, which the host passes to the interface |
|
|
562
598
|
| WebRTC | `proxy.on('progress', (percent, label) => …)` of a `PeerServiceProxy` |
|
|
563
599
|
|
|
564
600
|
## 6. Stopping and leaving
|