Skip to content

This page is for integrators and platform engineers who create or read stores through the API, or need to know exactly how the platform decides where an entry is written and which spaces can read it.

A data store is the physical partition that a data entity’s entries are written into. Every data entry carries a single store reference, and that reference decides which partition the entry lives in and, therefore, which spaces can read it. Stores are not a general-purpose key–value cache for builder code; they are the storage-routing layer that sits underneath a data entity’s entries and is driven by per-entity store rules. Conceptually, stores are dedicated units categorized by type to define the scope of sharing and permissions for an entity’s entries.

OSOS supports multi-store routing: an entry is written to a single store (the highest-priority store available to the current space) but reads aggregate across all stores available to that space.

Availability: Long-standing. The store-rules model and the Stores API predate the 1.2 milestone, so treat this as a foundational, always-present capability rather than a recent feature.

There are three kinds of store, defined by DataStoreTypeEnum (backend/packages/osos-shared/src/models/enums.ts):

TypeNumeric valueScopePersisted as a DataStore document?
Public0One global store shared by every spaceNo — virtual/default
Private1One store per spaceNo — virtual/default
Shared2A store spanning two or more explicitly selected spacesYes
  • Public store — created automatically with the entity; holds data accessible from all spaces. Only its weight can be adjusted.
  • Private store — created automatically with the entity; holds data accessible only within the owning space. Only its weight can be adjusted.
  • Shared store — defined by an administrator when needed; enables sharing data between specific spaces chosen at creation. The administrator selects the participating spaces and sets a weight.

Only Shared stores are real documents in the DataStore collection and are the only type you create, read, or update through the Stores API. Public and Private are synthesised at runtime from fixed identifiers and never stored as DataStore rows.

From backend/packages/osos-loopback/src/store/types.ts:

ConstantValue
PUBLIC_STORE_ID"PUBLIC"
PRIVATE_STORE_ID"PRIVATE"
PUBLIC_STOREReferenceProperty { dataEntity: "DataStore", dataEntry: "PUBLIC" }
PRIVATE_STORE(spaceId)ReferenceProperty { dataEntity: "DataStore", dataEntry: "PRIVATE_<spaceId>" }

The public store has one fixed dataEntry (PUBLIC). Each space gets its own private store whose dataEntry is PRIVATE_<spaceId>.

A data entity owns a list of store rules (dataEntity.storeRules: StoreRule[]). A store rule (store-rule.model.ts) has three fields:

FieldTypeNotes
typeDataStoreTypeEnum (number)Public / Private / Shared
storeIdstring | nullSet only when type === Shared; the DataStore id
prioritynumber (required)Higher priority wins when routing a write

When a data entity is created, it is seeded with two default rules (StoreService.defaultStoreRule):

RuleTypestoreIdpriority
Public defaultPublicPUBLIC_STORE_ID ("PUBLIC")100
Private defaultPrivatePRIVATE_STORE_ID ("PRIVATE")50

These defaults are attached in the create-data-entity and create-virtual-data-entity command handlers. Adding a Shared store to an entity appends a third rule (with the store’s id and the requested weight).

In the API surface the store rule’s priority is exposed as weight. They are the same value; the DTOs use weight, the persisted model uses priority.

StoreService.getStoreForWrite(storeRules, spaceId) decides where a new entry is written:

  1. Drop any Shared rule whose store does not include the current spaceId in its spaces list. Public and Private rules are always kept.
  2. From the remaining rules, pick the one with the highest priority.
  3. Resolve it to a ReferenceProperty:
    • Shared → { dataEntity: "DataStore", dataEntry: <storeId> }
    • Private → PRIVATE_STORE(spaceId)
    • anything else → PUBLIC_STORE

Because a freshly created Shared store is given a weight/priority, its value relative to the Public (100) and Private (50) defaults determines whether new entries in the participating spaces land in the shared store or fall back to the public/private defaults.

StoreService.getStoresForRead(spaceId) returns the set of stores visible from a space: the Public store, that space’s Private store, and every Shared store whose spaces include the space. The entry-read/validation paths (for example in data-entry-writer.service.ts) check that an entry’s store.dataEntry is in this set; an entry whose store is not visible from the current space is treated as not found in that space. This is the mechanism by which stores scope entry visibility across spaces.

data-store.model.ts — persisted only for Shared stores. Extends Identified<UUID> (so id is a UUID).

FieldTypeRequiredNotes
nameLocalizedValueYesLocalised display name
typeDataStoreTypeEnum (number)YesIn practice always Shared (2) for persisted stores
dataEntitystringYesId of the owning data entity
spacesReferenceProperty[]YesThe spaces the store spans
descriptionNullableLocalizedValueNo
creationInfoActionInfoNoWho/when created (with optional delegatee)
updateInfoActionInfoNoWho/when last updated

