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
|
@@ -17,9 +17,12 @@ import { ValidationError } from "@effect-dynamodb/schema/Errors.js";
|
|
|
17
17
|
import { Effect } from "effect";
|
|
18
18
|
import type { DynamoClient, DynamoClientError } from "../DynamoClient.js";
|
|
19
19
|
import type { Entity, EntityDelete, EntityPut, EntityUpdate, PlanDeleteError, PlanUpdateError, PutVerdict, WriteCancellationReason } from "../Entity.js";
|
|
20
|
-
import type { ExpressionResult } from "../Expression.js";
|
|
20
|
+
import type { ConditionInput, ExpressionResult } from "../Expression.js";
|
|
21
21
|
import { type TableConfig } from "../Table.js";
|
|
22
22
|
import type { BoundUpdateOp, BoundWriteOp } from "./BoundCrud.js";
|
|
23
|
+
import { type PutKind } from "./EntityOps.js";
|
|
24
|
+
import { type Expr } from "./Expr.js";
|
|
25
|
+
import { validateAndBuildPutItem } from "./TransactableOps.js";
|
|
23
26
|
import type { TransactPlan } from "./TransactPlan.js";
|
|
24
27
|
import { type KeyAttributes, type TransactItemTarget, transactItemTarget } from "./WriteDiagnosis.js";
|
|
25
28
|
/** @internal */
|
|
@@ -196,22 +199,70 @@ export interface BuiltTransactWriteItems {
|
|
|
196
199
|
*/
|
|
197
200
|
readonly keys: () => KeyAttributes;
|
|
198
201
|
}
|
|
202
|
+
/** A put's item, built and validated (`validateAndBuildPutItem`). */
|
|
203
|
+
type BuiltPut = Effect.Success<ReturnType<typeof validateAndBuildPutItem>>;
|
|
204
|
+
/** One caller op, with everything its items need that takes no read. */
|
|
205
|
+
interface PreparedOp {
|
|
206
|
+
readonly type: "put" | "delete" | "conditionCheck" | "planned";
|
|
207
|
+
readonly putKind?: PutKind | undefined;
|
|
208
|
+
readonly entity: Entity;
|
|
209
|
+
/** Index into the caller's `operations` array — preserved for provenance. */
|
|
210
|
+
readonly opIndex: number;
|
|
211
|
+
readonly input?: Record<string, unknown> | undefined;
|
|
212
|
+
readonly condition?: ExpressionResult | undefined;
|
|
213
|
+
/** The caller's own condition — what a `create` over a tombstone keeps. */
|
|
214
|
+
readonly callerCondition?: Expr | ConditionInput | undefined;
|
|
215
|
+
/** A put's item. */
|
|
216
|
+
readonly built?: BuiltPut | undefined;
|
|
217
|
+
/** A delete's or a check's primary key. */
|
|
218
|
+
readonly primaryKey?: Record<string, unknown> | undefined;
|
|
219
|
+
/** A planned op's plan, from its own read: its key is already encoded and composed. */
|
|
220
|
+
readonly plan?: (() => Effect.Effect<TransactPlan, ValidationError | PlanUpdateError | PlanDeleteError, DynamoClient | TableConfig>) | undefined;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A transaction's ops checked and composed with nothing read
|
|
224
|
+
* ({@link prepareTransactWriteOps}): every refusal an op's own values decide,
|
|
225
|
+
* its keys and put items included, comes before the first read of any op.
|
|
226
|
+
*/
|
|
227
|
+
export interface PreparedTransactWrite {
|
|
228
|
+
readonly count: number;
|
|
229
|
+
readonly ops: ReadonlyArray<PreparedOp>;
|
|
230
|
+
/** The nested stream appends, built, by caller op index. */
|
|
231
|
+
readonly streamOps: ReadonlyMap<number, BuiltStreamAppend>;
|
|
232
|
+
}
|
|
199
233
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* the standalone op would have — every read, item and guard included.
|
|
234
|
+
* Check and compose every op of a transaction without reading: refuse what an
|
|
235
|
+
* op can't carry, compile its condition, build a put's item, compose a
|
|
236
|
+
* delete's or a check's key and build a nested stream append — so a value
|
|
237
|
+
* with no key text, a put or an event its schema refuses, or an append op
|
|
238
|
+
* with no events, fails the transaction before any op reads, whatever its
|
|
239
|
+
* place in it.
|
|
207
240
|
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
241
|
+
* With `plan`, `Transaction.transactWrite` carries the ops the build step
|
|
242
|
+
* cannot: every `update`, and every `delete` of an entity whose delete writes
|
|
243
|
+
* more than its own row (`unique`, `versioned: { retain: true }`,
|
|
244
|
+
* `softDelete` — EDD-9048). Each is planned by the entity's own op
|
|
245
|
+
* (`Entity._planUpdate` / `_planDelete`) in {@link planTransactWriteOps}; here
|
|
246
|
+
* its key is encoded and composed (`Entity._encodeKey`), what it can't carry
|
|
247
|
+
* refused (EDD-9059 – EDD-9061, `rejectUnsupportedOp`), and an update's own
|
|
248
|
+
* operands decided (`Entity._prepareUpdate`: its payload, and the keys the
|
|
249
|
+
* payload composes), which its plan reuses. Without `plan`
|
|
250
|
+
* (`EventStore.append`), such ops are refused.
|
|
251
|
+
*/
|
|
252
|
+
export declare const prepareTransactWriteOps: (operations: ReadonlyArray<AppendWriteOp | TransactWriteUpdateOp>, operation: string, options?: {
|
|
253
|
+
readonly streams?: boolean | undefined;
|
|
254
|
+
readonly plan?: boolean | undefined;
|
|
255
|
+
} | undefined) => Effect.Effect<PreparedTransactWrite, ValidationError | DynamoClientError, TableConfig | DynamoClient>;
|
|
256
|
+
/**
|
|
257
|
+
* The read pass that lets `Transaction.transactWrite` carry its planned ops
|
|
258
|
+
* ({@link prepareTransactWriteOps}): each is the standalone op itself, run
|
|
259
|
+
* with its write recorded instead of sent, so the transaction writes exactly
|
|
260
|
+
* what the standalone op would have — every read, item and guard included.
|
|
261
|
+
* Returns the plans keyed by index into the caller's operations. Run on every
|
|
211
262
|
* attempt, so a transaction cancelled by a lost race is planned again from
|
|
212
263
|
* fresh reads.
|
|
213
264
|
*/
|
|
214
|
-
export declare const planTransactWriteOps: (
|
|
265
|
+
export declare const planTransactWriteOps: (prepared: PreparedTransactWrite) => Effect.Effect<ReadonlyMap<number, TransactPlan>, ValidationError | PlanUpdateError | PlanDeleteError, DynamoClient | TableConfig>;
|
|
215
266
|
/**
|
|
216
267
|
* Compile a list of Entity write ops into marshalled `TransactWriteItems` entries,
|
|
217
268
|
* preserving caller order.
|
|
@@ -238,14 +289,18 @@ export declare const planTransactWriteOps: (operations: ReadonlyArray<TransactWr
|
|
|
238
289
|
* `ValidationError` otherwise. Its items are built by the inner stream
|
|
239
290
|
* (provenance `kind: "stream"`), recorded in `streams`, and left out of
|
|
240
291
|
* `conditioned`.
|
|
292
|
+
*
|
|
293
|
+
* The ops are checked and composed first ({@link prepareTransactWriteOps}), or
|
|
294
|
+
* come so (`prepared`, with `plans`, from `transactWrite`), so nothing is read
|
|
295
|
+
* before every op's own refusals.
|
|
241
296
|
*/
|
|
242
297
|
export declare const buildTransactWriteItems: (operations: ReadonlyArray<AppendWriteOp | TransactWriteUpdateOp>, operation: string, options?: {
|
|
243
298
|
readonly streams?: boolean | undefined;
|
|
244
299
|
/**
|
|
245
|
-
*
|
|
246
|
-
* and
|
|
247
|
-
* (`EventStore.append`) passes none, and such ops are refused.
|
|
300
|
+
* `operations` prepared with `plan` ({@link prepareTransactWriteOps}),
|
|
301
|
+
* and its planned ops' plans ({@link planTransactWriteOps}).
|
|
248
302
|
*/
|
|
303
|
+
readonly prepared?: PreparedTransactWrite | undefined;
|
|
249
304
|
readonly plans?: ReadonlyMap<number, TransactPlan> | undefined;
|
|
250
305
|
} | undefined) => Effect.Effect<BuiltTransactWriteItems, ValidationError | DynamoClientError, TableConfig | DynamoClient>;
|
|
251
306
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactWriteOps.d.ts","sourceRoot":"","sources":["../../src/internal/TransactWriteOps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,eAAe,EAChB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,UAAU,EACV,uBAAuB,EACxB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"TransactWriteOps.d.ts","sourceRoot":"","sources":["../../src/internal/TransactWriteOps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,eAAe,EAChB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAi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AttributeName } from "../Table.js";
|
|
19
19
|
import { withGuard } from "./EntityOps.js";
|
|
20
|
-
import { compileExpr, emptyPartProblem, isExpr, parseShorthand } from "./Expr.js";
|
|
21
|
-
import { composePrimaryKeyOrFail, rejectUnsupportedOp, resolveTableNames, validateAndBuildPutItem, } from "./TransactableOps.js";
|
|
20
|
+
import { compileExpr, emptyPartProblem, isExpr, operandsAsStored, parseShorthand, unsentIn, } from "./Expr.js";
|
|
21
|
+
import { andRaw, composePrimaryKeyOrFail, rejectUnsupportedOp, resolveTableNames, validateAndBuildPutItem, } from "./TransactableOps.js";
|
|
22
22
|
import { keyAttributesOf, mergeKeyAttributes, transactItemTarget, } from "./WriteDiagnosis.js";
|
|
23
23
|
// ---------------------------------------------------------------------------
|
|
24
24
|
// ConditionCheck — composable from EntityGet + condition expression
|
|
@@ -42,7 +42,10 @@ const compileOpCondition = (entity, cond) => {
|
|
|
42
42
|
if (cond === undefined)
|
|
43
43
|
return undefined;
|
|
44
44
|
const expr = isExpr(cond) ? cond : parseShorthand(cond);
|
|
45
|
-
|
|
45
|
+
// Its operands in the form the attribute holds, as the entity's own write sends them (#242), and
|
|
46
|
+
// an entry of a sparse map a `field:` rename stores whole asked where the row holds it (#238). A
|
|
47
|
+
// path below its field is named as stored (#238).
|
|
48
|
+
return compileExpr(entity._entryForms(operandsAsStored(expr, entity._storedFormAt)), entity._resolveDbName, entity._storedBelow);
|
|
46
49
|
};
|
|
47
50
|
/**
|
|
48
51
|
* An op's condition with an empty part where none may be (#133) is refused
|
|
@@ -76,91 +79,26 @@ const conditionFields = (condition) => condition === undefined
|
|
|
76
79
|
: {}),
|
|
77
80
|
};
|
|
78
81
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* the standalone op would have — every read, item and guard included.
|
|
82
|
+
* Check and compose every op of a transaction without reading: refuse what an
|
|
83
|
+
* op can't carry, compile its condition, build a put's item, compose a
|
|
84
|
+
* delete's or a check's key and build a nested stream append — so a value
|
|
85
|
+
* with no key text, a put or an event its schema refuses, or an append op
|
|
86
|
+
* with no events, fails the transaction before any op reads, whatever its
|
|
87
|
+
* place in it.
|
|
86
88
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
89
|
+
* With `plan`, `Transaction.transactWrite` carries the ops the build step
|
|
90
|
+
* cannot: every `update`, and every `delete` of an entity whose delete writes
|
|
91
|
+
* more than its own row (`unique`, `versioned: { retain: true }`,
|
|
92
|
+
* `softDelete` — EDD-9048). Each is planned by the entity's own op
|
|
93
|
+
* (`Entity._planUpdate` / `_planDelete`) in {@link planTransactWriteOps}; here
|
|
94
|
+
* its key is encoded and composed (`Entity._encodeKey`), what it can't carry
|
|
95
|
+
* refused (EDD-9059 – EDD-9061, `rejectUnsupportedOp`), and an update's own
|
|
96
|
+
* operands decided (`Entity._prepareUpdate`: its payload, and the keys the
|
|
97
|
+
* payload composes), which its plan reuses. Without `plan`
|
|
98
|
+
* (`EventStore.append`), such ops are refused.
|
|
92
99
|
*/
|
|
93
|
-
export const
|
|
94
|
-
const
|
|
95
|
-
for (let opIndex = 0; opIndex < operations.length; opIndex++) {
|
|
96
|
-
const op = operations[opIndex];
|
|
97
|
-
if (op != null && typeof op === "object" && ConditionCheckTypeId in op)
|
|
98
|
-
continue;
|
|
99
|
-
const info = extractTransactable(op);
|
|
100
|
-
if (info === undefined)
|
|
101
|
-
continue;
|
|
102
|
-
if (info.opType === "update" && info.updateState !== undefined) {
|
|
103
|
-
yield* rejectUnsupportedOp(info.entity, "transactWrite", "update", undefined, undefined, {
|
|
104
|
-
updateState: info.updateState,
|
|
105
|
-
});
|
|
106
|
-
plans.set(opIndex, yield* info.entity._planUpdate(info.key, info.updateState));
|
|
107
|
-
}
|
|
108
|
-
else if (info.opType === "delete" &&
|
|
109
|
-
info.deleteRequest !== undefined &&
|
|
110
|
-
info.entity._multiItemWriteFeatures.length > 0) {
|
|
111
|
-
yield* rejectUnsupportedOp(info.entity, "transactWrite", "delete", undefined, undefined, {
|
|
112
|
-
returnValues: info.deleteRequest.returnValues,
|
|
113
|
-
readsStoredRow: true,
|
|
114
|
-
});
|
|
115
|
-
plans.set(opIndex, yield* info.entity._planDelete(info.key, {
|
|
116
|
-
condition: info.deleteRequest.condition,
|
|
117
|
-
mustExist: info.deleteRequest.mustExist,
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return plans;
|
|
122
|
-
});
|
|
123
|
-
/**
|
|
124
|
-
* Compile a list of Entity write ops into marshalled `TransactWriteItems` entries,
|
|
125
|
-
* preserving caller order.
|
|
126
|
-
*
|
|
127
|
-
* **One caller op may emit several items.** A put of a versioned or
|
|
128
|
-
* unique-constrained entity is a guarded put (#133): it reads the item, and
|
|
129
|
-
* emits the item guarded on what was read, plus its sentinel reservations and
|
|
130
|
-
* releases and its retain snapshot (see {@link GuardedWrite}). `provenance`
|
|
131
|
-
* records which caller op each emitted item belongs to; consumers that map
|
|
132
|
-
* cancellation reasons positionally MUST use it instead of assuming 1:1, and
|
|
133
|
-
* read a guarded put's reasons through {@link judgeCancellation}.
|
|
134
|
-
*
|
|
135
|
-
* DynamoDB's rules (one operation per item, 100 items, 4 MB, 400 KB per
|
|
136
|
-
* item, 2048-byte partition and 1024-byte sort keys, the limits on one expression) are not
|
|
137
|
-
* pre-checked: the caller sends the transaction and diagnoses DynamoDB's
|
|
138
|
-
* rejection through `internal/WriteDiagnosis.ts`, which counts the EXPANDED
|
|
139
|
-
* items and names the culprit through `targets` (and `keys`) — two ops
|
|
140
|
-
* touching one item included, among them two puts that swap unique values
|
|
141
|
-
* and so release and claim the same sentinels. A caller adding items of its
|
|
142
|
-
* own appends their targets to these.
|
|
143
|
-
*
|
|
144
|
-
* A {@link StreamAppendOp} is accepted only with `{ streams: true }` — an
|
|
145
|
-
* `EventStore` append's `additionalItems` — and is refused with
|
|
146
|
-
* `ValidationError` otherwise. Its items are built by the inner stream
|
|
147
|
-
* (provenance `kind: "stream"`), recorded in `streams`, and left out of
|
|
148
|
-
* `conditioned`.
|
|
149
|
-
*/
|
|
150
|
-
export const buildTransactWriteItems = (operations, operation, options) => Effect.gen(function* () {
|
|
151
|
-
if (operations.length === 0) {
|
|
152
|
-
return {
|
|
153
|
-
items: [],
|
|
154
|
-
provenance: [],
|
|
155
|
-
targets: () => [],
|
|
156
|
-
guarded: [],
|
|
157
|
-
streams: [],
|
|
158
|
-
conditioned: new Set(),
|
|
159
|
-
keys: () => mergeKeyAttributes(),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const opInfos = [];
|
|
163
|
-
/** The nested stream appends, by caller op index. */
|
|
100
|
+
export const prepareTransactWriteOps = (operations, operation, options) => Effect.gen(function* () {
|
|
101
|
+
const ops = [];
|
|
164
102
|
const streamOps = new Map();
|
|
165
103
|
for (let opIndex = 0; opIndex < operations.length; opIndex++) {
|
|
166
104
|
const op = operations[opIndex];
|
|
@@ -175,7 +113,9 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
175
113
|
"additionalItems. Nothing was sent.",
|
|
176
114
|
});
|
|
177
115
|
}
|
|
178
|
-
|
|
116
|
+
// Built by its own stream, reading nothing: its refusals (no events, an
|
|
117
|
+
// event its schema refuses) come before any op reads.
|
|
118
|
+
streamOps.set(opIndex, yield* op._build(`operation ${opIndex}`));
|
|
179
119
|
continue;
|
|
180
120
|
}
|
|
181
121
|
// Check for ConditionCheckOp first (has its own TypeId)
|
|
@@ -190,12 +130,23 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
190
130
|
cause: `${operation}: Transaction.check() was given an empty condition. Nothing was sent.`,
|
|
191
131
|
});
|
|
192
132
|
}
|
|
193
|
-
|
|
133
|
+
// `Expression.condition` compiled an operand without its map entry keyed `__proto__`
|
|
134
|
+
// (`EDD-9165`), as 1.40.0 did, and DynamoDB refused what that left on every path.
|
|
135
|
+
const unsent = unsentIn(checkOp._condition);
|
|
136
|
+
if (unsent !== undefined) {
|
|
137
|
+
return yield* new ValidationError({
|
|
138
|
+
entityType: checkOp._entity.entityType,
|
|
139
|
+
operation: `${operation}.check`,
|
|
140
|
+
cause: `${operation}: Transaction.check()'s condition compares with a value DynamoDB ` +
|
|
141
|
+
`can't store: ${unsent.describe()} Nothing was sent.`,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
ops.push({
|
|
194
145
|
type: "conditionCheck",
|
|
195
146
|
entity: checkOp._entity,
|
|
196
147
|
opIndex,
|
|
197
|
-
key: checkOp._key,
|
|
198
148
|
condition: checkOp._condition,
|
|
149
|
+
primaryKey: yield* composePrimaryKeyOrFail(checkOp._entity, checkOp._key, `${operation}.check`),
|
|
199
150
|
});
|
|
200
151
|
continue;
|
|
201
152
|
}
|
|
@@ -207,19 +158,52 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
207
158
|
cause: `${operation}: unrecognized operation type. Use EntityPut, EntityDelete, or Transaction.check().`,
|
|
208
159
|
});
|
|
209
160
|
}
|
|
210
|
-
|
|
211
|
-
|
|
161
|
+
if (options?.plan === true && info.opType === "update" && info.updateState !== undefined) {
|
|
162
|
+
const { entity, key, updateState } = info;
|
|
163
|
+
yield* rejectUnsupportedOp(entity, operation, "update", undefined, undefined, {
|
|
164
|
+
updateState,
|
|
165
|
+
});
|
|
166
|
+
// Its condition, refused here as every op's is, before any op of the transaction reads:
|
|
167
|
+
// planning compiles it only after the reads (#236).
|
|
168
|
+
yield* refuseEmptyParts(entity, operation, "update", updateState.condition);
|
|
169
|
+
const encoded = yield* entity._encodeKey(key, `${operation}.update.decodeKey`);
|
|
170
|
+
// What the update decides from its own operands: refused here, and planned from.
|
|
171
|
+
const prepared = yield* entity._prepareUpdate(key, updateState, encoded);
|
|
212
172
|
// No `condition` here, so a planned op is never in `conditioned`, even
|
|
213
173
|
// with a `.condition()` of its own: its verdict reports that as
|
|
214
174
|
// `"Condition"`. Only `EventStore.append` reads `conditioned`, and it
|
|
215
175
|
// plans nothing — if it ever does, add planned ops to it.
|
|
216
|
-
|
|
176
|
+
ops.push({
|
|
177
|
+
type: "planned",
|
|
178
|
+
entity,
|
|
179
|
+
opIndex,
|
|
180
|
+
plan: () => entity._planUpdate(key, updateState, prepared),
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (options?.plan === true &&
|
|
185
|
+
info.opType === "delete" &&
|
|
186
|
+
info.deleteRequest !== undefined &&
|
|
187
|
+
info.entity._multiItemWriteFeatures.length > 0) {
|
|
188
|
+
const { entity, key, deleteRequest } = info;
|
|
189
|
+
yield* rejectUnsupportedOp(entity, operation, "delete", undefined, undefined, {
|
|
190
|
+
returnValues: deleteRequest.returnValues,
|
|
191
|
+
readsStoredRow: true,
|
|
192
|
+
});
|
|
193
|
+
yield* refuseEmptyParts(entity, operation, "delete", deleteRequest.condition);
|
|
194
|
+
const encoded = yield* entity._encodeKey(key, `${operation}.delete.decodeKey`);
|
|
195
|
+
ops.push({
|
|
196
|
+
type: "planned",
|
|
197
|
+
entity,
|
|
198
|
+
opIndex,
|
|
199
|
+
plan: () => entity._planDelete(key, { condition: deleteRequest.condition, mustExist: deleteRequest.mustExist }, encoded),
|
|
200
|
+
});
|
|
217
201
|
continue;
|
|
218
202
|
}
|
|
219
203
|
if (info.opType === "put") {
|
|
220
204
|
yield* rejectUnsupportedOp(info.entity, operation, "put", info.putKind, info.input);
|
|
221
205
|
yield* refuseEmptyParts(info.entity, operation, "put", info.condition);
|
|
222
|
-
|
|
206
|
+
ops.push({
|
|
223
207
|
type: "put",
|
|
224
208
|
putKind: info.putKind,
|
|
225
209
|
entity: info.entity,
|
|
@@ -227,6 +211,7 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
227
211
|
input: info.input,
|
|
228
212
|
condition: compileOpCondition(info.entity, info.condition),
|
|
229
213
|
callerCondition: info.callerCondition,
|
|
214
|
+
built: yield* validateAndBuildPutItem(info.entity, info.input, `${operation}.put`),
|
|
230
215
|
});
|
|
231
216
|
}
|
|
232
217
|
else if (info.opType === "delete") {
|
|
@@ -234,12 +219,12 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
234
219
|
returnValues: info.deleteRequest?.returnValues,
|
|
235
220
|
});
|
|
236
221
|
yield* refuseEmptyParts(info.entity, operation, "delete", info.condition);
|
|
237
|
-
|
|
222
|
+
ops.push({
|
|
238
223
|
type: "delete",
|
|
239
224
|
entity: info.entity,
|
|
240
225
|
opIndex,
|
|
241
|
-
key: info.key,
|
|
242
226
|
condition: compileOpCondition(info.entity, info.condition),
|
|
227
|
+
primaryKey: yield* composePrimaryKeyOrFail(info.entity, info.key, `${operation}.delete`),
|
|
243
228
|
});
|
|
244
229
|
}
|
|
245
230
|
else {
|
|
@@ -254,6 +239,72 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
254
239
|
});
|
|
255
240
|
}
|
|
256
241
|
}
|
|
242
|
+
return { count: operations.length, ops, streamOps };
|
|
243
|
+
});
|
|
244
|
+
/**
|
|
245
|
+
* The read pass that lets `Transaction.transactWrite` carry its planned ops
|
|
246
|
+
* ({@link prepareTransactWriteOps}): each is the standalone op itself, run
|
|
247
|
+
* with its write recorded instead of sent, so the transaction writes exactly
|
|
248
|
+
* what the standalone op would have — every read, item and guard included.
|
|
249
|
+
* Returns the plans keyed by index into the caller's operations. Run on every
|
|
250
|
+
* attempt, so a transaction cancelled by a lost race is planned again from
|
|
251
|
+
* fresh reads.
|
|
252
|
+
*/
|
|
253
|
+
export const planTransactWriteOps = (prepared) => Effect.gen(function* () {
|
|
254
|
+
const plans = new Map();
|
|
255
|
+
for (const op of prepared.ops) {
|
|
256
|
+
if (op.plan !== undefined)
|
|
257
|
+
plans.set(op.opIndex, yield* op.plan());
|
|
258
|
+
}
|
|
259
|
+
return plans;
|
|
260
|
+
});
|
|
261
|
+
/**
|
|
262
|
+
* Compile a list of Entity write ops into marshalled `TransactWriteItems` entries,
|
|
263
|
+
* preserving caller order.
|
|
264
|
+
*
|
|
265
|
+
* **One caller op may emit several items.** A put of a versioned or
|
|
266
|
+
* unique-constrained entity is a guarded put (#133): it reads the item, and
|
|
267
|
+
* emits the item guarded on what was read, plus its sentinel reservations and
|
|
268
|
+
* releases and its retain snapshot (see {@link GuardedWrite}). `provenance`
|
|
269
|
+
* records which caller op each emitted item belongs to; consumers that map
|
|
270
|
+
* cancellation reasons positionally MUST use it instead of assuming 1:1, and
|
|
271
|
+
* read a guarded put's reasons through {@link judgeCancellation}.
|
|
272
|
+
*
|
|
273
|
+
* DynamoDB's rules (one operation per item, 100 items, 4 MB, 400 KB per
|
|
274
|
+
* item, 2048-byte partition and 1024-byte sort keys, the limits on one expression) are not
|
|
275
|
+
* pre-checked: the caller sends the transaction and diagnoses DynamoDB's
|
|
276
|
+
* rejection through `internal/WriteDiagnosis.ts`, which counts the EXPANDED
|
|
277
|
+
* items and names the culprit through `targets` (and `keys`) — two ops
|
|
278
|
+
* touching one item included, among them two puts that swap unique values
|
|
279
|
+
* and so release and claim the same sentinels. A caller adding items of its
|
|
280
|
+
* own appends their targets to these.
|
|
281
|
+
*
|
|
282
|
+
* A {@link StreamAppendOp} is accepted only with `{ streams: true }` — an
|
|
283
|
+
* `EventStore` append's `additionalItems` — and is refused with
|
|
284
|
+
* `ValidationError` otherwise. Its items are built by the inner stream
|
|
285
|
+
* (provenance `kind: "stream"`), recorded in `streams`, and left out of
|
|
286
|
+
* `conditioned`.
|
|
287
|
+
*
|
|
288
|
+
* The ops are checked and composed first ({@link prepareTransactWriteOps}), or
|
|
289
|
+
* come so (`prepared`, with `plans`, from `transactWrite`), so nothing is read
|
|
290
|
+
* before every op's own refusals.
|
|
291
|
+
*/
|
|
292
|
+
export const buildTransactWriteItems = (operations, operation, options) => Effect.gen(function* () {
|
|
293
|
+
if (operations.length === 0) {
|
|
294
|
+
return {
|
|
295
|
+
items: [],
|
|
296
|
+
provenance: [],
|
|
297
|
+
targets: () => [],
|
|
298
|
+
guarded: [],
|
|
299
|
+
streams: [],
|
|
300
|
+
conditioned: new Set(),
|
|
301
|
+
keys: () => mergeKeyAttributes(),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const prepared = options?.prepared ??
|
|
305
|
+
(yield* prepareTransactWriteOps(operations, operation, { streams: options?.streams }));
|
|
306
|
+
const opInfos = prepared.ops;
|
|
307
|
+
const streamOps = prepared.streamOps;
|
|
257
308
|
const tableNames = yield* resolveTableNames(opInfos);
|
|
258
309
|
const items = [];
|
|
259
310
|
const provenance = [];
|
|
@@ -277,9 +328,8 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
277
328
|
};
|
|
278
329
|
// The nested stream appends, built by their own streams, are pushed in
|
|
279
330
|
// caller op order between the entity ops' items.
|
|
280
|
-
const pushStreamOp = (opIndex) =>
|
|
281
|
-
const
|
|
282
|
-
const nested = yield* op._build(`operation ${opIndex}`);
|
|
331
|
+
const pushStreamOp = (opIndex) => {
|
|
332
|
+
const nested = streamOps.get(opIndex);
|
|
283
333
|
streams.push({
|
|
284
334
|
opIndex,
|
|
285
335
|
start: items.length,
|
|
@@ -299,30 +349,34 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
299
349
|
provenance.push({ opIndex, kind: "stream", entityType: nested.entityType });
|
|
300
350
|
naming.push(() => nestedTarget(i));
|
|
301
351
|
}
|
|
302
|
-
}
|
|
352
|
+
};
|
|
303
353
|
let nextOpIndex = 0;
|
|
304
|
-
const flushStreamOpsBefore = (opIndex) =>
|
|
354
|
+
const flushStreamOpsBefore = (opIndex) => {
|
|
305
355
|
for (; nextOpIndex < opIndex; nextOpIndex++) {
|
|
306
356
|
if (streamOps.has(nextOpIndex))
|
|
307
|
-
|
|
357
|
+
pushStreamOp(nextOpIndex);
|
|
308
358
|
}
|
|
309
359
|
nextOpIndex = opIndex + 1;
|
|
310
|
-
}
|
|
360
|
+
};
|
|
311
361
|
for (const op of opInfos) {
|
|
312
|
-
|
|
362
|
+
flushStreamOpsBefore(op.opIndex);
|
|
313
363
|
tableName = tableNames.get(op.entity);
|
|
314
364
|
const primary = op.entity.indexes.primary;
|
|
315
365
|
keyFields = [primary.pk.field, primary.sk.field];
|
|
316
366
|
if (op.type === "planned") {
|
|
317
367
|
// Already marshalled and table-resolved; read like a guarded put's.
|
|
318
|
-
|
|
319
|
-
|
|
368
|
+
const plan = options?.plans?.get(op.opIndex);
|
|
369
|
+
if (plan === undefined) {
|
|
370
|
+
return yield* Effect.die(new Error(`${operation}: operation ${op.opIndex} was not planned`));
|
|
371
|
+
}
|
|
372
|
+
guarded.push({ opIndex: op.opIndex, start: items.length, plan });
|
|
373
|
+
for (const [i, item] of plan.items.entries()) {
|
|
320
374
|
push(item, { opIndex: op.opIndex, kind: "guarded", entityType: op.entity.entityType }, i > 0);
|
|
321
375
|
}
|
|
322
376
|
continue;
|
|
323
377
|
}
|
|
324
378
|
if (op.type === "put") {
|
|
325
|
-
const built =
|
|
379
|
+
const built = op.built;
|
|
326
380
|
if (op.entity._incarnationToken || op.entity._multiItemWriteFeatures.includes("unique")) {
|
|
327
381
|
const plan = yield* op.entity._planPut({
|
|
328
382
|
tableName,
|
|
@@ -333,7 +387,7 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
333
387
|
userCondition: op.condition,
|
|
334
388
|
create: op.putKind === "create",
|
|
335
389
|
operation,
|
|
336
|
-
|
|
390
|
+
composeKeys: built.composeKeys,
|
|
337
391
|
});
|
|
338
392
|
guarded.push({ opIndex: op.opIndex, start: items.length, plan });
|
|
339
393
|
for (const [i, item] of plan.items.entries()) {
|
|
@@ -344,14 +398,14 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
344
398
|
// `create` over a projection tombstone (#154): take its place,
|
|
345
399
|
// carrying its checkpoints over, guarded on that tombstone.
|
|
346
400
|
const over = op.putKind === "create"
|
|
347
|
-
? yield* op.entity._overTombstone(
|
|
401
|
+
? yield* op.entity._overTombstone(built.item)
|
|
348
402
|
: Option.none();
|
|
349
403
|
push({
|
|
350
404
|
Put: {
|
|
351
405
|
TableName: tableName,
|
|
352
406
|
Item: Option.isSome(over) ? toAttributeMap(built.item) : built.marshalled,
|
|
353
407
|
...conditionFields(Option.isSome(over)
|
|
354
|
-
? compileOpCondition(op.entity, withGuard(over.value, op.callerCondition))
|
|
408
|
+
? andRaw(compileOpCondition(op.entity, withGuard(over.value.guard, op.callerCondition)), over.value.term)
|
|
355
409
|
: op.condition),
|
|
356
410
|
},
|
|
357
411
|
}, { opIndex: op.opIndex, kind: "main", entityType: op.entity.entityType });
|
|
@@ -360,7 +414,7 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
360
414
|
push({
|
|
361
415
|
Delete: {
|
|
362
416
|
TableName: tableName,
|
|
363
|
-
Key: toAttributeMap(
|
|
417
|
+
Key: toAttributeMap(op.primaryKey),
|
|
364
418
|
...conditionFields(op.condition),
|
|
365
419
|
},
|
|
366
420
|
}, { opIndex: op.opIndex, kind: "main", entityType: op.entity.entityType });
|
|
@@ -369,14 +423,14 @@ export const buildTransactWriteItems = (operations, operation, options) => Effec
|
|
|
369
423
|
push({
|
|
370
424
|
ConditionCheck: {
|
|
371
425
|
TableName: tableName,
|
|
372
|
-
Key: toAttributeMap(
|
|
426
|
+
Key: toAttributeMap(op.primaryKey),
|
|
373
427
|
ConditionExpression: op.condition.expression,
|
|
374
428
|
...conditionFields(op.condition),
|
|
375
429
|
},
|
|
376
430
|
}, { opIndex: op.opIndex, kind: "main", entityType: op.entity.entityType });
|
|
377
431
|
}
|
|
378
432
|
}
|
|
379
|
-
|
|
433
|
+
flushStreamOpsBefore(operations.length);
|
|
380
434
|
const keys = () => mergeKeyAttributes(...opInfos.map((op) => keyAttributesOf(op.entity.indexes)), ...streamKeys.map((nested) => nested()));
|
|
381
435
|
const targets = () => naming.map((name) => name());
|
|
382
436
|
return { items, provenance, targets, guarded, streams, conditioned, keys };
|