@sekiban/dcb-runtime 0.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/LICENSE +86 -0
- package/README.md +13 -0
- package/dist/allocator/AllocatorDurableObject.d.ts +36 -0
- package/dist/allocator/AllocatorDurableObject.js +658 -0
- package/dist/allocator/IssuanceLedger.d.ts +188 -0
- package/dist/allocator/IssuanceLedger.js +608 -0
- package/dist/allocator/IssuanceReconciler.d.ts +41 -0
- package/dist/allocator/IssuanceReconciler.js +191 -0
- package/dist/allocator/OrderClock.d.ts +41 -0
- package/dist/allocator/OrderClock.js +92 -0
- package/dist/allocator/SortableUniqueId.d.ts +46 -0
- package/dist/allocator/SortableUniqueId.js +156 -0
- package/dist/allocator/types.d.ts +52 -0
- package/dist/allocator/types.js +1 -0
- package/dist/bootstrap/BootstrapCoordinatorDurableObject.d.ts +28 -0
- package/dist/bootstrap/BootstrapCoordinatorDurableObject.js +357 -0
- package/dist/bootstrap/BootstrapStoreAdapter.d.ts +51 -0
- package/dist/bootstrap/BootstrapStoreAdapter.js +162 -0
- package/dist/bootstrap/OperatorBootstrap.d.ts +20 -0
- package/dist/bootstrap/OperatorBootstrap.js +104 -0
- package/dist/bootstrap/manifest.d.ts +9 -0
- package/dist/bootstrap/manifest.js +115 -0
- package/dist/bootstrap/types.d.ts +75 -0
- package/dist/bootstrap/types.js +1 -0
- package/dist/cli/OperatorRepairCli.d.ts +11 -0
- package/dist/cli/OperatorRepairCli.js +108 -0
- package/dist/cloudflare.d.ts +164 -0
- package/dist/cloudflare.js +19487 -0
- package/dist/commit/CommitWorker.d.ts +101 -0
- package/dist/commit/CommitWorker.js +921 -0
- package/dist/commit/types.d.ts +25 -0
- package/dist/commit/types.js +13 -0
- package/dist/completeness/GlobalCompletenessReconciler.d.ts +77 -0
- package/dist/completeness/GlobalCompletenessReconciler.js +572 -0
- package/dist/completeness/types.d.ts +85 -0
- package/dist/completeness/types.js +6 -0
- package/dist/composition.d.ts +123 -0
- package/dist/composition.js +237 -0
- package/dist/cosmos.d.ts +11 -0
- package/dist/cosmos.js +1411 -0
- package/dist/d1-mv.d.ts +8 -0
- package/dist/d1-mv.js +2001 -0
- package/dist/d1.d.ts +16 -0
- package/dist/d1.js +3418 -0
- package/dist/diagnostics/G60DurableHop.d.ts +99 -0
- package/dist/diagnostics/G60DurableHop.js +248 -0
- package/dist/diagnostics/G65Admission.d.ts +23 -0
- package/dist/diagnostics/G65Admission.js +43 -0
- package/dist/diagnostics/G65DirectRing.d.ts +33 -0
- package/dist/diagnostics/G65DirectRing.js +85 -0
- package/dist/diagnostics/G69AdmissionAttempt.d.ts +43 -0
- package/dist/diagnostics/G69AdmissionAttempt.js +22 -0
- package/dist/downstream/DeliveryCore.d.ts +127 -0
- package/dist/downstream/DeliveryCore.js +304 -0
- package/dist/downstream/Doorbell.d.ts +43 -0
- package/dist/downstream/Doorbell.js +137 -0
- package/dist/downstream/DownstreamAdapter.d.ts +52 -0
- package/dist/downstream/DownstreamAdapter.js +299 -0
- package/dist/downstream/ExclusionLookup.d.ts +36 -0
- package/dist/downstream/ExclusionLookup.js +50 -0
- package/dist/downstream/InconsistencyDetector.d.ts +27 -0
- package/dist/downstream/InconsistencyDetector.js +82 -0
- package/dist/downstream/OutboxDrain.d.ts +35 -0
- package/dist/downstream/OutboxDrain.js +126 -0
- package/dist/downstream/types.d.ts +77 -0
- package/dist/downstream/types.js +64 -0
- package/dist/eventIdentity.d.ts +30 -0
- package/dist/eventIdentity.js +49 -0
- package/dist/eventRecord.d.ts +26 -0
- package/dist/eventRecord.js +53 -0
- package/dist/g42-probe.d.ts +9 -0
- package/dist/g42-probe.js +9 -0
- package/dist/http/SerializedQueryWorker.d.ts +58 -0
- package/dist/http/SerializedQueryWorker.js +497 -0
- package/dist/http/commitResponse.d.ts +46 -0
- package/dist/http/commitResponse.js +80 -0
- package/dist/http/testServiceId.d.ts +17 -0
- package/dist/http/testServiceId.js +14 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +19926 -0
- package/dist/journal/JournalDurableObject.d.ts +30 -0
- package/dist/journal/JournalDurableObject.js +481 -0
- package/dist/journal/JournalFirstTouchProbe.d.ts +190 -0
- package/dist/journal/JournalFirstTouchProbe.js +375 -0
- package/dist/journal/types.d.ts +116 -0
- package/dist/journal/types.js +52 -0
- package/dist/mv/MaterializedViewCatchUp.d.ts +60 -0
- package/dist/mv/MaterializedViewCatchUp.js +353 -0
- package/dist/mv/MaterializedViewRuntime.d.ts +80 -0
- package/dist/mv/MaterializedViewRuntime.js +328 -0
- package/dist/mv/MaterializedViewStore.d.ts +257 -0
- package/dist/mv/MaterializedViewStore.js +875 -0
- package/dist/mv/UnsafeWindowMaterializedView.d.ts +112 -0
- package/dist/mv/UnsafeWindowMaterializedView.js +495 -0
- package/dist/mv/index.d.ts +8 -0
- package/dist/mv/index.js +2357 -0
- package/dist/projection/LiveProjectionWorker.d.ts +86 -0
- package/dist/projection/LiveProjectionWorker.js +240 -0
- package/dist/projection/ProjectionRuntime.d.ts +113 -0
- package/dist/projection/ProjectionRuntime.js +346 -0
- package/dist/projection/ProjectorRegistry.d.ts +51 -0
- package/dist/projection/ProjectorRegistry.js +116 -0
- package/dist/query/ProjectionQueryStore.d.ts +102 -0
- package/dist/query/ProjectionQueryStore.js +185 -0
- package/dist/query/QueryRegistry.d.ts +22 -0
- package/dist/query/QueryRegistry.js +36 -0
- package/dist/read/SerializedReadWorker.d.ts +36 -0
- package/dist/read/SerializedReadWorker.js +225 -0
- package/dist/repair/RepairWorker.d.ts +72 -0
- package/dist/repair/RepairWorker.js +461 -0
- package/dist/safeWindow.d.ts +20 -0
- package/dist/safeWindow.js +36 -0
- package/dist/scope/ControlRouteScope.d.ts +22 -0
- package/dist/scope/ControlRouteScope.js +36 -0
- package/dist/scope/ScopeName.d.ts +34 -0
- package/dist/scope/ScopeName.js +67 -0
- package/dist/service/ServiceIdentityProvider.d.ts +35 -0
- package/dist/service/ServiceIdentityProvider.js +56 -0
- package/dist/store/CosmosEventStore.d.ts +126 -0
- package/dist/store/CosmosEventStore.js +950 -0
- package/dist/store/D1EventStore.d.ts +111 -0
- package/dist/store/D1EventStore.js +1111 -0
- package/dist/store/PostgresEventStore.d.ts +35 -0
- package/dist/store/PostgresEventStore.js +811 -0
- package/dist/store/provider.d.ts +25 -0
- package/dist/store/provider.js +32 -0
- package/dist/store/types.d.ts +205 -0
- package/dist/store/types.js +18 -0
- package/dist/tag/EventDigest.d.ts +40 -0
- package/dist/tag/EventDigest.js +158 -0
- package/dist/tag/TagDurableObject.d.ts +286 -0
- package/dist/tag/TagDurableObject.js +4071 -0
- package/dist/tag/TagSqlMeasurement.d.ts +26 -0
- package/dist/tag/TagSqlMeasurement.js +44 -0
- package/dist/tag/TagSqlSchema.d.ts +29 -0
- package/dist/tag/TagSqlSchema.js +211 -0
- package/dist/tag/types.d.ts +173 -0
- package/dist/tag/types.js +3 -0
- package/dist/tagstate/TagStateDurableObject.d.ts +57 -0
- package/dist/tagstate/TagStateDurableObject.js +499 -0
- package/dist/trace/AttributionRatio.d.ts +12 -0
- package/dist/trace/AttributionRatio.js +68 -0
- package/dist/trace/CloudflareTracing.d.ts +7 -0
- package/dist/trace/CloudflareTracing.js +9 -0
- package/dist/trace/CommitTrace.d.ts +405 -0
- package/dist/trace/CommitTrace.js +1008 -0
- package/dist/trace/CommitTraceConsoleSink.d.ts +68 -0
- package/dist/trace/CommitTraceConsoleSink.js +114 -0
- package/dist/trace/CommitTraceVerifier.d.ts +22 -0
- package/dist/trace/CommitTraceVerifier.js +295 -0
- package/dist/trace/ObservationStream.d.ts +118 -0
- package/dist/trace/ObservationStream.js +148 -0
- package/package.json +71 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Separate Workers Logs observation stream for SDT-G30.
|
|
3
|
+
*
|
|
4
|
+
* This deliberately is not a CommitTrace span and never adds an attribute to
|
|
5
|
+
* the sealed sdt.commit/v1 matrix. Structured console events carry provider
|
|
6
|
+
* request metadata but Workers Logs does not expose a trace id for them. The
|
|
7
|
+
* exporter joins existing post-admission/attempt correlation to S00 and fails
|
|
8
|
+
* closed when that chain or the client-ledger identity is absent.
|
|
9
|
+
*
|
|
10
|
+
* The stream is observation-only: it does not write Durable Object storage,
|
|
11
|
+
* decide a control branch, or contribute to a public response.
|
|
12
|
+
*/
|
|
13
|
+
import { correlationIdForAttempt, } from "./CommitTrace";
|
|
14
|
+
export const OBSERVATION_SCHEMA = "sdt.observe/v1";
|
|
15
|
+
const consoleSink = Object.freeze({
|
|
16
|
+
emit(event) {
|
|
17
|
+
// Workers Logs indexes object members directly. The platform supplies
|
|
18
|
+
// the request/trace metadata; application code has no public trace-id API
|
|
19
|
+
// and must not introduce a propagation header just for attribution.
|
|
20
|
+
console.log(event);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
function now() {
|
|
24
|
+
return Date.now();
|
|
25
|
+
}
|
|
26
|
+
function nonNegativeElapsed(startedAtMs) {
|
|
27
|
+
return Math.max(0, now() - startedAtMs);
|
|
28
|
+
}
|
|
29
|
+
/** A log transport failure is itself non-semantic. */
|
|
30
|
+
export function emitObservation(event, sink = consoleSink) {
|
|
31
|
+
try {
|
|
32
|
+
sink.emit(event);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// G30 observes an existing commit; logging can never replace its result.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function observeWorkerInvocation(input, sink) {
|
|
39
|
+
// A missing ingress identity cannot affect a commit. The B0 exporter fails
|
|
40
|
+
// closed later if an accepted request does not have this observation.
|
|
41
|
+
if (input.requestId.length === 0 || input.correlationId.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
emitObservation(Object.freeze({
|
|
44
|
+
schema: OBSERVATION_SCHEMA,
|
|
45
|
+
event: "worker.invocation",
|
|
46
|
+
emittedAtMs: now(),
|
|
47
|
+
requestId: input.requestId,
|
|
48
|
+
correlationId: input.correlationId,
|
|
49
|
+
actorClass: "WORKER",
|
|
50
|
+
emittedWorkerRowIds: Object.freeze([...input.emittedWorkerRowIds]),
|
|
51
|
+
isolateInstanceId: input.isolateInstanceId,
|
|
52
|
+
activationFirst: input.firstInvocation,
|
|
53
|
+
...(typeof input.scriptVersion === "string" && input.scriptVersion.length > 0 ? { scriptVersion: input.scriptVersion } : {}),
|
|
54
|
+
...(typeof input.colo === "string" && input.colo.length > 0 ? { colo: input.colo } : {}),
|
|
55
|
+
storageWrites: 0,
|
|
56
|
+
usedForControl: false,
|
|
57
|
+
exposedInPublicResponse: false,
|
|
58
|
+
}), sink);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* One handler-local stopwatch. It is created after the constructor-derived
|
|
62
|
+
* activation fact and is passed explicitly; there is no module/global
|
|
63
|
+
* request state and no durable persistence.
|
|
64
|
+
*/
|
|
65
|
+
export class DurableObjectHandlerObservation {
|
|
66
|
+
actorClass;
|
|
67
|
+
activation;
|
|
68
|
+
sink;
|
|
69
|
+
firstStorageReadMs;
|
|
70
|
+
subrequestWallMs = 0;
|
|
71
|
+
observedSubrequest = false;
|
|
72
|
+
finished = false;
|
|
73
|
+
correlationId;
|
|
74
|
+
constructor(actorClass, activation, sink) {
|
|
75
|
+
this.actorClass = actorClass;
|
|
76
|
+
this.activation = activation;
|
|
77
|
+
this.sink = sink;
|
|
78
|
+
}
|
|
79
|
+
/** Call immediately before the first durable read/transaction starts. */
|
|
80
|
+
markFirstStorageRead() {
|
|
81
|
+
if (this.firstStorageReadMs !== undefined)
|
|
82
|
+
return;
|
|
83
|
+
this.firstStorageReadMs = nonNegativeElapsed(this.activation.handlerStartedAtMs);
|
|
84
|
+
}
|
|
85
|
+
/** Measures an actual awaited subrequest, never a declared duration. */
|
|
86
|
+
async subrequest(callback) {
|
|
87
|
+
const startedAtMs = now();
|
|
88
|
+
this.observedSubrequest = true;
|
|
89
|
+
try {
|
|
90
|
+
return await callback();
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
this.subrequestWallMs += nonNegativeElapsed(startedAtMs);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Actor identity is decoded from the existing body before the callback.
|
|
98
|
+
* Retaining its established trace correlation in the log avoids a new
|
|
99
|
+
* propagation header, durable write, or public response field.
|
|
100
|
+
*/
|
|
101
|
+
bindCorrelation(correlationId) {
|
|
102
|
+
if (typeof correlationId === "string" && correlationId.length > 0)
|
|
103
|
+
this.correlationId = correlationId;
|
|
104
|
+
}
|
|
105
|
+
/** Emits at most once and only after the native actor callback settles. */
|
|
106
|
+
finish() {
|
|
107
|
+
if (this.finished)
|
|
108
|
+
return;
|
|
109
|
+
this.finished = true;
|
|
110
|
+
emitObservation(Object.freeze({
|
|
111
|
+
schema: OBSERVATION_SCHEMA,
|
|
112
|
+
event: "do.handler",
|
|
113
|
+
emittedAtMs: now(),
|
|
114
|
+
...(this.correlationId === undefined ? {} : { correlationId: this.correlationId }),
|
|
115
|
+
actorClass: this.actorClass,
|
|
116
|
+
activationId: this.activation.activationId,
|
|
117
|
+
activationFirst: this.activation.first,
|
|
118
|
+
constructorToHandlerMs: this.activation.constructorToHandlerMs,
|
|
119
|
+
firstStorageReadMs: this.firstStorageReadMs ?? null,
|
|
120
|
+
subrequestWallMs: this.observedSubrequest ? this.subrequestWallMs : null,
|
|
121
|
+
storageWrites: 0,
|
|
122
|
+
usedForControl: false,
|
|
123
|
+
exposedInPublicResponse: false,
|
|
124
|
+
}), this.sink);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export function beginDurableObjectHandlerObservation(actorClass, activation, sink) {
|
|
128
|
+
return new DurableObjectHandlerObservation(actorClass, activation, sink);
|
|
129
|
+
}
|
|
130
|
+
/** Test seams may record bounded fault lifecycle facts without a V1 extension. */
|
|
131
|
+
export function observeFaultBarrier(input, sink) {
|
|
132
|
+
if (!Number.isFinite(input.boundedWindowMs) || input.boundedWindowMs < 0)
|
|
133
|
+
return;
|
|
134
|
+
emitObservation(Object.freeze({
|
|
135
|
+
schema: OBSERVATION_SCHEMA,
|
|
136
|
+
event: "fault.barrier",
|
|
137
|
+
emittedAtMs: now(),
|
|
138
|
+
...(typeof input.attemptId === "string" && input.attemptId.length > 0
|
|
139
|
+
? { correlationId: correlationIdForAttempt(input.attemptId) }
|
|
140
|
+
: {}),
|
|
141
|
+
barrierId: input.barrierId,
|
|
142
|
+
stage: input.stage,
|
|
143
|
+
boundedWindowMs: input.boundedWindowMs,
|
|
144
|
+
storageWrites: 0,
|
|
145
|
+
usedForControl: false,
|
|
146
|
+
exposedInPublicResponse: false,
|
|
147
|
+
}), sink);
|
|
148
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sekiban/dcb-runtime",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Cloudflare Durable Object and HTTP runtime for Serialized DCB V1.",
|
|
6
|
+
"license": "Elastic-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/J-Tech-Japan/sekiban-dcb-ts.git",
|
|
10
|
+
"directory": "packages/dcb-runtime"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/J-Tech-Japan/sekiban-dcb-ts/tree/main/packages/dcb-runtime#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/J-Tech-Japan/sekiban-dcb-ts/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"sekiban",
|
|
18
|
+
"dcb",
|
|
19
|
+
"runtime",
|
|
20
|
+
"cloudflare",
|
|
21
|
+
"durable-objects"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./cosmos": {
|
|
34
|
+
"types": "./dist/cosmos.d.ts",
|
|
35
|
+
"import": "./dist/cosmos.js"
|
|
36
|
+
},
|
|
37
|
+
"./d1": {
|
|
38
|
+
"types": "./dist/d1.d.ts",
|
|
39
|
+
"import": "./dist/d1.js"
|
|
40
|
+
},
|
|
41
|
+
"./d1-mv": {
|
|
42
|
+
"types": "./dist/d1-mv.d.ts",
|
|
43
|
+
"import": "./dist/d1-mv.js"
|
|
44
|
+
},
|
|
45
|
+
"./cloudflare": {
|
|
46
|
+
"types": "./dist/cloudflare.d.ts",
|
|
47
|
+
"import": "./dist/cloudflare.js"
|
|
48
|
+
},
|
|
49
|
+
"./mv": {
|
|
50
|
+
"types": "./dist/mv/index.d.ts",
|
|
51
|
+
"import": "./dist/mv/index.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"files": [
|
|
56
|
+
"dist",
|
|
57
|
+
"README.md",
|
|
58
|
+
"LICENSE"
|
|
59
|
+
],
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@sekiban/dcb-core": "0.2.0"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsc -p tsconfig.build.json && esbuild src/index.ts --bundle --format=esm --platform=neutral --external:postgres --external:cloudflare:workers --outfile=dist/index.js && esbuild src/cosmos.ts --bundle --format=esm --platform=neutral --external:postgres --external:cloudflare:workers --outfile=dist/cosmos.js && esbuild src/d1.ts --bundle --format=esm --platform=neutral --external:postgres --external:cloudflare:workers --outfile=dist/d1.js && esbuild src/d1-mv.ts --bundle --format=esm --platform=neutral --external:postgres --external:cloudflare:workers --outfile=dist/d1-mv.js && esbuild src/cloudflare.ts --bundle --format=esm --platform=neutral --external:cloudflare:workers --outfile=dist/cloudflare.js && esbuild src/mv/index.ts --bundle --format=esm --platform=neutral --external:postgres --external:cloudflare:workers --outfile=dist/mv/index.js",
|
|
68
|
+
"build:g42-probe": "esbuild src/g42-probe.ts --bundle --format=esm --platform=neutral --outfile=dist/g42-probe.js",
|
|
69
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
70
|
+
}
|
|
71
|
+
}
|