effect-dynamodb 1.39.0 → 1.41.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/README.md +1 -1
- package/dist/Aggregate.d.ts +138 -16
- package/dist/Aggregate.d.ts.map +1 -1
- package/dist/Aggregate.js +4298 -725
- package/dist/Aggregate.js.map +1 -1
- package/dist/Batch.d.ts +9 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +28 -44
- package/dist/Batch.js.map +1 -1
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +16 -9
- package/dist/Collection.js.map +1 -1
- package/dist/ConsumedCapacity.js +1 -1
- package/dist/ConsumedCapacity.js.map +1 -1
- package/dist/DynamoClient.d.ts +44 -21
- package/dist/DynamoClient.d.ts.map +1 -1
- package/dist/DynamoClient.js +342 -124
- package/dist/DynamoClient.js.map +1 -1
- package/dist/Entity.d.ts +246 -41
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +6818 -1166
- package/dist/Entity.js.map +1 -1
- package/dist/EventStore.d.ts +37 -15
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +403 -163
- package/dist/EventStore.js.map +1 -1
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +40 -24
- package/dist/Expression.js.map +1 -1
- package/dist/Marshaller.d.ts +72 -11
- package/dist/Marshaller.d.ts.map +1 -1
- package/dist/Marshaller.js +625 -71
- package/dist/Marshaller.js.map +1 -1
- package/dist/Query.d.ts +103 -5
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +262 -15
- package/dist/Query.js.map +1 -1
- package/dist/StorageEncoding.d.ts +7 -1
- package/dist/StorageEncoding.d.ts.map +1 -1
- package/dist/StorageEncoding.js +8 -2
- package/dist/StorageEncoding.js.map +1 -1
- package/dist/Table.d.ts +338 -16
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +30 -2
- package/dist/Table.js.map +1 -1
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +70 -7
- package/dist/Transaction.js.map +1 -1
- package/dist/VectorSearchEmulation.d.ts.map +1 -1
- package/dist/VectorSearchEmulation.js +4 -3
- package/dist/VectorSearchEmulation.js.map +1 -1
- package/dist/change-feed/ChangeFeed.d.ts +8 -3
- package/dist/change-feed/ChangeFeed.d.ts.map +1 -1
- package/dist/change-feed/ChangeFeed.js +76 -9
- package/dist/change-feed/ChangeFeed.js.map +1 -1
- package/dist/change-feed/CheckpointStore.js +1 -1
- package/dist/change-feed/CheckpointStore.js.map +1 -1
- package/dist/change-feed/DynamoStreamsClient.d.ts +19 -10
- package/dist/change-feed/DynamoStreamsClient.d.ts.map +1 -1
- package/dist/change-feed/DynamoStreamsClient.js +24 -14
- package/dist/change-feed/DynamoStreamsClient.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/BoundCrud.d.ts +78 -32
- package/dist/internal/BoundCrud.d.ts.map +1 -1
- package/dist/internal/BoundCrud.js +25 -0
- package/dist/internal/BoundCrud.js.map +1 -1
- package/dist/internal/BoundQuery.d.ts +46 -3
- package/dist/internal/BoundQuery.d.ts.map +1 -1
- package/dist/internal/BoundQuery.js +402 -37
- package/dist/internal/BoundQuery.js.map +1 -1
- package/dist/internal/BoundVectorQuery.d.ts +6 -0
- package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
- package/dist/internal/BoundVectorQuery.js +7 -4
- package/dist/internal/BoundVectorQuery.js.map +1 -1
- package/dist/internal/Capacity.d.ts +46 -5
- package/dist/internal/Capacity.d.ts.map +1 -1
- package/dist/internal/Capacity.js +177 -26
- package/dist/internal/Capacity.js.map +1 -1
- package/dist/internal/ClientOptions.d.ts +144 -0
- package/dist/internal/ClientOptions.d.ts.map +1 -0
- package/dist/internal/ClientOptions.js +290 -0
- package/dist/internal/ClientOptions.js.map +1 -0
- package/dist/internal/ConditionHolds.d.ts +29 -0
- package/dist/internal/ConditionHolds.d.ts.map +1 -0
- package/dist/internal/ConditionHolds.js +453 -0
- package/dist/internal/ConditionHolds.js.map +1 -0
- package/dist/internal/Cursor.d.ts +19 -10
- package/dist/internal/Cursor.d.ts.map +1 -1
- package/dist/internal/Cursor.js +25 -10
- package/dist/internal/Cursor.js.map +1 -1
- package/dist/internal/Digest.d.ts +20 -0
- package/dist/internal/Digest.d.ts.map +1 -0
- package/dist/internal/Digest.js +106 -0
- package/dist/internal/Digest.js.map +1 -0
- package/dist/internal/DynamoArithmetic.d.ts +33 -0
- package/dist/internal/DynamoArithmetic.d.ts.map +1 -0
- package/dist/internal/DynamoArithmetic.js +112 -0
- package/dist/internal/DynamoArithmetic.js.map +1 -0
- package/dist/internal/EntityCombinators.d.ts +23 -8
- package/dist/internal/EntityCombinators.d.ts.map +1 -1
- package/dist/internal/EntityCombinators.js +6 -2
- package/dist/internal/EntityCombinators.js.map +1 -1
- package/dist/internal/EntityOps.d.ts +69 -8
- package/dist/internal/EntityOps.d.ts.map +1 -1
- package/dist/internal/EntityOps.js.map +1 -1
- package/dist/internal/EventProjection.d.ts +18 -4
- package/dist/internal/EventProjection.d.ts.map +1 -1
- package/dist/internal/EventProjection.js +36 -8
- package/dist/internal/EventProjection.js.map +1 -1
- package/dist/internal/Expr.d.ts +72 -2
- package/dist/internal/Expr.d.ts.map +1 -1
- package/dist/internal/Expr.js +264 -5
- package/dist/internal/Expr.js.map +1 -1
- package/dist/internal/ExpressionLimits.d.ts +57 -1
- package/dist/internal/ExpressionLimits.d.ts.map +1 -1
- package/dist/internal/ExpressionLimits.js +97 -4
- package/dist/internal/ExpressionLimits.js.map +1 -1
- package/dist/internal/FormGuard.d.ts +52 -0
- package/dist/internal/FormGuard.d.ts.map +1 -0
- package/dist/internal/FormGuard.js +83 -0
- package/dist/internal/FormGuard.js.map +1 -0
- package/dist/internal/Hydrate.d.ts.map +1 -1
- package/dist/internal/Hydrate.js +2 -1
- package/dist/internal/Hydrate.js.map +1 -1
- package/dist/internal/InputForm.d.ts +24 -0
- package/dist/internal/InputForm.d.ts.map +1 -0
- package/dist/internal/InputForm.js +44 -0
- package/dist/internal/InputForm.js.map +1 -0
- package/dist/internal/InsertStatement.d.ts +15 -0
- package/dist/internal/InsertStatement.d.ts.map +1 -0
- package/dist/internal/InsertStatement.js +18 -0
- package/dist/internal/InsertStatement.js.map +1 -0
- package/dist/internal/ItemSize.d.ts +108 -4
- package/dist/internal/ItemSize.d.ts.map +1 -1
- package/dist/internal/ItemSize.js +190 -3
- package/dist/internal/ItemSize.js.map +1 -1
- package/dist/internal/MultiProjection.d.ts +7 -2
- package/dist/internal/MultiProjection.d.ts.map +1 -1
- package/dist/internal/MultiProjection.js +18 -12
- package/dist/internal/MultiProjection.js.map +1 -1
- package/dist/internal/OperandReaders.d.ts +36 -0
- package/dist/internal/OperandReaders.d.ts.map +1 -0
- package/dist/internal/OperandReaders.js +176 -0
- package/dist/internal/OperandReaders.js.map +1 -0
- package/dist/internal/Packed.d.ts.map +1 -1
- package/dist/internal/Packed.js +11 -10
- package/dist/internal/Packed.js.map +1 -1
- package/dist/internal/PathBuilder.d.ts +57 -8
- package/dist/internal/PathBuilder.d.ts.map +1 -1
- package/dist/internal/PathBuilder.js +98 -24
- package/dist/internal/PathBuilder.js.map +1 -1
- package/dist/internal/ProjectionEngine.d.ts +196 -3
- package/dist/internal/ProjectionEngine.d.ts.map +1 -1
- package/dist/internal/ProjectionEngine.js +1251 -86
- package/dist/internal/ProjectionEngine.js.map +1 -1
- package/dist/internal/Rekey.d.ts +187 -21
- package/dist/internal/Rekey.d.ts.map +1 -1
- package/dist/internal/Rekey.js +1349 -63
- package/dist/internal/Rekey.js.map +1 -1
- package/dist/internal/ReturnedItem.d.ts +23 -0
- package/dist/internal/ReturnedItem.d.ts.map +1 -0
- package/dist/internal/ReturnedItem.js +39 -0
- package/dist/internal/ReturnedItem.js.map +1 -0
- package/dist/internal/RoundTrip.d.ts +45 -0
- package/dist/internal/RoundTrip.d.ts.map +1 -0
- package/dist/internal/RoundTrip.js +106 -0
- package/dist/internal/RoundTrip.js.map +1 -0
- package/dist/internal/SentRequest.d.ts +14 -0
- package/dist/internal/SentRequest.d.ts.map +1 -0
- package/dist/internal/SentRequest.js +31 -0
- package/dist/internal/SentRequest.js.map +1 -0
- package/dist/internal/TransactPlan.d.ts.map +1 -1
- package/dist/internal/TransactPlan.js +4 -0
- package/dist/internal/TransactPlan.js.map +1 -1
- package/dist/internal/TransactWriteOps.d.ts +70 -15
- package/dist/internal/TransactWriteOps.d.ts.map +1 -1
- package/dist/internal/TransactWriteOps.js +166 -112
- package/dist/internal/TransactWriteOps.js.map +1 -1
- package/dist/internal/TransactableOps.d.ts +230 -27
- package/dist/internal/TransactableOps.d.ts.map +1 -1
- package/dist/internal/TransactableOps.js +549 -92
- package/dist/internal/TransactableOps.js.map +1 -1
- package/dist/internal/WriteDiagnosis.d.ts +66 -3
- package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
- package/dist/internal/WriteDiagnosis.js +261 -15
- package/dist/internal/WriteDiagnosis.js.map +1 -1
- package/package.json +5 -5
package/dist/Query.js
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
* Implements Pipeable for ergonomic composition.
|
|
9
9
|
*/
|
|
10
10
|
import { ValidationError } from "@effect-dynamodb/schema/Errors.js";
|
|
11
|
+
import { ownValue, setOwn } from "@effect-dynamodb/schema/internal/OwnNames.js";
|
|
11
12
|
import * as Projection from "@effect-dynamodb/schema/Projection.js";
|
|
12
13
|
import { Effect, Function, Option, Pipeable, Result, Stream } from "effect";
|
|
13
14
|
import { DynamoClient } from "./DynamoClient.js";
|
|
14
15
|
import * as Capacity from "./internal/Capacity.js";
|
|
15
16
|
import * as Cursor from "./internal/Cursor.js";
|
|
16
|
-
import { compileExpr, ExprTag, emptyPartProblem, isEmptyExpr } from "./internal/Expr.js";
|
|
17
|
+
import { compileExpr, ExprTag, emptyPartProblem, isEmptyExpr, operandsAsStored, } from "./internal/Expr.js";
|
|
17
18
|
import { batchGetRaw } from "./internal/Hydrate.js";
|
|
18
19
|
import { packedExprRefusal, packedProjectionRefusal, } from "./internal/Packed.js";
|
|
19
|
-
import { compilePath } from "./internal/PathBuilder.js";
|
|
20
|
+
import { compilePath, storedPath } from "./internal/PathBuilder.js";
|
|
20
21
|
import { canonicalJson, compositePlanner, cursorRefusal, DEFAULT_MAX_SKIPS, displayKeyCondition, fnv1a32, JUMP_INITIAL, JUMP_MAX_LIMIT, keyConditionHolds, readFrom, toKeyCondition, } from "./internal/RangePlanner.js";
|
|
21
22
|
import * as ShardMerge from "./internal/ShardMerge.js";
|
|
22
23
|
import { diagnoseFailure, explainDiagnosis, withCause } from "./internal/WriteDiagnosis.js";
|
|
@@ -70,6 +71,7 @@ class QueryImpl {
|
|
|
70
71
|
export const make = (config) => new QueryImpl({
|
|
71
72
|
rawRow: config.rawRow,
|
|
72
73
|
packed: config.packed ?? [],
|
|
74
|
+
storedAt: config.storedAt,
|
|
73
75
|
liveRows: config.liveRows,
|
|
74
76
|
prepare: config.prepare,
|
|
75
77
|
keepRow: undefined,
|
|
@@ -117,6 +119,7 @@ export const make = (config) => new QueryImpl({
|
|
|
117
119
|
export const makeScan = (config) => new QueryImpl({
|
|
118
120
|
rawRow: config.rawRow,
|
|
119
121
|
packed: config.packed ?? [],
|
|
122
|
+
storedAt: config.storedAt,
|
|
120
123
|
liveRows: config.liveRows,
|
|
121
124
|
prepare: config.prepare,
|
|
122
125
|
keepRow: undefined,
|
|
@@ -220,6 +223,39 @@ export const fanOut = (self, read) => read.fanOut === undefined
|
|
|
220
223
|
pkValue: read.partitions[0],
|
|
221
224
|
fanOut: { ...read.fanOut, partitions: read.partitions },
|
|
222
225
|
});
|
|
226
|
+
/**
|
|
227
|
+
* @internal A query whose terminals fail with `refusal`: building one has no error
|
|
228
|
+
* channel to fail into, and a value a key can't hold is the caller's error, not a
|
|
229
|
+
* defect. Nothing is sent.
|
|
230
|
+
*/
|
|
231
|
+
export const refuse = (self, refusal) => new QueryImpl({ ...self._state, refusal });
|
|
232
|
+
/** @internal Has {@link refuse} refused this query? Its builders have nothing left to do. */
|
|
233
|
+
export const isRefused = (self) => self._state.refusal !== undefined;
|
|
234
|
+
/** @internal A query that could not even be built: a composite it was given has no key. */
|
|
235
|
+
export const refused = (indexName, refusal) => refuse(make({
|
|
236
|
+
tableName: "",
|
|
237
|
+
indexName,
|
|
238
|
+
pkField: "",
|
|
239
|
+
pkValue: "",
|
|
240
|
+
skField: undefined,
|
|
241
|
+
entityTypes: [],
|
|
242
|
+
decoder: () => Effect.die(refusal),
|
|
243
|
+
}), refusal);
|
|
244
|
+
/**
|
|
245
|
+
* @internal What `build` returns, or `onRefusal` of the `ValidationError` for a value it
|
|
246
|
+
* threw for (`Capacity.isRefusedValue`). Any other throw is a misuse of the API and stays one.
|
|
247
|
+
*/
|
|
248
|
+
export const orRefusal = (operation, build, onRefusal) => {
|
|
249
|
+
try {
|
|
250
|
+
return build();
|
|
251
|
+
}
|
|
252
|
+
catch (cause) {
|
|
253
|
+
if (!Capacity.isRefusedValue(cause))
|
|
254
|
+
throw cause;
|
|
255
|
+
const name = operation?.name ?? "query";
|
|
256
|
+
return onRefusal(new ValidationError({ entityType: operation?.target ?? name, operation: name, cause }));
|
|
257
|
+
}
|
|
258
|
+
};
|
|
223
259
|
/** @internal Does this query read a sharded index's partitions (#183)? */
|
|
224
260
|
export const isFanOut = (self) => self._state.fanOut !== undefined;
|
|
225
261
|
/**
|
|
@@ -466,20 +502,210 @@ export const selectProjected = (self, storedPaths, decode) => {
|
|
|
466
502
|
decoder: (raw) => Effect.map(rawRow(raw), (row) => decode(row)),
|
|
467
503
|
});
|
|
468
504
|
};
|
|
505
|
+
/**
|
|
506
|
+
* @internal A select no `ProjectionExpression` can express (#238): a sparse map is stored one
|
|
507
|
+
* attribute per entry (`<prefix>#<key>`), and a projection can't name attributes by prefix. The
|
|
508
|
+
* rows are read whole. Each row is first cut to what a projection of `storedPaths` would return
|
|
509
|
+
* ({@link projectRow}: the other selected paths, under their stored names), and that goes through
|
|
510
|
+
* exactly what a projected row goes through: the raw-row hook, given what it reads to dispatch
|
|
511
|
+
* (taken back off after it ran, as off a projected row), and only where a projection of
|
|
512
|
+
* `storedPaths` would run it. Nothing the select doesn't name is unpacked, decompressed or
|
|
513
|
+
* checked. `decode` gets that, and the whole row, from which it takes the sparse maps selected.
|
|
514
|
+
*/
|
|
515
|
+
export const selectWhole = (self, storedPaths, decode) => {
|
|
516
|
+
if (self._state.predicates.length > 0) {
|
|
517
|
+
throw new Error(rejectPredicateWithProjection("select() after filterBy()"));
|
|
518
|
+
}
|
|
519
|
+
refusePackedProjection(self._state, storedPaths);
|
|
520
|
+
const hook = projectedRawRow(self._state.rawRow, storedPaths);
|
|
521
|
+
const reads = hook?.reads ?? [];
|
|
522
|
+
return new QueryImpl({
|
|
523
|
+
...self._state,
|
|
524
|
+
projection: undefined,
|
|
525
|
+
projectionPaths: undefined,
|
|
526
|
+
selectsWholeRows: true,
|
|
527
|
+
decoder: (raw) => {
|
|
528
|
+
const projected = projectRow(raw, storedPaths);
|
|
529
|
+
if (hook === undefined)
|
|
530
|
+
return Effect.succeed(decode(projected, raw));
|
|
531
|
+
const borrowed = reads.filter((attribute) => !Object.hasOwn(projected, attribute) && Object.hasOwn(raw, attribute));
|
|
532
|
+
for (const attribute of borrowed)
|
|
533
|
+
projected[attribute] = raw[attribute];
|
|
534
|
+
return Effect.map(hook(projected), (row) => {
|
|
535
|
+
const hooked = row;
|
|
536
|
+
for (const attribute of borrowed)
|
|
537
|
+
delete hooked[attribute];
|
|
538
|
+
return decode(hooked, raw);
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
/** Whether a value is a map a path's name segment can step into: a plain object. */
|
|
544
|
+
const isPlainMap = (value) => {
|
|
545
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
546
|
+
return false;
|
|
547
|
+
const prototype = Object.getPrototypeOf(value);
|
|
548
|
+
return prototype === Object.prototype || prototype === null;
|
|
549
|
+
};
|
|
550
|
+
/** Put `value` at `path` in `root`, unless a value selected whole above it holds it already. */
|
|
551
|
+
const place = (root, path, value) => {
|
|
552
|
+
let at = root;
|
|
553
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
554
|
+
const member = at.members.get(path[i]);
|
|
555
|
+
if (member !== undefined && !("members" in member))
|
|
556
|
+
return;
|
|
557
|
+
const next = member ?? { list: typeof path[i + 1] === "number", members: new Map() };
|
|
558
|
+
at.members.set(path[i], next);
|
|
559
|
+
at = next;
|
|
560
|
+
}
|
|
561
|
+
at.members.set(path[path.length - 1], { value });
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* @internal What a `ProjectionExpression` of `paths` returns of `row`, worked out on the row
|
|
565
|
+
* itself (#238): each path's value, under the maps and lists that hold it, a list keeping the
|
|
566
|
+
* positions selected in position order; nothing for a path the row doesn't hold (a name on
|
|
567
|
+
* anything but a map, a position on anything but a list, or past its end). A path inside one
|
|
568
|
+
* selected whole is held by it.
|
|
569
|
+
*/
|
|
570
|
+
export const projectRow = (row, paths) => {
|
|
571
|
+
const root = { list: false, members: new Map() };
|
|
572
|
+
for (const path of paths) {
|
|
573
|
+
let value = row;
|
|
574
|
+
let held = path.length > 0;
|
|
575
|
+
for (const segment of path) {
|
|
576
|
+
if (typeof segment === "number") {
|
|
577
|
+
held = Array.isArray(value) && segment >= 0 && segment < value.length;
|
|
578
|
+
if (held)
|
|
579
|
+
value = value[segment];
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
held = isPlainMap(value) && Object.hasOwn(value, segment);
|
|
583
|
+
if (held)
|
|
584
|
+
value = value[segment];
|
|
585
|
+
}
|
|
586
|
+
if (!held)
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
if (held)
|
|
590
|
+
place(root, path, value);
|
|
591
|
+
}
|
|
592
|
+
const built = (node) => {
|
|
593
|
+
const valueOf = (member) => "members" in member ? built(member) : member.value;
|
|
594
|
+
if (node.list) {
|
|
595
|
+
return [...node.members.entries()]
|
|
596
|
+
.sort(([a], [b]) => a - b)
|
|
597
|
+
.map(([, member]) => valueOf(member));
|
|
598
|
+
}
|
|
599
|
+
const map = {};
|
|
600
|
+
for (const [name, member] of node.members) {
|
|
601
|
+
Object.defineProperty(map, name, {
|
|
602
|
+
value: valueOf(member),
|
|
603
|
+
enumerable: true,
|
|
604
|
+
writable: true,
|
|
605
|
+
configurable: true,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
return map;
|
|
609
|
+
};
|
|
610
|
+
return built(root);
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* @internal How the values a select of `paths` projects are handed back by the names each was
|
|
614
|
+
* selected by (#238): a path whose segments below its field a struct stores under other names
|
|
615
|
+
* (`Schema.encodeKeys`) is projected by those ({@link storedPath}), and its value is handed back
|
|
616
|
+
* under the names written. Each of `paths` as written, beside it as stored, below the field. A name
|
|
617
|
+
* two paths wrote differently is handed back as stored. `undefined` when nothing is renamed: the
|
|
618
|
+
* values are handed back as they come.
|
|
619
|
+
*/
|
|
620
|
+
export const respelling = (paths) => {
|
|
621
|
+
const root = { names: new Map() };
|
|
622
|
+
let renamed = false;
|
|
623
|
+
for (const { written, stored } of paths) {
|
|
624
|
+
let node = root;
|
|
625
|
+
for (const [i, segment] of stored.entries()) {
|
|
626
|
+
if (typeof segment === "number") {
|
|
627
|
+
node.element ??= { names: new Map() };
|
|
628
|
+
node = node.element;
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const spelled = written[i];
|
|
632
|
+
const name = typeof spelled === "string" ? spelled : segment;
|
|
633
|
+
if (name !== segment)
|
|
634
|
+
renamed = true;
|
|
635
|
+
const step = node.names.get(segment);
|
|
636
|
+
if (step === undefined) {
|
|
637
|
+
const below = { names: new Map() };
|
|
638
|
+
node.names.set(segment, { written: name, below });
|
|
639
|
+
node = below;
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
if (step.written !== name)
|
|
643
|
+
step.written = segment;
|
|
644
|
+
node = step.below;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return renamed ? root : undefined;
|
|
649
|
+
};
|
|
650
|
+
/** @internal `value`, projected by stored names, handed back as {@link respelling} says. */
|
|
651
|
+
export const respelled = (value, plan) => {
|
|
652
|
+
if (plan === undefined)
|
|
653
|
+
return value;
|
|
654
|
+
if (Array.isArray(value)) {
|
|
655
|
+
const element = plan.element;
|
|
656
|
+
return element === undefined ? value : value.map((held) => respelled(held, element));
|
|
657
|
+
}
|
|
658
|
+
if (!isPlainMap(value) || plan.names.size === 0)
|
|
659
|
+
return value;
|
|
660
|
+
const out = {};
|
|
661
|
+
for (const key of Object.keys(value)) {
|
|
662
|
+
const step = plan.names.get(key);
|
|
663
|
+
Object.defineProperty(out, step?.written ?? key, {
|
|
664
|
+
value: step === undefined ? value[key] : respelled(value[key], step.below),
|
|
665
|
+
enumerable: true,
|
|
666
|
+
writable: true,
|
|
667
|
+
configurable: true,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
return out;
|
|
671
|
+
};
|
|
672
|
+
/**
|
|
673
|
+
* @internal Each head's {@link respelling}, for the paths `paths` selected, each stored as
|
|
674
|
+
* `storedOf` names it.
|
|
675
|
+
*/
|
|
676
|
+
export const respellings = (paths, storedOf) => {
|
|
677
|
+
const byHead = new Map();
|
|
678
|
+
for (const path of paths) {
|
|
679
|
+
const head = String(path[0]);
|
|
680
|
+
const held = byHead.get(head) ?? [];
|
|
681
|
+
held.push({ written: path.slice(1), stored: storedOf(path).slice(1) });
|
|
682
|
+
byHead.set(head, held);
|
|
683
|
+
}
|
|
684
|
+
const out = new Map();
|
|
685
|
+
for (const [head, held] of byHead) {
|
|
686
|
+
const plan = respelling(held);
|
|
687
|
+
if (plan !== undefined)
|
|
688
|
+
out.set(head, plan);
|
|
689
|
+
}
|
|
690
|
+
return out;
|
|
691
|
+
};
|
|
469
692
|
/**
|
|
470
693
|
* @internal `select` / `selectPaths` of DOMAIN field names on an entity that
|
|
471
|
-
* stores some under other names (`DynamoModel.configure(..., { field })
|
|
472
|
-
*
|
|
473
|
-
* by the domain names
|
|
694
|
+
* stores some under other names (`DynamoModel.configure(..., { field })`, or a
|
|
695
|
+
* struct's `Schema.encodeKeys` below one, #238): the projection names the
|
|
696
|
+
* stored attributes, and each item is handed back keyed by the domain names
|
|
697
|
+
* asked for (#133).
|
|
474
698
|
*/
|
|
475
|
-
export const selectRenamed = (self, paths, resolveDbName) => {
|
|
699
|
+
export const selectRenamed = (self, paths, resolveDbName, below) => {
|
|
476
700
|
const heads = [...new Set(paths.map((path) => String(path[0])))];
|
|
477
|
-
|
|
701
|
+
const storedOf = (path) => storedPath(path, resolveDbName, below);
|
|
702
|
+
const plans = respellings(paths, storedOf);
|
|
703
|
+
return selectProjected(self, paths.map(storedOf), (raw) => {
|
|
478
704
|
const item = {};
|
|
479
705
|
for (const head of heads) {
|
|
480
|
-
const value = raw
|
|
706
|
+
const value = ownValue(raw, resolveDbName(head));
|
|
481
707
|
if (value !== undefined)
|
|
482
|
-
item
|
|
708
|
+
setOwn(item, head, respelled(value, plans.get(head)));
|
|
483
709
|
}
|
|
484
710
|
return item;
|
|
485
711
|
});
|
|
@@ -494,7 +720,13 @@ export const selectRenamed = (self, paths, resolveDbName) => {
|
|
|
494
720
|
* `attribute_not_exists` to it, throws `[EDD-9076]`: DynamoDB sees one opaque
|
|
495
721
|
* value. Use {@link filterBy}, which runs on the decoded item.
|
|
496
722
|
*/
|
|
497
|
-
export const filterExpr = Function.dual(2, (self, expr) =>
|
|
723
|
+
export const filterExpr = Function.dual(2, (self, expr) => filterExprStored(self, self._state.storedAt === undefined ? expr : operandsAsStored(expr, self._state.storedAt)));
|
|
724
|
+
/**
|
|
725
|
+
* @internal {@link filterExpr} for an expression whose operands are already in the form its
|
|
726
|
+
* attributes hold (`operandsAsStored`, #242), with its paths' stored names: added as it is. A bound
|
|
727
|
+
* query's and `Entity.filter`'s, which put them so with the names their own owner resolves.
|
|
728
|
+
*/
|
|
729
|
+
export const filterExprStored = (self, expr) => {
|
|
498
730
|
// A filter that asserts nothing (`.filter({})`, `and()`) is no filter: it is
|
|
499
731
|
// dropped here, never sent as `FilterExpression: ""`, which DynamoDB
|
|
500
732
|
// rejects (#133). An empty part anywhere else — under `or` or `not`, or an
|
|
@@ -509,7 +741,7 @@ export const filterExpr = Function.dual(2, (self, expr) => {
|
|
|
509
741
|
...self._state,
|
|
510
742
|
exprFilters: [...self._state.exprFilters, expr],
|
|
511
743
|
});
|
|
512
|
-
}
|
|
744
|
+
};
|
|
513
745
|
/**
|
|
514
746
|
* Add a **client-side** predicate, evaluated on the decoded item.
|
|
515
747
|
*
|
|
@@ -548,7 +780,9 @@ export const filterExpr = Function.dual(2, (self, expr) => {
|
|
|
548
780
|
* item missing the attributes it reads — see EDD-9054.
|
|
549
781
|
*/
|
|
550
782
|
export const filterBy = Function.dual(2, (self, predicate) => {
|
|
551
|
-
if (self._state.projection !== undefined ||
|
|
783
|
+
if (self._state.projection !== undefined ||
|
|
784
|
+
self._state.projectionPaths !== undefined ||
|
|
785
|
+
self._state.selectsWholeRows === true) {
|
|
552
786
|
throw new Error(rejectPredicateWithProjection("filterBy() after select()"));
|
|
553
787
|
}
|
|
554
788
|
return new QueryImpl({
|
|
@@ -1053,6 +1287,8 @@ const refuseEmptyFilterParts = (state) => {
|
|
|
1053
1287
|
* first step (#171).
|
|
1054
1288
|
*/
|
|
1055
1289
|
const prepared = (state, tableName) => {
|
|
1290
|
+
if (state.refusal !== undefined)
|
|
1291
|
+
return Effect.fail(state.refusal);
|
|
1056
1292
|
// `.within()` is offered only where no prepare step is installed (an
|
|
1057
1293
|
// entity's `versions` installs one).
|
|
1058
1294
|
if (state.planner !== undefined && state.prepare !== undefined) {
|
|
@@ -1286,10 +1522,10 @@ const keyOfItem = (item, names) => {
|
|
|
1286
1522
|
return undefined;
|
|
1287
1523
|
const key = {};
|
|
1288
1524
|
for (const name of names) {
|
|
1289
|
-
const value = item
|
|
1525
|
+
const value = ownValue(item, name);
|
|
1290
1526
|
if (value === undefined)
|
|
1291
1527
|
return undefined;
|
|
1292
|
-
key
|
|
1528
|
+
setOwn(key, name, value);
|
|
1293
1529
|
}
|
|
1294
1530
|
return key;
|
|
1295
1531
|
};
|
|
@@ -2158,6 +2394,17 @@ const countPlanned = (client, tableName, state, plan) => Effect.gen(function* ()
|
|
|
2158
2394
|
*/
|
|
2159
2395
|
export const explain = (self) => Effect.sync(() => {
|
|
2160
2396
|
const state = self._state;
|
|
2397
|
+
if (state.refusal !== undefined) {
|
|
2398
|
+
return {
|
|
2399
|
+
index: state.indexName ?? "primary",
|
|
2400
|
+
plan: "empty",
|
|
2401
|
+
reason: `refused: ${state.refusal.message}`,
|
|
2402
|
+
keyConditions: [],
|
|
2403
|
+
filter: undefined,
|
|
2404
|
+
rowChecks: [],
|
|
2405
|
+
sizing: explainedSizing(state),
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2161
2408
|
if (state.fanOut !== undefined)
|
|
2162
2409
|
return explainFanOut(state, state.fanOut);
|
|
2163
2410
|
const factory = state.planner;
|
|
@@ -2195,7 +2442,7 @@ const explainedSizing = (state) => {
|
|
|
2195
2442
|
*/
|
|
2196
2443
|
export const asParams = (self) => Effect.gen(function* () {
|
|
2197
2444
|
const state = self._state;
|
|
2198
|
-
const refusal = refuseEmptyFilterParts(state);
|
|
2445
|
+
const refusal = state.refusal ?? refuseEmptyFilterParts(state);
|
|
2199
2446
|
if (refusal !== undefined)
|
|
2200
2447
|
return yield* refusal;
|
|
2201
2448
|
const tableName = state.resolveTableName ? yield* state.resolveTableName : state.tableName;
|