@rindle/optimistic 0.1.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +66 -0
- package/dist/agg-overlay.d.ts +86 -0
- package/dist/agg-overlay.d.ts.map +1 -0
- package/dist/agg-overlay.js +224 -0
- package/dist/agg-overlay.js.map +1 -0
- package/dist/backend.d.ts +243 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +998 -0
- package/dist/backend.js.map +1 -0
- package/dist/client-id.d.ts +12 -0
- package/dist/client-id.d.ts.map +1 -0
- package/dist/client-id.js +60 -0
- package/dist/client-id.js.map +1 -0
- package/dist/client.d.ts +64 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +81 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
- package/src/agg-overlay.ts +257 -0
- package/src/backend.ts +1155 -0
- package/src/client-id.ts +61 -0
- package/src/client.ts +156 -0
- package/src/index.ts +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @rindle/optimistic
|
|
2
|
+
|
|
3
|
+
Optimistic writes over the local-first wasm engine (`OPTIMISTIC-WRITES-DESIGN.md`).
|
|
4
|
+
|
|
5
|
+
The local IVM engine **is** the rebase function: the wasm `Db` keeps an authoritative
|
|
6
|
+
`sync` fork per base table and reconciles every server batch by **rewinding** the live
|
|
7
|
+
pipeline to the authoritative state and **re-invoking** the still-pending client
|
|
8
|
+
mutators against it — no inverse mutations, no second materialization. This package is
|
|
9
|
+
the client glue around that engine cycle:
|
|
10
|
+
|
|
11
|
+
- **Named client mutators** (`ClientRegistry`): `(tx, args) => void` against a
|
|
12
|
+
`MutationTx` (`get`/`add`/`remove`/`edit`; reads see the current base + the
|
|
13
|
+
transaction's own writes). Deterministic and replayable — a mutator is re-invoked on
|
|
14
|
+
every rebase, so a read-dependent `incrementScore(+5)` computed on a stale `10`
|
|
15
|
+
correctly becomes `105` after the server lands `100`.
|
|
16
|
+
- **cv-buffering** (§8.5): per-query data frames are `cv`-tagged and buffer; a
|
|
17
|
+
connection-level progress frame `{ cvMin, lmid, rejected }` releases everything
|
|
18
|
+
`cv ≤ cvMin` as one coherent step — no torn multi-query reads, ever. Buffer
|
|
19
|
+
overflow drops + re-hydrates (the one new client obligation).
|
|
20
|
+
- **Pending stack** of `(mid, name, args)` — never effects; `lmid` confirms (drop),
|
|
21
|
+
`rejected` snaps back (the engine cycle removes the phantom effects).
|
|
22
|
+
- **`ResultType`** per query (§6/§7): the **server channel's** state only — `unknown`
|
|
23
|
+
while not hydrated (the server hasn't answered yet), `complete` once it has. A pending
|
|
24
|
+
mutation no longer moves it; `error` is reserved and currently unproduced.
|
|
25
|
+
- **Pending axis** (§7.2): "is an unconfirmed prediction touching this query?" is its own
|
|
26
|
+
reactive signal — `pending(qid)` / `onPending` / `pendingTables()` — so a "saving…"
|
|
27
|
+
indicator is separate from loading.
|
|
28
|
+
- **Folded mutations** (FOLDED-MUTATIONS-DESIGN): `mutate.foo.folded({ key, debounceMs,
|
|
29
|
+
maxWaitMs }, args)` collapses a run of high-frequency same-key writes (a slider drag) into
|
|
30
|
+
**one** debounced, last-value-wins server write while the local view still updates on every
|
|
31
|
+
call. Folded mutators must be **absorbing** (last-writer-wins); a read-dependent one is
|
|
32
|
+
refused. `flushFolds()` (also auto-fired on `pagehide`/`beforeunload`) drains in-flight folds.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { createOptimisticStore, type ClientRegistry } from "@rindle/optimistic";
|
|
36
|
+
import { defineQuery, newQueryBuilder } from "@rindle/client";
|
|
37
|
+
// `schema` is your @rindle/client schema; `source` is an `OptimisticSource`
|
|
38
|
+
// (e.g. `createRemoteOptimisticSource` from @rindle/remote).
|
|
39
|
+
|
|
40
|
+
const registry = {
|
|
41
|
+
createIssue: (tx, args: { id: number; title: string }) =>
|
|
42
|
+
tx.add("issue", [args.id, args.title]),
|
|
43
|
+
} satisfies ClientRegistry;
|
|
44
|
+
|
|
45
|
+
const q = newQueryBuilder(schema);
|
|
46
|
+
const queries = {
|
|
47
|
+
allIssues: defineQuery("allIssues", () => q.issue.orderBy("id", "asc")),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const { store, backend, mutate } = createOptimisticStore(schema, source, registry, {
|
|
51
|
+
clientID: "client-1",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const view = store.materialize(queries.allIssues()); // named remote footprint + local view
|
|
55
|
+
mutate.createIssue({ id: 7, title: "instant" }); // applies NOW; reconciles when confirmed
|
|
56
|
+
backend.resultType(/* queryId */ 1); // "unknown" (loading) → "complete"
|
|
57
|
+
backend.pending(/* queryId */ 1); // is an optimistic write pending on this query?
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A `Store` over an `OptimisticBackend` is an ordinary `@rindle/client` store — the
|
|
61
|
+
`Backend` seam holds. Unstamped `store.query...materialize()` calls are local-only; use
|
|
62
|
+
`defineQuery` + `store.materialize(query)` for remote sync. The `OptimisticSource` (the server side: cv-tagged normalized
|
|
63
|
+
frames + progress frames + the mutation upstream) is pluggable; the ws transport wiring
|
|
64
|
+
is the follow-up slice. The engine-side cycle and the server protocol are proven in
|
|
65
|
+
Rust (`src/optimistic.rs`, `rindle-replica`'s mutation/envelope suites); this package's
|
|
66
|
+
tests pin the TS wiring against a scripted source.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Ast, Condition, WireValue } from "@rindle/client";
|
|
2
|
+
/** One aggregate's definition, derived from the original AST — everything needed to compute a
|
|
3
|
+
* per-group delta from the child table's pending mutations. */
|
|
4
|
+
export interface AggDef {
|
|
5
|
+
/** The synthetic table name (`__agg_*`) the delta is applied to. */
|
|
6
|
+
aggTable: string;
|
|
7
|
+
/** The child table whose mutations drive the count (e.g. `"comment"`). */
|
|
8
|
+
childTable: string;
|
|
9
|
+
/** The child column names (schema order) — resolves the group key + filter columns. */
|
|
10
|
+
childColumns: string[];
|
|
11
|
+
/** Indices into a positional child row of the correlation child fields = the group key. */
|
|
12
|
+
groupKeyCols: number[];
|
|
13
|
+
/** The child `where`, if any (already baked into the server count; re-evaluated locally
|
|
14
|
+
* to decide a pending child's membership). */
|
|
15
|
+
where?: Condition;
|
|
16
|
+
/** §6.2: whether the optimistic delta is computable — the `where` references only the
|
|
17
|
+
* child's own columns + literals over scalar ops. Unevaluable ⇒ no delta (server value). */
|
|
18
|
+
evaluable: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Collect every aggregate's `AggDef` from `ast` (recursively — a nested aggregate under a
|
|
21
|
+
* materialized relationship included), resolving child columns via `getColumns(table)`. The
|
|
22
|
+
* twin of `aggTableSchemas` (`@rindle/normalized`) but carrying the delta-computation fields. */
|
|
23
|
+
export declare function collectAggDefs(ast: Ast, getColumns: (table: string) => string[] | undefined): AggDef[];
|
|
24
|
+
/** §6.2 static gate: a condition is locally evaluable iff every leaf compares the child's own
|
|
25
|
+
* columns / literals with a scalar op. A `correlatedSubquery` (a join the client may not hold)
|
|
26
|
+
* or a column outside the child schema makes the whole aggregate unevaluable. */
|
|
27
|
+
export declare function isEvaluable(cond: Condition, childColumns: string[]): boolean;
|
|
28
|
+
/** Evaluate an EVALUABLE condition against a positional child row (SQL-ish three-valued logic
|
|
29
|
+
* collapsed to a boolean — an unknown comparison is `false`, i.e. the row is not a member).
|
|
30
|
+
* Only the grammar `isEvaluable` admits reaches here. */
|
|
31
|
+
export declare function evalCondition(cond: Condition, row: WireValue[], childColumns: string[]): boolean;
|
|
32
|
+
/** One observed child-table op (the wire shape the collector feeds the overlay). */
|
|
33
|
+
export interface ChildOp {
|
|
34
|
+
table: string;
|
|
35
|
+
kind: "add" | "remove" | "edit";
|
|
36
|
+
row: WireValue[];
|
|
37
|
+
/** The pre-image (edit only). */
|
|
38
|
+
old?: WireValue[];
|
|
39
|
+
}
|
|
40
|
+
/** One group's accumulated optimistic delta. */
|
|
41
|
+
export interface DeltaEntry {
|
|
42
|
+
aggTable: string;
|
|
43
|
+
def: AggDef;
|
|
44
|
+
/** The group-key cells (PK of the synthetic row). */
|
|
45
|
+
cells: WireValue[];
|
|
46
|
+
/** The net optimistic count delta for this group over the pending child mutations. */
|
|
47
|
+
n: number;
|
|
48
|
+
}
|
|
49
|
+
/** The stateful accumulator: holds the aggregate definitions and the per-group pending delta.
|
|
50
|
+
* Engine-agnostic — the backend feeds it observed child ops and reads back the entries to
|
|
51
|
+
* reconcile against the `__agg` head rows. */
|
|
52
|
+
export declare class AggOverlay {
|
|
53
|
+
/** By synthetic table name. Sharing a definition across queries is automatic (idempotent
|
|
54
|
+
* {@link register}); the backend refcounts readers and calls {@link unregister} when the
|
|
55
|
+
* last query over an aggregate is gone, so a definition is reclaimed with its table — not
|
|
56
|
+
* kept for the backend's life. */
|
|
57
|
+
private readonly defs;
|
|
58
|
+
/** Child table → the defs it feeds, for O(1) dispatch in `observe`. */
|
|
59
|
+
private readonly byChild;
|
|
60
|
+
/** `aggTable\0JSON(groupCells)` → the group's accumulated delta. */
|
|
61
|
+
private readonly delta;
|
|
62
|
+
/** Register aggregate definitions (idempotent per synthetic table name). */
|
|
63
|
+
register(defs: AggDef[]): void;
|
|
64
|
+
/** Forget an aggregate definition (its synthetic table is being removed because the last
|
|
65
|
+
* query reading it was unregistered — `AGGREGATE-SYNC-DESIGN.md` §4). Drops the def, its
|
|
66
|
+
* child-dispatch entry, and any accumulated delta for it. The inverse of the per-table half
|
|
67
|
+
* of {@link register}; a no-op for an unknown table. */
|
|
68
|
+
unregister(aggTable: string): void;
|
|
69
|
+
/** Does any aggregate count rows of `table`? (cheap collector guard) */
|
|
70
|
+
hasChild(table: string): boolean;
|
|
71
|
+
/** Any aggregate definitions at all? */
|
|
72
|
+
get hasDefs(): boolean;
|
|
73
|
+
/** Drop all accumulated deltas — called at the start of a reconcile cycle rebuild, where the
|
|
74
|
+
* delta is recomputed from scratch off the (confirm-filtered) pending set. */
|
|
75
|
+
reset(): void;
|
|
76
|
+
/** Fold one observed child op into the per-group delta, for every EVALUABLE aggregate over
|
|
77
|
+
* that child table. (Unevaluable defs contribute nothing — §6.2 server-value fallback.) */
|
|
78
|
+
observe(op: ChildOp): void;
|
|
79
|
+
private bump;
|
|
80
|
+
/** The current non-trivial deltas to reconcile against the `__agg` head rows. */
|
|
81
|
+
entries(): DeltaEntry[];
|
|
82
|
+
/** Forget groups whose delta has returned to 0 (their head row was reverted to the server
|
|
83
|
+
* value by the reconcile that observed the 0) — keeps the map bounded between releases. */
|
|
84
|
+
pruneZeros(): void;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=agg-overlay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agg-overlay.d.ts","sourceRoot":"","sources":["../src/agg-overlay.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAiB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS/E;gEACgE;AAChE,MAAM,WAAW,MAAM;IACrB,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,2FAA2F;IAC3F,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;mDAC+C;IAC/C,K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AAQ,EAAE,MAAM,GAAG,IAAI;IAWlC,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC,wCAAwC;IACxC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;mFAC+E;IAC/E,KAAK,IAAI,IAAI;IAIb;gGAC4F;IAC5F,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI;IAc1B,OAAO,CAAC,IAAI;IASZ,iFAAiF;IACjF,OAAO,IAAI,UAAU,EAAE;IAIvB;gGAC4F;IAC5F,UAAU,IAAI,IAAI;CAGnB"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// The optimistic aggregate overlay (AGGREGATE-SYNC-DESIGN.md §4–§6) — the pure half of
|
|
2
|
+
// "displayed = server_base ⊕ watermark-gated local_pending_delta".
|
|
3
|
+
//
|
|
4
|
+
// The DISPLAY path (§3) makes a relationship `count(comments)` read a server-authoritative
|
|
5
|
+
// synthetic base table `__agg_*` (the reduce's `(group_key, count)` output) via a plain
|
|
6
|
+
// projected join. This module computes the CLIENT's own pending delta on top: a mini
|
|
7
|
+
// invertible counter over only the pending child mutations, correlated by the same group key
|
|
8
|
+
// (`+1` per pending child add, `−1` per remove, net per edit). The backend applies the delta
|
|
9
|
+
// as an optimistic add/edit/remove to the `__agg` head row, so the displayed scalar updates
|
|
10
|
+
// through the same join + projection with no special path.
|
|
11
|
+
//
|
|
12
|
+
// Two things are pure and live here: the per-aggregate DEFINITIONS derived from the AST
|
|
13
|
+
// (`AggDef`, incl. the §6.2 static `evaluable` gate), and the accumulator (`AggOverlay`) that
|
|
14
|
+
// folds observed child ops into a per-group delta. The engine-touching reconcile (reading
|
|
15
|
+
// `server_base`, writing the `__agg` head row) stays in `backend.ts`.
|
|
16
|
+
import { aggTableName } from "@rindle/normalized";
|
|
17
|
+
/** The scalar comparison ops the v1 predicate evaluator (and the `evaluable` gate) cover.
|
|
18
|
+
* `LIKE`/`ILIKE`/`IN` are deliberately EXCLUDED — a filter using them is `evaluable: false`
|
|
19
|
+
* and falls back to the bare server value (avoids the LIKE-escape parity rabbit hole; always
|
|
20
|
+
* correct, just not optimistic for that aggregate). */
|
|
21
|
+
const SCALAR_OPS = new Set(["=", "!=", "<", "<=", ">", ">=", "IS", "IS NOT"]);
|
|
22
|
+
/** Collect every aggregate's `AggDef` from `ast` (recursively — a nested aggregate under a
|
|
23
|
+
* materialized relationship included), resolving child columns via `getColumns(table)`. The
|
|
24
|
+
* twin of `aggTableSchemas` (`@rindle/normalized`) but carrying the delta-computation fields. */
|
|
25
|
+
export function collectAggDefs(ast, getColumns) {
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const r of ast.related ?? []) {
|
|
28
|
+
if (r.subquery.aggregate) {
|
|
29
|
+
const childTable = r.subquery.table;
|
|
30
|
+
const childColumns = getColumns(childTable);
|
|
31
|
+
if (!childColumns)
|
|
32
|
+
continue; // child table not in the client schema — cannot key locally
|
|
33
|
+
const groupKeyCols = r.correlation.childField.map((n) => childColumns.indexOf(n));
|
|
34
|
+
if (groupKeyCols.some((i) => i < 0))
|
|
35
|
+
continue; // a correlation field not in the schema
|
|
36
|
+
const where = r.subquery.where;
|
|
37
|
+
out.push({
|
|
38
|
+
aggTable: aggTableName(r),
|
|
39
|
+
childTable,
|
|
40
|
+
childColumns,
|
|
41
|
+
groupKeyCols,
|
|
42
|
+
where,
|
|
43
|
+
evaluable: where === undefined || isEvaluable(where, childColumns),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
out.push(...collectAggDefs(r.subquery, getColumns));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
/** §6.2 static gate: a condition is locally evaluable iff every leaf compares the child's own
|
|
53
|
+
* columns / literals with a scalar op. A `correlatedSubquery` (a join the client may not hold)
|
|
54
|
+
* or a column outside the child schema makes the whole aggregate unevaluable. */
|
|
55
|
+
export function isEvaluable(cond, childColumns) {
|
|
56
|
+
switch (cond.type) {
|
|
57
|
+
case "simple":
|
|
58
|
+
return SCALAR_OPS.has(cond.op) && pos(cond.left, childColumns) && pos(cond.right, childColumns);
|
|
59
|
+
case "and":
|
|
60
|
+
case "or":
|
|
61
|
+
return cond.conditions.every((c) => isEvaluable(c, childColumns));
|
|
62
|
+
case "correlatedSubquery":
|
|
63
|
+
return false; // reaches into a join the client may not have
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function pos(vp, childColumns) {
|
|
67
|
+
return vp.type === "literal" || childColumns.includes(vp.name);
|
|
68
|
+
}
|
|
69
|
+
/** Evaluate an EVALUABLE condition against a positional child row (SQL-ish three-valued logic
|
|
70
|
+
* collapsed to a boolean — an unknown comparison is `false`, i.e. the row is not a member).
|
|
71
|
+
* Only the grammar `isEvaluable` admits reaches here. */
|
|
72
|
+
export function evalCondition(cond, row, childColumns) {
|
|
73
|
+
switch (cond.type) {
|
|
74
|
+
case "simple":
|
|
75
|
+
return evalSimple(cond.op, value(cond.left, row, childColumns), value(cond.right, row, childColumns));
|
|
76
|
+
case "and":
|
|
77
|
+
return cond.conditions.every((c) => evalCondition(c, row, childColumns));
|
|
78
|
+
case "or":
|
|
79
|
+
return cond.conditions.some((c) => evalCondition(c, row, childColumns));
|
|
80
|
+
case "correlatedSubquery":
|
|
81
|
+
return false; // never evaluable — defensive
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function value(vp, row, childColumns) {
|
|
85
|
+
return vp.type === "literal" ? vp.value : row[childColumns.indexOf(vp.name)];
|
|
86
|
+
}
|
|
87
|
+
function evalSimple(op, l, r) {
|
|
88
|
+
switch (op) {
|
|
89
|
+
case "IS":
|
|
90
|
+
return nullSafeEq(l, r); // null-safe: NULL IS NULL → true
|
|
91
|
+
case "IS NOT":
|
|
92
|
+
return !nullSafeEq(l, r);
|
|
93
|
+
case "=":
|
|
94
|
+
return l == null || r == null ? false : nullSafeEq(l, r);
|
|
95
|
+
case "!=":
|
|
96
|
+
return l == null || r == null ? false : !nullSafeEq(l, r);
|
|
97
|
+
case "<":
|
|
98
|
+
return less(l, r);
|
|
99
|
+
case "<=":
|
|
100
|
+
return less(l, r) || nullSafeEq(l, r);
|
|
101
|
+
case ">":
|
|
102
|
+
return less(r, l);
|
|
103
|
+
case ">=":
|
|
104
|
+
return less(r, l) || nullSafeEq(l, r);
|
|
105
|
+
default:
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function nullSafeEq(l, r) {
|
|
110
|
+
return l === r; // scalar cells: number/string/boolean/null compare by identity
|
|
111
|
+
}
|
|
112
|
+
function less(l, r) {
|
|
113
|
+
if (l == null || r == null)
|
|
114
|
+
return false; // ordered comparison with NULL → unknown → false
|
|
115
|
+
if (typeof l === "number" && typeof r === "number")
|
|
116
|
+
return l < r;
|
|
117
|
+
if (typeof l === "string" && typeof r === "string")
|
|
118
|
+
return l < r;
|
|
119
|
+
if (typeof l === "boolean" && typeof r === "boolean")
|
|
120
|
+
return Number(l) < Number(r);
|
|
121
|
+
return false; // mixed types: not a member (matches no row optimistically; self-corrects)
|
|
122
|
+
}
|
|
123
|
+
/** The stateful accumulator: holds the aggregate definitions and the per-group pending delta.
|
|
124
|
+
* Engine-agnostic — the backend feeds it observed child ops and reads back the entries to
|
|
125
|
+
* reconcile against the `__agg` head rows. */
|
|
126
|
+
export class AggOverlay {
|
|
127
|
+
/** By synthetic table name. Sharing a definition across queries is automatic (idempotent
|
|
128
|
+
* {@link register}); the backend refcounts readers and calls {@link unregister} when the
|
|
129
|
+
* last query over an aggregate is gone, so a definition is reclaimed with its table — not
|
|
130
|
+
* kept for the backend's life. */
|
|
131
|
+
defs = new Map();
|
|
132
|
+
/** Child table → the defs it feeds, for O(1) dispatch in `observe`. */
|
|
133
|
+
byChild = new Map();
|
|
134
|
+
/** `aggTable\0JSON(groupCells)` → the group's accumulated delta. */
|
|
135
|
+
delta = new Map();
|
|
136
|
+
/** Register aggregate definitions (idempotent per synthetic table name). */
|
|
137
|
+
register(defs) {
|
|
138
|
+
for (const d of defs) {
|
|
139
|
+
if (this.defs.has(d.aggTable))
|
|
140
|
+
continue;
|
|
141
|
+
this.defs.set(d.aggTable, d);
|
|
142
|
+
const list = this.byChild.get(d.childTable);
|
|
143
|
+
if (list)
|
|
144
|
+
list.push(d);
|
|
145
|
+
else
|
|
146
|
+
this.byChild.set(d.childTable, [d]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Forget an aggregate definition (its synthetic table is being removed because the last
|
|
150
|
+
* query reading it was unregistered — `AGGREGATE-SYNC-DESIGN.md` §4). Drops the def, its
|
|
151
|
+
* child-dispatch entry, and any accumulated delta for it. The inverse of the per-table half
|
|
152
|
+
* of {@link register}; a no-op for an unknown table. */
|
|
153
|
+
unregister(aggTable) {
|
|
154
|
+
const d = this.defs.get(aggTable);
|
|
155
|
+
if (!d)
|
|
156
|
+
return;
|
|
157
|
+
this.defs.delete(aggTable);
|
|
158
|
+
const rest = (this.byChild.get(d.childTable) ?? []).filter((x) => x.aggTable !== aggTable);
|
|
159
|
+
if (rest.length)
|
|
160
|
+
this.byChild.set(d.childTable, rest);
|
|
161
|
+
else
|
|
162
|
+
this.byChild.delete(d.childTable);
|
|
163
|
+
// Drop this table's accumulated groups (match on the stored aggTable — separator-agnostic).
|
|
164
|
+
for (const [k, e] of this.delta)
|
|
165
|
+
if (e.aggTable === aggTable)
|
|
166
|
+
this.delta.delete(k);
|
|
167
|
+
}
|
|
168
|
+
/** Does any aggregate count rows of `table`? (cheap collector guard) */
|
|
169
|
+
hasChild(table) {
|
|
170
|
+
return this.byChild.has(table);
|
|
171
|
+
}
|
|
172
|
+
/** Any aggregate definitions at all? */
|
|
173
|
+
get hasDefs() {
|
|
174
|
+
return this.defs.size > 0;
|
|
175
|
+
}
|
|
176
|
+
/** Drop all accumulated deltas — called at the start of a reconcile cycle rebuild, where the
|
|
177
|
+
* delta is recomputed from scratch off the (confirm-filtered) pending set. */
|
|
178
|
+
reset() {
|
|
179
|
+
this.delta.clear();
|
|
180
|
+
}
|
|
181
|
+
/** Fold one observed child op into the per-group delta, for every EVALUABLE aggregate over
|
|
182
|
+
* that child table. (Unevaluable defs contribute nothing — §6.2 server-value fallback.) */
|
|
183
|
+
observe(op) {
|
|
184
|
+
const defs = this.byChild.get(op.table);
|
|
185
|
+
if (!defs)
|
|
186
|
+
return;
|
|
187
|
+
for (const d of defs) {
|
|
188
|
+
if (!d.evaluable)
|
|
189
|
+
continue;
|
|
190
|
+
if (op.kind === "add")
|
|
191
|
+
this.bump(d, op.row, 1);
|
|
192
|
+
else if (op.kind === "remove")
|
|
193
|
+
this.bump(d, op.row, -1);
|
|
194
|
+
else {
|
|
195
|
+
if (op.old)
|
|
196
|
+
this.bump(d, op.old, -1);
|
|
197
|
+
this.bump(d, op.row, 1);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
bump(d, childRow, sign) {
|
|
202
|
+
if (d.where && !evalCondition(d.where, childRow, d.childColumns))
|
|
203
|
+
return; // not a member
|
|
204
|
+
const cells = d.groupKeyCols.map((i) => childRow[i]);
|
|
205
|
+
const key = `${d.aggTable}|${JSON.stringify(cells)}`;
|
|
206
|
+
const e = this.delta.get(key);
|
|
207
|
+
if (e)
|
|
208
|
+
e.n += sign;
|
|
209
|
+
else
|
|
210
|
+
this.delta.set(key, { aggTable: d.aggTable, def: d, cells, n: sign });
|
|
211
|
+
}
|
|
212
|
+
/** The current non-trivial deltas to reconcile against the `__agg` head rows. */
|
|
213
|
+
entries() {
|
|
214
|
+
return [...this.delta.values()];
|
|
215
|
+
}
|
|
216
|
+
/** Forget groups whose delta has returned to 0 (their head row was reverted to the server
|
|
217
|
+
* value by the reconcile that observed the 0) — keeps the map bounded between releases. */
|
|
218
|
+
pruneZeros() {
|
|
219
|
+
for (const [k, e] of this.delta)
|
|
220
|
+
if (e.n === 0)
|
|
221
|
+
this.delta.delete(k);
|
|
222
|
+
}
|
|
223
|
+
}
|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