tinybase 3.1.0-beta.3 → 3.1.0-beta.5

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 (99) hide show
  1. package/bin/cli.js +1 -1
  2. package/lib/cjs/tools.cjs +1 -1
  3. package/lib/cjs/tools.cjs.gz +0 -0
  4. package/lib/cjs-es6/tools.cjs +1 -1
  5. package/lib/cjs-es6/tools.cjs.gz +0 -0
  6. package/lib/debug/tools.js +14 -621
  7. package/lib/debug/ui-react.js +2 -2
  8. package/lib/es6/tools.js +1 -1
  9. package/lib/es6/tools.js.gz +0 -0
  10. package/lib/tools.js +1 -1
  11. package/lib/tools.js.gz +0 -0
  12. package/lib/{debug → types}/indexes.d.ts +1 -1
  13. package/lib/{debug → types}/metrics.d.ts +40 -41
  14. package/lib/{cjs-es6 → types}/queries.d.ts +466 -299
  15. package/lib/{debug → types}/relationships.d.ts +2 -2
  16. package/lib/{debug → types}/store.d.ts +115 -124
  17. package/lib/types/tinybase.d.ts +14 -0
  18. package/lib/{debug → types}/tools.d.ts +3 -174
  19. package/lib/{cjs-es6 → types}/ui-react.d.ts +11 -5
  20. package/lib/{cjs-es6 → types/with-schemas}/checkpoints.d.ts +20 -16
  21. package/lib/{cjs → types/with-schemas}/indexes.d.ts +44 -23
  22. package/lib/types/with-schemas/internal/queries.d.ts +15 -0
  23. package/lib/types/with-schemas/internal/store.d.ts +101 -0
  24. package/lib/types/with-schemas/internal/ui-react.d.ts +776 -0
  25. package/lib/{cjs → types/with-schemas}/metrics.d.ts +61 -55
  26. package/lib/{debug → types/with-schemas}/persisters.d.ts +31 -25
  27. package/lib/{debug → types/with-schemas}/queries.d.ts +615 -350
  28. package/lib/{cjs → types/with-schemas}/relationships.d.ts +42 -25
  29. package/lib/{cjs-es6 → types/with-schemas}/store.d.ts +758 -302
  30. package/lib/types/with-schemas/tinybase.d.ts +14 -0
  31. package/lib/{cjs-es6 → types/with-schemas}/tools.d.ts +11 -180
  32. package/lib/{cjs → types/with-schemas}/ui-react.d.ts +817 -1314
  33. package/lib/umd/tools.js +1 -1
  34. package/lib/umd/tools.js.gz +0 -0
  35. package/lib/umd-es6/tools.js +1 -1
  36. package/lib/umd-es6/tools.js.gz +0 -0
  37. package/package.json +149 -33
  38. package/readme.md +3 -3
  39. package/lib/cjs/checkpoints.d.ts +0 -959
  40. package/lib/cjs/persisters.d.ts +0 -727
  41. package/lib/cjs/queries.d.ts +0 -3024
  42. package/lib/cjs/store.d.ts +0 -5244
  43. package/lib/cjs/tinybase.d.ts +0 -14
  44. package/lib/cjs/tools.d.ts +0 -702
  45. package/lib/cjs-es6/indexes.d.ts +0 -966
  46. package/lib/cjs-es6/metrics.d.ts +0 -827
  47. package/lib/cjs-es6/relationships.d.ts +0 -1201
  48. package/lib/cjs-es6/tinybase.d.ts +0 -14
  49. package/lib/common.d.ts +0 -115
  50. package/lib/debug/checkpoints.d.ts +0 -959
  51. package/lib/debug/common.d.ts +0 -115
  52. package/lib/debug/tinybase.d.ts +0 -14
  53. package/lib/debug/ui-react.d.ts +0 -10921
  54. package/lib/es6/checkpoints.d.ts +0 -959
  55. package/lib/es6/common.d.ts +0 -115
  56. package/lib/es6/indexes.d.ts +0 -966
  57. package/lib/es6/metrics.d.ts +0 -827
  58. package/lib/es6/persisters.d.ts +0 -727
  59. package/lib/es6/queries.d.ts +0 -3024
  60. package/lib/es6/relationships.d.ts +0 -1201
  61. package/lib/es6/store.d.ts +0 -5244
  62. package/lib/es6/tinybase.d.ts +0 -14
  63. package/lib/es6/tools.d.ts +0 -702
  64. package/lib/es6/ui-react.d.ts +0 -10921
  65. package/lib/indexes.d.ts +0 -966
  66. package/lib/metrics.d.ts +0 -827
  67. package/lib/persisters.d.ts +0 -727
  68. package/lib/queries.d.ts +0 -3024
  69. package/lib/relationships.d.ts +0 -1201
  70. package/lib/store.d.ts +0 -5244
  71. package/lib/tinybase.d.ts +0 -14
  72. package/lib/tools.d.ts +0 -702
  73. package/lib/ui-react.d.ts +0 -10921
  74. package/lib/umd/checkpoints.d.ts +0 -959
  75. package/lib/umd/common.d.ts +0 -115
  76. package/lib/umd/indexes.d.ts +0 -966
  77. package/lib/umd/metrics.d.ts +0 -827
  78. package/lib/umd/persisters.d.ts +0 -727
  79. package/lib/umd/queries.d.ts +0 -3024
  80. package/lib/umd/relationships.d.ts +0 -1201
  81. package/lib/umd/store.d.ts +0 -5244
  82. package/lib/umd/tinybase.d.ts +0 -14
  83. package/lib/umd/tools.d.ts +0 -702
  84. package/lib/umd/ui-react.d.ts +0 -10921
  85. package/lib/umd-es6/checkpoints.d.ts +0 -959
  86. package/lib/umd-es6/common.d.ts +0 -115
  87. package/lib/umd-es6/indexes.d.ts +0 -966
  88. package/lib/umd-es6/metrics.d.ts +0 -827
  89. package/lib/umd-es6/persisters.d.ts +0 -727
  90. package/lib/umd-es6/queries.d.ts +0 -3024
  91. package/lib/umd-es6/relationships.d.ts +0 -1201
  92. package/lib/umd-es6/store.d.ts +0 -5244
  93. package/lib/umd-es6/tinybase.d.ts +0 -14
  94. package/lib/umd-es6/tools.d.ts +0 -702
  95. package/lib/umd-es6/ui-react.d.ts +0 -10921
  96. /package/lib/{checkpoints.d.ts → types/checkpoints.d.ts} +0 -0
  97. /package/lib/{cjs-es6 → types}/common.d.ts +0 -0
  98. /package/lib/{cjs-es6 → types}/persisters.d.ts +0 -0
  99. /package/lib/{cjs → types/with-schemas}/common.d.ts +0 -0
