@codenotch/codenotch.cli 1.0.40 → 1.0.42
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 +78 -28
- package/dist/commands/generate/app.js +6 -0
- package/dist/commands/generate/app.js.map +1 -1
- package/dist/commands/generate/appmanifest.js +5 -0
- package/dist/commands/generate/appmanifest.js.map +1 -1
- package/dist/commands/generate/dbcontext.js +6 -2
- package/dist/commands/generate/dbcontext.js.map +1 -1
- package/dist/commands/generate/i18n.js +5 -0
- package/dist/commands/generate/i18n.js.map +1 -1
- package/dist/commands/generate/index.js +8 -1
- package/dist/commands/generate/index.js.map +1 -1
- package/dist/commands/generate/manifest.js +4 -0
- package/dist/commands/generate/manifest.js.map +1 -1
- package/dist/commands/generate/openapi.js +5 -1
- package/dist/commands/generate/openapi.js.map +1 -1
- package/dist/commands/generate/pkg.js +4 -0
- package/dist/commands/generate/pkg.js.map +1 -1
- package/dist/commands/generate/process.js +6 -0
- package/dist/commands/generate/process.js.map +1 -1
- package/dist/commands/project/deploy.js +9 -2
- package/dist/commands/project/deploy.js.map +1 -1
- package/dist/commands/project/index.js +8 -1
- package/dist/commands/project/index.js.map +1 -1
- package/dist/commands/project/inspect.js +65 -1
- package/dist/commands/project/inspect.js.map +1 -1
- package/dist/commands/project/new.js +7 -1
- package/dist/commands/project/new.js.map +1 -1
- package/dist/commands/project/remove.js +6 -1
- package/dist/commands/project/remove.js.map +1 -1
- package/dist/commands/react/build.js +22 -1
- package/dist/commands/react/build.js.map +1 -1
- package/dist/commands/react/clean.js +7 -2
- package/dist/commands/react/clean.js.map +1 -1
- package/dist/commands/react/dev.js +6 -0
- package/dist/commands/react/dev.js.map +1 -1
- package/dist/commands/react/index.js +11 -1
- package/dist/commands/react/index.js.map +1 -1
- package/dist/commands/react/package.d.ts +2 -0
- package/dist/commands/react/package.js +47 -0
- package/dist/commands/react/package.js.map +1 -0
- package/dist/commands/react/serve.js +5 -0
- package/dist/commands/react/serve.js.map +1 -1
- package/dist/commands/runtime/clear.js +5 -0
- package/dist/commands/runtime/clear.js.map +1 -1
- package/dist/commands/runtime/index.js +8 -1
- package/dist/commands/runtime/index.js.map +1 -1
- package/dist/commands/system/docs.d.ts +2 -0
- package/dist/commands/system/docs.js +57 -0
- package/dist/commands/system/docs.js.map +1 -0
- package/dist/commands/system/index.js +2 -0
- package/dist/commands/system/index.js.map +1 -1
- package/dist/commands/system/read.js +2 -1
- package/dist/commands/system/read.js.map +1 -1
- package/dist/commands/validation/files/ScriptValidator.js +9 -8
- package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
- package/dist/commands/validation/validate.js +4 -13
- package/dist/commands/validation/validate.js.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/BuildUtils.d.ts +53 -5
- package/dist/utils/BuildUtils.js +233 -21
- package/dist/utils/BuildUtils.js.map +1 -1
- package/dist/utils/ConsoleUtils.d.ts +0 -2
- package/dist/utils/ConsoleUtils.js +0 -8
- package/dist/utils/ConsoleUtils.js.map +1 -1
- package/dist/utils/DbSchemaUtils.d.ts +16 -10
- package/dist/utils/DbSchemaUtils.js +82 -30
- package/dist/utils/DbSchemaUtils.js.map +1 -1
- package/dist/utils/DocsUtils.d.ts +34 -0
- package/dist/utils/DocsUtils.js +76 -0
- package/dist/utils/DocsUtils.js.map +1 -0
- package/dist/utils/OsUtils.d.ts +6 -0
- package/dist/utils/OsUtils.js +26 -0
- package/dist/utils/OsUtils.js.map +1 -1
- package/dist/utils/PackageUtils.d.ts +101 -0
- package/dist/utils/PackageUtils.js +538 -0
- package/dist/utils/PackageUtils.js.map +1 -0
- package/dist/utils/ProcessBundlerUtils.d.ts +103 -0
- package/dist/utils/ProcessBundlerUtils.js +336 -0
- package/dist/utils/ProcessBundlerUtils.js.map +1 -0
- package/dist/utils/ProjectCompilationUtils.d.ts +14 -2
- package/dist/utils/ProjectCompilationUtils.js +75 -3
- package/dist/utils/ProjectCompilationUtils.js.map +1 -1
- package/dist/utils/ProjectGeneratorUtils.d.ts +2 -1
- package/dist/utils/ProjectGeneratorUtils.js +21 -14
- package/dist/utils/ProjectGeneratorUtils.js.map +1 -1
- package/dist/utils/ProjectTemplates.d.ts +2 -2
- package/dist/utils/ProjectTemplates.js +12 -6
- package/dist/utils/ProjectTemplates.js.map +1 -1
- package/dist/utils/ProjectUtils.d.ts +18 -1
- package/dist/utils/ProjectUtils.js +33 -28
- package/dist/utils/ProjectUtils.js.map +1 -1
- package/dist/utils/ServeUtils.js +1 -2
- package/dist/utils/ServeUtils.js.map +1 -1
- package/dist/utils/TemplateUtils.d.ts +29 -0
- package/dist/utils/TemplateUtils.js +96 -3
- package/dist/utils/TemplateUtils.js.map +1 -1
- package/package.json +78 -71
- package/resources/docs/apps.md +109 -0
- package/resources/docs/i18n.md +51 -0
- package/resources/docs/processes.md +87 -0
- package/resources/docs/project.md +101 -0
- package/resources/docs/queries.md +54 -0
- package/resources/docs/tables.md +97 -0
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
| `compiled/` | the processes, one self-contained `.js` each | `cn project compile` (or packaging) |
|
|
56
|
+
| `.codenotch/` | React build staging | `cn react build` |
|
|
57
|
+
|
|
58
|
+
These files are in `.gitignore`: after a fresh clone they have to be generated again before the
|
|
59
|
+
project compiles. When one of them looks wrong, fix the source it is generated from, then
|
|
60
|
+
regenerate — an edit to the generated file is overwritten on the next run.
|
|
61
|
+
|
|
62
|
+
`tsconfig.json` must keep including `db-schema.d.ts`: the declaration merging it carries only
|
|
63
|
+
applies to files of the same TypeScript program, so removing it from `include` silently untypes
|
|
64
|
+
`ctx.tables` in every process.
|
|
65
|
+
|
|
66
|
+
## Lifecycle
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npm install -g @codenotch/codenotch.cli # the 'cn' command
|
|
70
|
+
cn runtime update # install (or update) the local Codenotch runtime
|
|
71
|
+
cn runtime start # start it
|
|
72
|
+
cn project start # build, deploy and open this project
|
|
73
|
+
cn project refresh # after a change: sync the project with the runtime
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Checks, at any time:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
cn validate . # hints, warnings and errors of every file
|
|
80
|
+
cn project inspect # parse the project and display everything the CLI discovered
|
|
81
|
+
cn project test # run the tests of the project
|
|
82
|
+
cn project compile # typecheck and bundle the processes, without packaging
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`cn validate`, `cn project inspect`, `cn runtime info` and `cn docs` all take `--json` for
|
|
86
|
+
machine-readable output.
|
|
87
|
+
|
|
88
|
+
Shipping:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
cn project package # compile and package the project as a zip
|
|
92
|
+
cn project deploy <service> <zip>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Packaging typechecks the whole project first: type errors fail it.
|
|
96
|
+
|
|
97
|
+
## The TODO policy
|
|
98
|
+
|
|
99
|
+
Where the runtime API is not settled yet (the client-side call of a process, the CNQL filter
|
|
100
|
+
syntax), the code carries an explicit `TODO` comment instead of a guess. Keep that policy: never
|
|
101
|
+
invent an API shape where the existing sources marked one as unsettled.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# CNQL queries
|
|
2
|
+
|
|
3
|
+
The `.cnql` read queries a process runs through `ctx.query`, and what is still unsettled in their syntax.
|
|
4
|
+
|
|
5
|
+
CNQL is an XML query language for reading data. A query lives in its own `.cnql` file,
|
|
6
|
+
conventionally under `queries/`, and is run from a process:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
const lists = await ctx.query<ITodoList>('queries/all-todolists.cnql')
|
|
10
|
+
const todos = await ctx.query<ITodo>('queries/todos-of-list.cnql', { listId: input.listId })
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The path is relative to the project root; the type parameter types the returned rows.
|
|
14
|
+
|
|
15
|
+
## Structure
|
|
16
|
+
|
|
17
|
+
```xml
|
|
18
|
+
<CNQL xmlns="myservice" PageSize="100" PageIndex="0">
|
|
19
|
+
<TodoList Ref="results">
|
|
20
|
+
<Id />
|
|
21
|
+
<Name />
|
|
22
|
+
<CreatedAt />
|
|
23
|
+
</TodoList>
|
|
24
|
+
</CNQL>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- The root is `<CNQL>`, its `xmlns` is the **service name** of the project (`serviceName` of
|
|
28
|
+
`manifest.json`), `PageSize`/`PageIndex` paginate the result.
|
|
29
|
+
- The first child is the queried **table**, named as declared in its `defineEntity` (`TodoList`,
|
|
30
|
+
not `todolists`). `Ref` names the output.
|
|
31
|
+
- Its children are the **columns** to select, PascalCase. `CreatedAt` is maintained by the
|
|
32
|
+
runtime and can be selected without being declared on the entity.
|
|
33
|
+
|
|
34
|
+
Only reads: inserts, updates and deletes go through `ctx.tables` in a process.
|
|
35
|
+
|
|
36
|
+
## What is not settled yet — keep the TODO policy
|
|
37
|
+
|
|
38
|
+
The **filter syntax** (restricting rows, binding the parameters passed as the second argument of
|
|
39
|
+
`ctx.query`) is not settled in the runtime yet. Generated projects mark the spot with an explicit
|
|
40
|
+
comment instead of guessing:
|
|
41
|
+
|
|
42
|
+
```xml
|
|
43
|
+
<!-- TODO: filter on the 'listId' parameter passed by the process. The filtering syntax of CNQL is not settled yet. -->
|
|
44
|
+
<CNQL xmlns="myservice" PageSize="100" PageIndex="0">
|
|
45
|
+
<Todo Ref="results">
|
|
46
|
+
<Id />
|
|
47
|
+
<Title />
|
|
48
|
+
<ListId />
|
|
49
|
+
</Todo>
|
|
50
|
+
</CNQL>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Do the same: never invent a filter, join, ordering or grouping syntax. When a query needs one,
|
|
54
|
+
write the unfiltered query, carry the `TODO` comment, and mention it to the user.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Tables and documents
|
|
2
|
+
|
|
3
|
+
How to declare the SQL tables and NoSQL documents of a project with `@codenotch/orm`, and how they become `db-schema.xml` and the typed `ctx.tables`.
|
|
4
|
+
|
|
5
|
+
## Declaring a table
|
|
6
|
+
|
|
7
|
+
A table is a `defineEntity({...})` declaration, conventionally one file per table under `tables/`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineEntity, type InferEntity, p } from '@codenotch/orm';
|
|
11
|
+
|
|
12
|
+
export const TodoList = defineEntity({
|
|
13
|
+
name: 'TodoList',
|
|
14
|
+
properties: {
|
|
15
|
+
id: p.uuid().primary(),
|
|
16
|
+
name: p.string().notNull(),
|
|
17
|
+
// Deleting a list deletes its todos
|
|
18
|
+
todos: p.hasMany('Todo').linkBehaviour('Delete'),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type ITodoList = InferEntity<typeof TodoList>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Three conventions are load-bearing, the CLI warns and skips when they are broken:
|
|
26
|
+
|
|
27
|
+
- the variable is **exported** and `name` is a **string literal** (a name built at runtime cannot
|
|
28
|
+
be discovered from the sources);
|
|
29
|
+
- the row type is exported next to it: `export type ITodoList = InferEntity<typeof TodoList>` —
|
|
30
|
+
without it the table is left out of the typed `ctx.tables`;
|
|
31
|
+
- table names are unique once pluralized (see collection names below).
|
|
32
|
+
|
|
33
|
+
## Column builders
|
|
34
|
+
|
|
35
|
+
Everything `p` exposes, with the aliases mapping to the same schema type:
|
|
36
|
+
|
|
37
|
+
| Builder | Schema type |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `p.string()` — accepts a length, e.g. `p.string(255)` | String |
|
|
40
|
+
| `p.text()` | Text |
|
|
41
|
+
| `p.email()` | Email |
|
|
42
|
+
| `p.integer()` / `p.int()` | Integer |
|
|
43
|
+
| `p.decimal()` / `p.float()` / `p.number()` | Decimal |
|
|
44
|
+
| `p.boolean()` / `p.bool()` | Boolean |
|
|
45
|
+
| `p.uuid()` / `p.guid()` | Guid |
|
|
46
|
+
| `p.date()` | Date |
|
|
47
|
+
| `p.datetime()` / `p.timestamp()` | DateTime |
|
|
48
|
+
| `p.version()` | Version |
|
|
49
|
+
| `p.enum()` | Enum |
|
|
50
|
+
| `p.autoIncrement()` | AutoIncrement |
|
|
51
|
+
| `p.belongsTo('Target')` | relation, holds the foreign key |
|
|
52
|
+
| `p.hasOne('Target')` / `p.hasMany('Target')` | relation on the other side |
|
|
53
|
+
|
|
54
|
+
A builder outside this list is reported as a warning and left out of the schema — it is never
|
|
55
|
+
silently mapped to a guessed type.
|
|
56
|
+
|
|
57
|
+
Modifiers, chained after the builder:
|
|
58
|
+
|
|
59
|
+
| Modifier | Effect |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `.primary()` | primary key (implies non-nullable) |
|
|
62
|
+
| `.notNull()` / `.required()` | non-nullable |
|
|
63
|
+
| `.unique()` | uniqueness constraint |
|
|
64
|
+
| `.default(value)` | default value (a literal) |
|
|
65
|
+
| `.linkBehaviour('Delete')` | on a relation: deleting the parent deletes the linked rows |
|
|
66
|
+
|
|
67
|
+
A `hasMany`/`hasOne` finds its paired `belongsTo` on the target table automatically; declare the
|
|
68
|
+
`belongsTo` side explicitly when the target has several relations to the same table.
|
|
69
|
+
|
|
70
|
+
## Collection names — how `ctx.tables` is keyed
|
|
71
|
+
|
|
72
|
+
A table is reachable in the processes under its lowercased, pluralized name: `TodoList` →
|
|
73
|
+
`ctx.tables.todolists`, `Box` → `ctx.tables.boxes`, `Category` → `ctx.tables.categories`. Two
|
|
74
|
+
tables mapping to the same collection name is a conflict: only the first one is kept, with a
|
|
75
|
+
warning.
|
|
76
|
+
|
|
77
|
+
## Documents
|
|
78
|
+
|
|
79
|
+
A document is declared the same way with `defineDocument({...})` (conventionally under
|
|
80
|
+
`documents/`), its type exported with `InferDocument`. Documents are keyed by their lowercased
|
|
81
|
+
name, **not** pluralized, and typed as document-store handles rather than table handles.
|
|
82
|
+
|
|
83
|
+
## Generation
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
cn generate dbcontext -f .
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
writes two files at the project root — both generated, never edit them:
|
|
90
|
+
|
|
91
|
+
- `db-schema.xml` — the schema the runtime migrates the database from;
|
|
92
|
+
- `db-schema.d.ts` — augments the `ProjectTables` and `ProjectDocs` interfaces of
|
|
93
|
+
`@codenotch/process` by declaration merging, so `ctx.tables.<collection>` autocompletes with
|
|
94
|
+
the row type of the table.
|
|
95
|
+
|
|
96
|
+
Regenerate after every change to a `defineEntity`/`defineDocument` declaration. The project's
|
|
97
|
+
`tsconfig.json` must keep `db-schema.d.ts` in its `include` for the merging to apply.
|