lakutata 3.0.0 → 3.1.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 (121) hide show
  1. package/README.md +50 -30
  2. package/README.zh-CN.md +130 -0
  3. package/dist/cjs/exports/QueueComponent.d.ts +1 -0
  4. package/dist/cjs/exports/QueueComponent.js +20 -0
  5. package/dist/esm/exports/QueueComponent.js +1 -0
  6. package/dist/types/exports/QueueComponent.d.ts +1 -0
  7. package/doc/en/Application.md +107 -0
  8. package/doc/en/CLI.md +274 -0
  9. package/doc/en/Cache.md +379 -0
  10. package/doc/en/Command.md +110 -0
  11. package/doc/en/ContainerdIntegration.md +17 -16
  12. package/doc/en/Controllers.md +256 -0
  13. package/doc/en/DBus.md +291 -0
  14. package/doc/en/DTOValidation.md +72 -43
  15. package/doc/en/Database.md +188 -0
  16. package/doc/en/DatabaseDrivers.md +287 -0
  17. package/doc/en/Decorator.md +52 -40
  18. package/doc/en/DockerIntegration.md +7 -6
  19. package/doc/en/Entities.md +240 -0
  20. package/doc/en/Entrypoint.md +216 -0
  21. package/doc/en/Exceptions.md +174 -0
  22. package/doc/en/GRPC.md +251 -0
  23. package/doc/en/GettingStarted.md +165 -0
  24. package/doc/en/HTTP.md +511 -0
  25. package/doc/en/HelperFunctions.md +11 -11
  26. package/doc/en/I18n.md +119 -115
  27. package/doc/en/Injection.md +144 -0
  28. package/doc/en/Installers.md +280 -0
  29. package/doc/en/Logger.md +206 -0
  30. package/doc/en/MCP.md +293 -0
  31. package/doc/en/Middlewares.md +213 -0
  32. package/doc/en/Migrations.md +202 -0
  33. package/doc/en/MongoEmbedded.md +149 -0
  34. package/doc/en/Monitor.md +164 -0
  35. package/doc/en/Mutex.md +27 -25
  36. package/doc/en/NATS.md +246 -0
  37. package/doc/en/NativeAddons.md +212 -0
  38. package/doc/en/Objects.md +143 -0
  39. package/doc/en/Overview.md +63 -85
  40. package/doc/en/Packaging.md +193 -0
  41. package/doc/en/ProjectStructure.md +124 -0
  42. package/doc/en/Queue.md +269 -0
  43. package/doc/en/Schedules.md +217 -0
  44. package/doc/en/Security.md +10 -9
  45. package/doc/en/ServiceCalls.md +508 -0
  46. package/doc/en/Time.md +19 -20
  47. package/doc/en/UpgradingFrom1.md +435 -0
  48. package/doc/en/UpgradingFrom2.md +315 -0
  49. package/doc/en/WebRTC.md +1364 -0
  50. package/doc/en/Workspaces.md +189 -0
  51. package/doc/en/examples/BackgroundJobs.md +677 -0
  52. package/doc/en/examples/CommandLineTool.md +664 -0
  53. package/doc/en/examples/DesktopApp.md +809 -0
  54. package/doc/en/examples/DeviceService.md +607 -0
  55. package/doc/en/examples/MCPServer.md +653 -0
  56. package/doc/en/examples/Meeting.md +573 -0
  57. package/doc/en/examples/README.md +17 -0
  58. package/doc/en/examples/RestAPI.md +490 -0
  59. package/doc/en/examples/ServiceCalls.md +829 -0
  60. package/doc/en/examples/WebApp.md +568 -0
  61. package/doc/zh/Application.md +75 -0
  62. package/doc/zh/CLI.md +250 -0
  63. package/doc/zh/Cache.md +328 -0
  64. package/doc/zh/Command.md +78 -0
  65. package/doc/zh/ContainerdIntegration.md +9 -9
  66. package/doc/zh/Controllers.md +228 -0
  67. package/doc/zh/DBus.md +257 -0
  68. package/doc/zh/DTOValidation.md +49 -19
  69. package/doc/zh/Database.md +175 -0
  70. package/doc/zh/DatabaseDrivers.md +261 -0
  71. package/doc/zh/Decorator.md +25 -18
  72. package/doc/zh/DockerIntegration.md +6 -6
  73. package/doc/zh/Entities.md +224 -0
  74. package/doc/zh/Entrypoint.md +193 -0
  75. package/doc/zh/Exceptions.md +158 -0
  76. package/doc/zh/GRPC.md +226 -0
  77. package/doc/zh/GettingStarted.md +148 -0
  78. package/doc/zh/HTTP.md +446 -0
  79. package/doc/zh/HelperFunctions.md +2 -2
  80. package/doc/zh/I18n.md +26 -26
  81. package/doc/zh/Injection.md +129 -0
  82. package/doc/zh/Installers.md +232 -0
  83. package/doc/zh/Logger.md +188 -0
  84. package/doc/zh/MCP.md +265 -0
  85. package/doc/zh/Middlewares.md +198 -0
  86. package/doc/zh/Migrations.md +178 -0
  87. package/doc/zh/MongoEmbedded.md +118 -0
  88. package/doc/zh/Monitor.md +145 -0
  89. package/doc/zh/Mutex.md +10 -10
  90. package/doc/zh/NATS.md +207 -0
  91. package/doc/zh/NativeAddons.md +180 -0
  92. package/doc/zh/Objects.md +119 -0
  93. package/doc/zh/Overview.md +47 -71
  94. package/doc/zh/Packaging.md +154 -0
  95. package/doc/zh/ProjectStructure.md +102 -0
  96. package/doc/zh/Queue.md +214 -0
  97. package/doc/zh/Schedules.md +193 -0
  98. package/doc/zh/Security.md +6 -6
  99. package/doc/zh/ServiceCalls.md +462 -0
  100. package/doc/zh/Time.md +2 -2
  101. package/doc/zh/UpgradingFrom1.md +347 -0
  102. package/doc/zh/UpgradingFrom2.md +230 -0
  103. package/doc/zh/WebRTC.md +1049 -0
  104. package/doc/zh/Workspaces.md +150 -0
  105. package/doc/zh/examples/BackgroundJobs.md +618 -0
  106. package/doc/zh/examples/CommandLineTool.md +618 -0
  107. package/doc/zh/examples/DesktopApp.md +748 -0
  108. package/doc/zh/examples/DeviceService.md +546 -0
  109. package/doc/zh/examples/MCPServer.md +604 -0
  110. package/doc/zh/examples/Meeting.md +524 -0
  111. package/doc/zh/examples/README.md +15 -0
  112. package/doc/zh/examples/RestAPI.md +458 -0
  113. package/doc/zh/examples/ServiceCalls.md +765 -0
  114. package/doc/zh/examples/WebApp.md +520 -0
  115. package/package.json +46 -17
  116. package/doc/en/ActionPattern.md +0 -408
  117. package/doc/en/Core.md +0 -312
  118. package/doc/en/ORMIntegration.md +0 -341
  119. package/doc/zh/ActionPattern.md +0 -334
  120. package/doc/zh/Core.md +0 -256
  121. package/doc/zh/ORMIntegration.md +0 -319
