effect-dynamodb 1.40.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.
Files changed (158) hide show
  1. package/README.md +1 -1
  2. package/dist/Aggregate.d.ts +19 -1
  3. package/dist/Aggregate.d.ts.map +1 -1
  4. package/dist/Aggregate.js +2387 -456
  5. package/dist/Aggregate.js.map +1 -1
  6. package/dist/Collection.d.ts.map +1 -1
  7. package/dist/Collection.js +4 -4
  8. package/dist/Collection.js.map +1 -1
  9. package/dist/DynamoClient.d.ts +25 -16
  10. package/dist/DynamoClient.d.ts.map +1 -1
  11. package/dist/DynamoClient.js +131 -69
  12. package/dist/DynamoClient.js.map +1 -1
  13. package/dist/Entity.d.ts +164 -24
  14. package/dist/Entity.d.ts.map +1 -1
  15. package/dist/Entity.js +4276 -860
  16. package/dist/Entity.js.map +1 -1
  17. package/dist/EventStore.d.ts.map +1 -1
  18. package/dist/EventStore.js +189 -85
  19. package/dist/EventStore.js.map +1 -1
  20. package/dist/Expression.d.ts.map +1 -1
  21. package/dist/Expression.js +40 -24
  22. package/dist/Expression.js.map +1 -1
  23. package/dist/Marshaller.d.ts +38 -7
  24. package/dist/Marshaller.d.ts.map +1 -1
  25. package/dist/Marshaller.js +265 -62
  26. package/dist/Marshaller.js.map +1 -1
  27. package/dist/Query.d.ts +80 -5
  28. package/dist/Query.d.ts.map +1 -1
  29. package/dist/Query.js +214 -13
  30. package/dist/Query.js.map +1 -1
  31. package/dist/Table.d.ts +275 -14
  32. package/dist/Table.d.ts.map +1 -1
  33. package/dist/Table.js +30 -2
  34. package/dist/Table.js.map +1 -1
  35. package/dist/Transaction.d.ts.map +1 -1
  36. package/dist/Transaction.js +60 -3
  37. package/dist/Transaction.js.map +1 -1
  38. package/dist/VectorSearchEmulation.d.ts.map +1 -1
  39. package/dist/VectorSearchEmulation.js +4 -3
  40. package/dist/VectorSearchEmulation.js.map +1 -1
  41. package/dist/change-feed/DynamoStreamsClient.d.ts +8 -6
  42. package/dist/change-feed/DynamoStreamsClient.d.ts.map +1 -1
  43. package/dist/change-feed/DynamoStreamsClient.js +11 -7
  44. package/dist/change-feed/DynamoStreamsClient.js.map +1 -1
  45. package/dist/index.d.ts +2 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/internal/BoundCrud.d.ts +39 -1
  50. package/dist/internal/BoundCrud.d.ts.map +1 -1
  51. package/dist/internal/BoundCrud.js +25 -0
  52. package/dist/internal/BoundCrud.js.map +1 -1
  53. package/dist/internal/BoundQuery.d.ts +46 -3
  54. package/dist/internal/BoundQuery.d.ts.map +1 -1
  55. package/dist/internal/BoundQuery.js +383 -28
  56. package/dist/internal/BoundQuery.js.map +1 -1
  57. package/dist/internal/BoundVectorQuery.d.ts +6 -0
  58. package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
  59. package/dist/internal/BoundVectorQuery.js +6 -4
  60. package/dist/internal/BoundVectorQuery.js.map +1 -1
  61. package/dist/internal/Capacity.d.ts +2 -1
  62. package/dist/internal/Capacity.d.ts.map +1 -1
  63. package/dist/internal/Capacity.js +89 -12
  64. package/dist/internal/Capacity.js.map +1 -1
  65. package/dist/internal/ClientOptions.d.ts +72 -0
  66. package/dist/internal/ClientOptions.d.ts.map +1 -1
  67. package/dist/internal/ClientOptions.js +212 -1
  68. package/dist/internal/ClientOptions.js.map +1 -1
  69. package/dist/internal/ConditionHolds.d.ts +29 -0
  70. package/dist/internal/ConditionHolds.d.ts.map +1 -0
  71. package/dist/internal/ConditionHolds.js +453 -0
  72. package/dist/internal/ConditionHolds.js.map +1 -0
  73. package/dist/internal/Digest.d.ts +20 -0
  74. package/dist/internal/Digest.d.ts.map +1 -0
  75. package/dist/internal/Digest.js +106 -0
  76. package/dist/internal/Digest.js.map +1 -0
  77. package/dist/internal/DynamoArithmetic.d.ts +33 -0
  78. package/dist/internal/DynamoArithmetic.d.ts.map +1 -0
  79. package/dist/internal/DynamoArithmetic.js +112 -0
  80. package/dist/internal/DynamoArithmetic.js.map +1 -0
  81. package/dist/internal/EntityCombinators.d.ts +2 -2
  82. package/dist/internal/EntityCombinators.d.ts.map +1 -1
  83. package/dist/internal/EntityCombinators.js.map +1 -1
  84. package/dist/internal/EntityOps.d.ts +58 -7
  85. package/dist/internal/EntityOps.d.ts.map +1 -1
  86. package/dist/internal/EntityOps.js.map +1 -1
  87. package/dist/internal/EventProjection.d.ts +3 -1
  88. package/dist/internal/EventProjection.d.ts.map +1 -1
  89. package/dist/internal/EventProjection.js +9 -0
  90. package/dist/internal/EventProjection.js.map +1 -1
  91. package/dist/internal/Expr.d.ts +72 -2
  92. package/dist/internal/Expr.d.ts.map +1 -1
  93. package/dist/internal/Expr.js +211 -3
  94. package/dist/internal/Expr.js.map +1 -1
  95. package/dist/internal/ExpressionLimits.d.ts.map +1 -1
  96. package/dist/internal/ExpressionLimits.js +10 -6
  97. package/dist/internal/ExpressionLimits.js.map +1 -1
  98. package/dist/internal/FormGuard.d.ts +52 -0
  99. package/dist/internal/FormGuard.d.ts.map +1 -0
  100. package/dist/internal/FormGuard.js +83 -0
  101. package/dist/internal/FormGuard.js.map +1 -0
  102. package/dist/internal/Hydrate.d.ts.map +1 -1
  103. package/dist/internal/Hydrate.js +2 -1
  104. package/dist/internal/Hydrate.js.map +1 -1
  105. package/dist/internal/InputForm.d.ts +24 -0
  106. package/dist/internal/InputForm.d.ts.map +1 -0
  107. package/dist/internal/InputForm.js +44 -0
  108. package/dist/internal/InputForm.js.map +1 -0
  109. package/dist/internal/InsertStatement.d.ts +15 -0
  110. package/dist/internal/InsertStatement.d.ts.map +1 -0
  111. package/dist/internal/InsertStatement.js +18 -0
  112. package/dist/internal/InsertStatement.js.map +1 -0
  113. package/dist/internal/MultiProjection.d.ts.map +1 -1
  114. package/dist/internal/MultiProjection.js +9 -9
  115. package/dist/internal/MultiProjection.js.map +1 -1
  116. package/dist/internal/OperandReaders.d.ts +36 -0
  117. package/dist/internal/OperandReaders.d.ts.map +1 -0
  118. package/dist/internal/OperandReaders.js +176 -0
  119. package/dist/internal/OperandReaders.js.map +1 -0
  120. package/dist/internal/Packed.d.ts.map +1 -1
  121. package/dist/internal/Packed.js +11 -10
  122. package/dist/internal/Packed.js.map +1 -1
  123. package/dist/internal/PathBuilder.d.ts +49 -11
  124. package/dist/internal/PathBuilder.d.ts.map +1 -1
  125. package/dist/internal/PathBuilder.js +88 -24
  126. package/dist/internal/PathBuilder.js.map +1 -1
  127. package/dist/internal/ProjectionEngine.d.ts +135 -16
  128. package/dist/internal/ProjectionEngine.d.ts.map +1 -1
  129. package/dist/internal/ProjectionEngine.js +961 -126
  130. package/dist/internal/ProjectionEngine.js.map +1 -1
  131. package/dist/internal/Rekey.d.ts +167 -21
  132. package/dist/internal/Rekey.d.ts.map +1 -1
  133. package/dist/internal/Rekey.js +1283 -64
  134. package/dist/internal/Rekey.js.map +1 -1
  135. package/dist/internal/ReturnedItem.d.ts +23 -0
  136. package/dist/internal/ReturnedItem.d.ts.map +1 -0
  137. package/dist/internal/ReturnedItem.js +39 -0
  138. package/dist/internal/ReturnedItem.js.map +1 -0
  139. package/dist/internal/RoundTrip.d.ts +17 -8
  140. package/dist/internal/RoundTrip.d.ts.map +1 -1
  141. package/dist/internal/RoundTrip.js +41 -14
  142. package/dist/internal/RoundTrip.js.map +1 -1
  143. package/dist/internal/TransactPlan.d.ts.map +1 -1
  144. package/dist/internal/TransactPlan.js +4 -0
  145. package/dist/internal/TransactPlan.js.map +1 -1
  146. package/dist/internal/TransactWriteOps.d.ts +2 -1
  147. package/dist/internal/TransactWriteOps.d.ts.map +1 -1
  148. package/dist/internal/TransactWriteOps.js +22 -5
  149. package/dist/internal/TransactWriteOps.js.map +1 -1
  150. package/dist/internal/TransactableOps.d.ts +116 -5
  151. package/dist/internal/TransactableOps.d.ts.map +1 -1
  152. package/dist/internal/TransactableOps.js +318 -25
  153. package/dist/internal/TransactableOps.js.map +1 -1
  154. package/dist/internal/WriteDiagnosis.d.ts +35 -0
  155. package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
  156. package/dist/internal/WriteDiagnosis.js +133 -4
  157. package/dist/internal/WriteDiagnosis.js.map +1 -1
  158. package/package.json +5 -5
