@oimdb/react 2.2.0 → 3.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/dist/index.cjs CHANGED
@@ -20,760 +20,377 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- OIMCollectionsContext: () => OIMCollectionsContext,
24
- OIMCollectionsProvider: () => OIMCollectionsProvider,
25
- createOIMCollectionsContext: () => createOIMCollectionsContext,
26
- useOIMCollectionsContext: () => useOIMCollectionsContext,
27
- useSelectEntitiesByCompositeIndexKeyArrayBased: () => useSelectEntitiesByCompositeIndexKeyArrayBased,
28
- useSelectEntitiesByCompositeIndexKeySetBased: () => useSelectEntitiesByCompositeIndexKeySetBased,
29
- useSelectEntitiesByGlobalIndexArrayBased: () => useSelectEntitiesByGlobalIndexArrayBased,
30
- useSelectEntitiesByGlobalIndexSetBased: () => useSelectEntitiesByGlobalIndexSetBased,
31
- useSelectEntitiesByIndexKeyArrayBased: () => useSelectEntitiesByIndexKeyArrayBased,
32
- useSelectEntitiesByIndexKeySetBased: () => useSelectEntitiesByIndexKeySetBased,
33
- useSelectEntitiesByIndexKeysArrayBased: () => useSelectEntitiesByIndexKeysArrayBased,
34
- useSelectEntitiesByIndexKeysSetBased: () => useSelectEntitiesByIndexKeysSetBased,
35
- useSelectEntitiesByPks: () => useSelectEntitiesByPks,
36
- useSelectEntityByPk: () => useSelectEntityByPk,
37
- useSelectEntityByPkSignal: () => useSelectEntityByPkSignal,
38
- useSelectPksByCompositeIndexKeyArrayBased: () => useSelectPksByCompositeIndexKeyArrayBased,
39
- useSelectPksByCompositeIndexKeySetBased: () => useSelectPksByCompositeIndexKeySetBased,
40
- useSelectPksByGlobalIndexArrayBased: () => useSelectPksByGlobalIndexArrayBased,
41
- useSelectPksByGlobalIndexArrayBasedSignal: () => useSelectPksByGlobalIndexArrayBasedSignal,
42
- useSelectPksByGlobalIndexSetBased: () => useSelectPksByGlobalIndexSetBased,
43
- useSelectPksByGlobalIndexSetBasedSignal: () => useSelectPksByGlobalIndexSetBasedSignal,
44
- useSelectPksByIndexKeyArrayBased: () => useSelectPksByIndexKeyArrayBased,
45
- useSelectPksByIndexKeyArrayBasedSignal: () => useSelectPksByIndexKeyArrayBasedSignal,
46
- useSelectPksByIndexKeySetBased: () => useSelectPksByIndexKeySetBased,
47
- useSelectPksByIndexKeySetBasedSignal: () => useSelectPksByIndexKeySetBasedSignal,
48
- useSelectPksByIndexKeysArrayBased: () => useSelectPksByIndexKeysArrayBased,
49
- useSelectPksByIndexKeysSetBased: () => useSelectPksByIndexKeysSetBased,
50
- useSelectValueByObjectKey: () => useSelectValueByObjectKey,
51
- useSelectValuesByObjectKeys: () => useSelectValuesByObjectKeys
23
+ OIMDBContext: () => OIMDBContext,
24
+ OIMDBProvider: () => OIMDBProvider,
25
+ useOIMBucketSlots: () => useOIMBucketSlots,
26
+ useOIMBucketSlotsByKey: () => useOIMBucketSlotsByKey,
27
+ useOIMComputedCollection: () => useOIMComputedCollection,
28
+ useOIMComputedValue: () => useOIMComputedValue,
29
+ useOIMComputedValueByKey: () => useOIMComputedValueByKey,
30
+ useOIMDB: () => useOIMDB,
31
+ useOIMEntity: () => useOIMEntity,
32
+ useOIMField: () => useOIMField,
33
+ useOIMSingleBucketSlots: () => useOIMSingleBucketSlots,
34
+ useOIMSingleComputedValue: () => useOIMSingleComputedValue,
35
+ useOIMSingleEntity: () => useOIMSingleEntity,
36
+ useOIMSlotsByKeys: () => useOIMSlotsByKeys,
37
+ useOIMValue: () => useOIMValue
52
38
  });
53
39
  module.exports = __toCommonJS(index_exports);
54
40
 
55
- // src/hooks/index.ts
56
- var import_react3 = require("react");
57
- var import_react4 = require("react");
58
-
59
- // src/hooks/global.ts
41
+ // src/OIMDBContext.ts
60
42
  var import_react = require("react");
