tinybase 2.1.1 → 2.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/bin/cli.js +2 -0
  2. package/lib/checkpoints.d.ts +0 -2
  3. package/lib/checkpoints.js +1 -1
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/debug/checkpoints.d.ts +0 -2
  6. package/lib/debug/checkpoints.js +4 -2
  7. package/lib/debug/indexes.d.ts +0 -2
  8. package/lib/debug/indexes.js +2 -1
  9. package/lib/debug/metrics.d.ts +0 -2
  10. package/lib/debug/metrics.js +2 -1
  11. package/lib/debug/queries.d.ts +0 -2
  12. package/lib/debug/queries.js +4 -3
  13. package/lib/debug/relationships.d.ts +0 -2
  14. package/lib/debug/relationships.js +2 -1
  15. package/lib/debug/store.d.ts +1 -1
  16. package/lib/debug/store.js +15 -17
  17. package/lib/debug/tinybase.js +18 -19
  18. package/lib/debug/tools.d.ts +440 -0
  19. package/lib/debug/tools.js +1012 -0
  20. package/lib/es6/checkpoints.d.ts +0 -2
  21. package/lib/es6/checkpoints.js +1 -1
  22. package/lib/es6/checkpoints.js.gz +0 -0
  23. package/lib/es6/indexes.d.ts +0 -2
  24. package/lib/es6/indexes.js +1 -1
  25. package/lib/es6/indexes.js.gz +0 -0
  26. package/lib/es6/metrics.d.ts +0 -2
  27. package/lib/es6/metrics.js +1 -1
  28. package/lib/es6/metrics.js.gz +0 -0
  29. package/lib/es6/queries.d.ts +0 -2
  30. package/lib/es6/queries.js +1 -1
  31. package/lib/es6/queries.js.gz +0 -0
  32. package/lib/es6/relationships.d.ts +0 -2
  33. package/lib/es6/relationships.js +1 -1
  34. package/lib/es6/relationships.js.gz +0 -0
  35. package/lib/es6/store.d.ts +1 -1
  36. package/lib/es6/store.js +1 -1
  37. package/lib/es6/store.js.gz +0 -0
  38. package/lib/es6/tinybase.js +1 -1
  39. package/lib/es6/tinybase.js.gz +0 -0
  40. package/lib/es6/tools.d.ts +440 -0
  41. package/lib/es6/tools.js +1 -0
  42. package/lib/es6/tools.js.gz +0 -0
  43. package/lib/es6/ui-react.js +1 -1
  44. package/lib/es6/ui-react.js.gz +0 -0
  45. package/lib/indexes.d.ts +0 -2
  46. package/lib/indexes.js +1 -1
  47. package/lib/indexes.js.gz +0 -0
  48. package/lib/metrics.d.ts +0 -2
  49. package/lib/metrics.js +1 -1
  50. package/lib/metrics.js.gz +0 -0
  51. package/lib/queries.d.ts +0 -2
  52. package/lib/queries.js +1 -1
  53. package/lib/queries.js.gz +0 -0
  54. package/lib/relationships.d.ts +0 -2
  55. package/lib/relationships.js +1 -1
  56. package/lib/relationships.js.gz +0 -0
  57. package/lib/store.d.ts +1 -1
  58. package/lib/store.js +1 -1
  59. package/lib/store.js.gz +0 -0
  60. package/lib/tinybase.js +1 -1
  61. package/lib/tinybase.js.gz +0 -0
  62. package/lib/tools.d.ts +440 -0
  63. package/lib/tools.js +1 -0
  64. package/lib/tools.js.gz +0 -0
  65. package/lib/umd/checkpoints.d.ts +0 -2
  66. package/lib/umd/checkpoints.js +1 -1
  67. package/lib/umd/checkpoints.js.gz +0 -0
  68. package/lib/umd/indexes.d.ts +0 -2
  69. package/lib/umd/indexes.js +1 -1
  70. package/lib/umd/indexes.js.gz +0 -0
  71. package/lib/umd/metrics.d.ts +0 -2
  72. package/lib/umd/metrics.js +1 -1
  73. package/lib/umd/metrics.js.gz +0 -0
  74. package/lib/umd/queries.d.ts +0 -2
  75. package/lib/umd/queries.js +1 -1
  76. package/lib/umd/queries.js.gz +0 -0
  77. package/lib/umd/relationships.d.ts +0 -2
  78. package/lib/umd/relationships.js +1 -1
  79. package/lib/umd/relationships.js.gz +0 -0
  80. package/lib/umd/store.d.ts +1 -1
  81. package/lib/umd/store.js +1 -1
  82. package/lib/umd/store.js.gz +0 -0
  83. package/lib/umd/tinybase.js +1 -1
  84. package/lib/umd/tinybase.js.gz +0 -0
  85. package/lib/umd/tools.d.ts +440 -0
  86. package/lib/umd/tools.js +1 -0
  87. package/lib/umd/tools.js.gz +0 -0
  88. package/lib/umd-es6/checkpoints.d.ts +0 -2
  89. package/lib/umd-es6/checkpoints.js +1 -1
  90. package/lib/umd-es6/checkpoints.js.gz +0 -0
  91. package/lib/umd-es6/indexes.d.ts +0 -2
  92. package/lib/umd-es6/indexes.js +1 -1
  93. package/lib/umd-es6/indexes.js.gz +0 -0
  94. package/lib/umd-es6/metrics.d.ts +0 -2
  95. package/lib/umd-es6/metrics.js +1 -1
  96. package/lib/umd-es6/metrics.js.gz +0 -0
  97. package/lib/umd-es6/queries.d.ts +0 -2
  98. package/lib/umd-es6/queries.js +1 -1
  99. package/lib/umd-es6/queries.js.gz +0 -0
  100. package/lib/umd-es6/relationships.d.ts +0 -2
  101. package/lib/umd-es6/relationships.js +1 -1
  102. package/lib/umd-es6/relationships.js.gz +0 -0
  103. package/lib/umd-es6/store.d.ts +1 -1
  104. package/lib/umd-es6/store.js +1 -1
  105. package/lib/umd-es6/store.js.gz +0 -0
  106. package/lib/umd-es6/tinybase.js +1 -1
  107. package/lib/umd-es6/tinybase.js.gz +0 -0
  108. package/lib/umd-es6/tools.d.ts +440 -0
  109. package/lib/umd-es6/tools.js +1 -0
  110. package/lib/umd-es6/tools.js.gz +0 -0
  111. package/lib/umd-es6/ui-react.js +1 -1
  112. package/lib/umd-es6/ui-react.js.gz +0 -0
  113. package/package.json +27 -17
  114. package/readme.md +31 -12
