effect-dynamodb 1.42.2 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Aggregate.d.ts +157 -20
- package/dist/Aggregate.d.ts.map +1 -1
- package/dist/Aggregate.js +1219 -286
- package/dist/Aggregate.js.map +1 -1
- package/dist/Batch.d.ts +17 -4
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +129 -62
- package/dist/Batch.js.map +1 -1
- package/dist/BlobGc.d.ts +243 -0
- package/dist/BlobGc.d.ts.map +1 -0
- package/dist/BlobGc.js +961 -0
- package/dist/BlobGc.js.map +1 -0
- package/dist/BlobStore.d.ts +83 -0
- package/dist/BlobStore.d.ts.map +1 -0
- package/dist/BlobStore.js +70 -0
- package/dist/BlobStore.js.map +1 -0
- package/dist/Collection.d.ts +88 -8
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +22 -26
- package/dist/Collection.js.map +1 -1
- package/dist/Collections.d.ts +0 -7
- package/dist/Collections.d.ts.map +1 -1
- package/dist/Collections.js +0 -16
- package/dist/Collections.js.map +1 -1
- package/dist/DynamoClient.d.ts +68 -35
- package/dist/DynamoClient.d.ts.map +1 -1
- package/dist/DynamoClient.js +58 -12
- package/dist/DynamoClient.js.map +1 -1
- package/dist/Entity.d.ts +403 -104
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +1771 -382
- package/dist/Entity.js.map +1 -1
- package/dist/EventStore.d.ts +323 -77
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +473 -96
- package/dist/EventStore.js.map +1 -1
- package/dist/Offload.d.ts +199 -0
- package/dist/Offload.d.ts.map +1 -0
- package/dist/Offload.js +120 -0
- package/dist/Offload.js.map +1 -0
- package/dist/Query.d.ts +132 -59
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +95 -31
- package/dist/Query.js.map +1 -1
- package/dist/StorageEncoding.d.ts +62 -15
- package/dist/StorageEncoding.d.ts.map +1 -1
- package/dist/StorageEncoding.js +108 -24
- package/dist/StorageEncoding.js.map +1 -1
- package/dist/Table.d.ts +1 -1
- package/dist/Table.d.ts.map +1 -1
- package/dist/Transaction.d.ts +16 -3
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +28 -9
- package/dist/Transaction.js.map +1 -1
- package/dist/blob/S3BlobStore.d.ts +178 -0
- package/dist/blob/S3BlobStore.d.ts.map +1 -0
- package/dist/blob/S3BlobStore.js +770 -0
- package/dist/blob/S3BlobStore.js.map +1 -0
- package/dist/blob/s3.d.ts +122 -0
- package/dist/blob/s3.d.ts.map +1 -0
- package/dist/blob/s3.js +143 -0
- package/dist/blob/s3.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/AggregateWrite.d.ts +130 -0
- package/dist/internal/AggregateWrite.d.ts.map +1 -0
- package/dist/internal/AggregateWrite.js +341 -0
- package/dist/internal/AggregateWrite.js.map +1 -0
- package/dist/internal/BlobCalls.d.ts +70 -0
- package/dist/internal/BlobCalls.d.ts.map +1 -0
- package/dist/internal/BlobCalls.js +105 -0
- package/dist/internal/BlobCalls.js.map +1 -0
- package/dist/internal/BlobKeys.d.ts +100 -0
- package/dist/internal/BlobKeys.d.ts.map +1 -0
- package/dist/internal/BlobKeys.js +135 -0
- package/dist/internal/BlobKeys.js.map +1 -0
- package/dist/internal/BlobLedger.d.ts +323 -0
- package/dist/internal/BlobLedger.d.ts.map +1 -0
- package/dist/internal/BlobLedger.js +1012 -0
- package/dist/internal/BlobLedger.js.map +1 -0
- package/dist/internal/BlobMetadata.d.ts +109 -0
- package/dist/internal/BlobMetadata.d.ts.map +1 -0
- package/dist/internal/BlobMetadata.js +249 -0
- package/dist/internal/BlobMetadata.js.map +1 -0
- package/dist/internal/BlobResolver.d.ts +146 -0
- package/dist/internal/BlobResolver.d.ts.map +1 -0
- package/dist/internal/BlobResolver.js +417 -0
- package/dist/internal/BlobResolver.js.map +1 -0
- package/dist/internal/BlobStoreContract.d.ts +214 -0
- package/dist/internal/BlobStoreContract.d.ts.map +1 -0
- package/dist/internal/BlobStoreContract.js +181 -0
- package/dist/internal/BlobStoreContract.js.map +1 -0
- package/dist/internal/BoundCrud.d.ts +153 -53
- package/dist/internal/BoundCrud.d.ts.map +1 -1
- package/dist/internal/BoundCrud.js +27 -5
- package/dist/internal/BoundCrud.js.map +1 -1
- package/dist/internal/BoundQuery.d.ts +49 -33
- package/dist/internal/BoundQuery.d.ts.map +1 -1
- package/dist/internal/BoundQuery.js +8 -2
- package/dist/internal/BoundQuery.js.map +1 -1
- package/dist/internal/BoundVectorQuery.d.ts +59 -25
- package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
- package/dist/internal/BoundVectorQuery.js +38 -17
- package/dist/internal/BoundVectorQuery.js.map +1 -1
- package/dist/internal/Capacity.d.ts +17 -2
- package/dist/internal/Capacity.d.ts.map +1 -1
- package/dist/internal/Capacity.js +47 -9
- package/dist/internal/Capacity.js.map +1 -1
- package/dist/internal/ConditionHolds.d.ts.map +1 -1
- package/dist/internal/ConditionHolds.js +2 -8
- package/dist/internal/ConditionHolds.js.map +1 -1
- package/dist/internal/CredentialRefusal.d.ts.map +1 -1
- package/dist/internal/CredentialRefusal.js +4 -0
- package/dist/internal/CredentialRefusal.js.map +1 -1
- package/dist/internal/Digest.d.ts +4 -3
- package/dist/internal/Digest.d.ts.map +1 -1
- package/dist/internal/Digest.js +25 -82
- package/dist/internal/Digest.js.map +1 -1
- package/dist/internal/EntityCombinators.d.ts +93 -45
- package/dist/internal/EntityCombinators.d.ts.map +1 -1
- package/dist/internal/EntityCombinators.js +42 -7
- package/dist/internal/EntityCombinators.js.map +1 -1
- package/dist/internal/EntityOps.d.ts +47 -6
- package/dist/internal/EntityOps.d.ts.map +1 -1
- package/dist/internal/EntityOps.js +30 -10
- package/dist/internal/EntityOps.js.map +1 -1
- package/dist/internal/EventProjection.d.ts +99 -25
- package/dist/internal/EventProjection.d.ts.map +1 -1
- package/dist/internal/EventProjection.js +124 -33
- package/dist/internal/EventProjection.js.map +1 -1
- package/dist/internal/ExpressionLimits.d.ts +22 -3
- package/dist/internal/ExpressionLimits.d.ts.map +1 -1
- package/dist/internal/ExpressionLimits.js +46 -7
- package/dist/internal/ExpressionLimits.js.map +1 -1
- package/dist/internal/GcSupport.d.ts +258 -0
- package/dist/internal/GcSupport.d.ts.map +1 -0
- package/dist/internal/GcSupport.js +284 -0
- package/dist/internal/GcSupport.js.map +1 -0
- package/dist/internal/ItemSize.d.ts +7 -1
- package/dist/internal/ItemSize.d.ts.map +1 -1
- package/dist/internal/ItemSize.js +13 -5
- package/dist/internal/ItemSize.js.map +1 -1
- package/dist/internal/MemoryBlobStore.d.ts +203 -0
- package/dist/internal/MemoryBlobStore.d.ts.map +1 -0
- package/dist/internal/MemoryBlobStore.js +623 -0
- package/dist/internal/MemoryBlobStore.js.map +1 -0
- package/dist/internal/MultiProjection.d.ts +56 -28
- package/dist/internal/MultiProjection.d.ts.map +1 -1
- package/dist/internal/MultiProjection.js +9 -3
- package/dist/internal/MultiProjection.js.map +1 -1
- package/dist/internal/Multipart.d.ts +96 -0
- package/dist/internal/Multipart.d.ts.map +1 -0
- package/dist/internal/Multipart.js +143 -0
- package/dist/internal/Multipart.js.map +1 -0
- package/dist/internal/OffloadChange.d.ts +187 -0
- package/dist/internal/OffloadChange.d.ts.map +1 -0
- package/dist/internal/OffloadChange.js +391 -0
- package/dist/internal/OffloadChange.js.map +1 -0
- package/dist/internal/OffloadInput.d.ts +141 -0
- package/dist/internal/OffloadInput.d.ts.map +1 -0
- package/dist/internal/OffloadInput.js +236 -0
- package/dist/internal/OffloadInput.js.map +1 -0
- package/dist/internal/OffloadRead.d.ts +140 -0
- package/dist/internal/OffloadRead.d.ts.map +1 -0
- package/dist/internal/OffloadRead.js +369 -0
- package/dist/internal/OffloadRead.js.map +1 -0
- package/dist/internal/OffloadTypes.d.ts +182 -0
- package/dist/internal/OffloadTypes.d.ts.map +1 -0
- package/dist/internal/OffloadTypes.js +15 -0
- package/dist/internal/OffloadTypes.js.map +1 -0
- package/dist/internal/OffloadValues.d.ts +87 -0
- package/dist/internal/OffloadValues.d.ts.map +1 -0
- package/dist/internal/OffloadValues.js +114 -0
- package/dist/internal/OffloadValues.js.map +1 -0
- package/dist/internal/OffloadWrite.d.ts +267 -0
- package/dist/internal/OffloadWrite.d.ts.map +1 -0
- package/dist/internal/OffloadWrite.js +766 -0
- package/dist/internal/OffloadWrite.js.map +1 -0
- package/dist/internal/Packed.d.ts +58 -23
- package/dist/internal/Packed.d.ts.map +1 -1
- package/dist/internal/Packed.js +108 -33
- package/dist/internal/Packed.js.map +1 -1
- package/dist/internal/ProjectionEngine.d.ts +28 -3
- package/dist/internal/ProjectionEngine.d.ts.map +1 -1
- package/dist/internal/ProjectionEngine.js +47 -9
- package/dist/internal/ProjectionEngine.js.map +1 -1
- package/dist/internal/RangePlanner.d.ts +3 -6
- package/dist/internal/RangePlanner.d.ts.map +1 -1
- package/dist/internal/RangePlanner.js +3 -29
- package/dist/internal/RangePlanner.js.map +1 -1
- package/dist/internal/Rekey.d.ts +16 -0
- package/dist/internal/Rekey.d.ts.map +1 -1
- package/dist/internal/Rekey.js +31 -2
- package/dist/internal/Rekey.js.map +1 -1
- package/dist/internal/StoredPointer.d.ts +19 -0
- package/dist/internal/StoredPointer.d.ts.map +1 -0
- package/dist/internal/StoredPointer.js +59 -0
- package/dist/internal/StoredPointer.js.map +1 -0
- package/dist/internal/TransactPlan.d.ts +18 -1
- package/dist/internal/TransactPlan.d.ts.map +1 -1
- package/dist/internal/TransactPlan.js +50 -10
- package/dist/internal/TransactPlan.js.map +1 -1
- package/dist/internal/TransactWriteOps.d.ts +33 -12
- package/dist/internal/TransactWriteOps.d.ts.map +1 -1
- package/dist/internal/TransactWriteOps.js +49 -19
- package/dist/internal/TransactWriteOps.js.map +1 -1
- package/dist/internal/TransactableOps.d.ts +58 -11
- package/dist/internal/TransactableOps.d.ts.map +1 -1
- package/dist/internal/TransactableOps.js +95 -19
- package/dist/internal/TransactableOps.js.map +1 -1
- package/dist/internal/Utf8Order.d.ts +21 -0
- package/dist/internal/Utf8Order.d.ts.map +1 -0
- package/dist/internal/Utf8Order.js +44 -0
- package/dist/internal/Utf8Order.js.map +1 -0
- package/dist/internal/WriteDiagnosis.d.ts +7 -1
- package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
- package/dist/internal/WriteDiagnosis.js +12 -16
- package/dist/internal/WriteDiagnosis.js.map +1 -1
- package/package.json +15 -4
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Change detection over offloaded fields (#179, design §10.3,
|
|
3
|
+
* §10.4): what a write did to one offloaded field, read from the stored forms
|
|
4
|
+
* of its old and new values — never from the blob store — and the check that
|
|
5
|
+
* a DynamoDB Streams record carries the images change detection needs.
|
|
6
|
+
*
|
|
7
|
+
* - **Stored forms.** An offloaded attribute holds, by its stored form: a
|
|
8
|
+
* pointer (a `B` json pointer on an overflow attribute, `~edbp:` `S` text on
|
|
9
|
+
* a binary one), an inline value (an overflow field's JSON as `S`, or as a
|
|
10
|
+
* v1 `B` — its content the decompressed JSON; a binary field's bytes), a
|
|
11
|
+
* legacy native value (an overflow attribute written before `Packed`: a map,
|
|
12
|
+
* a list, …), `NULL`, or nothing.
|
|
13
|
+
* - **Classification** ({@link compareForms}, design §10.3's table): a pointer
|
|
14
|
+
* to the same ref is `unchanged`; equal checksum algorithm, checksum and
|
|
15
|
+
* content size elsewhere `rewritten` (probably identical, §5); an inline
|
|
16
|
+
* value against a pointer is compared by the CRC-64/NVME and size of its
|
|
17
|
+
* content, computed here; two inline values by their content bytes; legacy
|
|
18
|
+
* native values only with each other, structurally; anything else
|
|
19
|
+
* `changed`. `added` / `removed` when one side is absent.
|
|
20
|
+
* - **Records** ({@link recordImages}): `[EDD-9119]` when a record's
|
|
21
|
+
* `StreamViewType` is not `NEW_AND_OLD_IMAGES`, or a record lacks an image
|
|
22
|
+
* its event has (a `MODIFY` / `REMOVE` without `OldImage`, a `MODIFY` /
|
|
23
|
+
* `INSERT` without `NewImage`).
|
|
24
|
+
*
|
|
25
|
+
* Runtime-neutral, like `Offload.ts`, which re-exports {@link compareStored}:
|
|
26
|
+
* no AWS SDK and no Node builtin in its import graph (types included), so the
|
|
27
|
+
* attribute values it takes are typed structurally
|
|
28
|
+
* ({@link StoredAttributeValue}, which the SDK's `AttributeValue` fits).
|
|
29
|
+
*
|
|
30
|
+
* Not part of the public API.
|
|
31
|
+
*/
|
|
32
|
+
import { Compression, empty as emptyRegistry, } from "@effect-dynamodb/schema/Compression.js";
|
|
33
|
+
import { ValidationError } from "@effect-dynamodb/schema/Errors.js";
|
|
34
|
+
import { isBlobPointer, isPointerText, } from "@effect-dynamodb/schema/internal/BlobPointer.js";
|
|
35
|
+
import { crc64nvme } from "@effect-dynamodb/schema/internal/Crc64Nvme.js";
|
|
36
|
+
import { isBase64PackedText, parseBinaryPointerText, unpackPayloadSync, } from "@effect-dynamodb/schema/internal/PackedCodec.js";
|
|
37
|
+
import { Context, Effect, Result } from "effect";
|
|
38
|
+
import { Base64 } from "effect/encoding";
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Records (EDD-9119)
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
const EVENT_NAMES = new Set(["INSERT", "MODIFY", "REMOVE"]);
|
|
43
|
+
const describe = (u) => {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(u) ?? String(u);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return String(u);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const isImage = (u) => typeof u === "object" && u !== null && !Array.isArray(u);
|
|
52
|
+
/**
|
|
53
|
+
* The event and images of `record`, or why it cannot be read: `[EDD-9119]`
|
|
54
|
+
* when it lacks the images change detection (and the reaper) need — its
|
|
55
|
+
* `StreamViewType` is not `NEW_AND_OLD_IMAGES`, or it lacks an image its
|
|
56
|
+
* event has (design §10.4) — and a plain reason for a record that is not
|
|
57
|
+
* one (no event name of DynamoDB's, an image that is not an object).
|
|
58
|
+
* `consumer` names the caller in the message. A `StreamViewType` is checked
|
|
59
|
+
* when present; the images always, so a record whose view type an input
|
|
60
|
+
* template stripped is still caught. An `INSERT`'s `OldImage` and a
|
|
61
|
+
* `REMOVE`'s `NewImage` are ignored.
|
|
62
|
+
*/
|
|
63
|
+
export const recordImages = (record, consumer) => {
|
|
64
|
+
if (typeof record !== "object" || record === null || Array.isArray(record)) {
|
|
65
|
+
return "a stream record must be an object";
|
|
66
|
+
}
|
|
67
|
+
const eventName = record.eventName;
|
|
68
|
+
if (typeof eventName !== "string" || !EVENT_NAMES.has(eventName)) {
|
|
69
|
+
return (`a stream record's eventName must be "INSERT", "MODIFY" or "REMOVE", got ` +
|
|
70
|
+
`${describe(eventName)}`);
|
|
71
|
+
}
|
|
72
|
+
const dynamodb = record.dynamodb;
|
|
73
|
+
const viewType = dynamodb?.StreamViewType;
|
|
74
|
+
if (viewType !== undefined && viewType !== "NEW_AND_OLD_IMAGES") {
|
|
75
|
+
return (`[EDD-9119] ${consumer} needs the records of a NEW_AND_OLD_IMAGES stream: this ` +
|
|
76
|
+
`record's StreamViewType is ${describe(viewType)}. Enable the table's stream with ` +
|
|
77
|
+
"StreamViewType NEW_AND_OLD_IMAGES — change detection compares the old and new images.");
|
|
78
|
+
}
|
|
79
|
+
const take = (name, needed) => {
|
|
80
|
+
const image = dynamodb?.[name];
|
|
81
|
+
if (!needed)
|
|
82
|
+
return undefined;
|
|
83
|
+
if (image === undefined || image === null) {
|
|
84
|
+
return (`[EDD-9119] ${consumer} needs the records of a NEW_AND_OLD_IMAGES stream: this ` +
|
|
85
|
+
`${eventName} record has no ${name}, so its stream's view type is not ` +
|
|
86
|
+
"NEW_AND_OLD_IMAGES (or an input template dropped the image).");
|
|
87
|
+
}
|
|
88
|
+
return isImage(image) ? image : `a stream record's ${name} must be an object`;
|
|
89
|
+
};
|
|
90
|
+
const oldImage = take("OldImage", eventName !== "INSERT");
|
|
91
|
+
if (typeof oldImage === "string")
|
|
92
|
+
return oldImage;
|
|
93
|
+
const newImage = take("NewImage", eventName !== "REMOVE");
|
|
94
|
+
if (typeof newImage === "string")
|
|
95
|
+
return newImage;
|
|
96
|
+
return { eventName: eventName, oldImage, newImage };
|
|
97
|
+
};
|
|
98
|
+
/** The form of an attribute an image does not hold. */
|
|
99
|
+
export const ABSENT = { _tag: "absent" };
|
|
100
|
+
const NULL = { _tag: "null" };
|
|
101
|
+
const encoder = new TextEncoder();
|
|
102
|
+
const invalid = (ctx, attribute, message, cause) => new ValidationError({
|
|
103
|
+
entityType: ctx.entityType,
|
|
104
|
+
operation: ctx.operation,
|
|
105
|
+
cause: cause === undefined
|
|
106
|
+
? new Error(`Offloaded attribute "${attribute}": ${message}`)
|
|
107
|
+
: new Error(`Offloaded attribute "${attribute}": ${message}`, { cause }),
|
|
108
|
+
});
|
|
109
|
+
/** Bytes, or the bytes base64 text stands for. */
|
|
110
|
+
const bytesOf = (value, ctx, attribute) => {
|
|
111
|
+
if (value instanceof Uint8Array)
|
|
112
|
+
return value;
|
|
113
|
+
if (typeof value === "string") {
|
|
114
|
+
const decoded = Base64.decode(value);
|
|
115
|
+
if (Result.isSuccess(decoded))
|
|
116
|
+
return decoded.success;
|
|
117
|
+
return invalid(ctx, attribute, "a binary value is not valid base64", decoded.failure);
|
|
118
|
+
}
|
|
119
|
+
return invalid(ctx, attribute, `a binary value must be bytes or base64 text, got ${typeof value}`);
|
|
120
|
+
};
|
|
121
|
+
/** An overflow attribute's `B` value: a json pointer, or an inline value's content. */
|
|
122
|
+
const overflowBytes = (bytes, registry, ctx, attribute) => {
|
|
123
|
+
const payload = unpackPayloadSync(bytes, registry, ctx, attribute);
|
|
124
|
+
if (payload instanceof ValidationError)
|
|
125
|
+
return payload;
|
|
126
|
+
return isBlobPointer(payload)
|
|
127
|
+
? { _tag: "pointer", pointer: payload }
|
|
128
|
+
: { _tag: "inline", content: payload };
|
|
129
|
+
};
|
|
130
|
+
/** A binary attribute's `S` value: a bytes pointer, or `undefined` when it is not one. */
|
|
131
|
+
const binaryText = (text, ctx, attribute) => {
|
|
132
|
+
const pointer = parseBinaryPointerText(text, ctx, attribute);
|
|
133
|
+
if (pointer === undefined || pointer instanceof ValidationError)
|
|
134
|
+
return pointer;
|
|
135
|
+
return { _tag: "pointer", pointer };
|
|
136
|
+
};
|
|
137
|
+
const notBinary = (ctx, attribute, what) => invalid(ctx, attribute, `${what} is neither a binary value nor a blob pointer`);
|
|
138
|
+
/**
|
|
139
|
+
* An overflow attribute's `S` value: its inline JSON — never a binary field's
|
|
140
|
+
* `~edbp:` pointer, which an overflow attribute does not hold (§4.1: its `S`
|
|
141
|
+
* is JSON, and `~` starts no JSON text).
|
|
142
|
+
*/
|
|
143
|
+
const overflowText = (text, ctx, attribute) => isPointerText(text)
|
|
144
|
+
? invalid(ctx, attribute, "the stored text is a binary field's blob pointer (~edbp:), which an overflow " +
|
|
145
|
+
"attribute never holds")
|
|
146
|
+
: { _tag: "inline", content: encoder.encode(text) };
|
|
147
|
+
/**
|
|
148
|
+
* The one member of a DynamoDB JSON value — a member set to `undefined` is no
|
|
149
|
+
* member (`StoredAttributeValue`'s optional members admit one) — or
|
|
150
|
+
* `undefined` when it has none or several, or is not an object.
|
|
151
|
+
*/
|
|
152
|
+
const tagOf = (value) => {
|
|
153
|
+
if (typeof value !== "object" || value === null)
|
|
154
|
+
return undefined;
|
|
155
|
+
let tag;
|
|
156
|
+
for (const key of Object.keys(value)) {
|
|
157
|
+
if (value[key] === undefined)
|
|
158
|
+
continue;
|
|
159
|
+
if (tag !== undefined)
|
|
160
|
+
return undefined;
|
|
161
|
+
tag = key;
|
|
162
|
+
}
|
|
163
|
+
return tag;
|
|
164
|
+
};
|
|
165
|
+
const ATTRIBUTE_VALUE_TAGS = new Set([
|
|
166
|
+
"S",
|
|
167
|
+
"N",
|
|
168
|
+
"B",
|
|
169
|
+
"BOOL",
|
|
170
|
+
"NULL",
|
|
171
|
+
"SS",
|
|
172
|
+
"NS",
|
|
173
|
+
"BS",
|
|
174
|
+
"M",
|
|
175
|
+
"L",
|
|
176
|
+
]);
|
|
177
|
+
/**
|
|
178
|
+
* The stored form of an offloaded attribute's value in DynamoDB JSON (`B` as
|
|
179
|
+
* bytes or base64 text): `undefined` is absent. In DynamoDB JSON the `S` /
|
|
180
|
+
* `B` tag says what the value is.
|
|
181
|
+
*/
|
|
182
|
+
export const formOfAttributeValue = (value, kind, registry, ctx, attribute) => {
|
|
183
|
+
if (value === undefined)
|
|
184
|
+
return ABSENT;
|
|
185
|
+
const tag = tagOf(value);
|
|
186
|
+
if (tag === undefined || !ATTRIBUTE_VALUE_TAGS.has(tag) || value instanceof Uint8Array) {
|
|
187
|
+
return invalid(ctx, attribute, "the value is not a DynamoDB JSON attribute value");
|
|
188
|
+
}
|
|
189
|
+
const member = value[tag];
|
|
190
|
+
if (tag === "NULL")
|
|
191
|
+
return NULL;
|
|
192
|
+
if (tag === "S") {
|
|
193
|
+
if (typeof member !== "string")
|
|
194
|
+
return invalid(ctx, attribute, "an S value must be a string");
|
|
195
|
+
if (kind === "overflow")
|
|
196
|
+
return overflowText(member, ctx, attribute);
|
|
197
|
+
return binaryText(member, ctx, attribute) ?? notBinary(ctx, attribute, "an S value");
|
|
198
|
+
}
|
|
199
|
+
if (tag === "B") {
|
|
200
|
+
const bytes = bytesOf(member, ctx, attribute);
|
|
201
|
+
if (bytes instanceof ValidationError)
|
|
202
|
+
return bytes;
|
|
203
|
+
return kind === "binary"
|
|
204
|
+
? { _tag: "inline", content: bytes }
|
|
205
|
+
: overflowBytes(bytes, registry, ctx, attribute);
|
|
206
|
+
}
|
|
207
|
+
return kind === "overflow"
|
|
208
|
+
? { _tag: "native", value: value }
|
|
209
|
+
: notBinary(ctx, attribute, `a ${tag} value`);
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* The stored form of an offloaded attribute's value in an unmarshalled item
|
|
213
|
+
* (`string` for `S`, `Uint8Array` for `B`): `undefined` is absent. In an
|
|
214
|
+
* unmarshalled stream **image** (`image`), a `B` value may arrive as base64
|
|
215
|
+
* text — on an overflow attribute a string starting with `I`–`X` (which JSON
|
|
216
|
+
* text never does), on a binary one any string but a `~edbp:` pointer (§4.3).
|
|
217
|
+
* A legacy native value is marshalled by `marshal` to be compared.
|
|
218
|
+
*/
|
|
219
|
+
export const formOfUnmarshalled = (value, kind, image, marshal, registry, ctx, attribute) => {
|
|
220
|
+
if (value === undefined)
|
|
221
|
+
return ABSENT;
|
|
222
|
+
if (value === null)
|
|
223
|
+
return NULL;
|
|
224
|
+
if (typeof value === "string") {
|
|
225
|
+
if (kind === "overflow") {
|
|
226
|
+
if (!(image && isBase64PackedText(value)))
|
|
227
|
+
return overflowText(value, ctx, attribute);
|
|
228
|
+
const bytes = bytesOf(value, ctx, attribute);
|
|
229
|
+
return bytes instanceof ValidationError
|
|
230
|
+
? bytes
|
|
231
|
+
: overflowBytes(bytes, registry, ctx, attribute);
|
|
232
|
+
}
|
|
233
|
+
const pointer = binaryText(value, ctx, attribute);
|
|
234
|
+
if (pointer !== undefined)
|
|
235
|
+
return pointer;
|
|
236
|
+
if (!image)
|
|
237
|
+
return notBinary(ctx, attribute, "a string value");
|
|
238
|
+
const bytes = bytesOf(value, ctx, attribute);
|
|
239
|
+
return bytes instanceof ValidationError ? bytes : { _tag: "inline", content: bytes };
|
|
240
|
+
}
|
|
241
|
+
if (value instanceof Uint8Array) {
|
|
242
|
+
return kind === "binary"
|
|
243
|
+
? { _tag: "inline", content: value }
|
|
244
|
+
: overflowBytes(value, registry, ctx, attribute);
|
|
245
|
+
}
|
|
246
|
+
if (kind === "binary")
|
|
247
|
+
return notBinary(ctx, attribute, `a ${typeof value} value`);
|
|
248
|
+
try {
|
|
249
|
+
return { _tag: "native", value: marshal(value) };
|
|
250
|
+
}
|
|
251
|
+
catch (cause) {
|
|
252
|
+
return invalid(ctx, attribute, "the legacy native value cannot be marshalled", cause);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
// ---------------------------------------------------------------------------
|
|
256
|
+
// Classification
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
const sameBytes = (a, b) => a.length === b.length && a.every((byte, i) => byte === b[i]);
|
|
259
|
+
/** Equal content checksum (algorithm and value) and content size. */
|
|
260
|
+
const sameContent = (a, b) => a.checksum.algorithm === b.checksum.algorithm &&
|
|
261
|
+
sameBytes(a.checksum.value, b.checksum.value) &&
|
|
262
|
+
a.contentSize === b.contentSize;
|
|
263
|
+
/** The inline content's CRC-64/NVME and size against the pointer's. */
|
|
264
|
+
const inlineMatches = (pointer, content) => pointer.checksum.algorithm === "crc64nvme" &&
|
|
265
|
+
pointer.contentSize === content.length &&
|
|
266
|
+
sameBytes(pointer.checksum.value, crc64nvme(content));
|
|
267
|
+
const sameRef = (a, b) => a.ref.key === b.ref.key && a.ref.version === b.ref.version;
|
|
268
|
+
/**
|
|
269
|
+
* What the change from `before` to `after` did to the field (design §10.3;
|
|
270
|
+
* see {@link OffloadChange}). Both absent: `unchanged`.
|
|
271
|
+
*/
|
|
272
|
+
export const compareForms = (before, after) => {
|
|
273
|
+
if (before._tag === "absent")
|
|
274
|
+
return after._tag === "absent" ? "unchanged" : "added";
|
|
275
|
+
if (after._tag === "absent")
|
|
276
|
+
return "removed";
|
|
277
|
+
if (before._tag === "null" || after._tag === "null") {
|
|
278
|
+
return before._tag === after._tag ? "unchanged" : "changed";
|
|
279
|
+
}
|
|
280
|
+
if (before._tag === "native" || after._tag === "native") {
|
|
281
|
+
return before._tag === "native" &&
|
|
282
|
+
after._tag === "native" &&
|
|
283
|
+
nativeEquals(before.value, after.value)
|
|
284
|
+
? "unchanged"
|
|
285
|
+
: "changed";
|
|
286
|
+
}
|
|
287
|
+
if (before._tag === "pointer" && after._tag === "pointer") {
|
|
288
|
+
if (!sameContent(before.pointer, after.pointer))
|
|
289
|
+
return "changed";
|
|
290
|
+
return sameRef(before.pointer, after.pointer) ? "unchanged" : "rewritten";
|
|
291
|
+
}
|
|
292
|
+
if (before._tag === "inline" && after._tag === "inline") {
|
|
293
|
+
return sameBytes(before.content, after.content) ? "unchanged" : "changed";
|
|
294
|
+
}
|
|
295
|
+
// One inline, one pointer: the inline content's checksum, computed here.
|
|
296
|
+
const [pointer, inline] = before._tag === "pointer"
|
|
297
|
+
? [before.pointer, after.content]
|
|
298
|
+
: [after.pointer, before.content];
|
|
299
|
+
return inlineMatches(pointer, inline) ? "rewritten" : "changed";
|
|
300
|
+
};
|
|
301
|
+
/** Bytes or base64 text, as bytes — `undefined` when it is neither. */
|
|
302
|
+
const looseBytes = (value) => {
|
|
303
|
+
if (value instanceof Uint8Array)
|
|
304
|
+
return value;
|
|
305
|
+
if (typeof value !== "string")
|
|
306
|
+
return undefined;
|
|
307
|
+
const decoded = Base64.decode(value);
|
|
308
|
+
return Result.isSuccess(decoded) ? decoded.success : undefined;
|
|
309
|
+
};
|
|
310
|
+
const bytesKey = (value) => {
|
|
311
|
+
const bytes = looseBytes(value);
|
|
312
|
+
return bytes === undefined ? undefined : Array.from(bytes).join(",");
|
|
313
|
+
};
|
|
314
|
+
const sameSet = (a, b) => {
|
|
315
|
+
if (a.includes(undefined) || b.includes(undefined))
|
|
316
|
+
return false;
|
|
317
|
+
const xs = new Set(a);
|
|
318
|
+
return xs.size === new Set(b).size && b.every((v) => xs.has(v));
|
|
319
|
+
};
|
|
320
|
+
/** Structural equality of two DynamoDB JSON values (sets as sets, `B` as bytes or base64). */
|
|
321
|
+
const nativeEquals = (a, b) => {
|
|
322
|
+
const tag = tagOf(a);
|
|
323
|
+
if (tag === undefined || tagOf(b) !== tag)
|
|
324
|
+
return false;
|
|
325
|
+
const x = a[tag];
|
|
326
|
+
const y = b[tag];
|
|
327
|
+
switch (tag) {
|
|
328
|
+
case "L": {
|
|
329
|
+
if (!Array.isArray(x) || !Array.isArray(y))
|
|
330
|
+
return false;
|
|
331
|
+
return x.length === y.length && x.every((v, i) => nativeEquals(v, y[i]));
|
|
332
|
+
}
|
|
333
|
+
case "M": {
|
|
334
|
+
if (typeof x !== "object" || x === null || typeof y !== "object" || y === null)
|
|
335
|
+
return false;
|
|
336
|
+
const xm = x;
|
|
337
|
+
const ym = y;
|
|
338
|
+
const keys = Object.keys(xm);
|
|
339
|
+
return (keys.length === Object.keys(ym).length &&
|
|
340
|
+
keys.every((k) => Object.hasOwn(ym, k) && nativeEquals(xm[k], ym[k])));
|
|
341
|
+
}
|
|
342
|
+
case "SS":
|
|
343
|
+
case "NS":
|
|
344
|
+
return Array.isArray(x) && Array.isArray(y) && sameSet(x, y);
|
|
345
|
+
case "B": {
|
|
346
|
+
const xb = bytesKey(x);
|
|
347
|
+
return xb !== undefined && xb === bytesKey(y);
|
|
348
|
+
}
|
|
349
|
+
case "BS":
|
|
350
|
+
return Array.isArray(x) && Array.isArray(y) && sameSet(x.map(bytesKey), y.map(bytesKey));
|
|
351
|
+
default:
|
|
352
|
+
return x === y;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
// compareStored
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
const COMPARE = {
|
|
359
|
+
entityType: "Offload",
|
|
360
|
+
operation: "Offload.compareStored",
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* What a change did to one offloaded field, from the stored attribute values
|
|
364
|
+
* of its old and new images (DynamoDB JSON, `B` as bytes or base64 text;
|
|
365
|
+
* `undefined` when the image has no such attribute) — see
|
|
366
|
+
* {@link OffloadChange}. `kind` is the field's: `"overflow"`
|
|
367
|
+
* (`Packed({ external })`) or `"binary"` (`External`). Never touches the blob
|
|
368
|
+
* store; an inline compressed value is decompressed with the `Compression`
|
|
369
|
+
* service in scope to checksum its content (without the codec: a
|
|
370
|
+
* `ValidationError` whose `cause` is a `CompressorNotRegistered`). A value
|
|
371
|
+
* that is not a stored form of `kind` (a malformed pointer, an `S` value on a
|
|
372
|
+
* binary attribute that is not a pointer, a binary field's `~edbp:` text on
|
|
373
|
+
* an overflow attribute) fails with a `ValidationError`.
|
|
374
|
+
*/
|
|
375
|
+
export const compareStored = (oldValue, newValue, kind) => Effect.withFiber((fiber) => {
|
|
376
|
+
if (kind !== "overflow" && kind !== "binary") {
|
|
377
|
+
return Effect.fail(new ValidationError({
|
|
378
|
+
...COMPARE,
|
|
379
|
+
cause: new Error(`compareStored: kind must be "overflow" or "binary", got ${describe(kind)}`),
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
const registry = Context.getOrUndefined(fiber.context, Compression) ?? emptyRegistry;
|
|
383
|
+
const before = formOfAttributeValue(oldValue, kind, registry, COMPARE, "old value");
|
|
384
|
+
if (before instanceof ValidationError)
|
|
385
|
+
return Effect.fail(before);
|
|
386
|
+
const after = formOfAttributeValue(newValue, kind, registry, COMPARE, "new value");
|
|
387
|
+
if (after instanceof ValidationError)
|
|
388
|
+
return Effect.fail(after);
|
|
389
|
+
return Effect.succeed(compareForms(before, after));
|
|
390
|
+
});
|
|
391
|
+
//# sourceMappingURL=OffloadChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OffloadChange.js","sourceRoot":"","sources":["../../src/internal/OffloadChange.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EACL,WAAW,EAEX,KAAK,IAAI,aAAa,GACvB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAEL,aAAa,EACb,aAAa,GACd,MAAM,iDAAiD,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AACzE,OAAO,EACL,kBAAkB,EAElB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,iDAAiD,CAAA;AACx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EAC1C,QAA0C,EAC1C,IAAiB,EAC8B,EAAE,CACjD,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;IACzB,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,MAAM,CAAC,IAAI,CAChB,IAAI,eAAe,CAAC;YAClB,GAAG,OAAO;YACV,KAAK,EAAE,IAAI,KAAK,CACd,2DAA2D,QAAQ,CAAC,IAAI,CAAC,EAAE,CAC5E;SACF,CAAC,CACH,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GACZ,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,OAAiC,EAAE,WAAW,CAAC,IAAI,aAAa,CAAA;IAC/F,MAAM,MAAM,GAAG,oBAAoB,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;IACnF,IAAI,MAAM,YAAY,eAAe;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACjE,MAAM,KAAK,GAAG,oBAAoB,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;IAClF,IAAI,KAAK,YAAY,eAAe;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/D,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;AACpD,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Write inputs of binary fields (#179, design §3.8, §7): what a
|
|
3
|
+
* `DynamoModel.External()` field takes on a write — a `Uint8Array`, a
|
|
4
|
+
* `Stream` of bytes, a `BlobHandle` (content to copy) or `Offload.source(...)`
|
|
5
|
+
* (bytes or a stream with upload options) — and how a write carries each one
|
|
6
|
+
* from its input to its upload.
|
|
7
|
+
*
|
|
8
|
+
* - **Placeholders.** Schema encoding, renames and request building handle a
|
|
9
|
+
* binary field's value as a `Uint8Array`. So {@link prepare} replaces every
|
|
10
|
+
* input that is not one with a fresh `Uint8Array` **placeholder**,
|
|
11
|
+
* registered (by identity) with what it stands for; the write path carries
|
|
12
|
+
* the placeholder to `OffloadWrite.route`, which uploads what it stands for
|
|
13
|
+
* ({@link preparedOf}). The bytes of an `Offload.source(bytes)` are the
|
|
14
|
+
* placeholder's own content (a copy), so the field's schema checks them
|
|
15
|
+
* like any other bytes; a stream's or a handle's placeholder is empty and
|
|
16
|
+
* **opaque** — the write path skips the field's schema for it
|
|
17
|
+
* ({@link opaqueFields}), as its content is not in hand before the upload.
|
|
18
|
+
* - **Single-use streams.** A placeholder stands for its stream; the upload
|
|
19
|
+
* ledger runs a given stream at most once, for one target object
|
|
20
|
+
* (`BlobLedger`, `[EDD-9120]`).
|
|
21
|
+
* - **Refusals.** {@link prepare} refuses, as a `ValidationError` naming
|
|
22
|
+
* `[EDD-9120]`, an input of the wrong shape for a binary field and a
|
|
23
|
+
* stream, handle, source or lazy value for an overflow field (which takes
|
|
24
|
+
* its domain value) — reachable only from untyped code.
|
|
25
|
+
*
|
|
26
|
+
* `prepare` is idempotent: a placeholder is kept as it is, so a write path
|
|
27
|
+
* that hands its prepared input to another (a guarded upsert's create, an
|
|
28
|
+
* update that creates its missing item) prepares nothing twice.
|
|
29
|
+
*
|
|
30
|
+
* Not part of the public API (`Offload.source`, `BinaryInput` and
|
|
31
|
+
* `BlobSource` are).
|
|
32
|
+
*/
|
|
33
|
+
import { ValidationError } from "@effect-dynamodb/schema/Errors.js";
|
|
34
|
+
import { Effect, Inspectable, Pipeable, Stream } from "effect";
|
|
35
|
+
import { type BlobHandle } from "./OffloadValues.js";
|
|
36
|
+
export declare const BlobSourceTypeId: unique symbol;
|
|
37
|
+
export type BlobSourceTypeId = typeof BlobSourceTypeId;
|
|
38
|
+
/** Upload options of one binary value ({@link source}). */
|
|
39
|
+
export interface BlobSourceOptions {
|
|
40
|
+
/**
|
|
41
|
+
* The object's `Content-Type` (and the pointer's): non-empty printable
|
|
42
|
+
* US-ASCII (no control character, which no HTTP header carries), at most
|
|
43
|
+
* 255 bytes. Default: the field's `External({ contentType })`.
|
|
44
|
+
*/
|
|
45
|
+
readonly contentType?: string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The body's length in bytes, when known before it is consumed: a stream
|
|
48
|
+
* that gives more or fewer bytes fails the write (`SourceFailed`). A store
|
|
49
|
+
* may use it to plan the upload (the S3 store raises its part size for a
|
|
50
|
+
* long one).
|
|
51
|
+
*/
|
|
52
|
+
readonly contentLength?: number | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** A binary value with upload options: {@link source}. */
|
|
55
|
+
export interface BlobSource extends Pipeable.Pipeable, Inspectable.Inspectable {
|
|
56
|
+
readonly [BlobSourceTypeId]: BlobSourceTypeId;
|
|
57
|
+
readonly body: Uint8Array | Stream.Stream<Uint8Array, unknown, never>;
|
|
58
|
+
readonly contentType: string | undefined;
|
|
59
|
+
readonly contentLength: number | undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What a binary field (`DynamoModel.External()`) takes on a write:
|
|
63
|
+
*
|
|
64
|
+
* - a `Uint8Array` — the bytes;
|
|
65
|
+
* - a `Stream` of byte chunks — **single-use**: the library runs it at most
|
|
66
|
+
* once, for one target object (a second field, item or operation given the
|
|
67
|
+
* same `Stream` value fails with `[EDD-9120]`); a failure of the stream
|
|
68
|
+
* fails the write with `BlobStoreError { reason: "SourceFailed" }`;
|
|
69
|
+
* - a `BlobHandle` (a binary field read lazily) — content to **copy**: the
|
|
70
|
+
* write stores a new version under this item's key, never shares the
|
|
71
|
+
* handle's;
|
|
72
|
+
* - {@link source}`(bytes | stream, { contentType, contentLength })`.
|
|
73
|
+
*/
|
|
74
|
+
export type BinaryInput = Uint8Array | Stream.Stream<Uint8Array, unknown, never> | BlobHandle | BlobSource;
|
|
75
|
+
/**
|
|
76
|
+
* A binary field's value with upload options: its bytes or a stream of them,
|
|
77
|
+
* the object's content type, and the body's length when known. The options
|
|
78
|
+
* are checked when the write runs (`[EDD-9120]`).
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* db.entities.Documents.put({
|
|
83
|
+
* id,
|
|
84
|
+
* owner,
|
|
85
|
+
* scan: Offload.source(fileStream, { contentType: "image/png", contentLength: size }),
|
|
86
|
+
* })
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare const source: (body: Uint8Array | Stream.Stream<Uint8Array, unknown, never>, options?: BlobSourceOptions) => BlobSource;
|
|
90
|
+
/** True iff `u` is a {@link BlobSource}. */
|
|
91
|
+
export declare const isBlobSource: (u: unknown) => u is BlobSource;
|
|
92
|
+
/** What a placeholder stands for. */
|
|
93
|
+
export type Prepared =
|
|
94
|
+
/** `Offload.source(bytes)`: the placeholder holds (a copy of) the bytes. */
|
|
95
|
+
{
|
|
96
|
+
readonly _tag: "Bytes";
|
|
97
|
+
readonly contentType: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
/** A stream (or `Offload.source(stream)`): `identity` is the caller's `Stream` value. */
|
|
100
|
+
| {
|
|
101
|
+
readonly _tag: "Stream";
|
|
102
|
+
readonly stream: Stream.Stream<Uint8Array, unknown>;
|
|
103
|
+
readonly identity: object;
|
|
104
|
+
readonly contentType: string | undefined;
|
|
105
|
+
readonly contentLength: number | undefined;
|
|
106
|
+
}
|
|
107
|
+
/** A handle: content to copy. */
|
|
108
|
+
| {
|
|
109
|
+
readonly _tag: "Handle";
|
|
110
|
+
readonly handle: BlobHandle;
|
|
111
|
+
};
|
|
112
|
+
/** What `value` stands for, when it is a placeholder {@link prepare} made. */
|
|
113
|
+
export declare const preparedOf: (value: unknown) => Prepared | undefined;
|
|
114
|
+
/** True iff `value` is an opaque placeholder (a stream's or a handle's). */
|
|
115
|
+
export declare const isOpaque: (value: unknown) => boolean;
|
|
116
|
+
/** A member's offloaded fields, by domain name. */
|
|
117
|
+
export interface InputFields {
|
|
118
|
+
readonly entityType: string;
|
|
119
|
+
/** Binary (`External`) fields. */
|
|
120
|
+
readonly binary: ReadonlyArray<string>;
|
|
121
|
+
/** Overflow (`Packed({ external })`) fields. */
|
|
122
|
+
readonly overflow: ReadonlyArray<string>;
|
|
123
|
+
}
|
|
124
|
+
/** The `[EDD-9120]` refusal of an offloaded field's write input. */
|
|
125
|
+
export declare const unusable: (entityType: string, operation: string, message: string) => ValidationError;
|
|
126
|
+
/**
|
|
127
|
+
* Replace every binary input of `record` that is not a `Uint8Array` with its
|
|
128
|
+
* placeholder, and refuse an unusable one (`[EDD-9120]`). `record` itself
|
|
129
|
+
* when nothing is replaced (a class instance keeps its prototype); a shallow
|
|
130
|
+
* copy otherwise.
|
|
131
|
+
*/
|
|
132
|
+
export declare const prepare: (record: unknown, fields: InputFields, operation: string) => Effect.Effect<unknown, ValidationError>;
|
|
133
|
+
/** The fields of `record` among `binary` that hold an opaque placeholder. */
|
|
134
|
+
export declare const opaqueFields: (record: unknown, binary: ReadonlyArray<string>) => Array<string>;
|
|
135
|
+
/**
|
|
136
|
+
* `encoded` (the schema encoding of a prepared `input`) with each
|
|
137
|
+
* `Offload.source(bytes)` placeholder's upload options kept on its encoded
|
|
138
|
+
* bytes, when the field's schema gave a new array for them.
|
|
139
|
+
*/
|
|
140
|
+
export declare const carry: (input: unknown, encoded: unknown, binary: ReadonlyArray<string>) => unknown;
|
|
141
|
+
//# sourceMappingURL=OffloadInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OffloadInput.d.ts","sourceRoot":"","sources":["../../src/internal/OffloadInput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,M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