tinybase 5.2.2 → 5.3.0-beta.1

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 (43) hide show
  1. package/@types/ui-react/index.d.cts +159 -0
  2. package/@types/ui-react/index.d.ts +159 -0
  3. package/@types/ui-react/with-schemas/index.d.cts +92 -0
  4. package/@types/ui-react/with-schemas/index.d.ts +92 -0
  5. package/cjs/es6/min/ui-react/index.cjs +1 -1
  6. package/cjs/es6/min/ui-react/index.cjs.gz +0 -0
  7. package/cjs/es6/min/ui-react/with-schemas/index.cjs +1 -1
  8. package/cjs/es6/min/ui-react/with-schemas/index.cjs.gz +0 -0
  9. package/cjs/es6/ui-react/index.cjs +89 -29
  10. package/cjs/es6/ui-react/with-schemas/index.cjs +89 -29
  11. package/cjs/min/ui-react/index.cjs +1 -1
  12. package/cjs/min/ui-react/index.cjs.gz +0 -0
  13. package/cjs/min/ui-react/with-schemas/index.cjs +1 -1
  14. package/cjs/min/ui-react/with-schemas/index.cjs.gz +0 -0
  15. package/cjs/ui-react/index.cjs +63 -30
  16. package/cjs/ui-react/with-schemas/index.cjs +63 -30
  17. package/es6/min/ui-react/index.js +1 -1
  18. package/es6/min/ui-react/index.js.gz +0 -0
  19. package/es6/min/ui-react/with-schemas/index.js +1 -1
  20. package/es6/min/ui-react/with-schemas/index.js.gz +0 -0
  21. package/es6/ui-react/index.js +89 -29
  22. package/es6/ui-react/with-schemas/index.js +89 -29
  23. package/min/ui-react/index.js +1 -1
  24. package/min/ui-react/index.js.gz +0 -0
  25. package/min/ui-react/with-schemas/index.js +1 -1
  26. package/min/ui-react/with-schemas/index.js.gz +0 -0
  27. package/package.json +1 -1
  28. package/readme.md +14 -14
  29. package/releases.md +24 -24
  30. package/ui-react/index.js +63 -30
  31. package/ui-react/with-schemas/index.js +63 -30
  32. package/umd/es6/min/ui-react/index.js +1 -1
  33. package/umd/es6/min/ui-react/index.js.gz +0 -0
  34. package/umd/es6/min/ui-react/with-schemas/index.js +1 -1
  35. package/umd/es6/min/ui-react/with-schemas/index.js.gz +0 -0
  36. package/umd/es6/ui-react/index.js +90 -33
  37. package/umd/es6/ui-react/with-schemas/index.js +90 -33
  38. package/umd/min/ui-react/index.js +1 -1
  39. package/umd/min/ui-react/index.js.gz +0 -0
  40. package/umd/min/ui-react/with-schemas/index.js +1 -1
  41. package/umd/min/ui-react/with-schemas/index.js.gz +0 -0
  42. package/umd/ui-react/index.js +65 -30
  43. package/umd/ui-react/with-schemas/index.js +65 -30
@@ -51,6 +51,7 @@
51
51
  const arrayMap = (array, cb) => array.map(cb);
52
52
  const arrayIsEmpty = (array) => size(array) == 0;
53
53
  const arrayFilter = (array, cb) => array.filter(cb);
54
+ const arrayWith = (array, index, value) => array.with(index, value);
54
55
 
55
56
  const object = Object;
56
57
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
@@ -116,33 +117,46 @@
116
117
  ? thing
117
118
  : thingOrThingId;
118
119
  };
120
+ const useProvideThing = (thingId, thing, offset) => {
121
+ const {12: addExtraThingById, 13: delExtraThingById} =
122
+ useContext$1(Context);
123
+ useEffect$1(() => {
124
+ addExtraThingById?.(offset, thingId, thing);
125
+ return () => delExtraThingById?.(offset, thingId);
126
+ }, [addExtraThingById, thingId, thing, offset, delExtraThingById]);
127
+ };
119
128
  const useThingIds = (offset) => objIds(useContext$1(Context)[offset] ?? {});