@@ -7,31 +7,33 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import { BatchGetItemCommand, BatchWriteItemCommand, CreateBackupCommand, CreateTableCommand, DeleteBackupCommand, DeleteItemCommand, DeleteTableCommand, DescribeContinuousBackupsCommand, DescribeExportCommand, DescribeTableCommand, DescribeTimeToLiveCommand, DynamoDBClient, ExportTableToPointInTimeCommand, GetItemCommand, ListBackupsCommand, ListTablesCommand, ListTagsOfResourceCommand, PutItemCommand, QueryCommand, RestoreTableFromBackupCommand, RestoreTableToPointInTimeCommand, ScanCommand, SearchVectorsCommand, TagResourceCommand, TransactGetItemsCommand, TransactWriteItemsCommand, UntagResourceCommand, UpdateContinuousBackupsCommand, UpdateItemCommand, UpdateTableCommand, UpdateTimeToLiveCommand, } from "@aws-sdk/client-dynamodb";
10
+ import { BatchGetItemCommand, BatchWriteItemCommand, CreateBackupCommand, CreateTableCommand, DeleteBackupCommand, DeleteItemCommand, DeleteTableCommand, DescribeContinuousBackupsCommand, DescribeExportCommand, DescribeTableCommand, DescribeTimeToLiveCommand, DynamoDBClient, ExecuteStatementCommand, ExecuteTransactionCommand, ExportTableToPointInTimeCommand, GetItemCommand, ListBackupsCommand, ListTablesCommand, ListTagsOfResourceCommand, PutItemCommand, QueryCommand, RestoreTableFromBackupCommand, RestoreTableToPointInTimeCommand, ScanCommand, SearchVectorsCommand, TagResourceCommand, TransactGetItemsCommand, TransactWriteItemsCommand, UntagResourceCommand, UpdateContinuousBackupsCommand, UpdateItemCommand, UpdateTableCommand, UpdateTimeToLiveCommand, } from "@aws-sdk/client-dynamodb";
11
11
  import { Compression, make as makeCompressionRegistry, } from "@effect-dynamodb/schema/Compression.js";
