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
package/lib/tools.d.ts DELETED
@@ -1,702 +0,0 @@
1
- /**
2
- * The tools module of the TinyBase project provides utilities for working with
3
- * TinyBase during development.
4
- *
5
- * This module is not intended to be directly used at runtime in a production
6
- * environment.
7
- *
8
- * @packageDocumentation
9
- * @module tools
10
- * @since v2.2.0
11
- */
12
-
13
- import {Store, TablesSchema, ValuesSchema} from './store.d';
14
- import {Id} from './common.d';
15
-
16
- /**
17
- * The StoreStats type describes a set of statistics about the Store, and
18
- * is used for debugging purposes.
19
- *
20
- * A StoreStats object is returned from the getStoreStats method.
21
- *
22
- * @category Statistics
23
- * @since v2.2.0
24
- */
25
- export type StoreStats = {
26
- /**
27
- * The number of Table objects in the Store.
28
- */
29
- totalTables: number;
30
- /**
31
- * The number of Row objects in the Store, across all Table objects.
32
- */
33
- totalRows: number;
34
- /**
35
- * The number of Cell objects in the Store, across all Row objects, across all
36
- * Table objects.
37
- */
38
- totalCells: number;
39
- /**
40
- * The number of Value objects in the Store, since v3.0.0.
41
- */
42
- totalValues: number;
43
- /**
44
- * The string length of the Store when serialized to JSON.
45
- */
46
- jsonLength: number;
47
- /**
48
- * Additional detailed statistics about the Store if the `detail` flag is
49
- * specified in the getStoreStats method.
50
- */
51
- detail?: StoreStatsDetail;
52
- };
53
-
54
- /**
55
- * The StoreStatsDetail type describes a more detailed set of statistics about
56
- * the Store, and is used for debugging purposes.
57
- *
58
- * A StoreStatsDetail object is added to the StoreStats object (returned from
59
- * the getStoreStats method) when the `detail` flag is specified.
60
- *
61
- * @category Statistics
62
- * @since v2.2.0
63
- */
64
- export type StoreStatsDetail = {
65
- /**
66
- * Information about each Table in the Store.
67
- */
68
- tables: {[tableId: Id]: StoreStatsTableDetail};
69
- };
70
-
71
- /**
72
- * The StoreStatsTableDetail type describes a detailed set of statistics about a
73
- * single Table in the Store, and is used for debugging purposes.
74
- *
75
- * @category Statistics
76
- * @since v2.2.0
77
- */
78
- export type StoreStatsTableDetail = {
79
- /**
80
- * The number of Row objects in the Table.
81
- */
82
- tableRows: number;
83
- /**
84
- * The number of Cell objects in the Table, across all Row objects.
85
- */
86
- tableCells: number;
87
- rows: {[rowId: Id]: StoreStatsRowDetail};
88
- };
89
-
90
- /**
91
- * The StoreStatsRowDetail type describes statistics about a single Row in the
92
- * Store, and is used for debugging purposes.
93
- *
94
- * @category Statistics
95
- * @since v2.2.0
96
- */
97
- export type StoreStatsRowDetail = {
98
- /**
99
- * The number of Cell objects in the Row.
100
- */
101
- rowCells: number;
102
- };
103
-
104
- /**
105
- * A Tools object lets you run various utilities on, and get certain information
106
- * about, Store objects in development.
107
- *
108
- * @see Developer Tools guides
109
- * @category Tools
110
- * @since v2.2.0
111
- */
112
- export interface Tools {
113
- /* eslint-disable max-len */
114
- /**
115
- * The getStoreStats method provides a set of statistics about the Store, and
116
- * is used for debugging purposes.
117
- *
118
- * @param detail An optional boolean that indicates more detailed stats about
119
- * the inner structure of the Store should be returned.
120
- * @returns A StoreStats object containing statistics about the Store.
121
- * @example
122
- * This example creates a Tools object and gets basic statistics about it.
123
- * ```js
124
- * const store = createStore()
125
- * .setTable('pets', {
126
- * fido: {species: 'dog', color: 'brown'},
127
- * felix: {species: 'cat', color: 'black'},
128
- * cujo: {species: 'dog', color: 'black'},
129
- * })
130
- * .setTable('species', {
131
- * dog: {price: 5},
132
- * cat: {price: 4},
133
- * })
134
- * .setValues({open: true, employees: 3});
135
- * const tools = createTools(store);
136
- * console.log(tools.getStoreStats());
137
- * // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
138
- * ```
139
- * @example
140
- * This example creates a Tools object and gets detailed statistics about it.
141
- * ```js
142
- * const store = createStore()
143
- * .setTable('pets', {
144
- * fido: {species: 'dog', color: 'brown'},
145
- * felix: {species: 'cat', color: 'black'},
146
- * cujo: {species: 'dog', color: 'black'},
147
- * })
148
- * .setTable('species', {
149
- * dog: {price: 5},
150
- * cat: {price: 4},
151
- * });
152
- * const stats = createTools(store).getStoreStats(true);
153
- *
154
- * console.log(stats.totalTables);
155
- * // -> 2
156
- * console.log(stats.totalRows);
157
- * // -> 5
158
- * console.log(stats.totalCells);
159
- * // -> 8
160
- * console.log(stats.detail.tables.pets.tableRows);
161
- * // -> 3
162
- * console.log(stats.detail.tables.pets.tableCells);
163
- * // -> 6
164
- * console.log(stats.detail.tables.pets.rows);
165
- * // -> {fido: {rowCells: 2}, felix: {rowCells: 2}, cujo: {rowCells: 2}}
166
- * ```
167
- * @category Statistics
168
- * @since v2.2.0
169
- */
170
- getStoreStats(detail?: boolean): StoreStats;
171
- /* eslint-enable max-len */
172
-
173
- /**
174
- * The getStoreTablesSchema method returns the TablesSchema of the Store as an
175
- * object.
176
- *
177
- * If the Store does not already have an explicit TablesSchema associated with
178
- * it, the data in the Store will be scanned to attempt to infer a new
179
- * TablesSchema.
180
- *
181
- * To be successful, this requires all the values of a given Cell across a
182
- * Table object's Row objects to have a consistent type. If a given Cell Id
183
- * appears in every Row, then a `default` for that Cell is specified in the
184
- * TablesSchema, based on the most common value found.
185
- *
186
- * @returns A TablesSchema object for the Store.
187
- * @example
188
- * This example creates a Tools object and gets the schema of a Store that
189
- * already has a TablesSchema.
190
- * ```js
191
- * const store = createStore().setTablesSchema({
192
- * pets: {
193
- * species: {type: 'string'},
194
- * color: {type: 'string'},
195
- * },
196
- * species: {
197
- * price: {type: 'number'},
198
- * },
199
- * });
200
- * const schema = createTools(store).getStoreTablesSchema();
201
- * console.log(schema.pets);
202
- * // -> {species: {type: 'string'}, color: {type: 'string'}}
203
- * ```
204
- * @example
205
- * This example creates a Tools object and infers the schema of a Store that
206
- * doesn't already have a TablesSchema.
207
- * ```js
208
- * const store = createStore()
209
- * .setTable('pets', {
210
- * fido: {species: 'dog', color: 'brown'},
211
- * felix: {species: 'cat', color: 'black'},
212
- * cujo: {species: 'dog', color: 'black'},
213
- * })
214
- * .setTable('species', {
215
- * dog: {price: 5, barks: true},
216
- * cat: {price: 4, purrs: true},
217
- * });
218
- * const schema = createTools(store).getStoreTablesSchema();
219
- * console.log(schema.pets.species);
220
- * // -> {type: 'string', default: 'dog'}
221
- * console.log(schema.pets.color);
222
- * // -> {type: 'string', default: 'black'}
223
- * console.log(schema.species.price);
224
- * // -> {type: 'number', default: 5}
225
- * console.log(schema.species.barks);
226
- * // -> {type: 'boolean'}
227
- * console.log(schema.species.purrs);
228
- * // -> {type: 'boolean'}
229
- * ```
230
- * @category Modelling
231
- * @since v3.0.0
232
- */
233
- getStoreTablesSchema(): TablesSchema;
234
-
235
- /**
236
- * The getStoreValuesSchema method returns the ValuesSchema of the Store as an
237
- * object.
238
- *
239
- * If the Store does not already have an explicit ValuesSchema associated with
240
- * it, the data in the Store will be scanned to infer a new ValuesSchema,
241
- * based on the types of the Values present. Note that, unlike the inference
242
- * of Cell values in the TablesSchema, it is not able to determine whether a
243
- * Value should have a default or not.
244
- *
245
- * @returns A ValuesSchema object for the Store.
246
- * @example
247
- * This example creates a Tools object and gets the schema of a Store that
248
- * already has a ValuesSchema.
249
- * ```js
250
- * const store = createStore().setValuesSchema({
251
- * open: {type: 'boolean', default: true},
252
- * employees: {type: 'number'},
253
- * });
254
- *
255
- * const schema = createTools(store).getStoreValuesSchema();
256
- * console.log(schema);
257
- * // -> {open: {type: 'boolean', default: true}, employees: {type: 'number'}}
258
- * ```
259
- * @example
260
- * This example creates a Tools object and infers the schema of a Store that
261
- * doesn't already have a ValuesSchema.
262
- * ```js
263
- * const store = createStore().setValues({open: true, employees: 3});
264
- * const schema = createTools(store).getStoreValuesSchema();
265
- *
266
- * console.log(schema);
267
- * // -> {open: {type: 'boolean'}, employees: {type: 'number'}}
268
- * ```
269
- * @category Modelling
270
- * @since v3.0.0
271
- */
272
- getStoreValuesSchema(): ValuesSchema;
273
-
274
- /**
275
- * The getStoreApi method returns code-generated `.d.ts` and `.ts(x)` files
276
- * that describe the schema of a Store and React bindings (since v3.1.0) in an
277
- * ORM style.
278
- *
279
- * If the Store does not already have an explicit TablesSchema or ValuesSchema
280
- * associated with it, the data in the Store will be scanned to attempt to
281
- * infer new schemas. The method returns four strings (which should be saved
282
- * as files) though if no schema can be inferred, the strings will be empty.
283
- *
284
- * The method takes a single argument which represents the name you want the
285
- * generated store object to have in code. You are expected to save the four
286
- * files yourself, as, respectively:
287
- *
288
- * - `[storeName].d.ts`
289
- * - `[storeName].ts`
290
- * - `[storeName]-ui-react.d.ts`
291
- * - `[storeName]-ui-react.tsx`
292
- *
293
- * Also you should save these alongside each other so that the `.ts(x)` files
294
- * can import types from the `.d.ts` files.
295
- *
296
- * The `.d.ts` and `.ts(x)` files that are generated are designed to resemble
297
- * the main TinyBase Store and React binding files, but provide named types
298
- * and methods that describe the domain of the schema in the Store.
299
- *
300
- * For example, from a Store that has a `pets` Table, you will get methods
301
- * like `getPetsTable`, types like `PetsRow`, and hooks and components that
302
- * are more specific versions of the underlying getTable method or the Row
303
- * type, and so on. For example:
304
- *
305
- * |Store type|Equivalent generated type|
306
- * |-|-|
307
- * |Table|[Table]Table|
308
- * |Row|[Table]Row|
309
- * |(Cell) Id|[Table]CellId|
310
- * |CellCallback|[Table]CellCallback|
311
- * |...|...|
312
- *
313
- * |Store method|Equivalent generated method|
314
- * |-|-|
315
- * |setTable|set[Table]Table|
316
- * |hasRow|has[Table]Row|
317
- * |getCell|get[Table][Cell]Cell|
318
- * |...|...|
319
- *
320
- * Equivalent to the TinyBase createStore function, a `create[StoreName]`
321
- * function will also be created. This acts as the main entry point to the
322
- * generated implementation.
323
- *
324
- * Each method is refined correctly to take, or return, the types specified by
325
- * the schema. For example, if the `pets` Table has a numeric `price` Cell in
326
- * the schema, the `getPetsPriceCell` method will be typed to return a number.
327
- *
328
- * The tables above include just a sample of the generated output. For the
329
- * full set of methods and types generated by this method, inspect the output
330
- * directly.
331
- *
332
- * @param storeName The name you want to provide to the generated Store, which
333
- * should also be used to save the `.d.ts`, `.ts`, and `.tsx` files.
334
- * @returns A set of four strings representing the contents of the `.d.ts`,
335
- * `.ts`, and `.tsx` files for the generated Store and React modules.
336
- * @example
337
- * This example creates a Tools object and generates code for a Store that
338
- * already has a TablesSchema.
339
- * ```js
340
- * const store = createStore().setTablesSchema({
341
- * pets: {
342
- * price: {type: 'number'},
343
- * },
344
- * });
345
- * const [dTs, ts, uiReactDTs, uiReactTsx] =
346
- * createTools(store).getStoreApi('shop');
347
- *
348
- * const dTsLines = dTs.split('\n');
349
- * console.log(dTsLines[3]);
350
- * // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price'?: number}}};`
351
- *
352
- * const tsLines = ts.split('\n');
353
- * console.log(tsLines[39]);
354
- * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
355
- * ```
356
- * @example
357
- * This example creates a Tools object and generates code for a Store that
358
- * doesn't already have a TablesSchema.
359
- * ```js
360
- * const store = createStore().setTable('pets', {
361
- * fido: {price: 5},
362
- * felix: {price: 4},
363
- * });
364
- * const [dTs, ts, uiReactDTs, uiReactTsx] =
365
- * createTools(store).getStoreApi('shop');
366
- *
367
- * const dTsLines = dTs.split('\n');
368
- * console.log(dTsLines[3]);
369
- * // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price': number}}};`
370
- *
371
- * const tsLines = ts.split('\n');
372
- * console.log(tsLines[41]);
373
- * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
374
- * ```
375
- * @category Modelling
376
- * @since v2.2.0
377
- */
378
- getStoreApi(storeName: string): [string, string, string, string];
379
-
380
- /**
381
- * The getPrettyStoreApi method attempts to return prettified code-generated
382
- * `.d.ts` and `.ts(x)` files that describe the schema of a Store and React
383
- * bindings (since v3.1.0) in an ORM style.
384
- *
385
- * This is simply a wrapper around the getStoreApi method that attempts to
386
- * invoke the `prettier` module (which it hopes you have installed) to format
387
- * the generated code. If `prettier` is not present, the output will resemble
388
- * that of the underlying getStoreApi method.
389
- *
390
- * The method is asynchronous, so you should use the `await` keyword or handle
391
- * the results as a promise.
392
- *
393
- * The method takes a single argument which represents the name you want the
394
- * generated store object to have in code. You are expected to save the four
395
- * files yourself, as, respectively:
396
- *
397
- * - `[storeName].d.ts`
398
- * - `[storeName].ts`
399
- * - `[storeName]-ui-react.d.ts`
400
- * - `[storeName]-ui-react.tsx`
401
- *
402
- * Also you should save these alongside each other so that the `.ts(x)` files
403
- * can import types from the `.d.ts` files.
404
- *
405
- * See the documentation for the getStoreApi method for details of the content
406
- * of the generated files.
407
- *
408
- * @param storeName The name you want to provide to the generated Store, which
409
- * should also be used to save the `.d.ts`, `.ts`, and `.tsx` files.
410
- * @returns A set of four strings representing the contents of the `.d.ts`,
411
- * `.ts`, and `.tsx` files for the generated Store and React modules.
412
- * @example
413
- * This example creates a Tools object and generates code for a Store that
414
- * already has a TablesSchema.
415
- * ```js
416
- * const store = createStore().setTablesSchema({
417
- * pets: {
418
- * price: {type: 'number'},
419
- * },
420
- * });
421
- * const tools = createTools(store);
422
- * const [dTs, ts, uiReactDTs, uiReactTsx] = await createTools(
423
- * store,
424
- * ).getPrettyStoreApi('shop');
425
- *
426
- * const dTsLines = dTs.split('\n');
427
- * console.log(dTsLines[5]);
428
- * // -> `export type Tables = {pets?: {[rowId: Id]: {price?: number}}};`
429
- *
430
- * const tsLines = ts.split('\n');
431
- * console.log(tsLines[79]);
432
- * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
433
- * ```
434
- * @example
435
- * This example creates a Tools object and generates code for a Store that
436
- * doesn't already have a TablesSchema.
437
- * ```js
438
- * const store = createStore().setTable('pets', {
439
- * fido: {price: 5},
440
- * felix: {price: 4},
441
- * });
442
- * const tools = createTools(store);
443
- * const [dTs, ts, uiReactDTs, uiReactTsx] = await createTools(
444
- * store,
445
- * ).getPrettyStoreApi('shop');
446
- *
447
- * const dTsLines = dTs.split('\n');
448
- * console.log(dTsLines[5]);
449
- * // -> 'export type Tables = {pets?: {[rowId: Id]: {price: number}}};'
450
- *
451
- * const tsLines = ts.split('\n');
452
- * console.log(tsLines[81]);
453
- * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
454
- * ```
455
- * @category Modelling
456
- * @since v2.2.0
457
- */
458
- getPrettyStoreApi(
459
- storeName: string,
460
- ): Promise<[string, string, string, string]>;
461
-
462
- /**
463
- * The getStoreRefinement method returns code-generated `.d.ts` files that
464
- * refine the Store and React bindings to have schema-specific methods and
465
- * types.
466
- *
467
- * If the Store does not already have an explicit TablesSchema or ValuesSchema
468
- * associated with it, the data in the Store will be scanned to attempt to
469
- * infer new schemas. The method returns two strings (which should be saved as
470
- * files) though if no schema can be inferred, the strings will be empty.
471
- *
472
- * The method takes a single argument which represents the name you want the
473
- * generated store object to have in code. You are expected to save the two
474
- * files yourself, as, respectively:
475
- *
476
- * - `[storeName]-refinement.d.ts`
477
- * - `[storeName]-ui-react-refinement.d.ts`
478
- *
479
- * You should save these alongside each other.
480
- *
481
- * The `.d.ts` files that are generated are designed to resemble the main
482
- * TinyBase Store and React binding files. In your application you will need
483
- * to coerce the Store to the refined interface to benefit from the type
484
- * safety. One easy way to do this is to cast the TinyBase module to the
485
- * refined module in bulk, and then destructure to get the refined imports:
486
- *
487
- * ```js yolo
488
- * import * as tinybase from 'tinybase';
489
- * import shopRefinement from './shop-refinement.d';
490
- *
491
- * const {createStore} = tinybase as typeof shopRefinement;
492
- *
493
- * const shop = createStore(); // shop is a refined Store
494
- * // ...
495
- * ```
496
- *
497
- * This is a particularly good approach for the React module which has many
498
- * top-level hook and component functions. You don't need to refine them one
499
- * by one:
500
- *
501
- * ```js yolo
502
- * import * as tinybaseUiReact from 'tinybase/ui-react';
503
- * import shopUiReactRefinement from './shop-ui-react-refinement.d';
504
- *
505
- * const {
506
- * useTables, // a refined hook
507
- * RowView, // a refined component
508
- * // ...
509
- * } = tinybaseUiReact as typeof shopUiReactRefinement;
510
- *
511
- * // ...
512
- * ```
513
- *
514
- * If you need access to refined types from the generated module definition,
515
- * you can access them as normal, in a separate import:
516
- *
517
- * ```js yolo
518
- * import {Tables} from './shop-refinement.d';
519
- * ```
520
- *
521
- * @param storeName The name you want to provide to the generated Store, which
522
- * should also be used to save the `.d.ts` files.
523
- * @returns A pair of strings representing the contents of the `.d.ts` files
524
- * for the generated Store and React modules.
525
- * @example
526
- * This example creates a Tools object and generates type refinements for a
527
- * Store that already has a TablesSchema.
528
- * ```js
529
- * const store = createStore().setTablesSchema({
530
- * pets: {
531
- * price: {type: 'number'},
532
- * },
533
- * });
534
- * const [refinementDTs, uiReactRefinementDTs] =
535
- * createTools(store).getStoreRefinement('shop');
536
- *
537
- * const dTsLines = refinementDTs.split('\n');
538
- * // console.log(dTsLines[3]);
539
- * // // -> ''
540
- * // console.log(dTsLines[6]);
541
- * // // -> ''
542
- * ```
543
- * @example
544
- * This example creates a Tools object and generates code for a Store that
545
- * doesn't already have a TablesSchema.
546
- * ```js
547
- * const store = createStore().setTable('pets', {
548
- * fido: {price: 5},
549
- * felix: {price: 4},
550
- * });
551
- * const [refinementDTs, uiReactRefinementDTs] =
552
- * createTools(store).getStoreRefinement('shop');
553
- *
554
- * const dTsLines = refinementDTs.split('\n');
555
- * // console.log(dTsLines[3]);
556
- * // // -> ''
557
- * // console.log(dTsLines[6]);
558
- * // // -> ''
559
- * ```
560
- * @category Modelling
561
- * @since v3.1.0
562
- */
563
- getStoreRefinement(storeName: string): [string, string];
564
-
565
- /**
566
- * The getPrettyStoreRefinement method attempts to return prettified
567
- * code-generated `.d.ts` files that refine the Store and React bindings to
568
- * have schema-specific methods and types.
569
- *
570
- * This is simply a wrapper around the getStoreRefinement method that attempts
571
- * to invoke the `prettier` module (which it hopes you have installed) to
572
- * format the generated code. If `prettier` is not present, the output will
573
- * resemble that of the underlying getStoreRefinement method.
574
- *
575
- * The method is asynchronous, so you should use the `await` keyword or handle
576
- * the results as a promise.
577
- *
578
- * The method takes a single argument which represents the name you want the
579
- * generated store object to have in code. You are expected to save the two
580
- * files yourself, as, respectively:
581
- *
582
- * - `[storeName]-refinement.d.ts`
583
- * - `[storeName]-ui-react-refinement.d.ts`
584
- *
585
- * You should save these alongside each other.
586
- *
587
- * See the documentation for the getStoreRefinement method for details of the
588
- * content of the generated files.
589
- *
590
- * @param storeName The name you want to provide to the generated Store, which
591
- * should also be used to save the `.d.ts` files.
592
- * @returns A pair of strings representing the contents of the `.d.ts` files
593
- * for the generated Store and React modules.
594
- * @example
595
- * This example creates a Tools object and generates type refinements for a
596
- * Store that already has a TablesSchema.
597
- * ```js
598
- * const store = createStore().setTablesSchema({
599
- * pets: {
600
- * price: {type: 'number'},
601
- * },
602
- * });
603
- * const [refinementDTs, uiReactRefinementDTs] = await createTools(
604
- * store,
605
- * ).getPrettyStoreRefinement('shop');
606
- *
607
- * const dTsLines = refinementDTs.split('\n');
608
- * // console.log(dTsLines[3]);
609
- * // // -> ''
610
- * // console.log(dTsLines[6]);
611
- * // // -> ''
612
- * ```
613
- * @example
614
- * This example creates a Tools object and generates code for a Store that
615
- * doesn't already have a TablesSchema.
616
- * ```js
617
- * const store = createStore().setTable('pets', {
618
- * fido: {price: 5},
619
- * felix: {price: 4},
620
- * });
621
- * const [refinementDTs, uiReactRefinementDTs] = await createTools(
622
- * store,
623
- * ).getPrettyStoreRefinement('shop');
624
- *
625
- * const dTsLines = refinementDTs.split('\n');
626
- * // console.log(dTsLines[3]);
627
- * // // -> ''
628
- * // console.log(dTsLines[6]);
629
- * // // -> ''
630
- * ```
631
- * @category Modelling
632
- * @since v3.1.0
633
- */
634
- getPrettyStoreRefinement(storeName: string): Promise<[string, string]>;
635
-
636
- /**
637
- * The getStore method returns a reference to the underlying Store that is
638
- * backing this Tools object.
639
- *
640
- * @returns A reference to the Store.
641
- * @example
642
- * This example creates a Tools object against a newly-created Store and
643
- * then gets its reference in order to update its data.
644
- *
645
- * ```js
646
- * const tools = createTools(createStore());
647
- * tools.getStore().setCell('species', 'dog', 'price', 5);
648
- * console.log(tools.getStoreStats().totalCells);
649
- * // -> 1
650
- * ```
651
- * @category Getter
652
- * @since v3.0.0
653
- */
654
- getStore(): Store;
655
- }
656
-
657
- /* eslint-disable max-len */
658
- /**
659
- * The createTools function creates a Tools object, and is the main entry point
660
- * into the tools module.
661
- *
662
- * A given Store can only have one Tools object associated with it. If you call
663
- * this function twice on the same Store, your second call will return a
664
- * reference to the Tools object created by the first.
665
- *
666
- * @param store The Store for which to register tools.
667
- * @returns A reference to the new Tools object.
668
- * @example
669
- * This example creates a Tools object.
670
- *
671
- * ```js
672
- * const store = createStore()
673
- * .setTable('pets', {
674
- * fido: {species: 'dog', color: 'brown'},
675
- * felix: {species: 'cat', color: 'black'},
676
- * cujo: {species: 'dog', color: 'black'},
677
- * })
678
- * .setTable('species', {
679
- * dog: {price: 5},
680
- * cat: {price: 4},
681
- * })
682
- * .setValues({open: true, employees: 3});
683
- * const tools = createTools(store);
684
- * console.log(tools.getStoreStats());
685
- * // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
686
- * ```
687
- * @example
688
- * This example creates a Tools object, and calls the method a second time
689
- * for the same Store to return the same object.
690
- *
691
- * ```js
692
- * const store = createStore();
693
- * const tools1 = createTools(store);
694
- * const tools2 = createTools(store);
695
- * console.log(tools1 === tools2);
696
- * // -> true
697
- * ```
698
- * @category Creation
699
- * @since v2.2.0
700
- */
701
- export function createTools(store: Store): Tools;
702
- /* eslint-enable max-len */