@party-stack/tanstack-db-patches 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
diff --git a/dist/cjs/query/compiler/order-by.cjs b/dist/cjs/query/compiler/order-by.cjs
|
|
2
|
-
index ae4a4162b4b2d998e07d41c4b0937507ccfce021..
|
|
2
|
+
index ae4a4162b4b2d998e07d41c4b0937507ccfce021..6d5c831df680bca915dd72190a5133a5fbe397a3 100644
|
|
3
3
|
--- a/dist/cjs/query/compiler/order-by.cjs
|
|
4
4
|
+++ b/dist/cjs/query/compiler/order-by.cjs
|
|
5
5
|
@@ -144,6 +144,7 @@ function processOrderBy(rawQuery, pipeline, orderByClause, selectClause, groupin
|
|
@@ -10,7 +10,7 @@ index ae4a4162b4b2d998e07d41c4b0937507ccfce021..6f31ab44d0989e804a8dc29e0d8bf402
|
|
|
10
10
|
sourceHoldsAllRows: followRefResult.collection.config.syncMode !== `on-demand`,
|
|
11
11
|
requiresFullSource: sourceOrderBy.some(
|
|
12
12
|
({ compareOptions }) => compareOptions.stringSort === `custom`
|
|
13
|
-
@@ -153,6 +154,
|
|
13
|
+
@@ -153,6 +154,51 @@ function processOrderBy(rawQuery, pipeline, orderByClause, selectClause, groupin
|
|
14
14
|
// root match may sit past the prefix.
|
|
15
15
|
(rawQuery.join?.some(({ type }) => type !== `left`) ?? false) || (rawQuery.where?.some(ir.isResidualWhere) ?? false) || hasCrossAliasWhere && joinedFilterSourceId === void 0 || (rawQuery.fnWhere?.length ?? 0) > 0 || rawQuery.groupBy !== void 0 || rawQuery.having !== void 0 || rawQuery.fnHaving !== void 0 || rawQuery.distinct === true
|
|
16
16
|
};
|
|
@@ -42,6 +42,7 @@ index ae4a4162b4b2d998e07d41c4b0937507ccfce021..6f31ab44d0989e804a8dc29e0d8bf402
|
|
|
42
42
|
+ ),
|
|
43
43
|
+ compare: comparison.makeComparator(term.compareOptions),
|
|
44
44
|
+ }))
|
|
45
|
+
+ const sourceCollection = followRefResult.collection
|
|
45
46
|
+ info.comparator = (a, b) => {
|
|
46
47
|
+ for (const term of terms) {
|
|
47
48
|
+ const compared = term.compare(
|
|
@@ -50,14 +51,18 @@ index ae4a4162b4b2d998e07d41c4b0937507ccfce021..6f31ab44d0989e804a8dc29e0d8bf402
|
|
|
50
51
|
+ )
|
|
51
52
|
+ if (compared !== 0) return compared
|
|
52
53
|
+ }
|
|
53
|
-
+
|
|
54
|
+
+ // Rows that tie on every term order by key, as the query's result does,
|
|
55
|
+
+ // so an ordering without its primary key is still a total order.
|
|
56
|
+
+ return a && b
|
|
57
|
+
+ ? dbIvm.compareKeys(sourceCollection.getKeyFromItem(a), sourceCollection.getKeyFromItem(b))
|
|
58
|
+
+ : 0
|
|
54
59
|
+ }
|
|
55
60
|
+ }
|
|
56
61
|
+ }
|
|
57
62
|
orderByOptimizationInfo = info;
|
|
58
63
|
const previous = optimizableOrderByCollections[orderBySourceId];
|
|
59
64
|
optimizableOrderByCollections[orderBySourceId] = previous ? {
|
|
60
|
-
@@ -172,19 +
|
|
65
|
+
@@ -172,19 +218,21 @@ function processOrderBy(rawQuery, pipeline, orderByClause, selectClause, groupin
|
|
61
66
|
info.offset + info.limit
|
|
62
67
|
) - this.offset;
|
|
63
68
|
},
|
|
@@ -82,7 +87,7 @@ index ae4a4162b4b2d998e07d41c4b0937507ccfce021..6f31ab44d0989e804a8dc29e0d8bf402
|
|
|
82
87
|
row[orderByAlias],
|
|
83
88
|
boundary
|
|
84
89
|
) <= 0)
|
|
85
|
-
@@ -235,4 +
|
|
90
|
+
@@ -235,4 +283,3 @@ function resolveCompareOptions(clause, defaults) {
|
|
86
91
|
}
|
|
87
92
|
exports.buildCompareOptions = buildCompareOptions;
|
|
88
93
|
exports.processOrderBy = processOrderBy;
|
|
@@ -191,11 +196,12 @@ index 7aad9cbbd5a1241da433fdd366bc80a9fb7ddf53..04cfc7a977e9f67065b3043664e4f7b5
|
|
|
191
196
|
joinedFilterSourceIds?: ReadonlyArray<string>;
|
|
192
197
|
};
|
|
193
198
|
diff --git a/dist/esm/query/compiler/order-by.js b/dist/esm/query/compiler/order-by.js
|
|
194
|
-
index 9a0a188851a196728a27421c15df5f0239b34400..
|
|
199
|
+
index 9a0a188851a196728a27421c15df5f0239b34400..27025711a3ddccdbac5e9c8079c157c16a36f2c5 100644
|
|
195
200
|
--- a/dist/esm/query/compiler/order-by.js
|
|
196
201
|
+++ b/dist/esm/query/compiler/order-by.js
|
|
197
202
|
@@ -1,13 +1,13 @@
|
|
198
|
-
|
|
203
|
+
-import { groupedOrderByWithFractionalIndex, orderByWithFractionalIndex } from "@tanstack/db-ivm";
|
|
204
|
+
+import { compareKeys, groupedOrderByWithFractionalIndex, orderByWithFractionalIndex } from "@tanstack/db-ivm";
|
|
199
205
|
import { makeComparator, defaultComparator } from "../../utils/comparison.js";
|
|
200
206
|
-import { followRef, collectCollectionSources, PropRef, getWhereExpression, isResidualWhere } from "../ir.js";
|
|
201
207
|
+import { followRef, collectCollectionSources, Func, PropRef, getWhereExpression, isResidualWhere } from "../ir.js";
|
|
@@ -218,7 +224,7 @@ index 9a0a188851a196728a27421c15df5f0239b34400..7095ca4ef2ac0ea769ebdf4cf765e673
|
|
|
218
224
|
sourceHoldsAllRows: followRefResult.collection.config.syncMode !== `on-demand`,
|
|
219
225
|
requiresFullSource: sourceOrderBy.some(
|
|
220
226
|
({ compareOptions }) => compareOptions.stringSort === `custom`
|
|
221
|
-
@@ -151,6 +152,
|
|
227
|
+
@@ -151,6 +152,51 @@ function processOrderBy(rawQuery, pipeline, orderByClause, selectClause, groupin
|
|
222
228
|
// root match may sit past the prefix.
|
|
223
229
|
(rawQuery.join?.some(({ type }) => type !== `left`) ?? false) || (rawQuery.where?.some(isResidualWhere) ?? false) || hasCrossAliasWhere && joinedFilterSourceId === void 0 || (rawQuery.fnWhere?.length ?? 0) > 0 || rawQuery.groupBy !== void 0 || rawQuery.having !== void 0 || rawQuery.fnHaving !== void 0 || rawQuery.distinct === true
|
|
224
230
|
};
|
|
@@ -250,6 +256,7 @@ index 9a0a188851a196728a27421c15df5f0239b34400..7095ca4ef2ac0ea769ebdf4cf765e673
|
|
|
250
256
|
+ ),
|
|
251
257
|
+ compare: makeComparator(term.compareOptions),
|
|
252
258
|
+ }))
|
|
259
|
+
+ const sourceCollection = followRefResult.collection
|
|
253
260
|
+ info.comparator = (a, b) => {
|
|
254
261
|
+ for (const term of terms) {
|
|
255
262
|
+ const compared = term.compare(
|
|
@@ -258,14 +265,18 @@ index 9a0a188851a196728a27421c15df5f0239b34400..7095ca4ef2ac0ea769ebdf4cf765e673
|
|
|
258
265
|
+ )
|
|
259
266
|
+ if (compared !== 0) return compared
|
|
260
267
|
+ }
|
|
261
|
-
+
|
|
268
|
+
+ // Rows that tie on every term order by key, as the query's result does,
|
|
269
|
+
+ // so an ordering without its primary key is still a total order.
|
|
270
|
+
+ return a && b
|
|
271
|
+
+ ? compareKeys(sourceCollection.getKeyFromItem(a), sourceCollection.getKeyFromItem(b))
|
|
272
|
+
+ : 0
|
|
262
273
|
+ }
|
|
263
274
|
+ }
|
|
264
275
|
+ }
|
|
265
276
|
orderByOptimizationInfo = info;
|
|
266
277
|
const previous = optimizableOrderByCollections[orderBySourceId];
|
|
267
278
|
optimizableOrderByCollections[orderBySourceId] = previous ? {
|
|
268
|
-
@@ -170,19 +
|
|
279
|
+
@@ -170,19 +216,21 @@ function processOrderBy(rawQuery, pipeline, orderByClause, selectClause, groupin
|
|
269
280
|
info.offset + info.limit
|
|
270
281
|
) - this.offset;
|
|
271
282
|
},
|
|
@@ -290,7 +301,7 @@ index 9a0a188851a196728a27421c15df5f0239b34400..7095ca4ef2ac0ea769ebdf4cf765e673
|
|
|
290
301
|
row[orderByAlias],
|
|
291
302
|
boundary
|
|
292
303
|
) <= 0)
|
|
293
|
-
@@ -235,4 +
|
|
304
|
+
@@ -235,4 +283,3 @@ export {
|
|
294
305
|
buildCompareOptions,
|
|
295
306
|
processOrderBy
|
|
296
307
|
};
|
|
@@ -373,10 +384,14 @@ index 734ebd81f8aadd42a5872f759c7a42a2b830f620..795be3fc6fb6e36af9414f030b452312
|
|
|
373
384
|
collection: Collection<T, TKey, any, any, any>;
|
|
374
385
|
/**
|
|
375
386
|
diff --git a/src/query/compiler/order-by.ts b/src/query/compiler/order-by.ts
|
|
376
|
-
index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..
|
|
387
|
+
index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e152c3f1f72b3d606c43dadc443f3270c06e228d 100644
|
|
377
388
|
--- a/src/query/compiler/order-by.ts
|
|
378
389
|
+++ b/src/query/compiler/order-by.ts
|
|
379
|
-
@@ -
|
|
390
|
+
@@ -1,9 +1,11 @@
|
|
391
|
+
import {
|
|
392
|
+
+ compareKeys,
|
|
393
|
+
groupedOrderByWithFractionalIndex,
|
|
394
|
+
orderByWithFractionalIndex,
|
|
380
395
|
} from '@tanstack/db-ivm'
|
|
381
396
|
import { defaultComparator, makeComparator } from '../../utils/comparison.js'
|
|
382
397
|
import {
|
|
@@ -384,7 +399,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
384
399
|
PropRef,
|
|
385
400
|
collectCollectionSources,
|
|
386
401
|
followRef,
|
|
387
|
-
@@ -20,7 +
|
|
402
|
+
@@ -20,7 +22,11 @@ import { hasVirtualPropPath } from '../../virtual-props.js'
|
|
388
403
|
import { deepEquals } from '../../utils.js'
|
|
389
404
|
import { devBuild } from '../../error-message.js'
|
|
390
405
|
import { compileExpression } from './evaluators.js'
|
|
@@ -397,7 +412,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
397
412
|
import type { CompareOptions } from '../builder/types.js'
|
|
398
413
|
import type { WindowOptions } from './types.js'
|
|
399
414
|
import type { Grouping } from './grouping.js'
|
|
400
|
-
@@ -67,6 +
|
|
415
|
+
@@ -67,6 +73,8 @@ export type OrderByOptimizationInfo = {
|
|
401
416
|
requiresFullSource: boolean
|
|
402
417
|
/** Whether the ordered source's installed rows are the whole source. */
|
|
403
418
|
sourceHoldsAllRows: boolean
|
|
@@ -406,7 +421,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
406
421
|
/** Sources whose lazy demand must settle before a joined-filter page. */
|
|
407
422
|
joinedFilterSourceIds?: ReadonlyArray<string>
|
|
408
423
|
}
|
|
409
|
-
@@ -297,6 +
|
|
424
|
+
@@ -297,6 +305,7 @@ export function processOrderBy(
|
|
410
425
|
joinedFilterSourceIds: joinedFilterSourceId
|
|
411
426
|
? [joinedFilterSourceId]
|
|
412
427
|
: undefined,
|
|
@@ -414,7 +429,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
414
429
|
sourceHoldsAllRows:
|
|
415
430
|
followRefResult.collection.config.syncMode !== `on-demand`,
|
|
416
431
|
requiresFullSource:
|
|
417
|
-
@@ -319,6 +
|
|
432
|
+
@@ -319,6 +328,51 @@ export function processOrderBy(
|
|
418
433
|
rawQuery.fnHaving !== undefined ||
|
|
419
434
|
rawQuery.distinct === true,
|
|
420
435
|
}
|
|
@@ -446,6 +461,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
446
461
|
+ ) as CompiledSingleRowExpression,
|
|
447
462
|
+ compare: makeComparator(term.compareOptions),
|
|
448
463
|
+ }))
|
|
464
|
+
+ const sourceCollection = followRefResult.collection
|
|
449
465
|
+ info.comparator = (a, b) => {
|
|
450
466
|
+ for (const term of terms) {
|
|
451
467
|
+ const compared = term.compare(
|
|
@@ -454,14 +470,18 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
454
470
|
+ )
|
|
455
471
|
+ if (compared !== 0) return compared
|
|
456
472
|
+ }
|
|
457
|
-
+
|
|
473
|
+
+ // Rows that tie on every term order by key, as the query's result does,
|
|
474
|
+
+ // so an ordering without its primary key is still a total order.
|
|
475
|
+
+ return a && b
|
|
476
|
+
+ ? compareKeys(sourceCollection.getKeyFromItem(a), sourceCollection.getKeyFromItem(b))
|
|
477
|
+
+ : 0
|
|
458
478
|
+ }
|
|
459
479
|
+ }
|
|
460
480
|
+ }
|
|
461
481
|
orderByOptimizationInfo = info
|
|
462
482
|
|
|
463
483
|
// Ordered loading is owned by one lexical source. A collection can occur
|
|
464
|
-
@@ -349,8 +
|
|
484
|
+
@@ -349,8 +403,19 @@ export function processOrderBy(
|
|
465
485
|
) - this.offset
|
|
466
486
|
)
|
|
467
487
|
},
|
|
@@ -481,7 +501,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
481
501
|
!deepEquals(previous.orderBy, info.orderBy) ||
|
|
482
502
|
previous.requiresFullSource ||
|
|
483
503
|
info.requiresFullSource,
|
|
484
|
-
@@ -366,7 +
|
|
504
|
+
@@ -366,7 +431,7 @@ export function processOrderBy(
|
|
485
505
|
// index, only an on-demand joined filter can leave the window short.
|
|
486
506
|
const needsCount =
|
|
487
507
|
joinedFilterSourceId !== undefined && !info.sourceHoldsAllRows
|
|
@@ -490,7 +510,7 @@ index 01c61fbf48116aa3b0e19cc1eea68290afd39e4c..e757709b5d9b113cabee8d71388ca5d8
|
|
|
490
510
|
setSizeCallback = (getSize) => {
|
|
491
511
|
info.dataNeeded = (boundary) => {
|
|
492
512
|
// Window rows at or before the boundary are a leading run of
|
|
493
|
-
@@ -374,7 +
|
|
513
|
+
@@ -374,7 +439,7 @@ export function processOrderBy(
|
|
494
514
|
const size = getSize(
|
|
495
515
|
boundary &&
|
|
496
516
|
((row) =>
|