tinybase 9.1.0-beta.1 → 9.1.0-beta.2

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 (80) hide show
  1. package/@types/_internal/store/with-schemas/index.d.ts +133 -2
  2. package/@types/indexes/index.d.ts +97 -0
  3. package/@types/indexes/with-schemas/index.d.ts +137 -0
  4. package/@types/store/index.d.ts +96 -18
  5. package/@types/store/with-schemas/index.d.ts +107 -44
  6. package/@types/ui-react/index.d.ts +42 -0
  7. package/@types/ui-react/with-schemas/index.d.ts +101 -32
  8. package/@types/ui-solid/index.d.ts +42 -0
  9. package/@types/ui-solid/with-schemas/index.d.ts +101 -32
  10. package/@types/ui-svelte/index.d.ts +34 -0
  11. package/@types/ui-svelte/with-schemas/index.d.ts +34 -0
  12. package/index.js +121 -32
  13. package/indexes/index.js +39 -0
  14. package/indexes/with-schemas/index.js +39 -0
  15. package/mergeable-store/index.js +82 -32
  16. package/mergeable-store/with-schemas/index.js +82 -32
  17. package/min/index.js +1 -1
  18. package/min/index.js.gz +0 -0
  19. package/min/indexes/index.js +1 -1
  20. package/min/indexes/index.js.gz +0 -0
  21. package/min/indexes/with-schemas/index.js +1 -1
  22. package/min/indexes/with-schemas/index.js.gz +0 -0
  23. package/min/mergeable-store/index.js +1 -1
  24. package/min/mergeable-store/index.js.gz +0 -0
  25. package/min/mergeable-store/with-schemas/index.js +1 -1
  26. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  27. package/min/omni/index.js +1 -1
  28. package/min/omni/index.js.gz +0 -0
  29. package/min/omni/with-schemas/index.js +1 -1
  30. package/min/omni/with-schemas/index.js.gz +0 -0
  31. package/min/store/index.js +1 -1
  32. package/min/store/index.js.gz +0 -0
  33. package/min/store/with-schemas/index.js +1 -1
  34. package/min/store/with-schemas/index.js.gz +0 -0
  35. package/min/ui-react/index.js +1 -1
  36. package/min/ui-react/index.js.gz +0 -0
  37. package/min/ui-react/with-schemas/index.js +1 -1
  38. package/min/ui-react/with-schemas/index.js.gz +0 -0
  39. package/min/ui-react-inspector/index.js +1 -1
  40. package/min/ui-react-inspector/index.js.gz +0 -0
  41. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  42. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  43. package/min/ui-solid/index.js +1 -1
  44. package/min/ui-solid/index.js.gz +0 -0
  45. package/min/ui-solid/with-schemas/index.js +1 -1
  46. package/min/ui-solid/with-schemas/index.js.gz +0 -0
  47. package/min/ui-solid-inspector/index.js +1 -1
  48. package/min/ui-solid-inspector/index.js.gz +0 -0
  49. package/min/ui-solid-inspector/with-schemas/index.js +1 -1
  50. package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
  51. package/min/ui-svelte/index.js +1 -1
  52. package/min/ui-svelte/index.js.gz +0 -0
  53. package/min/ui-svelte/with-schemas/index.js +1 -1
  54. package/min/ui-svelte/with-schemas/index.js.gz +0 -0
  55. package/min/ui-svelte-inspector/index.js +1 -1
  56. package/min/ui-svelte-inspector/index.js.gz +0 -0
  57. package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
  58. package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
  59. package/min/with-schemas/index.js +1 -1
  60. package/min/with-schemas/index.js.gz +0 -0
  61. package/omni/index.js +121 -32
  62. package/omni/with-schemas/index.js +121 -32
  63. package/package.json +2 -2
  64. package/readme.md +14 -14
  65. package/releases.md +101 -60
  66. package/store/index.js +82 -32
  67. package/store/with-schemas/index.js +82 -32
  68. package/ui-react/index.js +16 -0
  69. package/ui-react/with-schemas/index.js +16 -0
  70. package/ui-react-inspector/index.js +82 -32
  71. package/ui-react-inspector/with-schemas/index.js +82 -32
  72. package/ui-solid/index.js +16 -0
  73. package/ui-solid/with-schemas/index.js +16 -0
  74. package/ui-solid-inspector/index.js +82 -32
  75. package/ui-solid-inspector/with-schemas/index.js +82 -32
  76. package/ui-svelte/index.js +18 -0
  77. package/ui-svelte/with-schemas/index.js +18 -0
  78. package/ui-svelte-inspector/index.js +82 -32
  79. package/ui-svelte-inspector/with-schemas/index.js +82 -32
  80. package/with-schemas/index.js +121 -32