@@ -72,30 +72,34 @@ const upper = (str) => str.toUpperCase();
72
72
  const lower = (str) => str.toLowerCase();
73
73
  const A = 'a ';
74
74
  const A_FUNCTION_FOR = 'A function for';
75
+ const AND_REGISTERS =
76
+ ', and registers a listener so that any changes to that result will cause a re-render';
75
77
  const CALLBACK = 'Callback';
76
78
  const DEL = 'Del';
79
+ const DEPS = 'Deps';
80
+ const DEPS_SUFFIX = DEPS + '?: React.DependencyList';
77
81
  const DO_ROLLBACK_PARAM = 'doRollback?: DoRollback';
78
82
  const DO_ACTIONS_AND_ROLLBACK_PARAMS =
79
83
  'actions: () => Return, ' + DO_ROLLBACK_PARAM;
80
84
  const EXPORT = 'export';
81
85
  const ID = 'Id';
82
- const ID_OR_NULL = 'IdOrNull';
83
86
  const INVALID = 'Invalid';
84
87
  const JSON$1 = 'Json';
85
88
  const LISTENER_ = lower(LISTENER);
89
+ const OPTIONAL_COLON = '?: ';
86
90
  const OR_UNDEFINED = ' | undefined';
87
91
  const NON_NULLABLE = 'NonNullable';
88
92
  const PARTIAL = 'Partial';
93
+ const PROPS = 'Props';
94
+ const PROVIDER = 'Provider';
89
95
  const REGISTERS_A_LISTENER = `Registers a ${LISTENER_} that will be called`;
90
96
  const REPRESENTS = 'Represents';
91
97
  const ROW_ID_PARAM = 'rowId: ' + ID;
92
- const ROW_ID_OR_NULL_PARAM = 'rowId: ' + ID_OR_NULL;
93
98
  const SCHEMA = 'Schema';
94
99
  const SET = 'Set';
95
100
  const SORTED_ARGS = ', descending?: boolean, offset?: number, limit?: number';
96
101
  const SQUARE_BRACKETS = '[]';
97
- const STORE = 'Store';
98
- const THE_STORE = 'the ' + STORE;
102
+ const THE_STORE = 'the Store';
99
103
  const TRANSACTION = 'Transaction';
100
104
  const TRANSACTION_ = lower(TRANSACTION);
101
105
  const TRANSACTION_DOC =
@@ -150,7 +154,6 @@ const getListenerDoc = (childNoun, parentNoun, pluralChild = 0) =>
150
154
  (pluralChild ? EMPTY_STRING : 's');
151
155
  const getTableDoc = (tableId) => `the '${tableId}' ` + TABLE;
