upp-data — Overview
upp-data is the data layer library of the UnPisPas monorepo. It provides schema-driven data objects, view wrappers, real-time synchronization with the backend, and session management. It sits on top of upp-base and upp-defs, and is consumed by applications such as unpispas-pos and upp-test.
UppDataModule
The Angular module is minimal — it only imports CommonModule:
@NgModule({
imports: [CommonModule],
})
export class UppDataModule {}
There are no standalone components or directives. The library is primarily a collection of injectable services and model classes.
Public API
The library exports the following from its main entry point (libs/upp-data/src/index.ts):
Model Objects (DataObjects)
| Object | Table | Purpose |
|---|---|---|
Address | ADDRESS | Address data for places |
Category | CATEGORY | Product categories |
Discount | DISCOUNT | Discount definitions |
DiscountPeriod | DISCOUNTPERIOD | Discount validity periods |
DiscountProduct | DISCOUNTPRODUCT | Discount–product associations |
Employee | STAFF | Staff/employee records |
Extra | EXTRA | Extra options (add-ons) |
ExtraPeriod | EXTRAPERIOD | Extra validity periods |
ExtraOption | EXTRAPRODUCTOPT | Extra option definitions |
ExtraProduct | EXTRAPRODUCT | Extra–product associations |
ExtraTable | EXTRATABLE | Extra–table associations |
Family | FAMILY | Product families |
FamilyPeriod | FAMILYPERIOD | Family validity periods |
FamilyProduct | FAMILYPRODUCT | Family–product associations |
MixedPayment (MixedPay) | TICKETMIXEDPAY | Mixed payment records |
Offer | OFFER | Offer definitions |
OfferPeriod | OFFERPERIOD | Offer validity periods |
OfferOption | OFFERPRODUCTOPT | Offer option definitions |
OfferProduct | OFFERPRODUCT | Offer–product associations |
Place | PLACE | Place/business entities |
Preselect | PRESELECT | Preselection definitions |
PrintDevice (Printer) | PRINTER | Print device configuration |
Product | PRODUCT | Product catalog |
ProductOpt | PRODUCTOPT | Product options |
QrCode | QRCODE | QR code / table identifiers |
QrScan | QRSCAN | QR scan records |
Session | SESSION | User/guest sessions |
Ticket | TICKET | Sales tickets |
TicketDiscount | TICKETDISCOUNT | Ticket discount line items |
TicketInvoice | TICKETINVOICE | Ticket invoice data |
TicketOffer | TICKETOFFER | Ticket offer line items |
TicketExtra | TICKETEXTRA | Ticket extra line items |
TicketOption | TICKETOPTION | Ticket option line items |
TicketProduct | TICKETPRODUCT | Ticket product line items |
User | USER | User accounts |
View Objects
View objects wrap DataObjects with computed properties, subscriptions, and a Proxy for unified access:
| View | Wraps | Purpose |
|---|---|---|
CategoryView | Category | Category with computed properties |
DiscountView | Discount | Discount with period/product logic |
EmployeeView | Employee | Employee with place/role info |
ExtraView | Extra | Extra with options and products |
FamilyView | Family | Family with products |
OfferView | Offer | Offer with options and products |
PlaceView | Place | Place with address, catalog, etc. |
PreselectView | Preselect | Preselect with options |
ProductView | Product | Product with pricing, options |
ProductOptView | ProductOpt | Product option view |
QrCodeView | QrCode | QR code with table info |
TicketView | Ticket | Ticket with line items, totals |
TicketDiscountView | TicketDiscount | Ticket discount line view |
TicketOfferView | TicketOffer | Ticket offer line view |
TicketExtraView | TicketExtra | Ticket extra line view |
TicketProductView | TicketProduct | Ticket product line view |
UserView | User | User with employees, places |
Services
| Service | Purpose |
|---|---|
cacheService | IndexedDB/localStorage persistence; CacheManager integration |
syncService | Real-time server sync, Connection, PendingQueue, refresh cycles |
dataService | Main injectable; store, alives, session, user, place, qrcode; commits |
eventsNotifier | Event logging (LOGIN, GUEST, DRAWER) for registry notifications |
loginService | Login flow, session/place selection, guest access |
Importing
import {
dataService,
syncService,
cacheService,
loginService,
eventsNotifier,
Ticket,
TicketView,
Place,
PlaceView,
} from '@unpispas/upp-data';
Key Concepts
1. Schema-driven DataObjects
Objects are defined by a schema (table name, fields, relations). The CreateObject() function dynamically generates a TypeScript class with typed getters/setters from the schema.
Schema structure:
- fields: Array of column definitions with
name,type, optionalalias,default,volatile - relate: Array of relationship definitions with
direction,target,by,name,reason,child
Supported field types:
string— Text valuesfile— File URLs (url/b64) for uploadsnumber— Numeric valuesdate— Date values (MySQL-compatible)boolean— Boolean flagsobjid— Object references (foreign keys)
Relations:
>— 1:1 (parent reference); defines a getter/setter for the related object<— 1:N (children collection); auto-generatesAdd<Name>(),Del<Name>()methods and array getters
2. Relations
Relations are bidirectional and support:
- 1:1 (
>) — Parent reference; e.g.place.address→Address - 1:N (
<) — Children collection; e.g.ticket.products→TicketProduct[]
Methods like AddChild, DelChild, SetChild manage relations and update the Info store when changes are committed.
3. ViewObject Pattern
Each DataObject can have a ViewObject via the viewProxy getter. ViewObjects:
- Wrap DataObjects with a Proxy —
get Proxymerges ViewObject and DataObject properties - Add computed properties (e.g. totals, formatted prices)
- Subscribe to
OnRefreshfor reactive updates - Are managed through
aliveItemsusing WeakRef for automatic GC when no longer referenced
Access via data.alives.get(dataObject) returns the ViewObject for the given DataObject.
4. dataService
The main injectable service. It provides:
- store —
dataStorageinstance (resolved/awaiting maps by table) - alives —
aliveItemsfor ViewObject lifecycle - session — Current
Session - user — Current
User(logged-in) - place — Current
Place(selected place) - qrcode — Current
QrCode(guest table)
It handles commits (Commit, Flush), FetchByObjid, and coordinates with syncService for real-time updates.
5. Synchronization
syncService manages:
- Connection — Create/update/delete server connection; triggers (SESSION, QRCODE, USER, PLACE)
- Periodic refresh cycles — Polls server for updates
- PendingQueue — Priority-based processing of server updates; stages for SESSION, PLACE, etc.
- CacheManager — Loads/saves session and place data to IndexedDB/localStorage via
cacheService
Dependencies
| Library | Provides |
|---|---|
@unpispas/upp-base | adhocService, stateService, clockService, languageService, viewService, logsService, storeService, identificationService, toastService, alertService, configService |
@unpispas/upp-defs | AppConstants, GenericUtils, PriceType, PriceInfo |
Architecture Diagram
flowchart TB
subgraph Services
dataService[dataService]
syncService[syncService]
cacheService[cacheService]
loginService[loginService]
end
subgraph DataStores
dataStorage[(dataStorage)]
aliveItems[(aliveItems)]
end
subgraph SchemaFlow
Schema[Schema Definition]
CreateObject[CreateObject]
BaseClass[BaseClass]
ConcreteClass[Concrete DataObject]
end
subgraph ObjectModel
DataObject[DataObject]
ViewObject[ViewObject]
end
dataService --> dataStorage
dataService --> aliveItems
dataService --> syncService
syncService --> cacheService
dataService --> loginService
Schema --> CreateObject
CreateObject --> BaseClass
BaseClass --> ConcreteClass
ConcreteClass --> DataObject
DataObject -->|viewProxy| ViewObject
ViewObject -->|Proxy| DataObject
aliveItems -->|WeakRef| ViewObject
dataService -->|store| DataObject
dataService -->|alives.get| ViewObject
Summary
- upp-data is the data layer: schema-driven objects, views, sync, and session management.
- UppDataModule is minimal (CommonModule only).
- Public API: Model objects, View objects, and services (dataService, syncService, cacheService, loginService, eventsNotifier).
- Key concepts: Schema → CreateObject → BaseClass → ConcreteClass; DataObject ↔ ViewObject via Proxy and aliveItems; dataService at the center; syncService for real-time and cache.
- Dependencies: upp-base and upp-defs.