@@ -143,6 +143,8 @@ import type {
143
143
  MapCell,
144
144
  MapValue,
145
145
  OptionalSchemas,
146
+ PartialRow,
147
+ PartialValues,
146
148
  Row,
147
149
  RowCountListener,
148
150
  RowIdsListener,
@@ -2691,13 +2693,13 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
2691
2693
  * @category Store primitives
2692
2694
  * @since v8.3.0
2693
2695
  */
2694
- useSetTablesCallback: <Parameter, SetTables = Tables<Schemas[0], true>>(
2696
+ useSetTablesCallback: <Parameter>(
2695
2697
  getTables: (
2696
2698
  parameter: Parameter,
2697
2699
  store: Store<Schemas>,
2698
- ) => NoInfer<SetTables>,
2700
+ ) => Tables<Schemas[0], true>,
2699
2701
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
2700
- then?: (store: Store<Schemas>, tables: SetTables) => void,
2702
+ then?: (store: Store<Schemas>, tables: Tables<Schemas[0], true>) => void,
2701
2703
  ) => ParameterizedCallback<Parameter>;
2702
2704
 
2703
2705
  /**
@@ -2803,15 +2805,17 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
2803
2805
  useSetTableCallback: <
2804
2806
  Parameter,
2805
2807
  TableId extends TableIdFromSchema<Schemas[0]>,
2806
- SetTable = Table<Schemas[0], TableId, true>,
2807
2808
  >(
2808
2809
  tableId: MaybeAccessor<TableId> | GetId<Schemas, Parameter, TableId>,
2809
2810
  getTable: (
2810
2811
  parameter: Parameter,
2811
2812
  store: Store<Schemas>,
2812
- ) => NoInfer<SetTable>,
2813
+ ) => Table<Schemas[0], TableId, true>,
2813
2814
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
2814
- then?: (store: Store<Schemas>, table: SetTable) => void,
2815
+ then?: (
2816
+ store: Store<Schemas>,
2817
+ table: Table<Schemas[0], TableId, true>,
2818
+ ) => void,
2815
2819
  ) => ParameterizedCallback<Parameter>;
2816
2820
 
2817
2821
  /**
@@ -2917,16 +2921,15 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
2917
2921
  * @category Store primitives
2918
2922
  * @since v8.3.0
2919
2923
  */
2920
- useSetRowCallback: <
2921
- Parameter,
2922
- TableId extends TableIdFromSchema<Schemas[0]>,
2923
- SetRow = Row<Schemas[0], TableId, true>,
2924
- >(
2924
+ useSetRowCallback: <Parameter, TableId extends TableIdFromSchema<Schemas[0]>>(
2925
2925
  tableId: MaybeAccessor<TableId> | GetId<Schemas, Parameter, TableId>,
2926
2926
  rowId: MaybeAccessor<Id> | GetId<Schemas, Parameter, Id>,
2927
- getRow: (parameter: Parameter, store: Store<Schemas>) => NoInfer<SetRow>,
2927
+ getRow: (
2928
+ parameter: Parameter,
2929
+ store: Store<Schemas>,
2930
+ ) => Row<Schemas[0], TableId, true>,
2928
2931
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
2929
- then?: (store: Store<Schemas>, row: SetRow) => void,
2932
+ then?: (store: Store<Schemas>, row: Row<Schemas[0], TableId, true>) => void,
2930
2933
  ) => ParameterizedCallback<Parameter>;
2931
2934
 
2932
2935
  /**
@@ -3039,15 +3042,18 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
3039
3042
  * @category Store primitives
3040
3043
  * @since v8.3.0
3041
3044
  */
3042
- useAddRowCallback: <
3043
- Parameter,
3044
- TableId extends TableIdFromSchema<Schemas[0]>,
3045
- AddRow = Row<Schemas[0], TableId, true>,
3046
- >(
3045
+ useAddRowCallback: <Parameter, TableId extends TableIdFromSchema<Schemas[0]>>(
3047
3046
  tableId: MaybeAccessor<TableId> | GetId<Schemas, Parameter, TableId>,
3048
- getRow: (parameter: Parameter, store: Store<Schemas>) => NoInfer<AddRow>,
3047
+ getRow: (
3048
+ parameter: Parameter,
3049
+ store: Store<Schemas>,
3050
+ ) => Row<Schemas[0], TableId, true>,
3049
3051
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
3050
- then?: (rowId: Id | undefined, store: Store<Schemas>, row: AddRow) => void,
3052
+ then?: (
3053
+ rowId: Id | undefined,
3054
+ store: Store<Schemas>,
3055
+ row: Row<Schemas[0], TableId, true>,
3056
+ ) => void,
3051
3057
  reuseRowIds?: boolean,
3052
3058
  ) => ParameterizedCallback<Parameter>;
3053
3059
 
@@ -3158,16 +3164,18 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
3158
3164
  useSetPartialRowCallback: <
3159
3165
  Parameter,
3160
3166
  TableId extends TableIdFromSchema<Schemas[0]>,
3161
- SetPartialRow = Row<Schemas[0], TableId, true>,
3162
3167
  >(
3163
3168
  tableId: MaybeAccessor<TableId> | GetId<Schemas, Parameter, TableId>,
3164
3169
  rowId: MaybeAccessor<Id> | GetId<Schemas, Parameter, Id>,
3165
3170
  getPartialRow: (
3166
3171
  parameter: Parameter,
3167
3172
  store: Store<Schemas>,
3168
- ) => NoInfer<SetPartialRow>,
3173
+ ) => PartialRow<Schemas[0], TableId>,
3169
3174
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
3170
- then?: (store: Store<Schemas>, partialRow: SetPartialRow) => void,
3175
+ then?: (
3176
+ store: Store<Schemas>,
3177
+ partialRow: PartialRow<Schemas[0], TableId>,
3178
+ ) => void,
3171
3179
  ) => ParameterizedCallback<Parameter>;
3172
3180
 
3173
3181
  /**
@@ -3353,13 +3361,13 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
3353
3361
  * @category Store primitives
3354
3362
  * @since v8.3.0
3355
3363
  */
3356
- useSetValuesCallback: <Parameter, SetValues = Values<Schemas[1], true>>(
3364
+ useSetValuesCallback: <Parameter>(
3357
3365
  getValues: (
3358
3366
  parameter: Parameter,
3359
3367
  store: Store<Schemas>,
3360
- ) => NoInfer<SetValues>,
3368
+ ) => Values<Schemas[1], true>,
3361
3369
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
3362
- then?: (store: Store<Schemas>, values: SetValues) => void,
3370
+ then?: (store: Store<Schemas>, values: Values<Schemas[1], true>) => void,
3363
3371
  ) => ParameterizedCallback<Parameter>;
3364
3372
 
3365
3373
  /**
@@ -3460,16 +3468,16 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
3460
3468
  * @category Store primitives
3461
3469
  * @since v8.3.0
3462
3470
  */
3463
- useSetPartialValuesCallback: <
3464
- Parameter,
3465
- SetPartialValues = Values<Schemas[1], true>,
3466
- >(
3471
+ useSetPartialValuesCallback: <Parameter>(
3467
3472
  getPartialValues: (
3468
3473
  parameter: Parameter,
3469
3474
  store: Store<Schemas>,
3470
- ) => NoInfer<SetPartialValues>,
3475
+ ) => PartialValues<Schemas[1]>,
3471
3476
  storeOrStoreId?: MaybeAccessor<StoreOrStoreId<Schemas> | undefined>,
3472
- then?: (store: Store<Schemas>, partialValues: SetPartialValues) => void,
3477
+ then?: (
3478
+ store: Store<Schemas>,
3479
+ partialValues: PartialValues<Schemas[1]>,
3480
+ ) => void,
3473
3481
  ) => ParameterizedCallback<Parameter>;
3474
3482
 
3475
3483
  /**
@@ -7827,6 +7835,35 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
7827
7835
  indexesOrIndexesId?: MaybeAccessor<IndexesOrIndexesId<Schemas> | undefined>,
7828
7836
  ): Accessor<Ids>;
7829
7837
 
7838
+ /**
7839
+ * The useHasIndex primitive returns a boolean indicating whether a given Index
7840
+ * exists in the Indexes object, and registers a listener so that any changes to
7841
+ * that result will cause an update.
7842
+ *
7843
+ * This has schema-based typing. The following is a simplified representation:
7844
+ *
7845
+ * ```ts override
7846
+ * useHasIndex(
7847
+ * indexId: MaybeAccessor<Id>,
7848
+ * indexesOrIndexesId?: MaybeAccessor<IndexesOrIndexesId | undefined>,
7849
+ * ): Accessor<boolean>;
7850
+ * ```
7851
+ *
7852
+ * This primitive follows the same Indexes object resolution rules as the
7853
+ * useIndexIds primitive.
7854
+ * @param indexId The Id of a possible Index in the Indexes object.
7855
+ * @param indexesOrIndexesId The Indexes object to be accessed: omit for the
7856
+ * default context Indexes object, provide an Id for a named context Indexes
7857
+ * object, or provide an explicit reference.
7858
+ * @returns Whether an Index with that Id exists.
7859
+ * @category Indexes primitives
7860
+ * @since v9.1.0
7861
+ */
7862
+ useHasIndex: (
7863
+ indexId: MaybeAccessor<Id>,
7864
+ indexesOrIndexesId?: MaybeAccessor<IndexesOrIndexesId<Schemas> | undefined>,
7865
+ ) => Accessor<boolean>;
7866
+
7830
7867
  /**
7831
7868
  * The useSliceIds primitive gets the list of Slice Ids in an Index, and
7832
7869
  * registers a listener so that any changes to that result will cause an update.
@@ -7923,6 +7960,38 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
7923
7960
  indexesOrIndexesId?: MaybeAccessor<IndexesOrIndexesId<Schemas> | undefined>,
7924
7961
  ) => Accessor<Ids>;
7925
7962
 
7963
+ /**
7964
+ * The useHasSlice primitive returns a boolean indicating whether a given Slice
7965
+ * exists in an Index, and registers a listener so that any changes to that
7966
+ * result will cause an update.
7967
+ *
7968
+ * This has schema-based typing. The following is a simplified representation:
7969
+ *
7970
+ * ```ts override
7971
+ * useHasSlice(
7972
+ * indexId: MaybeAccessor<Id>,
7973
+ * sliceId: MaybeAccessor<Id>,
7974
+ * indexesOrIndexesId?: MaybeAccessor<IndexesOrIndexesId | undefined>,
7975
+ * ): Accessor<boolean>;
7976
+ * ```
7977
+ *
7978
+ * This primitive follows the same Indexes object resolution rules as the
7979
+ * useSliceIds primitive.
7980
+ * @param indexId The Id of a possible Index in the Indexes object.
7981
+ * @param sliceId The Id of a possible Slice in the Index.
7982
+ * @param indexesOrIndexesId The Indexes object to be accessed: omit for the
7983
+ * default context Indexes object, provide an Id for a named context Indexes
7984
+ * object, or provide an explicit reference.
7985
+ * @returns Whether a Slice with that Id exists.
7986
+ * @category Indexes primitives
7987
+ * @since v9.1.0
7988
+ */
7989
+ useHasSlice: (
7990
+ indexId: MaybeAccessor<Id>,
7991
+ sliceId: MaybeAccessor<Id>,
7992
+ indexesOrIndexesId?: MaybeAccessor<IndexesOrIndexesId<Schemas> | undefined>,
7993
+ ) => Accessor<boolean>;
7994
+
7926
7995
  /**
7927
7996
  * The useSliceRowIds primitive gets the list of Row Ids in a given Slice, and
7928
7997
  * registers a listener so that any changes to that result will cause an update.
@@ -4237,6 +4237,22 @@ export function getIndexIds(
4237
4237
  readonly current: Ids;
4238
4238
  };
4239
4239
 
4240
+ /**
4241
+ * The hasIndex function returns a reactive object reflecting whether a given
4242
+ * Index exists in the Indexes object, and registers a listener so that any
4243
+ * changes will update `current`.
4244
+ * @param indexId The Id of the possible Index (or a getter returning it).
4245
+ * @param indexesOrIndexesId The Indexes object to use (plain or getter), or its
4246
+ * Id.
4247
+ * @returns A reactive object with a `current` boolean property.
4248
+ * @category Getter
4249
+ * @since v9.1.0
4250
+ */
4251
+ export function hasIndex(
4252
+ indexId: MaybeGetter<Id>,
4253
+ indexesOrIndexesId?: MaybeGetter<IndexesOrIndexesId | undefined>,
4254
+ ): {readonly current: boolean};
4255
+
4240
4256
  /**
4241
4257
  * The getSliceIds function returns a reactive object reflecting the Ids of the
4242
4258
  * Slices in an Index, and registers a listener so that any changes will update
@@ -4295,6 +4311,24 @@ export function getSliceIds(
4295
4311
  indexesOrIndexesId?: MaybeGetter<IndexesOrIndexesId | undefined>,
4296
4312
  ): {readonly current: Ids};
4297
4313
 
4314
+ /**
4315
+ * The hasSlice function returns a reactive object reflecting whether a given
4316
+ * Slice exists in an Index, and registers a listener so that any changes will
4317
+ * update `current`.
4318
+ * @param indexId The Id of the Index (or a getter returning it).
4319
+ * @param sliceId The Id of the possible Slice (or a getter returning it).
4320
+ * @param indexesOrIndexesId The Indexes object to use (plain or getter), or its
4321
+ * Id.
4322
+ * @returns A reactive object with a `current` boolean property.
4323
+ * @category Getter
4324
+ * @since v9.1.0
4325
+ */
4326
+ export function hasSlice(
4327
+ indexId: MaybeGetter<Id>,
4328
+ sliceId: MaybeGetter<Id>,
4329
+ indexesOrIndexesId?: MaybeGetter<IndexesOrIndexesId | undefined>,
4330
+ ): {readonly current: boolean};
4331
+
4298
4332
  /**
4299
4333
  * The getSliceRowIds function returns a reactive object reflecting the Ids of
4300
4334
  * the Rows in a Slice, and registers a listener so that any changes will update
@@ -4718,6 +4718,22 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
4718
4718
  readonly current: Ids;
4719
4719
  };
4720
4720
 
4721
+ /**
4722
+ * The hasIndex function returns a reactive object reflecting whether a given
4723
+ * Index exists in the Indexes object, and registers a listener so that any
4724
+ * changes will update `current`.
4725
+ * @param indexId The Id of the possible Index (or a getter returning it).
4726
+ * @param indexesOrIndexesId The Indexes object to use (plain or getter), or its
4727
+ * Id.
4728
+ * @returns A reactive object with a `current` boolean property.
4729
+ * @category Getter
4730
+ * @since v9.1.0
4731
+ */
4732
+ hasIndex: (
4733
+ indexId: MaybeGetter<Id>,
4734
+ indexesOrIndexesId?: MaybeGetter<IndexesOrIndexesId<Schemas> | undefined>,
4735
+ ) => {readonly current: boolean};
4736
+
4721
4737
  /**
4722
4738
  * The getSliceIds function returns a reactive object reflecting the Ids of the
4723
4739
  * Slices in an Index, and registers a listener so that any changes will update
@@ -4785,6 +4801,24 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
4785
4801
  indexesOrIndexesId?: IndexesOrIndexesId<Schemas>,
4786
4802
  ) => {readonly current: Ids};
4787
4803
 
4804
+ /**
4805
+ * The hasSlice function returns a reactive object reflecting whether a given
4806
+ * Slice exists in an Index, and registers a listener so that any changes will
4807
+ * update `current`.
4808
+ * @param indexId The Id of the Index (or a getter returning it).
4809
+ * @param sliceId The Id of the possible Slice (or a getter returning it).
4810
+ * @param indexesOrIndexesId The Indexes object to use (plain or getter), or its
4811
+ * Id.
4812
+ * @returns A reactive object with a `current` boolean property.
4813
+ * @category Getter
4814
+ * @since v9.1.0
4815
+ */
4816
+ hasSlice: (
4817
+ indexId: MaybeGetter<Id>,
4818
+ sliceId: MaybeGetter<Id>,
4819
+ indexesOrIndexesId?: IndexesOrIndexesId<Schemas>,
4820
+ ) => {readonly current: boolean};
4821
+
4788
4822
  /**
4789
4823
  * The getSliceRowIds function returns a reactive object reflecting the Ids of
4790
4824
  * the Rows in a Slice, and registers a listener so that any changes will update
package/index.js CHANGED
@@ -35,6 +35,7 @@ const VALUE = 'Value';
35
35
  const VALUES = VALUE + 's';
36
36
  const VALUE_IDS = VALUE + IDS;
37
37
  const TRANSACTION = 'Transaction';
38
+ const REQUIRED = 'required';
38
39
  const JSON_PREFIX = '\uFFFD';
39
40
  const id = (key) => EMPTY_STRING + key;
40
41
  const strStartsWith = (str, prefix) => str.startsWith(prefix);
@@ -929,7 +930,9 @@ const defaultSorter = (sortKey1, sortKey2) =>
929
930
  (sortKey1 ?? 0) < (sortKey2 ?? 0) ? -1 : 1;
930
931
 
931
932
  const createIndexes = getCreateFunction((store) => {
933
+ const hasIndexListeners = mapNew();
932
934
  const sliceIdsListeners = mapNew();
935
+ const hasSliceListeners = mapNew();
933
936
  const sliceRowIdsListeners = mapNew();
934
937
  const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
935
938
  () => indexes,
@@ -968,6 +971,7 @@ const createIndexes = getCreateFunction((store) => {
968
971
  sliceIdSorter,
969
972
  rowIdSorter = defaultSorter,
970
973
  ) => {
974
+ const hadIndex = hasIndex(indexId);
971
975
  const sliceIdArraySorter = isUndefined(sliceIdSorter)
972
976
  ? void 0
973
977
  : ([id1], [id2]) => sliceIdSorter(id1, id2);
@@ -984,8 +988,14 @@ const createIndexes = getCreateFunction((store) => {
984
988
  ) => {
985
989
  let sliceIdsChanged = 0;
986
990
  const changedSlices = setNew();
991
+ const hadSlices = mapNew();
987
992
  const unsortedSlices = setNew();
988
993
  const index = getIndex(indexId);
994
+ const setHadSlice = (sliceId) => {
995
+ if (!collHas(hadSlices, sliceId)) {
996
+ mapSet(hadSlices, sliceId, collHas(index, sliceId));
997
+ }
998
+ };
989
999
  collForEach(
990
1000
  changedSliceIds,
991
1001
  ([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
@@ -997,6 +1007,7 @@ const createIndexes = getCreateFunction((store) => {
997
1007
  : 0,
998
1008
  );
999
1009
  collForEach(oldSliceIds, (oldSliceId) => {
1010
+ setHadSlice(oldSliceId);
1000
1011
  setAdd(changedSlices, oldSliceId);
1001
1012
  ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
1002
1013
  collDel(oldSlice, rowId);
@@ -1007,6 +1018,7 @@ const createIndexes = getCreateFunction((store) => {
1007
1018
  });
1008
1019
  });
1009
1020
  collForEach(newSliceIds, (newSliceId) => {
1021
+ setHadSlice(newSliceId);
1010
1022
  setAdd(changedSlices, newSliceId);
1011
1023
  if (!collHas(index, newSliceId)) {
1012
1024
  mapSet(index, newSliceId, setNew());
@@ -1068,6 +1080,12 @@ const createIndexes = getCreateFunction((store) => {
1068
1080
  if (sliceIdsChanged) {
1069
1081
  callListeners(sliceIdsListeners, [indexId]);
1070
1082
  }
1083
+ mapForEach(hadSlices, (sliceId, hadSlice) => {
1084
+ const hasSliceNow = collHas(index, sliceId);
1085
+ if (hadSlice != hasSliceNow) {
1086
+ callListeners(hasSliceListeners, [indexId, sliceId], hasSliceNow);
1087
+ }
1088
+ });
1071
1089
  collForEach(changedSlices, (sliceId) =>
1072
1090
  callListeners(sliceRowIdsListeners, [indexId, sliceId]),
1073
1091
  );
@@ -1075,6 +1093,9 @@ const createIndexes = getCreateFunction((store) => {
1075
1093
  getRowCellFunction(getSliceIdOrIds),
1076
1094
  ifNotUndefined(getSortKey, getRowCellFunction),
1077
1095
  );
1096
+ if (!hadIndex) {
1097
+ callListeners(hasIndexListeners, [indexId], true);
1098
+ }
1078
1099
  return indexes;
1079
1100
  };
1080
1101
  const forEachIndex = (indexCallback) =>
@@ -1098,7 +1119,20 @@ const createIndexes = getCreateFunction((store) => {
1098
1119
  );
1099
1120
  };
1100
1121
  const delIndexDefinition = (indexId) => {
1122
+ const index = getIndex(indexId);
1123
+ const hadIndex = hasIndex(indexId);
1124
+ const sliceIds = hadIndex ? mapKeys(index) : [];
1101
1125
  delDefinition(indexId);
1126
+ if (hadIndex) {
1127
+ callListeners(hasIndexListeners, [indexId], false);
1128
+ if (sliceIds.length > 0) {
1129
+ callListeners(sliceIdsListeners, [indexId]);
1130
+ arrayForEach(sliceIds, (sliceId) => {
1131
+ callListeners(hasSliceListeners, [indexId, sliceId], false);
1132
+ callListeners(sliceRowIdsListeners, [indexId, sliceId]);
1133
+ });
1134
+ }
1135
+ }
1102
1136
  return indexes;
1103
1137
  };
1104
1138
  const getSliceIds = (indexId) => mapKeys(getIndex(indexId));
@@ -1106,6 +1140,10 @@ const createIndexes = getCreateFunction((store) => {
1106
1140
  collValues(mapGet(getIndex(indexId), sliceId));
1107
1141
  const addSliceIdsListener = (indexId, listener) =>
1108
1142
  addListener(listener, sliceIdsListeners, [indexId]);
1143
+ const addHasIndexListener = (indexId, listener) =>
1144
+ addListener(listener, hasIndexListeners, [indexId]);
1145
+ const addHasSliceListener = (indexId, sliceId, listener) =>
1146
+ addListener(listener, hasSliceListeners, [indexId, sliceId]);
1109
1147
  const addSliceRowIdsListener = (indexId, sliceId, listener) =>
1110
1148
  addListener(listener, sliceRowIdsListeners, [indexId, sliceId]);
1111
1149
  const delListener = (listenerId) => {
@@ -1129,7 +1167,9 @@ const createIndexes = getCreateFunction((store) => {
1129
1167
  getSliceIds,
1130
1168
  getSliceRowIds,
1131
1169
  addIndexIdsListener,
1170
+ addHasIndexListener,
1132
1171
  addSliceIdsListener,
1172
+ addHasSliceListener,
1133
1173
  addSliceRowIdsListener,
1134
1174
  delListener,
1135
1175
  destroy,
@@ -1236,6 +1276,7 @@ const createStore = () => {
1236
1276
  const valuesSchemaMap = mapNew();
1237
1277
  const valuesDefaulted = mapNew();
1238
1278
  const valuesNonDefaulted = setNew();
1279
+ const valuesRequiredNonDefaulted = setNew();
1239
1280
  const tablePoolFunctions = mapNew();
1240
1281
  const tableCellIds = mapNew();
1241
1282
  const tablesMap = mapNew();
@@ -1288,7 +1329,7 @@ const createStore = () => {
1288
1329
  const validateCellOrValueSchema = (schema) => {
1289
1330
  if (
1290
1331
  !objValidate(schema, (_child, id2) =>
1291
- arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
1332
+ arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1292
1333
  )
1293
1334
  ) {
1294
1335
  return false;
@@ -1323,20 +1364,32 @@ const createStore = () => {
1323
1364
  (row, rowId) => validateRow(tableId, rowId, row),
1324
1365
  () => cellInvalid(tableId),
1325
1366
  );
1326
- const validateRow = (tableId, rowId, row, skipDefaults) =>
1327
- objValidate(
1328
- skipDefaults ? row : addDefaultsToRow(row, tableId, rowId),
1329
- (cell, cellId) =>
1330
- ifNotUndefined(
1331
- getValidatedCell(tableId, rowId, cellId, cell),
1332
- (validCell) => {
1333
- row[cellId] = validCell;
1334
- return true;
1335
- },
1336
- () => false,
1337
- ),
1338
- () => cellInvalid(tableId, rowId),
1367
+ const validateRow = (tableId, rowId, row, skipDefaults) => {
1368
+ const rowWithDefaults = skipDefaults
1369
+ ? row
1370
+ : addDefaultsToRow(row, tableId, rowId);
1371
+ return (
1372
+ objValidate(
1373
+ rowWithDefaults,
1374
+ (cell, cellId) =>
1375
+ ifNotUndefined(
1376
+ getValidatedCell(tableId, rowId, cellId, cell),
1377
+ (validCell) => {
1378
+ row[cellId] = validCell;
1379
+ return true;
1380
+ },
1381
+ () => false,
1382
+ ),
1383
+ () => cellInvalid(tableId, rowId),
1384
+ ) &&
1385
+ (skipDefaults
1386
+ ? true
1387
+ : arrayEvery(
1388
+ collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
1389
+ (cellId) => objHas(rowWithDefaults, cellId),
1390
+ ))
1339
1391
  );
1392
+ };
1340
1393
  const getValidatedCell = (tableId, rowId, cellId, cell) =>
1341
1394
  hasTablesSchema
1342
1395
  ? ifNotUndefined(
@@ -1362,20 +1415,31 @@ const createStore = () => {
1362
1415
  : isUndefined(getCellOrValueType(cell))
1363
1416
  ? cellInvalid(tableId, rowId, cellId, cell)
1364
1417
  : encodeIfJson(cell);
1365
- const validateValues = (values, skipDefaults) =>
1366
- objValidate(
1367
- skipDefaults ? values : addDefaultsToValues(values),
1368
- (value, valueId) =>
1369
- ifNotUndefined(
1370
- getValidatedValue(valueId, value),
1371
- (validValue) => {
1372
- values[valueId] = validValue;
1373
- return true;
1374
- },
1375
- () => false,
1376
- ),
1377
- () => valueInvalid(),
1418
+ const validateValues = (values, skipDefaults) => {
1419
+ const valuesWithDefaults = skipDefaults
1420
+ ? values
1421
+ : addDefaultsToValues(values);
1422
+ return (
1423
+ objValidate(
1424
+ valuesWithDefaults,
1425
+ (value, valueId) =>
1426
+ ifNotUndefined(
1427
+ getValidatedValue(valueId, value),
1428
+ (validValue) => {
1429
+ values[valueId] = validValue;
1430
+ return true;
1431
+ },
1432
+ () => false,
1433
+ ),
1434
+ () => valueInvalid(),
1435
+ ) &&
1436
+ (skipDefaults
1437
+ ? true
1438
+ : arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
1439
+ objHas(valuesWithDefaults, valueId),
1440
+ ))
1378
1441
  );
1442
+ };
1379
1443
  const getValidatedValue = (valueId, value) =>
1380
1444
  hasValuesSchema
1381
1445
  ? ifNotUndefined(
@@ -1446,6 +1510,7 @@ const createStore = () => {
1446
1510
  (_tablesSchema, tableId, tableSchema) => {
1447
1511
  const rowDefaulted = mapNew();
1448
1512
  const rowNonDefaulted = setNew();
1513
+ const rowRequiredNonDefaulted = setNew();
1449
1514
  mapMatch(
1450
1515
  mapEnsure(tablesSchemaMap, tableId, mapNew),
1451
1516
  tableSchema,
@@ -1453,12 +1518,23 @@ const createStore = () => {
1453
1518
  mapSet(tableSchemaMap, cellId, cellSchema);
1454
1519
  ifNotUndefined(
1455
1520
  cellSchema[DEFAULT],
1456
- (def) => mapSet(rowDefaulted, cellId, def),
1457
- () => setAdd(rowNonDefaulted, cellId),
1521
+ (defaultCell) => {
1522
+ mapSet(rowDefaulted, cellId, defaultCell);
1523
+ },
1524
+ () => {
1525
+ setAdd(rowNonDefaulted, cellId);
1526
+ if (cellSchema[REQUIRED] === true) {
1527
+ setAdd(rowRequiredNonDefaulted, cellId);
1528
+ }
1529
+ },
1458
1530
  );
1459
1531
  },
1460
1532
  );
1461
- mapSet(tablesSchemaRowCache, tableId, [rowDefaulted, rowNonDefaulted]);
1533
+ mapSet(tablesSchemaRowCache, tableId, [
1534
+ rowDefaulted,
1535
+ rowNonDefaulted,
1536
+ rowRequiredNonDefaulted,
1537
+ ]);
1462
1538
  },
1463
1539
  (_tablesSchema, tableId) => {
1464
1540
  mapSet(tablesSchemaMap, tableId);
@@ -1473,14 +1549,27 @@ const createStore = () => {
1473
1549
  mapSet(valuesSchemaMap, valueId, valueSchema);
1474
1550
  ifNotUndefined(
1475
1551
  valueSchema[DEFAULT],
1476
- (def) => mapSet(valuesDefaulted, valueId, def),
1477
- () => setAdd(valuesNonDefaulted, valueId),
1552
+ (defaultValue) => {
1553
+ mapSet(valuesDefaulted, valueId, defaultValue);
1554
+ collDel(valuesNonDefaulted, valueId);
1555
+ collDel(valuesRequiredNonDefaulted, valueId);
1556
+ },
1557
+ () => {
1558
+ mapSet(valuesDefaulted, valueId);
1559
+ setAdd(valuesNonDefaulted, valueId);
1560
+ if (valueSchema[REQUIRED] === true) {
1561
+ setAdd(valuesRequiredNonDefaulted, valueId);
1562
+ } else {
1563
+ collDel(valuesRequiredNonDefaulted, valueId);
1564
+ }
1565
+ },
1478
1566
  );
1479
1567
  },
1480
1568
  (_valuesSchema, valueId) => {
1481
1569
  mapSet(valuesSchemaMap, valueId);
1482
1570
  mapSet(valuesDefaulted, valueId);
1483
1571
  collDel(valuesNonDefaulted, valueId);
1572
+ collDel(valuesRequiredNonDefaulted, valueId);
1484
1573
  },
1485
1574
  );
1486
1575
  const setOrDelTables = (tables) =>