120
129
  const useStore = (id) => useThing(id, 0);
121
130
  const useStoreOrStoreById = (storeOrStoreId) =>
122
131
  useThingOrThingById(storeOrStoreId, 0);
123
- const useProvideStore = (storeId, store) => {
124
- const {12: addExtraStore, 13: delExtraStore} = useContext$1(Context);
125
- useEffect$1(() => {
126
- addExtraStore?.(storeId, store);
127
- return () => delExtraStore?.(storeId);
128
- }, [addExtraStore, storeId, store, delExtraStore]);
129
- };
132
+ const useProvideStore = (storeId, store) =>
133
+ useProvideThing(storeId, store, 0);
130
134
  const useMetrics = (id) => useThing(id, 2);
131
135
  const useMetricsOrMetricsById = (metricsOrMetricsId) =>
132
136
  useThingOrThingById(metricsOrMetricsId, 2);
137
+ const useProvideMetrics = (metricsId, metrics) =>
138
+ useProvideThing(metricsId, metrics, 1);
133
139
  const useIndexes = (id) => useThing(id, 4);
134
140
  const useIndexesOrIndexesById = (indexesOrIndexesId) =>
135
141
  useThingOrThingById(indexesOrIndexesId, 4);
142
+ const useProvideIndexes = (indexesId, indexes) =>
143
+ useProvideThing(indexesId, indexes, 2);
136
144
  const useRelationships = (id) => useThing(id, 6);
137
145
  const useRelationshipsOrRelationshipsById = (
138
146
  relationshipsOrRelationshipsId,
139
147
  ) => useThingOrThingById(relationshipsOrRelationshipsId, 6);
148
+ const useProvideRelationships = (relationshipsId, relationships) =>
149
+ useProvideThing(relationshipsId, relationships, 3);
140
150
  const useQueries = (id) => useThing(id, 8);
141
151
  const useQueriesOrQueriesById = (queriesOrQueriesId) =>
142
152
  useThingOrThingById(queriesOrQueriesId, 8);
153
+ const useProvideQueries = (queriesId, queries) =>
154
+ useProvideThing(queriesId, queries, 4);
143
155
  const useCheckpoints = (id) => useThing(id, 10);
144
156
  const useCheckpointsOrCheckpointsById = (checkpointsOrCheckpointsId) =>
145
157
  useThingOrThingById(checkpointsOrCheckpointsId, 10);
158
+ const useProvideCheckpoints = (checkpointsId, checkpoints) =>
159
+ useProvideThing(checkpointsId, checkpoints, 5);
146
160
 
147
161
  const lower = (str) => str.toLowerCase();
148
162
  lower(LISTENER);
@@ -1630,21 +1644,37 @@
1630
1644
  children,
