@oimdb/core 4.0.0 → 4.1.0
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/CHANGELOG.md +154 -32
- package/README.md +342 -453
- package/dist/index.cjs +1825 -1990
- package/dist/index.d.cts +619 -543
- package/dist/index.d.ts +619 -543
- package/dist/index.js +1778 -1945
- package/llms.txt +741 -860
- package/package.json +2 -2
package/llms.txt
CHANGED
|
@@ -6,41 +6,45 @@
|
|
|
6
6
|
> written against the current source.
|
|
7
7
|
>
|
|
8
8
|
> **Services hold no data; state lives on slots.** An `OIMDB` owns the clock, the collector slot and
|
|
9
|
-
> its `defaultChannelSlot`.
|
|
9
|
+
> its `defaultChannelSlot`. One channel per database; for isolation, a separate `OIMDB` — a write is
|
|
10
|
+
> delivered at its own channel's flush to every effect on the slots it moved, so a second channel on
|
|
11
|
+
> the same clock isolates nothing. A collection service (`OIMSlotCollectionService`) or a single slot service
|
|
10
12
|
> (`OIMSingleSlotService`) is built once per collection type, and `service.createStoreSlot(db)` makes an
|
|
11
13
|
> instance, a `TOIMStoreSlot`, which is NOT a slot (no owner, holds or effects) and carries its
|
|
12
14
|
> `channelSlot`.
|
|
13
15
|
> READS and minting are on the collection service and take the store slot first
|
|
14
16
|
> (`cardService.getSlotByKey(cards, key)`, `holdSlotByKey`, `findSlotByKey`, `getSlots`, `getSlotCount`, the
|
|
15
|
-
> column doors).
|
|
16
|
-
>
|
|
17
|
-
>
|
|
18
|
-
>
|
|
19
|
-
>
|
|
20
|
-
> `
|
|
17
|
+
> column doors). One WRITE is on the collection and takes a key:
|
|
18
|
+
> `cardService.writeSlotContentByKey(cards, key, entity)`, which mints the slot on a miss and writes the whole
|
|
19
|
+
> value on a hit. Every other write is on `service.slotContentService` and takes a slot
|
|
20
|
+
> (`cardService.slotContentService.updateEntity(slot, patch)`, `writeSlotContent(slot, entity)`,
|
|
21
|
+
> `clearSlotContent(slot)`). There are NO bulk writes and no `keyOf`: the key is always the caller's. A load is a
|
|
22
|
+
> loop of `writeSlotContentByKey` inside `cardService.writeInBatch(cards, () => { … })`, so an index on the
|
|
23
|
+
> collection hears the whole loop in one call.
|
|
24
|
+
> A single — one slot under no key — is an `OIMSingleSlotService`: `writeSingleSlotContent(storeSlot, value)`,
|
|
25
|
+
> `getSingleSlot(storeSlot)`, `holdSingleSlot(storeSlot)`, `findSingleSlot(storeSlot)`,
|
|
26
|
+
> `clearSingleSlotContent(storeSlot)`. No key is `void` or `undefined`: `TKey extends NonNullable<unknown>`.
|
|
21
27
|
>
|
|
22
|
-
>
|
|
23
|
-
> `createOIMSingleSlotService({ slotContentService })
|
|
24
|
-
> `
|
|
25
|
-
>
|
|
26
|
-
> `
|
|
27
|
-
>
|
|
28
|
-
> `
|
|
29
|
-
> `createOIMIndexServiceByCompositeKey` is a convenience wrapper over it.
|
|
28
|
+
> Every collection is `createOIMSlotCollectionService(db, { slotContentService })` and every single is
|
|
29
|
+
> `createOIMSingleSlotService(db, { slotContentService })`. The content service decides what the slots hold:
|
|
30
|
+
> `createOIMSlotContentEntityService<TEntity>(db, …)` for entities, `new OIMSlotContentSetBucketService()`,
|
|
31
|
+
> `new OIMSlotContentPositionalArrayBucketService()` or `new OIMSlotContentSortedArrayBucketService({ … })` for
|
|
32
|
+
> buckets. An index is `createOIMSlotCollectionIndexService(db, { entityService, keyOf | columns, slotContentService? })`;
|
|
33
|
+
> its `keyOf` is the index's key of an entity, not the collection's. An array key needs a tree store:
|
|
34
|
+
> `slotStoreService` on the collection, `bucketSlotStoreService` on the index.
|
|
30
35
|
> Position reads and writes (`getBucketMemberSlotAt`, `getBucketMemberSlotPosition`, `insertBucketMemberSlotAt`,
|
|
31
36
|
> `removeBucketMemberSlotAt`, `removeBucketMemberSlotRange`, `moveBucketMemberSlotToPosition`,
|
|
32
|
-
> `moveBucketMemberSlotRangeToPosition`) are on `
|
|
37
|
+
> `moveBucketMemberSlotRangeToPosition`) are on `OIMSlotContentPositionalArrayBucketService`, the default bucket
|
|
33
38
|
> content service; the set-driven one has none. A bucket sorts only on the sorted-at-write content service
|
|
34
|
-
> (`
|
|
35
|
-
> over any index is `
|
|
39
|
+
> (`createOIMSlotCollectionSortedArrayIndexService`); on every other bucket its order is the caller's. A sorted list
|
|
40
|
+
> over any index is `createOIMSortedComputedService`. The render script is `OIMBucketCommands`.
|
|
36
41
|
> The channel has no class: its operations are on `OIMChannelService.INSTANCE` and take a channel slot.
|
|
37
42
|
> Effects are `OIMEffectService.INSTANCE.createEffect(db, sourceSlots, sourceComputeds, body)`.
|
|
38
43
|
> Every stateless singleton is a static `INSTANCE` on its class. Module-level defaults are on `OIMDefaults`.
|
|
39
44
|
>
|
|
40
45
|
> Check every symbol you write against [the full export list](#full-export-list).
|
|
41
46
|
>
|
|
42
|
-
>
|
|
43
|
-
> Backwards compatibility, semver and migration paths are not costs here.
|
|
47
|
+
> Install: `npm install @oimdb/core` (4.x). The 3.x line is the previous engine with a different API.
|
|
44
48
|
>
|
|
45
49
|
> `packages/core/src/index.ts` is the entire public surface.
|
|
46
50
|
|
|
@@ -77,39 +81,7 @@ block and the one under [One derivation per key](#one-derivation-per-key). Block
|
|
|
77
81
|
marked `ts signature` are listings of an API and are not compiled.
|
|
78
82
|
|
|
79
83
|
```ts setup
|
|
80
|
-
import {
|
|
81
|
-
OIMChannelService,
|
|
82
|
-
OIMContentChangeListenerService,
|
|
83
|
-
OIMDB,
|
|
84
|
-
OIMDefaults,
|
|
85
|
-
OIMEffectService,
|
|
86
|
-
OIMSlotContentBucketServiceArrayDriven,
|
|
87
|
-
OIMSlotContentBucketServiceSetDriven,
|
|
88
|
-
OIMSlotStoreServiceMapDriven,
|
|
89
|
-
OIMSlotStoreServiceSingleSlotDriven,
|
|
90
|
-
OIMSlotStoreServiceTreeDriven,
|
|
91
|
-
OIMUnusedSlotCollectorService,
|
|
92
|
-
createOIMBucketService,
|
|
93
|
-
createOIMComputedServiceBucketMemo,
|
|
94
|
-
createOIMComputedService,
|
|
95
|
-
createOIMComputedServiceSorted,
|
|
96
|
-
createOIMEntityService,
|
|
97
|
-
createOIMEntityWriterInPlace,
|
|
98
|
-
createOIMEntityWriterReplacing,
|
|
99
|
-
createOIMIndexService,
|
|
100
|
-
createOIMIndexServiceSortedArrayDriven,
|
|
101
|
-
createOIMSingleBucketService,
|
|
102
|
-
createOIMSingleEntityService,
|
|
103
|
-
createOIMSlotCollectionService,
|
|
104
|
-
createOIMSlotContentEntityService,
|
|
105
|
-
createOIMUnusedSlotCollectorSlot,
|
|
106
|
-
oimIsSlotEmpty,
|
|
107
|
-
oimIsSlotReleased,
|
|
108
|
-
oimPatchEntityColumn,
|
|
109
|
-
oimPatchEntityColumns,
|
|
110
|
-
oimPutEntityColumns,
|
|
111
|
-
oimSameValueZeroGuard,
|
|
112
|
-
} from '@oimdb/core';
|
|
84
|
+
import { OIMChannelService, OIMContentChangeListenerService, OIMDB, OIMDefaults, OIMEffectService, OIMSlotContentPositionalArrayBucketService, OIMSlotContentSetBucketService, OIMSlotMapStoreService, OIMSingleSlotStoreService, OIMSlotTreeStoreService, OIMUnusedSlotCollectorService, createOIMBucketMemoComputedService, createOIMComputedService, createOIMSortedComputedService, createOIMEntityWriterInPlace, createOIMEntityWriterReplacing, createOIMSlotCollectionIndexService, createOIMSlotCollectionSortedArrayIndexService, createOIMSlotCollectionService, createOIMSlotContentEntityService, createOIMSingleSlotService, createOIMSingleComputedService, createOIMUnusedSlotCollectorSlot, oimIsSlotEmpty, oimIsSlotReleased, oimPatchEntityColumn, oimPatchEntityColumns, oimPutEntityColumns, oimSameValueZeroGuard, OIMBucketCommands, OIMSlotEarliestReleasePolicy, OIMSlotAfterWriteReleasePolicy, OIMSlotAfterIdleReleasePolicy, OIMThrowAtOnceErrorPolicy, type TOIMSlotStoreTree } from '@oimdb/core';
|
|
113
85
|
import type {
|
|
114
86
|
IOIMEntityWriter,
|
|
115
87
|
TOIMSlotEditable,
|
|
@@ -118,6 +90,7 @@ import type {
|
|
|
118
90
|
TOIMBucketSlotsSetStore,
|
|
119
91
|
TOIMComputedSlot,
|
|
120
92
|
TOIMDisposer,
|
|
93
|
+
TOIMEntityContentSlot,
|
|
121
94
|
TOIMEntitySlot,
|
|
122
95
|
TOIMOrderedListCommand,
|
|
123
96
|
TOIMSingleSlotStore,
|
|
@@ -138,17 +111,15 @@ declare const payload: readonly Card[];
|
|
|
138
111
|
const db = new OIMDB();
|
|
139
112
|
const channelSlot = db.defaultChannelSlot;
|
|
140
113
|
const effectService = OIMEffectService.INSTANCE;
|
|
141
|
-
const cardService =
|
|
114
|
+
const cardService = createOIMSlotCollectionService(db, { slotContentService: createOIMSlotContentEntityService<Card>(db) });
|
|
142
115
|
const cards = cardService.createStoreSlot(db);
|
|
143
|
-
const slot = cardService.
|
|
116
|
+
const slot = cardService.writeSlotContentByKey(cards, 'c1', { id: 'c1', title: 'Ace', rank: 1, deck: 'spades' });
|
|
144
117
|
|
|
145
|
-
const orderedService =
|
|
146
|
-
slotContentService: new OIMSlotContentBucketServiceArrayDriven<TOIMEntitySlot<Card>>(),
|
|
147
|
-
});
|
|
118
|
+
const orderedService = createOIMSlotCollectionService(db, { slotContentService: new OIMSlotContentPositionalArrayBucketService<TOIMEntitySlot<Card>>() });
|
|
148
119
|
const ordered = orderedService.createStoreSlot(db);
|
|
149
120
|
const orderedBucketSlot = orderedService.holdSlotByKey(ordered, 'top');
|
|
150
121
|
|
|
151
|
-
const pageService =
|
|
122
|
+
const pageService = createOIMSlotCollectionService(db, { slotContentService: new OIMSlotContentPositionalArrayBucketService<TOIMEntitySlot<Card>>({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: undefined }) }) });
|
|
152
123
|
const page = pageService.createStoreSlot(db);
|
|
153
124
|
const todo = pageService.holdSlotByKey(page, 'todo');
|
|
154
125
|
const done = pageService.holdSlotByKey(page, 'done');
|
|
@@ -160,26 +131,28 @@ const done = pageService.holdSlotByKey(page, 'done');
|
|
|
160
131
|
|
|
161
132
|
| Layer | Contents |
|
|
162
133
|
|---|---|
|
|
163
|
-
| `src/engine/<domain>/` | the channel (`OIMChannelService`, `TOIMChannelSlot`), the flush scheduler (`OIMFlushSchedulerService`), the slot owner (`OIMSlotOwner`, and `OIMSlotOwnerService`, a type-only export), `OIMContentChangeListenerService`, the entity content service `OIMSlotContentEntityService`, `OIMComputedValueService`, `OIMEffectService`, the column owner (abstract `
|
|
164
|
-
| `src/facade/<domain>/` | `facade/slot/`: `OIMSlotCollectionService`, `OIMSingleSlotService`; `facade/bucket/`: `OIMSlotContentBucketService` (abstract), `
|
|
165
|
-
| `src/factories/` | `OIMDB`, `OIMDefaults`, `OIMDefaultValue`;
|
|
134
|
+
| `src/engine/<domain>/` | the channel (`OIMChannelService`, `TOIMChannelSlot`), the flush scheduler (`OIMFlushSchedulerService`), the slot owner (`OIMSlotOwner`, and `OIMSlotOwnerService`, a type-only export), `OIMContentChangeListenerService`, the entity content service `OIMSlotContentEntityService`, `OIMComputedValueService`, `OIMEffectService`, the column owner (abstract `OIMColumnSlotOwner` with the strategies `OIMPushColumnSlotOwner` and `OIMPullColumnSlotOwner`), the key stores and key tree walks, the index keys services, `TOIMStoreSlot`, `TOIMComputedSlot`, `TOIMEffect`, the collector services and slots, and the release policies |
|
|
135
|
+
| `src/facade/<domain>/` | `facade/slot/`: `OIMSlotCollectionService`, `OIMWritableSlotCollectionService`, `OIMSingleSlotService`, `OIMWritableSingleSlotService`; `facade/column/`: `OIMColumnSlotService`; `facade/bucket/`: `OIMSlotContentBucketService` (abstract), `OIMSlotContentSetBucketService`, `OIMSlotContentArrayBucketService` (abstract), `OIMSlotContentPositionalArrayBucketService`, `OIMSlotContentSortedArrayBucketService`, `OIMBucketCommands`; `facade/index/`: `OIMSlotCollectionIndexService`, `OIMSlotCollectionSortedArrayIndexService`; `facade/computed/`: `OIMComputedService`, `OIMSortedComputedService`, `OIMBucketMemoComputedService` |
|
|
136
|
+
| `src/factories/` | `OIMDB`, `OIMDefaults`, `OIMDefaultValue`; `createOIMSlotCollectionService`, `createOIMSingleSlotService`, `createOIMSlotContentEntityService`, `createOIMSlotCollectionIndexService`, `createOIMSlotCollectionSortedArrayIndexService`, `createOIMComputedService`, `createOIMSingleComputedService`, `createOIMSortedComputedService`, `createOIMBucketMemoComputedService`, `createOIMEntityWriterInPlace`, `createOIMEntityWriterReplacing` |
|
|
166
137
|
|
|
167
138
|
**No class sits directly in `engine/` or `facade/`.** The directory is the
|
|
168
139
|
domain: `engine/bucket/`, `engine/channel/`, `engine/collector/`, `engine/column/`, `engine/computed/`,
|
|
169
140
|
`engine/entity/`, `engine/error/`, `engine/index/`, `engine/key/`, `engine/schedule/`, `engine/slot/`,
|
|
170
141
|
`engine/store/`, each with its own `constants/`, `interfaces/`, `types/` and `utils/` beside its classes; and
|
|
171
|
-
`facade/bucket/`, `facade/computed/`, `facade/index/`, `facade/slot/`.
|
|
142
|
+
`facade/bucket/`, `facade/column/`, `facade/computed/`, `facade/index/`, `facade/slot/`.
|
|
172
143
|
|
|
173
144
|
**A service holds no data; state lives on slots.** A collection service is built once per collection type
|
|
174
145
|
and holds only configuration and other services: its slot owner, its store service and its content
|
|
175
146
|
service (`service.slotContentService`). `service.createStoreSlot(db)` makes an instance, a `TOIMStoreSlot`,
|
|
176
147
|
which is NOT a slot (no owner, holds or effects): its `store` is what the store service built, its
|
|
177
|
-
`channelSlot` is the db's channel, and it carries the per-store
|
|
178
|
-
|
|
179
|
-
`slot.storeSlot`, which is why a slot door needs no store slot.
|
|
180
|
-
(`cardService.getSlotByKey(cards, pk)`,
|
|
181
|
-
|
|
182
|
-
|
|
148
|
+
`channelSlot` is the db's channel, its `slotService` is the service that made it, and it carries the per-store
|
|
149
|
+
state (content-change listeners, index key positions, the open batch and its queued changes, column readers).
|
|
150
|
+
Every slot filed in it points back to it through `slot.storeSlot`, which is why a slot door needs no store slot.
|
|
151
|
+
Reads and the keyed write are called on the service (`cardService.getSlotByKey(cards, pk)`,
|
|
152
|
+
`cardService.getSlots(cards)`, `cardService.writeSlotContentByKey(cards, pk, card)`, or through the store slot:
|
|
153
|
+
`cards.slotService.writeSlotContentByKey(cards, pk, card)`); writes on a slot go to its content service
|
|
154
|
+
(`cardService.slotContentService.updateEntity(slot, patch)`), and the column doors to
|
|
155
|
+
`cardService.columnSlotService`. A store slot's `store` is the store service's to read, never the caller's.
|
|
183
156
|
|
|
184
157
|
---
|
|
185
158
|
|
|
@@ -193,20 +166,20 @@ effect, a count, or a tracked mint — so nothing can unfile the identity under
|
|
|
193
166
|
the caller who just got it.
|
|
194
167
|
|
|
195
168
|
```ts
|
|
196
|
-
cardService.
|
|
169
|
+
cardService.writeSlotContentByKey(cards, 'c2', { id: 'c2', title: 'Two', rank: 2, deck: 'spades' }); // write
|
|
197
170
|
effectService.createEffect(db, [slot], [], () => { paint(slot.entity); }); // subscribe
|
|
198
171
|
cardService.holdSlotByKey(cards, 'c1'); // hold, by key -> the slot, holdCount up by one
|
|
199
|
-
const rankColumn = cardService.holdColumn(slot, 'rank'); // hold, on a column
|
|
200
|
-
cardService.unholdColumn(rankColumn); // give the column back
|
|
172
|
+
const rankColumn = cardService.columnSlotService.holdColumn(slot, 'rank'); // hold, on a column
|
|
173
|
+
cardService.columnSlotService.unholdColumn(rankColumn); // give the column back
|
|
201
174
|
cardService.getSlotByKey(cards, 'c1'); // read, by key -> the slot, tracked by the collector
|
|
202
175
|
```
|
|
203
176
|
|
|
204
177
|
**The non-minting lookup leaves no reference.** `findSlotByKey(storeSlot, key)` (and
|
|
205
178
|
`findSingleSlot(storeSlot)` on a single) answers `undefined` on a miss and mints nothing, and the
|
|
206
|
-
slot it does hand back is protected by nothing the caller took
|
|
207
|
-
|
|
208
|
-
the slot first and write through it. Do not write a helper
|
|
209
|
-
second spelling of a mint, not a fifth door.
|
|
179
|
+
slot it does hand back is protected by nothing the caller took; the entity is
|
|
180
|
+
`findSlotByKey(storeSlot, key)?.entity`. The one by-key write is `writeSlotContentByKey`, the write door
|
|
181
|
+
above; to patch or clear an entity by key, find the slot first and write through it. Do not write a helper
|
|
182
|
+
over any of the four doors — it would be a second spelling of a mint, not a fifth door.
|
|
210
183
|
|
|
211
184
|
**Subscribing leaves BOTH kinds of reference.** `OIMEffectService.INSTANCE.createEffect(db, …)` files
|
|
212
185
|
the effect in `slot.effects` *and* holds each root it subscribed to
|
|
@@ -238,13 +211,13 @@ owned by the object asked, and out of grace. Terms, and who gives each back:
|
|
|
238
211
|
|
|
239
212
|
| Term | Given back by |
|
|
240
213
|
|---|---|
|
|
241
|
-
| `holdCount` | `slot.owner.unholdSlot(slot)`, or `service.unholdColumn(columnSlot)` for a column; the unused-slot collector's flush; a slot leaving a bucket; `effectService.disposeEffect(effect)`, for the hold the effect took |
|
|
214
|
+
| `holdCount` | `slot.owner.unholdSlot(slot)`, or `service.columnSlotService.unholdColumn(columnSlot)` for a column; the unused-slot collector's flush; a slot leaving a bucket; `effectService.disposeEffect(effect)`, for the hold the effect took |
|
|
242
215
|
| `effects` | `effectService.disposeEffect(effect)` |
|
|
243
216
|
| a held column | its last column effect being disposed, through the service's column owner (`unsubscribeFromSlot`) |
|
|
244
|
-
| the value | `
|
|
245
|
-
| a composite-key edge | `
|
|
217
|
+
| the value | `service.slotContentService.clearSlotContent(slot)`, on an entity slot or a bucket slot alike; `clearSingleSlotContent(storeSlot)` on a single |
|
|
218
|
+
| a composite-key edge | `OIMCompositeKeyTreeWalk.deleteKey` unlinking that composite key part |
|
|
246
219
|
|
|
247
|
-
`
|
|
220
|
+
`clearSlotContent(slot)` takes the **value**. Subscribers stay, holds
|
|
248
221
|
stay, and the identity stays with them. Slots you wrote into a bucket are held by
|
|
249
222
|
that bucket until you empty it.
|
|
250
223
|
|
|
@@ -256,27 +229,36 @@ built from three stateless parts, wired once at construction, plus the injected
|
|
|
256
229
|
| Part | Where | What it does |
|
|
257
230
|
|---|---|---|
|
|
258
231
|
| the slot owner, `OIMSlotOwnerService` (type-only export) | `slot.owner`, typed `IOIMSlotOwner` | holds, subscriptions, release, emptiness, `assertWritable`, the column owner; one per collection type |
|
|
259
|
-
| the store service, `IOIMSlotStoreService` | given to the factory (`
|
|
260
|
-
| the content service | `service.slotContentService` | the writes and reads of one kind of content (`OIMSlotContentEntityService`, `
|
|
232
|
+
| the store service, `IOIMSlotStoreService` | given to the factory (`slotStoreService`, `bucketSlotStoreService`, …) or the Map default | files and finds the slots of each store slot's `store` |
|
|
233
|
+
| the content service | `service.slotContentService` | the writes and reads of one kind of content (`OIMSlotContentEntityService`, the bucket content services, `OIMSlotContentComputedService`) and the answers the owner asks of that kind |
|
|
261
234
|
|
|
262
|
-
The
|
|
235
|
+
The factory reads what it needs off the content service it is handed, through four small interfaces, never
|
|
263
236
|
through a subclass of the service:
|
|
264
237
|
|
|
265
238
|
```ts signature
|
|
266
|
-
interface
|
|
267
|
-
createSlot(key: TKey, storeSlot: TOIMStoreSlot
|
|
239
|
+
interface IOIMKeyedSlotCreator<TKey extends NonNullable<unknown>, TSlot> {
|
|
240
|
+
createSlot(key: TKey, storeSlot: TOIMStoreSlot, slotOwner: IOIMSlotOwner): TSlot;
|
|
241
|
+
}
|
|
242
|
+
interface IOIMSingleSlotCreator<TSlot> {
|
|
243
|
+
createSingleSlot(storeSlot: TOIMStoreSlot, slotOwner: IOIMSlotOwner): TSlot;
|
|
244
|
+
}
|
|
245
|
+
interface IOIMSlotContentWriter<TSlot, TContent> {
|
|
246
|
+
insertSlotContent(slot: TSlot, content: TContent, changedSlots?: TSlot[]): void;
|
|
247
|
+
writeSlotContent(slot: TSlot, content: TContent): boolean;
|
|
248
|
+
clearSlotContent(slot: TSlot): void;
|
|
249
|
+
}
|
|
250
|
+
interface IOIMSlotContentService<TSlot, TSlotOwnerService extends IOIMSlotOwner = IOIMSlotOwner> {
|
|
268
251
|
isSlotEmpty(slot: TSlot): boolean;
|
|
269
252
|
releaseSlotContent(slot: TSlot, slotOwnerService: TSlotOwnerService): void;
|
|
270
253
|
hasReference(slot: TSlot): boolean;
|
|
271
254
|
}
|
|
272
|
-
interface IOIMSlotContentFlushStrategy<TSlot, TSlotOwnerService> {
|
|
273
|
-
onSubframeClosed(storeSlot: TOIMStoreSlot<unknown, TSlot>, slotOwnerService: TSlotOwnerService): void;
|
|
274
|
-
}
|
|
275
255
|
```
|
|
276
256
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
257
|
+
A content service with `createSlot` goes into `createOIMSlotCollectionService`, one with `createSingleSlot` into
|
|
258
|
+
`createOIMSingleSlotService`; the entity and bucket content services have both. `hasReference` answers whether
|
|
259
|
+
something outside `holdCount` and `effects` keeps the slot (a bucket's members). Every write door asserts the
|
|
260
|
+
identity is still filed (`assertWritable`), and `releaseSlotContent` refuses inside a flush when the slot still
|
|
261
|
+
has content.
|
|
280
262
|
|
|
281
263
|
### The injected seams
|
|
282
264
|
|
|
@@ -285,26 +267,26 @@ question that the engine asks but does not decide. There is no flag and no optio
|
|
|
285
267
|
object.
|
|
286
268
|
|
|
287
269
|
```ts signature
|
|
288
|
-
interface
|
|
270
|
+
interface IOIMSlotEmptinessPolicy<TSlot> { isEmpty(slot: TSlot): boolean; }
|
|
289
271
|
|
|
290
272
|
interface IOIMSlotStamp<TSlot> { stamp(slotEditable: TOIMSlotEditable<TSlot>): void; }
|
|
291
273
|
```
|
|
292
274
|
|
|
293
275
|
**What a kind of content answers is not a seam.** Mint, write, clear and release
|
|
294
|
-
belong to the content service, which the
|
|
276
|
+
belong to the content service, which the collection service hands its owner as `slotContentService`.
|
|
295
277
|
"Does this still hold something" no part declares — the owner asks `oimIsSlotEmpty(slot)`,
|
|
296
278
|
`hasReference` and the release policy's `isSlotReleasable` separately.
|
|
297
279
|
|
|
298
|
-
**`
|
|
280
|
+
**`IOIMSlotEmptinessPolicy`** decides what counts as empty, and the answer is written once
|
|
299
281
|
per write into the EMPTY flag of `slot.slotFlags` — never recomputed at a read. The entity content
|
|
300
|
-
service defaults to "the entity is `undefined`" (the `
|
|
282
|
+
service defaults to "the entity is `undefined`" (the `slotEmptinessPolicy` option of
|
|
301
283
|
`createOIMSlotContentEntityService` replaces it); a bucket content service answers "no members"; a
|
|
302
284
|
computed answers `false`, because a derivation always has a value to produce.
|
|
303
285
|
|
|
304
|
-
**Emptiness decides lifetime, never the write path.**
|
|
305
|
-
still carries an entity
|
|
306
|
-
soft delete, a seed planted by `IOIMSlotStamp`): a column the new entity drops is
|
|
307
|
-
woken, an unchanged one is not, and
|
|
286
|
+
**Emptiness decides lifetime, never the write path.** A `writeSlotContent` (or `writeSlotContentByKey` on a
|
|
287
|
+
hit) onto an entity slot that still carries an entity is put over it even when emptiness calls the slot empty
|
|
288
|
+
(a soft delete, a seed planted by `IOIMSlotStamp`): a column the new entity drops is
|
|
289
|
+
woken, an unchanged one is not, and a write that repeats the entity exactly wakes
|
|
308
290
|
nothing. Only an entity slot with no entity at all is filled whole.
|
|
309
291
|
|
|
310
292
|
**`IOIMSlotStamp`** writes onto the slot at every write, just before emptiness is
|
|
@@ -325,53 +307,67 @@ interface IOIMSlotReleasePolicy {
|
|
|
325
307
|
cancelSlotRelease(slot: TOIMSlot): void;
|
|
326
308
|
}
|
|
327
309
|
|
|
328
|
-
new
|
|
329
|
-
|
|
330
|
-
new
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
310
|
+
new OIMSlotAfterWriteReleasePolicy({ keepAfterWriteMs: number, slotReleaseDueFramePolicy?: IOIMSlotReleaseDueFramePolicy })
|
|
311
|
+
OIMSlotReleaseAutoDueFramePolicy.INSTANCE
|
|
312
|
+
new OIMSlotReleaseManualDueFramePolicy() // openSlotReleaseDueFrame() · closeSlotReleaseDueFrame() · writeInSlotReleaseDueFrame(write)
|
|
313
|
+
new OIMSlotAfterIdleReleasePolicy({ keepAfterIdleMs: number })
|
|
314
|
+
new OIMSlotAfterUnholdReleasePolicy({ keepAfterUnholdMs: number })
|
|
315
|
+
OIMSlotAtUnholdReleasePolicy.INSTANCE
|
|
316
|
+
OIMSlotAtEmptyReleasePolicy.INSTANCE
|
|
317
|
+
OIMSlotNeverReleasePolicy.INSTANCE
|
|
318
|
+
new OIMSlotEarliestReleasePolicy(slotReleasePolicies: readonly IOIMSlotReleasePolicy[])
|
|
335
319
|
```
|
|
336
320
|
|
|
337
321
|
`releasesWrittenSlots` is whether the policy can ever release a slot that holds
|
|
338
322
|
data; a service reads it once at construction and skips the after-write
|
|
339
|
-
release check when it is false (`
|
|
340
|
-
`
|
|
323
|
+
release check when it is false (`OIMSlotAtEmptyReleasePolicy`, `OIMSlotNeverReleasePolicy`: false;
|
|
324
|
+
`OIMSlotAtUnholdReleasePolicy` and the timed policies: true; `OIMSlotEarliestReleasePolicy`: true
|
|
341
325
|
when any policy it combines is).
|
|
342
326
|
|
|
343
327
|
`schedulesReleaseOnWrite` is whether a write can make the policy schedule a release; a service
|
|
344
328
|
reads it once at construction and, when it is false and no `slotStamp` is set, skips `onSlotWritten`
|
|
345
|
-
and the first-fill `onSlotIdle` on every write (`
|
|
346
|
-
true; `
|
|
347
|
-
`
|
|
329
|
+
and the first-fill `onSlotIdle` on every write (`OIMSlotAfterWriteReleasePolicy`, `OIMSlotAfterIdleReleasePolicy`:
|
|
330
|
+
true; `OIMSlotAtEmptyReleasePolicy`, `OIMSlotNeverReleasePolicy`, `OIMSlotAtUnholdReleasePolicy`,
|
|
331
|
+
`OIMSlotAfterUnholdReleasePolicy`: false; `OIMSlotEarliestReleasePolicy`: true when any policy it combines is).
|
|
348
332
|
`onSlotIdle` is still called when the last subscriber leaves.
|
|
349
333
|
|
|
350
334
|
A policy decides whether and when a slot goes; it does no work itself. A
|
|
351
335
|
factory, and `OIMDB` (whose `slotReleasePolicy` option every factory reads as its default), takes ONE
|
|
352
336
|
through the option `slotReleasePolicy`. With none, the slot owner is built with
|
|
353
|
-
`
|
|
337
|
+
`OIMSlotAtEmptyReleasePolicy`, so a slot with a value stays for good and an empty
|
|
354
338
|
one with nothing holding it goes; there is no "no policy" branch on any path.
|
|
355
|
-
Computed services default to `
|
|
339
|
+
Computed services default to `OIMSlotAtUnholdReleasePolicy`.
|
|
356
340
|
|
|
357
341
|
| Policy | A slot goes |
|
|
358
342
|
|---|---|
|
|
359
|
-
| `
|
|
360
|
-
| `
|
|
361
|
-
| `
|
|
362
|
-
| `
|
|
363
|
-
| `
|
|
364
|
-
| `
|
|
365
|
-
| `
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
`
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
`
|
|
343
|
+
| `OIMSlotAfterWriteReleasePolicy` | once its last write is older than `keepAfterWriteMs` |
|
|
344
|
+
| `OIMSlotAfterIdleReleasePolicy` | once nothing has watched it for `keepAfterIdleMs` |
|
|
345
|
+
| `OIMSlotAfterUnholdReleasePolicy` | once `keepAfterUnholdMs` has passed since its LAST unhold; a hold taken again inside the window keeps it |
|
|
346
|
+
| `OIMSlotAtUnholdReleasePolicy` | at the last unhold, even with a value |
|
|
347
|
+
| `OIMSlotAtEmptyReleasePolicy` | once it has no value and nothing holds it; a computed, never empty, stays while its owner lives |
|
|
348
|
+
| `OIMSlotNeverReleasePolicy` | never, empty or not; a deleted key's slot stays filed |
|
|
349
|
+
| `OIMSlotEarliestReleasePolicy` | when the earliest deadline of its members falls due — a `min` over deadlines |
|
|
350
|
+
|
|
351
|
+
**WHICH WRITES MOVE THE WRITE DEADLINE is a strategy of `OIMSlotAfterWriteReleasePolicy`**,
|
|
352
|
+
`slotReleaseDueFramePolicy`, chosen at construction. `OIMSlotReleaseAutoDueFramePolicy` (the default)
|
|
353
|
+
makes every write its own frame, so every write moves the deadline. `OIMSlotReleaseManualDueFramePolicy`
|
|
354
|
+
moves it only for writes made while one of its frames is open: `openSlotReleaseDueFrame()` and
|
|
355
|
+
`closeSlotReleaseDueFrame()` (which throws by name when no frame is open), or
|
|
356
|
+
`writeInSlotReleaseDueFrame(write)`, which opens, calls `write` and closes in a `finally`. One Manual object
|
|
357
|
+
can be passed to several `OIMSlotAfterWriteReleasePolicy` policies with different windows: one frame then moves each slot's
|
|
358
|
+
deadline by its own collection's window. This is what keeps a local edit or a client-only field from
|
|
359
|
+
extending data that only a server response should refresh. `write` must be synchronous: a frame closes
|
|
360
|
+
when the function returns.
|
|
361
|
+
|
|
362
|
+
The release wheels live on the db's collector slot, at most one of each per `OIMDB`:
|
|
363
|
+
`db.collectorSlot.afterWriteSlotReleaseWheel`, `afterIdleSlotReleaseWheel` and
|
|
364
|
+
`afterUnholdSlotReleaseWheel`, each an `OIMSlotReleaseWheel` that holds its own slices, timer and clock.
|
|
365
|
+
A wheel is created by the first policy that needs it, through `oimMintAfterWriteSlotReleaseWheel(collectorSlot)`
|
|
366
|
+
(and its after-idle and after-unhold twins), which returns the existing wheel or creates it; until then the field is
|
|
367
|
+
`undefined`, and a db with no timed policy never pulls the wheel code into a bundle. The
|
|
372
368
|
clock and the timer are the db's: pass `new OIMDB({ getNowMs, releaseTimer })` to control time (tests),
|
|
373
|
-
and sweep with `
|
|
374
|
-
`
|
|
369
|
+
and sweep with `oimMintAfterIdleSlotReleaseWheel(db.collectorSlot).flush()`.
|
|
370
|
+
`OIMSlotAtUnholdReleasePolicy` is the zero window and has no collector.
|
|
375
371
|
|
|
376
372
|
A zero window never touches a release queue or a timer: when a slot goes idle with
|
|
377
373
|
`onSlotIdle` answering `true`, it is released at once if nothing holds it, and
|
|
@@ -380,16 +376,11 @@ leaves at the end of the frame. A window above zero is filed in that policy's ow
|
|
|
380
376
|
queue.
|
|
381
377
|
|
|
382
378
|
```ts
|
|
383
|
-
import {
|
|
384
|
-
OIMSlotReleasePolicyAfterIdle,
|
|
385
|
-
OIMSlotReleasePolicyAfterWrite,
|
|
386
|
-
OIMSlotReleasePolicyEarliest,
|
|
387
|
-
} from '@oimdb/core';
|
|
388
379
|
|
|
389
380
|
const releasingDb = new OIMDB({
|
|
390
|
-
slotReleasePolicy: new
|
|
391
|
-
new
|
|
392
|
-
new
|
|
381
|
+
slotReleasePolicy: new OIMSlotEarliestReleasePolicy([
|
|
382
|
+
new OIMSlotAfterWriteReleasePolicy({ keepAfterWriteMs: 60_000 }),
|
|
383
|
+
new OIMSlotAfterIdleReleasePolicy({ keepAfterIdleMs: 30_000 }),
|
|
393
384
|
]),
|
|
394
385
|
});
|
|
395
386
|
```
|
|
@@ -401,9 +392,9 @@ no other:
|
|
|
401
392
|
|
|
402
393
|
| Marker | Moved by | Not moved by |
|
|
403
394
|
|---|---|---|
|
|
404
|
-
| `releaseDueAfterWriteMs` | every write, under `
|
|
405
|
-
| `releaseDueAfterIdleMs` | the first content of a slot with no subscriber, and the departure of the last subscriber, under `
|
|
406
|
-
| `releaseDueAfterUnholdMs` | every last unhold, under `
|
|
395
|
+
| `releaseDueAfterWriteMs` | every write, under `OIMSlotAfterWriteReleasePolicy` | a subscriber arriving or leaving |
|
|
396
|
+
| `releaseDueAfterIdleMs` | the first content of a slot with no subscriber, and the departure of the last subscriber, under `OIMSlotAfterIdleReleasePolicy` | a later write, and the give-back of a hold |
|
|
397
|
+
| `releaseDueAfterUnholdMs` | every last unhold, under `OIMSlotAfterUnholdReleasePolicy` | a write |
|
|
407
398
|
|
|
408
399
|
`-1` means unset. A slot goes on the SOONEST of those that are set — each
|
|
409
400
|
marker is an eviction deadline, so whichever says "out" first decides — and a
|
|
@@ -424,8 +415,8 @@ now; `false` keeps it, and a policy with a finite deadline has itself filed the
|
|
|
424
415
|
slot into its release queue (a marker of `-1` is kept with nothing scheduled).
|
|
425
416
|
An **empty** slot is released without asking, and a service given no release
|
|
426
417
|
policy keeps a non-empty slot. `OIMComputedService` defaults its policy to
|
|
427
|
-
`
|
|
428
|
-
nothing refers to goes at once. `
|
|
418
|
+
`OIMSlotAtUnholdReleasePolicy`, which always answers `true`, so a derivation
|
|
419
|
+
nothing refers to goes at once. `OIMSlotEarliestReleasePolicy` asks every member
|
|
429
420
|
and answers `true` if any does.
|
|
430
421
|
|
|
431
422
|
**AN IDLE WINDOW OPENS IN EXACTLY TWO PLACES, AND NOWHERE ELSE:**
|
|
@@ -436,7 +427,7 @@ and answers `true` if any does.
|
|
|
436
427
|
2. **when the LAST SUBSCRIBER leaves** — `OIMSlotOwner.unsubscribeFromSlot` empties
|
|
437
428
|
`slot.effects` and runs the idle step, which opens one.
|
|
438
429
|
|
|
439
|
-
Both ask the policy's `onSlotIdle(slot)`; under `
|
|
430
|
+
Both ask the policy's `onSlotIdle(slot)`; under `OIMSlotAfterIdleReleasePolicy`
|
|
440
431
|
it stamps `releaseDueAfterIdleMs` and files the slot into the policy's queue. An
|
|
441
432
|
**empty** slot gets no window, and the release guard takes it without asking a
|
|
442
433
|
clock at all.
|
|
@@ -450,60 +441,65 @@ therefore taken at the give-back and not one window later.
|
|
|
450
441
|
nothing — and the queue has taken the slot off its slice, so nothing re-files it.
|
|
451
442
|
The give-back is where the guard is asked again.
|
|
452
443
|
|
|
453
|
-
### The
|
|
444
|
+
### The release wheels
|
|
454
445
|
|
|
455
|
-
Each of `
|
|
456
|
-
`
|
|
457
|
-
|
|
458
|
-
|
|
446
|
+
Each of `OIMSlotAfterWriteReleasePolicy`, `OIMSlotAfterIdleReleasePolicy` and
|
|
447
|
+
`OIMSlotAfterUnholdReleasePolicy` files into its own release wheel, and the difference between the wheels
|
|
448
|
+
is WHICH MARKER each reads and writes — injected at construction, so there is no flag and no branch on the
|
|
449
|
+
sweep path. A wheel is an aggregate: its slices, its timer and its clock are fields of the object.
|
|
459
450
|
|
|
460
451
|
```ts signature
|
|
461
|
-
abstract class
|
|
452
|
+
abstract class OIMSlotWheel {
|
|
453
|
+
readonly getNowMs: () => number;
|
|
454
|
+
getNextSliceNumber(): number | undefined; // the nearest filed slice, or undefined
|
|
455
|
+
sweepUpToSliceNumber(upToSliceNumber: number): void;
|
|
456
|
+
flush(): void; // sweeps what is due now and re-arms the timer
|
|
457
|
+
cancelAllSlots(): void; // takes the timer down and drops every filing
|
|
458
|
+
}
|
|
459
|
+
class OIMSlotReleaseWheel extends OIMSlotWheel {
|
|
460
|
+
constructor(options: TOIMSlotReleaseWheelOptions); // { getNowMs, timer, errorPolicy, getReleaseDueMs, setReleaseDueMs, releaseScheduledSlotFlag }
|
|
462
461
|
readonly getReleaseDueMs: (slot: TOIMSlot) => number;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
isSlotReleasable(
|
|
467
|
-
cancelSlotRelease(
|
|
468
|
-
|
|
469
|
-
cancelAllSlotReleases(releaseSlotCollectorSlot): void;
|
|
462
|
+
markSlotReleaseDue(slot, keepMs): number; // stamps now + keepMs on this marker, returns now
|
|
463
|
+
markSlotReleaseDueNow(slot): void; // the marker is now; an unheld, unwatched slot goes at once
|
|
464
|
+
scheduleSlotRelease(slot, nowMs): void; // files the slot at its marker; -1 or already filed files nothing
|
|
465
|
+
isSlotReleasable(slot): boolean; // due now; if not yet, files it on the wheel
|
|
466
|
+
cancelSlotRelease(slot): void; // no-op for a slot whose marker is -1
|
|
467
|
+
isSlotReleaseScheduled(slot): boolean;
|
|
470
468
|
}
|
|
471
|
-
OIMReleaseSlotCollectorServiceAfterIdle.INSTANCE
|
|
472
|
-
OIMReleaseSlotCollectorServiceAfterWrite.INSTANCE
|
|
473
|
-
OIMReleaseSlotCollectorServiceAfterUnhold.INSTANCE
|
|
474
469
|
|
|
475
470
|
type TOIMCollectorSlot = {
|
|
476
471
|
readonly unusedSlotCollectorSlot: TOIMUnusedSlotCollectorSlot;
|
|
477
|
-
readonly
|
|
478
|
-
|
|
479
|
-
|
|
472
|
+
readonly slotWheelOptions: TOIMSlotWheelOptions; // the db's clock, timer and error policy
|
|
473
|
+
afterIdleSlotReleaseWheel: OIMSlotReleaseWheel | undefined; // created on first use
|
|
474
|
+
afterWriteSlotReleaseWheel: OIMSlotReleaseWheel | undefined;
|
|
475
|
+
afterUnholdSlotReleaseWheel: OIMSlotReleaseWheel | undefined;
|
|
480
476
|
};
|
|
477
|
+
oimMintAfterWriteSlotReleaseWheel(collectorSlot): OIMSlotReleaseWheel // and …AfterIdle…, …AfterUnhold…
|
|
481
478
|
```
|
|
482
479
|
|
|
483
480
|
The clock (`getNowMs`, default `Date.now`), the timer (`releaseTimer`, default an unref'd `setTimeout`)
|
|
484
|
-
and the `errorPolicy` (default `
|
|
481
|
+
and the `errorPolicy` (default `OIMLogAndContinueErrorPolicy.INSTANCE`) are `OIMDB` options, shared by the
|
|
485
482
|
channel and every release collector of that db. A release that throws inside a hand-called `flush` throws to
|
|
486
483
|
that caller; one that throws on the collector's own timer tick has no caller and goes to the db's
|
|
487
484
|
`errorPolicy`. So one error policy on the db routes every error through one place:
|
|
488
485
|
|
|
489
486
|
```ts
|
|
490
|
-
import { OIMErrorPolicyThrowAtOnce, OIMSlotReleasePolicyAfterIdle } from '@oimdb/core';
|
|
491
487
|
|
|
492
488
|
const oneSinkDb = new OIMDB({
|
|
493
|
-
errorPolicy: new
|
|
494
|
-
slotReleasePolicy: new
|
|
489
|
+
errorPolicy: new OIMThrowAtOnceErrorPolicy(),
|
|
490
|
+
slotReleasePolicy: new OIMSlotAfterIdleReleasePolicy({ keepAfterIdleMs: 30_000 }),
|
|
495
491
|
});
|
|
496
492
|
```
|
|
497
493
|
|
|
498
|
-
|
|
|
494
|
+
| Wheel | Reads | What renews it | What does not |
|
|
499
495
|
|---|---|---|---|
|
|
500
|
-
| `
|
|
501
|
-
| `
|
|
502
|
-
| `
|
|
496
|
+
| `afterIdleSlotReleaseWheel` | `releaseDueAfterIdleMs` | the first content of a slot, and the give-back of the last hold | a later write |
|
|
497
|
+
| `afterWriteSlotReleaseWheel` | `releaseDueAfterWriteMs` | every write, under its policy | a subscriber arriving or leaving |
|
|
498
|
+
| `afterUnholdSlotReleaseWheel` | `releaseDueAfterUnholdMs` | every last unhold | a hold taken again inside the window |
|
|
503
499
|
|
|
504
|
-
**A CONSUMER MAY RUN BOTH, AND THEY SHARE NOTHING.** Each has its own
|
|
505
|
-
|
|
506
|
-
nothing has to be reconciled: `
|
|
500
|
+
**A CONSUMER MAY RUN BOTH, AND THEY SHARE NOTHING.** Each wheel has its own slices and its own
|
|
501
|
+
scheduled run. Whichever deadline falls due first takes the slot, and
|
|
502
|
+
nothing has to be reconciled: `OIMSlotEarliestReleasePolicy` answers a `min`
|
|
507
503
|
over its members' deadlines, so a sweep of either queue reaches the same verdict.
|
|
508
504
|
|
|
509
505
|
**NEITHER MEANS UNREAD.** No read is seen and no door reports one: an identity a
|
|
@@ -518,7 +514,7 @@ The slot owner's `releaseSlotIfUnheld` checks `holdCount > 0`, then
|
|
|
518
514
|
`oimIsSlotReleased(slot)`, then `slot.owner !== this`, then `hasReference(slot)`, and
|
|
519
515
|
only then — on a slot that is not empty — asks the policy's `isSlotReleasable`; an empty slot
|
|
520
516
|
asks `isEmptySlotReleasable` instead, which every policy but
|
|
521
|
-
`
|
|
517
|
+
`OIMSlotNeverReleasePolicy` answers `true`. So only `OIMSlotNeverReleasePolicy`
|
|
522
518
|
keeps an identity that holds nothing.
|
|
523
519
|
|
|
524
520
|
**A release that falls inside a flush waits for it to end.** Releasing a slot
|
|
@@ -530,7 +526,7 @@ back once the flush is over; the release then runs. An empty slot needs no write
|
|
|
530
526
|
and goes at once.
|
|
531
527
|
|
|
532
528
|
*The `owner !== this` line costs no lookup. A KEYLESS slot — a single's, filed in an
|
|
533
|
-
`
|
|
529
|
+
`OIMSingleSlotStoreService` store — goes through the same guard under its service's policy: an
|
|
534
530
|
emptied single bucket nothing holds is released like a keyed one, and the single service's
|
|
535
531
|
`getSingleSlot(storeSlot)` mints a fresh slot on the next read.*
|
|
536
532
|
|
|
@@ -561,28 +557,35 @@ Pinned by `engine/collector/tests/what-a-stale-index-takes-with-it.test.ts`,
|
|
|
561
557
|
|
|
562
558
|
### The release guard, and who fires it
|
|
563
559
|
|
|
564
|
-
**THE
|
|
565
|
-
`
|
|
560
|
+
**THE WHEEL DECIDES AT A DEADLINE, NOT THE OWNER.**
|
|
561
|
+
`OIMSlotReleaseWheel.sweepUpToSliceNumber`, per slot in a slice at or below the one due:
|
|
566
562
|
|
|
567
|
-
1. `oimIsSlotReleased(slot)` → skip it;
|
|
568
|
-
2. its own marker, read through `getReleaseDueMs(slot)` — the ONE field this
|
|
563
|
+
1. its bit is clear → a stale entry, skip it; `oimIsSlotReleased(slot)` → skip it;
|
|
564
|
+
2. its own marker, read through `getReleaseDueMs(slot)` — the ONE field this wheel
|
|
569
565
|
answers for;
|
|
570
|
-
3. `-1` → the slot is dropped from the
|
|
571
|
-
4. a moment still in the future → the
|
|
566
|
+
3. `-1` → the slot is dropped from the wheel: this policy does not claim it;
|
|
567
|
+
4. a moment still in the future → the wheel **re-files the slot itself**, into
|
|
572
568
|
`oimSliceOfMs(getReleaseDueMs)` through its own slice arithmetic;
|
|
573
569
|
5. a moment already passed → `slot.owner.releaseSlotIfUnheld(slot)`, which asks the
|
|
574
|
-
policy's `isSlotReleasable` and so declines when the other policy still keeps
|
|
575
|
-
the slot.
|
|
570
|
+
policy's `isSlotReleasable` and so declines when the other policy still keeps the
|
|
571
|
+
slot, or when the slot is held.
|
|
572
|
+
|
|
573
|
+
**INVALIDATING IS MARKING THE DEADLINE NOW.** `wheel.markSlotReleaseDueNow(slot)` sets this wheel's
|
|
574
|
+
marker to now and hands the slot to `slot.owner.releaseSlotIfUnheld(slot)` at once: a slot nothing
|
|
575
|
+
holds or watches goes with its data; a held or watched slot stays, keeps its data, and goes the moment
|
|
576
|
+
its last hold or subscriber leaves, because its deadline is already past. The next marked write moves
|
|
577
|
+
the marker a window ahead again. It writes no content, so it wakes no effect.
|
|
576
578
|
|
|
577
579
|
The owner files nothing from inside a sweep. It **opens** a window on its own
|
|
578
580
|
events, through the policy's `onSlotIdle` — when a slot first gets content, and
|
|
579
581
|
when the last subscriber leaves — and `onSlotUnheld` on the give-back of the last hold.
|
|
580
582
|
|
|
581
|
-
**A SLOT ALREADY ON A QUEUE STAYS WHERE IT IS.** `scheduleSlotRelease` of a slot
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
583
|
+
**A SLOT ALREADY ON A QUEUE STAYS WHERE IT IS.** `scheduleSlotRelease` of a slot that is
|
|
584
|
+
already filed moves nothing: the sweep re-reads the deadline when that slice comes
|
|
585
|
+
due and re-files the slot then (the timing-wheel lazy re-insertion). So a write to a
|
|
586
|
+
queued entity slot costs the queue one bit test, not an unfile and a refile. A
|
|
587
|
+
deadline only ever moves later — each policy adds a fixed window to a clock that
|
|
588
|
+
does not go back — so the slice a slot already sits in is never later than its deadline.
|
|
586
589
|
|
|
587
590
|
`releaseSlotIfUnheld(slot)` is the guard, and it releases only when all of
|
|
588
591
|
`holdCount === 0`, `oimIsSlotReleased(slot)` is false, `slot.owner === this`,
|
|
@@ -592,7 +595,7 @@ happens to it. On a slot that is not empty with time still owed, `isSlotReleasab
|
|
|
592
595
|
answers `false` and the policy files the slot into its queue at its own marker, so a
|
|
593
596
|
filing can neither shorten nor extend a deadline. That is the path from `unholdSlot` and from a write, never from a
|
|
594
597
|
sweep, which had already re-filed at step 4. Releasing hands the slot to the
|
|
595
|
-
content
|
|
598
|
+
content service's `releaseSlotContent` (which gives back what the content held),
|
|
596
599
|
marks the slot empty, calls the policy's `cancelSlotRelease(slot)`, unfiles the key
|
|
597
600
|
through the store service's `remove`, and sets the RELEASED flag in `slot.slotFlags`. The `owner` is NOT cleared — the slot keeps
|
|
598
601
|
pointing at the object that let it go, which is what makes `slot.owner !== this`
|
|
@@ -605,48 +608,48 @@ opposite:
|
|
|
605
608
|
`oimIsSlotReleased(slot)` and returns; it does not throw. A sweep meeting a slot
|
|
606
609
|
something else already let go must not raise.
|
|
607
610
|
- **Trying to WORK with a released slot throws by name.** `assertNotReleased`
|
|
608
|
-
guards the content services' write doors (`
|
|
609
|
-
`
|
|
611
|
+
guards the content services' write doors (`writeSlotContent`, `clearSlotContent`, `updateEntity`, `markEntityChanged`,
|
|
612
|
+
`addBucketMemberSlot`, `removeBucketMemberSlot`, `markContentChanged`) and the reference doors (`holdSlot`, `unholdSlot`, `subscribeToSlot`,
|
|
610
613
|
`unsubscribeFromSlot`). The refusal message starts `This identity was released:`.
|
|
611
614
|
|
|
612
|
-
### The
|
|
615
|
+
### The wheels and the unused-slot collector
|
|
613
616
|
|
|
614
617
|
```ts signature
|
|
615
|
-
|
|
616
|
-
|
|
618
|
+
oimMintAfterWriteSlotReleaseWheel(db.collectorSlot) // and …AfterIdle…, …AfterUnhold…
|
|
619
|
+
new OIMSlotRefetchWheel(options: TOIMSlotRefetchWheelOptions) // { slotRefetchListener, getNowMs?, timer?, errorPolicy? }
|
|
617
620
|
OIMUnusedSlotCollectorService.INSTANCE
|
|
618
621
|
createOIMUnusedSlotCollectorSlot(): TOIMUnusedSlotCollectorSlot
|
|
619
622
|
```
|
|
620
623
|
|
|
621
|
-
|
|
622
|
-
`
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
`
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
624
|
+
**A wheel is the clock.** `OIMSlotWheel` extends `OIMFlushSchedulerService` and is its own scheduled slot:
|
|
625
|
+
`flush()` sweeps what is due and re-arms the timer to the next deadline. `cancelAllSlots()` takes the timer
|
|
626
|
+
down and drops every filing; the next filing arms it again. The release wheels take the clock (`getNowMs`)
|
|
627
|
+
and the timer from the db, so a test drives them through `new OIMDB({ getNowMs, releaseTimer })`. The default
|
|
628
|
+
timer is a `setTimeout` that calls `unref` where the platform has it, so an idle Node process is not held open.
|
|
629
|
+
|
|
630
|
+
**A wheel files slots into time slices**, not one entry each. `oimSliceOfMs(ms)` is
|
|
631
|
+
`Math.floor(ms / OIM_SLICE_LENGTH_MS)` and `OIM_SLICE_LENGTH_MS` is `1024`, so every slot due inside the
|
|
632
|
+
same ~1s slice shares one array and one timer.
|
|
633
|
+
|
|
634
|
+
**WHETHER A SLOT IS ON A RELEASE WHEEL IS A BIT ON THE SLOT, NOT A MAP.** Each of the three release
|
|
635
|
+
wheels of a db owns one bit of `slot.slotFlags` (`releaseScheduledSlotFlag`, `4`, `8`, `16`), so a slot
|
|
636
|
+
can sit on all three at once, once on each. Filing pushes the slot onto its slice's array and sets the
|
|
637
|
+
bit; cancelling clears the bit and leaves the entry, which the sweep skips when its slice comes due. A
|
|
638
|
+
cancelled slot therefore keeps its slice named by `getNextSliceNumber` until that sweep.
|
|
639
|
+
|
|
640
|
+
A slot re-filed during a sweep cannot land in a slice the same sweep is still walking: the sweep raises a
|
|
641
|
+
floor for its duration, so a re-file — the wheel's own at step 4, or one a release makes — goes to the next
|
|
642
|
+
slice and is looked at next time, not in a loop.
|
|
643
|
+
|
|
644
|
+
**`OIMSlotRefetchWheel` is a wheel of slots due a refetch at an explicit time.** It computes no deadline,
|
|
645
|
+
keeps no bit and no field on the slot: `scheduleSlotRefetchAt(slot, atMs)` files an entry into the slice
|
|
646
|
+
of `atMs`, every call files one more. Its sweep takes only slices that have fully elapsed, skips released
|
|
647
|
+
slots, drops slots nobody subscribes to, and calls `slotRefetchListener.onSlotsRefetchDue(slots)` ONCE per
|
|
648
|
+
sweep with every watched slot that came due; the array is reused and emptied after the call, so a listener
|
|
649
|
+
does not keep it. Moving a refetch earlier is another `scheduleSlotRefetchAt`; the listener decides from
|
|
650
|
+
its own data whether an entry is current, so an early or duplicate entry is skipped there. The wheel is
|
|
651
|
+
created by whoever needs it, not by the db, and its clock, timer and error policy default to `Date.now`,
|
|
652
|
+
an unref'd `setTimeout` and `OIMLogAndContinueErrorPolicy.INSTANCE`.
|
|
650
653
|
|
|
651
654
|
**The unused-slot collector** has nothing to do with time. It is the one that makes
|
|
652
655
|
`getSlotByKey(storeSlot, key)` safe: `OIMUnusedSlotCollectorService.INSTANCE.holdSlotUntilFlush(unusedSlotCollectorSlot, slot)`
|
|
@@ -710,12 +713,12 @@ path. There is no `if (inPlace)` anywhere in the engine.
|
|
|
710
713
|
| Fork | Strategies |
|
|
711
714
|
|---|---|
|
|
712
715
|
| how a write lands | `createOIMEntityWriterInPlace()` / `createOIMEntityWriterReplacing()` |
|
|
713
|
-
| how a bucket holds slots | `
|
|
714
|
-
| what naming a slot records | `
|
|
715
|
-
| which writes re-sort a sorted list | `sortColumns` (only a write changing one of them on a member) / `comparator` alone (any member write), the options of `
|
|
716
|
+
| how a bucket holds slots | `OIMSlotContentSetBucketService` / `OIMSlotContentPositionalArrayBucketService` (the positions are the caller's) |
|
|
717
|
+
| what naming a slot records | `bucketMemberSlotsArrayService: OIMBucketMemberSlotsArrayService` (one per mention, the default) / `new OIMBucketUniqueMemberSlotsArrayService<TSlot>()` (one per slot), on either array bucket |
|
|
718
|
+
| which writes re-sort a sorted list | `sortColumns` (only a write changing one of them on a member) / `comparator` alone (any member write), the options of `createOIMSortedComputedService` |
|
|
716
719
|
| how a key is addressed | `OIMDefaults.KEY_TREE_WALK_SCALAR` / `OIMDefaults.KEY_TREE_WALK_COMPOSITE` |
|
|
717
|
-
| when a slot may go | `
|
|
718
|
-
| who decides a bucket's slots | a bucket collection (`
|
|
720
|
+
| when a slot may go | `OIMSlotAfterIdleReleasePolicy` / `OIMSlotAfterWriteReleasePolicy`, either or both |
|
|
721
|
+
| who decides a bucket's slots | a bucket collection (`createOIMSlotCollectionService` over a bucket content service, the caller) / an index (`createOIMSlotCollectionIndexService`, filed from the entity's own key) |
|
|
719
722
|
|
|
720
723
|
**One strategy per kind per app.** A V8 call site is shared by every service
|
|
721
724
|
that runs the same engine code, so mixing strategies of one kind in one process
|
|
@@ -725,7 +728,7 @@ V8 still caches each one and can still inline
|
|
|
725
728
|
per-site cache and no inlining through it. The kinds that count: release policies
|
|
726
729
|
(the `IOIMSlotReleasePolicy` strategies), set-driven vs array-driven buckets and indexes, entity
|
|
727
730
|
writers (`createOIMEntityWriterInPlace` / `createOIMEntityWriterReplacing`) and
|
|
728
|
-
`
|
|
731
|
+
`TOIMEntityInserter`, `TOIMSameValueGuard`, `IOIMSlotEmptinessPolicy`, and
|
|
729
732
|
`TOIMChannelScheduler`. Two or three of one kind is fine; five release policies in
|
|
730
733
|
one process is not. The pair
|
|
731
734
|
`alt.slot-shape.three-shapes-against-one-at-the-write` measures three slot shapes
|
|
@@ -736,27 +739,23 @@ Generate code with one strategy per kind unless the task names a second.
|
|
|
736
739
|
|
|
737
740
|
`createStoreSlot(db)` stamps the db's `defaultChannelSlot` on the store slot, and every write to its slots
|
|
738
741
|
is reported to that channel. No service holds a channel; there is no `channel` option and no
|
|
739
|
-
`unusedSlotCollector` option
|
|
742
|
+
`unusedSlotCollector` option:
|
|
740
743
|
|
|
741
744
|
```ts
|
|
742
|
-
const cardContentService = createOIMSlotContentEntityService<Card>(db
|
|
743
|
-
const handBuiltCardService = createOIMSlotCollectionService({ slotContentService: cardContentService });
|
|
745
|
+
const cardContentService = createOIMSlotContentEntityService<Card>(db);
|
|
746
|
+
const handBuiltCardService = createOIMSlotCollectionService(db, { slotContentService: cardContentService });
|
|
744
747
|
handBuiltCardService.createStoreSlot(db);
|
|
745
|
-
|
|
746
|
-
// THE CONVENIENCE WRAPPER — the same two calls in one:
|
|
747
|
-
createOIMEntityService<Card>(db, { keyOf: (c) => c.id }).createStoreSlot(db);
|
|
748
748
|
```
|
|
749
749
|
|
|
750
|
-
A single entity is `
|
|
751
|
-
`createOIMSlotContentEntityService(db, { slotStoreService: OIMSlotStoreServiceSingleSlotDriven.INSTANCE })`),
|
|
750
|
+
A single entity is `createOIMSingleSlotService(db, { slotContentService: createOIMSlotContentEntityService<T>(db) })`,
|
|
752
751
|
and its store slot takes the db's channel too and always reports.
|
|
753
752
|
|
|
754
753
|
### A bucket's slots are the caller's
|
|
755
754
|
|
|
756
755
|
A bucket's slots are a fact about the **response** being composed — a search result, a
|
|
757
756
|
page, a window — and **no column can express absence**. So a bucket collection
|
|
758
|
-
is manual, and `entityService.slotContentService.
|
|
759
|
-
bucket. Use an index (`
|
|
757
|
+
is manual, and `entityService.slotContentService.clearSlotContent(slot)` does not take a slot out of any
|
|
758
|
+
bucket. Use an index (`createOIMSlotCollectionIndexService`) when the slots are determined by the entity's key value,
|
|
760
759
|
and an index should maintain buckets only for keys being held.
|
|
761
760
|
|
|
762
761
|
---
|
|
@@ -773,7 +772,7 @@ new OIMDB(options?: TOIMDBOptions)
|
|
|
773
772
|
|
|
774
773
|
type TOIMDBOptions = {
|
|
775
774
|
channelScheduler?: TOIMChannelScheduler; // absent = you flush by hand
|
|
776
|
-
errorPolicy?: IOIMErrorPolicy; // absent =
|
|
775
|
+
errorPolicy?: IOIMErrorPolicy; // absent = OIMLogAndContinueErrorPolicy.INSTANCE
|
|
777
776
|
onBeforeFlush?: () => void; // start of the flush, before the frame; READ ONLY, a write is refused
|
|
778
777
|
getNowMs?: () => number; // the release collectors' clock; absent = Date.now
|
|
779
778
|
releaseTimer?: TOIMTimer; // the release collectors' timer; absent = an unref'd setTimeout
|
|
@@ -789,9 +788,9 @@ db.defaultChannelSlot // TOIMChannelSlot
|
|
|
789
788
|
db.flush() // OIMChannelService.INSTANCE.flush(db.defaultChannelSlot)
|
|
790
789
|
|
|
791
790
|
interface IOIMErrorPolicy { onErrorCaught(error: unknown): void }
|
|
792
|
-
|
|
793
|
-
new
|
|
794
|
-
new
|
|
791
|
+
OIMLogAndContinueErrorPolicy.INSTANCE // console.error; the flush goes on
|
|
792
|
+
new OIMLogAndContinueErrorPolicy({ onError?: (error: unknown) => void }) // console.error, then onError
|
|
793
|
+
new OIMThrowAtOnceErrorPolicy() // throws the first error out of the flush
|
|
795
794
|
```
|
|
796
795
|
|
|
797
796
|
**What the error policy covers** — every error with no synchronous caller to
|
|
@@ -802,7 +801,7 @@ hand-called collector `flush` — throws to it. `channelSlot.errorPolicy` is the
|
|
|
802
801
|
instance the channel reports through; it is the db's `errorPolicy`, which the release collectors share,
|
|
803
802
|
so one policy answers for the whole database. **The default digests and logs**: each throw goes to `console.error`
|
|
804
803
|
and then to `onError` (where Sentry or the devtools registry plugs in), and the
|
|
805
|
-
flush finishes every other effect and handler. `
|
|
804
|
+
flush finishes every other effect and handler. `OIMThrowAtOnceErrorPolicy` throws
|
|
806
805
|
the first error out of `flush()` at once; the effects the frame had not reached yet
|
|
807
806
|
stay queued and run at the next flush. **An effect whose body or cleanup threw
|
|
808
807
|
has not taken the change it woke for**: its `ranAtRevision`/`ranAtEpoch` are
|
|
@@ -853,10 +852,6 @@ Every door below is on `OIMChannelService.INSTANCE` and takes the channel slot f
|
|
|
853
852
|
| `assertNotFlushing(channelSlot)` | `void` — throws if the channel is flushing or its frame is running, i.e. for the whole of a flush |
|
|
854
853
|
| `write(channelSlot, slot)` | `void` — asks `assertNotFlushing`, then marks and queues |
|
|
855
854
|
| `writeWithoutFlushCheck(channelSlot, slot)` | `void` — the same marking and queueing WITHOUT the guard, for a door that already refused. Who may call it is pinned by `tests/who-may-write-without-asking-the-channel.test.ts`; a caller not on that list fails the suite |
|
|
856
|
-
| `openSubframe(channelSlot)` | `void` — a subframe opens, and the frame cannot close until it closes — `flush` throws meanwhile |
|
|
857
|
-
| `closeSubframe(channelSlot)` | `void` — it closes, delivering what was listed for its close and then asking for the frame it owes |
|
|
858
|
-
| `isSubframeOpen(channelSlot)` | `boolean` — whether a subframe is open right now, so a caller can defer work to its close instead of per write |
|
|
859
|
-
| `listChangedStoreSlot(channelSlot, storeSlot, subframeCloseListener)` | `void` — list a store slot whose changes are delivered when the OUTERMOST subframe closes, by calling `subframeCloseListener.onStoreSlotSubframeClosed(storeSlot)`; see below |
|
|
860
855
|
| `dropChannelSlot(channelSlot)` | `void` — kill the channel whole; see below |
|
|
861
856
|
| `isChangedInCurrentFrame(channelSlot, slot)` | `boolean` — whether the slot was written after the last frame ended, i.e. in the frame being collected now; compares `slot.changedAtRevision`/`changedAtEpoch` with the clock reading the last frame closed at. `OIMBucketCommands` keeps a bucket's render script across a flush only while this is true |
|
|
862
857
|
|
|
@@ -875,7 +870,7 @@ bucket, a computed — and a batch does not soften it: writes accumulate until
|
|
|
875
870
|
after it.
|
|
876
871
|
|
|
877
872
|
```ts
|
|
878
|
-
cardService.
|
|
873
|
+
cardService.writeSlotContentByKey(cards, 'a', { id: 'a', title: 'A', rank: 1, deck: 'spades' });
|
|
879
874
|
const entitySlot = cardService.getSlotByKey(cards, 'a');
|
|
880
875
|
|
|
881
876
|
effectService.createEffect(db, [entitySlot], [], () => { /* NEVER runs for the upsert above */ });
|
|
@@ -921,87 +916,27 @@ effectService.createEffect(db, [slot], [], () => {
|
|
|
921
916
|
- One list, not two: it goes into the same set at the same phase, so one-shot and
|
|
922
917
|
standing handlers are called in registration order among each other.
|
|
923
918
|
|
|
924
|
-
### `
|
|
925
|
-
|
|
926
|
-
A
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
bucket. Under a synchronous scheduler that gap used to flush — an auto-index
|
|
946
|
-
settled over a bucket the entity slot had not joined yet, stamped itself past the
|
|
947
|
-
entity slot's revision, and the entity was invisible to that index forever with nothing
|
|
948
|
-
thrown.
|
|
949
|
-
- `closeSubframe` is called from a `finally` by every opener, so a subframe that
|
|
950
|
-
threw part-way still closes and still delivers what it managed to write.
|
|
951
|
-
- **The span belongs to the DOOR, and exactly one door opens it.** The entity content service's
|
|
952
|
-
`writeEntity`, `deleteEntity`, `deleteEntities`, `fillEntities`, `updateEntity` and `markEntityChanged` each
|
|
953
|
-
open one — except a write that is exactly one channel write, which opens none — one write cannot be seen
|
|
954
|
-
half-done, and there is nobody to batch for: `updateEntity`/`updateEntityColumn` and `deleteEntity` when
|
|
955
|
-
the store slot has no content listener, no column of the entity is referenced and emptiness is not
|
|
956
|
-
recomputed on a column write; the entity writer's `fillEntity`, `putEntity`, `patchEntity`, `deleteColumns`
|
|
957
|
-
and `clearEntity` open none. One `upsertEntity` therefore opens one span, and one `insertEntities` opens one
|
|
958
|
-
however many entities it carries. The one exception is the content strategy's `releaseSlotContent`, which
|
|
959
|
-
keeps its own: `releaseSlotIfUnheld` reaches it when a release deadline has passed, and that call arrives
|
|
960
|
-
from the release queue through no door at all — so a removal opens two and an eviction opens one.
|
|
961
|
-
- Every write door of a content service is wrapped in the channel's `openSubframe` / `closeSubframe` on
|
|
962
|
-
`storeSlot.channelSlot`.
|
|
963
|
-
- **Every bucket door wakes the bucket the same way.** Each door of a bucket content service that changed
|
|
964
|
-
the bucket — `addBucketMemberSlot(s)`, `removeBucketMemberSlot(s)`,
|
|
965
|
-
`insertBucketMemberSlotAt`, `removeBucketMemberSlotAt` / `…Range`, both moves,
|
|
966
|
-
`writeBucketMemberSlots`, `clearBucketMemberSlots` — lists the bucket's store slot on the channel
|
|
967
|
-
(`listChangedStoreSlot`) and sets the bucket's EMPTY flag there and then; the outermost `closeSubframe`
|
|
968
|
-
stamps each changed bucket once, tells its release policy `onSlotWritten` once, and only then asks
|
|
969
|
-
whether it may go. So `hasSlotContentByKey` answers right inside an open batch, a
|
|
970
|
-
batch that mixes doors stamps the bucket once, a move renews a write deadline,
|
|
971
|
-
and a door that changed nothing stamps nothing and tells the policy nothing.
|
|
972
|
-
Commands are still recorded at the door, because a position is true only when it
|
|
973
|
-
is written. A release asked for while the bucket has a pending change waits for
|
|
974
|
-
the close.
|
|
975
|
-
- **A content listener that throws on one bucket does not strand the others.**
|
|
976
|
-
The close stamps every filed bucket and settles it before its listeners run,
|
|
977
|
-
goes on to the next bucket when one listener throws, and rethrows the first error
|
|
978
|
-
once every bucket is through — costing nothing when nothing throws.
|
|
979
|
-
- **A released identity is refused before the bucket changes.** Every door that
|
|
980
|
-
takes a member — the add doors, the doors by key, `insertBucketMemberSlotAt`,
|
|
981
|
-
a whole-list `writeBucketMemberSlots`, and the fill of a minted bucket — checks what it was
|
|
982
|
-
handed with `oimIsSlotReleased` first and throws, so a refused door leaves the members,
|
|
983
|
-
their holds and the EMPTY flag exactly as they were. It costs one field read per
|
|
984
|
-
member handed in.
|
|
985
|
-
|
|
986
|
-
### `isSubframeOpen(channelSlot)` / `listChangedStoreSlot(channelSlot, storeSlot, subframeCloseListener)`
|
|
987
|
-
|
|
988
|
-
**What a batch does once instead of per entity.** A subframe is the unit a
|
|
989
|
-
service can defer work to the end of: `listChangedStoreSlot` lists a store slot together with the
|
|
990
|
-
`IOIMSubframeCloseListener` (`onStoreSlotSubframeClosed(storeSlot)`) that delivers its changes, and the
|
|
991
|
-
outermost `closeSubframe` calls each listed listener with its store slot. `isSubframeOpen` says whether there
|
|
992
|
-
is a subframe to defer into at all — with none, the caller does the work immediately.
|
|
993
|
-
|
|
994
|
-
- **The drain runs before the count drops**, so a listener that writes is still inside the subframe and
|
|
995
|
-
still cannot close the frame. A store slot listed by a listener during the drain is picked up by the same
|
|
996
|
-
drain.
|
|
997
|
-
- **Every listed entry runs.** A listener that throws loses its own work for that batch and nothing retries
|
|
998
|
-
it; the entries after it still run, the list is emptied, the count still drops, the frame the subframe
|
|
999
|
-
owed is still asked for, and then the FIRST throw leaves `closeSubframe`.
|
|
1000
|
-
- **What uses it**: the bucket content services. A join or a leave records the bucket slot on its store
|
|
1001
|
-
slot's write queues and lists that store slot; the drain then writes the channel, settles emptiness and
|
|
1002
|
-
asks `releaseSlotIfUnheld` **once per bucket per batch** rather than once per member. Filing 10 000 entity
|
|
1003
|
-
slots into 100 buckets pays 100 of each tail instead of 10 000. Nothing is delivered before the flush either
|
|
1004
|
-
way, so the two are behaviourally the same.
|
|
919
|
+
### Batches: `openBatch` / `closeBatch` / `writeInBatch` on a collection
|
|
920
|
+
|
|
921
|
+
There are no bulk writes. A load or a sync is a loop of single writes, and a collection
|
|
922
|
+
service wraps it in a batch on its store slot:
|
|
923
|
+
|
|
924
|
+
```ts
|
|
925
|
+
cardService.writeInBatch(cards, () => {
|
|
926
|
+
for (const card of payload) cardService.writeSlotContentByKey(cards, card.id, card);
|
|
927
|
+
});
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
- `openBatch(storeSlot)` / `closeBatch(storeSlot)` nest by a count on the store slot; `writeInBatch` is the
|
|
931
|
+
`try/finally` form and returns what its function returns.
|
|
932
|
+
- **What the batch changes is who hears the writes, and when.** A content-change listener on the store slot (an
|
|
933
|
+
index on the collection) hears every write of the batch in ONE call, `onContentChangedMany`, when the
|
|
934
|
+
outermost batch closes. Code inside the batch reads the index as it was before the batch.
|
|
935
|
+
- Effects are not batched by it: every write marks its slot on the channel as usual, and the frame delivers each
|
|
936
|
+
identity once whatever the batch did. A `flush()` inside a batch is allowed; the index catches up when the
|
|
937
|
+
batch closes.
|
|
938
|
+
- A single write outside a batch tells the index at once, and is not rolled back: the slot is filed first and the
|
|
939
|
+
index is told after, so an index that throws leaves the write in place and the throw reaches the caller.
|
|
1005
940
|
|
|
1006
941
|
### `dropChannelSlot(channelSlot)`
|
|
1007
942
|
|
|
@@ -1051,19 +986,11 @@ OIMChannelService.INSTANCE.dropChannelSlot(db.defaultChannelSlot);
|
|
|
1051
986
|
`finally`; `assertNotFlushing` throws on `isFlushing` or `frame.isRunning`, so
|
|
1052
987
|
all three phases are refused. Refusal is per channel: a flush of one db's channel does not refuse a
|
|
1053
988
|
write to another db's.
|
|
1054
|
-
- **A refused write keeps its change pending — it is never dropped.** A bucket
|
|
1055
|
-
carries a change `addBucketMemberSlots`/`removeBucketMemberSlots` recorded inside an outer open batch
|
|
1056
|
-
until that batch closes. If something delivers it mid-flush — a member's
|
|
1057
|
-
subscriber giving the list back, so `unholdSlot` reaches `releaseSlotIfUnheld` —
|
|
1058
|
-
the write is refused and the bucket's store slot stays listed, so the next
|
|
1059
|
-
subframe close delivers it.
|
|
1060
989
|
- **Each door asks once, then writes through `writeWithoutFlushCheck`.** A content service
|
|
1061
990
|
door opens with `assertWritable`, which asks the channel, and every write it
|
|
1062
|
-
makes after that asks nothing
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
removable and stays — user code runs inside a door (`keyOf`, `index.keyOf`,
|
|
1066
|
-
`slotEmptiness.isEmpty`, an `IOIMEntityWriter`) and can call
|
|
991
|
+
makes after that asks nothing. The per-entity ask is NOT
|
|
992
|
+
removable and stays — user code runs inside a door (`index.keyOf`,
|
|
993
|
+
`slotEmptinessPolicy.isEmpty`, an `IOIMEntityWriter`) and can call
|
|
1067
994
|
`flush()`, so each entity is a new question. What went is the SECOND and THIRD ask
|
|
1068
995
|
of the same entity.
|
|
1069
996
|
- **`flush` during a frame throws:** the message says a frame is already running, and a second one
|
|
@@ -1078,7 +1005,7 @@ OIMChannelService.INSTANCE.dropChannelSlot(db.defaultChannelSlot);
|
|
|
1078
1005
|
hands the work to a microtask or a later callback rather than writing itself.
|
|
1079
1006
|
- A refusal raised from a tail handler does NOT reach the caller at the call: it
|
|
1080
1007
|
goes to the error policy like any handler throw — logged by default, or thrown
|
|
1081
|
-
out of `flush()` under `
|
|
1008
|
+
out of `flush()` under `OIMThrowAtOnceErrorPolicy`.
|
|
1082
1009
|
- Effects are isolated under the default policy: a throw is logged and handed to
|
|
1083
1010
|
`onError`, and the frame finishes every other effect.
|
|
1084
1011
|
- **A derivation is asked, never woken.** No frame walks to a computed slot.
|
|
@@ -1146,7 +1073,7 @@ class OIMEffectSourceTracker { // exported as a type; the service b
|
|
|
1146
1073
|
```
|
|
1147
1074
|
|
|
1148
1075
|
```ts
|
|
1149
|
-
const fallback = cardService.
|
|
1076
|
+
const fallback = cardService.writeSlotContentByKey(cards, 'c2', { id: 'c2', title: 'King', rank: 13, deck: 'hearts' });
|
|
1150
1077
|
effectService.createEffectWithSourceTracking(db, effectSourceTracker => {
|
|
1151
1078
|
const isFirst = effectSourceTracker.readSourceSlot(slot).entity?.rank === 1;
|
|
1152
1079
|
paint(effectSourceTracker.readSourceSlot(isFirst ? slot : fallback).entity);
|
|
@@ -1162,7 +1089,7 @@ effectService.createEffectWithSourceTracking(db, effectSourceTracker => {
|
|
|
1162
1089
|
creation. A returned function is the undo, exactly as for `TOIMEffectBody`.
|
|
1163
1090
|
|
|
1164
1091
|
```ts
|
|
1165
|
-
const onRank = effectService.createEffect(db, [cardService.holdColumn(slot, 'rank')], [], () => { paint(slot.entity); });
|
|
1092
|
+
const onRank = effectService.createEffect(db, [cardService.columnSlotService.holdColumn(slot, 'rank')], [], () => { paint(slot.entity); });
|
|
1166
1093
|
```
|
|
1167
1094
|
|
|
1168
1095
|
**A column effect takes the `TOIMColumnSlot` as a root, not a slot and a name.** Minting the
|
|
@@ -1178,7 +1105,7 @@ its carrier. An index store slot's buckets have the same doors on the index serv
|
|
|
1178
1105
|
`createEffect` returns the **effect**, not the column: a column holds no value; read `slot.entity[name]`.
|
|
1179
1106
|
|
|
1180
1107
|
**The name is compile-time checked only as far as the service's column-name type goes** —
|
|
1181
|
-
`holdColumn` takes the service's `TColumnName`, which `
|
|
1108
|
+
`holdColumn` takes the service's `TColumnName`, which `createOIMSlotContentEntityService` sets to
|
|
1182
1109
|
`TOIMEntityColumnName<TEntity>`. `TOIMEntityColumnName<TEntity>` is the type that narrows a name to the
|
|
1183
1110
|
entity's own columns, and `slotContentService.deleteEntityColumns` is typed on it.
|
|
1184
1111
|
|
|
@@ -1188,7 +1115,7 @@ per call; get it once per view, not per entity. `service.holdColumnGroup(slot, c
|
|
|
1188
1115
|
the group's column slot on `slot`, and `service.unholdColumn(columnSlot)` gives it back. A write wakes it once
|
|
1189
1116
|
if it changes any of the group's columns and not at all if it changes only others.
|
|
1190
1117
|
|
|
1191
|
-
**`columnNames` picks the column slot store.** `
|
|
1118
|
+
**`columnNames` picks the column slot store.** `createOIMSlotCollectionService(db, { slotContentService, columnNames: ['rank', 'label'] })`
|
|
1192
1119
|
— and `columnNames` on any factory's options — files the service's column slots by ordinal: every named column
|
|
1193
1120
|
gets a number, a group gets one at its first slot, and an entity slot's column slots sit in an array by
|
|
1194
1121
|
number instead of a `Map` per entity slot, which is cheaper to create and give back. `holdColumn` and
|
|
@@ -1221,26 +1148,21 @@ frame, with no further code. Every mutation goes through a domain neuron — a w
|
|
|
1221
1148
|
from outside the orchestrator is the mistake, not a case to cover with a fallback.
|
|
1222
1149
|
Full page: `website/docs/guides/with-cnstra.md`.
|
|
1223
1150
|
|
|
1224
|
-
The doors are free functions, one module each, so a consumer ships only the one they import. The
|
|
1225
|
-
|
|
1226
|
-
|
|
1151
|
+
The doors are free functions, one module each, so a consumer ships only the one they import. The collection,
|
|
1152
|
+
single and index factories take `db` first and ONE options object second; the computed factories take only
|
|
1153
|
+
the options object. Each builds a SERVICE,
|
|
1227
1154
|
once per collection type; the store slot is made separately:
|
|
1228
1155
|
|
|
1229
1156
|
| Door | Builds | Store slot |
|
|
1230
1157
|
|---|---|---|
|
|
1231
|
-
| `createOIMSlotContentEntityService(db, {
|
|
1232
|
-
| `createOIMSlotCollectionService({ slotContentService })` | `
|
|
1233
|
-
| `createOIMSingleSlotService({ slotContentService })` | `
|
|
1234
|
-
| `
|
|
1235
|
-
| `
|
|
1236
|
-
| `
|
|
1237
|
-
| `
|
|
1238
|
-
| `
|
|
1239
|
-
| `createOIMIndexServiceSortedArrayDriven(db, { entityService, columns? \| keyOf?, sortColumns, … })` | `OIMIndexServiceSortedArrayDriven`: the index whose buckets are kept in the order of `sortColumns` (`readonly TOIMSortColumn<TEntity>[]`, required) through an `OIMSlotContentBucketServiceSortedArrayDriven`. See [Sorted at write](#sorted-at-write) | `createIndexStoreSlot(entityStoreSlot)` |
|
|
1240
|
-
| `createOIMIndexServiceByCompositeKey(db, { entityService, columns? \| keyOf?, … })` | convenience wrapper: the index keyed by an array, `TKey extends readonly TOIMStoreKey[]`, inferred as a tuple from two or more inline columns or from an array-returning `keyOf`, over a tree store | `createIndexStoreSlot(entityStoreSlot)` |
|
|
1241
|
-
| `createOIMComputedService({ createSources?, derive?, sameValueGuard?, initialValue?, slotReleasePolicy?, computedSlotStoreService?, columnSlotStoreService?, columnNames? })` | `OIMComputedService<TKey, TValue, TComputedStore>`; its reads are on `computedService.computedCollectionService`; `derive` and `createSources` may instead be given per store slot; `computedSlotStoreService` is REQUIRED for a non-Map store (a single: `OIMSlotStoreServiceSingleSlotDriven`); see [One derivation per key](#one-derivation-per-key) | `createComputedStoreSlot(db, derive?, createSources?)` |
|
|
1242
|
-
| `createOIMComputedServiceSorted({ indexService, sortColumns?, comparator?, slotReleasePolicy?, columnSlotStoreService?, computedSlotStoreService? })` | `OIMComputedServiceSorted` — per key, the entity slots of the index bucket under that key, sorted; see [Sorted lists](#sorted-lists) | `createSortedStoreSlot(indexStoreSlot)` |
|
|
1243
|
-
| `createOIMComputedServiceBucketMemo({ bucketCollectionService, slotReleasePolicy?, columnSlotStoreService?, computedSlotStoreService? })` | `OIMComputedServiceBucketMemo` — per key, the bucket's slots as one array; see [The order of a bucket](#the-order-of-a-bucket-as-one-derivation-per-key) | `createBucketMemoStoreSlot(bucketStoreSlot)` |
|
|
1158
|
+
| `createOIMSlotContentEntityService<TEntity, TKey?, TColumnName?>(db, { entityWriter?, slotEmptinessPolicy? }?)` | `OIMSlotContentEntityService<TEntity, TKey, TColumnName>`, the entity content service; it creates keyed and single entity slots alike | — |
|
|
1159
|
+
| `createOIMSlotCollectionService(db, { slotContentService, slotStoreService?, slotReleasePolicy?, slotSubscriptionListener?, columnSlotStoreService? \| columnNames? })` | `OIMWritableSlotCollectionService` over any keyed content service (entity or bucket): the read doors, `writeSlotContentByKey`, the batch doors and `columnSlotService`. `slotStoreService` defaults to a Map store and is REQUIRED by type for an array key (`OIMSlotTreeStoreService`) | `createStoreSlot(db)` |
|
|
1160
|
+
| `createOIMSingleSlotService(db, { slotContentService, slotReleasePolicy?, slotSubscriptionListener?, columnSlotStoreService? \| columnNames? })` | `OIMWritableSingleSlotService` over any content service with `createSingleSlot` (entity or bucket) | `createStoreSlot(db)` |
|
|
1161
|
+
| `createOIMSlotCollectionIndexService(db, { entityService, columns? \| keyOf?, slotContentService?, bucketSlotStoreService?, slotReleasePolicy?, slotSubscriptionListener?, columnSlotStoreService? \| columnNames? })` | `OIMSlotCollectionIndexService`, over the entity collection service whose store slots it will index (it takes a `Pick` of `getSlots`); `slotContentService` defaults to an `OIMSlotContentPositionalArrayBucketService`, pass `new OIMSlotContentSetBucketService()` for an unordered one. A scalar key is inferred from ONE inline column or from `keyOf`'s return; an array key (two or more columns, or an array-returning `keyOf`) needs `bucketSlotStoreService: new OIMSlotTreeStoreService(…)` | `createIndexStoreSlot(entityStoreSlot)` |
|
|
1162
|
+
| `createOIMSlotCollectionSortedArrayIndexService(db, { entityService, columns? \| keyOf?, sortColumns, … })` | `OIMSlotCollectionSortedArrayIndexService`: the index whose buckets are kept in the order of `sortColumns` (`readonly TOIMSortColumn<TEntity>[]`, required) through an `OIMSlotContentSortedArrayBucketService`. See [Sorted at write](#sorted-at-write) | `createIndexStoreSlot(entityStoreSlot)` |
|
|
1163
|
+
| `createOIMComputedService({ createSources?, derive?, sameValueGuard?, initialValue?, slotReleasePolicy?, computedSlotStoreService?, columnSlotStoreService?, columnNames? })` | `OIMComputedService<TKey, TValue, TComputedStore>`; its reads are on `computedService.computedCollectionService`; `derive` and `createSources` may instead be given per store slot; `computedSlotStoreService` is REQUIRED for a non-Map store (a single: `OIMSingleSlotStoreService`); see [One derivation per key](#one-derivation-per-key) | `createComputedStoreSlot(db, derive?, createSources?)` |
|
|
1164
|
+
| `createOIMSortedComputedService({ indexService, sortColumns?, comparator?, slotReleasePolicy?, columnSlotStoreService?, computedSlotStoreService? })` | `OIMSortedComputedService` — per key, the entity slots of the index bucket under that key, sorted; see [Sorted lists](#sorted-lists) | `createSortedStoreSlot(indexStoreSlot)` |
|
|
1165
|
+
| `createOIMBucketMemoComputedService({ bucketCollectionService, slotReleasePolicy?, columnSlotStoreService?, computedSlotStoreService? })` | `OIMBucketMemoComputedService` — per key, the bucket's slots as one array; see [The order of a bucket](#the-order-of-a-bucket-as-one-derivation-per-key) | `createBucketMemoStoreSlot(bucketStoreSlot)` |
|
|
1244
1166
|
|
|
1245
1167
|
`entityWriter` and `slotReleasePolicy` on these doors default to the
|
|
1246
1168
|
db's, so naming one overrides it for that service alone.
|
|
@@ -1253,13 +1175,12 @@ which also fails when an option arrives on a service and is not forwarded,
|
|
|
1253
1175
|
when the root mints anything but the channel and the collector, or when a public
|
|
1254
1176
|
member appears on the root that is not one of the seven it owns.
|
|
1255
1177
|
|
|
1256
|
-
**`
|
|
1257
|
-
an `OIMSlotContentBucketServiceArrayDriven` — insertion order, never re-decided — that records an
|
|
1178
|
+
**`new OIMSlotContentPositionalArrayBucketService({ bucketCommands })` is the content service for a list whose order is yours.** It is — insertion order, never re-decided — that records an
|
|
1258
1179
|
`OIMBucketCommands` script per bucket. The recorder holds no subscription: it lists store slots on the channel
|
|
1259
1180
|
slot, and the script lives for one frame.
|
|
1260
1181
|
|
|
1261
1182
|
```ts
|
|
1262
|
-
const freshPageService =
|
|
1183
|
+
const freshPageService = createOIMSlotCollectionService(db, { slotContentService: new OIMSlotContentPositionalArrayBucketService<TOIMEntitySlot<Card>>({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: undefined }) }) });
|
|
1263
1184
|
const freshPage = freshPageService.createStoreSlot(db);
|
|
1264
1185
|
const freshBucketSlot = freshPageService.holdSlotByKey(freshPage, 'page-1');
|
|
1265
1186
|
// freshBucketSlot.commands and freshBucketSlot.isWholeListRecorded carry the script; read them in an effect on the bucket slot
|
|
@@ -1277,13 +1198,13 @@ construct one, never subclass it.
|
|
|
1277
1198
|
|---|---|---|
|
|
1278
1199
|
| `OIMDefaults.COLUMN_SLOT_STORE_SERVICE` | `IOIMSlotStoreService<string, TOIMColumnSlot>` | a map-driven store service for column slots; the factories pass it to every service they build without `columnNames` |
|
|
1279
1200
|
| `OIMDefaults.COMPUTED_COLUMN_SLOT_STORE_SERVICE` | `IOIMSlotStoreService<string, TOIMComputedColumnSlot>` | a map-driven store service for the column slots of computed services, keyed or single; the computed factories pass it to every one they build without `columnNames` |
|
|
1280
|
-
| `OIMDefaults.INDEX_KEYS_SERVICE` | `IOIMIndexKeysService` | `
|
|
1281
|
-
| `OIMDefaults.KEY_TREE_WALK_SCALAR` | `
|
|
1282
|
-
| `OIMDefaults.KEY_TREE_WALK_COMPOSITE` | `
|
|
1201
|
+
| `OIMDefaults.INDEX_KEYS_SERVICE` | `IOIMIndexKeysService` | `OIMAppendingIndexKeysService`; the factories pass it when `db.indexKeysService` is not set |
|
|
1202
|
+
| `OIMDefaults.KEY_TREE_WALK_SCALAR` | `OIMScalarKeyTreeWalk` | the chain-of-values walk |
|
|
1203
|
+
| `OIMDefaults.KEY_TREE_WALK_COMPOSITE` | `OIMCompositeKeyTreeWalk` | the chain-of-identities walk |
|
|
1283
1204
|
| `OIMDefaults.STANDALONE_SLOT_OWNER` | `OIMSlotOwner` | the owner of a slot nobody filed |
|
|
1284
1205
|
| `OIMDefaults.ENTITY_WRITER` | `IOIMEntityWriter` | `createOIMEntityWriterInPlace()` |
|
|
1285
|
-
| `OIMDefaults.ENTITY_SLOT_EMPTINESS` | `
|
|
1286
|
-
| `OIMDefaults.STORE_SLOT_LISTENER` | `IOIMStoreSlotListener` | `
|
|
1206
|
+
| `OIMDefaults.ENTITY_SLOT_EMPTINESS` | `IOIMSlotEmptinessPolicy<TOIMEntitySlot>` | "empty means `slot.entity === undefined`" |
|
|
1207
|
+
| `OIMDefaults.STORE_SLOT_LISTENER` | `IOIMStoreSlotListener` | `OIMNoStoreSlotListener`: hears nothing. Not a constructor option: every service reads it when it is built and calls `onStoreSlotCreated(storeSlot)` for each store slot it creates. A tool that wants to see every store slot sets its own with `setValue` before the first service is built; once one has been built, `setValue` throws |
|
|
1287
1208
|
|
|
1288
1209
|
**NOTHING IS CONSTRUCTED AT MODULE LOAD.** Every entry is an `OIMDefaultValue`
|
|
1289
1210
|
whose `getValue()` mints on its first call (`??=`) and hands the same instance back
|
|
@@ -1330,30 +1251,29 @@ with its slot owner; the collection service (`OIMSlotCollectionService`) over it
|
|
|
1330
1251
|
Neither holds an entity: each `createStoreSlot(db)` is one instance of that type's store.
|
|
1331
1252
|
|
|
1332
1253
|
```ts signature
|
|
1333
|
-
createOIMSlotContentEntityService<TEntity,
|
|
1334
|
-
keyOf: (entity: TEntity) => TKey; // REQUIRED for a key; absent for a single
|
|
1254
|
+
createOIMSlotContentEntityService<TEntity, TKey?, TColumnName?>(db, {
|
|
1335
1255
|
entityWriter?: IOIMEntityWriter; // db.entityWriter, then OIMDefaults.ENTITY_WRITER
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1256
|
+
slotEmptinessPolicy?: IOIMSlotEmptinessPolicy<TOIMEntityContentSlot<TEntity>>; // OIMDefaults.ENTITY_SLOT_EMPTINESS
|
|
1257
|
+
}?): OIMSlotContentEntityService<TEntity, TKey, TColumnName>
|
|
1258
|
+
|
|
1259
|
+
createOIMSlotCollectionService(db, {
|
|
1260
|
+
slotContentService,
|
|
1261
|
+
slotStoreService?: IOIMSlotStoreService<TKey, TSlot, TStore>; // Map; REQUIRED for an array key
|
|
1262
|
+
slotReleasePolicy?: IOIMSlotReleasePolicy; // db.slotReleasePolicy, then OIMSlotAtEmptyReleasePolicy
|
|
1263
|
+
slotSubscriptionListener?: IOIMSlotSubscriptionListener; // OIMNoSlotSubscriptionListener
|
|
1340
1264
|
columnSlotStoreService?: IOIMSlotStoreService<string, TOIMColumnSlot>; // OIMDefaults.COLUMN_SLOT_STORE_SERVICE
|
|
1341
1265
|
columnNames?: readonly TColumnName[]; // the ordinal column store over those names
|
|
1342
|
-
}):
|
|
1343
|
-
|
|
1344
|
-
createOIMSlotCollectionService({ slotContentService }): OIMSlotCollectionService<TKey, TOIMEntitySlot<TEntity, TKey>, TStore, …>
|
|
1345
|
-
collectionService.createStoreSlot(db): TOIMStoreSlot<TStore, TOIMEntitySlot<TEntity, TKey>, Partial<TEntity>>
|
|
1346
|
-
|
|
1347
|
-
createOIMEntityService<TEntity, TColumnName?, TKey?>(db, { keyOf, … }) // convenience: both calls, Map store
|
|
1266
|
+
}): OIMWritableSlotCollectionService<TKey, TOIMEntitySlot<TEntity, TKey>, TStore, TEntity, …>
|
|
1267
|
+
collectionService.createStoreSlot(db): TOIMStoreSlot<TStore, TOIMEntitySlot<TEntity, TKey>, Partial<TEntity>, typeof collectionService>
|
|
1348
1268
|
```
|
|
1349
1269
|
|
|
1350
1270
|
**Each collection type has its own column owner.** It is stateless configuration built with the slot owner
|
|
1351
1271
|
over `columnSlotStoreService` (or the ordinal store `columnNames` names); the column state — the column slots,
|
|
1352
1272
|
the column groups, and which columns are referenced — lives on the store slot. The doors are on the
|
|
1353
|
-
collection
|
|
1273
|
+
collection's `columnSlotService` (`getColumn`, `holdColumn`, `unholdColumn`, `getColumnGroup`, `holdColumnGroup`,
|
|
1354
1274
|
`getAnyColumn`, `holdAnyColumn`). The column owner has two strategies, chosen by the factory: write-driven
|
|
1355
|
-
column slots, woken by the marks a write makes (`
|
|
1356
|
-
derive-driven column slots, each a computed slot over its carrier (`
|
|
1275
|
+
column slots, woken by the marks a write makes (`OIMPushColumnSlotOwner`, entities and buckets), and
|
|
1276
|
+
derive-driven column slots, each a computed slot over its carrier (`OIMPullColumnSlotOwner`, computeds).
|
|
1357
1277
|
|
|
1358
1278
|
Example, over the `db`, `cardService`, `cards` and `slot` of the setup block:
|
|
1359
1279
|
|
|
@@ -1364,26 +1284,26 @@ db.flush();
|
|
|
1364
1284
|
effectService.disposeEffect(effect);
|
|
1365
1285
|
```
|
|
1366
1286
|
|
|
1367
|
-
Assembled
|
|
1287
|
+
Assembled with a store service of your own:
|
|
1368
1288
|
|
|
1369
1289
|
```ts
|
|
1370
|
-
const baseCardService = createOIMSlotCollectionService({
|
|
1371
|
-
slotContentService: createOIMSlotContentEntityService<Card>(db
|
|
1290
|
+
const baseCardService = createOIMSlotCollectionService(db, {
|
|
1291
|
+
slotContentService: createOIMSlotContentEntityService<Card, string>(db),
|
|
1292
|
+
slotStoreService: new OIMSlotMapStoreService<TOIMEntitySlot<Card, string>>(),
|
|
1372
1293
|
});
|
|
1373
1294
|
const baseCards = baseCardService.createStoreSlot(db);
|
|
1374
1295
|
```
|
|
1375
1296
|
|
|
1376
1297
|
The writer is omitted because the db and `OIMDefaults` supply it, and so is the column store. The slot stamp
|
|
1377
|
-
is not an option of
|
|
1298
|
+
is not an option of any factory: it is `new OIMDB({ slotStamp })`, for every collection of that db.
|
|
1378
1299
|
|
|
1379
1300
|
### Public properties
|
|
1380
1301
|
|
|
1381
1302
|
| Property | Of | Type |
|
|
1382
1303
|
|---|---|---|
|
|
1383
|
-
| `slotContentService` | the collection service | the content service: the write doors |
|
|
1384
|
-
| `
|
|
1385
|
-
| `
|
|
1386
|
-
| `slotStoreService` | the entity content service | the store service |
|
|
1304
|
+
| `slotContentService` | the collection service | the content service: the write doors on a slot |
|
|
1305
|
+
| `columnSlotService` | the collection service | `OIMColumnSlotService`: the column doors |
|
|
1306
|
+
| `slotService` | the store slot | the service that created it |
|
|
1387
1307
|
|
|
1388
1308
|
A store slot is not a slot, so nothing holds, subscribes or wakes it: there is no
|
|
1389
1309
|
`effectService.createEffect(db, [cards], …)` that hears the population. "Something in this population changed" is an
|
|
@@ -1407,7 +1327,7 @@ for (const filedSlot of cardService.getSlots(cards)) {
|
|
|
1407
1327
|
```
|
|
1408
1328
|
|
|
1409
1329
|
To have that answer MAINTAINED and subscribable instead of walked, declare an
|
|
1410
|
-
index keyed on the entity's own id (`keyOf: card => card.id`) and hold the key
|
|
1330
|
+
index keyed on the entity's own id (`keyOf: (card: Card) => card.id`) and hold the key
|
|
1411
1331
|
you want. An index's bucket is an injected lifetime — a
|
|
1412
1332
|
`slotReleasePolicy` — so it is the consumer who says how long the
|
|
1413
1333
|
answer outlives its last reader.
|
|
@@ -1416,13 +1336,12 @@ An index maintains buckets only while they are held, filing entity slots from th
|
|
|
1416
1336
|
store slot on every write by the entity's key value. The bucket is created on first
|
|
1417
1337
|
`holdSlotByKey` by walking the source store slot's slots once, and released on the last give-back.
|
|
1418
1338
|
|
|
1419
|
-
**`holdColumn(slot, columnName)`** is on the collection
|
|
1420
|
-
`service.unholdColumn(columnSlot)` gives that hold back. **`service.getColumn(slot, columnName)`**
|
|
1339
|
+
**`holdColumn(slot, columnName)`** is on the collection's `columnSlotService` and takes a hold on a column slot;
|
|
1340
|
+
`service.columnSlotService.unholdColumn(columnSlot)` gives that hold back. **`service.columnSlotService.getColumn(slot, columnName)`**
|
|
1421
1341
|
returns the same column slot without a hold: a column slot it mints is held by the
|
|
1422
1342
|
unused-slot collector until the end of the next flush, so `getColumn` is
|
|
1423
|
-
the door that does not hold but tracks. `
|
|
1424
|
-
itself
|
|
1425
|
-
and leaves no slot behind.
|
|
1343
|
+
the door that does not hold but tracks. `findSlotByKey(storeSlot, key)?.entity` reads the entity
|
|
1344
|
+
itself, so it mints nothing: a miss answers `undefined` and leaves no slot behind.
|
|
1426
1345
|
|
|
1427
1346
|
### The doors every service has
|
|
1428
1347
|
|
|
@@ -1443,8 +1362,15 @@ class OIMSlotCollectionService<TKey, TSlot, TStore, TSlotContentService, TColumn
|
|
|
1443
1362
|
getSlots(storeSlot): IterableIterator<TSlot>;
|
|
1444
1363
|
getSlotCount(storeSlot): number;
|
|
1445
1364
|
isSameKey(key, otherKey): boolean;
|
|
1446
|
-
|
|
1365
|
+
openBatch(storeSlot): void;
|
|
1366
|
+
closeBatch(storeSlot): void;
|
|
1367
|
+
writeInBatch<TResult>(storeSlot, write: () => TResult): TResult;
|
|
1368
|
+
readonly columnSlotService: OIMColumnSlotService; // getColumn / holdColumn / getAnyColumn / holdAnyColumn / getColumnGroup / holdColumnGroup / unholdColumn
|
|
1447
1369
|
}
|
|
1370
|
+
// createOIMSlotCollectionService returns OIMWritableSlotCollectionService, which adds:
|
|
1371
|
+
// writeSlotContentByKey(storeSlot, key, content, changedSlots?): TSlot
|
|
1372
|
+
// createOIMSingleSlotService returns OIMWritableSingleSlotService, which adds:
|
|
1373
|
+
// writeSingleSlotContent(storeSlot, content, changedSlots?): TSlot; clearSingleSlotContent(storeSlot): void
|
|
1448
1374
|
```
|
|
1449
1375
|
|
|
1450
1376
|
| Door | Of | Signature | Mints? |
|
|
@@ -1456,13 +1382,10 @@ class OIMSlotCollectionService<TKey, TSlot, TStore, TSlotContentService, TColumn
|
|
|
1456
1382
|
| `holdSlotByKey(storeSlot, key)` | collection | `TSlot` — minted if missing, `holdCount` up by one | **yes** |
|
|
1457
1383
|
| `hasSlotContentByKey(storeSlot, key)` | collection | `boolean` — **does this key have content right now**, not whether an identity is filed under it: a slot a read or a hold minted and nobody wrote answers `false`. It hands back no slot, which is why it can answer without minting, and it is not a read: the answer is about the past the moment it returns | no |
|
|
1458
1384
|
| `isSameKey(key, otherKey)` | collection | `boolean` — whether two keys name one slot here, answered by the store service (SameValueZero for a Map store, part by part for a tree store) | no |
|
|
1459
|
-
| `
|
|
1460
|
-
| `
|
|
1461
|
-
| `
|
|
1462
|
-
| `deleteEntity(slot)` / `deleteEntities(storeSlot, slots)` / `clearBucketMemberSlots(bucketSlot)` | content | `void` — it takes the value, not the identity | no |
|
|
1463
|
-
| `clearAllEntities(storeSlot)` | entity content | `void` — clears every slot filed in that store slot | no |
|
|
1385
|
+
| `writeSlotContentByKey(storeSlot, key, content, changed?)` | collection | `TSlot` — **total; always the identity it resolved or minted**. A hit writes the whole value through `slotContentService.writeSlotContent`, a miss mints and `insertSlotContent`s | **yes** |
|
|
1386
|
+
| `writeSlotContent(slot, content)` | content | `boolean` — on a slot you already hold; the boolean is about the CONTENT | no |
|
|
1387
|
+
| `clearSlotContent(slot)` | content | `void` — it takes the value, not the identity | no |
|
|
1464
1388
|
| `markContentChanged(bucketSlot)` | bucket content | `void` — re-settle emptiness and re-ask the guard after a write you made another way; the entity counterpart is `markEntityChanged(slot, changedColumns?)` | no |
|
|
1465
|
-
| `fillEntities(storeSlot, keys, entities)` / `insertEntities(storeSlot, entities)` | entity content | `void` — a bulk load of new keys; hands out no reference. On a key that is already filed or named twice it throws and rolls back only the entities this call filed; `fillEntities` also requires an empty store slot, and throws on lists of different lengths | yes |
|
|
1466
1389
|
| `slot.owner.holdSlot(slot)` / `slot.owner.unholdSlot(slot)` | `void` — the `IOIMSlotOwner` pair; `unholdSlot` on an unheld slot throws by name | no |
|
|
1467
1390
|
| `slot.owner.releaseSlotIfUnheld(slot)` | `void` — run the release guard; it releases nothing unless the slot is unheld, unreferenced, still owned here and out of grace | no |
|
|
1468
1391
|
|
|
@@ -1471,10 +1394,10 @@ class OIMSlotCollectionService<TKey, TSlot, TStore, TSlotContentService, TColumn
|
|
|
1471
1394
|
owned or in-grace slot it returns having done nothing, and on an
|
|
1472
1395
|
already-released one it returns silently rather than throwing.
|
|
1473
1396
|
|
|
1474
|
-
**`
|
|
1397
|
+
**`writeSlotContentByKey` does not file a key whose content is refused.** On a MISS it
|
|
1475
1398
|
mints, writes inside a `try`, and on a throw runs the release guard on what it
|
|
1476
1399
|
just minted before re-raising — so the caller's error is the only thing that
|
|
1477
|
-
leaves.
|
|
1400
|
+
leaves. The HIT path looks
|
|
1478
1401
|
the key up first and never mints, so a refused write on an existing key leaves
|
|
1479
1402
|
that key exactly as it was.
|
|
1480
1403
|
|
|
@@ -1482,21 +1405,18 @@ that key exactly as it was.
|
|
|
1482
1405
|
|
|
1483
1406
|
| | What happened | What the caller gets |
|
|
1484
1407
|
|---|---|---|
|
|
1485
|
-
| **Refused** | The write threw; **no content ever arrived** | The throw. A key minted for it is unwound — `
|
|
1408
|
+
| **Refused** | The write threw; **no content ever arrived** | The throw. A key minted for it is unwound — `writeSlotContentByKey` files nothing |
|
|
1486
1409
|
| **Unchanged** | The write **did** happen and the content was already there | The identity, like any other write. Nothing is unwound |
|
|
1487
1410
|
|
|
1488
|
-
`
|
|
1411
|
+
`writeSlotContentByKey` is **total**: whatever it decides about the content, it hands back
|
|
1489
1412
|
the identity it resolved or minted. A door that mints must leave a reference
|
|
1490
1413
|
behind, which is the one test that admits a door at all.
|
|
1491
1414
|
|
|
1492
|
-
`fillEntities` is the companion and does not carry the rule: it returns `void` and hands
|
|
1493
|
-
out no reference at all.
|
|
1494
|
-
|
|
1495
1415
|
**`changed?` — the verdict, into an array you own.**
|
|
1496
1416
|
|
|
1497
1417
|
```ts
|
|
1498
1418
|
const changed: TOIMEntitySlot<Card, TOIMStoreKey>[] = [];
|
|
1499
|
-
cardService.
|
|
1419
|
+
cardService.writeSlotContentByKey(cards, 'c1', { id: 'c1', title: 'Ace', rank: 1, deck: 'spades' }, changed); // pushed exactly when the content differed
|
|
1500
1420
|
```
|
|
1501
1421
|
|
|
1502
1422
|
- **Optional, yours, and appended to** — never read by the engine, never cleared.
|
|
@@ -1514,49 +1434,45 @@ cardService.slotContentService.insertEntity(cards, 'c1', { id: 'c1', title: 'Ace
|
|
|
1514
1434
|
|
|
1515
1435
|
## Writing
|
|
1516
1436
|
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1437
|
+
The keyed write is on the collection; every other write is on its content service, `service.slotContentService`,
|
|
1438
|
+
and takes the slot alone. There is no `keyOf`: the caller names the key. There are no bulk writes: a load is a
|
|
1439
|
+
loop of single writes inside `service.writeInBatch(storeSlot, () => { … })`.
|
|
1520
1440
|
|
|
1521
1441
|
| Call | Signature |
|
|
1522
1442
|
|---|---|
|
|
1523
|
-
| `
|
|
1524
|
-
| `
|
|
1525
|
-
| `insertEntity(storeSlot, key, entity, changedEntitySlots?)` | `(storeSlot, TKey, TEntity, TOIMEntitySlot<TEntity, TKey>[]?) => TOIMEntitySlot<TEntity, TKey>` — **total**, under a key you name |
|
|
1526
|
-
| `insertEntities(storeSlot, entities)` | `(storeSlot, readonly TEntity[]) => void` — a bulk load of NEW keys. A key already filed, or named twice in the list, throws and rolls back only the entities this call filed; what was in the store slot before stays. No `changed` — a bulk load changes every entity |
|
|
1527
|
-
| `fillEntities(storeSlot, keys, entities)` | `(storeSlot, readonly TKey[], readonly TEntity[]) => void` — the same under keys you name, with the same rollback; it also **throws unless the store slot is empty** |
|
|
1443
|
+
| `service.writeSlotContentByKey(storeSlot, key, entity, changedEntitySlots?)` | `(storeSlot, TKey, TEntity, TOIMEntitySlot<TEntity, TKey>[]?) => TOIMEntitySlot<TEntity, TKey>` — **total**: a miss mints and fills, a hit writes the whole value |
|
|
1444
|
+
| `writeSlotContent(slot, entity)` | `(slot, TEntity) => boolean` — the whole value onto a slot you hold; columns it had and `entity` does not, go |
|
|
1528
1445
|
| `updateEntity(slot, patch)` | `(slot, Partial<TEntity>) => slot` |
|
|
1529
1446
|
| `updateEntityColumn(slot, columnName, value)` | `<C extends keyof TEntity & string>(slot, C, TEntity[C]) => slot` — one column, no patch object and no walk over it |
|
|
1530
|
-
| `
|
|
1531
|
-
| `
|
|
1532
|
-
| `clearAllEntities(storeSlot)` | `(storeSlot) => void` — clears every filed slot inside one subframe, so the whole clear is one frame, not one per slot |
|
|
1533
|
-
| `markEntityChanged(slot, changedColumns?)` | `(TOIMEntitySlot<TEntity, TKey>, readonly (keyof TEntity & string)[]?) => void` |
|
|
1447
|
+
| `clearSlotContent(slot)` | `(slot) => void` — the entity goes; the identity stays while anything refers to it |
|
|
1448
|
+
| `markEntityChanged(slot, changedColumns?)` | `(slot, readonly (keyof TEntity & string)[]?) => void` |
|
|
1534
1449
|
| `deleteEntityColumns(slot, columnNames)` | `(slot, readonly TOIMEntityColumnName<TEntity>[]) => slot` — the named columns go |
|
|
1535
|
-
| `
|
|
1536
|
-
| `
|
|
1450
|
+
| `service.writeInBatch(storeSlot, write)` | `<TResult>(storeSlot, () => TResult) => TResult` — an index on the collection hears the whole batch in one call |
|
|
1451
|
+
| `service.findSlotByKey(storeSlot, key)?.entity` | the entity alone; mints nothing |
|
|
1537
1452
|
|
|
1538
1453
|
- **The store keeps your object by default.** Under the default `oimInsertEntityWithoutCopy` the
|
|
1539
1454
|
slot holds the object you hand in, so with the in-place writer a later update edits that
|
|
1540
|
-
same object; pass `
|
|
1455
|
+
same object; pass `entityInserter: oimInsertEntityWithCopy` to store `{ ...entity }`
|
|
1541
1456
|
and leave your object untouched. After an insert, change the object only through the
|
|
1542
1457
|
content service (`updateEntity`, or `markEntityChanged` after a hand edit): editing it and calling
|
|
1543
|
-
`
|
|
1458
|
+
`writeSlotContent` with the same object again wakes nobody, because no column reads as changed. `oimInsertEntityWithSanitizedCopy` also removes an own
|
|
1544
1459
|
`__proto__` key: pick it for untrusted JSON.
|
|
1545
1460
|
- `updateEntity` takes a **patch** — named columns move, unnamed ones stay.
|
|
1546
|
-
`
|
|
1461
|
+
`writeSlotContentByKey` and `writeSlotContent` take a **whole value**, and a column the new value does not name
|
|
1547
1462
|
is removed from the entity.
|
|
1548
1463
|
- A write that moves no column wakes nobody.
|
|
1549
|
-
- **`
|
|
1550
|
-
|
|
1551
|
-
- **`changedEntitySlots?` is the same array on both**: optional, yours, appended with the
|
|
1464
|
+
- **`writeSlotContentByKey` always hands back the slot**, whatever the write changed.
|
|
1465
|
+
- **`changedEntitySlots?`**: optional, yours, appended with the
|
|
1552
1466
|
entity slots whose content was different from what they already held. One array reused
|
|
1553
|
-
across a whole
|
|
1467
|
+
across a whole batch is the intended use, so a
|
|
1554
1468
|
pass over its slots costs the entities that changed rather than the entities that
|
|
1555
1469
|
arrived. It is never cleared — you empty it.
|
|
1556
1470
|
|
|
1557
1471
|
```ts
|
|
1558
1472
|
const changed: TOIMEntitySlot<Card, TOIMStoreKey>[] = [];
|
|
1559
|
-
cardService.
|
|
1473
|
+
cardService.writeInBatch(cards, () => {
|
|
1474
|
+
for (const card of payload) cardService.writeSlotContentByKey(cards, card.id, card, changed);
|
|
1475
|
+
});
|
|
1560
1476
|
for (const slot of changed) reindex(slot); // the re-sent entities are not in here
|
|
1561
1477
|
changed.length = 0;
|
|
1562
1478
|
```
|
|
@@ -1593,13 +1509,13 @@ cardService.slotContentService.markEntityChanged(slot, ['title']);
|
|
|
1593
1509
|
what the store holds. **Pass the list.** The no-argument form is the convenient
|
|
1594
1510
|
one and it gives back the per-column walk this door exists to skip.
|
|
1595
1511
|
- **An empty list wakes nothing at all** — not the columns, not the entity slot, not the
|
|
1596
|
-
store slot's listeners. `[]` is the caller saying nothing moved, so it returns before
|
|
1597
|
-
|
|
1512
|
+
store slot's listeners. `[]` is the caller saying nothing moved, so it returns before
|
|
1513
|
+
anything is marked: a write that changes nothing wakes nobody here too.
|
|
1598
1514
|
- **With either of the other two it wakes the entity slot and the store slot's content-change listeners**, so an
|
|
1599
1515
|
effect on the slot itself and an index over the store slot both see a hand mutation.
|
|
1600
1516
|
- **It re-stamps emptiness** whenever emptiness can depend on the mutation — with no column list,
|
|
1601
|
-
on a slot whose `entity` is `undefined`, and on a content service with a `
|
|
1602
|
-
`
|
|
1517
|
+
on a slot whose `entity` is `undefined`, and on a content service with a `slotEmptinessPolicy` other than
|
|
1518
|
+
`OIMSlotEntityPresenceEmptinessPolicy.INSTANCE`, a release policy that releases written slots, or a db with a
|
|
1603
1519
|
`slotStamp` — so a hand mutation that emptied the entity leaves `oimIsSlotEmpty(slot)`
|
|
1604
1520
|
true rather than lying, and the release guard can take the identity when it should.
|
|
1605
1521
|
- **It refuses inside a frame**, through the same `assertWritable` →
|
|
@@ -1619,19 +1535,19 @@ Both strategies ship as factories; the fork is chosen once, as the content servi
|
|
|
1619
1535
|
|
|
1620
1536
|
```ts signature
|
|
1621
1537
|
interface IOIMEntityWriter {
|
|
1622
|
-
readonly fillEntity: (slot:
|
|
1623
|
-
readonly putEntity: (slot:
|
|
1624
|
-
readonly patchEntity: (slot:
|
|
1538
|
+
readonly fillEntity: (slot: TOIMEntityContentSlot, entity: object) => void;
|
|
1539
|
+
readonly putEntity: (slot: TOIMEntityContentSlot, entity: object, changedColumnNames: string[] | undefined) => boolean;
|
|
1540
|
+
readonly patchEntity: (slot: TOIMEntityContentSlot, patch: object, changedColumnNames: string[] | undefined) => boolean;
|
|
1625
1541
|
readonly patchColumn: (
|
|
1626
|
-
slot:
|
|
1542
|
+
slot: TOIMEntityContentSlot, columnName: string, value: unknown, changedColumnNames: string[] | undefined,
|
|
1627
1543
|
) => boolean;
|
|
1628
|
-
readonly deleteColumns: (slot:
|
|
1629
|
-
readonly clearEntity: (slot:
|
|
1544
|
+
readonly deleteColumns: (slot: TOIMEntityContentSlot, names: readonly string[]) => readonly string[];
|
|
1545
|
+
readonly clearEntity: (slot: TOIMEntityContentSlot) => void;
|
|
1630
1546
|
}
|
|
1631
1547
|
|
|
1632
1548
|
type TOIMEntityWriterOptions = {
|
|
1633
1549
|
sameValueGuard?: TOIMSameValueGuard;
|
|
1634
|
-
|
|
1550
|
+
entityInserter?: TOIMEntityInserter;
|
|
1635
1551
|
putEntityColumns?: typeof oimPutEntityColumns; // oimPutEntityColumns | oimPutEntityColumnsGuarded
|
|
1636
1552
|
patchEntityColumns?: typeof oimPatchEntityColumns; // oimPatchEntityColumns | oimPatchEntityColumnsGuarded
|
|
1637
1553
|
patchEntityColumn?: typeof oimPatchEntityColumn; // oimPatchEntityColumn | oimPatchEntityColumnGuarded
|
|
@@ -1641,7 +1557,7 @@ createOIMEntityWriterInPlace(options?: TOIMEntityWriterOptions): IOIMEntityWrite
|
|
|
1641
1557
|
createOIMEntityWriterReplacing(options?: TOIMEntityWriterOptions): IOIMEntityWriter // a new object per write that changed something
|
|
1642
1558
|
```
|
|
1643
1559
|
|
|
1644
|
-
`
|
|
1560
|
+
`entityInserter` is the first-write strategy: `oimInsertEntityWithoutCopy` (the default) stores
|
|
1645
1561
|
your object itself, `oimInsertEntityWithCopy` stores `{ ...entity }`, `oimInsertEntityWithSanitizedCopy`
|
|
1646
1562
|
stores a copy with an own `__proto__` key removed (for untrusted JSON).
|
|
1647
1563
|
|
|
@@ -1661,8 +1577,8 @@ per-column comparison that decides "moved".
|
|
|
1661
1577
|
|
|
1662
1578
|
`putEntity` is PUT, `patchEntity` is PATCH (HTTP semantics). PUT makes the stored entity
|
|
1663
1579
|
the value handed in — changed columns written, columns the value lacks removed — in ONE
|
|
1664
|
-
call, returning both sets of names; PATCH writes only the columns named. `
|
|
1665
|
-
of a key that already has a value and `slotContentService.
|
|
1580
|
+
call, returning both sets of names; PATCH writes only the columns named. `writeSlotContentByKey`
|
|
1581
|
+
of a key that already has a value and `slotContentService.writeSlotContent(slot, entity)` are PUT: a whole-entity
|
|
1666
1582
|
write that drops a column is ONE channel write of the slot, and the replacing writer
|
|
1667
1583
|
builds ONE new object.
|
|
1668
1584
|
|
|
@@ -1680,9 +1596,9 @@ replacing — so the entity keeps its hidden class, and the key stays in
|
|
|
1680
1596
|
leaves it out does not report it, and taking the entity away does not wake its
|
|
1681
1597
|
readers.
|
|
1682
1598
|
|
|
1683
|
-
**Neither strategy reports anything.** Reporting is `OIMSlotContentEntityService`'s
|
|
1684
|
-
|
|
1685
|
-
|
|
1599
|
+
**Neither strategy reports anything.** Reporting is `OIMSlotContentEntityService`'s:
|
|
1600
|
+
after the writer returns, it marks the slot on the channel and tells the store slot's content-change listeners
|
|
1601
|
+
once for the whole write.
|
|
1686
1602
|
|
|
1687
1603
|
**A writer of your own** reuses the column walks both shipped writers run:
|
|
1688
1604
|
|
|
@@ -1722,9 +1638,9 @@ stores every value frozen:
|
|
|
1722
1638
|
```ts
|
|
1723
1639
|
const copyColumns = (entity: Record<string, unknown>): Record<string, unknown> => ({ ...entity });
|
|
1724
1640
|
|
|
1725
|
-
function storeFrozen(slot:
|
|
1641
|
+
function storeFrozen(slot: TOIMEntityContentSlot, next: Record<string, unknown> | undefined): boolean {
|
|
1726
1642
|
if (next === undefined) return false;
|
|
1727
|
-
(slot as TOIMSlotEditable<
|
|
1643
|
+
(slot as TOIMSlotEditable<TOIMEntityContentSlot>).entity = Object.freeze(next);
|
|
1728
1644
|
return true;
|
|
1729
1645
|
}
|
|
1730
1646
|
|
|
@@ -1752,30 +1668,25 @@ const freezingWriter: IOIMEntityWriter = {
|
|
|
1752
1668
|
## Single entities
|
|
1753
1669
|
|
|
1754
1670
|
A single entity — one value under no key, such as settings or a session — is a store slot of an
|
|
1755
|
-
`OIMSingleSlotService` over an entity content service
|
|
1756
|
-
|
|
1757
|
-
by-key doors: its read doors name the one slot.
|
|
1671
|
+
`OIMSingleSlotService` over an entity content service; its store service is `OIMSingleSlotStoreService.INSTANCE`,
|
|
1672
|
+
which files at most one slot per store slot. It has no key and no by-key doors: its doors name the one slot.
|
|
1758
1673
|
|
|
1759
1674
|
```ts signature
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
// the base layer it assembles
|
|
1765
|
-
createOIMSingleSlotService({
|
|
1766
|
-
slotContentService: createOIMSlotContentEntityService<TEntity>(db, {
|
|
1767
|
-
slotStoreService: OIMSlotStoreServiceSingleSlotDriven.INSTANCE, // no keyOf
|
|
1768
|
-
}),
|
|
1769
|
-
})
|
|
1675
|
+
createOIMSingleSlotService(db, {
|
|
1676
|
+
slotContentService: createOIMSlotContentEntityService<TEntity>(db),
|
|
1677
|
+
slotReleasePolicy?, slotSubscriptionListener?, columnSlotStoreService?, columnNames?,
|
|
1678
|
+
}): OIMWritableSingleSlotService<TOIMEntityContentSlot<TEntity>, TEntity, …>
|
|
1770
1679
|
|
|
1771
|
-
class
|
|
1680
|
+
class OIMWritableSingleSlotService<TSlot, TContent, TSlotContentService, …> {
|
|
1772
1681
|
readonly slotContentService: TSlotContentService;
|
|
1773
|
-
|
|
1682
|
+
readonly columnSlotService: OIMColumnSlotService;
|
|
1683
|
+
createStoreSlot(channelMap: IOIMChannelMap): TOIMStoreSlot<TOIMSingleSlotStore<TSlot>, TSlot, TPatch, this>;
|
|
1684
|
+
writeSingleSlotContent(storeSlot, content, changedSlots?): TSlot; // minted if missing
|
|
1685
|
+
clearSingleSlotContent(storeSlot): void;
|
|
1774
1686
|
findSingleSlot(storeSlot): TSlot | undefined; // mints nothing
|
|
1775
1687
|
hasSingleSlotContent(storeSlot): boolean; // mints nothing
|
|
1776
1688
|
getSingleSlot(storeSlot): TSlot; // minted if missing, tracked until the next flush
|
|
1777
1689
|
holdSingleSlot(storeSlot): TSlot; // minted if missing, holdCount up by one
|
|
1778
|
-
getColumn / holdColumn / getAnyColumn / holdAnyColumn / getColumnGroup / holdColumnGroup / unholdColumn;
|
|
1779
1690
|
}
|
|
1780
1691
|
```
|
|
1781
1692
|
|
|
@@ -1786,33 +1697,32 @@ with no value until something writes it. Its store slot is a `TOIMSingleSlotStor
|
|
|
1786
1697
|
```ts
|
|
1787
1698
|
type Settings = { theme: 'light' | 'dark'; zoom: number };
|
|
1788
1699
|
|
|
1789
|
-
const settingsService =
|
|
1700
|
+
const settingsService = createOIMSingleSlotService(db, { slotContentService: createOIMSlotContentEntityService<Settings>(db) });
|
|
1790
1701
|
const settings = settingsService.createStoreSlot(db);
|
|
1791
|
-
settingsService.
|
|
1702
|
+
settingsService.writeSingleSlotContent(settings, { theme: 'light', zoom: 1 });
|
|
1792
1703
|
const settingsSlot = settingsService.holdSingleSlot(settings);
|
|
1793
|
-
const themeColumn = settingsService.holdColumn(settingsSlot, 'theme');
|
|
1704
|
+
const themeColumn = settingsService.columnSlotService.holdColumn(settingsSlot, 'theme');
|
|
1794
1705
|
const themeEffect = effectService.createEffect(db, [themeColumn], [], () => { console.log(settingsSlot.entity?.theme); });
|
|
1795
1706
|
settingsService.slotContentService.updateEntity(settingsSlot, { theme: 'dark' });
|
|
1796
1707
|
db.flush();
|
|
1797
1708
|
effectService.disposeEffect(themeEffect);
|
|
1798
|
-
settingsService.unholdColumn(themeColumn);
|
|
1709
|
+
settingsService.columnSlotService.unholdColumn(themeColumn);
|
|
1799
1710
|
settingsSlot.owner.unholdSlot(settingsSlot);
|
|
1800
1711
|
```
|
|
1801
1712
|
|
|
1802
1713
|
**The slot is reached only through the service.** `getSingleSlot(storeSlot)` hands back the live slot, and
|
|
1803
1714
|
mints a fresh one — tracked by the unused-slot collector until the next flush — when there is none;
|
|
1804
|
-
`holdSingleSlot(storeSlot)` does the same and takes a hold.
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
`deleteEntity`) takes that slot.
|
|
1715
|
+
`holdSingleSlot(storeSlot)` does the same and takes a hold. `writeSingleSlotContent` and `clearSingleSlotContent`
|
|
1716
|
+
are the store doors, and every slot door of the content service (`updateEntity`, `updateEntityColumn`,
|
|
1717
|
+
`deleteEntityColumns`, `writeSlotContent`, `markEntityChanged`, `clearSlotContent`) takes that slot.
|
|
1808
1718
|
|
|
1809
|
-
The slot is of the keyed entity slot's literal shape
|
|
1810
|
-
`
|
|
1719
|
+
The slot is of the keyed entity slot's literal shape (with `key: undefined` and `indexKeys: undefined`), and its
|
|
1720
|
+
`storeSlot` is `settings` — so
|
|
1811
1721
|
`effectService.createEffect(db, [settingsSlot], [], …)` works and a column of it is a root like any other.
|
|
1812
1722
|
Its key is `undefined`, and its store is `{ slot }` (`TOIMSingleSlotStore`). Its lifetime is the
|
|
1813
|
-
`slotReleasePolicy` (the db's, then `
|
|
1723
|
+
`slotReleasePolicy` (the db's, then `OIMSlotAtEmptyReleasePolicy`), so a single entity that holds a value
|
|
1814
1724
|
stays; one emptied and unheld is released, and the slot `getSingleSlot` mints next holds no entity. The value
|
|
1815
|
-
is stored by the writer's `
|
|
1725
|
+
is stored by the writer's `entityInserter`, which by default keeps the object handed in rather than a copy.
|
|
1816
1726
|
|
|
1817
1727
|
---
|
|
1818
1728
|
|
|
@@ -1822,18 +1732,17 @@ A bucket collection is, like an entity collection, a content service and the col
|
|
|
1822
1732
|
The content service is the strategy — how a bucket keeps its member slots — and it is chosen at the factory:
|
|
1823
1733
|
|
|
1824
1734
|
```ts signature
|
|
1825
|
-
|
|
1826
|
-
slotContentService
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
columnSlotStoreService?: IOIMSlotStoreService<string, TOIMColumnSlot>;
|
|
1831
|
-
columnNames?: readonly string[];
|
|
1832
|
-
}?): OIMSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore, TSlotContentService, …>
|
|
1735
|
+
createOIMSlotCollectionService(db, {
|
|
1736
|
+
slotContentService: new OIMSlotContentPositionalArrayBucketService<TBucketMemberSlot>(), // or one of the others below
|
|
1737
|
+
slotStoreService?: IOIMSlotStoreService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore>; // Map; REQUIRED for an array key
|
|
1738
|
+
slotReleasePolicy?, slotSubscriptionListener?, columnSlotStoreService?, columnNames?,
|
|
1739
|
+
}): OIMWritableSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TStore, readonly TBucketMemberSlot[], …>
|
|
1833
1740
|
|
|
1834
|
-
new
|
|
1835
|
-
new
|
|
1836
|
-
new
|
|
1741
|
+
new OIMSlotContentSetBucketService<TBucketMemberSlot>({ bucketCommands? })
|
|
1742
|
+
new OIMSlotContentPositionalArrayBucketService<TBucketMemberSlot>({ bucketCommands?, bucketMemberSlotsArrayService? })
|
|
1743
|
+
new OIMSlotContentSortedArrayBucketService<TBucketMemberSlot>({ compareBucketMemberSlots, bucketCommands?, bucketMemberSlotsArrayService? })
|
|
1744
|
+
// bucketMemberSlotsArrayService: OIMBucketMemberSlotsArrayService (every mention, the default)
|
|
1745
|
+
// or new OIMBucketUniqueMemberSlotsArrayService<TBucketMemberSlot>() (each slot once)
|
|
1837
1746
|
```
|
|
1838
1747
|
|
|
1839
1748
|
A bucket holds bucket member slots of any slot type — entity slots, bucket slots, computeds — and its
|
|
@@ -1843,16 +1752,13 @@ of the collection service take that store slot first, and the bucket doors of th
|
|
|
1843
1752
|
bucket slot.
|
|
1844
1753
|
|
|
1845
1754
|
```ts
|
|
1846
|
-
const colourService =
|
|
1847
|
-
OIMSlotContentBucketServiceSetDriven<TOIMEntitySlot<Card>>>(db, {
|
|
1848
|
-
slotContentService: new OIMSlotContentBucketServiceSetDriven<TOIMEntitySlot<Card>>(),
|
|
1849
|
-
});
|
|
1755
|
+
const colourService = createOIMSlotCollectionService(db, { slotContentService: new OIMSlotContentSetBucketService<TOIMEntitySlot<Card>>() });
|
|
1850
1756
|
const colours = colourService.createStoreSlot(db);
|
|
1851
1757
|
const red = colourService.holdSlotByKey(colours, 'red');
|
|
1852
|
-
colourService.slotContentService.
|
|
1758
|
+
colourService.slotContentService.writeSlotContent(red, [slot, cardService.getSlotByKey(cards, 'c2')]);
|
|
1853
1759
|
db.flush();
|
|
1854
1760
|
for (const deckSlot of colourService.slotContentService.getBucketMemberSlots(red)) { paint(deckSlot.entity); }
|
|
1855
|
-
colourService.slotContentService.
|
|
1761
|
+
colourService.slotContentService.clearSlotContent(red);
|
|
1856
1762
|
red.owner.unholdSlot(red);
|
|
1857
1763
|
```
|
|
1858
1764
|
|
|
@@ -1860,23 +1766,24 @@ Every door below is the bucket content service's and takes the bucket slot:
|
|
|
1860
1766
|
|
|
1861
1767
|
| Door | Signature |
|
|
1862
1768
|
|---|---|
|
|
1863
|
-
| `
|
|
1769
|
+
| `writeSlotContent(bucketSlot, bucketMemberSlots)` | `boolean` — states the whole bucket; idempotent; true when anything arrived or departed |
|
|
1770
|
+
| `getBucketMemberSlotsMissingFrom(bucketSlot, bucketMemberSlots)` | `TBucketMemberSlot[]` — the members the given list leaves out, so a sync can write into them (clear a group key, set a deleted flag) instead of dropping them |
|
|
1864
1771
|
| `addBucketMemberSlot(bucketSlot, bucketMemberSlot)` / `addBucketMemberSlots(bucketSlot, bucketMemberSlots)` | joins the named bucket member slots and touches nothing else. REMOVES NOTHING |
|
|
1865
1772
|
| `removeBucketMemberSlot(bucketSlot, bucketMemberSlot)` / `removeBucketMemberSlots(bucketSlot, bucketMemberSlots)` | takes the named bucket member slots out and touches nothing else |
|
|
1866
|
-
| `
|
|
1773
|
+
| `clearSlotContent(bucketSlot)` | empties it |
|
|
1867
1774
|
| `getBucketMemberSlots(bucketSlot)` | `Iterable<TBucketMemberSlot>` |
|
|
1868
1775
|
| `getBucketMemberSlotCount(bucketSlot)` | `number` |
|
|
1869
|
-
| `hasBucketMemberSlot(bucketSlot, bucketMemberSlot)` | `boolean` — the content service's own membership test: one `Set.has` on a set
|
|
1776
|
+
| `hasBucketMemberSlot(bucketSlot, bucketMemberSlot)` | `boolean` — the content service's own membership test: one `Set.has` on a set bucket; on an array bucket its `bucketMemberSlotsArrayService.hasBucketMemberSlot` (a `Set.has` when unique, `indexOf` otherwise) |
|
|
1870
1777
|
| `markBucketColumnsChanged(bucketSlot, patch, changedColumns)` | `void` — tell the bucket's column slots which member columns moved |
|
|
1871
1778
|
| `markContentChanged(bucketSlot)` | `void` — re-settle emptiness and re-ask the release guard after a write made another way |
|
|
1872
|
-
| `fillBucketMemberSlots(bucketSlot, bucketMemberSlots)` | `void` — fills a bucket slot nobody was told about yet; it throws on one that was already announced, which `addBucketMemberSlots` / `
|
|
1779
|
+
| `fillBucketMemberSlots(bucketSlot, bucketMemberSlots)` | `void` — fills a bucket slot nobody was told about yet; it throws on one that was already announced, which `addBucketMemberSlots` / `writeSlotContent` are for |
|
|
1873
1780
|
|
|
1874
1781
|
The entities of a bucket by key are the index's door, `indexService.getEntitiesByKey(indexStoreSlot, key)`
|
|
1875
1782
|
([The index that fills itself](#the-index-that-fills-itself--oimindexservice)).
|
|
1876
1783
|
|
|
1877
1784
|
### Which door: you hold the answer, or you hold the delta
|
|
1878
1785
|
|
|
1879
|
-
`
|
|
1786
|
+
`writeSlotContent` is for a caller who has THE LIST THAT SHOULD BE THERE and does not
|
|
1880
1787
|
know what changed — a search result, a page from a server, a filter re-run. One
|
|
1881
1788
|
call, and the engine works out the arrivals and the departures. Its cost is
|
|
1882
1789
|
proportional to WHAT THE BUCKET HOLDS, not to the change: the difference builds a
|
|
@@ -1895,31 +1802,31 @@ the order you name them.
|
|
|
1895
1802
|
|
|
1896
1803
|
**`addBucketMemberSlots` removes nothing.** If the authoritative list SHRANK and you call
|
|
1897
1804
|
`addBucketMemberSlots`, the entity slots that left stay in the bucket, held. Not knowing what left is
|
|
1898
|
-
exactly when `
|
|
1805
|
+
exactly when `writeSlotContent` is the right door, and its cost is the price of not
|
|
1899
1806
|
knowing.
|
|
1900
1807
|
|
|
1901
1808
|
The keyed doors are the collection service's and take the store slot first —
|
|
1902
1809
|
`decksService.getSlotByKey(decks, key)`, `decksService.holdSlotByKey(decks, key)` — and a hold is given back
|
|
1903
|
-
with `bucketSlot.owner.unholdSlot(bucketSlot)`.
|
|
1904
|
-
`decksService.slotContentService.
|
|
1810
|
+
with `bucketSlot.owner.unholdSlot(bucketSlot)`. The by-key write is `decksService.writeSlotContentByKey(decks, key, members)`; on a bucket slot you hold it is
|
|
1811
|
+
`decksService.slotContentService.writeSlotContent(bucketSlot, members)`.
|
|
1905
1812
|
|
|
1906
1813
|
A bucket's emptiness is the content service's `isSlotEmpty(bucketSlot)`, a member count of zero, so
|
|
1907
1814
|
an emptied bucket that nothing holds and nothing watches is released by the
|
|
1908
1815
|
guard on the same call that emptied it.
|
|
1909
1816
|
|
|
1910
1817
|
**A bucket never sorts.** Its order is what the caller put in — `addBucketMemberSlots`
|
|
1911
|
-
appends, `insertBucketMemberSlotAt` inserts, a move moves, `
|
|
1818
|
+
appends, `insertBucketMemberSlotAt` inserts, a move moves, `writeSlotContent` takes the
|
|
1912
1819
|
sequence given. A sorted list is a computed over an index:
|
|
1913
|
-
[Sorted lists](#sorted-lists); or the bucket of a `
|
|
1820
|
+
[Sorted lists](#sorted-lists); or the bucket of a `createOIMSlotCollectionSortedArrayIndexService` index, which
|
|
1914
1821
|
orders itself: [Sorted at write](#sorted-at-write).
|
|
1915
1822
|
|
|
1916
|
-
`
|
|
1823
|
+
`writeSlotContent(bucketSlot, members)` runs `assertWritable` — the frame guard
|
|
1917
1824
|
(`assertNotFlushing`) and the released-identity check — then the reconcile (an empty `arrived` and
|
|
1918
1825
|
`departed` is an unchanged write, which wakes nobody), the holds taken on arrivals, the holds given back by
|
|
1919
1826
|
departures and the single channel write of the bucket slot. It is handed a slot, so it hands back a
|
|
1920
1827
|
`boolean`: true when anything arrived or departed.
|
|
1921
1828
|
|
|
1922
|
-
`
|
|
1829
|
+
`writeSlotContent` **joins before it evicts**, so a slot named by both the old and the
|
|
1923
1830
|
new list never reaches zero references. It empties with one `drainSlots` rather
|
|
1924
1831
|
than one removal at a time — per-slot eviction on an array-driven bucket is
|
|
1925
1832
|
n(n-1)/2 element moves.
|
|
@@ -1940,7 +1847,7 @@ empty means nothing changed. Each content service reconciles its own way:
|
|
|
1940
1847
|
`OIMBucketCommands` records onto the bucket slot (`bucket.commands`) as the writes land and
|
|
1941
1848
|
empties it once the flush has fully ended, so a consumer reads it INSIDE the
|
|
1942
1849
|
frame and what it reads can only describe the writes it was woken for.
|
|
1943
|
-
`
|
|
1850
|
+
`clearSlotContent` asks whether the bucket is empty **before** it
|
|
1944
1851
|
touches the store, so an already-empty bucket records nothing for a call that
|
|
1945
1852
|
reports nothing.
|
|
1946
1853
|
|
|
@@ -1948,33 +1855,20 @@ reports nothing.
|
|
|
1948
1855
|
|
|
1949
1856
|
| Class | Storage type | One add records |
|
|
1950
1857
|
|---|---|---|
|
|
1951
|
-
| `
|
|
1952
|
-
| `
|
|
1953
|
-
| `
|
|
1858
|
+
| `OIMSlotContentSetBucketService<TBucketMemberSlot>({ bucketCommands? })` | `TOIMBucketSlotsSetStore<TBucketMemberSlot>` = `Set<TBucketMemberSlot>` | one per slot |
|
|
1859
|
+
| `OIMSlotContentPositionalArrayBucketService<TBucketMemberSlot>({ bucketCommands?, bucketMemberSlotsArrayService? })` | `TOIMBucketSlotsArrayStore<TBucketMemberSlot>` = `{ bucketMemberSlots, uniqueBucketMemberSlots, sortedCount }` | one per **mention**; one per slot, order kept, with `new OIMBucketUniqueMemberSlotsArrayService()` |
|
|
1860
|
+
| `OIMSlotContentSortedArrayBucketService<TBucketMemberSlot>({ compareBucketMemberSlots, bucketMemberSlotsArrayService? })` | `TOIMBucketSlotsArrayStore<TBucketMemberSlot>` | one per mention or per slot, at its sorted place |
|
|
1954
1861
|
|
|
1955
|
-
The first two are the ones a caller picks between, and neither sorts: the array-driven
|
|
1956
|
-
caller's order. The
|
|
1862
|
+
The first two are the ones a caller picks between, and neither sorts: the array-driven services keep the
|
|
1863
|
+
caller's order. The last is the one the sorted-at-write index builds for itself
|
|
1957
1864
|
([Sorted at write](#sorted-at-write)); its `repositionBucketMemberSlot(bucketSlot, bucketMemberSlot)` moves one
|
|
1958
1865
|
member to its place after its sort columns changed.
|
|
1959
1866
|
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
>({
|
|
1966
|
-
bucketArrayMembership: new OIMBucketArrayMembershipUnique<TOIMEntitySlot<Card>>(),
|
|
1967
|
-
})
|
|
1968
|
-
|
|
1969
|
-
| Membership | Storage it builds | One add records |
|
|
1970
|
-
|---|---|---|
|
|
1971
|
-
| `OIMBucketArrayMembershipNonUnique.INSTANCE` (default) | `TOIMBucketSlotsArrayStore<TBucketMemberSlot>` | one per **mention** |
|
|
1972
|
-
| `new OIMBucketArrayMembershipUnique<TBucketMemberSlot>()` | `TOIMBucketSlotsArrayUniqueStore<TBucketMemberSlot>` | one per slot |
|
|
1973
|
-
|
|
1974
|
-
`IOIMBucketArrayMembership<TBucketMemberSlot, TSlots>`: `createStore`, `addSlot`, `removeSlot`,
|
|
1975
|
-
`hasSlot`, `clearSlots`, `containsTheSameSequence`. `hasBucketMemberSlot` asks the membership's `hasSlot`: the
|
|
1976
|
-
unique membership answers from its `Set` (no array walk), the non-unique one walks the
|
|
1977
|
-
array. Only the array-driven service takes one — a set-driven service keeps its slots IN a `Set`.
|
|
1867
|
+
Which slots an array bucket keeps is its `bucketMemberSlotsArrayService`, the only writer of the list and the
|
|
1868
|
+
`Set` beside it: `OIMBucketMemberSlotsArrayService` keeps every mention and no `Set`;
|
|
1869
|
+
`OIMBucketUniqueMemberSlotsArrayService` keeps each slot once and the list and its `Set` together, so the two never
|
|
1870
|
+
disagree. With the unique one `hasBucketMemberSlot` answers from the `Set` (no array walk); with the default it
|
|
1871
|
+
walks the array.
|
|
1978
1872
|
|
|
1979
1873
|
Nothing positional is on the abstract `OIMSlotContentBucketService`: the reads `getBucketMemberSlotAt` and
|
|
1980
1874
|
`getBucketMemberSlotPosition` are on the array-based services (array-driven and sorted), and the five
|
|
@@ -1994,8 +1888,8 @@ named constants:
|
|
|
1994
1888
|
A removal answering the third is recorded as `recordWholeList(bucketSlot)`: a set has no index to patch,
|
|
1995
1889
|
so the consumer is told to re-read the bucket rather than handed a fabricated one.
|
|
1996
1890
|
|
|
1997
|
-
`OIM_NOTHING_WAS_INSERTED` (`-1`) is the insert's answer when nothing was inserted, which is a repeat on an
|
|
1998
|
-
`
|
|
1891
|
+
`OIM_NOTHING_WAS_INSERTED` (`-1`) is the insert's answer when nothing was inserted, which is a repeat on an array bucket
|
|
1892
|
+
with `OIMBucketUniqueMemberSlotsArrayService`. The recorded insert names the index the slot LANDED on — `at` clamped to the
|
|
1999
1893
|
ends of the list — and not `getBucketMemberSlotPosition`, because the default ordered list keeps one place per
|
|
2000
1894
|
**mention**: inserting a slot the bucket already holds gives it a second position, and the position read
|
|
2001
1895
|
names the FIRST. A command script built from it would tell the consumer to patch at an index the slot is not
|
|
@@ -2007,9 +1901,8 @@ error. **One content service instance may serve two bucket collections** — it
|
|
|
2007
1901
|
|
|
2008
1902
|
### Positions the caller decides
|
|
2009
1903
|
|
|
2010
|
-
A bucket whose positions are the caller's is one over `
|
|
2011
|
-
|
|
2012
|
-
block. The two position reads and the five writes are that content service's, they take the bucket
|
|
1904
|
+
A bucket whose positions are the caller's is one over `OIMSlotContentPositionalArrayBucketService`, which is
|
|
1905
|
+
the `pageService` of the setup block. The two position reads and the five writes are that content service's, they take the bucket
|
|
2013
1906
|
slot and no store slot, and an index is valid only until the next write:
|
|
2014
1907
|
|
|
2015
1908
|
| Door | What it does |
|
|
@@ -2030,7 +1923,7 @@ like any other out-of-range position.
|
|
|
2030
1923
|
Each wraps a store change in the frame guard, the holds, the report and the
|
|
2031
1924
|
release question. The default ordered list records one place per MENTION, so
|
|
2032
1925
|
`insertBucketMemberSlotAt` of a slot the bucket already holds gives it a second position —
|
|
2033
|
-
|
|
1926
|
+
take `bucketMemberSlotsArrayService: new OIMBucketUniqueMemberSlotsArrayService()` when a position must name
|
|
2034
1927
|
exactly one entity slot.
|
|
2035
1928
|
|
|
2036
1929
|
Per strategy, generating code:
|
|
@@ -2053,7 +1946,7 @@ slotContentBucketService.moveBucketMemberSlotToPosition(
|
|
|
2053
1946
|
);
|
|
2054
1947
|
|
|
2055
1948
|
// a whole list at once, in the order the server sent
|
|
2056
|
-
slotContentBucketService.
|
|
1949
|
+
slotContentBucketService.writeSlotContent(todo, cardService.writeInBatch(cards, () => (payload).map(entity => cardService.writeSlotContentByKey(cards, entity.id, entity))));
|
|
2057
1950
|
```
|
|
2058
1951
|
|
|
2059
1952
|
### The render script: `OIMBucketCommands`
|
|
@@ -2062,14 +1955,13 @@ slotContentBucketService.writeBucketMemberSlots(todo, cardService.slotContentSer
|
|
|
2062
1955
|
new OIMBucketCommands(options: { maxCommandsPerSlot?: number }) // default OIM_MAX_COMMANDS_PER_SLOT
|
|
2063
1956
|
|
|
2064
1957
|
// a bucket content service takes it at construction, once:
|
|
2065
|
-
new
|
|
2066
|
-
// createOIMBucketService(db, { maxCommandsPerSlot }) builds the default content service with one
|
|
1958
|
+
new OIMSlotContentPositionalArrayBucketService({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: Infinity }) });
|
|
2067
1959
|
```
|
|
2068
1960
|
|
|
2069
1961
|
**Recording is a strategy chosen when the bucket content service is built.** `bucketCommands` is read once
|
|
2070
|
-
into a readonly field; left out of a content service built with `new`, it is `
|
|
1962
|
+
into a readonly field; left out of a content service built with `new`, it is `OIMNoBucketCommands`, whose
|
|
2071
1963
|
every method is empty, so a bucket nobody renders positionally pays one empty call per write and allocates no
|
|
2072
|
-
command.
|
|
1964
|
+
command. There is no setter: a content
|
|
2073
1965
|
service records into the one recorder it was built with. One recorder serves every bucket of every store slot
|
|
2074
1966
|
and of every db — it is stateless.
|
|
2075
1967
|
|
|
@@ -2104,8 +1996,8 @@ that lands after a flush but before that reset starts a new script instead of ex
|
|
|
2104
1996
|
read. The reset is subscribed with `subscribeAfterEachFlush` on the first script a channel slot ever sees, and
|
|
2105
1997
|
walks only the buckets that recorded.
|
|
2106
1998
|
|
|
2107
|
-
A positional write is always recorded as a position. `isWholeListRecorded` is set by a write of the whole bucket — `
|
|
2108
|
-
`
|
|
1999
|
+
A positional write is always recorded as a position. `isWholeListRecorded` is set by a write of the whole bucket — `writeSlotContent`,
|
|
2000
|
+
`clearSlotContent`, `moveBucketMemberSlotRangeToPosition` — by a removal from a bucket whose
|
|
2109
2001
|
content service keeps no positions, which has no index to patch, and by the script
|
|
2110
2002
|
outgrowing the list
|
|
2111
2003
|
it describes. `maxCommandsPerSlot` is that ratio; it defaults to
|
|
@@ -2124,19 +2016,20 @@ content service's own write doors do.
|
|
|
2124
2016
|
### A single bucket
|
|
2125
2017
|
|
|
2126
2018
|
One bucket under no key is a store slot of an `OIMSingleSlotService` over a bucket content service, with
|
|
2127
|
-
`
|
|
2019
|
+
`OIMSingleSlotStoreService.INSTANCE` as the store service:
|
|
2128
2020
|
|
|
2129
2021
|
```ts signature
|
|
2130
|
-
|
|
2131
|
-
slotContentService
|
|
2132
|
-
|
|
2022
|
+
createOIMSingleSlotService(db, {
|
|
2023
|
+
slotContentService: new OIMSlotContentPositionalArrayBucketService<TBucketMemberSlot>(), // or the set one
|
|
2024
|
+
slotReleasePolicy?, slotSubscriptionListener?, columnSlotStoreService?, columnNames?,
|
|
2025
|
+
}): OIMWritableSingleSlotService<TOIMBucketContentSlot<TSlots>, readonly TBucketMemberSlot[], …>
|
|
2133
2026
|
```
|
|
2134
2027
|
|
|
2135
2028
|
```ts
|
|
2136
|
-
const handService =
|
|
2029
|
+
const handService = createOIMSingleSlotService(db, { slotContentService: new OIMSlotContentPositionalArrayBucketService<TOIMEntitySlot<Card>>({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: undefined }) }) });
|
|
2137
2030
|
const hand = handService.createStoreSlot(db);
|
|
2138
2031
|
const handSlot = handService.holdSingleSlot(hand);
|
|
2139
|
-
handService.slotContentService.
|
|
2032
|
+
handService.slotContentService.writeSlotContent(handSlot, [slot]);
|
|
2140
2033
|
handService.slotContentService.insertBucketMemberSlotAt(handSlot, 0, cardService.getSlotByKey(cards, 'c2'));
|
|
2141
2034
|
effectService.disposeEffect(effectService.createEffect(db, [handSlot], [], () => {
|
|
2142
2035
|
render(Array.from(handService.slotContentService.getBucketMemberSlots(handSlot)));
|
|
@@ -2144,23 +2037,22 @@ effectService.disposeEffect(effectService.createEffect(db, [handSlot], [], () =>
|
|
|
2144
2037
|
handSlot.owner.unholdSlot(handSlot);
|
|
2145
2038
|
```
|
|
2146
2039
|
|
|
2147
|
-
One bucket, no key: the single-slot store files its one bucket slot
|
|
2148
|
-
|
|
2040
|
+
One bucket, no key: the single-slot store files its one bucket slot as the store's `slot`. The bucket slot is a
|
|
2041
|
+
`TOIMBucketContentSlot<TSlots>` of the keyed bucket slot's shape (`key: undefined`), what an effect subscribes to and what a reader is handed,
|
|
2149
2042
|
so the channel's write door still sees three slot shapes. Every door of the bucket content service takes it as
|
|
2150
2043
|
it takes a keyed bucket slot, and `markBucketColumnsChanged(bucketSlot, patch, changedColumns)` is how the
|
|
2151
2044
|
caller that changed members says which of their columns moved, as the index does for a keyed bucket. Each
|
|
2152
|
-
door
|
|
2153
|
-
subframe.
|
|
2045
|
+
door writes the bucket slot to the channel once.
|
|
2154
2046
|
|
|
2155
2047
|
**Its lifetime is the `slotReleasePolicy`.** With none named (here or on the db) it is
|
|
2156
|
-
`
|
|
2048
|
+
`OIMSlotAtEmptyReleasePolicy.INSTANCE`, so an emptied single bucket that nothing holds or watches is
|
|
2157
2049
|
released, and `getSingleSlot(storeSlot)` mints a fresh, empty one on the next read. Hold the
|
|
2158
|
-
slot (`holdSingleSlot(storeSlot)`) for as long as you write into it, or name `
|
|
2050
|
+
slot (`holdSingleSlot(storeSlot)`) for as long as you write into it, or name `OIMSlotNeverReleasePolicy.INSTANCE`.
|
|
2159
2051
|
|
|
2160
|
-
### The index that fills itself — `
|
|
2052
|
+
### The index that fills itself — `OIMSlotCollectionIndexService`
|
|
2161
2053
|
|
|
2162
2054
|
```ts signature
|
|
2163
|
-
|
|
2055
|
+
createOIMSlotCollectionIndexService<TEntity, TSourceKey, TColumns?, TKey?, TSourceStore?, TSlots?, TSlotContentService?>(db, {
|
|
2164
2056
|
entityService: Pick<OIMSlotCollectionService<TSourceKey, TOIMEntitySlot<TEntity, TSourceKey>, TSourceStore, unknown>, 'getSlots'>;
|
|
2165
2057
|
...TOIMIndexKeyOptions<TKey, TEntity, TColumns>; // { columns } | { keyOf } | { keyOf, columns }
|
|
2166
2058
|
slotContentService?: OIMSlotContentBucketService<TOIMEntitySlot<TEntity>, TSlots>; // default: array-driven, no commands
|
|
@@ -2168,9 +2060,9 @@ createOIMIndexService<TEntity, TSourceKey, TColumns?, TKey?, TSourceStore?, TSlo
|
|
|
2168
2060
|
slotReleasePolicy?: IOIMSlotReleasePolicy;
|
|
2169
2061
|
columnSlotStoreService?: IOIMSlotStoreService<string, TOIMColumnSlot>;
|
|
2170
2062
|
columnNames?: readonly string[];
|
|
2171
|
-
}):
|
|
2063
|
+
}): OIMSlotCollectionIndexService<TKey, TEntity, TSlots, TSourceKey, TSourceStore, TSlotContentService, …>
|
|
2172
2064
|
|
|
2173
|
-
class
|
|
2065
|
+
class OIMSlotCollectionIndexService<…> extends OIMSlotCollectionService<…> {
|
|
2174
2066
|
createIndexStoreSlot(sourceStoreSlot: TOIMStoreSlot<TSourceStore, TOIMEntitySlot<TEntity, TSourceKey>, Partial<TEntity>>): TOIMIndexStoreSlot<…>;
|
|
2175
2067
|
disposeIndexStoreSlot(indexStoreSlot: TOIMIndexStoreSlot<…>): void;
|
|
2176
2068
|
getEntitiesByKey(indexStoreSlot, key): (TEntity | undefined)[];
|
|
@@ -2181,12 +2073,12 @@ class OIMIndexService<…> extends OIMSlotCollectionService<…> {
|
|
|
2181
2073
|
}
|
|
2182
2074
|
```
|
|
2183
2075
|
|
|
2184
|
-
`
|
|
2076
|
+
`OIMSlotCollectionIndexService` is a collection service of buckets, so it has every read door of one, and its
|
|
2185
2077
|
`slotContentService` is the bucket content service narrowed by type to its reads (`getBucketMemberSlots`,
|
|
2186
2078
|
`getBucketMemberSlotCount`, `hasBucketMemberSlot`, and the positional reads where the strategy has them) — the
|
|
2187
2079
|
index is the only writer of its buckets. The strategy is chosen at the factory:
|
|
2188
|
-
`
|
|
2189
|
-
`slotContentService`, and the sorted one built by `
|
|
2080
|
+
`OIMSlotContentPositionalArrayBucketService` by default, `OIMSlotContentSetBucketService` passed as
|
|
2081
|
+
`slotContentService`, and the sorted one built by `createOIMSlotCollectionSortedArrayIndexService`. Only the array-based
|
|
2190
2082
|
content services answer by position: `getBucketMemberSlotAt(bucketSlot, index)` (O(1), `undefined` past the
|
|
2191
2083
|
end) and `getBucketMemberSlotPosition(bucketSlot, entitySlot)` (walks the array, O(n), `-1` for a non-member).
|
|
2192
2084
|
The index's default content service records no commands; pass one built with `bucketCommands` for a render
|
|
@@ -2202,11 +2094,11 @@ read through the index service, passing that store slot; the index is what write
|
|
|
2202
2094
|
written before it, without a flush, so minting inside an effect body does not throw.
|
|
2203
2095
|
`getSlotsByKeys` / `holdSlotsByKeys` fill every new bucket in ONE pass over the source. How long it lives after that is **the
|
|
2204
2096
|
`slotReleasePolicy`'s ordinary business**, exactly as for a hand-held bucket; the index injects no lifetime of its
|
|
2205
|
-
own. With none named it is `
|
|
2097
|
+
own. With none named it is `OIMSlotAtEmptyReleasePolicy.INSTANCE`: the bucket stands while it has members and is
|
|
2206
2098
|
maintained on every write.
|
|
2207
2099
|
|
|
2208
2100
|
```ts
|
|
2209
|
-
const byDeckService =
|
|
2101
|
+
const byDeckService = createOIMSlotCollectionIndexService(db, {
|
|
2210
2102
|
entityService: cardService,
|
|
2211
2103
|
keyOf: (card: Card) => card.deck,
|
|
2212
2104
|
});
|
|
@@ -2216,14 +2108,14 @@ const spades = byDeckService.holdSlotByKey(byDeck, 'spades');
|
|
|
2216
2108
|
effectService.createEffect(db, [spades], [], () => render(Array.from(byDeckService.slotContentService.getBucketMemberSlots(spades))));
|
|
2217
2109
|
```
|
|
2218
2110
|
|
|
2219
|
-
A set-driven index names its content service
|
|
2220
|
-
`new
|
|
2111
|
+
A set-driven index names its content service with the bucket member slot type and the index key type spelled
|
|
2112
|
+
out — `new OIMSlotContentSetBucketService()` infers `<TOIMSlot, TOIMStoreKey>` and fails to type-check:
|
|
2221
2113
|
|
|
2222
2114
|
```ts
|
|
2223
|
-
const bySuitService =
|
|
2115
|
+
const bySuitService = createOIMSlotCollectionIndexService(db, {
|
|
2224
2116
|
entityService: cardService,
|
|
2225
2117
|
columns: ['deck'],
|
|
2226
|
-
slotContentService: new
|
|
2118
|
+
slotContentService: new OIMSlotContentSetBucketService<TOIMEntitySlot<Card>, string>(),
|
|
2227
2119
|
});
|
|
2228
2120
|
const bySuit = bySuitService.createIndexStoreSlot(cards);
|
|
2229
2121
|
```
|
|
@@ -2241,17 +2133,15 @@ const bySuit = bySuitService.createIndexStoreSlot(cards);
|
|
|
2241
2133
|
ones `keyOf` reads. With `columns`, a patch or put whose changed columns include none of
|
|
2242
2134
|
them keeps the entity's key and calls nothing; a write of the whole value (a fill, a
|
|
2243
2135
|
clear, `markEntityChanged(slot)` with no names) always reads the key again.
|
|
2244
|
-
- **A key of several columns
|
|
2245
|
-
|
|
2246
|
-
tuple.
|
|
2247
|
-
`
|
|
2248
|
-
`isSameKey`), so a fresh array with the same parts moves nothing. `createOIMIndexService` takes a scalar key
|
|
2136
|
+
- **A key of several columns**: `createOIMSlotCollectionIndexService(db, { entityService, columns: ['deck', 'suit'],
|
|
2137
|
+
bucketSlotStoreService: new OIMSlotTreeStoreService(OIMDefaults.KEY_TREE_WALK_SCALAR.getValue()) })` makes the key
|
|
2138
|
+
the array of those values in order, typed as a tuple. Only that store knows the key is an array (its
|
|
2139
|
+
`isSameKey`), so a fresh array with the same parts moves nothing. `createOIMSlotCollectionIndexService` takes a scalar key
|
|
2249
2140
|
unless it is handed a `bucketSlotStoreService`: two columns or an array `keyOf` without one do not compile.
|
|
2250
2141
|
`getSlotsByKeys` / `holdSlotsByKeys` fill array-keyed buckets one pass over the
|
|
2251
2142
|
source per key (the cost of `getSlotByKey` each); only a scalar key gets one pass for all.
|
|
2252
|
-
- **Entity slots are filed on write**, using the index's key.
|
|
2253
|
-
|
|
2254
|
-
batch; the index groups the entity slots by key and moves each group with one bucket write.
|
|
2143
|
+
- **Entity slots are filed on write**, using the index's key. Writes inside `writeInBatch` on the collection
|
|
2144
|
+
notify once per batch; the index groups the entity slots by key and moves each group with one bucket write.
|
|
2255
2145
|
- **Reading**, each taking the index store slot first: `getSlotByKey`, `holdSlotByKey`, `findSlotByKey`,
|
|
2256
2146
|
`hasSlotContentByKey`, `getSlotsByKeys`, `holdSlotsByKeys`, `getSlots`, `getSlotCount`, `getEntitiesByKey`, and the bucket column
|
|
2257
2147
|
slot doors `getAnyBucketColumnByKey`, `holdAnyBucketColumnByKey`,
|
|
@@ -2275,9 +2165,9 @@ const bySuit = bySuitService.createIndexStoreSlot(cards);
|
|
|
2275
2165
|
is maintained whether anyone holds it or not.
|
|
2276
2166
|
- **Order is not the bucket's business, unless you pick the strategy that makes it so.**
|
|
2277
2167
|
A bucket keeps its arrival order; a sorted list is
|
|
2278
|
-
`
|
|
2168
|
+
`createOIMSortedComputedService(db, { indexService, sortColumns?, comparator? })`
|
|
2279
2169
|
— see [Sorted lists](#sorted-lists) — or the index is built with
|
|
2280
|
-
`
|
|
2170
|
+
`createOIMSlotCollectionSortedArrayIndexService`, whose buckets are already in order — see
|
|
2281
2171
|
[Sorted at write](#sorted-at-write). A second computed over the bucket handles
|
|
2282
2172
|
projection or filtering.
|
|
2283
2173
|
- **Members are read through the bucket content service**: `Array.from(indexService.slotContentService.getBucketMemberSlots(bucketSlot))`.
|
|
@@ -2287,9 +2177,9 @@ const bySuit = bySuitService.createIndexStoreSlot(cards);
|
|
|
2287
2177
|
membership only**: an entity slot joining or leaving. A write to an entity that stays in the
|
|
2288
2178
|
bucket does not wake it — subscribe to that entity's own slot for that.
|
|
2289
2179
|
- **Bucket lifetime is the `slotReleasePolicy` option, not the index's.** Name nothing (here or on the db)
|
|
2290
|
-
and it is `
|
|
2291
|
-
once empty; `
|
|
2292
|
-
and it cools on its queue; pass `
|
|
2180
|
+
and it is `OIMSlotAtEmptyReleasePolicy.INSTANCE`: an unheld bucket stays while it has members and goes
|
|
2181
|
+
once empty; `OIMSlotNeverReleasePolicy.INSTANCE` keeps it for good; pass an `OIMSlotAfterIdleReleasePolicy`
|
|
2182
|
+
and it cools on its queue; pass `OIMSlotAtUnholdReleasePolicy.INSTANCE` and it dies at the last give-back,
|
|
2293
2183
|
and the next hold builds a fresh one by walking the source again.
|
|
2294
2184
|
|
|
2295
2185
|
**The bucket's any-column slot exists, but it is not the recommended path.**
|
|
@@ -2300,7 +2190,7 @@ the bucket slot (`getSlotByKey` / `holdSlotByKey`). A reader that wants both sub
|
|
|
2300
2190
|
to both, and the subscriber picks by which slots it puts in `createEffect`.
|
|
2301
2191
|
|
|
2302
2192
|
```ts
|
|
2303
|
-
const deckIndexService =
|
|
2193
|
+
const deckIndexService = createOIMSlotCollectionIndexService(db, { entityService: cardService, keyOf: (card: Card) => card.deck });
|
|
2304
2194
|
const deckIndex = deckIndexService.createIndexStoreSlot(cards);
|
|
2305
2195
|
const spadesBucket = deckIndexService.holdSlotByKey(deckIndex, 'spades');
|
|
2306
2196
|
const spadesAnyColumn = deckIndexService.holdAnyBucketColumnByKey(deckIndex, 'spades');
|
|
@@ -2308,7 +2198,7 @@ const entitiesEffect = effectService.createEffect(db, [spadesBucket, spadesAnyCo
|
|
|
2308
2198
|
console.log(deckIndexService.getEntitiesByKey(deckIndex, 'spades'));
|
|
2309
2199
|
});
|
|
2310
2200
|
effectService.disposeEffect(entitiesEffect);
|
|
2311
|
-
deckIndexService.unholdColumn(spadesAnyColumn);
|
|
2201
|
+
deckIndexService.columnSlotService.unholdColumn(spadesAnyColumn);
|
|
2312
2202
|
spadesBucket.owner.unholdSlot(spadesBucket);
|
|
2313
2203
|
```
|
|
2314
2204
|
|
|
@@ -2340,19 +2230,17 @@ no listener is called, nothing is buffered, and the names array is reused across
|
|
|
2340
2230
|
every column write is added with `readColumnNames` `undefined`. **The filter is the union, per store
|
|
2341
2231
|
slot, not per listener**: once a write touches a column ANY listener of that store reads, every
|
|
2342
2232
|
listener of that store is called, so a listener that declared a narrower set still checks
|
|
2343
|
-
`changedColumns` itself, as `
|
|
2233
|
+
`changedColumns` itself, as `OIMSlotCollectionIndexService` does against its key columns.
|
|
2344
2234
|
`IOIMContentChangeListener<TSlot, TPatch>` has two methods:
|
|
2345
2235
|
`onContentChanged(slot, patch, changedColumns)` and
|
|
2346
2236
|
`onContentChangedMany(slotChannelQueue, patchChannelQueue, changedColumnsChannelQueue)` — three
|
|
2347
2237
|
parallel `OIMChannelQueue`s read with `getEntryCount()` / `getEntryAt(i)`, valid only during the
|
|
2348
2238
|
call, so a listener copies what it keeps — `patch` is what an update
|
|
2349
2239
|
wrote, `changedColumns` the names `markEntityChanged(slot, columns)` was given, either
|
|
2350
|
-
`undefined` when the write carries none. A
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
`onContentChangedMany` when the door returns. A subframe the caller opens on the channel slot
|
|
2355
|
-
does not hold them — an index is up to date as soon as the content service's own door returns.
|
|
2240
|
+
`undefined` when the write carries none. A single write outside a batch delivers one `onContentChanged` as soon as it is filed; inside
|
|
2241
|
+
`writeInBatch` (or `openBatch` / `closeBatch`) on the collection the writes are queued on the store slot and
|
|
2242
|
+
delivered as ONE `onContentChangedMany` when the outermost batch closes. Code inside the batch reads the index
|
|
2243
|
+
as it was before the batch.
|
|
2356
2244
|
This hook is the only seam an index uses; an index of your own is a listener.
|
|
2357
2245
|
|
|
2358
2246
|
**Bucket column slots.** An index hands out one column slot per bucket and column:
|
|
@@ -2366,24 +2254,24 @@ return the same kind of slot, written when any column of any member changes. A g
|
|
|
2366
2254
|
`slot.owner.unholdSlot(slot)`.
|
|
2367
2255
|
|
|
2368
2256
|
```ts
|
|
2369
|
-
const decksService =
|
|
2257
|
+
const decksService = createOIMSlotCollectionIndexService(db, { entityService: cardService, keyOf: (card: Card) => card.deck });
|
|
2370
2258
|
const decks = decksService.createIndexStoreSlot(cards);
|
|
2371
2259
|
const rankOfSpades = decksService.holdBucketColumnByKey(decks, 'spades', 'rank');
|
|
2372
2260
|
effectService.disposeEffect(effectService.createEffect(db, [rankOfSpades], [], () => {}));
|
|
2373
|
-
decksService.unholdColumn(rankOfSpades);
|
|
2261
|
+
decksService.columnSlotService.unholdColumn(rankOfSpades);
|
|
2374
2262
|
```
|
|
2375
2263
|
|
|
2376
2264
|
### Sorted lists
|
|
2377
2265
|
|
|
2378
2266
|
```ts signature
|
|
2379
|
-
|
|
2380
|
-
indexService:
|
|
2267
|
+
createOIMSortedComputedService<TKey, TEntity extends object, TSlots, TSourceKey, TSourceStore, TComputedStore?>({
|
|
2268
|
+
indexService: OIMSlotCollectionIndexService<TKey, TEntity, TSlots, TSourceKey, TSourceStore>;
|
|
2381
2269
|
sortColumns?: readonly TOIMSortColumn<TEntity>[]; // { column: TOIMSortableColumnName<TEntity>; direction: 'asc' | 'desc' }
|
|
2382
2270
|
comparator?: (left: TEntity, right: TEntity) => number;
|
|
2383
|
-
slotReleasePolicy?: IOIMSlotReleasePolicy; // default
|
|
2271
|
+
slotReleasePolicy?: IOIMSlotReleasePolicy; // default OIMSlotAtUnholdReleasePolicy.INSTANCE
|
|
2384
2272
|
columnSlotStoreService?: IOIMSlotStoreService<string, TOIMComputedColumnSlot>;
|
|
2385
2273
|
computedSlotStoreService?: IOIMSlotStoreService<TKey, TOIMComputedSlot<…>, TComputedStore>; // Map; REQUIRED for any other store
|
|
2386
|
-
}):
|
|
2274
|
+
}): OIMSortedComputedService<TKey, TEntity, TSlots, TSourceKey, TSourceStore, TComputedStore>
|
|
2387
2275
|
|
|
2388
2276
|
createSortedStoreSlot(indexStoreSlot: TOIMIndexStoreSlot<…>): TOIMStoreSlot<TComputedStore, TOIMSortedComputedSlot<TEntity, TKey>>
|
|
2389
2277
|
readonly computedCollectionService: OIMSlotCollectionService<TKey, TOIMSortedComputedSlot<TEntity, TKey>, TComputedStore, …>
|
|
@@ -2391,11 +2279,11 @@ readonly computedCollectionService: OIMSlotCollectionService<TKey, TOIMSortedCom
|
|
|
2391
2279
|
|
|
2392
2280
|
`slotReleasePolicy` decides whether a key's sorted list outlives its last hold. The
|
|
2393
2281
|
default lets it go at the unhold, so holding the key again sorts from scratch;
|
|
2394
|
-
`
|
|
2282
|
+
`OIMSlotNeverReleasePolicy.INSTANCE` keeps every key that was ever read and re-sorts it
|
|
2395
2283
|
only when a read finds it changed — the arm for a view that switches between groups.
|
|
2396
2284
|
Pass the same policy to the index the list reads, or its bucket is rebuilt instead.
|
|
2397
2285
|
|
|
2398
|
-
An `
|
|
2286
|
+
An `OIMSortedComputedService` takes no db: its store slots run on the channel slot of the index store slot
|
|
2399
2287
|
they sort. One per index service. `createSortedStoreSlot(indexStoreSlot)` makes one sorted store slot over
|
|
2400
2288
|
one index store slot, and the read doors of `computedCollectionService` take that store slot first:
|
|
2401
2289
|
`getSlotByKey`, `holdSlotByKey`, `findSlotByKey`, `getSlots`, `getSlotCount`, and the column doors; per key a
|
|
@@ -2421,11 +2309,11 @@ slots sorted. A hold is given back with `slot.owner.unholdSlot(slot)`.
|
|
|
2421
2309
|
to a member as with `comparator` alone.
|
|
2422
2310
|
|
|
2423
2311
|
```ts
|
|
2424
|
-
const cardsInDeckService =
|
|
2312
|
+
const cardsInDeckService = createOIMSlotCollectionIndexService(db, {
|
|
2425
2313
|
entityService: cardService,
|
|
2426
2314
|
keyOf: (card: Card) => card.deck,
|
|
2427
2315
|
});
|
|
2428
|
-
|
|
2316
|
+
createOIMSortedComputedService({
|
|
2429
2317
|
indexService: cardsInDeckService,
|
|
2430
2318
|
sortColumns: [{ column: 'title', direction: 'asc' }, { column: 'rank', direction: 'asc' }],
|
|
2431
2319
|
comparator: (l, r) => l.title.localeCompare(r.title, 'de') || l.rank - r.rank,
|
|
@@ -2440,9 +2328,9 @@ SECOND array of `createEffect`. A re-sort that yields the same sequence
|
|
|
2440
2328
|
(`oimSameSlotSequence`) keeps the previous array, so its identity is stable.
|
|
2441
2329
|
|
|
2442
2330
|
```ts
|
|
2443
|
-
const decksService =
|
|
2331
|
+
const decksService = createOIMSlotCollectionIndexService(db, { entityService: cardService, keyOf: (card: Card) => card.deck });
|
|
2444
2332
|
const decks = decksService.createIndexStoreSlot(cards);
|
|
2445
|
-
const byRankInDeckService =
|
|
2333
|
+
const byRankInDeckService = createOIMSortedComputedService({
|
|
2446
2334
|
indexService: decksService,
|
|
2447
2335
|
sortColumns: [{ column: 'rank', direction: 'asc' }],
|
|
2448
2336
|
});
|
|
@@ -2457,21 +2345,21 @@ spadesByRank.owner.unholdSlot(spadesByRank);
|
|
|
2457
2345
|
|
|
2458
2346
|
### Sorted at write
|
|
2459
2347
|
|
|
2460
|
-
A second way to get a sorted list. `
|
|
2461
|
-
index. `
|
|
2348
|
+
A second way to get a sorted list. `createOIMSortedComputedService` sorts at read, over any
|
|
2349
|
+
index. `createOIMSlotCollectionSortedArrayIndexService` keeps the index's own buckets sorted at write, and
|
|
2462
2350
|
the user picks one at construction.
|
|
2463
2351
|
|
|
2464
2352
|
```ts signature
|
|
2465
|
-
|
|
2466
|
-
entityService, ...TOIMIndexKeyOptions<TKey, TEntity, TColumns>, // as
|
|
2353
|
+
createOIMSlotCollectionSortedArrayIndexService<TEntity extends object, TSourceKey, TColumns?, TKey extends TOIMStoreKey?, TSourceStore?, TStore?>(db, {
|
|
2354
|
+
entityService, ...TOIMIndexKeyOptions<TKey, TEntity, TColumns>, // as createOIMSlotCollectionIndexService, scalar key
|
|
2467
2355
|
sortColumns: readonly TOIMSortColumn<TEntity>[]; // REQUIRED
|
|
2468
2356
|
bucketSlotStoreService?, slotReleasePolicy?, columnSlotStoreService?, columnNames?,
|
|
2469
|
-
}):
|
|
2357
|
+
}): OIMSlotCollectionSortedArrayIndexService<…> // its slotContentService is an OIMSlotContentSortedArrayBucketService
|
|
2470
2358
|
```
|
|
2471
2359
|
|
|
2472
2360
|
```ts
|
|
2473
2361
|
declare const someCardSlot: TOIMEntitySlot<Card, TOIMStoreKey>;
|
|
2474
|
-
const cardsByDeckService =
|
|
2362
|
+
const cardsByDeckService = createOIMSlotCollectionSortedArrayIndexService(db, {
|
|
2475
2363
|
entityService: cardService,
|
|
2476
2364
|
columns: ['deck'],
|
|
2477
2365
|
sortColumns: [{ column: 'rank', direction: 'asc' }, { column: 'id', direction: 'desc' }],
|
|
@@ -2484,26 +2372,26 @@ cardsByDeckService.slotContentService.getBucketMemberSlotPosition(spades, someCa
|
|
|
2484
2372
|
```
|
|
2485
2373
|
|
|
2486
2374
|
- **Reads come back in order**: `getBucketMemberSlots`, `getBucketMemberSlotAt` and
|
|
2487
|
-
`getBucketMemberSlotPosition` on `
|
|
2375
|
+
`getBucketMemberSlotPosition` on `OIMSlotContentSortedArrayBucketService` answer in `sortColumns` order,
|
|
2488
2376
|
so no sorted computed is needed.
|
|
2489
2377
|
- **A lazy insertion buffer.** A write appends the arrival to an unsorted tail of the bucket's
|
|
2490
|
-
array (`
|
|
2378
|
+
array (`TOIMBucketSlotsArrayStore`: the array store plus `sortedCount`). The first read
|
|
2491
2379
|
settles the tail: binary insertion when the tail is short, one sort of the array when it is
|
|
2492
2380
|
long. A bucket nobody reads is never sorted.
|
|
2493
2381
|
- **The index re-files a member when one of its sort columns changes, and only then.** A write
|
|
2494
2382
|
to a column that is neither the key nor a sort column neither reorders the bucket nor wakes it.
|
|
2495
2383
|
A re-file wakes the bucket once per frame.
|
|
2496
2384
|
- **There are no positional writes** on this bucket (`insertBucketMemberSlotAt` and the other
|
|
2497
|
-
position writes belong to `
|
|
2385
|
+
position writes belong to `OIMSlotContentPositionalArrayBucketService`): the order is the comparator's,
|
|
2498
2386
|
not the caller's.
|
|
2499
|
-
- **Bucket commands are always `
|
|
2387
|
+
- **Bucket commands are always `OIMNoBucketCommands`**: this strategy records no per-flush
|
|
2500
2388
|
script.
|
|
2501
|
-
- **Parts**: `
|
|
2502
|
-
`
|
|
2503
|
-
`repositionBucketMemberSlot(bucketSlot, bucketMemberSlot)`), `
|
|
2389
|
+
- **Parts**: `OIMSlotContentSortedArrayBucketService` (options
|
|
2390
|
+
`TOIMSlotContentSortedArrayBucketServiceOptions`: `compareBucketMemberSlots`; adds
|
|
2391
|
+
`repositionBucketMemberSlot(bucketSlot, bucketMemberSlot)`), `OIMSlotCollectionSortedArrayIndexService`.
|
|
2504
2392
|
|
|
2505
2393
|
**Choosing between the two arms.** Sort-at-write suits point updates: a change to a sort
|
|
2506
|
-
column re-files one member. Sort-at-read (`
|
|
2394
|
+
column re-files one member. Sort-at-read (`createOIMSortedComputedService` over any index)
|
|
2507
2395
|
suits bulk loads. Both are shipped; neither is a default.
|
|
2508
2396
|
|
|
2509
2397
|
**`indexKeys` on each entity slot.** Each indexable slot carries, per index store slot, the key the entity is
|
|
@@ -2516,10 +2404,10 @@ writer. Only the index writes it, through the `IOIMIndexKeysService` (`get(slot,
|
|
|
2516
2404
|
|
|
2517
2405
|
| strategy | on `disposeIndexStoreSlot` | cost |
|
|
2518
2406
|
|---|---|---|
|
|
2519
|
-
| `
|
|
2520
|
-
| `
|
|
2407
|
+
| `OIMAppendingIndexKeysService` (default) | the index's position is never reused; its stale entry stays on each entity slot | an entity slot's `indexKeys` grows to the highest position any index wrote on it (K indexes made and disposed → an array of K on an entity slot the last one filed), and a stale entry keeps its key reachable. Writes pay nothing for a disposed index: only live listeners are kept |
|
|
2408
|
+
| `OIMReclaimingIndexKeysService` | wipes that position on every entity slot of the source store slot and reuses it | O(N) per dispose |
|
|
2521
2409
|
|
|
2522
|
-
Switch to `
|
|
2410
|
+
Switch to `OIMReclaimingIndexKeysService` only if you create indexes dynamically and often. Creating
|
|
2523
2411
|
indexes dynamically and often is expensive, so avoid it.
|
|
2524
2412
|
|
|
2525
2413
|
### The channel of a bucket store slot
|
|
@@ -2582,7 +2470,7 @@ the next read or hold.
|
|
|
2582
2470
|
class OIMComputedService<TKey, TValue, TComputedStore> {
|
|
2583
2471
|
constructor(options: TOIMComputedServiceOptions<TKey, TValue, TComputedStore>);
|
|
2584
2472
|
readonly computedCollectionService: OIMSlotCollectionService<TKey, TOIMComputedSlot<TValue, TKey>, TComputedStore,
|
|
2585
|
-
OIMComputedValueService<TKey, TValue>, Extract<keyof TValue, string>, TOIMComputedColumnSlot,
|
|
2473
|
+
OIMComputedValueService<TKey, TValue>, Extract<keyof TValue, string>, TOIMComputedColumnSlot, OIMPullColumnSlotOwner>;
|
|
2586
2474
|
createComputedStoreSlot(channelMap: IOIMChannelMap, derive?, createSources?): TOIMComputedStoreSlot<TComputedStore, TValue, TKey>;
|
|
2587
2475
|
}
|
|
2588
2476
|
|
|
@@ -2591,7 +2479,7 @@ createOIMComputedService<TKey, TValue, TComputedStore = Map<TKey, TOIMComputedSl
|
|
|
2591
2479
|
derive?: (computedSlot: TOIMComputedSlot<TValue, TKey>) => TValue;
|
|
2592
2480
|
sameValueGuard?: TOIMSameValueGuard<TValue>; // default Object.is
|
|
2593
2481
|
initialValue?: TValue;
|
|
2594
|
-
slotReleasePolicy?: IOIMSlotReleasePolicy; // default
|
|
2482
|
+
slotReleasePolicy?: IOIMSlotReleasePolicy; // default OIMSlotAtUnholdReleasePolicy.INSTANCE
|
|
2595
2483
|
columnSlotStoreService?: IOIMSlotStoreService<string, TOIMComputedColumnSlot>; // OIMDefaults.COMPUTED_COLUMN_SLOT_STORE_SERVICE
|
|
2596
2484
|
columnNames?: readonly Extract<keyof TValue, string>[];
|
|
2597
2485
|
computedSlotStoreService?: IOIMSlotStoreService<TKey, TOIMComputedSlot<TValue, TKey>, TComputedStore>; // Map; REQUIRED for any other store
|
|
@@ -2611,15 +2499,13 @@ Doors of a keyed computed store slot are the read doors of `computedCollectionSe
|
|
|
2611
2499
|
`getSlots(storeSlot)`, `getSlotCount(storeSlot)`, and the column doors; the value is
|
|
2612
2500
|
`slot.computedValueService.getValueForSlot(slot)`, and a give-back is `slot.owner.unholdSlot(slot)`.
|
|
2613
2501
|
|
|
2614
|
-
**
|
|
2615
|
-
`
|
|
2616
|
-
|
|
2617
|
-
|
|
2502
|
+
**A single computed is its own service.** `createOIMSingleComputedService<TValue>({ … })` builds an
|
|
2503
|
+
`OIMSingleComputedService`, whose store slots each hold at most one computed slot, read through
|
|
2504
|
+
`computedSingleSlotService` (`getSingleSlot`, `holdSingleSlot`, `findSingleSlot`). Like a keyed one, a store slot
|
|
2505
|
+
outlives every computed slot it mints and mints a fresh one on the next read or hold once the previous one is gone.
|
|
2618
2506
|
|
|
2619
2507
|
```ts
|
|
2620
|
-
const topRankService =
|
|
2621
|
-
computedSlotStoreService:
|
|
2622
|
-
OIMSlotStoreServiceSingleSlotDriven.INSTANCE as unknown as OIMSlotStoreServiceSingleSlotDriven<TOIMComputedSlot<number, void>>,
|
|
2508
|
+
const topRankService = createOIMSingleComputedService<number>({
|
|
2623
2509
|
sameValueGuard: oimSameValueZeroGuard,
|
|
2624
2510
|
initialValue: -1,
|
|
2625
2511
|
});
|
|
@@ -2628,16 +2514,15 @@ const topRank = topRankService.createComputedStoreSlot(
|
|
|
2628
2514
|
() => cardService.getSlotByKey(cards, 'c1').entity?.rank ?? -1,
|
|
2629
2515
|
() => ({ sourceSlots: [cardService.getSlotByKey(cards, 'c1')] }),
|
|
2630
2516
|
);
|
|
2631
|
-
const heldTopRank = topRankService.
|
|
2517
|
+
const heldTopRank = topRankService.computedSingleSlotService.holdSingleSlot(topRank); // the same slot while anything holds it
|
|
2632
2518
|
heldTopRank.computedValueService.getValueForSlot(heldTopRank);
|
|
2633
|
-
heldTopRank.owner.unholdSlot(heldTopRank); // gone; the next
|
|
2519
|
+
heldTopRank.owner.unholdSlot(heldTopRank); // gone; the next holdSingleSlot(topRank) mints a new one
|
|
2634
2520
|
```
|
|
2635
2521
|
|
|
2636
|
-
A single computed store slot has
|
|
2637
|
-
undefined)` hands a slot without a hold — a fresh one goes to the unused-slot collector and is let go at the
|
|
2522
|
+
A single computed store slot has no key and a store of one slot. `getSingleSlot(storeSlot)` hands a slot without a hold — a fresh one goes to the unused-slot collector and is let go at the
|
|
2638
2523
|
next flush unless something holds it — and `holdSlotByKey(storeSlot, undefined)` holds the live slot, minting
|
|
2639
2524
|
one if the previous is gone. A computed slot goes at its last unhold once no effect reads it
|
|
2640
|
-
(`
|
|
2525
|
+
(`OIMSlotAtUnholdReleasePolicy`, the default), and gives back the holds it took on its
|
|
2641
2526
|
sources. A last unhold during a flush releases at the end of that flush, through the
|
|
2642
2527
|
db's unused-slot collector, as for every non-empty slot. The holds a computed takes on its sources and
|
|
2643
2528
|
gives back are one stateless service, shared by both shapes.
|
|
@@ -2651,11 +2536,11 @@ list, and a source a build closes over without naming is a source nothing holds.
|
|
|
2651
2536
|
**A derivation is never empty.** `OIMComputedService` answers
|
|
2652
2537
|
"empty" with `false`, so a filed derivation is released only when nothing holds
|
|
2653
2538
|
it, nothing watches it, and the grace is `0` — which is what
|
|
2654
|
-
`
|
|
2539
|
+
`OIMSlotAtUnholdReleasePolicy` answers, and the default when no `slotReleasePolicy` is given.
|
|
2655
2540
|
|
|
2656
2541
|
```ts setup
|
|
2657
2542
|
const rankService = createOIMComputedService<TOIMStoreKey, number>({
|
|
2658
|
-
createSources: (
|
|
2543
|
+
createSources: ({ key }) => ({ sourceSlots: [cardService.getSlotByKey(cards, key)] }),
|
|
2659
2544
|
derive: (computedSlot) => cardService.getSlotByKey(cards, computedSlot.key).entity?.rank ?? -1,
|
|
2660
2545
|
sameValueGuard: oimSameValueZeroGuard,
|
|
2661
2546
|
initialValue: -1,
|
|
@@ -2686,37 +2571,34 @@ Pinned by `facade/computed/tests/what-a-computed-column-wakes-on.test.ts`.
|
|
|
2686
2571
|
|
|
2687
2572
|
```ts
|
|
2688
2573
|
type Summary = { top: number; count: number };
|
|
2689
|
-
const summaryService =
|
|
2690
|
-
computedSlotStoreService:
|
|
2691
|
-
OIMSlotStoreServiceSingleSlotDriven.INSTANCE as unknown as OIMSlotStoreServiceSingleSlotDriven<TOIMComputedSlot<Summary, void>>,
|
|
2692
|
-
});
|
|
2574
|
+
const summaryService = createOIMSingleComputedService<Summary>();
|
|
2693
2575
|
const summary = summaryService.createComputedStoreSlot(
|
|
2694
2576
|
db,
|
|
2695
2577
|
() => ({ top: slot.entity?.rank ?? -1, count: cardService.getSlotCount(cards) }),
|
|
2696
2578
|
() => ({ sourceSlots: [slot] }),
|
|
2697
2579
|
);
|
|
2698
|
-
const
|
|
2699
|
-
const summaryTop =
|
|
2580
|
+
const summarySingleSlotService = summaryService.computedSingleSlotService;
|
|
2581
|
+
const summaryTop = summarySingleSlotService.columnSlotService.holdColumn(summarySingleSlotService.getSingleSlot(summary), 'top');
|
|
2700
2582
|
const topEffect = effectService.createEffect(db, [], [summaryTop], () => { paint(slot.entity); });
|
|
2701
2583
|
effectService.disposeEffect(topEffect);
|
|
2702
|
-
|
|
2584
|
+
summarySingleSlotService.columnSlotService.unholdColumn(summaryTop);
|
|
2703
2585
|
```
|
|
2704
2586
|
|
|
2705
2587
|
### The order of a bucket, as one derivation per key
|
|
2706
2588
|
|
|
2707
2589
|
```ts signature
|
|
2708
|
-
|
|
2590
|
+
createOIMBucketMemoComputedService<TKey, TBucketMemberSlot extends TOIMSlot, TSlots, TBucketStore, TComputedStore?>({
|
|
2709
2591
|
bucketCollectionService: OIMSlotCollectionService<TKey, TOIMBucketSlot<TSlots, TKey>, TBucketStore, OIMSlotContentBucketService<TBucketMemberSlot, TSlots>, …>;
|
|
2710
|
-
slotReleasePolicy?: IOIMSlotReleasePolicy; // default
|
|
2592
|
+
slotReleasePolicy?: IOIMSlotReleasePolicy; // default OIMSlotAtUnholdReleasePolicy.INSTANCE
|
|
2711
2593
|
columnSlotStoreService?: IOIMSlotStoreService<string, TOIMComputedColumnSlot>;
|
|
2712
2594
|
computedSlotStoreService?: IOIMSlotStoreService<TKey, TOIMComputedSlot<readonly TBucketMemberSlot[], TKey>, TComputedStore>;
|
|
2713
|
-
}):
|
|
2595
|
+
}): OIMBucketMemoComputedService<TKey, TBucketMemberSlot, TSlots, TBucketStore, TComputedStore>
|
|
2714
2596
|
|
|
2715
2597
|
createBucketMemoStoreSlot(bucketStoreSlot: TOIMStoreSlot<TBucketStore, TOIMBucketSlot<TSlots, TKey>, readonly TBucketMemberSlot[]>): TOIMStoreSlot<TComputedStore, TOIMBucketMemoComputedSlot<TBucketMemberSlot, TKey>>
|
|
2716
2598
|
```
|
|
2717
2599
|
|
|
2718
2600
|
It takes no db: a memo store slot runs on the channel slot of the bucket store slot it reads. The class is
|
|
2719
|
-
`new
|
|
2601
|
+
`new OIMBucketMemoComputedService(options)` (options type `TOIMBucketMemoComputedServiceOptions`), whose
|
|
2720
2602
|
`computedCollectionService` reads the per-key derivations; `createBucketMemoStoreSlot(bucketStoreSlot)` makes
|
|
2721
2603
|
one memo store slot over one bucket store slot.
|
|
2722
2604
|
|
|
@@ -2726,13 +2608,13 @@ it is produced on the read that asks for it and never while nothing reads it, an
|
|
|
2726
2608
|
its `changedAtRevision` and `changedAtEpoch` move only when the list a reader would
|
|
2727
2609
|
see actually changed. The list is handed back by IDENTITY: it is the same array for
|
|
2728
2610
|
as long as the list holds, so a consumer memoising on identity needs no comparison
|
|
2729
|
-
of its own. For a SORTED list use [`
|
|
2611
|
+
of its own. For a SORTED list use [`createOIMSortedComputedService`](#sorted-lists).
|
|
2730
2612
|
|
|
2731
2613
|
The source list is ONE slot — the bucket — and it never grows: a bucket
|
|
2732
2614
|
change is a move of the bucket's value, not of the derivation's sources.
|
|
2733
2615
|
|
|
2734
2616
|
```ts
|
|
2735
|
-
const orderService =
|
|
2617
|
+
const orderService = createOIMBucketMemoComputedService({
|
|
2736
2618
|
bucketCollectionService: orderedService,
|
|
2737
2619
|
});
|
|
2738
2620
|
const order = orderService.createBucketMemoStoreSlot(ordered);
|
|
@@ -2787,7 +2669,7 @@ type TOIMCompositeKeyNode<TAtKey = unknown, TCompositeKeyPart = TOIMEntitySlot>
|
|
|
2787
2669
|
};
|
|
2788
2670
|
```
|
|
2789
2671
|
|
|
2790
|
-
`TOIMSlotStoreTree` is what `
|
|
2672
|
+
`TOIMSlotStoreTree` is what `OIMSlotTreeStoreService.createStore()` builds:
|
|
2791
2673
|
the tree's root plus a flat `Set` of every filed slot, which makes `getSlots()` and
|
|
2792
2674
|
`getSlotCount()` O(1) rather than a walk, and keeps `getSlots()` in filing order like every other store.
|
|
2793
2675
|
`TOIMCompositeKeyNode` is one level of that tree — a `Map` from composite key part to the
|
|
@@ -2797,10 +2679,10 @@ are holding; neither is something you build by hand.
|
|
|
2797
2679
|
|
|
2798
2680
|
| Store | Key type |
|
|
2799
2681
|
|---|---|
|
|
2800
|
-
| `
|
|
2801
|
-
| `
|
|
2802
|
-
| `
|
|
2803
|
-
| `
|
|
2682
|
+
| `OIMSlotMapStoreService<TSlot>` | `TOIMStoreKey` = `string \| number` |
|
|
2683
|
+
| `OIMSlotTreeStoreService<TOIMStoreKey, TSlot>` built with `OIMDefaults.KEY_TREE_WALK_SCALAR.getValue()` | `readonly TOIMStoreKey[]` — **a chain of VALUES** |
|
|
2684
|
+
| `OIMSlotTreeStoreService<TOIMEntitySlot, TSlot>` built with `OIMDefaults.KEY_TREE_WALK_COMPOSITE.getValue()` | `readonly TOIMEntitySlot[]` — **a chain of entity SLOTS** |
|
|
2685
|
+
| `OIMSingleSlotStoreService.INSTANCE` | `void` — one slot per store slot, its store a `TOIMSingleSlotStore` (`{ slot }`); what every single is built on |
|
|
2804
2686
|
|
|
2805
2687
|
Two stores for keys, one per shape of address, and the single-slot store for no key. The chain store descends one `Map`
|
|
2806
2688
|
lookup per composite key part, keeps `[a]` and `[a, b]` apart, and has **no encoding step**:
|
|
@@ -2840,10 +2722,10 @@ deletes nothing and returns `undefined`.
|
|
|
2840
2722
|
|
|
2841
2723
|
| Walk | Class | Shared instance | What a composite key part is | Holds? |
|
|
2842
2724
|
|---|---|---|---|---|
|
|
2843
|
-
| scalar | `
|
|
2844
|
-
| composite | `
|
|
2725
|
+
| scalar | `OIMScalarKeyTreeWalk` | `OIMDefaults.KEY_TREE_WALK_SCALAR.getValue()` | `TOIMStoreKey` | no |
|
|
2726
|
+
| composite | `OIMCompositeKeyTreeWalk` | `OIMDefaults.KEY_TREE_WALK_COMPOSITE.getValue()` | `TOIMEntitySlot` | **yes — one hold per edge** |
|
|
2845
2727
|
|
|
2846
|
-
**The hold is the whole difference.** `
|
|
2728
|
+
**The hold is the whole difference.** `OIMCompositeKeyTreeWalk.mintNodeAt` calls
|
|
2847
2729
|
`holdCompositeKeyPart` the first time it creates an edge, which runs
|
|
2848
2730
|
`entitySlot.owner.holdSlot(entitySlot)`; `deleteKey` calls `unholdCompositeKeyPart` on
|
|
2849
2731
|
exactly the edges it unlinked, deepest first and only after every unlink is done, which runs `entitySlot.owner.unholdSlot(entitySlot)` unless
|
|
@@ -2861,16 +2743,16 @@ type TScalarChain = readonly TOIMStoreKey[];
|
|
|
2861
2743
|
type Tally = { deck: string; day: string; count: number };
|
|
2862
2744
|
type TTallyStore = import('@oimdb/core').TOIMSlotStoreTree<TOIMEntitySlot<Tally, TScalarChain>, TOIMStoreKey>;
|
|
2863
2745
|
|
|
2864
|
-
const tallyService = createOIMSlotCollectionService
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2746
|
+
const tallyService = createOIMSlotCollectionService<
|
|
2747
|
+
ReturnType<typeof createOIMSlotContentEntityService<Tally, TScalarChain>>, TTallyStore
|
|
2748
|
+
>(db, {
|
|
2749
|
+
slotContentService: createOIMSlotContentEntityService<Tally, TScalarChain>(db),
|
|
2750
|
+
slotStoreService: new OIMSlotTreeStoreService<TOIMStoreKey, TOIMEntitySlot<Tally, TScalarChain>>(
|
|
2751
|
+
OIMDefaults.KEY_TREE_WALK_SCALAR.getValue(),
|
|
2752
|
+
),
|
|
2871
2753
|
});
|
|
2872
2754
|
const tallies = tallyService.createStoreSlot(db);
|
|
2873
|
-
tallyService.
|
|
2755
|
+
tallyService.writeSlotContentByKey(tallies, ['spades', 'mon'], { deck: 'spades', day: 'mon', count: 1 });
|
|
2874
2756
|
tallyService.getSlotByKey(tallies, ['spades', 'mon']);
|
|
2875
2757
|
```
|
|
2876
2758
|
|
|
@@ -2891,16 +2773,16 @@ type Enrolment = {
|
|
|
2891
2773
|
type TChain = readonly TOIMEntitySlot[];
|
|
2892
2774
|
type TEnrolmentStore = import('@oimdb/core').TOIMSlotStoreTree<TOIMEntitySlot<Enrolment, TChain>, TOIMEntitySlot>;
|
|
2893
2775
|
|
|
2894
|
-
const enrolmentService = createOIMSlotCollectionService
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2776
|
+
const enrolmentService = createOIMSlotCollectionService<
|
|
2777
|
+
ReturnType<typeof createOIMSlotContentEntityService<Enrolment, TChain>>, TEnrolmentStore
|
|
2778
|
+
>(db, {
|
|
2779
|
+
slotContentService: createOIMSlotContentEntityService<Enrolment, TChain>(db),
|
|
2780
|
+
slotStoreService: new OIMSlotTreeStoreService<TOIMEntitySlot, TOIMEntitySlot<Enrolment, TChain>>(
|
|
2781
|
+
OIMDefaults.KEY_TREE_WALK_COMPOSITE.getValue(),
|
|
2782
|
+
),
|
|
2901
2783
|
});
|
|
2902
2784
|
const enrolments = enrolmentService.createStoreSlot(db);
|
|
2903
|
-
enrolmentService.
|
|
2785
|
+
enrolmentService.writeSlotContentByKey(enrolments, [alice, admins], { user: alice, group: admins, since: 2026 });
|
|
2904
2786
|
enrolmentService.getSlotByKey(enrolments, [alice, admins]);
|
|
2905
2787
|
```
|
|
2906
2788
|
|
|
@@ -2945,10 +2827,14 @@ At a deadline the release queue reads its MARKER off the slot, decides, and call
|
|
|
2945
2827
|
| `unsubscribeFromSlot(slot, at, effect)` | swap the tail of both arrays into `at`, tell the moved effect its new position at its edge (one write, no search), and **if that emptied the list, `onSlotIdle(slot)` opens a fresh idle window**, then give the subscription's hold back through `unholdSlot`; hand back whether it unfiled. Unfiling by remembered position is why taking N subscribers off one identity is O(N) and not quadratic. **Throws by name** on a released slot |
|
|
2946
2828
|
|
|
2947
2829
|
**`OIMSlotOwner`** is the base class and it is concrete: it implements all five.
|
|
2948
|
-
Its `releaseSlotIfUnheld` does nothing,
|
|
2830
|
+
Its `releaseSlotIfUnheld` does nothing, its
|
|
2831
|
+
`unsafeMutateSlot(slot, mutateSlot)` hands `mutateSlot` the slot as `TOIMSlotEditable` with no
|
|
2832
|
+
guard at all (it exists so a library that adds its own release wheel can keep its own bit in
|
|
2833
|
+
`slot.slotFlags`; the engine owns bits `1`, `2`, `4`, `8` and `16`, so a library starts at `32`;
|
|
2834
|
+
it is on the owner so a subclass can hook every such mutation), and a `protected
|
|
2949
2835
|
onSlotIdle` does nothing; a `protected assertNotReleased` is what every refusing
|
|
2950
2836
|
door above calls. `OIMSlotOwnerService` overrides `onSlotIdle` and
|
|
2951
|
-
`releaseSlotIfUnheld`, asking its release policy and its content
|
|
2837
|
+
`releaseSlotIfUnheld`, asking its release policy and its content service; the clock is the slot's channel slot's.
|
|
2952
2838
|
Extend `OIMSlotOwner` when you own slots that no collection files.
|
|
2953
2839
|
**`OIMDefaults.STANDALONE_SLOT_OWNER`** is one shared instance of it — the owner of a
|
|
2954
2840
|
computed slot nobody has filed. It never releases anything, which is exactly what
|
|
@@ -2959,12 +2845,12 @@ owner is its collection type's slot owner, and that release policy applies to it
|
|
|
2959
2845
|
|
|
2960
2846
|
**Columns are a module of every collection.** The column slots of a carrier slot live
|
|
2961
2847
|
in `carrierSlot.columnSlotStore`, a field of the base `TOIMSlot`, so any slot can carry
|
|
2962
|
-
them — an entity slot, a bucket slot, a computed slot. `
|
|
2848
|
+
them — an entity slot, a bucket slot, a computed slot. `OIMColumnSlotOwner` is abstract, an
|
|
2963
2849
|
`OIMSlotOwner` subclass, with two strategies:
|
|
2964
|
-
`
|
|
2965
|
-
keyed and single) and `
|
|
2850
|
+
`OIMPushColumnSlotOwner` (plain column slots woken by marks on a write; entity and bucket collections,
|
|
2851
|
+
keyed and single) and `OIMPullColumnSlotOwner` (each column slot a computed slot over its carrier;
|
|
2966
2852
|
computed collections, keyed and single). The factory hands the strategy's factory to the slot owner as
|
|
2967
|
-
`
|
|
2853
|
+
`createColumnSlotOwner`. Each collection type has its own column owner, and every column slot it mints names that
|
|
2968
2854
|
owner as its `owner`. The owner holds only the column slot store service; the column state — the column
|
|
2969
2855
|
groups and which columns are referenced — lives on the store slot. The collection exposes it only
|
|
2970
2856
|
through its column doors: `getColumn(slot, columnName)`, `holdColumn(slot, columnName)`,
|
|
@@ -3027,12 +2913,11 @@ content service hands back the LIVE list — declared `Iterable`, not an array,
|
|
|
3027
2913
|
`Array.from(bucketService.slotContentService.getBucketMemberSlots(bucketSlot))` is required and is the copy. A `prev` kept
|
|
3028
2914
|
live is the same array as `next` on the following frame: the diff is empty,
|
|
3029
2915
|
no reorder is ever drawn, and nothing throws. The other safe `prev` is
|
|
3030
|
-
`
|
|
2916
|
+
`createOIMBucketMemoComputedService`'s value — a fresh array on every write that
|
|
3031
2917
|
changed the list, the same array while it did not.
|
|
3032
2918
|
|
|
3033
2919
|
A LIST MAY NAME ONE SLOT TWICE, and then it holds that slot twice.
|
|
3034
|
-
`
|
|
3035
|
-
records every mention, so an ordered bucket's list is exactly such a list. The
|
|
2920
|
+
`OIMSlotContentPositionalArrayBucketService` records every mention, so an ordered bucket's list is exactly such a list. The
|
|
3036
2921
|
mentions of one identity are matched in the order they appear, and the script
|
|
3037
2922
|
reproduces `next` mention for mention. The minimal move count (`common − LIS`)
|
|
3038
2923
|
is claimed for lists whose identities are distinct: where the two lists name one
|
|
@@ -3084,7 +2969,9 @@ type TOIMStoreSlot<TStore = unknown, TSlot extends TOIMSlot = TOIMSlot, TPatch =
|
|
|
3084
2969
|
readonly indexKeysPositions: TOIMIndexKeysPositions | undefined;
|
|
3085
2970
|
readonly sourceStoreSlot: TOIMStoreSlot | undefined; // an index store slot's source
|
|
3086
2971
|
readonly isDisposed: boolean; // an index store slot after disposeIndexStoreSlot
|
|
3087
|
-
|
|
2972
|
+
readonly slotService: TSlotService; // the service that created the store slot
|
|
2973
|
+
readonly batchDepth: number; // openBatch / closeBatch nesting
|
|
2974
|
+
// … column-reader counts, column groups, batch queues, bucket write queues: the services' own
|
|
3088
2975
|
};
|
|
3089
2976
|
|
|
3090
2977
|
type TOIMSingleSlotStore<TSlot> = { slot: TSlot | undefined };
|
|
@@ -3118,7 +3005,7 @@ type TOIMEntitySlot<TEntity extends object = object, TKey = unknown> = TOIMIndex
|
|
|
3118
3005
|
};
|
|
3119
3006
|
|
|
3120
3007
|
// `data` belongs to the consumer: the core never reads or writes it, and clearing or
|
|
3121
|
-
// removing the slot (`slotContentService.
|
|
3008
|
+
// removing the slot (`slotContentService.clearSlotContent(slot)`) does not reset it. Each index keeps its
|
|
3122
3009
|
// last key for the entity slot in `indexKeys`, through the db's `IOIMIndexKeysService`.
|
|
3123
3010
|
|
|
3124
3011
|
type TOIMColumnSlot = TOIMSlot & {
|
|
@@ -3128,26 +3015,26 @@ type TOIMColumnSlot = TOIMSlot & {
|
|
|
3128
3015
|
|
|
3129
3016
|
type TOIMComputedColumnSlot = TOIMComputedSlot<unknown, string>; // a computed's getColumn / holdColumn return it; it goes in createEffect's second list
|
|
3130
3017
|
|
|
3131
|
-
type
|
|
3018
|
+
type TOIMBucketContentSlot<TSlots = unknown> = TOIMSlot & {
|
|
3132
3019
|
readonly owner: IOIMSlotOwner;
|
|
3133
|
-
readonly storeSlot: TOIMStoreSlot<unknown,
|
|
3020
|
+
readonly storeSlot: TOIMStoreSlot<unknown, TOIMBucketContentSlot<TSlots>>;
|
|
3134
3021
|
readonly bucketSlotsStore: TSlots;
|
|
3135
3022
|
readonly commands: readonly TOIMOrderedListCommand[] | undefined; // emptied when the flush has ended
|
|
3136
3023
|
readonly isWholeListRecorded: boolean; // reset to false with it
|
|
3137
3024
|
readonly commandsStartedAtRevision: number; // the clock the script started at
|
|
3138
3025
|
readonly commandsStartedAtEpoch: number;
|
|
3139
|
-
readonly wasEmptyBeforeChange: boolean | undefined;
|
|
3140
|
-
readonly isChangedAgainInSubframe: boolean;
|
|
3141
3026
|
};
|
|
3027
|
+
type TOIMBucketSlot<TSlots = unknown, TKey extends NonNullable<unknown> = NonNullable<unknown>> =
|
|
3028
|
+
TOIMBucketContentSlot<TSlots> & TOIMIndexableSlot<TKey>; // a keyed bucket slot; a single bucket is the content slot alone
|
|
3142
3029
|
|
|
3143
3030
|
// `holdSlotByKey(storeSlot, key)` hands back the slot itself; give the hold back with `slot.owner.unholdSlot(slot)`.
|
|
3144
3031
|
|
|
3145
3032
|
type TOIMBucketSlotsSetStore<TBucketMemberSlot extends TOIMSlot = TOIMSlot> = Set<TBucketMemberSlot>;
|
|
3146
3033
|
type TOIMBucketSlotsArrayStore<TBucketMemberSlot extends TOIMSlot = TOIMSlot> = {
|
|
3147
3034
|
bucketMemberSlots: TBucketMemberSlot[];
|
|
3035
|
+
uniqueBucketMemberSlots: Set<TBucketMemberSlot> | undefined; // kept by OIMBucketUniqueMemberSlotsArrayService
|
|
3036
|
+
sortedCount: number;
|
|
3148
3037
|
};
|
|
3149
|
-
type TOIMBucketSlotsArrayUniqueStore<TBucketMemberSlot extends TOIMSlot = TOIMSlot> =
|
|
3150
|
-
TOIMBucketSlotsArrayStore<TBucketMemberSlot> & { uniqueBucketMemberSlots: Set<TBucketMemberSlot> };
|
|
3151
3038
|
|
|
3152
3039
|
type TOIMEntityColumnName<TEntity extends object> =
|
|
3153
3040
|
[TEntity] extends [never] ? never
|
|
@@ -3182,38 +3069,39 @@ that matches what you are comparing; they are not interchangeable.
|
|
|
3182
3069
|
|
|
3183
3070
|
## Full export list
|
|
3184
3071
|
|
|
3185
|
-
**
|
|
3072
|
+
**218 names, every export of `packages/core/src/index.ts`, grouped by topic.**
|
|
3186
3073
|
|
|
3187
3074
|
*Channel and database slots* — `OIMChannelService` · `TOIMChannelSlot` · `TOIMChannelSlotOptions` · `createOIMChannelSlot` ·
|
|
3188
|
-
`IOIMChannelMap` · `TOIMDBOptions` · `OIMFlushSchedulerService` · `TOIMFlushSchedulerSlot`
|
|
3075
|
+
`IOIMChannelMap` · `TOIMDBOptions` · `OIMFlushSchedulerService` · `TOIMFlushSchedulerSlot` · `IOIMFlushSchedulerListener`
|
|
3189
3076
|
|
|
3190
3077
|
*Collector services and slots* — `OIMUnusedSlotCollectorService` · `TOIMUnusedSlotCollectorSlot` ·
|
|
3191
3078
|
`createOIMUnusedSlotCollectorSlot` · `TOIMCollectorSlot` · `TOIMCollectorSlotOptions` · `createOIMCollectorSlot` ·
|
|
3192
|
-
`
|
|
3193
|
-
`
|
|
3194
|
-
`
|
|
3195
|
-
|
|
3196
|
-
*Slot services* — `
|
|
3197
|
-
`
|
|
3198
|
-
`
|
|
3199
|
-
`
|
|
3200
|
-
`
|
|
3079
|
+
`OIMSlotWheel` · `TOIMSlotWheelOptions` · `OIMSlotReleaseWheel` · `TOIMSlotReleaseWheelOptions` ·
|
|
3080
|
+
`oimMintAfterWriteSlotReleaseWheel` · `oimMintAfterIdleSlotReleaseWheel` · `oimMintAfterUnholdSlotReleaseWheel` ·
|
|
3081
|
+
`OIMSlotRefetchWheel` · `TOIMSlotRefetchWheelOptions` · `IOIMSlotRefetchListener`
|
|
3082
|
+
|
|
3083
|
+
*Slot services* — `OIMSlotCollectionService` · `OIMWritableSlotCollectionService` · `TOIMSlotCollectionServiceOptions` ·
|
|
3084
|
+
`createOIMSlotCollectionService` · `OIMSingleSlotService` · `OIMWritableSingleSlotService` · `TOIMSingleSlotServiceOptions` ·
|
|
3085
|
+
`createOIMSingleSlotService` · `OIMColumnSlotService` (the column doors, `service.columnSlotService`) ·
|
|
3086
|
+
`OIMSlotOwnerService` (**type only**) · `TOIMSlotOwnerServiceOptions` · `IOIMSlotContentService` · `IOIMSlotContentWriter` ·
|
|
3087
|
+
`IOIMKeyedSlotCreator` · `IOIMSingleSlotCreator` · `IOIMSlotFilingService` · `TOIMSlotContentServiceKey` ·
|
|
3088
|
+
`TOIMSlotContentServiceSlot` · `TOIMSlotContentServiceSingleSlot` · `TOIMSlotContentServiceContent` ·
|
|
3089
|
+
`TOIMSlotContentServicePatch` · `OIMContentChangeListenerService`
|
|
3201
3090
|
|
|
3202
3091
|
*Content services* — `OIMSlotContentEntityService` · `TOIMSlotContentEntityServiceOptions` ·
|
|
3203
|
-
`createOIMSlotContentEntityService` · `
|
|
3204
|
-
`
|
|
3205
|
-
`
|
|
3206
|
-
`
|
|
3207
|
-
`
|
|
3208
|
-
`
|
|
3092
|
+
`createOIMSlotContentEntityService` · `TOIMEntitySlotOwnerService` · `TOIMEntityContentSlot` · `OIMSlotContentBucketService` ·
|
|
3093
|
+
`OIMSlotContentArrayBucketService` · `OIMSlotContentPositionalArrayBucketService` · `OIMSlotContentSetBucketService` ·
|
|
3094
|
+
`OIMSlotContentSortedArrayBucketService` · `TOIMSlotContentBucketServiceOptions` ·
|
|
3095
|
+
`TOIMSlotContentArrayBucketServiceOptions` · `TOIMSlotContentSortedArrayBucketServiceOptions` · `TOIMBucketSlotOwnerService` ·
|
|
3096
|
+
`TOIMBucketContentSlot` · `OIMSlotContentComputedService` (**type only**) · `TOIMSlotContentComputedServiceOptions` ·
|
|
3097
|
+
`TOIMComputedContentSlot`
|
|
3209
3098
|
|
|
3210
|
-
*Index and computed store slots* — `
|
|
3211
|
-
`
|
|
3212
|
-
`TOIMIndexServiceStoreSlot` · `TOIMSortedComputedSlot` · `TOIMBucketMemoComputedSlot`
|
|
3099
|
+
*Index and computed store slots* — `createOIMSlotCollectionIndexService` · `TOIMSlotCollectionIndexServiceFactoryOptions` ·
|
|
3100
|
+
`TOIMSlotCollectionIndexServiceStoreSlot` · `TOIMSortedComputedSlot` · `TOIMBucketMemoComputedSlot`
|
|
3213
3101
|
|
|
3214
3102
|
*Runtime* — `TOIMChannelFrame` · `TOIMChannelClock` ·
|
|
3215
|
-
`TOIMChannelScheduler` · `TOIMDisposer` · `IOIMErrorPolicy` · `
|
|
3216
|
-
`
|
|
3103
|
+
`TOIMChannelScheduler` · `TOIMDisposer` · `IOIMErrorPolicy` · `OIMLogAndContinueErrorPolicy` ·
|
|
3104
|
+
`TOIMLogAndContinueErrorPolicyOptions` · `OIMThrowAtOnceErrorPolicy` · `OIMChannelQueue` (**type only**) ·
|
|
3217
3105
|
`oimIsAnySlotChangedAfter`
|
|
3218
3106
|
|
|
3219
3107
|
`oimIsAnySlotChangedAfter(slots, revision, epoch): boolean` answers whether any of the slots was
|
|
@@ -3228,49 +3116,49 @@ written after that clock reading — `channelSlot.clock` read earlier.
|
|
|
3228
3116
|
read outside an effect (`useOIMValue` in `@oimdb/react`, `exoBinding` in `@oimdb/exodra`) calls it
|
|
3229
3117
|
on its `sourceComputeds` before `derive`, so the derive never reads a stale computed.
|
|
3230
3118
|
|
|
3231
|
-
*Slots and their owners* — `TOIMSlot` · `TOIMStoreSlot` · `TOIMSingleSlotStoreSlot` ·`IOIMStoreSlotListener` · `
|
|
3232
|
-
`TOIMEntitySlot` · `TOIMColumnSlot` · `TOIMComputedColumnSlot` · `TOIMColumnGroup` · `TOIMColumnReaders` · `
|
|
3233
|
-
`
|
|
3119
|
+
*Slots and their owners* — `TOIMSlot` · `TOIMStoreSlot` · `TOIMSingleSlotStoreSlot` ·`IOIMStoreSlotListener` · `OIMNoStoreSlotListener` · `IOIMSlotSubscriptionListener` · `OIMNoSlotSubscriptionListener` ·`oimIsSlotEmpty` · `oimIsSlotReleased` · `TOIMSlotEditable` · `TOIMKeyedSlot` · `TOIMIndexableSlot` ·
|
|
3120
|
+
`TOIMEntitySlot` · `TOIMColumnSlot` · `TOIMComputedColumnSlot` · `TOIMColumnGroup` · `TOIMColumnReaders` · `OIMColumnSlotOwner` ·
|
|
3121
|
+
`OIMPushColumnSlotOwner` · `OIMPullColumnSlotOwner` · `TOIMColumnSlotOwnerOptions` · `TOIMBucketSlot` ·
|
|
3234
3122
|
`TOIMSameValueGuard` · `OIMSlotOwner` ·
|
|
3235
|
-
`IOIMSlotOwner` · `
|
|
3123
|
+
`IOIMSlotOwner` · `IOIMSlotEmptinessPolicy` ·
|
|
3236
3124
|
`IOIMSlotStamp` · `oimHoldSlots` · `oimUnholdSlotsIfAlive` · `IOIMContentChangeListener`
|
|
3237
3125
|
|
|
3238
3126
|
`oimIsSlotEmpty(slot): boolean` reads the EMPTY bit of `slot.slotFlags`.
|
|
3239
3127
|
`oimIsSlotReleased(slot): boolean` reads its RELEASED bit.
|
|
3240
3128
|
|
|
3241
3129
|
*Release policies* — `IOIMSlotReleasePolicy` ·
|
|
3242
|
-
`
|
|
3243
|
-
`
|
|
3244
|
-
`
|
|
3245
|
-
`
|
|
3130
|
+
`OIMSlotAfterWriteReleasePolicy` · `TOIMSlotAfterWriteReleasePolicyOptions` ·
|
|
3131
|
+
`IOIMSlotReleaseDueFramePolicy` · `OIMSlotReleaseAutoDueFramePolicy` · `OIMSlotReleaseManualDueFramePolicy` ·
|
|
3132
|
+
`OIMSlotAfterIdleReleasePolicy` · `TOIMSlotAfterIdleReleasePolicyOptions` ·
|
|
3133
|
+
`OIMSlotAfterUnholdReleasePolicy` · `TOIMSlotAfterUnholdReleasePolicyOptions` ·
|
|
3134
|
+
`OIMSlotAtUnholdReleasePolicy` · `OIMSlotAtEmptyReleasePolicy` · `OIMSlotNeverReleasePolicy` · `OIMSlotEarliestReleasePolicy` ·
|
|
3246
3135
|
`TOIMTimer` · `oimSliceOfMs` · `OIM_SLICE_LENGTH_MS`
|
|
3247
3136
|
|
|
3248
3137
|
*Entity writers* — `IOIMEntityWriter` · `createOIMEntityWriterInPlace` ·
|
|
3249
|
-
`createOIMEntityWriterReplacing` · `TOIMEntityWriterOptions` · `
|
|
3138
|
+
`createOIMEntityWriterReplacing` · `TOIMEntityWriterOptions` · `TOIMEntityInserter` ·
|
|
3250
3139
|
`oimInsertEntityWithCopy` · `oimInsertEntityWithoutCopy` · `oimInsertEntityWithSanitizedCopy` · `oimPatchEntityColumns` · `oimPatchEntityColumn` · `oimPatchEntityColumnsGuarded` · `oimPatchEntityColumnGuarded` · `oimPutEntityColumns` · `oimPutEntityColumnsGuarded` · `TOIMEntityColumnName` · `TOIMEntityColumnValue`
|
|
3251
3140
|
|
|
3252
|
-
*Buckets* — `
|
|
3253
|
-
`
|
|
3254
|
-
`
|
|
3255
|
-
`OIMBucketArrayMembershipUnique` · `TOIMBucketSlotsSetStore` · `TOIMBucketSlotsArrayStore` ·
|
|
3256
|
-
`TOIMBucketSlotsSortedArrayStore` · `TOIMBucketSlotsArrayUniqueStore` · `OIM_NOTHING_WAS_INSERTED` ·
|
|
3141
|
+
*Buckets* — `OIMBucketCommands` · `TOIMBucketCommandsOptions` · `IOIMBucketCommands` ·
|
|
3142
|
+
`IOIMBucketMemberSlotsArrayService` · `OIMBucketMemberSlotsArrayService` · `OIMBucketUniqueMemberSlotsArrayService` ·
|
|
3143
|
+
`TOIMBucketSlotsSetStore` · `TOIMBucketSlotsArrayStore` · `OIM_NOTHING_WAS_INSERTED` ·
|
|
3257
3144
|
`OIM_NOTHING_WAS_REMOVED` · `OIM_FROZEN_EMPTY_SLOTS` · `OIM_REMOVED_WITHOUT_A_POSITION`
|
|
3258
3145
|
|
|
3259
|
-
*Index services* — `
|
|
3260
|
-
`
|
|
3146
|
+
*Index services* — `OIMSlotCollectionIndexService` · `OIMSlotCollectionSortedArrayIndexService` · `TOIMSlotCollectionIndexServiceOptions` · `TOIMIndexStoreSlot` ·
|
|
3147
|
+
`createOIMSlotCollectionSortedArrayIndexService` · `TOIMIndexKeyOptions` · `TOIMIndexKey` ·
|
|
3261
3148
|
`IOIMIndexKeysService` · `TOIMIndexKeysPositions` · `OIMIndexKeysService` ·
|
|
3262
|
-
`
|
|
3149
|
+
`OIMAppendingIndexKeysService` · `OIMReclaimingIndexKeysService`
|
|
3263
3150
|
|
|
3264
3151
|
*Computed services* — `OIMComputedService` · `TOIMComputedServiceOptions` ·
|
|
3265
|
-
`createOIMComputedService` · `TOIMComputedStoreSlot` · `
|
|
3266
|
-
`
|
|
3267
|
-
`
|
|
3152
|
+
`createOIMComputedService` · `TOIMComputedStoreSlot` · `OIMSortedComputedService` · `TOIMSortedComputedServiceOptions` ·
|
|
3153
|
+
`createOIMSortedComputedService` · `OIMBucketMemoComputedService` · `TOIMBucketMemoComputedServiceOptions` ·
|
|
3154
|
+
`createOIMBucketMemoComputedService` · `OIMSingleComputedService` · `createOIMSingleComputedService` ·
|
|
3155
|
+
`TOIMComputedDerivationOptions` · `TOIMSortColumn` · `TOIMSortableColumnName` · `oimColumnsComparator`
|
|
3268
3156
|
|
|
3269
3157
|
*Stores and keys* — `TOIMStoreKey` · `IOIMSlotStoreService` ·
|
|
3270
|
-
`
|
|
3271
|
-
`
|
|
3158
|
+
`OIMSlotMapStoreService` · `OIMSlotTreeStoreService` ·
|
|
3159
|
+
`OIMSingleSlotStoreService` · `TOIMSingleSlotStore` · `TOIMDefaultSlotStore` ·
|
|
3272
3160
|
`TOIMSlotStoreTree` · `IOIMKeyTreeWalk` · `TOIMCompositeKeyNode` ·
|
|
3273
|
-
`OIMKeyTreeWalk` · `
|
|
3161
|
+
`OIMKeyTreeWalk` · `OIMCompositeKeyTreeWalk` · `OIMScalarKeyTreeWalk`
|
|
3274
3162
|
|
|
3275
3163
|
*Assemblies* — `OIMDB` · `OIMDefaults` · `OIMDefaultValue` · `TOIMFactoryOptions`
|
|
3276
3164
|
|
|
@@ -3288,10 +3176,10 @@ on its `sourceComputeds` before `derive`, so the derive never reads a stale comp
|
|
|
3288
3176
|
|
|
3289
3177
|
### A scalar in a `KEY_TREE_WALK_COMPOSITE` key throws
|
|
3290
3178
|
|
|
3291
|
-
`
|
|
3179
|
+
`OIMSlotTreeStoreService` built with `OIMDefaults.KEY_TREE_WALK_COMPOSITE.getValue()` keys on
|
|
3292
3180
|
`readonly TOIMEntitySlot[]`, so a string or a number in the key throws
|
|
3293
3181
|
a TypeError past a cast, setting `holdCount` on a string. The store for a tuple
|
|
3294
|
-
of scalars is `
|
|
3182
|
+
of scalars is `OIMSlotTreeStoreService` built with
|
|
3295
3183
|
`OIMDefaults.KEY_TREE_WALK_SCALAR.getValue()` —
|
|
3296
3184
|
see **Key stores** above. The fix is the other walk, never a cast.
|
|
3297
3185
|
|
|
@@ -3358,14 +3246,14 @@ The computed SERVICE is the caller's, built once at module scope with `createOIM
|
|
|
3358
3246
|
slot per mount — `computedService.createComputedStoreSlot(db, derive, createSources)` in a `useMemo` on `deps`;
|
|
3359
3247
|
`derive` / `createSources` may be `undefined` when the service has them.
|
|
3360
3248
|
`useOIMSingleComputedValue(computedService, derive, createSources, deps): TValue` is the same for a void-keyed
|
|
3361
|
-
service whose `computedSlotStoreService` is `
|
|
3249
|
+
service whose `computedSlotStoreService` is `OIMSingleSlotStoreService.INSTANCE`, read through
|
|
3362
3250
|
`useOIMComputedValueByKey(computedService.computedCollectionService, computedStoreSlot, undefined)`, so a flush
|
|
3363
3251
|
between render and subscribe is safe.
|
|
3364
3252
|
`useOIMSlotsByKeys(slotCollectionService, storeSlot, keys)` holds the identities its keys name for as long as the
|
|
3365
3253
|
component is mounted (a `holdSlotByKey` per key on commit, the same holds given back on unmount or when the list
|
|
3366
3254
|
moves) and subscribes to nothing; it needs no provider.
|
|
3367
|
-
Singles are not keyed collections: `
|
|
3368
|
-
`
|
|
3255
|
+
Singles are not keyed collections: `createOIMSingleSlotService(db, { slotContentService })` returns an
|
|
3256
|
+
`OIMWritableSingleSlotService` (`getSingleSlot(storeSlot)`, `holdSingleSlot(storeSlot)`), read by
|
|
3369
3257
|
`useOIMSingleEntity(singleSlotService, singleSlotStoreSlot): TEntity | undefined` and
|
|
3370
3258
|
`useOIMSingleBucketSlots(singleSlotService, singleSlotStoreSlot): readonly TOIMEntitySlot<TEntity>[]` — the by-key
|
|
3371
3259
|
mechanics without a key (getSingleSlot on render, holdSingleSlot on commit, resolve-hold given back once the
|
|
@@ -3376,8 +3264,8 @@ re-read the imports rather than trusting this table.
|
|
|
3376
3264
|
|
|
3377
3265
|
| Package | Imports from the core | Imports a name the core does not export? |
|
|
3378
3266
|
|---|---|---|
|
|
3379
|
-
| `@oimdb/persist` | `IOIMChannelMap`, `IOIMContentChangeListener`, `IOIMEntityWriter`, `OIMChannelService`, `
|
|
3380
|
-
| `@oimdb/redux-adapter` | `IOIMChannelMap`, `IOIMContentChangeListener`, `OIMChannelService`, `
|
|
3267
|
+
| `@oimdb/persist` | `IOIMChannelMap`, `IOIMContentChangeListener`, `IOIMEntityWriter`, `OIMChannelService`, `OIMPushColumnSlotOwner`, `OIMContentChangeListenerService`, `OIMEffectService`, `OIMSingleSlotService`, `OIMSlotCollectionService`, `OIMSlotContentBucketService`, `OIMSlotContentEntityService`, `TOIMBucketSlot`, `TOIMChannelClock`, `TOIMChannelSlot`, `TOIMColumnSlot`, `TOIMDefaultSlotStore`, `TOIMDisposer`, `TOIMEffect`, `TOIMEntitySlot`, `TOIMSingleSlotStore`, `TOIMSingleSlotStoreSlot`, `TOIMSlot`, `TOIMStoreKey`, `TOIMStoreSlot`, `oimHoldSlots`, `oimIsAnySlotChangedAfter`, `oimIsSlotReleased`, `oimSameValueZeroGuard`, `oimUnholdSlotsIfAlive` | no |
|
|
3268
|
+
| `@oimdb/redux-adapter` | `IOIMChannelMap`, `IOIMContentChangeListener`, `OIMChannelService`, `OIMPushColumnSlotOwner`, `OIMContentChangeListenerService`, `OIMEffectService`, `OIMSlotCollectionService`, `OIMSlotContentBucketService`, `OIMSlotContentEntityService`, `TOIMBucketSlot`, `TOIMColumnSlot`, `TOIMDefaultSlotStore`, `TOIMDisposer`, `TOIMEffect`, `TOIMEntityColumnName`, `TOIMEntitySlot`, `TOIMStoreKey`, `TOIMStoreSlot` | no |
|
|
3381
3269
|
| `@oimdb/exodra` | `IOIMChannelMap`, `OIMChannelService`, `OIMEffectService`, `OIMSlotContentBucketService`, `OIM_FROZEN_EMPTY_SLOTS`, `TOIMBucketSlot`, `TOIMComputedSlot`, `TOIMDisposer`, `TOIMEffect`, `TOIMEntitySlot`, `TOIMOrderedListCommand`, `TOIMSlot`, `TOIMStoreKey`, `oimOrderedListCommandsOfTransition`, `oimRefreshSourceComputeds`, `oimSameKeySequence` | no |
|
|
3382
3270
|
| `@oimdb/react` | `IOIMChannelMap`, `OIMComputedService`, `OIMDB`, `OIMEffectService`, `OIMSingleSlotService`, `OIMSlotCollectionService`, `OIMSlotContentBucketService`, `OIM_FROZEN_EMPTY_SLOTS`, `TOIMBucketSlot`, `TOIMColumnSlot`, `TOIMComputedSlot`, `TOIMComputedSources`, `TOIMComputedStoreSlot`, `TOIMDisposer`, `TOIMEntityColumnName`, `TOIMEntityColumnValue`, `TOIMEntitySlot`, `TOIMIndexableSlot`, `TOIMKeyedSlot`, `TOIMSingleSlotStore`, `TOIMSlot`, `TOIMStoreKey`, `TOIMStoreSlot`, `oimHoldSlots`, `oimRefreshSourceComputeds`, `oimSameKeySequence`, `oimUnholdSlotsIfAlive` | no |
|
|
3383
3271
|
| `@oimdb/devtools` | `IOIMChannelMap`, `IOIMStoreSlotListener`, `OIMChannelService`, `OIMComputedService`, `OIMDefaults`, `OIMSlotCollectionService`, `TOIMBucketSlot`, `TOIMComputedStoreSlot`, `TOIMDefaultSlotStore`, `TOIMDisposer`, `TOIMEntitySlot`, `TOIMKeyedSlot`, `TOIMStoreKey`, `TOIMStoreSlot` | no |
|
|
@@ -3398,10 +3286,10 @@ Every constructor in the family takes ONE options object.
|
|
|
3398
3286
|
| package | exports |
|
|
3399
3287
|
|---|---|
|
|
3400
3288
|
| `@oimdb/persist` | the engine, plus the key-value backend `OIMPersistKeyValueBackend` and its strategies; error types `TOIMPersistErrorHandler`, `TOIMPersistErrorContext`, `TOIMPersistOperation` and `TOIMPersistErrorReport` (`{ error, persistErrorContext }`, one failure as `onPersistError` receives it or as it lands in the `AggregateError`) |
|
|
3401
|
-
| `@oimdb/persist-memory` | `OIMPersistMemoryBackend`, `OIMPersistMemoryWriteBatch`, `
|
|
3402
|
-
| `@oimdb/persist-json` | `
|
|
3403
|
-
| `@oimdb/persist-idb` | `OIMPersistIndexedDbBackend`, `OIMPersistIndexedDbWriteBatch`, `
|
|
3404
|
-
| `@oimdb/persist-localstorage` | `
|
|
3289
|
+
| `@oimdb/persist-memory` | `OIMPersistMemoryBackend`, `OIMPersistMemoryWriteBatch`, `OIMPersistMemoryRecordsService`, `OIMPersistMemorySnapshotService`, `TOIMPersistMemoryServiceOptions` |
|
|
3290
|
+
| `@oimdb/persist-json` | `OIMPersistJsonMemoryBackend`, `TOIMPersistJsonMemoryBackendOptions`, `TOIMPersistJsonDump`; depends on `@oimdb/persist-memory` |
|
|
3291
|
+
| `@oimdb/persist-idb` | `OIMPersistIndexedDbBackend`, `OIMPersistIndexedDbWriteBatch`, `OIMPersistIndexedDbRecordsService`, `OIMPersistIndexedDbSnapshotService`, `TOIMPersistIndexedDbBackendOptions`, `TOIMPersistIndexedDbRecordsServiceOptions`, `TOIMPersistIndexedDbSnapshotServiceOptions`, `TOIMPersistIndexedDbPrimaryKey`, `TOIMPersistIndexedDbTableRecord` |
|
|
3292
|
+
| `@oimdb/persist-localstorage` | `OIMPersistLocalStorageKeyValueBackend`, `TOIMPersistLocalStorageKeyValueBackendOptions` |
|
|
3405
3293
|
| `@oimdb/persist-async-kv` | `OIMPersistAsyncKVStorage`, `TOIMPersistAsyncKVStorageOptions`, `TOIMPersistAsyncKVMultiStorage` |
|
|
3406
3294
|
|
|
3407
3295
|
### The wiring
|
|
@@ -3412,42 +3300,37 @@ lives in the backend) and what to do on hydrate.
|
|
|
3412
3300
|
|
|
3413
3301
|
```ts
|
|
3414
3302
|
import {
|
|
3415
|
-
OIMPersistEntityWriter,
|
|
3416
|
-
|
|
3303
|
+
OIMPersistEntityWriter, OIMPersistCollectionWriteRecordSource, OIMPersistRecordsResource,
|
|
3304
|
+
OIMPersistMicrotaskScheduler, OIMPersistor,
|
|
3417
3305
|
} from '@oimdb/persist';
|
|
3418
|
-
import { OIMPersistMemoryBackend,
|
|
3306
|
+
import { OIMPersistMemoryBackend, OIMPersistMemoryRecordsService, OIMPersistMemoryWriteBatch } from '@oimdb/persist-memory';
|
|
3419
3307
|
|
|
3420
3308
|
const persistEntityWriter = new OIMPersistEntityWriter<Card, TOIMStoreKey>({
|
|
3421
3309
|
entityWriter: createOIMEntityWriterInPlace(),
|
|
3422
3310
|
});
|
|
3423
|
-
const persistedCardCollectionService =
|
|
3424
|
-
keyOf: card => card.id,
|
|
3425
|
-
entityWriter: persistEntityWriter,
|
|
3426
|
-
});
|
|
3311
|
+
const persistedCardCollectionService = createOIMSlotCollectionService(db, { slotContentService: createOIMSlotContentEntityService<Card>(db, { entityWriter: persistEntityWriter }) });
|
|
3427
3312
|
const persistedCardEntityStoreSlot = persistedCardCollectionService.createStoreSlot(db);
|
|
3428
3313
|
|
|
3429
3314
|
const persistMemoryBackend = new OIMPersistMemoryBackend();
|
|
3430
3315
|
const persistor = new OIMPersistor<OIMPersistMemoryBackend, OIMPersistMemoryWriteBatch>({
|
|
3431
3316
|
persistBackend: persistMemoryBackend,
|
|
3432
|
-
persistScheduler: new
|
|
3317
|
+
persistScheduler: new OIMPersistMicrotaskScheduler(),
|
|
3433
3318
|
onPersistError: (error, persistErrorContext) => {
|
|
3434
3319
|
console.error(persistErrorContext.persistOperation, error);
|
|
3435
3320
|
},
|
|
3436
3321
|
});
|
|
3437
|
-
const cardPersistResourceRecords = persistor.addPersistResource(new
|
|
3438
|
-
persistRecordSource: new
|
|
3322
|
+
const cardPersistResourceRecords = persistor.addPersistResource(new OIMPersistRecordsResource({
|
|
3323
|
+
persistRecordSource: new OIMPersistCollectionWriteRecordSource({
|
|
3439
3324
|
entityCollectionService: persistedCardCollectionService,
|
|
3440
3325
|
entityStoreSlot: persistedCardEntityStoreSlot,
|
|
3441
3326
|
persistEntityWriter,
|
|
3442
3327
|
}),
|
|
3443
|
-
|
|
3328
|
+
persistRecordsService: new OIMPersistMemoryRecordsService<TOIMStoreKey, Card>({ storageKey: 'cards' }),
|
|
3444
3329
|
}));
|
|
3445
3330
|
|
|
3446
3331
|
await persistor.hydrate();
|
|
3447
3332
|
persistor.start();
|
|
3448
|
-
persistedCardCollectionService.
|
|
3449
|
-
persistedCardEntityStoreSlot, { id: 'c1', title: 'Ace', rank: 1, deck: 'spades' },
|
|
3450
|
-
);
|
|
3333
|
+
persistedCardCollectionService.writeSlotContentByKey(persistedCardEntityStoreSlot, 'c1', { id: 'c1', title: 'Ace', rank: 1, deck: 'spades' });
|
|
3451
3334
|
await persistor.persist();
|
|
3452
3335
|
await persistor.unload(cardPersistResourceRecords, ['c1']);
|
|
3453
3336
|
await persistor.load(cardPersistResourceRecords, ['c1']);
|
|
@@ -3457,8 +3340,8 @@ Rules a generator must keep:
|
|
|
3457
3340
|
|
|
3458
3341
|
- Pass both generics of `OIMPersistor<TPersistBackend, TWriteBatch>`: the backend
|
|
3459
3342
|
class and its write batch class (`OIMPersistMemoryWriteBatch`, `OIMPersistIndexedDbWriteBatch`,
|
|
3460
|
-
`OIMPersistKeyValueWriteBatch`; `
|
|
3461
|
-
`
|
|
3343
|
+
`OIMPersistKeyValueWriteBatch`; `OIMPersistJsonMemoryBackend` uses `OIMPersistMemoryWriteBatch`,
|
|
3344
|
+
`OIMPersistLocalStorageKeyValueBackend` uses `OIMPersistKeyValueWriteBatch`).
|
|
3462
3345
|
- Pass the generics of strategies, codecs and `OIMPersistEntityWriter<TEntity, TKey>`
|
|
3463
3346
|
explicitly; their options carry no type to infer them from.
|
|
3464
3347
|
- An entity collection persisted through a collection source is built with the
|
|
@@ -3470,9 +3353,9 @@ Rules a generator must keep:
|
|
|
3470
3353
|
`new OIMPersistEntityWriter({ entityWriter })` wraps the `IOIMEntityWriter` that
|
|
3471
3354
|
really writes, and reports the entity slot of every fill, put, patch, column patch,
|
|
3472
3355
|
column delete and clear that changed something (`subscribeEntitySlotWritten`).
|
|
3473
|
-
- The entity collection service a source takes is any collection service with `getSlots`, `findSlotByKey
|
|
3474
|
-
`
|
|
3475
|
-
(`TOIMPersistEntityCollectionService`)
|
|
3356
|
+
- The entity collection service a source takes is any collection service with `getSlots`, `findSlotByKey`,
|
|
3357
|
+
`writeSlotContentByKey`, `writeInBatch` and a `slotContentService` with `clearSlotContent`
|
|
3358
|
+
(`TOIMPersistEntityCollectionService`): what `createOIMSlotCollectionService` over an entity content service builds.
|
|
3476
3359
|
- A source refuses, by name, a store slot on another channel slot than the one it was given (the bucket source
|
|
3477
3360
|
checks both the entity and the bucket store slot).
|
|
3478
3361
|
- Order: `addPersistResource` every resource, `await persistor.hydrate()`, then
|
|
@@ -3483,29 +3366,29 @@ Rules a generator must keep:
|
|
|
3483
3366
|
| constructor | options |
|
|
3484
3367
|
|---|---|
|
|
3485
3368
|
| `OIMPersistor` | `{ persistBackend, persistScheduler, onPersistError? }` |
|
|
3486
|
-
| `
|
|
3487
|
-
| `
|
|
3488
|
-
| `
|
|
3489
|
-
| `
|
|
3490
|
-
| `
|
|
3369
|
+
| `OIMPersistRecordsResource` | `{ persistRecordSource, persistRecordsService, persistHydrateReconcile? }` |
|
|
3370
|
+
| `OIMPersistSnapshotResource` | `{ persistSnapshotSource, persistSnapshotService, persistCodec, persistHydrateReconcile? }` |
|
|
3371
|
+
| `OIMPersistCollectionWriteRecordSource`, `OIMPersistCollectionChangeWriteRecordSource` | `{ entityCollectionService, entityStoreSlot, persistEntityWriter }` (`TOIMPersistRecordSourceCollectionOptions`) |
|
|
3372
|
+
| `OIMPersistBucketRecordSource` | `{ channelMap, entityCollectionService, entityStoreSlot, slotContentBucketService, bucketSlot }` — `channelMap` is the db, `slotContentBucketService` the bucket collection's `slotContentService` |
|
|
3373
|
+
| `OIMPersistSingleEntitySnapshotSource` | `{ channelMap, singleSlotService, entityStoreSlot }` — a single entity service (`createOIMSingleSlotService` over an entity content service) and one of its store slots (`TOIMSingleSlotStoreSlot`) |
|
|
3491
3374
|
| `OIMPersistEntityWriter` | `{ entityWriter }` |
|
|
3492
|
-
| `
|
|
3493
|
-
| `
|
|
3494
|
-
| `
|
|
3495
|
-
| `
|
|
3375
|
+
| `OIMPersistMicrotaskScheduler` | none |
|
|
3376
|
+
| `OIMPersistFrameScheduler` | `{ channelSlot }` — `db.defaultChannelSlot` |
|
|
3377
|
+
| `OIMPersistIdentityCodec` | none |
|
|
3378
|
+
| `OIMPersistVersionedCodec` | `{ version, migrations, persistCodec }` |
|
|
3496
3379
|
| `OIMPersistMemoryBackend` | none |
|
|
3497
|
-
| `
|
|
3498
|
-
| `
|
|
3380
|
+
| `OIMPersistMemoryRecordsService`, `OIMPersistMemorySnapshotService` | `{ storageKey }` |
|
|
3381
|
+
| `OIMPersistJsonMemoryBackend` | `{ initialPersistJsonDump? }`, the object itself optional |
|
|
3499
3382
|
| `OIMPersistIndexedDbBackend` | `{ databaseName, databaseVersion?, indexedDb? }` |
|
|
3500
|
-
| `
|
|
3501
|
-
| `
|
|
3383
|
+
| `OIMPersistIndexedDbRecordsService` | `{ tableName }` |
|
|
3384
|
+
| `OIMPersistIndexedDbSnapshotService` | `{ tableName, primaryKey }` |
|
|
3502
3385
|
| `OIMPersistKeyValueBackend` | `{ persistKeyValueStorage, persistKeyValueSerializer? }` |
|
|
3503
|
-
| `
|
|
3504
|
-
| `
|
|
3505
|
-
| `
|
|
3506
|
-
| `
|
|
3507
|
-
| `
|
|
3508
|
-
| `
|
|
3386
|
+
| `OIMPersistItemKeyValueStorage` | `{ persistKeyValueItemStorage }` |
|
|
3387
|
+
| `OIMPersistKeyValueEntrySnapshotService` | `{ storageKey }` |
|
|
3388
|
+
| `OIMPersistKeyValuePathSnapshotService` | `{ storageKey, path }` |
|
|
3389
|
+
| `OIMPersistLocalStorageKeyValueBackend` | `{ persistKeyValueItemStorage?, persistKeyValueSerializer? }`, the object itself optional |
|
|
3390
|
+
| `OIMPersistSlotSourceChangeMark` | `{ channelClock, slots }` |
|
|
3391
|
+
| `OIMPersistSubscriptionSourceChangeMark` | `{ subscribeSourceChanged }` |
|
|
3509
3392
|
| `OIMPersistAsyncKVStorage` | `{ persistAsyncKVMultiStorage }` |
|
|
3510
3393
|
|
|
3511
3394
|
`onPersistError(error, persistErrorContext)` receives a `TOIMPersistErrorContext`,
|
|
@@ -3516,10 +3399,10 @@ or collected into the `AggregateError`.
|
|
|
3516
3399
|
|
|
3517
3400
|
### Two resource kinds, and when to pick each
|
|
3518
3401
|
|
|
3519
|
-
| | `
|
|
3402
|
+
| | `OIMPersistRecordsResource` | `OIMPersistSnapshotResource` |
|
|
3520
3403
|
|---|---|---|
|
|
3521
3404
|
| source | a record source: entity store slot or bucket | any snapshot source: entity store slot, bucket or single entity |
|
|
3522
|
-
| strategy | `
|
|
3405
|
+
| strategy | `OIMPersistMemoryRecordsService`, `OIMPersistIndexedDbRecordsService` | `OIMPersistMemorySnapshotService`, `OIMPersistIndexedDbSnapshotService`, `OIMPersistKeyValueEntrySnapshotService`, `OIMPersistKeyValuePathSnapshotService` |
|
|
3523
3406
|
| autosave writes | the delta: one upsert or one deletion per entity slot written since the last drain | the whole snapshot, read from the source and encoded |
|
|
3524
3407
|
| `persist()` writes | every record, replacing what is stored; while any key is unloaded, every in-memory record as an upsert over what is stored, plus the deletions the resource already heard | the whole snapshot |
|
|
3525
3408
|
| codec | none | `persistCodec`, required |
|
|
@@ -3545,10 +3428,10 @@ slot wins: an upsert, not a deletion.
|
|
|
3545
3428
|
|
|
3546
3429
|
| source | reports | scheduler |
|
|
3547
3430
|
|---|---|---|
|
|
3548
|
-
| `
|
|
3549
|
-
| `
|
|
3550
|
-
| `
|
|
3551
|
-
| `
|
|
3431
|
+
| `OIMPersistCollectionWriteRecordSource` | synchronously, at the write, from `OIMPersistEntityWriter` only | `OIMPersistMicrotaskScheduler` |
|
|
3432
|
+
| `OIMPersistCollectionChangeWriteRecordSource` | synchronously, at the write, from `OIMPersistEntityWriter` and from a content-change listener on the entity store slot | `OIMPersistMicrotaskScheduler` |
|
|
3433
|
+
| `OIMPersistBucketRecordSource` | from effects (`OIMEffectService`), when the channel runs its frame | `OIMPersistFrameScheduler({ channelSlot })` |
|
|
3434
|
+
| `OIMPersistSingleEntitySnapshotSource` | from an effect, when the channel runs its frame | `OIMPersistFrameScheduler({ channelSlot })` |
|
|
3552
3435
|
|
|
3553
3436
|
- **Collection** (an entity collection service and one of its store slots): every entity slot of that store slot that holds an entity. Starting
|
|
3554
3437
|
reports nothing; content present before `start()` is written by `persist()` or by
|
|
@@ -3559,8 +3442,8 @@ slot wins: an upsert, not a deletion.
|
|
|
3559
3442
|
|
|
3560
3443
|
| collection source | in-place edit announced with `slotContentService.markEntityChanged(entitySlot, changedColumns?)` | cost while a resource listens | pick it when |
|
|
3561
3444
|
|---|---|---|---|
|
|
3562
|
-
| `
|
|
3563
|
-
| `
|
|
3445
|
+
| `OIMPersistCollectionWriteRecordSource` | NOT persisted: it hears only the writer | none: every write stays on the core fast path | every change goes through `writeSlotContentByKey`, `writeSlotContent`, `updateEntity` and `clearSlotContent` |
|
|
3446
|
+
| `OIMPersistCollectionChangeWriteRecordSource` | persisted: while subscribed it adds a content-change listener of every column to the store slot | EVERY write to that store slot leaves the core fast path, not only `markEntityChanged`: changed-column bookkeeping and the listener loop per write | the app edits entities in place |
|
|
3564
3447
|
- **Bucket**: the entities one bucket slot holds. Get the slot with
|
|
3565
3448
|
`bucketCollectionService.holdSlotByKey(bucketStoreSlot, key)`. The source watches the
|
|
3566
3449
|
bucket slot with one effect and each member entity slot with one effect. An entity
|
|
@@ -3570,7 +3453,7 @@ slot wins: an upsert, not a deletion.
|
|
|
3570
3453
|
hydrate restored.
|
|
3571
3454
|
- **Single entity**: the snapshot is the entity itself (a store slot of a single entity service, read through
|
|
3572
3455
|
`findSingleSlot(entityStoreSlot)`), so it
|
|
3573
|
-
goes only into `
|
|
3456
|
+
goes only into `OIMPersistSnapshotResource`. Its first subscription reports the
|
|
3574
3457
|
current value unless it is the value a hydrate restored. `readSnapshot` throws when
|
|
3575
3458
|
the entity slot holds no value.
|
|
3576
3459
|
|
|
@@ -3583,38 +3466,36 @@ frame, are both written.
|
|
|
3583
3466
|
|
|
3584
3467
|
```ts
|
|
3585
3468
|
import {
|
|
3586
|
-
|
|
3469
|
+
OIMPersistBucketRecordSource, OIMPersistRecordsResource, OIMPersistFrameScheduler, OIMPersistor,
|
|
3587
3470
|
} from '@oimdb/persist';
|
|
3588
|
-
import { OIMPersistMemoryBackend,
|
|
3471
|
+
import { OIMPersistMemoryBackend, OIMPersistMemoryRecordsService, OIMPersistMemoryWriteBatch } from '@oimdb/persist-memory';
|
|
3589
3472
|
|
|
3590
3473
|
type TDeckCardSlot = TOIMEntitySlot<Card, TOIMStoreKey>;
|
|
3591
|
-
const deckCardCollectionService =
|
|
3474
|
+
const deckCardCollectionService = createOIMSlotCollectionService(db, { slotContentService: createOIMSlotContentEntityService<Card>(db) });
|
|
3592
3475
|
const deckCardEntityStoreSlot = deckCardCollectionService.createStoreSlot(db);
|
|
3593
|
-
const deckBucketService =
|
|
3476
|
+
const deckBucketService = createOIMSlotCollectionService(db, { slotContentService: new OIMSlotContentPositionalArrayBucketService<TDeckCardSlot>({ bucketCommands: new OIMBucketCommands({ maxCommandsPerSlot: undefined }) }) });
|
|
3594
3477
|
const deckBucketStoreSlot = deckBucketService.createStoreSlot(db);
|
|
3595
3478
|
const spadesBucketSlot = deckBucketService.holdSlotByKey(deckBucketStoreSlot, 'spades');
|
|
3596
3479
|
|
|
3597
3480
|
const deckPersistor = new OIMPersistor<OIMPersistMemoryBackend, OIMPersistMemoryWriteBatch>({
|
|
3598
3481
|
persistBackend: new OIMPersistMemoryBackend(),
|
|
3599
|
-
persistScheduler: new
|
|
3482
|
+
persistScheduler: new OIMPersistFrameScheduler({ channelSlot: db.defaultChannelSlot }),
|
|
3600
3483
|
});
|
|
3601
|
-
deckPersistor.addPersistResource(new
|
|
3602
|
-
persistRecordSource: new
|
|
3484
|
+
deckPersistor.addPersistResource(new OIMPersistRecordsResource({
|
|
3485
|
+
persistRecordSource: new OIMPersistBucketRecordSource({
|
|
3603
3486
|
channelMap: db,
|
|
3604
3487
|
entityCollectionService: deckCardCollectionService,
|
|
3605
3488
|
entityStoreSlot: deckCardEntityStoreSlot,
|
|
3606
3489
|
slotContentBucketService: deckBucketService.slotContentService,
|
|
3607
3490
|
bucketSlot: spadesBucketSlot,
|
|
3608
3491
|
}),
|
|
3609
|
-
|
|
3492
|
+
persistRecordsService: new OIMPersistMemoryRecordsService<TOIMStoreKey, Card>({ storageKey: 'spades' }),
|
|
3610
3493
|
}));
|
|
3611
3494
|
await deckPersistor.hydrate();
|
|
3612
3495
|
deckPersistor.start();
|
|
3613
3496
|
|
|
3614
|
-
const aceSlot = deckCardCollectionService.
|
|
3615
|
-
|
|
3616
|
-
);
|
|
3617
|
-
deckBucketService.slotContentService.writeBucketMemberSlots(spadesBucketSlot, [aceSlot]);
|
|
3497
|
+
const aceSlot = deckCardCollectionService.writeSlotContentByKey(deckCardEntityStoreSlot, 'c1', { id: 'c1', title: 'Ace', rank: 1, deck: 'spades' });
|
|
3498
|
+
deckBucketService.slotContentService.writeSlotContent(spadesBucketSlot, [aceSlot]);
|
|
3618
3499
|
db.flush();
|
|
3619
3500
|
await deckPersistor.whenIdle();
|
|
3620
3501
|
```
|
|
@@ -3625,10 +3506,10 @@ await deckPersistor.whenIdle();
|
|
|
3625
3506
|
The persistor calls `attachDrain` from its constructor; both shipped schedulers throw
|
|
3626
3507
|
when a second persistor attaches, so construct one scheduler per persistor.
|
|
3627
3508
|
|
|
3628
|
-
- `
|
|
3509
|
+
- `OIMPersistMicrotaskScheduler`: `requestDrain()` queues one microtask; the
|
|
3629
3510
|
requests that follow before it runs are absorbed by it. `stop()` makes a queued
|
|
3630
3511
|
microtask do nothing.
|
|
3631
|
-
- `
|
|
3512
|
+
- `OIMPersistFrameScheduler({ channelSlot })`: while started it subscribes with
|
|
3632
3513
|
`OIMChannelService.INSTANCE.subscribeAfterEachFrame(channelSlot, …)` and drains after a frame only when a drain was
|
|
3633
3514
|
requested since the last one; `stop()` unsubscribes and forgets the request. It
|
|
3634
3515
|
holds no slot and never asks the channel for a frame: it drains only after a frame
|
|
@@ -3637,11 +3518,11 @@ when a second persistor attaches, so construct one scheduler per persistor.
|
|
|
3637
3518
|
**The pairing is a rule.** A write to an entity slot that nobody holds causes no frame
|
|
3638
3519
|
(`OIMChannelService.INSTANCE.writeWithoutFlushCheck` returns at once when `holdCount` is `0`), so a
|
|
3639
3520
|
collection source on the frame scheduler can report changes that no frame ever
|
|
3640
|
-
drains. Pair `
|
|
3641
|
-
`
|
|
3642
|
-
`
|
|
3521
|
+
drains. Pair `OIMPersistCollectionWriteRecordSource` and
|
|
3522
|
+
`OIMPersistCollectionChangeWriteRecordSource` with
|
|
3523
|
+
`OIMPersistMicrotaskScheduler`. The bucket and single-entity sources report from
|
|
3643
3524
|
effects, which cause the frames they run in, so pair them with
|
|
3644
|
-
`
|
|
3525
|
+
`OIMPersistFrameScheduler`. Resources of both groups in one persistor share its
|
|
3645
3526
|
one scheduler; give them two persistors when they need different schedulers.
|
|
3646
3527
|
|
|
3647
3528
|
`whenIdle()` resolves when the work queued at the moment of the call has settled. On
|
|
@@ -3661,8 +3542,8 @@ is queued on the microtask after the write: let one microtask pass before callin
|
|
|
3661
3542
|
| `hydrate()` | reads every resource and writes it into its source; ends the upsert-only mode of an unloaded resource |
|
|
3662
3543
|
| `persist()` | writes every resource in full, started or not, in one write batch; a records resource with unloaded keys writes its in-memory records as upserts over the stored table instead of replacing it, plus the deletions it already heard |
|
|
3663
3544
|
| `clearPersisted()` | deletes every resource's stored data in one write batch; memory is untouched; ends the upsert-only mode of an unloaded resource |
|
|
3664
|
-
| `unload(
|
|
3665
|
-
| `load(
|
|
3545
|
+
| `unload(persistRecordsResource, keys)` | writes the keys' current values plus the resource's pending change in one write batch, repeated until the keys have no unwritten change (unload holds the keys' entity slots while it writes and compares their revision stamps, a slot's stamp moving only on a real write; it also checks the resource's pending set and whether a key's slot was replaced), then removes the keys from memory only |
|
|
3546
|
+
| `load(persistRecordsResource, keys)` | the pair of `unload`: queued after the pending writes, reads only those keys from the backend (`readRecordsOfKeys`) and puts the stored entities back without writing them back; skips a key that holds a value in memory or has a change the resource has not written yet; the keys stop counting as unloaded |
|
|
3666
3547
|
| `whenIdle()` | resolves when the queued work settles; never rejects |
|
|
3667
3548
|
|
|
3668
3549
|
Every promise-returning call and every autosave runs on one ordered chain, one at a
|
|
@@ -3713,7 +3594,7 @@ What the source does with it:
|
|
|
3713
3594
|
name; the store slot becomes exactly the stored content;
|
|
3714
3595
|
- bucket: upserts every record into the entity store slot and sets the bucket's
|
|
3715
3596
|
members to exactly the restored entities;
|
|
3716
|
-
- single entity: `singleSlotService.
|
|
3597
|
+
- single entity: `singleSlotService.writeSingleSlotContent(entityStoreSlot, entity)`.
|
|
3717
3598
|
|
|
3718
3599
|
**Refusal.** If the source changes while the backend read is in flight and the
|
|
3719
3600
|
resource has no `persistHydrateReconcile`, hydrate throws instead of applying, because
|
|
@@ -3721,10 +3602,10 @@ applying would revert that change. The source keeps its newer state; the error g
|
|
|
3721
3602
|
to `onPersistError` with `'hydrate'`, or into the `AggregateError`. Before the read
|
|
3722
3603
|
the resource calls `persistSnapshotSource.markSourceChanges()`, which returns an
|
|
3723
3604
|
`IOIMPersistSourceChangeMark` (`isSourceChangedSinceMark()`, `dispose()`): the
|
|
3724
|
-
single-entity and bucket sources return an `
|
|
3605
|
+
single-entity and bucket sources return an `OIMPersistSlotSourceChangeMark`
|
|
3725
3606
|
that holds the slots and compares their revision stamps (`changedAtRevision`, `changedAtEpoch`) with the
|
|
3726
3607
|
channel clock reading taken at the mark (`oimIsAnySlotChangedAfter`), the
|
|
3727
|
-
collection sources an `
|
|
3608
|
+
collection sources an `OIMPersistSubscriptionSourceChangeMark` whose flag their
|
|
3728
3609
|
own report sets. A change made during the read is seen even when no frame runs, and
|
|
3729
3610
|
the guard runs whether or not the persistor is started.
|
|
3730
3611
|
|
|
@@ -3748,7 +3629,7 @@ const answerReconcile = oimReconcileByKey<TOIMStoreKey, Card>(
|
|
|
3748
3629
|
|
|
3749
3630
|
### unload, load and clearPersisted
|
|
3750
3631
|
|
|
3751
|
-
`persistor.unload(
|
|
3632
|
+
`persistor.unload(persistRecordsResource, keys)` takes an `OIMPersistRecordsResource`
|
|
3752
3633
|
only. It first drains the persistor's dirty resources onto the chain, then, in its
|
|
3753
3634
|
own turn, writes in one write batch that resource's pending change and the current
|
|
3754
3635
|
value of every unloaded key (`persistRecordSource.readRecordsDelta(persistRecordSource.findEntitySlotsByKeys(keys))`), so
|
|
@@ -3776,11 +3657,11 @@ stay on the backend. A deletion it never heard is not written in that mode.
|
|
|
3776
3657
|
`hydrate()` and `clearPersisted()` end that mode, and so does a `load` of every
|
|
3777
3658
|
unloaded key.
|
|
3778
3659
|
|
|
3779
|
-
`persistor.load(
|
|
3780
|
-
`
|
|
3660
|
+
`persistor.load(persistRecordsResource, keys)` is the pair of `unload` and takes an
|
|
3661
|
+
`OIMPersistRecordsResource` only (a key-value backend has no records strategy, so a
|
|
3781
3662
|
snapshot resource has no `load`). It drains the dirty resources onto the chain and
|
|
3782
3663
|
runs after those writes. In its turn it reads only those keys through
|
|
3783
|
-
`
|
|
3664
|
+
`persistRecordsService.readRecordsOfKeys(persistBackend, keys)`: on IndexedDB one
|
|
3784
3665
|
`readonly` transaction with one `get` per key, on memory a lookup of each key in the
|
|
3785
3666
|
stored map; a key the backend does not hold is left out. It skips every key that holds
|
|
3786
3667
|
a value in memory or has a change the resource has not written yet (pending or in a
|
|
@@ -3820,10 +3701,10 @@ required `persistCodec`, an `IOIMPersistCodec<TSourceSnapshot, TPersistedSnapsho
|
|
|
3820
3701
|
(`encode`, `decode`). A records resource has no codec: it stores entities as the
|
|
3821
3702
|
source holds them.
|
|
3822
3703
|
|
|
3823
|
-
- `new
|
|
3824
|
-
- `new
|
|
3704
|
+
- `new OIMPersistIdentityCodec<TSnapshot>()`: passes the snapshot through.
|
|
3705
|
+
- `new OIMPersistVersionedCodec<TSourceSnapshot, TPersistedSnapshot>({ version, migrations, persistCodec })`:
|
|
3825
3706
|
stores a `TOIMPersistVersionedShape`, `{ version, data }`, where `data` is the
|
|
3826
|
-
inner `persistCodec`'s encoding (required; use `
|
|
3707
|
+
inner `persistCodec`'s encoding (required; use `OIMPersistIdentityCodec` when
|
|
3827
3708
|
nothing transforms). `migrations` is a `Record<number, (data: unknown) => unknown>`
|
|
3828
3709
|
keyed by the version each migration produces. On decode it runs, ascending, every
|
|
3829
3710
|
migration whose key is above the stored `version` and at most the current one,
|
|
@@ -3833,21 +3714,21 @@ source holds them.
|
|
|
3833
3714
|
|
|
3834
3715
|
```ts
|
|
3835
3716
|
import {
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3717
|
+
OIMPersistIdentityCodec, OIMPersistVersionedCodec, OIMPersistKeyValueBackend, OIMPersistKeyValueEntrySnapshotService,
|
|
3718
|
+
OIMPersistItemKeyValueStorage, OIMPersistKeyValueWriteBatch, OIMPersistSnapshotResource,
|
|
3719
|
+
OIMPersistFrameScheduler, OIMPersistSingleEntitySnapshotSource, OIMPersistor,
|
|
3839
3720
|
} from '@oimdb/persist';
|
|
3840
3721
|
import type { TOIMPersistVersionedShape } from '@oimdb/persist';
|
|
3841
3722
|
|
|
3842
3723
|
type TSettings = { theme: 'light' | 'dark'; density: 'compact' | 'comfortable' };
|
|
3843
3724
|
|
|
3844
|
-
const settingsSingleEntityService =
|
|
3725
|
+
const settingsSingleEntityService = createOIMSingleSlotService(db, { slotContentService: createOIMSlotContentEntityService<TSettings>(db) });
|
|
3845
3726
|
const settingsEntityStoreSlot = settingsSingleEntityService.createStoreSlot(db);
|
|
3846
|
-
settingsSingleEntityService.
|
|
3727
|
+
settingsSingleEntityService.writeSingleSlotContent(settingsEntityStoreSlot, { theme: 'light', density: 'compact' });
|
|
3847
3728
|
const itemByStorageKey = new Map<string, string>();
|
|
3848
3729
|
const settingsPersistor = new OIMPersistor<OIMPersistKeyValueBackend, OIMPersistKeyValueWriteBatch>({
|
|
3849
3730
|
persistBackend: new OIMPersistKeyValueBackend({
|
|
3850
|
-
persistKeyValueStorage: new
|
|
3731
|
+
persistKeyValueStorage: new OIMPersistItemKeyValueStorage({
|
|
3851
3732
|
persistKeyValueItemStorage: {
|
|
3852
3733
|
getItem: storageKey => itemByStorageKey.get(storageKey) ?? null,
|
|
3853
3734
|
setItem: (storageKey, item) => { itemByStorageKey.set(storageKey, item); },
|
|
@@ -3855,17 +3736,17 @@ const settingsPersistor = new OIMPersistor<OIMPersistKeyValueBackend, OIMPersist
|
|
|
3855
3736
|
},
|
|
3856
3737
|
}),
|
|
3857
3738
|
}),
|
|
3858
|
-
persistScheduler: new
|
|
3739
|
+
persistScheduler: new OIMPersistFrameScheduler({ channelSlot: db.defaultChannelSlot }),
|
|
3859
3740
|
});
|
|
3860
|
-
settingsPersistor.addPersistResource(new
|
|
3861
|
-
persistSnapshotSource: new
|
|
3741
|
+
settingsPersistor.addPersistResource(new OIMPersistSnapshotResource({
|
|
3742
|
+
persistSnapshotSource: new OIMPersistSingleEntitySnapshotSource({
|
|
3862
3743
|
channelMap: db, singleSlotService: settingsSingleEntityService, entityStoreSlot: settingsEntityStoreSlot,
|
|
3863
3744
|
}),
|
|
3864
|
-
|
|
3865
|
-
persistCodec: new
|
|
3745
|
+
persistSnapshotService: new OIMPersistKeyValueEntrySnapshotService<TOIMPersistVersionedShape>({ storageKey: 'settings' }),
|
|
3746
|
+
persistCodec: new OIMPersistVersionedCodec<TSettings, TSettings>({
|
|
3866
3747
|
version: 2,
|
|
3867
3748
|
migrations: { 2: data => ({ density: 'comfortable', ...(data as object) }) },
|
|
3868
|
-
persistCodec: new
|
|
3749
|
+
persistCodec: new OIMPersistIdentityCodec<TSettings>(),
|
|
3869
3750
|
}),
|
|
3870
3751
|
}));
|
|
3871
3752
|
await settingsPersistor.hydrate();
|
|
@@ -3882,34 +3763,34 @@ await settingsPersistor.whenIdle();
|
|
|
3882
3763
|
|
|
3883
3764
|
**Memory** (`@oimdb/persist-memory`). `new OIMPersistMemoryBackend()`. Snapshot values
|
|
3884
3765
|
and records live in two separate maps, so a snapshot and a records resource may share
|
|
3885
|
-
a `storageKey`. `
|
|
3766
|
+
a `storageKey`. `OIMPersistMemoryRecordsService<TKey, TEntity>({ storageKey })` keeps one
|
|
3886
3767
|
`Map` of key to entity per `storageKey`: autosave sets and deletes keys, `persist()`
|
|
3887
|
-
replaces the map (while the resource has unloaded keys, sets keys and deletes only the deletions the resource already heard), `clearPersisted()` deletes it, and a `load` looks each of its keys up in the map through `readRecordsOfKeys`. `
|
|
3768
|
+
replaces the map (while the resource has unloaded keys, sets keys and deletes only the deletions the resource already heard), `clearPersisted()` deletes it, and a `load` looks each of its keys up in the map through `readRecordsOfKeys`. `OIMPersistMemorySnapshotService<TSnapshot>({ storageKey })`
|
|
3888
3769
|
keeps one value. `readRecords(storageKey)` and `readSnapshotValue(storageKey)` read
|
|
3889
3770
|
what was committed. `OIMPersistMemoryWriteBatch` queues every change and applies them in
|
|
3890
3771
|
order on `commit()`.
|
|
3891
3772
|
|
|
3892
3773
|
**JSON** (`@oimdb/persist-json`, depends on `@oimdb/persist-memory`).
|
|
3893
|
-
`
|
|
3774
|
+
`OIMPersistJsonMemoryBackend` extends `OIMPersistMemoryBackend` and takes the memory
|
|
3894
3775
|
strategies. `dehydrate()` returns a `TOIMPersistJsonDump`,
|
|
3895
3776
|
`{ snapshotValues: Record<storageKey, value>, recordsByStorageKey: Record<storageKey, { key, entity }[]> }`;
|
|
3896
|
-
`new
|
|
3777
|
+
`new OIMPersistJsonMemoryBackend({ initialPersistJsonDump })` writes such a dump straight into
|
|
3897
3778
|
its maps. The SSR flow: on the server, `await persistor.persist()` and then
|
|
3898
|
-
`JSON.stringify(
|
|
3899
|
-
`new
|
|
3779
|
+
`JSON.stringify(persistJsonMemoryBackend.dehydrate())`; on the client,
|
|
3780
|
+
`new OIMPersistJsonMemoryBackend({ initialPersistJsonDump: JSON.parse(jsonText) })`, register
|
|
3900
3781
|
the same resources under the same `storageKey`s, `await persistor.hydrate()`. To merge
|
|
3901
3782
|
a durable cache over the server's content, hydrate the JSON persistor first, then the
|
|
3902
3783
|
durable persistor with `persistHydrateReconcile`, then `start()` the durable one.
|
|
3903
3784
|
|
|
3904
3785
|
**IndexedDB** (`@oimdb/persist-idb`). `new OIMPersistIndexedDbBackend({ databaseName, databaseVersion?, indexedDb? })`;
|
|
3905
3786
|
`indexedDb` defaults to `globalThis.indexedDB` and the constructor throws without
|
|
3906
|
-
either. `
|
|
3787
|
+
either. `OIMPersistIndexedDbRecordsService<TKey, TEntity>({ tableName })` stores one value
|
|
3907
3788
|
per entity key in an object store: autosave puts and deletes per key, `persist()`
|
|
3908
3789
|
clears the table and puts every entity (while the resource has unloaded keys, only
|
|
3909
3790
|
puts plus a delete per deletion the resource already heard), `clearPersisted()` clears it,
|
|
3910
3791
|
and a `load` reads its keys through `readRecordsOfKeys` in one `readonly` transaction,
|
|
3911
3792
|
one `get` per key.
|
|
3912
|
-
`
|
|
3793
|
+
`OIMPersistIndexedDbSnapshotService<TSnapshot>({ tableName, primaryKey })` stores one value
|
|
3913
3794
|
at `primaryKey`. One commit is one `readwrite` transaction over every table the batch
|
|
3914
3795
|
touches. A commit opens the database and creates missing tables by a version upgrade
|
|
3915
3796
|
(retried when another connection upgrades first, up to five attempts; an upgrade
|
|
@@ -3921,7 +3802,7 @@ sorted property names, and is read back as that string.
|
|
|
3921
3802
|
**Key-value** (`@oimdb/persist`). `new OIMPersistKeyValueBackend({ persistKeyValueStorage, persistKeyValueSerializer? })`
|
|
3922
3803
|
stores serialized strings under string keys. `persistKeyValueStorage` is an
|
|
3923
3804
|
`IOIMPersistKeyValueStorage` (`readItems(storageKeys)`, `writeItems(itemByStorageKey)`,
|
|
3924
|
-
`removeItems(storageKeys)`); `
|
|
3805
|
+
`removeItems(storageKeys)`); `OIMPersistItemKeyValueStorage({ persistKeyValueItemStorage })`
|
|
3925
3806
|
adapts any `TOIMPersistKeyValueItemStorage` (`getItem`, `setItem`, `removeItem`,
|
|
3926
3807
|
synchronous or returning promises) with one call per key. The serializer is a
|
|
3927
3808
|
`TOIMPersistKeyValueSerializer` (`serialize`, `deserialize`) and defaults to
|
|
@@ -3929,15 +3810,15 @@ synchronous or returning promises) with one call per key. The serializer is a
|
|
|
3929
3810
|
|
|
3930
3811
|
| strategy | stored as |
|
|
3931
3812
|
|---|---|
|
|
3932
|
-
| `
|
|
3933
|
-
| `
|
|
3813
|
+
| `OIMPersistKeyValueEntrySnapshotService<TSnapshot>({ storageKey })` | the whole snapshot under `storageKey` |
|
|
3814
|
+
| `OIMPersistKeyValuePathSnapshotService<TSnapshot>({ storageKey, path })` | the snapshot at `path` (a `string[]`) inside an object under `storageKey`; several resources may share the key; the constructor throws on an empty `path` |
|
|
3934
3815
|
|
|
3935
3816
|
`OIMPersistKeyValueWriteBatch` commits with at most one `readItems` (keys with path
|
|
3936
3817
|
writes or path deletions and no whole-value write in the batch), one `writeItems` and
|
|
3937
3818
|
one `removeItems`; it serializes every value before writing any. Path segments are
|
|
3938
3819
|
own properties, so a stored `__proto__` is data.
|
|
3939
3820
|
|
|
3940
|
-
- **localStorage** (`@oimdb/persist-localstorage`): `
|
|
3821
|
+
- **localStorage** (`@oimdb/persist-localstorage`): `OIMPersistLocalStorageKeyValueBackend`
|
|
3941
3822
|
extends `OIMPersistKeyValueBackend` over a `TOIMPersistKeyValueItemStorage`
|
|
3942
3823
|
(`getItem`, `setItem`, `removeItem`) given as `persistKeyValueItemStorage`, which
|
|
3943
3824
|
defaults to `globalThis.localStorage`; the constructor throws without either. One `setItem` per written key.
|
|
@@ -3956,10 +3837,10 @@ own properties, so a stored `__proto__` is data.
|
|
|
3956
3837
|
batch keeps them in: `addWriteBatchChange(change)`, `hasWriteBatchChanges`,
|
|
3957
3838
|
`applyWriteBatchChanges(target)`. `oimWritePersistRecordsDelta(delta, putRecord, deleteRecord)`
|
|
3958
3839
|
walks a `TOIMPersistRecordsDelta` in the one order every backend uses: upserts, then deletions.
|
|
3959
|
-
- Snapshot strategy: `
|
|
3840
|
+
- Snapshot strategy: `IOIMPersistSnapshotService<TPersistBackend, TWriteBatch, TSnapshot>`
|
|
3960
3841
|
with `readSnapshot(persistBackend)`, `writeSnapshot(writeBatch, snapshot)`,
|
|
3961
3842
|
`deleteSnapshot(writeBatch)`. Records strategy:
|
|
3962
|
-
`
|
|
3843
|
+
`IOIMPersistRecordsService<TPersistBackend, TWriteBatch, TKey, TEntity>` with
|
|
3963
3844
|
`readRecords(persistBackend)`, `readRecordsOfKeys(persistBackend, keys)`,
|
|
3964
3845
|
`writeRecords(writeBatch, persistRecords)`,
|
|
3965
3846
|
`writeRecordsDelta(writeBatch, persistRecordsDelta)` (a `TOIMPersistRecordsDelta`,
|
|
@@ -3973,15 +3854,15 @@ own properties, so a stored `__proto__` is data.
|
|
|
3973
3854
|
`loadRecords(persistRecords)`, `unloadKeys(keys)`.
|
|
3974
3855
|
`markSourceChanges()` is required and returns an `IOIMPersistSourceChangeMark`
|
|
3975
3856
|
(`isSourceChangedSinceMark()`, `dispose()`); build it with
|
|
3976
|
-
`new
|
|
3977
|
-
`new
|
|
3857
|
+
`new OIMPersistSlotSourceChangeMark({ channelClock, slots })` or
|
|
3858
|
+
`new OIMPersistSubscriptionSourceChangeMark({ subscribeSourceChanged })`.
|
|
3978
3859
|
It must accept more than one subscription, each with its own `TOIMDisposer`.
|
|
3979
3860
|
- Scheduler: `IOIMPersistScheduler`, above.
|
|
3980
3861
|
|
|
3981
3862
|
### Limits
|
|
3982
3863
|
|
|
3983
3864
|
- **No key-value records strategy.** Over `OIMPersistKeyValueBackend` (localStorage,
|
|
3984
|
-
async KV) an entity store slot or a bucket goes through `
|
|
3865
|
+
async KV) an entity store slot or a bucket goes through `OIMPersistSnapshotResource`: every
|
|
3985
3866
|
autosave walks every entity slot of the source and serializes the whole snapshot
|
|
3986
3867
|
under one key.
|
|
3987
3868
|
- **A bucket membership change walks the bucket.** Each change of the bucket slot
|
|
@@ -3991,7 +3872,7 @@ own properties, so a stored `__proto__` is data.
|
|
|
3991
3872
|
`createOIMEntityWriterInPlace()` the stored entity is the live entity object, so an
|
|
3992
3873
|
in-place write moves the stored value before any commit, and `dehydrate()` returns
|
|
3993
3874
|
the live objects. Use `createOIMEntityWriterReplacing()` with
|
|
3994
|
-
`
|
|
3875
|
+
`entityInserter: oimInsertEntityWithCopy` where the stored value must stay
|
|
3995
3876
|
what was committed, and serialize a dump at once.
|
|
3996
3877
|
- **Hydrate without a reconcile replaces.** The collection source deletes every
|
|
3997
3878
|
entity the stored records do not name, and an existing but empty records table
|
|
@@ -4080,7 +3961,7 @@ Who decided the order is the difference, and the core already forks on it.
|
|
|
4080
3961
|
|
|
4081
3962
|
| | `exoDerivedList(channelMap, computedSlot, render, maxCommandsPerSlot?)` | `exoPositionalList(channelMap, slotContentBucketService, bucketSlot, render)` |
|
|
4082
3963
|
|---|---|---|
|
|
4083
|
-
| takes | a `TOIMComputedSlot<readonly TOIMEntitySlot[]>` | a bucket content service built with an `OIMBucketCommands`
|
|
3964
|
+
| takes | a `TOIMComputedSlot<readonly TOIMEntitySlot[]>` | a bucket content service built with an `OIMBucketCommands` and one of its bucket slots, from any of its store slots |
|
|
4084
3965
|
| the script | **derived**, by `oimOrderedListCommandsOfTransition` | **recorded**, by `OIMBucketCommands`, read inside the frame |
|
|
4085
3966
|
| per changed frame | one diff: two passes plus an LIS pass, `common − LIS` moves | one pass over the frame's own script |
|
|
4086
3967
|
|
|
@@ -4131,8 +4012,8 @@ them.
|
|
|
4131
4012
|
|
|
4132
4013
|
The one quantity that needs no measurement, because it is arithmetic rather than
|
|
4133
4014
|
a reading: emptying a bucket one slot at a time on an array-driven bucket costs
|
|
4134
|
-
n(n-1)/2 element moves — **499 500** for a thousand — which is why a bucket content service's `
|
|
4135
|
-
and `
|
|
4015
|
+
n(n-1)/2 element moves — **499 500** for a thousand — which is why a bucket content service's `writeSlotContent`
|
|
4016
|
+
and `clearSlotContent` go through one `drainSlots`. Counted, not timed, in
|
|
4136
4017
|
`packages/core/src/engine/bucket/array/tests/everyone-out-at-once-and-not-one-at-a-time.test.ts`, which
|
|
4137
4018
|
also pins `drainSlots` at zero element writes.
|
|
4138
4019
|
|