12
12
  import * as DynamoSchema from "@effect-dynamodb/schema/DynamoSchema.js";
13
13
  import { Embedder } from "@effect-dynamodb/schema/Embedder.js";
14
14
  import { DynamoError, DynamoValidationError, InternalServerError, isAwsInternalServerError, isAwsResourceNotFound, isAwsThrottling, isAwsValidationError, ResourceNotFoundError, ThrottlingError, ValidationError, } from "@effect-dynamodb/schema/Errors.js";
15
15
  import { compositeKeyFormKind, keyFormValueKind, keyFormValueKindOf, makeCompositeDomainKeyForm, makeCompositeKeyForm, refuseInexact, toCompositeKeyRecord, } from "@effect-dynamodb/schema/internal/CompositeCodec.js";
16
16
  import { makeDefaultCrypto } from "@effect-dynamodb/schema/internal/DefaultCrypto.js";
17
+ import { given, ownValue, setOwn } from "@effect-dynamodb/schema/internal/OwnNames.js";
17
18
  import { getSchemaFields } from "@effect-dynamodb/schema/internal/SchemaAccessors.js";
18
19
  import * as ZOrderCurve from "@effect-dynamodb/schema/internal/ZOrderCurve.js";
19
20
  import * as KeyComposer from "@effect-dynamodb/schema/KeyComposer.js";
20
21
  import { Config, Context, DateTime, Duration, Effect, Layer, Option, SchemaAST, } from "effect";
21
22
  import { SecureRandom } from "effect/crypto";
22
23
  import { bind as aggregateBind, ownershipConflict } from "./Aggregate.js";
23
- import { bind as entityBind, fromDefinition as entityFromDefinition } from "./Entity.js";
24
- import { BoundQueryImpl, collectionNaming, entityNaming, } from "./internal/BoundQuery.js";
24
+ import { bind as entityBind, fromDefinition as entityFromDefinition, storedRefIdOf, } from "./Entity.js";
25
+ import { BoundQueryImpl, collectionNaming, entityNaming, wholeRowsOf, } from "./internal/BoundQuery.js";
25
26
  import { makeBoundVectorQuery, } from "./internal/BoundVectorQuery.js";
26
27
  import * as Capacity from "./internal/Capacity.js";
27
- import { acquireSdkClient, readClientOptions, } from "./internal/ClientOptions.js";
28
+ import { acquireSdkClient, readClientOptions, readCredentials, sdkCredentials, } from "./internal/ClientOptions.js";
28
29
  import { redactCredentialRefusal } from "./internal/CredentialRefusal.js";
29
30
  import { createConditionOps, ExprTag } from "./internal/Expr.js";
30
31
  import { codecRequirements, collectionPackedQueryOptions, entityPackedQueryOptions, unregisteredCodecError, } from "./internal/Packed.js";
31
- import { createPathBuilder } from "./internal/PathBuilder.js";
32
- import { physicalTableName, refuseSharedOutboxKeySpace, remoteOutboxesOf, sharedOutboxKeySpace, } from "./internal/ProjectionEngine.js";
32
+ import { pathBuilderOf } from "./internal/PathBuilder.js";
33
+ import { physicalTableName, refuseSharedOutboxKeySpace, rekeyOutboxMember, remoteOutboxesOf, sharedOutboxKeySpace, } from "./internal/ProjectionEngine.js";
33
34
  import { canonicalJson, compareUtf8, compositePlanner, keyJustBelow, zorderPlanner, } from "./internal/RangePlanner.js";
34
35
  import * as Rekey from "./internal/Rekey.js";
36
+ import { hideReturnedItems } from "./internal/ReturnedItem.js";
35
37
  import { diagnoseFailure, explainDiagnosis, withCause, } from "./internal/WriteDiagnosis.js";
36
38
  import * as Query from "./Query.js";
37
39
  import { mergeVectorIndexes, definition as tableDefinition, toVectorIndexSpec } from "./Table.js";
@@ -240,21 +242,35 @@ const BOUND_OPERATORS = new Set(["eq", "between", "gt", "gte", "lt", "lte"]);
240
242
  * inside the stored ref, which is the value the key was composed from —
241
243
  * through the accessor's encoder for a numeric field stored as a string, so a
242
244
  * stored `"950000"` reads as `950000`. `undefined` when the row lacks it.
245
+ *
246
+ * A stored ref holds its id in the referenced entity's stored form, which is
247
+ * not always the form the key was composed from (a date key stored as epoch
248
+ * milliseconds, keyed as its ISO text): read as a value of that entity's key
249
+ * (`storedRefIdOf`), then keyed as a caller's value is (#241). Up to 1.40.0 it
250
+ * was compared as stored, and a bound on such an id matched no row.
243
251
  */
