Commit 17d7f87
Typed projection views + target runtime flag (0.11.6) (#72)
* feat(codegen-ts): typed projection view columns + honor allowlists:false
Projection (view) codegen had two gaps that made a generated `.existing()`
pgView unusable for a typed read:
- It emitted `pgView(name, {})` with no column map, so `db.select().from(view)`
yielded `{}` rows. Now emits the typed column map from the projection fields
(honoring @dbColumnType — e.g. a passthrough of a jsonb column → `jsonb(...)`,
timestamps → `timestamp(..., { mode })`), carrying `.notNull()` (the only table
modifier valid on an existing view).
- It always imported `@metaobjectsdev/runtime-ts` for the filter/sort allowlists,
ignoring the `allowlists` flag that entity-file already honors. renderEntityFile
now threads `allowlists` (+ `timestampMode`) to renderProjectionDecl, which omits
the allowlists (and the runtime-ts import) when false — so a dependency-free
consumer gets compilable output.
Adds projection-decl regression tests. Verified end-to-end against a real
consumer (typed view-backed reads compile + run).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* feat(codegen-ts): projection passthroughs resolve value-object refs
A field.object passthrough in a projection collapsed to z.unknown() (Zod) and a
bare jsonb column (no $type), losing the value-object shape. Now the projection
declaration resolves @objectref the same way the entity codegen does:
- the read Zod schema references the VO's <Ref>InsertSchema (so z.infer carries
the VO shape, not unknown),
- the .existing() view column narrows to .$type<VO>() so a typed db.select()
returns the VO type.
Import modules resolve layout/package/extStyle-aware via the shared
valueObjectModuleSpecifier when a RenderContext is threaded (entity-file now
passes ctx), with a flat same-dir fallback for bare unit-test calls. Adds a
projection-decl regression test. Verified against a real consumer (view-backed
reads now carry the precise VO types).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* feat(codegen-ts): contract-only projection output (includeViewDecl flag)
Add an includeViewDecl option (default true) on the entityFile generator,
threaded to renderProjectionDecl. When false, the projection emits only the
read Zod schema + inferred type + constants — NO Drizzle .existing() view
declaration and no drizzle-orm import. This lets a projection's contract type
be generated into a runtime-free types package (e.g. a shared package consumed
by a web client) while the Drizzle view stays in the DB-layer target.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* refactor(codegen-ts): replace includeViewDecl with a target-level runtime flag
The `includeViewDecl` option (added on this branch) was scoped to the wrong
concept — it singled out the projection's view declaration, when the real axis
is the TARGET's audience: a server package wants the full DB layer, a contract
package consumed by a UI client wants types only. Per-artifact "drop this one
binding" booleans don't generalize: the next consumer needs `includeTableDecl`,
then `includeQueryHelpers`, and each target has to remember to set them all.
Replace it with one flag on the target: `runtime` (default true).
- `runtime: false` = a contract-only target. Every object renders as its plain
shape (interface + Zod), every projection as its read schema + inferred type.
No drizzle-orm (no pgTable / pgView), no runtime-ts allowlists. The flag lives
on ResolvedTarget, so it reaches every template as `ctx.selfTarget.runtime`
with no new plumbing.
- `allowlists` stays as the finer Fastify-vs-Hono opt-out WITHIN a runtime
target — it's a different axis (runtime-ts dependency, not drizzle).
Views stop being special: a contract projection drops its pgView the same way a
contract entity drops its pgTable. EntityFileOpts loses `includeViewDecl`; the
low-level renderProjectionDecl keeps its opt (driven from the target now).
Tests: add a contract-target (runtime:false) block asserting a projection keeps
its Zod schema + type but emits no pgView/drizzle-orm, and a write-through entity
renders its plain shape with no pgTable. 818 pass.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* fix(codegen-ts-react,tanstack): add runtime to cross-target test ResolvedTarget literals
The new required `runtime` field on ResolvedTarget broke the workspace typecheck
in the two client codegen packages, whose cross-target tests construct target
literals directly. codegen-ts's own tests were already updated; these two siblings
typecheck against codegen-ts's built dist and were missed.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 9a226fe commit 17d7f87
15 files changed
Lines changed: 325 additions & 31 deletions
File tree
- server/typescript/packages
- codegen-ts-react/test
- codegen-ts-tanstack/test
- codegen-ts
- src
- templates
- test
- projection
- templates
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
121 | 134 | | |
122 | 135 | | |
123 | 136 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
195 | 203 | | |
196 | 204 | | |
197 | 205 | | |
| 206 | + | |
| 207 | + | |
198 | 208 | | |
199 | 209 | | |
200 | 210 | | |
| |||
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
| 217 | + | |
207 | 218 | | |
208 | 219 | | |
209 | 220 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
Lines changed: 22 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| |||
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
46 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
65 | 75 | | |
66 | 76 | | |
67 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
68 | 83 | | |
69 | 84 | | |
70 | 85 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
76 | 92 | | |
77 | 93 | | |
78 | 94 | | |
| |||
Lines changed: 91 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
17 | 23 | | |
18 | 24 | | |
| |||
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
28 | 55 | | |
29 | 56 | | |
30 | 57 | | |
| |||
64 | 91 | | |
65 | 92 | | |
66 | 93 | | |
67 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
68 | 108 | | |
69 | 109 | | |
70 | 110 | | |
| |||
93 | 133 | | |
94 | 134 | | |
95 | 135 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
99 | 175 | | |
100 | 176 | | |
101 | 177 | | |
| |||
114 | 190 | | |
115 | 191 | | |
116 | 192 | | |
117 | | - | |
| 193 | + | |
| 194 | + | |
118 | 195 | | |
119 | 196 | | |
120 | 197 | | |
121 | | - | |
122 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
123 | 203 | | |
124 | 204 | | |
125 | 205 | | |
| |||
137 | 217 | | |
138 | 218 | | |
139 | 219 | | |
140 | | - | |
141 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
142 | 223 | | |
143 | 224 | | |
144 | 225 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
247 | 301 | | |
0 commit comments