hikoutei 0.8.38 → 0.8.40
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/api/Hikoutei.d.ts.map +1 -1
- package/dist/api/Hikoutei.js +206 -13
- package/dist/api/Hikoutei.js.map +1 -1
- package/dist/application/sync/service/SyncServiceBootstrap.d.ts.map +1 -1
- package/dist/application/sync/service/SyncServiceBootstrap.js +18 -1
- package/dist/application/sync/service/SyncServiceBootstrap.js.map +1 -1
- package/dist/application/sync/service/systemStateReadiness.d.ts +35 -0
- package/dist/application/sync/service/systemStateReadiness.d.ts.map +1 -0
- package/dist/application/sync/service/systemStateReadiness.js +51 -0
- package/dist/application/sync/service/systemStateReadiness.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hikoutei.d.ts","sourceRoot":"","sources":["../../src/api/Hikoutei.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAEL,cAAc,EACd,KAAK,gCAAgC,EACtC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Hikoutei.d.ts","sourceRoot":"","sources":["../../src/api/Hikoutei.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAEL,cAAc,EACd,KAAK,gCAAgC,EACtC,MAAM,aAAa,CAAC;AAuBrB,sDAAsD;AACtD,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;CAC/C;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA+QD;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,+BAA+B,EACzC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,gCAAgC,CAAC,EAClE,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAChC,QAAQ,CAEV;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAe,GAC9D,MAAM,CAMR;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAmBlF;AAED;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,QAAQ,CAAC,CAkBnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,QAAQ,CAAC,CA8BnB"}
|
package/dist/api/Hikoutei.js
CHANGED
|
@@ -11,16 +11,36 @@ import { createEntityManager } from "./internalEntityManager.js";
|
|
|
11
11
|
import { HIKOUTEI_ERROR_CODES, HikouteiError } from "./errors.js";
|
|
12
12
|
import { getRegisteredEntityTokens, } from "./entity.js";
|
|
13
13
|
import { resolveEntityDescriptors, } from "./internalEntityRegistry.js";
|
|
14
|
+
import { describeErrorForInternalLog, getHikouteiInternalLogger, logHikouteiInternalEvent, } from "../shared/observability/internalLog.js";
|
|
15
|
+
import { HIKOUTEI_LOG_COMPONENTS, HIKOUTEI_LOG_EVENTS, } from "../shared/observability/logEvents.js";
|
|
16
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
14
17
|
/** Environment variable that supplies the default SQLite path. */
|
|
15
18
|
const HIKOUTEI_DB_PATH_ENV = "HIKOUTEI_DB_PATH";
|
|
16
19
|
/** SQLite path used when neither `dbName` nor the env var is set. */
|
|
17
20
|
const DEFAULT_DB_PATH = "./hikoutei.sqlite";
|
|
21
|
+
const beforeCloseHookContext = new AsyncLocalStorage();
|
|
18
22
|
class HikouteiImpl {
|
|
19
23
|
provider;
|
|
20
24
|
beforeClose;
|
|
21
25
|
/** Root entity manager; call `fork()` before request or job-local work. */
|
|
22
26
|
em;
|
|
23
|
-
|
|
27
|
+
closeState = "open";
|
|
28
|
+
/**
|
|
29
|
+
* The single in-flight close attempt. Concurrent close() calls OUTSIDE
|
|
30
|
+
* the active beforeClose hook await this same promise, so cleanup runs
|
|
31
|
+
* exactly once per attempt and every caller observes the same outcome
|
|
32
|
+
* (single-flight). The shared promise represents the FULL close +
|
|
33
|
+
* process-logger-drain operation and settles only AFTER the drain
|
|
34
|
+
* completes (final safe step), so a close() that lands while the first
|
|
35
|
+
* attempt is still draining — including one arriving after
|
|
36
|
+
* performClose() succeeded but before the drain finished — awaits the
|
|
37
|
+
* SAME attempt until the drain is done instead of resolving early on
|
|
38
|
+
* the terminal marker or starting a second cleanup. A close() called
|
|
39
|
+
* from WITHIN the hook resolves immediately instead (MEDIUM 5:
|
|
40
|
+
* awaiting the pending attempt from the hook would self-deadlock). A
|
|
41
|
+
* failed attempt leaves the runtime retryable after the slot release.
|
|
42
|
+
*/
|
|
43
|
+
closeAttempt;
|
|
24
44
|
constructor(provider, descriptors, beforeClose) {
|
|
25
45
|
this.provider = provider;
|
|
26
46
|
this.beforeClose = beforeClose;
|
|
@@ -28,27 +48,200 @@ class HikouteiImpl {
|
|
|
28
48
|
}
|
|
29
49
|
/** Stops internal service work, then releases the local SQLite connection. */
|
|
30
50
|
async close() {
|
|
31
|
-
|
|
51
|
+
// Concurrent callers share the single in-flight attempt. This check
|
|
52
|
+
// comes BEFORE the terminal fast path so a caller that arrives after
|
|
53
|
+
// performClose() succeeded but while the final logger drain is still
|
|
54
|
+
// running awaits the SAME attempt (which settles only after drain)
|
|
55
|
+
// instead of resolving early on the closed marker — the shared
|
|
56
|
+
// promise represents the full close + drain operation.
|
|
57
|
+
if (this.closeAttempt !== undefined) {
|
|
58
|
+
// MEDIUM 5: a close awaited from within the ACTIVE beforeClose hook
|
|
59
|
+
// of THIS runtime must not await the pending attempt — the attempt
|
|
60
|
+
// cannot settle until the hook returns, so awaiting it would
|
|
61
|
+
// self-deadlock. The call resolves immediately: the close is already
|
|
62
|
+
// in progress and owned by the outer caller, so the hook must not
|
|
63
|
+
// rely on the reentrant promise for completion. The exemption is
|
|
64
|
+
// scoped to the OWNING runtime (runtime identity in the context) AND
|
|
65
|
+
// to the hook's execution window (`active`): a close() on a
|
|
66
|
+
// DIFFERENT runtime made from inside the hook, or a close() from a
|
|
67
|
+
// DETACHED callback (setImmediate/promise continuation) that runs
|
|
68
|
+
// AFTER the hook's execution window ended, is an ordinary concurrent
|
|
69
|
+
// call and shares that runtime's in-flight attempt, observing its
|
|
70
|
+
// exact outcome (Luna: the flag is cleared in `finally`, so the
|
|
71
|
+
// detached callback cannot bypass the close/drain attempt). Callers
|
|
72
|
+
// OUTSIDE any hook (no context store) keep sharing the attempt too.
|
|
73
|
+
const marker = beforeCloseHookContext.getStore();
|
|
74
|
+
if (marker !== undefined && marker.runtime === this && marker.active) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return this.closeAttempt;
|
|
78
|
+
}
|
|
79
|
+
// A successful close is terminal and idempotent: later calls resolve
|
|
80
|
+
// immediately without touching the provider again.
|
|
81
|
+
if (this.closeState === "closed")
|
|
32
82
|
return;
|
|
33
|
-
|
|
34
|
-
|
|
83
|
+
let settleAttempt = () => { };
|
|
84
|
+
const attempt = new Promise((resolve, reject) => {
|
|
85
|
+
settleAttempt = (outcome) => {
|
|
86
|
+
if (outcome.ok)
|
|
87
|
+
resolve();
|
|
88
|
+
else
|
|
89
|
+
reject(outcome.error);
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
this.closeAttempt = attempt;
|
|
93
|
+
// The shared attempt is observed by concurrent callers outside the
|
|
94
|
+
// hook; when none exists, a failed attempt must not surface as an
|
|
95
|
+
// unhandled rejection. The no-op side handler marks the rejection
|
|
96
|
+
// handled for the runtime while those callers still receive the
|
|
97
|
+
// original rejection.
|
|
98
|
+
attempt.catch(() => undefined);
|
|
99
|
+
// The attempt's outcome is decided ONLY after the process logger
|
|
100
|
+
// drain completes (final safe step): the shared promise represents
|
|
101
|
+
// the full close + drain operation, so a concurrent caller awaiting
|
|
102
|
+
// it (including one that arrived while the drain was running) cannot
|
|
103
|
+
// proceed before every final event is on disk.
|
|
104
|
+
let failed = false;
|
|
105
|
+
let failure;
|
|
35
106
|
try {
|
|
36
|
-
await this.
|
|
107
|
+
await this.performClose();
|
|
37
108
|
}
|
|
38
109
|
catch (error) {
|
|
39
|
-
|
|
110
|
+
// Boolean flag, never `error !== undefined`: a hook or provider
|
|
111
|
+
// that throws `undefined` is still a FAILED attempt and the shared
|
|
112
|
+
// promise must reject, never resolve.
|
|
113
|
+
failed = true;
|
|
114
|
+
failure = error;
|
|
40
115
|
}
|
|
41
116
|
try {
|
|
42
|
-
|
|
117
|
+
// The soak collector reads the log file immediately after close();
|
|
118
|
+
// drain the process logger queue so every final event (including
|
|
119
|
+
// RUNTIME_CLOSED and any close-failure line) is on disk before the
|
|
120
|
+
// attempt settles. Drain is fail-open by contract, and even a
|
|
121
|
+
// throwing drain must never mask the close outcome — it is
|
|
122
|
+
// swallowed, never propagated.
|
|
123
|
+
await getHikouteiInternalLogger().drain();
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Fail-open: the drain exists to flush diagnostics, so its failure
|
|
127
|
+
// must not change the close outcome decided above.
|
|
128
|
+
}
|
|
129
|
+
// Settle the shared attempt with the ORIGINAL outcome so every
|
|
130
|
+
// concurrent caller observes exactly the same success or failure.
|
|
131
|
+
if (failed) {
|
|
132
|
+
settleAttempt({ ok: false, error: failure });
|
|
43
133
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
134
|
+
else {
|
|
135
|
+
settleAttempt({ ok: true });
|
|
136
|
+
}
|
|
137
|
+
// Release the shared slot only after the attempt settled (final safe
|
|
138
|
+
// step). On success performClose() made the close terminal; on
|
|
139
|
+
// failure performClose() already returned the state to retryable
|
|
140
|
+
// "open", so the NEXT close() call after the slot release genuinely
|
|
141
|
+
// re-runs the cleanup. The original failure is rethrown unchanged to
|
|
142
|
+
// THIS caller after the slot release; concurrent callers already
|
|
143
|
+
// received it through the shared attempt.
|
|
144
|
+
this.closeAttempt = undefined;
|
|
145
|
+
if (failed)
|
|
146
|
+
throw failure;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Runs one full cleanup attempt (beforeClose + provider close).
|
|
150
|
+
*
|
|
151
|
+
* Marks the runtime terminally closed ONLY after the provider close
|
|
152
|
+
* succeeded. EVERY failure — a throwing beforeClose hook, a throwing
|
|
153
|
+
* provider close, or the aggregate of both — explicitly returns the
|
|
154
|
+
* state to retryable `open` before the original error is rethrown
|
|
155
|
+
* unchanged, so the next close() call genuinely re-runs the full
|
|
156
|
+
* cleanup instead of no-oping on a half-closed runtime.
|
|
157
|
+
*/
|
|
158
|
+
async performClose() {
|
|
159
|
+
this.closeState = "closing";
|
|
160
|
+
try {
|
|
161
|
+
let beforeCloseFailed = false;
|
|
162
|
+
let beforeCloseError;
|
|
163
|
+
try {
|
|
164
|
+
const beforeClose = this.beforeClose;
|
|
165
|
+
if (beforeClose !== undefined) {
|
|
166
|
+
// MEDIUM 5: the hook runs inside the marked async context so a
|
|
167
|
+
// close() called from within it is recognized as reentrant for
|
|
168
|
+
// THIS runtime (and never awaits its own pending attempt). The
|
|
169
|
+
// stored runtime identity scopes the exemption: a cross-runtime
|
|
170
|
+
// close() made from the hook is not reentrant.
|
|
171
|
+
//
|
|
172
|
+
// Luna: the exemption is scoped to the hook's EXECUTION WINDOW.
|
|
173
|
+
// Detached setImmediate/promise callbacks scheduled by the hook
|
|
174
|
+
// retain the AsyncLocalStorage store after run() returns, so the
|
|
175
|
+
// active flag is cleared in `finally` once the hook's execution
|
|
176
|
+
// has ended — those callbacks' close() then awaits the same
|
|
177
|
+
// close/drain attempt instead of bypassing it. The flag is
|
|
178
|
+
// cleared even when the hook throws.
|
|
179
|
+
const marker = { runtime: this, active: true };
|
|
180
|
+
try {
|
|
181
|
+
await beforeCloseHookContext.run(marker, () => beforeClose());
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
marker.active = false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
47
187
|
}
|
|
48
|
-
|
|
188
|
+
catch (error) {
|
|
189
|
+
// Boolean flag, never `error !== undefined`: a hook that throws
|
|
190
|
+
// `undefined` is still a FAILED hook and must keep the attempt
|
|
191
|
+
// failed and retryable instead of being treated as success.
|
|
192
|
+
beforeCloseFailed = true;
|
|
193
|
+
beforeCloseError = error;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
await this.provider.close();
|
|
197
|
+
}
|
|
198
|
+
catch (providerError) {
|
|
199
|
+
logHikouteiInternalEvent({
|
|
200
|
+
event: HIKOUTEI_LOG_EVENTS.RUNTIME_CLOSE_FAILED,
|
|
201
|
+
level: "error",
|
|
202
|
+
component: HIKOUTEI_LOG_COMPONENTS.RUNTIME,
|
|
203
|
+
...describeErrorForInternalLog(providerError),
|
|
204
|
+
});
|
|
205
|
+
if (beforeCloseFailed) {
|
|
206
|
+
// Luna: the AggregateError preserves BOTH original failure
|
|
207
|
+
// values as-thrown — including a hook that throws `undefined`
|
|
208
|
+
// or `null`, which are legitimate thrown values. The errors
|
|
209
|
+
// array must never replace the original hook failure with a
|
|
210
|
+
// synthetic Error, so diagnostics can always inspect exactly
|
|
211
|
+
// what each stage threw.
|
|
212
|
+
throw new AggregateError([beforeCloseError, providerError], "Hikoutei failed to stop internal work and close SQLite.");
|
|
213
|
+
}
|
|
214
|
+
throw providerError;
|
|
215
|
+
}
|
|
216
|
+
if (beforeCloseFailed) {
|
|
217
|
+
logHikouteiInternalEvent({
|
|
218
|
+
event: HIKOUTEI_LOG_EVENTS.RUNTIME_CLOSE_FAILED,
|
|
219
|
+
level: "error",
|
|
220
|
+
component: HIKOUTEI_LOG_COMPONENTS.RUNTIME,
|
|
221
|
+
...describeErrorForInternalLog(beforeCloseError),
|
|
222
|
+
});
|
|
223
|
+
// `throw beforeCloseError` is intentional: `undefined` is a
|
|
224
|
+
// legitimate thrown value and the rejection still marks the
|
|
225
|
+
// attempt failed (the caller's catch below returns the state to
|
|
226
|
+
// retryable open).
|
|
227
|
+
throw beforeCloseError;
|
|
228
|
+
}
|
|
229
|
+
this.closeState = "closed";
|
|
230
|
+
logHikouteiInternalEvent({
|
|
231
|
+
event: HIKOUTEI_LOG_EVENTS.RUNTIME_CLOSED,
|
|
232
|
+
level: "info",
|
|
233
|
+
component: HIKOUTEI_LOG_COMPONENTS.RUNTIME,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
// Explicit state transition for EVERY failure path (beforeClose or
|
|
238
|
+
// provider): the runtime returns to retryable `open` so the next
|
|
239
|
+
// close() re-runs the cleanup. The original error is rethrown
|
|
240
|
+
// unchanged; the shared-attempt slot was already released by the
|
|
241
|
+
// caller's finally block.
|
|
242
|
+
this.closeState = "open";
|
|
243
|
+
throw error;
|
|
49
244
|
}
|
|
50
|
-
if (beforeCloseError !== undefined)
|
|
51
|
-
throw beforeCloseError;
|
|
52
245
|
}
|
|
53
246
|
}
|
|
54
247
|
/**
|
package/dist/api/Hikoutei.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hikoutei.js","sourceRoot":"","sources":["../../src/api/Hikoutei.ts"],"names":[],"mappings":"AAAA;;;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,8CAA8C,CAC/C,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,yBAAyB,CAAC;QAC7C,MAAM;QACN,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC;QACvB,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,QAAQ,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,SAAS,4BAA4B,CACnC,OAA0C;IAE1C,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,eAAe;YAClB,MAAM,IAAI,aAAa,CACrB,oBAAoB,CAAC,yBAAyB,EAC9C,gFAAgF,CACjF,CAAC;QACJ,KAAK,gBAAgB;YACnB,MAAM,IAAI,aAAa,CACrB,oBAAoB,CAAC,gBAAgB,EACrC,gBAAgB,OAAO,CAAC,UAAU,iCAAiC,CACpE,CAAC;QACJ,KAAK,iBAAiB;YACpB,MAAM,IAAI,aAAa,CACrB,oBAAoB,CAAC,gBAAgB,EACrC,UAAU,OAAO,CAAC,SAAS,4BAA4B,OAAO,CAAC,eAAe,UAAU,OAAO,CAAC,gBAAgB,IAAI,CACrH,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncServiceBootstrap.d.ts","sourceRoot":"","sources":["../../../../src/application/sync/service/SyncServiceBootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"SyncServiceBootstrap.d.ts","sourceRoot":"","sources":["../../../../src/application/sync/service/SyncServiceBootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAyCH,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAChC,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,mBAAmB,CAAC,CA4H9B"}
|
|
@@ -29,6 +29,7 @@ import { createRemoteProvider } from "./remoteProvider.js";
|
|
|
29
29
|
import { createEffectSupervisor } from "./effectSupervisor.js";
|
|
30
30
|
import { createPollingSupervisor } from "./pollingSupervisor.js";
|
|
31
31
|
import { createStopHandler, expireRuntimeWriterLeases } from "./shutdown.js";
|
|
32
|
+
import { registerSystemStateReadiness, unregisterSystemStateReadiness, } from "./systemStateReadiness.js";
|
|
32
33
|
import { createWriterOptions, throwSyncResolutionError, validateServiceOptions, } from "./serviceOptions.js";
|
|
33
34
|
/**
|
|
34
35
|
* Opens, provisions, and starts one internal sync service.
|
|
@@ -94,7 +95,23 @@ export async function createInternalSyncService(options) {
|
|
|
94
95
|
effectSupervisor,
|
|
95
96
|
});
|
|
96
97
|
const provider = new MikroOrmScalarPersistenceProvider(runtime.storage, generated.bindings, runtime.flushCoordinator);
|
|
97
|
-
|
|
98
|
+
// The runtime object is the readiness key: the beforeClose hook runs
|
|
99
|
+
// only after this assignment, so the captured reference is always the
|
|
100
|
+
// fully constructed runtime. Unregistering happens BEFORE the stop
|
|
101
|
+
// handler runs, so a closing runtime reports ready (no outbox to drain)
|
|
102
|
+
// the moment its close begins.
|
|
103
|
+
let hikoutei;
|
|
104
|
+
const hikouteiClose = async () => {
|
|
105
|
+
unregisterSystemStateReadiness(hikoutei);
|
|
106
|
+
await stop();
|
|
107
|
+
};
|
|
108
|
+
hikoutei = createInternalHikoutei(provider, descriptors, hikouteiClose);
|
|
109
|
+
// Register the runtime's System_State readiness right after bootstrap so
|
|
110
|
+
// external convergence barriers can wait on the drain; the runtime is
|
|
111
|
+
// unregistered on close (see hikouteiClose). Never part of the public
|
|
112
|
+
// API — the registration is keyed to the internal/public runtime object
|
|
113
|
+
// and read only through this internal module.
|
|
114
|
+
registerSystemStateReadiness(hikoutei, runtime.storage);
|
|
98
115
|
effectSupervisor.start();
|
|
99
116
|
pollingSupervisor.start();
|
|
100
117
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncServiceBootstrap.js","sourceRoot":"","sources":["../../../../src/application/sync/service/SyncServiceBootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,sBAAsB,
|
|
1
|
+
{"version":3,"file":"SyncServiceBootstrap.js","sourceRoot":"","sources":["../../../../src/application/sync/service/SyncServiceBootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,sBAAsB,GAEvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,GACzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,uBAAuB,GACxB,MAAM,kFAAkF,CAAC;AAC1F,OAAO,EACL,2BAA2B,GAC5B,MAAM,kFAAkF,CAAC;AAC1F,OAAO,EACL,iCAAiC,GAClC,MAAM,2FAA2F,CAAC;AACnG,OAAO,EACL,0CAA0C,EAC1C,qCAAqC,GACtC,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EACL,6BAA6B,GAC9B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,oCAAoC,GACrC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EACL,mCAAmC,EACnC,kCAAkC,GACnC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,GAGvB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|
2
|
+
* Internal System_State readiness controller for external convergence
|
|
3
|
+
* barriers.
|
|
4
|
+
*
|
|
5
|
+
* External tooling (for example the local multi-table soak runner's live
|
|
6
|
+
* convergence phase) needs to know when a runtime's System_State outbox
|
|
7
|
+
* drain has finished so its own batched sheet reads do not compete with
|
|
8
|
+
* the initial drain on the shared request limiter. The sync service
|
|
9
|
+
* registers every runtime it bootstraps here and unregisters it when the
|
|
10
|
+
* runtime closes; a runtime that was never registered (plain local-only
|
|
11
|
+
* mode, or an already-closed runtime) reports ready immediately.
|
|
12
|
+
*
|
|
13
|
+
* This module is deliberately internal: it is never re-exported from
|
|
14
|
+
* `src/index.ts`, and applications observe readiness only through the
|
|
15
|
+
* library's own behavior.
|
|
16
|
+
*/
|
|
17
|
+
import type { Hikoutei } from "../../../api/Hikoutei.js";
|
|
18
|
+
import type { MikroOrmSqliteAdapter } from "../../../adapter/persistence/providers/mikro-orm/storage/MikroOrmSqliteAdapter.js";
|
|
19
|
+
import { type SystemStateDrainReadiness } from "@hikoutei/ikisaki";
|
|
20
|
+
/** Registers one bootstrapped runtime for readiness queries. */
|
|
21
|
+
export declare function registerSystemStateReadiness(runtime: Hikoutei, storage: MikroOrmSqliteAdapter): void;
|
|
22
|
+
/** Unregisters one runtime (called on close, before storage is released). */
|
|
23
|
+
export declare function unregisterSystemStateReadiness(runtime: Hikoutei): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reports the CURRENT System_State drain readiness of one runtime.
|
|
26
|
+
*
|
|
27
|
+
* Only the System_State projection's claimable in-flight effects are
|
|
28
|
+
* considered — never the whole-outbox idle state. A pending follower behind
|
|
29
|
+
* a conflict/blocked_candidate/failed predecessor is not claimable drain
|
|
30
|
+
* work and never defers, so an open conflict cannot stall the barrier. A
|
|
31
|
+
* runtime without a registered sync service (local-only mode, or already
|
|
32
|
+
* closed) has no outbox to drain and is ready immediately.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readRuntimeSystemStateReadiness(runtime: Hikoutei): Promise<SystemStateDrainReadiness>;
|
|
35
|
+
//# sourceMappingURL=systemStateReadiness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemStateReadiness.d.ts","sourceRoot":"","sources":["../../../../src/application/sync/service/systemStateReadiness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mFAAmF,CAAC;AAC/H,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,mBAAmB,CAAC;AAiB3B,gEAAgE;AAChE,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,qBAAqB,GAC7B,IAAI,CAEN;AAED,6EAA6E;AAC7E,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAEtE;AAED;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,yBAAyB,CAAC,CAIpC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal System_State readiness controller for external convergence
|
|
3
|
+
* barriers.
|
|
4
|
+
*
|
|
5
|
+
* External tooling (for example the local multi-table soak runner's live
|
|
6
|
+
* convergence phase) needs to know when a runtime's System_State outbox
|
|
7
|
+
* drain has finished so its own batched sheet reads do not compete with
|
|
8
|
+
* the initial drain on the shared request limiter. The sync service
|
|
9
|
+
* registers every runtime it bootstraps here and unregisters it when the
|
|
10
|
+
* runtime closes; a runtime that was never registered (plain local-only
|
|
11
|
+
* mode, or an already-closed runtime) reports ready immediately.
|
|
12
|
+
*
|
|
13
|
+
* This module is deliberately internal: it is never re-exported from
|
|
14
|
+
* `src/index.ts`, and applications observe readiness only through the
|
|
15
|
+
* library's own behavior.
|
|
16
|
+
*/
|
|
17
|
+
import { readSystemStateDrainReadinessWithAdapter, } from "@hikoutei/ikisaki";
|
|
18
|
+
/**
|
|
19
|
+
* Registry of bootstrapped runtimes keyed by the runtime object itself.
|
|
20
|
+
*
|
|
21
|
+
* A WeakMap keeps the registry inert: a runtime that is garbage-collected
|
|
22
|
+
* without closing (or whose registration leaked) never pins its storage
|
|
23
|
+
* or SQLite file open, and the key is the exact public `Hikoutei` object
|
|
24
|
+
* the caller holds.
|
|
25
|
+
*/
|
|
26
|
+
const registeredRuntimes = new WeakMap();
|
|
27
|
+
/** Registers one bootstrapped runtime for readiness queries. */
|
|
28
|
+
export function registerSystemStateReadiness(runtime, storage) {
|
|
29
|
+
registeredRuntimes.set(runtime, { storage });
|
|
30
|
+
}
|
|
31
|
+
/** Unregisters one runtime (called on close, before storage is released). */
|
|
32
|
+
export function unregisterSystemStateReadiness(runtime) {
|
|
33
|
+
registeredRuntimes.delete(runtime);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reports the CURRENT System_State drain readiness of one runtime.
|
|
37
|
+
*
|
|
38
|
+
* Only the System_State projection's claimable in-flight effects are
|
|
39
|
+
* considered — never the whole-outbox idle state. A pending follower behind
|
|
40
|
+
* a conflict/blocked_candidate/failed predecessor is not claimable drain
|
|
41
|
+
* work and never defers, so an open conflict cannot stall the barrier. A
|
|
42
|
+
* runtime without a registered sync service (local-only mode, or already
|
|
43
|
+
* closed) has no outbox to drain and is ready immediately.
|
|
44
|
+
*/
|
|
45
|
+
export async function readRuntimeSystemStateReadiness(runtime) {
|
|
46
|
+
const entry = registeredRuntimes.get(runtime);
|
|
47
|
+
if (entry === undefined)
|
|
48
|
+
return { status: "ready" };
|
|
49
|
+
return readSystemStateDrainReadinessWithAdapter(entry.storage);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=systemStateReadiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemStateReadiness.js","sourceRoot":"","sources":["../../../../src/application/sync/service/systemStateReadiness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EACL,wCAAwC,GAEzC,MAAM,mBAAmB,CAAC;AAO3B;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAA+B,CAAC;AAEtE,gEAAgE;AAChE,MAAM,UAAU,4BAA4B,CAC1C,OAAiB,EACjB,OAA8B;IAE9B,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,8BAA8B,CAAC,OAAiB;IAC9D,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,OAAiB;IAEjB,MAAM,KAAK,GAAG,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACpD,OAAO,wCAAwC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hikoutei",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.40",
|
|
4
4
|
"description": "Typed repository and safe write layer for Google Sheets-backed MVPs. SQLite-authoritative entity lifecycle with asynchronous Google Sheets projection.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|