Skip to main content

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)

ObjectTablePurpose
AddressADDRESSAddress data for places
CategoryCATEGORYProduct categories
DiscountDISCOUNTDiscount definitions
DiscountPeriodDISCOUNTPERIODDiscount validity periods
DiscountProductDISCOUNTPRODUCTDiscount–product associations
EmployeeSTAFFStaff/employee records
ExtraEXTRAExtra options (add-ons)
ExtraPeriodEXTRAPERIODExtra validity periods
ExtraOptionEXTRAPRODUCTOPTExtra option definitions
ExtraProductEXTRAPRODUCTExtra–product associations
ExtraTableEXTRATABLEExtra–table associations
FamilyFAMILYProduct families
FamilyPeriodFAMILYPERIODFamily validity periods
FamilyProductFAMILYPRODUCTFamily–product associations
MixedPayment (MixedPay)TICKETMIXEDPAYMixed payment records
OfferOFFEROffer definitions
OfferPeriodOFFERPERIODOffer validity periods
OfferOptionOFFERPRODUCTOPTOffer option definitions
OfferProductOFFERPRODUCTOffer–product associations
PlacePLACEPlace/business entities
PreselectPRESELECTPreselection definitions
PrintDevice (Printer)PRINTERPrint device configuration
ProductPRODUCTProduct catalog
ProductOptPRODUCTOPTProduct options
QrCodeQRCODEQR code / table identifiers
QrScanQRSCANQR scan records
SessionSESSIONUser/guest sessions
TicketTICKETSales tickets
TicketDiscountTICKETDISCOUNTTicket discount line items
TicketInvoiceTICKETINVOICETicket invoice data
TicketOfferTICKETOFFERTicket offer line items
TicketExtraTICKETEXTRATicket extra line items
TicketOptionTICKETOPTIONTicket option line items
TicketProductTICKETPRODUCTTicket product line items
UserUSERUser accounts

View Objects

View objects wrap DataObjects with computed properties, subscriptions, and a Proxy for unified access:

ViewWrapsPurpose
CategoryViewCategoryCategory with computed properties
DiscountViewDiscountDiscount with period/product logic
EmployeeViewEmployeeEmployee with place/role info
ExtraViewExtraExtra with options and products
FamilyViewFamilyFamily with products
OfferViewOfferOffer with options and products
PlaceViewPlacePlace with address, catalog, etc.
PreselectViewPreselectPreselect with options
ProductViewProductProduct with pricing, options
ProductOptViewProductOptProduct option view
QrCodeViewQrCodeQR code with table info
TicketViewTicketTicket with line items, totals
TicketDiscountViewTicketDiscountTicket discount line view
TicketOfferViewTicketOfferTicket offer line view
TicketExtraViewTicketExtraTicket extra line view
TicketProductViewTicketProductTicket product line view
UserViewUserUser with employees, places

Services

ServicePurpose
cacheServiceIndexedDB/localStorage persistence; CacheManager integration
syncServiceReal-time server sync, Connection, PendingQueue, refresh cycles
dataServiceMain injectable; store, alives, session, user, place, qrcode; commits
eventsNotifierEvent logging (LOGIN, GUEST, DRAWER) for registry notifications
loginServiceLogin 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, optional alias, default, volatile
  • relate: Array of relationship definitions with direction, target, by, name, reason, child

Supported field types:

  • string — Text values
  • file — File URLs (url/b64) for uploads
  • number — Numeric values
  • date — Date values (MySQL-compatible)
  • boolean — Boolean flags
  • objid — Object references (foreign keys)

Relations:

  • > — 1:1 (parent reference); defines a getter/setter for the related object
  • < — 1:N (children collection); auto-generates Add<Name>(), Del<Name>() methods and array getters

2. Relations

Relations are bidirectional and support:

  • 1:1 (>) — Parent reference; e.g. place.addressAddress
  • 1:N (<) — Children collection; e.g. ticket.productsTicketProduct[]

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 Proxyget Proxy merges ViewObject and DataObject properties
  • Add computed properties (e.g. totals, formatted prices)
  • Subscribe to OnRefresh for reactive updates
  • Are managed through aliveItems using 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:

  • storedataStorage instance (resolved/awaiting maps by table)
  • alivesaliveItems for 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

LibraryProvides
@unpispas/upp-baseadhocService, stateService, clockService, languageService, viewService, logsService, storeService, identificationService, toastService, alertService, configService
@unpispas/upp-defsAppConstants, 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.