very-express 0.7.8 → 0.8.0
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/AGENTS.md +116 -0
- package/CLAUDE.md +8 -160
- package/LICENSE +674 -21
- package/dist/index.js +501 -458
- package/dist/templates/_middlewares/DataIsolationContext.ts +10 -4
- package/dist/templates/_projectSettings/env +1 -0
- package/dist/templates/_services/MongooseRepositoryAdapter.ts +66 -3
- package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +72 -11
- package/dist/templates/_services/VexDbConnector.ts +7 -4
- package/dist/templates/_services/auth/JWTService.ts +32 -4
- package/dist/templates/_types/vex/VexRepository.ts +5 -4
- package/dist/templates/jsonSchema/User.json +17 -1
- package/docs/CONTRIBUTING.md +8 -3
- package/docs/architecture/authAndRouting.md +95 -0
- package/docs/architecture/databaseTargets.md +99 -0
- package/docs/architecture/generatorPipeline.md +198 -0
- package/docs/architecture/templates.md +66 -0
- package/docs/features/auditFields.md +240 -0
- package/docs/features/dataIsolation.md +19 -7
- package/docs/releaseNote/v0-8-0.md +95 -0
- package/docs/vexJsonSchema.md +40 -2
- package/package.json +8 -4
- package/vitest.config.ts +18 -0
- package/.github/copilot-instructions.md +0 -106
package/docs/vexJsonSchema.md
CHANGED
|
@@ -49,7 +49,7 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
|
|
|
49
49
|
| `format` | `string` | JSON Schema format hint, e.g. `email`, `date-time` |
|
|
50
50
|
| `index` | `boolean` | Create DB index on this field |
|
|
51
51
|
| `enum` | `array<string>` | Restrict values to this list |
|
|
52
|
-
| `default` | `any` | Default value |
|
|
52
|
+
| `default` | `any` | Default value. Six reserved keyword values make the DB layer fill the field itself — see [auto-written audit fields](#auto-written-audit-fields-default-keywords) |
|
|
53
53
|
| `minLength` / `maxLength` | `number` | String length constraints (used in validator) |
|
|
54
54
|
| `minimum` / `maximum` | `number` | Number constraints (used in validator) |
|
|
55
55
|
| `description` | `string` | OpenAPI description |
|
|
@@ -64,8 +64,11 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
|
|
|
64
64
|
| Value | Description |
|
|
65
65
|
| --- | --- |
|
|
66
66
|
| `Primary` | Marks field as primary key (`_id`). Auto-indexed. |
|
|
67
|
-
| `
|
|
67
|
+
| `PrimaryUUID` | Primary key stored as a UUID column (SQL: `uuid`) |
|
|
68
|
+
| `UUID` | UUID string field (SQL: `uuid`) |
|
|
68
69
|
| `ObjectId` | MongoDB ObjectId (mongo mode) |
|
|
70
|
+
| `UnixTimestamp` | Integer epoch **seconds** (SQL: `bigint`) |
|
|
71
|
+
| `Timestamp` | ISO-8601 datetime (SQL: `timestamptz`, mapped back to an ISO string) |
|
|
69
72
|
| `enum` | Enum field — pair with `enum` array |
|
|
70
73
|
|
|
71
74
|
### `x-vexData` values
|
|
@@ -73,6 +76,41 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
|
|
|
73
76
|
| Value | Description |
|
|
74
77
|
| --- | --- |
|
|
75
78
|
| `role` | Marks this field as the RBAC role field. Required for role-based access control to work. |
|
|
79
|
+
| `userId` | Marks the field that holds the identity value. Declare it **exactly once**, on the account schema (`User._id`) — every `onXXUserId` audit field is filled from it. |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Auto-written audit fields (`default` keywords)
|
|
84
|
+
|
|
85
|
+
A field whose `default` is one of the reserved keywords below is owned by the DB layer: the
|
|
86
|
+
repository adapter strips any client-supplied value and writes the correct one per write phase.
|
|
87
|
+
Works for both `sql` and `mongo` targets. Full reference:
|
|
88
|
+
[`docs/features/auditFields.md`](features/auditFields.md).
|
|
89
|
+
|
|
90
|
+
| `default` keyword | field declaration | written on |
|
|
91
|
+
| --- | --- | --- |
|
|
92
|
+
| `onCreateTimestamp` | `{ "type": "string", "x-format": "Timestamp" }` | create only |
|
|
93
|
+
| `onCreateUnixTimestamp` | `{ "type": "integer", "x-format": "UnixTimestamp" }` | create only |
|
|
94
|
+
| `onUpdateTimestamp` | `{ "type": "string", "x-format": "Timestamp" }` | update / replace only |
|
|
95
|
+
| `onUpdateUnixTimestamp` | `{ "type": "integer", "x-format": "UnixTimestamp" }` | update / replace only |
|
|
96
|
+
| `onCreateUserId` | `{ "type": "string", "x-format": "UUID" }` | create only |
|
|
97
|
+
| `onUpdateUserId` | `{ "type": "string", "x-format": "UUID" }` | update / replace only |
|
|
98
|
+
|
|
99
|
+
```jsonc
|
|
100
|
+
"createdAt": { "type": "string", "x-format": "Timestamp", "default": "onCreateTimestamp" },
|
|
101
|
+
"createdBy": { "type": "string", "x-format": "UUID", "default": "onCreateUserId" },
|
|
102
|
+
"updatedAt": { "type": "string", "x-format": "Timestamp", "default": "onUpdateTimestamp" },
|
|
103
|
+
"updatedBy": { "type": "string", "x-format": "UUID", "default": "onUpdateUserId" }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Generation fails early on a contradiction: an unknown `x-vexData` value, an `onXXUserId` field whose
|
|
107
|
+
column type differs from the tagged identity field, a mismatched timestamp keyword, a missing identity
|
|
108
|
+
field, or an audit field marked `required`.
|
|
109
|
+
|
|
110
|
+
Declaring a keyword also removes the field from the **request body**: the generator emits
|
|
111
|
+
`export type Create{Doc} = Omit<{Doc}, "createdAt" | … >;` into `src/system/_types/{Doc}.gen.ts` and the
|
|
112
|
+
controllers use it, so the OpenAPI request schema only advertises what a client may actually send.
|
|
113
|
+
Because tsoa runs with `throw-on-extras`, a request still carrying such a field gets `400`.
|
|
76
114
|
|
|
77
115
|
---
|
|
78
116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "very-express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
|
|
5
5
|
"author": "Justin26l",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,8 +14,11 @@
|
|
|
14
14
|
"build": "npm run lint && npm run compile",
|
|
15
15
|
"lint": "eslint ./src --ext .ts --fix",
|
|
16
16
|
"compile": "node ./scripts/build.js && node ./scripts/copyTsTemplates.js",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"postversion": "npm run build && git push && git push --tags",
|
|
18
|
+
"test": "npm run compile && vitest run",
|
|
19
|
+
"test:watch": "vitest",
|
|
20
|
+
"test:update": "npm run compile && UPDATE_GOLDEN=1 vitest run",
|
|
21
|
+
"test:e2e": "npm run compile && VEX_E2E=1 vitest run test/e2e"
|
|
19
22
|
},
|
|
20
23
|
"keywords": [
|
|
21
24
|
"jsonSchema",
|
|
@@ -53,6 +56,7 @@
|
|
|
53
56
|
"objection": "^3.1.5",
|
|
54
57
|
"pg": "^8.20.0",
|
|
55
58
|
"ts-node": "^10.9.2",
|
|
56
|
-
"typescript": "^5.3.3"
|
|
59
|
+
"typescript": "^5.3.3",
|
|
60
|
+
"vitest": "^2.1.9"
|
|
57
61
|
}
|
|
58
62
|
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
const srcDir = fileURLToPath(new URL("./src", import.meta.url));
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
resolve: {
|
|
8
|
+
// mirror tsconfig.json "~/*" -> "src/*" so tests can import generator internals
|
|
9
|
+
alias: { "~": srcDir },
|
|
10
|
+
},
|
|
11
|
+
test: {
|
|
12
|
+
include: ["test/**/*.test.ts"],
|
|
13
|
+
environment: "node",
|
|
14
|
+
// golden scenarios spawn a full generation each; give them room
|
|
15
|
+
testTimeout: 120_000,
|
|
16
|
+
hookTimeout: 120_000,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# Project Guidelines — VeryExpress
|
|
2
|
-
|
|
3
|
-
VeryExpress is a **code generator** that reads JSON Schema files and produces a complete Express.js REST API (with Mongoose, RBAC, OAuth2, Swagger). The CLI entry is `src/cli.ts`; the orchestrator is `src/index.ts` → `generate()`.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
jsonSchema/*.json → preprocess → generators → templates → output/
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
| Directory | Role |
|
|
12
|
-
|-----------|------|
|
|
13
|
-
| `src/generators/` | Async `compile()` functions that call templates and write files |
|
|
14
|
-
| `src/templates/` | Static base files copied verbatim (with `.gen.ts` suffix) to output |
|
|
15
|
-
| `src/preprocess/` | Schema validation & normalisation before generation |
|
|
16
|
-
| `src/types/types.ts` | Core interfaces: `compilerOptions`, `jsonSchema`, `jsonSchemaPropsItem` |
|
|
17
|
-
| `src/utils/` | File I/O, logging, JSON-schema helpers, template formatter |
|
|
18
|
-
| `output/` | Generated Express app — **do not hand-edit `*.gen.ts` files** |
|
|
19
|
-
|
|
20
|
-
## Build and Test
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm run dev # compile (esbuild → dist/index.js) + run CLI
|
|
24
|
-
npm run build # lint + compile (production)
|
|
25
|
-
npm run lint # eslint --fix
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
- Build bundles everything into a single `dist/index.js` via esbuild (platform: node, target: es2016).
|
|
29
|
-
- `scripts/copyTsTemplates.js` copies static templates into `output/` after compilation.
|
|
30
|
-
- No test suite exists yet; validate changes by running `npm run dev` and inspecting `output/`.
|
|
31
|
-
|
|
32
|
-
## Conventions
|
|
33
|
-
|
|
34
|
-
### Generator pattern
|
|
35
|
-
|
|
36
|
-
Every generator exports an async `compile(options)` that:
|
|
37
|
-
1. Validates / extracts data from options
|
|
38
|
-
2. Calls a `*Template()` function returning a string
|
|
39
|
-
3. Writes the result with `utils.common.writeFile()`
|
|
40
|
-
|
|
41
|
-
### Template pattern
|
|
42
|
-
|
|
43
|
-
- Template functions live in `*.template.ts` beside their generator.
|
|
44
|
-
- Use `{{placeholder}}` syntax replaced via `.replace(/{{placeholder}}/g, value)`.
|
|
45
|
-
- `FUNC{{ <code> }}` embeds runnable JS in generated output (processed by `utils/template.ts → format()`).
|
|
46
|
-
|
|
47
|
-
### Naming
|
|
48
|
-
|
|
49
|
-
| Artifact | Convention | Example |
|
|
50
|
-
|----------|-----------|---------|
|
|
51
|
-
| Generated files | `{DocName}{Type}.gen.ts` | `UserController.gen.ts` |
|
|
52
|
-
| Controller class | PascalCase | `UserController` |
|
|
53
|
-
| REST endpoint | lowercase `documentName` | `/user`, `/userContact` |
|
|
54
|
-
| Template function | camelCase default export | `controllerTemplate()` |
|
|
55
|
-
| Role class | `Role{Name}` | `RoleAdmin` |
|
|
56
|
-
|
|
57
|
-
### JSON Schema extensions
|
|
58
|
-
|
|
59
|
-
Custom `x-*` properties drive generation — see [docs/vexJsonSchema.md](../docs/vexJsonSchema.md):
|
|
60
|
-
|
|
61
|
-
- `x-documentConfig` — REST methods, document name
|
|
62
|
-
- `x-foreignKey` — relationships ([docs/ForeignKey.md](../docs/ForeignKey.md))
|
|
63
|
-
- `x-vexData: "role"` — marks role field for RBAC
|
|
64
|
-
- `x-format: "ObjectId"` — MongoDB ObjectId handling
|
|
65
|
-
|
|
66
|
-
### Path aliases
|
|
67
|
-
|
|
68
|
-
`tsconfig.json` maps `~/*` → `src/*`. Use `~/generators/...` style imports.
|
|
69
|
-
|
|
70
|
-
## Key docs (link, don't duplicate)
|
|
71
|
-
|
|
72
|
-
- [docs/vexJsonSchema.md](../docs/vexJsonSchema.md) — full schema definition guide
|
|
73
|
-
- [docs/ForeignKey.md](../docs/ForeignKey.md) — foreign-key joins and `join`/`select` params
|
|
74
|
-
- [docs/appGenerated/auth.md](../docs/appGenerated/auth.md) — JWT rolling keys, OAuth2 setup
|
|
75
|
-
- [docs/developmentNote.md](../docs/developmentNote.md) — dev conventions, `FUNC{{ }}` syntax
|
|
76
|
-
- [docs/roadMap/](../docs/roadMap/) — released features and upcoming plans
|
|
77
|
-
|
|
78
|
-
## Pitfalls
|
|
79
|
-
|
|
80
|
-
- **`output/` is regenerated** — never edit `*.gen.ts` files by hand; changes will be overwritten on next `vex` run.
|
|
81
|
-
- **Schema ↔ filename mismatch** — `x-documentConfig.documentName` must match the JSON schema filename (e.g. `User.json` → `"documentName": "User"`).
|
|
82
|
-
- **`required` field format** — the preprocessor normalises `required: true` on individual properties into a root-level `required: string[]`, but source schemas should use the array form.
|
|
83
|
-
- **No test runner** — confirm changes by running `npm run dev` and inspecting `output/`.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
## Core Rule
|
|
87
|
-
|
|
88
|
-
Respond like smart caveman. Cut articles, filler, pleasantries. Keep all technical substance.
|
|
89
|
-
|
|
90
|
-
## Grammar
|
|
91
|
-
|
|
92
|
-
- Drop articles (a, an, the)
|
|
93
|
-
- Drop filler (just, really, basically, actually, simply)
|
|
94
|
-
- Drop pleasantries (sure, certainly, of course, happy to)
|
|
95
|
-
- Short synonyms (big not extensive, fix not "implement a solution for")
|
|
96
|
-
- No hedging (skip "it might be worth considering")
|
|
97
|
-
- Fragments fine. No need full sentence
|
|
98
|
-
- Technical terms stay exact. "Polymorphism" stays "polymorphism"
|
|
99
|
-
- Code blocks unchanged. Caveman speak around code, not in code
|
|
100
|
-
- Error messages quoted exact. Caveman only for explanation
|
|
101
|
-
|
|
102
|
-
## Code Style
|
|
103
|
-
- always consider readability and maintainability.
|
|
104
|
-
- actively split different workflow's code into functions instead of large monolithic blocks.
|
|
105
|
-
- define types, avoid use `any` or `unknown` as possible.
|
|
106
|
-
- name variables, functions, interface, classes descriptively.
|