152
156
  const getRowDoc = (tableId) => 'the specified Row in ' + getTableDoc(tableId);
153
- const getContentDoc = (verb = 0, noun = 0) => VERBS[verb] + SPACE + NOUNS[noun];
154
157
  const getTableContentDoc = (tableId, verb = 0) =>
155
158
  VERBS[verb] + ` ${getTheContentOfDoc()} ` + getTableDoc(tableId);
156
159
  const getRowContentDoc = (tableId, verb = 0) =>
@@ -1550,27 +1553,20 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
1550
1553
  ];
1551
1554
  };
1552
1555
 
1553
- const DEPS = 'Deps';
1554
1556
  const getGet = (noun) => GET + noun;
1555
1557
  const getGetAndGetDeps = (noun) =>
1556
1558
  getParameterList(getGet(noun), getGet(noun) + DEPS);
1557
1559
  const DEBUG_IDS_PROP_TYPE = 'debugIds?: boolean';
1558
1560
  const DEBUG_IDS_PROP = 'debugIds={debugIds}';
1559
- const DEPS_SUFFIX = DEPS + '?: React.DependencyList';
1560
1561
  const THEN_DEPS = 'then' + DEPS_SUFFIX;
1561
1562
  const PARAMETER = 'Parameter';
1562
1563
  const GETTER_ARGS = ': (parameter: ' + PARAMETER + ', store: Store) => ';
1563
- const PROVIDER = 'Provider';
1564
1564
  const USE_CONTEXT = 'const contextValue = useContext(Context);';
1565
- const AND_REGISTERS =
1566
- ', and registers a listener so that any changes to that result will cause a re-render';
1567
1565
  const BASED_ON_A_PARAMETER = ', based on a parameter';
1568
1566
  const COLON_SPACE = ': ';
1569
- const OPTIONAL_COLON = '?: ';
1570
1567
  const GENERIC_PARAMETER = '<' + PARAMETER + ',>';
1571
1568
  const PARAMETERIZED_CALLBACK =
1572
1569
  PARAMETER + 'ized' + CALLBACK + '<' + PARAMETER + '>';
1573
- const PROPS = 'Props';
1574
1570
  const ROW_ID = 'rowId';
1575
1571
  const ROW_ID_PROP = 'rowId={rowId}';
1576
1572
  const SEPARATOR_AND_DEBUG_IDS = ', separator, debugIds';
@@ -2643,597 +2639,6 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
2643
2639
  ];
2644
2640
  };
2645
2641
 
