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
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 exports Price, which wraps cnst.Price.
  • Import the sibling file. The path is ./price.constant in the same folder.
  • The body stays empty. by() already copies every field, and helpers go on the constant class, as the next section shows.

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.ts holds chain methods such as approve(); a scalar's document holds none.

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.LeaveInfo is data only. It lists the stored fields of the LeaveInfo scalar and no methods.
  • Browser code uses cnst.LeaveInfo. The db types 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 valueleaveInfo.document.ts
leaveInfo: db.LeaveInfo
One price label reused in product cards, order summaries and invoicesprice.constant.ts
price.getLabel()
An address summary built from city and streetaddress.constant.ts
address.getSummary()
A calculation across two values, such as a distancecoordinate.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.Price from 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

Released under the MIT License

Connect your AI to these docs

MCPhttps://akanjs.com/mcp
Copyright © 2026 Akan.js All rights reserved.System managed bybassman