effect-dynamodb 1.42.2 → 1.44.0
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/dist/Aggregate.d.ts +157 -20
- package/dist/Aggregate.d.ts.map +1 -1
- package/dist/Aggregate.js +1219 -286
- package/dist/Aggregate.js.map +1 -1
- package/dist/Batch.d.ts +17 -4
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +129 -62
- package/dist/Batch.js.map +1 -1
- package/dist/BlobGc.d.ts +243 -0
- package/dist/BlobGc.d.ts.map +1 -0
- package/dist/BlobGc.js +961 -0
- package/dist/BlobGc.js.map +1 -0
- package/dist/BlobStore.d.ts +83 -0
- package/dist/BlobStore.d.ts.map +1 -0
- package/dist/BlobStore.js +70 -0
- package/dist/BlobStore.js.map +1 -0
- package/dist/Collection.d.ts +88 -8
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +22 -26
- package/dist/Collection.js.map +1 -1
- package/dist/Collections.d.ts +0 -7
- package/dist/Collections.d.ts.map +1 -1
- package/dist/Collections.js +0 -16
- package/dist/Collections.js.map +1 -1
- package/dist/DynamoClient.d.ts +68 -35
- package/dist/DynamoClient.d.ts.map +1 -1
- package/dist/DynamoClient.js +58 -12
- package/dist/DynamoClient.js.map +1 -1
- package/dist/Entity.d.ts +403 -104
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +1771 -382
- package/dist/Entity.js.map +1 -1
- package/dist/EventStore.d.ts +323 -77
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +473 -96
- package/dist/EventStore.js.map +1 -1
- package/dist/Offload.d.ts +199 -0
- package/dist/Offload.d.ts.map +1 -0
- package/dist/Offload.js +120 -0
- package/dist/Offload.js.map +1 -0
- package/dist/Query.d.ts +132 -59
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +95 -31
- package/dist/Query.js.map +1 -1
- package/dist/StorageEncoding.d.ts +62 -15
- package/dist/StorageEncoding.d.ts.map +1 -1
- package/dist/StorageEncoding.js +108 -24
- package/dist/StorageEncoding.js.map +1 -1
- package/dist/Table.d.ts +1 -1
- package/dist/Table.d.ts.map +1 -1
- package/dist/Transaction.d.ts +16 -3
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +28 -9
- package/dist/Transaction.js.map +1 -1
- package/dist/blob/S3BlobStore.d.ts +178 -0
- package/dist/blob/S3BlobStore.d.ts.map +1 -0
- package/dist/blob/S3BlobStore.js +770 -0
- package/dist/blob/S3BlobStore.js.map +1 -0
- package/dist/blob/s3.d.ts +122 -0
- package/dist/blob/s3.d.ts.map +1 -0
- package/dist/blob/s3.js +143 -0
- package/dist/blob/s3.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/AggregateWrite.d.ts +130 -0
- package/dist/internal/AggregateWrite.d.ts.map +1 -0
- package/dist/internal/AggregateWrite.js +341 -0
- package/dist/internal/AggregateWrite.js.map +1 -0
- package/dist/internal/BlobCalls.d.ts +70 -0
- package/dist/internal/BlobCalls.d.ts.map +1 -0
- package/dist/internal/BlobCalls.js +105 -0
- package/dist/internal/BlobCalls.js.map +1 -0
- package/dist/internal/BlobKeys.d.ts +100 -0
- package/dist/internal/BlobKeys.d.ts.map +1 -0
- package/dist/internal/BlobKeys.js +135 -0
- package/dist/internal/BlobKeys.js.map +1 -0
- package/dist/internal/BlobLedger.d.ts +323 -0
- package/dist/internal/BlobLedger.d.ts.map +1 -0
- package/dist/internal/BlobLedger.js +1012 -0
- package/dist/internal/BlobLedger.js.map +1 -0
- package/dist/internal/BlobMetadata.d.ts +109 -0
- package/dist/internal/BlobMetadata.d.ts.map +1 -0
- package/dist/internal/BlobMetadata.js +249 -0
- package/dist/internal/BlobMetadata.js.map +1 -0
- package/dist/internal/BlobResolver.d.ts +146 -0
- package/dist/internal/BlobResolver.d.ts.map +1 -0
- package/dist/internal/BlobResolver.js +417 -0
- package/dist/internal/BlobResolver.js.map +1 -0
- package/dist/internal/BlobStoreContract.d.ts +214 -0
- package/dist/internal/BlobStoreContract.d.ts.map +1 -0
- package/dist/internal/BlobStoreContract.js +181 -0
- package/dist/internal/BlobStoreContract.js.map +1 -0
- package/dist/internal/BoundCrud.d.ts +153 -53
- package/dist/internal/BoundCrud.d.ts.map +1 -1
- package/dist/internal/BoundCrud.js +27 -5
- package/dist/internal/BoundCrud.js.map +1 -1
- package/dist/internal/BoundQuery.d.ts +49 -33
- package/dist/internal/BoundQuery.d.ts.map +1 -1
- package/dist/internal/BoundQuery.js +8 -2
- package/dist/internal/BoundQuery.js.map +1 -1
- package/dist/internal/BoundVectorQuery.d.ts +59 -25
- package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
- package/dist/internal/BoundVectorQuery.js +38 -17
- package/dist/internal/BoundVectorQuery.js.map +1 -1
- package/dist/internal/Capacity.d.ts +17 -2
- package/dist/internal/Capacity.d.ts.map +1 -1
- package/dist/internal/Capacity.js +47 -9
- package/dist/internal/Capacity.js.map +1 -1
- package/dist/internal/ConditionHolds.d.ts.map +1 -1
- package/dist/internal/ConditionHolds.js +2 -8
- package/dist/internal/ConditionHolds.js.map +1 -1
- package/dist/internal/CredentialRefusal.d.ts.map +1 -1
- package/dist/internal/CredentialRefusal.js +4 -0
- package/dist/internal/CredentialRefusal.js.map +1 -1
- package/dist/internal/Digest.d.ts +4 -3
- package/dist/internal/Digest.d.ts.map +1 -1
- package/dist/internal/Digest.js +25 -82
- package/dist/internal/Digest.js.map +1 -1
- package/dist/internal/EntityCombinators.d.ts +93 -45
- package/dist/internal/EntityCombinators.d.ts.map +1 -1
- package/dist/internal/EntityCombinators.js +42 -7
- package/dist/internal/EntityCombinators.js.map +1 -1
- package/dist/internal/EntityOps.d.ts +47 -6
- package/dist/internal/EntityOps.d.ts.map +1 -1
- package/dist/internal/EntityOps.js +30 -10
- package/dist/internal/EntityOps.js.map +1 -1
- package/dist/internal/EventProjection.d.ts +99 -25
- package/dist/internal/EventProjection.d.ts.map +1 -1
- package/dist/internal/EventProjection.js +124 -33
- package/dist/internal/EventProjection.js.map +1 -1
- package/dist/internal/ExpressionLimits.d.ts +22 -3
- package/dist/internal/ExpressionLimits.d.ts.map +1 -1
- package/dist/internal/ExpressionLimits.js +46 -7
- package/dist/internal/ExpressionLimits.js.map +1 -1
- package/dist/internal/GcSupport.d.ts +258 -0
- package/dist/internal/GcSupport.d.ts.map +1 -0
- package/dist/internal/GcSupport.js +284 -0
- package/dist/internal/GcSupport.js.map +1 -0
- package/dist/internal/ItemSize.d.ts +7 -1
- package/dist/internal/ItemSize.d.ts.map +1 -1
- package/dist/internal/ItemSize.js +13 -5
- package/dist/internal/ItemSize.js.map +1 -1
- package/dist/internal/MemoryBlobStore.d.ts +203 -0
- package/dist/internal/MemoryBlobStore.d.ts.map +1 -0
- package/dist/internal/MemoryBlobStore.js +623 -0
- package/dist/internal/MemoryBlobStore.js.map +1 -0
- package/dist/internal/MultiProjection.d.ts +56 -28
- package/dist/internal/MultiProjection.d.ts.map +1 -1
- package/dist/internal/MultiProjection.js +9 -3
- package/dist/internal/MultiProjection.js.map +1 -1
- package/dist/internal/Multipart.d.ts +96 -0
- package/dist/internal/Multipart.d.ts.map +1 -0
- package/dist/internal/Multipart.js +143 -0
- package/dist/internal/Multipart.js.map +1 -0
- package/dist/internal/OffloadChange.d.ts +187 -0
- package/dist/internal/OffloadChange.d.ts.map +1 -0
- package/dist/internal/OffloadChange.js +391 -0
- package/dist/internal/OffloadChange.js.map +1 -0
- package/dist/internal/OffloadInput.d.ts +141 -0
- package/dist/internal/OffloadInput.d.ts.map +1 -0
- package/dist/internal/OffloadInput.js +236 -0
- package/dist/internal/OffloadInput.js.map +1 -0
- package/dist/internal/OffloadRead.d.ts +140 -0
- package/dist/internal/OffloadRead.d.ts.map +1 -0
- package/dist/internal/OffloadRead.js +369 -0
- package/dist/internal/OffloadRead.js.map +1 -0
- package/dist/internal/OffloadTypes.d.ts +182 -0
- package/dist/internal/OffloadTypes.d.ts.map +1 -0
- package/dist/internal/OffloadTypes.js +15 -0
- package/dist/internal/OffloadTypes.js.map +1 -0
- package/dist/internal/OffloadValues.d.ts +87 -0
- package/dist/internal/OffloadValues.d.ts.map +1 -0
- package/dist/internal/OffloadValues.js +114 -0
- package/dist/internal/OffloadValues.js.map +1 -0
- package/dist/internal/OffloadWrite.d.ts +267 -0
- package/dist/internal/OffloadWrite.d.ts.map +1 -0
- package/dist/internal/OffloadWrite.js +766 -0
- package/dist/internal/OffloadWrite.js.map +1 -0
- package/dist/internal/Packed.d.ts +58 -23
- package/dist/internal/Packed.d.ts.map +1 -1
- package/dist/internal/Packed.js +108 -33
- package/dist/internal/Packed.js.map +1 -1
- package/dist/internal/ProjectionEngine.d.ts +28 -3
- package/dist/internal/ProjectionEngine.d.ts.map +1 -1
- package/dist/internal/ProjectionEngine.js +47 -9
- package/dist/internal/ProjectionEngine.js.map +1 -1
- package/dist/internal/RangePlanner.d.ts +3 -6
- package/dist/internal/RangePlanner.d.ts.map +1 -1
- package/dist/internal/RangePlanner.js +3 -29
- package/dist/internal/RangePlanner.js.map +1 -1
- package/dist/internal/Rekey.d.ts +16 -0
- package/dist/internal/Rekey.d.ts.map +1 -1
- package/dist/internal/Rekey.js +31 -2
- package/dist/internal/Rekey.js.map +1 -1
- package/dist/internal/StoredPointer.d.ts +19 -0
- package/dist/internal/StoredPointer.d.ts.map +1 -0
- package/dist/internal/StoredPointer.js +59 -0
- package/dist/internal/StoredPointer.js.map +1 -0
- package/dist/internal/TransactPlan.d.ts +18 -1
- package/dist/internal/TransactPlan.d.ts.map +1 -1
- package/dist/internal/TransactPlan.js +50 -10
- package/dist/internal/TransactPlan.js.map +1 -1
- package/dist/internal/TransactWriteOps.d.ts +33 -12
- package/dist/internal/TransactWriteOps.d.ts.map +1 -1
- package/dist/internal/TransactWriteOps.js +49 -19
- package/dist/internal/TransactWriteOps.js.map +1 -1
- package/dist/internal/TransactableOps.d.ts +58 -11
- package/dist/internal/TransactableOps.d.ts.map +1 -1
- package/dist/internal/TransactableOps.js +95 -19
- package/dist/internal/TransactableOps.js.map +1 -1
- package/dist/internal/Utf8Order.d.ts +21 -0
- package/dist/internal/Utf8Order.d.ts.map +1 -0
- package/dist/internal/Utf8Order.js +44 -0
- package/dist/internal/Utf8Order.js.map +1 -0
- package/dist/internal/WriteDiagnosis.d.ts +7 -1
- package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
- package/dist/internal/WriteDiagnosis.js +12 -16
- package/dist/internal/WriteDiagnosis.js.map +1 -1
- package/package.json +15 -4
package/dist/Query.js
CHANGED
|
@@ -16,6 +16,7 @@ import * as Capacity from "./internal/Capacity.js";
|
|
|
16
16
|
import * as Cursor from "./internal/Cursor.js";
|
|
17
17
|
import { compileExpr, ExprTag, emptyPartProblem, isEmptyExpr, operandsAsStored, } from "./internal/Expr.js";
|
|
18
18
|
import { batchGetRaw } from "./internal/Hydrate.js";
|
|
19
|
+
import { DEFAULT_MODES, offloadedAfterFilterBy, parseModes, } from "./internal/OffloadRead.js";
|
|
19
20
|
import { packedExprRefusal, packedProjectionRefusal, } from "./internal/Packed.js";
|
|
20
21
|
import { compilePath, storedPath } from "./internal/PathBuilder.js";
|
|
21
22
|
import { canonicalJson, compositePlanner, cursorRefusal, DEFAULT_MAX_SKIPS, displayKeyCondition, fnv1a32, JUMP_INITIAL, JUMP_MAX_LIMIT, keyConditionHolds, readFrom, toKeyCondition, } from "./internal/RangePlanner.js";
|
|
@@ -48,7 +49,7 @@ const normalizeKeyFields = (fields) => {
|
|
|
48
49
|
return out.length > 0 ? out : undefined;
|
|
49
50
|
};
|
|
50
51
|
// ---------------------------------------------------------------------------
|
|
51
|
-
// Query<A> interface
|
|
52
|
+
// Query<A, E, O> interface
|
|
52
53
|
// ---------------------------------------------------------------------------
|
|
53
54
|
const QueryTypeId = Symbol.for("effect-dynamodb/Query");
|
|
54
55
|
// ---------------------------------------------------------------------------
|
|
@@ -69,6 +70,8 @@ class QueryImpl {
|
|
|
69
70
|
// Constructor (internal — used by Entity and Collection)
|
|
70
71
|
// ---------------------------------------------------------------------------
|
|
71
72
|
export const make = (config) => new QueryImpl({
|
|
73
|
+
prefetch: config.prefetch,
|
|
74
|
+
offloadModes: undefined,
|
|
72
75
|
rawRow: config.rawRow,
|
|
73
76
|
packed: config.packed ?? [],
|
|
74
77
|
storedAt: config.storedAt,
|
|
@@ -117,6 +120,8 @@ export const make = (config) => new QueryImpl({
|
|
|
117
120
|
* No key condition — only filter expressions and entity type filter.
|
|
118
121
|
*/
|
|
119
122
|
export const makeScan = (config) => new QueryImpl({
|
|
123
|
+
prefetch: config.prefetch,
|
|
124
|
+
offloadModes: undefined,
|
|
120
125
|
rawRow: config.rawRow,
|
|
121
126
|
packed: config.packed ?? [],
|
|
122
127
|
storedAt: config.storedAt,
|
|
@@ -453,7 +458,9 @@ plan(new QueryImpl({ ...self._state, fanOut: undefined }), {
|
|
|
453
458
|
maxSkips: undefined,
|
|
454
459
|
});
|
|
455
460
|
/** @internal The decoder of a projected (raw) row: the raw-row hook, or the identity. */
|
|
456
|
-
const rawRowDecoder = (hook) => hook
|
|
461
|
+
const rawRowDecoder = (hook) => hook === undefined
|
|
462
|
+
? (raw) => Effect.succeed(raw)
|
|
463
|
+
: (raw, modes) => hook(raw, modes ?? DEFAULT_MODES);
|
|
457
464
|
/** @internal Throw `[EDD-9076]` for a projection inside a packed attribute. */
|
|
458
465
|
const refusePackedProjection = (state, paths) => {
|
|
459
466
|
const refused = packedProjectionRefusal(paths, state.packed);
|
|
@@ -499,7 +506,7 @@ export const selectProjected = (self, storedPaths, decode) => {
|
|
|
499
506
|
...self._state,
|
|
500
507
|
projection: undefined,
|
|
501
508
|
projectionPaths: storedPaths,
|
|
502
|
-
decoder: (raw) => Effect.map(rawRow(raw), (row) => decode(row)),
|
|
509
|
+
decoder: (raw, modes) => Effect.map(rawRow(raw, modes), (row) => decode(row)),
|
|
503
510
|
});
|
|
504
511
|
};
|
|
505
512
|
/**
|
|
@@ -524,14 +531,17 @@ export const selectWhole = (self, storedPaths, decode) => {
|
|
|
524
531
|
projection: undefined,
|
|
525
532
|
projectionPaths: undefined,
|
|
526
533
|
selectsWholeRows: true,
|
|
527
|
-
|
|
534
|
+
// The selected subset of each row is loaded by the raw-row hook (#179): a page prefetch of
|
|
535
|
+
// the whole row would fetch offloaded values the select does not name.
|
|
536
|
+
prefetch: undefined,
|
|
537
|
+
decoder: (raw, modes) => {
|
|
528
538
|
const projected = projectRow(raw, storedPaths);
|
|
529
539
|
if (hook === undefined)
|
|
530
540
|
return Effect.succeed(decode(projected, raw));
|
|
531
541
|
const borrowed = reads.filter((attribute) => !Object.hasOwn(projected, attribute) && Object.hasOwn(raw, attribute));
|
|
532
542
|
for (const attribute of borrowed)
|
|
533
543
|
projected[attribute] = raw[attribute];
|
|
534
|
-
return Effect.map(hook(projected), (row) => {
|
|
544
|
+
return Effect.map(hook(projected, modes ?? DEFAULT_MODES), (row) => {
|
|
535
545
|
const hooked = row;
|
|
536
546
|
for (const attribute of borrowed)
|
|
537
547
|
delete hooked[attribute];
|
|
@@ -820,6 +830,35 @@ export const selectPaths = Function.dual(2, (self, paths) => {
|
|
|
820
830
|
decoder: rawRowDecoder(projectedRawRow(self._state.rawRow, paths)),
|
|
821
831
|
});
|
|
822
832
|
});
|
|
833
|
+
/**
|
|
834
|
+
* Read the query's offloaded fields (#179) in `mode` — `"eager"` or `"lazy"`
|
|
835
|
+
* for both kinds, or `{ overflow?, binary? }` to set the kinds it names over
|
|
836
|
+
* the query's current modes. Defaults: overflow eager, binary lazy.
|
|
837
|
+
*
|
|
838
|
+
* - **eager** — the value, fetched in a page-level prefetch inside the
|
|
839
|
+
* `limit` window (rows past `limit` are never fetched) at the store's
|
|
840
|
+
* `readConcurrency`, verified by size and checksum; the terminals carry
|
|
841
|
+
* `BlobStoreError`;
|
|
842
|
+
* - **lazy** — an `OffloadedValue<A>` (overflow) or `BlobHandle` (binary):
|
|
843
|
+
* no store I/O until `read()` / `stream()` / `presignedUrl()`.
|
|
844
|
+
*
|
|
845
|
+
* Re-types the items: call it before {@link filterBy}, whose predicate is
|
|
846
|
+
* typed on the item — after `filterBy` it throws `[EDD-9117]`, as it does for
|
|
847
|
+
* an unknown mode (from untyped code). Under `filterBy` an eager query
|
|
848
|
+
* fetches every row it examines; `.offloaded("lazy")` keeps it from
|
|
849
|
+
* downloading. A query whose items offload nothing is unchanged.
|
|
850
|
+
*/
|
|
851
|
+
export const offloaded = Function.dual(2, (self, mode) => {
|
|
852
|
+
if (self._state.predicates.length > 0) {
|
|
853
|
+
throw offloadedAfterFilterBy("Query.offloaded");
|
|
854
|
+
}
|
|
855
|
+
return new QueryImpl({
|
|
856
|
+
...self._state,
|
|
857
|
+
offloadModes: parseModes(mode, self._state.offloadModes ?? DEFAULT_MODES, "Query.offloaded"),
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
/** @internal The read modes a query's decoders run under. */
|
|
861
|
+
export const readModes = (self) => self._state.offloadModes ?? DEFAULT_MODES;
|
|
823
862
|
// ---------------------------------------------------------------------------
|
|
824
863
|
// Internal: shared filter clause builder (entity type + user filters)
|
|
825
864
|
// ---------------------------------------------------------------------------
|
|
@@ -1576,17 +1615,19 @@ const selectedInside = (state) => {
|
|
|
1576
1615
|
};
|
|
1577
1616
|
/**
|
|
1578
1617
|
* @internal Examine one response's rows in order, as `execute` and `paginate`
|
|
1579
|
-
* both do: drop excluded rows, hydrate (see {@link QueryHydration}),
|
|
1580
|
-
* apply the client predicates, and stop
|
|
1618
|
+
* both do: drop excluded rows, hydrate (see {@link QueryHydration}), load
|
|
1619
|
+
* (the page prefetch, #179), decode, apply the client predicates, and stop
|
|
1620
|
+
* once `budget` items are accepted.
|
|
1581
1621
|
*
|
|
1582
1622
|
* Without a client predicate every row is accepted, so only the rows the
|
|
1583
|
-
* budget can still take are hydrated and decoded
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1623
|
+
* budget can still take are hydrated, loaded and decoded — rows past `limit`
|
|
1624
|
+
* never fetch an offloaded value; a row dropped after hydration (its item
|
|
1625
|
+
* gone) widens the window by one. With a predicate, acceptance is only known
|
|
1626
|
+
* after decode, so the whole response is examined (#122) — and, in eager
|
|
1627
|
+
* mode, its offloaded values fetched. `stoppedAt` is the index of the row
|
|
1628
|
+
* that filled the budget, or -1. `accepted` counts the rows that became
|
|
1629
|
+
* items: an excluded row, a hydration miss and a predicate's rejection are
|
|
1630
|
+
* not, and neither is a row past the budget, left unexamined.
|
|
1590
1631
|
*/
|
|
1591
1632
|
const examinePage = (client, tableName, state, returned, budget, borrowedFields) => Effect.gen(function* () {
|
|
1592
1633
|
// Nothing left to accept. Without this the loop below never advances
|
|
@@ -1594,7 +1635,8 @@ const examinePage = (client, tableName, state, returned, budget, borrowedFields)
|
|
|
1594
1635
|
// the budget. No terminal asks; a guard all the same (#171).
|
|
1595
1636
|
if (budget === 0)
|
|
1596
1637
|
return { items: [], stoppedAt: -1, accepted: 0, rows: [] };
|
|
1597
|
-
const
|
|
1638
|
+
const predicated = state.predicates.length > 0;
|
|
1639
|
+
const modes = state.offloadModes ?? DEFAULT_MODES;
|
|
1598
1640
|
// Borrowed attributes the raw-row hook reads are stripped after it ran:
|
|
1599
1641
|
// borrowed into the request's projection, or — on a `BatchGet`-hydrated
|
|
1600
1642
|
// query — into the hydrating fetch's (see `hydrateRows`).
|
|
@@ -1602,30 +1644,44 @@ const examinePage = (client, tableName, state, returned, budget, borrowedFields)
|
|
|
1602
1644
|
const strippedAfterHook = new Set(borrowedFields.filter((field) => hookReads.has(field)));
|
|
1603
1645
|
// Borrowed whole, but selected inside: handed back whole.
|
|
1604
1646
|
const kept = selectedInside(state);
|
|
1647
|
+
const projected = state.projection !== undefined || state.projectionPaths !== undefined;
|
|
1605
1648
|
if (state.hydration?._tag === "BatchGet") {
|
|
1606
|
-
const
|
|
1649
|
+
const names = new Set([
|
|
1607
1650
|
...(state.projection ?? []),
|
|
1608
1651
|
...(state.projectionPaths ?? []).map((segments) => String(segments[0])),
|
|
1609
1652
|
]);
|
|
1610
|
-
if (
|
|
1653
|
+
if (names.size > 0) {
|
|
1611
1654
|
for (const field of hookReads)
|
|
1612
|
-
if (!
|
|
1655
|
+
if (!names.has(field))
|
|
1613
1656
|
strippedAfterHook.add(field);
|
|
1614
1657
|
}
|
|
1615
1658
|
}
|
|
1659
|
+
// A projection that names no attribute the hook rewrites (no offloaded,
|
|
1660
|
+
// packed or bytes attribute) installs no hook, and prefetches nothing.
|
|
1661
|
+
const prefetch = state.prefetch === undefined || (projected && activeRawRow(state) === undefined)
|
|
1662
|
+
? undefined
|
|
1663
|
+
: state.prefetch;
|
|
1664
|
+
const operation = state.isScan ? "scan" : "query";
|
|
1616
1665
|
const items = [];
|
|
1617
1666
|
const rows = [];
|
|
1618
1667
|
let next = 0;
|
|
1619
1668
|
while (next < returned.length) {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1669
|
+
// The window: the rows the budget can still take. A row the query
|
|
1670
|
+
// drops by its raw form (history rows, a per-row key bound — #133,
|
|
1671
|
+
// #171) is judged before it is hydrated or loaded, so it never takes a
|
|
1672
|
+
// place in the window: only a rejection known after decode (a client
|
|
1673
|
+
// predicate) opens the whole response. A row past the window is never
|
|
1674
|
+
// hydrated, loaded — no offloaded value fetched (#179) — or decoded.
|
|
1675
|
+
const room = budget === undefined || predicated ? Infinity : budget - items.length;
|
|
1623
1676
|
const positions = [];
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1677
|
+
let end = next;
|
|
1678
|
+
while (end < returned.length && positions.length < room) {
|
|
1679
|
+
if (!isExcludedRow(state, returned[end]))
|
|
1680
|
+
positions.push(end);
|
|
1681
|
+
end++;
|
|
1627
1682
|
}
|
|
1628
1683
|
const sources = yield* hydrateRows(client, tableName, state, positions.map((i) => returned[i]));
|
|
1684
|
+
const raws = [];
|
|
1629
1685
|
for (let k = 0; k < positions.length; k++) {
|
|
1630
1686
|
const source = sources[k];
|
|
1631
1687
|
if (source === undefined)
|
|
@@ -1635,15 +1691,22 @@ const examinePage = (client, tableName, state, returned, budget, borrowedFields)
|
|
|
1635
1691
|
if (!hookReads.has(field) && !kept.has(field))
|
|
1636
1692
|
delete raw[field];
|
|
1637
1693
|
}
|
|
1638
|
-
|
|
1694
|
+
raws.push([positions[k], raw]);
|
|
1695
|
+
}
|
|
1696
|
+
// The window's offloaded values resolve together (design §8.2).
|
|
1697
|
+
if (prefetch !== undefined && raws.length > 0) {
|
|
1698
|
+
yield* prefetch(raws.map(([, raw]) => raw), { modes, raw: projected, operation });
|
|
1699
|
+
}
|
|
1700
|
+
for (const [position, raw] of raws) {
|
|
1701
|
+
const item = (yield* state.decoder(raw, modes));
|
|
1639
1702
|
for (const field of strippedAfterHook)
|
|
1640
1703
|
delete raw[field];
|
|
1641
|
-
if (
|
|
1704
|
+
if (predicated && !accepts(state, item))
|
|
1642
1705
|
continue;
|
|
1643
1706
|
items.push(item);
|
|
1644
|
-
rows.push(
|
|
1707
|
+
rows.push(position);
|
|
1645
1708
|
if (budget !== undefined && items.length >= budget) {
|
|
1646
|
-
return { items, stoppedAt:
|
|
1709
|
+
return { items, stoppedAt: position, accepted: items.length, rows };
|
|
1647
1710
|
}
|
|
1648
1711
|
}
|
|
1649
1712
|
next = end;
|
|
@@ -1668,7 +1731,8 @@ export const operationOptions = (self) => ({
|
|
|
1668
1731
|
* Stops at {@link limit} items when one is set, otherwise reads to the end of
|
|
1669
1732
|
* the key range (or {@link maxPages} requests).
|
|
1670
1733
|
*/
|
|
1671
|
-
export const collect = (self) => Capacity.delegate("Query.collect", operationOptions(self),
|
|
1734
|
+
export const collect = (self) => Capacity.delegate("Query.collect", operationOptions(self), collectCore(self));
|
|
1735
|
+
const collectCore = (self) => Effect.gen(function* () {
|
|
1672
1736
|
const client = yield* Capacity.client;
|
|
1673
1737
|
const tableName = self._state.resolveTableName
|
|
1674
1738
|
? yield* self._state.resolveTableName
|
|
@@ -1679,7 +1743,7 @@ export const collect = (self) => Capacity.delegate("Query.collect", operationOpt
|
|
|
1679
1743
|
return yield* collectRanges(client, tableName, state, ranges);
|
|
1680
1744
|
const pages = yield* Stream.runCollect(pageStream(client, tableName, state));
|
|
1681
1745
|
return pages.flat();
|
|
1682
|
-
})
|
|
1746
|
+
});
|
|
1683
1747
|
/**
|
|
1684
1748
|
* @internal The ranges a `collect` drains independently (design §9.3): a
|
|
1685
1749
|
* precise plan read to its end — no `limit`, no `maxPages`, no skip tuple —
|
|
@@ -2217,7 +2281,7 @@ const countCore = (self) => Effect.gen(function* () {
|
|
|
2217
2281
|
// predicate the database cannot evaluate, and the alternative is a wrong
|
|
2218
2282
|
// number (#122).
|
|
2219
2283
|
if (state.predicates.length > 0) {
|
|
2220
|
-
const items = yield*
|
|
2284
|
+
const items = yield* collectCore(self);
|
|
2221
2285
|
return items.length;
|
|
2222
2286
|
}
|
|
2223
2287
|
if (state.fanOutStart !== undefined) {
|