244
252
  const storedKeyForm = (args, field) => {
245
253
  const resolve = args.entityLike._resolveDbName ?? ((name) => name);
246
254
  const ref = args.entityLike._resolvedRefs?.find((r) => r.idFieldName === field);
247
255
  const attribute = resolve(ref?.fieldName ?? field);
248
- const schema = getSchemaFields(args.encoderSource)?.[field];
256
+ const schema = ownValue(getSchemaFields(args.encoderSource), field);
249
257
  const wantsBigInt = schema !== undefined && SchemaAST.isBigInt(SchemaAST.toType(schema.ast));
250
258
  const typeNumeric = compositeKeyFormKind(args.encoderSource, field) === "type-numeric";
251
259
  return {
252
260
  attribute,
253
261
  read: (row) => {
254
- const value = ref === undefined ? row[attribute] : row[attribute]?.M?.[ref.identifierField];
262
+ const value = ref === undefined
263
+ ? ownValue(row, attribute)
264
+ : ownValue(ownValue(row, attribute)?.M, ref.keyField);
255
265
  if (value === undefined)
256
266
  return undefined;
257
267
  const stored = value.S ?? value.N;
268
+ if (ref !== undefined && stored !== undefined) {
269
+ const held = value.S ?? (wantsBigInt ? BigInt(value.N) : Number(value.N));
270
+ const id = storedRefIdOf(ref, held);
271
+ if (Option.isSome(id))
272
+ return args.domainKeyForm(field, id.value);
273
+ }
258
274
  if (typeNumeric && stored !== undefined)
259
275
  return args.compositeKeyForm(field, stored);
260
276
  if (value.S !== undefined)
@@ -308,7 +324,7 @@ const planCompositeWithin = (args) => {
308
324
  const { entityLike, accessor, indexDef, domainKeyForm, pinnedKeyForm } = args;
309
325
  const sk = indexDef.sk.composite;
310
326
  const n = sk.length;
311
- const p = sk.findIndex((attr) => pinnedKeyForm[attr] === undefined);
327
+ const p = sk.findIndex((attr) => given(pinnedKeyForm, attr) === undefined);
312
328
  const pinnedCount = p === -1 ? n : p;
313
329
  const refuse = (why) => {
314
330
  throw new Error(`[EDD-9093] .within() on index "${accessor}" of entity "${entityLike.entityType}": ${why}`);
@@ -322,7 +338,7 @@ const planCompositeWithin = (args) => {
322
338
  const refOf = (field) => entityLike._resolvedRefs?.find((ref) => ref.idFieldName === field);
323
339
  /** The kind of value a composite's key form is, when its schema says (EDD-9093's type check). */
324
340
  const kindOf = (field) => {
325
- const schema = fields?.[field];
341
+ const schema = ownValue(fields, field);
326
342
  return schema === undefined ? undefined : keyFormValueKind(schema);
327
343
  };
328
344
  // -- validate and normalise (EDD-9093) --
@@ -668,7 +684,7 @@ const planZOrderWithin = (args) => {
668
684
  /** `value` in the field's key form: `[EDD-9050]` from the encoder, `[EDD-9093]` for the wrong type. */
669
685
  const keyForm = (field, value) => {
670
686
  const converted = domainKeyForm(field, value);
671
- const schema = fields?.[field];
687
+ const schema = ownValue(fields, field);
672
688
  const expected = schema === undefined ? undefined : keyFormValueKind(schema);
673
689
  if (expected !== undefined && keyFormValueKindOf(converted) !== expected) {
674
690
  return refuse(`the bound on "${field}" is ${JSON.stringify(String(value))} (${typeof value}), but ` +
@@ -944,7 +960,7 @@ const planZOrderWithin = (args) => {
944
960
  const later = firstMissing === -1 ? [] : prefix.slice(firstMissing);
945
961
  const hashed = prefix.filter((part) => part.hash !== undefined && prefixValues.has(part.field));
946
962
  const parsedExactly = later.filter((part) => part.hash === undefined && prefixValues.has(part.field));
947
- const renameExpr = entityNaming(entityLike._resolveDbName).renameExpr ?? ((expr) => expr);
963
+ const renameExpr = entityNaming(entityLike._resolveDbName, undefined, wholeRowsOf(entityLike), entityLike._storedBelow).renameExpr ?? ((expr) => expr);
948
964
  const filter = filters.length === 0
949
965
  ? undefined
950
966
  : renameExpr(filters.length === 1
@@ -995,7 +1011,7 @@ const planZOrderWithin = (args) => {
995
1011
  * the key `put` wrote for those values (`internal/CompositeCodec.ts`,
996
1012
  * `makeCompositeDomainKeyForm`), as `Entity._domainKeyForm` composes it.
997
1013
  */
998
- const entityDomainKeyForm = (entityLike, record) => {
1014
+ const entityDomainKeyForm = (entityLike, record, needs) => {
999
1015
  const source = (entityLike.schemas?.inputSchema ?? entityLike.model);
1000
1016
  if (source === undefined)
1001
1017
  return record;
@@ -1005,7 +1021,7 @@ const entityDomainKeyForm = (entityLike, record) => {
1005
1021
  throw new Error(`[EDD-9050] Composite "${attr}" could not be put into its key form: ` +
1006
1022
  `${JSON.stringify(String(value))} resolves under neither encode nor decode->encode.`);
1007
1023
  });
1008
- return toCompositeKeyRecord(form, record);
1024
+ return toCompositeKeyRecord(form, record, needs);
1009
1025
  };
1010
1026
  /**
1011
1027
  * Fail at bind time when a collection's members spell a shared PK composite
@@ -1067,7 +1083,8 @@ export class DynamoClient extends Context.Service()("@effect-dynamodb/DynamoClie
1067
1083
  *
1068
1084
  * @param config.region - AWS region
1069
1085
  * @param config.endpoint - Optional endpoint override (e.g., for DynamoDB Local)
1070
- * @param config.credentials - Optional static credentials
1086
+ * @param config.credentials - Optional static credentials, with a
1087
+ * `sessionToken` when they are temporary (an assumed role)
1071
1088
  * @param config.requestHandler - Optional HTTP handler, or the options of the
1072
1089
  * runtime's handler (`{ socketTimeout: 5000 }`), passed to the SDK client.
1073
1090
  * None is set by default, so without one a connection that stays open and
@@ -1102,7 +1119,15 @@ export class DynamoClient extends Context.Service()("@effect-dynamodb/DynamoClie
1102
1119
  *
1103
1120
  * @param config.region - Config for AWS region
1104
1121
  * @param config.endpoint - Optional Config for endpoint override
1105
- * @param config.credentials - Optional Config for static credentials
1122
+ * @param config.credentials - Optional Config for static credentials, with a
1123
+ * `sessionToken` when they are temporary (an assumed role). With none of
1124
+ * them in the provider, the SDK's default credential chain applies. With
1125
+ * one of them there and another missing (an empty value counts as
1126
+ * missing), the layer fails with the `Config`'s error for what is missing;
1127
+ * a token that may be absent is read with `Config.withDefault(undefined)`.
1128
+ * Both must be shown to be parts of the credentials: a value given, or
1129
+ * one missing, that is a mode, a flag or another setting, or a part the
1130
+ * `Config` turns into other text, leaves the default chain, as before.
1106
1131
  * @param config.requestHandler - Optional Config for each of the handler's
1107
1132
  * timeouts (`connectionTimeout`, `socketTimeout`, `requestTimeout`,
1108
1133
  * `throwOnRequestTimeout`), which an operator tunes per environment, or an
@@ -1116,11 +1141,9 @@ export class DynamoClient extends Context.Service()("@effect-dynamodb/DynamoClie
1116
1141
  static layerConfig = (config) => withCompressors(Layer.effect(DynamoClient, Effect.gen(function* () {
1117
1142
  const region = yield* config.region;
1118
1143
  const endpoint = config.endpoint ? yield* Config.option(config.endpoint) : undefined;
1119
- const credentials = config.credentials
1120
- ? yield* Config.option(config.credentials)
1121
- : undefined;
1144
+ const credentials = yield* readCredentials(config.credentials);
1122
1145
  const options = yield* readClientOptions(config);
1123
- return yield* buildService(region, endpoint && endpoint._tag === "Some" ? endpoint.value : undefined, credentials && credentials._tag === "Some" ? credentials.value : undefined, options);
1146
+ return yield* buildService(region, endpoint && endpoint._tag === "Some" ? endpoint.value : undefined, credentials, options);
1124
1147
  })), config.compressors);
1125
1148
  /**
1126
1149
  * Create a typed client gateway from entities, aggregates, and (optionally) tables.
@@ -1153,6 +1176,12 @@ export class DynamoClient extends Context.Service()("@effect-dynamodb/DynamoClie
1153
1176
  * that lands on one of these would take the corresponding feature offline.
1154
1177
  */
1155
1178
  const RESERVED_ACCESSOR_NAMES = new Set(["scan", "reembed"]);
1179
+ /**
1180
+ * A query's path builder over the members' models (`pathBuilderOf`): `.entry(key)` on each sparse
1181
+ * map field, baked with the first member's prefix where members declare one field with different
1182
+ * ones (a collection names each member's entry by its own prefix: `collectionNaming`).
1183
+ */
1184
+ const queryPathBuilder = (entities) => pathBuilderOf(entities.map((entityLike) => entityLike.model));
1156
1185
  /** An entity's domain field names (its record's), when its schema exposes them. */
1157
1186
  const domainFieldsOf = (entityLike) => {
1158
1187
  const fields = entityLike.schemas.recordSchema.fields;
@@ -1268,14 +1297,14 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1268
1297
  const skAttrs = indexDef.sk.composite;
1269
1298
  // 1. All PK composites must be present
1270
1299
  for (const attr of pkAttrs) {
1271
- if (composites[attr] === undefined) {
1300
+ if (given(composites, attr) === undefined) {
1272
1301
  throw new Error(`[EDD-9002] Missing required partition key attribute "${attr}" for index "${indexName}"`);
1273
1302
  }
1274
1303
  }
1275
1304
  // 2. SK composites must follow prefix ordering
1276
1305
  let lastProvided = -1;
1277
1306
  for (let i = 0; i < skAttrs.length; i++) {
1278
- if (composites[skAttrs[i]] !== undefined) {
1307
+ if (given(composites, skAttrs[i]) !== undefined) {
1279
1308
  if (i !== lastProvided + 1) {
1280
1309
  const missing = skAttrs.slice(lastProvided + 1, i).join(", ");
1281
1310
  throw new Error(`[EDD-9004] Sort key composite "${skAttrs[i]}" for index "${indexName}" requires prior composites: ${missing}. Sort key composites must follow prefix ordering.`);
@@ -1331,7 +1360,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1331
1360
  const zorderPlans = zorderLayout === undefined ? undefined : makeZOrderPlans(zorderLayout);
1332
1361
  const accessor = (rawComposites) => {
1333
1362
  if (zorder) {
1334
- const misplaced = indexDef.sk.composite.filter((attr) => rawComposites[attr] !== undefined);
1363
+ const misplaced = indexDef.sk.composite.filter((attr) => given(rawComposites, attr) !== undefined);
1335
1364
  if (misplaced.length > 0) {
1336
1365
  throw new Error(`[EDD-9093] Index "${_indexName}" of entity "${entityLike.entityType}" has a ` +
1337
1366
  `Z-order sort key, so ${misplaced.map((attr) => `"${attr}"`).join(", ")} can't ` +
@@ -1340,7 +1369,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1340
1369
  }
1341
1370
  }
1342
1371
  validateQueryComposites(_indexName, accessorDef, rawComposites);
1343
- const compositesKeyForm = toCompositeKeyRecord(domainKeyForm, rawComposites);
1372
+ const compositesKeyForm = toCompositeKeyRecord(domainKeyForm, rawComposites, indexDef.pk.composite, indexDef.sk.composite);
1344
1373
  // One partition, or a sharded index's several (#183).
1345
1374
  const read = KeyComposer.composeReadPartitions(entityLike._schema, entityLike.entityType, indexDef, compositesKeyForm);
1346
1375
  const pkValue = read.partitions[0];
@@ -1378,11 +1407,11 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1378
1407
  // complete key is an exact `=`, or `seq: 3` also matches 3.14 and
1379
1408
  // `name: "a"` also matches "ab".
1380
1409
  const hasSkComposites = !zorder &&
1381
- indexDef.sk.composite.some((attr) => compositesKeyForm[attr] !== undefined);
1410
+ indexDef.sk.composite.some((attr) => given(compositesKeyForm, attr) !== undefined);
1382
1411
  const pinnedQuery = hasSkComposites
1383
1412
  ? Query.whereUnderPins(query, KeyComposer.composeSortKeyCondition(entityLike._schema, entityLike.entityType, 1, indexDef, compositesKeyForm))
1384
1413
  : query;
1385
- const pathBuilder = createPathBuilder();
1414
+ const pathBuilder = queryPathBuilder([entityLike]);
1386
1415
  const conditionOps = createConditionOps();
1387
1416
  // composeSkCondition — compose the user's `.where()` operand into a full
1388
1417
  // sort key value the same way `put` composes the stored one
@@ -1404,7 +1433,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1404
1433
  // with EDD-9004 before the accessor is built — so this count is also
1405
1434
  // the index of the first composite still open to a condition.
1406
1435
  const pinnedCount = (() => {
1407
- const i = skComposites.findIndex((attr) => compositesKeyForm[attr] === undefined);
1436
+ const i = skComposites.findIndex((attr) => given(compositesKeyForm, attr) === undefined);
1408
1437
  return i === -1 ? skComposites.length : i;
1409
1438
  })();
1410
1439
  /**
@@ -1425,7 +1454,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1425
1454
  */
1426
1455
  const rejectPinned = (attr) => {
1427
1456
  throw new Error(`[EDD-9053] Sort key composite "${attr}" for index "${_indexName}" is already ` +
1428
- `pinned to ${JSON.stringify(String(compositesKeyForm[attr]))} by the accessor, ` +
1457
+ `pinned to ${JSON.stringify(String(given(compositesKeyForm, attr)))} by the accessor, ` +
1429
1458
  `so .where() cannot also constrain it: DynamoDB allows one sort key condition, ` +
1430
1459
  `and this one would REPLACE the accessor's own prefix rather than narrow it — ` +
1431
1460
  `returning rows outside the pinned value. Drop "${attr}" from the accessor call ` +
@@ -1454,7 +1483,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1454
1483
  // silently compare against the wrong prefix.
1455
1484
  const missing = skComposites
1456
1485
  .slice(0, targetIndex)
1457
- .filter((attr) => compositesKeyForm[attr] === undefined);
1486
+ .filter((attr) => given(compositesKeyForm, attr) === undefined);
1458
1487
  if (missing.length > 0) {
1459
1488
  throw new Error(`[EDD-9004] Sort key condition on "${targetAttr}" for index "${_indexName}" ` +
1460
1489
  `requires prior composites: ${missing.join(", ")}. Sort key composites must ` +
@@ -1465,7 +1494,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1465
1494
  // follows them, so the shared delimiter rule always applies).
1466
1495
  const pinnedKeyForm = {};
1467
1496
  for (let i = 0; i < targetIndex; i++) {
1468
- pinnedKeyForm[skComposites[i]] = compositesKeyForm[skComposites[i]];
1497
+ pinnedKeyForm[skComposites[i]] = given(compositesKeyForm, skComposites[i]);
1469
1498
  }
1470
1499
  const prefixText = KeyComposer.composeSortKeyBeginsWith(entityLike._schema, entityLike.entityType, 1, indexDef, pinnedKeyForm);
1471
1500
  // Operands are encoded exactly as the accessor composites (and the
@@ -1526,7 +1555,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1526
1555
  }),
1527
1556
  }),
1528
1557
  skFields: accessorDef.sk.composite,
1529
- ...entityNaming(entityLike._resolveDbName),
1558
+ ...entityNaming(entityLike._resolveDbName, entityLike._storedFormAt, wholeRowsOf(entityLike), entityLike._storedBelow),
1530
1559
  operation: { name: "Entity.query", target: entityLike.entityType, index: _indexName },
1531
1560
  };
1532
1561
  return new BoundQueryImpl(pinnedQuery, bqConfig);
@@ -1538,10 +1567,10 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1538
1567
  index: _indexName,
1539
1568
  };
1540
1569
  return Query.orRefusal(operation, () => accessor(rawComposites), (refusal) => new BoundQueryImpl(Query.refused(indexDef.index, refusal), {
1541
- pathBuilder: createPathBuilder(),
1570
+ pathBuilder: queryPathBuilder([entityLike]),
1542
1571
  conditionOps: createConditionOps(),
1543
1572
  provide,
1544
- ...entityNaming(entityLike._resolveDbName),
1573
+ ...entityNaming(entityLike._resolveDbName, entityLike._storedFormAt, wholeRowsOf(entityLike), entityLike._storedBelow),
1545
1574
  operation,
1546
1575
  }));
1547
1576
  };
@@ -1575,7 +1604,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1575
1604
  for (const [indexName, indexDef] of Object.entries(entityLike.indexes)) {
1576
1605
  if (!indexDef)
1577
1606
  continue;
1578
- accessors[indexName] = buildEntityQueryAccessor(entityLike, indexName, indexDef);
1607
+ setOwn(accessors, indexName, buildEntityQueryAccessor(entityLike, indexName, indexDef));
1579
1608
  // Track collection membership for auto-discovery
1580
1609
  if (indexDef.collection) {
1581
1610
  const collNames = Array.isArray(indexDef.collection)
@@ -1595,13 +1624,13 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1595
1624
  // named after an existing index accessor (or `scan` / `reembed`) would
1596
1625
  // silently replace it and take the other feature offline, so make the
1597
1626
  // collision a construction-time failure instead.
1598
- if (logicalName in accessors || RESERVED_ACCESSOR_NAMES.has(logicalName)) {
1627
+ if (Object.hasOwn(accessors, logicalName) || RESERVED_ACCESSOR_NAMES.has(logicalName)) {
1599
1628
  throw new Error(`[EDD-9038] Entity "${key}": vector index "${logicalName}" collides with an existing ` +
1600
1629
  `accessor of the same name. Vector index names share a namespace with GSI query ` +
1601
1630
  `accessors, \`scan\` and \`reembed\` — rename one of them.`);
1602
1631
  }
1603
1632
  const vqConfig = {
1604
- keyForm: (record) => entityDomainKeyForm(entityLike, record),
1633
+ keyForm: (record) => entityDomainKeyForm(entityLike, record, definition.partition ?? []),
1605
1634
  entityType: entityLike.entityType,
1606
1635
  logicalName,
1607
1636
  definition,
@@ -1612,6 +1641,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1612
1641
  unpackAttributes: entityLike._dispatchAttributes,
1613
1642
  provide,
1614
1643
  resolveDbName: entityLike._resolveDbName ?? ((domainName) => domainName),
1644
+ storedAt: entityLike._storedFormAt,
1615
1645
  };
1616
1646
  accessors[logicalName] = (query) => makeBoundVectorQuery(vqConfig, query);
1617
1647
  }
@@ -1627,13 +1657,13 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1627
1657
  keyFields: [entityLike.indexes.primary?.pk.field, entityLike.indexes.primary?.sk.field],
1628
1658
  liveRows: entityLike._liveRows?.(),
1629
1659
  });
1630
- const pathBuilder = createPathBuilder();
1660
+ const pathBuilder = queryPathBuilder([entityLike]);
1631
1661
  const conditionOps = createConditionOps();
1632
1662
  const bqConfig = {
1633
1663
  pathBuilder,
1634
1664
  conditionOps,
1635
1665
  provide,
1636
- ...entityNaming(entityLike._resolveDbName),
1666
+ ...entityNaming(entityLike._resolveDbName, entityLike._storedFormAt, wholeRowsOf(entityLike), entityLike._storedBelow),
1637
1667
  operation: { name: "Entity.scan", target: entityLike.entityType },
1638
1668
  };
1639
1669
  return new BoundQueryImpl(scanQuery, bqConfig);
@@ -1691,7 +1721,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1691
1721
  // different PK from `db.entities.Readings.byWindow({ takenAt })` and
1692
1722
  // returned nothing.
1693
1723
  // Members share the partitions, whatever each hashes: never pruned (#183).
1694
- const read = KeyComposer.composeReadPartitions(firstMember.entityLike._schema, firstMember.entityLike.entityType, indexDef, entityDomainKeyForm(firstMember.entityLike, composites), { prune: false });
1724
+ const read = KeyComposer.composeReadPartitions(firstMember.entityLike._schema, firstMember.entityLike.entityType, indexDef, entityDomainKeyForm(firstMember.entityLike, composites, indexDef.pk.composite), { prune: false });
1695
1725
  // Always isolated — begins_with on collection SK prefix
1696
1726
  let query = Query.make({
1697
1727
  tableName: "",
@@ -1733,7 +1763,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1733
1763
  query = Query.where(query, { beginsWith: skPrefix });
1734
1764
  }
1735
1765
  // Wrap in BoundQuery that groups results by entity key
1736
- const pathBuilder = createPathBuilder();
1766
+ const pathBuilder = queryPathBuilder(members.map((m) => m.entityLike));
1737
1767
  const conditionOps = createConditionOps();
1738
1768
  const collectionProvide = (eff) => Effect.provide(eff, ctx);
1739
1769
  const bqConfig = {
@@ -1766,6 +1796,9 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1766
1796
  entityKey: m.entityKey,
1767
1797
  resolve: m.entityLike._resolveDbName ?? ((name) => name),
1768
1798
  fields: domainFieldsOf(m.entityLike),
1799
+ storedAt: m.entityLike._storedFormAt,
1800
+ wholeRows: wholeRowsOf(m.entityLike),
1801
+ below: m.entityLike._storedBelow,
1769
1802
  }))),
1770
1803
  operation: { name: "Collection.query", target: collName },
1771
1804
  };
@@ -1774,7 +1807,7 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1774
1807
  boundCollections[collName] = (composites) => {
1775
1808
  const operation = { name: "Collection.query", target: collName };
1776
1809
  return Query.orRefusal(operation, () => collectionAccessor(composites), (refusal) => new BoundQueryImpl(Query.refused(members[0].indexDef.index, refusal), {
1777
- pathBuilder: createPathBuilder(),
1810
+ pathBuilder: queryPathBuilder(members.map((m) => m.entityLike)),
1778
1811
  conditionOps: createConditionOps(),
1779
1812
  provide,
1780
1813
  operation,
@@ -1871,12 +1904,12 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1871
1904
  handlers.add(handler);
1872
1905
  }
1873
1906
  // The read models whose outboxes are on this table are checked before anything is
1874
- // sent: `rekey` reads an item's key back by its key space, so two whose keys could be
1875
- // read as each other's are refused here, where `DynamoClient.make` refuses only those
1876
- // whose items would overwrite each other in normal operation, and so is a member of
1877
- // this table that would read a read model's items as its own. Projections are defined
1878
- // when the program runs them, so one defined after the client was made has its outbox
1879
- // recorded only now. A run's refusal is the run's `ValidationError`.
1907
+ // sent, as `DynamoClient.make` checks them: two whose items would overwrite each other
1908
+ // in normal operation are refused, and so is a member of this table claiming a read
1909
+ // model's items whose own would. Projections are defined when the program runs them,
1910
+ // so one defined after the client was made has its outbox recorded only now. Whose an
1911
+ // item is otherwise is decided item by item (`rekeyOutboxMember`). A run's refusal is
1912
+ // the run's `ValidationError`.
1880
1913
  const shared = yield* sharedOutboxKeySpace("rekey", named, {
1881
1914
  key: tagKey,
1882
1915
  name: tableName,
@@ -1893,34 +1926,55 @@ const makeFromConfig = (config) => Effect.gen(function* () {
1893
1926
  cause: shared,
1894
1927
  });
1895
1928
  }
1896
- // The outboxes on this table of a read model on another (#171): every projection's, so
1897
- // a second projection of one read model doesn't hide the first's items, named by this
1898
- // table's service or by another handle on the same physical table. A read model's
1899
- // projections may have one each, on tables of their own.
1900
- const outboxOf = new Set();
1901
- for (const entity of [...registered, ...visibleEntities]) {
1902
- if (outboxOf.has(entity))
1929
+ // The outbox items on this table, by entity type, are judged by one member each, which
1930
+ // asks every read model of that type that can have written them (#237): the table's
1931
+ // members (their own projections' outbox items), then each read model whose
1932
+ // projection's outbox is on this table (#171) — every projection's, so a second
1933
+ // projection of one read model doesn't hide the first's items, named by this table's
1934
+ // service or by another handle on the same physical table. A read model's projections
1935
+ // may have one each, on tables of their own.
1936
+ const outboxCandidates = new Map();
1937
+ const addCandidate = (entity, key) => {
1938
+ const type = entity.entityType;
1939
+ const byEntity = outboxCandidates.get(type) ??
1940
+ new Map();
1941
+ outboxCandidates.set(type, byEntity);
1942
+ const keys = byEntity.get(entity) ?? [];
1943
+ byEntity.set(entity, keys);
1944
+ if (!keys.some((k) => k.pk === key.pk && k.sk === key.sk))
1945
+ keys.push(key);
1946
+ };
1947
+ for (const member of new Set(tableMembers)) {
1948
+ const type = member.entityType;
1949
+ const primary = member.indexes?.primary;
1950
+ if (type === undefined ||
1951
+ primary === undefined ||
1952
+ member._valuelessMove === undefined ||
1953
+ Rekey.handlerOf(member)?.types.includes(`${type}#outbox`) !== true) {
1903
1954
  continue;
1904
- outboxOf.add(entity);
1905
- // Their key attributes, once each.
1906
- const layouts = new Map();
1955
+ }
1956
+ addCandidate(member, { pk: primary.pk.field, sk: primary.sk.field });
1957
+ }
1958
+ for (const entity of new Set([...registered, ...visibleEntities])) {
1907
1959
  for (const outbox of remoteOutboxesOf(entity)) {
1908
1960
  if (outbox.table.Tag.key !== tagKey &&
1909
1961
  (yield* physicalTableName(outbox.table.Tag)) !== tableName) {
1910
1962
  continue;
1911
1963
  }
1912
- layouts.set(`${outbox.pk}\u0000${outbox.sk}`, { pk: outbox.pk, sk: outbox.sk });
1964
+ addCandidate(entity, { pk: outbox.pk, sk: outbox.sk });
1913
1965
  }
1914
- if (layouts.size === 0)
1915
- continue;
1916
- const keys = [...layouts.values()];
1917
- const readModel = entity;
1966
+ }
1967
+ for (const [type, byEntity] of outboxCandidates) {
1968
+ // A read model with one layout on this table names the table's key attributes.
1969
+ const layout = [...byEntity.values()].find((keys) => keys.length === 1)?.[0];
1918
1970
  handlers.add({
1919
- name: readModel.entityType,
1920
- types: [`${readModel.entityType}#outbox`],
1921
- // A table has one key schema, so its items are under the layout whose attributes
1922
- // they hold.
1923
- row: (row, ctx) => readModel._rekeyProjectionRow(row, ctx, keys.find((key) => row[key.pk]?.S !== undefined && row[key.sk]?.S !== undefined) ?? keys[0]),
1971
+ ...rekeyOutboxMember(type, [...byEntity].map(([entity, keys]) => ({
1972
+ readModel: entity,
1973
+ // A table has one key schema, so its items are under the layout whose
1974
+ // attributes they hold.
1975
+ keys: (row) => keys.find((key) => row[key.pk]?.S !== undefined && row[key.sk]?.S !== undefined) ?? keys[0],
1976
+ }))),
1977
+ ...(layout !== undefined && { key: layout }),
1924
1978
  });
1925
1979
  }
1926
1980
  return yield* Rekey.run({ tableName, members: [...handlers], options });
@@ -2246,7 +2300,7 @@ const waitForVectorIndexReady = (tableName, indexName, client, options) => {
2246
2300
  };
2247
2301
  /** @internal Classify an AWS SDK error into a specific tagged error type. */
2248
2302
  export const classifyError = (operation) => (thrown) => {
2249
- const cause = redactCredentialRefusal(thrown);
2303
+ const cause = hideReturnedItems(redactCredentialRefusal(thrown));
2250
2304
  if (isAwsThrottling(cause))
2251
2305
  return new ThrottlingError({ operation, cause });
2252
2306
  if (isAwsValidationError(cause))
@@ -2263,7 +2317,7 @@ const buildService = (region, endpoint, credentials, options) => Effect.gen(func
2263
2317
  if (endpoint !== undefined)
2264
2318
  clientConfig.endpoint = endpoint;
2265
2319
  if (credentials !== undefined)
2266
- clientConfig.credentials = credentials;
2320
+ clientConfig.credentials = sdkCredentials(credentials);
2267
2321
  if (options.requestHandler !== undefined)
2268
2322
  clientConfig.requestHandler = options.requestHandler;
2269
2323
  if (options.maxAttempts !== undefined)
@@ -2326,6 +2380,14 @@ const buildService = (region, endpoint, credentials, options) => Effect.gen(func
2326
2380
  try: (signal) => client.send(new TransactWriteItemsCommand(input), { abortSignal: signal }),
2327
2381
  catch: classifyError("TransactWriteItems"),
2328
2382
  }),
2383
+ executeStatement: (input) => Effect.tryPromise({
2384
+ try: (signal) => client.send(new ExecuteStatementCommand(input), { abortSignal: signal }),
2385
+ catch: classifyError("ExecuteStatement"),
2386
+ }),
2387
+ executeTransaction: (input) => Effect.tryPromise({
2388
+ try: (signal) => client.send(new ExecuteTransactionCommand(input), { abortSignal: signal }),
2389
+ catch: classifyError("ExecuteTransaction"),
2390
+ }),
2329
2391
  // --- Table management ---
2330
2392
  updateTable: (input) => Effect.tryPromise({
2331
2393
  try: (signal) => client.send(new UpdateTableCommand(input), { abortSignal: signal }),