tinybase 7.2.0-beta.1 → 7.2.0-beta.3

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 (44) hide show
  1. package/@types/queries/index.d.ts +333 -4
  2. package/@types/queries/with-schemas/index.d.ts +359 -4
  3. package/@types/ui-react/index.d.ts +484 -15
  4. package/@types/ui-react/with-schemas/index.d.ts +528 -17
  5. package/agents.md +34 -0
  6. package/index.js +67 -12
  7. package/min/index.js +1 -1
  8. package/min/index.js.gz +0 -0
  9. package/min/omni/index.js +1 -1
  10. package/min/omni/index.js.gz +0 -0
  11. package/min/omni/with-schemas/index.js +1 -1
  12. package/min/omni/with-schemas/index.js.gz +0 -0
  13. package/min/queries/index.js +1 -1
  14. package/min/queries/index.js.gz +0 -0
  15. package/min/queries/with-schemas/index.js +1 -1
  16. package/min/queries/with-schemas/index.js.gz +0 -0
  17. package/min/ui-react/index.js +1 -1
  18. package/min/ui-react/index.js.gz +0 -0
  19. package/min/ui-react/with-schemas/index.js +1 -1
  20. package/min/ui-react/with-schemas/index.js.gz +0 -0
  21. package/min/ui-react-dom/index.js +1 -1
  22. package/min/ui-react-dom/index.js.gz +0 -0
  23. package/min/ui-react-dom/with-schemas/index.js +1 -1
  24. package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
  25. package/min/ui-react-inspector/index.js +1 -1
  26. package/min/ui-react-inspector/index.js.gz +0 -0
  27. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  28. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  29. package/min/with-schemas/index.js +1 -1
  30. package/min/with-schemas/index.js.gz +0 -0
  31. package/omni/index.js +161 -45
  32. package/omni/with-schemas/index.js +161 -45
  33. package/package.json +2 -2
  34. package/queries/index.js +80 -15
  35. package/queries/with-schemas/index.js +80 -15
  36. package/readme.md +3 -3
  37. package/releases.md +31 -3
  38. package/ui-react/index.js +98 -33
  39. package/ui-react/with-schemas/index.js +98 -33
  40. package/ui-react-dom/index.js +34 -14
  41. package/ui-react-dom/with-schemas/index.js +34 -14
  42. package/ui-react-inspector/index.js +36 -16
  43. package/ui-react-inspector/with-schemas/index.js +36 -16
  44. package/with-schemas/index.js +67 -12
@@ -78,6 +78,10 @@ const arrayEvery = (array, cb) => array.every(cb);
78
78
  const arrayIsEqual = (array1, array2) =>
79
79
  size(array1) === size(array2) &&
80
80
  arrayEvery(array1, (value1, index) => array2[index] === value1);
81
+ const arrayOrValueEqual = (value1, value2) =>
82
+ isArray(value1) && isArray(value2)
83
+ ? arrayIsEqual(value1, value2)
84
+ : value1 === value2;
81
85
  const arrayIsSorted = (array, sorter) =>
