@logbrew/sdk 0.1.20 → 0.1.21
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/core.cjs +16 -7
- package/package.json +1 -1
package/core.cjs
CHANGED
|
@@ -1212,19 +1212,28 @@ function normalizeStoredRecord(record) {
|
|
|
1212
1212
|
if (!event.attributes || Array.isArray(event.attributes) || typeof event.attributes !== "object") {
|
|
1213
1213
|
throw invalidStoredRecord();
|
|
1214
1214
|
}
|
|
1215
|
+
if (JSON.stringify(event) !== serializedEvent || utf8ByteLength(serializedEvent) !== eventBytes) {
|
|
1216
|
+
throw invalidStoredRecord();
|
|
1217
|
+
}
|
|
1218
|
+
const context = event.attributes.context;
|
|
1219
|
+
const recoveredEvent = context && !Array.isArray(context) && typeof context === "object"
|
|
1220
|
+
&& context.schemaVersion === undefined
|
|
1221
|
+
? { ...event, attributes: { ...event.attributes, context: { schemaVersion: 1, ...context } } }
|
|
1222
|
+
: event;
|
|
1215
1223
|
const normalizedEvent = {
|
|
1216
|
-
type:
|
|
1217
|
-
id:
|
|
1218
|
-
timestamp:
|
|
1219
|
-
attributes: validator(
|
|
1224
|
+
type: recoveredEvent.type,
|
|
1225
|
+
id: recoveredEvent.id,
|
|
1226
|
+
timestamp: recoveredEvent.timestamp,
|
|
1227
|
+
attributes: validator(recoveredEvent.attributes)
|
|
1220
1228
|
};
|
|
1221
|
-
|
|
1229
|
+
const normalizedSerializedEvent = JSON.stringify(normalizedEvent);
|
|
1230
|
+
if (normalizedSerializedEvent !== JSON.stringify(recoveredEvent)) {
|
|
1222
1231
|
throw invalidStoredRecord();
|
|
1223
1232
|
}
|
|
1224
1233
|
return {
|
|
1225
1234
|
event: cloneEvent(normalizedEvent),
|
|
1226
|
-
eventBytes,
|
|
1227
|
-
serializedEvent
|
|
1235
|
+
eventBytes: utf8ByteLength(normalizedSerializedEvent),
|
|
1236
|
+
serializedEvent: normalizedSerializedEvent
|
|
1228
1237
|
};
|
|
1229
1238
|
} catch (error) {
|
|
1230
1239
|
if (error instanceof SdkError && error.code === "persistence_error") {
|