Persistence is a plain LoopBack DefaultCrudRepository (DataStoreRepository) over the Mongo datasource.

All endpoints live in StoresController and require authentication via the OSOS Auth2 LoopBack strategy. They are all scoped to a data entity by entityId in the path. Before doing anything, each handler loads the entity and runs Helper.validateDataEntityExistsActive (the entity must exist and be active).

MethodPathPurpose
POST/v1/entities/{entityId}/storesCreate a Shared store for the entity
GET/v1/entities/{entityId}/storesList all stores for the entity (defaults + shared)
GET/v1/entities/{entityId}/stores/{storeId}Get one store rule / store
PUT/v1/entities/{entityId}/stores/{storeId}Update a store

Every endpoint returns this shape (or an array of it):

FieldTypeNotes
storeIdstringStore id, or "PUBLIC" / "PRIVATE" for the defaults
storeNameLocalizedValueOnly populated for Shared stores
typeDataStoreTypeEnum (number)Required
descriptionNullableLocalizedValueOptional; Shared only
spacesReferenceProperty[]Optional; Shared only
weightnumberThe store rule priority

For Public/Private entries the response carries only storeId, type, and weight — storeName, description, and spaces are left unset because those stores have no DataStore document.

Create a store — POST /v1/entities/{entityId}/stores

Section titled “Create a store — POST /v1/entities/{entityId}/stores”

Request body (CreateDataStoreRequestDto, which extends DataStore and adds weight):

FieldTypeRequiredNotes
nameLocalizedValueYes
typeDataStoreTypeEnum (number)YesMust be 2 (Shared) — see validation
spacesReferenceProperty[]YesAt least two, no duplicates
descriptionNullableLocalizedValueNo
weightnumberYesStore rule priority; must be unique within the entity
dataEntitystring—Ignored in the body; the controller overwrites it with entityId from the path

Server-side flow:

  1. Reject if any existing store rule on the entity already has priority === weight → StoreWithSameWeightExistsException.
  2. storeDto.dataEntity is forced to the path entityId.
  3. StoreService.createStore validates (see below) and persists the DataStore, stamping creationInfo/updateInfo with the caller (and delegatee when acting on behalf of another user).
  4. A new StoreRule { storeId, priority: weight, type } is appended to the entity’s storeRules.
  5. An UpdateDataEntityCommand is published on the service bus and a token is registered via InvokerService.registerToken. The rule attachment to the entity is therefore asynchronous / eventually consistent — the HTTP response returns before the entity update is confirmed.

Response: StoresResponseDto for the created store (storeName, description, spaces, type, weight, storeId).

Example request:

{
"name": { "en": "Regional shared store" },
"type": 2,
"spaces": [
{ "dataEntity": "Space", "dataEntry": "space-a" },
{ "dataEntity": "Space", "dataEntry": "space-b" }
],
"description": { "en": "Entries visible to both regional spaces" },
"weight": 75
}

Create-time validation (validateCreateStore)

Section titled “Create-time validation (validateCreateStore)”
ConditionExceptionError code
Fewer than 2 spacesNotEnoughStoreSpacesSelectedExceptionNOT_ENOUGH_STORE_SPACES_SELECTED
Duplicate space idsStoreSelectedSpacesDuplicationNotAllowedExceptionSELECTED_SPACES_SHOULD_NOT_HAVE_DUPLICATION
type !== SharedOperationNotSupportedForThisTypeOPERATION_NOT_SUPPORTED_FOR_THIS_STORE_TYPE
Weight collides with an existing ruleStoreWithSameWeightExistsExceptionSTORE_WITH_SAME_WEIGHT_ALREADY_EXIST

A source comment confirms the intent: “At the moment of implementation only supports type: shared.” Creating Public or Private stores through the API is not supported.

List stores — GET /v1/entities/{entityId}/stores

Section titled “List stores — GET /v1/entities/{entityId}/stores”

Optional query parameter filterCriteria (a FilterCriteria<DataStore>) is merged with a forced where.dataEntity = entityId before querying, so filters only ever match this entity’s Shared stores.

The response concatenates:

  1. Default rules — every store rule whose type !== Shared (i.e. the Public and Private defaults), each returned as { storeId, type, weight }.
  2. Shared stores — fetched from the DataStore collection for this entity, each returned with full detail and its weight looked up from the matching store rule’s priority.

For Shared stores the service also resolves each space reference: it loads the matching DataEntryIndex rows and attaches the space’s index meta as a _resolved field on each space reference (used to render the space’s display metadata without a second call).

Get one store — GET /v1/entities/{entityId}/stores/{storeId}

