Skip to content

About

Larena package: larena/storage

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

159 Commits

Folders and files

Repository files navigation

Larena Storage

Universal dynamic data storage layer for typed schemas, records, lists, query boundaries, persistence profiles, validation pipelines and portable SitePack-compatible data models.

StorageWorkbench::filterOperators() reports executable filter operators by Property field type from the same rule table used by the guarded query runtime. Relative periods remain a host concern. Storage validates and persists typed values; the read-only, plain-text value projection belongs to Property, while Admin/Dataview own visual rendering and owner-bound reference label resolution.

Current implementation state: partial data/content foundation runtime. The package has an in-memory runtime slice plus an additive database-native slice for immutable schema versions, immutable record versions, compare-and-swap, Access authorization, transactional Security Audit and exact public projection.

The durable slice also exposes listCurrentRecords() for generic current-head queries. It joins the package-owned record heads to their exact immutable versions in the database, resolves a QueryScopeProvider decision before any Storage data lookup. Caller filters accept only schema-known public fields with exact eq; a trusted provider may additionally add exact typed public or protected filters, but cannot remove/change caller filters or use unknown, admin or arbitrary operators. Queries order by stable record identity and bound pages to 1..100 items. Continuation tokens are HMAC-protected and bound to the exact schema, Property-normalized filters and resolved Access scope. Missing/denied/malformed scope, an absent cursor key, unknown fields/operators, hidden-field filters, tampering and cross-query/cross-scope reuse all fail closed. Returned items contain only schema-owned public values; owner references, protected/admin values and caller correlation material are not included.

This is not the older in-memory/local-development list adapter. It runs against the existing immutable version tables, needs no migration, and has disposable SQLite evidence that survives a PHP-process restart. The container binding uses the application key as the cursor integrity key and requires a bound canonical Access QueryScopeProvider; direct construction must supply both explicitly. Storage calls that provider with the operation-compatible resource type storage.record; the exact schema id remains inside the typed query and both cursor identities. Consumers must explicitly bind their chosen QueryScopeProvider interface before resolving Storage. Access intentionally does not provide a global default interface binding, and Storage fails closed when the consumer has not selected one. Package tests prove compatibility with the concrete PersistentGlobalRoleQueryScopeProvider; this is not a Root or production container-integration claim.

For durable typed content, the canonical container contract is Larena\Storage\Contracts\VersionedStorage backed by the database-native Larena\Storage\Runtime\VersionedStorage. The older LaravelDatabaseStorageAdapter delegates to the in-memory foundation and is not a persistent typed-content adapter.

The database-native slice now also exposes a bounded schema-evolution service. It can analyze, persist, explain and atomically apply only additive optional fields with empty constraints. Direct publication of schema version 2+ is blocked: callers must use a content-addressed immutable migration plan. Apply locks and rechecks the schema head, every record head and every immutable definition/value hash before it publishes a new schema version and matching schema_migration record revisions.

Workbench structures change fields without that rewrite: a field change registers the next schema version and keeps every record version as written; readers pass older versions through the read converter (StorageRecordConverter). Adding an optional field or removing one switches at once; a retype, a field made required or changed constraints first checks every record (inline up to 5000 records, above that as the storage.schema.migrate queue job) and switches only when all of them convert. See docs/developer/schema-evolution.md.

Schema-owning consumers may register an owner-neutral protection policy before Storage provider boot. Protected namespaces require the consumer's one-shot capability inside the exact outer transaction and connection; direct generic, forged, expired or replayed plan/apply calls fail closed before mutation. Storage does not issue consumer capabilities or own their aggregate workflow.

Initial immutable schema registration validates each exact Property type/version constraint set before any schema head or version is written. Unsupported keys, wrong scalar types and contradictory ranges fail closed without a success Audit event.

Immutable schemas admit exactly public, protected and admin visibility. protected is preserved as a distinct canonical value for owner packages such as Content. Database-native, in-memory and disposable-PDO public projections include only fields whose visibility is exactly public; protected, admin, hidden, encrypted, unknown, missing and invalid legacy visibility values fail closed and are omitted.

