@codenotch/codenotch.cli 1.0.41 → 1.0.43

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 (54) hide show
  1. package/README.md +78 -28
  2. package/dist/commands/generate/dbcontext.js +2 -2
  3. package/dist/commands/generate/dbcontext.js.map +1 -1
  4. package/dist/commands/generate/index.js +1 -1
  5. package/dist/commands/project/compile.js +7 -4
  6. package/dist/commands/project/compile.js.map +1 -1
  7. package/dist/commands/project/deploy.js +53 -5
  8. package/dist/commands/project/deploy.js.map +1 -1
  9. package/dist/commands/project/inspect.js +65 -1
  10. package/dist/commands/project/inspect.js.map +1 -1
  11. package/dist/commands/project/package.js +2 -2
  12. package/dist/commands/project/package.js.map +1 -1
  13. package/dist/commands/system/docs.d.ts +2 -0
  14. package/dist/commands/system/docs.js +57 -0
  15. package/dist/commands/system/docs.js.map +1 -0
  16. package/dist/commands/system/index.js +2 -0
  17. package/dist/commands/system/index.js.map +1 -1
  18. package/dist/commands/system/read.js +2 -1
  19. package/dist/commands/system/read.js.map +1 -1
  20. package/dist/commands/validation/files/ScriptValidator.js +9 -8
  21. package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
  22. package/dist/index.js +12 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/utils/DbSchemaUtils.d.ts +16 -10
  25. package/dist/utils/DbSchemaUtils.js +82 -30
  26. package/dist/utils/DbSchemaUtils.js.map +1 -1
  27. package/dist/utils/DocsUtils.d.ts +34 -0
  28. package/dist/utils/DocsUtils.js +76 -0
  29. package/dist/utils/DocsUtils.js.map +1 -0
  30. package/dist/utils/ProcessBundlerUtils.d.ts +103 -0
  31. package/dist/utils/ProcessBundlerUtils.js +336 -0
  32. package/dist/utils/ProcessBundlerUtils.js.map +1 -0
  33. package/dist/utils/ProjectCompilationUtils.d.ts +17 -6
  34. package/dist/utils/ProjectCompilationUtils.js +78 -10
  35. package/dist/utils/ProjectCompilationUtils.js.map +1 -1
  36. package/dist/utils/ProjectGeneratorUtils.d.ts +2 -1
  37. package/dist/utils/ProjectGeneratorUtils.js +21 -14
  38. package/dist/utils/ProjectGeneratorUtils.js.map +1 -1
  39. package/dist/utils/ProjectTemplates.d.ts +2 -2
  40. package/dist/utils/ProjectTemplates.js +12 -6
  41. package/dist/utils/ProjectTemplates.js.map +1 -1
  42. package/dist/utils/ProjectUtils.d.ts +24 -1
  43. package/dist/utils/ProjectUtils.js +49 -29
  44. package/dist/utils/ProjectUtils.js.map +1 -1
  45. package/dist/utils/TemplateUtils.d.ts +28 -0
  46. package/dist/utils/TemplateUtils.js +94 -3
  47. package/dist/utils/TemplateUtils.js.map +1 -1
  48. package/package.json +78 -71
  49. package/resources/docs/apps.md +109 -0
  50. package/resources/docs/i18n.md +51 -0
  51. package/resources/docs/processes.md +87 -0
  52. package/resources/docs/project.md +100 -0
  53. package/resources/docs/queries.md +54 -0
  54. package/resources/docs/tables.md +97 -0