Section titled “Get one store — GET /v1/entities/{entityId}/stores/{storeId}”

Looks up the store rule on the entity by storeId.

  • If no rule matches → DataSourceStoreNotExist.
  • If the rule’s type !== Shared (a Public/Private default) → returns { type, weight, storeId } only, without hitting the DataStore collection.
  • If the rule is Shared → loads the DataStore (via getStoreById, which throws DataSourceStoreNotExist on ENTITY_NOT_FOUND) and returns full detail plus the rule’s weight.

Update a store — PUT /v1/entities/{entityId}/stores/{storeId}

Section titled “Update a store — PUT /v1/entities/{entityId}/stores/{storeId}”

Request body (UpdateDataStoreRequestDto) — all fields optional, treated as a partial update:

FieldTypeNotes
nameLocalizedValueShared stores only
descriptionNullableLocalizedValueShared stores only
weightnumberNew store-rule priority
spacesReferenceProperty[]Shared stores only; must have at least 2 entries

Server-side flow:

  1. The store rule must exist on the entity → else DataSourceStoreNotExist.
  2. If weight is provided and collides with another rule’s priority → StoreWithSameWeightExistsException.
  3. If the rule is Shared, StoreService.updateStore updates the DataStore document. It rejects a spaces array with fewer than 2 entries (NotEnoughStoreSpacesSelectedException), then merges each supplied field over the existing values (name, description, spaces) and refreshes updateInfo. type, dataEntity, and creationInfo are preserved. For Public/Private rules the DataStore collection is not touched.
  4. The store rule’s priority is set to the new weight (or left unchanged), the entity’s storeRules array is rewritten, and — as with create — an UpdateDataEntityCommand is published and a token registered (asynchronous / eventually consistent).

Note: updateStore uses the repository’s updateById, which rebuilds the model before writing. DataStore’s constructor does not force-seed array fields, so the omitted-field merge is done explicitly in updateStore. If you extend the model, keep this in mind (see the repository’s migration guidance on partial updates).

Collated store indexes for list reads Since 1.10

Section titled “Collated store indexes for list reads Since 1.10”

Every entity list read starts by matching the entry’s store (then its state and virtual flag), and it runs with the entity collation {locale: 'en', strength: 2}. MongoDB only uses an index whose collation matches the operation’s, and none of the implicit indexes had one, so on a large entity that leading store match was a collection scan.

From 1.10 each non-virtual entity also carries:

  • collated twins of the implicit store and sharingLevel indexes, and
  • a store-and-order index named IX_<entity>_store_metaOrder_state_ci (keys store.dataEntry, value._metaOrder.value, _id, then the state/virtual filter), so a list page sorts and skips on index keys instead of in memory.

New entities get them when they are created; existing entities receive them through data-service migrations 1.10.0-a38, a41 and a44. The indexes are built asynchronously by the indexing service, so a freshly upgraded tenant serves list reads from the new indexes only once its index queue has built them. There is nothing to configure, and store rules and the Stores API are unchanged. Virtual entities are skipped, because a MongoDB view cannot carry an index.

Error codeMeaning
NOT_ENOUGH_STORE_SPACES_SELECTEDA store needs at least two spaces
SELECTED_SPACES_SHOULD_NOT_HAVE_DUPLICATIONThe selected spaces contain duplicates
OPERATION_NOT_SUPPORTED_FOR_THIS_STORE_TYPEAttempted a create with a non-Shared type
STORE_WITH_SAME_WEIGHT_ALREADY_EXISTAnother store rule already uses this weight
DATA_SOURCE_STORE_... (DataSourceStoreNotExist)The store / store rule does not exist for this entity
  • Weight/priority is per-entity unique. You cannot have two store rules on the same entity with the same weight; both create and update enforce this.
  • Weight is the routing knob. New entries in a space are written to the highest-priority store rule that applies to that space. With the default weights the Public rule (100) outranks the Private rule (50), so new entries go to the public store unless the weights are changed. Set a Shared store’s weight above 100 to make it win for the spaces it spans; a weight between 50 and 100 only outranks the private default, which the public default already does, so it has no effect unless the Public weight has been lowered below it.
  • Shared stores must span ≥ 2 spaces with no duplicates, on both create and (when spaces is supplied) update.
  • Only Shared stores are manageable via the API. Public and Private stores exist implicitly on every entity and cannot be created or edited.
  • Rule attachment is eventually consistent. Create/update return before the UpdateDataEntityCommand is processed, so an immediately following read of the entity’s store rules may not yet reflect the change.
  • Cross-space visibility is enforced on read. An entry is only visible in a space whose read set (Public + that space’s Private + Shared stores covering it) contains the entry’s store.

Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27