61
- var useSelectPksByGlobalIndexArrayBased = (reactiveIndex) => {
62
- const snapshotValueRef = (0, import_react.useRef)();
63
- const subscribe = (0, import_react.useMemo)(() => {
64
- snapshotValueRef.current = reactiveIndex.getPks();
65
- return (onStoreChange) => {
66
- return reactiveIndex.subscribe(() => {
67
- snapshotValueRef.current = reactiveIndex.getPks();
68
- onStoreChange();
69
- });
70
- };
71
- }, [reactiveIndex]);
72
- const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
73
- return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
74
- };
75
- var useSelectPksByGlobalIndexSetBased = (reactiveIndex) => {
76
- const snapshotValueRef = (0, import_react.useRef)();
77
- const subscribe = (0, import_react.useMemo)(() => {
78
- snapshotValueRef.current = reactiveIndex.getPks();
79
- return (onStoreChange) => {
80
- return reactiveIndex.subscribe(() => {
81
- snapshotValueRef.current = reactiveIndex.getPks();
82
- onStoreChange();
83
- });
84
- };
85
- }, [reactiveIndex]);
86
- const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
87
- return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
88
- };
89
- var useSelectEntitiesByGlobalIndexArrayBased = (reactiveCollection, reactiveIndex) => {
90
- const snapshotRef = (0, import_react.useRef)();
91
- const subscribe = (0, import_react.useMemo)(() => {
92
- const readPks = () => reactiveIndex.getPks();
93
- const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
94
- snapshotRef.current = readSnapshot();
95
- return (onStoreChange) => {
96
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
97
- readPks(),
98
- () => {
99
- snapshotRef.current = readSnapshot();
100
- onStoreChange();
101
- }
102
- );
103
- const resubscribeCollection = () => {
104
- unsubscribeFromCollection();
105
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
106
- readPks(),
107
- () => {
108
- snapshotRef.current = readSnapshot();
109
- onStoreChange();
110
- }
111
- );
112
- };
113
- const unsubscribeFromIndex = reactiveIndex.subscribe(() => {
114
- resubscribeCollection();
115
- snapshotRef.current = readSnapshot();
116
- onStoreChange();
117
- });
118
- return () => {
119
- unsubscribeFromIndex();
120
- unsubscribeFromCollection();
121
- };
122
- };
123
- }, [reactiveCollection, reactiveIndex]);
124
- const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
125
- return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
126
- };
127
- var useSelectEntitiesByGlobalIndexSetBased = (reactiveCollection, reactiveIndex) => {
128
- const snapshotRef = (0, import_react.useRef)();
129
- const subscribe = (0, import_react.useMemo)(() => {
130
- const readPks = () => Array.from(reactiveIndex.getPks());
131
- const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
132
- snapshotRef.current = readSnapshot();
133
- return (onStoreChange) => {
134
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
135
- readPks(),
136
- () => {
137
- snapshotRef.current = readSnapshot();
138
- onStoreChange();
139
- }
140
- );
141
- const resubscribeCollection = () => {
142
- unsubscribeFromCollection();
143
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
144
- readPks(),
145
- () => {
146
- snapshotRef.current = readSnapshot();
147
- onStoreChange();
148
- }
149
- );
150
- };
151
- const unsubscribeFromIndex = reactiveIndex.subscribe(() => {
152
- resubscribeCollection();
153
- snapshotRef.current = readSnapshot();
154
- onStoreChange();
155
- });
156
- return () => {
157
- unsubscribeFromIndex();
158
- unsubscribeFromCollection();
159
- };
160
- };
161
- }, [reactiveCollection, reactiveIndex]);
162
- const getSnapshot = (0, import_react.useMemo)(() => () => snapshotRef.current, []);
163
- return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
164
- };
43
+ var OIMDBContext = (0, import_react.createContext)(void 0);
44
+
45
+ // src/OIMDBProvider.tsx
46
+ var import_jsx_runtime = require("react/jsx-runtime");
47
+ function OIMDBProvider({ db, children }) {
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OIMDBContext.Provider, { value: db, children });
49
+ }
165
50
 
166
- // src/hooks/signal.ts
51
+ // src/useOIMDB.ts
167
52
  var import_react2 = require("react");
168
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_react2.useLayoutEffect : import_react2.useEffect;
169
- function useForceUpdate() {
170
- const [, force] = (0, import_react2.useReducer)((c) => c + 1 | 0, 0);
171
- return force;
53
+ function useOIMDB() {
54
+ const db = (0, import_react2.useContext)(OIMDBContext);
55
+ if (db === void 0) {
56
+ throw new Error(
57
+ "useOIMDB: no <OIMDBProvider db={...}> above this component. The hooks that build a computed for the component take the database from it."
58
+ );
59
+ }
60
+ return db;
172
61
  }
173
- var useSelectEntityByPkSignal = (reactiveCollection, pk) => {
174
- const force = useForceUpdate();
175
- useIsomorphicLayoutEffect(
176
- () => reactiveCollection.subscribeOnKey(pk, force),
177
- [reactiveCollection, pk]
178
- );
179
- return reactiveCollection.getOneByPk(pk);
180
- };
181
- var useSelectPksByIndexKeyArrayBasedSignal = (reactiveIndex, key) => {
182
- const force = useForceUpdate();
183
- useIsomorphicLayoutEffect(
184
- () => reactiveIndex.subscribeOnKey(key, force),
185
- [reactiveIndex, key]
186
- );
187
- return reactiveIndex.getPksByKey(key);
188
- };
189
- var useSelectPksByIndexKeySetBasedSignal = (reactiveIndex, key) => {
190
- const force = useForceUpdate();
191
- useIsomorphicLayoutEffect(
192
- () => reactiveIndex.subscribeOnKey(key, force),
193
- [reactiveIndex, key]
194
- );
195
- return reactiveIndex.getPksByKey(key);
196
- };
197
- var useSelectPksByGlobalIndexArrayBasedSignal = (reactiveIndex) => {
198
- const force = useForceUpdate();
199
- useIsomorphicLayoutEffect(
200
- () => reactiveIndex.subscribe(force),
201
- [reactiveIndex]
202
- );
203
- return reactiveIndex.getPks();
204
- };
205
- var useSelectPksByGlobalIndexSetBasedSignal = (reactiveIndex) => {
206
- const force = useForceUpdate();
207
- useIsomorphicLayoutEffect(
208
- () => reactiveIndex.subscribe(force),
209
- [reactiveIndex]
210
- );
211
- return reactiveIndex.getPks();
212
- };
213
62
 
214
- // src/hooks/index.ts
215
- var EMPTY_ARRAY = [];
216
- var useSelectPksByIndexKeysSetBased = (reactiveIndex, keys) => {
217
- const prevKeysRef = (0, import_react3.useRef)();
218
- const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
219
- if (!keysAreEqual) {
220
- prevKeysRef.current = keys;
63
+ // src/useOIMValue.ts
64
+ var import_react4 = require("react");
65
+ var import_core2 = require("@oimdb/core");
66
+
67
+ // src/OIMSnapshotVersion.ts
68
+ var import_core = require("@oimdb/core");
69
+ var OIMSnapshotVersion = class {
70
+ constructor() {
71
+ this.version = 0;
72
+ this.getVersion = () => this.version;
73
+ }
74
+ subscribeEffect(channelMap, onStoreChange, sourceSlots, sourceComputeds) {
75
+ this.version++;
76
+ return import_core.OIMEffectService.INSTANCE.subscribeEffect(channelMap, () => {
77
+ this.version++;
78
+ onStoreChange();
79
+ }, sourceSlots, sourceComputeds);
221
80
  }
222
- const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
223
- const snapshotValueRef = (0, import_react3.useRef)();
224
- const subscribe = (0, import_react3.useMemo)(() => {
225
- snapshotValueRef.current = stableKeys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
226
- return (onStoreChange) => {
227
- const updateSnapshot = () => {
228
- snapshotValueRef.current = stableKeys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
229
- onStoreChange();
230
- };
231
- const unsubscribe = reactiveIndex.subscribeOnKeys(
232
- stableKeys,
233
- updateSnapshot
234
- );
235
- return () => {
236
- unsubscribe();
237
- };
238
- };
239
- }, [reactiveIndex, stableKeys]);
240
- const getSnapshot = (0, import_react3.useMemo)(() => {
241
- return () => {
242
- return snapshotValueRef.current;
243
- };
244
- }, []);
245
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
246
- return snapshot;
247
81
  };
248
- var useSelectPksByIndexKeySetBased = (reactiveIndex, key) => {
249
- const snapshotValueRef = (0, import_react3.useRef)();
250
- const subscribe = (0, import_react3.useMemo)(() => {
251
- snapshotValueRef.current = reactiveIndex.getPksByKey(key);
252
- return (onStoreChange) => {
253
- const updateSnapshot = () => {
254
- snapshotValueRef.current = reactiveIndex.getPksByKey(key);
255
- onStoreChange();
256
- };
257
- return reactiveIndex.subscribeOnKey(key, updateSnapshot);
258
- };
259
- }, [key, reactiveIndex]);
260
- const getSnapshot = (0, import_react3.useMemo)(() => {
261
- return () => {
262
- return snapshotValueRef.current;
82
+
83
+ // src/useOIMSnapshotVersion.ts
84
+ var import_react3 = require("react");
85
+ function useOIMSnapshotVersion(snapshotVersion, subscribe) {
86
+ return (0, import_react3.useSyncExternalStore)(subscribe, snapshotVersion.getVersion, snapshotVersion.getVersion);
87
+ }
88
+
89
+ // src/useOIMValue.ts
90
+ function useOIMValue(binding) {
91
+ const db = useOIMDB();
92
+ const sourceComputeds = binding.sourceComputeds ?? import_core2.OIM_FROZEN_EMPTY_SLOTS;
93
+ const store = (0, import_react4.useMemo)(() => {
94
+ const snapshotVersion = new OIMSnapshotVersion();
95
+ return {
96
+ snapshotVersion,
97
+ subscribe: (onStoreChange) => snapshotVersion.subscribeEffect(
98
+ db,
99
+ onStoreChange,
100
+ binding.sourceSlots ?? import_core2.OIM_FROZEN_EMPTY_SLOTS,
101
+ sourceComputeds
102
+ )
263
103
  };
264
- }, []);
265
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
266
- return snapshot;
267
- };
268
- var useSelectPksByIndexKeysArrayBased = (reactiveIndex, keys) => {
269
- const prevKeysRef = (0, import_react3.useRef)();
270
- const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
271
- if (!keysAreEqual) {
272
- prevKeysRef.current = keys;
104
+ }, [db, binding, sourceComputeds]);
105
+ useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
106
+ (0, import_core2.oimRefreshSourceComputeds)(sourceComputeds);
107
+ return binding.derive();
108
+ }
109
+
110
+ // src/useOIMComputedValue.ts
111
+ var import_react5 = require("react");
112
+ function useOIMComputedValue(computedSlot) {
113
+ const binding = (0, import_react5.useMemo)(() => ({
114
+ sourceComputeds: [computedSlot],
115
+ derive: () => computedSlot.value
116
+ }), [computedSlot]);
117
+ return useOIMValue(binding);
118
+ }
119
+
120
+ // src/useOIMSlotByKey.ts
121
+ var import_react6 = require("react");
122
+ var import_core3 = require("@oimdb/core");
123
+
124
+ // src/oimAssertOneChannel.ts
125
+ function oimAssertOneChannel(channelMap, slot, door) {
126
+ if (slot.storeSlot.channelSlot === channelMap.defaultChannelSlot) return;
127
+ throw new Error(
128
+ `${door}: the slot was filed on another OIMDB than the one <OIMDBProvider> was given, so a write would never wake this component. Build the services and their store slots on the one OIMDB the provider holds.`
129
+ );
130
+ }
131
+
132
+ // src/oimSubscribeHeldSlot.ts
133
+ function oimSubscribeHeldSlot(channelMap, hookName, snapshotVersion, holdingSlot, sourcesOfSlot, onStoreChange) {
134
+ try {
135
+ oimAssertOneChannel(channelMap, holdingSlot, hookName);
136
+ const [sourceSlots, sourceComputeds] = sourcesOfSlot(holdingSlot);
137
+ return snapshotVersion.subscribeEffect(channelMap, onStoreChange, sourceSlots, sourceComputeds);
138
+ } finally {
139
+ holdingSlot.owner.unholdSlot(holdingSlot);
273
140
  }
274
- const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
275
- const snapshotValueRef = (0, import_react3.useRef)();
276
- const subscribe = (0, import_react3.useMemo)(() => {
277
- snapshotValueRef.current = stableKeys.map((key) => reactiveIndex.getPksByKey(key)).flat();
278
- return (onStoreChange) => {
279
- const updateSnapshot = () => {
280
- snapshotValueRef.current = stableKeys.map((key) => reactiveIndex.getPksByKey(key)).flat();
281
- onStoreChange();
282
- };
283
- const unsubscribe = reactiveIndex.subscribeOnKeys(
284
- stableKeys,
285
- updateSnapshot
286
- );
287
- return () => {
288
- unsubscribe();
289
- };
290
- };
291
- }, [reactiveIndex, stableKeys]);
292
- const getSnapshot = (0, import_react3.useMemo)(() => {
293
- return () => {
294
- return snapshotValueRef.current;
295
- };
296
- }, []);
297
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
298
- return snapshot;
299
- };
300
- var useSelectPksByIndexKeyArrayBased = (reactiveIndex, key) => {
301
- const prevKeyRef = (0, import_react3.useRef)();
302
- const keyAreEqual = prevKeyRef.current === key;
303
- if (!keyAreEqual) {
304
- prevKeyRef.current = key;
141
+ }
142
+
143
+ // src/useOIMSlotByKey.ts
144
+ var sourcesOfRootSlot = (rootSlot) => [[rootSlot], import_core3.OIM_FROZEN_EMPTY_SLOTS];
145
+ function useOIMSlotByKey(hookName, slotCollectionService, storeSlot, key, sourcesOfSlot = sourcesOfRootSlot) {
146
+ const db = useOIMDB();
147
+ const lastSeenKeyRef = (0, import_react6.useRef)(key);
148
+ const settledKeyRef = (0, import_react6.useRef)(key);
149
+ if (key !== lastSeenKeyRef.current) {
150
+ lastSeenKeyRef.current = key;
151
+ if (slotCollectionService.getSlotByKey(storeSlot, key) !== slotCollectionService.getSlotByKey(storeSlot, settledKeyRef.current)) {
152
+ settledKeyRef.current = key;
153
+ }
305
154
  }
306
- const snapshotValueRef = (0, import_react3.useRef)();
307
- const subscribe = (0, import_react3.useMemo)(() => {
308
- snapshotValueRef.current = reactiveIndex.getPksByKey(key);
309
- return (onStoreChange) => {
310
- const prevKey = prevKeyRef.current;
311
- if (!prevKey) {
155
+ const settledKey = settledKeyRef.current;
156
+ const store = (0, import_react6.useMemo)(() => {
157
+ const snapshotVersion = new OIMSnapshotVersion();
158
+ let subscribedSlot = void 0;
159
+ return {
160
+ snapshotVersion,
161
+ subscribe: (onStoreChange) => {
162
+ const holdingSlot = slotCollectionService.holdSlotByKey(storeSlot, settledKey);
163
+ const effectDisposer = oimSubscribeHeldSlot(db, hookName, snapshotVersion, holdingSlot, sourcesOfSlot, onStoreChange);
164
+ subscribedSlot = holdingSlot;
312
165
  return () => {
166
+ subscribedSlot = void 0;
167
+ effectDisposer();
313
168
  };
314
- }
315
- const updateSnapshot = () => {
316
- snapshotValueRef.current = reactiveIndex.getPksByKey(prevKey);
317
- onStoreChange();
318
- };
319
- const unsubscribe = reactiveIndex.subscribeOnKey(
320
- prevKey,
321
- updateSnapshot
322
- );
323
- return () => {
324
- unsubscribe();
325
- };
169
+ },
170
+ getSlot: () => subscribedSlot ?? slotCollectionService.getSlotByKey(storeSlot, settledKey)
326
171
  };
327
- }, [key, reactiveIndex]);
328
- const getSnapshot = (0, import_react3.useMemo)(() => {
329
- return () => {
330
- return snapshotValueRef.current;
331
- };
332
- }, []);
333
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
334
- return snapshot;
335
- };
336
- var useSelectEntityByPk = (reactiveCollection, pk) => {
337
- const getSnapshot = (0, import_react3.useMemo)(
338
- () => () => reactiveCollection.getOneByPk(pk),
339
- [pk, reactiveCollection]
340
- );
341
- const subscribe = (0, import_react3.useMemo)(() => {
342
- return (onStoreChange) => {
343
- return reactiveCollection.subscribeOnKey(pk, onStoreChange);
344
- };
345
- }, [pk, reactiveCollection]);
346
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
347
- return snapshot;
348
- };
349
- var useSelectValueByObjectKey = (reactiveObject, key) => {
350
- const getSnapshot = (0, import_react3.useMemo)(
351
- () => () => reactiveObject.get(key),
352
- [key, reactiveObject]
353
- );
354
- const subscribe = (0, import_react3.useMemo)(() => {
355
- return (onStoreChange) => {
356
- return reactiveObject.subscribeOnKey(key, onStoreChange);
172
+ }, [hookName, db, slotCollectionService, storeSlot, settledKey, sourcesOfSlot]);
173
+ useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
174
+ return store.getSlot();
175
+ }
176
+
177
+ // src/useOIMEntity.ts
178
+ function useOIMEntity(entityCollectionService, entityStoreSlot, key) {
179
+ return useOIMSlotByKey("useOIMEntity", entityCollectionService, entityStoreSlot, key).entity;
180
+ }
181
+
182
+ // src/useOIMSingleSlot.ts
183
+ var import_react7 = require("react");
184
+ var import_core4 = require("@oimdb/core");
185
+ var sourcesOfRootSlot2 = (rootSlot) => [[rootSlot], import_core4.OIM_FROZEN_EMPTY_SLOTS];
186
+ function useOIMSingleSlot(hookName, singleSlotService, singleSlotStoreSlot, sourcesOfSlot = sourcesOfRootSlot2) {
187
+ const db = useOIMDB();
188
+ const store = (0, import_react7.useMemo)(() => {
189
+ const snapshotVersion = new OIMSnapshotVersion();
190
+ let subscribedSlot = void 0;
191
+ return {
192
+ snapshotVersion,
193
+ subscribe: (onStoreChange) => {
194
+ const holdingSlot = singleSlotService.holdSingleSlot(singleSlotStoreSlot);
195
+ const effectDisposer = oimSubscribeHeldSlot(db, hookName, snapshotVersion, holdingSlot, sourcesOfSlot, onStoreChange);
196
+ subscribedSlot = holdingSlot;
197
+ return () => {
198
+ subscribedSlot = void 0;
199
+ effectDisposer();
200
+ };
201
+ },
202
+ getSlot: () => subscribedSlot ?? singleSlotService.getSingleSlot(singleSlotStoreSlot)
357
203
  };
358
- }, [key, reactiveObject]);
359
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
360
- return snapshot;
361
- };
362
- var useSelectValuesByObjectKeys = (reactiveObject, keys) => {
363
- const prevKeysRef = (0, import_react3.useRef)();
364
- const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
365
- if (!keysAreEqual) {
366
- prevKeysRef.current = keys;
204
+ }, [hookName, db, singleSlotService, singleSlotStoreSlot, sourcesOfSlot]);
205
+ useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
206
+ return store.getSlot();
207
+ }
208
+
209
+ // src/useOIMSingleEntity.ts
210
+ function useOIMSingleEntity(singleSlotService, singleSlotStoreSlot) {
211
+ return useOIMSingleSlot("useOIMSingleEntity", singleSlotService, singleSlotStoreSlot).entity;
212
+ }
213
+
214
+ // src/useOIMSingleBucketSlots.ts
215
+ function useOIMSingleBucketSlots(singleSlotService, singleSlotStoreSlot) {
216
+ const bucketSlot = useOIMSingleSlot("useOIMSingleBucketSlots", singleSlotService, singleSlotStoreSlot);
217
+ return Array.from(singleSlotService.slotContentService.getBucketMemberSlots(bucketSlot));
218
+ }
219
+
220
+ // src/useOIMField.ts
221
+ var import_react8 = require("react");
222
+
223
+ // src/holdWhileSubscribed.ts
224
+ var import_core5 = require("@oimdb/core");
225
+ function holdWhileSubscribed(slots, subscribe) {
226
+ (0, import_core5.oimHoldSlots)(slots);
227
+ const giveEveryHoldBack = () => {
228
+ (0, import_core5.oimUnholdSlotsIfAlive)(slots);
229
+ };
230
+ let disposer;
231
+ try {
232
+ disposer = subscribe();
233
+ } catch (failure) {
234
+ giveEveryHoldBack();
235
+ throw failure;
367
236
  }
368
- const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
369
- const snapshotRef = (0, import_react3.useRef)();
370
- const subscribe = (0, import_react3.useMemo)(() => {
371
- snapshotRef.current = stableKeys.map((key) => reactiveObject.get(key));
372
- return (onStoreChange) => {
373
- const updateSnapshot = () => {
374
- snapshotRef.current = stableKeys.map(
375
- (key) => reactiveObject.get(key)
376
- );
377
- onStoreChange();
378
- };
379
- const unsubscribe = reactiveObject.subscribeOnKeys(
380
- stableKeys,
381
- updateSnapshot
382
- );
383
- return () => {
384
- unsubscribe();
385
- };
386
- };
387
- }, [reactiveObject, stableKeys]);
388
- const getSnapshot = (0, import_react3.useMemo)(() => {
389
- return () => {
390
- return snapshotRef.current;
237
+ return () => {
238
+ try {
239
+ disposer();
240
+ } finally {
241
+ giveEveryHoldBack();
242
+ }
243
+ };
244
+ }
245
+
246
+ // src/useOIMField.ts
247
+ function useOIMField(entityCollectionService, slot, name) {
248
+ const db = useOIMDB();
249
+ const store = (0, import_react8.useMemo)(() => {
250
+ oimAssertOneChannel(db, slot, "useOIMField");
251
+ const holds = [slot];
252
+ const snapshotVersion = new OIMSnapshotVersion();
253
+ return {
254
+ snapshotVersion,
255
+ subscribe: (onStoreChange) => holdWhileSubscribed(holds, () => snapshotVersion.subscribeEffect(
256
+ db,
257
+ onStoreChange,
258
+ [entityCollectionService.columnSlotService.getColumn(slot, name)]
259
+ ))
391
260
  };
392
- }, []);
393
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
394
- return snapshot;
395
- };
396
- function arraysEqual(a, b) {
397
- if (a === b) return true;
398
- if (a.length !== b.length) return false;
399
- for (let i = 0; i < a.length; i++) {
400
- if (a[i] !== b[i]) return false;
401
- }
402
- return true;
261
+ }, [db, entityCollectionService, slot, name]);
262
+ useOIMSnapshotVersion(store.snapshotVersion, store.subscribe);
263
+ return slot.entity?.[name];
264
+ }
265
+
266
+ // src/useOIMBucketSlots.ts
267
+ var import_react9 = require("react");
268
+ function useOIMBucketSlots(bucketCollectionService, bucketSlot) {
269
+ const db = useOIMDB();
270
+ const binding = (0, import_react9.useMemo)(() => {
271
+ oimAssertOneChannel(db, bucketSlot, "useOIMBucketSlots");
272
+ return { sourceSlots: [bucketSlot], derive: () => bucketSlot };
273
+ }, [db, bucketSlot]);
274
+ const { changedAtRevision, changedAtEpoch } = useOIMValue(binding);
275
+ return (0, import_react9.useMemo)(
276
+ () => Array.from(bucketCollectionService.slotContentService.getBucketMemberSlots(bucketSlot)),
277
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- the bucket slot's change stamp moves exactly when its members do
278
+ [bucketCollectionService, bucketSlot, changedAtRevision, changedAtEpoch]
279
+ );
280
+ }
281
+
282
+ // src/useOIMBucketSlotsByKey.ts
283
+ function useOIMBucketSlotsByKey(bucketCollectionService, bucketStoreSlot, key) {
284
+ const bucketSlot = useOIMSlotByKey("useOIMBucketSlotsByKey", bucketCollectionService, bucketStoreSlot, key);
285
+ return Array.from(bucketCollectionService.slotContentService.getBucketMemberSlots(bucketSlot));
403
286
  }
404
- var useSelectEntitiesByPks = (reactiveCollection, pks) => {
405
- const prevPksRef = (0, import_react3.useRef)();
406
- const pksAreEqual = arraysEqual(prevPksRef.current || EMPTY_ARRAY, pks);
407
- if (!pksAreEqual) {
408
- prevPksRef.current = pks;
287
+
288
+ // src/useOIMSlotsByKeys.ts
289
+ var import_react10 = require("react");
290
+ var import_core6 = require("@oimdb/core");
291
+ function useOIMSlotsByKeys(slotCollectionService, storeSlot, keys) {
292
+ const settledKeys = (0, import_react10.useRef)(keys);
293
+ const previousKeys = settledKeys.current;
294
+ if (!(0, import_core6.oimSameKeySequence)(previousKeys, keys)) settledKeys.current = keys;
295
+ const keysToHold = settledKeys.current;
296
+ const [, resolveAgain] = (0, import_react10.useState)(0);
297
+ const resolvedSlots = (0, import_react10.useRef)(void 0);
298
+ const resolvedKeys = (0, import_react10.useRef)(keysToHold);
299
+ const resolvedSlotCollectionService = (0, import_react10.useRef)(slotCollectionService);
300
+ const resolvedStoreSlot = (0, import_react10.useRef)(storeSlot);
301
+ if (resolvedSlots.current === void 0 || resolvedKeys.current !== keysToHold || resolvedSlotCollectionService.current !== slotCollectionService || resolvedStoreSlot.current !== storeSlot) {
302
+ const slots2 = [];
303
+ for (let i = 0; i < keysToHold.length; i++) {
304
+ slots2.push(slotCollectionService.getSlotByKey(storeSlot, keysToHold[i]));
305
+ }
306
+ resolvedSlots.current = slots2;
307
+ resolvedKeys.current = keysToHold;
308
+ resolvedSlotCollectionService.current = slotCollectionService;
309
+ resolvedStoreSlot.current = storeSlot;
409
310
  }
410
- const stablePks = pksAreEqual ? prevPksRef.current ?? pks : pks;
411
- const snapshotRef = (0, import_react3.useRef)();
412
- const subscribe = (0, import_react3.useMemo)(() => {
413
- snapshotRef.current = stablePks.map(
414
- (pk) => reactiveCollection.getOneByPk(pk)
415
- );
416
- return (onStoreChange) => {
417
- const updateSnapshot = () => {
418
- snapshotRef.current = stablePks.map(
419
- (pk) => reactiveCollection.getOneByPk(pk)
420
- );
421
- onStoreChange();
422
- };
423
- const unsubscribe = reactiveCollection.subscribeOnKeys(
424
- stablePks,
425
- updateSnapshot
426
- );
427
- return () => {
428
- unsubscribe();
429
- };
430
- };
431
- }, [reactiveCollection, stablePks]);
432
- const getSnapshot = (0, import_react3.useMemo)(() => {
311
+ const slots = resolvedSlots.current;
312
+ (0, import_react10.useEffect)(() => {
313
+ const renderedSlots = resolvedSlots.current;
314
+ const heldSlots = [];
315
+ let someKeyNamesAnotherIdentityNow = false;
316
+ for (let i = 0; i < keysToHold.length; i++) {
317
+ const slot = slotCollectionService.holdSlotByKey(storeSlot, keysToHold[i]);
318
+ heldSlots.push(slot);
319
+ if (slot !== renderedSlots?.[i]) someKeyNamesAnotherIdentityNow = true;
320
+ }
321
+ if (someKeyNamesAnotherIdentityNow) {
322
+ resolvedSlots.current = void 0;
323
+ resolveAgain((version) => version + 1);
324
+ }
433
325
  return () => {
434
- return snapshotRef.current;
435
- };
436
- }, []);
437
- const snapshot = (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
438
- return snapshot;
439
- };
440
- var useSelectEntitiesByIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
441
- const snapshotRef = (0, import_react3.useRef)();
442
- const subscribe = (0, import_react3.useMemo)(() => {
443
- const readSnapshot = () => Array.from(
444
- reactiveIndex.getPksByKey(key),
445
- (pk) => reactiveCollection.getOneByPk(pk)
446
- );
447
- const readPks = () => Array.from(reactiveIndex.getPksByKey(key));
448
- snapshotRef.current = readSnapshot();
449
- return (onStoreChange) => {
450
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
451
- snapshotRef.current = readSnapshot();
452
- onStoreChange();
453
- });
454
- const resubscribeCollection = () => {
455
- unsubscribeFromCollection();
456
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
457
- readPks(),
458
- () => {
459
- snapshotRef.current = readSnapshot();
460
- onStoreChange();
461
- }
462
- );
463
- };
464
- const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
465
- resubscribeCollection();
466
- snapshotRef.current = readSnapshot();
467
- onStoreChange();
468
- });
469
- return () => {
470
- unsubscribeFromIndex();
471
- unsubscribeFromCollection();
472
- };
473
- };
474
- }, [key, reactiveCollection, reactiveIndex]);
475
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
476
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
477
- };
478
- var useSelectEntitiesByIndexKeysSetBased = (reactiveCollection, reactiveIndex, keys) => {
479
- const prevKeysRef = (0, import_react3.useRef)();
480
- const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
481
- if (!keysAreEqual) {
482
- prevKeysRef.current = keys;
483
- }
484
- const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
485
- const snapshotRef = (0, import_react3.useRef)();
486
- const subscribe = (0, import_react3.useMemo)(() => {
487
- const readPks = () => stableKeys.flatMap(
488
- (key) => Array.from(reactiveIndex.getPksByKey(key))
489
- );
490
- const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
491
- snapshotRef.current = readSnapshot();
492
- return (onStoreChange) => {
493
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
494
- snapshotRef.current = readSnapshot();
495
- onStoreChange();
496
- });
497
- const resubscribeCollection = () => {
498
- unsubscribeFromCollection();
499
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
500
- readPks(),
501
- () => {
502
- snapshotRef.current = readSnapshot();
503
- onStoreChange();
504
- }
505
- );
506
- };
507
- const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
508
- stableKeys,
509
- () => {
510
- resubscribeCollection();
511
- snapshotRef.current = readSnapshot();
512
- onStoreChange();
513
- }
514
- );
515
- return () => {
516
- unsubscribeFromIndex();
517
- unsubscribeFromCollection();
518
- };
519
- };
520
- }, [reactiveCollection, reactiveIndex, stableKeys]);
521
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
522
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
523
- };
524
- var useSelectEntitiesByIndexKeyArrayBased = (reactiveCollection, reactiveIndex, key) => {
525
- const snapshotRef = (0, import_react3.useRef)();
526
- const subscribe = (0, import_react3.useMemo)(() => {
527
- const readSnapshot = () => reactiveIndex.getPksByKey(key).map((pk) => reactiveCollection.getOneByPk(pk));
528
- const readPks = () => reactiveIndex.getPksByKey(key);
529
- snapshotRef.current = readSnapshot();
530
- return (onStoreChange) => {
531
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
532
- snapshotRef.current = readSnapshot();
533
- onStoreChange();
534
- });
535
- const resubscribeCollection = () => {
536
- unsubscribeFromCollection();
537
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
538
- readPks(),
539
- () => {
540
- snapshotRef.current = readSnapshot();
541
- onStoreChange();
542
- }
543
- );
544
- };
545
- const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(key, () => {
546
- resubscribeCollection();
547
- snapshotRef.current = readSnapshot();
548
- onStoreChange();
549
- });
550
- return () => {
551
- unsubscribeFromIndex();
552
- unsubscribeFromCollection();
553
- };
554
- };
555
- }, [key, reactiveCollection, reactiveIndex]);
556
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
557
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
558
- };
559
- var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex, keys) => {
560
- const prevKeysRef = (0, import_react3.useRef)();
561
- const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
562
- if (!keysAreEqual) {
563
- prevKeysRef.current = keys;
564
- }
565
- const stableKeys = keysAreEqual ? prevKeysRef.current ?? keys : keys;
566
- const snapshotRef = (0, import_react3.useRef)();
567
- const subscribe = (0, import_react3.useMemo)(() => {
568
- const readPks = () => stableKeys.flatMap((key) => reactiveIndex.getPksByKey(key));
569
- const readSnapshot = () => readPks().map((pk) => reactiveCollection.getOneByPk(pk));
570
- snapshotRef.current = readSnapshot();
571
- return (onStoreChange) => {
572
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
573
- snapshotRef.current = readSnapshot();
574
- onStoreChange();
575
- });
576
- const resubscribeCollection = () => {
577
- unsubscribeFromCollection();
578
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
579
- readPks(),
580
- () => {
581
- snapshotRef.current = readSnapshot();
582
- onStoreChange();
583
- }
584
- );
585
- };
586
- const unsubscribeFromIndex = reactiveIndex.subscribeOnKeys(
587
- stableKeys,
588
- () => {
589
- resubscribeCollection();
590
- snapshotRef.current = readSnapshot();
591
- onStoreChange();
592
- }
593
- );
594
- return () => {
595
- unsubscribeFromIndex();
596
- unsubscribeFromCollection();
597
- };
326
+ for (let i = 0; i < heldSlots.length; i++) {
327
+ const heldSlot = heldSlots[i];
328
+ heldSlot.owner.unholdSlot(heldSlot);
329
+ }
598
330
  };
599
- }, [reactiveCollection, reactiveIndex, stableKeys]);
600
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
601
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
602
- };
603
- function useStableKeyPath(key) {
604
- const prevRef = (0, import_react3.useRef)();
605
- const equal = prevRef.current !== void 0 && arraysEqual(prevRef.current, key);
606
- if (!equal) {
607
- prevRef.current = key;
608
- }
609
- return equal ? prevRef.current : key;
331
+ }, [slotCollectionService, storeSlot, keysToHold]);
332
+ return slots;
610
333
  }
611
- var useSelectPksByCompositeIndexKeySetBased = (reactiveIndex, key) => {
612
- const stableKey = useStableKeyPath(key);
613
- const snapshotValueRef = (0, import_react3.useRef)();
614
- const subscribe = (0, import_react3.useMemo)(() => {
615
- snapshotValueRef.current = reactiveIndex.getPksByKey(stableKey);
616
- return (onStoreChange) => {
617
- const updateSnapshot = () => {
618
- snapshotValueRef.current = reactiveIndex.getPksByKey(stableKey);
619
- onStoreChange();
620
- };
621
- return reactiveIndex.subscribeOnKey(stableKey, updateSnapshot);
622
- };
623
- }, [stableKey, reactiveIndex]);
624
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotValueRef.current, []);
625
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
626
- };
627
- var useSelectPksByCompositeIndexKeyArrayBased = (reactiveIndex, key) => {
628
- const stableKey = useStableKeyPath(key);
629
- const snapshotValueRef = (0, import_react3.useRef)();
630
- const subscribe = (0, import_react3.useMemo)(() => {
631
- snapshotValueRef.current = reactiveIndex.getPksByKey(stableKey);
632
- return (onStoreChange) => {
633
- const updateSnapshot = () => {
634
- snapshotValueRef.current = reactiveIndex.getPksByKey(stableKey);
635
- onStoreChange();
636
- };
637
- return reactiveIndex.subscribeOnKey(stableKey, updateSnapshot);
638
- };
639
- }, [stableKey, reactiveIndex]);
640
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotValueRef.current, []);
641
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
642
- };
643
- var useSelectEntitiesByCompositeIndexKeySetBased = (reactiveCollection, reactiveIndex, key) => {
644
- const stableKey = useStableKeyPath(key);
645
- const snapshotRef = (0, import_react3.useRef)();
646
- const subscribe = (0, import_react3.useMemo)(() => {
647
- const readSnapshot = () => Array.from(
648
- reactiveIndex.getPksByKey(stableKey),
649
- (pk) => reactiveCollection.getOneByPk(pk)
650
- );
651
- const readPks = () => Array.from(reactiveIndex.getPksByKey(stableKey));
652
- snapshotRef.current = readSnapshot();
653
- return (onStoreChange) => {
654
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
655
- snapshotRef.current = readSnapshot();
656
- onStoreChange();
657
- });
658
- const resubscribeCollection = () => {
659
- unsubscribeFromCollection();
660
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
661
- readPks(),
662
- () => {
663
- snapshotRef.current = readSnapshot();
664
- onStoreChange();
665
- }
666
- );
667
- };
668
- const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(
669
- stableKey,
670
- () => {
671
- resubscribeCollection();
672
- snapshotRef.current = readSnapshot();
673
- onStoreChange();
674
- }
675
- );
676
- return () => {
677
- unsubscribeFromIndex();
678
- unsubscribeFromCollection();
679
- };
680
- };
681
- }, [stableKey, reactiveCollection, reactiveIndex]);
682
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
683
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
684
- };
685
- var useSelectEntitiesByCompositeIndexKeyArrayBased = (reactiveCollection, reactiveIndex, key) => {
686
- const stableKey = useStableKeyPath(key);
687
- const snapshotRef = (0, import_react3.useRef)();
688
- const subscribe = (0, import_react3.useMemo)(() => {
689
- const readSnapshot = () => reactiveIndex.getPksByKey(stableKey).map((pk) => reactiveCollection.getOneByPk(pk));
690
- const readPks = () => reactiveIndex.getPksByKey(stableKey);
691
- snapshotRef.current = readSnapshot();
692
- return (onStoreChange) => {
693
- let unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(readPks(), () => {
694
- snapshotRef.current = readSnapshot();
695
- onStoreChange();
696
- });
697
- const resubscribeCollection = () => {
698
- unsubscribeFromCollection();
699
- unsubscribeFromCollection = reactiveCollection.subscribeOnKeys(
700
- readPks(),
701
- () => {
702
- snapshotRef.current = readSnapshot();
703
- onStoreChange();
704
- }
705
- );
706
- };
707
- const unsubscribeFromIndex = reactiveIndex.subscribeOnKey(
708
- stableKey,
709
- () => {
710
- resubscribeCollection();
711
- snapshotRef.current = readSnapshot();
712
- onStoreChange();
713
- }
714
- );
715
- return () => {
716
- unsubscribeFromIndex();
717
- unsubscribeFromCollection();
718
- };
719
- };
720
- }, [stableKey, reactiveCollection, reactiveIndex]);
721
- const getSnapshot = (0, import_react3.useMemo)(() => () => snapshotRef.current, []);
722
- return (0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
723
- };
724
334
 
725
- // src/context/index.tsx
726
- var import_react5 = require("react");
727
- var import_jsx_runtime = require("react/jsx-runtime");
728
- var OIMCollectionsContext = (0, import_react5.createContext)(
729
- {}
730
- );
731
- function createOIMCollectionsContext() {
732
- return (0, import_react5.createContext)({});
335
+ // src/useOIMComputedValueByKey.ts
336
+ var import_core7 = require("@oimdb/core");
337
+ var sourcesOfComputedSlot = (computedSlot) => [import_core7.OIM_FROZEN_EMPTY_SLOTS, [computedSlot]];
338
+ function useOIMComputedValueByKey(computedCollectionService, computedStoreSlot, key) {
339
+ const computedSlot = useOIMSlotByKey(
340
+ "useOIMComputedValueByKey",
341
+ computedCollectionService,
342
+ computedStoreSlot,
343
+ key,
344
+ sourcesOfComputedSlot
345
+ );
346
+ return computedSlot.computedValueService.getValueForSlot(computedSlot);
733
347
  }
734
- function OIMCollectionsProvider({ collections, children, context }) {
735
- const ContextToUse = context || OIMCollectionsContext;
736
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextToUse.Provider, { value: collections, children });
348
+
349
+ // src/useOIMSingleComputedValue.ts
350
+ var import_react11 = require("react");
351
+ var import_core8 = require("@oimdb/core");
352
+ var sourcesOfComputedSlot2 = (computedSlot) => [import_core8.OIM_FROZEN_EMPTY_SLOTS, [computedSlot]];
353
+ function useOIMSingleComputedValue(computedService, derive, createSources, dependencyList) {
354
+ const db = useOIMDB();
355
+ const computedStoreSlot = (0, import_react11.useMemo)(
356
+ () => computedService.createComputedStoreSlot(db, derive, createSources),
357
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller's list is checked at the call site
358
+ [db, computedService, ...dependencyList]
359
+ );
360
+ const computedSlot = useOIMSingleSlot(
361
+ "useOIMSingleComputedValue",
362
+ computedService.computedSingleSlotService,
363
+ computedStoreSlot,
364
+ sourcesOfComputedSlot2
365
+ );
366
+ return computedSlot.computedValueService.getValueForSlot(computedSlot);
737
367
  }
738
- function useOIMCollectionsContext(context) {
739
- const contextToUse = context || OIMCollectionsContext;
740
- const collections = (0, import_react5.useContext)(contextToUse);
741
- if (!collections || Object.keys(collections).length === 0) {
742
- throw new Error(
743
- "useOIMCollectionsContext must be used within an OIMCollectionsProvider"
744
- );
745
- }
746
- return collections;
368
+
369
+ // src/useOIMComputedCollection.ts
370
+ var import_react12 = require("react");
371
+ function useOIMComputedCollection(computedService, derive, createSources, dependencyList) {
372
+ const db = useOIMDB();
373
+ return (0, import_react12.useMemo)(
374
+ () => computedService.createComputedStoreSlot(db, derive, createSources),
375
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller's list is checked at the call site
376
+ [db, computedService, ...dependencyList]
377
+ );
747
378
  }
748
379
  // Annotate the CommonJS export names for ESM import in node:
749
380
  0 && (module.exports = {
750
- OIMCollectionsContext,
751
- OIMCollectionsProvider,
752
- createOIMCollectionsContext,
753
- useOIMCollectionsContext,
754
- useSelectEntitiesByCompositeIndexKeyArrayBased,
755
- useSelectEntitiesByCompositeIndexKeySetBased,
756
- useSelectEntitiesByGlobalIndexArrayBased,
757
- useSelectEntitiesByGlobalIndexSetBased,
758
- useSelectEntitiesByIndexKeyArrayBased,
759
- useSelectEntitiesByIndexKeySetBased,
760
- useSelectEntitiesByIndexKeysArrayBased,
761
- useSelectEntitiesByIndexKeysSetBased,
762
- useSelectEntitiesByPks,
763
- useSelectEntityByPk,
764
- useSelectEntityByPkSignal,
765
- useSelectPksByCompositeIndexKeyArrayBased,
766
- useSelectPksByCompositeIndexKeySetBased,
767
- useSelectPksByGlobalIndexArrayBased,
768
- useSelectPksByGlobalIndexArrayBasedSignal,
769
- useSelectPksByGlobalIndexSetBased,
770
- useSelectPksByGlobalIndexSetBasedSignal,
771
- useSelectPksByIndexKeyArrayBased,
772
- useSelectPksByIndexKeyArrayBasedSignal,
773
- useSelectPksByIndexKeySetBased,
774
- useSelectPksByIndexKeySetBasedSignal,
775
- useSelectPksByIndexKeysArrayBased,
776
- useSelectPksByIndexKeysSetBased,
777
- useSelectValueByObjectKey,
778
- useSelectValuesByObjectKeys
381
+ OIMDBContext,
382
+ OIMDBProvider,
383
+ useOIMBucketSlots,
384
+ useOIMBucketSlotsByKey,
385
+ useOIMComputedCollection,
386
+ useOIMComputedValue,
387
+ useOIMComputedValueByKey,
388
+ useOIMDB,
389
+ useOIMEntity,
390
+ useOIMField,
391
+ useOIMSingleBucketSlots,
392
+ useOIMSingleComputedValue,
393
+ useOIMSingleEntity,
394
+ useOIMSlotsByKeys,
395
+ useOIMValue
779
396
  });