@@ -0,0 +1,440 @@
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 {Schema, Store} 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 string length of the Store when serialized to JSON.
41
+ */
42
+ jsonLength: number;
43
+ /**
44
+ * Additional detailed statistics about the Store if the `detail` flag is
45
+ * specified in the getStoreStats method.
46
+ */
47
+ detail?: StoreStatsDetail;
48
+ };
49
+
50
+ /**
51
+ * The StoreStatsDetail type describes a more detailed set of statistics about
52
+ * the Store, and is used for debugging purposes.
53
+ *
54
+ * A StoreStatsDetail object is added to the StoreStats object (returned from
55
+ * the getStoreStats method) when the `detail` flag is specified.
56
+ *
57
+ * @category Statistics
58
+ * @since v2.2.0
59
+ */
60
+ export type StoreStatsDetail = {
61
+ /**
62
+ * Information about each Table in the Store.
63
+ */
64
+ tables: {[tableId: Id]: StoreStatsTableDetail};
65
+ };
66
+
67
+ /**
68
+ * The StoreStatsTableDetail type describes a detailed set of statistics about a
69
+ * single Table in the Store, and is used for debugging purposes.
70
+ *
71
+ * @category Statistics
72
+ * @since v2.2.0
73
+ */
74
+ export type StoreStatsTableDetail = {
75
+ /**
76
+ * The number of Row objects in the Table.
77
+ */
78
+ tableRows: number;
79
+ /**
80
+ * The number of Cell objects in the Table, across all Row objects.
81
+ */
82
+ tableCells: number;
83
+ rows: {[rowId: Id]: StoreStatsRowDetail};
84
+ };
85
+
86
+ /**
87
+ * The StoreStatsRowDetail type describes statistics about a single Row in the
88
+ * Store, and is used for debugging purposes.
89
+ *
90
+ * @category Statistics
91
+ * @since v2.2.0
92
+ */
93
+ export type StoreStatsRowDetail = {
94
+ /**
95
+ * The number of Cell objects in the Row.
96
+ */
97
+ rowCells: number;
98
+ };
99
+
100
+ /**
101
+ * A Tools object lets you run various utilities on, and get certain information
102
+ * about, Store objects in development.
103
+ *
104
+ * @category Tools
105
+ * @since v2.2.0
106
+ */
107
+ export interface Tools {
108
+ /**
109
+ * The getStoreStats method provides a set of statistics about the Store, and
110
+ * is used for debugging purposes.
111
+ *
112
+ * @param detail An optional boolean that indicates more detailed stats about
113
+ * the inner structure of the Store should be returned.
114
+ * @returns A StoreStats object containing statistics about the Store.
115
+ * @example
116
+ * This example creates a Tools object and gets basic statistics about it.
117
+ * ```js
118
+ * const store = createStore()
119
+ * .setTable('pets', {
120
+ * fido: {species: 'dog', color: 'brown'},
121
+ * felix: {species: 'cat', color: 'black'},
122
+ * cujo: {species: 'dog', color: 'black'},
123
+ * })
124
+ * .setTable('species', {
125
+ * dog: {price: 5},
126
+ * cat: {price: 4},
127
+ * });
128
+ * const tools = createTools(store);
129
+ * console.log(tools.getStoreStats());
130
+ * // -> {totalTables: 2, totalRows: 5, totalCells: 8, jsonLength: 182}
131
+ * ```
132
+ * @example
133
+ * This example creates a Tools object and gets detailed statistics about it.
134
+ * ```js
135
+ * const store = createStore()
136
+ * .setTable('pets', {
137
+ * fido: {species: 'dog', color: 'brown'},
138
+ * felix: {species: 'cat', color: 'black'},
139
+ * cujo: {species: 'dog', color: 'black'},
140
+ * })
141
+ * .setTable('species', {
142
+ * dog: {price: 5},
143
+ * cat: {price: 4},
144
+ * });
145
+ * const stats = createTools(store).getStoreStats(true);
146
+ *
147
+ * console.log(stats.totalTables);
148
+ * // -> 2
149
+ * console.log(stats.totalRows);
150
+ * // -> 5
151
+ * console.log(stats.totalCells);
152
+ * // -> 8
153
+ * console.log(stats.detail.tables.pets.tableRows);
154
+ * // -> 3
155
+ * console.log(stats.detail.tables.pets.tableCells);
156
+ * // -> 6
157
+ * console.log(stats.detail.tables.pets.rows);
158
+ * // -> {fido: {rowCells: 2}, felix: {rowCells: 2}, cujo: {rowCells: 2}}
159
+ * ```
160
+ * @category Statistics
161
+ * @since v2.2.0
162
+ */
163
+ getStoreStats(detail?: boolean): StoreStats;
164
+
165
+ /**
166
+ * The getStoreSchema method returns the Schema of the Store as an object.
167
+ *
168
+ * If the Store does not already have an explicit Schema associated with it,
169
+ * the data in the Store will be scanned to attempt to infer a new Schema.
170
+ *
171
+ * To be successful, this requires all the values of a given Cell across a
172
+ * Table object's Row objects to have a consistent type. If a given Cell Id
173
+ * appears in every Row, then a `default` for that Cell is specified in the
174
+ * Schema, based on the most common value found.
175
+ *
176
+ * @returns A Schema object for the Store.
177
+ * @example
178
+ * This example creates a Tools object and gets basic statistics about a Store
179
+ * that already has a Schema.
180
+ * ```js
181
+ * const store = createStore().setSchema({
182
+ * pets: {
183
+ * species: {type: 'string'},
184
+ * color: {type: 'string'},
185
+ * },
186
+ * species: {
187
+ * price: {type: 'number'},
188
+ * },
189
+ * });
190
+ * const schema = createTools(store).getStoreSchema();
191
+ * console.log(schema.pets);
192
+ * // -> {species: {type: 'string'}, color: {type: 'string'}}
193
+ * ```
194
+ * @example
195
+ * This example creates a Tools object and gets basic statistics about a Store
196
+ * that doesn't already have a Schema.
197
+ * ```js
198
+ * const store = createStore()
199
+ * .setTable('pets', {
200
+ * fido: {species: 'dog', color: 'brown'},
201
+ * felix: {species: 'cat', color: 'black'},
202
+ * cujo: {species: 'dog', color: 'black'},
203
+ * })
204
+ * .setTable('species', {
205
+ * dog: {price: 5, barks: true},
206
+ * cat: {price: 4, purrs: true},
207
+ * });
208
+ * const schema = createTools(store).getStoreSchema();
209
+ * console.log(schema.pets.species);
210
+ * // -> {type: 'string', default: 'dog'}
211
+ * console.log(schema.pets.color);
212
+ * // -> {type: 'string', default: 'black'}
213
+ * console.log(schema.species.price);
214
+ * // -> {type: 'number', default: 5}
215
+ * console.log(schema.species.barks);
216
+ * // -> {type: 'boolean'}
217
+ * console.log(schema.species.purrs);
218
+ * // -> {type: 'boolean'}
219
+ * ```
220
+ * @category Modelling
221
+ * @since v2.2.0
222
+ */
223
+ getStoreSchema(): Schema;
224
+
225
+ /**
226
+ * The getStoreApi method returns a code-generated .d.ts file and a .ts file
227
+ * that describe the schema of a Store in an ORM style.
228
+ *
229
+ * If the Store does not already have an explicit Schema associated with it,
230
+ * the data in the Store will be scanned to attempt to infer a new Schema. The
231
+ * method returns two strings (which should be saved as files) though if no
232
+ * schema can be inferred, the strings will be empty.
233
+ *
234
+ * The method takes a single argument which represents the name you want the
235
+ * generated store object to have in code. You are expected to save the files
236
+ * as `[storeName].d.ts` and `[storeName].ts`, and alongside each other so
237
+ * that the latter can import types from the former.
238
+ *
239
+ * The .d.ts and .ts files that are generated are designed to resemble the
240
+ * main TinyBase `store.d.ts` and `store.ts` files, but provide named types
241
+ * and methods that describe the domain of the schema in the store.
242
+ *
243
+ * For example, from a Store that has a `pets` Table, you will get methods
244
+ * like `getPetsTable`, and types like `PetsRow`, that are more specific
245
+ * versions of the underlying getTable method or the Row type. For example:
246
+ *
247
+ * |Store type|Equivalent generated type|
248
+ * |-|-|
249
+ * |Table|[Table]Table|
250
+ * |Row|[Table]Row|
251
+ * |(Cell) Id|[Table]CellId|
252
+ * |CellCallback|[Table]CellCallback|
253
+ * |...|...|
254
+ *
255
+ * |Store method|Equivalent generated method|
256
+ * |-|-|
257
+ * |setTable|set[Table]Table|
258
+ * |hasRow|has[Table]Row|
259
+ * |getCell|get[Table][Cell]Cell|
260
+ * |...|...|
261
+ *
262
+ * Equivalent to the TinyBase createStore function, a `create[StoreName]`
263
+ * function will also be created. This acts as the main entry point to the
264
+ * generated implementation.
265
+ *
266
+ * Each method is refined correctly to take, or return, the types specified by
267
+ * the schema. For example, if the `pets` Table has a numeric `price` Cell in
268
+ * the schema, the `getPetsPriceCell` method will be typed to return a number.
269
+ *
270
+ * The tables above include just a sample of the generated output. For the
271
+ * full set of methods and types generated by this method, inspect the output
272
+ * directly.
273
+ *
274
+ * @param storeName The name you want to provide to the generated Store, which
275
+ * should also be used to save the `.d.ts` and `.ts` files.
276
+ * @returns A pair of strings representing the contents of the `.d.ts` and
277
+ * `.ts` files.
278
+ * @example
279
+ * This example creates a Tools object and generates code for a Store that
280
+ * already has a Schema.
281
+ * ```js
282
+ * const store = createStore().setSchema({
283
+ * pets: {
284
+ * price: {type: 'number'},
285
+ * },
286
+ * });
287
+ * const [dTs, ts] = createTools(store).getStoreApi('shop');
288
+ *
289
+ * const dTsLines = dTs.split('\n');
290
+ * console.log(dTsLines[3]);
291
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
292
+ * console.log(dTsLines[6]);
293
+ * // -> 'export type PetsRow = {\'price\'?: number;};'
294
+ *
295
+ * const tsLines = ts.split('\n');
296
+ * console.log(tsLines[40]);
297
+ * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
298
+ * ```
299
+ * @example
300
+ * This example creates a Tools object and generates code for a Store that
301
+ * doesn't already have a Schema.
302
+ * ```js
303
+ * const store = createStore().setTable('pets', {
304
+ * fido: {price: 5},
305
+ * felix: {price: 4},
306
+ * });
307
+ * const [dTs, ts] = createTools(store).getStoreApi('shop');
308
+ *
309
+ * const dTsLines = dTs.split('\n');
310
+ * console.log(dTsLines[3]);
311
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
312
+ * console.log(dTsLines[6]);
313
+ * // -> 'export type PetsRow = {\'price\': number;};'
314
+ *
315
+ * const tsLines = ts.split('\n');
316
+ * console.log(tsLines[42]);
317
+ * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
318
+ * ```
319
+ * @category Modelling
320
+ * @since v2.2.0
321
+ */
322
+ getStoreApi(storeName: string): [string, string];
323
+
324
+ /**
325
+ * The getPrettyStoreApi method attempts to returns a prettified
326
+ * code-generated .d.ts file and a .ts file that describe the schema of a
327
+ * Store in an ORM style.
328
+ *
329
+ * This is simply a wrapper around the getStoreApi method that attempts to
330
+ * invoke the `prettier` module (which it hopes you have installed) to format
331
+ * the generated code. If `prettier` is not present, the output will resemble
332
+ * that of the underlying getStoreApi method.
333
+ *
334
+ * The method is asynchronous, so you should use the `await` keyword or handle
335
+ * the results as a promise.
336
+ *
337
+ * The method takes a single argument which represents the name you want the
338
+ * generated store object to have in code. You are expected to save the files
339
+ * as `[storeName].d.ts` and `[storeName].ts`, and alongside each other so
340
+ * that the latter can import types from the former.
341
+ *
342
+ * See the documentation for the getStoreApi method for details of the content
343
+ * of the generated files.
344
+ *
345
+ * @param storeName The name you want to provide to the generated Store, which
346
+ * should also be used to save the `.d.ts` and `.ts` files.
347
+ * @returns A pair of strings representing the contents of the `.d.ts` and
348
+ * `.ts` files.
349
+ * @example
350
+ * This example creates a Tools object and generates code for a Store that
351
+ * already has a Schema.
352
+ * ```js
353
+ * const store = createStore().setSchema({
354
+ * pets: {
355
+ * price: {type: 'number'},
356
+ * },
357
+ * });
358
+ * const tools = createTools(store);
359
+ * const [dTs, ts] = await tools.getPrettyStoreApi('shop');
360
+ *
361
+ * const dTsLines = dTs.split('\n');
362
+ * console.log(dTsLines[14]);
363
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
364
+ * console.log(dTsLines[19]);
365
+ * // -> 'export type PetsRow = {price?: number};'
366
+ *
367
+ * const tsLines = ts.split('\n');
368
+ * console.log(tsLines[73]);
369
+ * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
370
+ * ```
371
+ * @example
372
+ * This example creates a Tools object and generates code for a Store that
373
+ * doesn't already have a Schema.
374
+ * ```js
375
+ * const store = createStore().setTable('pets', {
376
+ * fido: {price: 5},
377
+ * felix: {price: 4},
378
+ * });
379
+ * const tools = createTools(store);
380
+ * const [dTs, ts] = await tools.getPrettyStoreApi('shop');
381
+ *
382
+ * const dTsLines = dTs.split('\n');
383
+ * console.log(dTsLines[14]);
384
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
385
+ * console.log(dTsLines[19]);
386
+ * // -> 'export type PetsRow = {price: number};'
387
+ *
388
+ * const tsLines = ts.split('\n');
389
+ * console.log(tsLines[75]);
390
+ * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
391
+ * ```
392
+ * @category Modelling
393
+ * @since v2.2.0
394
+ */
395
+ getPrettyStoreApi(storeName: string): Promise<[string, string]>;
396
+ }
397
+
398
+ /**
399
+ * The createTools function creates a Tools object, and is the main entry point
400
+ * into the tools module.
401
+ *
402
+ * A given Store can only have one Tools object associated with it. If you call
403
+ * this function twice on the same Store, your second call will return a
404
+ * reference to the Tools object created by the first.
405
+ *
406
+ * @param store The Store for which to register tools.
407
+ * @returns A reference to the new Tools object.
408
+ * @example
409
+ * This example creates a Tools object.
410
+ *
411
+ * ```js
412
+ * const store = createStore()
413
+ * .setTable('pets', {
414
+ * fido: {species: 'dog', color: 'brown'},
415
+ * felix: {species: 'cat', color: 'black'},
416
+ * cujo: {species: 'dog', color: 'black'},
417
+ * })
418
+ * .setTable('species', {
419
+ * dog: {price: 5},
420
+ * cat: {price: 4},
421
+ * });
422
+ * const tools = createTools(store);
423
+ * console.log(tools.getStoreStats());
424
+ * // -> {totalTables: 2, totalRows: 5, totalCells: 8, jsonLength: 182}
425
+ * ```
426
+ * @example
427
+ * This example creates a Tools object, and calls the method a second time
428
+ * for the same Store to return the same object.
429
+ *
430
+ * ```js
431
+ * const store = createStore();
432
+ * const tools1 = createTools(store);
433
+ * const tools2 = createTools(store);
434
+ * console.log(tools1 === tools2);
435
+ * // -> true
436
+ * ```
437
+ * @category Creation
438
+ * @since v2.2.0
439
+ */
440
+ export function createTools(store: Store): Tools;
@@ -0,0 +1 @@
1
+ var e,l;e=this,l=function(e){"use strict";const l=e=>typeof e,t="",a=l(t),o=l(!0),n=l(0),d="type",r="default",s=(e,l)=>e.every(l),$=(e,l)=>e.sort(l),i=(e,l)=>e.forEach(l),I=(e,l)=>e.map(l),c=e=>e.length,b=e=>0==c(e),w=(e,...l)=>e.push(...l),C=e=>e.pop(),h=(e,...l)=>e.unshift(...l),u=e=>e.shift(),g=JSON.parse,T=isFinite,f=e=>null==e,R=e=>e==a||e==o,p=e=>l(e)==a,m=e=>Array.isArray(e),y=(e,l)=>e?.has(l)??!1,L=e=>[...e?.values()??[]],v=(e,l)=>e?.forEach(l),S=(e,l)=>e?.delete(l),k=e=>new Map(e),E=(e,l)=>e?.get(l),j=(e,l)=>v(e,((e,t)=>l(t,e))),x=(e,l)=>I([...e?.entries()??[]],(([e,t])=>l(t,e))),A=(e,l,t)=>f(t)?(S(e,l),e):e?.set(l,t),J=(e,l,t)=>(y(e,l)||A(e,l,t()),E(e,l)),O=e=>new Set(m(e)||f(e)?e:[e]),N=(e,l)=>e?.add(l),z=e=>[e,e],D=()=>[k(),k()],F=/[^A-Za-z0-9]+/,G=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,l,t)=>e.substring(l,t),W=e=>e.toUpperCase(),P=e=>e.toLowerCase(),_=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return y(e,o)?_(e,l,t,a+1):(A(e,o,t),o)},B=e=>e.replace(G,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,l=t)=>e.join(l),Z=e=>e.flat(1e3),q=(e,l=0)=>U(I(e.split(F),((e,t)=>(t>0||l?W:P)(M(e,0,1))+M(e,1)))),H=e=>W(U(e.split(F),"_")),K=e=>`/** ${e}. */`,V=()=>{const e=D(),l=k(),a=k(),o=k();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>i(a,(a=>N(J(e[l],t,O),a))),(e,t="",a="")=>_(l,e,[t,a]),(e,l,t,o,n,d="")=>_(a,e,[l,t,o,n,d]),(e,l,t)=>_(o,e,m(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>E(o,e)===l?e:_(o,e,l),l=>[...$(x(e[l],((e,l)=>`import {${U($(L(e)),", ")}} from '${l}';`))),t],()=>x(l,(([e,l],a)=>[K(l),`export type ${a} = ${e};`,t])),e=>x(a,(([l,a,o,n,d],r)=>{const s=e?[`${r}: ${d}(${l}): ${a} => ${o},`]:[`${r}${d}(${l}): ${a};`];return e||h(s,K(n)),w(s,t),s})),()=>x(o,((e,l)=>(e=m(e)?e:[e],w(e,C(e)+";"),[`const ${l} = ${u(e)}`,e,t])))]},X=Object,Y=X.keys,ee=X.freeze,le=(e,l)=>I(X.entries(e),(([e,t])=>l(t,e))),te=e=>b(Y(e)),ae=e=>{const t=l(e);return R(t)||t==n&&T(e)?t:void 0},oe="the content of",ne="the Store",de="A function for",re="export",se="listener",$e=" | undefined",ie=`Registers a ${se} that will be called`,Ie="Represents",ce=" => void",be=`${oe} ${ne}`,we="the end of the transaction",Ce="the specified Row",he=(e,l=0)=>`${Ie} a Row when ${l?"s":"g"}etting ${oe} the '${e}' Table`,ue=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=ne)=>`Gets whether ${e} exists in ${l}`,fe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${de} listening to changes to ${xe[e]} in ${xe[l]}`,pe=(e,l,t=0)=>`${ie} whenever ${e} in ${l} change`+(t?"":"s"),me=(e=0)=>`${je[e]} ${be}`,ye=e=>`the '${e}' Table`,Le=e=>`${Ce} in ${ye(e)}`,ve=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${je[l]} ${oe} ${ye(e)}`,ke=(e,l=0)=>`${je[l]} ${oe} ${Le(e)}`,Ee=(e,l,t=0)=>`${je[t]} ${ve(l)} for ${Le(e)}`,je=["Gets","Sets","Sets part of","Deletes"],xe=[ne,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],Ae=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Je=(e,l=t,a=t)=>`store.${e}(${l})${a?" as "+a:t}`,Oe=(e,l=t)=>`fluent(() => ${Je(e,l)})`,Ne=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(${se})${a?", "+a:t})`,ze=(e,l)=>{if(te(e))return z(t);const[a,n,s,$,i,I,c,b,w,C]=V(),h=`./${q(l)}.d`,u=q(l,1),g=q(u),T=k(),R=l=>le(e,((e,a)=>l(a,J(T,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,l,a)=>`'${e}'${f(a)?"?":t}: ${l};`))," ")}}`,he(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,he(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${ce}`,fe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,fe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(H(a),`'${a}'`)))),m=(l,t)=>le(e[l],((e,l)=>t(l,e[d],e[r],I(H(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(R(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${Ie} ${be}`),v=s("TableId",U(R((e=>`'${e}'`))," | "),"A Table Id in "+ne),S=s("TableCallback",`(...[tableId, rowCallback]: ${U(R(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${ce}]`))," | ")})${ce}`,fe("a Table Id, and a Row iterator")),E=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(R(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),x=s("TablesListener",`(${g}: ${u}, getCellChange: ${E}${$e})${ce}`,Re(1)),O=s("TableIdsListener",`(${g}: ${u})${ce}`,Re(2)),N=s("TableListener",`(${g}: ${u}, tableId: ${v}, getCellChange: ${E}${$e})${ce}`,Re(3)),D=s("RowIdsListener",`(${g}: ${u}, tableId: ${v})${ce}`,Re(4,3)),F=s("RowListener",`(${g}: ${u}, tableId: ${v}, rowId: Id, getCellChange: ${E}${$e})${ce}`,Re(5,3)),G=s("CellIdsListener",`(${g}: ${u}, tableId: ${v}, rowId: Id)`+ce,Re(6,5)),M=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(R((e=>m(e,((l,t)=>`[${g}: ${u}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${$e}, oldCell: ${t}${$e}, getCellChange: ${E} | undefined]`)))))," | ")})${ce}`,Re(7,5)),W=s("InvalidCellListener",`(${g}: ${u}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce};`,Re(8)),P=s("TransactionListener",`(${g}: ${u}, cellsTouched: boolean)${ce};`,de+" listening to the completion of a transaction");$("hasTables",t,o,Je("hasTables"),Te("any Table")),$("getTables",t,y,Je("getTables"),me()),$("setTables","tables: "+y,u,Oe("setTables","tables"),me(1)),$("delTables",t,u,Oe("delTables"),me(3)),$("getTableIds",t,v+"[]",Je("getTableIds",t,v+"[]"),ue("Table",ne)),$("forEachTable","tableCallback: "+S,"void",Je("forEachTable","tableCallback as any"),ge("Table",ne));const _=k();return R(((e,[l,a,d,r,s,i],I,c)=>{n(1,h,l,a,d,r,s,i),$(`has${I}Table`,t,o,Je("hasTable",c),Te(ye(e))),$(`get${I}Table`,t,l,Je("getTable",c,l),Se(e)),$(`set${I}Table`,"table: "+l,u,Oe("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,t,u,Oe("delTable",c),Se(e,3)),$(`get${I}RowIds`,t,"Ids",Je("getRowIds",c),ue("Row",ye(e))),$(`get${I}SortedRowIds`,`cellId?: ${r}, descending?: boolean, offset?: number, limit?: number`,"Ids",Je("getSortedRowIds",c+", cellId, descending, offset, limit"),ue("Row",ye(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Je("forEachRow",c+", rowCallback as any"),ge("Row",ye(e))),$(`has${I}Row`,"rowId: Id",o,Je("hasRow",c+", rowId"),Te(Ce,ye(e))),$(`get${I}Row`,"rowId: Id",a,Je("getRow",c+", rowId",a),ke(e)),$(`set${I}Row`,"rowId: Id, row: "+d,u,Oe("setRow",c+", rowId, row"),ke(e,1)),$(`add${I}Row`,"row: "+d,"Id"+$e,Je("addRow",c+", row"),"Adds a new Row to "+ye(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+d,u,Oe("setPartialRow",c+", rowId, partialRow"),ke(e,2)),$(`del${I}Row`,"rowId: Id",u,Oe("delRow",c+", rowId"),ke(e,3)),$(`get${I}CellIds`,"rowId: Id",r+"[]",Je("getCellIds",c+", rowId",r+"[]"),ue("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Je("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",Le(e))),m(e,((l,a,n,d,r)=>{const s="Map"+q(a,1);A(_,a,s),$(`has${I}${r}Cell`,"rowId: Id",o,Je("hasCell",`${c}, rowId, ${d}`),Te(ve(l),Le(e)));const i=`${a}${f(n)?$e:t}`;$(`get${I}${r}Cell`,"rowId: Id",i,Je("getCell",`${c}, rowId, ${d}`,i),Ee(e,l)),$(`set${I}${r}Cell`,`rowId: Id, cell: ${a} | ${s}`,u,Oe("setCell",`${c}, rowId, ${d}, cell as any`),Ee(e,l,1)),$(`del${I}${r}Cell`,"rowId: Id",u,Oe("delCell",`${c}, rowId, ${d}`),Ee(e,l,3))}))})),$("getJson",t,"Json",Je("getJson"),`${je[0]} a string serialization ${be}`),$("setJson","json: Json",u,Oe("setJson","json"),`${je[1]} ${be} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Je("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",t,u,Oe("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",u,Oe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${se}: ${x}, mutator?: boolean`,"Id",Ne("addTablesListener",t,"mutator"),`${ie} whenever ${be} changes`),$("addTableIdsListener",`${se}: ${O}, mutator?: boolean`,"Id",Ne("addTableIdsListener",t,"mutator"),pe("the Table Ids",ne,1)),$("addTableListener",`tableId: ${v} | null, ${se}: ${N}, mutator?: boolean`,"Id",Ne("addTableListener","tableId","mutator"),pe("a Table",ne)),$("addRowIdsListener",`tableId: ${v} | null, ${se}: ${D}, mutator?: boolean`,"Id",Ne("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${v} | null, rowId: IdOrNull, ${se}: ${F}, mutator?: boolean`,"Id",Ne("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),$("addCellIdsListener",`tableId: ${v} | null, rowId: IdOrNull, ${se}: ${G}, mutator?: boolean`,"Id",Ne("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${v} | null, rowId: IdOrNull, cellId: ${U(R(((e,l)=>l[3]))," | ")} | null, ${se}: ${M}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${se}: ${W}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${se}: ${P}`,"Id",Ne("addWillFinishTransactionListener"),`${ie} just before ${we}`),$("addDidFinishTransactionListener",`${se}: ${P}`,"Id",Ne("addDidFinishTransactionListener"),`${ie} just after ${we}`),$("callListener",se+"Id: Id",u,Oe("callListener",se+"Id"),`Manually provoke a ${se} to be called`),$("delListener",se+"Id: Id",u,Oe("delListener",se+"Id"),`Remove a ${se} that was previously added to ${ne}`),$("getStore",t,"Store","store",je[0]+" the underlying Store object"),j(_,((e,l)=>s(l,`(cell: ${e}${$e}) => ${e}`,`Takes a ${e} Cell value and returns another`))),n(0,"tinybase","CellChange",...Ae),n(1,"tinybase","createStore",...Ae),n(1,h,u,`create${u} as create${u}Decl`,y,v,S,x,O,N,D,F,G,M,W,P,...L(_)),I("store",["createStore().setSchema({",Z(R(((e,l,a,o)=>[`[${o}]: {`,...m(e,((e,l,a,o)=>`[${o}]: {[${I(H(d),`'${d}'`)}]: ${I(H(l),`'${l}'`)}${f(a)?t:`, [${I(H(r),`'${r}'`)}]: ${p(a)?I(H(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",se+": any",`(_: Store, ...args: any[]) => ${se}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[a(...c(0),...b(),`${re} interface ${u} {`,...w(0),"}",t,K(`Creates a ${u} object`),`${re} function create${u}(): ${u};`),a(...c(1),`${re} const create${u}: typeof create${u}Decl = () => {`,...C(),`return Object.freeze(${g});`,"};")]},De={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Fe=(e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))})((e=>{const l=()=>{const l=g(e.getSchemaJson());return!te(l)||s(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=k();if(s(a,(l=>s(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),d=J(o,a,(()=>[ae(n),k(),[0],0])),[r,s,[$]]=d,i=J(s,n,(()=>0))+1;return i>$&&(d[2]=[i,n]),A(s,n,i),d[3]++,r==ae(n)})))))return l[t]={},v(o,(([e,,[,o],n],s)=>{l[t][s]={[d]:e,...n==c(a)?{[r]:o}:{}}})),1}))?l:{}},t=e=>ze(l(),e),a=async e=>{let l;try{l=(await import("prettier")).format}catch{l=e=>e}return I(t(e),(e=>B(l(e,De))))};return ee({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,d)=>{t++;let r=0,s=0;const $={};d(((e,t)=>{r++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=r,o+=s,l&&(n[e]={tableRows:r,tableCells:s,rows:$})})),{totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson()),...l?{detail:{tables:n}}:{}}},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));e.createTools=Fe},"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
Binary file
@@ -913,8 +913,6 @@ export interface Checkpoints {
913
913
  * The createCheckpoints function creates a Checkpoints object, and is the main
914
914
  * entry point into the checkpoints module.
915
915
  *
916
- * It is trivially simple.
917
- *
918
916
  * A given Store can only have one Checkpoints object associated with it. If you
919
917
  * call this function twice on the same Store, your second call will return a
920
918
  * reference to the Checkpoints object created by the first.
@@ -1 +1 @@
1
- var e,n;e=this,n=function(e){"use strict";const n="",t=(e,n)=>e.includes(n),l=(e,n)=>e.forEach(n),o=e=>e.length,r=e=>0==o(e),s=(e,...n)=>e.push(...n),i=e=>e.pop(),u=e=>e.shift(),d=e=>null==e,c=(e,n,t)=>d(e)?null==t?void 0:t():n(e),a=(e,n)=>{var t;return null!=(t=null==e?void 0:e.has(n))&&t},h=e=>d(e)||0==(e=>e.size)(e),p=(e,n)=>null==e?void 0:e.forEach(n),f=(e,n)=>null==e?void 0:e.delete(n),v=e=>new Map(e),C=(e,n)=>null==e?void 0:e.get(n),g=(e,n,t)=>d(t)?(f(e,n),e):null==e?void 0:e.set(n,t),k=(e,n,t)=>(a(e,n)||g(e,n,t()),C(e,n)),y=(e,n,t,l,r=0)=>c((t?k:C)(e,n[r],r>o(n)-2?t:v),(s=>{if(r>o(n)-2)return(null==l?void 0:l(s))&&g(e,n[r]),s;const i=y(s,n,t,l,r+1);return h(s)&&g(e,n[r]),i})),L=e=>new Set(Array.isArray(e)||d(e)?e:[e]),w=/^\d+$/,b=e=>{let t;const[r,i]=(()=>{const e=[];let t=0;return[()=>{var l;return null!=(l=u(e))?l:n+t++},n=>{w.test(n)&&o(e)<1e3&&s(e,n)}]})(),a=v();return[(l,o,s)=>{null!=t||(t=e());const i=r();var u,d;return g(a,i,[l,o,s]),u=y(o,null!=s?s:[n],L),d=i,null==u||u.add(d),i},(e,r,...i)=>l(((e,t=[n])=>{const r=[],i=(e,n)=>n==o(t)?s(r,e):null===t[n]?p(e,(e=>i(e,n+1))):l([t[n],null],(t=>i(C(e,t),n+1)));return i(e,0),r})(e,r),(e=>p(e,(e=>C(a,e)[0](t,...null!=r?r:[],...i))))),e=>c(C(a,e),(([,t,l])=>(y(t,null!=l?l:[n],void 0,(n=>(f(n,e),h(n)?1:0))),g(a,e),i(e),l))),(e,n,r)=>c(C(a,e),(([e,,s=[]])=>{const i=(...u)=>{const c=o(u);c==o(s)?e(t,...u,...r(u)):d(s[c])?l(n[c](...u),(e=>i(...u,e))):i(...u,s[c])};i()}))]},S=Object.freeze,T=(e=>{const n=new WeakMap;return t=>(n.has(t)||n.set(t,e(t)),n.get(t))})((e=>{let f,y,L,w=100,T=v(),x=1;const z=v(),E=v(),[j,m,A]=b((()=>R)),B=v(),I=v(),M=[],F=[],O=(n,t)=>{x=0,e.transaction((()=>p(C(B,t),((t,l)=>p(t,((t,o)=>p(t,((t,r)=>((e,n,t,l,o)=>d(o)?e.delCell(n,t,l,!0):e.setCell(n,t,l,o))(e,l,o,r,t[n]))))))))),x=1},W=e=>{g(B,e),g(I,e),m(E,[e])},$=(e,n)=>l(((e,n)=>e.splice(0,n))(e,null!=n?n:o(e)),W),q=()=>$(M,o(M)-w),D=e.addCellListener(null,null,null,((e,n,t,l,o,r)=>{if(x){c(f,(()=>{s(M,f),q(),$(F),f=void 0,L=1}));const e=k(T,n,v),u=k(e,t,v),d=k(u,l,(()=>[r,void 0]));d[1]=o,d[0]===o&&h(g(u,l))&&h(g(e,t))&&h(g(T,n))&&(f=i(M),L=1),K()}})),G=(e="")=>(d(f)&&(f=n+y++,g(B,f,T),P(f,e),T=v(),L=1),f),H=()=>{r(M)||(F.unshift(G()),O(0,f),f=i(M),L=1)},J=()=>{r(F)||(s(M,f),f=u(F),O(1,f),L=1)},K=()=>{L&&(m(z),L=0)},N=e=>{const n=G(e);return K(),n},P=(e,n)=>(Q(e)&&C(I,e)!==n&&(g(I,e,n),m(E,[e])),R),Q=e=>a(B,e),R={setSize:e=>(w=e,q(),R),addCheckpoint:N,setCheckpoint:P,getStore:()=>e,getCheckpointIds:()=>[[...M],f,[...F]],forEachCheckpoint:e=>{return n=e,p(I,((e,t)=>n(t,e)));var n},hasCheckpoint:Q,getCheckpoint:e=>C(I,e),goBackward:()=>(H(),K(),R),goForward:()=>(J(),K(),R),goTo:e=>{const n=t(M,e)?H:t(F,e)?J:null;for(;!d(n)&&e!=f;)n();return K(),R},addCheckpointIdsListener:e=>j(e,z),addCheckpointListener:(e,n)=>j(n,E,[e]),delListener:e=>(A(e),R),clear:()=>($(M),$(F),d(f)||W(f),f=void 0,y=0,N(),R),destroy:()=>{e.delListener(D)},getListenerStats:()=>({})};return S(R.clear())}));e.createCheckpoints=T},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseCheckpoints={});
1
+ var e,n;e=this,n=function(e){"use strict";const n=(e,n)=>e.includes(n),t=(e,n)=>e.forEach(n),l=e=>e.length,o=e=>0==l(e),r=(e,...n)=>e.push(...n),s=e=>e.pop(),i=e=>e.shift(),u=e=>null==e,d=(e,n,t)=>u(e)?null==t?void 0:t():n(e),c=(e,n)=>{var t;return null!=(t=null==e?void 0:e.has(n))&&t},a=e=>u(e)||0==(e=>e.size)(e),h=(e,n)=>null==e?void 0:e.forEach(n),p=(e,n)=>null==e?void 0:e.delete(n),f=e=>new Map(e),v=(e,n)=>null==e?void 0:e.get(n),C=(e,n,t)=>u(t)?(p(e,n),e):null==e?void 0:e.set(n,t),g=(e,n,t)=>(c(e,n)||C(e,n,t()),v(e,n)),k=(e,n,t,o,r=0)=>d((t?g:v)(e,n[r],r>l(n)-2?t:f),(s=>{if(r>l(n)-2)return(null==o?void 0:o(s))&&C(e,n[r]),s;const i=k(s,n,t,o,r+1);return a(s)&&C(e,n[r]),i})),y=e=>new Set(Array.isArray(e)||u(e)?e:[e]),L=/^\d+$/,w=Object.freeze,b=(e=>{const b=new WeakMap;return e=>(b.has(e)||b.set(e,(e=>{let b,S,T,x=100,z=f(),E=1;const j=f(),m=f(),[A,B,I]=(e=>{let n;const[o,s]=(()=>{const e=[];let n=0;return[()=>{var t;return null!=(t=i(e))?t:""+n++},n=>{L.test(n)&&l(e)<1e3&&r(e,n)}]})(),c=f();return[(e,t,l)=>{null!=n||(n=V);const r=o();var s,i;return C(c,r,[e,t,l]),i=r,null==(s=k(t,null!=l?l:[""],y))||s.add(i),r},(e,o,...s)=>t(((e,n=[""])=>{const o=[],s=(e,i)=>i==l(n)?r(o,e):null===n[i]?h(e,(e=>s(e,i+1))):t([n[i],null],(n=>s(v(e,n),i+1)));return s(e,0),o})(e,o),(e=>h(e,(e=>v(c,e)[0](n,...null!=o?o:[],...s))))),e=>d(v(c,e),(([,n,t])=>(k(n,null!=t?t:[""],void 0,(n=>(p(n,e),a(n)?1:0))),C(c,e),s(e),t))),(e,o,r)=>d(v(c,e),(([e,,s=[]])=>{const i=(...d)=>{const c=l(d);c==l(s)?e(n,...d,...r(d)):u(s[c])?t(o[c](...d),(e=>i(...d,e))):i(...d,s[c])};i()}))]})(),M=f(),F=f(),O=[],W=[],$=(n,t)=>{E=0,e.transaction((()=>h(v(M,t),((t,l)=>h(t,((t,o)=>h(t,((t,r)=>((e,n,t,l,o)=>u(o)?e.delCell(n,t,l,!0):e.setCell(n,t,l,o))(e,l,o,r,t[n]))))))))),E=1},q=e=>{C(M,e),C(F,e),B(m,[e])},D=(e,n)=>t(((e,n)=>e.splice(0,n))(e,null!=n?n:l(e)),q),G=()=>D(O,l(O)-x),H=e.addCellListener(null,null,null,((e,n,t,l,o,i)=>{if(E){d(b,(()=>{r(O,b),G(),D(W),b=void 0,T=1}));const e=g(z,n,f),u=g(e,t,f),c=g(u,l,(()=>[i,void 0]));c[1]=o,c[0]===o&&a(C(u,l))&&a(C(e,t))&&a(C(z,n))&&(b=s(O),T=1),P()}})),J=(e="")=>(u(b)&&(b=""+S++,C(M,b,z),R(b,e),z=f(),T=1),b),K=()=>{o(O)||(((e,...n)=>{e.unshift(...n)})(W,J()),$(0,b),b=s(O),T=1)},N=()=>{o(W)||(r(O,b),b=i(W),$(1,b),T=1)},P=()=>{T&&(B(j),T=0)},Q=e=>{const n=J(e);return P(),n},R=(e,n)=>(U(e)&&v(F,e)!==n&&(C(F,e,n),B(m,[e])),V),U=e=>c(M,e),V={setSize:e=>(x=e,G(),V),addCheckpoint:Q,setCheckpoint:R,getStore:()=>e,getCheckpointIds:()=>[[...O],b,[...W]],forEachCheckpoint:e=>{return n=e,h(F,((e,t)=>n(t,e)));var n},hasCheckpoint:U,getCheckpoint:e=>v(F,e),goBackward:()=>(K(),P(),V),goForward:()=>(N(),P(),V),goTo:e=>{const t=n(O,e)?K:n(W,e)?N:null;for(;!u(t)&&e!=b;)t();return P(),V},addCheckpointIdsListener:e=>A(e,j),addCheckpointListener:(e,n)=>A(n,m,[e]),delListener:e=>(I(e),V),clear:()=>(D(O),D(W),u(b)||q(b),b=void 0,S=0,Q(),V),destroy:()=>{e.delListener(H)},getListenerStats:()=>({})};return w(V.clear())})(e)),b.get(e))})();e.createCheckpoints=b},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseCheckpoints={});
Binary file
@@ -935,8 +935,6 @@ export interface Indexes {
935
935
  * The createIndexes function creates an Indexes object, and is the main entry
936
936
  * point into the indexes module.
937
937
  *
938
- * It is trivially simple.
939
- *
940
938
  * A given Store can only have one Indexes object associated with it. If you
941
939
  * call this function twice on the same Store, your second call will return a
942
940
  * reference to the Indexes object created by the first.
@@ -1 +1 @@
1
- var e,n;e=this,n=function(e){"use strict";const n=e=>typeof e,t="",l=n(t),r=e=>t+e,s=(e,n)=>e.every(n),o=(e,n)=>s(e,((t,l)=>0==l||n(e[l-1],t)<=0)),d=(e,n)=>e.sort(n),i=(e,n)=>e.forEach(n),u=e=>e.length,a=(e,...n)=>e.push(...n),c=e=>null==e,f=(e,n,t)=>c(e)?null==t?void 0:t():n(e),v=e=>Array.isArray(e),h=(e,n)=>{var t;return null!=(t=null==e?void 0:e.has(n))&&t},I=e=>c(e)||0==(e=>e.size)(e),g=e=>{var n;return[...null!=(n=null==e?void 0:e.values())?n:[]]},p=e=>e.clear(),y=(e,n)=>null==e?void 0:e.forEach(n),x=(e,n)=>null==e?void 0:e.delete(n),S=e=>new Map(e),w=e=>{var n;return[...null!=(n=null==e?void 0:e.keys())?n:[]]},L=(e,n)=>null==e?void 0:e.get(n),b=(e,n)=>y(e,((e,t)=>n(t,e))),T=(e,n,t)=>c(t)?(x(e,n),e):null==e?void 0:e.set(n,t),E=(e,n,t)=>(h(e,n)||T(e,n,t()),L(e,n)),R=(e,n,t,l,r=0)=>f((t?E:L)(e,n[r],r>u(n)-2?t:S),(s=>{if(r>u(n)-2)return(null==l?void 0:l(s))&&T(e,n[r]),s;const o=R(s,n,t,l,r+1);return I(s)&&T(e,n[r]),o})),m=e=>new Set(v(e)||c(e)?e:[e]),j=(e,n)=>null==e?void 0:e.add(n),k=(e,n,t)=>{const l=e.hasRow,r=S(),o=S(),d=S(),a=S(),R=S(),k=(n,t,...l)=>{const r=E(R,n,m);return i(l,(n=>j(r,n)&&t&&e.callListener(n))),l},z=(n,...t)=>f(L(R,n),(l=>{i(0==u(t)?g(l):t,(n=>{e.delListener(n),x(l,n)})),I(l)&&T(R,n)})),A=(e,t)=>{T(r,e,t),h(o,e)||(T(o,e,n()),T(d,e,S()),T(a,e,S()))},C=e=>{T(r,e),T(o,e),T(d,e),T(a,e),z(e)};return[()=>e,()=>w(r),e=>b(o,e),e=>h(o,e),e=>L(r,e),e=>L(o,e),(e,n)=>T(o,e,n),A,(n,r,o,f,I)=>{A(n,r);const g=S(),x=S(),w=L(d,n),E=L(a,n),R=n=>{const o=t=>e.getCell(r,n,t),d=L(w,n),i=l(r,n)?t(f(o,n)):void 0;var a,h;if(d===i||v(d)&&v(i)&&(h=i,u(a=d)===u(h)&&s(a,((e,n)=>h[n]===e)))||T(g,n,[d,i]),!c(I)){const e=L(E,n),t=l(r,n)?I(o,n):void 0;e!=t&&T(x,n,t)}},m=e=>{o((()=>{y(g,(([,e],n)=>T(w,n,e))),y(x,((e,n)=>T(E,n,e)))}),g,x,w,E,e),p(g),p(x)};b(w,R),e.hasTable(r)&&i(e.getRowIds(r),(e=>{h(w,e)||R(e)})),m(!0),z(n),k(n,0,e.addRowListener(r,null,((e,n,t)=>R(t))),e.addTableListener(r,(()=>m())))},C,()=>b(R,C),k,z]},z=(e,r)=>n(e)==l?n=>n(e):null!=e?e:()=>null!=r?r:t,A=(e,n)=>e<n?-1:1,C=/^\d+$/,D=e=>{let n;const[l,r]=(()=>{const e=[];let n=0;return[()=>{var l;return null!=(l=e.shift())?l:t+n++},n=>{C.test(n)&&u(e)<1e3&&a(e,n)}]})(),s=S();return[(r,o,d)=>{null!=n||(n=e());const i=l();return T(s,i,[r,o,d]),j(R(o,null!=d?d:[t],m),i),i},(e,l,...r)=>i(((e,n=[t])=>{const l=[],r=(e,t)=>t==u(n)?a(l,e):null===n[t]?y(e,(e=>r(e,t+1))):i([n[t],null],(n=>r(L(e,n),t+1)));return r(e,0),l})(e,l),(e=>y(e,(e=>L(s,e)[0](n,...null!=l?l:[],...r))))),e=>f(L(s,e),(([,n,l])=>(R(n,null!=l?l:[t],void 0,(n=>(x(n,e),I(n)?1:0))),T(s,e),r(e),l))),(e,t,l)=>f(L(s,e),(([e,,r=[]])=>{const s=(...o)=>{const d=u(o);d==u(r)?e(n,...o,...l(o)):c(r[d])?i(t[d](...o),(e=>s(...o,e))):s(...o,r[d])};s()}))]},M=Object.freeze,B=(e=>{const n=new WeakMap;return t=>(n.has(t)||n.set(t,e(t)),n.get(t))})((e=>{const n=S(),l=S(),[s,i,u,a,p,E,R,,C,B,O]=k(e,S,(e=>{return c(e)?t:v(e)?(n=r,e.map(n)):r(e);var n})),[W,$,q]=D((()=>G)),F=(n,t,l)=>{const r=p(n);y(l,((n,l)=>t(l,(t=>y(n,(n=>t(n,(t=>e.forEachCell(r,n,t)))))))))},G={setIndexDefinition:(e,t,r,s,i,u=A)=>{const a=c(i)?void 0:([e],[n])=>i(e,n);return C(e,t,((t,r,i,v,g,p)=>{let w=0;const k=m(),z=m(),A=E(e);if(y(r,(([e,n],t)=>{const l=m(e),r=m(n);y(l,(e=>x(r,e)?x(l,e):0)),y(l,(e=>{j(k,e),f(L(A,e),(n=>{x(n,t),I(n)&&(T(A,e),w=1)}))})),y(r,(e=>{j(k,e),h(A,e)||(T(A,e,m()),w=1),j(L(A,e),t),c(s)||j(z,e)}))})),t(),I(g)||(p?b(A,(e=>j(z,e))):b(i,(e=>f(L(v,e),(e=>j(z,e))))),y(z,(e=>{const n=(n,t)=>u(L(g,n),L(g,t),e),t=[...L(A,e)];o(t,n)||(T(A,e,m(d(t,n))),j(k,e))}))),(w||p)&&!c(a)){const n=[...A];o(n,a)||(R(e,S(d(n,a))),w=1)}w&&$(n,[e]),y(k,(n=>$(l,[e,n])))}),z(r),f(s,z)),G},delIndexDefinition:e=>(B(e),G),getStore:s,getIndexIds:i,forEachIndex:e=>u(((n,t)=>e(n,(e=>F(n,e,t))))),forEachSlice:(e,n)=>F(e,n,E(e)),hasIndex:a,hasSlice:(e,n)=>h(E(e),n),getTableId:p,getSliceIds:e=>w(E(e)),getSliceRowIds:(e,n)=>g(L(E(e),n)),addSliceIdsListener:(e,t)=>W(t,n,[e]),addSliceRowIdsListener:(e,n,t)=>W(t,l,[e,n]),delListener:e=>(q(e),G),destroy:O,getListenerStats:()=>({})};return M(G)}));e.createIndexes=B},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseIndexes={});
1
+ var e,n;e=this,n=function(e){"use strict";const n=e=>typeof e,t="",l=n(t),r=e=>t+e,s=(e,n)=>e.every(n),o=(e,n)=>s(e,((t,l)=>0==l||n(e[l-1],t)<=0)),d=(e,n)=>e.sort(n),i=(e,n)=>e.forEach(n),u=e=>e.length,a=(e,...n)=>e.push(...n),c=e=>null==e,f=(e,n,t)=>c(e)?null==t?void 0:t():n(e),v=e=>Array.isArray(e),h=(e,n)=>{var t;return null!=(t=null==e?void 0:e.has(n))&&t},I=e=>c(e)||0==(e=>e.size)(e),g=e=>{var n;return[...null!=(n=null==e?void 0:e.values())?n:[]]},p=e=>e.clear(),y=(e,n)=>null==e?void 0:e.forEach(n),x=(e,n)=>null==e?void 0:e.delete(n),S=e=>new Map(e),w=e=>{var n;return[...null!=(n=null==e?void 0:e.keys())?n:[]]},L=(e,n)=>null==e?void 0:e.get(n),b=(e,n)=>y(e,((e,t)=>n(t,e))),T=(e,n,t)=>c(t)?(x(e,n),e):null==e?void 0:e.set(n,t),E=(e,n,t)=>(h(e,n)||T(e,n,t()),L(e,n)),R=(e,n,t,l,r=0)=>f((t?E:L)(e,n[r],r>u(n)-2?t:S),(s=>{if(r>u(n)-2)return(null==l?void 0:l(s))&&T(e,n[r]),s;const o=R(s,n,t,l,r+1);return I(s)&&T(e,n[r]),o})),m=e=>new Set(v(e)||c(e)?e:[e]),j=(e,n)=>null==e?void 0:e.add(n),k=(e,r)=>n(e)==l?n=>n(e):null!=e?e:()=>null!=r?r:t,z=(e,n)=>e<n?-1:1,A=/^\d+$/,C=Object.freeze,D=(e=>{const n=new WeakMap;return e=>(n.has(e)||n.set(e,(e=>{const n=S(),l=S(),[D,M,B,O,W,$,q,,F,G,H]=((e,n,t)=>{const l=e.hasRow,r=S(),o=S(),d=S(),a=S(),R=S(),k=(n,t,...l)=>{const r=E(R,n,m);return i(l,(n=>j(r,n)&&t&&e.callListener(n))),l},z=(n,...t)=>f(L(R,n),(l=>{i(0==u(t)?g(l):t,(n=>{e.delListener(n),x(l,n)})),I(l)&&T(R,n)})),A=(e,t)=>{T(r,e,t),h(o,e)||(T(o,e,n()),T(d,e,S()),T(a,e,S()))},C=e=>{T(r,e),T(o,e),T(d,e),T(a,e),z(e)};return[()=>e,()=>w(r),e=>b(o,e),e=>h(o,e),e=>L(r,e),e=>L(o,e),(e,n)=>T(o,e,n),A,(n,r,o,f,I)=>{A(n,r);const g=S(),x=S(),w=L(d,n),E=L(a,n),R=n=>{const o=t=>e.getCell(r,n,t),d=L(w,n),i=l(r,n)?t(f(o,n)):void 0;var a,h;if(d===i||v(d)&&v(i)&&(h=i,u(a=d)===u(h)&&s(a,((e,n)=>h[n]===e)))||T(g,n,[d,i]),!c(I)){const e=L(E,n),t=l(r,n)?I(o,n):void 0;e!=t&&T(x,n,t)}},m=e=>{o((()=>{y(g,(([,e],n)=>T(w,n,e))),y(x,((e,n)=>T(E,n,e)))}),g,x,w,E,e),p(g),p(x)};b(w,R),e.hasTable(r)&&i(e.getRowIds(r),(e=>{h(w,e)||R(e)})),m(!0),z(n),k(n,0,e.addRowListener(r,null,((e,n,t)=>R(t))),e.addTableListener(r,(()=>m())))},C,()=>b(R,C),k,z]})(e,S,(e=>{return c(e)?t:v(e)?(n=r,e.map(n)):r(e);var n})),[J,K,N]=(e=>{let n;const[l,r]=(()=>{const e=[];let n=0;return[()=>{var l;return null!=(l=e.shift())?l:t+n++},n=>{A.test(n)&&u(e)<1e3&&a(e,n)}]})(),s=S();return[(e,r,o)=>{null!=n||(n=Q);const d=l();return T(s,d,[e,r,o]),j(R(r,null!=o?o:[t],m),d),d},(e,l,...r)=>i(((e,n=[t])=>{const l=[],r=(e,t)=>t==u(n)?a(l,e):null===n[t]?y(e,(e=>r(e,t+1))):i([n[t],null],(n=>r(L(e,n),t+1)));return r(e,0),l})(e,l),(e=>y(e,(e=>L(s,e)[0](n,...null!=l?l:[],...r))))),e=>f(L(s,e),(([,n,l])=>(R(n,null!=l?l:[t],void 0,(n=>(x(n,e),I(n)?1:0))),T(s,e),r(e),l))),(e,t,l)=>f(L(s,e),(([e,,r=[]])=>{const s=(...o)=>{const d=u(o);d==u(r)?e(n,...o,...l(o)):c(r[d])?i(t[d](...o),(e=>s(...o,e))):s(...o,r[d])};s()}))]})(),P=(n,t,l)=>{const r=W(n);y(l,((n,l)=>t(l,(t=>y(n,(n=>t(n,(t=>e.forEachCell(r,n,t)))))))))},Q={setIndexDefinition:(e,t,r,s,i,u=z)=>{const a=c(i)?void 0:([e],[n])=>i(e,n);return F(e,t,((t,r,i,v,g,p)=>{let w=0;const E=m(),R=m(),k=$(e);if(y(r,(([e,n],t)=>{const l=m(e),r=m(n);y(l,(e=>x(r,e)?x(l,e):0)),y(l,(e=>{j(E,e),f(L(k,e),(n=>{x(n,t),I(n)&&(T(k,e),w=1)}))})),y(r,(e=>{j(E,e),h(k,e)||(T(k,e,m()),w=1),j(L(k,e),t),c(s)||j(R,e)}))})),t(),I(g)||(p?b(k,(e=>j(R,e))):b(i,(e=>f(L(v,e),(e=>j(R,e))))),y(R,(e=>{const n=(n,t)=>u(L(g,n),L(g,t),e),t=[...L(k,e)];o(t,n)||(T(k,e,m(d(t,n))),j(E,e))}))),(w||p)&&!c(a)){const n=[...k];o(n,a)||(q(e,S(d(n,a))),w=1)}w&&K(n,[e]),y(E,(n=>K(l,[e,n])))}),k(r),f(s,k)),Q},delIndexDefinition:e=>(G(e),Q),getStore:D,getIndexIds:M,forEachIndex:e=>B(((n,t)=>e(n,(e=>P(n,e,t))))),forEachSlice:(e,n)=>P(e,n,$(e)),hasIndex:O,hasSlice:(e,n)=>h($(e),n),getTableId:W,getSliceIds:e=>w($(e)),getSliceRowIds:(e,n)=>g(L($(e),n)),addSliceIdsListener:(e,t)=>J(t,n,[e]),addSliceRowIdsListener:(e,n,t)=>J(t,l,[e,n]),delListener:e=>(N(e),Q),destroy:H,getListenerStats:()=>({})};return C(Q)})(e)),n.get(e))})();e.createIndexes=D},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseIndexes={});
Binary file
@@ -796,8 +796,6 @@ export interface Metrics {
796
796
  * The createMetrics function creates a Metrics object, and is the main entry
797
797
  * point into the metrics module.
798
798
  *
799
- * It is trivially simple.
800
- *
801
799
  * A given Store can only have one Metrics object associated with it. If you
802
800
  * call this function twice on the same Store, your second call will return a
803
801
  * reference to the Metrics object created by the first.
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",l=t(n),r=t(t),i=(e,t)=>e.forEach(t),o=e=>u(e,((e,t)=>e+t),0),s=e=>e.length,u=(e,t,n)=>e.reduce(t,n),d=(e,...t)=>e.push(...t),a=Math.max,c=Math.min,v=isFinite,f=e=>null==e,h=(e,t,n)=>f(e)?null==n?void 0:n():t(e),g=e=>Array.isArray(e),M=()=>{},p=e=>e.size,y=(e,t)=>{var n;return null!=(n=null==e?void 0:e.has(t))&&n},m=e=>f(e)||0==p(e),b=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},L=e=>e.clear(),w=(e,t)=>null==e?void 0:e.forEach(t),T=(e,t)=>null==e?void 0:e.delete(t),x=e=>new Map(e),E=(e,t)=>null==e?void 0:e.get(t),I=(e,t)=>w(e,((e,n)=>t(n,e))),R=(e,t,n)=>f(n)?(T(e,t),e):null==e?void 0:e.set(t,n),S=(e,t,n)=>(y(e,t)||R(e,t,n()),E(e,t)),j=(e,t,n,l,r=0)=>h((n?S:E)(e,t[r],r>s(t)-2?n:x),(i=>{if(r>s(t)-2)return(null==l?void 0:l(i))&&R(e,t[r]),i;const o=j(i,t,n,l,r+1);return m(i)&&R(e,t[r]),o})),k=x([["avg",[(e,t)=>o(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,l)=>e+(t-n)/l]],["max",[e=>a(...e),(e,t)=>a(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:a(t,e)]],["min",[e=>c(...e),(e,t)=>c(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:c(t,e)]],["sum",[e=>o(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),z=e=>new Set(g(e)||f(e)?e:[e]),A=(e,t)=>null==e?void 0:e.add(t),D=(e,t,n)=>{const l=e.hasRow,r=x(),o=x(),u=x(),d=x(),a=x(),c=(t,n,...l)=>{const r=S(a,t,z);return i(l,(t=>A(r,t)&&n&&e.callListener(t))),l},v=(t,...n)=>h(E(a,t),(l=>{i(0==s(n)?b(l):n,(t=>{e.delListener(t),T(l,t)})),m(l)&&R(a,t)})),M=(e,n)=>{R(r,e,n),y(o,e)||(R(o,e,t()),R(u,e,x()),R(d,e,x()))},p=e=>{R(r,e),R(o,e),R(u,e),R(d,e),v(e)};return[()=>e,()=>{return[...null!=(t=null==(e=r)?void 0:e.keys())?t:[]];var e,t},e=>I(o,e),e=>y(o,e),e=>E(r,e),e=>E(o,e),(e,t)=>R(o,e,t),M,(t,r,o,a,h)=>{M(t,r);const p=x(),m=x(),b=E(u,t),T=E(d,t),S=t=>{const i=n=>e.getCell(r,t,n),o=E(b,t),u=l(r,t)?n(a(i,t)):void 0;var d,c,v;if(o===u||g(o)&&g(u)&&(c=u,s(d=o)===s(c)&&(v=(e,t)=>c[t]===e,d.every(v)))||R(p,t,[o,u]),!f(h)){const e=E(T,t),n=l(r,t)?h(i,t):void 0;e!=n&&R(m,t,n)}},j=e=>{o((()=>{w(p,(([,e],t)=>R(b,t,e))),w(m,((e,t)=>R(T,t,e)))}),p,m,b,T,e),L(p),L(m)};I(b,S),e.hasTable(r)&&i(e.getRowIds(r),(e=>{y(b,e)||S(e)})),j(!0),v(t),c(t,0,e.addRowListener(r,null,((e,t,n)=>S(n))),e.addTableListener(r,(()=>j())))},p,()=>I(a,p),c,v]},N=(e,r)=>t(e)==l?t=>t(e):null!=e?e:()=>null!=r?r:n,B=/^\d+$/,C=e=>{let t;const[l,r]=(()=>{const e=[];let t=0;return[()=>{var l;return null!=(l=e.shift())?l:n+t++},t=>{B.test(t)&&s(e)<1e3&&d(e,t)}]})(),o=x();return[(r,i,s)=>{null!=t||(t=e());const u=l();return R(o,u,[r,i,s]),A(j(i,null!=s?s:[n],z),u),u},(e,l,...r)=>i(((e,t=[n])=>{const l=[],r=(e,n)=>n==s(t)?d(l,e):null===t[n]?w(e,(e=>r(e,n+1))):i([t[n],null],(t=>r(E(e,t),n+1)));return r(e,0),l})(e,l),(e=>w(e,(e=>E(o,e)[0](t,...null!=l?l:[],...r))))),e=>h(E(o,e),(([,t,l])=>(j(t,null!=l?l:[n],void 0,(t=>(T(t,e),m(t)?1:0))),R(o,e),r(e),l))),(e,n,l)=>h(E(o,e),(([e,,r=[]])=>{const o=(...u)=>{const d=s(u);d==s(r)?e(t,...u,...l(u)):f(r[d])?i(n[d](...u),(e=>o(...u,e))):o(...u,r[d])};o()}))]},F=Object.freeze,O=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((e=>{const l=x(),[i,o,s,u,d,a,c,,h,g,y]=D(e,M,(e=>isNaN(e)||f(e)||!0===e||!1===e||e===n?void 0:1*e)),[L,T,I]=C((()=>R)),R={setMetricDefinition:(e,n,i,o,s,u,d)=>{var g;const M=t(i)==r?[i,s,u,d]:null!=(g=E(k,i))?g:E(k,"sum");return h(e,n,((t,n,r,i,o,s)=>{const u=a(e),d=p(i);s||(s=f(u)),t();let h=((e,t,n,l,r,i=!1)=>{if(m(n))return;const[o,s,u,d]=r;return i||(i=f(e)),w(l,(([n,l])=>{i||(e=f(n)?null==s?void 0:s(e,l,t++):f(l)?null==u?void 0:u(e,n,t--):null==d?void 0:d(e,l,n,t),i||(i=f(e)))})),i?o(b(n),p(n)):e})(u,d,i,n,M,s);v(h)||(h=void 0),h!=u&&(c(e,h),T(l,[e],h,u))}),N(o,1)),R},delMetricDefinition:e=>(g(e),R),getStore:i,getMetricIds:o,forEachMetric:s,hasMetric:u,getTableId:d,getMetric:a,addMetricListener:(e,t)=>L(t,l,[e]),delListener:e=>(I(e),R),destroy:y,getListenerStats:()=>({})};return F(R)}));e.createMetrics=O},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseMetrics={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",l=t(n),r=t(t),i=(e,t)=>e.forEach(t),o=e=>u(e,((e,t)=>e+t),0),s=e=>e.length,u=(e,t,n)=>e.reduce(t,n),d=(e,...t)=>e.push(...t),a=Math.max,c=Math.min,v=isFinite,f=e=>null==e,h=(e,t,n)=>f(e)?null==n?void 0:n():t(e),g=e=>Array.isArray(e),M=()=>{},p=e=>e.size,y=(e,t)=>{var n;return null!=(n=null==e?void 0:e.has(t))&&n},m=e=>f(e)||0==p(e),b=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},L=e=>e.clear(),w=(e,t)=>null==e?void 0:e.forEach(t),T=(e,t)=>null==e?void 0:e.delete(t),x=e=>new Map(e),E=(e,t)=>null==e?void 0:e.get(t),I=(e,t)=>w(e,((e,n)=>t(n,e))),R=(e,t,n)=>f(n)?(T(e,t),e):null==e?void 0:e.set(t,n),S=(e,t,n)=>(y(e,t)||R(e,t,n()),E(e,t)),j=(e,t,n,l,r=0)=>h((n?S:E)(e,t[r],r>s(t)-2?n:x),(i=>{if(r>s(t)-2)return(null==l?void 0:l(i))&&R(e,t[r]),i;const o=j(i,t,n,l,r+1);return m(i)&&R(e,t[r]),o})),k=x([["avg",[(e,t)=>o(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,l)=>e+(t-n)/l]],["max",[e=>a(...e),(e,t)=>a(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:a(t,e)]],["min",[e=>c(...e),(e,t)=>c(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:c(t,e)]],["sum",[e=>o(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),z=e=>new Set(g(e)||f(e)?e:[e]),A=(e,t)=>null==e?void 0:e.add(t),D=/^\d+$/,N=Object.freeze,B=(e=>{const o=new WeakMap;return e=>(o.has(e)||o.set(e,(e=>{const o=x(),[u,a,c,B,C,F,O,,W,$,q]=((e,t,l)=>{const r=e.hasRow,o=x(),u=x(),d=x(),a=x(),c=x(),v=(t,n,...l)=>{const r=S(c,t,z);return i(l,(t=>A(r,t)&&n&&e.callListener(t))),l},M=(t,...n)=>h(E(c,t),(l=>{i(0==s(n)?b(l):n,(t=>{e.delListener(t),T(l,t)})),m(l)&&R(c,t)})),p=(e,n)=>{R(o,e,n),y(u,e)||(R(u,e,t()),R(d,e,x()),R(a,e,x()))},j=e=>{R(o,e),R(u,e),R(d,e),R(a,e),M(e)};return[()=>e,()=>{return[...null!=(t=null==(e=o)?void 0:e.keys())?t:[]];var e,t},e=>I(u,e),e=>y(u,e),e=>E(o,e),e=>E(u,e),(e,t)=>R(u,e,t),p,(t,l,o,u,c)=>{p(t,l);const h=x(),m=x(),b=E(d,t),T=E(a,t),S=t=>{const i=n=>e.getCell(l,t,n),o=E(b,t),d=r(l,t)?(a=u(i,t),isNaN(a)||f(a)||!0===a||!1===a||a===n?void 0:1*a):void 0;var a,v,M,p;if(o===d||g(o)&&g(d)&&(M=d,s(v=o)===s(M)&&(p=(e,t)=>M[t]===e,v.every(p)))||R(h,t,[o,d]),!f(c)){const e=E(T,t),n=r(l,t)?c(i,t):void 0;e!=n&&R(m,t,n)}},j=e=>{o((()=>{w(h,(([,e],t)=>R(b,t,e))),w(m,((e,t)=>R(T,t,e)))}),h,m,b,T,e),L(h),L(m)};I(b,S),e.hasTable(l)&&i(e.getRowIds(l),(e=>{y(b,e)||S(e)})),j(!0),M(t),v(t,0,e.addRowListener(l,null,((e,t,n)=>S(n))),e.addTableListener(l,(()=>j())))},j,()=>I(c,j),v,M]})(e,M),[G,H,J]=(e=>{let t;const[l,r]=(()=>{const e=[];let t=0;return[()=>{var l;return null!=(l=e.shift())?l:n+t++},t=>{D.test(t)&&s(e)<1e3&&d(e,t)}]})(),o=x();return[(e,r,i)=>{null!=t||(t=K);const s=l();return R(o,s,[e,r,i]),A(j(r,null!=i?i:[n],z),s),s},(e,l,...r)=>i(((e,t=[n])=>{const l=[],r=(e,n)=>n==s(t)?d(l,e):null===t[n]?w(e,(e=>r(e,n+1))):i([t[n],null],(t=>r(E(e,t),n+1)));return r(e,0),l})(e,l),(e=>w(e,(e=>E(o,e)[0](t,...null!=l?l:[],...r))))),e=>h(E(o,e),(([,t,l])=>(j(t,null!=l?l:[n],void 0,(t=>(T(t,e),m(t)?1:0))),R(o,e),r(e),l))),(e,n,l)=>h(E(o,e),(([e,,r=[]])=>{const o=(...u)=>{const d=s(u);d==s(r)?e(t,...u,...l(u)):f(r[d])?i(n[d](...u),(e=>o(...u,e))):o(...u,r[d])};o()}))]})(),K={setMetricDefinition:(e,n,i,s,u,d,a)=>{var c;const h=t(i)==r?[i,u,d,a]:null!=(c=E(k,i))?c:E(k,"sum");return W(e,n,((t,n,l,r,i,s)=>{const u=F(e),d=p(r);s||(s=f(u)),t();let a=((e,t,n,l,r,i=!1)=>{if(m(n))return;const[o,s,u,d]=r;return i||(i=f(e)),w(l,(([n,l])=>{i||(e=f(n)?null==s?void 0:s(e,l,t++):f(l)?null==u?void 0:u(e,n,t--):null==d?void 0:d(e,l,n,t),i||(i=f(e)))})),i?o(b(n),p(n)):e})(u,d,r,n,h,s);v(a)||(a=void 0),a!=u&&(O(e,a),H(o,[e],a,u))}),(1,t(g=s)==l?e=>e(g):null!=g?g:()=>1)),K;var g},delMetricDefinition:e=>($(e),K),getStore:u,getMetricIds:a,forEachMetric:c,hasMetric:B,getTableId:C,getMetric:F,addMetricListener:(e,t)=>G(t,o,[e]),delListener:e=>(J(e),K),destroy:q,getListenerStats:()=>({})};return N(K)})(e)),o.get(e))})();e.createMetrics=B},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseMetrics={});
Binary file
@@ -2992,8 +2992,6 @@ export interface Queries {
2992
2992
  * The createQueries function creates a Queries object, and is the main entry
2993
2993
  * point into the queries module.
2994
2994
  *
2995
- * It is trivially simple.
2996
- *
2997
2995
  * A given Store can only have one Queries object associated with it. If you
2998
2996
  * call this function twice on the same Store, your second call will return a
2999
2997
  * reference to the Queries object created by the first.