@@ -0,0 +1,189 @@
1
+ # Lakutata Workspaces
2
+
3
+ A project made of several packages (an application, its web interface, shared libraries, native addons) is a
4
+ workspace: one repository whose root `package.json` lists the directories of its packages. The package manager (npm,
5
+ pnpm or yarn) links the packages to each other; the `lakutata` command runs their scripts in the order of their
6
+ dependencies, gives them one version, and adds new packages. It covers the part of lerna that these projects use.
7
+ Every template but `default` makes a workspace ([ProjectStructure](ProjectStructure.md), section 2).
8
+
9
+ ## 1. A workspace
10
+
11
+ The root `package.json` of a project made by `lakutata create --name shop --template web-react` (its migration and
12
+ Docker scripts left out):
13
+
14
+ ```json
15
+ {
16
+ "name": "shop-workspace",
17
+ "version": "0.0.1",
18
+ "private": true,
19
+ "workspaces": ["packages/*"],
20
+ "scripts": {
21
+ "build": "lakutata run rebuild",
22
+ "test": "npm run build && lakutata run test",
23
+ "dev": "lakutata run dev --parallel",
24
+ "start": "npm start -w app",
25
+ "version:patch": "lakutata version patch --yes"
26
+ },
27
+ "devDependencies": {
28
+ "@lakutata/cli": "^3.0.0",
29
+ "@types/node": "^22.0.0",
30
+ "typescript": "^6.0.3"
31
+ }
32
+ }
33
+ ```
34
+
35
+ - **The packages** are the directories that the patterns of `workspaces` match and that hold a `package.json` with a
36
+ `name`: `*` matches within one directory name, `**` any number of directories, and `!packages/old` leaves a directory
37
+ out. `node_modules` and the directories starting with a dot are never searched. A pnpm workspace lists its patterns in
38
+ `pnpm-workspace.yaml` instead, as a list under `packages:` (`- 'packages/*'` lines, or `['packages/*']`).
39
+ - **The commands work from any directory** of the workspace: they use the nearest parent directory that declares a
40
+ workspace.
41
+ - **The dependencies between packages** are the ones in `dependencies`, `devDependencies`, `peerDependencies` or
42
+ `optionalDependencies`, whatever their range (`^0.0.1`, `*`, `workspace:*`, `file:`).
43
+ - **The build tools** (`@lakutata/cli`, `typescript`, `@types/node`) are development dependencies of the root, so every
44
+ package can use them in its scripts.
45
+
46
+ `lakutata list` shows the packages, their versions, their directories and the packages each one depends on. Here,
47
+ `app` (the server) depends on `ui` (the web interface), whose built pages it serves:
48
+
49
+ ```
50
+ 2 packages, version 0.0.1
51
+ app 0.0.1 (private) packages/app → ui
52
+ ui 0.0.1 (private) packages/ui
53
+ ```
54
+
55
+ ## 2. Running scripts
56
+
57
+ `lakutata run <script>` runs an npm script in every package that has it. A package starts once the packages it depends
58
+ on (directly or not) have finished, and packages that do not depend on each other run at the same time. Each line of
59
+ output starts with the name of its package:
60
+
61
+ ```
62
+ lib │ start lib
63
+ tools │ start tools
64
+ tools │ end tools
65
+ lib │ end lib
66
+ app │ start app
67
+ app │ end app
68
+ ✔ build ran in tools, lib, app
69
+ ```
70
+
71
+ | Option | Meaning |
72
+ |---|---|
73
+ | `--parallel` | Start all the packages at once, without waiting for their dependencies: for scripts that keep running, such as dev servers and watchers (`lakutata run dev --parallel`) |
74
+ | `--scope <names...>` | Only these packages; `*` matches any characters (`--scope 'app' '@shop/*'`). The packages they depend on are neither run nor waited for, and a scope matching no package is an error |
75
+ | `--concurrency <n>` | How many packages run at a time (the number of processors by default) |
76
+ | `--no-bail` | Go on after a failure: the packages that depend on the failed one are skipped, the others still run |
77
+
78
+ - **Failures**: by default, no package starts after a failure, and those already running finish. The command ends with
79
+ `error: build failed in lib, not run in app` and the exit code 1.
80
+ - **No package has the script**: the command prints `No package has the script lint` and succeeds.
81
+ - **The package manager**: the scripts run with `npm run`, `pnpm run` or `yarn run`, chosen from the `packageManager`
82
+ field of the root `package.json` (`"pnpm@9.15.0"`), else from the files at the root (`pnpm-lock.yaml` or
83
+ `pnpm-workspace.yaml`, `yarn.lock`, `package-lock.json`); npm by default.
84
+ - **Arguments**: the scripts take no extra arguments (`lakutata run build -- --watch` is refused): add a script
85
+ instead.
86
+
87
+ ## 3. Giving the packages a version
88
+
89
+ All the packages of a workspace share one version. `lakutata version <bump>` gives it to all of them, and updates the
90
+ dependencies between them. From version 1.2.3:
91
+
92
+ ```bash
93
+ lakutata version patch # 1.2.4, after a confirmation in a terminal
94
+ lakutata version minor --git --yes # 1.3.0, committed and tagged v1.3.0
95
+ lakutata version preminor --preid beta # 1.3.0-beta.0, then prerelease gives 1.3.0-beta.1
96
+ lakutata version 2.0.0
97
+ ```
98
+
99
+ The output, in a workspace at 0.0.16:
100
+
101
+ ```
102
+ Version 0.0.16 → 0.0.17
103
+ app 0.0.16 → 0.0.17
104
+ lib 0.0.16 → 0.0.17
105
+ tools 0.0.16 → 0.0.17
106
+ ✔ Version 0.0.17 given (packages/app/package.json, packages/lib/package.json, packages/tools/package.json, package.json)
107
+ ```
108
+
109
+ - **The current version** is the `version` of `lerna.json` when that file gives one, else the one of the root
110
+ `package.json`, else the highest version among the packages, a prerelease included (`0.0.0` when there is none). The
111
+ new version is written back there, and into every package, the private ones included.
112
+ - **The bumps** are `major`, `minor`, `patch`, `premajor`, `preminor`, `prepatch`, `prerelease`, or an explicit version.
113
+ `--preid <id>` names the prerelease of the `pre…` bumps (`beta` gives `1.3.0-beta.0`; without it, `1.3.0-0`).
114
+ - **The dependencies between the packages** follow: `^0.0.16` becomes `^0.0.17`, and so do `~`, `>=`, `=` and
115
+ `workspace:^` ranges. `*`, `workspace:*` and `file:` dependencies are left as they are. With `0.x` versions this
116
+ matters, because `^0.0.16` does not accept `0.0.17`.
117
+ - **The lock file** follows too: `package-lock.json` or `pnpm-lock.yaml` is updated, so that `npm ci` (or
118
+ `pnpm install --frozen-lockfile`) still accepts it. A `yarn.lock` is not: the command reminds you to run
119
+ `yarn install`.
120
+ - **`--git`** commits the changed files, and only them, with the message `v1.3.0` and tags the commit `v1.3.0`. Nothing
121
+ is pushed. The repository and the tag are checked before a file is changed.
122
+ - **The confirmation** is asked only in a terminal: in CI, or when the output is piped, the version is given at once.
123
+ `--yes` skips it in a terminal too.
124
+
125
+ ## 4. Adding a package
126
+
127
+ `lakutata add <name>` creates a TypeScript package in the workspace; `--to <package>` adds it to the dependencies of
128
+ another package. In the `web-react` project of section 1, a package of code shared by the server and the web interface:
129
+
130
+ ```bash
131
+ lakutata add @shop/shared --to app
132
+ ```
133
+
134
+ ```
135
+ ✔ Package @shop/shared 0.0.1 added: packages/shared (package.json, tsconfig.json, src/index.ts, src/tests/index.spec.ts, README.md), a dependency of app
136
+ Next: npm install (links the package), then npm run rebuild -w @shop/shared
137
+ ```
138
+
139
+ `--to` names one package: add the dependency to `ui` by hand, in `packages/ui/package.json`:
140
+
141
+ ```json
142
+ {
143
+ "dependencies": {
144
+ "@shop/shared": "^0.0.1"
145
+ }
146
+ }
147
+ ```
148
+
149
+ Then `npm install` links the new package, and `lakutata list` shows it:
150
+
151
+ ```
152
+ 3 packages, version 0.0.1
153
+ app 0.0.1 (private) packages/app → ui, @shop/shared
154
+ @shop/shared 0.0.1 (private) packages/shared
155
+ ui 0.0.1 (private) packages/ui → @shop/shared
156
+ ```
157
+
158
+ `npm run build` (`lakutata run rebuild`) now builds `@shop/shared` first, then `ui`, then `app`, and both import it as
159
+ any package: `import {greet} from '@shop/shared'`.
160
+
161
+ - **Where**: in the directory of the packages of the workspace, without the scope of the name: the directory of the
162
+ first pattern such as `apps/*` (`packages/*` when there is one). A workspace whose patterns have no such directory
163
+ (only packages named one by one, or `packages/**`) is refused.
164
+ - **Its version** is the version of the workspace (`0.0.1` without one, or with the independent versions of lerna), and
165
+ `--to` adds the dependency `"@shop/shared": "^0.0.1"`.
166
+ - **Its files**: `src/index.ts` (an example function to replace), a test run by `node --test`, and a `package.json`
167
+ whose scripts are `clean`, `build` (`tsc`), `rebuild` and `test`. It compiles `src` into `build`, with its type
168
+ declarations, which its `exports` give to the other packages. Code that the web interface also uses must not use the
169
+ modules of Node.js.
170
+ - **Private**: the package is `"private": true`. Remove that line to publish it (`npm publish -w @shop/shared`).
171
+ - **Nothing is installed**: run the install of the package manager of the workspace afterwards, as the command says
172
+ (`pnpm install`, `yarn install`), so that the other packages see the new one.
173
+
174
+ `lakutata add <name> --native gyp|cmake|rust` creates a native addon instead: see [NativeAddons](NativeAddons.md).
175
+
176
+ ## 5. Coming from lerna
177
+
178
+ | lerna | lakutata |
179
+ |---|---|
180
+ | `lerna run rebuild` | `lakutata run rebuild` |
181
+ | `lerna run dev --parallel` | `lakutata run dev --parallel` |
182
+ | `lerna version patch --no-git-tag-version --no-push -y` | `lakutata version patch --yes` |
183
+ | `lerna version patch` | `lakutata version patch --git` (the tag is not pushed) |
184
+
185
+ - A workspace can keep its `lerna.json`: lakutata reads and writes its `version` only. The packages come from the
186
+ `workspaces` of the root `package.json` (or `pnpm-workspace.yaml`), not from the `packages` of `lerna.json`.
187
+ - lakutata gives all the packages one version: a `lerna.json` with `"version": "independent"` cannot be bumped.
188
+ - It does not write changelogs, cache builds, select the packages changed since a release, or publish: publish with
189
+ `npm publish -w <package>`. Workspaces that need these keep lerna (or nx, turborepo) alongside it.