YouBothAgent▾
You — Business rules and flows you own. Read these yourself.
Both — Know the idea; your agent follows the details.
Agent — Conventions and references your agent follows. Look up as needed.
Workspace▾
App & Library▾
Domain▾
Scalar▾
scalar.document.ts
price.document.ts is the server-side class of a scalar. It is one line that wraps the constant class, and it stays that way.akan create-scalar price writes it together with the other core files. Keep it even when the scalar needs nothing but fields and labels.Words used on this page
NameDescription
The constant class that server and browser both load: fields, defaults and helpers.
by(cnst.Price)
Builds a server-side class with the same fields as the constant class.
db.Price
The value's type in server code: its stored fields, without methods.
The Whole File
Import the constant file as
cnst and wrap its class with by(cnst.Price). The document class then has the same fields as the constant class:apps/<app>/lib/__scalar/price/price.document.ts
- Same name as the constant class. The
price/folder exportsPrice, which wrapscnst.Price. - Import the sibling file. The path is
./price.constantin the same folder. - The body stays empty.
by()already copies every field, and helpers go on the constant class, as the next section shows.



Only server code may import this file. A value import from
ui/, webkit/, page/, common/, *.store.ts, *.constant.ts or any .tsx fails lint. Use cnst.Price there; import type is still allowed.Helpers Go On The Constant
A helper that reads the scalar's fields, such as a label, a flag or a small calculation, belongs on the constant class. The document class keeps only the wrapper.
What you write
constant
dictionary
document
The value itself, for server and browser
Fields and defaults
✓
The value's shape, such as
amount: field(Float, { default: 0 }).enumOf(…)
✓
Enum classes such as
Currency, declared above the scalar class.Helper methods
✓
Display, predicate and small calculation methods such as
getLabel().Labels
Labels and descriptions
✓
An
[en, ko] label and description for every field and enum value.Server only
by(cnst.Price)
✓
The one-line wrapper that gives server code the
db.Price type.✓Lives in this fileNot here
So a price label is a short method on
Price in the constant file:apps/<app>/lib/__scalar/price/price.constant.ts
- Keep it short. Read the fields and return a display value, a boolean or a small calculated result.
- Unlike a database module. A
model.document.tsholds chain methods such asapprove(); a scalar's document holds none.


Never add a method to the document class. Nothing turns a stored price into a
Price document, so the method has no instance to run on, and browser code cannot import it at all.When You Use It
You rarely edit this file, but server code uses its type. A service method that takes a scalar value types it as
db.<Scalar>:libs/shared/lib/user/user.service.ts
db.LeaveInfois data only. It lists the stored fields of theLeaveInfoscalar and no methods.- Browser code uses
cnst.LeaveInfo. Thedbtypes stay on the server side.
Where each need goes
Reach for a helper when the same display or calculation shows up in several places. Anything that loads data stays in a service.
| When you need… | File |
|---|---|
| ↳ Example | |
| A service method that takes or returns the value | leaveInfo.document.ts |
| leaveInfo: db.LeaveInfo | |
| One price label reused in product cards, order summaries and invoices | price.constant.ts |
| price.getLabel() | |
An address summary built from city and street | address.constant.ts |
| address.getSummary() | |
| A calculation across two values, such as a distance | coordinate.constant.ts |
| Coordinate.getDistanceKm(a, b) | |
| Loading other records or calling a backend service | <model>.service.ts |
| this.userModel.getUser(userId) | |
Common mistakes
- Writing
getLabel()in the document class. Move it to the constant class, which server and browser code can both import. - Deleting the file because it is one line. Server code gets
db.Pricefrom it, so it stays beside the constant and dictionary. - Loading records inside a helper. A helper only reads its own fields; a query or a service call belongs in the parent module's service.
Read next