You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5d12334
Browse filesBrowse the repository at this point in the historyBrowse files
`agentDocsFile()`, `metamodelDocsFile()` and `docsSiteFile()` write to the target named
@@ -473,6 +486,33 @@ operands by those options. `meta migrate` warns for a decimal declared with `@pr
473
486
on SQLite or D1. `meta verify --codegen` names the `wire` block that reproduces committed output
474
487
generated under another setting.
475
488
489
+
### Types exported per entity
490
+
491
+
Code that talks to a generated entity imports these names, so they are a contract. Each
492
+
entity module (`<Entity>.ts`) exports six types. `entityTypeNames(obj)`, exported from
493
+
`@metaobjectsdev/codegen-ts`, returns the same six spellings for an owned generator, so it
494
+
need not rebuild them from the entity name.
495
+
496
+
| Type | Derived from | Use it for |
497
+
| --- | --- | --- |
498
+
|`<Entity>`| the Drizzle table, `InferSelectModel`| a row read back from the database: what `find<Entity>ById` and `create<Entity>` return |
499
+
|`<Entity>Insert`| the Drizzle table, `InferInsertModel`| a row as the database accepts it, before validation |
500
+
|`<Entity>Update`|`Partial<<Entity>Insert>`| the same, every column optional |
501
+
|`<Entity>Create`|`z.input` of `<Entity>InsertSchema`|**the argument of `create<Entity>`**, and what a client posts |
502
+
|`<Entity>Patch`|`z.input` of `<Entity>UpdateSchema`|**the argument of `update<Entity>`**, and what a client patches |
503
+
|`<Entity>Filter`| the `@filterable` and `@sortable` fields | the `filter`, `sort`, `limit` and `offset` options of `list<Entity>` and the generated hooks |
504
+
505
+
`Create` and `Patch` are the pair to use at a call site. They come from the Zod schemas the
506
+
functions validate with, so a renamed or dropped field is a compile error at every call.
507
+
`Insert` and `Update` come from the table and describe what the database takes. They are
508
+
looser than the validators, so prefer `Create` and `Patch` at the API boundary.
509
+
510
+
When the entity is a TPH discriminator base, the row type is `<Entity>Row`, because
511
+
`<Entity>` is the discriminated union over its subtypes. A read-only projection has no
512
+
table to insert into, so do not expect `Create` or `Patch` there; read its generated module
513
+
for what it exports. `test/entity-type-names.test.ts` in `codegen-ts` checks the table
514
+
against the golden `Subscriber` module.
515
+
476
516
### `<Entity>Names` — the physical names, as constants
477
517
478
518
`meta init` scaffolds a `names` generator, so a new project gets `<Entity>.names.ts`
0 commit comments