tinybase 6.0.0-beta.1 → 6.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,599 +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
- * @packageDocumentation
8
- * @module tools
9
- * @since v2.2.0
10
- */
11
-
12
- import type {OptionalSchemas, Store} from '../../store/with-schemas/index.d.ts';
13
- import type {Id} from '../../common/with-schemas/index.d.ts';
14
-
15
- /**
16
- * The StoreStats type describes a set of statistics about the Store, and
17
- * is used for debugging purposes.
18
- *
19
- * A StoreStats object is returned from the getStoreStats method.
20
- * @category Statistics
21
- * @since v2.2.0
22
- */
23
- export type StoreStats = {
24
- /**
25
- * The number of Table objects in the Store.
26
- * @category Stat
27
- * @since v2.2.0
28
- */
29
- totalTables: number;
30
- /**
31
- * The number of Row objects in the Store, across all Table objects.
32
- * @category Stat
33
- * @since v2.2.0
34
- */
35
- totalRows: number;
36
- /**
37
- * The number of Cell objects in the Store, across all Row objects, across all
38
- * Table objects.
39
- * @category Stat
40
- * @since v2.2.0
41
- */
42
- totalCells: number;
43
- /**
44
- * The number of Value objects in the Store, since v3.0.
45
- * @category Stat
46
- * @since v2.2.0
47
- */
48
- totalValues: number;
49
- /**
50
- * The string length of the Store when serialized to JSON.
51
- * @category Stat
52
- * @since v2.2.0
53
- */
54
- jsonLength: number;
55
- /**
56
- * Additional detailed statistics about the Store if the `detail` flag is
57
- * specified in the getStoreStats method.
58
- * @category Stat
59
- * @since v2.2.0
60
- */
61
- detail?: StoreStatsDetail;
62
- };
63
-
64
- /**
65
- * The StoreStatsDetail type describes a more detailed set of statistics about
66
- * the Store, and is used for debugging purposes.
67
- *
68
- * A StoreStatsDetail object is added to the StoreStats object (returned from
69
- * the getStoreStats method) when the `detail` flag is specified.
70
- * @category Statistics
71
- * @since v2.2.0
72
- */
73
- export type StoreStatsDetail = {
74
- /**
75
- * Information about each Table in the Store.
76
- * @category Stat
77
- * @since v2.2.0
78
- */
79
- tables: {[tableId: Id]: StoreStatsTableDetail};
80
- };
81
-
82
- /**
83
- * The StoreStatsTableDetail type describes a detailed set of statistics about a
84
- * single Table in the Store, and is used for debugging purposes.
85
- * @category Statistics
86
- * @since v2.2.0
87
- */
88
- export type StoreStatsTableDetail = {
89
- /**
90
- * The number of Row objects in the Table.
91
- * @category Stat
92
- * @since v2.2.0
93
- */
94
- tableRows: number;
95
- /**
96
- * The number of Cell objects in the Table, across all Row objects.
97
- * @category Stat
98
- * @since v2.2.0
99
- */
100
- tableCells: number;
101
- /**
102
- * Detail about the Table object.
103
- * @category Stat
104
- * @since v2.2.0
105
- */
106
- rows: {[rowId: Id]: StoreStatsRowDetail};
107
- };
108
-
109
- /**
110
- * The StoreStatsRowDetail type describes statistics about a single Row in the
111
- * Store, and is used for debugging purposes.
112
- * @category Statistics
113
- * @since v2.2.0
114
- */
115
- export type StoreStatsRowDetail = {
116
- /**
117
- * The number of Cell objects in the Row.
118
- * @category Stat
119
- * @since v2.2.0
120
- */
121
- rowCells: number;
122
- };
123
-
124
- /**
125
- * A Tools object lets you run various utilities on, and get certain information
126
- * about, Store objects in development.
127
- * @see Developer Tools guides
128
- * @category Tools
129
- * @since v2.2.0
130
- */
131
- export interface Tools<in out Schemas extends OptionalSchemas> {
132
- /* eslint-disable max-len */
133
- /**
134
- * The getStoreStats method provides a set of statistics about the Store, and
135
- * is used for debugging purposes.
136
- * @param detail An optional boolean that indicates more detailed stats about
137
- * the inner structure of the Store should be returned.
138
- * @returns A StoreStats object containing statistics about the Store.
139
- * @example
140
- * This example creates a Tools object and gets basic statistics about it.
141
- *
142
- * ```js
143
- * import {createStore} from 'tinybase';
144
- * import {createTools} from 'tinybase/tools';
145
- *
146
- * const store = createStore()
147
- * .setTable('pets', {
148
- * fido: {species: 'dog', color: 'brown'},
149
- * felix: {species: 'cat', color: 'black'},
150
- * cujo: {species: 'dog', color: 'black'},
151
- * })
152
- * .setTable('species', {
153
- * dog: {price: 5},
154
- * cat: {price: 4},
155
- * })
156
- * .setValues({open: true, employees: 3});
157
- * console.log(createTools(store).getStoreStats());
158
- * // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
159
- * ```
160
- * @example
161
- * This example creates a Tools object and gets detailed statistics about it.
162
- *
163
- * ```js
164
- * import {createStore} from 'tinybase';
165
- * import {createTools} from 'tinybase/tools';
166
- *
167
- * const store = createStore()
168
- * .setTable('pets', {
169
- * fido: {species: 'dog', color: 'brown'},
170
- * felix: {species: 'cat', color: 'black'},
171
- * cujo: {species: 'dog', color: 'black'},
172
- * })
173
- * .setTable('species', {
174
- * dog: {price: 5},
175
- * cat: {price: 4},
176
- * });
177
- * const stats = createTools(store).getStoreStats(true);
178
- *
179
- * console.log(stats.totalTables);
180
- * // -> 2
181
- * console.log(stats.totalRows);
182
- * // -> 5
183
- * console.log(stats.totalCells);
184
- * // -> 8
185
- * console.log(stats.detail.tables.pets.tableRows);
186
- * // -> 3
187
- * console.log(stats.detail.tables.pets.tableCells);
188
- * // -> 6
189
- * console.log(stats.detail.tables.pets.rows);
190
- * // -> {fido: {rowCells: 2}, felix: {rowCells: 2}, cujo: {rowCells: 2}}
191
- * ```
192
- * @category Statistics
193
- * @since v2.2.0
194
- */
195
- getStoreStats(detail?: boolean): StoreStats;
196
-
197
- /* eslint-enable max-len */
198
-
199
- /**
200
- * The getStoreTablesSchema method returns the TablesSchema of the Store as an
201
- * object.
202
- *
203
- * If the Store does not already have an explicit TablesSchema associated with
204
- * it, the data in the Store will be scanned to attempt to infer a new
205
- * TablesSchema.
206
- *
207
- * To be successful, this requires all the values of a given Cell across a
208
- * Table object's Row objects to have a consistent type. If a given Cell Id
209
- * appears in every Row, then a `default` for that Cell is specified in the
210
- * TablesSchema, based on the most common value found.
211
- * @returns A TablesSchema object for the Store.
212
- * @example
213
- * This example creates a Tools object and gets the schema of a Store that
214
- * already has a TablesSchema.
215
- *
216
- * ```js
217
- * import {createStore} from 'tinybase';
218
- * import {createTools} from 'tinybase/tools';
219
- *
220
- * const store = createStore().setTablesSchema({
221
- * pets: {
222
- * species: {type: 'string'},
223
- * color: {type: 'string'},
224
- * },
225
- * species: {
226
- * price: {type: 'number'},
227
- * },
228
- * });
229
- * const schema = createTools(store).getStoreTablesSchema();
230
- * console.log(schema.pets);
231
- * // -> {species: {type: 'string'}, color: {type: 'string'}}
232
- * ```
233
- * @example
234
- * This example creates a Tools object and infers the schema of a Store that
235
- * doesn't already have a TablesSchema.
236
- *
237
- * ```js
238
- * import {createStore} from 'tinybase';
239
- * import {createTools} from 'tinybase/tools';
240
- *
241
- * const store = createStore()
242
- * .setTable('pets', {
243
- * fido: {species: 'dog', color: 'brown'},
244
- * felix: {species: 'cat', color: 'black'},
245
- * cujo: {species: 'dog', color: 'black'},
246
- * })
247
- * .setTable('species', {
248
- * dog: {price: 5, barks: true},
249
- * cat: {price: 4, purrs: true},
250
- * });
251
- * const schema = createTools(store).getStoreTablesSchema();
252
- * console.log(schema.pets.species);
253
- * // -> {type: 'string', default: 'dog'}
254
- * console.log(schema.pets.color);
255
- * // -> {type: 'string', default: 'black'}
256
- * console.log(schema.species.price);
257
- * // -> {type: 'number', default: 5}
258
- * console.log(schema.species.barks);
259
- * // -> {type: 'boolean'}
260
- * console.log(schema.species.purrs);
261
- * // -> {type: 'boolean'}
262
- * ```
263
- * @category Modelling
264
- * @since v3.0.0
265
- */
266
- getStoreTablesSchema(): Schemas[0];
267
-
268
- /**
269
- * The getStoreValuesSchema method returns the ValuesSchema of the Store as an
270
- * object.
271
- *
272
- * If the Store does not already have an explicit ValuesSchema associated with
273
- * it, the data in the Store will be scanned to infer a new ValuesSchema,
274
- * based on the types of the Values present. Note that, unlike the inference
275
- * of Cell values in the TablesSchema, it is not able to determine whether a
276
- * Value should have a default or not.
277
- * @returns A ValuesSchema object for the Store.
278
- * @example
279
- * This example creates a Tools object and gets the schema of a Store that
280
- * already has a ValuesSchema.
281
- *
282
- * ```js
283
- * import {createStore} from 'tinybase';
284
- * import {createTools} from 'tinybase/tools';
285
- *
286
- * const store = createStore().setValuesSchema({
287
- * open: {type: 'boolean', default: true},
288
- * employees: {type: 'number'},
289
- * });
290
- *
291
- * const schema = createTools(store).getStoreValuesSchema();
292
- * console.log(schema);
293
- * // -> {open: {type: 'boolean', default: true}, employees: {type: 'number'}}
294
- * ```
295
- * @example
296
- * This example creates a Tools object and infers the schema of a Store that
297
- * doesn't already have a ValuesSchema.
298
- *
299
- * ```js
300
- * import {createStore} from 'tinybase';
301
- * import {createTools} from 'tinybase/tools';
302
- *
303
- * const store = createStore().setValues({open: true, employees: 3});
304
- * const schema = createTools(store).getStoreValuesSchema();
305
- *
306
- * console.log(schema);
307
- * // -> {open: {type: 'boolean'}, employees: {type: 'number'}}
308
- * ```
309
- * @category Modelling
310
- * @since v3.0.0
311
- */
312
- getStoreValuesSchema(): Schemas[1];
313
-
314
- /**
315
- * The getStoreApi method returns code-generated `.d.ts` and `.ts(x)` files
316
- * that describe the schema of a Store and React bindings (since v3.1) in an
317
- * ORM style.
318
- *
319
- * If the Store does not already have an explicit TablesSchema or ValuesSchema
320
- * associated with it, the data in the Store will be scanned to attempt to
321
- * infer new schemas. The method returns four strings (which should be saved
322
- * as files) though if no schema can be inferred, the strings will be empty.
323
- *
324
- * The method takes a single argument which represents the name you want the
325
- * generated store object to have in code. You are expected to save the four
326
- * files yourself, as the following:
327
- *
328
- * - `[storeName].d.ts` as the main definition,
329
- * - `[storeName].ts` as the main library,
330
- * - `[storeName]-ui-react.d.ts` as the ui-react module definition,
331
- * - `[storeName]-ui-react.tsx` as the ui-react module library.
332
- *
333
- * Also you should save these alongside each other so that the `.ts(x)` files
334
- * can import types from the `.d.ts` files.
335
- *
336
- * The `.d.ts` and `.ts(x)` files that are generated are designed to resemble
337
- * the main TinyBase Store and React binding files, but provide named types
338
- * and methods that describe the domain of the schema in the Store.
339
- *
340
- * For example, from a Store that has a `pets` Table, you will get methods
341
- * like `getPetsTable`, types like `PetsRow`, and hooks and components that
342
- * are more specific versions of the underlying getTable method or the Row
343
- * type, and so on. For example:
344
- *
345
- * |Store type|Equivalent generated type|
346
- * |-|-|
347
- * |Table|[Table]Table|
348
- * |Row|[Table]Row|
349
- * |(Cell) Id|[Table]CellId|
350
- * |CellCallback|[Table]CellCallback|
351
- * |...|...|
352
- *
353
- * |Store method|Equivalent generated method|
354
- * |-|-|
355
- * |setTable|set[Table]Table|
356
- * |hasRow|has[Table]Row|
357
- * |getCell|get[Table][Cell]Cell|
358
- * |...|...|
359
- *
360
- * Equivalent to the TinyBase createStore function, a `create[StoreName]`
361
- * function will also be created. This acts as the main entry point to the
362
- * generated implementation.
363
- *
364
- * Each method is refined correctly to take, or return, the types specified by
365
- * the schema. For example, if the `pets` Table has a numeric `price` Cell in
366
- * the schema, the `getPetsPriceCell` method will be typed to return a number.
367
- *
368
- * The tables above include just a sample of the generated output. For the
369
- * full set of methods and types generated by this method, inspect the output
370
- * directly.
371
- * @param storeName The name you want to provide to the generated Store, which
372
- * should also be used to save the `.d.ts`, `.ts`, and `.tsx` files.
373
- * @returns A set of four strings representing the contents of the `.d.ts`,
374
- * `.ts`, and `.tsx` files for the generated Store and React modules.
375
- * @example
376
- * This example creates a Tools object and generates code for a Store that
377
- * already has a TablesSchema.
378
- *
379
- * ```js
380
- * import {createStore} from 'tinybase';
381
- * import {createTools} from 'tinybase/tools';
382
- *
383
- * const store = createStore().setTablesSchema({
384
- * pets: {
385
- * price: {type: 'number'},
386
- * },
387
- * });
388
- * const [dTs, ts, _uiReactDTs, _uiReactTsx] =
389
- * createTools(store).getStoreApi('shop');
390
- *
391
- * const dTsLines = dTs.split('\n');
392
- * console.log(dTsLines[3]);
393
- * // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price'?: number}}};`
394
- *
395
- * const tsLines = ts.split('\n');
396
- * console.log(tsLines[39]);
397
- * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
398
- * ```
399
- * @example
400
- * This example creates a Tools object and generates code for a Store that
401
- * doesn't already have a TablesSchema.
402
- *
403
- * ```js
404
- * import {createStore} from 'tinybase';
405
- * import {createTools} from 'tinybase/tools';
406
- *
407
- * const store = createStore().setTable('pets', {
408
- * fido: {price: 5},
409
- * felix: {price: 4},
410
- * });
411
- * const [dTs, ts, _uiReactDTs, _uiReactTsx] =
412
- * createTools(store).getStoreApi('shop');
413
- *
414
- * const dTsLines = dTs.split('\n');
415
- * console.log(dTsLines[3]);
416
- * // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price': number}}};`
417
- *
418
- * const tsLines = ts.split('\n');
419
- * console.log(tsLines[41]);
420
- * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
421
- * ```
422
- * @category Modelling
423
- * @since v2.2.0
424
- */
425
- getStoreApi(storeName: string): [string, string, string, string];
426
-
427
- /**
428
- * The getPrettyStoreApi method attempts to return prettified code-generated
429
- * `.d.ts` and `.ts(x)` files that describe the schema of a Store and React
430
- * bindings (since v3.1) in an ORM style.
431
- *
432
- * This is simply a wrapper around the getStoreApi method that attempts to
433
- * invoke the `prettier` module (which it hopes you have installed) to format
434
- * the generated code. If `prettier` is not present, the output will resemble
435
- * that of the underlying getStoreApi method.
436
- *
437
- * The method is asynchronous, so you should use the `await` keyword or handle
438
- * the results as a promise.
439
- *
440
- * The method takes a single argument which represents the name you want the
441
- * generated store object to have in code. You are expected to save the four
442
- * files yourself, as the following:
443
- *
444
- * - `[storeName].d.ts` as the main definition,
445
- * - `[storeName].ts` as the main library,
446
- * - `[storeName]-ui-react.d.ts` as the ui-react module definition,
447
- * - `[storeName]-ui-react.tsx` as the ui-react module library.
448
- *
449
- * Also you should save these alongside each other so that the `.ts(x)` files
450
- * can import types from the `.d.ts` files.
451
- *
452
- * See the documentation for the getStoreApi method for details of the content
453
- * of the generated files.
454
- * @param storeName The name you want to provide to the generated Store, which
455
- * should also be used to save the `.d.ts`, `.ts`, and `.tsx` files.
456
- * @returns A set of four strings representing the contents of the `.d.ts`,
457
- * `.ts`, and `.tsx` files for the generated Store and React modules.
458
- * @example
459
- * This example creates a Tools object and generates code for a Store that
460
- * already has a TablesSchema.
461
- *
462
- * ```js
463
- * import {createStore} from 'tinybase';
464
- * import {createTools} from 'tinybase/tools';
465
- *
466
- * const store = createStore().setTablesSchema({
467
- * pets: {
468
- * price: {type: 'number'},
469
- * },
470
- * });
471
- * const [dTs, ts, _uiReactDTs, _uiReactTsx] =
472
- * await createTools(store).getPrettyStoreApi('shop');
473
- *
474
- * const dTsLines = dTs.split('\n');
475
- * console.log(dTsLines[15]);
476
- * // -> `export type Tables = {pets?: {[rowId: Id]: {price?: number}}};`
477
- *
478
- * const tsLines = ts.split('\n');
479
- * console.log(tsLines[89]);
480
- * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
481
- * ```
482
- * @example
483
- * This example creates a Tools object and generates code for a Store that
484
- * doesn't already have a TablesSchema.
485
- *
486
- * ```js
487
- * import {createStore} from 'tinybase';
488
- * import {createTools} from 'tinybase/tools';
489
- *
490
- * const store = createStore().setTable('pets', {
491
- * fido: {price: 5},
492
- * felix: {price: 4},
493
- * });
494
- * const [dTs, ts, _uiReactDTs, _uiReactTsx] =
495
- * await createTools(store).getPrettyStoreApi('shop');
496
- *
497
- * const dTsLines = dTs.split('\n');
498
- * console.log(dTsLines[15]);
499
- * // -> 'export type Tables = {pets?: {[rowId: Id]: {price: number}}};'
500
- *
501
- * const tsLines = ts.split('\n');
502
- * console.log(tsLines[91]);
503
- * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
504
- * ```
505
- * @category Modelling
506
- * @since v2.2.0
507
- */
508
- getPrettyStoreApi(
509
- storeName: string,
510
- ): Promise<[string, string, string, string]>;
511
-
512
- /**
513
- * The getStore method returns a reference to the underlying Store that is
514
- * backing this Tools object.
515
- * @returns A reference to the Store.
516
- * @example
517
- * This example creates a Tools object against a newly-created Store and
518
- * then gets its reference in order to update its data.
519
- *
520
- * This has schema-based typing. The following is a simplified representation:
521
- *
522
- * ```ts override
523
- * getStore(): Store;
524
- * ```
525
- *
526
- * ```js
527
- * import {createStore} from 'tinybase';
528
- * import {createTools} from 'tinybase/tools';
529
- *
530
- * const tools = createTools(createStore());
531
- * tools.getStore().setCell('species', 'dog', 'price', 5);
532
- * console.log(tools.getStoreStats().totalCells);
533
- * // -> 1
534
- * ```
535
- * @category Getter
536
- * @since v3.0.0
537
- */
538
- getStore(): Store<Schemas>;
539
- }
540
-
541
- /* eslint-disable max-len */
542
- /**
543
- * The createTools function creates a Tools object, and is the main entry point
544
- * into the tools module.
545
- *
546
- * This has schema-based typing. The following is a simplified representation:
547
- *
548
- * ```ts override
549
- * createTools(store: Store): Tools;
550
- * ```
551
- *
552
- * A given Store can only have one Tools object associated with it. If you call
553
- * this function twice on the same Store, your second call will return a
554
- * reference to the Tools object created by the first.
555
- * @param store The Store for which to register tools.
556
- * @returns A reference to the new Tools object.
557
- * @example
558
- * This example creates a Tools object.
559
- *
560
- * ```js
561
- * import {createStore} from 'tinybase';
562
- * import {createTools} from 'tinybase/tools';
563
- *
564
- * const store = createStore()
565
- * .setTable('pets', {
566
- * fido: {species: 'dog', color: 'brown'},
567
- * felix: {species: 'cat', color: 'black'},
568
- * cujo: {species: 'dog', color: 'black'},
569
- * })
570
- * .setTable('species', {
571
- * dog: {price: 5},
572
- * cat: {price: 4},
573
- * })
574
- * .setValues({open: true, employees: 3});
575
- * console.log(createTools(store).getStoreStats());
576
- * // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
577
- * ```
578
- * @example
579
- * This example creates a Tools object, and calls the method a second time
580
- * for the same Store to return the same object.
581
- *
582
- * ```js
583
- * import {createStore} from 'tinybase';
584
- * import {createTools} from 'tinybase/tools';
585
- *
586
- * const store = createStore();
587
- * const tools1 = createTools(store);
588
- * const tools2 = createTools(store);
589
- * console.log(tools1 === tools2);
590
- * // -> true
591
- * ```
592
- * @category Creation
593
- * @since v2.2.0
594
- */
595
- export function createTools<Schemas extends OptionalSchemas>(
596
- store: Store<Schemas>,
597
- ): Tools<Schemas>;
598
-
599
- /* eslint-enable max-len */
package/cli/index.js DELETED
@@ -1,93 +0,0 @@
1
- #! /usr/bin/env node
2
- import {resolve, dirname} from 'path';
3
- import {writeFileSync, readFileSync} from 'fs';
4
- import {createStore} from 'tinybase/store';
5
- import {createTools} from 'tinybase/tools';
6
- import {fileURLToPath} from 'url';
7
-
8
- const UTF8 = 'utf8';
9
-
10
- const isArray = (thing) => Array.isArray(thing);
11
-
12
- const arrayForEach = (array, cb) => array.forEach(cb);
13
- const arrayMap = (array, cb) => array.map(cb);
14
-
15
- const object = Object;
16
- const objEntries = object.entries;
17
- const objNew = (entries = []) => object.fromEntries(entries);
18
- const objToArray = (obj, cb) =>
19
- arrayMap(objEntries(obj), ([id, value]) => cb(value, id));
20
- const objMap = (obj, cb) =>
21
- objNew(objToArray(obj, (value, id) => [id, cb(value, id)]));
22
-
23
- const jsonParse = JSON.parse;
24
-
25
- const FILE_ERROR = 'provide a valid schemaFile, storeName, and outputDir';
26
- const log = (...lines) =>
27
- arrayForEach(lines, (line) =>
28
- process.stdout.write(`${line}
29
- `),
30
- );
31
- const err = (line) =>
32
- process.stderr.write(`ERROR: ${line}
33
- `);
34
- const getJson = (file) => jsonParse(readFileSync(file, UTF8));
35
- const writeFile = (outputDir, fileName, content, label) => {
36
- const file = resolve(outputDir, fileName);
37
- log(label.padStart(23) + ': ' + file);
38
- writeFileSync(file, content, UTF8);
39
- };
40
- const getTools = (schemaFile) => {
41
- const schema = getJson(schemaFile);
42
- return createTools(
43
- createStore().setSchema(...(isArray(schema) ? schema : [schema])),
44
- );
45
- };
46
- const help = () => {
47
- log('', 'tinybase <command>', '', 'Usage:', '');
48
- objMap(commands, ([, args, help2], command) =>
49
- log(` tinybase ${command} ${args}`, ` - ${help2}`, ''),
50
- );
51
- log('See also http://tinybase.org/guides/developer-tools/command-line/', '');
52
- };
53
- const version = () =>
54
- log(
55
- getJson(resolve(dirname(fileURLToPath(import.meta.url)), '../package.json'))
56
- .version,
57
- );
58
- const getStoreApi = async (schemaFile, storeName, outputDir) => {
59
- try {
60
- const [dTs, ts, uiReactDTs, uiReactTsx] =
61
- await getTools(schemaFile).getPrettyStoreApi(storeName);
62
- writeFile(outputDir, storeName + '.d.ts', dTs, 'Definition');
63
- writeFile(outputDir, storeName + '.ts', ts, 'Implementation');
64
- writeFile(
65
- outputDir,
66
- storeName + '-ui-react.d.ts',
67
- uiReactDTs,
68
- 'UI React definition',
69
- );
70
- writeFile(
71
- outputDir,
72
- storeName + '-ui-react.tsx',
73
- uiReactTsx,
74
- 'UI React implementation',
75
- );
76
- } catch {
77
- err(FILE_ERROR);
78
- }
79
- };
80
- const commands = {
81
- help: [help, '', 'print this message'],
82
- version: [version, '', 'get the current TinyBase version'],
83
- getStoreApi: [
84
- getStoreApi,
85
- '<schemaFile> <storeName> <outputDir>',
86
- 'generate .d.ts, .ts, and .tsx API files from a schema file',
87
- ],
88
- };
89
- const main = () => {
90
- const [, , command, ...args] = process.argv;
91
- (commands[command]?.[0] ?? help)(...args);
92
- };
93
- main();