@ossy/event-store 3.0.8 → 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/event-store",
3
- "version": "3.0.8",
3
+ "version": "3.2.0",
4
4
  "description": "Ossy Event Store — Aggregate, EventStore, and MongoDB client",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,8 +25,8 @@
25
25
  "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@ossy/fold": "^3.0.8",
29
- "@ossy/observability": "^3.0.8",
28
+ "@ossy/fold": "^3.0.9",
29
+ "@ossy/observability": "^3.0.9",
30
30
  "mongodb": "^7.2.0",
31
31
  "nanoid": "^5.1.11"
32
32
  },
@@ -37,5 +37,5 @@
37
37
  "files": [
38
38
  "src"
39
39
  ],
40
- "gitHead": "980b380c9dee0de78ef3ebabe86efcec1c223a9a"
40
+ "gitHead": "b045f1fd7f2fe00c776b9ea96f76083b93fd8556"
41
41
  }
@@ -62,7 +62,16 @@ export class SchemaStream {
62
62
 
63
63
  const latestVersion = stream.events[stream.events.length - 1]?.version ?? stream.version
64
64
  const state = stream.AggregateRoot.View(stream.events, stream.state)
65
- const schemaId = state.type ?? stream.events[0]?.type ?? stream.AggregateRoot.SchemaId
65
+ // Prefer SchemaId — `state.type` is often a domain subtype (e.g. User.Created payload.type = 'User'),
66
+ // not the aggregate schema id used for Collection lookups.
67
+ const schemaId = stream.AggregateRoot.SchemaId
68
+ ?? stream.events.find((e) => e?.type)?.type
69
+
70
+ if (!schemaId) {
71
+ return Promise.reject(new Error(
72
+ `[SchemaStream] save failed for ${stream.id}: missing SchemaId`,
73
+ ))
74
+ }
66
75
 
67
76
  return withMongoReconnect(() =>
68
77
  SchemaStream.Collection.updateOne(