tinybase 3.1.0-beta.0 → 3.1.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.
- package/bin/cli.js +1 -1
- package/lib/cjs/checkpoints.cjs +1 -0
- package/lib/cjs/checkpoints.cjs.gz +0 -0
- package/lib/cjs/checkpoints.d.ts +959 -0
- package/lib/cjs/common.cjs +1 -0
- package/lib/cjs/common.cjs.gz +0 -0
- package/lib/cjs/common.d.ts +115 -0
- package/lib/cjs/indexes.cjs +1 -0
- package/lib/cjs/indexes.cjs.gz +0 -0
- package/lib/cjs/indexes.d.ts +966 -0
- package/lib/cjs/metrics.cjs +1 -0
- package/lib/cjs/metrics.cjs.gz +0 -0
- package/lib/cjs/metrics.d.ts +827 -0
- package/lib/cjs/persisters.cjs +1 -0
- package/lib/cjs/persisters.cjs.gz +0 -0
- package/lib/cjs/persisters.d.ts +727 -0
- package/lib/cjs/queries.cjs +1 -0
- package/lib/cjs/queries.cjs.gz +0 -0
- package/lib/cjs/queries.d.ts +3024 -0
- package/lib/cjs/relationships.cjs +1 -0
- package/lib/cjs/relationships.cjs.gz +0 -0
- package/lib/cjs/relationships.d.ts +1201 -0
- package/lib/cjs/store.cjs +1 -0
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/store.d.ts +5244 -0
- package/lib/cjs/tinybase.cjs +1 -0
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/tinybase.d.ts +14 -0
- package/lib/cjs/tools.cjs +1 -0
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/tools.d.ts +536 -0
- package/lib/cjs/ui-react.cjs +1 -0
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs/ui-react.d.ts +10921 -0
- package/lib/cjs-es6/checkpoints.cjs +1 -0
- package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
- package/lib/cjs-es6/checkpoints.d.ts +959 -0
- package/lib/cjs-es6/common.cjs +1 -0
- package/lib/cjs-es6/common.cjs.gz +0 -0
- package/lib/cjs-es6/common.d.ts +115 -0
- package/lib/cjs-es6/indexes.cjs +1 -0
- package/lib/cjs-es6/indexes.cjs.gz +0 -0
- package/lib/cjs-es6/indexes.d.ts +966 -0
- package/lib/cjs-es6/metrics.cjs +1 -0
- package/lib/cjs-es6/metrics.cjs.gz +0 -0
- package/lib/cjs-es6/metrics.d.ts +827 -0
- package/lib/cjs-es6/persisters.cjs +1 -0
- package/lib/cjs-es6/persisters.cjs.gz +0 -0
- package/lib/cjs-es6/persisters.d.ts +727 -0
- package/lib/cjs-es6/queries.cjs +1 -0
- package/lib/cjs-es6/queries.cjs.gz +0 -0
- package/lib/cjs-es6/queries.d.ts +3024 -0
- package/lib/cjs-es6/relationships.cjs +1 -0
- package/lib/cjs-es6/relationships.cjs.gz +0 -0
- package/lib/cjs-es6/relationships.d.ts +1201 -0
- package/lib/cjs-es6/store.cjs +1 -0
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/store.d.ts +5244 -0
- package/lib/cjs-es6/tinybase.cjs +1 -0
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.d.ts +14 -0
- package/lib/cjs-es6/tools.cjs +1 -0
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/tools.d.ts +536 -0
- package/lib/cjs-es6/ui-react.cjs +1 -0
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.d.ts +10921 -0
- package/lib/debug/queries.js +4 -3
- package/lib/debug/store.js +7 -6
- package/lib/debug/tinybase.js +8 -7
- package/lib/debug/tools.d.ts +59 -35
- package/lib/debug/tools.js +1966 -727
- package/lib/debug/ui-react.js +32 -30
- package/lib/es6/tools.d.ts +59 -35
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/tools.d.ts +59 -35
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.d.ts +59 -35
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +59 -35
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +31 -23
- package/readme.md +1 -1
package/lib/debug/tools.js
CHANGED
|
@@ -5,6 +5,21 @@ const BOOLEAN = getTypeOf(true);
|
|
|
5
5
|
const NUMBER = getTypeOf(0);
|
|
6
6
|
const TYPE = 'type';
|
|
7
7
|
const DEFAULT = 'default';
|
|
8
|
+
const LISTENER = 'Listener';
|
|
9
|
+
const GET = 'get';
|
|
10
|
+
const ADD = 'add';
|
|
11
|
+
const IDS = 'Ids';
|
|
12
|
+
const TABLE = 'Table';
|
|
13
|
+
const TABLES = TABLE + 's';
|
|
14
|
+
const TABLE_IDS = TABLE + IDS;
|
|
15
|
+
const ROW = 'Row';
|
|
16
|
+
const ROW_IDS = ROW + IDS;
|
|
17
|
+
const SORTED_ROW_IDS = 'Sorted' + ROW + IDS;
|
|
18
|
+
const CELL = 'Cell';
|
|
19
|
+
const CELL_IDS = CELL + IDS;
|
|
20
|
+
const VALUE = 'Value';
|
|
21
|
+
const VALUES = VALUE + 's';
|
|
22
|
+
const VALUE_IDS = VALUE + IDS;
|
|
8
23
|
|
|
9
24
|
const arrayEvery = (array, cb) => array.every(cb);
|
|
10
25
|
const arraySort = (array, sorter) => array.sort(sorter);
|
|
@@ -12,6 +27,7 @@ const arrayForEach = (array, cb) => array.forEach(cb);
|
|
|
12
27
|
const arrayMap = (array, cb) => array.map(cb);
|
|
13
28
|
const arrayLength = (array) => array.length;
|
|
14
29
|
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
30
|
+
const arrayFilter = (array, cb) => array.filter(cb);
|
|
15
31
|
const arrayPush = (array, ...values) => array.push(...values);
|
|
16
32
|
const arrayPop = (array) => array.pop();
|
|
17
33
|
const arrayUnshift = (array, ...values) => array.unshift(...values);
|
|
@@ -52,6 +68,113 @@ const mapEnsure = (map, key, getDefaultValue) => {
|
|
|
52
68
|
return mapGet(map, key);
|
|
53
69
|
};
|
|
54
70
|
|
|
71
|
+
const upper = (str) => str.toUpperCase();
|
|
72
|
+
const lower = (str) => str.toLowerCase();
|
|
73
|
+
const A = 'a ';
|
|
74
|
+
const A_FUNCTION_FOR = 'A function for';
|
|
75
|
+
const CALLBACK = 'Callback';
|
|
76
|
+
const DEL = 'Del';
|
|
77
|
+
const EXPORT = 'export';
|
|
78
|
+
const ID = 'Id';
|
|
79
|
+
const INVALID = 'Invalid';
|
|
80
|
+
const JSON$1 = 'Json';
|
|
81
|
+
const LISTENER_ = lower(LISTENER);
|
|
82
|
+
const OR_UNDEFINED = ' | undefined';
|
|
83
|
+
const PARTIAL = 'Partial';
|
|
84
|
+
const REGISTERS_A_LISTENER = `Registers a ${LISTENER_} that will be called`;
|
|
85
|
+
const REPRESENTS = 'Represents';
|
|
86
|
+
const SET = 'Set';
|
|
87
|
+
const SQUARE_BRACKETS = '[]';
|
|
88
|
+
const THE_STORE = 'the Store';
|
|
89
|
+
const TRANSACTION = 'Transaction';
|
|
90
|
+
const TRANSACTION_ = lower(TRANSACTION);
|
|
91
|
+
const THE_END_OF_THE_TRANSACTION = 'the end of the ' + TRANSACTION_;
|
|
92
|
+
const VOID = 'void';
|
|
93
|
+
const RETURNS_VOID = ' => ' + VOID;
|
|
94
|
+
const A_STRING_SERIALIZATION_OF = A + 'string serialization of';
|
|
95
|
+
const SPACE = ' ';
|
|
96
|
+
const GETS_A_CALLBACK_THAT_CAN = 'Gets a callback that can ';
|
|
97
|
+
const THE = 'the ';
|
|
98
|
+
const getTheContentOfDoc = (content = 0, theStore = 0) =>
|
|
99
|
+
`the ${CONTENT[content]}content of` +
|
|
100
|
+
(theStore ? SPACE + THE_STORE : EMPTY_STRING);
|
|
101
|
+
const getTheContentOfTheStoreDoc = (content = 0, verb, set = 0) =>
|
|
102
|
+
VERBS[verb] +
|
|
103
|
+
SPACE +
|
|
104
|
+
getTheContentOfDoc(content, 1) +
|
|
105
|
+
(set ? ' when set' : EMPTY_STRING);
|
|
106
|
+
const getRowTypeDoc = (tableId, set = 0) =>
|
|
107
|
+
REPRESENTS +
|
|
108
|
+
` a Row when ${
|
|
109
|
+
set ? 's' : 'g'
|
|
110
|
+
}etting ${getTheContentOfDoc()} the '${tableId}' ` +
|
|
111
|
+
TABLE;
|
|
112
|
+
const getIdsDoc = (idsNoun, parentNoun, sorted = 0) =>
|
|
113
|
+
`Gets ${sorted ? 'sorted, paginated' : 'the'} Ids of the ${idsNoun}s in ` +
|
|
114
|
+
parentNoun;
|
|
115
|
+
const getForEachDoc = (childNoun, parentNoun) =>
|
|
116
|
+
`Calls a function for each ${childNoun} in ` + parentNoun;
|
|
117
|
+
const getPropsDoc = (childNoun) =>
|
|
118
|
+
'The props passed to a component that renders ' + childNoun;
|
|
119
|
+
const getCallbackDoc = (takes) => 'A function that takes ' + takes;
|
|
120
|
+
const getListenerTypeDoc = (childNoun, parentNoun = 0) =>
|
|
121
|
+
A_FUNCTION_FOR +
|
|
122
|
+
' listening to changes to ' +
|
|
123
|
+
NOUNS[childNoun] +
|
|
124
|
+
' in ' +
|
|
125
|
+
NOUNS[parentNoun];
|
|
126
|
+
const getListenerDoc = (childNoun, parentNoun, pluralChild = 0) =>
|
|
127
|
+
REGISTERS_A_LISTENER +
|
|
128
|
+
' whenever ' +
|
|
129
|
+
NOUNS[childNoun] +
|
|
130
|
+
' in ' +
|
|
131
|
+
NOUNS[parentNoun] +
|
|
132
|
+
' change' +
|
|
133
|
+
(pluralChild ? EMPTY_STRING : 's');
|
|
134
|
+
const getTableDoc = (tableId) => `the '${tableId}' ` + TABLE;
|
|
135
|
+
const getRowDoc = (tableId) => 'the specified Row in ' + getTableDoc(tableId);
|
|
136
|
+
const getTableContentDoc = (tableId, verb = 0) =>
|
|
137
|
+
VERBS[verb] + ` ${getTheContentOfDoc()} ` + getTableDoc(tableId);
|
|
138
|
+
const getRowContentDoc = (tableId, verb = 0) =>
|
|
139
|
+
VERBS[verb] + ` ${getTheContentOfDoc()} ` + getRowDoc(tableId);
|
|
140
|
+
const getCellContentDoc = (tableId, cellId, verb = 0) =>
|
|
141
|
+
VERBS[verb] + ` the '${cellId}' Cell for ` + getRowDoc(tableId);
|
|
142
|
+
const getValueContentDoc = (valueId, verb = 0) =>
|
|
143
|
+
VERBS[verb] + ` the '${valueId}' Value`;
|
|
144
|
+
const VERBS = [
|
|
145
|
+
'Gets',
|
|
146
|
+
'Checks existence of',
|
|
147
|
+
'Sets',
|
|
148
|
+
'Deletes',
|
|
149
|
+
'Sets part of',
|
|
150
|
+
REPRESENTS,
|
|
151
|
+
'Gets ' + A_STRING_SERIALIZATION_OF,
|
|
152
|
+
'Sets ' + A_STRING_SERIALIZATION_OF,
|
|
153
|
+
REGISTERS_A_LISTENER + ' whenever',
|
|
154
|
+
GETS_A_CALLBACK_THAT_CAN + 'set',
|
|
155
|
+
GETS_A_CALLBACK_THAT_CAN + 'add',
|
|
156
|
+
GETS_A_CALLBACK_THAT_CAN + 'set part of',
|
|
157
|
+
GETS_A_CALLBACK_THAT_CAN + 'delete',
|
|
158
|
+
'Renders',
|
|
159
|
+
];
|
|
160
|
+
const NOUNS = [
|
|
161
|
+
THE_STORE,
|
|
162
|
+
TABLES,
|
|
163
|
+
THE + TABLE + SPACE + IDS,
|
|
164
|
+
A + TABLE,
|
|
165
|
+
THE + ROW + SPACE + IDS,
|
|
166
|
+
A + ROW,
|
|
167
|
+
THE + CELL + SPACE + IDS,
|
|
168
|
+
A + CELL,
|
|
169
|
+
'invalid Cell changes',
|
|
170
|
+
VALUES,
|
|
171
|
+
THE + VALUE + SPACE + IDS,
|
|
172
|
+
A + VALUE,
|
|
173
|
+
'invalid Value changes',
|
|
174
|
+
THE + 'sorted ' + ROW + SPACE + IDS,
|
|
175
|
+
];
|
|
176
|
+
const CONTENT = [EMPTY_STRING, 'tabular ', 'keyed value '];
|
|
177
|
+
|
|
55
178
|
const setNew = (entryOrEntries) =>
|
|
56
179
|
new Set(
|
|
57
180
|
isArray(entryOrEntries) || isUndefined(entryOrEntries)
|
|
@@ -60,15 +183,11 @@ const setNew = (entryOrEntries) =>
|
|
|
60
183
|
);
|
|
61
184
|
const setAdd = (set, value) => set?.add(value);
|
|
62
185
|
|
|
63
|
-
const pairNew = (value) => [value, value];
|
|
64
|
-
const pairNewMap = () => [mapNew(), mapNew()];
|
|
65
|
-
|
|
66
186
|
const NON_ALPHA = /[^A-Za-z]+/;
|
|
67
187
|
const NON_ALPHANUMERIC = /[^A-Za-z0-9]+/;
|
|
68
188
|
const JSDOC = /^( *)\/\*\* *(.*?) *\*\/$/gm;
|
|
69
189
|
const substr = (str, start, end) => str.substring(start, end);
|
|
70
|
-
const
|
|
71
|
-
const lower = (str) => str.toLowerCase();
|
|
190
|
+
const stringHasComma = (str) => str.includes(',');
|
|
72
191
|
const mapUnique = (map, id, value, index = 1) => {
|
|
73
192
|
const uniqueId = `${id}${index == 1 ? '' : index}`;
|
|
74
193
|
if (collHas(map, uniqueId)) {
|
|
@@ -110,20 +229,26 @@ const snake = (str) =>
|
|
|
110
229
|
),
|
|
111
230
|
);
|
|
112
231
|
const comment = (doc) => `/** ${doc}. */`;
|
|
232
|
+
const getParameterList = (...params) =>
|
|
233
|
+
join(
|
|
234
|
+
arrayFilter(params, (param) => param),
|
|
235
|
+
', ',
|
|
236
|
+
);
|
|
113
237
|
const getCodeFunctions = () => {
|
|
114
|
-
const allImports =
|
|
238
|
+
const allImports = [mapNew(), mapNew(), mapNew(), mapNew()];
|
|
115
239
|
const types = mapNew();
|
|
116
|
-
const methods = mapNew();
|
|
117
240
|
const constants = mapNew();
|
|
118
241
|
const build = (...lines) => join(flat(lines), '\n');
|
|
119
242
|
const addImport = (location, source, ...items) =>
|
|
120
243
|
arrayForEach(items, (item) =>
|
|
121
|
-
|
|
244
|
+
arrayForEach([0, 1], (eachLocation) =>
|
|
245
|
+
(location ?? eachLocation) == eachLocation
|
|
246
|
+
? setAdd(mapEnsure(allImports[eachLocation], source, setNew), item)
|
|
247
|
+
: 0,
|
|
248
|
+
),
|
|
122
249
|
);
|
|
123
250
|
const addType = (name, body, doc) => mapUnique(types, name, [body, doc]);
|
|
124
|
-
const
|
|
125
|
-
mapUnique(methods, name, [parameters, returnType, body, doc, generic]);
|
|
126
|
-
const addFunction = (name, parameters, body) =>
|
|
251
|
+
const addInternalFunction = (name, parameters, body) =>
|
|
127
252
|
mapUnique(
|
|
128
253
|
constants,
|
|
129
254
|
name,
|
|
@@ -133,36 +258,38 @@ const getCodeFunctions = () => {
|
|
|
133
258
|
);
|
|
134
259
|
const addConstant = (name, body) =>
|
|
135
260
|
mapGet(constants, name) === body ? name : mapUnique(constants, name, body);
|
|
136
|
-
const getImports = (location) =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
261
|
+
const getImports = (location = 0) =>
|
|
262
|
+
arrayMap(
|
|
263
|
+
[
|
|
264
|
+
...arraySort(
|
|
265
|
+
mapMap(
|
|
266
|
+
allImports[location],
|
|
267
|
+
(items, source) =>
|
|
268
|
+
`import {${join(
|
|
269
|
+
arraySort(collValues(items)),
|
|
270
|
+
', ',
|
|
271
|
+
)}} from '${source}';`,
|
|
272
|
+
),
|
|
273
|
+
(import1, import2) =>
|
|
274
|
+
stringHasComma(import1) != stringHasComma(import2)
|
|
275
|
+
? stringHasComma(import1)
|
|
276
|
+
? -1
|
|
277
|
+
: 1
|
|
278
|
+
: import1 > import2
|
|
279
|
+
? 1
|
|
280
|
+
: -1,
|
|
281
|
+
),
|
|
282
|
+
EMPTY_STRING,
|
|
283
|
+
],
|
|
284
|
+
(line) => line.replace('{React}', 'React'),
|
|
285
|
+
// sigh
|
|
286
|
+
);
|
|
149
287
|
const getTypes = () =>
|
|
150
288
|
mapMap(types, ([body, doc], name) => [
|
|
151
289
|
comment(doc),
|
|
152
|
-
|
|
290
|
+
`${EXPORT} type ${name} = ${body};`,
|
|
153
291
|
EMPTY_STRING,
|
|
154
292
|
]);
|
|
155
|
-
const getMethods = (location) =>
|
|
156
|
-
mapMap(methods, ([parameters, returnType, body, doc, generic], name) => {
|
|
157
|
-
const lines = location
|
|
158
|
-
? [`${name}: ${generic}(${parameters}): ${returnType} => ${body},`]
|
|
159
|
-
: [`${name}${generic}(${parameters}): ${returnType};`];
|
|
160
|
-
if (!location) {
|
|
161
|
-
arrayUnshift(lines, comment(doc));
|
|
162
|
-
}
|
|
163
|
-
arrayPush(lines, EMPTY_STRING);
|
|
164
|
-
return lines;
|
|
165
|
-
});
|
|
166
293
|
const getConstants = () =>
|
|
167
294
|
mapMap(constants, (body, name) => {
|
|
168
295
|
body = isArray(body) ? body : [body];
|
|
@@ -173,12 +300,10 @@ const getCodeFunctions = () => {
|
|
|
173
300
|
build,
|
|
174
301
|
addImport,
|
|
175
302
|
addType,
|
|
176
|
-
|
|
177
|
-
addFunction,
|
|
303
|
+
addInternalFunction,
|
|
178
304
|
addConstant,
|
|
179
305
|
getImports,
|
|
180
306
|
getTypes,
|
|
181
|
-
getMethods,
|
|
182
307
|
getConstants,
|
|
183
308
|
];
|
|
184
309
|
};
|
|
@@ -202,182 +327,11 @@ const getCreateFunction = (getFunction) => {
|
|
|
202
327
|
};
|
|
203
328
|
};
|
|
204
329
|
|
|
205
|
-
const
|
|
206
|
-
const A_FUNCTION_FOR = 'A function for';
|
|
207
|
-
const EXPORT = 'export';
|
|
208
|
-
const LISTENER = 'listener';
|
|
209
|
-
const OR_UNDEFINED = ' | undefined';
|
|
210
|
-
const REGISTERS_A_LISTENER = `Registers a ${LISTENER} that will be called`;
|
|
211
|
-
const REPRESENTS = 'Represents';
|
|
212
|
-
const RETURNS_VOID = ' => void';
|
|
213
|
-
const THE_END_OF_THE_TRANSACTION = 'the end of the transaction';
|
|
214
|
-
const THE_SPECIFIED_ROW = 'the specified Row';
|
|
215
|
-
const A_STRING_SERIALIZATION_OF = 'a string serialization of';
|
|
216
|
-
const getTheContentOfDoc = (content = 0, theStore = 0) =>
|
|
217
|
-
`the ${CONTENT[content]}content of${theStore ? ` ${THE_STORE}` : ''}`;
|
|
218
|
-
const getTheContentOfTheStoreDoc = (verb, content = 0, set = 0) =>
|
|
219
|
-
`${VERBS[verb]} ${getTheContentOfDoc(content, 1)}${set ? ' when set' : ''}`;
|
|
220
|
-
const getRowTypeDoc = (tableId, set = 0) =>
|
|
221
|
-
`${REPRESENTS} a Row when ${
|
|
222
|
-
set ? 's' : 'g'
|
|
223
|
-
}etting ${getTheContentOfDoc()} the '${tableId}' Table`;
|
|
224
|
-
const getIdsDoc = (idsNoun, parentNoun, sorted = 0) =>
|
|
225
|
-
`Gets ${
|
|
226
|
-
sorted ? 'sorted, paginated' : 'the'
|
|
227
|
-
} Ids of the ${idsNoun}s in ${parentNoun}`;
|
|
228
|
-
const getForEachDoc = (childNoun, parentNoun) =>
|
|
229
|
-
`Calls a function for each ${childNoun} in ${parentNoun}`;
|
|
230
|
-
const getHasDoc = (childNoun, parentNoun = THE_STORE) =>
|
|
231
|
-
`Gets whether ${childNoun} exists in ${parentNoun}`;
|
|
232
|
-
const getCallbackDoc = (takes) => `A function that takes ${takes}`;
|
|
233
|
-
const getListenerTypeDoc = (childNoun, parentNoun = 0) =>
|
|
234
|
-
`${A_FUNCTION_FOR} listening to changes to ${NOUNS[childNoun]} in ${NOUNS[parentNoun]}`;
|
|
235
|
-
const getListenerDoc = (childNoun, parentNoun, pluralChild = 0) =>
|
|
236
|
-
`${REGISTERS_A_LISTENER} whenever ${childNoun} in ${parentNoun} change` +
|
|
237
|
-
(pluralChild ? EMPTY_STRING : 's');
|
|
238
|
-
const getTableDoc = (tableId) => `the '${tableId}' Table`;
|
|
239
|
-
const getRowDoc = (tableId) =>
|
|
240
|
-
`${THE_SPECIFIED_ROW} in ${getTableDoc(tableId)}`;
|
|
241
|
-
const getCellDoc = (cellId) => `the '${cellId}' Cell`;
|
|
242
|
-
const getValueDoc = (valueId) => `the '${valueId}' Value`;
|
|
243
|
-
const getTableContentDoc = (tableId, verb = 0) =>
|
|
244
|
-
`${VERBS[verb]} ${getTheContentOfDoc()} ${getTableDoc(tableId)}`;
|
|
245
|
-
const getRowContentDoc = (tableId, verb = 0) =>
|
|
246
|
-
`${VERBS[verb]} ${getTheContentOfDoc()} ${getRowDoc(tableId)}`;
|
|
247
|
-
const getCellContentDoc = (tableId, cellId, verb = 0) =>
|
|
248
|
-
`${VERBS[verb]} ${getCellDoc(cellId)} for ${getRowDoc(tableId)}`;
|
|
249
|
-
const getValueContentDoc = (valueId, verb = 0) =>
|
|
250
|
-
`${VERBS[verb]} ${getValueDoc(valueId)}`;
|
|
251
|
-
const VERBS = [
|
|
252
|
-
'Gets',
|
|
253
|
-
'Sets',
|
|
254
|
-
'Sets part of',
|
|
255
|
-
'Deletes',
|
|
256
|
-
REPRESENTS,
|
|
257
|
-
`Gets ${A_STRING_SERIALIZATION_OF}`,
|
|
258
|
-
`Sets ${A_STRING_SERIALIZATION_OF}`,
|
|
259
|
-
`${REGISTERS_A_LISTENER} whenever`,
|
|
260
|
-
];
|
|
261
|
-
const NOUNS = [
|
|
262
|
-
THE_STORE,
|
|
263
|
-
'Tables',
|
|
264
|
-
'Table Ids',
|
|
265
|
-
'a Table',
|
|
266
|
-
'Row Ids',
|
|
267
|
-
'a Row',
|
|
268
|
-
'Cell Ids',
|
|
269
|
-
'a Cell',
|
|
270
|
-
'invalid Cell changes',
|
|
271
|
-
'Values',
|
|
272
|
-
'Value Ids',
|
|
273
|
-
'a Value',
|
|
274
|
-
'invalid Value changes',
|
|
275
|
-
];
|
|
276
|
-
const CONTENT = ['', 'tabular ', 'keyed value '];
|
|
277
|
-
|
|
278
|
-
const COMMON_IMPORTS = ['DoRollback', 'Id', 'IdOrNull', 'Ids', 'Json', 'Store'];
|
|
279
|
-
const storeMethod = (method, parameters = EMPTY_STRING, cast = EMPTY_STRING) =>
|
|
280
|
-
`store.${method}(${parameters})${cast ? ` as ${cast}` : EMPTY_STRING}`;
|
|
281
|
-
const fluentStoreMethod = (method, parameters = EMPTY_STRING) =>
|
|
282
|
-
`fluent(() => ${storeMethod(method, parameters)})`;
|
|
283
|
-
const storeListener = (
|
|
284
|
-
method,
|
|
285
|
-
beforeParameters = EMPTY_STRING,
|
|
286
|
-
afterParameters = EMPTY_STRING,
|
|
287
|
-
) =>
|
|
288
|
-
`store.${method}(${
|
|
289
|
-
beforeParameters ? `${beforeParameters}, ` : EMPTY_STRING
|
|
290
|
-
}proxy(${LISTENER})${
|
|
291
|
-
afterParameters ? `, ${afterParameters}` : EMPTY_STRING
|
|
292
|
-
})`;
|
|
293
|
-
const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
294
|
-
if (objIsEmpty(tablesSchema) && objIsEmpty(valuesSchema)) {
|
|
295
|
-
return pairNew(EMPTY_STRING);
|
|
296
|
-
}
|
|
297
|
-
const [
|
|
298
|
-
build,
|
|
299
|
-
addImport,
|
|
300
|
-
addType,
|
|
301
|
-
addMethod,
|
|
302
|
-
addFunction,
|
|
303
|
-
addConstant,
|
|
304
|
-
getImports,
|
|
305
|
-
getTypes,
|
|
306
|
-
getMethods,
|
|
307
|
-
getConstants,
|
|
308
|
-
] = getCodeFunctions();
|
|
309
|
-
const moduleDefinition = `./${camel(module)}.d`;
|
|
310
|
-
const storeType = camel(module, 1);
|
|
311
|
-
const storeInstance = camel(storeType);
|
|
312
|
-
const createSteps = [];
|
|
313
|
-
const tableTypes = mapNew();
|
|
330
|
+
const getSchemaFunctions = (tablesSchema, valuesSchema, addConstant) => {
|
|
314
331
|
const mapTablesSchema = (callback) =>
|
|
315
332
|
objMap(tablesSchema, (_, tableId) => {
|
|
316
333
|
return callback(
|
|
317
334
|
tableId,
|
|
318
|
-
mapEnsure(tableTypes, tableId, () => {
|
|
319
|
-
const table = camel(tableId, 1);
|
|
320
|
-
return [
|
|
321
|
-
addType(
|
|
322
|
-
`${table}Table`,
|
|
323
|
-
`{[rowId: Id]: ${table}Row}`,
|
|
324
|
-
`${REPRESENTS} the '${tableId}' Table`,
|
|
325
|
-
),
|
|
326
|
-
addType(
|
|
327
|
-
`${table}Row`,
|
|
328
|
-
`{${join(
|
|
329
|
-
mapCellSchema(
|
|
330
|
-
tableId,
|
|
331
|
-
(cellId, type, defaultValue) =>
|
|
332
|
-
`'${cellId}'${
|
|
333
|
-
isUndefined(defaultValue) ? '?' : EMPTY_STRING
|
|
334
|
-
}: ${type};`,
|
|
335
|
-
),
|
|
336
|
-
' ',
|
|
337
|
-
)}}`,
|
|
338
|
-
getRowTypeDoc(tableId),
|
|
339
|
-
),
|
|
340
|
-
addType(
|
|
341
|
-
`${table}RowWhenSet`,
|
|
342
|
-
`{${join(
|
|
343
|
-
mapCellSchema(
|
|
344
|
-
tableId,
|
|
345
|
-
(cellId, type) => `'${cellId}'?: ${type};`,
|
|
346
|
-
),
|
|
347
|
-
' ',
|
|
348
|
-
)}}`,
|
|
349
|
-
getRowTypeDoc(tableId, 1),
|
|
350
|
-
),
|
|
351
|
-
addType(
|
|
352
|
-
`${table}CellId`,
|
|
353
|
-
join(
|
|
354
|
-
mapCellSchema(tableId, (cellId) => `'${cellId}'`),
|
|
355
|
-
' | ',
|
|
356
|
-
),
|
|
357
|
-
`A Cell Id for the '${tableId}' Table`,
|
|
358
|
-
),
|
|
359
|
-
addType(
|
|
360
|
-
`${table}CellCallback`,
|
|
361
|
-
`(...[cellId, cell]: ${join(
|
|
362
|
-
mapCellSchema(
|
|
363
|
-
tableId,
|
|
364
|
-
(cellId, type) => `[cellId: '${cellId}', cell: ${type}]`,
|
|
365
|
-
),
|
|
366
|
-
' | ',
|
|
367
|
-
)})${RETURNS_VOID}`,
|
|
368
|
-
getCallbackDoc(
|
|
369
|
-
`a Cell Id and value from a Row in the '${tableId}' Table`,
|
|
370
|
-
),
|
|
371
|
-
),
|
|
372
|
-
addType(
|
|
373
|
-
`${table}RowCallback`,
|
|
374
|
-
`(rowId: Id, forEachCell: (cellCallback: ${table}CellCallback)${RETURNS_VOID})${RETURNS_VOID}`,
|
|
375
|
-
getCallbackDoc(
|
|
376
|
-
`a Row Id from the '${tableId}' Table, and a Cell iterator`,
|
|
377
|
-
),
|
|
378
|
-
),
|
|
379
|
-
];
|
|
380
|
-
}),
|
|
381
335
|
camel(tableId, 1),
|
|
382
336
|
addConstant(snake(tableId), `'${tableId}'`),
|
|
383
337
|
);
|
|
@@ -402,6 +356,124 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
402
356
|
camel(valueId, 1),
|
|
403
357
|
),
|
|
404
358
|
);
|
|
359
|
+
return [mapTablesSchema, mapCellSchema, mapValuesSchema];
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const METHOD_PREFIX_VERBS = [
|
|
363
|
+
GET,
|
|
364
|
+
'has',
|
|
365
|
+
'set',
|
|
366
|
+
'del',
|
|
367
|
+
'set',
|
|
368
|
+
'forEach',
|
|
369
|
+
ADD,
|
|
370
|
+
EMPTY_STRING,
|
|
371
|
+
];
|
|
372
|
+
const storeMethod = (method, parameters = EMPTY_STRING, cast = EMPTY_STRING) =>
|
|
373
|
+
`store.${method}(${parameters})` + (cast ? ' as ' + cast : EMPTY_STRING);
|
|
374
|
+
const fluentStoreMethod = (method, parameters = EMPTY_STRING) =>
|
|
375
|
+
`fluent(() => ${storeMethod(method, parameters)})`;
|
|
376
|
+
const storeListener = (
|
|
377
|
+
method,
|
|
378
|
+
beforeParameters = EMPTY_STRING,
|
|
379
|
+
afterParameters = EMPTY_STRING,
|
|
380
|
+
) =>
|
|
381
|
+
`store.${method}(${
|
|
382
|
+
beforeParameters ? beforeParameters + ', ' : EMPTY_STRING
|
|
383
|
+
}proxy(listener)${afterParameters ? ', ' + afterParameters : EMPTY_STRING})`;
|
|
384
|
+
const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
385
|
+
const [
|
|
386
|
+
build,
|
|
387
|
+
addImport,
|
|
388
|
+
addType,
|
|
389
|
+
addInternalFunction,
|
|
390
|
+
addConstant,
|
|
391
|
+
getImports,
|
|
392
|
+
getTypes,
|
|
393
|
+
getConstants,
|
|
394
|
+
] = getCodeFunctions();
|
|
395
|
+
const [mapTablesSchema, mapCellSchema, mapValuesSchema] = getSchemaFunctions(
|
|
396
|
+
tablesSchema,
|
|
397
|
+
valuesSchema,
|
|
398
|
+
addConstant,
|
|
399
|
+
);
|
|
400
|
+
const methods = mapNew();
|
|
401
|
+
const getMethods = (location = 0) =>
|
|
402
|
+
mapMap(methods, ([parameters, returnType, body, doc, generic], name) => {
|
|
403
|
+
const lines = location
|
|
404
|
+
? [name + `: ${generic}(${parameters}): ${returnType} => ${body},`]
|
|
405
|
+
: [name + generic + `(${parameters}): ${returnType};`];
|
|
406
|
+
if (!location) {
|
|
407
|
+
arrayUnshift(lines, comment(doc));
|
|
408
|
+
}
|
|
409
|
+
arrayPush(lines, EMPTY_STRING);
|
|
410
|
+
return lines;
|
|
411
|
+
});
|
|
412
|
+
const addMethod = (
|
|
413
|
+
name,
|
|
414
|
+
parameters,
|
|
415
|
+
returnType,
|
|
416
|
+
body,
|
|
417
|
+
doc,
|
|
418
|
+
generic = EMPTY_STRING,
|
|
419
|
+
) => mapUnique(methods, name, [parameters, returnType, body, doc, generic]);
|
|
420
|
+
const addProxyMethod = (
|
|
421
|
+
prefixVerb,
|
|
422
|
+
prefix,
|
|
423
|
+
underlyingName,
|
|
424
|
+
returnType,
|
|
425
|
+
doc,
|
|
426
|
+
params = EMPTY_STRING,
|
|
427
|
+
paramsInCall = EMPTY_STRING,
|
|
428
|
+
generic = EMPTY_STRING,
|
|
429
|
+
) =>
|
|
430
|
+
addMethod(
|
|
431
|
+
METHOD_PREFIX_VERBS[prefixVerb] +
|
|
432
|
+
prefix +
|
|
433
|
+
(prefixVerb == 4 ? PARTIAL : EMPTY_STRING) +
|
|
434
|
+
underlyingName,
|
|
435
|
+
params,
|
|
436
|
+
returnType,
|
|
437
|
+
(returnType == storeType ? fluentStoreMethod : storeMethod)(
|
|
438
|
+
METHOD_PREFIX_VERBS[prefixVerb] +
|
|
439
|
+
(prefixVerb == 4 ? PARTIAL : EMPTY_STRING) +
|
|
440
|
+
underlyingName,
|
|
441
|
+
paramsInCall,
|
|
442
|
+
prefixVerb ? void 0 : returnType,
|
|
443
|
+
),
|
|
444
|
+
doc,
|
|
445
|
+
generic,
|
|
446
|
+
);
|
|
447
|
+
const addProxyListener = (
|
|
448
|
+
underlyingName,
|
|
449
|
+
listenerType,
|
|
450
|
+
doc,
|
|
451
|
+
params = EMPTY_STRING,
|
|
452
|
+
paramsInCall = EMPTY_STRING,
|
|
453
|
+
mutator = 1,
|
|
454
|
+
) =>
|
|
455
|
+
addMethod(
|
|
456
|
+
ADD + underlyingName + LISTENER,
|
|
457
|
+
(params ? params + ', ' : EMPTY_STRING) +
|
|
458
|
+
LISTENER_ +
|
|
459
|
+
': ' +
|
|
460
|
+
listenerType +
|
|
461
|
+
(mutator ? ', mutator?: boolean' : EMPTY_STRING),
|
|
462
|
+
ID,
|
|
463
|
+
storeListener(
|
|
464
|
+
ADD + underlyingName + LISTENER,
|
|
465
|
+
paramsInCall,
|
|
466
|
+
mutator ? 'mutator' : EMPTY_STRING,
|
|
467
|
+
),
|
|
468
|
+
doc,
|
|
469
|
+
);
|
|
470
|
+
const moduleDefinition = `./${camel(module)}.d`;
|
|
471
|
+
const storeType = camel(module, 1);
|
|
472
|
+
const storeInstance = camel(storeType);
|
|
473
|
+
const createSteps = [];
|
|
474
|
+
const mapCellOrValueTypes = mapNew();
|
|
475
|
+
let sharedTableTypes = [];
|
|
476
|
+
let sharedValueTypes = [];
|
|
405
477
|
addImport(
|
|
406
478
|
1,
|
|
407
479
|
moduleDefinition,
|
|
@@ -409,80 +481,171 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
409
481
|
`create${storeType} as create${storeType}Decl`,
|
|
410
482
|
);
|
|
411
483
|
if (!objIsEmpty(tablesSchema)) {
|
|
484
|
+
const tablesTypes = mapNew();
|
|
485
|
+
mapTablesSchema((tableId, tableName) => {
|
|
486
|
+
const tableTypes = [
|
|
487
|
+
addType(
|
|
488
|
+
tableName + TABLE,
|
|
489
|
+
`{[rowId: Id]: ${tableName}Row}`,
|
|
490
|
+
REPRESENTS + ` the '${tableId}' ` + TABLE,
|
|
491
|
+
),
|
|
492
|
+
addType(
|
|
493
|
+
tableName + ROW,
|
|
494
|
+
`{${join(
|
|
495
|
+
mapCellSchema(
|
|
496
|
+
tableId,
|
|
497
|
+
(cellId, type, defaultValue) =>
|
|
498
|
+
`'${cellId}'${
|
|
499
|
+
isUndefined(defaultValue) ? '?' : EMPTY_STRING
|
|
500
|
+
}: ${type};`,
|
|
501
|
+
),
|
|
502
|
+
' ',
|
|
503
|
+
)}}`,
|
|
504
|
+
getRowTypeDoc(tableId),
|
|
505
|
+
),
|
|
506
|
+
addType(
|
|
507
|
+
tableName + ROW + 'WhenSet',
|
|
508
|
+
`{${join(
|
|
509
|
+
mapCellSchema(tableId, (cellId, type) => `'${cellId}'?: ${type};`),
|
|
510
|
+
' ',
|
|
511
|
+
)}}`,
|
|
512
|
+
getRowTypeDoc(tableId, 1),
|
|
513
|
+
),
|
|
514
|
+
addType(
|
|
515
|
+
tableName + CELL + ID,
|
|
516
|
+
join(
|
|
517
|
+
mapCellSchema(tableId, (cellId) => `'${cellId}'`),
|
|
518
|
+
' | ',
|
|
519
|
+
),
|
|
520
|
+
`A Cell Id for the '${tableId}' ` + TABLE,
|
|
521
|
+
),
|
|
522
|
+
addType(
|
|
523
|
+
tableName + CELL + CALLBACK,
|
|
524
|
+
`(...[cellId, cell]: ${join(
|
|
525
|
+
mapCellSchema(
|
|
526
|
+
tableId,
|
|
527
|
+
(cellId, type) => `[cellId: '${cellId}', cell: ${type}]`,
|
|
528
|
+
),
|
|
529
|
+
' | ',
|
|
530
|
+
)})` + RETURNS_VOID,
|
|
531
|
+
getCallbackDoc(
|
|
532
|
+
`a Cell Id and value from a Row in the '${tableId}' ` + TABLE,
|
|
533
|
+
),
|
|
534
|
+
),
|
|
535
|
+
addType(
|
|
536
|
+
tableName + ROW + CALLBACK,
|
|
537
|
+
`(rowId: Id, forEachCell: (cellCallback: ${tableName}CellCallback)` +
|
|
538
|
+
RETURNS_VOID +
|
|
539
|
+
')' +
|
|
540
|
+
RETURNS_VOID,
|
|
541
|
+
getCallbackDoc(
|
|
542
|
+
`a Row Id from the '${tableId}' Table, and a Cell iterator`,
|
|
543
|
+
),
|
|
544
|
+
),
|
|
545
|
+
];
|
|
546
|
+
mapSet(tablesTypes, tableId, tableTypes);
|
|
547
|
+
addImport(1, moduleDefinition, ...tableTypes);
|
|
548
|
+
});
|
|
549
|
+
addImport(null, 'tinybase', IDS);
|
|
412
550
|
const tablesType = addType(
|
|
413
|
-
|
|
551
|
+
TABLES,
|
|
414
552
|
`{${join(
|
|
415
553
|
mapTablesSchema(
|
|
416
|
-
(tableId
|
|
554
|
+
(tableId) => `'${tableId}'?: ${mapGet(tablesTypes, tableId)?.[0]};`,
|
|
417
555
|
),
|
|
418
556
|
' ',
|
|
419
557
|
)}}`,
|
|
420
|
-
getTheContentOfTheStoreDoc(
|
|
558
|
+
getTheContentOfTheStoreDoc(1, 5),
|
|
421
559
|
);
|
|
422
560
|
const tableIdType = addType(
|
|
423
|
-
|
|
561
|
+
TABLE + ID,
|
|
424
562
|
join(
|
|
425
563
|
mapTablesSchema((tableId) => `'${tableId}'`),
|
|
426
564
|
' | ',
|
|
427
565
|
),
|
|
428
|
-
|
|
566
|
+
'A ' + TABLE + ' Id in ' + THE_STORE,
|
|
429
567
|
);
|
|
430
568
|
const tableCallbackType = addType(
|
|
431
|
-
|
|
569
|
+
TABLE + CALLBACK,
|
|
432
570
|
`(...[tableId, rowCallback]: ${join(
|
|
433
571
|
mapTablesSchema(
|
|
434
|
-
(tableId
|
|
435
|
-
`[tableId: '${tableId}', forEachRow: (rowCallback: ${
|
|
572
|
+
(tableId) =>
|
|
573
|
+
`[tableId: '${tableId}', forEachRow: (rowCallback: ${
|
|
574
|
+
mapGet(tablesTypes, tableId)?.[5]
|
|
575
|
+
})${RETURNS_VOID}]`,
|
|
436
576
|
),
|
|
437
577
|
' | ',
|
|
438
|
-
)})
|
|
439
|
-
getCallbackDoc('
|
|
578
|
+
)})` + RETURNS_VOID,
|
|
579
|
+
getCallbackDoc(A + TABLE + ' Id, and a Row iterator'),
|
|
440
580
|
);
|
|
441
581
|
const getCellChangeType = addType(
|
|
442
582
|
'GetCellChange',
|
|
443
583
|
`(...[tableId, rowId, cellId]: ${join(
|
|
444
584
|
mapTablesSchema(
|
|
445
|
-
(tableId
|
|
446
|
-
`[tableId: '${tableId}', rowId: Id, cellId: ${
|
|
585
|
+
(tableId) =>
|
|
586
|
+
`[tableId: '${tableId}', rowId: Id, cellId: ${
|
|
587
|
+
mapGet(tablesTypes, tableId)?.[3]
|
|
588
|
+
}]`,
|
|
447
589
|
),
|
|
448
590
|
' | ',
|
|
449
591
|
)}) => CellChange`,
|
|
450
|
-
|
|
592
|
+
A_FUNCTION_FOR +
|
|
593
|
+
` returning information about any Cell's changes during a ` +
|
|
594
|
+
TRANSACTION_,
|
|
451
595
|
);
|
|
452
596
|
const tablesListenerType = addType(
|
|
453
|
-
|
|
454
|
-
`(${storeInstance}: ${storeType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})
|
|
597
|
+
TABLES + LISTENER,
|
|
598
|
+
`(${storeInstance}: ${storeType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
599
|
+
RETURNS_VOID,
|
|
455
600
|
getListenerTypeDoc(1),
|
|
456
601
|
);
|
|
457
602
|
const tableIdsListenerType = addType(
|
|
458
|
-
|
|
459
|
-
`(${storeInstance}: ${storeType})
|
|
603
|
+
TABLE_IDS + LISTENER,
|
|
604
|
+
`(${storeInstance}: ${storeType})` + RETURNS_VOID,
|
|
460
605
|
getListenerTypeDoc(2),
|
|
461
606
|
);
|
|
462
607
|
const tableListenerType = addType(
|
|
463
|
-
|
|
464
|
-
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})
|
|
608
|
+
TABLE + LISTENER,
|
|
609
|
+
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
610
|
+
RETURNS_VOID,
|
|
465
611
|
getListenerTypeDoc(3),
|
|
466
612
|
);
|
|
467
613
|
const rowIdsListenerType = addType(
|
|
468
|
-
|
|
614
|
+
ROW_IDS + LISTENER,
|
|
469
615
|
`(${storeInstance}: ${storeType}, tableId: ${tableIdType})` +
|
|
470
616
|
RETURNS_VOID,
|
|
471
617
|
getListenerTypeDoc(4, 3),
|
|
472
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
|
+
);
|
|
473
635
|
const rowListenerType = addType(
|
|
474
|
-
|
|
475
|
-
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, rowId: Id, getCellChange: ${getCellChangeType}${OR_UNDEFINED})
|
|
636
|
+
ROW + LISTENER,
|
|
637
|
+
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, rowId: Id, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
|
|
638
|
+
RETURNS_VOID,
|
|
476
639
|
getListenerTypeDoc(5, 3),
|
|
477
640
|
);
|
|
478
641
|
const cellIdsListenerType = addType(
|
|
479
|
-
|
|
642
|
+
CELL_IDS + LISTENER,
|
|
480
643
|
`(${storeInstance}: ${storeType}, tableId: ${tableIdType}, rowId: Id)` +
|
|
481
644
|
RETURNS_VOID,
|
|
482
645
|
getListenerTypeDoc(6, 5),
|
|
483
646
|
);
|
|
484
647
|
const cellListenerType = addType(
|
|
485
|
-
|
|
648
|
+
CELL + LISTENER,
|
|
486
649
|
`(...[${storeInstance}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${join(
|
|
487
650
|
flat(
|
|
488
651
|
mapTablesSchema((tableId) =>
|
|
@@ -494,319 +657,279 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
494
657
|
),
|
|
495
658
|
),
|
|
496
659
|
' | ',
|
|
497
|
-
)})
|
|
660
|
+
)})` + RETURNS_VOID,
|
|
498
661
|
getListenerTypeDoc(7, 5),
|
|
499
662
|
);
|
|
500
663
|
const invalidCellListenerType = addType(
|
|
501
|
-
|
|
502
|
-
`(${storeInstance}: ${storeType}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])
|
|
664
|
+
INVALID + CELL + LISTENER,
|
|
665
|
+
`(${storeInstance}: ${storeType}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])` +
|
|
666
|
+
RETURNS_VOID,
|
|
503
667
|
getListenerTypeDoc(8),
|
|
504
668
|
);
|
|
505
|
-
|
|
506
|
-
`hasTables`,
|
|
507
|
-
EMPTY_STRING,
|
|
508
|
-
BOOLEAN,
|
|
509
|
-
storeMethod('hasTables'),
|
|
510
|
-
getHasDoc('any Table'),
|
|
511
|
-
);
|
|
512
|
-
addMethod(
|
|
513
|
-
`getTables`,
|
|
514
|
-
EMPTY_STRING,
|
|
669
|
+
sharedTableTypes = [
|
|
515
670
|
tablesType,
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
671
|
+
tableIdType,
|
|
672
|
+
tablesListenerType,
|
|
673
|
+
tableIdsListenerType,
|
|
674
|
+
tableListenerType,
|
|
675
|
+
rowIdsListenerType,
|
|
676
|
+
sortedRowIdsListenerType,
|
|
677
|
+
rowListenerType,
|
|
678
|
+
cellIdsListenerType,
|
|
679
|
+
cellListenerType,
|
|
680
|
+
tablesTypes,
|
|
681
|
+
];
|
|
682
|
+
arrayForEach(
|
|
683
|
+
[
|
|
684
|
+
[tablesType],
|
|
685
|
+
[BOOLEAN],
|
|
686
|
+
[storeType, 'tables: ' + tablesType, 'tables'],
|
|
687
|
+
[storeType],
|
|
688
|
+
],
|
|
689
|
+
([returnType, params, paramsInCall], verb) =>
|
|
690
|
+
addProxyMethod(
|
|
691
|
+
verb,
|
|
692
|
+
EMPTY_STRING,
|
|
693
|
+
TABLES,
|
|
694
|
+
returnType,
|
|
695
|
+
getTheContentOfTheStoreDoc(1, verb),
|
|
696
|
+
params,
|
|
697
|
+
paramsInCall,
|
|
698
|
+
),
|
|
525
699
|
);
|
|
526
|
-
|
|
527
|
-
|
|
700
|
+
addProxyMethod(
|
|
701
|
+
0,
|
|
528
702
|
EMPTY_STRING,
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
703
|
+
TABLE_IDS,
|
|
704
|
+
tableIdType + SQUARE_BRACKETS,
|
|
705
|
+
getIdsDoc(TABLE, THE_STORE),
|
|
532
706
|
);
|
|
533
|
-
|
|
534
|
-
|
|
707
|
+
addProxyMethod(
|
|
708
|
+
5,
|
|
535
709
|
EMPTY_STRING,
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
710
|
+
TABLE,
|
|
711
|
+
VOID,
|
|
712
|
+
getForEachDoc(TABLE, THE_STORE),
|
|
713
|
+
'tableCallback: ' + tableCallbackType,
|
|
714
|
+
'tableCallback as any',
|
|
539
715
|
);
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
(
|
|
550
|
-
tableId,
|
|
716
|
+
mapTablesSchema((tableId, tableName, TABLE_ID) => {
|
|
717
|
+
const [
|
|
718
|
+
tableType,
|
|
719
|
+
rowType,
|
|
720
|
+
rowWhenSetType,
|
|
721
|
+
cellIdType,
|
|
722
|
+
cellCallbackType,
|
|
723
|
+
rowCallbackType,
|
|
724
|
+
] = mapGet(tablesTypes, tableId);
|
|
725
|
+
arrayForEach(
|
|
551
726
|
[
|
|
552
|
-
tableType,
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
cellCallbackType,
|
|
557
|
-
rowCallbackType,
|
|
727
|
+
[tableType],
|
|
728
|
+
[BOOLEAN],
|
|
729
|
+
[storeType, 'table: ' + tableType, ', table'],
|
|
730
|
+
[storeType],
|
|
558
731
|
],
|
|
732
|
+
([returnType, params, paramsInCall = EMPTY_STRING], verb) =>
|
|
733
|
+
addProxyMethod(
|
|
734
|
+
verb,
|
|
735
|
+
tableName,
|
|
736
|
+
TABLE,
|
|
737
|
+
returnType,
|
|
738
|
+
getTableContentDoc(tableId, verb),
|
|
739
|
+
params,
|
|
740
|
+
TABLE_ID + paramsInCall,
|
|
741
|
+
),
|
|
742
|
+
);
|
|
743
|
+
addProxyMethod(
|
|
744
|
+
0,
|
|
559
745
|
tableName,
|
|
746
|
+
ROW_IDS,
|
|
747
|
+
IDS,
|
|
748
|
+
getIdsDoc(ROW, getTableDoc(tableId)),
|
|
749
|
+
EMPTY_STRING,
|
|
560
750
|
TABLE_ID,
|
|
561
|
-
)
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
)
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
EMPTY_STRING,
|
|
603
|
-
'Ids',
|
|
604
|
-
storeMethod('getRowIds', TABLE_ID),
|
|
605
|
-
getIdsDoc('Row', getTableDoc(tableId)),
|
|
606
|
-
);
|
|
607
|
-
addMethod(
|
|
608
|
-
`get${tableName}SortedRowIds`,
|
|
609
|
-
`cellId?: ${cellIdType}, descending?: boolean, offset?: number, limit?: number`,
|
|
610
|
-
'Ids',
|
|
611
|
-
storeMethod(
|
|
612
|
-
'getSortedRowIds',
|
|
613
|
-
`${TABLE_ID}, cellId, descending, offset, limit`,
|
|
751
|
+
);
|
|
752
|
+
addProxyMethod(
|
|
753
|
+
0,
|
|
754
|
+
tableName,
|
|
755
|
+
SORTED_ROW_IDS,
|
|
756
|
+
IDS,
|
|
757
|
+
getIdsDoc(ROW, getTableDoc(tableId), 1),
|
|
758
|
+
'cellId?: ' +
|
|
759
|
+
cellIdType +
|
|
760
|
+
', descending?: boolean, offset?: number, limit?: number',
|
|
761
|
+
TABLE_ID + ', cellId, descending, offset, limit',
|
|
762
|
+
);
|
|
763
|
+
addProxyMethod(
|
|
764
|
+
5,
|
|
765
|
+
tableName,
|
|
766
|
+
ROW,
|
|
767
|
+
VOID,
|
|
768
|
+
getForEachDoc(ROW, getTableDoc(tableId)),
|
|
769
|
+
'rowCallback: ' + rowCallbackType,
|
|
770
|
+
TABLE_ID + ', rowCallback as any',
|
|
771
|
+
);
|
|
772
|
+
arrayForEach(
|
|
773
|
+
[
|
|
774
|
+
[rowType],
|
|
775
|
+
[BOOLEAN],
|
|
776
|
+
[storeType, ', row: ' + rowWhenSetType, ', row'],
|
|
777
|
+
[storeType],
|
|
778
|
+
[storeType, ', partialRow: ' + rowWhenSetType, ', partialRow'],
|
|
779
|
+
],
|
|
780
|
+
(
|
|
781
|
+
[returnType, params = EMPTY_STRING, paramsInCall = EMPTY_STRING],
|
|
782
|
+
verb,
|
|
783
|
+
) =>
|
|
784
|
+
addProxyMethod(
|
|
785
|
+
verb,
|
|
786
|
+
tableName,
|
|
787
|
+
ROW,
|
|
788
|
+
returnType,
|
|
789
|
+
getRowContentDoc(tableId, verb),
|
|
790
|
+
'rowId: Id' + params,
|
|
791
|
+
TABLE_ID + ', rowId' + paramsInCall,
|
|
614
792
|
),
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
)
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
`${cellIdType}[]`,
|
|
670
|
-
storeMethod('getCellIds', `${TABLE_ID}, rowId`, `${cellIdType}[]`),
|
|
671
|
-
getIdsDoc('Cell', getRowDoc(tableId)),
|
|
672
|
-
);
|
|
673
|
-
addMethod(
|
|
674
|
-
`forEach${tableName}Cell`,
|
|
675
|
-
`rowId: Id, cellCallback: ${cellCallbackType}`,
|
|
676
|
-
'void',
|
|
677
|
-
storeMethod('forEachCell', `${TABLE_ID}, rowId, cellCallback as any`),
|
|
678
|
-
getForEachDoc('Cell', getRowDoc(tableId)),
|
|
679
|
-
);
|
|
680
|
-
mapCellSchema(
|
|
681
|
-
tableId,
|
|
682
|
-
(cellId, type, defaultValue, CELL_ID, cellName) => {
|
|
683
|
-
const mapCellType = `Map${camel(type, 1)}`;
|
|
684
|
-
mapSet(mapCellTypes, type, mapCellType);
|
|
685
|
-
addMethod(
|
|
686
|
-
`has${tableName}${cellName}Cell`,
|
|
687
|
-
'rowId: Id',
|
|
688
|
-
BOOLEAN,
|
|
689
|
-
storeMethod('hasCell', `${TABLE_ID}, rowId, ${CELL_ID}`),
|
|
690
|
-
getHasDoc(getCellDoc(cellId), getRowDoc(tableId)),
|
|
691
|
-
);
|
|
692
|
-
const returnCellType = `${type}${
|
|
693
|
-
isUndefined(defaultValue) ? OR_UNDEFINED : EMPTY_STRING
|
|
694
|
-
}`;
|
|
695
|
-
addMethod(
|
|
696
|
-
`get${tableName}${cellName}Cell`,
|
|
697
|
-
'rowId: Id',
|
|
698
|
-
returnCellType,
|
|
699
|
-
storeMethod(
|
|
700
|
-
'getCell',
|
|
701
|
-
`${TABLE_ID}, rowId, ${CELL_ID}`,
|
|
702
|
-
returnCellType,
|
|
703
|
-
),
|
|
704
|
-
getCellContentDoc(tableId, cellId),
|
|
705
|
-
);
|
|
706
|
-
addMethod(
|
|
707
|
-
`set${tableName}${cellName}Cell`,
|
|
708
|
-
`rowId: Id, cell: ${type} | ${mapCellType}`,
|
|
709
|
-
storeType,
|
|
710
|
-
fluentStoreMethod(
|
|
711
|
-
'setCell',
|
|
712
|
-
`${TABLE_ID}, rowId, ${CELL_ID}, cell as any`,
|
|
793
|
+
);
|
|
794
|
+
addProxyMethod(
|
|
795
|
+
6,
|
|
796
|
+
tableName,
|
|
797
|
+
ROW,
|
|
798
|
+
ID + OR_UNDEFINED,
|
|
799
|
+
'Adds a new Row to ' + getTableDoc(tableId),
|
|
800
|
+
'row: ' + rowWhenSetType,
|
|
801
|
+
TABLE_ID + ', row',
|
|
802
|
+
);
|
|
803
|
+
addProxyMethod(
|
|
804
|
+
0,
|
|
805
|
+
tableName,
|
|
806
|
+
CELL_IDS,
|
|
807
|
+
cellIdType + SQUARE_BRACKETS,
|
|
808
|
+
getIdsDoc(CELL, getRowDoc(tableId)),
|
|
809
|
+
'rowId: ' + ID,
|
|
810
|
+
TABLE_ID + ', rowId',
|
|
811
|
+
);
|
|
812
|
+
addProxyMethod(
|
|
813
|
+
5,
|
|
814
|
+
tableName,
|
|
815
|
+
CELL,
|
|
816
|
+
VOID,
|
|
817
|
+
getForEachDoc(CELL, getRowDoc(tableId)),
|
|
818
|
+
'rowId: Id, cellCallback: ' + cellCallbackType,
|
|
819
|
+
TABLE_ID + ', rowId, cellCallback as any',
|
|
820
|
+
);
|
|
821
|
+
mapCellSchema(
|
|
822
|
+
tableId,
|
|
823
|
+
(cellId, type, defaultValue, CELL_ID, cellName) => {
|
|
824
|
+
const mapCellType = 'Map' + camel(type, 1);
|
|
825
|
+
mapSet(mapCellOrValueTypes, type, mapCellType);
|
|
826
|
+
const returnCellType =
|
|
827
|
+
type + (isUndefined(defaultValue) ? OR_UNDEFINED : EMPTY_STRING);
|
|
828
|
+
arrayForEach(
|
|
829
|
+
[
|
|
830
|
+
[returnCellType],
|
|
831
|
+
[BOOLEAN],
|
|
832
|
+
[storeType, `, cell: ${type} | ` + mapCellType, ', cell as any'],
|
|
833
|
+
[storeType],
|
|
834
|
+
],
|
|
835
|
+
(
|
|
836
|
+
[returnType, params = EMPTY_STRING, paramsInCall = EMPTY_STRING],
|
|
837
|
+
verb,
|
|
838
|
+
) =>
|
|
839
|
+
addProxyMethod(
|
|
840
|
+
verb,
|
|
841
|
+
tableName + cellName,
|
|
842
|
+
CELL,
|
|
843
|
+
returnType,
|
|
844
|
+
getCellContentDoc(tableId, cellId, verb),
|
|
845
|
+
'rowId: Id' + params,
|
|
846
|
+
TABLE_ID + ', rowId, ' + CELL_ID + paramsInCall,
|
|
713
847
|
),
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
fluentStoreMethod('delCell', `${TABLE_ID}, rowId, ${CELL_ID}`),
|
|
721
|
-
getCellContentDoc(tableId, cellId, 3),
|
|
722
|
-
);
|
|
723
|
-
},
|
|
724
|
-
);
|
|
725
|
-
},
|
|
726
|
-
);
|
|
727
|
-
addMethod(
|
|
728
|
-
'getTablesJson',
|
|
848
|
+
);
|
|
849
|
+
},
|
|
850
|
+
);
|
|
851
|
+
});
|
|
852
|
+
addProxyMethod(
|
|
853
|
+
0,
|
|
729
854
|
EMPTY_STRING,
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
getTheContentOfTheStoreDoc(
|
|
855
|
+
TABLES + JSON$1,
|
|
856
|
+
JSON$1,
|
|
857
|
+
getTheContentOfTheStoreDoc(1, 6),
|
|
733
858
|
);
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
859
|
+
addProxyMethod(
|
|
860
|
+
2,
|
|
861
|
+
EMPTY_STRING,
|
|
862
|
+
TABLES + JSON$1,
|
|
737
863
|
storeType,
|
|
738
|
-
|
|
739
|
-
|
|
864
|
+
getTheContentOfTheStoreDoc(1, 7),
|
|
865
|
+
'tablesJson: ' + JSON$1,
|
|
866
|
+
'tables' + JSON$1,
|
|
740
867
|
);
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
'
|
|
745
|
-
storeListener('addTablesListener', EMPTY_STRING, 'mutator'),
|
|
746
|
-
getTheContentOfTheStoreDoc(7, 1) + ' changes',
|
|
868
|
+
addProxyListener(
|
|
869
|
+
TABLES,
|
|
870
|
+
tablesListenerType,
|
|
871
|
+
getTheContentOfTheStoreDoc(1, 8) + ' changes',
|
|
747
872
|
);
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
873
|
+
addProxyListener(TABLE_IDS, tableIdsListenerType, getListenerDoc(2, 0, 1));
|
|
874
|
+
addProxyListener(
|
|
875
|
+
TABLE,
|
|
876
|
+
tableListenerType,
|
|
877
|
+
getListenerDoc(3, 0),
|
|
878
|
+
`tableId: ${tableIdType} | null`,
|
|
879
|
+
'tableId',
|
|
754
880
|
);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
881
|
+
addProxyListener(
|
|
882
|
+
ROW_IDS,
|
|
883
|
+
rowIdsListenerType,
|
|
884
|
+
getListenerDoc(4, 3, 1),
|
|
885
|
+
`tableId: ${tableIdType} | null`,
|
|
886
|
+
'tableId',
|
|
761
887
|
);
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
888
|
+
addProxyListener(
|
|
889
|
+
SORTED_ROW_IDS,
|
|
890
|
+
sortedRowIdsListenerType,
|
|
891
|
+
getListenerDoc(13, 3, 1),
|
|
892
|
+
getParameterList(
|
|
893
|
+
'tableId: ' + tableIdType,
|
|
894
|
+
'cellId: Id' + OR_UNDEFINED,
|
|
895
|
+
'descending: boolean',
|
|
896
|
+
'offset: number',
|
|
897
|
+
'limit: number' + OR_UNDEFINED,
|
|
898
|
+
),
|
|
899
|
+
getParameterList('tableId', 'cellId', 'descending', 'offset', 'limit'),
|
|
768
900
|
);
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
901
|
+
addProxyListener(
|
|
902
|
+
ROW,
|
|
903
|
+
rowListenerType,
|
|
904
|
+
getListenerDoc(5, 3),
|
|
905
|
+
`tableId: ${tableIdType} | null, rowId: IdOrNull`,
|
|
906
|
+
'tableId, rowId',
|
|
775
907
|
);
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
908
|
+
addProxyListener(
|
|
909
|
+
CELL_IDS,
|
|
910
|
+
cellIdsListenerType,
|
|
911
|
+
getListenerDoc(6, 5, 1),
|
|
912
|
+
`tableId: ${tableIdType} | null, rowId: IdOrNull`,
|
|
913
|
+
'tableId, rowId',
|
|
782
914
|
);
|
|
783
|
-
|
|
784
|
-
|
|
915
|
+
addProxyListener(
|
|
916
|
+
CELL,
|
|
917
|
+
cellListenerType,
|
|
918
|
+
getListenerDoc(7, 5),
|
|
785
919
|
`tableId: ${tableIdType} | null, rowId: IdOrNull, cellId: ${join(
|
|
786
|
-
mapTablesSchema(
|
|
920
|
+
mapTablesSchema(
|
|
921
|
+
(tableId) => mapGet(tablesTypes, tableId)?.[3] ?? EMPTY_STRING,
|
|
922
|
+
),
|
|
787
923
|
' | ',
|
|
788
|
-
)} | null
|
|
789
|
-
'
|
|
790
|
-
storeListener('addCellListener', 'tableId, rowId, cellId', 'mutator'),
|
|
791
|
-
getListenerDoc('a Cell', 'a Row'),
|
|
792
|
-
);
|
|
793
|
-
addMethod(
|
|
794
|
-
'addInvalidCellListener',
|
|
795
|
-
`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${LISTENER}: ${invalidCellListenerType}, mutator?: boolean`,
|
|
796
|
-
'Id',
|
|
797
|
-
storeListener(
|
|
798
|
-
'addInvalidCellListener',
|
|
799
|
-
'tableId, rowId, cellId',
|
|
800
|
-
'mutator',
|
|
801
|
-
),
|
|
802
|
-
`${REGISTERS_A_LISTENER} whenever an invalid Cell change was attempted`,
|
|
924
|
+
)} | null`,
|
|
925
|
+
'tableId, rowId, cellId',
|
|
803
926
|
);
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
927
|
+
addProxyListener(
|
|
928
|
+
INVALID + CELL,
|
|
929
|
+
invalidCellListenerType,
|
|
930
|
+
REGISTERS_A_LISTENER + ' whenever an invalid Cell change was attempted',
|
|
931
|
+
`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull`,
|
|
932
|
+
'tableId, rowId, cellId',
|
|
810
933
|
);
|
|
811
934
|
addImport(
|
|
812
935
|
1,
|
|
@@ -818,18 +941,19 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
818
941
|
tableIdsListenerType,
|
|
819
942
|
tableListenerType,
|
|
820
943
|
rowIdsListenerType,
|
|
944
|
+
sortedRowIdsListenerType,
|
|
821
945
|
rowListenerType,
|
|
822
946
|
cellIdsListenerType,
|
|
823
947
|
cellListenerType,
|
|
824
948
|
invalidCellListenerType,
|
|
825
|
-
...collValues(
|
|
949
|
+
...collValues(mapCellOrValueTypes),
|
|
826
950
|
);
|
|
827
951
|
addImport(0, 'tinybase', 'CellChange');
|
|
828
952
|
arrayPush(
|
|
829
953
|
createSteps,
|
|
830
954
|
'.setTablesSchema({',
|
|
831
955
|
flat(
|
|
832
|
-
mapTablesSchema((tableId, _,
|
|
956
|
+
mapTablesSchema((tableId, _, TABLE_ID) => [
|
|
833
957
|
`[${TABLE_ID}]: {`,
|
|
834
958
|
...mapCellSchema(
|
|
835
959
|
tableId,
|
|
@@ -840,11 +964,10 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
840
964
|
)}]: ${addConstant(snake(type), `'${type}'`)}${
|
|
841
965
|
isUndefined(defaultValue)
|
|
842
966
|
? EMPTY_STRING
|
|
843
|
-
: `, [${addConstant(snake(DEFAULT), `'${DEFAULT}'`)}]:
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
}`
|
|
967
|
+
: `, [${addConstant(snake(DEFAULT), `'${DEFAULT}'`)}]: ` +
|
|
968
|
+
(isString(defaultValue)
|
|
969
|
+
? addConstant(snake(defaultValue), `'${defaultValue}'`)
|
|
970
|
+
: defaultValue)
|
|
848
971
|
}},`,
|
|
849
972
|
),
|
|
850
973
|
`},`,
|
|
@@ -855,207 +978,196 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
855
978
|
}
|
|
856
979
|
if (!objIsEmpty(valuesSchema)) {
|
|
857
980
|
const valuesType = addType(
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
(
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
981
|
+
VALUES,
|
|
982
|
+
'{' +
|
|
983
|
+
join(
|
|
984
|
+
mapValuesSchema(
|
|
985
|
+
(valueId, type, defaultValue) =>
|
|
986
|
+
`'${valueId}'${
|
|
987
|
+
isUndefined(defaultValue) ? '?' : EMPTY_STRING
|
|
988
|
+
}: ${type};`,
|
|
989
|
+
),
|
|
990
|
+
' ',
|
|
991
|
+
) +
|
|
992
|
+
'}',
|
|
993
|
+
getTheContentOfTheStoreDoc(2, 5),
|
|
869
994
|
);
|
|
870
995
|
const valuesWhenSetType = addType(
|
|
871
|
-
'
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
996
|
+
VALUES + 'WhenSet',
|
|
997
|
+
'{' +
|
|
998
|
+
join(
|
|
999
|
+
mapValuesSchema((valueId, type) => `'${valueId}'?: ${type};`),
|
|
1000
|
+
' ',
|
|
1001
|
+
) +
|
|
1002
|
+
'}',
|
|
1003
|
+
getTheContentOfTheStoreDoc(2, 5, 1),
|
|
877
1004
|
);
|
|
878
1005
|
const valueIdType = addType(
|
|
879
|
-
|
|
1006
|
+
VALUE + ID,
|
|
880
1007
|
join(
|
|
881
1008
|
mapValuesSchema((valueId) => `'${valueId}'`),
|
|
882
1009
|
' | ',
|
|
883
1010
|
),
|
|
884
|
-
|
|
1011
|
+
'A Value Id in ' + THE_STORE,
|
|
885
1012
|
);
|
|
886
1013
|
const valueCallbackType = addType(
|
|
887
|
-
|
|
1014
|
+
VALUE + CALLBACK,
|
|
888
1015
|
`(...[valueId, rowCallback]: ${join(
|
|
889
1016
|
mapValuesSchema(
|
|
890
1017
|
(valueId, type) => `[valueId: '${valueId}', value: ${type}]`,
|
|
891
1018
|
),
|
|
892
1019
|
' | ',
|
|
893
|
-
)})
|
|
1020
|
+
)})` + RETURNS_VOID,
|
|
894
1021
|
getCallbackDoc('a Value Id, and value'),
|
|
895
1022
|
);
|
|
896
1023
|
const getValueChangeType = addType(
|
|
897
1024
|
'GetValueChange',
|
|
898
1025
|
`(valueId: ${valueIdType}) => ValueChange`,
|
|
899
|
-
|
|
1026
|
+
A_FUNCTION_FOR +
|
|
1027
|
+
` returning information about any Value's changes during a ` +
|
|
1028
|
+
TRANSACTION_,
|
|
900
1029
|
);
|
|
901
1030
|
const valuesListenerType = addType(
|
|
902
|
-
|
|
1031
|
+
VALUES + LISTENER,
|
|
903
1032
|
`(${storeInstance}: ${storeType}, getValueChange: ${getValueChangeType}${OR_UNDEFINED})` +
|
|
904
1033
|
RETURNS_VOID,
|
|
905
1034
|
getListenerTypeDoc(9),
|
|
906
1035
|
);
|
|
907
1036
|
const valueIdsListenerType = addType(
|
|
908
|
-
|
|
909
|
-
`(${storeInstance}: ${storeType})
|
|
1037
|
+
VALUE_IDS + LISTENER,
|
|
1038
|
+
`(${storeInstance}: ${storeType})` + RETURNS_VOID,
|
|
910
1039
|
getListenerTypeDoc(10),
|
|
911
1040
|
);
|
|
912
1041
|
const valueListenerType = addType(
|
|
913
|
-
|
|
1042
|
+
VALUE + LISTENER,
|
|
914
1043
|
`(...[${storeInstance}, valueId, newValue, oldValue, getValueChange]: ${join(
|
|
915
1044
|
mapValuesSchema(
|
|
916
1045
|
(valueId, type) =>
|
|
917
1046
|
`[${storeInstance}: ${storeType}, valueId: '${valueId}', newValue: ${type}${OR_UNDEFINED}, oldValue: ${type}${OR_UNDEFINED}, getValueChange: ${getValueChangeType} | undefined]`,
|
|
918
1047
|
),
|
|
919
1048
|
' | ',
|
|
920
|
-
)})
|
|
1049
|
+
)})` + RETURNS_VOID,
|
|
921
1050
|
getListenerTypeDoc(11),
|
|
922
1051
|
);
|
|
923
1052
|
const invalidValueListenerType = addType(
|
|
924
|
-
|
|
925
|
-
`(${storeInstance}: ${storeType}, valueId: Id, invalidValues: any[])
|
|
1053
|
+
INVALID + VALUE + LISTENER,
|
|
1054
|
+
`(${storeInstance}: ${storeType}, valueId: Id, invalidValues: any[])` +
|
|
1055
|
+
RETURNS_VOID,
|
|
926
1056
|
getListenerTypeDoc(12),
|
|
927
1057
|
);
|
|
928
|
-
|
|
929
|
-
`hasValues`,
|
|
930
|
-
EMPTY_STRING,
|
|
931
|
-
BOOLEAN,
|
|
932
|
-
storeMethod('hasValues'),
|
|
933
|
-
getHasDoc('any Value'),
|
|
934
|
-
);
|
|
935
|
-
addMethod(
|
|
936
|
-
`getValues`,
|
|
937
|
-
EMPTY_STRING,
|
|
1058
|
+
sharedValueTypes = [
|
|
938
1059
|
valuesType,
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1060
|
+
valuesWhenSetType,
|
|
1061
|
+
valueIdType,
|
|
1062
|
+
valuesListenerType,
|
|
1063
|
+
valueIdsListenerType,
|
|
1064
|
+
valueListenerType,
|
|
1065
|
+
];
|
|
1066
|
+
arrayForEach(
|
|
1067
|
+
[
|
|
1068
|
+
[valuesType],
|
|
1069
|
+
[BOOLEAN],
|
|
1070
|
+
[storeType, 'values: ' + valuesWhenSetType, 'values'],
|
|
1071
|
+
[storeType],
|
|
1072
|
+
[storeType, 'partialValues: ' + valuesWhenSetType, 'partialValues'],
|
|
1073
|
+
],
|
|
1074
|
+
([returnType, params, paramsInCall], verb) =>
|
|
1075
|
+
addProxyMethod(
|
|
1076
|
+
verb,
|
|
1077
|
+
EMPTY_STRING,
|
|
1078
|
+
VALUES,
|
|
1079
|
+
returnType,
|
|
1080
|
+
getTheContentOfTheStoreDoc(2, verb),
|
|
1081
|
+
params,
|
|
1082
|
+
paramsInCall,
|
|
1083
|
+
),
|
|
955
1084
|
);
|
|
956
|
-
|
|
957
|
-
|
|
1085
|
+
addProxyMethod(
|
|
1086
|
+
0,
|
|
958
1087
|
EMPTY_STRING,
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1088
|
+
VALUE_IDS,
|
|
1089
|
+
valueIdType + SQUARE_BRACKETS,
|
|
1090
|
+
getIdsDoc(VALUE, THE_STORE),
|
|
962
1091
|
);
|
|
963
|
-
|
|
964
|
-
|
|
1092
|
+
addProxyMethod(
|
|
1093
|
+
5,
|
|
965
1094
|
EMPTY_STRING,
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
);
|
|
970
|
-
addMethod(
|
|
971
|
-
'forEachValue',
|
|
1095
|
+
VALUE,
|
|
1096
|
+
`void`,
|
|
1097
|
+
getForEachDoc(VALUE, THE_STORE),
|
|
972
1098
|
`valueCallback: ${valueCallbackType}`,
|
|
973
|
-
'
|
|
974
|
-
storeMethod('forEachValue', 'valueCallback as any'),
|
|
975
|
-
getForEachDoc('Value', THE_STORE),
|
|
1099
|
+
'valueCallback as any',
|
|
976
1100
|
);
|
|
977
1101
|
mapValuesSchema((valueId, type, _, VALUE_ID, valueName) => {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
EMPTY_STRING,
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
getValueContentDoc(valueId, 1),
|
|
998
|
-
);
|
|
999
|
-
addMethod(
|
|
1000
|
-
`del${valueName}Value`,
|
|
1001
|
-
EMPTY_STRING,
|
|
1002
|
-
storeType,
|
|
1003
|
-
fluentStoreMethod('delValue', VALUE_ID),
|
|
1004
|
-
getValueContentDoc(valueId, 3),
|
|
1102
|
+
const mapValueType = 'Map' + camel(type, 1);
|
|
1103
|
+
mapSet(mapCellOrValueTypes, type, mapValueType);
|
|
1104
|
+
arrayForEach(
|
|
1105
|
+
[
|
|
1106
|
+
[type],
|
|
1107
|
+
[BOOLEAN],
|
|
1108
|
+
[storeType, `value: ${type} | ` + mapValueType, ', value as any'],
|
|
1109
|
+
[storeType],
|
|
1110
|
+
],
|
|
1111
|
+
([returnType, params, paramsInCall = EMPTY_STRING], verb) =>
|
|
1112
|
+
addProxyMethod(
|
|
1113
|
+
verb,
|
|
1114
|
+
valueName,
|
|
1115
|
+
VALUE,
|
|
1116
|
+
returnType,
|
|
1117
|
+
getValueContentDoc(valueId, verb),
|
|
1118
|
+
params,
|
|
1119
|
+
VALUE_ID + paramsInCall,
|
|
1120
|
+
),
|
|
1005
1121
|
);
|
|
1006
1122
|
});
|
|
1007
|
-
|
|
1008
|
-
|
|
1123
|
+
addProxyMethod(
|
|
1124
|
+
0,
|
|
1009
1125
|
EMPTY_STRING,
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
getTheContentOfTheStoreDoc(
|
|
1126
|
+
VALUES + JSON$1,
|
|
1127
|
+
JSON$1,
|
|
1128
|
+
getTheContentOfTheStoreDoc(2, 6),
|
|
1013
1129
|
);
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1130
|
+
addProxyMethod(
|
|
1131
|
+
2,
|
|
1132
|
+
EMPTY_STRING,
|
|
1133
|
+
VALUES + JSON$1,
|
|
1017
1134
|
storeType,
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
addMethod(
|
|
1022
|
-
'addValuesListener',
|
|
1023
|
-
`${LISTENER}: ${valuesListenerType}, mutator?: boolean`,
|
|
1024
|
-
'Id',
|
|
1025
|
-
storeListener('addValuesListener', EMPTY_STRING, 'mutator'),
|
|
1026
|
-
getTheContentOfTheStoreDoc(7, 2) + ' changes',
|
|
1135
|
+
getTheContentOfTheStoreDoc(2, 7),
|
|
1136
|
+
'valuesJson: ' + JSON$1,
|
|
1137
|
+
'values' + JSON$1,
|
|
1027
1138
|
);
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
'
|
|
1032
|
-
storeListener('addValueIdsListener', EMPTY_STRING, 'mutator'),
|
|
1033
|
-
getListenerDoc('the Value Ids', THE_STORE, 1),
|
|
1139
|
+
addProxyListener(
|
|
1140
|
+
VALUES,
|
|
1141
|
+
valuesListenerType,
|
|
1142
|
+
getTheContentOfTheStoreDoc(2, 8) + ' changes',
|
|
1034
1143
|
);
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1144
|
+
addProxyListener(VALUE_IDS, valueIdsListenerType, getListenerDoc(10, 0, 1));
|
|
1145
|
+
addProxyListener(
|
|
1146
|
+
VALUE,
|
|
1147
|
+
valueListenerType,
|
|
1148
|
+
getListenerDoc(11, 0),
|
|
1149
|
+
`valueId: ${valueIdType} | null`,
|
|
1150
|
+
'valueId',
|
|
1041
1151
|
);
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
'
|
|
1046
|
-
|
|
1047
|
-
|
|
1152
|
+
addProxyListener(
|
|
1153
|
+
INVALID + VALUE,
|
|
1154
|
+
invalidValueListenerType,
|
|
1155
|
+
REGISTERS_A_LISTENER + ' whenever an invalid Value change was attempted',
|
|
1156
|
+
`valueId: IdOrNull`,
|
|
1157
|
+
'valueId',
|
|
1048
1158
|
);
|
|
1049
1159
|
addImport(
|
|
1050
1160
|
1,
|
|
1051
1161
|
moduleDefinition,
|
|
1052
1162
|
valuesType,
|
|
1163
|
+
valuesWhenSetType,
|
|
1053
1164
|
valueIdType,
|
|
1054
1165
|
valueCallbackType,
|
|
1055
1166
|
valuesListenerType,
|
|
1056
1167
|
valueIdsListenerType,
|
|
1057
1168
|
valueListenerType,
|
|
1058
1169
|
invalidValueListenerType,
|
|
1170
|
+
...collValues(mapCellOrValueTypes),
|
|
1059
1171
|
);
|
|
1060
1172
|
addImport(0, 'tinybase', 'ValueChange');
|
|
1061
1173
|
arrayPush(
|
|
@@ -1068,94 +1180,113 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1068
1180
|
)}]: ${addConstant(snake(type), `'${type}'`)}${
|
|
1069
1181
|
isUndefined(defaultValue)
|
|
1070
1182
|
? EMPTY_STRING
|
|
1071
|
-
: `, [${addConstant(snake(DEFAULT), `'${DEFAULT}'`)}]:
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
}`
|
|
1183
|
+
: `, [${addConstant(snake(DEFAULT), `'${DEFAULT}'`)}]: ` +
|
|
1184
|
+
(isString(defaultValue)
|
|
1185
|
+
? addConstant(snake(defaultValue), `'${defaultValue}'`)
|
|
1186
|
+
: defaultValue)
|
|
1076
1187
|
}},`,
|
|
1077
1188
|
]),
|
|
1078
1189
|
'})',
|
|
1079
1190
|
);
|
|
1080
1191
|
}
|
|
1081
|
-
|
|
1192
|
+
mapForEach(mapCellOrValueTypes, (type, mapCellType) =>
|
|
1193
|
+
addType(
|
|
1194
|
+
mapCellType,
|
|
1195
|
+
`(cell: ${type}${OR_UNDEFINED}) => ` + type,
|
|
1196
|
+
`Takes a ${type} Cell value and returns another`,
|
|
1197
|
+
),
|
|
1198
|
+
);
|
|
1199
|
+
addImport(null, 'tinybase', 'DoRollback', ID, 'IdOrNull', JSON$1, 'Store');
|
|
1082
1200
|
const transactionListenerType = addType(
|
|
1083
|
-
|
|
1084
|
-
`(${storeInstance}: ${storeType}, cellsTouched: boolean, valuesTouched: boolean)
|
|
1085
|
-
|
|
1201
|
+
TRANSACTION + LISTENER,
|
|
1202
|
+
`(${storeInstance}: ${storeType}, cellsTouched: boolean, valuesTouched: boolean)` +
|
|
1203
|
+
RETURNS_VOID,
|
|
1204
|
+
A_FUNCTION_FOR + ' listening to the completion of a ' + TRANSACTION_,
|
|
1086
1205
|
);
|
|
1087
|
-
|
|
1088
|
-
|
|
1206
|
+
addProxyMethod(
|
|
1207
|
+
0,
|
|
1089
1208
|
EMPTY_STRING,
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
getTheContentOfTheStoreDoc(
|
|
1209
|
+
JSON$1,
|
|
1210
|
+
JSON$1,
|
|
1211
|
+
getTheContentOfTheStoreDoc(0, 6),
|
|
1093
1212
|
);
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1213
|
+
addProxyMethod(
|
|
1214
|
+
2,
|
|
1215
|
+
EMPTY_STRING,
|
|
1216
|
+
JSON$1,
|
|
1097
1217
|
storeType,
|
|
1098
|
-
|
|
1099
|
-
|
|
1218
|
+
getTheContentOfTheStoreDoc(0, 7),
|
|
1219
|
+
'json: ' + JSON$1,
|
|
1220
|
+
'json',
|
|
1100
1221
|
);
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1222
|
+
addProxyMethod(
|
|
1223
|
+
7,
|
|
1224
|
+
EMPTY_STRING,
|
|
1225
|
+
TRANSACTION_,
|
|
1104
1226
|
'Return',
|
|
1105
|
-
|
|
1106
|
-
'
|
|
1227
|
+
'Execute a ' + TRANSACTION_ + ' to make multiple mutations',
|
|
1228
|
+
'actions: () => Return, doRollback?: DoRollback',
|
|
1229
|
+
'actions, doRollback',
|
|
1107
1230
|
'<Return>',
|
|
1108
1231
|
);
|
|
1109
|
-
|
|
1110
|
-
|
|
1232
|
+
addProxyMethod(
|
|
1233
|
+
7,
|
|
1111
1234
|
EMPTY_STRING,
|
|
1235
|
+
'start' + TRANSACTION,
|
|
1112
1236
|
storeType,
|
|
1113
|
-
|
|
1114
|
-
'Explicitly starts a transaction',
|
|
1237
|
+
'Explicitly starts a ' + TRANSACTION_,
|
|
1115
1238
|
);
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1239
|
+
addProxyMethod(
|
|
1240
|
+
7,
|
|
1241
|
+
EMPTY_STRING,
|
|
1242
|
+
'finish' + TRANSACTION,
|
|
1119
1243
|
storeType,
|
|
1120
|
-
|
|
1121
|
-
'
|
|
1244
|
+
'Explicitly finishes a ' + TRANSACTION_,
|
|
1245
|
+
'doRollback?: DoRollback,',
|
|
1246
|
+
'doRollback',
|
|
1122
1247
|
);
|
|
1123
|
-
|
|
1124
|
-
'
|
|
1125
|
-
|
|
1126
|
-
'
|
|
1127
|
-
|
|
1128
|
-
|
|
1248
|
+
addProxyListener(
|
|
1249
|
+
'WillFinish' + TRANSACTION,
|
|
1250
|
+
transactionListenerType,
|
|
1251
|
+
REGISTERS_A_LISTENER + ' just before ' + THE_END_OF_THE_TRANSACTION,
|
|
1252
|
+
EMPTY_STRING,
|
|
1253
|
+
EMPTY_STRING,
|
|
1254
|
+
0,
|
|
1129
1255
|
);
|
|
1130
|
-
|
|
1131
|
-
'
|
|
1132
|
-
|
|
1133
|
-
'
|
|
1134
|
-
|
|
1135
|
-
|
|
1256
|
+
addProxyListener(
|
|
1257
|
+
'DidFinish' + TRANSACTION,
|
|
1258
|
+
transactionListenerType,
|
|
1259
|
+
REGISTERS_A_LISTENER + ' just after ' + THE_END_OF_THE_TRANSACTION,
|
|
1260
|
+
EMPTY_STRING,
|
|
1261
|
+
EMPTY_STRING,
|
|
1262
|
+
0,
|
|
1136
1263
|
);
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1264
|
+
addProxyMethod(
|
|
1265
|
+
7,
|
|
1266
|
+
EMPTY_STRING,
|
|
1267
|
+
'call' + LISTENER,
|
|
1140
1268
|
storeType,
|
|
1141
|
-
|
|
1142
|
-
`
|
|
1269
|
+
`Manually provoke a listener to be called`,
|
|
1270
|
+
`listenerId: Id`,
|
|
1271
|
+
`listenerId`,
|
|
1143
1272
|
);
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1273
|
+
addProxyMethod(
|
|
1274
|
+
3,
|
|
1275
|
+
EMPTY_STRING,
|
|
1276
|
+
LISTENER,
|
|
1147
1277
|
storeType,
|
|
1148
|
-
|
|
1149
|
-
|
|
1278
|
+
'Remove a listener that was previously added to ' + THE_STORE,
|
|
1279
|
+
'listenerId: Id',
|
|
1280
|
+
'listenerId',
|
|
1150
1281
|
);
|
|
1151
1282
|
addMethod(
|
|
1152
1283
|
'getStore',
|
|
1153
1284
|
EMPTY_STRING,
|
|
1154
1285
|
'Store',
|
|
1155
1286
|
'store',
|
|
1156
|
-
|
|
1287
|
+
VERBS[0] + ' the underlying Store object',
|
|
1157
1288
|
);
|
|
1158
|
-
addImport(1, 'tinybase', 'createStore'
|
|
1289
|
+
addImport(1, 'tinybase', 'createStore');
|
|
1159
1290
|
addImport(
|
|
1160
1291
|
1,
|
|
1161
1292
|
moduleDefinition,
|
|
@@ -1164,33 +1295,1138 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1164
1295
|
transactionListenerType,
|
|
1165
1296
|
);
|
|
1166
1297
|
addConstant('store', ['createStore()', ...createSteps]);
|
|
1167
|
-
|
|
1298
|
+
addInternalFunction('fluent', 'actions: () => Store', [
|
|
1168
1299
|
'actions();',
|
|
1169
1300
|
`return ${storeInstance};`,
|
|
1170
1301
|
]);
|
|
1171
|
-
|
|
1302
|
+
addInternalFunction(
|
|
1172
1303
|
'proxy',
|
|
1173
|
-
|
|
1174
|
-
`(_: Store, ...
|
|
1304
|
+
`listener: any`,
|
|
1305
|
+
`(_: Store, ...params: any[]) => listener(${storeInstance}, ...params)`,
|
|
1175
1306
|
);
|
|
1176
1307
|
addConstant(storeInstance, ['{', ...getMethods(1), '}']);
|
|
1177
1308
|
return [
|
|
1178
1309
|
build(
|
|
1179
1310
|
...getImports(0),
|
|
1180
1311
|
...getTypes(),
|
|
1181
|
-
|
|
1312
|
+
EXPORT + ' interface ' + storeType + ' {',
|
|
1182
1313
|
...getMethods(0),
|
|
1183
|
-
|
|
1314
|
+
'}',
|
|
1184
1315
|
EMPTY_STRING,
|
|
1185
1316
|
comment(`Creates a ${storeType} object`),
|
|
1186
|
-
|
|
1317
|
+
EXPORT + ' function create' + storeType + '(): ' + storeType + ';',
|
|
1187
1318
|
),
|
|
1188
1319
|
build(
|
|
1189
1320
|
...getImports(1),
|
|
1190
|
-
|
|
1321
|
+
EXPORT +
|
|
1322
|
+
' const create' +
|
|
1323
|
+
storeType +
|
|
1324
|
+
': typeof create' +
|
|
1325
|
+
storeType +
|
|
1326
|
+
'Decl = () => {',
|
|
1191
1327
|
...getConstants(),
|
|
1192
1328
|
`return Object.freeze(${storeInstance});`,
|
|
1193
|
-
|
|
1329
|
+
'};',
|
|
1330
|
+
),
|
|
1331
|
+
sharedTableTypes,
|
|
1332
|
+
sharedValueTypes,
|
|
1333
|
+
];
|
|
1334
|
+
};
|
|
1335
|
+
|
|
1336
|
+
const DEPS = 'Deps';
|
|
1337
|
+
const getGet = (noun) => GET + noun;
|
|
1338
|
+
const getGetAndGetDeps = (noun) =>
|
|
1339
|
+
getParameterList(getGet(noun), getGet(noun) + DEPS);
|
|
1340
|
+
const getPropsTypeList = (...props) =>
|
|
1341
|
+
'{' +
|
|
1342
|
+
join(
|
|
1343
|
+
arrayMap(props, (prop) => 'readonly ' + prop),
|
|
1344
|
+
'; ',
|
|
1345
|
+
) +
|
|
1346
|
+
'}';
|
|
1347
|
+
const DEBUG_IDS_PROP_TYPE = 'debugIds?: boolean';
|
|
1348
|
+
const DEBUG_IDS_PROP = 'debugIds={debugIds}';
|
|
1349
|
+
const DEPS_SUFFIX = DEPS + '?: React.DependencyList';
|
|
1350
|
+
const THEN_DEPS = 'then' + DEPS_SUFFIX;
|
|
1351
|
+
const PARAMETER = 'Parameter';
|
|
1352
|
+
const GETTER_ARGS = ': (parameter: ' + PARAMETER + ', store: Store) => ';
|
|
1353
|
+
const PROVIDER = 'Provider';
|
|
1354
|
+
const USE_CONTEXT = 'const contextValue = useContext(Context);';
|
|
1355
|
+
const AND_REGISTERS =
|
|
1356
|
+
', and registers a listener so that any changes to that result will cause a re-render';
|
|
1357
|
+
const BASED_ON_A_PARAMETER = ', based on a parameter';
|
|
1358
|
+
const COLON_SPACE = ': ';
|
|
1359
|
+
const OPTIONAL_COLON = '?: ';
|
|
1360
|
+
const GENERIC_PARAMETER = '<' + PARAMETER + ',>';
|
|
1361
|
+
const PARAMETERIZED_CALLBACK =
|
|
1362
|
+
PARAMETER + 'ized' + CALLBACK + '<' + PARAMETER + '>';
|
|
1363
|
+
const PROPS = 'Props';
|
|
1364
|
+
const ROW_ID = 'rowId';
|
|
1365
|
+
const ROW_ID_PROP = 'rowId={rowId}';
|
|
1366
|
+
const SEPARATOR_AND_DEBUG_IDS = ', separator, debugIds';
|
|
1367
|
+
const SEPARATOR_PROP_TYPE = 'separator?: ReactElement | string';
|
|
1368
|
+
const THEN_PREFIX = 'then?: (store: Store';
|
|
1369
|
+
const THEN_AND_THEN_DEPS = getParameterList(
|
|
1370
|
+
THEN_PREFIX + ')' + RETURNS_VOID,
|
|
1371
|
+
THEN_DEPS,
|
|
1372
|
+
);
|
|
1373
|
+
const THEN_AND_THEN_DEPS_IN_CALL = 'then, then' + DEPS;
|
|
1374
|
+
const TYPED_ROW_ID = ROW_ID + COLON_SPACE + ID;
|
|
1375
|
+
const VIEW = 'View';
|
|
1376
|
+
const getListenerHookParams = (listenerType, ...extraParams) =>
|
|
1377
|
+
getParameterList(
|
|
1378
|
+
...extraParams,
|
|
1379
|
+
LISTENER_ + ': ' + listenerType,
|
|
1380
|
+
LISTENER_ + DEPS_SUFFIX,
|
|
1381
|
+
'mutator?: boolean',
|
|
1382
|
+
);
|
|
1383
|
+
const getListenerHookParamsInCall = (...extraParams) =>
|
|
1384
|
+
getParameterList(...extraParams, LISTENER_, LISTENER_ + DEPS, 'mutator');
|
|
1385
|
+
const getStoreUiReactApi = (
|
|
1386
|
+
tablesSchema,
|
|
1387
|
+
valuesSchema,
|
|
1388
|
+
module,
|
|
1389
|
+
sharedTableTypes,
|
|
1390
|
+
sharedValueTypes,
|
|
1391
|
+
) => {
|
|
1392
|
+
const [
|
|
1393
|
+
build,
|
|
1394
|
+
addImport,
|
|
1395
|
+
addType,
|
|
1396
|
+
addInternalFunction,
|
|
1397
|
+
addConstant,
|
|
1398
|
+
getImports,
|
|
1399
|
+
getTypes,
|
|
1400
|
+
getConstants,
|
|
1401
|
+
] = getCodeFunctions();
|
|
1402
|
+
const [mapTablesSchema, mapCellSchema, mapValuesSchema] = getSchemaFunctions(
|
|
1403
|
+
tablesSchema,
|
|
1404
|
+
valuesSchema,
|
|
1405
|
+
addConstant,
|
|
1406
|
+
);
|
|
1407
|
+
const moduleDefinition = `./${camel(module)}.d`;
|
|
1408
|
+
const uiReactModuleDefinition = `./${camel(module)}-ui-react.d`;
|
|
1409
|
+
const tinyBaseUiReact = 'tinybase/ui-react';
|
|
1410
|
+
const storeType = camel(module, 1);
|
|
1411
|
+
const storeInstance = camel(storeType);
|
|
1412
|
+
const StoreOrStoreId = storeType + 'Or' + storeType + ID;
|
|
1413
|
+
const storeOrStoreId = storeInstance + 'Or' + storeType + ID;
|
|
1414
|
+
const storeProp = storeInstance + `={${storeInstance}}`;
|
|
1415
|
+
const functions = mapNew();
|
|
1416
|
+
const addFunction = (
|
|
1417
|
+
name,
|
|
1418
|
+
parameters,
|
|
1419
|
+
returnType,
|
|
1420
|
+
body,
|
|
1421
|
+
doc,
|
|
1422
|
+
generic = EMPTY_STRING,
|
|
1423
|
+
) => {
|
|
1424
|
+
addImport(1, uiReactModuleDefinition, name + ' as ' + name + 'Decl');
|
|
1425
|
+
return mapUnique(functions, name, [
|
|
1426
|
+
parameters,
|
|
1427
|
+
returnType,
|
|
1428
|
+
body,
|
|
1429
|
+
doc,
|
|
1430
|
+
generic,
|
|
1431
|
+
]);
|
|
1432
|
+
};
|
|
1433
|
+
const addHook = (
|
|
1434
|
+
name,
|
|
1435
|
+
parameters,
|
|
1436
|
+
returnType,
|
|
1437
|
+
body,
|
|
1438
|
+
doc,
|
|
1439
|
+
generic = EMPTY_STRING,
|
|
1440
|
+
) => addFunction(`use${name}`, parameters, returnType, body, doc, generic);
|
|
1441
|
+
const addProxyHook = (
|
|
1442
|
+
name,
|
|
1443
|
+
underlyingName,
|
|
1444
|
+
returnType,
|
|
1445
|
+
doc,
|
|
1446
|
+
preParameters = EMPTY_STRING,
|
|
1447
|
+
preParametersInCall = EMPTY_STRING,
|
|
1448
|
+
generic = EMPTY_STRING,
|
|
1449
|
+
postParameters = EMPTY_STRING,
|
|
1450
|
+
postParametersInCall = EMPTY_STRING,
|
|
1451
|
+
) => {
|
|
1452
|
+
addImport(
|
|
1453
|
+
1,
|
|
1454
|
+
tinyBaseUiReact,
|
|
1455
|
+
`use${underlyingName} as use${underlyingName}Core`,
|
|
1456
|
+
);
|
|
1457
|
+
return addHook(
|
|
1458
|
+
name,
|
|
1459
|
+
getParameterList(preParameters, storeOrStoreIdParameter, postParameters),
|
|
1460
|
+
returnType,
|
|
1461
|
+
useHook +
|
|
1462
|
+
`(${storeOrStoreId}, use${underlyingName}Core, [` +
|
|
1463
|
+
(preParametersInCall ? preParametersInCall : EMPTY_STRING) +
|
|
1464
|
+
(postParametersInCall ? '], [' + postParametersInCall : EMPTY_STRING) +
|
|
1465
|
+
']);',
|
|
1466
|
+
doc,
|
|
1467
|
+
generic,
|
|
1468
|
+
);
|
|
1469
|
+
};
|
|
1470
|
+
const addComponent = (name, parameters, body, doc) =>
|
|
1471
|
+
addFunction(name, parameters, 1, body, doc);
|
|
1472
|
+
const getFunctions = (location = 0) =>
|
|
1473
|
+
mapMap(functions, ([parameters, returnType, body, doc, generic], name) => {
|
|
1474
|
+
const lines = location
|
|
1475
|
+
? [
|
|
1476
|
+
EXPORT +
|
|
1477
|
+
` const ${name}: typeof ${name}Decl = ${generic}(${parameters}): ${
|
|
1478
|
+
returnType == 1 ? 'any' : returnType
|
|
1479
|
+
} =>`,
|
|
1480
|
+
body,
|
|
1481
|
+
]
|
|
1482
|
+
: [
|
|
1483
|
+
EXPORT +
|
|
1484
|
+
` function ${name}${generic}(${parameters}): ${
|
|
1485
|
+
returnType == 1 ? 'ComponentReturnType' : returnType
|
|
1486
|
+
};`,
|
|
1487
|
+
];
|
|
1488
|
+
if (!location) {
|
|
1489
|
+
arrayUnshift(lines, comment(doc));
|
|
1490
|
+
}
|
|
1491
|
+
arrayPush(lines, EMPTY_STRING);
|
|
1492
|
+
return lines;
|
|
1493
|
+
});
|
|
1494
|
+
addImport(
|
|
1495
|
+
null,
|
|
1496
|
+
'tinybase',
|
|
1497
|
+
ID,
|
|
1498
|
+
'Store',
|
|
1499
|
+
CALLBACK,
|
|
1500
|
+
PARAMETER + 'ized' + CALLBACK,
|
|
1501
|
+
);
|
|
1502
|
+
addImport(0, tinyBaseUiReact, 'ComponentReturnType');
|
|
1503
|
+
addImport(null, tinyBaseUiReact, 'ExtraProps');
|
|
1504
|
+
addImport(0, moduleDefinition, storeType);
|
|
1505
|
+
const storeOrStoreIdType = addType(
|
|
1506
|
+
StoreOrStoreId,
|
|
1507
|
+
storeType + ' | ' + ID,
|
|
1508
|
+
`Used when you need to refer to a ${storeType} in a React hook or component`,
|
|
1509
|
+
);
|
|
1510
|
+
const providerPropsType = addType(
|
|
1511
|
+
PROVIDER + PROPS,
|
|
1512
|
+
getPropsTypeList(
|
|
1513
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1514
|
+
storeInstance + `ById?: {[${storeInstance}Id: Id]: ${storeType}}`,
|
|
1515
|
+
),
|
|
1516
|
+
`Used with the ${PROVIDER} component, so that a ` +
|
|
1517
|
+
storeType +
|
|
1518
|
+
' can be passed into the context of an application',
|
|
1519
|
+
);
|
|
1520
|
+
addImport(0, 'react', 'ReactElement', 'ComponentType');
|
|
1521
|
+
addImport(1, 'react', 'React');
|
|
1522
|
+
addImport(1, uiReactModuleDefinition, storeOrStoreIdType, providerPropsType);
|
|
1523
|
+
const storeOrStoreIdParameter =
|
|
1524
|
+
storeOrStoreId + OPTIONAL_COLON + storeOrStoreIdType;
|
|
1525
|
+
addConstant('{createContext, useContext, useMemo}', 'React');
|
|
1526
|
+
addConstant(
|
|
1527
|
+
'Context',
|
|
1528
|
+
`createContext<[${storeType}?, {[${storeInstance}Id: Id]: ${storeType}}?]>([])`,
|
|
1529
|
+
);
|
|
1530
|
+
addHook(
|
|
1531
|
+
`Create${storeType}`,
|
|
1532
|
+
`create: () => ${storeType}, create` + DEPS_SUFFIX,
|
|
1533
|
+
storeType,
|
|
1534
|
+
'\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)',
|
|
1535
|
+
`Create a ${storeType} within a React application with convenient memoization`,
|
|
1536
|
+
);
|
|
1537
|
+
const getStoreHook = addHook(
|
|
1538
|
+
storeType,
|
|
1539
|
+
`id?: Id`,
|
|
1540
|
+
storeType + OR_UNDEFINED,
|
|
1541
|
+
[
|
|
1542
|
+
'{',
|
|
1543
|
+
USE_CONTEXT,
|
|
1544
|
+
'return id == null ? contextValue[0] : contextValue[1]?.[id];',
|
|
1545
|
+
'}',
|
|
1546
|
+
],
|
|
1547
|
+
`Get a reference to a ${storeType} from within a ${PROVIDER} component context`,
|
|
1548
|
+
);
|
|
1549
|
+
const useHook = addInternalFunction(
|
|
1550
|
+
`useHook`,
|
|
1551
|
+
storeOrStoreId +
|
|
1552
|
+
`: ${storeOrStoreIdType} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,
|
|
1553
|
+
[
|
|
1554
|
+
`const ${storeInstance} = ${getStoreHook}(${storeOrStoreId} as Id);`,
|
|
1555
|
+
`return hook(...preParams, ((${storeOrStoreId} == null || typeof ${storeOrStoreId} == 'string')`,
|
|
1556
|
+
`? ${storeInstance} : ${storeOrStoreId})?.getStore(), ...postParams)`,
|
|
1557
|
+
],
|
|
1558
|
+
);
|
|
1559
|
+
const getProps = addInternalFunction(
|
|
1560
|
+
'getProps',
|
|
1561
|
+
'getProps: ((id: any) => ExtraProps) | undefined, id: Id',
|
|
1562
|
+
'(getProps == null) ? ({} as ExtraProps) : getProps(id)',
|
|
1563
|
+
);
|
|
1564
|
+
const wrap = addInternalFunction(
|
|
1565
|
+
'wrap',
|
|
1566
|
+
getParameterList(
|
|
1567
|
+
'children: any',
|
|
1568
|
+
'separator?: any',
|
|
1569
|
+
'encloseWithId?: boolean',
|
|
1570
|
+
'id?: Id',
|
|
1571
|
+
),
|
|
1572
|
+
[
|
|
1573
|
+
'const separated = separator==null || !Array.isArray(children)',
|
|
1574
|
+
' ? children',
|
|
1575
|
+
' : children.map((child, c) => (c > 0 ? [separator, child] : child));',
|
|
1576
|
+
`return encloseWithId ? [id, ':{', separated, '}'] : separated;`,
|
|
1577
|
+
],
|
|
1578
|
+
);
|
|
1579
|
+
const NullComponent = addConstant('NullComponent', `() => null`);
|
|
1580
|
+
if (!objIsEmpty(tablesSchema)) {
|
|
1581
|
+
const [
|
|
1582
|
+
tablesType,
|
|
1583
|
+
tableIdType,
|
|
1584
|
+
tablesListenerType,
|
|
1585
|
+
tableIdsListenerType,
|
|
1586
|
+
tableListenerType,
|
|
1587
|
+
rowIdsListenerType,
|
|
1588
|
+
sortedRowIdsListenerType,
|
|
1589
|
+
rowListenerType,
|
|
1590
|
+
cellIdsListenerType,
|
|
1591
|
+
cellListenerType,
|
|
1592
|
+
tablesTypes,
|
|
1593
|
+
] = sharedTableTypes;
|
|
1594
|
+
addImport(
|
|
1595
|
+
null,
|
|
1596
|
+
moduleDefinition,
|
|
1597
|
+
tablesType,
|
|
1598
|
+
tableIdType,
|
|
1599
|
+
tablesListenerType,
|
|
1600
|
+
tableIdsListenerType,
|
|
1601
|
+
tableListenerType,
|
|
1602
|
+
rowIdsListenerType,
|
|
1603
|
+
sortedRowIdsListenerType,
|
|
1604
|
+
rowListenerType,
|
|
1605
|
+
cellIdsListenerType,
|
|
1606
|
+
cellListenerType,
|
|
1607
|
+
);
|
|
1608
|
+
addImport(1, moduleDefinition, storeType);
|
|
1609
|
+
addImport(null, 'tinybase', IDS, 'IdOrNull');
|
|
1610
|
+
const tableView = addInternalFunction(
|
|
1611
|
+
'tableView',
|
|
1612
|
+
`{${storeInstance}, rowComponent, getRowComponentProps` +
|
|
1613
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
1614
|
+
'}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>',
|
|
1615
|
+
[
|
|
1616
|
+
'const Row = rowComponent ?? defaultRowComponent;',
|
|
1617
|
+
`return ${wrap}(rowIds.map((rowId) => (`,
|
|
1618
|
+
'<Row',
|
|
1619
|
+
'{...' + getProps + '(getRowComponentProps, rowId)}',
|
|
1620
|
+
'key={rowId}',
|
|
1621
|
+
'tableId={tableId}',
|
|
1622
|
+
ROW_ID_PROP,
|
|
1623
|
+
storeProp,
|
|
1624
|
+
DEBUG_IDS_PROP,
|
|
1625
|
+
'/>',
|
|
1626
|
+
'))',
|
|
1627
|
+
SEPARATOR_AND_DEBUG_IDS,
|
|
1628
|
+
', tableId,',
|
|
1629
|
+
');',
|
|
1630
|
+
],
|
|
1631
|
+
);
|
|
1632
|
+
const getDefaultTableComponent = addInternalFunction(
|
|
1633
|
+
'getDefaultTableComponent',
|
|
1634
|
+
'tableId: Id',
|
|
1635
|
+
join(
|
|
1636
|
+
mapTablesSchema(
|
|
1637
|
+
(_, tableName, TABLE_ID) =>
|
|
1638
|
+
`tableId == ${TABLE_ID} ? ${tableName}TableView : `,
|
|
1639
|
+
),
|
|
1640
|
+
) + NullComponent,
|
|
1641
|
+
);
|
|
1642
|
+
const getDefaultCellComponent = addInternalFunction(
|
|
1643
|
+
'getDefaultCellComponent',
|
|
1644
|
+
'tableId: Id, cellId: Id',
|
|
1645
|
+
join(
|
|
1646
|
+
mapTablesSchema(
|
|
1647
|
+
(tableId, tableName, TABLE_ID) =>
|
|
1648
|
+
`tableId == ${TABLE_ID} ? ${
|
|
1649
|
+
join(
|
|
1650
|
+
mapCellSchema(
|
|
1651
|
+
tableId,
|
|
1652
|
+
(_, _2, _3, CELL_ID, cellName) =>
|
|
1653
|
+
`cellId == ${CELL_ID} ? ` +
|
|
1654
|
+
tableName +
|
|
1655
|
+
cellName +
|
|
1656
|
+
'CellView : ',
|
|
1657
|
+
),
|
|
1658
|
+
) + NullComponent
|
|
1659
|
+
} : `,
|
|
1660
|
+
),
|
|
1661
|
+
) + NullComponent,
|
|
1662
|
+
);
|
|
1663
|
+
addProxyHook(
|
|
1664
|
+
TABLES,
|
|
1665
|
+
TABLES,
|
|
1666
|
+
tablesType,
|
|
1667
|
+
getTheContentOfTheStoreDoc(1, 0) + AND_REGISTERS,
|
|
1668
|
+
);
|
|
1669
|
+
const useTableIds = addProxyHook(
|
|
1670
|
+
TABLE_IDS,
|
|
1671
|
+
TABLE_IDS,
|
|
1672
|
+
tableIdType + SQUARE_BRACKETS,
|
|
1673
|
+
getIdsDoc(TABLE, THE_STORE) + AND_REGISTERS,
|
|
1674
|
+
);
|
|
1675
|
+
addProxyHook(
|
|
1676
|
+
SET + TABLES + CALLBACK,
|
|
1677
|
+
SET + TABLES + CALLBACK,
|
|
1678
|
+
PARAMETERIZED_CALLBACK,
|
|
1679
|
+
getTheContentOfTheStoreDoc(1, 9) + BASED_ON_A_PARAMETER,
|
|
1680
|
+
getParameterList(
|
|
1681
|
+
getGet(TABLES) + GETTER_ARGS + tablesType,
|
|
1682
|
+
getGet(TABLES) + DEPS_SUFFIX,
|
|
1683
|
+
),
|
|
1684
|
+
getGetAndGetDeps(TABLES),
|
|
1685
|
+
GENERIC_PARAMETER,
|
|
1686
|
+
getParameterList(
|
|
1687
|
+
THEN_PREFIX,
|
|
1688
|
+
`tables: ${tablesType})` + RETURNS_VOID,
|
|
1689
|
+
THEN_DEPS,
|
|
1690
|
+
),
|
|
1691
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1692
|
+
);
|
|
1693
|
+
addProxyHook(
|
|
1694
|
+
DEL + TABLES + CALLBACK,
|
|
1695
|
+
DEL + TABLES + CALLBACK,
|
|
1696
|
+
CALLBACK,
|
|
1697
|
+
getTheContentOfTheStoreDoc(1, 12),
|
|
1698
|
+
EMPTY_STRING,
|
|
1699
|
+
EMPTY_STRING,
|
|
1700
|
+
EMPTY_STRING,
|
|
1701
|
+
THEN_AND_THEN_DEPS,
|
|
1702
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1703
|
+
);
|
|
1704
|
+
const tablesPropsType = addType(
|
|
1705
|
+
TABLES + PROPS,
|
|
1706
|
+
getPropsTypeList(
|
|
1707
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1708
|
+
'tableComponents?: {' +
|
|
1709
|
+
join(
|
|
1710
|
+
mapTablesSchema(
|
|
1711
|
+
(tableId, tableName) =>
|
|
1712
|
+
`'${tableId}'?: ComponentType<${tableName}TableProps>`,
|
|
1713
|
+
),
|
|
1714
|
+
', ',
|
|
1715
|
+
) +
|
|
1716
|
+
'}',
|
|
1717
|
+
`getTableComponentProps?: (tableId: ${tableIdType}) => ExtraProps`,
|
|
1718
|
+
SEPARATOR_PROP_TYPE,
|
|
1719
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1720
|
+
),
|
|
1721
|
+
getPropsDoc(getTheContentOfDoc(1, 1)),
|
|
1722
|
+
);
|
|
1723
|
+
const cellPropsType = addType(
|
|
1724
|
+
CELL + PROPS,
|
|
1725
|
+
getPropsTypeList(
|
|
1726
|
+
'rowId: Id',
|
|
1727
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1728
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1729
|
+
),
|
|
1730
|
+
getPropsDoc('a Cell'),
|
|
1731
|
+
);
|
|
1732
|
+
addImport(1, uiReactModuleDefinition, tablesPropsType, cellPropsType);
|
|
1733
|
+
addComponent(
|
|
1734
|
+
TABLES + VIEW,
|
|
1735
|
+
'{' +
|
|
1736
|
+
storeInstance +
|
|
1737
|
+
', tableComponents, getTableComponentProps' +
|
|
1738
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
1739
|
+
'}: ' +
|
|
1740
|
+
tablesPropsType,
|
|
1741
|
+
[
|
|
1742
|
+
wrap + `(${useTableIds}(${storeInstance}).map((tableId) => {`,
|
|
1743
|
+
'const Table = tableComponents?.[tableId] ?? ' +
|
|
1744
|
+
getDefaultTableComponent +
|
|
1745
|
+
'(tableId);',
|
|
1746
|
+
'return <Table',
|
|
1747
|
+
`{...${getProps}(getTableComponentProps, tableId)}`,
|
|
1748
|
+
'key={tableId}',
|
|
1749
|
+
storeProp,
|
|
1750
|
+
DEBUG_IDS_PROP,
|
|
1751
|
+
'/>;',
|
|
1752
|
+
'}), separator)',
|
|
1753
|
+
],
|
|
1754
|
+
getTheContentOfTheStoreDoc(1, 13) + AND_REGISTERS,
|
|
1755
|
+
);
|
|
1756
|
+
mapTablesSchema((tableId, tableName, TABLE_ID) => {
|
|
1757
|
+
const [tableType, rowType, rowWhenSetType, cellIdType] = mapGet(
|
|
1758
|
+
tablesTypes,
|
|
1759
|
+
tableId,
|
|
1760
|
+
);
|
|
1761
|
+
addImport(
|
|
1762
|
+
0,
|
|
1763
|
+
moduleDefinition,
|
|
1764
|
+
tableType,
|
|
1765
|
+
rowType,
|
|
1766
|
+
rowWhenSetType,
|
|
1767
|
+
cellIdType,
|
|
1768
|
+
);
|
|
1769
|
+
addImport(
|
|
1770
|
+
1,
|
|
1771
|
+
moduleDefinition,
|
|
1772
|
+
tableType,
|
|
1773
|
+
rowType,
|
|
1774
|
+
rowWhenSetType,
|
|
1775
|
+
cellIdType,
|
|
1776
|
+
);
|
|
1777
|
+
addProxyHook(
|
|
1778
|
+
tableName + TABLE,
|
|
1779
|
+
TABLE,
|
|
1780
|
+
tableType,
|
|
1781
|
+
getTableContentDoc(tableId) + AND_REGISTERS,
|
|
1782
|
+
EMPTY_STRING,
|
|
1783
|
+
TABLE_ID,
|
|
1784
|
+
);
|
|
1785
|
+
const useRowIds = addProxyHook(
|
|
1786
|
+
tableName + ROW_IDS,
|
|
1787
|
+
ROW_IDS,
|
|
1788
|
+
IDS,
|
|
1789
|
+
getIdsDoc(ROW, getTableDoc(tableId)) + AND_REGISTERS,
|
|
1790
|
+
EMPTY_STRING,
|
|
1791
|
+
TABLE_ID,
|
|
1792
|
+
);
|
|
1793
|
+
const useSortedRowIds = addProxyHook(
|
|
1794
|
+
tableName + SORTED_ROW_IDS,
|
|
1795
|
+
SORTED_ROW_IDS,
|
|
1796
|
+
IDS,
|
|
1797
|
+
getIdsDoc(ROW, getTableDoc(tableId), 1) + AND_REGISTERS,
|
|
1798
|
+
'cellId?: ' +
|
|
1799
|
+
cellIdType +
|
|
1800
|
+
', descending?: boolean, offset?: number, limit?: number',
|
|
1801
|
+
TABLE_ID + ', cellId, descending, offset, limit',
|
|
1802
|
+
);
|
|
1803
|
+
addProxyHook(
|
|
1804
|
+
tableName + ROW,
|
|
1805
|
+
ROW,
|
|
1806
|
+
rowType,
|
|
1807
|
+
getRowContentDoc(tableId) + AND_REGISTERS,
|
|
1808
|
+
TYPED_ROW_ID,
|
|
1809
|
+
getParameterList(TABLE_ID, ROW_ID),
|
|
1810
|
+
);
|
|
1811
|
+
const useCellIds = addProxyHook(
|
|
1812
|
+
tableName + CELL_IDS,
|
|
1813
|
+
CELL_IDS,
|
|
1814
|
+
cellIdType + SQUARE_BRACKETS,
|
|
1815
|
+
getIdsDoc(CELL, getRowDoc(tableId)) + AND_REGISTERS,
|
|
1816
|
+
TYPED_ROW_ID,
|
|
1817
|
+
getParameterList(TABLE_ID, ROW_ID),
|
|
1818
|
+
);
|
|
1819
|
+
addProxyHook(
|
|
1820
|
+
SET + tableName + TABLE + CALLBACK,
|
|
1821
|
+
SET + TABLE + CALLBACK,
|
|
1822
|
+
PARAMETERIZED_CALLBACK,
|
|
1823
|
+
getTableContentDoc(tableId, 9) + BASED_ON_A_PARAMETER,
|
|
1824
|
+
getParameterList(
|
|
1825
|
+
getGet(TABLE) + GETTER_ARGS + tableType,
|
|
1826
|
+
getGet(TABLE) + DEPS_SUFFIX,
|
|
1827
|
+
),
|
|
1828
|
+
getParameterList(TABLE_ID, getGetAndGetDeps(TABLE)),
|
|
1829
|
+
GENERIC_PARAMETER,
|
|
1830
|
+
getParameterList(
|
|
1831
|
+
THEN_PREFIX,
|
|
1832
|
+
`table: ${tableType})` + RETURNS_VOID,
|
|
1833
|
+
THEN_DEPS,
|
|
1834
|
+
),
|
|
1835
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1836
|
+
);
|
|
1837
|
+
addProxyHook(
|
|
1838
|
+
DEL + tableName + TABLE + CALLBACK,
|
|
1839
|
+
DEL + TABLE + CALLBACK,
|
|
1840
|
+
CALLBACK,
|
|
1841
|
+
getTableContentDoc(tableId, 12),
|
|
1842
|
+
EMPTY_STRING,
|
|
1843
|
+
TABLE_ID,
|
|
1844
|
+
EMPTY_STRING,
|
|
1845
|
+
THEN_AND_THEN_DEPS,
|
|
1846
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1847
|
+
);
|
|
1848
|
+
addProxyHook(
|
|
1849
|
+
SET + tableName + ROW + CALLBACK,
|
|
1850
|
+
SET + ROW + CALLBACK,
|
|
1851
|
+
PARAMETERIZED_CALLBACK,
|
|
1852
|
+
getRowContentDoc(tableId, 9) + BASED_ON_A_PARAMETER,
|
|
1853
|
+
getParameterList(
|
|
1854
|
+
TYPED_ROW_ID,
|
|
1855
|
+
getGet(ROW) + GETTER_ARGS + rowWhenSetType,
|
|
1856
|
+
getGet(ROW) + DEPS_SUFFIX,
|
|
1857
|
+
),
|
|
1858
|
+
getParameterList(TABLE_ID, ROW_ID, getGetAndGetDeps(ROW)),
|
|
1859
|
+
GENERIC_PARAMETER,
|
|
1860
|
+
getParameterList(
|
|
1861
|
+
THEN_PREFIX,
|
|
1862
|
+
`row: ${rowWhenSetType})` + RETURNS_VOID,
|
|
1863
|
+
THEN_DEPS,
|
|
1864
|
+
),
|
|
1865
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1866
|
+
);
|
|
1867
|
+
addProxyHook(
|
|
1868
|
+
'Add' + tableName + ROW + CALLBACK,
|
|
1869
|
+
'Add' + ROW + CALLBACK,
|
|
1870
|
+
PARAMETERIZED_CALLBACK,
|
|
1871
|
+
getRowContentDoc(tableId, 10) + BASED_ON_A_PARAMETER,
|
|
1872
|
+
getParameterList(
|
|
1873
|
+
getGet(ROW) + GETTER_ARGS + rowWhenSetType,
|
|
1874
|
+
getGet(ROW) + DEPS_SUFFIX,
|
|
1875
|
+
),
|
|
1876
|
+
getParameterList(TABLE_ID, getGetAndGetDeps(ROW)),
|
|
1877
|
+
GENERIC_PARAMETER,
|
|
1878
|
+
'then?: (' +
|
|
1879
|
+
getParameterList(
|
|
1880
|
+
TYPED_ROW_ID + OR_UNDEFINED,
|
|
1881
|
+
'store: Store',
|
|
1882
|
+
'row: ' + rowWhenSetType + ')' + RETURNS_VOID,
|
|
1883
|
+
'then' + DEPS_SUFFIX,
|
|
1884
|
+
),
|
|
1885
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1886
|
+
);
|
|
1887
|
+
addProxyHook(
|
|
1888
|
+
SET + tableName + PARTIAL + ROW + CALLBACK,
|
|
1889
|
+
SET + PARTIAL + ROW + CALLBACK,
|
|
1890
|
+
PARAMETERIZED_CALLBACK,
|
|
1891
|
+
getRowContentDoc(tableId, 11) + BASED_ON_A_PARAMETER,
|
|
1892
|
+
getParameterList(
|
|
1893
|
+
TYPED_ROW_ID,
|
|
1894
|
+
getGet(PARTIAL + ROW) + GETTER_ARGS + rowWhenSetType,
|
|
1895
|
+
getGet(PARTIAL + ROW) + DEPS_SUFFIX,
|
|
1896
|
+
),
|
|
1897
|
+
getParameterList(TABLE_ID, ROW_ID, getGetAndGetDeps(PARTIAL + ROW)),
|
|
1898
|
+
GENERIC_PARAMETER,
|
|
1899
|
+
getParameterList(
|
|
1900
|
+
THEN_PREFIX,
|
|
1901
|
+
`partialRow: ${rowWhenSetType})` + RETURNS_VOID,
|
|
1902
|
+
THEN_DEPS,
|
|
1903
|
+
),
|
|
1904
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1905
|
+
);
|
|
1906
|
+
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,
|
|
1969
|
+
);
|
|
1970
|
+
const rowView = addComponent(
|
|
1971
|
+
tableName + ROW + VIEW,
|
|
1972
|
+
'{rowId, ' +
|
|
1973
|
+
storeInstance +
|
|
1974
|
+
', cellComponents, getCellComponentProps' +
|
|
1975
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
1976
|
+
'}: ' +
|
|
1977
|
+
rowPropsType,
|
|
1978
|
+
[
|
|
1979
|
+
wrap + `(${useCellIds}(rowId, ${storeInstance}).map((cellId) => {`,
|
|
1980
|
+
'const Cell = cellComponents?.[cellId] ?? ' +
|
|
1981
|
+
getDefaultCellComponent +
|
|
1982
|
+
`(${TABLE_ID}, cellId);`,
|
|
1983
|
+
'return <Cell',
|
|
1984
|
+
`{...${getProps}(getCellComponentProps, cellId)} `,
|
|
1985
|
+
'key={cellId}',
|
|
1986
|
+
ROW_ID_PROP,
|
|
1987
|
+
storeProp,
|
|
1988
|
+
DEBUG_IDS_PROP,
|
|
1989
|
+
'/>;',
|
|
1990
|
+
'})' + SEPARATOR_AND_DEBUG_IDS + ', rowId)',
|
|
1991
|
+
],
|
|
1992
|
+
getRowContentDoc(tableId, 13) + AND_REGISTERS,
|
|
1993
|
+
);
|
|
1994
|
+
addComponent(
|
|
1995
|
+
tableName + 'Sorted' + TABLE + VIEW,
|
|
1996
|
+
'{cellId, descending, offset, limit, ...props}: ' +
|
|
1997
|
+
sortedTablePropsType,
|
|
1998
|
+
tableView +
|
|
1999
|
+
'(props, ' +
|
|
2000
|
+
useSortedRowIds +
|
|
2001
|
+
`(cellId, descending, offset, limit, props.${storeInstance}), ${TABLE_ID}, ${rowView});`,
|
|
2002
|
+
getTableContentDoc(tableId, 13) + ', sorted' + AND_REGISTERS,
|
|
2003
|
+
);
|
|
2004
|
+
addComponent(
|
|
2005
|
+
tableName + TABLE + VIEW,
|
|
2006
|
+
'props: ' + tablePropsType,
|
|
2007
|
+
tableView +
|
|
2008
|
+
'(props, ' +
|
|
2009
|
+
useRowIds +
|
|
2010
|
+
`(props.${storeInstance}), ${TABLE_ID}, ${rowView});`,
|
|
2011
|
+
getTableContentDoc(tableId, 13) + AND_REGISTERS,
|
|
2012
|
+
);
|
|
2013
|
+
mapCellSchema(
|
|
2014
|
+
tableId,
|
|
2015
|
+
(cellId, type, defaultValue, CELL_ID, cellName) => {
|
|
2016
|
+
const mapCellType = 'Map' + camel(type, 1);
|
|
2017
|
+
addImport(0, moduleDefinition, mapCellType);
|
|
2018
|
+
addImport(1, moduleDefinition, mapCellType);
|
|
2019
|
+
const useCell = addProxyHook(
|
|
2020
|
+
tableName + cellName + CELL,
|
|
2021
|
+
CELL,
|
|
2022
|
+
type + (isUndefined(defaultValue) ? OR_UNDEFINED : EMPTY_STRING),
|
|
2023
|
+
getCellContentDoc(tableId, cellId) + AND_REGISTERS,
|
|
2024
|
+
TYPED_ROW_ID,
|
|
2025
|
+
getParameterList(TABLE_ID, ROW_ID, CELL_ID),
|
|
2026
|
+
);
|
|
2027
|
+
addProxyHook(
|
|
2028
|
+
SET + tableName + cellName + CELL + CALLBACK,
|
|
2029
|
+
SET + CELL + CALLBACK,
|
|
2030
|
+
PARAMETERIZED_CALLBACK,
|
|
2031
|
+
getCellContentDoc(tableId, cellId, 9) + BASED_ON_A_PARAMETER,
|
|
2032
|
+
getParameterList(
|
|
2033
|
+
TYPED_ROW_ID,
|
|
2034
|
+
getGet(CELL) + GETTER_ARGS + type + ' | ' + mapCellType,
|
|
2035
|
+
getGet(CELL) + DEPS_SUFFIX,
|
|
2036
|
+
),
|
|
2037
|
+
getParameterList(TABLE_ID, ROW_ID, CELL_ID, getGetAndGetDeps(CELL)),
|
|
2038
|
+
GENERIC_PARAMETER,
|
|
2039
|
+
getParameterList(
|
|
2040
|
+
THEN_PREFIX,
|
|
2041
|
+
`cell: ${type} | ${mapCellType})` + RETURNS_VOID,
|
|
2042
|
+
THEN_DEPS,
|
|
2043
|
+
),
|
|
2044
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2045
|
+
);
|
|
2046
|
+
addProxyHook(
|
|
2047
|
+
DEL + tableName + cellName + CELL + CALLBACK,
|
|
2048
|
+
DEL + CELL + CALLBACK,
|
|
2049
|
+
CALLBACK,
|
|
2050
|
+
getCellContentDoc(tableId, cellId, 12),
|
|
2051
|
+
getParameterList(TYPED_ROW_ID, 'forceDel?: boolean'),
|
|
2052
|
+
getParameterList(TABLE_ID, ROW_ID, CELL_ID, 'forceDel'),
|
|
2053
|
+
EMPTY_STRING,
|
|
2054
|
+
THEN_AND_THEN_DEPS,
|
|
2055
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2056
|
+
);
|
|
2057
|
+
addComponent(
|
|
2058
|
+
tableName + cellName + CELL + VIEW,
|
|
2059
|
+
`{rowId, ${storeInstance}, debugIds}: ` + cellPropsType,
|
|
2060
|
+
[
|
|
2061
|
+
wrap +
|
|
2062
|
+
`('' + ${useCell}(rowId, ` +
|
|
2063
|
+
storeInstance +
|
|
2064
|
+
`) ?? '', undefined, debugIds, ${CELL_ID})`,
|
|
2065
|
+
],
|
|
2066
|
+
getCellContentDoc(tableId, cellId, 13) + AND_REGISTERS,
|
|
2067
|
+
);
|
|
2068
|
+
},
|
|
2069
|
+
);
|
|
2070
|
+
});
|
|
2071
|
+
const cellIdsType = join(
|
|
2072
|
+
mapTablesSchema(
|
|
2073
|
+
(tableId) => mapGet(tablesTypes, tableId)?.[3] ?? EMPTY_STRING,
|
|
2074
|
+
),
|
|
2075
|
+
' | ',
|
|
2076
|
+
);
|
|
2077
|
+
addProxyHook(
|
|
2078
|
+
TABLES + LISTENER,
|
|
2079
|
+
TABLES + LISTENER,
|
|
2080
|
+
VOID,
|
|
2081
|
+
getTheContentOfTheStoreDoc(1, 8) + ' changes',
|
|
2082
|
+
getListenerHookParams(tablesListenerType),
|
|
2083
|
+
getListenerHookParamsInCall(),
|
|
2084
|
+
);
|
|
2085
|
+
addProxyHook(
|
|
2086
|
+
TABLE_IDS + LISTENER,
|
|
2087
|
+
TABLE_IDS + LISTENER,
|
|
2088
|
+
VOID,
|
|
2089
|
+
getListenerDoc(2, 0, 1),
|
|
2090
|
+
getListenerHookParams(tableIdsListenerType),
|
|
2091
|
+
getListenerHookParamsInCall(),
|
|
2092
|
+
);
|
|
2093
|
+
addProxyHook(
|
|
2094
|
+
TABLE + LISTENER,
|
|
2095
|
+
TABLE + LISTENER,
|
|
2096
|
+
VOID,
|
|
2097
|
+
getListenerDoc(3, 0),
|
|
2098
|
+
getListenerHookParams(
|
|
2099
|
+
tableListenerType,
|
|
2100
|
+
`tableId: ${tableIdType} | null`,
|
|
2101
|
+
),
|
|
2102
|
+
getListenerHookParamsInCall('tableId'),
|
|
2103
|
+
);
|
|
2104
|
+
addProxyHook(
|
|
2105
|
+
ROW_IDS + LISTENER,
|
|
2106
|
+
ROW_IDS + LISTENER,
|
|
2107
|
+
VOID,
|
|
2108
|
+
getListenerDoc(4, 3, 1),
|
|
2109
|
+
getListenerHookParams(
|
|
2110
|
+
rowIdsListenerType,
|
|
2111
|
+
`tableId: ${tableIdType} | null`,
|
|
2112
|
+
),
|
|
2113
|
+
getListenerHookParamsInCall('tableId'),
|
|
2114
|
+
);
|
|
2115
|
+
addProxyHook(
|
|
2116
|
+
SORTED_ROW_IDS + LISTENER,
|
|
2117
|
+
SORTED_ROW_IDS + LISTENER,
|
|
2118
|
+
VOID,
|
|
2119
|
+
getListenerDoc(13, 3, 1),
|
|
2120
|
+
getListenerHookParams(
|
|
2121
|
+
sortedRowIdsListenerType,
|
|
2122
|
+
`tableId: ${tableIdType} | null`,
|
|
2123
|
+
'cellId: ' + cellIdsType + OR_UNDEFINED,
|
|
2124
|
+
'descending: boolean',
|
|
2125
|
+
'offset: number',
|
|
2126
|
+
'limit: number' + OR_UNDEFINED,
|
|
2127
|
+
),
|
|
2128
|
+
getListenerHookParamsInCall(
|
|
2129
|
+
'tableId',
|
|
2130
|
+
'cellId',
|
|
2131
|
+
'descending',
|
|
2132
|
+
'offset',
|
|
2133
|
+
'limit',
|
|
2134
|
+
),
|
|
2135
|
+
);
|
|
2136
|
+
addProxyHook(
|
|
2137
|
+
ROW + LISTENER,
|
|
2138
|
+
ROW + LISTENER,
|
|
2139
|
+
VOID,
|
|
2140
|
+
getListenerDoc(5, 3),
|
|
2141
|
+
getListenerHookParams(
|
|
2142
|
+
rowListenerType,
|
|
2143
|
+
`tableId: ${tableIdType} | null`,
|
|
2144
|
+
ROW_ID + `: IdOrNull`,
|
|
2145
|
+
),
|
|
2146
|
+
getListenerHookParamsInCall('tableId', ROW_ID),
|
|
2147
|
+
);
|
|
2148
|
+
addProxyHook(
|
|
2149
|
+
CELL_IDS + LISTENER,
|
|
2150
|
+
CELL_IDS + LISTENER,
|
|
2151
|
+
VOID,
|
|
2152
|
+
getListenerDoc(6, 5, 1),
|
|
2153
|
+
getListenerHookParams(
|
|
2154
|
+
cellIdsListenerType,
|
|
2155
|
+
`tableId: ${tableIdType} | null`,
|
|
2156
|
+
ROW_ID + `: IdOrNull`,
|
|
2157
|
+
),
|
|
2158
|
+
getListenerHookParamsInCall('tableId', ROW_ID),
|
|
2159
|
+
);
|
|
2160
|
+
addProxyHook(
|
|
2161
|
+
CELL + LISTENER,
|
|
2162
|
+
CELL + LISTENER,
|
|
2163
|
+
VOID,
|
|
2164
|
+
getListenerDoc(7, 5),
|
|
2165
|
+
getListenerHookParams(
|
|
2166
|
+
cellListenerType,
|
|
2167
|
+
`tableId: ${tableIdType} | null`,
|
|
2168
|
+
ROW_ID + `: IdOrNull`,
|
|
2169
|
+
`cellId: ${cellIdsType} | null`,
|
|
2170
|
+
),
|
|
2171
|
+
getListenerHookParamsInCall('tableId', ROW_ID, 'cellId'),
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
if (!objIsEmpty(valuesSchema)) {
|
|
2175
|
+
const [
|
|
2176
|
+
valuesType,
|
|
2177
|
+
valuesWhenSetType,
|
|
2178
|
+
valueIdType,
|
|
2179
|
+
valuesListenerType,
|
|
2180
|
+
valueIdsListenerType,
|
|
2181
|
+
valueListenerType,
|
|
2182
|
+
] = sharedValueTypes;
|
|
2183
|
+
addImport(null, moduleDefinition, ...sharedValueTypes);
|
|
2184
|
+
addImport(1, moduleDefinition, storeType);
|
|
2185
|
+
const getDefaultValueComponent = addInternalFunction(
|
|
2186
|
+
'getDefaultValueComponent',
|
|
2187
|
+
'valueId: Id',
|
|
2188
|
+
join(
|
|
2189
|
+
mapValuesSchema(
|
|
2190
|
+
(_, _2, _3, VALUE_ID, valueName) =>
|
|
2191
|
+
`valueId == ${VALUE_ID} ? ` + valueName + 'ValueView : ',
|
|
2192
|
+
),
|
|
2193
|
+
) + NullComponent,
|
|
2194
|
+
);
|
|
2195
|
+
addProxyHook(
|
|
2196
|
+
VALUES,
|
|
2197
|
+
VALUES,
|
|
2198
|
+
valuesType,
|
|
2199
|
+
getTheContentOfTheStoreDoc(2, 0) + AND_REGISTERS,
|
|
2200
|
+
);
|
|
2201
|
+
const useValueIds = addProxyHook(
|
|
2202
|
+
VALUE_IDS,
|
|
2203
|
+
VALUE_IDS,
|
|
2204
|
+
valueIdType + SQUARE_BRACKETS,
|
|
2205
|
+
getIdsDoc(VALUE, THE_STORE) + AND_REGISTERS,
|
|
2206
|
+
);
|
|
2207
|
+
addProxyHook(
|
|
2208
|
+
SET + VALUES + CALLBACK,
|
|
2209
|
+
SET + VALUES + CALLBACK,
|
|
2210
|
+
PARAMETERIZED_CALLBACK,
|
|
2211
|
+
getTheContentOfTheStoreDoc(2, 9) + BASED_ON_A_PARAMETER,
|
|
2212
|
+
getParameterList(
|
|
2213
|
+
getGet(VALUES) + GETTER_ARGS + valuesWhenSetType,
|
|
2214
|
+
getGet(VALUES) + DEPS_SUFFIX,
|
|
2215
|
+
),
|
|
2216
|
+
getGetAndGetDeps(VALUES),
|
|
2217
|
+
GENERIC_PARAMETER,
|
|
2218
|
+
getParameterList(
|
|
2219
|
+
THEN_PREFIX,
|
|
2220
|
+
`values: ${valuesWhenSetType})` + RETURNS_VOID,
|
|
2221
|
+
THEN_DEPS,
|
|
2222
|
+
),
|
|
2223
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2224
|
+
);
|
|
2225
|
+
addProxyHook(
|
|
2226
|
+
SET + PARTIAL + VALUES + CALLBACK,
|
|
2227
|
+
SET + PARTIAL + VALUES + CALLBACK,
|
|
2228
|
+
PARAMETERIZED_CALLBACK,
|
|
2229
|
+
getTheContentOfTheStoreDoc(2, 11) + BASED_ON_A_PARAMETER,
|
|
2230
|
+
getParameterList(
|
|
2231
|
+
getGet(PARTIAL + VALUES) + GETTER_ARGS + valuesWhenSetType,
|
|
2232
|
+
getGet(PARTIAL + VALUES) + DEPS_SUFFIX,
|
|
2233
|
+
),
|
|
2234
|
+
getGetAndGetDeps(PARTIAL + VALUES),
|
|
2235
|
+
GENERIC_PARAMETER,
|
|
2236
|
+
getParameterList(
|
|
2237
|
+
THEN_PREFIX,
|
|
2238
|
+
`partialValues: ${valuesWhenSetType})` + RETURNS_VOID,
|
|
2239
|
+
THEN_DEPS,
|
|
2240
|
+
),
|
|
2241
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2242
|
+
);
|
|
2243
|
+
addProxyHook(
|
|
2244
|
+
DEL + VALUES + CALLBACK,
|
|
2245
|
+
DEL + VALUES + CALLBACK,
|
|
2246
|
+
CALLBACK,
|
|
2247
|
+
getTheContentOfTheStoreDoc(2, 12),
|
|
2248
|
+
EMPTY_STRING,
|
|
2249
|
+
EMPTY_STRING,
|
|
2250
|
+
EMPTY_STRING,
|
|
2251
|
+
THEN_AND_THEN_DEPS,
|
|
2252
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2253
|
+
);
|
|
2254
|
+
const valuePropsType = addType(
|
|
2255
|
+
VALUE + PROPS,
|
|
2256
|
+
getPropsTypeList(
|
|
2257
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
2258
|
+
DEBUG_IDS_PROP_TYPE,
|
|
2259
|
+
),
|
|
2260
|
+
getPropsDoc('a Value'),
|
|
2261
|
+
);
|
|
2262
|
+
const valuesPropsType = addType(
|
|
2263
|
+
VALUES + PROPS,
|
|
2264
|
+
getPropsTypeList(
|
|
2265
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
2266
|
+
'valueComponents?: {' +
|
|
2267
|
+
join(
|
|
2268
|
+
mapValuesSchema(
|
|
2269
|
+
(valueId) => `'${valueId}'?: ComponentType<${valuePropsType}>`,
|
|
2270
|
+
),
|
|
2271
|
+
', ',
|
|
2272
|
+
) +
|
|
2273
|
+
'}',
|
|
2274
|
+
`getValueComponentProps?: (valueId: ${valueIdType}) => ExtraProps`,
|
|
2275
|
+
SEPARATOR_PROP_TYPE,
|
|
2276
|
+
DEBUG_IDS_PROP_TYPE,
|
|
2277
|
+
),
|
|
2278
|
+
getPropsDoc(getTheContentOfDoc(2, 1)),
|
|
2279
|
+
);
|
|
2280
|
+
addImport(1, uiReactModuleDefinition, valuesPropsType, valuePropsType);
|
|
2281
|
+
addComponent(
|
|
2282
|
+
VALUES + VIEW,
|
|
2283
|
+
'{' +
|
|
2284
|
+
storeInstance +
|
|
2285
|
+
', valueComponents, getValueComponentProps' +
|
|
2286
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
2287
|
+
'}: ' +
|
|
2288
|
+
valuesPropsType,
|
|
2289
|
+
[
|
|
2290
|
+
wrap + `(${useValueIds}(${storeInstance}).map((valueId) => {`,
|
|
2291
|
+
'const Value = valueComponents?.[valueId] ?? ' +
|
|
2292
|
+
getDefaultValueComponent +
|
|
2293
|
+
'(valueId);',
|
|
2294
|
+
'return <Value',
|
|
2295
|
+
`{...${getProps}(getValueComponentProps, valueId)}`,
|
|
2296
|
+
'key={valueId}',
|
|
2297
|
+
storeProp,
|
|
2298
|
+
DEBUG_IDS_PROP,
|
|
2299
|
+
'/>;',
|
|
2300
|
+
'}), separator)',
|
|
2301
|
+
],
|
|
2302
|
+
getTheContentOfTheStoreDoc(2, 13) + AND_REGISTERS,
|
|
2303
|
+
);
|
|
2304
|
+
mapValuesSchema((valueId, type, _, VALUE_ID, valueName) => {
|
|
2305
|
+
const mapValueType = 'Map' + camel(type, 1);
|
|
2306
|
+
addImport(0, moduleDefinition, mapValueType);
|
|
2307
|
+
addImport(1, moduleDefinition, mapValueType);
|
|
2308
|
+
const useValue = addProxyHook(
|
|
2309
|
+
valueName + VALUE,
|
|
2310
|
+
VALUE,
|
|
2311
|
+
type,
|
|
2312
|
+
getValueContentDoc(valueId) + AND_REGISTERS,
|
|
2313
|
+
EMPTY_STRING,
|
|
2314
|
+
VALUE_ID,
|
|
2315
|
+
);
|
|
2316
|
+
addProxyHook(
|
|
2317
|
+
SET + valueName + VALUE + CALLBACK,
|
|
2318
|
+
SET + VALUE + CALLBACK,
|
|
2319
|
+
PARAMETERIZED_CALLBACK,
|
|
2320
|
+
getValueContentDoc(valueId, 9) + BASED_ON_A_PARAMETER,
|
|
2321
|
+
getParameterList(
|
|
2322
|
+
getGet(VALUE) + GETTER_ARGS + type + ' | ' + mapValueType,
|
|
2323
|
+
getGet(VALUE) + DEPS_SUFFIX,
|
|
2324
|
+
),
|
|
2325
|
+
getParameterList(VALUE_ID, getGetAndGetDeps(VALUE)),
|
|
2326
|
+
GENERIC_PARAMETER,
|
|
2327
|
+
getParameterList(
|
|
2328
|
+
THEN_PREFIX,
|
|
2329
|
+
`value: ${type} | ${mapValueType})` + RETURNS_VOID,
|
|
2330
|
+
THEN_DEPS,
|
|
2331
|
+
),
|
|
2332
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2333
|
+
);
|
|
2334
|
+
addProxyHook(
|
|
2335
|
+
DEL + valueName + VALUE + CALLBACK,
|
|
2336
|
+
DEL + VALUE + CALLBACK,
|
|
2337
|
+
CALLBACK,
|
|
2338
|
+
getValueContentDoc(valueId, 12),
|
|
2339
|
+
EMPTY_STRING,
|
|
2340
|
+
VALUE_ID,
|
|
2341
|
+
EMPTY_STRING,
|
|
2342
|
+
THEN_AND_THEN_DEPS,
|
|
2343
|
+
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2344
|
+
);
|
|
2345
|
+
addComponent(
|
|
2346
|
+
valueName + VALUE + VIEW,
|
|
2347
|
+
`{${storeInstance}, debugIds}: ` + valuePropsType,
|
|
2348
|
+
[
|
|
2349
|
+
wrap +
|
|
2350
|
+
`('' + ${useValue}(` +
|
|
2351
|
+
storeInstance +
|
|
2352
|
+
`) ?? '', undefined, debugIds, ${VALUE_ID})`,
|
|
2353
|
+
],
|
|
2354
|
+
getValueContentDoc(valueId, 13) + AND_REGISTERS,
|
|
2355
|
+
);
|
|
2356
|
+
});
|
|
2357
|
+
addProxyHook(
|
|
2358
|
+
VALUES + LISTENER,
|
|
2359
|
+
VALUES + LISTENER,
|
|
2360
|
+
VOID,
|
|
2361
|
+
getTheContentOfTheStoreDoc(2, 8) + ' changes',
|
|
2362
|
+
getListenerHookParams(valuesListenerType),
|
|
2363
|
+
getListenerHookParamsInCall(),
|
|
2364
|
+
);
|
|
2365
|
+
addProxyHook(
|
|
2366
|
+
VALUE_IDS + LISTENER,
|
|
2367
|
+
VALUE_IDS + LISTENER,
|
|
2368
|
+
VOID,
|
|
2369
|
+
getListenerDoc(10, 0, 1),
|
|
2370
|
+
getListenerHookParams(valueIdsListenerType),
|
|
2371
|
+
getListenerHookParamsInCall(),
|
|
2372
|
+
);
|
|
2373
|
+
addProxyHook(
|
|
2374
|
+
VALUE + LISTENER,
|
|
2375
|
+
VALUE + LISTENER,
|
|
2376
|
+
VOID,
|
|
2377
|
+
getListenerDoc(11, 0),
|
|
2378
|
+
getListenerHookParams(
|
|
2379
|
+
valueListenerType,
|
|
2380
|
+
`valueId: ${valueIdType} | null`,
|
|
2381
|
+
),
|
|
2382
|
+
getListenerHookParamsInCall('valueId'),
|
|
2383
|
+
);
|
|
2384
|
+
}
|
|
2385
|
+
addComponent(
|
|
2386
|
+
PROVIDER,
|
|
2387
|
+
`{${storeInstance}, ${storeInstance}ById, children}: ` +
|
|
2388
|
+
providerPropsType +
|
|
2389
|
+
' & {children: React.ReactNode}',
|
|
2390
|
+
[
|
|
2391
|
+
'{',
|
|
2392
|
+
USE_CONTEXT,
|
|
2393
|
+
'return (',
|
|
2394
|
+
'<Context.' + PROVIDER,
|
|
2395
|
+
'value={useMemo(',
|
|
2396
|
+
`() => [${storeInstance} ?? contextValue[0], {...contextValue[1], ...${storeInstance}ById}],`,
|
|
2397
|
+
`[${storeInstance}, ${storeInstance}ById, contextValue],`,
|
|
2398
|
+
')}>',
|
|
2399
|
+
'{children}',
|
|
2400
|
+
`</Context.${PROVIDER}>`,
|
|
2401
|
+
');',
|
|
2402
|
+
'}',
|
|
2403
|
+
],
|
|
2404
|
+
'Wraps part of an application in a context that provides default objects to be used by hooks and components within',
|
|
2405
|
+
);
|
|
2406
|
+
return [
|
|
2407
|
+
build(...getImports(0), ...getTypes(), ...getFunctions(0)),
|
|
2408
|
+
build(...getImports(1), ...getConstants(), ...getFunctions(1)),
|
|
2409
|
+
];
|
|
2410
|
+
};
|
|
2411
|
+
|
|
2412
|
+
const getStoreApi = (tablesSchema, valuesSchema, module) => {
|
|
2413
|
+
if (objIsEmpty(tablesSchema) && objIsEmpty(valuesSchema)) {
|
|
2414
|
+
return [EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING];
|
|
2415
|
+
}
|
|
2416
|
+
const [dTsCore, tsCore, sharedTableTypes, sharedValueTypes] = getStoreCoreApi(
|
|
2417
|
+
tablesSchema,
|
|
2418
|
+
valuesSchema,
|
|
2419
|
+
module,
|
|
2420
|
+
);
|
|
2421
|
+
return [
|
|
2422
|
+
dTsCore,
|
|
2423
|
+
tsCore,
|
|
2424
|
+
...getStoreUiReactApi(
|
|
2425
|
+
tablesSchema,
|
|
2426
|
+
valuesSchema,
|
|
2427
|
+
module,
|
|
2428
|
+
sharedTableTypes,
|
|
2429
|
+
sharedValueTypes,
|
|
1194
2430
|
),
|
|
1195
2431
|
];
|
|
1196
2432
|
};
|
|
@@ -1294,14 +2530,17 @@ const createTools = getCreateFunction((store) => {
|
|
|
1294
2530
|
const getStoreApi$1 = (module) =>
|
|
1295
2531
|
getStoreApi(getStoreTablesSchema(), getStoreValuesSchema(), module);
|
|
1296
2532
|
const getPrettyStoreApi = async (module) => {
|
|
2533
|
+
const extensions = ['d.ts', 'ts', 'd.ts', 'tsx'];
|
|
1297
2534
|
let format;
|
|
1298
2535
|
try {
|
|
1299
2536
|
format = (await import('prettier')).format;
|
|
1300
|
-
} catch {
|
|
2537
|
+
} catch (e) {
|
|
1301
2538
|
format = (str) => str;
|
|
1302
2539
|
}
|
|
1303
|
-
return arrayMap(getStoreApi$1(module), (file) =>
|
|
1304
|
-
formatJsDoc(
|
|
2540
|
+
return arrayMap(getStoreApi$1(module), (file, f) =>
|
|
2541
|
+
formatJsDoc(
|
|
2542
|
+
format(file, {...prettierConfig, filepath: `_.${extensions[f]}`}),
|
|
2543
|
+
),
|
|
1305
2544
|
);
|
|
1306
2545
|
};
|
|
1307
2546
|
const getStore = () => store;
|