@codenotch/codenotch.cli 1.0.41 → 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.
Files changed (50) 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/deploy.js +9 -2
  6. package/dist/commands/project/deploy.js.map +1 -1
  7. package/dist/commands/project/inspect.js +65 -1
  8. package/dist/commands/project/inspect.js.map +1 -1
  9. package/dist/commands/system/docs.d.ts +2 -0
  10. package/dist/commands/system/docs.js +57 -0
  11. package/dist/commands/system/docs.js.map +1 -0
  12. package/dist/commands/system/index.js +2 -0
  13. package/dist/commands/system/index.js.map +1 -1
  14. package/dist/commands/system/read.js +2 -1
  15. package/dist/commands/system/read.js.map +1 -1
  16. package/dist/commands/validation/files/ScriptValidator.js +9 -8
  17. package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
  18. package/dist/index.js +12 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/utils/DbSchemaUtils.d.ts +16 -10
  21. package/dist/utils/DbSchemaUtils.js +82 -30
  22. package/dist/utils/DbSchemaUtils.js.map +1 -1
  23. package/dist/utils/DocsUtils.d.ts +34 -0
  24. package/dist/utils/DocsUtils.js +76 -0
  25. package/dist/utils/DocsUtils.js.map +1 -0
  26. package/dist/utils/ProcessBundlerUtils.d.ts +103 -0
  27. package/dist/utils/ProcessBundlerUtils.js +336 -0
  28. package/dist/utils/ProcessBundlerUtils.js.map +1 -0
  29. package/dist/utils/ProjectCompilationUtils.d.ts +14 -2
  30. package/dist/utils/ProjectCompilationUtils.js +75 -3
  31. package/dist/utils/ProjectCompilationUtils.js.map +1 -1
  32. package/dist/utils/ProjectGeneratorUtils.d.ts +2 -1
  33. package/dist/utils/ProjectGeneratorUtils.js +21 -14
  34. package/dist/utils/ProjectGeneratorUtils.js.map +1 -1
  35. package/dist/utils/ProjectTemplates.d.ts +2 -2
  36. package/dist/utils/ProjectTemplates.js +12 -6
  37. package/dist/utils/ProjectTemplates.js.map +1 -1
  38. package/dist/utils/ProjectUtils.d.ts +18 -1
  39. package/dist/utils/ProjectUtils.js +33 -28
  40. package/dist/utils/ProjectUtils.js.map +1 -1
  41. package/dist/utils/TemplateUtils.d.ts +28 -0
  42. package/dist/utils/TemplateUtils.js +95 -3
  43. package/dist/utils/TemplateUtils.js.map +1 -1
  44. package/package.json +78 -71
  45. package/resources/docs/apps.md +109 -0
  46. package/resources/docs/i18n.md +51 -0
  47. package/resources/docs/processes.md +87 -0
  48. package/resources/docs/project.md +101 -0
  49. package/resources/docs/queries.md +54 -0
  50. package/resources/docs/tables.md +97 -0
@@ -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.