2646
- const MAY_CONTRADICT_REFINEMENT =
2647
- '. Note that this may contradict the generated type refinements';
2648
- const getStoreCoreRefinement = (tablesSchema, valuesSchema, _module) => {
2649
- const [
2650
- build,
2651
- addImport,
2652
- addType,
2653
- _addInternalFunction,
2654
- _addConstant,
2655
- getImports,
2656
- getTypes,
2657
- _getConstants,
2658
- ] = getCodeFunctions();
2659
- const [mapTablesSchema, mapCellSchema, mapValuesSchema] = getSchemaFunctions(
2660
- tablesSchema,
2661
- valuesSchema,
2662
- () => EMPTY_STRING,
2663
- );
2664
- const [getTablesTypes, getValuesTypes, getTransactionListenerType] =
2665
- getTypeFunctions(addType, mapTablesSchema, mapCellSchema, mapValuesSchema);
2666
- const methods = mapNew();
2667
- const getMethods = () =>
2668
- mapMap(methods, ([parameters, returnType, doc, generic], name) => [
2669
- comment(doc),
2670
- name + generic + `(${getParameterList(...parameters)}): ${returnType};`,
2671
- EMPTY_STRING,
2672
- ]);
2673
- const addMethod = (
2674
- name,
2675
- parameters,
2676
- returnType,
2677
- doc,
2678
- generic = EMPTY_STRING,
2679
- ) =>
2680
- mapUnique(methods, name, [
2681
- isArray(parameters) ? parameters : [parameters],
2682
- returnType,
2683
- doc,
2684
- generic,
2685
- ]);
2686
- addImport(
2687
- 0,
2688
- 'tinybase',
2689
- ID,
2690
- IDS,
2691
- ID_OR_NULL,
2692
- 'StoreListenerStats',
2693
- JSON$1,
2694
- TABLES + SCHEMA,
2695
- VALUES + SCHEMA,
2696
- 'DoRollback',
2697
- );
2698
- let tablesTypes;
2699
- if (objIsEmpty(tablesSchema)) {
2700
- tablesTypes = [
2701
- TABLES,
2702
- TABLES,
2703
- ID,
2704
- TABLE,
2705
- TABLE,
2706
- ROW,
2707
- ROW,
2708
- ID,
2709
- CELL,
2710
- CELL + CALLBACK,
2711
- ROW + CALLBACK,
2712
- TABLE + CALLBACK,
2713
- TABLES + LISTENER,
2714
- TABLE_IDS + LISTENER,
2715
- TABLE + LISTENER,
2716
- ROW_IDS + LISTENER,
2717
- SORTED_ROW_IDS + LISTENER,
2718
- ROW + LISTENER,
2719
- CELL_IDS + LISTENER,
2720
- CELL + LISTENER,
2721
- INVALID + CELL + LISTENER,
2722
- ];
2723
- addImport(0, 'tinybase', ...tablesTypes);
2724
- arrayPush(tablesTypes, ID, ID_OR_NULL, ID, EMPTY_STRING, ID, EMPTY_STRING);
2725
- } else {
2726
- addImport(0, 'tinybase', 'CellChange');
2727
- tablesTypes = getTablesTypes('store', STORE);
2728
- arrayForEach([3, 4, 5, 6, 7, 9, 10], (i) => (tablesTypes[i] += '<TId>'));
2729
- tablesTypes[8] += '<TId, CId>';
2730
- arrayPush(
2731
- tablesTypes,
2732
- 'TId',
2733
- 'TId | null',
2734
- join(
2735
- mapTablesSchema((tableId2) => `CellId<'${tableId2}'>`),
2736
- ' | ',
2737
- ),
2738
- `<TId extends ${tablesTypes[2]}>`,
2739
- 'CId',
2740
- `<TId extends ${tablesTypes[2]}, CId extends ${tablesTypes[7]}>`,
2741
- );
2742
- }
2743
- const [
2744
- tablesType,
2745
- tablesWhenSetType,
2746
- tableIdType,
2747
- tableType,
2748
- tableWhenSetType,
2749
- rowType,
2750
- rowWhenSetType,
2751
- cellIdType,
2752
- cellType,
2753
- cellCallbackType,
2754
- rowCallbackType,
2755
- tableCallbackType,
2756
- tablesListenerType,
2757
- tableIdsListenerType,
2758
- tableListenerType,
2759
- rowIdsListenerType,
2760
- sortedRowIdsListenerType,
2761
- rowListenerType,
2762
- cellIdsListenerType,
2763
- cellListenerType,
2764
- invalidCellListenerType,
2765
- tableId,
2766
- tableIdOrNull,
2767
- allCellIdsType,
2768
- tIdGeneric,
2769
- cId,
2770
- cIdGeneric,
2771
- ] = tablesTypes;
2772
- const tableIdParam = 'tableId: ' + tableId;
2773
- const rowIdParams = getParameterList(tableIdParam, ROW_ID_PARAM);
2774
- const cellIdParams = getParameterList(rowIdParams, 'cellId: ' + cId);
2775
- const tableIdOrNullParam = 'tableId: ' + tableIdOrNull;
2776
- const rowIdOrNullParams = getParameterList(
2777
- tableIdOrNullParam,
2778
- ROW_ID_OR_NULL_PARAM,
2779
- );
2780
- const cellIdOrNullParams = getParameterList(
2781
- rowIdOrNullParams,
2782
- 'cellId: ' + allCellIdsType,
2783
- );
2784
- arrayForEach(
2785
- [[tablesType], [BOOLEAN], [STORE, 'tables: ' + tablesWhenSetType], [STORE]],
2786
- ([returnType, params], verb) =>
2787
- addMethod(
2788
- METHOD_PREFIX_VERBS[verb] + TABLES,
2789
- params ?? EMPTY_STRING,
2790
- returnType,
2791
- getTheContentOfTheStoreDoc(1, verb),
2792
- ),
2793
- );
2794
- addMethod(
2795
- GET + TABLE_IDS,
2796
- EMPTY_STRING,
2797
- tableIdType + SQUARE_BRACKETS,
2798
- getIdsDoc(TABLE, THE_STORE),
2799
- );
2800
- addMethod(
2801
- METHOD_PREFIX_VERBS[5] + TABLE,
2802
- 'tableCallback: ' + tableCallbackType,
2803
- VOID,
2804
- getForEachDoc(TABLE, THE_STORE),
2805
- );
2806
- arrayForEach(
2807
- [
2808
- [tableType, tableIdParam],
2809
- [BOOLEAN, tableIdParam],
2810
- [STORE, [tableIdParam, 'table: ' + tableWhenSetType]],
2811
- [STORE, tableIdParam],
2812
- ],
2813
- ([returnType, params], verb) =>
2814
- addMethod(
2815
- METHOD_PREFIX_VERBS[verb] + TABLE,
2816
- params ?? EMPTY_STRING,
2817
- returnType,
2818
- getContentDoc(verb, 3),
2819
- tIdGeneric,
2820
- ),
2821
- );
2822
- addMethod(
2823
- GET + ROW_IDS,
2824
- tableIdParam,
2825
- IDS,
2826
- getIdsDoc(ROW, A + TABLE),
2827
- tIdGeneric,
2828
- );
2829
- addMethod(
2830
- GET + SORTED_ROW_IDS,
2831
- [tableIdParam, 'cellId?: ' + cellIdType + SORTED_ARGS],
2832
- IDS,
2833
- getIdsDoc(ROW, A + TABLE),
2834
- tIdGeneric,
2835
- );
2836
- addMethod(
2837
- METHOD_PREFIX_VERBS[5] + ROW,
2838
- [tableIdParam, 'rowCallback: ' + rowCallbackType],
2839
- VOID,
2840
- getForEachDoc(ROW, A + TABLE),
2841
- tIdGeneric,
2842
- );
2843
- arrayForEach(
2844
- [
2845
- [rowType, rowIdParams],
2846
- [BOOLEAN, rowIdParams],
2847
- [STORE, [rowIdParams, 'row: ' + rowWhenSetType]],
2848
- [STORE, rowIdParams],
2849
- ],
2850
- ([returnType, params], verb) =>
2851
- addMethod(
2852
- METHOD_PREFIX_VERBS[verb] + ROW,
2853
- params ?? EMPTY_STRING,
2854
- returnType,
2855
- getContentDoc(verb, 5),
2856
- tIdGeneric,
2857
- ),
2858
- );
2859
- addMethod(
2860
- 'set' + PARTIAL + ROW,
2861
- [tableIdParam, ROW_ID_PARAM, 'partialRow: ' + rowWhenSetType],
2862
- STORE,
2863
- getContentDoc(4, 5),
2864
- tIdGeneric,
2865
- );
2866
- addMethod(
2867
- ADD + ROW,
2868
- [tableIdParam, 'row: ' + rowWhenSetType],
2869
- ID + OR_UNDEFINED,
2870
- 'Add a new ' + ROW,
2871
- tIdGeneric,
2872
- );
2873
- addMethod(
2874
- GET + CELL_IDS,
2875
- [tableIdParam, ROW_ID_PARAM],
2876
- cellIdType + SQUARE_BRACKETS,
2877
- getIdsDoc(CELL, A + ROW),
2878
- tIdGeneric,
2879
- );
2880
- addMethod(
2881
- METHOD_PREFIX_VERBS[5] + CELL,
2882
- [tableIdParam, ROW_ID_PARAM, 'cellCallback: ' + cellCallbackType],
2883
- VOID,
2884
- getForEachDoc(CELL, A + ROW),
2885
- tIdGeneric,
2886
- );
2887
- arrayForEach(
2888
- [
2889
- [cellType, cellIdParams],
2890
- [BOOLEAN, cellIdParams],
2891
- [STORE, [cellIdParams, 'cell: ' + cellType]],
2892
- [STORE, cellIdParams],
2893
- ],
2894
- ([returnType, params], verb) =>
2895
- addMethod(
2896
- METHOD_PREFIX_VERBS[verb] + CELL,
2897
- params ?? EMPTY_STRING,
2898
- returnType,
2899
- getContentDoc(verb, 7),
2900
- cIdGeneric,
2901
- ),
2902
- );
2903
- addMethod(
2904
- ADD + TABLES + LISTENER,
2905
- [LISTENER_ + ': ' + tablesListenerType, 'mutator?: boolean'],
2906
- ID,
2907
- getTheContentOfTheStoreDoc(1, 8) + ' changes',
2908
- );
2909
- addMethod(
2910
- ADD + TABLE_IDS + LISTENER,
2911
- [LISTENER_ + ': ' + tableIdsListenerType, 'mutator?: boolean'],
2912
- ID,
2913
- getListenerDoc(2, 0, 1),
2914
- );
2915
- addMethod(
2916
- ADD + TABLE + LISTENER,
2917
- [
2918
- tableIdOrNullParam,
2919
- LISTENER_ + ': ' + tableListenerType,
2920
- 'mutator?: boolean',
2921
- ],
2922
- ID,
2923
- getListenerDoc(3, 0),
2924
- tIdGeneric,
2925
- );
2926
- addMethod(
2927
- ADD + ROW_IDS + LISTENER,
2928
- [
2929
- tableIdOrNullParam,
2930
- LISTENER_ + ': ' + rowIdsListenerType,
2931
- 'mutator?: boolean',
2932
- ],
2933
- ID,
2934
- getListenerDoc(4, 3, 1),
2935
- tIdGeneric,
2936
- );
2937
- addMethod(
2938
- ADD + SORTED_ROW_IDS + LISTENER,
2939
- [
2940
- tableIdParam,
2941
- 'cellId: ' + cellIdType + OR_UNDEFINED,
2942
- 'descending: boolean',
2943
- 'offset: number',
2944
- 'limit: number' + OR_UNDEFINED,
2945
- LISTENER_ + ': ' + sortedRowIdsListenerType,
2946
- 'mutator?: boolean',
2947
- ],
2948
- ID,
2949
- getListenerDoc(13, 3, 1),
2950
- tIdGeneric,
2951
- );
2952
- addMethod(
2953
- ADD + ROW + LISTENER,
2954
- [
2955
- rowIdOrNullParams,
2956
- LISTENER_ + ': ' + rowListenerType,
2957
- 'mutator?: boolean',
2958
- ],
2959
- ID,
2960
- getListenerDoc(5, 3),
2961
- tIdGeneric,
2962
- );
2963
- addMethod(
2964
- ADD + CELL_IDS + LISTENER,
2965
- [
2966
- rowIdOrNullParams,
2967
- LISTENER_ + ': ' + cellIdsListenerType,
2968
- 'mutator?: boolean',
2969
- ],
2970
- ID,
2971
- getListenerDoc(6, 5, 1),
2972
- tIdGeneric,
2973
- );
2974
- addMethod(
2975
- ADD + CELL + LISTENER,
2976
- [
2977
- cellIdOrNullParams,
2978
- LISTENER_ + ': ' + cellListenerType,
2979
- 'mutator?: boolean',
2980
- ],
2981
- ID,
2982
- getListenerDoc(7, 5),
2983
- tIdGeneric,
2984
- );
2985
- addMethod(
2986
- ADD + INVALID + CELL + LISTENER,
2987
- [
2988
- 'tableId: ' + ID_OR_NULL,
2989
- 'rowId: ' + ID_OR_NULL,
2990
- 'cellId: ' + ID_OR_NULL,
2991
- LISTENER_ + ': ' + invalidCellListenerType,
2992
- 'mutator?: boolean',
2993
- ],
2994
- ID,
2995
- REGISTERS_A_LISTENER + ' whenever an invalid Cell change was attempted',
2996
- );
2997
- let valuesTypes;
2998
- if (objIsEmpty(valuesSchema)) {
2999
- valuesTypes = [
3000
- VALUES,
3001
- VALUES,
3002
- ID,
3003
- VALUE,
3004
- VALUE + CALLBACK,
3005
- VALUES + LISTENER,
3006
- VALUE_IDS + LISTENER,
3007
- VALUE + LISTENER,
3008
- INVALID + VALUE + LISTENER,
3009
- ];
3010
- addImport(0, 'tinybase', ...valuesTypes);
3011
- arrayPush(valuesTypes, ID, ID_OR_NULL, EMPTY_STRING);
3012
- } else {
3013
- addImport(0, 'tinybase', 'ValueChange');
3014
- valuesTypes = getValuesTypes('store', STORE);
3015
- valuesTypes[3] += '<VId>';
3016
- arrayPush(
3017
- valuesTypes,
3018
- 'VId',
3019
- 'VId | null',
3020
- `<VId extends ${valuesTypes[2]}>`,
3021
- );
3022
- }
3023
- const [
3024
- valuesType,
3025
- valuesWhenSetType,
3026
- valueIdType,
3027
- valueType,
3028
- valueCallbackType,
3029
- valuesListenerType,
3030
- valueIdsListenerType,
3031
- valueListenerType,
3032
- invalidValueListenerType,
3033
- valueId,
3034
- valueIdOrNull,
3035
- vIdGeneric,
3036
- ] = valuesTypes;
3037
- const valueIdParam = 'valueId: ' + valueId;
3038
- arrayForEach(
3039
- [[valuesType], [BOOLEAN], [STORE, 'values: ' + valuesWhenSetType], [STORE]],
3040
- ([returnType, params], verb) =>
3041
- addMethod(
3042
- METHOD_PREFIX_VERBS[verb] + VALUES,
3043
- params ?? EMPTY_STRING,
3044
- returnType,
3045
- getTheContentOfTheStoreDoc(2, verb),
3046
- ),
3047
- );
3048
- addMethod(
3049
- 'set' + PARTIAL + VALUES,
3050
- 'partialValues: ' + valuesWhenSetType,
3051
- STORE,
3052
- getTheContentOfTheStoreDoc(2, 4),
3053
- );
3054
- addMethod(
3055
- GET + VALUE_IDS,
3056
- EMPTY_STRING,
3057
- valueIdType + SQUARE_BRACKETS,
3058
- getIdsDoc(VALUE, THE_STORE),
3059
- );
3060
- addMethod(
3061
- METHOD_PREFIX_VERBS[5] + VALUE,
3062
- 'valueCallback: ' + valueCallbackType,
3063
- VOID,
3064
- getForEachDoc(VALUE, THE_STORE),
3065
- );
3066
- arrayForEach(
3067
- [
3068
- [valueType, valueIdParam],
3069
- [BOOLEAN, valueIdParam],
3070
- [STORE, [valueIdParam, 'value: ' + valueType]],
3071
- [STORE, valueIdParam],
3072
- ],
3073
- ([returnType, params], verb) =>
3074
- addMethod(
3075
- METHOD_PREFIX_VERBS[verb] + VALUE,
3076
- params ?? EMPTY_STRING,
3077
- returnType,
3078
- getContentDoc(verb, 11),
3079
- vIdGeneric,
3080
- ),
3081
- );
3082
- addMethod(
3083
- ADD + VALUES + LISTENER,
3084
- [LISTENER_ + ': ' + valuesListenerType, 'mutator?: boolean'],
3085
- ID,
3086
- getTheContentOfTheStoreDoc(2, 8) + ' changes',
3087
- );
3088
- addMethod(
3089
- ADD + VALUE_IDS + LISTENER,
3090
- [LISTENER_ + ': ' + valueIdsListenerType, 'mutator?: boolean'],
3091
- ID,
3092
- getListenerDoc(10, 0, 1),
3093
- );
3094
- addMethod(
3095
- ADD + VALUE + LISTENER,
3096
- [
3097
- 'valueId: ' + valueIdOrNull,
3098
- LISTENER_ + ': ' + valueListenerType,
3099
- 'mutator?: boolean',
3100
- ],
3101
- ID,
3102
- getListenerDoc(11, 0),
3103
- vIdGeneric,
3104
- );
3105
- addMethod(
3106
- ADD + INVALID + VALUE + LISTENER,
3107
- [
3108
- 'valueId: ' + ID_OR_NULL,
3109
- LISTENER_ + ': ' + invalidValueListenerType,
3110
- 'mutator?: boolean',
3111
- ],
3112
- ID,
3113
- REGISTERS_A_LISTENER + ' whenever an invalid Value change was attempted',
3114
- );
3115
- arrayForEach(
3116
- [
3117
- [EMPTY_STRING, 'tablesAndValues'],
3118
- [TABLES, 'tables'],
3119
- [VALUES, 'values'],
3120
- ],
3121
- ([noun, param], content) => {
3122
- addMethod(
3123
- GET + noun + JSON$1,
3124
- EMPTY_STRING,
3125
- JSON$1,
3126
- getTheContentOfTheStoreDoc(content, 6),
3127
- );
3128
- addMethod(
3129
- 'set' + noun + JSON$1,
3130
- param + JSON$1 + ': ' + JSON$1,
3131
- STORE,
3132
- getTheContentOfTheStoreDoc(content, 7),
3133
- );
3134
- addMethod(
3135
- GET + noun + SCHEMA + JSON$1,
3136
- EMPTY_STRING,
3137
- JSON$1,
3138
- getTheContentOfTheStoreDoc(content, 14),
3139
- );
3140
- if (noun) {
3141
- addMethod(
3142
- 'set' + noun + SCHEMA,
3143
- param + SCHEMA + ': ' + noun + SCHEMA,
3144
- STORE,
3145
- getTheContentOfTheStoreDoc(content, 15) + MAY_CONTRADICT_REFINEMENT,
3146
- );
3147
- }
3148
- addMethod(
3149
- 'del' + noun + SCHEMA,
3150
- EMPTY_STRING,
3151
- STORE,
3152
- getTheContentOfTheStoreDoc(content, 16),
3153
- );
3154
- },
3155
- );
3156
- addMethod(
3157
- 'set' + SCHEMA,
3158
- [
3159
- `tables${SCHEMA}: ` + TABLES + SCHEMA,
3160
- `values${SCHEMA}?: ` + VALUES + SCHEMA,
3161
- ],
3162
- STORE,
3163
- getTheContentOfTheStoreDoc(0, 15) + MAY_CONTRADICT_REFINEMENT,
3164
- );
3165
- addMethod(
3166
- TRANSACTION_,
3167
- DO_ACTIONS_AND_ROLLBACK_PARAMS,
3168
- 'Return',
3169
- TRANSACTION_DOC,
3170
- '<Return>',
3171
- );
3172
- addMethod('start' + TRANSACTION, EMPTY_STRING, STORE, START_TRANSACTION_DOC);
3173
- addMethod(
3174
- 'finish' + TRANSACTION,
3175
- DO_ROLLBACK_PARAM,
3176
- STORE,
3177
- FINISH_TRANSACTION_DOC,
3178
- );
3179
- const transactionListenerType = getTransactionListenerType('store', STORE);
3180
- addMethod(
3181
- ADD + 'WillFinish' + TRANSACTION + LISTENER,
3182
- LISTENER_ + ': ' + transactionListenerType,
3183
- ID,
3184
- REGISTERS_A_LISTENER + ' just before ' + THE_END_OF_THE_TRANSACTION,
3185
- );
3186
- addMethod(
3187
- ADD + 'DidFinish' + TRANSACTION + LISTENER,
3188
- LISTENER_ + ': ' + transactionListenerType,
3189
- ID,
3190
- REGISTERS_A_LISTENER + ' just after ' + THE_END_OF_THE_TRANSACTION,
3191
- );
3192
- addMethod(
3193
- 'call' + LISTENER,
3194
- 'listenerId: Id',
3195
- STORE,
3196
- 'Manually provoke a listener to be called',
3197
- );
3198
- addMethod(
3199
- 'del' + LISTENER,
3200
- 'listenerId: Id',
3201
- STORE,
3202
- 'Remove a listener that was previously added to ' + THE_STORE,
3203
- );
3204
- addMethod(
3205
- GET + LISTENER + 'Stats',
3206
- EMPTY_STRING,
3207
- 'StoreListenerStats',
3208
- 'Get listener statistics',
3209
- );
3210
- return [
3211
- build(
3212
- `export * from 'tinybase';`,
3213
- ...getImports(0),
3214
- ...getTypes(),
3215
- 'export interface Store {',
3216
- ...getMethods(),
3217
- '}',
3218
- EMPTY_STRING,
3219
- comment(`Creates a Store object`),
3220
- 'export function createStore(): Store',
3221
- ),
3222
- ];
3223
- };
3224
-
3225
- const getStoreUiReactRefinement = (_tablesSchema, _valuesSchema, _module) => {
3226
- return [`export * from 'tinybase/ui-react';`];
3227
- };
3228
-
3229
- const getStoreRefinement = (tablesSchema, valuesSchema, module) => {
3230
- if (objIsEmpty(tablesSchema) && objIsEmpty(valuesSchema)) {
3231
- return [EMPTY_STRING, EMPTY_STRING];
3232
- }
3233
- const [dTsCore] = getStoreCoreRefinement(tablesSchema, valuesSchema);
3234
- return [dTsCore, ...getStoreUiReactRefinement()];
3235
- };
3236
-
3237
2642
  const prettierConfig = {
3238
2643
  parser: 'typescript',
3239
2644
  singleQuote: true,
@@ -3241,13 +2646,6 @@ const prettierConfig = {
3241
2646
  bracketSpacing: false,
3242
2647
  jsdocSingleLineComment: false,
3243
2648
  };
3244
- const getFormat = async () => {
3245
- try {
3246
- return (await import('prettier')).format;
3247
- } catch (e) {
3248
- return (str) => str;
3249
- }
3250
- };
3251
2649
  const createTools = getCreateFunction((store) => {
3252
2650
  const getStoreStats = (detail) => {
3253
2651
  let totalTables = 0;
@@ -3341,21 +2739,18 @@ const createTools = getCreateFunction((store) => {
3341
2739
  getStoreApi(getStoreTablesSchema(), getStoreValuesSchema(), module);
3342
2740
  const getPrettyStoreApi = async (module) => {
3343
2741
  const extensions = ['d.ts', 'ts', 'd.ts', 'tsx'];
3344
- const format = await getFormat();
2742
+ let format;
2743
+ try {
2744
+ format = (await import('prettier')).format;
2745
+ } catch (e) {
2746
+ format = (str) => str;
2747
+ }
3345
2748
  return arrayMap(getStoreApi$1(module), (file, f) =>
3346
2749
  formatJsDoc(
3347
2750
  format(file, {...prettierConfig, filepath: `_.${extensions[f]}`}),
3348
2751
  ),
3349
2752
  );
3350
2753
  };
3351
- const getStoreRefinement$1 = (module) =>
3352
- getStoreRefinement(getStoreTablesSchema(), getStoreValuesSchema());
3353
- const getPrettyStoreRefinement = async (module) => {
3354
- const format = await getFormat();
3355
- return arrayMap(getStoreRefinement$1(), (file) =>
3356
- formatJsDoc(format(file, {...prettierConfig, filepath: `_.d.ts`})),
3357
- );
3358
- };
3359
2754
  const getStore = () => store;
3360
2755
  const tools = {
3361
2756
  getStoreStats,
@@ -3363,8 +2758,6 @@ const createTools = getCreateFunction((store) => {
3363
2758
  getStoreValuesSchema,
3364
2759
  getStoreApi: getStoreApi$1,
3365
2760
  getPrettyStoreApi,
3366
- getStoreRefinement: getStoreRefinement$1,
3367
- getPrettyStoreRefinement,
3368
2761
  getStore,
3369
2762
  };
3370
2763
  return objFreeze(tools);