The validation capability is additive and fail-closed: a third-party Property registry that implements the original registry contract but not PropertyConstraintValidator cannot register a new Storage schema. Historical schema rows created before this preflight remain exact and readable, including their public/admin visibility projection, but an invalid historical constraint blocks every new record write with a stable code. Storage never rewrites that immutable history.

The versioned database contract deliberately separates historical reads from new writes:

  • readAdminVersion() returns an exact immutable version after an actor-based Access check;
  • readAdminCurrentVersion() resolves the current record for an owner after the same Access check and supports a consumer's next compare-and-swap;
  • compareAndSwap() always creates an update version from the exact current head supplied by the caller;
  • record creation and compare-and-swap accept only the current exact schema head, using schema-first locking to share the migration lock order;
  • caller correlation inputs are converted to opaque package-scoped hashes before persistence or Security Audit, so submitted content cannot be copied through that metadata channel;
  • Docara historical revision restoration belongs to Docara and reuses an exact immutable reference; this versioned Storage contract does not expose a restore-as-new mutation.

The package-owned version and migration tables are additive and protected by separate shared shape guards. Before the first create or drop, the guard validates the complete column contract plus primary-key composition and the explicit names/compositions of unique and secondary indexes through Laravel's portable schema inspection APIs. A compatible empty partial topology can be completed. Foreign, damaged or data-bearing partial topologies fail closed without partial DDL. A clean unused migration can be rolled back and reapplied; rollback refuses before dropping anything when typed-content rows exist. The plan/result tables additionally have isolated real-MySQL evidence for exact type/index contracts, restart, concurrent apply and cleanup.

The Storage-owned workbench treats a public structure as the pair (scope_ref, structure_id). It derives an opaque, deterministic Versioned Storage schema identifier from that pair, so independently authorized scopes may use the same ordinary public model name without sharing schema versions, records, history, queries, cursors or compare-and-swap state. The derived identifier contains no raw scope, path, disk, blob key or secret. The additive workbench identity migration preserves an existing single-scope model and refuses rollback once scoped workbench data exists, because flattening multiple scopes back to one global schema identity could lose or merge data.

A workbench structure can be archived and restored. An archived structure keeps its records and history, is listed only on request and accepts no record writes or structure edits. Permanent deletion is explicit and takes archived data only: purgeRecords() removes archived records, purgeStructure() removes an archived structure with all of its records. Both remove every version, localized value, publication row and relation edge in one transaction, are refused while a record outside the set references one inside it, and audit identifiers and counts only. A deleted structure's id cannot be used again. A field can be marked hidden; that is presentation only and keeps the field and its values.

The editor's document port (simai.document-port 1.0.0, src/DocumentPort) keeps a composition@1 field of a workbench record. Its history is read a page at a time (limit, before, before_publication, more): the drafts are read newest first in chunks of versions, never every version of the record, and a run of versions with the same document is still one draft.

A write's client_key is remembered for 30 days (DocumentPortReceiptSweep::RETENTION_DAYS), long enough for the editor to repeat a lost answer after a reconnect, a new sign-in or a closed laptop over a holiday. The command larena:storage:document-port:sweep [--days=30] (7 to 3650 days), which the package schedules daily, forgets older keys: a plain save's receipt is removed; a publication or a restore keeps its row without the key, so the history and the live publication stay as they were. A repeat of a forgotten client_key is a new operation, not the stored answer: a save or a publish is compared with the revision it names as any other (usually stale-revision, since the draft has moved), and a restore or a rollback makes a new draft or publication.

See docs/developer/schema-evolution.md for the bounded evolution contract and docs/developer/owned-table-shape-guard.md for the exact install, upgrade, diagnostic and rollback contracts.

This compatibility slice does not add a table, migration, route, provider, Content-owned behavior or live database operation. Production readiness, frontend readiness, encryption policy, SitePack portability and readiness of all Larena packages are not claimed.

S-STORAGE-01 is claimed only as TESTED. It does not change accepted Root or Workspace pins and does not claim adoption, runtime readiness or production readiness.

Canonical specifications are in simai/larena-specs.

Developer documentation starts at docs/developer/README.md.

About

Larena package: larena/storage

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages