tinybase 0.0.0 → 0.9.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/lib/checkpoints.d.ts +861 -0
  3. package/lib/checkpoints.js +1 -0
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/common.d.ts +59 -0
  6. package/lib/debug/checkpoints.d.ts +861 -0
  7. package/lib/debug/checkpoints.js +326 -0
  8. package/lib/debug/common.d.ts +59 -0
  9. package/lib/debug/indexes.d.ts +815 -0
  10. package/lib/debug/indexes.js +390 -0
  11. package/lib/debug/metrics.d.ts +728 -0
  12. package/lib/debug/metrics.js +391 -0
  13. package/lib/debug/persisters.d.ts +521 -0
  14. package/lib/debug/persisters.js +191 -0
  15. package/lib/debug/react.d.ts +7077 -0
  16. package/lib/debug/react.js +1037 -0
  17. package/lib/debug/relationships.d.ts +1091 -0
  18. package/lib/debug/relationships.js +418 -0
  19. package/lib/debug/store.d.ts +2424 -0
  20. package/lib/debug/store.js +725 -0
  21. package/lib/debug/tinybase.d.ts +14 -0
  22. package/lib/debug/tinybase.js +2727 -0
  23. package/lib/indexes.d.ts +815 -0
  24. package/lib/indexes.js +1 -0
  25. package/lib/indexes.js.gz +0 -0
  26. package/lib/metrics.d.ts +728 -0
  27. package/lib/metrics.js +1 -0
  28. package/lib/metrics.js.gz +0 -0
  29. package/lib/persisters.d.ts +521 -0
  30. package/lib/persisters.js +1 -0
  31. package/lib/persisters.js.gz +0 -0
  32. package/lib/react.d.ts +7077 -0
  33. package/lib/react.js +1 -0
  34. package/lib/react.js.gz +0 -0
  35. package/lib/relationships.d.ts +1091 -0
  36. package/lib/relationships.js +1 -0
  37. package/lib/relationships.js.gz +0 -0
  38. package/lib/store.d.ts +2424 -0
  39. package/lib/store.js +1 -0
  40. package/lib/store.js.gz +0 -0
  41. package/lib/tinybase.d.ts +14 -0
  42. package/lib/tinybase.js +1 -0
  43. package/lib/tinybase.js.gz +0 -0
  44. package/lib/umd/checkpoints.js +1 -0
  45. package/lib/umd/checkpoints.js.gz +0 -0
  46. package/lib/umd/indexes.js +1 -0
  47. package/lib/umd/indexes.js.gz +0 -0
  48. package/lib/umd/metrics.js +1 -0
  49. package/lib/umd/metrics.js.gz +0 -0
  50. package/lib/umd/persisters.js +1 -0
  51. package/lib/umd/persisters.js.gz +0 -0
  52. package/lib/umd/react.js +1 -0
  53. package/lib/umd/react.js.gz +0 -0
  54. package/lib/umd/relationships.js +1 -0
  55. package/lib/umd/relationships.js.gz +0 -0
  56. package/lib/umd/store.js +1 -0
  57. package/lib/umd/store.js.gz +0 -0
  58. package/lib/umd/tinybase.js +1 -0
  59. package/lib/umd/tinybase.js.gz +0 -0
  60. package/package.json +93 -2
  61. package/readme.md +195 -0
@@ -0,0 +1,1037 @@
1
+ import React from 'react';
2
+
3
+ const getTypeOf = (thing) => typeof thing;
4
+ const EMPTY_STRING = '';
5
+ const STRING = getTypeOf(EMPTY_STRING);
6
+
7
+ const arrayMap = (array, cb) => array.map(cb);
8
+ const arrayLength = (array) => array.length;
9
+ const arrayIsEmpty = (array) => arrayLength(array) == 0;
10
+
11
+ const isUndefined = (thing) => thing == void 0;
12
+ const ifNotUndefined = (value, then, otherwise) =>
13
+ isUndefined(value) ? otherwise?.() : then(value);
14
+ const isString = (thing) => getTypeOf(thing) == STRING;
15
+ const getUndefined = () => void 0;
16
+
17
+ const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
18
+
19
+ const {createContext, useContext} = React;
20
+ const Context = createContext([]);
21
+ const useThing = (id, offset) => {
22
+ const thingsAndThingsById = useContext(Context);
23
+ return isUndefined(id)
24
+ ? thingsAndThingsById[offset]
25
+ : objGet(thingsAndThingsById[offset + 1], id);
26
+ };
27
+ const useThingOrThingId = (thingOrThingId, offset) => {
28
+ const thing = useThing(thingOrThingId, offset);
29
+ if (isUndefined(thingOrThingId) || isString(thingOrThingId)) {
30
+ return thing;
31
+ }
32
+ return thingOrThingId;
33
+ };
34
+ const useStore = (id) => useThing(id, 0);
35
+ const useMetrics = (id) => useThing(id, 2);
36
+ const useIndexes = (id) => useThing(id, 4);
37
+ const useRelationships = (id) => useThing(id, 6);
38
+ const useCheckpoints = (id) => useThing(id, 8);
39
+ const useStoreOrStoreId = (storeOrStoreId) =>
40
+ useThingOrThingId(storeOrStoreId, 0);
41
+ const useMetricsOrMetricsId = (metricsOrMetricsId) =>
42
+ useThingOrThingId(metricsOrMetricsId, 2);
43
+ const useIndexesOrIndexesId = (indexesOrIndexesId) =>
44
+ useThingOrThingId(indexesOrIndexesId, 4);
45
+ const useRelationshipsOrRelationshipsId = (relationshipsOrRelationshipsId) =>
46
+ useThingOrThingId(relationshipsOrRelationshipsId, 6);
47
+ const useCheckpointsOrCheckpointsId = (checkpointsOrCheckpointsId) =>
48
+ useThingOrThingId(checkpointsOrCheckpointsId, 8);
49
+
50
+ const {useCallback, useEffect, useMemo: useMemo$1, useState} = React;
51
+ const useCreate = (store, create, createDeps = []) =>
52
+ useMemo$1(() => create(store), [store, ...createDeps]);
53
+ const useListenable = (listenable, thing, defaulted, ...args) => {
54
+ const getListenable = thing?.['get' + listenable] ?? (() => defaulted);
55
+ const immediateListenable = getListenable(...args);
56
+ const [, setListenable] = useState(immediateListenable);
57
+ useEffect(() => {
58
+ const listenerId = thing?.[`add${listenable}Listener`]?.(
59
+ ...args,
60
+ () => setListenable(getListenable(...args)),
61
+ false,
62
+ );
63
+ return () => thing?.delListener(listenerId);
64
+ }, [thing, listenable, setListenable, getListenable, ...args]);
65
+ return immediateListenable;
66
+ };
67
+ const useListener = (
68
+ listenable,
69
+ thing,
70
+ listener,
71
+ listenerDeps = [],
72
+ mutator,
73
+ ...args
74
+ ) => {
75
+ useEffect(() => {
76
+ const listenerId = thing?.[`add${listenable}Listener`]?.(
77
+ ...args,
78
+ listener,
79
+ mutator,
80
+ );
81
+ return () => thing?.delListener(listenerId);
82
+ }, [thing, listenable, ...listenerDeps, mutator, ...args]);
83
+ };
84
+ const useSetCallback = (
85
+ storeOrStoreId,
86
+ settable,
87
+ get,
88
+ getDeps = [],
89
+ then = getUndefined,
90
+ thenDeps = [],
91
+ ...args
92
+ ) => {
93
+ const store = useStoreOrStoreId(storeOrStoreId);
94
+ return useCallback(
95
+ (parameter) =>
96
+ ifNotUndefined(store, (store2) =>
97
+ ifNotUndefined(get(parameter, store2), (value) =>
98
+ then(store2['set' + settable](...args, value), value),
99
+ ),
100
+ ),
101
+ [store, settable, ...getDeps, ...thenDeps, ...args],
102
+ );
103
+ };
104
+ const useDel = (
105
+ storeOrStoreId,
106
+ deletable,
107
+ then = getUndefined,
108
+ thenDeps = [],
109
+ ...args
110
+ ) => {
111
+ const store = useStoreOrStoreId(storeOrStoreId);
112
+ return useCallback(
113
+ () => then(store?.['del' + deletable](...args)),
114
+ [store, deletable, ...thenDeps, ...args],
115
+ );
116
+ };
117
+ const useCheckpointAction = (checkpointsOrCheckpointsId, action, arg) => {
118
+ const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
119
+ return useCallback(
120
+ () => checkpoints?.[action](arg),
121
+ [checkpoints, action, arg],
122
+ );
123
+ };
124
+ const useCreateStore = (create, createDeps = []) =>
125
+ useMemo$1(create, createDeps);
126
+ const useTables = (storeOrStoreId) =>
127
+ useListenable('Tables', useStoreOrStoreId(storeOrStoreId), {});
128
+ const useTableIds = (storeOrStoreId) =>
129
+ useListenable('TableIds', useStoreOrStoreId(storeOrStoreId), []);
130
+ const useTable = (tableId, storeOrStoreId) =>
131
+ useListenable('Table', useStoreOrStoreId(storeOrStoreId), {}, tableId);
132
+ const useRowIds = (tableId, storeOrStoreId) =>
133
+ useListenable('RowIds', useStoreOrStoreId(storeOrStoreId), [], tableId);
134
+ const useRow = (tableId, rowId, storeOrStoreId) =>
135
+ useListenable('Row', useStoreOrStoreId(storeOrStoreId), {}, tableId, rowId);
136
+ const useCellIds = (tableId, rowId, storeOrStoreId) =>
137
+ useListenable(
138
+ 'CellIds',
139
+ useStoreOrStoreId(storeOrStoreId),
140
+ [],
141
+ tableId,
142
+ rowId,
143
+ );
144
+ const useCell = (tableId, rowId, cellId, storeOrStoreId) =>
145
+ useListenable(
146
+ 'Cell',
147
+ useStoreOrStoreId(storeOrStoreId),
148
+ void 0,
149
+ tableId,
150
+ rowId,
151
+ cellId,
152
+ );
153
+ const useSetTablesCallback = (
154
+ getTables,
155
+ getTablesDeps,
156
+ storeOrStoreId,
157
+ then,
158
+ thenDeps,
159
+ ) =>
160
+ useSetCallback(
161
+ storeOrStoreId,
162
+ 'Tables',
163
+ getTables,
164
+ getTablesDeps,
165
+ then,
166
+ thenDeps,
167
+ );
168
+ const useSetTableCallback = (
169
+ tableId,
170
+ getTable,
171
+ getTableDeps,
172
+ storeOrStoreId,
173
+ then,
174
+ thenDeps,
175
+ ) =>
176
+ useSetCallback(
177
+ storeOrStoreId,
178
+ 'Table',
179
+ getTable,
180
+ getTableDeps,
181
+ then,
182
+ thenDeps,
183
+ tableId,
184
+ );
185
+ const useSetRowCallback = (
186
+ tableId,
187
+ rowId,
188
+ getRow,
189
+ getRowDeps,
190
+ storeOrStoreId,
191
+ then,
192
+ thenDeps,
193
+ ) =>
194
+ useSetCallback(
195
+ storeOrStoreId,
196
+ 'Row',
197
+ getRow,
198
+ getRowDeps,
199
+ then,
200
+ thenDeps,
201
+ tableId,
202
+ rowId,
203
+ );
204
+ const useAddRowCallback = (
205
+ tableId,
206
+ getRow,
207
+ getRowDeps = [],
208
+ storeOrStoreId,
209
+ then = getUndefined,
210
+ thenDeps = [],
211
+ ) => {
212
+ const store = useStoreOrStoreId(storeOrStoreId);
213
+ return useCallback(
214
+ (parameter) =>
215
+ ifNotUndefined(store, (store2) =>
216
+ ifNotUndefined(getRow(parameter, store2), (row) =>
217
+ then(store2.addRow(tableId, row), store2, row),
218
+ ),
219
+ ),
220
+ [store, tableId, ...getRowDeps, ...thenDeps],
221
+ );
222
+ };
223
+ const useSetPartialRowCallback = (
224
+ tableId,
225
+ rowId,
226
+ getPartialRow,
227
+ getPartialRowDeps,
228
+ storeOrStoreId,
229
+ then,
230
+ thenDeps,
231
+ ) =>
232
+ useSetCallback(
233
+ storeOrStoreId,
234
+ 'PartialRow',
235
+ getPartialRow,
236
+ getPartialRowDeps,
237
+ then,
238
+ thenDeps,
239
+ tableId,
240
+ rowId,
241
+ );
242
+ const useSetCellCallback = (
243
+ tableId,
244
+ rowId,
245
+ cellId,
246
+ getCell,
247
+ getCellDeps,
248
+ storeOrStoreId,
249
+ then,
250
+ thenDeps,
251
+ ) =>
252
+ useSetCallback(
253
+ storeOrStoreId,
254
+ 'Cell',
255
+ getCell,
256
+ getCellDeps,
257
+ then,
258
+ thenDeps,
259
+ tableId,
260
+ rowId,
261
+ cellId,
262
+ );
263
+ const useDelTablesCallback = (storeOrStoreId, then, thenDeps) =>
264
+ useDel(storeOrStoreId, 'Tables', then, thenDeps);
265
+ const useDelTableCallback = (tableId, storeOrStoreId, then, thenDeps) =>
266
+ useDel(storeOrStoreId, 'Table', then, thenDeps, tableId);
267
+ const useDelRowCallback = (tableId, rowId, storeOrStoreId, then, thenDeps) =>
268
+ useDel(storeOrStoreId, 'Row', then, thenDeps, tableId, rowId);
269
+ const useDelCellCallback = (
270
+ tableId,
271
+ rowId,
272
+ cellId,
273
+ forceDel,
274
+ storeOrStoreId,
275
+ then,
276
+ thenDeps,
277
+ ) =>
278
+ useDel(
279
+ storeOrStoreId,
280
+ 'Cell',
281
+ then,
282
+ thenDeps,
283
+ tableId,
284
+ rowId,
285
+ cellId,
286
+ forceDel,
287
+ );
288
+ const useTablesListener = (listener, listenerDeps, mutator, storeOrStoreId) =>
289
+ useListener(
290
+ 'Tables',
291
+ useStoreOrStoreId(storeOrStoreId),
292
+ listener,
293
+ listenerDeps,
294
+ mutator,
295
+ );
296
+ const useTableIdsListener = (listener, listenerDeps, mutator, storeOrStoreId) =>
297
+ useListener(
298
+ 'TableIds',
299
+ useStoreOrStoreId(storeOrStoreId),
300
+ listener,
301
+ listenerDeps,
302
+ mutator,
303
+ );
304
+ const useTableListener = (
305
+ tableId,
306
+ listener,
307
+ listenerDeps,
308
+ mutator,
309
+ storeOrStoreId,
310
+ ) =>
311
+ useListener(
312
+ 'Table',
313
+ useStoreOrStoreId(storeOrStoreId),
314
+ listener,
315
+ listenerDeps,
316
+ mutator,
317
+ tableId,
318
+ );
319
+ const useRowIdsListener = (
320
+ tableId,
321
+ listener,
322
+ listenerDeps,
323
+ mutator,
324
+ storeOrStoreId,
325
+ ) =>
326
+ useListener(
327
+ 'RowIds',
328
+ useStoreOrStoreId(storeOrStoreId),
329
+ listener,
330
+ listenerDeps,
331
+ mutator,
332
+ tableId,
333
+ );
334
+ const useRowListener = (
335
+ tableId,
336
+ rowId,
337
+ listener,
338
+ listenerDeps,
339
+ mutator,
340
+ storeOrStoreId,
341
+ ) =>
342
+ useListener(
343
+ 'Row',
344
+ useStoreOrStoreId(storeOrStoreId),
345
+ listener,
346
+ listenerDeps,
347
+ mutator,
348
+ tableId,
349
+ rowId,
350
+ );
351
+ const useCellIdsListener = (
352
+ tableId,
353
+ rowId,
354
+ listener,
355
+ listenerDeps,
356
+ mutator,
357
+ storeOrStoreId,
358
+ ) =>
359
+ useListener(
360
+ 'CellIds',
361
+ useStoreOrStoreId(storeOrStoreId),
362
+ listener,
363
+ listenerDeps,
364
+ mutator,
365
+ tableId,
366
+ rowId,
367
+ );
368
+ const useCellListener = (
369
+ tableId,
370
+ rowId,
371
+ cellId,
372
+ listener,
373
+ listenerDeps,
374
+ mutator,
375
+ storeOrStoreId,
376
+ ) =>
377
+ useListener(
378
+ 'Cell',
379
+ useStoreOrStoreId(storeOrStoreId),
380
+ listener,
381
+ listenerDeps,
382
+ mutator,
383
+ tableId,
384
+ rowId,
385
+ cellId,
386
+ );
387
+ const useCreateMetrics = (store, create, createDeps) =>
388
+ useCreate(store, create, createDeps);
389
+ const useMetric = (metricId, metricsOrMetricsId) =>
390
+ useListenable(
391
+ 'Metric',
392
+ useMetricsOrMetricsId(metricsOrMetricsId),
393
+ void 0,
394
+ metricId,
395
+ );
396
+ const useMetricListener = (
397
+ metricId,
398
+ listener,
399
+ listenerDeps,
400
+ metricsOrMetricsId,
401
+ ) =>
402
+ useListener(
403
+ 'Metric',
404
+ useMetricsOrMetricsId(metricsOrMetricsId),
405
+ listener,
406
+ listenerDeps,
407
+ void 0,
408
+ metricId,
409
+ );
410
+ const useCreateIndexes = (store, create, createDeps) =>
411
+ useCreate(store, create, createDeps);
412
+ const useSliceIds = (indexId, indexesOrIndexesId) =>
413
+ useListenable(
414
+ 'SliceIds',
415
+ useIndexesOrIndexesId(indexesOrIndexesId),
416
+ [],
417
+ indexId,
418
+ );
419
+ const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
420
+ useListenable(
421
+ 'SliceRowIds',
422
+ useIndexesOrIndexesId(indexesOrIndexesId),
423
+ [],
424
+ indexId,
425
+ sliceId,
426
+ );
427
+ const useSliceIdsListener = (
428
+ indexId,
429
+ listener,
430
+ listenerDeps,
431
+ indexesOrIndexesId,
432
+ ) =>
433
+ useListener(
434
+ 'SliceIds',
435
+ useIndexesOrIndexesId(indexesOrIndexesId),
436
+ listener,
437
+ listenerDeps,
438
+ void 0,
439
+ indexId,
440
+ );
441
+ const useSliceRowIdsListener = (
442
+ indexId,
443
+ sliceId,
444
+ listener,
445
+ listenerDeps,
446
+ indexesOrIndexesId,
447
+ ) =>
448
+ useListener(
449
+ 'SliceRowIds',
450
+ useIndexesOrIndexesId(indexesOrIndexesId),
451
+ listener,
452
+ listenerDeps,
453
+ void 0,
454
+ indexId,
455
+ sliceId,
456
+ );
457
+ const useCreateRelationships = (store, create, createDeps) =>
458
+ useCreate(store, create, createDeps);
459
+ const useRemoteRowId = (
460
+ relationshipId,
461
+ localRowId,
462
+ relationshipsOrRelationshipsId,
463
+ ) =>
464
+ useListenable(
465
+ 'RemoteRowId',
466
+ useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
467
+ void 0,
468
+ relationshipId,
469
+ localRowId,
470
+ );
471
+ const useLocalRowIds = (
472
+ relationshipId,
473
+ remoteRowId,
474
+ relationshipsOrRelationshipsId,
475
+ ) =>
476
+ useListenable(
477
+ 'LocalRowIds',
478
+ useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
479
+ [],
480
+ relationshipId,
481
+ remoteRowId,
482
+ );
483
+ const useLinkedRowIds = (
484
+ relationshipId,
485
+ firstRowId,
486
+ relationshipsOrRelationshipsId,
487
+ ) =>
488
+ useListenable(
489
+ 'LinkedRowIds',
490
+ useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
491
+ [],
492
+ relationshipId,
493
+ firstRowId,
494
+ );
495
+ const useRemoteRowIdListener = (
496
+ relationshipId,
497
+ localRowId,
498
+ listener,
499
+ listenerDeps,
500
+ relationshipsOrRelationshipsId,
501
+ ) =>
502
+ useListener(
503
+ 'RemoteRowId',
504
+ useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
505
+ listener,
506
+ listenerDeps,
507
+ void 0,
508
+ relationshipId,
509
+ localRowId,
510
+ );
511
+ const useLocalRowIdsListener = (
512
+ relationshipId,
513
+ remoteRowId,
514
+ listener,
515
+ listenerDeps,
516
+ relationshipsOrRelationshipsId,
517
+ ) =>
518
+ useListener(
519
+ 'LocalRowIds',
520
+ useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
521
+ listener,
522
+ listenerDeps,
523
+ void 0,
524
+ relationshipId,
525
+ remoteRowId,
526
+ );
527
+ const useLinkedRowIdsListener = (
528
+ relationshipId,
529
+ firstRowId,
530
+ listener,
531
+ listenerDeps,
532
+ relationshipsOrRelationshipsId,
533
+ ) =>
534
+ useListener(
535
+ 'LinkedRowIds',
536
+ useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
537
+ listener,
538
+ listenerDeps,
539
+ void 0,
540
+ relationshipId,
541
+ firstRowId,
542
+ );
543
+ const useCreateCheckpoints = (store, create, createDeps) =>
544
+ useCreate(store, create, createDeps);
545
+ const useCheckpointIds = (checkpointsOrCheckpointsId) =>
546
+ useListenable(
547
+ 'CheckpointIds',
548
+ useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
549
+ [[], void 0, []],
550
+ );
551
+ const useCheckpoint = (checkpointId, checkpointsOrCheckpointsId) =>
552
+ useListenable(
553
+ 'Checkpoint',
554
+ useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
555
+ void 0,
556
+ checkpointId,
557
+ );
558
+ const useSetCheckpointCallback = (
559
+ getCheckpoint = getUndefined,
560
+ getCheckpointDeps = [],
561
+ checkpointsOrCheckpointsId,
562
+ then = getUndefined,
563
+ thenDeps = [],
564
+ ) => {
565
+ const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
566
+ return useCallback(
567
+ (parameter) =>
568
+ ifNotUndefined(checkpoints, (checkpoints2) => {
569
+ const label = getCheckpoint(parameter);
570
+ then(checkpoints2.addCheckpoint(label), checkpoints2, label);
571
+ }),
572
+ [checkpoints, ...getCheckpointDeps, ...thenDeps],
573
+ );
574
+ };
575
+ const useGoBackwardCallback = (checkpointsOrCheckpointsId) =>
576
+ useCheckpointAction(checkpointsOrCheckpointsId, 'goBackward');
577
+ const useGoForwardCallback = (checkpointsOrCheckpointsId) =>
578
+ useCheckpointAction(checkpointsOrCheckpointsId, 'goForward');
579
+ const useGoToCallback = (
580
+ getCheckpointId,
581
+ getCheckpointIdDeps = [],
582
+ checkpointsOrCheckpointsId,
583
+ then = getUndefined,
584
+ thenDeps = [],
585
+ ) => {
586
+ const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
587
+ return useCallback(
588
+ (parameter) =>
589
+ ifNotUndefined(checkpoints, (checkpoints2) =>
590
+ ifNotUndefined(getCheckpointId(parameter), (checkpointId) =>
591
+ then(checkpoints2.goTo(checkpointId), checkpointId),
592
+ ),
593
+ ),
594
+ [checkpoints, ...getCheckpointIdDeps, ...thenDeps],
595
+ );
596
+ };
597
+ const useUndoInformation = (checkpointsOrCheckpointsId) => {
598
+ const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
599
+ const [backwardIds, currentId] = useCheckpointIds(checkpoints);
600
+ return [
601
+ !arrayIsEmpty(backwardIds),
602
+ useGoBackwardCallback(checkpoints),
603
+ currentId,
604
+ ifNotUndefined(currentId, (id) => checkpoints?.getCheckpoint(id)) ?? '',
605
+ ];
606
+ };
607
+ const useRedoInformation = (checkpointsOrCheckpointsId) => {
608
+ const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
609
+ const [, , [forwardId]] = useCheckpointIds(checkpoints);
610
+ return [
611
+ !isUndefined(forwardId),
612
+ useGoForwardCallback(checkpoints),
613
+ forwardId,
614
+ ifNotUndefined(forwardId, (id) => checkpoints?.getCheckpoint(id)) ?? '',
615
+ ];
616
+ };
617
+ const useCheckpointIdsListener = (
618
+ listener,
619
+ listenerDeps,
620
+ checkpointsOrCheckpointsId,
621
+ ) =>
622
+ useListener(
623
+ 'CheckpointIds',
624
+ useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
625
+ listener,
626
+ listenerDeps,
627
+ );
628
+ const useCheckpointListener = (
629
+ checkpointId,
630
+ listener,
631
+ listenerDeps,
632
+ checkpointsOrCheckpointsId,
633
+ ) =>
634
+ useListener(
635
+ 'Checkpoint',
636
+ useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
637
+ listener,
638
+ listenerDeps,
639
+ void 0,
640
+ checkpointId,
641
+ );
642
+ const useCreatePersister = (
643
+ store,
644
+ create,
645
+ createDeps = [],
646
+ then,
647
+ thenDeps = [],
648
+ ) => {
649
+ const [, setDone] = useState();
650
+ const persister = useMemo$1(() => create(store), [store, ...createDeps]);
651
+ useEffect(() => {
652
+ (async () => {
653
+ await then?.(persister);
654
+ setDone(1);
655
+ return;
656
+ })();
657
+ }, [persister, ...thenDeps]);
658
+ return persister;
659
+ };
660
+
661
+ const {createElement, useMemo} = React;
662
+ const useRelationshipsStoreTableId = (relationships) => {
663
+ const resolvedRelationships =
664
+ useRelationshipsOrRelationshipsId(relationships);
665
+ return [resolvedRelationships, resolvedRelationships?.getStore()];
666
+ };
667
+ const useComponentPerRow = (
668
+ {
669
+ relationshipId,
670
+ relationships,
671
+ rowComponent: Row = RowView,
672
+ getRowComponentProps,
673
+ separator,
674
+ debugIds,
675
+ },
676
+ getRowIdsHook,
677
+ rowId,
678
+ ) => {
679
+ const [resolvedRelationships, store] =
680
+ useRelationshipsStoreTableId(relationships);
681
+ const tableId = resolvedRelationships?.getLocalTableId(relationshipId);
682
+ const rowIds = getRowIdsHook(relationshipId, rowId, resolvedRelationships);
683
+ return wrap(
684
+ arrayMap(rowIds, (rowId2) =>
685
+ /* @__PURE__ */ createElement(Row, {
686
+ ...getProps(getRowComponentProps, rowId2),
687
+ key: rowId2,
688
+ tableId,
689
+ rowId: rowId2,
690
+ store,
691
+ debugIds,
692
+ }),
693
+ ),
694
+ separator,
695
+ debugIds,
696
+ rowId,
697
+ );
698
+ };
699
+ const getUseCheckpointView =
700
+ (getCheckpoints) =>
701
+ ({
702
+ checkpoints,
703
+ checkpointComponent: Checkpoint = CheckpointView,
704
+ getCheckpointComponentProps,
705
+ separator,
706
+ debugIds,
707
+ }) => {
708
+ const resolvedCheckpoints = useCheckpointsOrCheckpointsId(checkpoints);
709
+ return wrap(
710
+ arrayMap(
711
+ getCheckpoints(useCheckpointIds(resolvedCheckpoints)),
712
+ (checkpointId) =>
713
+ /* @__PURE__ */ createElement(Checkpoint, {
714
+ ...getProps(getCheckpointComponentProps, checkpointId),
715
+ key: checkpointId,
716
+ checkpoints: resolvedCheckpoints,
717
+ checkpointId,
718
+ debugIds,
719
+ }),
720
+ ),
721
+ separator,
722
+ );
723
+ };
724
+ const getProps = (getProps2, id) =>
725
+ isUndefined(getProps2) ? {} : getProps2(id);
726
+ const Provider = ({
727
+ store,
728
+ storesById,
729
+ metrics,
730
+ metricsById,
731
+ indexes,
732
+ indexesById,
733
+ relationships,
734
+ relationshipsById,
735
+ checkpoints,
736
+ checkpointsById,
737
+ children,
738
+ }) =>
739
+ /* @__PURE__ */ createElement(
740
+ Context.Provider,
741
+ {
742
+ value: useMemo(
743
+ () => [
744
+ store,
745
+ storesById,
746
+ metrics,
747
+ metricsById,
748
+ indexes,
749
+ indexesById,
750
+ relationships,
751
+ relationshipsById,
752
+ checkpoints,
753
+ checkpointsById,
754
+ ],
755
+ [
756
+ store,
757
+ storesById,
758
+ metrics,
759
+ metricsById,
760
+ indexes,
761
+ indexesById,
762
+ relationships,
763
+ relationshipsById,
764
+ checkpoints,
765
+ checkpointsById,
766
+ ],
767
+ ),
768
+ },
769
+ children,
770
+ );
771
+ const wrap = (children, separator, encloseWithId, id) => {
772
+ const separatedChildren =
773
+ isUndefined(separator) || !Array.isArray(children)
774
+ ? children
775
+ : arrayMap(children, (child, c) => (c > 0 ? [separator, child] : child));
776
+ return encloseWithId ? [id, ':{', separatedChildren, '}'] : separatedChildren;
777
+ };
778
+ const CellView = ({tableId, rowId, cellId, store, debugIds}) =>
779
+ wrap(
780
+ EMPTY_STRING + (useCell(tableId, rowId, cellId, store) ?? EMPTY_STRING),
781
+ void 0,
782
+ debugIds,
783
+ cellId,
784
+ );
785
+ const RowView = ({
786
+ tableId,
787
+ rowId,
788
+ store,
789
+ cellComponent: Cell = CellView,
790
+ getCellComponentProps,
791
+ separator,
792
+ debugIds,
793
+ }) =>
794
+ wrap(
795
+ arrayMap(useCellIds(tableId, rowId, store), (cellId) =>
796
+ /* @__PURE__ */ createElement(Cell, {
797
+ ...getProps(getCellComponentProps, cellId),
798
+ key: cellId,
799
+ tableId,
800
+ rowId,
801
+ cellId,
802
+ store,
803
+ debugIds,
804
+ }),
805
+ ),
806
+ separator,
807
+ debugIds,
808
+ rowId,
809
+ );
810
+ const TableView = ({
811
+ tableId,
812
+ store,
813
+ rowComponent: Row = RowView,
814
+ getRowComponentProps,
815
+ separator,
816
+ debugIds,
817
+ }) =>
818
+ wrap(
819
+ arrayMap(useRowIds(tableId, store), (rowId) =>
820
+ /* @__PURE__ */ createElement(Row, {
821
+ ...getProps(getRowComponentProps, rowId),
822
+ key: rowId,
823
+ tableId,
824
+ rowId,
825
+ store,
826
+ debugIds,
827
+ }),
828
+ ),
829
+ separator,
830
+ debugIds,
831
+ tableId,
832
+ );
833
+ const TablesView = ({
834
+ store,
835
+ tableComponent: Table = TableView,
836
+ getTableComponentProps,
837
+ separator,
838
+ debugIds,
839
+ }) =>
840
+ wrap(
841
+ arrayMap(useTableIds(store), (tableId) =>
842
+ /* @__PURE__ */ createElement(Table, {
843
+ ...getProps(getTableComponentProps, tableId),
844
+ key: tableId,
845
+ tableId,
846
+ store,
847
+ debugIds,
848
+ }),
849
+ ),
850
+ separator,
851
+ );
852
+ const MetricView = ({metricId, metrics, debugIds}) =>
853
+ wrap(
854
+ useMetric(metricId, metrics) ?? EMPTY_STRING,
855
+ void 0,
856
+ debugIds,
857
+ metricId,
858
+ );
859
+ const SliceView = ({
860
+ indexId,
861
+ sliceId,
862
+ indexes,
863
+ rowComponent: Row = RowView,
864
+ getRowComponentProps,
865
+ separator,
866
+ debugIds,
867
+ }) => {
868
+ const resolvedIndexes = useIndexesOrIndexesId(indexes);
869
+ const store = resolvedIndexes?.getStore();
870
+ const tableId = resolvedIndexes?.getTableId(indexId);
871
+ const rowIds = useSliceRowIds(indexId, sliceId, resolvedIndexes);
872
+ return wrap(
873
+ arrayMap(rowIds, (rowId) =>
874
+ /* @__PURE__ */ createElement(Row, {
875
+ ...getProps(getRowComponentProps, rowId),
876
+ key: rowId,
877
+ tableId,
878
+ rowId,
879
+ store,
880
+ debugIds,
881
+ }),
882
+ ),
883
+ separator,
884
+ debugIds,
885
+ sliceId,
886
+ );
887
+ };
888
+ const IndexView = ({
889
+ indexId,
890
+ indexes,
891
+ sliceComponent: Slice = SliceView,
892
+ getSliceComponentProps,
893
+ separator,
894
+ debugIds,
895
+ }) =>
896
+ wrap(
897
+ arrayMap(useSliceIds(indexId, indexes), (sliceId) =>
898
+ /* @__PURE__ */ createElement(Slice, {
899
+ ...getProps(getSliceComponentProps, sliceId),
900
+ key: sliceId,
901
+ indexId,
902
+ sliceId,
903
+ indexes,
904
+ debugIds,
905
+ }),
906
+ ),
907
+ separator,
908
+ debugIds,
909
+ indexId,
910
+ );
911
+ const RemoteRowView = ({
912
+ relationshipId,
913
+ localRowId,
914
+ relationships,
915
+ rowComponent: Row = RowView,
916
+ getRowComponentProps,
917
+ debugIds,
918
+ }) => {
919
+ const [resolvedRelationships, store] =
920
+ useRelationshipsStoreTableId(relationships);
921
+ const tableId = resolvedRelationships?.getRemoteTableId(relationshipId);
922
+ const rowId = useRemoteRowId(
923
+ relationshipId,
924
+ localRowId,
925
+ resolvedRelationships,
926
+ );
927
+ return wrap(
928
+ isUndefined(tableId) || isUndefined(rowId)
929
+ ? null
930
+ : /* @__PURE__ */ createElement(Row, {
931
+ ...getProps(getRowComponentProps, rowId),
932
+ key: rowId,
933
+ tableId,
934
+ rowId,
935
+ store,
936
+ debugIds,
937
+ }),
938
+ void 0,
939
+ debugIds,
940
+ localRowId,
941
+ );
942
+ };
943
+ const LocalRowsView = (props) =>
944
+ useComponentPerRow(props, useLocalRowIds, props.remoteRowId);
945
+ const LinkedRowsView = (props) =>
946
+ useComponentPerRow(props, useLinkedRowIds, props.firstRowId);
947
+ const CheckpointView = ({checkpoints, checkpointId, debugIds}) =>
948
+ wrap(
949
+ useCheckpoint(checkpointId, checkpoints) ?? '',
950
+ void 0,
951
+ debugIds,
952
+ checkpointId,
953
+ );
954
+ const BackwardCheckpointsView = getUseCheckpointView(
955
+ (checkpointIds) => checkpointIds[0],
956
+ );
957
+ const CurrentCheckpointView = getUseCheckpointView((checkpointIds) =>
958
+ isUndefined(checkpointIds[1]) ? [] : [checkpointIds[1]],
959
+ );
960
+ const ForwardCheckpointsView = getUseCheckpointView(
961
+ (checkpointIds) => checkpointIds[2],
962
+ );
963
+
964
+ export {
965
+ BackwardCheckpointsView,
966
+ CellView,
967
+ CheckpointView,
968
+ CurrentCheckpointView,
969
+ ForwardCheckpointsView,
970
+ IndexView,
971
+ LinkedRowsView,
972
+ LocalRowsView,
973
+ MetricView,
974
+ Provider,
975
+ RemoteRowView,
976
+ RowView,
977
+ SliceView,
978
+ TableView,
979
+ TablesView,
980
+ useAddRowCallback,
981
+ useCell,
982
+ useCellIds,
983
+ useCellIdsListener,
984
+ useCellListener,
985
+ useCheckpoint,
986
+ useCheckpointIds,
987
+ useCheckpointIdsListener,
988
+ useCheckpointListener,
989
+ useCheckpoints,
990
+ useCreateCheckpoints,
991
+ useCreateIndexes,
992
+ useCreateMetrics,
993
+ useCreatePersister,
994
+ useCreateRelationships,
995
+ useCreateStore,
996
+ useDelCellCallback,
997
+ useDelRowCallback,
998
+ useDelTableCallback,
999
+ useDelTablesCallback,
1000
+ useGoBackwardCallback,
1001
+ useGoForwardCallback,
1002
+ useGoToCallback,
1003
+ useIndexes,
1004
+ useLinkedRowIds,
1005
+ useLinkedRowIdsListener,
1006
+ useLocalRowIds,
1007
+ useLocalRowIdsListener,
1008
+ useMetric,
1009
+ useMetricListener,
1010
+ useMetrics,
1011
+ useRedoInformation,
1012
+ useRelationships,
1013
+ useRemoteRowId,
1014
+ useRemoteRowIdListener,
1015
+ useRow,
1016
+ useRowIds,
1017
+ useRowIdsListener,
1018
+ useRowListener,
1019
+ useSetCellCallback,
1020
+ useSetCheckpointCallback,
1021
+ useSetPartialRowCallback,
1022
+ useSetRowCallback,
1023
+ useSetTableCallback,
1024
+ useSetTablesCallback,
1025
+ useSliceIds,
1026
+ useSliceIdsListener,
1027
+ useSliceRowIds,
1028
+ useSliceRowIdsListener,
1029
+ useStore,
1030
+ useTable,
1031
+ useTableIds,
1032
+ useTableIdsListener,
1033
+ useTableListener,
1034
+ useTables,
1035
+ useTablesListener,
1036
+ useUndoInformation,
1037
+ };