@kronos-ts/eventsourcing 0.2.2 → 0.3.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/schedule.d.ts.map +1 -1
- package/dist/schedule.js +18 -3
- package/dist/schedule.js.map +1 -1
- package/package.json +4 -4
- package/src/schedule.ts +20 -3
package/dist/schedule.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,QAAQ,EAAe,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGnH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,sBAAsB,CAAA;AAE7B;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,cAAc,CAAiC,CAAA;AAE7F,iEAAiE;AACjE,MAAM,WAAW,gBAAgB;IAC/B,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IACvG,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAClB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EACnB,EAAE,EAAE,IAAI,EACR,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,aAAa,CAAC,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,EAAE,gBA8CD,CAAA;AAEtB,uEAAuE;AACvE,MAAM,WAAW,qBAAqB;IACpC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAC9G,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAClB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,aAAa,CAAC,CAAA;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,qBAaD,CAAA;AAE3B;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAU,OAAO,aAAa,KAAG,OAAO,CAAC,YAAY,CAK/E,CAAA"}
|
package/dist/schedule.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { generateIdentifier, resourceKey } from "@kronos-ts/common";
|
|
2
|
-
import { requireInvocationPhase } from "@kronos-ts/messaging/processing-state";
|
|
1
|
+
import { generateIdentifier, mergeMetadata, resourceKey } from "@kronos-ts/common";
|
|
2
|
+
import { getResource, requireInvocationPhase } from "@kronos-ts/messaging/processing-state";
|
|
3
|
+
import { CORRELATION_DATA_KEY } from "@kronos-ts/messaging/correlation-data";
|
|
3
4
|
/**
|
|
4
5
|
* Resource key for the event scheduler component.
|
|
5
6
|
* Written by handling modules + processors at handler-invocation entry,
|
|
@@ -37,13 +38,27 @@ export const schedule = (async (event, payload, at, metadata) => {
|
|
|
37
38
|
if (!(at instanceof Date) || Number.isNaN(at.getTime())) {
|
|
38
39
|
throw new Error(`schedule: \`at\` must be a valid Date, received ${String(at)}`);
|
|
39
40
|
}
|
|
41
|
+
// Capture the active UnitOfWork's correlation data onto the scheduled event
|
|
42
|
+
// at schedule-time — mirroring append(). Correlation/causation lineage lives
|
|
43
|
+
// in the CORRELATION_DATA_KEY resource (written by the correlation handler
|
|
44
|
+
// interceptor), NOT in state.metadata, so capturing only the UoW metadata
|
|
45
|
+
// would drop it. There is no originating UoW to read from when the event
|
|
46
|
+
// later fires (timer / worker tick), so schedule-time is the only point where
|
|
47
|
+
// this lineage is available. The causationId becomes the message that
|
|
48
|
+
// scheduled the event, which is exactly "what caused" the fired event.
|
|
49
|
+
// No-op when no correlation data is set.
|
|
50
|
+
const baseMetadata = metadata ?? state.metadata;
|
|
51
|
+
const correlationData = getResource(CORRELATION_DATA_KEY);
|
|
52
|
+
const eventMetadata = correlationData && Object.keys(correlationData).length > 0
|
|
53
|
+
? mergeMetadata(baseMetadata, correlationData)
|
|
54
|
+
: baseMetadata;
|
|
40
55
|
const eventMessage = {
|
|
41
56
|
kind: "event",
|
|
42
57
|
identifier: generateIdentifier(),
|
|
43
58
|
name: event.name,
|
|
44
59
|
version: event.version,
|
|
45
60
|
payload,
|
|
46
|
-
metadata:
|
|
61
|
+
metadata: eventMetadata,
|
|
47
62
|
timestamp: Date.now(),
|
|
48
63
|
tags: event.tags ? event.tags(payload) : [],
|
|
49
64
|
};
|
package/dist/schedule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.js","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAiB,WAAW,EAAoB,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"schedule.js","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAiB,WAAW,EAAoB,MAAM,mBAAmB,CAAA;AACnH,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AA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AAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;IAChE,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-ts/eventsourcing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Event sourcing for Kronos — dynamic-consistency-boundary event store with load/append.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@kronos-ts/common": "0.1.1",
|
|
51
|
-
"@kronos-ts/messaging": "0.
|
|
52
|
-
"@kronos-ts/modelling": "0.2.
|
|
51
|
+
"@kronos-ts/messaging": "0.8.0",
|
|
52
|
+
"@kronos-ts/modelling": "0.2.7",
|
|
53
53
|
"zod": "^4.3.6"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@kronos-ts/app": "0.
|
|
56
|
+
"@kronos-ts/app": "0.5.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/schedule.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { generateIdentifier, type Metadata, resourceKey, type ResourceKey } from "@kronos-ts/common"
|
|
2
|
-
import { requireInvocationPhase } from "@kronos-ts/messaging/processing-state"
|
|
1
|
+
import { generateIdentifier, mergeMetadata, type Metadata, resourceKey, type ResourceKey } from "@kronos-ts/common"
|
|
2
|
+
import { getResource, requireInvocationPhase } from "@kronos-ts/messaging/processing-state"
|
|
3
|
+
import { CORRELATION_DATA_KEY } from "@kronos-ts/messaging/correlation-data"
|
|
3
4
|
import type { z } from "zod"
|
|
4
5
|
import type {
|
|
5
6
|
EventDescriptor,
|
|
@@ -64,13 +65,29 @@ export const schedule: ScheduleFunction = (async <P extends z.ZodType>(
|
|
|
64
65
|
throw new Error(`schedule: \`at\` must be a valid Date, received ${String(at)}`)
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
// Capture the active UnitOfWork's correlation data onto the scheduled event
|
|
69
|
+
// at schedule-time — mirroring append(). Correlation/causation lineage lives
|
|
70
|
+
// in the CORRELATION_DATA_KEY resource (written by the correlation handler
|
|
71
|
+
// interceptor), NOT in state.metadata, so capturing only the UoW metadata
|
|
72
|
+
// would drop it. There is no originating UoW to read from when the event
|
|
73
|
+
// later fires (timer / worker tick), so schedule-time is the only point where
|
|
74
|
+
// this lineage is available. The causationId becomes the message that
|
|
75
|
+
// scheduled the event, which is exactly "what caused" the fired event.
|
|
76
|
+
// No-op when no correlation data is set.
|
|
77
|
+
const baseMetadata = metadata ?? state.metadata
|
|
78
|
+
const correlationData = getResource(CORRELATION_DATA_KEY)
|
|
79
|
+
const eventMetadata =
|
|
80
|
+
correlationData && Object.keys(correlationData).length > 0
|
|
81
|
+
? mergeMetadata(baseMetadata, correlationData)
|
|
82
|
+
: baseMetadata
|
|
83
|
+
|
|
67
84
|
const eventMessage: EventMessage = {
|
|
68
85
|
kind: "event",
|
|
69
86
|
identifier: generateIdentifier(),
|
|
70
87
|
name: event.name,
|
|
71
88
|
version: event.version,
|
|
72
89
|
payload,
|
|
73
|
-
metadata:
|
|
90
|
+
metadata: eventMetadata,
|
|
74
91
|
timestamp: Date.now(),
|
|
75
92
|
tags: event.tags ? event.tags(payload) : [],
|
|
76
93
|
}
|