1631
1645
  }) => {
1632
1646
  const parentValue = useContext(Context);
1633
- const [extraStoresById, setExtraStoresById] = useState({});
1634
- const addExtraStore = useCallback(
1635
- (id, store2) =>
1636
- setExtraStoresById((extraStoresById2) =>
1637
- objGet(extraStoresById2, id) == store2
1638
- ? extraStoresById2
1639
- : {...extraStoresById2, [id]: store2},
1647
+ const [extraThingsById, setExtraThingsById] = useState([
1648
+ {},
1649
+ {},
1650
+ {},
1651
+ {},
1652
+ {},
1653
+ {},
1654
+ ]);
1655
+ const addExtraThingById = useCallback(
1656
+ (thingOffset, id, thing) =>
1657
+ setExtraThingsById((extraThingsById2) =>
1658
+ objGet(extraThingsById2[thingOffset], id) == thing
1659
+ ? extraThingsById2
1660
+ : arrayWith(extraThingsById2, thingOffset, {
1661
+ ...extraThingsById2[thingOffset],
1662
+ [id]: thing,
1663
+ }),
1640
1664
  ),
1641
1665
  [],
1642
1666
  );
1643
- const delExtraStore = useCallback(
1644
- (id) =>
1645
- setExtraStoresById((extraStoresById2) => ({
1646
- ...objDel(extraStoresById2, id),
1647
- })),
1667
+ const delExtraThingById = useCallback(
1668
+ (thingOffset, id) =>
1669
+ setExtraThingsById((extraThingsById2) =>
1670
+ !objHas(extraThingsById2[thingOffset], id)
1671
+ ? extraThingsById2
1672
+ : arrayWith(
1673
+ extraThingsById2,
1674
+ thingOffset,
1675
+ objDel(extraThingsById2[thingOffset], id),
1676
+ ),
1677
+ ),
1648
1678
  [],
1649
1679
  );
1650
1680
  return /* @__PURE__ */ createElement(
@@ -1653,24 +1683,24 @@
1653
1683
  value: useMemo(
1654
1684
  () => [
1655
1685
  store ?? parentValue[0],
1656
- {...parentValue[1], ...storesById, ...extraStoresById},
1686
+ {...parentValue[1], ...storesById, ...extraThingsById[0]},
1657
1687
  metrics ?? parentValue[2],
1658
- {...parentValue[3], ...metricsById},
1688
+ {...parentValue[3], ...metricsById, ...extraThingsById[1]},
1659
1689
  indexes ?? parentValue[4],
1660
- {...parentValue[5], ...indexesById},
1690
+ {...parentValue[5], ...indexesById, ...extraThingsById[2]},
1661
1691
  relationships ?? parentValue[6],
1662
- {...parentValue[7], ...relationshipsById},
1692
+ {...parentValue[7], ...relationshipsById, ...extraThingsById[3]},
1663
1693
  queries ?? parentValue[8],
1664
- {...parentValue[9], ...queriesById},
1694
+ {...parentValue[9], ...queriesById, ...extraThingsById[4]},
1665
1695
  checkpoints ?? parentValue[10],
1666
- {...parentValue[11], ...checkpointsById},
1667
- addExtraStore,
1668
- delExtraStore,
1696
+ {...parentValue[11], ...checkpointsById, ...extraThingsById[5]},
1697
+ addExtraThingById,
1698
+ delExtraThingById,
1669
1699
  ],
1670
1700
  [
1671
1701
  store,
1672
1702
  storesById,
1673
- extraStoresById,
1703
+ extraThingsById,
1674
1704
  metrics,
1675
1705
  metricsById,
1676
1706
  indexes,
@@ -1682,8 +1712,8 @@
1682
1712
  checkpoints,
1683
1713
  checkpointsById,
1684
1714
  parentValue,
1685
- addExtraStore,
1686
- delExtraStore,
1715
+ addExtraThingById,
1716
+ delExtraThingById,
1687
1717
  ],
1688
1718
  ),
1689
1719
  },
@@ -2046,6 +2076,11 @@
2046
2076
  exports.useMetrics = useMetrics;
2047
2077
  exports.useMetricsIds = useMetricsIds;
2048
2078
  exports.useMetricsOrMetricsById = useMetricsOrMetricsById;
2079
+ exports.useProvideCheckpoints = useProvideCheckpoints;
2080
+ exports.useProvideIndexes = useProvideIndexes;
2081
+ exports.useProvideMetrics = useProvideMetrics;
2082
+ exports.useProvideQueries = useProvideQueries;
2083
+ exports.useProvideRelationships = useProvideRelationships;
2049
2084
  exports.useProvideStore = useProvideStore;
2050
2085
  exports.useQueries = useQueries;
2051
2086
  exports.useQueriesIds = useQueriesIds;
@@ -51,6 +51,7 @@
51
51
  const arrayMap = (array, cb) => array.map(cb);
52
52
  const arrayIsEmpty = (array) => size(array) == 0;
53
53
  const arrayFilter = (array, cb) => array.filter(cb);
54
+ const arrayWith = (array, index, value) => array.with(index, value);
54
55
 
55
56
  const object = Object;
56
57
  const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
@@ -116,33 +117,46 @@
116
117
  ? thing
117
118
  : thingOrThingId;
118
119
  };
120
+ const useProvideThing = (thingId, thing, offset) => {
121
+ const {12: addExtraThingById, 13: delExtraThingById} =
122
+ useContext$1(Context);
123
+ useEffect$1(() => {
124
+ addExtraThingById?.(offset, thingId, thing);
125
+ return () => delExtraThingById?.(offset, thingId);
126
+ }, [addExtraThingById, thingId, thing, offset, delExtraThingById]);
127
+ };
119
128
  const useThingIds = (offset) => objIds(useContext$1(Context)[offset] ?? {});
120
129
  const useStore = (id) => useThing(id, 0);
121
130
  const useStoreOrStoreById = (storeOrStoreId) =>
122
131
  useThingOrThingById(storeOrStoreId, 0);
123
- const useProvideStore = (storeId, store) => {
124
- const {12: addExtraStore, 13: delExtraStore} = useContext$1(Context);
125
- useEffect$1(() => {
126
- addExtraStore?.(storeId, store);
127
- return () => delExtraStore?.(storeId);
128
- }, [addExtraStore, storeId, store, delExtraStore]);
129
- };
132
+ const useProvideStore = (storeId, store) =>
133
+ useProvideThing(storeId, store, 0);
130
134
  const useMetrics = (id) => useThing(id, 2);
131
135
  const useMetricsOrMetricsById = (metricsOrMetricsId) =>
132
136
  useThingOrThingById(metricsOrMetricsId, 2);
137
+ const useProvideMetrics = (metricsId, metrics) =>
138
+ useProvideThing(metricsId, metrics, 1);
133
139
  const useIndexes = (id) => useThing(id, 4);
134
140
  const useIndexesOrIndexesById = (indexesOrIndexesId) =>
135
141
  useThingOrThingById(indexesOrIndexesId, 4);
142
+ const useProvideIndexes = (indexesId, indexes) =>
143
+ useProvideThing(indexesId, indexes, 2);
136
144
  const useRelationships = (id) => useThing(id, 6);
137
145
  const useRelationshipsOrRelationshipsById = (
138
146
  relationshipsOrRelationshipsId,
139
147
  ) => useThingOrThingById(relationshipsOrRelationshipsId, 6);
148
+ const useProvideRelationships = (relationshipsId, relationships) =>
149
+ useProvideThing(relationshipsId, relationships, 3);
140
150
  const useQueries = (id) => useThing(id, 8);
141
151
  const useQueriesOrQueriesById = (queriesOrQueriesId) =>
142
152
  useThingOrThingById(queriesOrQueriesId, 8);
153
+ const useProvideQueries = (queriesId, queries) =>
154
+ useProvideThing(queriesId, queries, 4);
143
155
  const useCheckpoints = (id) => useThing(id, 10);
144
156
  const useCheckpointsOrCheckpointsById = (checkpointsOrCheckpointsId) =>
145
157
  useThingOrThingById(checkpointsOrCheckpointsId, 10);
158
+ const useProvideCheckpoints = (checkpointsId, checkpoints) =>
159
+ useProvideThing(checkpointsId, checkpoints, 5);
146
160
 
147
161
  const lower = (str) => str.toLowerCase();
148
162
  lower(LISTENER);
@@ -1630,21 +1644,37 @@
1630
1644
  children,
1631
1645
  }) => {
1632
1646
  const parentValue = useContext(Context);
1633
- const [extraStoresById, setExtraStoresById] = useState({});
1634
- const addExtraStore = useCallback(
1635
- (id, store2) =>
1636
- setExtraStoresById((extraStoresById2) =>
1637
- objGet(extraStoresById2, id) == store2
1638
- ? extraStoresById2
1639
- : {...extraStoresById2, [id]: store2},
1647
+ const [extraThingsById, setExtraThingsById] = useState([
1648
+ {},
1649
+ {},
1650
+ {},
1651
+ {},
1652
+ {},
1653
+ {},
1654
+ ]);
1655
+ const addExtraThingById = useCallback(
1656
+ (thingOffset, id, thing) =>
1657
+ setExtraThingsById((extraThingsById2) =>
1658
+ objGet(extraThingsById2[thingOffset], id) == thing
1659
+ ? extraThingsById2
1660
+ : arrayWith(extraThingsById2, thingOffset, {
1661
+ ...extraThingsById2[thingOffset],
1662
+ [id]: thing,
1663
+ }),
1640
1664
  ),
1641
1665
  [],
1642
1666
  );
1643
- const delExtraStore = useCallback(
1644
- (id) =>
1645
- setExtraStoresById((extraStoresById2) => ({
1646
- ...objDel(extraStoresById2, id),
1647
- })),
1667
+ const delExtraThingById = useCallback(
1668
+ (thingOffset, id) =>
1669
+ setExtraThingsById((extraThingsById2) =>
1670
+ !objHas(extraThingsById2[thingOffset], id)
1671
+ ? extraThingsById2
1672
+ : arrayWith(
1673
+ extraThingsById2,
1674
+ thingOffset,
1675
+ objDel(extraThingsById2[thingOffset], id),
1676
+ ),
1677
+ ),
1648
1678
  [],
1649
1679
  );
1650
1680
  return /* @__PURE__ */ createElement(
@@ -1653,24 +1683,24 @@
1653
1683
  value: useMemo(
1654
1684
  () => [
1655
1685
  store ?? parentValue[0],
1656
- {...parentValue[1], ...storesById, ...extraStoresById},
1686
+ {...parentValue[1], ...storesById, ...extraThingsById[0]},
1657
1687
  metrics ?? parentValue[2],
1658
- {...parentValue[3], ...metricsById},
1688
+ {...parentValue[3], ...metricsById, ...extraThingsById[1]},
1659
1689
  indexes ?? parentValue[4],
1660
- {...parentValue[5], ...indexesById},
1690
+ {...parentValue[5], ...indexesById, ...extraThingsById[2]},
1661
1691
  relationships ?? parentValue[6],
1662
- {...parentValue[7], ...relationshipsById},
1692
+ {...parentValue[7], ...relationshipsById, ...extraThingsById[3]},
1663
1693
  queries ?? parentValue[8],
1664
- {...parentValue[9], ...queriesById},
1694
+ {...parentValue[9], ...queriesById, ...extraThingsById[4]},
1665
1695
  checkpoints ?? parentValue[10],
1666
- {...parentValue[11], ...checkpointsById},
1667
- addExtraStore,
1668
- delExtraStore,
1696
+ {...parentValue[11], ...checkpointsById, ...extraThingsById[5]},
1697
+ addExtraThingById,
1698
+ delExtraThingById,
1669
1699
  ],
1670
1700
  [
1671
1701
  store,
1672
1702
  storesById,
1673
- extraStoresById,
1703
+ extraThingsById,
1674
1704
  metrics,
1675
1705
  metricsById,
1676
1706
  indexes,
@@ -1682,8 +1712,8 @@
1682
1712
  checkpoints,
1683
1713
  checkpointsById,
1684
1714
  parentValue,
1685
- addExtraStore,
1686
- delExtraStore,
1715
+ addExtraThingById,
1716
+ delExtraThingById,
1687
1717
  ],
1688
1718
  ),
1689
1719
  },
@@ -2046,6 +2076,11 @@
2046
2076
  exports.useMetrics = useMetrics;
2047
2077
  exports.useMetricsIds = useMetricsIds;
2048
2078
  exports.useMetricsOrMetricsById = useMetricsOrMetricsById;
2079
+ exports.useProvideCheckpoints = useProvideCheckpoints;
2080
+ exports.useProvideIndexes = useProvideIndexes;
2081
+ exports.useProvideMetrics = useProvideMetrics;
2082
+ exports.useProvideQueries = useProvideQueries;
2083
+ exports.useProvideRelationships = useProvideRelationships;
2049
2084
  exports.useProvideStore = useProvideStore;
2050
2085
  exports.useQueries = useQueries;
2051
2086
  exports.useQueriesIds = useQueriesIds;