Ordering and limits
Unit ordering, UTF-16 string comparisons, maxAffectedKeys, permanent faults, pre-release storage rules, and current scope limits.
This page describes the ordering guarantees, safety limits, fault classes, and current boundaries of @streamsy/views.
Unit ordering and State semantics
Each circuit unit reads one page per input stream after its checkpoint offset, in input declaration order:
- Within a single input stream, items apply in stream order. Append order across distinct input streams is not preserved.
- Multiple changes to the same input key within one unit coalesce against the circuit's stored source integral.
- Deletes do not require
old_value. - A
resetcontrol retracts every stored row of that source. - A
snapshot-startcontrol preserves previously visible rows untilsnapshot-end, then retracts unseen keys. Snapshot bookkeeping persists across units. Bothresetand snapshot controls can visit an entire relation. - Numeric State keys use their string wire representation, while numeric row fields keep their numeric type.
- Views strips
undefinedmembers from decoded input objects at every depth and rejectsundefinedarray elements withViewDataFault. - Output messages are absolute upserts and deletes without
old_value. Every change emitted by a unit carriesheaders: { txid: unit.key }. Each unit appends at most one change per output collection and key pair; unchanged rows emit nothing.
A source consumed only by direct where filters keeps rows that match at least one of those filters. If any consumer reads the unfiltered source, the circuit keeps its full integral.
String, extrema, and top ordering
String comparisons (eq, ne, in, gt, gte, lt, lte), View.min, View.max, View.list, and top orderings use lexicographic UTF-16 code-unit ordering. Views performs no locale collation, case folding, or Unicode normalization. Equal encoded sort keys are ordered by encoded row key in UTF-8 byte order.
Rules for top:
limitmust be a finite positive integer.bymust end with a final ascending stable key term. Static plan validation accepts eitherView.key.asc()(which sorts by the encoded relation key) or an ascending reference to a field whose name ends inid(case-insensitive, such asrow.orderId.asc()). If your key field has another name (such asslugorcode), useView.key.asc(), or declaration throwsPlanCheckFailedwith codeunstable-top-order.topproduces a keyed State collection, not an ordered result list.StateTable.listreturns rows ordered by their wire keys, not by thetopsort order.
Bounding fan-out with maxAffectedKeys
Set the optional maxAffectedKeys option on View.circuit (or View.live) to a positive safe integer to cap the distinct affected relation keys processed in one unit, including intermediate relation keys. Joins also check candidate key counts before building large joined results.
For closure, Views checks candidate nodes within maxDepth - 1 edges below each changed edge in both graph images. Reparenting a subtree of s nodes between chains of heights h1 and h2 can change up to s * (min(h1, maxDepth) + min(h2, maxDepth)) closure rows. These changes count toward the unit limit. Each stored path has one part per edge, so a single descendant's paths grow quadratically with its depth up to maxDepth. Summed over all descendants, an untruncated chain's path storage grows cubically in its height.
- Passing a value that is not a positive safe integer throws
RangeErrorat declaration time. - When a unit exceeds the limit, the unit rolls back. Operator state, output streams, and the checkpoint keep their pre-unit state.
- The unit fails with a permanent
ViewDataFaultidentifying the offending key. maxAffectedKeysis not part of the plan hash. You can raise or adjust it and retry without raisinggeneration.- The limit bounds changed keys rather than unchanged rows read by an operator (for example, recomputing a fractional sum still reads the group's rows, and
View.listdoes not bound group size).
Permanent faults and error handling
A circuit unit can fail with a CircuitError (PlanChanged | ViewFault | ViewDataFault | ProjectionFault), and declaration time can throw ViewFault, PlanCheckFailed, or RangeError.
| Fault | _tag | Retryable | When it happens |
|---|---|---|---|
PlanChanged | "ViewPlanChanged" | No ([NonRetryable] = true) | The declared plan hash differs from the hash stored for the binding’s namespace. Exposes namespace, stored, and requested. Commits nothing |
ViewDataFault | "ViewDataFault" | No ([NonRetryable] = true) | Row-boundary or limit error during evaluation, such as exceeding maxAffectedKeys, an input key disagreeing with its key expression, unwrap() on an absent value, an unencodable route value, or an invalid predicate value. Exposes view, node, key, and reason. Rolls back the unit |
ViewFault | "ViewFault" | Non-retryable for transaction/layout faults; retryable otherwise | Setup or operational failure: missing owner transaction context or unsupported Postgres/MySQL layout version (marked [NonRetryable] = true), View.migrate on an unsupported SQL dialect, an unwrapped output passed to View.circuit, schema encode/decode error, or an internal engine error. Exposes message and optional cause |
PlanCheckFailed | "PlanCheckFailed" | No (compile time) | Invalid compiled plan IR during declaration. Exposes issues, each with code, view, optional nodeId, path, and message |
ProjectionFault | "ProjectionFault" | By reason | Storage, checkpoint, output, identity, or retirement faults from @streamsy/projection. See ProjectionFault |
Under Projection.attach and ProjectionWakeup.attach, non-retryable faults (PlanChanged, ViewDataFault, non-retryable ViewFault, and non-retryable ProjectionFault reasons such as identity-mismatch, invalid-output, or retired-generation) stop only the affected binding and record the failure in Projection.Registry. Other bindings continue running.
Storage layout and generation rule
@streamsy/views is pre-1.0. A change to the SQL operator-state layout or to internal plan naming requires raising generation, so affected bindings rebuild into fresh namespaces and output streams. A release that changes the layout or plan naming says so in the changelog with a Breaking change: marker. Raise generation on every affected circuit when you upgrade to that release. See Lifecycle and rebuilds.
Current limits
- SQL backends. Views supports SQLite, Postgres, and MySQL. See Postgres key and identifier limits and MySQL key and identifier limits.
- SQLite bind limit. The SQLite store computes index keys in JavaScript and binds at most 100 parameters per statement, fitting Cloudflare Durable Object SQLite limits.
- JSON object rows. Input collection values must be JSON objects, and collection codecs must require no Effect services.
- Equi-joins only. Join conditions must test equality between a left-only expression and a right-only expression.
- Closure string keys.
closurerequires string relation keys and stringparentexpressions. - Separate binding namespaces. Circuit parameters bind separate namespaces with independent operator state. Dynamic parameters-as-data across bindings are not supported.
- Unsupported features.
avg,distinct, fact folds, frontier rows, andold_valueon emitted upserts are not supported.