82
86
  arrayEvery(
83
87
  array,
@@ -3221,6 +3225,8 @@ const createQueries = getCreateFunction((store) => {
3221
3225
  const preStore = createStore();
3222
3226
  const resultStore = createStore();
3223
3227
  const preStoreListenerIds = mapNew();
3228
+ const paramValuesListeners = mapNew();
3229
+ const paramValueListeners = mapNew();
3224
3230
  const {
3225
3231
  addListener,
3226
3232
  callListeners,
@@ -3243,7 +3249,7 @@ const createQueries = getCreateFunction((store) => {
3243
3249
  delStoreListeners,
3244
3250
  ] = getDefinableFunctions(
3245
3251
  store,
3246
- () => [() => {}, mapNew()],
3252
+ () => [],
3247
3253
  getUndefined,
3248
3254
  addListener,
3249
3255
  callListeners,
@@ -3614,21 +3620,45 @@ const createQueries = getCreateFunction((store) => {
3614
3620
  return queries;
3615
3621
  };
3616
3622
  const delQueryDefinition = (queryId) => {
3623
+ const oldParamValues = getQueryArgs(queryId)?.[1];
3617
3624
  resetPreStores(queryId);
3618
3625
  delDefinition(queryId);
3626
+ ifNotUndefined(oldParamValues, (paramValues) => {
3627
+ mapForEach(paramValues, (paramId) =>
3628
+ callListeners(paramValueListeners, [queryId, paramId], void 0),
3629
+ );
3630
+ callListeners(paramValuesListeners, [queryId], {});
3631
+ });
3619
3632
  return queries;
3620
3633
  };
3621
3634
  const setParamValues = (queryId, paramValues) => {
3622
- ifNotUndefined(getQueryArgs(queryId), (definition) =>
3623
- resultStore.transaction(() =>
3624
- setQueryDefinition(
3625
- queryId,
3626
- getTableId(queryId),
3627
- definition[0],
3628
- paramValues,
3629
- ),
3630
- ),
3631
- );
3635
+ ifNotUndefined(getQueryArgs(queryId), ([definition, oldParamValues]) => {
3636
+ const changedParamValues = mapNew();
3637
+ mapMatch(
3638
+ oldParamValues,
3639
+ paramValues,
3640
+ (_, paramId, newValue) => {
3641
+ if (!arrayOrValueEqual(newValue, mapGet(oldParamValues, paramId))) {
3642
+ mapSet(changedParamValues, paramId, newValue);
3643
+ }
3644
+ },
3645
+ (_, paramId) => mapSet(changedParamValues, paramId, void 0),
3646
+ );
3647
+ if (!collIsEmpty(changedParamValues)) {
3648
+ resultStore.transaction(() =>
3649
+ setQueryDefinition(
3650
+ queryId,
3651
+ getTableId(queryId),
3652
+ definition,
3653
+ paramValues,
3654
+ ),
3655
+ );
3656
+ mapForEach(changedParamValues, (paramId, value) =>
3657
+ callListeners(paramValueListeners, [queryId, paramId], value),
3658
+ );
3659
+ callListeners(paramValuesListeners, [queryId], {...paramValues});
3660
+ }
3661
+ });
3632
3662
  return queries;
3633
3663
  };
3634
3664
  const setParamValue = (queryId, paramId, value) =>
@@ -3636,8 +3666,25 @@ const createQueries = getCreateFunction((store) => {
3636
3666
  ...mapToObj(getQueryArgs(queryId)?.[1]),
3637
3667
  [paramId]: value,
3638
3668
  });
3669
+ const getParamValues = (queryId) =>
3670
+ ifNotUndefined(getQueryArgs(queryId)?.[1], mapToObj) ?? {};
3671
+ const getParamValue = (queryId, paramId) =>
3672
+ mapGet(getQueryArgs(queryId)?.[1], paramId);
3639
3673
  const addQueryIdsListener = (listener) =>
3640
3674
  addQueryIdsListenerImpl(() => listener(queries));
3675
+ const addParamValuesListener = (queryId, listener) =>
3676
+ addListener(
3677
+ (_, queryId2, paramValues) => listener(queries, queryId2, paramValues),
3678
+ paramValuesListeners,
3679
+ [queryId],
3680
+ );
3681
+ const addParamValueListener = (queryId, paramId, listener) =>
3682
+ addListener(
3683
+ (_, queryId2, paramId2, paramValue) =>
3684
+ listener(queries, queryId2, paramId2, paramValue),
3685
+ paramValueListeners,
3686
+ [queryId, paramId],
3687
+ );
3641
3688
  const delListener = (listenerId) => {
3642
3689
  delListenerImpl(listenerId);
3643
3690
  return queries;
@@ -3649,11 +3696,17 @@ const createQueries = getCreateFunction((store) => {
3649
3696
  transaction: _3,
3650
3697
  ...stats
3651
3698
  } = resultStore.getListenerStats();
3652
- return stats;
3699
+ return {
3700
+ ...stats,
3701
+ paramValues: collSize2(paramValuesListeners),
3702
+ paramValue: collSize3(paramValueListeners),
3703
+ };
3653
3704
  };
3654
3705
  const queries = {
3655
3706
  setQueryDefinition,
3656
3707
  delQueryDefinition,
3708
+ getParamValues,
3709
+ getParamValue,
3657
3710
  setParamValues,
3658
3711
  setParamValue,
3659
3712
  getStore,
@@ -3662,6 +3715,8 @@ const createQueries = getCreateFunction((store) => {
3662
3715
  hasQuery,
3663
3716
  getTableId,
3664
3717
  addQueryIdsListener,
3718
+ addParamValuesListener,
3719
+ addParamValueListener,
3665
3720
  delListener,
3666
3721
  destroy,
3667
3722
  getListenerStats,