@@ -106,22 +106,111 @@ class TemplateUtils {
106
106
  * Folders of a new project, relative to its root
107
107
  */
108
108
  static PROJECT_FOLDERS = ['processes', 'apps', 'documents', 'tables'];
109
+ /**
110
+ * tsconfig.json of a Codenotch project.
111
+ *
112
+ * Its 'include' must cover the generated 'db-schema.d.ts': the declaration merging it carries
113
+ * only applies to files of the same TypeScript program, and without a tsconfig the editor
114
+ * builds an inferred program out of the open files alone, so a d.ts nobody imports would
115
+ * never be loaded and `ctx.tables` would stay untyped.
116
+ *
117
+ * '**' takes the whole workspace, so a folder the developer adds is typed like the rest. A
118
+ * wildcard never walks into 'node_modules' nor into a folder whose name starts with a dot
119
+ * ('.codenotch', '.git', '.vscode', ...), so only the rest has to be listed in 'exclude' -
120
+ * they are named there anyway, as the cli also reads it to know what not to package.
121
+ * 'compiled' held the process bundles of the in-place compile of older CLIs (it now stages
122
+ * under '.codenotch'): generated .js that would otherwise join the program through allowJs.
123
+ */
124
+ static createTsConfigJson() {
125
+ return JSON.stringify({
126
+ compilerOptions: BuildUtils_1.default.defaultCompilerOptions(),
127
+ include: ['**/*'],
128
+ exclude: ['node_modules', '.codenotch', 'compiled']
129
+ }, null, 4) + '\n';
130
+ }
109
131
  static createGitignore() {
110
132
  return [
111
133
  'package-lock.json',
112
134
  '',
113
135
  '# Generated by the cli, regenerate them with the commands of the readme',
114
136
  // Anchored with a leading slash: these three only ever sit at the root of the project
115
- '/db-schema.ts',
137
+ '/db-schema.d.ts',
116
138
  '/db-schema.xml',
117
139
  '/openapi.json',
118
140
  // No slash: a translation file can sit anywhere, and its class is generated next to it
119
141
  '*.i18n.ts',
142
+ // Process bundles of the in-place compile of older CLIs, now staged under .codenotch
143
+ '/compiled',
120
144
  '',
121
145
  '/.codenotch',
122
146
  '/node_modules'
123
147
  ].join('\n') + '\n';
124
148
  }
149
+ /**
150
+ * AGENTS.md of a new project: the entry point of AI coding agents (Claude Code reads it
151
+ * through CLAUDE.md). Kept short on purpose: the reference documentation ships with the CLI
152
+ * and is read through 'cn docs <topic>', so it follows the installed CLI instead of being
153
+ * frozen at the version that created the project.
154
+ */
155
+ static createAgentsMd(projectName, serviceName) {
156
+ return `# Instructions for AI coding agents
157
+
158
+ This is **${projectName}**, a [Codenotch](https://codenotch.com/) project: TypeScript end to
159
+ end, built and deployed on a Codenotch runtime by the \`cn\` CLI (\`npm install -g @codenotch/codenotch.cli\`).
160
+ The website is not up to date — trust \`cn docs\` and the files of this project over it.
161
+ Its service name is \`${serviceName}\` (see \`manifest.json\`): it identifies the project on the
162
+ runtime and is part of its URL — never rename it on your own.
163
+
164
+ ## The reference documentation lives in the CLI
165
+
166
+ Run \`cn docs\` to list the topics, and **read the topic before writing a file of that kind** —
167
+ this file does not repeat the reference, and the docs follow the installed CLI version:
168
+
169
+ | Command | Read before touching |
170
+ | --- | --- |
171
+ | \`cn docs project\` | anything — anatomy, manifest, generated files, lifecycle |
172
+ | \`cn docs tables\` | \`tables/*.ts\`, \`documents/*.ts\` (\`defineEntity\`, \`defineDocument\`) |
173
+ | \`cn docs processes\` | \`processes/*.ts\` (\`process({...})\` declarations) |
174
+ | \`cn docs queries\` | \`queries/*.cnql\` |
175
+ | \`cn docs apps\` | \`apps/*.tsx\` and their manifests |
176
+ | \`cn docs i18n\` | \`*.i18n.csv\` |
177
+
178
+ ## Rules
179
+
180
+ 1. **Never edit generated files**: \`db-schema.xml\`, \`db-schema.d.ts\`, \`openapi.json\`,
181
+ \`*.i18n.ts\`, \`.codenotch/\`. Fix the source they are generated from, then regenerate.
182
+ 2. **Regenerate after changing sources** — tables or documents:
183
+ \`cn generate dbcontext -f .\`; processes exposing endpoints: \`cn generate openapi -f .\`;
184
+ translations: \`cn generate i18n -f <file>.i18n.csv\`.
185
+ 3. **Keep the TODO policy**: where the runtime API is not settled yet (the client-side call of a
186
+ process, the CNQL filter syntax), the sources carry an explicit \`TODO\` comment instead of a
187
+ guess. Never invent those APIs; carry the TODO and tell the user.
188
+ 4. **Check your work**: \`cn validate .\` reports hints, warnings and errors of every file, and
189
+ \`cn project compile\` typechecks and bundles the processes without deploying anything.
190
+ \`cn validate\`, \`cn project inspect\`, \`cn runtime info\` and \`cn docs\` take \`--json\`
191
+ for machine-readable output.
192
+
193
+ ## Everyday commands
194
+
195
+ | Command | What it does |
196
+ | --- | --- |
197
+ | \`cn project start\` | build, deploy and start the project on the local runtime |
198
+ | \`cn project refresh\` | after a change: sync the project with the running runtime |
199
+ | \`cn project inspect\` | parse the project and display everything the CLI discovered |
200
+ | \`cn project test\` | run the tests of the project |
201
+ | \`cn react dev [app]\` | Vite dev server with HMR for one app |
202
+ | \`cn runtime start\` / \`cn runtime info\` | start the local runtime / its status |
203
+
204
+ Run \`cn --help\` (or \`cn <command> --help\`) for the complete list.
205
+ `;
206
+ }
207
+ /**
208
+ * CLAUDE.md of a new project: Claude Code reads this file, the '@' import pulls the shared
209
+ * AGENTS.md in so both stay one single source of truth
210
+ */
211
+ static createClaudeMd() {
212
+ return `@AGENTS.md\n`;
213
+ }
125
214
  /**
126
215
  * readme.md of a new project: what the generated files are and how to work with them
127
216
  */
@@ -138,7 +227,7 @@ Renaming it later means updating every reference to it, so it is better chosen o
138
227
  ## Requirements
139
228
 
140
229
  ${fence}sh
141
- npm install -g codenotch-cli # the 'cn' command
230
+ npm install -g @codenotch/codenotch.cli # the 'cn' command
142
231
  cn runtime update # install (or update) the local Codenotch runtime
143
232
  ${fence}
144
233
 
@@ -154,7 +243,7 @@ The files the cli derives from the sources are not versioned (see \`.gitignore\`
154
243
  fresh clone they have to be written again before the project compiles:
155
244
 
156
245
  ${fence}sh
157
- cn generate dbcontext -f . # db-schema.xml + db-schema.ts, when the project has tables
246
+ cn generate dbcontext -f . # db-schema.xml + db-schema.d.ts, when the project has tables or documents
158
247
  cn generate openapi -f . # openapi.json, when processes expose endpoints
159
248
  cn generate i18n -f <file>.i18n.csv # the typed class of each translation file
160
249
  ${fence}
@@ -171,11 +260,13 @@ ${fence}
171
260
  | --- | --- |
172
261
  | \`manifest.json\` | project name, service name, version, languages and roles |
173
262
  | \`package.json\` | npm dependencies, React and \`@codenotch/codenotch.react\` |
263
+ | \`tsconfig.json\` | covers the sources and the generated \`db-schema.d.ts\`, which types \`ctx.tables\` |
174
264
  | \`processes/\` | server side processes, one TypeScript file each |
175
265
  | \`tables/\` | SQL table definitions |
176
266
  | \`documents/\` | NoSQL document schemas |
177
267
  | \`apps/\` | React apps: \`<App>.tsx\` and its \`<App>.manifest.json\` |
178
268
  | \`*.i18n.csv\` | translations, one column per language |
269
+ | \`AGENTS.md\` | instructions for AI coding agents (\`CLAUDE.md\` imports it) |
179
270
 
180
271
  ## Apps
181
272
 
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateUtils.js","sourceRoot":"","sources":["../../src/utils/TemplateUtils.ts"],"names":[],"mappings":";;;;;;AACA,8DAAsC;AAEtC;;GAEG;AACU,QAAA,gBAAgB,GAAG,oBAAoB,CAAC;AAErD;;;;;;GAMG;AACH,MAA8B,aAAa;IAEvC,MAAM,CAAC,cAAc,CAAC,OAAe;QACjC,O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,OAAO;YACH,mBAAmB;YACnB,EAAE;YACF,yEAAyE;YACzE,sFAAsF;YACtF,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;YACf,uFAAuF;YACvF,WAAW;YACX,qFAAqF;YACrF,WAAW;YACX,EAAE;YACF,aAAa;YACb,eAAe;SAClB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,WAAmB,EAAE,WAAmB;QAC1D,OAAO;;YAEH,WAAW;;;wBAGC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4ClC,CAAC;IACE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc;QACjB,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAmB,EAAE,WAAmB;QAE1D,yEAAyE;QACzE,MAAM,KAAK,GAAG,KAAK,CAAC;QAEpB,OAAO,KAAK,WAAW;;;;wBAIP,WAAW;;;;;EAKjC,KAAK;;;EAGL,KAAK;;;;EAIL,KAAK;;;;EAIL,KAAK;;;;;EAKL,KAAK;;;;EAIL,KAAK;;;;EAIL,KAAK;;EAEL,KAAK;;;;;;;;;;;;;;;;;;;;EAoBL,KAAK;;;;;;;;;;;;EAYL,KAAK;;;;;;;;EAQL,KAAK;;;;EAIL,KAAK;;;;EAIL,KAAK;;EAEL,KAAK;;;;;;;;;;;;;;;;;;CAkBN,CAAC;IACE,CAAC;;AA7TL,gCA8TC"}
package/package.json CHANGED
@@ -1,71 +1,78 @@
1
- {
2
- "name": "@codenotch/codenotch.cli",
3
- "version": "1.0.41",
4
- "description": "A CLI tool for code management",
5
- "main": "dist/index.js",
6
- "files": [
7
- "dist"
8
- ],
9
- "bin": {
10
- "codenotch-cli": "./dist/bin/cli.js",
11
- "cn": "./dist/bin/cli.js"
12
- },
13
- "scripts": {
14
- "build": "tsc",
15
- "dev": "tsx src/index.ts",
16
- "start": "node dist/index.js",
17
- "clean": "rimraf dist",
18
- "prebuild": "npm run clean",
19
- "prepare": "npm run build",
20
- "pack:check": "npm pack --dry-run",
21
- "release": "npm run build && npm run pack:check && npm publish",
22
- "test": "vitest run",
23
- "test:watch": "vitest",
24
- "test:coverage": "vitest run --coverage"
25
- },
26
- "keywords": [
27
- "cli",
28
- "tool",
29
- "code"
30
- ],
31
- "author": "Codenotch SA",
32
- "license": "MIT",
33
- "repository": {
34
- "type": "git",
35
- "url": "https://github.com/EchinoHub/codenotch-cli.git"
36
- },
37
- "publishConfig": {
38
- "access": "public"
39
- },
40
- "dependencies": {
41
- "@codenotch/codenotch.core": "1.0.25",
42
- "@octokit/auth-oauth-device": "^8.0.3",
43
- "@types/express": "^5.0.6",
44
- "adm-zip": "^0.5.17",
45
- "chalk": "^5.3.0",
46
- "commander": "^12.0.0",
47
- "cross-keychain": "^1.1.0",
48
- "decompress": "^4.2.1",
49
- "dotenv": "^17.4.2",
50
- "ignore": "^7.0.6",
51
- "express": "^5.2.1",
52
- "fs-extra": "^10.0.0",
53
- "js2xmlparser": "^5.0.0",
54
- "node-fetch": "^3.3.2",
55
- "papaparse": "^5.3.1",
56
- "typescript": "^5.9.3"
57
- },
58
- "devDependencies": {
59
- "@types/adm-zip": "^0.5.8",
60
- "@types/decompress": "^4.2.7",
61
- "@types/fs-extra": "^9.0.13",
62
- "@types/json-schema": "^7.0.6",
63
- "@types/node": "^20.19.34",
64
- "@types/papaparse": "^5.3.1",
65
- "@vitest/coverage-v8": "^4.1.10",
66
- "rimraf": "^5.0.0",
67
- "ts-node": "^10.9.2",
68
- "tsx": "^4.21.0",
69
- "vitest": "^4.1.10"
70
- }
71
- }
1
+ {
2
+ "name": "@codenotch/codenotch.cli",
3
+ "version": "1.0.43",
4
+ "description": "The Codenotch CLI ('cn'): scaffold, run, validate, package and deploy full-stack TypeScript Codenotch projects - processes, tables, documents and React apps - on a local Codenotch runtime",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist",
8
+ "resources"
9
+ ],
10
+ "bin": {
11
+ "codenotch-cli": "./dist/bin/cli.js",
12
+ "cn": "./dist/bin/cli.js"
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "dev": "tsx src/index.ts",
17
+ "start": "node dist/index.js",
18
+ "clean": "rimraf dist",
19
+ "prebuild": "npm run clean",
20
+ "prepare": "npm run build",
21
+ "pack:check": "npm pack --dry-run",
22
+ "release": "npm run build && npm run pack:check && npm publish",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "test:coverage": "vitest run --coverage"
26
+ },
27
+ "keywords": [
28
+ "codenotch",
29
+ "cn",
30
+ "cli",
31
+ "fullstack",
32
+ "typescript",
33
+ "react",
34
+ "scaffold",
35
+ "runtime"
36
+ ],
37
+ "author": "Codenotch SA",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/EchinoHub/codenotch-cli.git"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "@codenotch/codenotch.core": "1.0.25",
48
+ "@octokit/auth-oauth-device": "^8.0.3",
49
+ "@types/express": "^5.0.6",
50
+ "adm-zip": "^0.5.17",
51
+ "chalk": "^5.3.0",
52
+ "commander": "^12.0.0",
53
+ "cross-keychain": "^1.1.0",
54
+ "decompress": "^4.2.1",
55
+ "dotenv": "^17.4.2",
56
+ "esbuild": "0.28.2",
57
+ "express": "^5.2.1",
58
+ "fs-extra": "^10.0.0",
59
+ "ignore": "^7.0.6",
60
+ "js2xmlparser": "^5.0.0",
61
+ "node-fetch": "^3.3.2",
62
+ "papaparse": "^5.3.1",
63
+ "typescript": "^5.9.3"
64
+ },
65
+ "devDependencies": {
66
+ "@types/adm-zip": "^0.5.8",
67
+ "@types/decompress": "^4.2.7",
68
+ "@types/fs-extra": "^9.0.13",
69
+ "@types/json-schema": "^7.0.6",
70
+ "@types/node": "^20.19.34",
71
+ "@types/papaparse": "^5.3.1",
72
+ "@vitest/coverage-v8": "^4.1.10",
73
+ "rimraf": "^5.0.0",
74
+ "ts-node": "^10.9.2",
75
+ "tsx": "^4.21.0",
76
+ "vitest": "^4.1.10"
77
+ }
78
+ }
@@ -0,0 +1,109 @@
1
+ # React apps
2
+
3
+ How the React apps of a project are structured, the `useCodenotch()` runtime bridge, styling with Scss or Tailwind, and the `cn react` commands.
4
+
5
+ ## An app is a pair of files
6
+
7
+ An app is a `<Name>.tsx` and its sibling `<Name>.manifest.json`, both under `apps/`. The name
8
+ must be a valid JavaScript identifier — it is also the React component name and how the
9
+ `cn react` commands address the app. The `.tsx` default-exports the component:
10
+
11
+ ```tsx
12
+ import React from 'react';
13
+ import { useCodenotch } from '@codenotch/codenotch.react';
14
+
15
+ const index: React.FC<{}> = () => {
16
+ const cn = useCodenotch();
17
+ return <div>
18
+ <h1>My new Codenotch App</h1>
19
+ <pre>{JSON.stringify(cn.env, null, 4)}</pre>
20
+ </div>;
21
+ };
22
+
23
+ export default index;
24
+ ```
25
+
26
+ The manifest carries the display and PWA settings:
27
+
28
+ ```json
29
+ {
30
+ "app": { "name": "index" },
31
+ "html": { "title": "My Project" },
32
+ "pwa": {
33
+ "name": "index",
34
+ "display": "standalone",
35
+ "display_override": ["window-controls-overlay"],
36
+ "start_url": "./",
37
+ "icons": [
38
+ { "src": "logo512.png", "sizes": "512x512", "type": "image/png" },
39
+ { "src": "logo192.png", "sizes": "192x192", "type": "image/png" }
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ `cn generate app -n <Name>` scaffolds the pair.
46
+
47
+ ## Stack
48
+
49
+ - **React 19** — the only supported major.
50
+ - **react-router 7** for multi-page apps, with `HashRouter`: it keeps the routing client side
51
+ whatever URL the runtime serves the app from.
52
+ - **`@codenotch/codenotch.react`** — the bridge to the runtime, through `useCodenotch()`.
53
+
54
+ ## useCodenotch()
55
+
56
+ What the generated code relies on:
57
+
58
+ | Member | Meaning |
59
+ | --- | --- |
60
+ | `cn.env` | the environment the runtime gave the app |
61
+ | `cn.getTheme()` / `cn.setTheme('light' \| 'dark')` | theme; `setTheme` toggles the `dark` class on `<html>` |
62
+ | `cn.getLanguage()` / `cn.setLanguage(lang)` / `cn.getLanguages()` | languages, from `manifest.json` |
63
+ | `cn.startProcess(processId, input)` | call a server-side process — **not implemented yet** in `@codenotch/codenotch.react` 2.0.1 (it throws `Not implemented.`) |
64
+
65
+ For the full surface, read the typings in
66
+ `node_modules/@codenotch/codenotch.react/dist/`. Because `startProcess` is not settled, generated
67
+ projects wrap it in one typed `apps/api.ts` module carrying a `TODO` comment — keep that pattern
68
+ instead of scattering direct calls.
69
+
70
+ ## Styling
71
+
72
+ Every template styles through a `.scss` imported by the app entry (`import './index.scss'`).
73
+ The Tailwind flavour uses **Tailwind CSS 4**:
74
+
75
+ ```scss
76
+ // @use rather than @import: sass deprecates @import (gone in dart sass 3)
77
+ @use "tailwindcss";
78
+
79
+ /* setTheme('dark') toggles the 'dark' class on <html>: key the dark: variants on it */
80
+ @custom-variant dark (&:where(.dark, .dark *));
81
+ ```
82
+
83
+ plus a `postcss.config.js` with the `@tailwindcss/postcss` plugin, picked up by the Vite build.
84
+ No CSS modules.
85
+
86
+ ## Translations in the UI
87
+
88
+ Import the class generated from a `*.i18n.csv` and follow the runtime language (see
89
+ `cn docs i18n`):
90
+
91
+ ```tsx
92
+ import globals from '../../globals.i18n';
93
+
94
+ globals.setLanguage(cn.getLanguage() ?? 'en');
95
+ <h1>{globals.appTitle()}</h1>
96
+ ```
97
+
98
+ ## Commands
99
+
100
+ | Command | What it does |
101
+ | --- | --- |
102
+ | `cn react dev [app]` | Vite dev server with HMR on the real project sources |
103
+ | `cn react build [app]` | production bundle (options for a static or PWA build) |
104
+ | `cn react serve [target]` | serve a build locally |
105
+ | `cn react clean [app]` | delete the build staging of the app |
106
+ | `cn react package [app]` | desktop installer (Tauri) |
107
+
108
+ Apps are addressed by the `app.name` of their manifest; with a single app the name can be
109
+ omitted.
@@ -0,0 +1,51 @@
1
+ # Translations
2
+
3
+ The `*.i18n.csv` translation files, and the typed class `cn generate i18n` derives from each of them.
4
+
5
+ ## The csv
6
+
7
+ A `*.i18n.csv` holds one `key` column plus one column per language, matching the `languages` of
8
+ `manifest.json`:
9
+
10
+ ```csv
11
+ key,en,de,fr
12
+ appTitle,My todo lists,Meine Aufgabenlisten,Mes listes de tâches
13
+ todoCount,"{0} todo(s), {1} done","{0} Aufgabe(n), {1} erledigt","{0} tâche(s), {1} terminée(s)"
14
+ ```
15
+
16
+ - `{0}`, `{1}`, ... are the placeholders of the arguments.
17
+ - Standard CSV quoting: wrap a value containing a comma, a quote or a newline in double quotes.
18
+ - Rows without a key are ignored (a leading empty row after the header is tolerated).
19
+ - Best practice: one global file at the project root (e.g. `globals.i18n.csv`) rather than many
20
+ scattered ones.
21
+
22
+ Keys should be valid identifiers (they become method names): a key that is not is converted with
23
+ a warning, and the names `values`, `lang`, `setLanguage`, `getValue` are reserved.
24
+
25
+ ## The generated class
26
+
27
+ ```sh
28
+ cn generate i18n -f globals.i18n.csv
29
+ ```
30
+
31
+ writes `globals.i18n.ts` next to the csv — generated, gitignored, never edit it; regenerate after
32
+ every change to the csv. The class name comes from the file name, and it exposes one static
33
+ method per key:
34
+
35
+ ```tsx
36
+ import globals from './globals.i18n';
37
+
38
+ globals.setLanguage('de');
39
+ globals.appTitle(); // 'Meine Aufgabenlisten'
40
+ globals.todoCount('3', '1'); // '3 Aufgabe(n), 1 erledigt'
41
+ ```
42
+
43
+ Behavior of the generated methods:
44
+
45
+ - the argument count of a method is the highest `{n}` placeholder across all languages, plus one;
46
+ - a language without a value falls back to the first language column of the csv;
47
+ - an unknown key returns `KEY '<key>' NOT EXISTS` rather than throwing — a visible marker in the
48
+ UI instead of a crash.
49
+
50
+ In an app, follow the runtime language: `globals.setLanguage(cn.getLanguage() ?? 'en')` (see
51
+ `cn docs apps`).
@@ -0,0 +1,87 @@
1
+ # Processes
2
+
3
+ How to write the server-side processes of a project with `@codenotch/process`, what `ctx` offers, and the constraints coming from how they are bundled and executed.
4
+
5
+ ## Declaring a process
6
+
7
+ A process is a `process({...})` declaration, conventionally grouped by domain in files under
8
+ `processes/`:
9
+
10
+ ```ts
11
+ import { process, api, Context } from '@codenotch/process'
12
+ import type { ITodoList } from '../tables/todolist'
13
+
14
+ export const createTodoList = process({
15
+ id: 'CreateTodoList',
16
+ description: 'Creates an empty todo list',
17
+ auth: { scope: 'internal' },
18
+ trigger: api.post('/todolists'),
19
+ run: async (ctx: Context, input: { name: string }): Promise<{ id: string }> => {
20
+ const id = ctx.uuid()
21
+ await ctx.tables.todolists.write(id, { name: input.name })
22
+ return { id }
23
+ },
24
+ })
25
+ ```
26
+
27
+ | Property | Meaning |
28
+ | --- | --- |
29
+ | `id` | Unique across the project, a **string literal**. The registry key and the `ctx.call` target. |
30
+ | `description` | One line, shown in diagnostics and OpenAPI. |
31
+ | `auth.scope` | Who may start it: `'public'`, `'internal'`, `'system'`. |
32
+ | `trigger` | How it starts (below). Omitted: only reachable through `ctx.call` from another process. |
33
+ | `run` | `async (ctx, input) => output`. Always returns a Promise. |
34
+
35
+ Triggers:
36
+
37
+ | Trigger | Starts the process |
38
+ | --- | --- |
39
+ | `api.get('/route')` / `api.post` / `api.put` / `api.delete` | as an HTTP endpoint; `:param` segments land in `input` |
40
+ | `timer('0 7 * * *')` | on a cron schedule |
41
+ | `signal('some.ref')` | when that signal is raised |
42
+ | `install({ ... })` | at installation of the project |
43
+
44
+ Type the `input` parameter and the return type of `run`: the CLI turns those annotations into
45
+ JSON schemas used for payload validation and `openapi.json` (`cn generate openapi -f .`).
46
+
47
+ ## What `ctx` offers
48
+
49
+ The capabilities the generated code relies on:
50
+
51
+ | Member | Meaning |
52
+ | --- | --- |
53
+ | `ctx.tables.<collection>.write(id, patch)` | insert or update a row (only the fields present in the patch are written) |
54
+ | `ctx.tables.<collection>.require(id)` | one row, throws when the id is unknown — an `api` process turns that into a 404 |
55
+ | `ctx.tables.<collection>.delete(id)` | delete a row (relations with `linkBehaviour('Delete')` cascade) |
56
+ | `ctx.query<T>('queries/x.cnql', params)` | run a read query, see `cn docs queries` |
57
+ | `ctx.uuid()` | a new UUID |
58
+ | `ctx.call` | start another process by its `id` |
59
+ | `ctx.log.info(message, data)` | structured logging |
60
+
61
+ `ctx.tables` is typed by the generated `db-schema.d.ts` — regenerate it after changing a table
62
+ (`cn generate dbcontext -f .`), otherwise the collections stay untyped.
63
+
64
+ ## Rules — a process that breaks them is skipped with a warning, never guessed
65
+
66
+ - **Export the variable** (`export const createTodoList = ...`): a non-exported process is not
67
+ reachable.
68
+ - **Literal, unique `id`**: an id that is missing, computed at runtime, or already used by
69
+ another process gets the declaration skipped.
70
+
71
+ ## Bundling constraints
72
+
73
+ At packaging time each process becomes one self-contained `.js` artifact executed in a bare V8
74
+ engine — no Node, no module system. Consequences for the code you write:
75
+
76
+ - **No Node standard library** (`fs`, `node:crypto`, ...): importing one is a compile error, it
77
+ cannot exist in the runtime's engine.
78
+ - **npm dependencies are inlined** into each artifact: only pure-JS packages can work (no native
79
+ addons, no Node API inside).
80
+ - `@codenotch/*` packages are **provided by the runtime**, never inlined.
81
+ - **Module-level state is per process**: a top-level cache in a shared helper exists once per
82
+ artifact, it is never shared between processes.
83
+ - The whole project is **typechecked before bundling**: type errors fail the packaging.
84
+
85
+ `cn project compile` runs the same typecheck and bundling without packaging — the quick way to
86
+ check the processes build. `cn generate process` scaffolds boilerplate processes (CRUD, api) for
87
+ a discovered table (`-m api|insert|insert-full|update|upsert|delete|clean`).
@@ -0,0 +1,100 @@
1
+ # The anatomy of a Codenotch project
2
+
3
+ What a Codenotch project is made of, which files are generated from which sources, and the commands of its lifecycle.
4
+
5
+ A Codenotch project is TypeScript end to end: server-side processes are `process({...})`
6
+ declarations from `@codenotch/process`, tables are `defineEntity({...})` from `@codenotch/orm`,
7
+ apps are React 19 components. The project is built, deployed and run on a Codenotch runtime by
8
+ the `cn` CLI. The CLI discovers what the project declares by parsing its TypeScript sources —
9
+ there is no registry to maintain by hand.
10
+
11
+ ## Layout
12
+
13
+ | Path | Contains | Topic |
14
+ | --- | --- | --- |
15
+ | `manifest.json` | project name, service name, version, languages and roles | below |
16
+ | `package.json` | npm dependencies, React and `@codenotch/codenotch.react` | |
17
+ | `tsconfig.json` | covers the sources and the generated `db-schema.d.ts` | below |
18
+ | `processes/` | server side processes, plain TypeScript files | `cn docs processes` |
19
+ | `tables/` | SQL table definitions (`defineEntity`) | `cn docs tables` |
20
+ | `documents/` | NoSQL document schemas (`defineDocument`) | `cn docs tables` |
21
+ | `queries/` | `.cnql` read queries run by the processes | `cn docs queries` |
22
+ | `apps/` | React apps: `<App>.tsx` and its `<App>.manifest.json` | `cn docs apps` |
23
+ | `*.i18n.csv` | translations, one column per language | `cn docs i18n` |
24
+
25
+ The folder names are a convention, not a requirement: the CLI discovers declarations by parsing
26
+ every TypeScript file of the project, wherever it sits.
27
+
28
+ ## manifest.json
29
+
30
+ ```json
31
+ {
32
+ "packages": {},
33
+ "projectName": "My Project",
34
+ "serviceName": "myproject",
35
+ "languages": ["en", "de", "fr"],
36
+ "roles": [],
37
+ "version": "0.0.0",
38
+ "dependencies": [],
39
+ "postInstallationProcesses": []
40
+ }
41
+ ```
42
+
43
+ `serviceName` identifies the project on the runtime and is part of its URL. Renaming it means
44
+ updating every reference to it (queries carry it as their `xmlns`, for instance) — treat it as
45
+ fixed unless the user explicitly asks for a rename.
46
+
47
+ ## Generated files — never edit them
48
+
49
+ | File | Generated from | Regenerate with |
50
+ | --- | --- | --- |
51
+ | `db-schema.xml` | the `defineEntity` declarations | `cn generate dbcontext -f .` |
52
+ | `db-schema.d.ts` | same — types `ctx.tables` by declaration merging | `cn generate dbcontext -f .` |
53
+ | `openapi.json` | the processes exposing endpoints | `cn generate openapi -f .` |
54
+ | `*.i18n.ts` | its sibling `*.i18n.csv` | `cn generate i18n -f <file>.i18n.csv` |
55
+ | `.codenotch/` | build outputs: compiled project, package zip, React staging | `cn project compile` / `package`, `cn react build` |
56
+
57
+ These files are in `.gitignore`: after a fresh clone they have to be generated again before the
58
+ project compiles. When one of them looks wrong, fix the source it is generated from, then
59
+ regenerate — an edit to the generated file is overwritten on the next run.
60
+
61
+ `tsconfig.json` must keep including `db-schema.d.ts`: the declaration merging it carries only
62
+ applies to files of the same TypeScript program, so removing it from `include` silently untypes
63
+ `ctx.tables` in every process.
64
+
65
+ ## Lifecycle
66
+
67
+ ```sh
68
+ npm install -g @codenotch/codenotch.cli # the 'cn' command
69
+ cn runtime update # install (or update) the local Codenotch runtime
70
+ cn runtime start # start it
71
+ cn project start # build, deploy and open this project
72
+ cn project refresh # after a change: sync the project with the runtime
73
+ ```
74
+
75
+ Checks, at any time:
76
+
77
+ ```sh
78
+ cn validate . # hints, warnings and errors of every file
79
+ cn project inspect # parse the project and display everything the CLI discovered
80
+ cn project test # run the tests of the project
81
+ cn project compile # typecheck and bundle into .codenotch/compiled, without packaging
82
+ ```
83
+
84
+ `cn validate`, `cn project inspect`, `cn runtime info` and `cn docs` all take `--json` for
85
+ machine-readable output.
86
+
87
+ Shipping:
88
+
89
+ ```sh
90
+ cn project package # compile and package the project as a zip (.codenotch/build.zip)
91
+ cn project deploy <service> [zip] # zip omitted: pick one found under .codenotch/
92
+ ```
93
+
94
+ Packaging typechecks the whole project first: type errors fail it.
95
+
96
+ ## The TODO policy
97
+
98
+ Where the runtime API is not settled yet (the client-side call of a process, the CNQL filter
99
+ syntax), the code carries an explicit `TODO` comment instead of a guess. Keep that policy: never
100
+ invent an API shape where the existing sources marked one as unsettled.