tinybase 3.1.0-beta.2 → 3.1.0-beta.3
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.
- package/bin/cli.js +1 -1
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/tools.d.ts +193 -27
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/tools.d.ts +193 -27
- package/lib/debug/tools.d.ts +193 -27
- package/lib/debug/tools.js +1266 -451
- package/lib/es6/tools.d.ts +193 -27
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/tools.d.ts +193 -27
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/umd/tools.d.ts +193 -27
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +193 -27
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/package.json +17 -17
- package/readme.md +1 -1
package/lib/debug/tools.js
CHANGED
|
@@ -74,27 +74,44 @@ const A = 'a ';
|
|
|
74
74
|
const A_FUNCTION_FOR = 'A function for';
|
|
75
75
|
const CALLBACK = 'Callback';
|
|
76
76
|
const DEL = 'Del';
|
|
77
|
+
const DO_ROLLBACK_PARAM = 'doRollback?: DoRollback';
|
|
78
|
+
const DO_ACTIONS_AND_ROLLBACK_PARAMS =
|
|
79
|
+
'actions: () => Return, ' + DO_ROLLBACK_PARAM;
|
|
77
80
|
const EXPORT = 'export';
|
|
78
81
|
const ID = 'Id';
|
|
82
|
+
const ID_OR_NULL = 'IdOrNull';
|
|
79
83
|
const INVALID = 'Invalid';
|
|
80
84
|
const JSON$1 = 'Json';
|
|
81
85
|
const LISTENER_ = lower(LISTENER);
|
|
82
86
|
const OR_UNDEFINED = ' | undefined';
|
|
87
|
+
const NON_NULLABLE = 'NonNullable';
|
|
83
88
|
const PARTIAL = 'Partial';
|
|
84
89
|
const REGISTERS_A_LISTENER = `Registers a ${LISTENER_} that will be called`;
|
|
85
90
|
const REPRESENTS = 'Represents';
|
|
91
|
+
const ROW_ID_PARAM = 'rowId: ' + ID;
|
|
92
|
+
const ROW_ID_OR_NULL_PARAM = 'rowId: ' + ID_OR_NULL;
|
|
93
|
+
const SCHEMA = 'Schema';
|
|
86
94
|
const SET = 'Set';
|
|
95
|
+
const SORTED_ARGS = ', descending?: boolean, offset?: number, limit?: number';
|
|
87
96
|
const SQUARE_BRACKETS = '[]';
|
|
88
|
-
const
|
|
97
|
+
const STORE = 'Store';
|
|
98
|
+
const THE_STORE = 'the ' + STORE;
|
|
89
99
|
const TRANSACTION = 'Transaction';
|
|
90
100
|
const TRANSACTION_ = lower(TRANSACTION);
|
|
101
|
+
const TRANSACTION_DOC =
|
|
102
|
+
'Execute a ' + TRANSACTION_ + ' to make multiple mutations';
|
|
103
|
+
const START_TRANSACTION_DOC = 'Explicitly starts a ' + TRANSACTION_;
|
|
104
|
+
const FINISH_TRANSACTION_DOC = 'Explicitly finishes a ' + TRANSACTION_;
|
|
91
105
|
const THE_END_OF_THE_TRANSACTION = 'the end of the ' + TRANSACTION_;
|
|
92
106
|
const VOID = 'void';
|
|
93
107
|
const RETURNS_VOID = ' => ' + VOID;
|
|
108
|
+
const WHEN_SET = 'WhenSet';
|
|
109
|
+
const WHEN_SETTING_IT = ' when setting it';
|
|
94
110
|
const A_STRING_SERIALIZATION_OF = A + 'string serialization of';
|
|
95
111
|
const SPACE = ' ';
|
|
96
112
|
const GETS_A_CALLBACK_THAT_CAN = 'Gets a callback that can ';
|
|
97
113
|
const THE = 'the ';
|
|
114
|
+
const THE_SCHEMA_FOR = ' the schema for';
|
|
98
115
|
const getTheContentOfDoc = (content = 0, theStore = 0) =>
|
|
99
116
|
`the ${CONTENT[content]}content of` +
|
|
100
117
|
(theStore ? SPACE + THE_STORE : EMPTY_STRING);
|
|
@@ -102,7 +119,7 @@ const getTheContentOfTheStoreDoc = (content = 0, verb, set = 0) =>
|
|
|
102
119
|
VERBS[verb] +
|
|
103
120
|
SPACE +
|
|
104
121
|
getTheContentOfDoc(content, 1) +
|
|
105
|
-
(set ? ' when
|
|
122
|
+
(set ? ' when setting it' : EMPTY_STRING);
|
|
106
123
|
const getRowTypeDoc = (tableId, set = 0) =>
|
|
107
124
|
REPRESENTS +
|
|
108
125
|
` a Row when ${
|
|
@@ -133,6 +150,7 @@ const getListenerDoc = (childNoun, parentNoun, pluralChild = 0) =>
|
|
|
133
150
|
(pluralChild ? EMPTY_STRING : 's');
|
|
134
151
|
const getTableDoc = (tableId) => `the '${tableId}' ` + TABLE;
|
|
135
152
|
const getRowDoc = (tableId) => 'the specified Row in ' + getTableDoc(tableId);
|
|
153
|
+
const getContentDoc = (verb = 0, noun = 0) => VERBS[verb] + SPACE + NOUNS[noun];
|
|
136
154
|
const getTableContentDoc = (tableId, verb = 0) =>
|
|
137
155
|
VERBS[verb] + ` ${getTheContentOfDoc()} ` + getTableDoc(tableId);
|
|
138
156
|
const getRowContentDoc = (tableId, verb = 0) =>
|
|
@@ -156,6 +174,20 @@ const VERBS = [
|
|
|
156
174
|
GETS_A_CALLBACK_THAT_CAN + 'set part of',
|
|
157
175
|
GETS_A_CALLBACK_THAT_CAN + 'delete',
|
|
158
176
|
'Renders',
|
|
177
|
+
'Gets ' + A_STRING_SERIALIZATION_OF + THE_SCHEMA_FOR,
|
|
178
|
+
'Sets' + THE_SCHEMA_FOR,
|
|
179
|
+
'Deletes' + THE_SCHEMA_FOR,
|
|
180
|
+
];
|
|
181
|
+
const METHOD_PREFIX_VERBS = [
|
|
182
|
+
GET,
|
|
183
|
+
'has',
|
|
184
|
+
'set',
|
|
185
|
+
'del',
|
|
186
|
+
'set',
|
|
187
|
+
// partial
|
|
188
|
+
'forEach',
|
|
189
|
+
ADD,
|
|
190
|
+
EMPTY_STRING,
|
|
159
191
|
];
|
|
160
192
|
const NOUNS = [
|
|
161
193
|
THE_STORE,
|
|
@@ -234,6 +266,9 @@ const getParameterList = (...params) =>
|
|
|
234
266
|
arrayFilter(params, (param) => param),
|
|
235
267
|
', ',
|
|
236
268
|
);
|
|
269
|
+
const getFieldTypeList = (...props) => '{' + join(props, '; ') + '}';
|
|
270
|
+
const getPropTypeList = (...props) =>
|
|
271
|
+
getFieldTypeList(...arrayMap(props, (prop) => 'readonly ' + prop));
|
|
237
272
|
const getCodeFunctions = () => {
|
|
238
273
|
const allImports = [mapNew(), mapNew(), mapNew(), mapNew()];
|
|
239
274
|
const types = mapNew();
|
|
@@ -247,7 +282,8 @@ const getCodeFunctions = () => {
|
|
|
247
282
|
: 0,
|
|
248
283
|
),
|
|
249
284
|
);
|
|
250
|
-
const addType = (name, body, doc
|
|
285
|
+
const addType = (name, body, doc, generic = EMPTY_STRING, exported = 1) =>
|
|
286
|
+
mapUnique(types, name, [body, doc, generic, exported]);
|
|
251
287
|
const addInternalFunction = (name, parameters, body) =>
|
|
252
288
|
mapUnique(
|
|
253
289
|
constants,
|
|
@@ -285,9 +321,11 @@ const getCodeFunctions = () => {
|
|
|
285
321
|
// sigh
|
|
286
322
|
);
|
|
287
323
|
const getTypes = () =>
|
|
288
|
-
mapMap(types, ([body, doc], name) => [
|
|
324
|
+
mapMap(types, ([body, doc, generic, exported], name) => [
|
|
289
325
|
comment(doc),
|
|
290
|
-
`${
|
|
326
|
+
`${
|
|
327
|
+
exported ? EXPORT + ' ' : EMPTY_STRING
|
|
328
|
+
}type ${name}${generic} = ${body};`,
|
|
291
329
|
EMPTY_STRING,
|
|
292
330
|
]);
|
|
293
331
|
const getConstants = () =>
|
|
@@ -359,16 +397,362 @@ const getSchemaFunctions = (tablesSchema, valuesSchema, addConstant) => {
|
|
|
359
397
|
return [mapTablesSchema, mapCellSchema, mapValuesSchema];
|
|
360
398
|
};
|
|
361
399
|
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
400
|
+
const getTypeFunctions = (
|
|
401
|
+
addType,
|
|
402
|
+
mapTablesSchema,
|
|
403
|
+
mapCellSchema,
|
|
404
|
+
mapValuesSchema,
|
|
405
|
+
) => {
|
|
406
|
+
const getTablesTypes = (storeInstance, storeType) => {
|
|
407
|
+
const storeParam = storeInstance + ': ' + storeType;
|
|
408
|
+
const tablesType = addType(
|
|
409
|
+
TABLES,
|
|
410
|
+
getFieldTypeList(
|
|
411
|
+
...mapTablesSchema(
|
|
412
|
+
(tableId) =>
|
|
413
|
+
`'${tableId}'?: {[rowId: Id]: ` +
|
|
414
|
+
getFieldTypeList(
|
|
415
|
+
...mapCellSchema(
|
|
416
|
+
tableId,
|
|
417
|
+
(cellId, type, defaultValue) =>
|
|
418
|
+
`'${cellId}'${
|
|
419
|
+
isUndefined(defaultValue) ? '?' : EMPTY_STRING
|
|
420
|
+
}: ${type}`,
|
|
421
|
+
),
|
|
422
|
+
) +
|
|
423
|
+
'}',
|
|
424
|
+
),
|
|
425
|
+
),
|
|
426
|
+
getTheContentOfTheStoreDoc(1, 5),
|
|
427
|
+
);
|
|
428
|
+
const tablesWhenSetType = addType(
|
|
429
|
+
TABLES + WHEN_SET,
|
|
430
|
+
getFieldTypeList(
|
|
431
|
+
...mapTablesSchema(
|
|
432
|
+
(tableId) =>
|
|
433
|
+
`'${tableId}'?: {[rowId: Id]: ` +
|
|
434
|
+
getFieldTypeList(
|
|
435
|
+
...mapCellSchema(
|
|
436
|
+
tableId,
|
|
437
|
+
(cellId, type) => `'${cellId}'?: ${type}`,
|
|
438
|
+
),
|
|
439
|
+
) +
|
|
440
|
+
'}',
|
|
441
|
+
),
|
|
442
|
+
),
|
|
443
|
+
getTheContentOfTheStoreDoc(1, 5, 1),
|
|
444
|
+
);
|
|
445
|
+
const tableIdType = addType(
|
|
446
|
+
TABLE + ID,
|
|
447
|
+
'keyof ' + tablesType,
|
|
448
|
+
'A ' + TABLE + ' Id in ' + THE_STORE,
|
|
449
|
+
);
|
|
450
|
+
const tIdGeneric = `<TId extends ${tableIdType}>`;
|
|
451
|
+
const tableType = addType(
|
|
452
|
+
TABLE,
|
|
453
|
+
NON_NULLABLE + `<${tablesType}[TId]>`,
|
|
454
|
+
'A ' + TABLE + ' in ' + THE_STORE,
|
|
455
|
+
tIdGeneric,
|
|
456
|
+
);
|
|
457
|
+
const tableWhenSetType = addType(
|
|
458
|
+
TABLE + WHEN_SET,
|
|
459
|
+
NON_NULLABLE + `<${tablesWhenSetType}[TId]>`,
|
|
460
|
+
'A ' + TABLE + ' in ' + THE_STORE + WHEN_SETTING_IT,
|
|
461
|
+
tIdGeneric,
|
|
462
|
+
);
|
|
463
|
+
const rowType = addType(
|
|
464
|
+
ROW,
|
|
465
|
+
tableType + '<TId>[Id]',
|
|
466
|
+
'A ' + ROW + ' in a ' + TABLE,
|
|
467
|
+
tIdGeneric,
|
|
468
|
+
);
|
|
469
|
+
const rowWhenSetType = addType(
|
|
470
|
+
ROW + WHEN_SET,
|
|
471
|
+
tableWhenSetType + '<TId>[Id]',
|
|
472
|
+
'A ' + ROW + ' in a ' + TABLE + WHEN_SETTING_IT,
|
|
473
|
+
tIdGeneric,
|
|
474
|
+
);
|
|
475
|
+
const cellIdType = addType(
|
|
476
|
+
CELL + ID,
|
|
477
|
+
`Extract<keyof ${rowType}<TId>, Id>`,
|
|
478
|
+
'A ' + CELL + ' Id in a ' + ROW,
|
|
479
|
+
tIdGeneric,
|
|
480
|
+
);
|
|
481
|
+
const cellType = addType(
|
|
482
|
+
CELL,
|
|
483
|
+
NON_NULLABLE + `<${tablesType}[TId]>[Id][CId]`,
|
|
484
|
+
'A ' + CELL + ' in a ' + ROW,
|
|
485
|
+
`<TId extends ${tableIdType}, CId extends ${cellIdType}<TId>>`,
|
|
486
|
+
);
|
|
487
|
+
const cellIdCellArrayType = addType(
|
|
488
|
+
'CellIdCellArray',
|
|
489
|
+
`CId extends ${cellIdType}<TId> ? [cellId: CId, cell: ${cellType}<TId, CId>] : never`,
|
|
490
|
+
CELL + ' Ids and types in a ' + ROW,
|
|
491
|
+
`<TId extends ${tableIdType}, CId = ${cellIdType}<TId>>`,
|
|
492
|
+
0,
|
|
493
|
+
);
|
|
494
|
+
const cellCallbackType = addType(
|
|
495
|
+
CELL + CALLBACK,
|
|
496
|
+
`(...[cellId, cell]: ${cellIdCellArrayType}<TId>)` + RETURNS_VOID,
|
|
497
|
+
getCallbackDoc(A + CELL + ' Id, and ' + CELL),
|
|
498
|
+
tIdGeneric,
|
|
499
|
+
);
|
|
500
|
+
const rowCallbackType = addType(
|
|
501
|
+
ROW + CALLBACK,
|
|
502
|
+
'(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) ' +
|
|
503
|
+
RETURNS_VOID +
|
|
504
|
+
') ' +
|
|
505
|
+
RETURNS_VOID,
|
|
506
|
+
getCallbackDoc(A + ROW + ' Id, and a ' + CELL + ' iterator'),
|
|
507
|
+
tIdGeneric,
|
|
508
|
+
);
|
|
509
|
+
const tableIdForEachRowArrayType = addType(
|
|
510
|
+
'TableIdForEachRowArray',
|
|
511
|
+
`TId extends ${tableIdType} ? [tableId: TId, forEachRow: (rowCallback: ${rowCallbackType}<TId>)${RETURNS_VOID}] : never`,
|
|
512
|
+
TABLE + ' Ids and callback types',
|
|
513
|
+
`<TId = ${tableIdType}>`,
|
|
514
|
+
0,
|
|
515
|
+
);
|
|
516
|
+
const tableCallbackType = addType(
|
|
517
|
+
TABLE + CALLBACK,
|
|
518
|
+
`(...[tableId, forEachRow]: ${tableIdForEachRowArrayType})` +
|
|
519
|
+
RETURNS_VOID,
|
|
520
|
+
getCallbackDoc(A + TABLE + ' Id, and a ' + ROW + ' iterator'),
|
|
521
|
+
EMPTY_STRING,
|
|
522
|
+
);
|
|
523
|
+
const tableIdRowIdCellIdArrayType = addType(
|
|
524
|
+
'TableIdRowIdCellIdArray',
|
|
525
|
+
`TId extends ${tableIdType} ? [tableId: TId, rowId: Id, cellId: ${cellIdType}<TId>] : never`,
|
|
526
|
+
'Ids for GetCellChange',
|
|
527
|
+
`<TId = ${tableIdType}>`,
|
|
528
|
+
0,
|
|
529
|
+
);
|
|
530
|
+
const getCellChangeType = addType(
|
|
531
|
+
'GetCellChange',
|
|
532
|
+
`(...[tableId, rowId, cellId]: ${tableIdRowIdCellIdArrayType}) => CellChange`,
|
|
533
|
+
A_FUNCTION_FOR +
|
|
534
|
+
` returning information about any Cell's changes during a ` +
|
|
535
|
+
TRANSACTION_,
|
|
536
|
+
);
|
|
537
|
+
const tablesListenerType = addType(
|
|
538
|
+
TABLES + LISTENER,
|
|
539
|
+
`(${storeParam}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
540
|
+
RETURNS_VOID,
|
|
541
|
+
getListenerTypeDoc(1),
|
|
542
|
+
);
|
|
543
|
+
const tableIdsListenerType = addType(
|
|
544
|
+
TABLE_IDS + LISTENER,
|
|
545
|
+
`(${storeParam})` + RETURNS_VOID,
|
|
546
|
+
getListenerTypeDoc(2),
|
|
547
|
+
);
|
|
548
|
+
const tableListenerType = addType(
|
|
549
|
+
TABLE + LISTENER,
|
|
550
|
+
`(${storeParam}, tableId: ${tableIdType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
551
|
+
RETURNS_VOID,
|
|
552
|
+
getListenerTypeDoc(3),
|
|
553
|
+
);
|
|
554
|
+
const rowIdsListenerType = addType(
|
|
555
|
+
ROW_IDS + LISTENER,
|
|
556
|
+
`(${storeParam}, tableId: ${tableIdType})` + RETURNS_VOID,
|
|
557
|
+
getListenerTypeDoc(4, 3),
|
|
558
|
+
);
|
|
559
|
+
const sortedRowIdsListenerType = addType(
|
|
560
|
+
SORTED_ROW_IDS + LISTENER,
|
|
561
|
+
'(' +
|
|
562
|
+
getParameterList(
|
|
563
|
+
storeParam,
|
|
564
|
+
'tableId: ' + tableIdType,
|
|
565
|
+
'cellId: Id' + OR_UNDEFINED,
|
|
566
|
+
'descending: boolean',
|
|
567
|
+
'offset: number',
|
|
568
|
+
'limit: number' + OR_UNDEFINED,
|
|
569
|
+
'sortedRowIds: Ids',
|
|
570
|
+
) +
|
|
571
|
+
')' +
|
|
572
|
+
RETURNS_VOID,
|
|
573
|
+
getListenerTypeDoc(13, 3),
|
|
574
|
+
);
|
|
575
|
+
const rowListenerType = addType(
|
|
576
|
+
ROW + LISTENER,
|
|
577
|
+
'(' +
|
|
578
|
+
getParameterList(
|
|
579
|
+
`${storeParam}`,
|
|
580
|
+
'tableId: ' + tableIdType,
|
|
581
|
+
ROW_ID_PARAM,
|
|
582
|
+
`getCellChange: ${getCellChangeType}${OR_UNDEFINED}`,
|
|
583
|
+
) +
|
|
584
|
+
')' +
|
|
585
|
+
RETURNS_VOID,
|
|
586
|
+
getListenerTypeDoc(5, 3),
|
|
587
|
+
);
|
|
588
|
+
const cellIdsListenerType = addType(
|
|
589
|
+
CELL_IDS + LISTENER,
|
|
590
|
+
'(' +
|
|
591
|
+
getParameterList(
|
|
592
|
+
`${storeParam}`,
|
|
593
|
+
'tableId: ' + tableIdType,
|
|
594
|
+
ROW_ID_PARAM,
|
|
595
|
+
) +
|
|
596
|
+
')' +
|
|
597
|
+
RETURNS_VOID,
|
|
598
|
+
getListenerTypeDoc(6, 5),
|
|
599
|
+
);
|
|
600
|
+
const cellListenerArgsArrayInnerType = addType(
|
|
601
|
+
'CellListenerArgsArrayInner',
|
|
602
|
+
`CId extends ${cellIdType}<TId> ? [${storeParam}, tableId: TId, ${ROW_ID_PARAM}, cellId: CId, newCell: ${cellType}<TId, CId> ${OR_UNDEFINED}, oldCell: ${cellType}<TId, CId> ${OR_UNDEFINED}, getCellChange: ${getCellChangeType} ${OR_UNDEFINED}] : never`,
|
|
603
|
+
'Cell args for CellListener',
|
|
604
|
+
`<TId extends ${tableIdType}, CId = ${cellIdType}<TId>>`,
|
|
605
|
+
0,
|
|
606
|
+
);
|
|
607
|
+
const cellListenerArgsArrayOuterType = addType(
|
|
608
|
+
'CellListenerArgsArrayOuter',
|
|
609
|
+
`TId extends ${tableIdType} ? ` +
|
|
610
|
+
cellListenerArgsArrayInnerType +
|
|
611
|
+
'<TId> : never',
|
|
612
|
+
'Table args for CellListener',
|
|
613
|
+
`<TId = ${tableIdType}>`,
|
|
614
|
+
0,
|
|
615
|
+
);
|
|
616
|
+
const cellListenerType = addType(
|
|
617
|
+
CELL + LISTENER,
|
|
618
|
+
`(...[${storeInstance}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${cellListenerArgsArrayOuterType})` +
|
|
619
|
+
RETURNS_VOID,
|
|
620
|
+
getListenerTypeDoc(7, 5),
|
|
621
|
+
);
|
|
622
|
+
const invalidCellListenerType = addType(
|
|
623
|
+
INVALID + CELL + LISTENER,
|
|
624
|
+
`(${storeParam}, tableId: Id, ${ROW_ID_PARAM}, cellId: Id, invalidCells: any[])` +
|
|
625
|
+
RETURNS_VOID,
|
|
626
|
+
getListenerTypeDoc(8),
|
|
627
|
+
);
|
|
628
|
+
return [
|
|
629
|
+
tablesType,
|
|
630
|
+
tablesWhenSetType,
|
|
631
|
+
tableIdType,
|
|
632
|
+
tableType,
|
|
633
|
+
tableWhenSetType,
|
|
634
|
+
rowType,
|
|
635
|
+
rowWhenSetType,
|
|
636
|
+
cellIdType,
|
|
637
|
+
cellType,
|
|
638
|
+
cellCallbackType,
|
|
639
|
+
rowCallbackType,
|
|
640
|
+
tableCallbackType,
|
|
641
|
+
tablesListenerType,
|
|
642
|
+
tableIdsListenerType,
|
|
643
|
+
tableListenerType,
|
|
644
|
+
rowIdsListenerType,
|
|
645
|
+
sortedRowIdsListenerType,
|
|
646
|
+
rowListenerType,
|
|
647
|
+
cellIdsListenerType,
|
|
648
|
+
cellListenerType,
|
|
649
|
+
invalidCellListenerType,
|
|
650
|
+
];
|
|
651
|
+
};
|
|
652
|
+
const getValuesTypes = (storeInstance, storeType) => {
|
|
653
|
+
const storeParam = storeInstance + ': ' + storeType;
|
|
654
|
+
const valuesType = addType(
|
|
655
|
+
VALUES,
|
|
656
|
+
getFieldTypeList(
|
|
657
|
+
...mapValuesSchema(
|
|
658
|
+
(valueId, type, defaultValue) =>
|
|
659
|
+
`'${valueId}'${
|
|
660
|
+
isUndefined(defaultValue) ? '?' : EMPTY_STRING
|
|
661
|
+
}: ${type}`,
|
|
662
|
+
),
|
|
663
|
+
),
|
|
664
|
+
getTheContentOfTheStoreDoc(2, 5),
|
|
665
|
+
);
|
|
666
|
+
const valuesWhenSetType = addType(
|
|
667
|
+
VALUES + WHEN_SET,
|
|
668
|
+
getFieldTypeList(
|
|
669
|
+
...mapValuesSchema((valueId, type) => `'${valueId}'?: ${type}`),
|
|
670
|
+
),
|
|
671
|
+
getTheContentOfTheStoreDoc(2, 5, 1),
|
|
672
|
+
);
|
|
673
|
+
const valueIdType = addType(
|
|
674
|
+
VALUE + ID,
|
|
675
|
+
'keyof ' + valuesType,
|
|
676
|
+
'A ' + VALUE + ' Id in ' + THE_STORE,
|
|
677
|
+
);
|
|
678
|
+
const valueType = addType(
|
|
679
|
+
VALUE,
|
|
680
|
+
NON_NULLABLE + `<${valuesType}[VId]>`,
|
|
681
|
+
'A ' + VALUE + ' Id in ' + THE_STORE,
|
|
682
|
+
`<VId extends ${valueIdType}>`,
|
|
683
|
+
);
|
|
684
|
+
const valueIdValueArrayType = addType(
|
|
685
|
+
'ValueIdValueArray',
|
|
686
|
+
`VId extends ${valueIdType} ? [valueId: VId, value: ${valueType}<VId>] : never`,
|
|
687
|
+
VALUE + ' Ids and types in ' + THE_STORE,
|
|
688
|
+
`<VId = ${valueIdType}>`,
|
|
689
|
+
0,
|
|
690
|
+
);
|
|
691
|
+
const valueCallbackType = addType(
|
|
692
|
+
VALUE + CALLBACK,
|
|
693
|
+
`(...[valueId, value]: ${valueIdValueArrayType})` + RETURNS_VOID,
|
|
694
|
+
getCallbackDoc(A + VALUE + ' Id, and ' + VALUE),
|
|
695
|
+
);
|
|
696
|
+
const getValueChangeType = addType(
|
|
697
|
+
'GetValueChange',
|
|
698
|
+
`(valueId: ${valueIdType}) => ValueChange`,
|
|
699
|
+
A_FUNCTION_FOR +
|
|
700
|
+
` returning information about any Value's changes during a ` +
|
|
701
|
+
TRANSACTION_,
|
|
702
|
+
);
|
|
703
|
+
const valuesListenerType = addType(
|
|
704
|
+
VALUES + LISTENER,
|
|
705
|
+
`(${storeParam}, getValueChange: ${getValueChangeType}${OR_UNDEFINED})` +
|
|
706
|
+
RETURNS_VOID,
|
|
707
|
+
getListenerTypeDoc(9),
|
|
708
|
+
);
|
|
709
|
+
const valueIdsListenerType = addType(
|
|
710
|
+
VALUE_IDS + LISTENER,
|
|
711
|
+
`(${storeParam})` + RETURNS_VOID,
|
|
712
|
+
getListenerTypeDoc(10),
|
|
713
|
+
);
|
|
714
|
+
const valueListenerArgsArrayType = addType(
|
|
715
|
+
'ValueListenerArgsArray',
|
|
716
|
+
`VId extends ${valueIdType} ? [${storeParam}, valueId: VId, newValue: ${valueType}<VId> ${OR_UNDEFINED}, oldValue: ${valueType}<VId> ${OR_UNDEFINED}, getValueChange: ${getValueChangeType} ${OR_UNDEFINED}] : never`,
|
|
717
|
+
'Value args for ValueListener',
|
|
718
|
+
`<VId = ${valueIdType}>`,
|
|
719
|
+
0,
|
|
720
|
+
);
|
|
721
|
+
const valueListenerType = addType(
|
|
722
|
+
VALUE + LISTENER,
|
|
723
|
+
`(...[${storeInstance}, valueId, newValue, oldValue, getValueChange]: ` +
|
|
724
|
+
valueListenerArgsArrayType +
|
|
725
|
+
')' +
|
|
726
|
+
RETURNS_VOID,
|
|
727
|
+
getListenerTypeDoc(11),
|
|
728
|
+
);
|
|
729
|
+
const invalidValueListenerType = addType(
|
|
730
|
+
INVALID + VALUE + LISTENER,
|
|
731
|
+
`(${storeParam}, valueId: Id, invalidValues: any[])` + RETURNS_VOID,
|
|
732
|
+
getListenerTypeDoc(12),
|
|
733
|
+
);
|
|
734
|
+
return [
|
|
735
|
+
valuesType,
|
|
736
|
+
valuesWhenSetType,
|
|
737
|
+
valueIdType,
|
|
738
|
+
valueType,
|
|
739
|
+
valueCallbackType,
|
|
740
|
+
valuesListenerType,
|
|
741
|
+
valueIdsListenerType,
|
|
742
|
+
valueListenerType,
|
|
743
|
+
invalidValueListenerType,
|
|
744
|
+
];
|
|
745
|
+
};
|
|
746
|
+
const getTransactionListenerType = (storeInstance, storeType) =>
|
|
747
|
+
addType(
|
|
748
|
+
TRANSACTION + LISTENER,
|
|
749
|
+
`(${storeInstance}: ${storeType}, cellsTouched: boolean, valuesTouched: boolean)` +
|
|
750
|
+
RETURNS_VOID,
|
|
751
|
+
A_FUNCTION_FOR + ' listening to the completion of a ' + TRANSACTION_,
|
|
752
|
+
);
|
|
753
|
+
return [getTablesTypes, getValuesTypes, getTransactionListenerType];
|
|
754
|
+
};
|
|
755
|
+
|
|
372
756
|
const storeMethod = (method, parameters = EMPTY_STRING, cast = EMPTY_STRING) =>
|
|
373
757
|
`store.${method}(${parameters})` + (cast ? ' as ' + cast : EMPTY_STRING);
|
|
374
758
|
const fluentStoreMethod = (method, parameters = EMPTY_STRING) =>
|
|
@@ -397,6 +781,8 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
397
781
|
valuesSchema,
|
|
398
782
|
addConstant,
|
|
399
783
|
);
|
|
784
|
+
const [getTablesTypes, getValuesTypes, getTransactionListenerType] =
|
|
785
|
+
getTypeFunctions(addType, mapTablesSchema, mapCellSchema, mapValuesSchema);
|
|
400
786
|
const methods = mapNew();
|
|
401
787
|
const getMethods = (location = 0) =>
|
|
402
788
|
mapMap(methods, ([parameters, returnType, body, doc, generic], name) => {
|
|
@@ -451,6 +837,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
451
837
|
params = EMPTY_STRING,
|
|
452
838
|
paramsInCall = EMPTY_STRING,
|
|
453
839
|
mutator = 1,
|
|
840
|
+
generic = EMPTY_STRING,
|
|
454
841
|
) =>
|
|
455
842
|
addMethod(
|
|
456
843
|
ADD + underlyingName + LISTENER,
|
|
@@ -466,6 +853,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
466
853
|
mutator ? 'mutator' : EMPTY_STRING,
|
|
467
854
|
),
|
|
468
855
|
doc,
|
|
856
|
+
generic,
|
|
469
857
|
);
|
|
470
858
|
const moduleDefinition = `./${camel(module)}.d`;
|
|
471
859
|
const storeType = camel(module, 1);
|
|
@@ -481,63 +869,77 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
481
869
|
`create${storeType} as create${storeType}Decl`,
|
|
482
870
|
);
|
|
483
871
|
if (!objIsEmpty(tablesSchema)) {
|
|
872
|
+
addImport(0, 'tinybase', 'CellChange');
|
|
873
|
+
addImport(null, 'tinybase', IDS);
|
|
874
|
+
const [
|
|
875
|
+
tablesType,
|
|
876
|
+
tablesWhenSetType,
|
|
877
|
+
tableIdType,
|
|
878
|
+
tableType,
|
|
879
|
+
tableWhenSetType,
|
|
880
|
+
rowType,
|
|
881
|
+
rowWhenSetType,
|
|
882
|
+
cellIdType,
|
|
883
|
+
_cellType,
|
|
884
|
+
cellCallbackType,
|
|
885
|
+
rowCallbackType,
|
|
886
|
+
tableCallbackType,
|
|
887
|
+
tablesListenerType,
|
|
888
|
+
tableIdsListenerType,
|
|
889
|
+
tableListenerType,
|
|
890
|
+
rowIdsListenerType,
|
|
891
|
+
sortedRowIdsListenerType,
|
|
892
|
+
rowListenerType,
|
|
893
|
+
cellIdsListenerType,
|
|
894
|
+
cellListenerType,
|
|
895
|
+
invalidCellListenerType,
|
|
896
|
+
] = getTablesTypes(storeInstance, storeType);
|
|
484
897
|
const tablesTypes = mapNew();
|
|
485
898
|
mapTablesSchema((tableId, tableName) => {
|
|
899
|
+
const tableIdGeneric = `<'${tableId}'>`;
|
|
486
900
|
const tableTypes = [
|
|
901
|
+
// Table
|
|
487
902
|
addType(
|
|
488
903
|
tableName + TABLE,
|
|
489
|
-
|
|
904
|
+
tableType + tableIdGeneric,
|
|
490
905
|
REPRESENTS + ` the '${tableId}' ` + TABLE,
|
|
491
906
|
),
|
|
907
|
+
// TableWhenSet
|
|
908
|
+
addType(
|
|
909
|
+
tableName + TABLE + WHEN_SET,
|
|
910
|
+
tableWhenSetType + tableIdGeneric,
|
|
911
|
+
REPRESENTS + ` the '${tableId}' ` + TABLE + WHEN_SETTING_IT,
|
|
912
|
+
),
|
|
913
|
+
// Row
|
|
492
914
|
addType(
|
|
493
915
|
tableName + ROW,
|
|
494
|
-
|
|
495
|
-
mapCellSchema(
|
|
496
|
-
tableId,
|
|
497
|
-
(cellId, type, defaultValue) =>
|
|
498
|
-
`'${cellId}'${
|
|
499
|
-
isUndefined(defaultValue) ? '?' : EMPTY_STRING
|
|
500
|
-
}: ${type};`,
|
|
501
|
-
),
|
|
502
|
-
' ',
|
|
503
|
-
)}}`,
|
|
916
|
+
rowType + tableIdGeneric,
|
|
504
917
|
getRowTypeDoc(tableId),
|
|
505
918
|
),
|
|
919
|
+
// RowWhenSet
|
|
506
920
|
addType(
|
|
507
|
-
tableName + ROW +
|
|
508
|
-
|
|
509
|
-
mapCellSchema(tableId, (cellId, type) => `'${cellId}'?: ${type};`),
|
|
510
|
-
' ',
|
|
511
|
-
)}}`,
|
|
921
|
+
tableName + ROW + WHEN_SET,
|
|
922
|
+
rowWhenSetType + tableIdGeneric,
|
|
512
923
|
getRowTypeDoc(tableId, 1),
|
|
513
924
|
),
|
|
925
|
+
// CellId
|
|
514
926
|
addType(
|
|
515
927
|
tableName + CELL + ID,
|
|
516
|
-
|
|
517
|
-
mapCellSchema(tableId, (cellId) => `'${cellId}'`),
|
|
518
|
-
' | ',
|
|
519
|
-
),
|
|
928
|
+
cellIdType + tableIdGeneric,
|
|
520
929
|
`A Cell Id for the '${tableId}' ` + TABLE,
|
|
521
930
|
),
|
|
931
|
+
// CellCallback
|
|
522
932
|
addType(
|
|
523
933
|
tableName + CELL + CALLBACK,
|
|
524
|
-
|
|
525
|
-
mapCellSchema(
|
|
526
|
-
tableId,
|
|
527
|
-
(cellId, type) => `[cellId: '${cellId}', cell: ${type}]`,
|
|
528
|
-
),
|
|
529
|
-
' | ',
|
|
530
|
-
)})` + RETURNS_VOID,
|
|
934
|
+
cellCallbackType + tableIdGeneric,
|
|
531
935
|
getCallbackDoc(
|
|
532
936
|
`a Cell Id and value from a Row in the '${tableId}' ` + TABLE,
|
|
533
937
|
),
|
|
534
938
|
),
|
|
939
|
+
// RowCallback
|
|
535
940
|
addType(
|
|
536
941
|
tableName + ROW + CALLBACK,
|
|
537
|
-
|
|
538
|
-
RETURNS_VOID +
|
|
539
|
-
')' +
|
|
540
|
-
RETURNS_VOID,
|
|
942
|
+
rowCallbackType + tableIdGeneric,
|
|
541
943
|
getCallbackDoc(
|
|
542
944
|
`a Row Id from the '${tableId}' Table, and a Cell iterator`,
|
|
543
945
|
),
|
|
@@ -546,129 +948,29 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
546
948
|
mapSet(tablesTypes, tableId, tableTypes);
|
|
547
949
|
addImport(1, moduleDefinition, ...tableTypes);
|
|
548
950
|
});
|
|
549
|
-
addImport(
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
'A ' + TABLE + ' Id in ' + THE_STORE,
|
|
567
|
-
);
|
|
568
|
-
const tableCallbackType = addType(
|
|
569
|
-
TABLE + CALLBACK,
|
|
570
|
-
`(...[tableId, rowCallback]: ${join(
|
|
571
|
-
mapTablesSchema(
|
|
572
|
-
(tableId) =>
|
|
573
|
-
`[tableId: '${tableId}', forEachRow: (rowCallback: ${
|
|
574
|
-
mapGet(tablesTypes, tableId)?.[5]
|
|
575
|
-
})${RETURNS_VOID}]`,
|
|
576
|
-
),
|
|
577
|
-
' | ',
|
|
578
|
-
)})` + RETURNS_VOID,
|
|
579
|
-
getCallbackDoc(A + TABLE + ' Id, and a Row iterator'),
|
|
580
|
-
);
|
|
581
|
-
const getCellChangeType = addType(
|
|
582
|
-
'GetCellChange',
|
|
583
|
-
`(...[tableId, rowId, cellId]: ${join(
|
|
584
|
-
mapTablesSchema(
|
|
585
|
-
(tableId) =>
|
|
586
|
-
`[tableId: '${tableId}', rowId: Id, cellId: ${
|
|
587
|
-
mapGet(tablesTypes, tableId)?.[3]
|
|
588
|
-
}]`,
|
|
589
|
-
),
|
|
590
|
-
' | ',
|
|
591
|
-
)}) => CellChange`,
|
|
592
|
-
A_FUNCTION_FOR +
|
|
593
|
-
` returning information about any Cell's changes during a ` +
|
|
594
|
-
TRANSACTION_,
|
|
595
|
-
);
|
|
596
|
-
const tablesListenerType = addType(
|
|
597
|
-
TABLES + LISTENER,
|
|
598
|
-
`(${storeInstance}: ${storeType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
599
|
-
RETURNS_VOID,
|
|
600
|
-
getListenerTypeDoc(1),
|
|
601
|
-
);
|
|
602
|
-
const tableIdsListenerType = addType(
|
|
603
|
-
TABLE_IDS + LISTENER,
|
|
604
|
-
`(${storeInstance}: ${storeType})` + RETURNS_VOID,
|
|
605
|
-
getListenerTypeDoc(2),
|
|
606
|
-
);
|
|
607
|
-
const tableListenerType = addType(
|
|
608
|
-
TABLE + LISTENER,
|
|
609
|
-
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
610
|
-
RETURNS_VOID,
|
|
611
|
-
getListenerTypeDoc(3),
|
|
612
|
-
);
|
|
613
|
-
const rowIdsListenerType = addType(
|
|
614
|
-
ROW_IDS + LISTENER,
|
|
615
|
-
`(${storeInstance}: ${storeType}, tableId: ${tableIdType})` +
|
|
616
|
-
RETURNS_VOID,
|
|
617
|
-
getListenerTypeDoc(4, 3),
|
|
618
|
-
);
|
|
619
|
-
const sortedRowIdsListenerType = addType(
|
|
620
|
-
SORTED_ROW_IDS + LISTENER,
|
|
621
|
-
'(' +
|
|
622
|
-
getParameterList(
|
|
623
|
-
storeInstance + ': ' + storeType,
|
|
624
|
-
'tableId: ' + tableIdType,
|
|
625
|
-
'cellId: Id' + OR_UNDEFINED,
|
|
626
|
-
'descending: boolean',
|
|
627
|
-
'offset: number',
|
|
628
|
-
'limit: number' + OR_UNDEFINED,
|
|
629
|
-
'sortedRowIds: Ids',
|
|
630
|
-
) +
|
|
631
|
-
')' +
|
|
632
|
-
RETURNS_VOID,
|
|
633
|
-
getListenerTypeDoc(13, 3),
|
|
634
|
-
);
|
|
635
|
-
const rowListenerType = addType(
|
|
636
|
-
ROW + LISTENER,
|
|
637
|
-
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, rowId: Id, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
638
|
-
RETURNS_VOID,
|
|
639
|
-
getListenerTypeDoc(5, 3),
|
|
640
|
-
);
|
|
641
|
-
const cellIdsListenerType = addType(
|
|
642
|
-
CELL_IDS + LISTENER,
|
|
643
|
-
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, rowId: Id)` +
|
|
644
|
-
RETURNS_VOID,
|
|
645
|
-
getListenerTypeDoc(6, 5),
|
|
646
|
-
);
|
|
647
|
-
const cellListenerType = addType(
|
|
648
|
-
CELL + LISTENER,
|
|
649
|
-
`(...[${storeInstance}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${join(
|
|
650
|
-
flat(
|
|
651
|
-
mapTablesSchema((tableId) =>
|
|
652
|
-
mapCellSchema(
|
|
653
|
-
tableId,
|
|
654
|
-
(cellId, type) =>
|
|
655
|
-
`[${storeInstance}: ${storeType}, tableId: '${tableId}', rowId: Id, cellId: '${cellId}', newCell: ${type}${OR_UNDEFINED}, oldCell: ${type}${OR_UNDEFINED}, getCellChange: ${getCellChangeType} | undefined]`,
|
|
656
|
-
),
|
|
657
|
-
),
|
|
658
|
-
),
|
|
659
|
-
' | ',
|
|
660
|
-
)})` + RETURNS_VOID,
|
|
661
|
-
getListenerTypeDoc(7, 5),
|
|
662
|
-
);
|
|
663
|
-
const invalidCellListenerType = addType(
|
|
664
|
-
INVALID + CELL + LISTENER,
|
|
665
|
-
`(${storeInstance}: ${storeType}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])` +
|
|
666
|
-
RETURNS_VOID,
|
|
667
|
-
getListenerTypeDoc(8),
|
|
951
|
+
addImport(
|
|
952
|
+
1,
|
|
953
|
+
moduleDefinition,
|
|
954
|
+
tablesType,
|
|
955
|
+
tablesWhenSetType,
|
|
956
|
+
tableIdType,
|
|
957
|
+
cellIdType,
|
|
958
|
+
tableCallbackType,
|
|
959
|
+
tablesListenerType,
|
|
960
|
+
tableIdsListenerType,
|
|
961
|
+
tableListenerType,
|
|
962
|
+
rowIdsListenerType,
|
|
963
|
+
sortedRowIdsListenerType,
|
|
964
|
+
rowListenerType,
|
|
965
|
+
cellIdsListenerType,
|
|
966
|
+
cellListenerType,
|
|
967
|
+
invalidCellListenerType,
|
|
668
968
|
);
|
|
669
969
|
sharedTableTypes = [
|
|
670
970
|
tablesType,
|
|
971
|
+
tablesWhenSetType,
|
|
671
972
|
tableIdType,
|
|
973
|
+
cellIdType,
|
|
672
974
|
tablesListenerType,
|
|
673
975
|
tableIdsListenerType,
|
|
674
976
|
tableListenerType,
|
|
@@ -683,7 +985,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
683
985
|
[
|
|
684
986
|
[tablesType],
|
|
685
987
|
[BOOLEAN],
|
|
686
|
-
[storeType, 'tables: ' +
|
|
988
|
+
[storeType, 'tables: ' + tablesWhenSetType, 'tables'],
|
|
687
989
|
[storeType],
|
|
688
990
|
],
|
|
689
991
|
([returnType, params, paramsInCall], verb) =>
|
|
@@ -715,18 +1017,19 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
715
1017
|
);
|
|
716
1018
|
mapTablesSchema((tableId, tableName, TABLE_ID) => {
|
|
717
1019
|
const [
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
1020
|
+
tableType2,
|
|
1021
|
+
tableWhenSetType2,
|
|
1022
|
+
rowType2,
|
|
1023
|
+
rowWhenSetType2,
|
|
1024
|
+
cellIdType2,
|
|
1025
|
+
cellCallbackType2,
|
|
1026
|
+
rowCallbackType2,
|
|
724
1027
|
] = mapGet(tablesTypes, tableId);
|
|
725
1028
|
arrayForEach(
|
|
726
1029
|
[
|
|
727
|
-
[
|
|
1030
|
+
[tableType2],
|
|
728
1031
|
[BOOLEAN],
|
|
729
|
-
[storeType, 'table: ' +
|
|
1032
|
+
[storeType, 'table: ' + tableWhenSetType2, ', table'],
|
|
730
1033
|
[storeType],
|
|
731
1034
|
],
|
|
732
1035
|
([returnType, params, paramsInCall = EMPTY_STRING], verb) =>
|
|
@@ -755,9 +1058,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
755
1058
|
SORTED_ROW_IDS,
|
|
756
1059
|
IDS,
|
|
757
1060
|
getIdsDoc(ROW, getTableDoc(tableId), 1),
|
|
758
|
-
'cellId?: ' +
|
|
759
|
-
cellIdType +
|
|
760
|
-
', descending?: boolean, offset?: number, limit?: number',
|
|
1061
|
+
'cellId?: ' + cellIdType2 + SORTED_ARGS,
|
|
761
1062
|
TABLE_ID + ', cellId, descending, offset, limit',
|
|
762
1063
|
);
|
|
763
1064
|
addProxyMethod(
|
|
@@ -766,16 +1067,16 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
766
1067
|
ROW,
|
|
767
1068
|
VOID,
|
|
768
1069
|
getForEachDoc(ROW, getTableDoc(tableId)),
|
|
769
|
-
'rowCallback: ' +
|
|
1070
|
+
'rowCallback: ' + rowCallbackType2,
|
|
770
1071
|
TABLE_ID + ', rowCallback as any',
|
|
771
1072
|
);
|
|
772
1073
|
arrayForEach(
|
|
773
1074
|
[
|
|
774
|
-
[
|
|
1075
|
+
[rowType2],
|
|
775
1076
|
[BOOLEAN],
|
|
776
|
-
[storeType, ', row: ' +
|
|
1077
|
+
[storeType, ', row: ' + rowWhenSetType2, ', row'],
|
|
777
1078
|
[storeType],
|
|
778
|
-
[storeType, ', partialRow: ' +
|
|
1079
|
+
[storeType, ', partialRow: ' + rowWhenSetType2, ', partialRow'],
|
|
779
1080
|
],
|
|
780
1081
|
(
|
|
781
1082
|
[returnType, params = EMPTY_STRING, paramsInCall = EMPTY_STRING],
|
|
@@ -787,7 +1088,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
787
1088
|
ROW,
|
|
788
1089
|
returnType,
|
|
789
1090
|
getRowContentDoc(tableId, verb),
|
|
790
|
-
|
|
1091
|
+
ROW_ID_PARAM + params,
|
|
791
1092
|
TABLE_ID + ', rowId' + paramsInCall,
|
|
792
1093
|
),
|
|
793
1094
|
);
|
|
@@ -796,17 +1097,17 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
796
1097
|
tableName,
|
|
797
1098
|
ROW,
|
|
798
1099
|
ID + OR_UNDEFINED,
|
|
799
|
-
'
|
|
800
|
-
'row: ' +
|
|
1100
|
+
'Add a new Row to ' + getTableDoc(tableId),
|
|
1101
|
+
'row: ' + rowWhenSetType2,
|
|
801
1102
|
TABLE_ID + ', row',
|
|
802
1103
|
);
|
|
803
1104
|
addProxyMethod(
|
|
804
1105
|
0,
|
|
805
1106
|
tableName,
|
|
806
1107
|
CELL_IDS,
|
|
807
|
-
|
|
1108
|
+
cellIdType2 + SQUARE_BRACKETS,
|
|
808
1109
|
getIdsDoc(CELL, getRowDoc(tableId)),
|
|
809
|
-
|
|
1110
|
+
ROW_ID_PARAM,
|
|
810
1111
|
TABLE_ID + ', rowId',
|
|
811
1112
|
);
|
|
812
1113
|
addProxyMethod(
|
|
@@ -815,7 +1116,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
815
1116
|
CELL,
|
|
816
1117
|
VOID,
|
|
817
1118
|
getForEachDoc(CELL, getRowDoc(tableId)),
|
|
818
|
-
'
|
|
1119
|
+
ROW_ID_PARAM + ', cellCallback: ' + cellCallbackType2,
|
|
819
1120
|
TABLE_ID + ', rowId, cellCallback as any',
|
|
820
1121
|
);
|
|
821
1122
|
mapCellSchema(
|
|
@@ -842,7 +1143,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
842
1143
|
CELL,
|
|
843
1144
|
returnType,
|
|
844
1145
|
getCellContentDoc(tableId, cellId, verb),
|
|
845
|
-
|
|
1146
|
+
ROW_ID_PARAM + params,
|
|
846
1147
|
TABLE_ID + ', rowId, ' + CELL_ID + paramsInCall,
|
|
847
1148
|
),
|
|
848
1149
|
);
|
|
@@ -890,13 +1191,15 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
890
1191
|
sortedRowIdsListenerType,
|
|
891
1192
|
getListenerDoc(13, 3, 1),
|
|
892
1193
|
getParameterList(
|
|
893
|
-
'tableId: '
|
|
894
|
-
|
|
1194
|
+
'tableId: TId',
|
|
1195
|
+
`cellId: ${cellIdType}<TId>` + OR_UNDEFINED,
|
|
895
1196
|
'descending: boolean',
|
|
896
1197
|
'offset: number',
|
|
897
1198
|
'limit: number' + OR_UNDEFINED,
|
|
898
1199
|
),
|
|
899
1200
|
getParameterList('tableId', 'cellId', 'descending', 'offset', 'limit'),
|
|
1201
|
+
1,
|
|
1202
|
+
'<TId extends TableId>',
|
|
900
1203
|
);
|
|
901
1204
|
addProxyListener(
|
|
902
1205
|
ROW,
|
|
@@ -918,7 +1221,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
918
1221
|
getListenerDoc(7, 5),
|
|
919
1222
|
`tableId: ${tableIdType} | null, rowId: IdOrNull, cellId: ${join(
|
|
920
1223
|
mapTablesSchema(
|
|
921
|
-
(tableId) => mapGet(tablesTypes, tableId)?.[
|
|
1224
|
+
(tableId) => mapGet(tablesTypes, tableId)?.[4] ?? EMPTY_STRING,
|
|
922
1225
|
),
|
|
923
1226
|
' | ',
|
|
924
1227
|
)} | null`,
|
|
@@ -931,27 +1234,10 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
931
1234
|
`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull`,
|
|
932
1235
|
'tableId, rowId, cellId',
|
|
933
1236
|
);
|
|
934
|
-
addImport(
|
|
935
|
-
1,
|
|
936
|
-
moduleDefinition,
|
|
937
|
-
tablesType,
|
|
938
|
-
tableIdType,
|
|
939
|
-
tableCallbackType,
|
|
940
|
-
tablesListenerType,
|
|
941
|
-
tableIdsListenerType,
|
|
942
|
-
tableListenerType,
|
|
943
|
-
rowIdsListenerType,
|
|
944
|
-
sortedRowIdsListenerType,
|
|
945
|
-
rowListenerType,
|
|
946
|
-
cellIdsListenerType,
|
|
947
|
-
cellListenerType,
|
|
948
|
-
invalidCellListenerType,
|
|
949
|
-
...collValues(mapCellOrValueTypes),
|
|
950
|
-
);
|
|
951
|
-
addImport(0, 'tinybase', 'CellChange');
|
|
1237
|
+
addImport(1, moduleDefinition, ...collValues(mapCellOrValueTypes));
|
|
952
1238
|
arrayPush(
|
|
953
1239
|
createSteps,
|
|
954
|
-
'.
|
|
1240
|
+
'.set' + TABLES + SCHEMA + '({',
|
|
955
1241
|
flat(
|
|
956
1242
|
mapTablesSchema((tableId, _, TABLE_ID) => [
|
|
957
1243
|
`[${TABLE_ID}]: {`,
|
|
@@ -977,83 +1263,28 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
977
1263
|
);
|
|
978
1264
|
}
|
|
979
1265
|
if (!objIsEmpty(valuesSchema)) {
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
'}',
|
|
1003
|
-
getTheContentOfTheStoreDoc(2, 5, 1),
|
|
1004
|
-
);
|
|
1005
|
-
const valueIdType = addType(
|
|
1006
|
-
VALUE + ID,
|
|
1007
|
-
join(
|
|
1008
|
-
mapValuesSchema((valueId) => `'${valueId}'`),
|
|
1009
|
-
' | ',
|
|
1010
|
-
),
|
|
1011
|
-
'A Value Id in ' + THE_STORE,
|
|
1012
|
-
);
|
|
1013
|
-
const valueCallbackType = addType(
|
|
1014
|
-
VALUE + CALLBACK,
|
|
1015
|
-
`(...[valueId, rowCallback]: ${join(
|
|
1016
|
-
mapValuesSchema(
|
|
1017
|
-
(valueId, type) => `[valueId: '${valueId}', value: ${type}]`,
|
|
1018
|
-
),
|
|
1019
|
-
' | ',
|
|
1020
|
-
)})` + RETURNS_VOID,
|
|
1021
|
-
getCallbackDoc('a Value Id, and value'),
|
|
1022
|
-
);
|
|
1023
|
-
const getValueChangeType = addType(
|
|
1024
|
-
'GetValueChange',
|
|
1025
|
-
`(valueId: ${valueIdType}) => ValueChange`,
|
|
1026
|
-
A_FUNCTION_FOR +
|
|
1027
|
-
` returning information about any Value's changes during a ` +
|
|
1028
|
-
TRANSACTION_,
|
|
1029
|
-
);
|
|
1030
|
-
const valuesListenerType = addType(
|
|
1031
|
-
VALUES + LISTENER,
|
|
1032
|
-
`(${storeInstance}: ${storeType}, getValueChange: ${getValueChangeType}${OR_UNDEFINED})` +
|
|
1033
|
-
RETURNS_VOID,
|
|
1034
|
-
getListenerTypeDoc(9),
|
|
1035
|
-
);
|
|
1036
|
-
const valueIdsListenerType = addType(
|
|
1037
|
-
VALUE_IDS + LISTENER,
|
|
1038
|
-
`(${storeInstance}: ${storeType})` + RETURNS_VOID,
|
|
1039
|
-
getListenerTypeDoc(10),
|
|
1040
|
-
);
|
|
1041
|
-
const valueListenerType = addType(
|
|
1042
|
-
VALUE + LISTENER,
|
|
1043
|
-
`(...[${storeInstance}, valueId, newValue, oldValue, getValueChange]: ${join(
|
|
1044
|
-
mapValuesSchema(
|
|
1045
|
-
(valueId, type) =>
|
|
1046
|
-
`[${storeInstance}: ${storeType}, valueId: '${valueId}', newValue: ${type}${OR_UNDEFINED}, oldValue: ${type}${OR_UNDEFINED}, getValueChange: ${getValueChangeType} | undefined]`,
|
|
1047
|
-
),
|
|
1048
|
-
' | ',
|
|
1049
|
-
)})` + RETURNS_VOID,
|
|
1050
|
-
getListenerTypeDoc(11),
|
|
1051
|
-
);
|
|
1052
|
-
const invalidValueListenerType = addType(
|
|
1053
|
-
INVALID + VALUE + LISTENER,
|
|
1054
|
-
`(${storeInstance}: ${storeType}, valueId: Id, invalidValues: any[])` +
|
|
1055
|
-
RETURNS_VOID,
|
|
1056
|
-
getListenerTypeDoc(12),
|
|
1266
|
+
const [
|
|
1267
|
+
valuesType,
|
|
1268
|
+
valuesWhenSetType,
|
|
1269
|
+
valueIdType,
|
|
1270
|
+
_valueType,
|
|
1271
|
+
valueCallbackType,
|
|
1272
|
+
valuesListenerType,
|
|
1273
|
+
valueIdsListenerType,
|
|
1274
|
+
valueListenerType,
|
|
1275
|
+
invalidValueListenerType,
|
|
1276
|
+
] = getValuesTypes(storeInstance, storeType);
|
|
1277
|
+
addImport(
|
|
1278
|
+
1,
|
|
1279
|
+
moduleDefinition,
|
|
1280
|
+
valuesType,
|
|
1281
|
+
valuesWhenSetType,
|
|
1282
|
+
valueIdType,
|
|
1283
|
+
valueCallbackType,
|
|
1284
|
+
valuesListenerType,
|
|
1285
|
+
valueIdsListenerType,
|
|
1286
|
+
valueListenerType,
|
|
1287
|
+
invalidValueListenerType,
|
|
1057
1288
|
);
|
|
1058
1289
|
sharedValueTypes = [
|
|
1059
1290
|
valuesType,
|
|
@@ -1156,24 +1387,12 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1156
1387
|
`valueId: IdOrNull`,
|
|
1157
1388
|
'valueId',
|
|
1158
1389
|
);
|
|
1159
|
-
addImport(
|
|
1160
|
-
1,
|
|
1161
|
-
moduleDefinition,
|
|
1162
|
-
valuesType,
|
|
1163
|
-
valuesWhenSetType,
|
|
1164
|
-
valueIdType,
|
|
1165
|
-
valueCallbackType,
|
|
1166
|
-
valuesListenerType,
|
|
1167
|
-
valueIdsListenerType,
|
|
1168
|
-
valueListenerType,
|
|
1169
|
-
invalidValueListenerType,
|
|
1170
|
-
...collValues(mapCellOrValueTypes),
|
|
1171
|
-
);
|
|
1390
|
+
addImport(1, moduleDefinition, ...collValues(mapCellOrValueTypes));
|
|
1172
1391
|
addImport(0, 'tinybase', 'ValueChange');
|
|
1173
1392
|
arrayPush(
|
|
1174
1393
|
createSteps,
|
|
1175
|
-
'.
|
|
1176
|
-
mapValuesSchema((
|
|
1394
|
+
'.set' + VALUES + SCHEMA + '({',
|
|
1395
|
+
mapValuesSchema((_, type, defaultValue, VALUE_ID) => [
|
|
1177
1396
|
`[${VALUE_ID}]: {[${addConstant(
|
|
1178
1397
|
snake(TYPE),
|
|
1179
1398
|
`'${TYPE}'`,
|
|
@@ -1197,12 +1416,6 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1197
1416
|
),
|
|
1198
1417
|
);
|
|
1199
1418
|
addImport(null, 'tinybase', 'DoRollback', ID, 'IdOrNull', JSON$1, 'Store');
|
|
1200
|
-
const transactionListenerType = addType(
|
|
1201
|
-
TRANSACTION + LISTENER,
|
|
1202
|
-
`(${storeInstance}: ${storeType}, cellsTouched: boolean, valuesTouched: boolean)` +
|
|
1203
|
-
RETURNS_VOID,
|
|
1204
|
-
A_FUNCTION_FOR + ' listening to the completion of a ' + TRANSACTION_,
|
|
1205
|
-
);
|
|
1206
1419
|
addProxyMethod(
|
|
1207
1420
|
0,
|
|
1208
1421
|
EMPTY_STRING,
|
|
@@ -1216,16 +1429,16 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1216
1429
|
JSON$1,
|
|
1217
1430
|
storeType,
|
|
1218
1431
|
getTheContentOfTheStoreDoc(0, 7),
|
|
1219
|
-
'
|
|
1220
|
-
'
|
|
1432
|
+
'tablesAndValuesJson: ' + JSON$1,
|
|
1433
|
+
'tablesAndValuesJson',
|
|
1221
1434
|
);
|
|
1222
1435
|
addProxyMethod(
|
|
1223
1436
|
7,
|
|
1224
1437
|
EMPTY_STRING,
|
|
1225
1438
|
TRANSACTION_,
|
|
1226
1439
|
'Return',
|
|
1227
|
-
|
|
1228
|
-
|
|
1440
|
+
TRANSACTION_DOC,
|
|
1441
|
+
DO_ACTIONS_AND_ROLLBACK_PARAMS,
|
|
1229
1442
|
'actions, doRollback',
|
|
1230
1443
|
'<Return>',
|
|
1231
1444
|
);
|
|
@@ -1234,17 +1447,21 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1234
1447
|
EMPTY_STRING,
|
|
1235
1448
|
'start' + TRANSACTION,
|
|
1236
1449
|
storeType,
|
|
1237
|
-
|
|
1450
|
+
START_TRANSACTION_DOC,
|
|
1238
1451
|
);
|
|
1239
1452
|
addProxyMethod(
|
|
1240
1453
|
7,
|
|
1241
1454
|
EMPTY_STRING,
|
|
1242
1455
|
'finish' + TRANSACTION,
|
|
1243
1456
|
storeType,
|
|
1244
|
-
|
|
1245
|
-
|
|
1457
|
+
FINISH_TRANSACTION_DOC,
|
|
1458
|
+
DO_ROLLBACK_PARAM,
|
|
1246
1459
|
'doRollback',
|
|
1247
1460
|
);
|
|
1461
|
+
const transactionListenerType = getTransactionListenerType(
|
|
1462
|
+
storeInstance,
|
|
1463
|
+
storeType,
|
|
1464
|
+
);
|
|
1248
1465
|
addProxyListener(
|
|
1249
1466
|
'WillFinish' + TRANSACTION,
|
|
1250
1467
|
transactionListenerType,
|
|
@@ -1266,9 +1483,9 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1266
1483
|
EMPTY_STRING,
|
|
1267
1484
|
'call' + LISTENER,
|
|
1268
1485
|
storeType,
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1486
|
+
'Manually provoke a listener to be called',
|
|
1487
|
+
'listenerId: Id',
|
|
1488
|
+
'listenerId',
|
|
1272
1489
|
);
|
|
1273
1490
|
addProxyMethod(
|
|
1274
1491
|
3,
|
|
@@ -1337,13 +1554,6 @@ const DEPS = 'Deps';
|
|
|
1337
1554
|
const getGet = (noun) => GET + noun;
|
|
1338
1555
|
const getGetAndGetDeps = (noun) =>
|
|
1339
1556
|
getParameterList(getGet(noun), getGet(noun) + DEPS);
|
|
1340
|
-
const getPropsTypeList = (...props) =>
|
|
1341
|
-
'{' +
|
|
1342
|
-
join(
|
|
1343
|
-
arrayMap(props, (prop) => 'readonly ' + prop),
|
|
1344
|
-
'; ',
|
|
1345
|
-
) +
|
|
1346
|
-
'}';
|
|
1347
1557
|
const DEBUG_IDS_PROP_TYPE = 'debugIds?: boolean';
|
|
1348
1558
|
const DEBUG_IDS_PROP = 'debugIds={debugIds}';
|
|
1349
1559
|
const DEPS_SUFFIX = DEPS + '?: React.DependencyList';
|
|
@@ -1509,7 +1719,7 @@ const getStoreUiReactApi = (
|
|
|
1509
1719
|
);
|
|
1510
1720
|
const providerPropsType = addType(
|
|
1511
1721
|
PROVIDER + PROPS,
|
|
1512
|
-
|
|
1722
|
+
getPropTypeList(
|
|
1513
1723
|
storeInstance + OPTIONAL_COLON + storeType,
|
|
1514
1724
|
storeInstance + `ById?: {[${storeInstance}Id: Id]: ${storeType}}`,
|
|
1515
1725
|
),
|
|
@@ -1580,7 +1790,9 @@ const getStoreUiReactApi = (
|
|
|
1580
1790
|
if (!objIsEmpty(tablesSchema)) {
|
|
1581
1791
|
const [
|
|
1582
1792
|
tablesType,
|
|
1793
|
+
tablesWhenSetType,
|
|
1583
1794
|
tableIdType,
|
|
1795
|
+
cellIdType,
|
|
1584
1796
|
tablesListenerType,
|
|
1585
1797
|
tableIdsListenerType,
|
|
1586
1798
|
tableListenerType,
|
|
@@ -1595,6 +1807,7 @@ const getStoreUiReactApi = (
|
|
|
1595
1807
|
null,
|
|
1596
1808
|
moduleDefinition,
|
|
1597
1809
|
tablesType,
|
|
1810
|
+
tablesWhenSetType,
|
|
1598
1811
|
tableIdType,
|
|
1599
1812
|
tablesListenerType,
|
|
1600
1813
|
tableIdsListenerType,
|
|
@@ -1605,6 +1818,7 @@ const getStoreUiReactApi = (
|
|
|
1605
1818
|
cellIdsListenerType,
|
|
1606
1819
|
cellListenerType,
|
|
1607
1820
|
);
|
|
1821
|
+
addImport(0, moduleDefinition, cellIdType);
|
|
1608
1822
|
addImport(1, moduleDefinition, storeType);
|
|
1609
1823
|
addImport(null, 'tinybase', IDS, 'IdOrNull');
|
|
1610
1824
|
const tableView = addInternalFunction(
|
|
@@ -1678,14 +1892,14 @@ const getStoreUiReactApi = (
|
|
|
1678
1892
|
PARAMETERIZED_CALLBACK,
|
|
1679
1893
|
getTheContentOfTheStoreDoc(1, 9) + BASED_ON_A_PARAMETER,
|
|
1680
1894
|
getParameterList(
|
|
1681
|
-
getGet(TABLES) + GETTER_ARGS +
|
|
1895
|
+
getGet(TABLES) + GETTER_ARGS + tablesWhenSetType,
|
|
1682
1896
|
getGet(TABLES) + DEPS_SUFFIX,
|
|
1683
1897
|
),
|
|
1684
1898
|
getGetAndGetDeps(TABLES),
|
|
1685
1899
|
GENERIC_PARAMETER,
|
|
1686
1900
|
getParameterList(
|
|
1687
1901
|
THEN_PREFIX,
|
|
1688
|
-
`tables: ${
|
|
1902
|
+
`tables: ${tablesWhenSetType})` + RETURNS_VOID,
|
|
1689
1903
|
THEN_DEPS,
|
|
1690
1904
|
),
|
|
1691
1905
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
@@ -1701,35 +1915,86 @@ const getStoreUiReactApi = (
|
|
|
1701
1915
|
THEN_AND_THEN_DEPS,
|
|
1702
1916
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1703
1917
|
);
|
|
1918
|
+
const cellPropsType = addType(
|
|
1919
|
+
CELL + PROPS,
|
|
1920
|
+
getPropTypeList(
|
|
1921
|
+
'tableId?: TId',
|
|
1922
|
+
'rowId: Id',
|
|
1923
|
+
'cellId?: CId',
|
|
1924
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1925
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1926
|
+
),
|
|
1927
|
+
getPropsDoc(A + CELL),
|
|
1928
|
+
`<TId extends ${tableIdType}, CId extends ${cellIdType}<TId>>`,
|
|
1929
|
+
);
|
|
1930
|
+
const rowPropsType = addType(
|
|
1931
|
+
ROW + PROPS,
|
|
1932
|
+
getPropTypeList(
|
|
1933
|
+
`tableId?: TId`,
|
|
1934
|
+
'rowId: Id',
|
|
1935
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1936
|
+
'cellComponents?: {readonly [CId in ' +
|
|
1937
|
+
cellIdType +
|
|
1938
|
+
`<TId>]?: ComponentType<${cellPropsType}<TId, CId>>;}`,
|
|
1939
|
+
`getCellComponentProps?: (cellId: ${cellIdType}<TId>) => ExtraProps`,
|
|
1940
|
+
SEPARATOR_PROP_TYPE,
|
|
1941
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1942
|
+
),
|
|
1943
|
+
getPropsDoc(A + ROW),
|
|
1944
|
+
`<TId extends ${tableIdType}>`,
|
|
1945
|
+
);
|
|
1946
|
+
const tablePropsType = addType(
|
|
1947
|
+
TABLE + PROPS,
|
|
1948
|
+
getPropTypeList(
|
|
1949
|
+
`tableId?: TId`,
|
|
1950
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1951
|
+
`rowComponent?: ComponentType<${rowPropsType}<TId>>`,
|
|
1952
|
+
`getRowComponentProps?: (rowId: Id) => ExtraProps`,
|
|
1953
|
+
SEPARATOR_PROP_TYPE,
|
|
1954
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1955
|
+
),
|
|
1956
|
+
getPropsDoc(A + TABLE),
|
|
1957
|
+
`<TId extends ${tableIdType}>`,
|
|
1958
|
+
);
|
|
1959
|
+
const sortedTablePropsType = addType(
|
|
1960
|
+
'Sorted' + TABLE + PROPS,
|
|
1961
|
+
getPropTypeList(
|
|
1962
|
+
`tableId?: TId`,
|
|
1963
|
+
'cellId?: ' + cellIdType + '<TId>',
|
|
1964
|
+
'descending?: boolean',
|
|
1965
|
+
'offset?: number',
|
|
1966
|
+
'limit?: number',
|
|
1967
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1968
|
+
`rowComponent?: ComponentType<${rowPropsType}<TId>>`,
|
|
1969
|
+
`getRowComponentProps?: (rowId: Id) => ExtraProps`,
|
|
1970
|
+
SEPARATOR_PROP_TYPE,
|
|
1971
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1972
|
+
),
|
|
1973
|
+
getPropsDoc(A + 'sorted ' + TABLE),
|
|
1974
|
+
`<TId extends ${tableIdType}>`,
|
|
1975
|
+
);
|
|
1704
1976
|
const tablesPropsType = addType(
|
|
1705
1977
|
TABLES + PROPS,
|
|
1706
|
-
|
|
1978
|
+
getPropTypeList(
|
|
1707
1979
|
storeInstance + OPTIONAL_COLON + storeType,
|
|
1708
|
-
'tableComponents?: {' +
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
(tableId, tableName) =>
|
|
1712
|
-
`'${tableId}'?: ComponentType<${tableName}TableProps>`,
|
|
1713
|
-
),
|
|
1714
|
-
', ',
|
|
1715
|
-
) +
|
|
1716
|
-
'}',
|
|
1980
|
+
'tableComponents?: {readonly [TId in ' +
|
|
1981
|
+
tableIdType +
|
|
1982
|
+
`]?: ComponentType<${tablePropsType}<TId>>;}`,
|
|
1717
1983
|
`getTableComponentProps?: (tableId: ${tableIdType}) => ExtraProps`,
|
|
1718
1984
|
SEPARATOR_PROP_TYPE,
|
|
1719
1985
|
DEBUG_IDS_PROP_TYPE,
|
|
1720
1986
|
),
|
|
1721
1987
|
getPropsDoc(getTheContentOfDoc(1, 1)),
|
|
1722
1988
|
);
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1989
|
+
addImport(
|
|
1990
|
+
1,
|
|
1991
|
+
uiReactModuleDefinition,
|
|
1992
|
+
tablesPropsType,
|
|
1993
|
+
tablePropsType,
|
|
1994
|
+
sortedTablePropsType,
|
|
1995
|
+
rowPropsType,
|
|
1996
|
+
cellPropsType,
|
|
1731
1997
|
);
|
|
1732
|
-
addImport(1, uiReactModuleDefinition, tablesPropsType, cellPropsType);
|
|
1733
1998
|
addComponent(
|
|
1734
1999
|
TABLES + VIEW,
|
|
1735
2000
|
'{' +
|
|
@@ -1740,11 +2005,12 @@ const getStoreUiReactApi = (
|
|
|
1740
2005
|
tablesPropsType,
|
|
1741
2006
|
[
|
|
1742
2007
|
wrap + `(${useTableIds}(${storeInstance}).map((tableId) => {`,
|
|
1743
|
-
'const Table = tableComponents?.[tableId] ?? ' +
|
|
2008
|
+
'const Table = (tableComponents?.[tableId] ?? ' +
|
|
1744
2009
|
getDefaultTableComponent +
|
|
1745
|
-
|
|
2010
|
+
`(tableId)) as React.ComponentType<TableProps<typeof tableId>>;`,
|
|
1746
2011
|
'return <Table',
|
|
1747
2012
|
`{...${getProps}(getTableComponentProps, tableId)}`,
|
|
2013
|
+
'tableId={tableId}',
|
|
1748
2014
|
'key={tableId}',
|
|
1749
2015
|
storeProp,
|
|
1750
2016
|
DEBUG_IDS_PROP,
|
|
@@ -1754,25 +2020,21 @@ const getStoreUiReactApi = (
|
|
|
1754
2020
|
getTheContentOfTheStoreDoc(1, 13) + AND_REGISTERS,
|
|
1755
2021
|
);
|
|
1756
2022
|
mapTablesSchema((tableId, tableName, TABLE_ID) => {
|
|
1757
|
-
const [
|
|
1758
|
-
tablesTypes,
|
|
1759
|
-
tableId,
|
|
1760
|
-
);
|
|
1761
|
-
addImport(
|
|
1762
|
-
0,
|
|
1763
|
-
moduleDefinition,
|
|
2023
|
+
const [
|
|
1764
2024
|
tableType,
|
|
2025
|
+
tableWhenSetType,
|
|
1765
2026
|
rowType,
|
|
1766
2027
|
rowWhenSetType,
|
|
1767
|
-
|
|
1768
|
-
);
|
|
2028
|
+
cellIdType2,
|
|
2029
|
+
] = mapGet(tablesTypes, tableId);
|
|
1769
2030
|
addImport(
|
|
1770
|
-
|
|
2031
|
+
null,
|
|
1771
2032
|
moduleDefinition,
|
|
1772
2033
|
tableType,
|
|
2034
|
+
tableWhenSetType,
|
|
1773
2035
|
rowType,
|
|
1774
2036
|
rowWhenSetType,
|
|
1775
|
-
|
|
2037
|
+
cellIdType2,
|
|
1776
2038
|
);
|
|
1777
2039
|
addProxyHook(
|
|
1778
2040
|
tableName + TABLE,
|
|
@@ -1796,7 +2058,7 @@ const getStoreUiReactApi = (
|
|
|
1796
2058
|
IDS,
|
|
1797
2059
|
getIdsDoc(ROW, getTableDoc(tableId), 1) + AND_REGISTERS,
|
|
1798
2060
|
'cellId?: ' +
|
|
1799
|
-
|
|
2061
|
+
cellIdType2 +
|
|
1800
2062
|
', descending?: boolean, offset?: number, limit?: number',
|
|
1801
2063
|
TABLE_ID + ', cellId, descending, offset, limit',
|
|
1802
2064
|
);
|
|
@@ -1811,7 +2073,7 @@ const getStoreUiReactApi = (
|
|
|
1811
2073
|
const useCellIds = addProxyHook(
|
|
1812
2074
|
tableName + CELL_IDS,
|
|
1813
2075
|
CELL_IDS,
|
|
1814
|
-
|
|
2076
|
+
cellIdType2 + SQUARE_BRACKETS,
|
|
1815
2077
|
getIdsDoc(CELL, getRowDoc(tableId)) + AND_REGISTERS,
|
|
1816
2078
|
TYPED_ROW_ID,
|
|
1817
2079
|
getParameterList(TABLE_ID, ROW_ID),
|
|
@@ -1822,14 +2084,14 @@ const getStoreUiReactApi = (
|
|
|
1822
2084
|
PARAMETERIZED_CALLBACK,
|
|
1823
2085
|
getTableContentDoc(tableId, 9) + BASED_ON_A_PARAMETER,
|
|
1824
2086
|
getParameterList(
|
|
1825
|
-
getGet(TABLE) + GETTER_ARGS +
|
|
2087
|
+
getGet(TABLE) + GETTER_ARGS + tableWhenSetType,
|
|
1826
2088
|
getGet(TABLE) + DEPS_SUFFIX,
|
|
1827
2089
|
),
|
|
1828
2090
|
getParameterList(TABLE_ID, getGetAndGetDeps(TABLE)),
|
|
1829
2091
|
GENERIC_PARAMETER,
|
|
1830
2092
|
getParameterList(
|
|
1831
2093
|
THEN_PREFIX,
|
|
1832
|
-
`table: ${
|
|
2094
|
+
`table: ${tableWhenSetType})` + RETURNS_VOID,
|
|
1833
2095
|
THEN_DEPS,
|
|
1834
2096
|
),
|
|
1835
2097
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
@@ -1904,68 +2166,15 @@ const getStoreUiReactApi = (
|
|
|
1904
2166
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1905
2167
|
);
|
|
1906
2168
|
addProxyHook(
|
|
1907
|
-
DEL + tableName + ROW + CALLBACK,
|
|
1908
|
-
DEL + ROW + CALLBACK,
|
|
1909
|
-
CALLBACK,
|
|
1910
|
-
getRowContentDoc(tableId, 12),
|
|
1911
|
-
TYPED_ROW_ID,
|
|
1912
|
-
getParameterList(TABLE_ID, ROW_ID),
|
|
1913
|
-
EMPTY_STRING,
|
|
1914
|
-
THEN_AND_THEN_DEPS,
|
|
1915
|
-
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1916
|
-
);
|
|
1917
|
-
const rowPropsType = addType(
|
|
1918
|
-
tableName + 'RowProps',
|
|
1919
|
-
getPropsTypeList(
|
|
1920
|
-
'rowId: Id',
|
|
1921
|
-
storeInstance + OPTIONAL_COLON + storeType,
|
|
1922
|
-
'cellComponents?: {' +
|
|
1923
|
-
join(
|
|
1924
|
-
mapCellSchema(
|
|
1925
|
-
tableId,
|
|
1926
|
-
(cellId) => `'${cellId}'?: ComponentType<${cellPropsType}>`,
|
|
1927
|
-
),
|
|
1928
|
-
', ',
|
|
1929
|
-
) +
|
|
1930
|
-
'}',
|
|
1931
|
-
`getCellComponentProps?: (cellId: ${cellIdType}) => ExtraProps`,
|
|
1932
|
-
SEPARATOR_PROP_TYPE,
|
|
1933
|
-
DEBUG_IDS_PROP_TYPE,
|
|
1934
|
-
),
|
|
1935
|
-
getPropsDoc(getRowDoc(tableId)),
|
|
1936
|
-
);
|
|
1937
|
-
const tablePropsType = addType(
|
|
1938
|
-
tableName + 'TableProps',
|
|
1939
|
-
getPropsTypeList(
|
|
1940
|
-
storeInstance + OPTIONAL_COLON + storeType,
|
|
1941
|
-
`rowComponent?: ComponentType<${rowPropsType}>`,
|
|
1942
|
-
`getRowComponentProps?: (rowId: Id) => ExtraProps`,
|
|
1943
|
-
SEPARATOR_PROP_TYPE,
|
|
1944
|
-
DEBUG_IDS_PROP_TYPE,
|
|
1945
|
-
),
|
|
1946
|
-
getPropsDoc(getTableDoc(tableId)),
|
|
1947
|
-
);
|
|
1948
|
-
const sortedTablePropsType = addType(
|
|
1949
|
-
tableName + 'SortedTableProps',
|
|
1950
|
-
getPropsTypeList(
|
|
1951
|
-
'cellId?: ' + cellIdType,
|
|
1952
|
-
'descending?: boolean',
|
|
1953
|
-
'offset?: number',
|
|
1954
|
-
'limit?: number',
|
|
1955
|
-
storeInstance + OPTIONAL_COLON + storeType,
|
|
1956
|
-
`rowComponent?: ComponentType<${rowPropsType}>`,
|
|
1957
|
-
`getRowComponentProps?: (rowId: Id) => ExtraProps`,
|
|
1958
|
-
SEPARATOR_PROP_TYPE,
|
|
1959
|
-
DEBUG_IDS_PROP_TYPE,
|
|
1960
|
-
),
|
|
1961
|
-
getPropsDoc(getTableDoc(tableId)) + ', sorted',
|
|
1962
|
-
);
|
|
1963
|
-
addImport(
|
|
1964
|
-
1,
|
|
1965
|
-
uiReactModuleDefinition,
|
|
1966
|
-
rowPropsType,
|
|
1967
|
-
tablePropsType,
|
|
1968
|
-
sortedTablePropsType,
|
|
2169
|
+
DEL + tableName + ROW + CALLBACK,
|
|
2170
|
+
DEL + ROW + CALLBACK,
|
|
2171
|
+
CALLBACK,
|
|
2172
|
+
getRowContentDoc(tableId, 12),
|
|
2173
|
+
TYPED_ROW_ID,
|
|
2174
|
+
getParameterList(TABLE_ID, ROW_ID),
|
|
2175
|
+
EMPTY_STRING,
|
|
2176
|
+
THEN_AND_THEN_DEPS,
|
|
2177
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1969
2178
|
);
|
|
1970
2179
|
const rowView = addComponent(
|
|
1971
2180
|
tableName + ROW + VIEW,
|
|
@@ -1973,17 +2182,20 @@ const getStoreUiReactApi = (
|
|
|
1973
2182
|
storeInstance +
|
|
1974
2183
|
', cellComponents, getCellComponentProps' +
|
|
1975
2184
|
SEPARATOR_AND_DEBUG_IDS +
|
|
1976
|
-
|
|
1977
|
-
rowPropsType,
|
|
2185
|
+
`}: ${rowPropsType}<'${tableId}'>`,
|
|
1978
2186
|
[
|
|
1979
2187
|
wrap + `(${useCellIds}(rowId, ${storeInstance}).map((cellId) => {`,
|
|
1980
|
-
'const Cell = cellComponents?.[cellId] ?? ' +
|
|
2188
|
+
'const Cell = (cellComponents?.[cellId] ?? ' +
|
|
1981
2189
|
getDefaultCellComponent +
|
|
1982
|
-
`(${TABLE_ID}, cellId)
|
|
2190
|
+
`(${TABLE_ID}, cellId)) as React.ComponentType<CellProps<typeof ` +
|
|
2191
|
+
TABLE_ID +
|
|
2192
|
+
', typeof cellId>>;',
|
|
1983
2193
|
'return <Cell',
|
|
1984
2194
|
`{...${getProps}(getCellComponentProps, cellId)} `,
|
|
1985
2195
|
'key={cellId}',
|
|
2196
|
+
`tableId={${TABLE_ID}}`,
|
|
1986
2197
|
ROW_ID_PROP,
|
|
2198
|
+
'cellId={cellId}',
|
|
1987
2199
|
storeProp,
|
|
1988
2200
|
DEBUG_IDS_PROP,
|
|
1989
2201
|
'/>;',
|
|
@@ -1994,7 +2206,8 @@ const getStoreUiReactApi = (
|
|
|
1994
2206
|
addComponent(
|
|
1995
2207
|
tableName + 'Sorted' + TABLE + VIEW,
|
|
1996
2208
|
'{cellId, descending, offset, limit, ...props}: ' +
|
|
1997
|
-
sortedTablePropsType
|
|
2209
|
+
sortedTablePropsType +
|
|
2210
|
+
`<'${tableId}'>`,
|
|
1998
2211
|
tableView +
|
|
1999
2212
|
'(props, ' +
|
|
2000
2213
|
useSortedRowIds +
|
|
@@ -2003,7 +2216,7 @@ const getStoreUiReactApi = (
|
|
|
2003
2216
|
);
|
|
2004
2217
|
addComponent(
|
|
2005
2218
|
tableName + TABLE + VIEW,
|
|
2006
|
-
|
|
2219
|
+
`props: ${tablePropsType}<'${tableId}'>`,
|
|
2007
2220
|
tableView +
|
|
2008
2221
|
'(props, ' +
|
|
2009
2222
|
useRowIds +
|
|
@@ -2056,7 +2269,9 @@ const getStoreUiReactApi = (
|
|
|
2056
2269
|
);
|
|
2057
2270
|
addComponent(
|
|
2058
2271
|
tableName + cellName + CELL + VIEW,
|
|
2059
|
-
`{rowId, ${storeInstance}, debugIds}: ` +
|
|
2272
|
+
`{rowId, ${storeInstance}, debugIds}: ` +
|
|
2273
|
+
cellPropsType +
|
|
2274
|
+
`<'${tableId}', '${cellId}'>`,
|
|
2060
2275
|
[
|
|
2061
2276
|
wrap +
|
|
2062
2277
|
`('' + ${useCell}(rowId, ` +
|
|
@@ -2070,7 +2285,7 @@ const getStoreUiReactApi = (
|
|
|
2070
2285
|
});
|
|
2071
2286
|
const cellIdsType = join(
|
|
2072
2287
|
mapTablesSchema(
|
|
2073
|
-
(tableId) => mapGet(tablesTypes, tableId)?.[
|
|
2288
|
+
(tableId) => mapGet(tablesTypes, tableId)?.[4] ?? EMPTY_STRING,
|
|
2074
2289
|
),
|
|
2075
2290
|
' | ',
|
|
2076
2291
|
);
|
|
@@ -2253,24 +2468,21 @@ const getStoreUiReactApi = (
|
|
|
2253
2468
|
);
|
|
2254
2469
|
const valuePropsType = addType(
|
|
2255
2470
|
VALUE + PROPS,
|
|
2256
|
-
|
|
2471
|
+
getPropTypeList(
|
|
2472
|
+
`valueId?: VId`,
|
|
2257
2473
|
storeInstance + OPTIONAL_COLON + storeType,
|
|
2258
2474
|
DEBUG_IDS_PROP_TYPE,
|
|
2259
2475
|
),
|
|
2260
2476
|
getPropsDoc('a Value'),
|
|
2477
|
+
`<VId extends ${valueIdType}>`,
|
|
2261
2478
|
);
|
|
2262
2479
|
const valuesPropsType = addType(
|
|
2263
2480
|
VALUES + PROPS,
|
|
2264
|
-
|
|
2481
|
+
getPropTypeList(
|
|
2265
2482
|
storeInstance + OPTIONAL_COLON + storeType,
|
|
2266
|
-
'valueComponents?: {' +
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
(valueId) => `'${valueId}'?: ComponentType<${valuePropsType}>`,
|
|
2270
|
-
),
|
|
2271
|
-
', ',
|
|
2272
|
-
) +
|
|
2273
|
-
'}',
|
|
2483
|
+
'valueComponents?: {readonly [VId in ' +
|
|
2484
|
+
valueIdType +
|
|
2485
|
+
`]?: ComponentType<${valuePropsType}<VId>>;}`,
|
|
2274
2486
|
`getValueComponentProps?: (valueId: ${valueIdType}) => ExtraProps`,
|
|
2275
2487
|
SEPARATOR_PROP_TYPE,
|
|
2276
2488
|
DEBUG_IDS_PROP_TYPE,
|
|
@@ -2344,7 +2556,7 @@ const getStoreUiReactApi = (
|
|
|
2344
2556
|
);
|
|
2345
2557
|
addComponent(
|
|
2346
2558
|
valueName + VALUE + VIEW,
|
|
2347
|
-
`{${storeInstance}, debugIds}:
|
|
2559
|
+
`{${storeInstance}, debugIds}: ${valuePropsType}<'${valueId}'>`,
|
|
2348
2560
|
[
|
|
2349
2561
|
wrap +
|
|
2350
2562
|
`('' + ${useValue}(` +
|
|
@@ -2431,6 +2643,597 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
2431
2643
|
];
|
|
2432
2644
|
};
|
|
2433
2645
|
|
|
2646
|
+
const MAY_CONTRADICT_REFINEMENT =
|
|
2647
|
+
'. Note that this may contradict the generated type refinements';
|
|
2648
|
+
const getStoreCoreRefinement = (tablesSchema, valuesSchema, _module) => {
|
|
2649
|
+
const [
|
|
2650
|
+
build,
|
|
2651
|
+
addImport,
|
|
2652
|
+
addType,
|
|
2653
|
+
_addInternalFunction,
|
|
2654
|
+
_addConstant,
|
|
2655
|
+
getImports,
|
|
2656
|
+
getTypes,
|
|
2657
|
+
_getConstants,
|
|
2658
|
+
] = getCodeFunctions();
|
|
2659
|
+
const [mapTablesSchema, mapCellSchema, mapValuesSchema] = getSchemaFunctions(
|
|
2660
|
+
tablesSchema,
|
|
2661
|
+
valuesSchema,
|
|
2662
|
+
() => EMPTY_STRING,
|
|
2663
|
+
);
|
|
2664
|
+
const [getTablesTypes, getValuesTypes, getTransactionListenerType] =
|
|
2665
|
+
getTypeFunctions(addType, mapTablesSchema, mapCellSchema, mapValuesSchema);
|
|
2666
|
+
const methods = mapNew();
|
|
2667
|
+
const getMethods = () =>
|
|
2668
|
+
mapMap(methods, ([parameters, returnType, doc, generic], name) => [
|
|
2669
|
+
comment(doc),
|
|
2670
|
+
name + generic + `(${getParameterList(...parameters)}): ${returnType};`,
|
|
2671
|
+
EMPTY_STRING,
|
|
2672
|
+
]);
|
|
2673
|
+
const addMethod = (
|
|
2674
|
+
name,
|
|
2675
|
+
parameters,
|
|
2676
|
+
returnType,
|
|
2677
|
+
doc,
|
|
2678
|
+
generic = EMPTY_STRING,
|
|
2679
|
+
) =>
|
|
2680
|
+
mapUnique(methods, name, [
|
|
2681
|
+
isArray(parameters) ? parameters : [parameters],
|
|
2682
|
+
returnType,
|
|
2683
|
+
doc,
|
|
2684
|
+
generic,
|
|
2685
|
+
]);
|
|
2686
|
+
addImport(
|
|
2687
|
+
0,
|
|
2688
|
+
'tinybase',
|
|
2689
|
+
ID,
|
|
2690
|
+
IDS,
|
|
2691
|
+
ID_OR_NULL,
|
|
2692
|
+
'StoreListenerStats',
|
|
2693
|
+
JSON$1,
|
|
2694
|
+
TABLES + SCHEMA,
|
|
2695
|
+
VALUES + SCHEMA,
|
|
2696
|
+
'DoRollback',
|
|
2697
|
+
);
|
|
2698
|
+
let tablesTypes;
|
|
2699
|
+
if (objIsEmpty(tablesSchema)) {
|
|
2700
|
+
tablesTypes = [
|
|
2701
|
+
TABLES,
|
|
2702
|
+
TABLES,
|
|
2703
|
+
ID,
|
|
2704
|
+
TABLE,
|
|
2705
|
+
TABLE,
|
|
2706
|
+
ROW,
|
|
2707
|
+
ROW,
|
|
2708
|
+
ID,
|
|
2709
|
+
CELL,
|
|
2710
|
+
CELL + CALLBACK,
|
|
2711
|
+
ROW + CALLBACK,
|
|
2712
|
+
TABLE + CALLBACK,
|
|
2713
|
+
TABLES + LISTENER,
|
|
2714
|
+
TABLE_IDS + LISTENER,
|
|
2715
|
+
TABLE + LISTENER,
|
|
2716
|
+
ROW_IDS + LISTENER,
|
|
2717
|
+
SORTED_ROW_IDS + LISTENER,
|
|
2718
|
+
ROW + LISTENER,
|
|
2719
|
+
CELL_IDS + LISTENER,
|
|
2720
|
+
CELL + LISTENER,
|
|
2721
|
+
INVALID + CELL + LISTENER,
|
|
2722
|
+
];
|
|
2723
|
+
addImport(0, 'tinybase', ...tablesTypes);
|
|
2724
|
+
arrayPush(tablesTypes, ID, ID_OR_NULL, ID, EMPTY_STRING, ID, EMPTY_STRING);
|
|
2725
|
+
} else {
|
|
2726
|
+
addImport(0, 'tinybase', 'CellChange');
|
|
2727
|
+
tablesTypes = getTablesTypes('store', STORE);
|
|
2728
|
+
arrayForEach([3, 4, 5, 6, 7, 9, 10], (i) => (tablesTypes[i] += '<TId>'));
|
|
2729
|
+
tablesTypes[8] += '<TId, CId>';
|
|
2730
|
+
arrayPush(
|
|
2731
|
+
tablesTypes,
|
|
2732
|
+
'TId',
|
|
2733
|
+
'TId | null',
|
|
2734
|
+
join(
|
|
2735
|
+
mapTablesSchema((tableId2) => `CellId<'${tableId2}'>`),
|
|
2736
|
+
' | ',
|
|
2737
|
+
),
|
|
2738
|
+
`<TId extends ${tablesTypes[2]}>`,
|
|
2739
|
+
'CId',
|
|
2740
|
+
`<TId extends ${tablesTypes[2]}, CId extends ${tablesTypes[7]}>`,
|
|
2741
|
+
);
|
|
2742
|
+
}
|
|
2743
|
+
const [
|
|
2744
|
+
tablesType,
|
|
2745
|
+
tablesWhenSetType,
|
|
2746
|
+
tableIdType,
|
|
2747
|
+
tableType,
|
|
2748
|
+
tableWhenSetType,
|
|
2749
|
+
rowType,
|
|
2750
|
+
rowWhenSetType,
|
|
2751
|
+
cellIdType,
|
|
2752
|
+
cellType,
|
|
2753
|
+
cellCallbackType,
|
|
2754
|
+
rowCallbackType,
|
|
2755
|
+
tableCallbackType,
|
|
2756
|
+
tablesListenerType,
|
|
2757
|
+
tableIdsListenerType,
|
|
2758
|
+
tableListenerType,
|
|
2759
|
+
rowIdsListenerType,
|
|
2760
|
+
sortedRowIdsListenerType,
|
|
2761
|
+
rowListenerType,
|
|
2762
|
+
cellIdsListenerType,
|
|
2763
|
+
cellListenerType,
|
|
2764
|
+
invalidCellListenerType,
|
|
2765
|
+
tableId,
|
|
2766
|
+
tableIdOrNull,
|
|
2767
|
+
allCellIdsType,
|
|
2768
|
+
tIdGeneric,
|
|
2769
|
+
cId,
|
|
2770
|
+
cIdGeneric,
|
|
2771
|
+
] = tablesTypes;
|
|
2772
|
+
const tableIdParam = 'tableId: ' + tableId;
|
|
2773
|
+
const rowIdParams = getParameterList(tableIdParam, ROW_ID_PARAM);
|
|
2774
|
+
const cellIdParams = getParameterList(rowIdParams, 'cellId: ' + cId);
|
|
2775
|
+
const tableIdOrNullParam = 'tableId: ' + tableIdOrNull;
|
|
2776
|
+
const rowIdOrNullParams = getParameterList(
|
|
2777
|
+
tableIdOrNullParam,
|
|
2778
|
+
ROW_ID_OR_NULL_PARAM,
|
|
2779
|
+
);
|
|
2780
|
+
const cellIdOrNullParams = getParameterList(
|
|
2781
|
+
rowIdOrNullParams,
|
|
2782
|
+
'cellId: ' + allCellIdsType,
|
|
2783
|
+
);
|
|
2784
|
+
arrayForEach(
|
|
2785
|
+
[[tablesType], [BOOLEAN], [STORE, 'tables: ' + tablesWhenSetType], [STORE]],
|
|
2786
|
+
([returnType, params], verb) =>
|
|
2787
|
+
addMethod(
|
|
2788
|
+
METHOD_PREFIX_VERBS[verb] + TABLES,
|
|
2789
|
+
params ?? EMPTY_STRING,
|
|
2790
|
+
returnType,
|
|
2791
|
+
getTheContentOfTheStoreDoc(1, verb),
|
|
2792
|
+
),
|
|
2793
|
+
);
|
|
2794
|
+
addMethod(
|
|
2795
|
+
GET + TABLE_IDS,
|
|
2796
|
+
EMPTY_STRING,
|
|
2797
|
+
tableIdType + SQUARE_BRACKETS,
|
|
2798
|
+
getIdsDoc(TABLE, THE_STORE),
|
|
2799
|
+
);
|
|
2800
|
+
addMethod(
|
|
2801
|
+
METHOD_PREFIX_VERBS[5] + TABLE,
|
|
2802
|
+
'tableCallback: ' + tableCallbackType,
|
|
2803
|
+
VOID,
|
|
2804
|
+
getForEachDoc(TABLE, THE_STORE),
|
|
2805
|
+
);
|
|
2806
|
+
arrayForEach(
|
|
2807
|
+
[
|
|
2808
|
+
[tableType, tableIdParam],
|
|
2809
|
+
[BOOLEAN, tableIdParam],
|
|
2810
|
+
[STORE, [tableIdParam, 'table: ' + tableWhenSetType]],
|
|
2811
|
+
[STORE, tableIdParam],
|
|
2812
|
+
],
|
|
2813
|
+
([returnType, params], verb) =>
|
|
2814
|
+
addMethod(
|
|
2815
|
+
METHOD_PREFIX_VERBS[verb] + TABLE,
|
|
2816
|
+
params ?? EMPTY_STRING,
|
|
2817
|
+
returnType,
|
|
2818
|
+
getContentDoc(verb, 3),
|
|
2819
|
+
tIdGeneric,
|
|
2820
|
+
),
|
|
2821
|
+
);
|
|
2822
|
+
addMethod(
|
|
2823
|
+
GET + ROW_IDS,
|
|
2824
|
+
tableIdParam,
|
|
2825
|
+
IDS,
|
|
2826
|
+
getIdsDoc(ROW, A + TABLE),
|
|
2827
|
+
tIdGeneric,
|
|
2828
|
+
);
|
|
2829
|
+
addMethod(
|
|
2830
|
+
GET + SORTED_ROW_IDS,
|
|
2831
|
+
[tableIdParam, 'cellId?: ' + cellIdType + SORTED_ARGS],
|
|
2832
|
+
IDS,
|
|
2833
|
+
getIdsDoc(ROW, A + TABLE),
|
|
2834
|
+
tIdGeneric,
|
|
2835
|
+
);
|
|
2836
|
+
addMethod(
|
|
2837
|
+
METHOD_PREFIX_VERBS[5] + ROW,
|
|
2838
|
+
[tableIdParam, 'rowCallback: ' + rowCallbackType],
|
|
2839
|
+
VOID,
|
|
2840
|
+
getForEachDoc(ROW, A + TABLE),
|
|
2841
|
+
tIdGeneric,
|
|
2842
|
+
);
|
|
2843
|
+
arrayForEach(
|
|
2844
|
+
[
|
|
2845
|
+
[rowType, rowIdParams],
|
|
2846
|
+
[BOOLEAN, rowIdParams],
|
|
2847
|
+
[STORE, [rowIdParams, 'row: ' + rowWhenSetType]],
|
|
2848
|
+
[STORE, rowIdParams],
|
|
2849
|
+
],
|
|
2850
|
+
([returnType, params], verb) =>
|
|
2851
|
+
addMethod(
|
|
2852
|
+
METHOD_PREFIX_VERBS[verb] + ROW,
|
|
2853
|
+
params ?? EMPTY_STRING,
|
|
2854
|
+
returnType,
|
|
2855
|
+
getContentDoc(verb, 5),
|
|
2856
|
+
tIdGeneric,
|
|
2857
|
+
),
|
|
2858
|
+
);
|
|
2859
|
+
addMethod(
|
|
2860
|
+
'set' + PARTIAL + ROW,
|
|
2861
|
+
[tableIdParam, ROW_ID_PARAM, 'partialRow: ' + rowWhenSetType],
|
|
2862
|
+
STORE,
|
|
2863
|
+
getContentDoc(4, 5),
|
|
2864
|
+
tIdGeneric,
|
|
2865
|
+
);
|
|
2866
|
+
addMethod(
|
|
2867
|
+
ADD + ROW,
|
|
2868
|
+
[tableIdParam, 'row: ' + rowWhenSetType],
|
|
2869
|
+
ID + OR_UNDEFINED,
|
|
2870
|
+
'Add a new ' + ROW,
|
|
2871
|
+
tIdGeneric,
|
|
2872
|
+
);
|
|
2873
|
+
addMethod(
|
|
2874
|
+
GET + CELL_IDS,
|
|
2875
|
+
[tableIdParam, ROW_ID_PARAM],
|
|
2876
|
+
cellIdType + SQUARE_BRACKETS,
|
|
2877
|
+
getIdsDoc(CELL, A + ROW),
|
|
2878
|
+
tIdGeneric,
|
|
2879
|
+
);
|
|
2880
|
+
addMethod(
|
|
2881
|
+
METHOD_PREFIX_VERBS[5] + CELL,
|
|
2882
|
+
[tableIdParam, ROW_ID_PARAM, 'cellCallback: ' + cellCallbackType],
|
|
2883
|
+
VOID,
|
|
2884
|
+
getForEachDoc(CELL, A + ROW),
|
|
2885
|
+
tIdGeneric,
|
|
2886
|
+
);
|
|
2887
|
+
arrayForEach(
|
|
2888
|
+
[
|
|
2889
|
+
[cellType, cellIdParams],
|
|
2890
|
+
[BOOLEAN, cellIdParams],
|
|
2891
|
+
[STORE, [cellIdParams, 'cell: ' + cellType]],
|
|
2892
|
+
[STORE, cellIdParams],
|
|
2893
|
+
],
|
|
2894
|
+
([returnType, params], verb) =>
|
|
2895
|
+
addMethod(
|
|
2896
|
+
METHOD_PREFIX_VERBS[verb] + CELL,
|
|
2897
|
+
params ?? EMPTY_STRING,
|
|
2898
|
+
returnType,
|
|
2899
|
+
getContentDoc(verb, 7),
|
|
2900
|
+
cIdGeneric,
|
|
2901
|
+
),
|
|
2902
|
+
);
|
|
2903
|
+
addMethod(
|
|
2904
|
+
ADD + TABLES + LISTENER,
|
|
2905
|
+
[LISTENER_ + ': ' + tablesListenerType, 'mutator?: boolean'],
|
|
2906
|
+
ID,
|
|
2907
|
+
getTheContentOfTheStoreDoc(1, 8) + ' changes',
|
|
2908
|
+
);
|
|
2909
|
+
addMethod(
|
|
2910
|
+
ADD + TABLE_IDS + LISTENER,
|
|
2911
|
+
[LISTENER_ + ': ' + tableIdsListenerType, 'mutator?: boolean'],
|
|
2912
|
+
ID,
|
|
2913
|
+
getListenerDoc(2, 0, 1),
|
|
2914
|
+
);
|
|
2915
|
+
addMethod(
|
|
2916
|
+
ADD + TABLE + LISTENER,
|
|
2917
|
+
[
|
|
2918
|
+
tableIdOrNullParam,
|
|
2919
|
+
LISTENER_ + ': ' + tableListenerType,
|
|
2920
|
+
'mutator?: boolean',
|
|
2921
|
+
],
|
|
2922
|
+
ID,
|
|
2923
|
+
getListenerDoc(3, 0),
|
|
2924
|
+
tIdGeneric,
|
|
2925
|
+
);
|
|
2926
|
+
addMethod(
|
|
2927
|
+
ADD + ROW_IDS + LISTENER,
|
|
2928
|
+
[
|
|
2929
|
+
tableIdOrNullParam,
|
|
2930
|
+
LISTENER_ + ': ' + rowIdsListenerType,
|
|
2931
|
+
'mutator?: boolean',
|
|
2932
|
+
],
|
|
2933
|
+
ID,
|
|
2934
|
+
getListenerDoc(4, 3, 1),
|
|
2935
|
+
tIdGeneric,
|
|
2936
|
+
);
|
|
2937
|
+
addMethod(
|
|
2938
|
+
ADD + SORTED_ROW_IDS + LISTENER,
|
|
2939
|
+
[
|
|
2940
|
+
tableIdParam,
|
|
2941
|
+
'cellId: ' + cellIdType + OR_UNDEFINED,
|
|
2942
|
+
'descending: boolean',
|
|
2943
|
+
'offset: number',
|
|
2944
|
+
'limit: number' + OR_UNDEFINED,
|
|
2945
|
+
LISTENER_ + ': ' + sortedRowIdsListenerType,
|
|
2946
|
+
'mutator?: boolean',
|
|
2947
|
+
],
|
|
2948
|
+
ID,
|
|
2949
|
+
getListenerDoc(13, 3, 1),
|
|
2950
|
+
tIdGeneric,
|
|
2951
|
+
);
|
|
2952
|
+
addMethod(
|
|
2953
|
+
ADD + ROW + LISTENER,
|
|
2954
|
+
[
|
|
2955
|
+
rowIdOrNullParams,
|
|
2956
|
+
LISTENER_ + ': ' + rowListenerType,
|
|
2957
|
+
'mutator?: boolean',
|
|
2958
|
+
],
|
|
2959
|
+
ID,
|
|
2960
|
+
getListenerDoc(5, 3),
|
|
2961
|
+
tIdGeneric,
|
|
2962
|
+
);
|
|
2963
|
+
addMethod(
|
|
2964
|
+
ADD + CELL_IDS + LISTENER,
|
|
2965
|
+
[
|
|
2966
|
+
rowIdOrNullParams,
|
|
2967
|
+
LISTENER_ + ': ' + cellIdsListenerType,
|
|
2968
|
+
'mutator?: boolean',
|
|
2969
|
+
],
|
|
2970
|
+
ID,
|
|
2971
|
+
getListenerDoc(6, 5, 1),
|
|
2972
|
+
tIdGeneric,
|
|
2973
|
+
);
|
|
2974
|
+
addMethod(
|
|
2975
|
+
ADD + CELL + LISTENER,
|
|
2976
|
+
[
|
|
2977
|
+
cellIdOrNullParams,
|
|
2978
|
+
LISTENER_ + ': ' + cellListenerType,
|
|
2979
|
+
'mutator?: boolean',
|
|
2980
|
+
],
|
|
2981
|
+
ID,
|
|
2982
|
+
getListenerDoc(7, 5),
|
|
2983
|
+
tIdGeneric,
|
|
2984
|
+
);
|
|
2985
|
+
addMethod(
|
|
2986
|
+
ADD + INVALID + CELL + LISTENER,
|
|
2987
|
+
[
|
|
2988
|
+
'tableId: ' + ID_OR_NULL,
|
|
2989
|
+
'rowId: ' + ID_OR_NULL,
|
|
2990
|
+
'cellId: ' + ID_OR_NULL,
|
|
2991
|
+
LISTENER_ + ': ' + invalidCellListenerType,
|
|
2992
|
+
'mutator?: boolean',
|
|
2993
|
+
],
|
|
2994
|
+
ID,
|
|
2995
|
+
REGISTERS_A_LISTENER + ' whenever an invalid Cell change was attempted',
|
|
2996
|
+
);
|
|
2997
|
+
let valuesTypes;
|
|
2998
|
+
if (objIsEmpty(valuesSchema)) {
|
|
2999
|
+
valuesTypes = [
|
|
3000
|
+
VALUES,
|
|
3001
|
+
VALUES,
|
|
3002
|
+
ID,
|
|
3003
|
+
VALUE,
|
|
3004
|
+
VALUE + CALLBACK,
|
|
3005
|
+
VALUES + LISTENER,
|
|
3006
|
+
VALUE_IDS + LISTENER,
|
|
3007
|
+
VALUE + LISTENER,
|
|
3008
|
+
INVALID + VALUE + LISTENER,
|
|
3009
|
+
];
|
|
3010
|
+
addImport(0, 'tinybase', ...valuesTypes);
|
|
3011
|
+
arrayPush(valuesTypes, ID, ID_OR_NULL, EMPTY_STRING);
|
|
3012
|
+
} else {
|
|
3013
|
+
addImport(0, 'tinybase', 'ValueChange');
|
|
3014
|
+
valuesTypes = getValuesTypes('store', STORE);
|
|
3015
|
+
valuesTypes[3] += '<VId>';
|
|
3016
|
+
arrayPush(
|
|
3017
|
+
valuesTypes,
|
|
3018
|
+
'VId',
|
|
3019
|
+
'VId | null',
|
|
3020
|
+
`<VId extends ${valuesTypes[2]}>`,
|
|
3021
|
+
);
|
|
3022
|
+
}
|
|
3023
|
+
const [
|
|
3024
|
+
valuesType,
|
|
3025
|
+
valuesWhenSetType,
|
|
3026
|
+
valueIdType,
|
|
3027
|
+
valueType,
|
|
3028
|
+
valueCallbackType,
|
|
3029
|
+
valuesListenerType,
|
|
3030
|
+
valueIdsListenerType,
|
|
3031
|
+
valueListenerType,
|
|
3032
|
+
invalidValueListenerType,
|
|
3033
|
+
valueId,
|
|
3034
|
+
valueIdOrNull,
|
|
3035
|
+
vIdGeneric,
|
|
3036
|
+
] = valuesTypes;
|
|
3037
|
+
const valueIdParam = 'valueId: ' + valueId;
|
|
3038
|
+
arrayForEach(
|
|
3039
|
+
[[valuesType], [BOOLEAN], [STORE, 'values: ' + valuesWhenSetType], [STORE]],
|
|
3040
|
+
([returnType, params], verb) =>
|
|
3041
|
+
addMethod(
|
|
3042
|
+
METHOD_PREFIX_VERBS[verb] + VALUES,
|
|
3043
|
+
params ?? EMPTY_STRING,
|
|
3044
|
+
returnType,
|
|
3045
|
+
getTheContentOfTheStoreDoc(2, verb),
|
|
3046
|
+
),
|
|
3047
|
+
);
|
|
3048
|
+
addMethod(
|
|
3049
|
+
'set' + PARTIAL + VALUES,
|
|
3050
|
+
'partialValues: ' + valuesWhenSetType,
|
|
3051
|
+
STORE,
|
|
3052
|
+
getTheContentOfTheStoreDoc(2, 4),
|
|
3053
|
+
);
|
|
3054
|
+
addMethod(
|
|
3055
|
+
GET + VALUE_IDS,
|
|
3056
|
+
EMPTY_STRING,
|
|
3057
|
+
valueIdType + SQUARE_BRACKETS,
|
|
3058
|
+
getIdsDoc(VALUE, THE_STORE),
|
|
3059
|
+
);
|
|
3060
|
+
addMethod(
|
|
3061
|
+
METHOD_PREFIX_VERBS[5] + VALUE,
|
|
3062
|
+
'valueCallback: ' + valueCallbackType,
|
|
3063
|
+
VOID,
|
|
3064
|
+
getForEachDoc(VALUE, THE_STORE),
|
|
3065
|
+
);
|
|
3066
|
+
arrayForEach(
|
|
3067
|
+
[
|
|
3068
|
+
[valueType, valueIdParam],
|
|
3069
|
+
[BOOLEAN, valueIdParam],
|
|
3070
|
+
[STORE, [valueIdParam, 'value: ' + valueType]],
|
|
3071
|
+
[STORE, valueIdParam],
|
|
3072
|
+
],
|
|
3073
|
+
([returnType, params], verb) =>
|
|
3074
|
+
addMethod(
|
|
3075
|
+
METHOD_PREFIX_VERBS[verb] + VALUE,
|
|
3076
|
+
params ?? EMPTY_STRING,
|
|
3077
|
+
returnType,
|
|
3078
|
+
getContentDoc(verb, 11),
|
|
3079
|
+
vIdGeneric,
|
|
3080
|
+
),
|
|
3081
|
+
);
|
|
3082
|
+
addMethod(
|
|
3083
|
+
ADD + VALUES + LISTENER,
|
|
3084
|
+
[LISTENER_ + ': ' + valuesListenerType, 'mutator?: boolean'],
|
|
3085
|
+
ID,
|
|
3086
|
+
getTheContentOfTheStoreDoc(2, 8) + ' changes',
|
|
3087
|
+
);
|
|
3088
|
+
addMethod(
|
|
3089
|
+
ADD + VALUE_IDS + LISTENER,
|
|
3090
|
+
[LISTENER_ + ': ' + valueIdsListenerType, 'mutator?: boolean'],
|
|
3091
|
+
ID,
|
|
3092
|
+
getListenerDoc(10, 0, 1),
|
|
3093
|
+
);
|
|
3094
|
+
addMethod(
|
|
3095
|
+
ADD + VALUE + LISTENER,
|
|
3096
|
+
[
|
|
3097
|
+
'valueId: ' + valueIdOrNull,
|
|
3098
|
+
LISTENER_ + ': ' + valueListenerType,
|
|
3099
|
+
'mutator?: boolean',
|
|
3100
|
+
],
|
|
3101
|
+
ID,
|
|
3102
|
+
getListenerDoc(11, 0),
|
|
3103
|
+
vIdGeneric,
|
|
3104
|
+
);
|
|
3105
|
+
addMethod(
|
|
3106
|
+
ADD + INVALID + VALUE + LISTENER,
|
|
3107
|
+
[
|
|
3108
|
+
'valueId: ' + ID_OR_NULL,
|
|
3109
|
+
LISTENER_ + ': ' + invalidValueListenerType,
|
|
3110
|
+
'mutator?: boolean',
|
|
3111
|
+
],
|
|
3112
|
+
ID,
|
|
3113
|
+
REGISTERS_A_LISTENER + ' whenever an invalid Value change was attempted',
|
|
3114
|
+
);
|
|
3115
|
+
arrayForEach(
|
|
3116
|
+
[
|
|
3117
|
+
[EMPTY_STRING, 'tablesAndValues'],
|
|
3118
|
+
[TABLES, 'tables'],
|
|
3119
|
+
[VALUES, 'values'],
|
|
3120
|
+
],
|
|
3121
|
+
([noun, param], content) => {
|
|
3122
|
+
addMethod(
|
|
3123
|
+
GET + noun + JSON$1,
|
|
3124
|
+
EMPTY_STRING,
|
|
3125
|
+
JSON$1,
|
|
3126
|
+
getTheContentOfTheStoreDoc(content, 6),
|
|
3127
|
+
);
|
|
3128
|
+
addMethod(
|
|
3129
|
+
'set' + noun + JSON$1,
|
|
3130
|
+
param + JSON$1 + ': ' + JSON$1,
|
|
3131
|
+
STORE,
|
|
3132
|
+
getTheContentOfTheStoreDoc(content, 7),
|
|
3133
|
+
);
|
|
3134
|
+
addMethod(
|
|
3135
|
+
GET + noun + SCHEMA + JSON$1,
|
|
3136
|
+
EMPTY_STRING,
|
|
3137
|
+
JSON$1,
|
|
3138
|
+
getTheContentOfTheStoreDoc(content, 14),
|
|
3139
|
+
);
|
|
3140
|
+
if (noun) {
|
|
3141
|
+
addMethod(
|
|
3142
|
+
'set' + noun + SCHEMA,
|
|
3143
|
+
param + SCHEMA + ': ' + noun + SCHEMA,
|
|
3144
|
+
STORE,
|
|
3145
|
+
getTheContentOfTheStoreDoc(content, 15) + MAY_CONTRADICT_REFINEMENT,
|
|
3146
|
+
);
|
|
3147
|
+
}
|
|
3148
|
+
addMethod(
|
|
3149
|
+
'del' + noun + SCHEMA,
|
|
3150
|
+
EMPTY_STRING,
|
|
3151
|
+
STORE,
|
|
3152
|
+
getTheContentOfTheStoreDoc(content, 16),
|
|
3153
|
+
);
|
|
3154
|
+
},
|
|
3155
|
+
);
|
|
3156
|
+
addMethod(
|
|
3157
|
+
'set' + SCHEMA,
|
|
3158
|
+
[
|
|
3159
|
+
`tables${SCHEMA}: ` + TABLES + SCHEMA,
|
|
3160
|
+
`values${SCHEMA}?: ` + VALUES + SCHEMA,
|
|
3161
|
+
],
|
|
3162
|
+
STORE,
|
|
3163
|
+
getTheContentOfTheStoreDoc(0, 15) + MAY_CONTRADICT_REFINEMENT,
|
|
3164
|
+
);
|
|
3165
|
+
addMethod(
|
|
3166
|
+
TRANSACTION_,
|
|
3167
|
+
DO_ACTIONS_AND_ROLLBACK_PARAMS,
|
|
3168
|
+
'Return',
|
|
3169
|
+
TRANSACTION_DOC,
|
|
3170
|
+
'<Return>',
|
|
3171
|
+
);
|
|
3172
|
+
addMethod('start' + TRANSACTION, EMPTY_STRING, STORE, START_TRANSACTION_DOC);
|
|
3173
|
+
addMethod(
|
|
3174
|
+
'finish' + TRANSACTION,
|
|
3175
|
+
DO_ROLLBACK_PARAM,
|
|
3176
|
+
STORE,
|
|
3177
|
+
FINISH_TRANSACTION_DOC,
|
|
3178
|
+
);
|
|
3179
|
+
const transactionListenerType = getTransactionListenerType('store', STORE);
|
|
3180
|
+
addMethod(
|
|
3181
|
+
ADD + 'WillFinish' + TRANSACTION + LISTENER,
|
|
3182
|
+
LISTENER_ + ': ' + transactionListenerType,
|
|
3183
|
+
ID,
|
|
3184
|
+
REGISTERS_A_LISTENER + ' just before ' + THE_END_OF_THE_TRANSACTION,
|
|
3185
|
+
);
|
|
3186
|
+
addMethod(
|
|
3187
|
+
ADD + 'DidFinish' + TRANSACTION + LISTENER,
|
|
3188
|
+
LISTENER_ + ': ' + transactionListenerType,
|
|
3189
|
+
ID,
|
|
3190
|
+
REGISTERS_A_LISTENER + ' just after ' + THE_END_OF_THE_TRANSACTION,
|
|
3191
|
+
);
|
|
3192
|
+
addMethod(
|
|
3193
|
+
'call' + LISTENER,
|
|
3194
|
+
'listenerId: Id',
|
|
3195
|
+
STORE,
|
|
3196
|
+
'Manually provoke a listener to be called',
|
|
3197
|
+
);
|
|
3198
|
+
addMethod(
|
|
3199
|
+
'del' + LISTENER,
|
|
3200
|
+
'listenerId: Id',
|
|
3201
|
+
STORE,
|
|
3202
|
+
'Remove a listener that was previously added to ' + THE_STORE,
|
|
3203
|
+
);
|
|
3204
|
+
addMethod(
|
|
3205
|
+
GET + LISTENER + 'Stats',
|
|
3206
|
+
EMPTY_STRING,
|
|
3207
|
+
'StoreListenerStats',
|
|
3208
|
+
'Get listener statistics',
|
|
3209
|
+
);
|
|
3210
|
+
return [
|
|
3211
|
+
build(
|
|
3212
|
+
`export * from 'tinybase';`,
|
|
3213
|
+
...getImports(0),
|
|
3214
|
+
...getTypes(),
|
|
3215
|
+
'export interface Store {',
|
|
3216
|
+
...getMethods(),
|
|
3217
|
+
'}',
|
|
3218
|
+
EMPTY_STRING,
|
|
3219
|
+
comment(`Creates a Store object`),
|
|
3220
|
+
'export function createStore(): Store',
|
|
3221
|
+
),
|
|
3222
|
+
];
|
|
3223
|
+
};
|
|
3224
|
+
|
|
3225
|
+
const getStoreUiReactRefinement = (_tablesSchema, _valuesSchema, _module) => {
|
|
3226
|
+
return [`export * from 'tinybase/ui-react';`];
|
|
3227
|
+
};
|
|
3228
|
+
|
|
3229
|
+
const getStoreRefinement = (tablesSchema, valuesSchema, module) => {
|
|
3230
|
+
if (objIsEmpty(tablesSchema) && objIsEmpty(valuesSchema)) {
|
|
3231
|
+
return [EMPTY_STRING, EMPTY_STRING];
|
|
3232
|
+
}
|
|
3233
|
+
const [dTsCore] = getStoreCoreRefinement(tablesSchema, valuesSchema);
|
|
3234
|
+
return [dTsCore, ...getStoreUiReactRefinement()];
|
|
3235
|
+
};
|
|
3236
|
+
|
|
2434
3237
|
const prettierConfig = {
|
|
2435
3238
|
parser: 'typescript',
|
|
2436
3239
|
singleQuote: true,
|
|
@@ -2438,6 +3241,13 @@ const prettierConfig = {
|
|
|
2438
3241
|
bracketSpacing: false,
|
|
2439
3242
|
jsdocSingleLineComment: false,
|
|
2440
3243
|
};
|
|
3244
|
+
const getFormat = async () => {
|
|
3245
|
+
try {
|
|
3246
|
+
return (await import('prettier')).format;
|
|
3247
|
+
} catch (e) {
|
|
3248
|
+
return (str) => str;
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
2441
3251
|
const createTools = getCreateFunction((store) => {
|
|
2442
3252
|
const getStoreStats = (detail) => {
|
|
2443
3253
|
let totalTables = 0;
|
|
@@ -2531,18 +3341,21 @@ const createTools = getCreateFunction((store) => {
|
|
|
2531
3341
|
getStoreApi(getStoreTablesSchema(), getStoreValuesSchema(), module);
|
|
2532
3342
|
const getPrettyStoreApi = async (module) => {
|
|
2533
3343
|
const extensions = ['d.ts', 'ts', 'd.ts', 'tsx'];
|
|
2534
|
-
|
|
2535
|
-
try {
|
|
2536
|
-
format = (await import('prettier')).format;
|
|
2537
|
-
} catch (e) {
|
|
2538
|
-
format = (str) => str;
|
|
2539
|
-
}
|
|
3344
|
+
const format = await getFormat();
|
|
2540
3345
|
return arrayMap(getStoreApi$1(module), (file, f) =>
|
|
2541
3346
|
formatJsDoc(
|
|
2542
3347
|
format(file, {...prettierConfig, filepath: `_.${extensions[f]}`}),
|
|
2543
3348
|
),
|
|
2544
3349
|
);
|
|
2545
3350
|
};
|
|
3351
|
+
const getStoreRefinement$1 = (module) =>
|
|
3352
|
+
getStoreRefinement(getStoreTablesSchema(), getStoreValuesSchema());
|
|
3353
|
+
const getPrettyStoreRefinement = async (module) => {
|
|
3354
|
+
const format = await getFormat();
|
|
3355
|
+
return arrayMap(getStoreRefinement$1(), (file) =>
|
|
3356
|
+
formatJsDoc(format(file, {...prettierConfig, filepath: `_.d.ts`})),
|
|
3357
|
+
);
|
|
3358
|
+
};
|
|
2546
3359
|
const getStore = () => store;
|
|
2547
3360
|
const tools = {
|
|
2548
3361
|
getStoreStats,
|
|
@@ -2550,6 +3363,8 @@ const createTools = getCreateFunction((store) => {
|
|
|
2550
3363
|
getStoreValuesSchema,
|
|
2551
3364
|
getStoreApi: getStoreApi$1,
|
|
2552
3365
|
getPrettyStoreApi,
|
|
3366
|
+
getStoreRefinement: getStoreRefinement$1,
|
|
3367
|
+
getPrettyStoreRefinement,
|
|
2553
3368
|
getStore,
|
|
2554
3369
|
};
|
|
2555
3370
|
return objFreeze(tools);
|