tinybase 2.0.0-beta.2 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.js +1 -4
- package/lib/debug/indexes.js +1 -3
- package/lib/debug/metrics.js +1 -4
- package/lib/debug/queries.d.ts +61 -296
- package/lib/debug/queries.js +59 -201
- package/lib/debug/relationships.js +1 -4
- package/lib/debug/store.d.ts +112 -90
- package/lib/debug/store.js +90 -149
- package/lib/debug/tinybase.js +130 -333
- package/lib/debug/ui-react.d.ts +81 -81
- package/lib/debug/ui-react.js +138 -173
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/queries.d.ts +61 -296
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +112 -90
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +81 -81
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +9 -9
- package/readme.md +2 -2
package/lib/checkpoints.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),o=(e,...t)=>e.push(...t),s=e=>e.pop(),l=e=>null==e,c=(e,t,n)=>l(e)?n?.():t(e),i=(e,t)=>e?.has(t)??!1,a=e=>l(e)||0==(e=>e.size)(e),d=(e,t)=>e?.forEach(t),u=(e,t)=>e?.delete(t),h=e=>new Map(e),p=(e,t)=>e?.get(t),C=(e,t,n)=>l(n)?(u(e,t),e):e?.set(t,n),g=(e,t,n)=>(i(e,t)||C(e,t,n()),p(e,t)),k=(e,t,r,o,s=0)=>c((r?g:p)(e,t[s],s>n(t)-2?r:h),(l=>{if(s>n(t)-2)return o?.(l)&&C(e,t[s]),l;const c=k(l,t,r,o,s+1);return a(l)&&C(e,t[s]),c})),f=e=>new Set(e),v=(e,r=[""])=>{const s=[],l=(e,c)=>c==n(r)?o(s,e):null===r[c]?d(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(p(e,t),c+1)));return l(e,0),s}
|
|
1
|
+
const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),o=(e,...t)=>e.push(...t),s=e=>e.pop(),l=e=>null==e,c=(e,t,n)=>l(e)?n?.():t(e),i=(e,t)=>e?.has(t)??!1,a=e=>l(e)||0==(e=>e.size)(e),d=(e,t)=>e?.forEach(t),u=(e,t)=>e?.delete(t),h=e=>new Map(e),p=(e,t)=>e?.get(t),C=(e,t,n)=>l(n)?(u(e,t),e):e?.set(t,n),g=(e,t,n)=>(i(e,t)||C(e,t,n()),p(e,t)),k=(e,t,r,o,s=0)=>c((r?g:p)(e,t[s],s>n(t)-2?r:h),(l=>{if(s>n(t)-2)return o?.(l)&&C(e,t[s]),l;const c=k(l,t,r,o,s+1);return a(l)&&C(e,t[s]),c})),f=e=>new Set(e),v=e=>{let r,i=0;const g=[],v=h();return[(t,n,o)=>{r??=e();const l=s(g)??""+i++;var c,a;return C(v,l,[t,n,o]),c=k(n,o??[""],f),a=l,c?.add(a),l},(e,s,...l)=>t(((e,r=[""])=>{const s=[],l=(e,c)=>c==n(r)?o(s,e):null===r[c]?d(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(p(e,t),c+1)));return l(e,0),s})(e,s),(e=>d(e,(e=>p(v,e)[0](r,...s??[],...l))))),e=>c(p(v,e),(([,t,r])=>(k(t,r??[""],void 0,(t=>(u(t,e),a(t)?1:0))),C(v,e),n(g)<1e3&&o(g,e),r))),(e,o,s)=>c(p(v,e),(([e,,c=[]])=>{const i=(...a)=>{const d=n(a);d==n(c)?e(r,...a,...s(a)):l(c[d])?t(o[d](...a),(e=>i(...a,e))):i(...a,c[d])};i()}))]},L=Object.freeze,w=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((u=>{let k,f,w,S=100,z=h(),E=1;const I=h(),M=h(),[b,j,x]=v((()=>Q)),y=h(),B=h(),F=[],O=[],T=(e,t)=>{E=0,u.transaction((()=>d(p(y,t),((t,n)=>d(t,((t,r)=>d(t,((t,o)=>((e,t,n,r,o)=>l(o)?e.delCell(t,n,r,!0):e.setCell(t,n,r,o))(u,n,r,o,t[e]))))))))),E=1},W=e=>{C(y,e),C(B,e),j(M,[e])},m=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),W),q=()=>m(F,n(F)-S),A=u.addCellListener(null,null,null,((e,t,n,r,l,i)=>{if(E){c(k,(()=>{o(F,k),q(),m(O),k=void 0,w=1}));const e=g(z,t,h),d=g(e,n,h),u=g(d,r,(()=>[i,void 0]));u[1]=l,u[0]===l&&a(C(d,r))&&a(C(e,n))&&a(C(z,t))&&(k=s(F),w=1),J()}})),D=(e="")=>(l(k)&&(k=""+f++,C(y,k,z),N(k,e),z=h(),w=1),k),G=()=>{r(F)||(O.unshift(D()),T(0,k),k=s(F),w=1)},H=()=>{r(O)||(o(F,k),k=O.shift(),T(1,k),w=1)},J=()=>{w&&(j(I),w=0)},K=e=>{const t=D(e);return J(),t},N=(e,t)=>(P(e)&&p(B,e)!==t&&(C(B,e,t),j(M,[e])),Q),P=e=>i(y,e),Q={setSize:e=>(S=e,q(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>u,getCheckpointIds:()=>[[...F],k,[...O]],forEachCheckpoint:e=>{return t=e,d(B,((e,n)=>t(n,e)));var t},hasCheckpoint:P,getCheckpoint:e=>p(B,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:t=>{const n=e(F,t)?G:e(O,t)?H:null;for(;!l(n)&&t!=k;)n();return J(),Q},addCheckpointIdsListener:e=>b(e,I),addCheckpointListener:(e,t)=>b(t,M,[e]),delListener:e=>(x(e),Q),clear:()=>(m(F),m(O),l(k)||W(k),k=void 0,f=0,K(),Q),destroy:()=>{u.delListener(A)},getListenerStats:()=>({})};return L(Q.clear())}));export{w as createCheckpoints};
|
package/lib/checkpoints.js.gz
CHANGED
|
Binary file
|
package/lib/debug/checkpoints.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const EMPTY_STRING = '';
|
|
2
2
|
|
|
3
3
|
const arrayHas = (array, value) => array.includes(value);
|
|
4
|
-
const arrayEvery = (array, cb) => array.every(cb);
|
|
5
4
|
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
6
5
|
const arrayLength = (array) => array.length;
|
|
7
6
|
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
@@ -112,8 +111,6 @@ const getListenerFunctions = (getThing) => {
|
|
|
112
111
|
}
|
|
113
112
|
return idOrNulls;
|
|
114
113
|
});
|
|
115
|
-
const hasListeners = (idSetNode, ids) =>
|
|
116
|
-
!arrayEvery(getWildcardedLeaves(idSetNode, ids), isUndefined);
|
|
117
114
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
|
118
115
|
ifNotUndefined(mapGet(allListeners, id), ([listener, , idOrNulls = []]) => {
|
|
119
116
|
const callWithIds = (...ids) => {
|
|
@@ -128,7 +125,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
128
125
|
};
|
|
129
126
|
callWithIds();
|
|
130
127
|
});
|
|
131
|
-
return [addListener, callListeners, delListener,
|
|
128
|
+
return [addListener, callListeners, delListener, callListener];
|
|
132
129
|
};
|
|
133
130
|
|
|
134
131
|
const object = Object;
|
package/lib/debug/indexes.js
CHANGED
|
@@ -265,8 +265,6 @@ const getListenerFunctions = (getThing) => {
|
|
|
265
265
|
}
|
|
266
266
|
return idOrNulls;
|
|
267
267
|
});
|
|
268
|
-
const hasListeners = (idSetNode, ids) =>
|
|
269
|
-
!arrayEvery(getWildcardedLeaves(idSetNode, ids), isUndefined);
|
|
270
268
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
|
271
269
|
ifNotUndefined(mapGet(allListeners, id), ([listener, , idOrNulls = []]) => {
|
|
272
270
|
const callWithIds = (...ids) => {
|
|
@@ -281,7 +279,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
281
279
|
};
|
|
282
280
|
callWithIds();
|
|
283
281
|
});
|
|
284
|
-
return [addListener, callListeners, delListener,
|
|
282
|
+
return [addListener, callListeners, delListener, callListener];
|
|
285
283
|
};
|
|
286
284
|
|
|
287
285
|
const object = Object;
|
package/lib/debug/metrics.js
CHANGED
|
@@ -7,7 +7,6 @@ const AVG = 'avg';
|
|
|
7
7
|
const MIN = 'min';
|
|
8
8
|
const MAX = 'max';
|
|
9
9
|
|
|
10
|
-
const arrayEvery = (array, cb) => array.every(cb);
|
|
11
10
|
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
12
11
|
const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
|
|
13
12
|
const arrayLength = (array) => array.length;
|
|
@@ -336,8 +335,6 @@ const getListenerFunctions = (getThing) => {
|
|
|
336
335
|
}
|
|
337
336
|
return idOrNulls;
|
|
338
337
|
});
|
|
339
|
-
const hasListeners = (idSetNode, ids) =>
|
|
340
|
-
!arrayEvery(getWildcardedLeaves(idSetNode, ids), isUndefined);
|
|
341
338
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
|
342
339
|
ifNotUndefined(mapGet(allListeners, id), ([listener, , idOrNulls = []]) => {
|
|
343
340
|
const callWithIds = (...ids) => {
|
|
@@ -352,7 +349,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
352
349
|
};
|
|
353
350
|
callWithIds();
|
|
354
351
|
});
|
|
355
|
-
return [addListener, callListeners, delListener,
|
|
352
|
+
return [addListener, callListeners, delListener, callListener];
|
|
356
353
|
};
|
|
357
354
|
|
|
358
355
|
const object = Object;
|
package/lib/debug/queries.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
Table,
|
|
25
25
|
TableCallback,
|
|
26
26
|
} from './store.d';
|
|
27
|
-
import {Id, IdOrNull, Ids
|
|
27
|
+
import {Id, IdOrNull, Ids} from './common.d';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* The Aggregate type describes a custom function that takes an array of Cell
|
|
@@ -203,15 +203,18 @@ export type ResultRowIdsListener = (queries: Queries, tableId: Id) => void;
|
|
|
203
203
|
*
|
|
204
204
|
* When called, a ResultSortedRowIdsListener is given a reference to the Queries
|
|
205
205
|
* object, the Id of the Table whose Row Ids changed (which is the same as the
|
|
206
|
-
* query Id), the Cell Id being used to sort them,
|
|
207
|
-
*
|
|
208
|
-
*
|
|
206
|
+
* query Id), the Cell Id being used to sort them, whether descending or not,
|
|
207
|
+
* and the offset and limit of the number of Ids returned, for pagination
|
|
208
|
+
* purposes. It also receives the sorted array of Ids itself, so that you can
|
|
209
|
+
* use them in the listener without the additional cost of an explicit call to
|
|
209
210
|
* getResultSortedRowIds.
|
|
210
211
|
*
|
|
211
212
|
* @param queries A reference to the Queries object that changed.
|
|
212
213
|
* @param tableId The Id of the Table that changed, which is also the query Id.
|
|
213
214
|
* @param cellId The Id of the Cell whose values were used for the sorting.
|
|
214
215
|
* @param descending Whether the sorting was in descending order.
|
|
216
|
+
* @param offset The number of Row Ids skipped.
|
|
217
|
+
* @param limit The maximum number of Row Ids returned.
|
|
215
218
|
* @param sortedRowIds The sorted Row Ids themselves.
|
|
216
219
|
* @category Listener
|
|
217
220
|
* @since v2.0.0-beta
|
|
@@ -221,6 +224,8 @@ export type ResultSortedRowIdsListener = (
|
|
|
221
224
|
tableId: Id,
|
|
222
225
|
cellId: Id | undefined,
|
|
223
226
|
descending: boolean,
|
|
227
|
+
offset: number,
|
|
228
|
+
limit: number | undefined,
|
|
224
229
|
sortedRowIds: Ids,
|
|
225
230
|
) => void;
|
|
226
231
|
|
|
@@ -1323,212 +1328,6 @@ export type Having = {
|
|
|
1323
1328
|
(condition: (getSelectedOrGroupedCell: GetCell) => boolean): void;
|
|
1324
1329
|
};
|
|
1325
1330
|
|
|
1326
|
-
/**
|
|
1327
|
-
* The Order type describes a function that lets you specify how you want the
|
|
1328
|
-
* Rows in the result Table to be ordered, based on values within.
|
|
1329
|
-
*
|
|
1330
|
-
* The Order function is provided as an parameter in the `build` parameter of
|
|
1331
|
-
* the setQueryDefinition method.
|
|
1332
|
-
*
|
|
1333
|
-
* An Order clause can either order alphanumerically by the value of a single
|
|
1334
|
-
* Cell or by a 'sort key' calculated from Cell values. The alphanumeric sorting
|
|
1335
|
-
* will be ascending by default, or descending if the second parameter is set to
|
|
1336
|
-
* `true`.
|
|
1337
|
-
*
|
|
1338
|
-
* This is applied after any grouping.
|
|
1339
|
-
*
|
|
1340
|
-
* It is possible to provide multiple Order clauses, and a later clause will be
|
|
1341
|
-
* used to establish the order of pairs of Rows if the earlier clauses have not
|
|
1342
|
-
* been able to.
|
|
1343
|
-
*
|
|
1344
|
-
* Note that the Order clause does not work by changing the Row Ids of the
|
|
1345
|
-
* result Table, but by changing their insert order. Therefore the Ids array
|
|
1346
|
-
* returned from the getResultRowIds method will be correctly ordered, even if
|
|
1347
|
-
* the Ids themselves might seem out of order based on their values. If you _do_
|
|
1348
|
-
* want to sort Rows by their Id, that is provided as a second parameter to the
|
|
1349
|
-
* getSortKey callback.
|
|
1350
|
-
*
|
|
1351
|
-
* Importantly, if you are using the addResultRowIdsListener method to listen to
|
|
1352
|
-
* changes to the order of Rows due to this clause, you will need to set the
|
|
1353
|
-
* optional `trackReorder` parameter to `true` to track when the set of Ids has
|
|
1354
|
-
* not changed, but the order has.
|
|
1355
|
-
*
|
|
1356
|
-
* @example
|
|
1357
|
-
* This example shows a query that orders a Table by a numeric Cell, in a
|
|
1358
|
-
* descending fashion.
|
|
1359
|
-
*
|
|
1360
|
-
* ```js
|
|
1361
|
-
* const store = createStore().setTable('pets', {
|
|
1362
|
-
* cujo: {price: 4},
|
|
1363
|
-
* fido: {price: 5},
|
|
1364
|
-
* tom: {price: 3},
|
|
1365
|
-
* carnaby: {price: 3},
|
|
1366
|
-
* felix: {price: 4},
|
|
1367
|
-
* polly: {price: 3},
|
|
1368
|
-
* });
|
|
1369
|
-
*
|
|
1370
|
-
* const queries = createQueries(store);
|
|
1371
|
-
* queries.setQueryDefinition('query', 'pets', ({select, order}) => {
|
|
1372
|
-
* select('pets', 'price');
|
|
1373
|
-
* order('price', true);
|
|
1374
|
-
* });
|
|
1375
|
-
*
|
|
1376
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1377
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1378
|
-
* });
|
|
1379
|
-
* // -> {fido: {price: 5}}
|
|
1380
|
-
* // -> {cujo: {price: 4}}
|
|
1381
|
-
* // -> {felix: {price: 4}}
|
|
1382
|
-
* // -> {tom: {price: 3}}
|
|
1383
|
-
* // -> {carnaby: {price: 3}}
|
|
1384
|
-
* // -> {polly: {price: 3}}
|
|
1385
|
-
* ```
|
|
1386
|
-
* @example
|
|
1387
|
-
* This example shows a query that orders a Table by a string Cell, and then a
|
|
1388
|
-
* calculated sort key based on the Row Id.
|
|
1389
|
-
*
|
|
1390
|
-
* ```js
|
|
1391
|
-
* const store = createStore().setTable('pets', {
|
|
1392
|
-
* cujo: {species: 'dog'},
|
|
1393
|
-
* fido: {species: 'dog'},
|
|
1394
|
-
* tom: {species: 'cat'},
|
|
1395
|
-
* carnaby: {species: 'parrot'},
|
|
1396
|
-
* felix: {species: 'cat'},
|
|
1397
|
-
* polly: {species: 'parrot'},
|
|
1398
|
-
* });
|
|
1399
|
-
*
|
|
1400
|
-
* const queries = createQueries(store);
|
|
1401
|
-
* queries.setQueryDefinition('query', 'pets', ({select, order}) => {
|
|
1402
|
-
* select('pets', 'species');
|
|
1403
|
-
* order('species');
|
|
1404
|
-
* order((getSelectedOrGroupedCell, rowId) => rowId);
|
|
1405
|
-
* });
|
|
1406
|
-
*
|
|
1407
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1408
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1409
|
-
* });
|
|
1410
|
-
* // -> {felix: {species: 'cat'}}
|
|
1411
|
-
* // -> {tom: {species: 'cat'}}
|
|
1412
|
-
* // -> {cujo: {species: 'dog'}}
|
|
1413
|
-
* // -> {fido: {species: 'dog'}}
|
|
1414
|
-
* // -> {carnaby: {species: 'parrot'}}
|
|
1415
|
-
* // -> {polly: {species: 'parrot'}}
|
|
1416
|
-
* ```
|
|
1417
|
-
* @category Definition
|
|
1418
|
-
* @since v2.0.0-beta
|
|
1419
|
-
*/
|
|
1420
|
-
export type Order = {
|
|
1421
|
-
/**
|
|
1422
|
-
* Calling this function with the first parameter as an Id is used to sort the
|
|
1423
|
-
* Rows by the value in that Cell.
|
|
1424
|
-
*
|
|
1425
|
-
* @param selectedOrGroupedCellId The Id of the Cell in the query to sort by.
|
|
1426
|
-
* @param descending Set to `true` to have the Rows sorted in descending
|
|
1427
|
-
* order.
|
|
1428
|
-
*/
|
|
1429
|
-
(selectedOrGroupedCellId: Id, descending?: boolean): void;
|
|
1430
|
-
/**
|
|
1431
|
-
* Calling this function with the first parameter as a function is used to
|
|
1432
|
-
* sort the Rows by a value calculate from their Cells or Id.
|
|
1433
|
-
*
|
|
1434
|
-
* @param getSortKey A callback that takes a GetCell function and that should
|
|
1435
|
-
* return a 'sort key' to be used for ordering the Rows.
|
|
1436
|
-
* @param descending Set to `true` to have the Rows sorted in descending
|
|
1437
|
-
* order.
|
|
1438
|
-
*/
|
|
1439
|
-
(
|
|
1440
|
-
getSortKey: (getSelectedOrGroupedCell: GetCell, rowId: Id) => SortKey,
|
|
1441
|
-
descending?: boolean,
|
|
1442
|
-
): void;
|
|
1443
|
-
};
|
|
1444
|
-
|
|
1445
|
-
/**
|
|
1446
|
-
* The Limit type describes a function that lets you specify how many Rows you
|
|
1447
|
-
* want in the result Table, and how they should be offset.
|
|
1448
|
-
*
|
|
1449
|
-
* The Limit function is provided as an parameter in the `build` parameter of
|
|
1450
|
-
* the setQueryDefinition method.
|
|
1451
|
-
*
|
|
1452
|
-
* A Limit clause can either provide an 'page' offset and size limit, or just
|
|
1453
|
-
* the limit. The offset is zero-based, so if you specify `2`, say, the results
|
|
1454
|
-
* will skip the first two Rows and start with the third.
|
|
1455
|
-
*
|
|
1456
|
-
* This is applied after any grouping and sorting.
|
|
1457
|
-
*
|
|
1458
|
-
* @example
|
|
1459
|
-
* This example shows a query that limits a Table to four Rows from its first.
|
|
1460
|
-
*
|
|
1461
|
-
* ```js
|
|
1462
|
-
* const store = createStore().setTable('pets', {
|
|
1463
|
-
* cujo: {price: 4},
|
|
1464
|
-
* fido: {price: 5},
|
|
1465
|
-
* tom: {price: 3},
|
|
1466
|
-
* carnaby: {price: 3},
|
|
1467
|
-
* felix: {price: 4},
|
|
1468
|
-
* polly: {price: 3},
|
|
1469
|
-
* });
|
|
1470
|
-
*
|
|
1471
|
-
* const queries = createQueries(store);
|
|
1472
|
-
* queries.setQueryDefinition('query', 'pets', ({select, limit}) => {
|
|
1473
|
-
* select('pets', 'price');
|
|
1474
|
-
* limit(4);
|
|
1475
|
-
* });
|
|
1476
|
-
*
|
|
1477
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1478
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1479
|
-
* });
|
|
1480
|
-
* // -> {cujo: {price: 4}}
|
|
1481
|
-
* // -> {fido: {price: 5}}
|
|
1482
|
-
* // -> {tom: {price: 3}}
|
|
1483
|
-
* // -> {carnaby: {price: 3}}
|
|
1484
|
-
* ```
|
|
1485
|
-
* @example
|
|
1486
|
-
* This example shows a query that limits a Table to three Rows, offset by two.
|
|
1487
|
-
*
|
|
1488
|
-
* ```js
|
|
1489
|
-
* const store = createStore().setTable('pets', {
|
|
1490
|
-
* cujo: {price: 4},
|
|
1491
|
-
* fido: {price: 5},
|
|
1492
|
-
* tom: {price: 3},
|
|
1493
|
-
* carnaby: {price: 3},
|
|
1494
|
-
* felix: {price: 4},
|
|
1495
|
-
* polly: {price: 3},
|
|
1496
|
-
* });
|
|
1497
|
-
*
|
|
1498
|
-
* const queries = createQueries(store);
|
|
1499
|
-
* queries.setQueryDefinition('query', 'pets', ({select, limit}) => {
|
|
1500
|
-
* select('pets', 'price');
|
|
1501
|
-
* limit(2, 3);
|
|
1502
|
-
* });
|
|
1503
|
-
*
|
|
1504
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1505
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1506
|
-
* });
|
|
1507
|
-
* // -> {tom: {price: 3}}
|
|
1508
|
-
* // -> {carnaby: {price: 3}}
|
|
1509
|
-
* // -> {felix: {price: 4}}
|
|
1510
|
-
* ```
|
|
1511
|
-
* @category Definition
|
|
1512
|
-
* @since v2.0.0-beta
|
|
1513
|
-
*/
|
|
1514
|
-
export type Limit = {
|
|
1515
|
-
/**
|
|
1516
|
-
* Calling this function with one numeric parameter is used to limit the Rows
|
|
1517
|
-
* returned, starting from the first.
|
|
1518
|
-
*
|
|
1519
|
-
* @param limit The number of Rows to return.
|
|
1520
|
-
*/
|
|
1521
|
-
(limit: number): void;
|
|
1522
|
-
/**
|
|
1523
|
-
* Calling this function with two numeric parameters is used to offset the
|
|
1524
|
-
* start of the results, and then limit the Rows returned.
|
|
1525
|
-
*
|
|
1526
|
-
* @param offset The number of Rows to skip.
|
|
1527
|
-
* @param limit The number of Rows to return.
|
|
1528
|
-
*/
|
|
1529
|
-
(offset: number, limit: number): void;
|
|
1530
|
-
};
|
|
1531
|
-
|
|
1532
1331
|
/**
|
|
1533
1332
|
* A Queries object lets you create and track queries of the data in Store
|
|
1534
1333
|
* objects.
|
|
@@ -1590,33 +1389,32 @@ export type Limit = {
|
|
|
1590
1389
|
* console.log(queries.getResultTable('petOwners'));
|
|
1591
1390
|
* // -> {fido: {owner: 'Alice'}, felix: {owner: 'Bob'}, cujo: {owner: 'Carol'}}
|
|
1592
1391
|
*
|
|
1593
|
-
* // A grouped
|
|
1392
|
+
* // A grouped query:
|
|
1594
1393
|
* queries.setQueryDefinition(
|
|
1595
1394
|
* 'colorPrice',
|
|
1596
1395
|
* 'pets',
|
|
1597
|
-
* ({select, join, group
|
|
1396
|
+
* ({select, join, group}) => {
|
|
1598
1397
|
* select('color');
|
|
1599
1398
|
* select('species', 'price');
|
|
1600
1399
|
* join('species', 'species');
|
|
1601
1400
|
* group('price', 'avg');
|
|
1602
|
-
* order('price');
|
|
1603
1401
|
* },
|
|
1604
1402
|
* );
|
|
1605
1403
|
* console.log(queries.getResultTable('colorPrice'));
|
|
1606
1404
|
* // -> {"1": {color: 'black', price: 4.5}, "0": {color: 'brown', price: 5}}
|
|
1607
|
-
* console.log(queries.
|
|
1608
|
-
* // -> ["
|
|
1405
|
+
* console.log(queries.getResultSortedRowIds('colorPrice', 'price', true));
|
|
1406
|
+
* // -> ["0", "1"]
|
|
1609
1407
|
*
|
|
1610
1408
|
* const listenerId = queries.addResultTableListener('colorPrice', () => {
|
|
1611
1409
|
* console.log('Average prices per color changed');
|
|
1612
1410
|
* console.log(queries.getResultTable('colorPrice'));
|
|
1613
|
-
* console.log(queries.
|
|
1411
|
+
* console.log(queries.getResultSortedRowIds('colorPrice', 'price', true));
|
|
1614
1412
|
* });
|
|
1615
1413
|
*
|
|
1616
1414
|
* store.setRow('pets', 'lowly', {species: 'worm', color: 'brown'});
|
|
1617
1415
|
* // -> 'Average prices per color changed'
|
|
1618
1416
|
* // -> {"0": {color: 'brown', price: 3}, "1": {color: 'black', price: 4.5}}
|
|
1619
|
-
* // -> ["
|
|
1417
|
+
* // -> ["1", "0"]
|
|
1620
1418
|
*
|
|
1621
1419
|
* queries.delListener(listenerId);
|
|
1622
1420
|
* queries.destroy();
|
|
@@ -1639,7 +1437,7 @@ export interface Queries {
|
|
|
1639
1437
|
* The third `build` parameter is a callback that you provide to define the
|
|
1640
1438
|
* query. That callback is provided with a `builders` object that contains the
|
|
1641
1439
|
* named 'keywords' for the query, like `select`, `join`, and so on. You can
|
|
1642
|
-
* see how that is used in the simple example below. The following
|
|
1440
|
+
* see how that is used in the simple example below. The following five
|
|
1643
1441
|
* clause types are supported:
|
|
1644
1442
|
*
|
|
1645
1443
|
* - The Select type describes a function that lets you specify a Cell or
|
|
@@ -1653,13 +1451,12 @@ export interface Queries {
|
|
|
1653
1451
|
* of a Cell in multiple result Rows should be aggregated together.
|
|
1654
1452
|
* - The Having type describes a function that lets you specify conditions to
|
|
1655
1453
|
* filter results, based on the grouped Cells resulting from a Group clause.
|
|
1656
|
-
* - The Order type describes a function that lets you specify how you want
|
|
1657
|
-
* the Rows in the result Table to be ordered, based on values within.
|
|
1658
|
-
* - The Limit type describes a function that lets you specify how many Rows
|
|
1659
|
-
* you want in the result Table, and how they should be offset.
|
|
1660
1454
|
*
|
|
1661
1455
|
* Full documentation and examples are provided in the sections for each of
|
|
1662
1456
|
* those clause types.
|
|
1457
|
+
*
|
|
1458
|
+
* Additionally, you can use the getResultSortedRowIds method and
|
|
1459
|
+
* addResultSortedRowIdsListener method to sort and paginate the results.
|
|
1663
1460
|
*
|
|
1664
1461
|
* @param queryId The Id of the query to define.
|
|
1665
1462
|
* @param tableId The Id of the main Table the query will be based on.
|
|
@@ -1699,8 +1496,6 @@ export interface Queries {
|
|
|
1699
1496
|
where: Where;
|
|
1700
1497
|
group: Group;
|
|
1701
1498
|
having: Having;
|
|
1702
|
-
order: Order;
|
|
1703
|
-
limit: Limit;
|
|
1704
1499
|
}) => void,
|
|
1705
1500
|
): Queries;
|
|
1706
1501
|
|
|
@@ -1942,9 +1737,6 @@ export interface Queries {
|
|
|
1942
1737
|
* returns a copy of, rather than a reference to the list of Ids, so changes
|
|
1943
1738
|
* made to the list object are not made to the query results themselves.
|
|
1944
1739
|
*
|
|
1945
|
-
* An Order clause in the query explicitly affects the order of entries in
|
|
1946
|
-
* this array.
|
|
1947
|
-
*
|
|
1948
1740
|
* @param queryId The Id of a query.
|
|
1949
1741
|
* @returns An array of the Ids of every Row in the result of the query.
|
|
1950
1742
|
* @example
|
|
@@ -1987,7 +1779,9 @@ export interface Queries {
|
|
|
1987
1779
|
* This has the same behavior as a Store's getSortedRowIds method. For
|
|
1988
1780
|
* example, if the query Id is invalid, the method returns an empty array.
|
|
1989
1781
|
* Similarly, the sorting of the rows is alphanumeric, and you can indicate
|
|
1990
|
-
* whether it should be in descending order.
|
|
1782
|
+
* whether it should be in descending order. The `offset` and `limit`
|
|
1783
|
+
* parameters are used to paginate results, but default to `0` and `undefined`
|
|
1784
|
+
* to return all available Row Ids if not specified.
|
|
1991
1785
|
*
|
|
1992
1786
|
* Note that every call to this method will perform the sorting afresh - there
|
|
1993
1787
|
* is no caching of the results - and so you are advised to memoize the
|
|
@@ -1999,6 +1793,10 @@ export interface Queries {
|
|
|
1999
1793
|
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
2000
1794
|
* `undefined` to by sort the Row Id itself.
|
|
2001
1795
|
* @param descending Whether the sorting should be in descending order.
|
|
1796
|
+
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
1797
|
+
* any.
|
|
1798
|
+
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
1799
|
+
* all.
|
|
2002
1800
|
* @returns An array of the sorted Ids of every Row in the result of the
|
|
2003
1801
|
* query.
|
|
2004
1802
|
* @example
|
|
@@ -2031,7 +1829,13 @@ export interface Queries {
|
|
|
2031
1829
|
* @category Result
|
|
2032
1830
|
* @since v2.0.0-beta
|
|
2033
1831
|
*/
|
|
2034
|
-
getResultSortedRowIds(
|
|
1832
|
+
getResultSortedRowIds(
|
|
1833
|
+
queryId: Id,
|
|
1834
|
+
cellId?: Id,
|
|
1835
|
+
descending?: boolean,
|
|
1836
|
+
offset?: number,
|
|
1837
|
+
limit?: number,
|
|
1838
|
+
): Ids;
|
|
2035
1839
|
|
|
2036
1840
|
/**
|
|
2037
1841
|
* The getResultRow method returns an object containing the entire data of a
|
|
@@ -2519,22 +2323,13 @@ export interface Queries {
|
|
|
2519
2323
|
* the method's first parameter) or changes to any result Table (by providing
|
|
2520
2324
|
* a `null` wildcard).
|
|
2521
2325
|
*
|
|
2522
|
-
* Use the optional `trackReorder` parameter to additionally track when the
|
|
2523
|
-
* set of Ids has not changed, but the order has - specifically when the Order
|
|
2524
|
-
* clause of the query causes the Row Ids to be re-sorted. This behavior is
|
|
2525
|
-
* disabled by default due to the potential performance cost of detecting such
|
|
2526
|
-
* changes.
|
|
2527
|
-
*
|
|
2528
2326
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2529
2327
|
* @param listener The function that will be called whenever the Row Ids in
|
|
2530
2328
|
* the result Table change.
|
|
2531
|
-
* @param trackReorder An optional boolean that indicates that the listener
|
|
2532
|
-
* should be called if the set of Ids remains the same but their order
|
|
2533
|
-
* changes.
|
|
2534
2329
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2535
2330
|
* @example
|
|
2536
2331
|
* This example registers a listener that responds to any change to the Row
|
|
2537
|
-
* Ids of a specific result Table
|
|
2332
|
+
* Ids of a specific result Table.
|
|
2538
2333
|
*
|
|
2539
2334
|
* ```js
|
|
2540
2335
|
* const store = createStore().setTable('pets', {
|
|
@@ -2546,50 +2341,9 @@ export interface Queries {
|
|
|
2546
2341
|
* const queries = createQueries(store).setQueryDefinition(
|
|
2547
2342
|
* 'dogColors',
|
|
2548
2343
|
* 'pets',
|
|
2549
|
-
* ({select, where
|
|
2550
|
-
* select('color');
|
|
2551
|
-
* where('species', 'dog');
|
|
2552
|
-
* order('color');
|
|
2553
|
-
* },
|
|
2554
|
-
* );
|
|
2555
|
-
*
|
|
2556
|
-
* const listenerId = queries.addResultRowIdsListener(
|
|
2557
|
-
* 'dogColors',
|
|
2558
|
-
* (queries, tableId) => {
|
|
2559
|
-
* console.log(`Row Ids for dogColors result table changed`);
|
|
2560
|
-
* console.log(queries.getResultRowIds('dogColors'));
|
|
2561
|
-
* },
|
|
2562
|
-
* );
|
|
2563
|
-
*
|
|
2564
|
-
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2565
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2566
|
-
* // -> ['cujo', 'fido', 'rex']
|
|
2567
|
-
*
|
|
2568
|
-
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
2569
|
-
* // -> undefined
|
|
2570
|
-
* // trackReorder not set for listener
|
|
2571
|
-
*
|
|
2572
|
-
* store.delListener(listenerId);
|
|
2573
|
-
* ```
|
|
2574
|
-
* @example
|
|
2575
|
-
* This example registers a listener that responds to a change of order in the
|
|
2576
|
-
* rows of a specific result Table, even though the set of Ids themselves has
|
|
2577
|
-
* not changed.
|
|
2578
|
-
*
|
|
2579
|
-
* ```js
|
|
2580
|
-
* const store = createStore().setTable('pets', {
|
|
2581
|
-
* fido: {species: 'dog', color: 'brown'},
|
|
2582
|
-
* felix: {species: 'cat', color: 'black'},
|
|
2583
|
-
* cujo: {species: 'dog', color: 'black'},
|
|
2584
|
-
* });
|
|
2585
|
-
*
|
|
2586
|
-
* const queries = createQueries(store).setQueryDefinition(
|
|
2587
|
-
* 'dogColors',
|
|
2588
|
-
* 'pets',
|
|
2589
|
-
* ({select, where, order}) => {
|
|
2344
|
+
* ({select, where}) => {
|
|
2590
2345
|
* select('color');
|
|
2591
2346
|
* where('species', 'dog');
|
|
2592
|
-
* order('color');
|
|
2593
2347
|
* },
|
|
2594
2348
|
* );
|
|
2595
2349
|
*
|
|
@@ -2599,16 +2353,11 @@ export interface Queries {
|
|
|
2599
2353
|
* console.log(`Row Ids for dogColors result table changed`);
|
|
2600
2354
|
* console.log(queries.getResultRowIds('dogColors'));
|
|
2601
2355
|
* },
|
|
2602
|
-
* true, // track reorder
|
|
2603
2356
|
* );
|
|
2604
2357
|
*
|
|
2605
2358
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2606
2359
|
* // -> 'Row Ids for dogColors result table changed'
|
|
2607
|
-
* // -> ['
|
|
2608
|
-
*
|
|
2609
|
-
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
2610
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2611
|
-
* // -> ['cujo', 'rex', 'fido']
|
|
2360
|
+
* // -> ['fido', 'cujo', 'rex']
|
|
2612
2361
|
*
|
|
2613
2362
|
* store.delListener(listenerId);
|
|
2614
2363
|
* ```
|
|
@@ -2652,20 +2401,21 @@ export interface Queries {
|
|
|
2652
2401
|
addResultRowIdsListener(
|
|
2653
2402
|
queryId: IdOrNull,
|
|
2654
2403
|
listener: ResultRowIdsListener,
|
|
2655
|
-
trackReorder?: boolean,
|
|
2656
2404
|
): Id;
|
|
2657
2405
|
|
|
2658
2406
|
/**
|
|
2659
2407
|
* The addResultSortedRowIdsListener method registers a listener function with
|
|
2660
|
-
* the Queries object that will be called whenever sorted
|
|
2661
|
-
* Table change.
|
|
2408
|
+
* the Queries object that will be called whenever sorted (and optionally,
|
|
2409
|
+
* paginated) Row Ids in a result Table change.
|
|
2662
2410
|
*
|
|
2663
2411
|
* The provided listener is a ResultSortedRowIdsListener function, and will be
|
|
2664
2412
|
* called with a reference to the Queries object, the Id of the result Table
|
|
2665
2413
|
* whose Row Ids sorting changed (which is also the query Id), the Cell Id
|
|
2666
|
-
* being used to sort them,
|
|
2667
|
-
* the
|
|
2668
|
-
*
|
|
2414
|
+
* being used to sort them, whether descending or not, and the offset and
|
|
2415
|
+
* limit of the number of Ids returned, for pagination purposes. It also
|
|
2416
|
+
* receives the sorted array of Ids itself, so that you can use them in the
|
|
2417
|
+
* listener without the additional cost of an explicit call to
|
|
2418
|
+
* getResultSortedRowIds
|
|
2669
2419
|
*
|
|
2670
2420
|
* Such a listener is called when a Row is added or removed, but also when a
|
|
2671
2421
|
* value in the specified Cell (somewhere in the result Table) has changed
|
|
@@ -2675,10 +2425,19 @@ export interface Queries {
|
|
|
2675
2425
|
* of detecting changes to the sorting). You can only listen to a single
|
|
2676
2426
|
* specified result Table, sorted by a single specified Cell.
|
|
2677
2427
|
*
|
|
2428
|
+
* The sorting of the rows is alphanumeric, and you can indicate whether it
|
|
2429
|
+
* should be in descending order. The `offset` and `limit` parameters are used
|
|
2430
|
+
* to paginate results, but default to `0` and `undefined` to return all
|
|
2431
|
+
* available Row Ids if not specified.
|
|
2432
|
+
*
|
|
2678
2433
|
* @param queryId The Id of the query to listen to.
|
|
2679
2434
|
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
2680
2435
|
* `undefined` to by sort the result Row Id itself.
|
|
2681
2436
|
* @param descending Whether the sorting should be in descending order.
|
|
2437
|
+
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
2438
|
+
* any.
|
|
2439
|
+
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
2440
|
+
* all.
|
|
2682
2441
|
* @param listener The function that will be called whenever the sorted Row
|
|
2683
2442
|
* Ids in the result Table change.
|
|
2684
2443
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
@@ -2706,7 +2465,9 @@ export interface Queries {
|
|
|
2706
2465
|
* 'dogColors',
|
|
2707
2466
|
* 'color',
|
|
2708
2467
|
* false,
|
|
2709
|
-
*
|
|
2468
|
+
* 0,
|
|
2469
|
+
* undefined,
|
|
2470
|
+
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2710
2471
|
* console.log(`Sorted Row Ids for dogColors result table changed`);
|
|
2711
2472
|
* console.log(sortedRowIds);
|
|
2712
2473
|
* // ^ cheaper than calling getResultSortedRowIds again
|
|
@@ -2739,14 +2500,16 @@ export interface Queries {
|
|
|
2739
2500
|
* where('species', 'dog');
|
|
2740
2501
|
* },
|
|
2741
2502
|
* );
|
|
2742
|
-
* console.log(queries.getResultSortedRowIds('dogColors', undefined
|
|
2503
|
+
* console.log(queries.getResultSortedRowIds('dogColors', undefined));
|
|
2743
2504
|
* // -> ['cujo', 'fido']
|
|
2744
2505
|
*
|
|
2745
2506
|
* const listenerId = queries.addResultSortedRowIdsListener(
|
|
2746
2507
|
* 'dogColors',
|
|
2747
2508
|
* undefined,
|
|
2748
2509
|
* false,
|
|
2749
|
-
*
|
|
2510
|
+
* 0,
|
|
2511
|
+
* undefined,
|
|
2512
|
+
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2750
2513
|
* console.log(`Sorted Row Ids for dogColors result table changed`);
|
|
2751
2514
|
* console.log(sortedRowIds);
|
|
2752
2515
|
* // ^ cheaper than calling getSortedRowIds again
|
|
@@ -2765,6 +2528,8 @@ export interface Queries {
|
|
|
2765
2528
|
queryId: Id,
|
|
2766
2529
|
cellId: Id | undefined,
|
|
2767
2530
|
descending: boolean,
|
|
2531
|
+
offset: number,
|
|
2532
|
+
limit: number | undefined,
|
|
2768
2533
|
listener: ResultSortedRowIdsListener,
|
|
2769
2534
|
): Id;
|
|
2770
2535
|
|